Skip to content

Commit

Permalink
Rename trace to tsTrace to avoid hypothetical future collision with t…
Browse files Browse the repository at this point in the history
…s-node tracing flags (tracing ts-node behavior as opposed to tsc behavior); also pass trace option in compilerHost codepath
  • Loading branch information
cspotcode committed Nov 7, 2021
1 parent 9643f55 commit 260f274
Show file tree
Hide file tree
Showing 4 changed files with 18 additions and 17 deletions.
5 changes: 2 additions & 3 deletions src/configuration.ts
Original file line number Diff line number Diff line change
Expand Up @@ -94,6 +94,7 @@ export function readConfig(
readFile = ts.sys.readFile,
skipProject = DEFAULTS.skipProject,
project = DEFAULTS.project,
tsTrace = DEFAULTS.tsTrace,
} = rawApiOptions;

// Read project configuration when available.
Expand Down Expand Up @@ -137,7 +138,7 @@ export function readConfig(
readDirectory: ts.sys.readDirectory,
readFile,
useCaseSensitiveFileNames: ts.sys.useCaseSensitiveFileNames,
trace: rawApiOptions.trace,
trace: tsTrace,
},
bp,
errors,
Expand Down Expand Up @@ -276,7 +277,6 @@ function filterRecognizedTsConfigTsNodeOptions(
scopeDir,
moduleTypes,
experimentalReplAwait,
trace,
swc,
...unrecognized
} = jsonObject as TsConfigOptions;
Expand All @@ -300,7 +300,6 @@ function filterRecognizedTsConfigTsNodeOptions(
scope,
scopeDir,
moduleTypes,
trace,
swc,
};
// Use the typechecker to make sure this implementation has the correct set of properties
Expand Down
18 changes: 10 additions & 8 deletions src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -354,11 +354,11 @@ export interface CreateOptions {
*/
optionBasePaths?: OptionBasePaths;
/**
* A function to collect trace messages, for example when `traceResolution` is enabled.
* A function to collect trace messages from the TypeScript compiler, for example when `traceResolution` is enabled.
*
* @default console.log.bind(console)
* @default console.log
*/
trace?: (str: string) => void;
tsTrace?: (str: string) => void;
}

/** @internal */
Expand Down Expand Up @@ -395,6 +395,7 @@ export interface TsConfigOptions
| 'cwd'
| 'projectSearchDir'
| 'optionBasePaths'
| 'tsTrace'
> {}

/**
Expand Down Expand Up @@ -430,7 +431,7 @@ export const DEFAULTS: RegisterOptions = {
compilerHost: yn(env.TS_NODE_COMPILER_HOST),
logError: yn(env.TS_NODE_LOG_ERROR),
experimentalReplAwait: yn(env.TS_NODE_EXPERIMENTAL_REPL_AWAIT) ?? undefined,
trace: console.log.bind(console),
tsTrace: console.log.bind(console),
};

/**
Expand Down Expand Up @@ -890,7 +891,7 @@ export function create(rawOptions: CreateOptions = {}): Service {
getCompilationSettings: () => config.options,
getDefaultLibFileName: () => ts.getDefaultLibFilePath(config.options),
getCustomTransformers: getCustomTransformers,
trace: options.trace,
trace: options.tsTrace,
};
const {
resolveModuleNames,
Expand All @@ -899,7 +900,7 @@ export function create(rawOptions: CreateOptions = {}): Service {
isFileKnownToBeInternal,
markBucketOfFilenameInternal,
} = createResolverFunctions({
serviceHost,
host: serviceHost,
getCanonicalFileName,
ts,
cwd,
Expand Down Expand Up @@ -1044,13 +1045,14 @@ export function create(rawOptions: CreateOptions = {}): Service {
),
useCaseSensitiveFileNames: () => sys.useCaseSensitiveFileNames,
};
host.trace = options.tsTrace;
const {
resolveModuleNames,
resolveTypeReferenceDirectives,
isFileKnownToBeInternal,
markBucketOfFilenameInternal,
} = createResolverFunctions({
serviceHost: host,
host,
cwd,
configFilePath,
config,
Expand All @@ -1065,7 +1067,7 @@ export function create(rawOptions: CreateOptions = {}): Service {
? ts.createIncrementalProgram({
rootNames: Array.from(rootFileNames),
options: config.options,
host: host,
host,
configFileParsingDiagnostics: config.errors,
projectReferences: config.projectReferences,
})
Expand Down
10 changes: 5 additions & 5 deletions src/resolver-functions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,14 +7,14 @@ import type * as _ts from 'typescript';
*/
export function createResolverFunctions(kwargs: {
ts: typeof _ts;
serviceHost: _ts.ModuleResolutionHost;
host: _ts.ModuleResolutionHost;
cwd: string;
getCanonicalFileName: (filename: string) => string;
config: _ts.ParsedCommandLine;
configFilePath: string | undefined;
}) {
const {
serviceHost,
host,
ts,
config,
cwd,
Expand Down Expand Up @@ -93,7 +93,7 @@ export function createResolverFunctions(kwargs: {
moduleName,
containingFile,
config.options,
serviceHost,
host,
moduleResolutionCache,
redirectedReference
);
Expand Down Expand Up @@ -132,7 +132,7 @@ export function createResolverFunctions(kwargs: {
typeDirectiveName,
containingFile,
config.options,
serviceHost,
host,
redirectedReference
);
if (typeDirectiveName === 'node' && !resolvedTypeReferenceDirective) {
Expand All @@ -157,7 +157,7 @@ export function createResolverFunctions(kwargs: {
...config.options,
typeRoots,
},
serviceHost,
host,
redirectedReference
));
}
Expand Down
2 changes: 1 addition & 1 deletion src/test/repl/helpers.ts
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ export async function contextReplHelpers(
...replService.evalAwarePartialHost,
project: `${TEST_DIR}/tsconfig.json`,
...createServiceOpts,
trace: replService.console.log.bind(replService.console),
tsTrace: replService.console.log.bind(replService.console),
});
replService.setService(service);
t.teardown(async () => {
Expand Down

0 comments on commit 260f274

Please sign in to comment.