@rollup/plugin-node-resolve 6.0.0 → 7.1.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/index.es.js CHANGED
@@ -1,121 +1,152 @@
1
- import { dirname, join, resolve, normalize, sep, extname } from 'path';
2
- import fs, { realpathSync } from 'fs';
1
+ import { dirname, resolve, extname, normalize, sep } from 'path';
3
2
  import builtinList from 'builtin-modules';
4
- import resolveId from 'resolve';
5
3
  import isModule from 'is-module';
4
+ import fs, { realpathSync } from 'fs';
5
+ import { promisify } from 'util';
6
6
  import { createFilter } from '@rollup/pluginutils';
7
+ import resolveModule from 'resolve';
7
8
 
8
- function _slicedToArray(arr, i) {
9
- return _arrayWithHoles(arr) || _iterableToArrayLimit(arr, i) || _nonIterableRest();
10
- }
11
-
12
- function _arrayWithHoles(arr) {
13
- if (Array.isArray(arr)) return arr;
14
- }
15
-
16
- function _iterableToArrayLimit(arr, i) {
17
- if (!(Symbol.iterator in Object(arr) || Object.prototype.toString.call(arr) === "[object Arguments]")) {
9
+ function asyncGeneratorStep(gen, resolve, reject, _next, _throw, key, arg) {
10
+ try {
11
+ var info = gen[key](arg);
12
+ var value = info.value;
13
+ } catch (error) {
14
+ reject(error);
18
15
  return;
19
16
  }
20
17
 
21
- var _arr = [];
22
- var _n = true;
23
- var _d = false;
24
- var _e = undefined;
18
+ if (info.done) {
19
+ resolve(value);
20
+ } else {
21
+ Promise.resolve(value).then(_next, _throw);
22
+ }
23
+ }
25
24
 
26
- try {
27
- for (var _i = arr[Symbol.iterator](), _s; !(_n = (_s = _i.next()).done); _n = true) {
28
- _arr.push(_s.value);
25
+ function _asyncToGenerator(fn) {
26
+ return function () {
27
+ var self = this,
28
+ args = arguments;
29
+ return new Promise(function (resolve, reject) {
30
+ var gen = fn.apply(self, args);
29
31
 
30
- if (i && _arr.length === i) break;
31
- }
32
- } catch (err) {
33
- _d = true;
34
- _e = err;
35
- } finally {
36
- try {
37
- if (!_n && _i["return"] != null) _i["return"]();
38
- } finally {
39
- if (_d) throw _e;
40
- }
41
- }
32
+ function _next(value) {
33
+ asyncGeneratorStep(gen, resolve, reject, _next, _throw, "next", value);
34
+ }
42
35
 
43
- return _arr;
44
- }
36
+ function _throw(err) {
37
+ asyncGeneratorStep(gen, resolve, reject, _next, _throw, "throw", err);
38
+ }
45
39
 
46
- function _nonIterableRest() {
47
- throw new TypeError("Invalid attempt to destructure non-iterable instance");
40
+ _next(undefined);
41
+ });
42
+ };
48
43
  }
49
44
 
50
- var peerDependencies = {
51
- rollup: "^1.20.0"
45
+ const exists = promisify(fs.exists);
46
+ const readFile = promisify(fs.readFile);
47
+ const realpath = promisify(fs.realpath);
48
+ const stat = promisify(fs.stat);
49
+
50
+ const onError = error => {
51
+ if (error.code === 'ENOENT') {
52
+ return false;
53
+ }
54
+
55
+ throw error;
52
56
  };
53
57
 
54
- const builtins = new Set(builtinList);
55
- const ES6_BROWSER_EMPTY = '\0node-resolve:empty.js'; // It is important that .mjs occur before .js so that Rollup will interpret npm modules
56
- // which deploy both ESM .mjs and CommonJS .js files as ESM.
58
+ const makeCache = fn => {
59
+ const cache = new Map();
57
60
 
58
- const DEFAULT_EXTS = ['.mjs', '.js', '.json', '.node'];
61
+ const wrapped =
62
+ /*#__PURE__*/
63
+ function () {
64
+ var _ref = _asyncToGenerator(function* (param, done) {
65
+ if (cache.has(param) === false) {
66
+ cache.set(param, fn(param).catch(err => {
67
+ cache.delete(param);
68
+ throw err;
69
+ }));
70
+ }
59
71
 
60
- const existsAsync = file => new Promise(fulfil => fs.exists(file, fulfil));
72
+ try {
73
+ const result = cache.get(param);
74
+ const value = yield result;
75
+ return done(null, value);
76
+ } catch (error) {
77
+ return done(error);
78
+ }
79
+ });
61
80
 
62
- const readFileAsync = file => new Promise((fulfil, reject) => fs.readFile(file, (err, contents) => err ? reject(err) : fulfil(contents)));
81
+ return function wrapped(_x, _x2) {
82
+ return _ref.apply(this, arguments);
83
+ };
84
+ }();
63
85
 
64
- const realpathAsync = file => new Promise((fulfil, reject) => fs.realpath(file, (err, contents) => err ? reject(err) : fulfil(contents)));
86
+ wrapped.clear = () => cache.clear();
65
87
 
66
- const statAsync = file => new Promise((fulfil, reject) => fs.stat(file, (err, contents) => err ? reject(err) : fulfil(contents)));
88
+ return wrapped;
89
+ };
67
90
 
68
- const cache = fn => {
69
- const cache = new Map();
91
+ const isDirCached = makeCache(
92
+ /*#__PURE__*/
93
+ function () {
94
+ var _ref2 = _asyncToGenerator(function* (file) {
95
+ try {
96
+ const stats = yield stat(file);
97
+ return stats.isDirectory();
98
+ } catch (error) {
99
+ return onError(error);
100
+ }
101
+ });
70
102
 
71
- const wrapped = (param, done) => {
72
- if (cache.has(param) === false) {
73
- cache.set(param, fn(param).catch(err => {
74
- cache.delete(param);
75
- throw err;
76
- }));
103
+ return function (_x3) {
104
+ return _ref2.apply(this, arguments);
105
+ };
106
+ }());
107
+ const isFileCached = makeCache(
108
+ /*#__PURE__*/
109
+ function () {
110
+ var _ref3 = _asyncToGenerator(function* (file) {
111
+ try {
112
+ const stats = yield stat(file);
113
+ return stats.isFile();
114
+ } catch (error) {
115
+ return onError(error);
77
116
  }
117
+ });
78
118
 
79
- return cache.get(param).then(result => done(null, result), done);
119
+ return function (_x4) {
120
+ return _ref3.apply(this, arguments);
80
121
  };
122
+ }());
123
+ const readCachedFile = makeCache(readFile);
81
124
 
82
- wrapped.clear = () => cache.clear();
125
+ const resolveId = promisify(resolveModule); // returns the imported package name for bare module imports
83
126
 
84
- return wrapped;
85
- };
127
+ function getPackageName(id) {
128
+ if (id.startsWith('.') || id.startsWith('/')) {
129
+ return null;
130
+ }
86
131
 
87
- const ignoreENOENT = err => {
88
- if (err.code === 'ENOENT') return false;
89
- throw err;
90
- };
132
+ const split = id.split('/'); // @my-scope/my-package/foo.js -> @my-scope/my-package
133
+ // @my-scope/my-package -> @my-scope/my-package
134
+
135
+ if (split[0][0] === '@') {
136
+ return `${split[0]}/${split[1]}`;
137
+ } // my-package/foo.js -> my-package
138
+ // my-package -> my-package
91
139
 
92
- const readFileCached = cache(readFileAsync);
93
- const isDirCached = cache(file => statAsync(file).then(stat => stat.isDirectory(), ignoreENOENT));
94
- const isFileCached = cache(file => statAsync(file).then(stat => stat.isFile(), ignoreENOENT));
95
140
 
141
+ return split[0];
142
+ }
96
143
  function getMainFields(options) {
97
144
  let mainFields;
98
145
 
99
146
  if (options.mainFields) {
100
- if ('module' in options || 'main' in options || 'jsnext' in options) {
101
- throw new Error(`node-resolve: do not use deprecated 'module', 'main', 'jsnext' options with 'mainFields'`);
102
- }
103
-
104
147
  mainFields = options.mainFields;
105
148
  } else {
106
- mainFields = [];
107
- [['module', 'module', true], ['jsnext', 'jsnext:main', false], ['main', 'main', true]].forEach(([option, field, defaultIncluded]) => {
108
- if (option in options) {
109
- // eslint-disable-next-line no-console
110
- console.warn(`node-resolve: setting options.${option} is deprecated, please override options.mainFields instead`);
111
-
112
- if (options[option]) {
113
- mainFields.push(field);
114
- }
115
- } else if (defaultIncluded) {
116
- mainFields.push(field);
117
- }
118
- });
149
+ mainFields = ['module', 'main'];
119
150
  }
120
151
 
121
152
  if (options.browser && mainFields.indexOf('browser') === -1) {
@@ -123,331 +154,411 @@ function getMainFields(options) {
123
154
  }
124
155
 
125
156
  if (!mainFields.length) {
126
- throw new Error(`Please ensure at least one 'mainFields' value is specified`);
157
+ throw new Error('Please ensure at least one `mainFields` value is specified');
127
158
  }
128
159
 
129
160
  return mainFields;
130
161
  }
162
+ function getPackageInfo(options) {
163
+ const cache = options.cache,
164
+ extensions = options.extensions,
165
+ pkg = options.pkg,
166
+ mainFields = options.mainFields,
167
+ preserveSymlinks = options.preserveSymlinks,
168
+ useBrowserOverrides = options.useBrowserOverrides;
169
+ let pkgPath = options.pkgPath;
170
+
171
+ if (cache.has(pkgPath)) {
172
+ return cache.get(pkgPath);
173
+ } // browserify/resolve doesn't realpath paths returned in its packageFilter callback
174
+
175
+
176
+ if (!preserveSymlinks) {
177
+ pkgPath = realpathSync(pkgPath);
178
+ }
179
+
180
+ const pkgRoot = dirname(pkgPath);
181
+ const packageInfo = {
182
+ // copy as we are about to munge the `main` field of `pkg`.
183
+ packageJson: Object.assign({}, pkg),
184
+ // path to package.json file
185
+ packageJsonPath: pkgPath,
186
+ // directory containing the package.json
187
+ root: pkgRoot,
188
+ // which main field was used during resolution of this module (main, module, or browser)
189
+ resolvedMainField: 'main',
190
+ // whether the browser map was used to resolve the entry point to this module
191
+ browserMappedMain: false,
192
+ // the entry point of the module with respect to the selected main field and any
193
+ // relevant browser mappings.
194
+ resolvedEntryPoint: ''
195
+ };
196
+ let overriddenMain = false;
197
+
198
+ for (let i = 0; i < mainFields.length; i++) {
199
+ const field = mainFields[i];
200
+
201
+ if (typeof pkg[field] === 'string') {
202
+ pkg.main = pkg[field];
203
+ packageInfo.resolvedMainField = field;
204
+ overriddenMain = true;
205
+ break;
206
+ }
207
+ }
208
+
209
+ const internalPackageInfo = {
210
+ cachedPkg: pkg,
211
+ hasModuleSideEffects: () => null,
212
+ hasPackageEntry: overriddenMain !== false || mainFields.indexOf('main') !== -1,
213
+ packageBrowserField: useBrowserOverrides && typeof pkg.browser === 'object' && Object.keys(pkg.browser).reduce((browser, key) => {
214
+ let resolved = pkg.browser[key];
215
+
216
+ if (resolved && resolved[0] === '.') {
217
+ resolved = resolve(pkgRoot, resolved);
218
+ }
219
+ /* eslint-disable no-param-reassign */
220
+
131
221
 
132
- const alwaysNull = () => null;
222
+ browser[key] = resolved;
133
223
 
134
- const resolveIdAsync = (file, opts) => new Promise((fulfil, reject) => resolveId(file, opts, (err, contents) => err ? reject(err) : fulfil(contents))); // Resolve module specifiers in order. Promise resolves to the first
135
- // module that resolves successfully, or the error that resulted from
136
- // the last attempted module resolution.
224
+ if (key[0] === '.') {
225
+ const absoluteKey = resolve(pkgRoot, key);
226
+ browser[absoluteKey] = resolved;
137
227
 
228
+ if (!extname(key)) {
229
+ extensions.reduce((subBrowser, ext) => {
230
+ subBrowser[absoluteKey + ext] = subBrowser[key];
231
+ return subBrowser;
232
+ }, browser);
233
+ }
234
+ }
235
+
236
+ return browser;
237
+ }, {}),
238
+ packageInfo
239
+ };
240
+ const browserMap = internalPackageInfo.packageBrowserField;
241
+
242
+ if (useBrowserOverrides && typeof pkg.browser === 'object' && // eslint-disable-next-line no-prototype-builtins
243
+ browserMap.hasOwnProperty(pkg.main)) {
244
+ packageInfo.resolvedEntryPoint = browserMap[pkg.main];
245
+ packageInfo.browserMappedMain = true;
246
+ } else {
247
+ // index.node is technically a valid default entrypoint as well...
248
+ packageInfo.resolvedEntryPoint = resolve(pkgRoot, pkg.main || 'index.js');
249
+ packageInfo.browserMappedMain = false;
250
+ }
251
+
252
+ const packageSideEffects = pkg.sideEffects;
253
+
254
+ if (typeof packageSideEffects === 'boolean') {
255
+ internalPackageInfo.hasModuleSideEffects = () => packageSideEffects;
256
+ } else if (Array.isArray(packageSideEffects)) {
257
+ internalPackageInfo.hasModuleSideEffects = createFilter(packageSideEffects, null, {
258
+ resolve: pkgRoot
259
+ });
260
+ }
261
+
262
+ cache.set(pkgPath, internalPackageInfo);
263
+ return internalPackageInfo;
264
+ }
265
+ function normalizeInput(input) {
266
+ if (Array.isArray(input)) {
267
+ return input;
268
+ } else if (typeof input === 'object') {
269
+ return Object.values(input);
270
+ } // otherwise it's a string
271
+
272
+
273
+ return input;
274
+ } // Resolve module specifiers in order. Promise resolves to the first module that resolves
275
+ // successfully, or the error that resulted from the last attempted module resolution.
138
276
 
139
277
  function resolveImportSpecifiers(importSpecifierList, resolveOptions) {
140
- let p = Promise.resolve();
278
+ let promise = Promise.resolve();
141
279
 
142
280
  for (let i = 0; i < importSpecifierList.length; i++) {
143
- p = p.then(v => {
281
+ promise = promise.then(value => {
144
282
  // if we've already resolved to something, just return it.
145
- if (v) return v;
146
- return resolveIdAsync(importSpecifierList[i], resolveOptions);
283
+ if (value) {
284
+ return value;
285
+ }
286
+
287
+ return resolveId(importSpecifierList[i], resolveOptions);
147
288
  });
148
289
 
149
290
  if (i < importSpecifierList.length - 1) {
150
291
  // swallow MODULE_NOT_FOUND errors from all but the last resolution
151
- p = p.catch(err => {
152
- if (err.code !== 'MODULE_NOT_FOUND') {
153
- throw err;
292
+ promise = promise.catch(error => {
293
+ if (error.code !== 'MODULE_NOT_FOUND') {
294
+ throw error;
154
295
  }
155
296
  });
156
297
  }
157
298
  }
158
299
 
159
- return p;
300
+ return promise;
160
301
  }
161
302
 
162
- function nodeResolve(options = {}) {
303
+ const builtins = new Set(builtinList);
304
+ const ES6_BROWSER_EMPTY = '\0node-resolve:empty.js';
305
+
306
+ const nullFn = () => null;
307
+
308
+ const defaults = {
309
+ customResolveOptions: {},
310
+ dedupe: [],
311
+ // It's important that .mjs is listed before .js so that Rollup will interpret npm modules
312
+ // which deploy both ESM .mjs and CommonJS .js files as ESM.
313
+ extensions: ['.mjs', '.js', '.json', '.node'],
314
+ resolveOnly: []
315
+ };
316
+ function nodeResolve(opts = {}) {
317
+ const options = Object.assign({}, defaults, opts);
318
+ const customResolveOptions = options.customResolveOptions,
319
+ extensions = options.extensions,
320
+ jail = options.jail;
321
+ const warnings = [];
322
+ const packageInfoCache = new Map();
323
+ const idToPackageInfo = new Map();
163
324
  const mainFields = getMainFields(options);
164
325
  const useBrowserOverrides = mainFields.indexOf('browser') !== -1;
165
- const dedupe = options.dedupe || [];
166
326
  const isPreferBuiltinsSet = options.preferBuiltins === true || options.preferBuiltins === false;
167
327
  const preferBuiltins = isPreferBuiltinsSet ? options.preferBuiltins : true;
168
- const customResolveOptions = options.customResolveOptions || {};
169
- const jail = options.jail;
170
- const only = Array.isArray(options.only) ? options.only.map(o => o instanceof RegExp ? o : new RegExp(`^${String(o).replace(/[\\^$*+?.()|[\]{}]/g, '\\$&')}$`)) : null;
171
- const browserMapCache = new Map();
172
- let preserveSymlinks;
328
+ const rootDir = options.rootDir || process.cwd();
329
+ let dedupe = options.dedupe;
330
+ let rollupOptions;
173
331
 
174
- if (options.skip) {
175
- throw new Error('options.skip is no longer supported you should use the main Rollup `external` option instead');
332
+ if (options.only) {
333
+ warnings.push('node-resolve: The `only` options is deprecated, please use `resolveOnly`');
334
+ options.resolveOnly = options.only;
176
335
  }
177
336
 
178
- const extensions = options.extensions || DEFAULT_EXTS;
179
- const packageInfoCache = new Map();
180
- const idToPackageInfo = new Map();
181
- const shouldDedupe = typeof dedupe === 'function' ? dedupe : importee => dedupe.includes(importee);
182
-
183
- function getCachedPackageInfo(pkg, pkgPath) {
184
- if (packageInfoCache.has(pkgPath)) {
185
- return packageInfoCache.get(pkgPath);
186
- } // browserify/resolve doesn't realpath paths returned in its packageFilter callback
187
-
188
-
189
- if (!preserveSymlinks) {
190
- pkgPath = realpathSync(pkgPath);
191
- }
192
-
193
- const pkgRoot = dirname(pkgPath);
194
- const packageInfo = {
195
- // copy as we are about to munge the `main` field of `pkg`.
196
- packageJson: Object.assign({}, pkg),
197
- // path to package.json file
198
- packageJsonPath: pkgPath,
199
- // directory containing the package.json
200
- root: pkgRoot,
201
- // which main field was used during resolution of this module (main, module, or browser)
202
- resolvedMainField: 'main',
203
- // whether the browser map was used to resolve the entry point to this module
204
- browserMappedMain: false,
205
- // the entry point of the module with respect to the selected main field and any
206
- // relevant browser mappings.
207
- resolvedEntryPoint: ''
208
- };
209
- let overriddenMain = false;
210
-
211
- for (let i = 0; i < mainFields.length; i++) {
212
- const field = mainFields[i];
337
+ if (typeof dedupe !== 'function') {
338
+ dedupe = importee => options.dedupe.includes(importee) || options.dedupe.includes(getPackageName(importee));
339
+ }
213
340
 
214
- if (typeof pkg[field] === 'string') {
215
- pkg.main = pkg[field];
216
- packageInfo.resolvedMainField = field;
217
- overriddenMain = true;
218
- break;
219
- }
341
+ const resolveOnly = options.resolveOnly.map(pattern => {
342
+ if (pattern instanceof RegExp) {
343
+ return pattern;
220
344
  }
221
345
 
222
- const internalPackageInfo = {
223
- cachedPkg: pkg,
224
- hasModuleSideEffects: alwaysNull,
225
- hasPackageEntry: overriddenMain !== false || mainFields.indexOf('main') !== -1,
226
- packageBrowserField: useBrowserOverrides && typeof pkg.browser === 'object' && Object.keys(pkg.browser).reduce((browser, key) => {
227
- let resolved = pkg.browser[key];
346
+ const normalized = pattern.replace(/[\\^$*+?.()|[\]{}]/g, '\\$&');
347
+ return new RegExp(`^${normalized}$`);
348
+ });
349
+ const browserMapCache = new Map();
350
+ let preserveSymlinks;
351
+ return {
352
+ name: 'node-resolve',
228
353
 
229
- if (resolved && resolved[0] === '.') {
230
- resolved = resolve(pkgRoot, resolved);
354
+ buildStart(options) {
355
+ rollupOptions = options;
356
+ var _iteratorNormalCompletion = true;
357
+ var _didIteratorError = false;
358
+ var _iteratorError = undefined;
359
+
360
+ try {
361
+ for (var _iterator = warnings[Symbol.iterator](), _step; !(_iteratorNormalCompletion = (_step = _iterator.next()).done); _iteratorNormalCompletion = true) {
362
+ const warning = _step.value;
363
+ this.warn(warning);
231
364
  }
232
-
233
- browser[key] = resolved;
234
-
235
- if (key[0] === '.') {
236
- const absoluteKey = resolve(pkgRoot, key);
237
- browser[absoluteKey] = resolved;
238
-
239
- if (!extname(key)) {
240
- extensions.reduce((browser, ext) => {
241
- browser[absoluteKey + ext] = browser[key];
242
- return browser;
243
- }, browser);
365
+ } catch (err) {
366
+ _didIteratorError = true;
367
+ _iteratorError = err;
368
+ } finally {
369
+ try {
370
+ if (!_iteratorNormalCompletion && _iterator.return != null) {
371
+ _iterator.return();
372
+ }
373
+ } finally {
374
+ if (_didIteratorError) {
375
+ throw _iteratorError;
244
376
  }
245
377
  }
378
+ }
246
379
 
247
- return browser;
248
- }, {}),
249
- packageInfo
250
- };
251
- const browserMap = internalPackageInfo.packageBrowserField;
252
-
253
- if (useBrowserOverrides && typeof pkg.browser === 'object' && // eslint-disable-next-line no-prototype-builtins
254
- browserMap.hasOwnProperty(pkg.main)) {
255
- packageInfo.resolvedEntryPoint = browserMap[pkg.main];
256
- packageInfo.browserMappedMain = true;
257
- } else {
258
- // index.node is technically a valid default entrypoint as well...
259
- packageInfo.resolvedEntryPoint = resolve(pkgRoot, pkg.main || 'index.js');
260
- packageInfo.browserMappedMain = false;
261
- }
380
+ preserveSymlinks = options.preserveSymlinks;
381
+ },
262
382
 
263
- const packageSideEffects = pkg.sideEffects;
383
+ generateBundle() {
384
+ readCachedFile.clear();
385
+ isFileCached.clear();
386
+ isDirCached.clear();
387
+ },
264
388
 
265
- if (typeof packageSideEffects === 'boolean') {
266
- internalPackageInfo.hasModuleSideEffects = () => packageSideEffects;
267
- } else if (Array.isArray(packageSideEffects)) {
268
- internalPackageInfo.hasModuleSideEffects = createFilter(packageSideEffects, null, {
269
- resolve: pkgRoot
270
- });
271
- }
389
+ resolveId(importee, importer) {
390
+ var _this = this;
272
391
 
273
- packageInfoCache.set(pkgPath, internalPackageInfo);
274
- return internalPackageInfo;
275
- }
392
+ return _asyncToGenerator(function* () {
393
+ if (importee === ES6_BROWSER_EMPTY) {
394
+ return importee;
395
+ } // ignore IDs with null character, these belong to other plugins
276
396
 
277
- return {
278
- name: 'node-resolve',
279
397
 
280
- buildStart(options) {
281
- preserveSymlinks = options.preserveSymlinks;
398
+ if (/\0/.test(importee)) return null;
399
+ const basedir = !importer || dedupe(importee) ? rootDir : dirname(importer); // https://github.com/defunctzombie/package-browser-field-spec
282
400
 
283
- const _this$meta$rollupVers = this.meta.rollupVersion.split('.').map(Number),
284
- _this$meta$rollupVers2 = _slicedToArray(_this$meta$rollupVers, 2),
285
- major = _this$meta$rollupVers2[0],
286
- minor = _this$meta$rollupVers2[1];
401
+ const browser = browserMapCache.get(importer);
287
402
 
288
- const minVersion = peerDependencies.rollup.slice(2);
403
+ if (useBrowserOverrides && browser) {
404
+ const resolvedImportee = resolve(basedir, importee);
289
405
 
290
- const _minVersion$split$map = minVersion.split('.').map(Number),
291
- _minVersion$split$map2 = _slicedToArray(_minVersion$split$map, 2),
292
- minMajor = _minVersion$split$map2[0],
293
- minMinor = _minVersion$split$map2[1];
406
+ if (browser[importee] === false || browser[resolvedImportee] === false) {
407
+ return ES6_BROWSER_EMPTY;
408
+ }
294
409
 
295
- if (major < minMajor || major === minMajor && minor < minMinor) {
296
- this.error(`Insufficient Rollup version: "rollup-plugin-node-resolve" requires at least rollup@${minVersion} but found rollup@${this.meta.rollupVersion}.`);
297
- }
298
- },
410
+ const browserImportee = browser[importee] || browser[resolvedImportee] || browser[`${resolvedImportee}.js`] || browser[`${resolvedImportee}.json`];
299
411
 
300
- generateBundle() {
301
- readFileCached.clear();
302
- isFileCached.clear();
303
- isDirCached.clear();
304
- },
412
+ if (browserImportee) {
413
+ importee = browserImportee;
414
+ }
415
+ }
305
416
 
306
- resolveId(importee, importer) {
307
- if (importee === ES6_BROWSER_EMPTY) {
308
- return importee;
309
- } // ignore IDs with null character, these belong to other plugins
417
+ const parts = importee.split(/[/\\]/);
418
+ let id = parts.shift();
310
419
 
420
+ if (id[0] === '@' && parts.length > 0) {
421
+ // scoped packages
422
+ id += `/${parts.shift()}`;
423
+ } else if (id[0] === '.') {
424
+ // an import relative to the parent dir of the importer
425
+ id = resolve(basedir, importee);
426
+ }
311
427
 
312
- if (/\0/.test(importee)) return null;
313
- const basedir = importer ? dirname(importer) : process.cwd();
428
+ const input = normalizeInput(rollupOptions.input);
314
429
 
315
- if (shouldDedupe(importee)) {
316
- importee = join(process.cwd(), 'node_modules', importee);
317
- } // https://github.com/defunctzombie/package-browser-field-spec
430
+ if (resolveOnly.length && !resolveOnly.some(pattern => pattern.test(id))) {
431
+ if (input.includes(id)) {
432
+ return null;
433
+ }
318
434
 
435
+ return false;
436
+ }
319
437
 
320
- const browser = browserMapCache.get(importer);
438
+ let hasModuleSideEffects = nullFn;
439
+ let hasPackageEntry = true;
440
+ let packageBrowserField = false;
441
+ let packageInfo;
442
+
443
+ const filter = (pkg, pkgPath) => {
444
+ const info = getPackageInfo({
445
+ cache: packageInfoCache,
446
+ extensions,
447
+ pkg,
448
+ pkgPath,
449
+ mainFields,
450
+ preserveSymlinks,
451
+ useBrowserOverrides
452
+ });
453
+ packageInfo = info.packageInfo;
454
+ hasModuleSideEffects = info.hasModuleSideEffects;
455
+ hasPackageEntry = info.hasPackageEntry;
456
+ packageBrowserField = info.packageBrowserField;
457
+ return info.cachedPkg;
458
+ };
321
459
 
322
- if (useBrowserOverrides && browser) {
323
- const resolvedImportee = resolve(basedir, importee);
460
+ let resolveOptions = {
461
+ basedir,
462
+ packageFilter: filter,
463
+ readFile: readCachedFile,
464
+ isFile: isFileCached,
465
+ isDirectory: isDirCached,
466
+ extensions
467
+ };
324
468
 
325
- if (browser[importee] === false || browser[resolvedImportee] === false) {
326
- return ES6_BROWSER_EMPTY;
469
+ if (preserveSymlinks !== undefined) {
470
+ resolveOptions.preserveSymlinks = preserveSymlinks;
327
471
  }
328
472
 
329
- const browserImportee = browser[importee] || browser[resolvedImportee] || browser[`${resolvedImportee}.js`] || browser[`${resolvedImportee}.json`];
473
+ const importSpecifierList = [];
330
474
 
331
- if (browserImportee) {
332
- importee = browserImportee;
475
+ if (importer === undefined && !importee[0].match(/^\.?\.?\//)) {
476
+ // For module graph roots (i.e. when importer is undefined), we
477
+ // need to handle 'path fragments` like `foo/bar` that are commonly
478
+ // found in rollup config files. If importee doesn't look like a
479
+ // relative or absolute path, we make it relative and attempt to
480
+ // resolve it. If we don't find anything, we try resolving it as we
481
+ // got it.
482
+ importSpecifierList.push(`./${importee}`);
333
483
  }
334
- }
335
484
 
336
- const parts = importee.split(/[/\\]/);
337
- let id = parts.shift();
485
+ const importeeIsBuiltin = builtins.has(importee);
338
486
 
339
- if (id[0] === '@' && parts.length > 0) {
340
- // scoped packages
341
- id += `/${parts.shift()}`;
342
- } else if (id[0] === '.') {
343
- // an import relative to the parent dir of the importer
344
- id = resolve(basedir, importee);
345
- }
487
+ if (importeeIsBuiltin && (!preferBuiltins || !isPreferBuiltinsSet)) {
488
+ // The `resolve` library will not resolve packages with the same
489
+ // name as a node built-in module. If we're resolving something
490
+ // that's a builtin, and we don't prefer to find built-ins, we
491
+ // first try to look up a local module with that name. If we don't
492
+ // find anything, we resolve the builtin which just returns back
493
+ // the built-in's name.
494
+ importSpecifierList.push(`${importee}/`);
495
+ }
346
496
 
347
- if (only && !only.some(pattern => pattern.test(id))) return null;
348
- let hasModuleSideEffects = alwaysNull;
349
- let hasPackageEntry = true;
350
- let packageBrowserField = false;
351
- let packageInfo;
352
- const resolveOptions = {
353
- basedir,
354
-
355
- packageFilter(pkg, pkgPath) {
356
- let cachedPkg;
357
-
358
- var _getCachedPackageInfo = getCachedPackageInfo(pkg, pkgPath);
359
-
360
- packageInfo = _getCachedPackageInfo.packageInfo;
361
- cachedPkg = _getCachedPackageInfo.cachedPkg;
362
- hasModuleSideEffects = _getCachedPackageInfo.hasModuleSideEffects;
363
- hasPackageEntry = _getCachedPackageInfo.hasPackageEntry;
364
- packageBrowserField = _getCachedPackageInfo.packageBrowserField;
365
- return cachedPkg;
366
- },
367
-
368
- readFile: readFileCached,
369
- isFile: isFileCached,
370
- isDirectory: isDirCached,
371
- extensions
372
- };
373
-
374
- if (preserveSymlinks !== undefined) {
375
- resolveOptions.preserveSymlinks = preserveSymlinks;
376
- }
497
+ importSpecifierList.push(importee);
498
+ resolveOptions = Object.assign(resolveOptions, customResolveOptions);
377
499
 
378
- const importSpecifierList = [];
500
+ try {
501
+ let resolved = yield resolveImportSpecifiers(importSpecifierList, resolveOptions);
379
502
 
380
- if (importer === undefined && !importee[0].match(/^\.?\.?\//)) {
381
- // For module graph roots (i.e. when importer is undefined), we
382
- // need to handle 'path fragments` like `foo/bar` that are commonly
383
- // found in rollup config files. If importee doesn't look like a
384
- // relative or absolute path, we make it relative and attempt to
385
- // resolve it. If we don't find anything, we try resolving it as we
386
- // got it.
387
- importSpecifierList.push(`./${importee}`);
388
- }
503
+ if (resolved && packageBrowserField) {
504
+ if (Object.prototype.hasOwnProperty.call(packageBrowserField, resolved)) {
505
+ if (!packageBrowserField[resolved]) {
506
+ browserMapCache.set(resolved, packageBrowserField);
507
+ return ES6_BROWSER_EMPTY;
508
+ }
389
509
 
390
- const importeeIsBuiltin = builtins.has(importee);
510
+ resolved = packageBrowserField[resolved];
511
+ }
391
512
 
392
- if (importeeIsBuiltin && (!preferBuiltins || !isPreferBuiltinsSet)) {
393
- // The `resolve` library will not resolve packages with the same
394
- // name as a node built-in module. If we're resolving something
395
- // that's a builtin, and we don't prefer to find built-ins, we
396
- // first try to look up a local module with that name. If we don't
397
- // find anything, we resolve the builtin which just returns back
398
- // the built-in's name.
399
- importSpecifierList.push(`${importee}/`);
400
- }
513
+ browserMapCache.set(resolved, packageBrowserField);
514
+ }
401
515
 
402
- importSpecifierList.push(importee);
403
- return resolveImportSpecifiers(importSpecifierList, Object.assign(resolveOptions, customResolveOptions)).then(resolved => {
404
- if (resolved && packageBrowserField) {
405
- if (Object.prototype.hasOwnProperty.call(packageBrowserField, resolved)) {
406
- if (!packageBrowserField[resolved]) {
407
- browserMapCache.set(resolved, packageBrowserField);
408
- return ES6_BROWSER_EMPTY;
409
- }
516
+ if (hasPackageEntry && !preserveSymlinks && resolved) {
517
+ const fileExists = yield exists(resolved);
410
518
 
411
- resolved = packageBrowserField[resolved];
519
+ if (fileExists) {
520
+ resolved = yield realpath(resolved);
521
+ }
412
522
  }
413
523
 
414
- browserMapCache.set(resolved, packageBrowserField);
415
- }
524
+ idToPackageInfo.set(resolved, packageInfo);
416
525
 
417
- if (hasPackageEntry && !preserveSymlinks && resolved) {
418
- return existsAsync(resolved).then(exists => exists ? realpathAsync(resolved) : resolved);
419
- }
526
+ if (hasPackageEntry) {
527
+ if (builtins.has(resolved) && preferBuiltins && isPreferBuiltinsSet) {
528
+ return null;
529
+ } else if (importeeIsBuiltin && preferBuiltins) {
530
+ if (!isPreferBuiltinsSet) {
531
+ _this.warn(`preferring built-in module '${importee}' over local alternative at '${resolved}', pass 'preferBuiltins: false' to disable this behavior or 'preferBuiltins: true' to disable this warning`);
532
+ }
420
533
 
421
- return resolved;
422
- }).then(resolved => {
423
- idToPackageInfo.set(resolved, packageInfo);
534
+ return null;
535
+ } else if (jail && resolved.indexOf(normalize(jail.trim(sep))) !== 0) {
536
+ return null;
537
+ }
538
+ }
424
539
 
425
- if (hasPackageEntry) {
426
- if (builtins.has(resolved) && preferBuiltins && isPreferBuiltinsSet) {
427
- return null;
428
- } else if (importeeIsBuiltin && preferBuiltins) {
429
- if (!isPreferBuiltinsSet) {
430
- this.warn(`preferring built-in module '${importee}' over local alternative ` + `at '${resolved}', pass 'preferBuiltins: false' to disable this ` + `behavior or 'preferBuiltins: true' to disable this warning`);
540
+ if (resolved && options.modulesOnly) {
541
+ const code = yield readFile(resolved, 'utf-8');
542
+
543
+ if (isModule(code)) {
544
+ return {
545
+ id: resolved,
546
+ moduleSideEffects: hasModuleSideEffects(resolved)
547
+ };
431
548
  }
432
549
 
433
- return null;
434
- } else if (jail && resolved.indexOf(normalize(jail.trim(sep))) !== 0) {
435
550
  return null;
436
551
  }
437
- }
438
552
 
439
- if (resolved && options.modulesOnly) {
440
- return readFileAsync(resolved).then(code => isModule(code) ? {
553
+ const result = {
441
554
  id: resolved,
442
555
  moduleSideEffects: hasModuleSideEffects(resolved)
443
- } : null);
556
+ };
557
+ return result;
558
+ } catch (error) {
559
+ return null;
444
560
  }
445
-
446
- return {
447
- id: resolved,
448
- moduleSideEffects: hasModuleSideEffects(resolved)
449
- };
450
- }).catch(() => null);
561
+ })();
451
562
  },
452
563
 
453
564
  load(importee) {