Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
const existingAssetNames = [filename];
if (sourceMap) {
existingAssetNames.push(`${filename}.map`);
existingAssetNames.push('sourcemap-register.js');
}
if (v8cache) {
existingAssetNames.push(`${filename}.cache`);
existingAssetNames.push(`${filename}.cache.js`);
}
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;
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,
{
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() {
constructor(rawOptions: Partial = {}) {
this.source = "described-resolve";
this.target = "resolve";
const options = Options.getOptions(rawOptions);
this.extensions = options.extensions;
const colors = new chalk.constructor({ enabled: options.colors });
this.log = Logger.makeLogger(options, colors);
const context = options.context || process.cwd();
const loadFrom = options.configFile || context;
const loadResult = TsconfigPaths.loadConfig(loadFrom);
if (loadResult.resultType === "failed") {
this.log.logError(`Failed to load ${loadFrom}: ${loadResult.message}`);
} else {
this.log.logInfo(
`tsconfig-paths-webpack-plugin: Using config file at ${
loadResult.configFileAbsolutePath
}`
);
this.baseUrl = options.baseUrl || loadResult.baseUrl;
this.absoluteBaseUrl = options.baseUrl
? path.resolve(options.baseUrl)
: loadResult.absoluteBaseUrl;
this.matchPath = TsconfigPaths.createMatchPathAsync(
this.absoluteBaseUrl,
loadResult.paths,
options.mainFields