Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
compilerOptions.outDir = compilerOptions.outFile = undefined;
if (autoScriptTarget) {
const [nodeMajor] = process.versions.node.split('.'); // '12.0.0' => '12'
compilerOptions.target = nodeVersionToScriptTarget(Number(nodeMajor));
}
if (typeof cacheDirectoryPath !== 'string') {
// couldn't find a cache directory, so fall back to a non-caching implementation
return createTransformerExtension(
filePath =>
ts.transpileModule(readFileSync(filePath, 'utf8'), { fileName: filePath, compilerOptions }).outputText
);
}
const optionsScopedCachePath = join(cacheDirectoryPath, compilerOptionsToCacheName(compilerOptions));
try {
ensureDirectorySync(optionsScopedCachePath);
} catch {
/**/
}
if (installSourceMapSupport) {
sourceMapSupport.install({
environment: 'node',
retrieveSourceMap(filePath) {
const cacheFilePath = join(optionsScopedCachePath, filePathToCacheFileName(filePath));
const cachedOutput = readCacheFileSync(cacheFilePath);
if (cachedOutput && cachedOutput.mtime === statSync(filePath).mtime.getTime()) {
const { sourceMapText, outputText } = cachedOutput;
const map = sourceMapText || extractInlineSourceMap(outputText);
if (map) {
// we dont accept any user overrides of sourcemap configuration
// instead, we force external sourcemaps (with inline sources) on/off based on webpack signals.
compilerOptions.sourceMap = compilerOptions.inlineSources = sourceMap;
compilerOptions.inlineSourceMap = compilerOptions.mapRoot = compilerOptions.sourceRoot = undefined;
// force declarations off, as we don't have .d.ts bundling.
// output locations are irrelevant, as we bundle. this ensures source maps have proper relative paths.
// noEmit will not give us any output, so force that off.
compilerOptions.declaration = compilerOptions.declarationMap = undefined;
compilerOptions.outDir = compilerOptions.out = compilerOptions.outFile = undefined;
compilerOptions.noEmit = compilerOptions.noEmitOnError = compilerOptions.emitDeclarationOnly = undefined;
// caching
const optionsScopedCachePath = cacheDirectoryPath
? join(cacheDirectoryPath, compilerOptionsToCacheName(compilerOptions))
: undefined;
if (optionsScopedCachePath && !ensuredDirectories.has(optionsScopedCachePath)) {
try {
ensureDirectorySync(optionsScopedCachePath);
} catch {
/**/
}
ensuredDirectories.add(optionsScopedCachePath);
}
const transpileOptions = {
fileName: resourcePath,
compilerOptions,
transformers,
reportDiagnostics: true