@rollup/plugin-node-resolve
Advanced tools
Comparing version 11.2.1 to 13.0.0
# @rollup/plugin-node-resolve ChangeLog | ||
## v13.0.0 | ||
_2021-05-04_ | ||
### Breaking Changes | ||
- fix!: mark module as external if resolved module is external (#799) | ||
### Features | ||
- feat: Follow up to #843, refining exports and browser field interaction (#866) | ||
## v12.0.0 | ||
_2021-05-04_ | ||
### Breaking Changes | ||
- fix!: mark module as external if resolved module is external (#799) | ||
### Features | ||
- feat: Follow up to #843, refining exports and browser field interaction (#866) | ||
## v11.2.1 | ||
@@ -4,0 +28,0 @@ |
@@ -25,3 +25,3 @@ 'use strict'; | ||
const access = util.promisify(fs__default['default'].access); | ||
const readFile = util.promisify(fs__default['default'].readFile); | ||
const readFile$1 = util.promisify(fs__default['default'].readFile); | ||
const realpath = util.promisify(fs__default['default'].realpath); | ||
@@ -90,3 +90,3 @@ const stat = util.promisify(fs__default['default'].stat); | ||
const readCachedFile = makeCache(readFile); | ||
const readCachedFile = makeCache(readFile$1); | ||
@@ -352,7 +352,7 @@ // returns the imported package name for bare module imports | ||
); | ||
return result ? url.pathToFileURL(result.location) : null; | ||
return result ? url.pathToFileURL(result.location).href : null; | ||
} | ||
const result = await context.resolveId(`${target}${subpath}`, context.pkgURL.href); | ||
return result ? url.pathToFileURL(result.location) : null; | ||
return result ? url.pathToFileURL(result.location).href : null; | ||
} | ||
@@ -558,3 +558,3 @@ throw new InvalidPackageTargetError(context, `Invalid mapping: "${target}".`); | ||
const resolveImportPath = util.promisify(resolve__default['default']); | ||
const readFile$1 = util.promisify(fs__default['default'].readFile); | ||
const readFile = util.promisify(fs__default['default'].readFile); | ||
@@ -572,3 +572,3 @@ async function getPackageJson(importer, pkgName, resolveOptions, moduleDirectories) { | ||
const pkgJsonPath = await resolveImportPath(`${pkgName}/package.json`, resolveOptions); | ||
const pkgJson = JSON.parse(await readFile$1(pkgJsonPath, 'utf-8')); | ||
const pkgJson = JSON.parse(await readFile(pkgJsonPath, 'utf-8')); | ||
return { pkgJsonPath, pkgJson }; | ||
@@ -880,199 +880,214 @@ } catch (_) { | ||
return { | ||
name: 'node-resolve', | ||
const doResolveId = async (context, importee, importer, opts) => { | ||
// strip query params from import | ||
const [importPath, params] = importee.split('?'); | ||
const importSuffix = `${params ? `?${params}` : ''}`; | ||
importee = importPath; | ||
buildStart(options) { | ||
rollupOptions = options; | ||
const baseDir = !importer || dedupe(importee) ? rootDir : path.dirname(importer); | ||
for (const warning of warnings) { | ||
this.warn(warning); | ||
// https://github.com/defunctzombie/package-browser-field-spec | ||
const browser = browserMapCache.get(importer); | ||
if (useBrowserOverrides && browser) { | ||
const resolvedImportee = path.resolve(baseDir, importee); | ||
if (browser[importee] === false || browser[resolvedImportee] === false) { | ||
return { id: ES6_BROWSER_EMPTY }; | ||
} | ||
const browserImportee = | ||
browser[importee] || | ||
browser[resolvedImportee] || | ||
browser[`${resolvedImportee}.js`] || | ||
browser[`${resolvedImportee}.json`]; | ||
if (browserImportee) { | ||
importee = browserImportee; | ||
} | ||
} | ||
({ preserveSymlinks } = options); | ||
}, | ||
const parts = importee.split(/[/\\]/); | ||
let id = parts.shift(); | ||
let isRelativeImport = false; | ||
generateBundle() { | ||
readCachedFile.clear(); | ||
isFileCached.clear(); | ||
isDirCached.clear(); | ||
}, | ||
if (id[0] === '@' && parts.length > 0) { | ||
// scoped packages | ||
id += `/${parts.shift()}`; | ||
} else if (id[0] === '.') { | ||
// an import relative to the parent dir of the importer | ||
id = path.resolve(baseDir, importee); | ||
isRelativeImport = true; | ||
} | ||
async resolveId(importee, importer, opts) { | ||
if (importee === ES6_BROWSER_EMPTY) { | ||
return importee; | ||
if ( | ||
!isRelativeImport && | ||
resolveOnly.length && | ||
!resolveOnly.some((pattern) => pattern.test(id)) | ||
) { | ||
if (normalizeInput(rollupOptions.input).includes(importee)) { | ||
return null; | ||
} | ||
// ignore IDs with null character, these belong to other plugins | ||
if (/\0/.test(importee)) return null; | ||
return false; | ||
} | ||
if (/\0/.test(importer)) { | ||
importer = undefined; | ||
} | ||
const importSpecifierList = []; | ||
// strip query params from import | ||
const [importPath, params] = importee.split('?'); | ||
const importSuffix = `${params ? `?${params}` : ''}`; | ||
importee = importPath; | ||
if (importer === undefined && !importee[0].match(/^\.?\.?\//)) { | ||
// For module graph roots (i.e. when importer is undefined), we | ||
// need to handle 'path fragments` like `foo/bar` that are commonly | ||
// found in rollup config files. If importee doesn't look like a | ||
// relative or absolute path, we make it relative and attempt to | ||
// resolve it. If we don't find anything, we try resolving it as we | ||
// got it. | ||
importSpecifierList.push(`./${importee}`); | ||
} | ||
const baseDir = !importer || dedupe(importee) ? rootDir : path.dirname(importer); | ||
const importeeIsBuiltin = builtins.has(importee); | ||
// https://github.com/defunctzombie/package-browser-field-spec | ||
const browser = browserMapCache.get(importer); | ||
if (useBrowserOverrides && browser) { | ||
const resolvedImportee = path.resolve(baseDir, importee); | ||
if (browser[importee] === false || browser[resolvedImportee] === false) { | ||
return ES6_BROWSER_EMPTY; | ||
if (importeeIsBuiltin) { | ||
// The `resolve` library will not resolve packages with the same | ||
// name as a node built-in module. If we're resolving something | ||
// that's a builtin, and we don't prefer to find built-ins, we | ||
// first try to look up a local module with that name. If we don't | ||
// find anything, we resolve the builtin which just returns back | ||
// the built-in's name. | ||
importSpecifierList.push(`${importee}/`); | ||
} | ||
// TypeScript files may import '.js' to refer to either '.ts' or '.tsx' | ||
if (importer && importee.endsWith('.js')) { | ||
for (const ext of ['.ts', '.tsx']) { | ||
if (importer.endsWith(ext) && extensions.includes(ext)) { | ||
importSpecifierList.push(importee.replace(/.js$/, ext)); | ||
} | ||
const browserImportee = | ||
browser[importee] || | ||
browser[resolvedImportee] || | ||
browser[`${resolvedImportee}.js`] || | ||
browser[`${resolvedImportee}.json`]; | ||
if (browserImportee) { | ||
importee = browserImportee; | ||
} | ||
} | ||
} | ||
const parts = importee.split(/[/\\]/); | ||
let id = parts.shift(); | ||
let isRelativeImport = false; | ||
importSpecifierList.push(importee); | ||
if (id[0] === '@' && parts.length > 0) { | ||
// scoped packages | ||
id += `/${parts.shift()}`; | ||
} else if (id[0] === '.') { | ||
// an import relative to the parent dir of the importer | ||
id = path.resolve(baseDir, importee); | ||
isRelativeImport = true; | ||
} | ||
const warn = (...args) => context.warn(...args); | ||
const isRequire = | ||
opts && opts.custom && opts.custom['node-resolve'] && opts.custom['node-resolve'].isRequire; | ||
const exportConditions = isRequire ? conditionsCjs : conditionsEsm; | ||
if ( | ||
!isRelativeImport && | ||
resolveOnly.length && | ||
!resolveOnly.some((pattern) => pattern.test(id)) | ||
) { | ||
if (normalizeInput(rollupOptions.input).includes(importee)) { | ||
return null; | ||
if (useBrowserOverrides && !exportConditions.includes('browser')) | ||
exportConditions.push('browser'); | ||
const resolvedWithoutBuiltins = await resolveImportSpecifiers({ | ||
importer, | ||
importSpecifierList, | ||
exportConditions, | ||
warn, | ||
packageInfoCache, | ||
extensions, | ||
mainFields, | ||
preserveSymlinks, | ||
useBrowserOverrides, | ||
baseDir, | ||
moduleDirectories, | ||
rootDir, | ||
ignoreSideEffectsForRoot | ||
}); | ||
const resolved = | ||
importeeIsBuiltin && preferBuiltins | ||
? { | ||
packageInfo: undefined, | ||
hasModuleSideEffects: () => null, | ||
hasPackageEntry: true, | ||
packageBrowserField: false | ||
} | ||
: resolvedWithoutBuiltins; | ||
if (!resolved) { | ||
return null; | ||
} | ||
const { packageInfo, hasModuleSideEffects, hasPackageEntry, packageBrowserField } = resolved; | ||
let { location } = resolved; | ||
if (packageBrowserField) { | ||
if (Object.prototype.hasOwnProperty.call(packageBrowserField, location)) { | ||
if (!packageBrowserField[location]) { | ||
browserMapCache.set(location, packageBrowserField); | ||
return { id: ES6_BROWSER_EMPTY }; | ||
} | ||
return false; | ||
location = packageBrowserField[location]; | ||
} | ||
browserMapCache.set(location, packageBrowserField); | ||
} | ||
const importSpecifierList = []; | ||
if (importer === undefined && !importee[0].match(/^\.?\.?\//)) { | ||
// For module graph roots (i.e. when importer is undefined), we | ||
// need to handle 'path fragments` like `foo/bar` that are commonly | ||
// found in rollup config files. If importee doesn't look like a | ||
// relative or absolute path, we make it relative and attempt to | ||
// resolve it. If we don't find anything, we try resolving it as we | ||
// got it. | ||
importSpecifierList.push(`./${importee}`); | ||
if (hasPackageEntry && !preserveSymlinks) { | ||
const fileExists = await exists(location); | ||
if (fileExists) { | ||
location = await realpath(location); | ||
} | ||
} | ||
const importeeIsBuiltin = builtins.has(importee); | ||
idToPackageInfo.set(location, packageInfo); | ||
if (importeeIsBuiltin) { | ||
// The `resolve` library will not resolve packages with the same | ||
// name as a node built-in module. If we're resolving something | ||
// that's a builtin, and we don't prefer to find built-ins, we | ||
// first try to look up a local module with that name. If we don't | ||
// find anything, we resolve the builtin which just returns back | ||
// the built-in's name. | ||
importSpecifierList.push(`${importee}/`); | ||
if (hasPackageEntry) { | ||
if (importeeIsBuiltin && preferBuiltins) { | ||
if (!isPreferBuiltinsSet && resolvedWithoutBuiltins && resolved !== importee) { | ||
context.warn( | ||
`preferring built-in module '${importee}' over local alternative at '${resolvedWithoutBuiltins.location}', pass 'preferBuiltins: false' to disable this behavior or 'preferBuiltins: true' to disable this warning` | ||
); | ||
} | ||
return false; | ||
} else if (jail && location.indexOf(path.normalize(jail.trim(path.sep))) !== 0) { | ||
return null; | ||
} | ||
} | ||
// TypeScript files may import '.js' to refer to either '.ts' or '.tsx' | ||
if (importer && importee.endsWith('.js')) { | ||
for (const ext of ['.ts', '.tsx']) { | ||
if (importer.endsWith(ext) && extensions.includes(ext)) { | ||
importSpecifierList.push(importee.replace(/.js$/, ext)); | ||
} | ||
} | ||
if (options.modulesOnly && (await exists(location))) { | ||
const code = await readFile$1(location, 'utf-8'); | ||
if (isModule__default['default'](code)) { | ||
return { | ||
id: `${location}${importSuffix}`, | ||
moduleSideEffects: hasModuleSideEffects(location) | ||
}; | ||
} | ||
return null; | ||
} | ||
const result = { | ||
id: `${location}${importSuffix}`, | ||
moduleSideEffects: hasModuleSideEffects(location) | ||
}; | ||
return result; | ||
}; | ||
importSpecifierList.push(importee); | ||
return { | ||
name: 'node-resolve', | ||
const warn = (...args) => this.warn(...args); | ||
const isRequire = | ||
opts && opts.custom && opts.custom['node-resolve'] && opts.custom['node-resolve'].isRequire; | ||
const exportConditions = isRequire ? conditionsCjs : conditionsEsm; | ||
buildStart(options) { | ||
rollupOptions = options; | ||
const resolvedWithoutBuiltins = await resolveImportSpecifiers({ | ||
importer, | ||
importSpecifierList, | ||
exportConditions, | ||
warn, | ||
packageInfoCache, | ||
extensions, | ||
mainFields, | ||
preserveSymlinks, | ||
useBrowserOverrides, | ||
baseDir, | ||
moduleDirectories, | ||
rootDir, | ||
ignoreSideEffectsForRoot | ||
}); | ||
const resolved = | ||
importeeIsBuiltin && preferBuiltins | ||
? { | ||
packageInfo: undefined, | ||
hasModuleSideEffects: () => null, | ||
hasPackageEntry: true, | ||
packageBrowserField: false | ||
} | ||
: resolvedWithoutBuiltins; | ||
if (!resolved) { | ||
return null; | ||
for (const warning of warnings) { | ||
this.warn(warning); | ||
} | ||
const { packageInfo, hasModuleSideEffects, hasPackageEntry, packageBrowserField } = resolved; | ||
let { location } = resolved; | ||
if (packageBrowserField) { | ||
if (Object.prototype.hasOwnProperty.call(packageBrowserField, location)) { | ||
if (!packageBrowserField[location]) { | ||
browserMapCache.set(location, packageBrowserField); | ||
return ES6_BROWSER_EMPTY; | ||
} | ||
location = packageBrowserField[location]; | ||
} | ||
browserMapCache.set(location, packageBrowserField); | ||
({ preserveSymlinks } = options); | ||
}, | ||
generateBundle() { | ||
readCachedFile.clear(); | ||
isFileCached.clear(); | ||
isDirCached.clear(); | ||
}, | ||
async resolveId(importee, importer, opts) { | ||
if (importee === ES6_BROWSER_EMPTY) { | ||
return importee; | ||
} | ||
// ignore IDs with null character, these belong to other plugins | ||
if (/\0/.test(importee)) return null; | ||
if (hasPackageEntry && !preserveSymlinks) { | ||
const fileExists = await exists(location); | ||
if (fileExists) { | ||
location = await realpath(location); | ||
} | ||
if (/\0/.test(importer)) { | ||
importer = undefined; | ||
} | ||
idToPackageInfo.set(location, packageInfo); | ||
if (hasPackageEntry) { | ||
if (importeeIsBuiltin && preferBuiltins) { | ||
if (!isPreferBuiltinsSet && resolvedWithoutBuiltins && resolved !== importee) { | ||
this.warn( | ||
`preferring built-in module '${importee}' over local alternative at '${resolvedWithoutBuiltins.location}', pass 'preferBuiltins: false' to disable this behavior or 'preferBuiltins: true' to disable this warning` | ||
); | ||
} | ||
const resolved = await doResolveId(this, importee, importer, opts); | ||
if (resolved) { | ||
const resolvedResolved = await this.resolve(resolved.id, importer, { skipSelf: true }); | ||
const isExternal = !!(resolvedResolved && resolvedResolved.external); | ||
if (isExternal) { | ||
return false; | ||
} else if (jail && location.indexOf(path.normalize(jail.trim(path.sep))) !== 0) { | ||
return null; | ||
} | ||
} | ||
if (options.modulesOnly && (await exists(location))) { | ||
const code = await readFile(location, 'utf-8'); | ||
if (isModule__default['default'](code)) { | ||
return { | ||
id: `${location}${importSuffix}`, | ||
moduleSideEffects: hasModuleSideEffects(location) | ||
}; | ||
} | ||
return null; | ||
} | ||
const result = { | ||
id: `${location}${importSuffix}`, | ||
moduleSideEffects: hasModuleSideEffects(location) | ||
}; | ||
return result; | ||
return resolved; | ||
}, | ||
@@ -1079,0 +1094,0 @@ |
@@ -12,3 +12,3 @@ import path, { dirname, resolve, extname, normalize, sep } from 'path'; | ||
const access = promisify(fs.access); | ||
const readFile = promisify(fs.readFile); | ||
const readFile$1 = promisify(fs.readFile); | ||
const realpath = promisify(fs.realpath); | ||
@@ -77,3 +77,3 @@ const stat = promisify(fs.stat); | ||
const readCachedFile = makeCache(readFile); | ||
const readCachedFile = makeCache(readFile$1); | ||
@@ -339,7 +339,7 @@ // returns the imported package name for bare module imports | ||
); | ||
return result ? pathToFileURL(result.location) : null; | ||
return result ? pathToFileURL(result.location).href : null; | ||
} | ||
const result = await context.resolveId(`${target}${subpath}`, context.pkgURL.href); | ||
return result ? pathToFileURL(result.location) : null; | ||
return result ? pathToFileURL(result.location).href : null; | ||
} | ||
@@ -545,3 +545,3 @@ throw new InvalidPackageTargetError(context, `Invalid mapping: "${target}".`); | ||
const resolveImportPath = promisify(resolve$1); | ||
const readFile$1 = promisify(fs.readFile); | ||
const readFile = promisify(fs.readFile); | ||
@@ -559,3 +559,3 @@ async function getPackageJson(importer, pkgName, resolveOptions, moduleDirectories) { | ||
const pkgJsonPath = await resolveImportPath(`${pkgName}/package.json`, resolveOptions); | ||
const pkgJson = JSON.parse(await readFile$1(pkgJsonPath, 'utf-8')); | ||
const pkgJson = JSON.parse(await readFile(pkgJsonPath, 'utf-8')); | ||
return { pkgJsonPath, pkgJson }; | ||
@@ -867,199 +867,214 @@ } catch (_) { | ||
return { | ||
name: 'node-resolve', | ||
const doResolveId = async (context, importee, importer, opts) => { | ||
// strip query params from import | ||
const [importPath, params] = importee.split('?'); | ||
const importSuffix = `${params ? `?${params}` : ''}`; | ||
importee = importPath; | ||
buildStart(options) { | ||
rollupOptions = options; | ||
const baseDir = !importer || dedupe(importee) ? rootDir : dirname(importer); | ||
for (const warning of warnings) { | ||
this.warn(warning); | ||
// https://github.com/defunctzombie/package-browser-field-spec | ||
const browser = browserMapCache.get(importer); | ||
if (useBrowserOverrides && browser) { | ||
const resolvedImportee = resolve(baseDir, importee); | ||
if (browser[importee] === false || browser[resolvedImportee] === false) { | ||
return { id: ES6_BROWSER_EMPTY }; | ||
} | ||
const browserImportee = | ||
browser[importee] || | ||
browser[resolvedImportee] || | ||
browser[`${resolvedImportee}.js`] || | ||
browser[`${resolvedImportee}.json`]; | ||
if (browserImportee) { | ||
importee = browserImportee; | ||
} | ||
} | ||
({ preserveSymlinks } = options); | ||
}, | ||
const parts = importee.split(/[/\\]/); | ||
let id = parts.shift(); | ||
let isRelativeImport = false; | ||
generateBundle() { | ||
readCachedFile.clear(); | ||
isFileCached.clear(); | ||
isDirCached.clear(); | ||
}, | ||
if (id[0] === '@' && parts.length > 0) { | ||
// scoped packages | ||
id += `/${parts.shift()}`; | ||
} else if (id[0] === '.') { | ||
// an import relative to the parent dir of the importer | ||
id = resolve(baseDir, importee); | ||
isRelativeImport = true; | ||
} | ||
async resolveId(importee, importer, opts) { | ||
if (importee === ES6_BROWSER_EMPTY) { | ||
return importee; | ||
if ( | ||
!isRelativeImport && | ||
resolveOnly.length && | ||
!resolveOnly.some((pattern) => pattern.test(id)) | ||
) { | ||
if (normalizeInput(rollupOptions.input).includes(importee)) { | ||
return null; | ||
} | ||
// ignore IDs with null character, these belong to other plugins | ||
if (/\0/.test(importee)) return null; | ||
return false; | ||
} | ||
if (/\0/.test(importer)) { | ||
importer = undefined; | ||
} | ||
const importSpecifierList = []; | ||
// strip query params from import | ||
const [importPath, params] = importee.split('?'); | ||
const importSuffix = `${params ? `?${params}` : ''}`; | ||
importee = importPath; | ||
if (importer === undefined && !importee[0].match(/^\.?\.?\//)) { | ||
// For module graph roots (i.e. when importer is undefined), we | ||
// need to handle 'path fragments` like `foo/bar` that are commonly | ||
// found in rollup config files. If importee doesn't look like a | ||
// relative or absolute path, we make it relative and attempt to | ||
// resolve it. If we don't find anything, we try resolving it as we | ||
// got it. | ||
importSpecifierList.push(`./${importee}`); | ||
} | ||
const baseDir = !importer || dedupe(importee) ? rootDir : dirname(importer); | ||
const importeeIsBuiltin = builtins.has(importee); | ||
// https://github.com/defunctzombie/package-browser-field-spec | ||
const browser = browserMapCache.get(importer); | ||
if (useBrowserOverrides && browser) { | ||
const resolvedImportee = resolve(baseDir, importee); | ||
if (browser[importee] === false || browser[resolvedImportee] === false) { | ||
return ES6_BROWSER_EMPTY; | ||
if (importeeIsBuiltin) { | ||
// The `resolve` library will not resolve packages with the same | ||
// name as a node built-in module. If we're resolving something | ||
// that's a builtin, and we don't prefer to find built-ins, we | ||
// first try to look up a local module with that name. If we don't | ||
// find anything, we resolve the builtin which just returns back | ||
// the built-in's name. | ||
importSpecifierList.push(`${importee}/`); | ||
} | ||
// TypeScript files may import '.js' to refer to either '.ts' or '.tsx' | ||
if (importer && importee.endsWith('.js')) { | ||
for (const ext of ['.ts', '.tsx']) { | ||
if (importer.endsWith(ext) && extensions.includes(ext)) { | ||
importSpecifierList.push(importee.replace(/.js$/, ext)); | ||
} | ||
const browserImportee = | ||
browser[importee] || | ||
browser[resolvedImportee] || | ||
browser[`${resolvedImportee}.js`] || | ||
browser[`${resolvedImportee}.json`]; | ||
if (browserImportee) { | ||
importee = browserImportee; | ||
} | ||
} | ||
} | ||
const parts = importee.split(/[/\\]/); | ||
let id = parts.shift(); | ||
let isRelativeImport = false; | ||
importSpecifierList.push(importee); | ||
if (id[0] === '@' && parts.length > 0) { | ||
// scoped packages | ||
id += `/${parts.shift()}`; | ||
} else if (id[0] === '.') { | ||
// an import relative to the parent dir of the importer | ||
id = resolve(baseDir, importee); | ||
isRelativeImport = true; | ||
} | ||
const warn = (...args) => context.warn(...args); | ||
const isRequire = | ||
opts && opts.custom && opts.custom['node-resolve'] && opts.custom['node-resolve'].isRequire; | ||
const exportConditions = isRequire ? conditionsCjs : conditionsEsm; | ||
if ( | ||
!isRelativeImport && | ||
resolveOnly.length && | ||
!resolveOnly.some((pattern) => pattern.test(id)) | ||
) { | ||
if (normalizeInput(rollupOptions.input).includes(importee)) { | ||
return null; | ||
if (useBrowserOverrides && !exportConditions.includes('browser')) | ||
exportConditions.push('browser'); | ||
const resolvedWithoutBuiltins = await resolveImportSpecifiers({ | ||
importer, | ||
importSpecifierList, | ||
exportConditions, | ||
warn, | ||
packageInfoCache, | ||
extensions, | ||
mainFields, | ||
preserveSymlinks, | ||
useBrowserOverrides, | ||
baseDir, | ||
moduleDirectories, | ||
rootDir, | ||
ignoreSideEffectsForRoot | ||
}); | ||
const resolved = | ||
importeeIsBuiltin && preferBuiltins | ||
? { | ||
packageInfo: undefined, | ||
hasModuleSideEffects: () => null, | ||
hasPackageEntry: true, | ||
packageBrowserField: false | ||
} | ||
: resolvedWithoutBuiltins; | ||
if (!resolved) { | ||
return null; | ||
} | ||
const { packageInfo, hasModuleSideEffects, hasPackageEntry, packageBrowserField } = resolved; | ||
let { location } = resolved; | ||
if (packageBrowserField) { | ||
if (Object.prototype.hasOwnProperty.call(packageBrowserField, location)) { | ||
if (!packageBrowserField[location]) { | ||
browserMapCache.set(location, packageBrowserField); | ||
return { id: ES6_BROWSER_EMPTY }; | ||
} | ||
return false; | ||
location = packageBrowserField[location]; | ||
} | ||
browserMapCache.set(location, packageBrowserField); | ||
} | ||
const importSpecifierList = []; | ||
if (importer === undefined && !importee[0].match(/^\.?\.?\//)) { | ||
// For module graph roots (i.e. when importer is undefined), we | ||
// need to handle 'path fragments` like `foo/bar` that are commonly | ||
// found in rollup config files. If importee doesn't look like a | ||
// relative or absolute path, we make it relative and attempt to | ||
// resolve it. If we don't find anything, we try resolving it as we | ||
// got it. | ||
importSpecifierList.push(`./${importee}`); | ||
if (hasPackageEntry && !preserveSymlinks) { | ||
const fileExists = await exists(location); | ||
if (fileExists) { | ||
location = await realpath(location); | ||
} | ||
} | ||
const importeeIsBuiltin = builtins.has(importee); | ||
idToPackageInfo.set(location, packageInfo); | ||
if (importeeIsBuiltin) { | ||
// The `resolve` library will not resolve packages with the same | ||
// name as a node built-in module. If we're resolving something | ||
// that's a builtin, and we don't prefer to find built-ins, we | ||
// first try to look up a local module with that name. If we don't | ||
// find anything, we resolve the builtin which just returns back | ||
// the built-in's name. | ||
importSpecifierList.push(`${importee}/`); | ||
if (hasPackageEntry) { | ||
if (importeeIsBuiltin && preferBuiltins) { | ||
if (!isPreferBuiltinsSet && resolvedWithoutBuiltins && resolved !== importee) { | ||
context.warn( | ||
`preferring built-in module '${importee}' over local alternative at '${resolvedWithoutBuiltins.location}', pass 'preferBuiltins: false' to disable this behavior or 'preferBuiltins: true' to disable this warning` | ||
); | ||
} | ||
return false; | ||
} else if (jail && location.indexOf(normalize(jail.trim(sep))) !== 0) { | ||
return null; | ||
} | ||
} | ||
// TypeScript files may import '.js' to refer to either '.ts' or '.tsx' | ||
if (importer && importee.endsWith('.js')) { | ||
for (const ext of ['.ts', '.tsx']) { | ||
if (importer.endsWith(ext) && extensions.includes(ext)) { | ||
importSpecifierList.push(importee.replace(/.js$/, ext)); | ||
} | ||
} | ||
if (options.modulesOnly && (await exists(location))) { | ||
const code = await readFile$1(location, 'utf-8'); | ||
if (isModule(code)) { | ||
return { | ||
id: `${location}${importSuffix}`, | ||
moduleSideEffects: hasModuleSideEffects(location) | ||
}; | ||
} | ||
return null; | ||
} | ||
const result = { | ||
id: `${location}${importSuffix}`, | ||
moduleSideEffects: hasModuleSideEffects(location) | ||
}; | ||
return result; | ||
}; | ||
importSpecifierList.push(importee); | ||
return { | ||
name: 'node-resolve', | ||
const warn = (...args) => this.warn(...args); | ||
const isRequire = | ||
opts && opts.custom && opts.custom['node-resolve'] && opts.custom['node-resolve'].isRequire; | ||
const exportConditions = isRequire ? conditionsCjs : conditionsEsm; | ||
buildStart(options) { | ||
rollupOptions = options; | ||
const resolvedWithoutBuiltins = await resolveImportSpecifiers({ | ||
importer, | ||
importSpecifierList, | ||
exportConditions, | ||
warn, | ||
packageInfoCache, | ||
extensions, | ||
mainFields, | ||
preserveSymlinks, | ||
useBrowserOverrides, | ||
baseDir, | ||
moduleDirectories, | ||
rootDir, | ||
ignoreSideEffectsForRoot | ||
}); | ||
const resolved = | ||
importeeIsBuiltin && preferBuiltins | ||
? { | ||
packageInfo: undefined, | ||
hasModuleSideEffects: () => null, | ||
hasPackageEntry: true, | ||
packageBrowserField: false | ||
} | ||
: resolvedWithoutBuiltins; | ||
if (!resolved) { | ||
return null; | ||
for (const warning of warnings) { | ||
this.warn(warning); | ||
} | ||
const { packageInfo, hasModuleSideEffects, hasPackageEntry, packageBrowserField } = resolved; | ||
let { location } = resolved; | ||
if (packageBrowserField) { | ||
if (Object.prototype.hasOwnProperty.call(packageBrowserField, location)) { | ||
if (!packageBrowserField[location]) { | ||
browserMapCache.set(location, packageBrowserField); | ||
return ES6_BROWSER_EMPTY; | ||
} | ||
location = packageBrowserField[location]; | ||
} | ||
browserMapCache.set(location, packageBrowserField); | ||
({ preserveSymlinks } = options); | ||
}, | ||
generateBundle() { | ||
readCachedFile.clear(); | ||
isFileCached.clear(); | ||
isDirCached.clear(); | ||
}, | ||
async resolveId(importee, importer, opts) { | ||
if (importee === ES6_BROWSER_EMPTY) { | ||
return importee; | ||
} | ||
// ignore IDs with null character, these belong to other plugins | ||
if (/\0/.test(importee)) return null; | ||
if (hasPackageEntry && !preserveSymlinks) { | ||
const fileExists = await exists(location); | ||
if (fileExists) { | ||
location = await realpath(location); | ||
} | ||
if (/\0/.test(importer)) { | ||
importer = undefined; | ||
} | ||
idToPackageInfo.set(location, packageInfo); | ||
if (hasPackageEntry) { | ||
if (importeeIsBuiltin && preferBuiltins) { | ||
if (!isPreferBuiltinsSet && resolvedWithoutBuiltins && resolved !== importee) { | ||
this.warn( | ||
`preferring built-in module '${importee}' over local alternative at '${resolvedWithoutBuiltins.location}', pass 'preferBuiltins: false' to disable this behavior or 'preferBuiltins: true' to disable this warning` | ||
); | ||
} | ||
const resolved = await doResolveId(this, importee, importer, opts); | ||
if (resolved) { | ||
const resolvedResolved = await this.resolve(resolved.id, importer, { skipSelf: true }); | ||
const isExternal = !!(resolvedResolved && resolvedResolved.external); | ||
if (isExternal) { | ||
return false; | ||
} else if (jail && location.indexOf(normalize(jail.trim(sep))) !== 0) { | ||
return null; | ||
} | ||
} | ||
if (options.modulesOnly && (await exists(location))) { | ||
const code = await readFile(location, 'utf-8'); | ||
if (isModule(code)) { | ||
return { | ||
id: `${location}${importSuffix}`, | ||
moduleSideEffects: hasModuleSideEffects(location) | ||
}; | ||
} | ||
return null; | ||
} | ||
const result = { | ||
id: `${location}${importSuffix}`, | ||
moduleSideEffects: hasModuleSideEffects(location) | ||
}; | ||
return result; | ||
return resolved; | ||
}, | ||
@@ -1066,0 +1081,0 @@ |
{ | ||
"name": "@rollup/plugin-node-resolve", | ||
"version": "11.2.1", | ||
"version": "13.0.0", | ||
"publishConfig": { | ||
@@ -9,3 +9,6 @@ "access": "public" | ||
"license": "MIT", | ||
"repository": "rollup/plugins", | ||
"repository": { | ||
"url": "rollup/plugins", | ||
"directory": "packages/node-resolve" | ||
}, | ||
"author": "Rich Harris <richard.a.harris@gmail.com>", | ||
@@ -30,9 +33,5 @@ "homepage": "https://github.com/rollup/plugins/tree/master/packages/node-resolve/#readme", | ||
"ci:test": "pnpm run test -- --verbose && pnpm run test:ts", | ||
"lint": "pnpm run lint:js && pnpm run lint:docs && pnpm run lint:package", | ||
"lint:docs": "prettier --single-quote --arrow-parens avoid --trailing-comma none --write README.md", | ||
"lint:js": "eslint --fix --cache src test types --ext .js,.ts", | ||
"lint:package": "prettier --write package.json --plugin=prettier-plugin-package", | ||
"prebuild": "del-cli dist", | ||
"prepare": "pnpm run build", | ||
"prepublishOnly": "pnpm run lint && pnpm run test && pnpm run test:ts", | ||
"prepublishOnly": "pnpm -w run lint && pnpm run test && pnpm run test:ts", | ||
"pretest": "pnpm run build", | ||
@@ -56,3 +55,3 @@ "test": "ava", | ||
"peerDependencies": { | ||
"rollup": "^1.20.0||^2.0.0" | ||
"rollup": "^2.42.0" | ||
}, | ||
@@ -74,3 +73,3 @@ "dependencies": { | ||
"es5-ext": "^0.10.53", | ||
"rollup": "^2.23.0", | ||
"rollup": "^2.42.0", | ||
"source-map": "^0.7.3", | ||
@@ -77,0 +76,0 @@ "string-capitalize": "^1.0.1" |
@@ -67,3 +67,3 @@ [npm]: https://img.shields.io/npm/v/@rollup/plugin-node-resolve | ||
If `true`, instructs the plugin to use the `"browser"` property in `package.json` files to specify alternative files to load for bundling. This is useful when bundling for a browser environment. Alternatively, a value of `'browser'` can be added to the `mainFields` option. If `false`, any `"browser"` properties in package files will be ignored. This option takes precedence over `mainFields`. | ||
If `true`, instructs the plugin to use the browser module resolutions in `package.json` and adds `'browser'` to `exportConditions` if it is not present so browser conditionals in `exports` are applied. If `false`, any browser properties in package files will be ignored. Alternatively, a value of `'browser'` can be added to both the `mainFields` and `exportConditions` options, however this option takes precedence over `mainFields`. | ||
@@ -70,0 +70,0 @@ > This option does not work when a package is using [package entrypoints](https://nodejs.org/api/packages.html#packages_package_entry_points) |
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
No repository
Supply chain riskPackage does not have a linked source code repository. Without this field, a package will have no reference to the location of the source code use to generate the package.
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
No repository
Supply chain riskPackage does not have a linked source code repository. Without this field, a package will have no reference to the location of the source code use to generate the package.
Found 1 instance in 1 package
88041
1981