microsoft / microsoft/TypeScript

Extend the tsc --listFiles option to specify an output file for the list

Open
#60,966 4 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Awaiting More Feedback Suggestion
Dominant language
Go
Stars
111k
Forks
14.3k
Avg merge
2d 4h
Merged PRs (30d)
132

Description

🔍 Search Terms

listFiles redirect

✅ Viability Checklist
⭐ Suggestion

I would like to be able to separate the output from the listFiles option from the rest of the tsc output (eg. compilation errors). I think the easiest way to do this would be to allow an output file to be specified.

📃 Motivating Example

While integrating typescript scripts into a make build process, I wanted to generate dependency files to facilitate incremental builds. Initially I tried running with the listFiles flag and capturing the output to create the dependency files to include in my makefile, however I quickly ran into the following issues:

  1. Compilation errors and the file list are both output to stdout
  2. By default capturing the output of a subshell stops it being output to the console

My initial solution was to run tsc twice, once with --listFiles --noEmit and then again without those options. This resulted in excessive build times as I needed to do this for lots of scripts.

For now I have solved the issue with the following bash script that attempts to extract the compilation output from the listFiles output:

#!/usr/bin/env bash

set -e

INPUT_DIR=$1
DEPS_FILE=$2

SQL_SCRIPT=$INPUT_DIR/sql/test.sql

rm -rf "${INPUT_DIR:?}/"lib
if INPUT_FILES=$(npx tsc --project "$INPUT_DIR"/tsconfig.json --listFiles); then
  echo "$SQL_SCRIPT: $(echo "$INPUT_FILES" | sed 's/$/ \\/')" > "$DEPS_FILE"
  cd "$INPUT_DIR"/lib
  node index.js
else
  EXIT_CODE=$?
  # the following assumes that all important compilation output contains the text ': error'
  echo "$INPUT_FILES" | grep ": error"
  exit $EXIT_CODE
fi

However it would be much simpler if I could separate the listFiles output using the tsc command, eg:

#!/usr/bin/env bash

set -e

INPUT_DIR=$1
DEPS_FILE=$2

SQL_SCRIPT=$INPUT_DIR/sql/test.sql

rm -rf "${INPUT_DIR:?}/"lib
npx tsc --project "$INPUT_DIR"/tsconfig.json --listFilesTo $INPUT_DIR/ts/deps
echo "$SQL_SCRIPT: $(sed 's/$/ \\/' $INPUT_DIR/ts/deps)" > "$DEPS_FILE"
cd "$INPUT_DIR"/lib
node index.js
💻 Use Cases
  1. What do you want to use this for? : I want to simply integrate the listFiles output into a make based build environment
  2. What shortcomings exist with current approaches? : The listFiles and compilation error outputs are mixed together
  3. What workarounds are you using in the meantime? : A complicated shell script that tries to extract the compilation output from the listFiles output

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start with the tsc command and its existing --listFiles handling, using the motivating bash script and tsconfig invocation as the behavioral context. Define how an output-file option should separate the file list from compilation diagnostics, then add coverage for successful and failing compilations and verify the generated dependency file.

Written by the indexing model from the issue text.

Assessment

Tech stack
typescript
Domain
build-system, cli
Issue type
Feature
Difficulty
4/5
Estimated time
3-5 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
42/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.