Repository navigation
[BREAKING] make --script-mode the default; add --cwd-mode to switch back to old behavior - #1155
Merged
Merged
Conversation
Codecov Report
|
…quire.resolve cache; causes entrypoint to resolve incorrectly when --prefer-ts-exts is used
…ojectSearchDir as needed
cspotcode
force-pushed
the
ab/script-mode-by-default
branch
from
February 15, 2021 10:33
e05f037 to
7d7f76b
Compare
This was referenced Feb 15, 2021
hanzo-dev
pushed a commit
to hanzoai/ts-node
that referenced
this pull request
Sep 9, 2026
…behavior; other cwd, project, and dir fixes (TypeStrong#1155) * 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 (TypeStrong#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 (TypeStrong#1225) --- *Original GH-generated squash summary* * make --script-mode the default; add --cwd-mode to switch back to old behavior * Fix bug where --script-mode entrypoint require.resolve poisons the require.resolve cache; causes entrypoint to resolve incorrectly when --prefer-ts-exts is used * WIP TODO amend / rewrite this commit * wip * WIP * add ts-node-cwd bin, which is equivalent to ts-node --cwd-mode * rename projectSearchPath to projectSearchDir * Revert undesirable changes from WIP commits * add --cwd-mode and --script-mode tests * revert undesirable logging from WIP commits * update tests which relied on --dir affecting to cwd to instead use projectSearchDir as needed * remove --script-mode from test invocations that don't need it anymore * fix lint failures * fix tests * fix requireResolveNonCached to avoid hack on node 10 & 11 * fix tests to avoid type error on ts2.7 * fix tests on node 10 * update README and final cleanup * more cleanup * Load typescript compiler relative to tsconfig.json
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Resolves #949
Resolves #1194
Resolves #1189
Resolves #1197
Resolves #1220
Resolves #1225
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-modeflag to switch back to the old behavior, or users can specify a directory with--diror a tsconfig file with--projectNeed to rethink the way
--dirworks. Currently, it is treated as if you'dcded to the target directory, which affects lots of behaviors. The--helpdocs say it only affects config resolution. But in the code, it overrides allprocess.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.--projectis also interpreted relative to--dir.Now that implementation is complete, a summary of changes:
--script-modeby default--cwd-modeflag to opt-out of--script-modets-node-cwdentry-point that uses--cwd-modeby default--dirto--cwd;TS_NODE_DIRtoTS_NODE_CWD; parse legacy names for backwards compatibility--cwddocs to say it changes effectivecwdprojectSearchDirAPI option to set directory from which tsconfig search is performedrequire.resolvecache and prevent correct extension from loading (ts-node ./index may execute the wrong file extension because tsconfig search poisons the require.resolve cache #1220)--cwdno longer sets--scope--scopefrom CLI flags and tsconfig-loaded options; it is an API-only option, to match the intended use-case: programmatically installing multiple ts-node instancesscopeDirAPI optionTS_NODE_SCOPEenv varignorerules evaluated relative totsconfig.json, otherwisecwd; no longer tied to--dircompileris loaded relative totsconfig.jsoninstead ofcwdor entrypoint script (Load compiler relative to tsconfig.json instead of cwd #1225)