Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
configFilePath = configLookup ? ts.findConfigFile(contextPath, fileExists, configFileName) : undefined,
compilerOptions: noConfigOptions = defaultCompilerOptions,
cacheDirectoryPath = findCacheDirectory(contextPath),
installSourceMapSupport = !process.execArgv.includes('--enable-source-maps'),
autoScriptTarget = true
}: ICreateNodeExtensionOptions = {}): NodeExtension {
const formatDiagnosticsHost: ts.FormatDiagnosticsHost = {
getCurrentDirectory: () => contextPath,
getCanonicalFileName: getCanonicalPath,
getNewLine
};
const compilerOptions: ts.CompilerOptions = {};
if (typeof configFilePath === 'string') {
const { options, errors } = readAndParseConfigFile(configFilePath);
if (errors.length) {
throw new Error(ts.formatDiagnostics(errors, formatDiagnosticsHost));
}
Object.assign(compilerOptions, options);
if (compilerOptions.module !== ts.ModuleKind.CommonJS) {
// force commonjs, for node
compilerOptions.module = ts.ModuleKind.CommonJS;
}
} else {
Object.assign(compilerOptions, noConfigOptions);
}
// Ensure source maps get picked up by v8 inspector (vscode/chrome debuggers) and node's `--enable-source-maps`.
compilerOptions.inlineSourceMap = true;
compilerOptions.sourceMap = compilerOptions.inlineSources = undefined;
compilerOptions.mapRoot = compilerOptions.sourceRoot = undefined;
throw chalk.red(`Cannot find directory ${srcDirectoryPath}`);
}
const tsConfigPath = ts.findConfigFile(srcDirectoryPath, fileExists, configName);
if (!tsConfigPath) {
throw chalk.red(`Cannot find a ${configName} file for ${srcDirectoryPath}`);
}
const formatDiagnosticsHost: ts.FormatDiagnosticsHost = {
getCurrentDirectory,
getCanonicalFileName: getCanonicalPath,
getNewLine: getNewLine
};
const { errors, fileNames, options: tsconfigOptions } = readAndParseConfigFile(tsConfigPath);
if (errors.length) {
throw ts.formatDiagnosticsWithColorAndContext(errors, formatDiagnosticsHost);
}
const canonicalSrcPath = getCanonicalPath(srcDirectoryPath);
const filesInSrcDirectory = fileNames
.map(filePath => ({ filePath, normalizedPath: normalize(filePath) }))
.filter(({ normalizedPath }) => getCanonicalPath(normalizedPath).startsWith(canonicalSrcPath));
const programs: Array<{ folderName: string; program: ts.Program }> = [];
for (const { folderName, getCompilerOptions } of formats) {
const compilerOptions: ts.CompilerOptions = {
...getCompilerOptions(tsconfigOptions),
outDir: undefined,