@parcel/node-resolver-core
Advanced tools
Comparing version 2.0.0-nightly.1832 to 2.0.0-nightly.1836
@@ -14,4 +14,6 @@ "use strict"; | ||
const empty = require.resolve('./_empty.js'); | ||
// $FlowFixMe this is untyped | ||
const empty = require.resolve('./_empty.js'); // $FlowFixMe | ||
let builtins = Object.create(null); // use definite (current) list of Node builtins | ||
@@ -18,0 +20,0 @@ |
@@ -22,2 +22,4 @@ "use strict"; | ||
var _module = _interopRequireDefault(require("module")); | ||
function _getRequireWildcardCache() { if (typeof WeakMap !== "function") return null; var cache = new WeakMap(); _getRequireWildcardCache = function () { return cache; }; return cache; } | ||
@@ -252,11 +254,32 @@ | ||
resolved = await this.findNodeModulePath(filename, dir); | ||
} catch (err) {} // ignore | ||
// If we couldn't resolve the node_modules path, just return the module name info | ||
} catch (err) {// ignore | ||
} | ||
if (resolved === undefined && process.versions.pnp != null && parent) { | ||
try { | ||
let [moduleName, subPath] = this.getModuleParts(filename); | ||
let pnp = // $FlowFixMe injected at runtime | ||
require('pnpapi'); | ||
let res = pnp.resolveToUnqualified(moduleName, parent); | ||
resolved = { | ||
moduleName, | ||
subPath, | ||
moduleDir: res, | ||
filePath: _path.default.join(res, subPath || '') | ||
}; | ||
} catch (e) { | ||
if (e.code !== 'MODULE_NOT_FOUND') { | ||
throw e; | ||
} | ||
} | ||
} // If we couldn't resolve the node_modules path, just return the module name info | ||
if (resolved === undefined) { | ||
let parts = this.getModuleParts(filename); | ||
let [moduleName, subPath] = this.getModuleParts(filename); | ||
resolved = { | ||
moduleName: parts[0], | ||
subPath: parts[1] | ||
moduleName, | ||
subPath | ||
}; | ||
@@ -288,9 +311,9 @@ let alternativeModules = await this.findAlternativeNodeModules(resolved.moduleName, dir); | ||
if (Array.isArray(includeNodeModules)) { | ||
let parts = this.getModuleParts(name); | ||
return includeNodeModules.includes(parts[0]); | ||
let [moduleName] = this.getModuleParts(name); | ||
return includeNodeModules.includes(moduleName); | ||
} | ||
if (includeNodeModules && typeof includeNodeModules === 'object') { | ||
let parts = this.getModuleParts(name); | ||
let include = includeNodeModules[parts[0]]; | ||
let [moduleName] = this.getModuleParts(name); | ||
let include = includeNodeModules[moduleName]; | ||
@@ -395,3 +418,3 @@ if (include != null) { | ||
async findNodeModulePath(filename, dir) { | ||
let parts = this.getModuleParts(filename); | ||
let [moduleName, subPath] = this.getModuleParts(filename); | ||
@@ -408,3 +431,3 @@ let root = _path.default.parse(dir).root; | ||
// First, check if the module directory exists. This prevents a lot of unnecessary checks later. | ||
let moduleDir = _path.default.join(dir, 'node_modules', parts[0]); | ||
let moduleDir = _path.default.join(dir, 'node_modules', moduleName); | ||
@@ -415,4 +438,4 @@ let stats = await this.options.inputFS.stat(moduleDir); | ||
return { | ||
moduleName: parts[0], | ||
subPath: parts[1], | ||
moduleName: moduleName, | ||
subPath: subPath, | ||
moduleDir: moduleDir, | ||
@@ -680,8 +703,8 @@ filePath: _path.default.join(dir, 'node_modules', filename) | ||
// If it didn't match, try only the module name. | ||
let [mod, ...rest] = this.getModuleParts(filename); | ||
alias = await this.lookupAlias(aliases, mod, dir); | ||
let [moduleName, subPath] = this.getModuleParts(filename); | ||
alias = await this.lookupAlias(aliases, moduleName, dir); | ||
if (typeof alias === 'string') { | ||
if (typeof alias === 'string' && subPath) { | ||
// Append the filename back onto the aliased module. | ||
alias = _path.default.join(alias, ...rest); | ||
alias = _path.default.join(alias, subPath); | ||
} | ||
@@ -762,10 +785,14 @@ } | ||
getModuleParts(name) { | ||
let parts = _path.default.normalize(name).split(_path.default.sep); | ||
name = _path.default.normalize(name); | ||
let splitOn = name.indexOf(_path.default.sep); | ||
if (parts[0].charAt(0) === '@') { | ||
// Scoped module (e.g. @scope/module). Merge the first two parts back together. | ||
parts.splice(0, 2, `${parts[0]}/${parts[1]}`); | ||
if (name.charAt(0) === '@') { | ||
splitOn = name.indexOf(_path.default.sep, splitOn + 1); | ||
} | ||
return parts; | ||
if (splitOn < 0) { | ||
return [name.replace(/\\/g, '/'), undefined]; | ||
} else { | ||
return [name.substring(0, splitOn).replace(/\\/g, '/'), name.substring(splitOn + 1) || undefined]; | ||
} | ||
} | ||
@@ -772,0 +799,0 @@ |
{ | ||
"name": "@parcel/node-resolver-core", | ||
"version": "2.0.0-nightly.1832+10e18b0a", | ||
"version": "2.0.0-nightly.1836+52fd6741", | ||
"license": "MIT", | ||
@@ -18,9 +18,9 @@ "publishConfig": { | ||
"dependencies": { | ||
"@parcel/diagnostic": "2.0.0-nightly.210+10e18b0a", | ||
"@parcel/node-libs-browser": "2.0.0-nightly.1832+10e18b0a", | ||
"@parcel/utils": "2.0.0-nightly.210+10e18b0a", | ||
"@parcel/diagnostic": "2.0.0-nightly.214+52fd6741", | ||
"@parcel/node-libs-browser": "2.0.0-nightly.1836+52fd6741", | ||
"@parcel/utils": "2.0.0-nightly.214+52fd6741", | ||
"micromatch": "^3.0.4", | ||
"nullthrows": "^1.1.1" | ||
}, | ||
"gitHead": "10e18b0a440b1678ef0fdcd7d104a1394a5ed6f6" | ||
"gitHead": "52fd6741a0ea1f2e043c628cf6b7be0715b1c837" | ||
} |
@@ -0,2 +1,4 @@ | ||
// @flow | ||
import polyfills from '@parcel/node-libs-browser'; | ||
// $FlowFixMe this is untyped | ||
import {builtinModules} from 'module'; | ||
@@ -6,3 +8,4 @@ | ||
let builtins = Object.create(null); | ||
// $FlowFixMe | ||
let builtins: {[string]: any, ...} = Object.create(null); | ||
// use definite (current) list of Node builtins | ||
@@ -9,0 +12,0 @@ for (let key of builtinModules) { |
@@ -19,2 +19,4 @@ // @flow | ||
import nullthrows from 'nullthrows'; | ||
// $FlowFixMe this is untyped | ||
import _Module from 'module'; | ||
@@ -289,8 +291,31 @@ const EMPTY_SHIM = require.resolve('./_empty'); | ||
if (resolved === undefined && process.versions.pnp != null && parent) { | ||
try { | ||
let [moduleName, subPath] = this.getModuleParts(filename); | ||
let pnp = | ||
process.env.PARCEL_BUILD_ENV !== 'production' | ||
? _Module.findPnpApi(path.dirname(parent)) | ||
: // $FlowFixMe injected at runtime | ||
require('pnpapi'); | ||
let res = pnp.resolveToUnqualified(moduleName, parent); | ||
resolved = { | ||
moduleName, | ||
subPath, | ||
moduleDir: res, | ||
filePath: path.join(res, subPath || ''), | ||
}; | ||
} catch (e) { | ||
if (e.code !== 'MODULE_NOT_FOUND') { | ||
throw e; | ||
} | ||
} | ||
} | ||
// If we couldn't resolve the node_modules path, just return the module name info | ||
if (resolved === undefined) { | ||
let parts = this.getModuleParts(filename); | ||
let [moduleName, subPath] = this.getModuleParts(filename); | ||
resolved = { | ||
moduleName: parts[0], | ||
subPath: parts[1], | ||
moduleName, | ||
subPath, | ||
}; | ||
@@ -324,9 +349,9 @@ | ||
if (Array.isArray(includeNodeModules)) { | ||
let parts = this.getModuleParts(name); | ||
return includeNodeModules.includes(parts[0]); | ||
let [moduleName] = this.getModuleParts(name); | ||
return includeNodeModules.includes(moduleName); | ||
} | ||
if (includeNodeModules && typeof includeNodeModules === 'object') { | ||
let parts = this.getModuleParts(name); | ||
let include = includeNodeModules[parts[0]]; | ||
let [moduleName] = this.getModuleParts(name); | ||
let include = includeNodeModules[moduleName]; | ||
if (include != null) { | ||
@@ -446,3 +471,3 @@ return !!include; | ||
async findNodeModulePath(filename: string, dir: string) { | ||
let parts = this.getModuleParts(filename); | ||
let [moduleName, subPath] = this.getModuleParts(filename); | ||
let root = path.parse(dir).root; | ||
@@ -458,8 +483,8 @@ | ||
// First, check if the module directory exists. This prevents a lot of unnecessary checks later. | ||
let moduleDir = path.join(dir, 'node_modules', parts[0]); | ||
let moduleDir = path.join(dir, 'node_modules', moduleName); | ||
let stats = await this.options.inputFS.stat(moduleDir); | ||
if (stats.isDirectory()) { | ||
return { | ||
moduleName: parts[0], | ||
subPath: parts[1], | ||
moduleName: moduleName, | ||
subPath: subPath, | ||
moduleDir: moduleDir, | ||
@@ -785,7 +810,7 @@ filePath: path.join(dir, 'node_modules', filename), | ||
// If it didn't match, try only the module name. | ||
let [mod, ...rest] = this.getModuleParts(filename); | ||
alias = await this.lookupAlias(aliases, mod, dir); | ||
if (typeof alias === 'string') { | ||
let [moduleName, subPath] = this.getModuleParts(filename); | ||
alias = await this.lookupAlias(aliases, moduleName, dir); | ||
if (typeof alias === 'string' && subPath) { | ||
// Append the filename back onto the aliased module. | ||
alias = path.join(alias, ...rest); | ||
alias = path.join(alias, subPath); | ||
} | ||
@@ -861,12 +886,18 @@ } | ||
getModuleParts(name: string) { | ||
let parts = path.normalize(name).split(path.sep); | ||
if (parts[0].charAt(0) === '@') { | ||
// Scoped module (e.g. @scope/module). Merge the first two parts back together. | ||
parts.splice(0, 2, `${parts[0]}/${parts[1]}`); | ||
name = path.normalize(name); | ||
let splitOn = name.indexOf(path.sep); | ||
if (name.charAt(0) === '@') { | ||
splitOn = name.indexOf(path.sep, splitOn + 1); | ||
} | ||
return parts; | ||
if (splitOn < 0) { | ||
return [name.replace(/\\/g, '/'), undefined]; | ||
} else { | ||
return [ | ||
name.substring(0, splitOn).replace(/\\/g, '/'), | ||
name.substring(splitOn + 1) || undefined, | ||
]; | ||
} | ||
} | ||
hasSideEffects(filePath: FilePath, pkg: InternalPackageJSON) { | ||
hasSideEffects(filePath: FilePath, pkg: InternalPackageJSON): boolean { | ||
switch (typeof pkg.sideEffects) { | ||
@@ -873,0 +904,0 @@ case 'boolean': |
Manifest confusion
Supply chain riskThis package has inconsistent metadata. This could be malicious or caused by an error when publishing the package.
Found 1 instance in 1 package
Environment variable access
Supply chain riskPackage accesses environment variables, which may be a sign of credential stuffing or data theft.
Found 1 instance in 1 package
Manifest confusion
Supply chain riskThis package has inconsistent metadata. This could be malicious or caused by an error when publishing the package.
Found 1 instance in 1 package
51999
1484
5