Skip to content

Commit 98c0c9b

Browse files
committed
Rename --cwd flag to --dir
1 parent be8e2e1 commit 98c0c9b

File tree

4 files changed

+17
-13
lines changed

4 files changed

+17
-13
lines changed

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -133,7 +133,7 @@ _Environment variable denoted in parentheses._
133133
* `-C, --compiler [name]` Specify a custom TypeScript compiler (`TS_NODE_COMPILER`, default: `typescript`)
134134
* `-D, --ignore-diagnostics [code]` Ignore TypeScript warnings by diagnostic code (`TS_NODE_IGNORE_DIAGNOSTICS`)
135135
* `-O, --compiler-options [opts]` JSON object to merge with compiler options (`TS_NODE_COMPILER_OPTIONS`)
136-
* `--cwd` Specify working directory for config resolution (`TS_NODE_CWD`, default: `process.cwd()`)
136+
* `--dir` Specify working directory for config resolution (`TS_NODE_CWD`, default: `process.cwd()`)
137137
* `--scope` Scope compiler to files within `cwd` (`TS_NODE_SCOPE`, default: `false`)
138138
* `--files` Load files from `tsconfig.json` on startup (`TS_NODE_FILES`, default: `false`)
139139
* `--pretty` Use pretty diagnostic formatter (`TS_NODE_PRETTY`, default: `false`)

src/bin.ts

Lines changed: 10 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,7 @@ export function main (argv: string[]) {
4545
'--version': arg.COUNT,
4646

4747
// Project options.
48-
'--cwd': String,
48+
'--dir': String,
4949
'--files': Boolean,
5050
'--compiler': String,
5151
'--compiler-options': parse,
@@ -79,7 +79,7 @@ export function main (argv: string[]) {
7979
})
8080

8181
const {
82-
'--cwd': cwd = DEFAULTS.cwd || process.cwd(),
82+
'--dir': dir = DEFAULTS.dir,
8383
'--help': help = false,
8484
'--script-mode': scriptMode = false,
8585
'--version': version = 0,
@@ -139,12 +139,13 @@ export function main (argv: string[]) {
139139
process.exit(0)
140140
}
141141

142+
const cwd = dir || process.cwd()
142143
const scriptPath = args._.length ? resolve(cwd, args._[0]) : undefined
143144
const state = new EvalState(scriptPath || join(cwd, EVAL_FILENAME))
144145

145146
// Register the TypeScript compiler instance.
146147
const service = register({
147-
cwd: getCwd(cwd, scriptMode, scriptPath),
148+
dir: getCwd(dir, scriptMode, scriptPath),
148149
files,
149150
pretty,
150151
transpileOnly,
@@ -222,17 +223,21 @@ export function main (argv: string[]) {
222223
/**
223224
* Get project path from args.
224225
*/
225-
function getCwd (cwd: string, scriptMode?: boolean, scriptPath?: string) {
226+
function getCwd (dir?: string, scriptMode?: boolean, scriptPath?: string) {
226227
// Validate `--script-mode` usage is correct.
227228
if (scriptMode) {
228229
if (!scriptPath) {
229230
throw new TypeError('Script mode must be used with a script name, e.g. `ts-node -s <script.ts>`')
230231
}
231232

233+
if (dir) {
234+
throw new TypeError('Script mode cannot be combined with `--dir`')
235+
}
236+
232237
return dirname(scriptPath)
233238
}
234239

235-
return cwd
240+
return dir
236241
}
237242

238243
/**

src/index.spec.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -388,8 +388,8 @@ describe('ts-node', function () {
388388
registered.enabled(false)
389389

390390
const compilers = [
391-
register({ cwd: join(TEST_DIR, 'scope/a'), scope: true }),
392-
register({ cwd: join(TEST_DIR, 'scope/b'), scope: true })
391+
register({ dir: join(TEST_DIR, 'scope/a'), scope: true }),
392+
register({ dir: join(TEST_DIR, 'scope/b'), scope: true })
393393
]
394394

395395
compilers.forEach(c => {

src/index.ts

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -72,7 +72,7 @@ export const VERSION = require('../package.json').version
7272
* Options for creating a new TypeScript compiler instance.
7373
*/
7474
export interface CreateOptions {
75-
cwd?: string
75+
dir?: string
7676
scope?: boolean | null
7777
pretty?: boolean | null
7878
typeCheck?: boolean | null
@@ -123,7 +123,7 @@ export interface TypeInfo {
123123
* Default register options.
124124
*/
125125
export const DEFAULTS: RegisterOptions = {
126-
cwd: process.env.TS_NODE_CWD,
126+
dir: process.env.TS_NODE_DIR,
127127
scope: yn(process.env.TS_NODE_SCOPE),
128128
files: yn(process.env['TS_NODE_FILES']),
129129
pretty: yn(process.env['TS_NODE_PRETTY']),
@@ -195,7 +195,6 @@ export class TSError extends BaseError {
195195
* Return type for registering `ts-node`.
196196
*/
197197
export interface Register {
198-
cwd: string
199198
ts: TSCommon
200199
config: _ts.ParsedCommandLine
201200
enabled (enabled?: boolean): boolean
@@ -258,7 +257,7 @@ export function create (options: CreateOptions = {}): Register {
258257
).map(str => new RegExp(str))
259258

260259
// Require the TypeScript compiler and configuration.
261-
const cwd = options.cwd ? resolve(options.cwd) : process.cwd()
260+
const cwd = options.dir ? resolve(options.dir) : process.cwd()
262261
const isScoped = options.scope ? (fileName: string) => relative(cwd, fileName).charAt(0) !== '.' : () => true
263262
const typeCheck = options.typeCheck === true || options.transpileOnly !== true
264263
const compiler = require.resolve(options.compiler || 'typescript', { paths: [cwd, __dirname] })
@@ -465,7 +464,7 @@ export function create (options: CreateOptions = {}): Register {
465464
const enabled = (enabled?: boolean) => enabled === undefined ? active : (active = !!enabled)
466465
const ignored = (fileName: string) => !active || !isScoped(fileName) || shouldIgnore(fileName, ignore)
467466

468-
return { cwd, ts, config, compile, getTypeInfo, ignored, enabled }
467+
return { ts, config, compile, getTypeInfo, ignored, enabled }
469468
}
470469

471470
/**

0 commit comments

Comments
 (0)