From e10b216ae09a11527627143c1fdd767e0cbd13bd Mon Sep 17 00:00:00 2001 From: Andrew Bradley Date: Tue, 1 Feb 2022 17:02:15 -0500 Subject: [PATCH 1/5] render proper relative moduleTypes paths and omit empty require array in --showConfig output --- src/bin.ts | 13 ++++++++++++- 1 file changed, 12 insertions(+), 1 deletion(-) diff --git a/src/bin.ts b/src/bin.ts index 564ddaba3..05cc30c6d 100644 --- a/src/bin.ts +++ b/src/bin.ts @@ -1,6 +1,6 @@ #!/usr/bin/env node -import { join, resolve, dirname, parse as parsePath } from 'path'; +import { join, resolve, dirname, parse as parsePath, relative } from 'path'; import { inspect } from 'util'; import Module = require('module'); import arg = require('arg'); @@ -327,9 +327,20 @@ Options: ); process.exit(1); } + let moduleTypes = undefined; + if(service.options.moduleTypes) { + // Assumption: this codepath requires CLI invocation, so moduleTypes must have come from a tsconfig, not API. + const showRelativeTo = dirname(service.configFilePath!); + moduleTypes = {} as Record; + for(const [key, value] of Object.entries(service.options.moduleTypes)) { + moduleTypes[relative(showRelativeTo, resolve(service.options.optionBasePaths?.moduleTypes!, key))] = value; + } + } const json = { ['ts-node']: { ...service.options, + require: service.options.require?.length ? service.options.require : undefined, + moduleTypes, optionBasePaths: undefined, compilerOptions: undefined, project: service.configFilePath ?? service.options.project, From 40c30df48a14fd0870db83bef6fc2d5a2a50eefd Mon Sep 17 00:00:00 2001 From: Andrew Bradley Date: Tue, 1 Feb 2022 17:02:35 -0500 Subject: [PATCH 2/5] lint-fix --- src/bin.ts | 15 +++++++++++---- 1 file changed, 11 insertions(+), 4 deletions(-) diff --git a/src/bin.ts b/src/bin.ts index 05cc30c6d..8c05fc059 100644 --- a/src/bin.ts +++ b/src/bin.ts @@ -328,18 +328,25 @@ Options: process.exit(1); } let moduleTypes = undefined; - if(service.options.moduleTypes) { + if (service.options.moduleTypes) { // Assumption: this codepath requires CLI invocation, so moduleTypes must have come from a tsconfig, not API. const showRelativeTo = dirname(service.configFilePath!); moduleTypes = {} as Record; - for(const [key, value] of Object.entries(service.options.moduleTypes)) { - moduleTypes[relative(showRelativeTo, resolve(service.options.optionBasePaths?.moduleTypes!, key))] = value; + for (const [key, value] of Object.entries(service.options.moduleTypes)) { + moduleTypes[ + relative( + showRelativeTo, + resolve(service.options.optionBasePaths?.moduleTypes!, key) + ) + ] = value; } } const json = { ['ts-node']: { ...service.options, - require: service.options.require?.length ? service.options.require : undefined, + require: service.options.require?.length + ? service.options.require + : undefined, moduleTypes, optionBasePaths: undefined, compilerOptions: undefined, From 885de4831b05c9ef9695a0899adfe5bc64a7e722 Mon Sep 17 00:00:00 2001 From: Andrew Bradley Date: Tue, 1 Feb 2022 17:03:14 -0500 Subject: [PATCH 3/5] rewrite error message to mention --showConfig instead of --show-config --- src/bin.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/bin.ts b/src/bin.ts index 8c05fc059..09f79c739 100644 --- a/src/bin.ts +++ b/src/bin.ts @@ -323,7 +323,7 @@ Options: const ts = service.ts as any as TSInternal; if (typeof ts.convertToTSConfig !== 'function') { console.error( - 'Error: --show-config requires a typescript versions >=3.2 that support --showConfig' + 'Error: --showConfig requires a typescript versions >=3.2 that support --showConfig' ); process.exit(1); } From 34fe3d3b992e0131e1e80bd632e6423ca0db66cf Mon Sep 17 00:00:00 2001 From: Andrew Bradley Date: Tue, 1 Feb 2022 20:41:43 -0500 Subject: [PATCH 4/5] fix --- src/test/index.spec.ts | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/src/test/index.spec.ts b/src/test/index.spec.ts index 40f12ca59..114c44a62 100644 --- a/src/test/index.spec.ts +++ b/src/test/index.spec.ts @@ -889,7 +889,7 @@ test.suite('ts-node', (test) => { }); if (semver.gte(ts.version, '3.2.0')) { - test('--show-config should log resolved configuration', async (t) => { + test('--showConfig should log resolved configuration', async (t) => { function native(path: string) { return path.replace(/\/|\\/g, pathSep); } @@ -908,7 +908,6 @@ test.suite('ts-node', (test) => { cwd: native(`${ROOT_DIR}/tests`), projectSearchDir: native(`${ROOT_DIR}/tests`), project: native(`${ROOT_DIR}/tests/tsconfig.json`), - require: [], }, compilerOptions: { target: 'es6', From 6cd21e036b1904df4d236667dde0b7d3bc04f2bf Mon Sep 17 00:00:00 2001 From: Andrew Bradley Date: Tue, 1 Feb 2022 21:57:05 -0500 Subject: [PATCH 5/5] Update index.spec.ts --- src/test/index.spec.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/test/index.spec.ts b/src/test/index.spec.ts index 114c44a62..fb7870bc2 100644 --- a/src/test/index.spec.ts +++ b/src/test/index.spec.ts @@ -937,7 +937,7 @@ test.suite('ts-node', (test) => { `${CMD_TS_NODE_WITH_PROJECT_FLAG} --showConfig` ); expect(err).not.toBe(null); - expect(stderr).toMatch('Error: --show-config requires'); + expect(stderr).toMatch('Error: --showConfig requires'); }); }