Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
exports.resolveURL = (issuer, id) => {
if (/^\./.test(id)) {
// Relative file
// Excluded something like ./node_modules/webpack/buildin/global.js
if (!/node_modules/.test(id)) {
id = url.resolve(issuer, id)
}
} else if (!builtinModules.includes(id)) {
// Propably an npm package
id = `https://unpkg.com/${id}`
}
return id
}
async resolveId(importee: string, importer?: string) {
const id = await plugin.resolveId(
importee,
importer || `${options.rootDir}/__no_importer__.js`
)
if (typeof id === 'string') {
// Exclude built-in modules
if (builtinModules.includes(id)) {
return false
}
// If we don't intend to bundle node_modules
// Mark it as external
if (/node_modules/.test(id)) {
if (!options.bundleNodeModules) {
return false
}
if (Array.isArray(options.bundleNodeModules)) {
const shouldBundle = options.bundleNodeModules.some(name =>
id.includes(`/node_modules/${name}/`)
)
if (!shouldBundle) {
return false
}
resolveId(importee) {
if (importee.startsWith(PREFIX)) {
return importee;
}
if (/\0/.test(importee) || !builtins.includes(importee)) {
return null;
}
const shim = path.resolve(dir, importee + ".js");
if (fs.existsSync(shim)) {
return shim;
}
return PREFIX + importee;
},
context: Rule.RuleContext,
) {
const moduleName = module.value;
if (typeof moduleName !== "string") {
return;
}
const ts = require("typescript");
if (ts.isExternalModuleNameRelative(moduleName)) {
return;
}
const packageName = getPackageName(moduleName);
if (
!whitelist.includes(packageName) &&
!builtins.includes(packageName) &&
!dependencies.has(packageName)
) {
context.report({
message: "Either remove this import or add it as a dependency.",
loc,
});
}
}
isBuiltIn(name) {
return builtIns.includes(name);
},