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

[BREAKING] make --script-mode the default; add --cwd-mode to switch back to old behavior #1155

Merged
merged 24 commits into from Feb 16, 2021

Conversation

cspotcode
Copy link
Collaborator

@cspotcode cspotcode commented Nov 19, 2020

Resolves #949
Resolves #1194
Resolves #1189
Resolves #1197
Resolves #1220
Resolves #1225

  • add tests

I took a quick look at our old discussions and it doesn't seem like we came up with any reasons why this change is bad.

Adds --cwd-mode flag to switch back to the old behavior, or users can specify a directory with --dir or a tsconfig file with --project

Need to rethink the way --dir works. Currently, it is treated as if you'd cded to the target directory, which affects lots of behaviors. The --help docs say it only affects config resolution. But in the code, it overrides all process.cwd() checks. That seems confusing to me.

For example, if you use --dir, then error messages which log script paths will log them relative to --dir. --project is also interpreted relative to --dir.


Now that implementation is complete, a summary of changes:

  • Use --script-mode by default
  • Add --cwd-mode flag to opt-out of --script-mode
  • Add ts-node-cwd entry-point that uses --cwd-mode by default
  • Rename --dir to --cwd; TS_NODE_DIR to TS_NODE_CWD; parse legacy names for backwards compatibility
  • Rewrite --cwd docs to say it changes effective cwd
  • Add projectSearchDir API option to set directory from which tsconfig search is performed
  • Fix bug where resolving entry-point location could poison require.resolve cache and prevent correct extension from loading (ts-node ./index may execute the wrong file extension because tsconfig search poisons the require.resolve cache #1220)
  • --cwd no longer sets --scope
  • Remove --scope from CLI flags and tsconfig-loaded options; it is an API-only option, to match the intended use-case: programmatically installing multiple ts-node instances
  • Add scopeDir API option
  • Deprecate TS_NODE_SCOPE env var
  • ignore rules evaluated relative to tsconfig.json, otherwise cwd; no longer tied to --dir
  • compiler is loaded relative to tsconfig.json instead of cwd or entrypoint script (Load compiler relative to tsconfig.json instead of cwd #1225)

@codecov
Copy link

codecov bot commented Nov 19, 2020

Codecov Report

Merging #1155 (1811706) into master (080af32) will increase coverage by 0.38%.
The diff coverage is 84.78%.

Impacted Files Coverage Δ
src/bin.ts 90.10% <75.00%> (-0.14%) ⬇️
src/index.ts 79.75% <91.66%> (+0.44%) ⬆️
src/bin-cwd.ts 100.00% <100.00%> (ø)

@cspotcode cspotcode merged commit bacbeaf into master Feb 16, 2021
@cspotcode cspotcode changed the title make --script-mode the default; add --cwd-mode to switch back to old behavior [BREAKING] make --script-mode the default; add --cwd-mode to switch back to old behavior Feb 22, 2021
@cspotcode cspotcode added this to the 10.0.0 milestone May 19, 2021
@cspotcode cspotcode deleted the ab/script-mode-by-default branch October 11, 2021 03:48
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment