Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
let found = resolver.resolveImport(path, absPath);
if (!found) {
throw new Error(`can't locate ${path} referred to in module rules:${JSON.stringify(moduleRules, null, 2)}`);
}
output.push({
absPath,
target: explicitRelative(dirname(absPath), found.absPath),
runtimeName: found.runtimeName,
});
}
}
if (moduleRules.dependsOnComponents) {
for (let snippet of moduleRules.dependsOnComponents) {
let found = resolver.resolveComponentSnippet(snippet, moduleRules);
for (let { absPath: target, runtimeName } of found.modules) {
output.push({ absPath, target: explicitRelative(dirname(absPath), target), runtimeName });
}
}
}
return output;
}
export function expandModuleRules(absPath: string, moduleRules: ModuleRules, resolver: CompatResolver) {
let output: { absPath: string; target: string; runtimeName: string }[] = [];
if (moduleRules.dependsOnModules) {
for (let path of moduleRules.dependsOnModules) {
let found = resolver.resolveImport(path, absPath);
if (!found) {
throw new Error(`can't locate ${path} referred to in module rules:${JSON.stringify(moduleRules, null, 2)}`);
}
output.push({
absPath,
target: explicitRelative(dirname(absPath), found.absPath),
runtimeName: found.runtimeName,
});
}
}
if (moduleRules.dependsOnComponents) {
for (let snippet of moduleRules.dependsOnComponents) {
let found = resolver.resolveComponentSnippet(snippet, moduleRules);
for (let { absPath: target, runtimeName } of found.modules) {
output.push({ absPath, target: explicitRelative(dirname(absPath), target), runtimeName });
}
}
}
return output;
}
modules: componentModules.map(p => ({
path: explicitRelative(dirname(from), p.absPath),
absPath: p.absPath,
runtimeName: p.runtimeName,
})),
yieldsComponents: componentRules ? componentRules.yieldsSafeComponents : [],
private tryHelper(path: string, from: string): Resolution | null {
for (let extension of this.params.resolvableExtensions) {
let absPath = join(this.params.root, 'helpers', path) + extension;
if (pathExistsSync(absPath)) {
return {
type: 'helper',
modules: [
{
runtimeName: `${this.params.modulePrefix}/helpers/${path}`,
path: explicitRelative(dirname(from), absPath),
absPath,
},
],
};
}
}
return null;
}