(opts = {})
| 48 | export const DEFAULTS = deepFreeze(deepMerge({}, defaults)); |
| 49 | |
| 50 | export function nodeResolve(opts = {}) { |
| 51 | const { warnings } = handleDeprecatedOptions(opts); |
| 52 | |
| 53 | const options = { ...defaults, ...opts }; |
| 54 | const { extensions, jail, moduleDirectories, modulePaths, ignoreSideEffectsForRoot } = options; |
| 55 | const exportConditions = options.exportConditions || []; |
| 56 | const devProdCondition = |
| 57 | exportConditions.includes('development') || exportConditions.includes('production') |
| 58 | ? [] |
| 59 | : [ |
| 60 | process.env.NODE_ENV && process.env.NODE_ENV !== 'production' |
| 61 | ? 'development' |
| 62 | : 'production' |
| 63 | ]; |
| 64 | const conditionsEsm = [...baseConditionsEsm, ...exportConditions, ...devProdCondition]; |
| 65 | const conditionsCjs = [...baseConditionsCjs, ...exportConditions, ...devProdCondition]; |
| 66 | const packageInfoCache = new Map(); |
| 67 | const idToPackageInfo = new Map(); |
| 68 | const mainFields = getMainFields(options); |
| 69 | const useBrowserOverrides = mainFields.indexOf('browser') !== -1; |
| 70 | const isPreferBuiltinsSet = Object.prototype.hasOwnProperty.call(options, 'preferBuiltins'); |
| 71 | const preferBuiltins = isPreferBuiltinsSet ? options.preferBuiltins : true; |
| 72 | const rootDir = resolve(options.rootDir || process.cwd()); |
| 73 | let { dedupe } = options; |
| 74 | let rollupOptions; |
| 75 | |
| 76 | if (moduleDirectories.some((name) => name.includes('/'))) { |
| 77 | throw new Error( |
| 78 | '`moduleDirectories` option must only contain directory names. If you want to load modules from somewhere not supported by the default module resolution algorithm, see `modulePaths`.' |
| 79 | ); |
| 80 | } |
| 81 | |
| 82 | if (typeof dedupe !== 'function') { |
| 83 | dedupe = (importee) => |
| 84 | options.dedupe.includes(importee) || options.dedupe.includes(getPackageName(importee)); |
| 85 | } |
| 86 | |
| 87 | // creates a function from the patterns to test if a particular module should be bundled. |
| 88 | const allowPatterns = (patterns) => { |
| 89 | const regexPatterns = patterns.map((pattern) => { |
| 90 | if (pattern instanceof RegExp) { |
| 91 | return pattern; |
| 92 | } |
| 93 | const normalized = pattern.replace(/[\\^$*+?.()|[\]{}]/g, '\\$&'); |
| 94 | return new RegExp(`^${normalized}$`); |
| 95 | }); |
| 96 | return (id) => !regexPatterns.length || regexPatterns.some((pattern) => pattern.test(id)); |
| 97 | }; |
| 98 | |
| 99 | const resolveOnly = |
| 100 | typeof options.resolveOnly === 'function' |
| 101 | ? options.resolveOnly |
| 102 | : allowPatterns(options.resolveOnly); |
| 103 | |
| 104 | const browserMapCache = new Map(); |
| 105 | let preserveSymlinks; |
| 106 | |
| 107 | const resolveLikeNode = async (context, importee, importer, custom) => { |
no test coverage detected