|
1 | 1 | #!/usr/bin/env node
|
2 | 2 |
|
3 |
| -import { join, resolve, dirname, parse as parsePath } from 'path'; |
| 3 | +import { join, resolve, dirname, parse as parsePath, relative } from 'path'; |
4 | 4 | import { inspect } from 'util';
|
5 | 5 | import Module = require('module');
|
6 | 6 | import arg = require('arg');
|
@@ -331,13 +331,31 @@ Options:
|
331 | 331 | const ts = service.ts as any as TSInternal;
|
332 | 332 | if (typeof ts.convertToTSConfig !== 'function') {
|
333 | 333 | console.error(
|
334 |
| - 'Error: --show-config requires a typescript versions >=3.2 that support --showConfig' |
| 334 | + 'Error: --showConfig requires a typescript versions >=3.2 that support --showConfig' |
335 | 335 | );
|
336 | 336 | process.exit(1);
|
337 | 337 | }
|
| 338 | + let moduleTypes = undefined; |
| 339 | + if (service.options.moduleTypes) { |
| 340 | + // Assumption: this codepath requires CLI invocation, so moduleTypes must have come from a tsconfig, not API. |
| 341 | + const showRelativeTo = dirname(service.configFilePath!); |
| 342 | + moduleTypes = {} as Record<string, string>; |
| 343 | + for (const [key, value] of Object.entries(service.options.moduleTypes)) { |
| 344 | + moduleTypes[ |
| 345 | + relative( |
| 346 | + showRelativeTo, |
| 347 | + resolve(service.options.optionBasePaths?.moduleTypes!, key) |
| 348 | + ) |
| 349 | + ] = value; |
| 350 | + } |
| 351 | + } |
338 | 352 | const json = {
|
339 | 353 | ['ts-node']: {
|
340 | 354 | ...service.options,
|
| 355 | + require: service.options.require?.length |
| 356 | + ? service.options.require |
| 357 | + : undefined, |
| 358 | + moduleTypes, |
341 | 359 | optionBasePaths: undefined,
|
342 | 360 | compilerOptions: undefined,
|
343 | 361 | project: service.configFilePath ?? service.options.project,
|
|
0 commit comments