Comparing version 3.0.0-beta3 to 3.0.0-rc1
@@ -19,3 +19,3 @@ "use strict"; | ||
const { packageDir, version } = tsPackage; | ||
targetModuleNames !== null && targetModuleNames !== void 0 ? targetModuleNames : (targetModuleNames = tsPackage.moduleNames); | ||
targetModuleNames ?? (targetModuleNames = tsPackage.moduleNames); | ||
/* Check Modules */ | ||
@@ -22,0 +22,0 @@ log(`Checking TypeScript ${chalk_1.default.blueBright(`v${version}`)} installation in ${chalk_1.default.blueBright(packageDir)}\r\n`); |
@@ -9,3 +9,3 @@ #!/usr/bin/env node | ||
if (require.main === module) { | ||
require('../lib/tsc'); | ||
require('../compiler/tsc'); | ||
} | ||
@@ -12,0 +12,0 @@ else { |
@@ -45,5 +45,4 @@ "use strict"; | ||
function run(opt) { | ||
var _a, _b; | ||
/* Parse Input */ | ||
const args = (0, minimist_1.default)((_b = (_a = opt === null || opt === void 0 ? void 0 : opt.cmdArgs) === null || _a === void 0 ? void 0 : _a.split(' ')) !== null && _b !== void 0 ? _b : process.argv.slice(2)); | ||
const args = (0, minimist_1.default)(opt?.cmdArgs?.split(' ') ?? process.argv.slice(2)); | ||
const cliOptions = (0, options_1.getCliOptions)(args); | ||
@@ -53,3 +52,3 @@ const cmd = (0, commands_1.getCliCommand)(args); | ||
const options = (0, options_1.getInstallerOptionsFromCliOptions)(cliOptions); | ||
const log = (0, system_1.createLogger)(options.logLevel, options.useColor); | ||
const log = (0, system_1.createLogger)(options.logLevel, options.useColor, options.silent); | ||
try { | ||
@@ -56,0 +55,0 @@ /* Handle commands */ |
@@ -33,3 +33,2 @@ "use strict"; | ||
function getCliCommand(args) { | ||
var _a; | ||
let cmd = args._[0] ? args._[0].toLowerCase() : void 0; | ||
@@ -44,5 +43,5 @@ /* Handle special cases */ | ||
/* Get long command */ | ||
cmd = (_a = Object | ||
cmd = Object | ||
.entries(exports.cliCommandsConfig) | ||
.find(([long, { short }]) => long === cmd || short === cmd)) === null || _a === void 0 ? void 0 : _a[0]; | ||
.find(([long, { short }]) => long === cmd || short === cmd)?.[0]; | ||
return cmd; | ||
@@ -49,0 +48,0 @@ } |
@@ -16,3 +16,3 @@ "use strict"; | ||
*/ | ||
// TODO - This logic should not be present in dist | ||
// TODO - This should be improved at some point | ||
exports.appRoot = (() => { | ||
@@ -19,0 +19,0 @@ const moduleDir = __dirname; |
@@ -11,6 +11,5 @@ "use strict"; | ||
function getModuleSource(tsModule) { | ||
var _a; | ||
const moduleFile = tsModule.getUnpatchedModuleFile(); | ||
const { firstSourceFileStart, fileEnd, wrapperPos, bodyPos, sourceFileStarts } = (0, module_slice_1.sliceModule)(moduleFile, tsModule.package.version); | ||
const fileHeaderEnd = (_a = wrapperPos === null || wrapperPos === void 0 ? void 0 : wrapperPos.start) !== null && _a !== void 0 ? _a : firstSourceFileStart; | ||
const fileHeaderEnd = wrapperPos?.start ?? firstSourceFileStart; | ||
return { | ||
@@ -20,4 +19,3 @@ fileHeader: (0, source_section_1.createSourceSection)(moduleFile, 'file-header', 0, fileHeaderEnd), | ||
body: sourceFileStarts.map(([srcFileName, startPos], i) => { | ||
var _a, _b, _c; | ||
const endPos = (_c = (_b = (_a = sourceFileStarts[i + 1]) === null || _a === void 0 ? void 0 : _a[1]) !== null && _b !== void 0 ? _b : bodyPos === null || bodyPos === void 0 ? void 0 : bodyPos.end) !== null && _c !== void 0 ? _c : fileEnd; | ||
const endPos = sourceFileStarts[i + 1]?.[1] ?? bodyPos?.end ?? fileEnd; | ||
return (0, source_section_1.createSourceSection)(moduleFile, 'body', startPos, endPos, wrapperPos != null ? 2 : 0, srcFileName); | ||
@@ -24,0 +22,0 @@ }), |
@@ -26,3 +26,3 @@ "use strict"; | ||
get sourceText() { | ||
return sourceText !== null && sourceText !== void 0 ? sourceText : (sourceText = moduleFile.content.slice(startPos, endPos)); | ||
return sourceText ?? (sourceText = moduleFile.content.slice(startPos, endPos)); | ||
}, | ||
@@ -43,3 +43,3 @@ getSourceFile() { | ||
getOriginalSourceFile() { | ||
originalSourceFile !== null && originalSourceFile !== void 0 ? originalSourceFile : (originalSourceFile = createSourceFile(this)); | ||
originalSourceFile ?? (originalSourceFile = createSourceFile(this)); | ||
return originalSourceFile; | ||
@@ -56,3 +56,3 @@ }, | ||
return this.sourceText; | ||
printer !== null && printer !== void 0 ? printer : (printer = typescript_1.default.createPrinter()); | ||
printer ?? (printer = typescript_1.default.createPrinter()); | ||
return printer.printFile(this.getSourceFile()); | ||
@@ -59,0 +59,0 @@ } |
@@ -21,4 +21,3 @@ "use strict"; | ||
function getTsModule(tsPackage, moduleNameOrModuleFile, options) { | ||
var _a; | ||
const skipCache = options === null || options === void 0 ? void 0 : options.skipCache; | ||
const skipCache = options?.skipCache; | ||
/* Get Module File */ | ||
@@ -49,3 +48,3 @@ let moduleFile; | ||
/* Get Cache Paths */ | ||
const cacheKey = ((_a = moduleFile.patchDetail) === null || _a === void 0 ? void 0 : _a.originalHash) || moduleFile.getHash(); | ||
const cacheKey = moduleFile.patchDetail?.originalHash || moduleFile.getHash(); | ||
const backupCachePaths = { | ||
@@ -52,0 +51,0 @@ js: (0, system_1.getCachePath)(cacheKey, moduleName), |
@@ -23,3 +23,2 @@ "use strict"; | ||
function getInstallerOptions(options) { | ||
var _a; | ||
if (!options && typeof options === "object" && Object.isSealed(options)) | ||
@@ -30,3 +29,3 @@ return options; | ||
...res, | ||
logger: (_a = res.logger) !== null && _a !== void 0 ? _a : (0, system_1.createLogger)(res.logLevel, res.useColor) | ||
logger: res.logger ?? (0, system_1.createLogger)(res.logLevel, res.useColor, res.silent) | ||
}); | ||
@@ -33,0 +32,0 @@ } |
{ | ||
"name": "ts-patch", | ||
"version": "3.0.0-beta3", | ||
"version": "3.0.0-rc1", | ||
"description": "Patch typescript to support custom transformers in tsconfig.json", | ||
@@ -5,0 +5,0 @@ "main": "./index.js", |
@@ -12,2 +12,3 @@ "use strict"; | ||
const fs_1 = __importDefault(require("fs")); | ||
const module_1 = require("../module"); | ||
const patch_module_1 = require("./patch-module"); | ||
@@ -19,3 +20,2 @@ // endregion | ||
function getPatchedSource(tsModule, options) { | ||
var _a; | ||
const { backupCachePaths, patchedCachePaths } = tsModule; | ||
@@ -27,7 +27,7 @@ const { log, skipCache } = options || {}; | ||
const srcPath = key === 'dts' ? tsModule.dtsPath : tsModule.modulePath; | ||
if (key === 'dts' && (options === null || options === void 0 ? void 0 : options.skipDts)) | ||
if (key === 'dts' && options?.skipDts) | ||
continue; | ||
if (!srcPath) | ||
continue; | ||
log === null || log === void 0 ? void 0 : log(['~', `Writing backup cache to ${chalk_1.default.blueBright(backupPath)}`], system_1.LogLevel.verbose); | ||
log?.(['~', `Writing backup cache to ${chalk_1.default.blueBright(backupPath)}`], system_1.LogLevel.verbose); | ||
const cacheDir = path_1.default.dirname(backupPath); | ||
@@ -40,5 +40,6 @@ (0, utils_1.mkdirIfNotExist)(cacheDir); | ||
const canUseCache = !skipCache | ||
&& !((_a = tsModule.moduleFile.patchDetail) === null || _a === void 0 ? void 0 : _a.isOutdated) | ||
&& !tsModule.moduleFile.patchDetail?.isOutdated | ||
&& (!patchedCachePaths.dts || fs_1.default.existsSync(patchedCachePaths.dts)) | ||
&& fs_1.default.existsSync(patchedCachePaths.js); | ||
&& fs_1.default.existsSync(patchedCachePaths.js) | ||
&& !(0, module_1.getModuleFile)(patchedCachePaths.js).patchDetail?.isOutdated; | ||
let js; | ||
@@ -48,6 +49,6 @@ let dts; | ||
js = (0, utils_1.readFileWithLock)(patchedCachePaths.js); | ||
dts = !(options === null || options === void 0 ? void 0 : options.skipDts) && patchedCachePaths.dts ? (0, utils_1.readFileWithLock)(patchedCachePaths.dts) : undefined; | ||
dts = !options?.skipDts && patchedCachePaths.dts ? (0, utils_1.readFileWithLock)(patchedCachePaths.dts) : undefined; | ||
} | ||
else { | ||
const res = (0, patch_module_1.patchModule)(tsModule, options === null || options === void 0 ? void 0 : options.skipDts); | ||
const res = (0, patch_module_1.patchModule)(tsModule, options?.skipDts); | ||
js = res.js; | ||
@@ -60,7 +61,7 @@ dts = res.dts; | ||
const srcPath = key === 'dts' ? dts : js; | ||
if (key === 'dts' && (options === null || options === void 0 ? void 0 : options.skipDts)) | ||
if (key === 'dts' && options?.skipDts) | ||
continue; | ||
if (!srcPath) | ||
continue; | ||
log === null || log === void 0 ? void 0 : log(['~', `Writing patched cache to ${chalk_1.default.blueBright(patchPath)}`], system_1.LogLevel.verbose); | ||
log?.(['~', `Writing patched cache to ${chalk_1.default.blueBright(patchPath)}`], system_1.LogLevel.verbose); | ||
(0, utils_1.mkdirIfNotExist)(cacheDir); | ||
@@ -67,0 +68,0 @@ (0, utils_1.writeFileWithLock)(patchPath, srcPath); |
@@ -22,4 +22,3 @@ "use strict"; | ||
function visitNode(node) { | ||
var _a; | ||
if (typescript_1.default.isFunctionDeclaration(node) && ((_a = node.name) === null || _a === void 0 ? void 0 : _a.getText()) === 'createProgram') { | ||
if (typescript_1.default.isFunctionDeclaration(node) && node.name?.getText() === 'createProgram') { | ||
const originalCreateProgram = factory.updateFunctionDeclaration(node, node.modifiers, node.asteriskToken, factory.createIdentifier('originalCreateProgram'), node.typeParameters, node.parameters, node.type, node.body); | ||
@@ -26,0 +25,0 @@ // function createProgram() { return tsp.originalCreateProgram(...arguments); } |
@@ -24,2 +24,6 @@ /** | ||
/** | ||
* Is the transformer an ES Module | ||
*/ | ||
isEsm?: boolean; | ||
/** | ||
* Plugin entry point format type, default is program | ||
@@ -26,0 +30,0 @@ */ |
@@ -8,2 +8,3 @@ declare namespace ts { | ||
import?: string; | ||
isEsm?: boolean; | ||
type?: 'ls' | 'program' | 'config' | 'checker' | 'raw' | 'compilerOptions'; | ||
@@ -10,0 +11,0 @@ after?: boolean; |
@@ -14,4 +14,4 @@ var tsp = (function () { | ||
if (configFilePath === undefined) { | ||
const baseDir = (rootFileNames.length > 0) ? dirname(rootFileNames[0]) : projectDir !== null && projectDir !== void 0 ? projectDir : process.cwd(); | ||
configFilePath = tsp.shim.findConfigFile(baseDir, tsp.shim.sys.fileExists); | ||
const baseDir = (rootFileNames.length > 0) ? dirname(rootFileNames[0]) : projectDir ?? process.cwd(); | ||
configFilePath = tsp.tsShim.findConfigFile(baseDir, tsp.tsShim.sys.fileExists); | ||
if (configFilePath) { | ||
@@ -27,6 +27,6 @@ const config = readConfig(configFilePath); | ||
const projectDir = dirname(configFileNamePath); | ||
const result = tsp.shim.readConfigFile(configFileNamePath, tsp.shim.sys.readFile); | ||
const result = tsp.tsShim.readConfigFile(configFileNamePath, tsp.tsShim.sys.readFile); | ||
if (result.error) | ||
throw new Error("Error in tsconfig.json: " + result.error.messageText); | ||
return tsp.shim.parseJsonConfigFileContent(result.config, tsp.shim.sys, projectDir, undefined, configFileNamePath); | ||
return tsp.tsShim.parseJsonConfigFileContent(result.config, tsp.tsShim.sys, projectDir, undefined, configFileNamePath); | ||
} | ||
@@ -46,3 +46,2 @@ function preparePluginsFromCompilerOptions(plugins) { | ||
function createProgram(rootNamesOrOptions, options, host, oldProgram, configFileParsingDiagnostics) { | ||
var _a; | ||
let rootNames; | ||
@@ -68,6 +67,6 @@ const createOpts = !Array.isArray(rootNamesOrOptions) ? rootNamesOrOptions : void 0; | ||
let program = createOpts ? | ||
tsp.shim.originalCreateProgram(createOpts) : | ||
tsp.shim.originalCreateProgram(rootNames, options, host, oldProgram, configFileParsingDiagnostics); | ||
tsp.tsShim.originalCreateProgram(createOpts) : | ||
tsp.tsShim.originalCreateProgram(rootNames, options, host, oldProgram, configFileParsingDiagnostics); | ||
const plugins = preparePluginsFromCompilerOptions(options.plugins); | ||
const pluginCreator = new tsp.PluginCreator(plugins, (_a = projectConfig.projectDir) !== null && _a !== void 0 ? _a : process.cwd()); | ||
const pluginCreator = new tsp.PluginCreator(plugins, projectConfig.projectDir ?? process.cwd()); | ||
const programTransformers = new Map(pluginCreator.getProgramTransformers()); | ||
@@ -82,3 +81,3 @@ for (const [transformer] of pluginCreator.getProgramTransformers()) { | ||
const newProgram = programTransformer(program, host, config, { ts: ts }); | ||
if (typeof (newProgram === null || newProgram === void 0 ? void 0 : newProgram["emit"]) === "function") | ||
if (typeof newProgram?.["emit"] === "function") | ||
program = newProgram; | ||
@@ -105,5 +104,33 @@ } | ||
(function (tsp) { | ||
const path = require("path"); | ||
let tsNodeIncluded = false; | ||
const requireStack = []; | ||
tsp.diagnosticMap = new WeakMap(); | ||
tsp.supportedExtensions = [".ts", ".mts", ".cts", ".js", ".mjs", ".cjs"]; | ||
tsp.tsExtensions = [".ts", ".mts", ".cts"]; | ||
function diagnosticExtrasFactory(program) { | ||
const diagnostics = tsp.diagnosticMap.get(program) || tsp.diagnosticMap.set(program, []).get(program); | ||
const addDiagnostic = (diag) => diagnostics.push(diag); | ||
const removeDiagnostic = (index) => { diagnostics.splice(index, 1); }; | ||
return { addDiagnostic, removeDiagnostic, diagnostics }; | ||
} | ||
tsp.diagnosticExtrasFactory = diagnosticExtrasFactory; | ||
})(tsp || (tsp = {})); | ||
var tsp; | ||
(function (tsp) { | ||
tsp.tsShim = new Proxy({}, { | ||
get(_, key) { | ||
if (ts) { | ||
return ts[key]; | ||
} | ||
else { | ||
try { | ||
return eval(key); | ||
} | ||
catch (e) { | ||
return undefined; | ||
} | ||
} | ||
}, | ||
}); | ||
})(tsp || (tsp = {})); | ||
var tsp; | ||
(function (tsp) { | ||
class PluginCreator { | ||
@@ -134,3 +161,3 @@ constructor(configs, resolveBaseDir = process.cwd()) { | ||
continue; | ||
const factory = this.resolveFactory(config); | ||
const factory = tsp.resolveFactory(this, config); | ||
if (factory === undefined) | ||
@@ -149,3 +176,3 @@ continue; | ||
continue; | ||
const factory = this.resolveFactory(config); | ||
const factory = tsp.resolveFactory(this, config); | ||
if (factory === undefined) | ||
@@ -157,71 +184,2 @@ continue; | ||
} | ||
resolveFactory(config) { | ||
var _a; | ||
const tsConfig = config.tsConfig && path.resolve(this.resolveBaseDir, config.tsConfig); | ||
const transform = config.transform; | ||
const importKey = config.import || "default"; | ||
let tsConfigCleanup; | ||
if (transform.match(/\.ts$/)) { | ||
if (tsNodeIncluded && (tsConfig !== this.currentProject)) | ||
tsNodeIncluded = false; | ||
this.currentProject = tsConfig; | ||
if (!tsNodeIncluded) { | ||
try { | ||
require("ts-node").register({ | ||
transpileOnly: true, | ||
...(tsConfig ? { project: tsConfig } : { skipProject: true }), | ||
compilerOptions: { | ||
target: "ES2018", | ||
jsx: "react", | ||
esModuleInterop: true, | ||
module: "commonjs", | ||
} | ||
}); | ||
tsNodeIncluded = true; | ||
} | ||
catch (e) { | ||
if (e.code === "MODULE_NOT_FOUND") | ||
throw new Error(`Cannot use a typescript-based transformer without ts-node installed. ` + | ||
`Either add ts-node as a (dev)-dependency or install globally.`); | ||
else | ||
throw e; | ||
} | ||
} | ||
const tsConfigData = tsConfig && tsp.shim.readConfigFile(tsConfig, tsp.shim.sys.readFile).config; | ||
if ((_a = tsConfigData === null || tsConfigData === void 0 ? void 0 : tsConfigData.compilerOptions) === null || _a === void 0 ? void 0 : _a.paths) { | ||
try { | ||
const tsConfigPaths = require("tsconfig-paths"); | ||
const { absoluteBaseUrl } = tsConfigPaths.loadConfig(tsConfig); | ||
tsConfigCleanup = tsConfigPaths.register({ | ||
baseUrl: absoluteBaseUrl, | ||
paths: tsConfigData.compilerOptions.paths | ||
}); | ||
} | ||
catch (e) { | ||
if (e.code === "MODULE_NOT_FOUND") | ||
console.warn(`Paths specified in transformer tsconfig.json, but they may not be able to be resolved. ` + | ||
`If not, try adding 'tsconfig-paths' as a dev dependency`); | ||
else | ||
throw e; | ||
} | ||
} | ||
} | ||
const modulePath = require.resolve(transform, { paths: [this.resolveBaseDir] }); | ||
if (requireStack.indexOf(modulePath) > -1) | ||
return; | ||
requireStack.push(modulePath); | ||
const commonjsModule = require(modulePath); | ||
requireStack.pop(); | ||
tsConfigCleanup === null || tsConfigCleanup === void 0 ? void 0 : tsConfigCleanup(); | ||
const factoryModule = (typeof commonjsModule === "function") ? { default: commonjsModule } : commonjsModule; | ||
const factory = factoryModule[importKey]; | ||
if (!factory) | ||
throw new Error(`tsconfig.json > plugins: "${transform}" does not have an export "${importKey}": ` + | ||
require("util").inspect(factoryModule)); | ||
if (typeof factory !== "function") { | ||
throw new Error(`tsconfig.json > plugins: "${transform}" export "${importKey}" is not a plugin: ` + | ||
require("util").inspect(factory)); | ||
} | ||
return factory; | ||
} | ||
static validateConfigs(configs) { | ||
@@ -280,23 +238,160 @@ for (const config of configs) | ||
(function (tsp) { | ||
tsp.diagnosticMap = new WeakMap(); | ||
function diagnosticExtrasFactory(program) { | ||
const diagnostics = tsp.diagnosticMap.get(program) || tsp.diagnosticMap.set(program, []).get(program); | ||
const addDiagnostic = (diag) => diagnostics.push(diag); | ||
const removeDiagnostic = (index) => { diagnostics.splice(index, 1); }; | ||
return { addDiagnostic, removeDiagnostic, diagnostics }; | ||
const requireStack = []; | ||
const path = require("path"); | ||
const crypto = require("crypto"); | ||
function resolveFactory(pluginCreator, config) { | ||
let originalRequire; | ||
let requireHooked = false; | ||
let compilerOptions; | ||
let moduleResolutionCache; | ||
const tsConfig = config.tsConfig && path.resolve(pluginCreator.resolveBaseDir, config.tsConfig); | ||
const transform = config.transform; | ||
const importKey = config.import || "default"; | ||
const builtFiles = new Map(); | ||
const transformerPath = require.resolve(transform, { paths: [pluginCreator.resolveBaseDir] }); | ||
if (requireStack.includes(transformerPath)) | ||
return; | ||
requireStack.push(transformerPath); | ||
try { | ||
let isEsm = config.isEsm; | ||
if (isEsm == null) { | ||
const impliedModuleFormat = tsp.tsShim.getImpliedNodeFormatForFile(transformerPath, undefined, tsp.tsShim.sys, { moduleResolution: tsp.tsShim.ModuleResolutionKind.Node16 }); | ||
isEsm = impliedModuleFormat === tsp.tsShim.ModuleKind.ESNext; | ||
} | ||
hookRequire(isEsm, builtFiles); | ||
if (transform.match(/\.[mc]?ts$/)) { | ||
const configFile = tsConfig && tsp.tsShim.readConfigFile(tsConfig, tsp.tsShim.sys.readFile); | ||
const parsedConfigFile = configFile && tsp.tsShim.parseJsonConfigFileContent(configFile.config, tsp.tsShim.sys, path.dirname(tsConfig)); | ||
compilerOptions = parsedConfigFile?.options; | ||
compilerOptions ?? (compilerOptions = {}); | ||
compilerOptions.target = tsp.tsShim.ScriptTarget.ES2020; | ||
compilerOptions.module = isEsm ? tsp.tsShim.ModuleKind.ESNext : tsp.tsShim.ModuleKind.CommonJS; | ||
compilerOptions.noEmit = false; | ||
compilerOptions.outDir = undefined; | ||
compilerOptions.declarations = false; | ||
compilerOptions.isolatedModules = true; | ||
compilerOptions.allowNonTsExtensions = true; | ||
compilerOptions.suppressOutputPathCheck = true; | ||
compilerOptions.inlineSourceMap = true; | ||
compilerOptions = tsp.tsShim.fixupCompilerOptions(compilerOptions); | ||
moduleResolutionCache = tsp.tsShim.createModuleResolutionCache(pluginCreator.resolveBaseDir, tsp.tsShim.sys.realpath ?? (tsp.tsShim.sys.useCaseSensitiveFileNames | ||
? (x) => x | ||
: tsp.tsShim.sys.getCanonicalFileName)); | ||
const program = tsp.tsShim.createProgram([transformerPath], compilerOptions); | ||
const emitResult = program.emit(undefined, (fileName, data) => { | ||
builtFiles.set(getCachePath(fileName), data); | ||
}); | ||
const allDiagnostics = tsp.tsShim.getPreEmitDiagnostics(program).concat(emitResult.diagnostics); | ||
allDiagnostics.forEach(diagnostic => { | ||
if (diagnostic.file) { | ||
const { line, character } = diagnostic.file.getLineAndCharacterOfPosition(diagnostic.start); | ||
const message = tsp.tsShim.flattenDiagnosticMessageText(diagnostic.messageText, "\n"); | ||
console.error(`${diagnostic.file.fileName} (${line + 1},${character + 1}): ${message}`); | ||
} | ||
else { | ||
console.error(tsp.tsShim.flattenDiagnosticMessageText(diagnostic.messageText, "\n")); | ||
} | ||
}); | ||
if (emitResult.emitSkipped) { | ||
console.error("Failed to compile transformer!"); | ||
process.exit(1); | ||
} | ||
} | ||
let commonjsModule = require(transformerPath); | ||
const factoryModule = (typeof commonjsModule === "function") ? { default: commonjsModule } : commonjsModule; | ||
const factory = factoryModule[importKey]; | ||
if (!factory) | ||
throw new Error(`tsconfig.json > plugins: "${transform}" does not have an export "${importKey}": ` + | ||
require("util").inspect(factoryModule)); | ||
if (typeof factory !== "function") { | ||
throw new Error(`tsconfig.json > plugins: "${transform}" export "${importKey}" is not a plugin: ` + | ||
require("util").inspect(factory)); | ||
} | ||
return factory; | ||
} | ||
finally { | ||
requireStack.pop(); | ||
} | ||
function requireCustom(ctx, request, onNotFound) { | ||
let res; | ||
try { | ||
res = originalRequire.call(ctx, request); | ||
} | ||
catch (error) { | ||
if (error.code === "MODULE_NOT_FOUND") | ||
throw onNotFound(error); | ||
throw error; | ||
} | ||
return res; | ||
} | ||
function resolveMappedPath(moduleName, containingFile) { | ||
const resolved = tsp.tsShim.resolveModuleName(moduleName, containingFile, compilerOptions, tsp.tsShim.sys, moduleResolutionCache); | ||
const res = resolved.resolvedModule?.resolvedFileName || undefined; | ||
return res; | ||
} | ||
function hookRequire(isEsm, builtFiles) { | ||
const fs = require("fs"); | ||
const os = require("os"); | ||
const Module = require("module"); | ||
originalRequire = Module.prototype.require; | ||
Module.prototype.require = function (request) { | ||
const resolvedPath = compilerOptions?.paths | ||
&& !process.env.TSP_IGNORE_PATH_ALIASES | ||
&& resolveMappedPath(request, this.filename); | ||
if (resolvedPath) | ||
request = resolvedPath; | ||
const filePath = Module._resolveFilename(request, this); | ||
const extension = path.extname(filePath); | ||
if (!tsp.supportedExtensions.includes(extension)) | ||
return originalRequire.call(this, request); | ||
const cacheKey = getCachePath(filePath); | ||
const isBuiltFile = builtFiles.has(cacheKey); | ||
const code = isBuiltFile ? builtFiles.get(cacheKey) : fs.readFileSync(filePath, "utf8"); | ||
let requireFilePath = filePath; | ||
if (isBuiltFile) { | ||
const extName = extension === ".mts" ? ".ts" : extension; | ||
let tempFilename = path.join(os.tmpdir(), crypto.randomBytes(16).toString("hex") + extName); | ||
fs.writeFileSync(tempFilename, code, "utf8"); | ||
requireFilePath = tempFilename; | ||
} | ||
try { | ||
return isEsm ? requireEsm.call(this, requireFilePath, filePath) : requireCjs.call(this, requireFilePath); | ||
} | ||
catch (error) { | ||
if (error.code === "ERR_REQUIRE_ESM") { | ||
return requireEsm.call(this, requireFilePath, filePath); | ||
} | ||
else { | ||
throw error; | ||
} | ||
} | ||
finally { | ||
if (isBuiltFile) | ||
try { | ||
fs.unlinkSync(requireFilePath); | ||
} | ||
catch { } | ||
} | ||
function requireCjs(requireFilePath) { | ||
return originalRequire.call(this, requireFilePath); | ||
} | ||
function requireEsm(requireFilePath, filePath) { | ||
const esm = requireCustom(this, "esm", () => new Error(`The transformer "${request}" is an esm file. Add "esm" to your dependencies to enable esm transformers.`)); | ||
const newModule = new Module(request, this); | ||
newModule.filename = filePath; | ||
newModule.paths = Module._nodeModulePaths(filePath); | ||
return esm(newModule)(requireFilePath); | ||
} | ||
}; | ||
requireHooked = true; | ||
} | ||
function getCachePath(filePath) { | ||
const basedir = path.dirname(filePath); | ||
const basename = path.basename(filePath, path.extname(filePath)); | ||
return tsp.tsShim.normalizePath(path.join(basedir, basename)); | ||
} | ||
} | ||
tsp.diagnosticExtrasFactory = diagnosticExtrasFactory; | ||
tsp.resolveFactory = resolveFactory; | ||
})(tsp || (tsp = {})); | ||
var tsp; | ||
(function (tsp) { | ||
tsp.shim = { | ||
get createProgram() { var _a; return (_a = ts.createProgram) !== null && _a !== void 0 ? _a : createProgram; }, | ||
get originalCreateProgram() { var _a; return (_a = ts.originalCreateProgram) !== null && _a !== void 0 ? _a : originalCreateProgram; }, | ||
get findConfigFile() { var _a; return (_a = ts.findConfigFile) !== null && _a !== void 0 ? _a : findConfigFile; }, | ||
get readConfigFile() { var _a; return (_a = ts.readConfigFile) !== null && _a !== void 0 ? _a : readConfigFile; }, | ||
get parseJsonConfigFileContent() { var _a; return (_a = ts.parseJsonConfigFileContent) !== null && _a !== void 0 ? _a : parseJsonConfigFileContent; }, | ||
get sys() { var _a; return (_a = ts.sys) !== null && _a !== void 0 ? _a : sys; }, | ||
}; | ||
})(tsp || (tsp = {})); | ||
return tsp; | ||
})(); |
@@ -19,3 +19,3 @@ "use strict"; | ||
const firstMatch = matcher.exec(content); | ||
if (!(firstMatch === null || firstMatch === void 0 ? void 0 : firstMatch[0])) | ||
if (!firstMatch?.[0]) | ||
throw module_slice_1.ModuleSlice.createError(); | ||
@@ -30,3 +30,3 @@ /* Handle wrapped */ | ||
const firstFileMatch = matcher.exec(content); | ||
if (!(firstFileMatch === null || firstFileMatch === void 0 ? void 0 : firstFileMatch[0])) | ||
if (!firstFileMatch?.[0]) | ||
throw module_slice_1.ModuleSlice.createError(); | ||
@@ -38,3 +38,3 @@ firstSourceFileStart = firstFileMatch.index; | ||
const wrapperEndMatch = matcher.exec(content); | ||
if (!(wrapperEndMatch === null || wrapperEndMatch === void 0 ? void 0 : wrapperEndMatch[0])) | ||
if (!wrapperEndMatch?.[0]) | ||
throw module_slice_1.ModuleSlice.createError(); | ||
@@ -41,0 +41,0 @@ bodyEnd = wrapperEndMatch.index - 1; |
@@ -7,2 +7,2 @@ export declare enum LogLevel { | ||
export type Logger = (msg: string | [string, string], logLevel?: LogLevel) => void; | ||
export declare function createLogger(logLevel: LogLevel, useColour?: boolean): (msg: string | [string, string], msgLogLevel?: LogLevel) => void; | ||
export declare function createLogger(logLevel: LogLevel, useColour?: boolean, isSilent?: boolean): Logger; |
@@ -22,5 +22,5 @@ "use strict"; | ||
/* ****************************************************************************************************************** */ | ||
function createLogger(logLevel, useColour = true) { | ||
function createLogger(logLevel, useColour = true, isSilent = false) { | ||
return function log(msg, msgLogLevel = LogLevel.normal) { | ||
if (msgLogLevel > logLevel) | ||
if (isSilent || msgLogLevel > logLevel) | ||
return; | ||
@@ -27,0 +27,0 @@ /* Handle Icon */ |
@@ -28,3 +28,3 @@ "use strict"; | ||
} | ||
catch (_a) { | ||
catch { | ||
break; | ||
@@ -31,0 +31,0 @@ } |
@@ -36,3 +36,3 @@ "use strict"; | ||
} | ||
catch (_a) { | ||
catch { | ||
return false; | ||
@@ -39,0 +39,0 @@ } |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
Deprecated
MaintenanceThe maintainer of the package marked it as deprecated. This could indicate that a single version should not be used, or that the package is no longer maintained and any new vulnerabilities will not be fixed.
Found 1 instance in 1 package
Uses eval
Supply chain riskPackage uses eval() which is a dangerous function. This prevents the code from running in certain environments and increases the risk that the code may contain exploits or malicious behavior.
Found 1 instance in 1 package
Debug access
Supply chain riskUses debug, reflection and dynamic code execution features.
Found 1 instance in 1 package
Dynamic require
Supply chain riskDynamic require can indicate the package is performing dangerous or unsafe dynamic code execution.
Found 1 instance in 1 package
Environment variable access
Supply chain riskPackage accesses environment variables, which may be a sign of credential stuffing or data theft.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
Dynamic require
Supply chain riskDynamic require can indicate the package is performing dangerous or unsafe dynamic code execution.
Found 1 instance in 1 package
273085
144
3180
1
29
1