Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
async function warnAboutNodeSassBeingUnsupported(
filePath,
logger: PluginLogger,
) {
if (!didWarnAboutNodeSass) {
try {
// TODO: replace this with the actual filesystem later
await resolve(fs, 'node-sass', {basedir: dirname(filePath)});
logger.warn({
origin: '@parcel/transformer-sass',
message:
'`node-sass` is unsupported in Parcel 2, it will use Dart Sass a.k.a. `sass`',
});
} catch (err) {
if (err.code !== 'MODULE_NOT_FOUND') {
throw err;
}
} finally {
didWarnAboutNodeSass = true;
}
}
}
export async function localResolve(
name: string,
path: FilePath,
fs: FileSystem = nodeFS,
triedInstall: boolean = false
): Promise<[string, ?PackageJSON]> {
let basedir = dirname(path);
let key = basedir + ':' + name;
let resolved = cache.get(key);
if (!resolved) {
try {
resolved = await resolve(fs, name, {
basedir,
extensions: ['.js', '.json']
});
} catch (e) {
if (e.code === 'MODULE_NOT_FOUND' && !triedInstall) {
await installPackage(fs, [name], path);
return localResolve(name, path, fs, true);
}
throw e;
}
cache.set(key, resolved);
}
return resolved;
}
export async function resolveExtends(
ext: string,
configPath: FilePath,
options: ParcelOptions
) {
if (ext.startsWith('.')) {
return path.resolve(path.dirname(configPath), ext);
} else {
let [resolved] = await resolve(options.inputFS, ext, {
basedir: path.dirname(configPath)
});
return options.inputFS.realpath(resolved);
}
}
async function installPeerDependencies(
fs: FileSystem,
filepath: FilePath,
name: string,
options,
) {
let basedir = path.dirname(filepath);
const {resolved} = await resolve(fs, name, {basedir});
const pkg = nullthrows(await loadConfig(fs, resolved, ['package.json']))
.config;
const peers = pkg.peerDependencies || {};
const modules = [];
for (const peer in peers) {
modules.push(`${peer}@${peers[peer]}`);
}
if (modules.length) {
await install(
fs,
modules,
filepath,
Object.assign({}, options, {installPeers: false}),
);
async resolve(
name: ModuleSpecifier,
from: FilePath,
triedInstall: boolean = false,
) {
let basedir = dirname(from);
let key = basedir + ':' + name;
let resolved = this.cache.get(key);
if (!resolved) {
try {
resolved = await resolve(this.fs, name, {
basedir,
extensions: Object.keys(Module._extensions),
});
} catch (e) {
if (e.code === 'MODULE_NOT_FOUND' && !triedInstall) {
await this.install([name], from);
return this.resolve(name, from, true);
}
throw e;
}
this.cache.set(key, resolved);
}
return resolved;
}