Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
const resolvePlugins = [];
// add TsconfigPathsPlugin to support `paths` resolution in tsconfig
// we need to catch here because the plugin will
// error if there's no tsconfig in the working directory
try {
const tsconfig = tsconfigPaths.loadConfig();
const fullTsconfig = require(tsconfig.configFileAbsolutePath)
const tsconfigPathsOptions = { silent: true }
if (fullTsconfig.compilerOptions.allowJs) {
tsconfigPathsOptions.extensions = SUPPORTED_EXTENSIONS
}
resolvePlugins.push(new TsconfigPathsPlugin(tsconfigPathsOptions));
if (tsconfig.resultType === "success") {
tsconfigMatchPath = tsconfigPaths.createMatchPath(tsconfig.absoluteBaseUrl, tsconfig.paths);
}
} catch (e) {}
resolvePlugins.push({
apply(resolver) {
const resolve = resolver.resolve;
resolver.resolve = function (context, path, request, resolveContext, callback) {
resolve.call(resolver, context, path, request, resolveContext, function (err, result) {
if (!err) return callback(null, result);
if (!err.missing || !err.missing.length)
return callback(err);
// make not found errors runtime errors
callback(null, __dirname + '/@@notfound.js' + '?' + (externalMap.get(request) || request));
});
};
}
registerHook = (addHook: AddHook, addFileResolver: AddFileResolver) => {
const matchPath = createMatchPath(
this.absoluteBaseUrl,
this.config.compilerOptions.paths || {},
);
addHook(this.compile, { exts: this.exts, matcher: () => true });
addFileResolver(original =>
(request: string) => {
const found = matchPath(request, undefined, undefined, this.exts);
return found
? original(found)
: original(request);
});
};
resolveTsConfigPaths() {
const tsConfig = tsconfig_paths_1.loadConfig(this.config.directory);
if (tsConfig.resultType === "success") {
this.tsConfigFilePath = tsConfig.configFileAbsolutePath;
logger_1.debug("Found TypeScript config", this.tsConfigFilePath);
logger_1.debug("Registering ts-config paths...");
logger_1.debug(tsConfig.paths);
this.tsResolve = tsconfig_paths_1.createMatchPath(tsConfig.absoluteBaseUrl, tsConfig.paths, tsConfig.mainFields, tsConfig.addMatchAll);
}
else {
this.tsResolve = tsconfig_paths_1.createMatchPath(this.config.directory, {
"~/*": ["*"],
"@/*": ["*", "src/*"]
}, undefined, true);
}
}
prepareProject() {
resolveTsConfigPaths() {
const tsConfig = tsconfig_paths_1.loadConfig(this.config.directory);
if (tsConfig.resultType === "success") {
this.tsConfigFilePath = tsConfig.configFileAbsolutePath;
logger_1.debug("Found TypeScript config", this.tsConfigFilePath);
logger_1.debug("Registering ts-config paths...");
logger_1.debug(tsConfig.paths);
this.tsResolve = tsconfig_paths_1.createMatchPath(tsConfig.absoluteBaseUrl, tsConfig.paths, tsConfig.mainFields, tsConfig.addMatchAll);
}
else {
this.tsResolve = tsconfig_paths_1.createMatchPath(this.config.directory, {
"~/*": ["*"],
"@/*": ["*", "src/*"]
}, undefined, true);
}
}
prepareProject() {
private resolveTsConfigPaths() {
const tsConfig = loadConfig(this.config.directory);
if (tsConfig.resultType === "success") {
this.tsConfigFilePath = tsConfig.configFileAbsolutePath;
debug("Found TypeScript config", this.tsConfigFilePath);
debug("Registering ts-config paths...");
debug(tsConfig.paths);
this.tsResolve = createMatchPath(
tsConfig.absoluteBaseUrl,
tsConfig.paths,
tsConfig.mainFields,
tsConfig.addMatchAll
);
} else {
this.tsResolve = createMatchPath(
this.config.directory,
{
"~/*": ["*"],
"@/*": ["*", "src/*"]
},
undefined,
true
);
}
private resolveTsConfigPaths() {
const tsConfig = loadConfig(this.config.directory);
if (tsConfig.resultType === "success") {
this.tsConfigFilePath = tsConfig.configFileAbsolutePath;
debug("Found TypeScript config", this.tsConfigFilePath);
debug("Registering ts-config paths...");
debug(tsConfig.paths);
this.tsResolve = createMatchPath(
tsConfig.absoluteBaseUrl,
tsConfig.paths,
tsConfig.mainFields,
tsConfig.addMatchAll
);
} else {
this.tsResolve = createMatchPath(
this.config.directory,
{
"~/*": ["*"],
"@/*": ["*", "src/*"]
},
undefined,
true
);
}
}