Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
]](node) {
const sourceNode = node.source
// skip `import(foo)`
if (
node.type === "ImportExpression" &&
sourceNode &&
sourceNode.type !== "Literal"
) {
return
}
const name = sourceNode && stripImportPathParams(sourceNode.value)
if (name && (includeCore || !resolve.isCore(name))) {
targets.push(new ImportTarget(sourceNode, name, options))
}
},
pkgResolve(id, { basedir: basedir }, function(error, result, pkg) {
if (pkgResolve.isCore(id)) {
resolve({
name: id,
core: true
});
} else if (pkg && pkgResolve.isCore(pkg.name)) {
resolve({
name: pkg.name,
core: true
});
} else if (pkg && !(_.startsWith(id, '.') || _.startsWith(id, '/'))) {
const pkgPath = path.resolve(path.dirname(result).split(pkg.name)[0] + '/', pkg.name);
resolve({
name: pkg.name,
version: pkg.version,
dependencies: pkg.dependencies,
path: pkgPath
});
} else {
resolve({
name: id,
, fixNameField: function(data, options) {
if (typeof options === "boolean") options = {strict: options}
else if (typeof options === "undefined") options = {}
var strict = options.strict
if (!data.name && !strict) {
data.name = ""
return
}
if (typeof data.name !== "string") {
throw new Error("name field must be a string.")
}
if (!strict)
data.name = data.name.trim()
ensureValidName(data.name, strict, options.allowLegacyCase)
if (isBuiltinModule(data.name))
this.warn("conflictingName", data.name)
}
"Program:exit"() {
const tracker = new ReferenceTracker(context.getScope())
const references = tracker.iterateGlobalReferences({
require: {
[CALL]: true,
resolve: { [CALL]: true },
},
})
for (const { node } of references) {
const targetNode = node.arguments[0]
const rawName = getStringIfConstant(targetNode)
const name = rawName && stripImportPathParams(rawName)
if (name && (includeCore || !resolve.isCore(name))) {
targets.push(new ImportTarget(targetNode, name, options))
}
}
callback(targets)
},
}
function nodeResolver(source, file, config) {
if (resolve.isCore(source)) {
return { found: true, path: null };
}
try {
return { found: true, path: resolve.sync(source, opts(file, config)) };
} catch (err) {
return { found: false };
}
}
module.exports.resolve = function(source, file, config) {
log('Resolving:', source, 'from:', file);
let resolvedPath;
if (resolve.isCore(source)) {
log('resolved to core');
return {found: true, path: null};
}
source = applyModuleNameMapper(source, config);
try {
resolvedPath = resolve.sync(source, opts(file, config));
log('Resolved to:', resolvedPath);
return {found: true, path: resolvedPath};
} catch (err) {
log('resolve threw error:', err);
return {found: false};
}
};
, fixNameField: function(data, options) {
if (typeof options === "boolean") options = {strict: options}
else if (typeof options === "undefined") options = {}
var strict = options.strict
if (!data.name && !strict) {
data.name = ""
return
}
if (typeof data.name !== "string") {
throw new Error("name field must be a string.")
}
if (!strict)
data.name = data.name.trim()
ensureValidName(data.name, strict, options.allowLegacyCase)
if (isBuiltinModule(data.name))
this.warn("conflictingName", data.name)
}
exports.resolve = function (source, file, config) {
log('Resolving:', source, 'from:', file)
var resolvedPath
if (resolve.isCore(source)) {
log('resolved to core')
return { found: true, path: null }
}
try {
resolvedPath = resolve.sync(source, opts(file, config))
log('Resolved to:', resolvedPath)
return { found: true, path: resolvedPath }
} catch (err) {
log('resolve threw error:', err)
return { found: false }
}
}
exports.resolve = function (source, file, config) {
log('Resolving:', source, 'from:', file)
var resolvedPath
if (resolve.isCore(source)) {
log('resolved to core')
return { found: true, path: null }
}
try {
resolvedPath = resolve.sync(source, opts(file, config))
log('Resolved to:', resolvedPath)
return { found: true, path: resolvedPath }
} catch (err) {
log('resolve threw error:', err)
return { found: false }
}
}