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

Re-export node-relevant @tsconfig/bases; use by default in absence of a tsconfig file #1202

Closed
6 tasks done
cspotcode opened this issue Jan 28, 2021 · 2 comments · Fixed by #1236
Closed
6 tasks done

Comments

@cspotcode
Copy link
Collaborator

cspotcode commented Jan 28, 2021

This is technically 2 features in one:

a) re-export @tsconfig/bases so that a user's tsconfig can, for example, "extends": "ts-node/node14/tsconfig.json"
b) in the absence of a tsconfig, check node version and use a suitable default.

https://github.com/tsconfig/bases

This allows ts-node to handle bare scripts using modern language features. For example, bigint literals require a modern "target" option which tsc does not adopt by default. If someone tried to write a ts-node shebang script using bigint literals, it would fail to compile unless they accompanied it with a tsconfig.json.

Note: changelog below mentions CLI and programmatic flags to disable this automatic base config.
Decided that was not necessary but put an implementation in #1249

TODO

  • add CLI flag --skip-default-project
    • UPDATE decided to omit this feature until it is requested, per discord discussion below.
      Users can always create a tsconfig.json to suppress default project, or specify --compiler-options to override options)
  • update programmatic option to match? skipDefaultProject?
    • not implemented, see rationale above
  • what to name the CLI flag
  • extract CLI flag to another PR; do not implement it in this first pass
  • add tests
  • newer @tsconfig/bases are incompatible with Typescript 2.7: how to handle this?
    • can check ts.ScriptTarget and ts.libs to ensure they have the necessary entries. If node14 config is incompatible, try node12, then node10
    • TS 3.4 added target ES2019 but does not have the necessary require('typescript').libs entries for the node12 tsconfig, so checking libs is necessary
@cspotcode
Copy link
Collaborator Author

Will need to add an option --skip-default-project

If you really want ts-node to use default tsc compiler options:
ts-node --skip-project --skip-default-project ./index.ts

This is verbose; the rationale is that people will rarely want to do this.

The default, ts-node ./index.ts or ts-node, will load @tsconfig/node* where it picks node10, node12, or node14 based on node runtime's major version number.

@cspotcode
Copy link
Collaborator Author

When implementing, should be sure to avoid triggering any logic that cares about the path of the tsconfig file. In other words, we don't want to affect scope, or ignore, or anything like that. We just want to get the tsconfig compilerOptions such as "target" and "lib".

cspotcode added a commit that referenced this issue Feb 27, 2021
* Implementation

* fix

* fix lint

* fix

* fix

* cleanup

* fallback to older @tsconfig/node* config when we detect an incompatibility with the lib or target options

* lint fix

* WIP

* Add CLI and programmatic option to disable implicit compiler options

* Remove --no-implicit-compiler-options flag and programmatic option; it is implemented in another PR

* add tests

* fix tests

* fix tests

* fix tests
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

1 participant