@parcel/utils
Advanced tools
Comparing version 2.0.0-nightly.210 to 2.0.0-nightly.214
@@ -7,2 +7,3 @@ "use strict"; | ||
exports.resolveConfig = resolveConfig; | ||
exports.resolveConfigSync = resolveConfigSync; | ||
exports.loadConfig = loadConfig; | ||
@@ -20,3 +21,2 @@ | ||
}; | ||
const existsCache = new Map(); | ||
@@ -45,2 +45,20 @@ async function resolveConfig(fs, filepath, filenames, opts, root = _path.default.parse(filepath).root) { | ||
function resolveConfigSync(fs, filepath, filenames, opts, root = _path.default.parse(filepath).root) { | ||
filepath = fs.realpathSync(_path.default.dirname(filepath)); // Don't traverse above the module root | ||
if (filepath === root || _path.default.basename(filepath) === 'node_modules') { | ||
return null; | ||
} | ||
for (const filename of filenames) { | ||
let file = _path.default.join(filepath, filename); | ||
if (fs.existsSync(file) && fs.statSync(file).isFile()) { | ||
return file; | ||
} | ||
} | ||
return resolveConfigSync(fs, filepath, filenames, opts); | ||
} | ||
async function loadConfig(fs, filepath, filenames, opts) { | ||
@@ -86,3 +104,2 @@ let configFile = await resolveConfig(fs, filepath, filenames, opts); | ||
if (err.code === 'MODULE_NOT_FOUND' || err.code === 'ENOENT') { | ||
existsCache.delete(configFile); | ||
return null; | ||
@@ -89,0 +106,0 @@ } |
@@ -13,2 +13,6 @@ "use strict"; | ||
var _ = require("../"); | ||
var _module = _interopRequireDefault(require("module")); | ||
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; } | ||
@@ -25,2 +29,9 @@ | ||
async function resolve(fs, id, opts) { | ||
if (id === 'pnpapi') { | ||
// the resolve package doesn't recognize pnpapi as a builtin | ||
return { | ||
resolved: 'pnpapi' | ||
}; | ||
} | ||
let res = await resolveAsync(id, _objectSpread({}, opts, { | ||
@@ -69,3 +80,10 @@ async readFile(filename, callback) { | ||
function resolveSync(fs, id, opts) { | ||
// $FlowFixMe | ||
if (id === 'pnpapi') { | ||
// the resolve package doesn't recognize pnpapi as a builtin | ||
return { | ||
resolved: 'pnpapi' | ||
}; | ||
} // $FlowFixMe | ||
let res = _resolve2.default.sync(id, _objectSpread({}, opts, { | ||
@@ -72,0 +90,0 @@ readFileSync: (...args) => { |
{ | ||
"name": "@parcel/utils", | ||
"version": "2.0.0-nightly.210+10e18b0a", | ||
"version": "2.0.0-nightly.214+52fd6741", | ||
"description": "Blazing fast, zero configuration web application bundler", | ||
@@ -20,6 +20,6 @@ "license": "MIT", | ||
"@iarna/toml": "^2.2.0", | ||
"@parcel/codeframe": "2.0.0-nightly.210+10e18b0a", | ||
"@parcel/diagnostic": "2.0.0-nightly.210+10e18b0a", | ||
"@parcel/logger": "2.0.0-nightly.210+10e18b0a", | ||
"@parcel/markdown-ansi": "2.0.0-nightly.210+10e18b0a", | ||
"@parcel/codeframe": "2.0.0-nightly.214+52fd6741", | ||
"@parcel/diagnostic": "2.0.0-nightly.214+52fd6741", | ||
"@parcel/logger": "2.0.0-nightly.214+52fd6741", | ||
"@parcel/markdown-ansi": "2.0.0-nightly.214+52fd6741", | ||
"ansi-html": "^0.0.7", | ||
@@ -44,3 +44,3 @@ "chalk": "^2.4.2", | ||
}, | ||
"gitHead": "10e18b0a440b1678ef0fdcd7d104a1394a5ed6f6" | ||
"gitHead": "52fd6741a0ea1f2e043c628cf6b7be0715b1c837" | ||
} |
@@ -22,4 +22,2 @@ // @flow | ||
const existsCache = new Map(); | ||
export async function resolveConfig( | ||
@@ -53,2 +51,26 @@ fs: FileSystem, | ||
export function resolveConfigSync( | ||
fs: FileSystem, | ||
filepath: FilePath, | ||
filenames: Array<FilePath>, | ||
opts: ?ConfigOptions, | ||
root: FilePath = path.parse(filepath).root, | ||
): FilePath | null { | ||
filepath = fs.realpathSync(path.dirname(filepath)); | ||
// Don't traverse above the module root | ||
if (filepath === root || path.basename(filepath) === 'node_modules') { | ||
return null; | ||
} | ||
for (const filename of filenames) { | ||
let file = path.join(filepath, filename); | ||
if (fs.existsSync(file) && fs.statSync(file).isFile()) { | ||
return file; | ||
} | ||
} | ||
return resolveConfigSync(fs, filepath, filenames, opts); | ||
} | ||
export async function loadConfig( | ||
@@ -91,3 +113,2 @@ fs: FileSystem, | ||
if (err.code === 'MODULE_NOT_FOUND' || err.code === 'ENOENT') { | ||
existsCache.delete(configFile); | ||
return null; | ||
@@ -94,0 +115,0 @@ } |
@@ -15,2 +15,5 @@ // @flow strict-local | ||
import _resolve from 'resolve'; | ||
import {resolveConfig, resolveConfigSync} from '../'; | ||
// $FlowFixMe this is untyped | ||
import Module from 'module'; | ||
@@ -27,11 +30,44 @@ const resolveAsync = promisify(_resolve); | ||
id: string, | ||
opts?: {| | ||
opts: {| | ||
range?: ?SemverRange, | ||
...ResolveOptions, | ||
basedir: string, | ||
|}, | ||
): Promise<ResolveResult> { | ||
if (process.env.PARCEL_BUILD_ENV !== 'production') { | ||
// Yarn patches resolve automatically in a non-linked setup | ||
let pnp; | ||
if ( | ||
process.versions.pnp != null && | ||
(!id.includes('@parcel/') || id.startsWith('@parcel/watcher')) && | ||
(pnp = Module.findPnpApi(opts.basedir)) | ||
) { | ||
try { | ||
let res = pnp.resolveRequest(id, `${opts.basedir}/`, { | ||
extensions: opts.extensions, | ||
considerBuiltins: true, | ||
}); | ||
if (!res) { | ||
// builtin | ||
return {resolved: id}; | ||
} | ||
let pkgFile = await resolveConfig(fs, res, ['package.json']); | ||
let pkg = null; | ||
if (pkgFile != null) { | ||
pkg = JSON.parse(await fs.readFile(pkgFile, 'utf8')); | ||
} | ||
if (res) { | ||
return {resolved: res, pkg}; | ||
} | ||
} catch (e) { | ||
if (e.code !== 'MODULE_NOT_FOUND') { | ||
throw e; | ||
} | ||
} | ||
} | ||
// $FlowFixMe | ||
opts = opts || {}; | ||
// $FlowFixMe | ||
opts.packageFilter = pkg => { | ||
@@ -51,2 +87,7 @@ if ( | ||
if (id === 'pnpapi') { | ||
// the resolve package doesn't recognize pnpapi as a builtin | ||
return {resolved: 'pnpapi'}; | ||
} | ||
let res = await resolveAsync(id, { | ||
@@ -95,8 +136,43 @@ ...opts, | ||
id: string, | ||
opts?: ResolveOptions, | ||
opts: {| | ||
...ResolveOptions, | ||
basedir: string, | ||
|}, | ||
): ResolveResult { | ||
if (process.env.PARCEL_BUILD_ENV !== 'production') { | ||
// Yarn patches resolve automatically in a non-linked setup | ||
let pnp; | ||
if ( | ||
process.versions.pnp != null && | ||
(!id.startsWith('@parcel') || id.startsWith('@parcel/watcher')) && | ||
(pnp = Module.findPnpApi(opts.basedir)) | ||
) { | ||
try { | ||
let res = pnp.resolveRequest(id, `${opts.basedir}/`, { | ||
extensions: opts.extensions, | ||
considerBuiltins: true, | ||
}); | ||
if (!res) { | ||
// builtin | ||
return {resolved: id}; | ||
} | ||
let pkgFile = resolveConfigSync(fs, res, ['package.json']); | ||
let pkg = null; | ||
if (pkgFile != null) { | ||
pkg = JSON.parse(fs.readFileSync(pkgFile, 'utf8')); | ||
} | ||
if (res) { | ||
return {resolved: res, pkg}; | ||
} | ||
} catch (e) { | ||
if (e.code !== 'MODULE_NOT_FOUND') { | ||
throw e; | ||
} | ||
} | ||
} | ||
// $FlowFixMe | ||
opts = opts || {}; | ||
// $FlowFixMe | ||
opts.packageFilter = pkg => { | ||
@@ -112,2 +188,7 @@ if (pkg.name.startsWith('@parcel/') && pkg.name !== '@parcel/watcher') { | ||
if (id === 'pnpapi') { | ||
// the resolve package doesn't recognize pnpapi as a builtin | ||
return {resolved: 'pnpapi'}; | ||
} | ||
// $FlowFixMe | ||
@@ -114,0 +195,0 @@ let res = _resolve.sync(id, { |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
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
Debug access
Supply chain riskUses debug, reflection and dynamic code execution features.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
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
136692
4289
9