Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Open
6 tasks done
pghalliday opened this issue Jan 13, 2025 · 3 comments
Open
6 tasks done
Labels
Awaiting More Feedback This means we'd like to hear from more people who would be helped by this feature Suggestion An idea for TypeScript

Comments

@pghalliday
Copy link

πŸ” 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
@RyanCavanaugh
Copy link
Member

I think you're just asking for listFilesOnly, which was added exactly for this scenario. If not, please explain why that's not sufficient

@RyanCavanaugh RyanCavanaugh added the Needs More Info The issue still hasn't been fully clarified label Jan 13, 2025
@pghalliday
Copy link
Author

I think you're just asking for listFilesOnly, which was added exactly for this scenario. If not, please explain why that's not sufficient

But then I still have to run tsc twice. Is this different to --listFiles --noEmit?

@pghalliday
Copy link
Author

Ok I can see that with --listFilesOnly then I don't get errors mixed in with the file list. However I tried the following script:

#!/usr/bin/env bash

set -e

INPUT_DIR=$1
DEPS_FILE=$2

SQL_SCRIPT=$INPUT_DIR/sql/test.sql

rm -rf "${INPUT_DIR:?}/"lib
INPUT_FILES=$(npx tsc --project "$INPUT_DIR"/tsconfig.json --listFilesOnly)
echo "$SQL_SCRIPT: $(echo "$INPUT_FILES" | sed 's/$/ \\/')" > "$DEPS_FILE"
npx tsc --project "$INPUT_DIR"/tsconfig.json
cd "$INPUT_DIR"/lib
node index.js

And It still takes nearly twice as long to run as the workaround where I run tsc once and try to extract the compiler output from the listFiles output (3 seconds vs 1.5 seconds on average, but I run this script for lots of test directories so it really adds up).

@RyanCavanaugh RyanCavanaugh added Suggestion An idea for TypeScript Awaiting More Feedback This means we'd like to hear from more people who would be helped by this feature and removed Needs More Info The issue still hasn't been fully clarified labels Jan 13, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Awaiting More Feedback This means we'd like to hear from more people who would be helped by this feature Suggestion An idea for TypeScript
Projects
None yet
Development

No branches or pull requests

2 participants