@rollup/plugin-node-resolve 9.0.0 → 10.0.0

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/CHANGELOG.md CHANGED
@@ -1,5 +1,17 @@
1
1
  # @rollup/plugin-node-resolve ChangeLog
2
2
 
3
+ ## v10.0.0
4
+
5
+ _2020-10-27_
6
+
7
+ ### Breaking Changes
8
+
9
+ - fix!: resolve hash in path (#588)
10
+
11
+ ### Bugfixes
12
+
13
+ - fix: do not ignore exceptions (#564)
14
+
3
15
  ## v9.0.0
4
16
 
5
17
  _2020-08-13_
package/dist/cjs/index.js CHANGED
@@ -2,22 +2,27 @@
2
2
 
3
3
  Object.defineProperty(exports, '__esModule', { value: true });
4
4
 
5
- function _interopDefault (ex) { return (ex && (typeof ex === 'object') && 'default' in ex) ? ex['default'] : ex; }
6
-
7
5
  var path = require('path');
8
- var builtinList = _interopDefault(require('builtin-modules'));
9
- var deepMerge = _interopDefault(require('deepmerge'));
10
- var isModule = _interopDefault(require('is-module'));
6
+ var builtinList = require('builtin-modules');
7
+ var deepMerge = require('deepmerge');
8
+ var isModule = require('is-module');
11
9
  var fs = require('fs');
12
- var fs__default = _interopDefault(fs);
13
10
  var util = require('util');
14
11
  var pluginutils = require('@rollup/pluginutils');
15
- var resolveModule = _interopDefault(require('resolve'));
12
+ var resolveModule = require('resolve');
13
+
14
+ function _interopDefaultLegacy (e) { return e && typeof e === 'object' && 'default' in e ? e : { 'default': e }; }
15
+
16
+ var builtinList__default = /*#__PURE__*/_interopDefaultLegacy(builtinList);
17
+ var deepMerge__default = /*#__PURE__*/_interopDefaultLegacy(deepMerge);
18
+ var isModule__default = /*#__PURE__*/_interopDefaultLegacy(isModule);
19
+ var fs__default = /*#__PURE__*/_interopDefaultLegacy(fs);
20
+ var resolveModule__default = /*#__PURE__*/_interopDefaultLegacy(resolveModule);
16
21
 
17
- const exists = util.promisify(fs__default.exists);
18
- const readFile = util.promisify(fs__default.readFile);
19
- const realpath = util.promisify(fs__default.realpath);
20
- const stat = util.promisify(fs__default.stat);
22
+ const exists = util.promisify(fs__default['default'].exists);
23
+ const readFile = util.promisify(fs__default['default'].readFile);
24
+ const realpath = util.promisify(fs__default['default'].realpath);
25
+ const stat = util.promisify(fs__default['default'].stat);
21
26
 
22
27
  const onError = (error) => {
23
28
  if (error.code === 'ENOENT') {
@@ -73,7 +78,7 @@ const isFileCached = makeCache(async (file) => {
73
78
 
74
79
  const readCachedFile = makeCache(readFile);
75
80
 
76
- const resolveId = util.promisify(resolveModule);
81
+ const resolveId = util.promisify(resolveModule__default['default']);
77
82
 
78
83
  // returns the imported package name for bare module imports
79
84
  function getPackageName(id) {
@@ -231,28 +236,28 @@ function resolveImportSpecifiers(importSpecifierList, resolveOptions) {
231
236
  let promise = Promise.resolve();
232
237
 
233
238
  for (let i = 0; i < importSpecifierList.length; i++) {
234
- promise = promise.then((value) => {
239
+ // eslint-disable-next-line no-loop-func
240
+ promise = promise.then(async (value) => {
235
241
  // if we've already resolved to something, just return it.
236
242
  if (value) {
237
243
  return value;
238
244
  }
239
245
 
240
- return resolveId(importSpecifierList[i], resolveOptions).then((result) => {
241
- if (!resolveOptions.preserveSymlinks) {
242
- result = fs.realpathSync(result);
246
+ let result = await resolveId(importSpecifierList[i], resolveOptions);
247
+ if (!resolveOptions.preserveSymlinks) {
248
+ if (await exists(result)) {
249
+ result = await realpath(result);
243
250
  }
244
- return result;
245
- });
251
+ }
252
+ return result;
246
253
  });
247
254
 
248
- if (i < importSpecifierList.length - 1) {
249
- // swallow MODULE_NOT_FOUND errors from all but the last resolution
250
- promise = promise.catch((error) => {
251
- if (error.code !== 'MODULE_NOT_FOUND') {
252
- throw error;
253
- }
254
- });
255
- }
255
+ // swallow MODULE_NOT_FOUND errors
256
+ promise = promise.catch((error) => {
257
+ if (error.code !== 'MODULE_NOT_FOUND') {
258
+ throw error;
259
+ }
260
+ });
256
261
  }
257
262
 
258
263
  return promise;
@@ -260,7 +265,7 @@ function resolveImportSpecifiers(importSpecifierList, resolveOptions) {
260
265
 
261
266
  /* eslint-disable no-param-reassign, no-shadow, no-undefined */
262
267
 
263
- const builtins = new Set(builtinList);
268
+ const builtins = new Set(builtinList__default['default']);
264
269
  const ES6_BROWSER_EMPTY = '\0node-resolve:empty.js';
265
270
  const nullFn = () => null;
266
271
  const deepFreeze = (object) => {
@@ -282,7 +287,7 @@ const defaults = {
282
287
  extensions: ['.mjs', '.js', '.json', '.node'],
283
288
  resolveOnly: []
284
289
  };
285
- const DEFAULTS = deepFreeze(deepMerge({}, defaults));
290
+ const DEFAULTS = deepFreeze(deepMerge__default['default']({}, defaults));
286
291
 
287
292
  function nodeResolve(opts = {}) {
288
293
  const options = Object.assign({}, defaults, opts);
@@ -345,10 +350,13 @@ function nodeResolve(opts = {}) {
345
350
  // ignore IDs with null character, these belong to other plugins
346
351
  if (/\0/.test(importee)) return null;
347
352
 
348
- // strip hash and query params from import
349
- const [withoutHash, hash] = importee.split('#');
350
- const [importPath, params] = withoutHash.split('?');
351
- const importSuffix = `${params ? `?${params}` : ''}${hash ? `#${hash}` : ''}`;
353
+ if (/\0/.test(importer)) {
354
+ importer = undefined;
355
+ }
356
+
357
+ // strip query params from import
358
+ const [importPath, params] = importee.split('?');
359
+ const importSuffix = `${params ? `?${params}` : ''}`;
352
360
  importee = importPath;
353
361
 
354
362
  const basedir = !importer || dedupe(importee) ? rootDir : path.dirname(importer);
@@ -464,62 +472,61 @@ function nodeResolve(opts = {}) {
464
472
  importSpecifierList.push(importee);
465
473
  resolveOptions = Object.assign(resolveOptions, customResolveOptions);
466
474
 
467
- try {
468
- let resolved = await resolveImportSpecifiers(importSpecifierList, resolveOptions);
475
+ let resolved = await resolveImportSpecifiers(importSpecifierList, resolveOptions);
476
+ if (!resolved) {
477
+ return null;
478
+ }
469
479
 
470
- if (resolved && packageBrowserField) {
471
- if (Object.prototype.hasOwnProperty.call(packageBrowserField, resolved)) {
472
- if (!packageBrowserField[resolved]) {
473
- browserMapCache.set(resolved, packageBrowserField);
474
- return ES6_BROWSER_EMPTY;
475
- }
476
- resolved = packageBrowserField[resolved];
480
+ if (packageBrowserField) {
481
+ if (Object.prototype.hasOwnProperty.call(packageBrowserField, resolved)) {
482
+ if (!packageBrowserField[resolved]) {
483
+ browserMapCache.set(resolved, packageBrowserField);
484
+ return ES6_BROWSER_EMPTY;
477
485
  }
478
- browserMapCache.set(resolved, packageBrowserField);
486
+ resolved = packageBrowserField[resolved];
479
487
  }
488
+ browserMapCache.set(resolved, packageBrowserField);
489
+ }
480
490
 
481
- if (hasPackageEntry && !preserveSymlinks && resolved) {
482
- const fileExists = await exists(resolved);
483
- if (fileExists) {
484
- resolved = await realpath(resolved);
485
- }
491
+ if (hasPackageEntry && !preserveSymlinks) {
492
+ const fileExists = await exists(resolved);
493
+ if (fileExists) {
494
+ resolved = await realpath(resolved);
486
495
  }
496
+ }
487
497
 
488
- idToPackageInfo.set(resolved, packageInfo);
489
-
490
- if (hasPackageEntry) {
491
- if (builtins.has(resolved) && preferBuiltins && isPreferBuiltinsSet) {
492
- return null;
493
- } else if (importeeIsBuiltin && preferBuiltins) {
494
- if (!isPreferBuiltinsSet) {
495
- this.warn(
496
- `preferring built-in module '${importee}' over local alternative at '${resolved}', pass 'preferBuiltins: false' to disable this behavior or 'preferBuiltins: true' to disable this warning`
497
- );
498
- }
499
- return null;
500
- } else if (jail && resolved.indexOf(path.normalize(jail.trim(path.sep))) !== 0) {
501
- return null;
502
- }
503
- }
498
+ idToPackageInfo.set(resolved, packageInfo);
504
499
 
505
- if (resolved && options.modulesOnly) {
506
- const code = await readFile(resolved, 'utf-8');
507
- if (isModule(code)) {
508
- return {
509
- id: `${resolved}${importSuffix}`,
510
- moduleSideEffects: hasModuleSideEffects(resolved)
511
- };
500
+ if (hasPackageEntry) {
501
+ if (builtins.has(resolved) && preferBuiltins && isPreferBuiltinsSet) {
502
+ return null;
503
+ } else if (importeeIsBuiltin && preferBuiltins) {
504
+ if (!isPreferBuiltinsSet) {
505
+ this.warn(
506
+ `preferring built-in module '${importee}' over local alternative at '${resolved}', pass 'preferBuiltins: false' to disable this behavior or 'preferBuiltins: true' to disable this warning`
507
+ );
512
508
  }
513
509
  return null;
510
+ } else if (jail && resolved.indexOf(path.normalize(jail.trim(path.sep))) !== 0) {
511
+ return null;
512
+ }
513
+ }
514
+
515
+ if (options.modulesOnly && (await exists(resolved))) {
516
+ const code = await readFile(resolved, 'utf-8');
517
+ if (isModule__default['default'](code)) {
518
+ return {
519
+ id: `${resolved}${importSuffix}`,
520
+ moduleSideEffects: hasModuleSideEffects(resolved)
521
+ };
514
522
  }
515
- const result = {
516
- id: `${resolved}${importSuffix}`,
517
- moduleSideEffects: hasModuleSideEffects(resolved)
518
- };
519
- return result;
520
- } catch (error) {
521
523
  return null;
522
524
  }
525
+ const result = {
526
+ id: `${resolved}${importSuffix}`,
527
+ moduleSideEffects: hasModuleSideEffects(resolved)
528
+ };
529
+ return result;
523
530
  },
524
531
 
525
532
  load(importee) {
package/dist/es/index.js CHANGED
@@ -224,28 +224,28 @@ function resolveImportSpecifiers(importSpecifierList, resolveOptions) {
224
224
  let promise = Promise.resolve();
225
225
 
226
226
  for (let i = 0; i < importSpecifierList.length; i++) {
227
- promise = promise.then((value) => {
227
+ // eslint-disable-next-line no-loop-func
228
+ promise = promise.then(async (value) => {
228
229
  // if we've already resolved to something, just return it.
229
230
  if (value) {
230
231
  return value;
231
232
  }
232
233
 
233
- return resolveId(importSpecifierList[i], resolveOptions).then((result) => {
234
- if (!resolveOptions.preserveSymlinks) {
235
- result = realpathSync(result);
234
+ let result = await resolveId(importSpecifierList[i], resolveOptions);
235
+ if (!resolveOptions.preserveSymlinks) {
236
+ if (await exists(result)) {
237
+ result = await realpath(result);
236
238
  }
237
- return result;
238
- });
239
+ }
240
+ return result;
239
241
  });
240
242
 
241
- if (i < importSpecifierList.length - 1) {
242
- // swallow MODULE_NOT_FOUND errors from all but the last resolution
243
- promise = promise.catch((error) => {
244
- if (error.code !== 'MODULE_NOT_FOUND') {
245
- throw error;
246
- }
247
- });
248
- }
243
+ // swallow MODULE_NOT_FOUND errors
244
+ promise = promise.catch((error) => {
245
+ if (error.code !== 'MODULE_NOT_FOUND') {
246
+ throw error;
247
+ }
248
+ });
249
249
  }
250
250
 
251
251
  return promise;
@@ -338,10 +338,13 @@ function nodeResolve(opts = {}) {
338
338
  // ignore IDs with null character, these belong to other plugins
339
339
  if (/\0/.test(importee)) return null;
340
340
 
341
- // strip hash and query params from import
342
- const [withoutHash, hash] = importee.split('#');
343
- const [importPath, params] = withoutHash.split('?');
344
- const importSuffix = `${params ? `?${params}` : ''}${hash ? `#${hash}` : ''}`;
341
+ if (/\0/.test(importer)) {
342
+ importer = undefined;
343
+ }
344
+
345
+ // strip query params from import
346
+ const [importPath, params] = importee.split('?');
347
+ const importSuffix = `${params ? `?${params}` : ''}`;
345
348
  importee = importPath;
346
349
 
347
350
  const basedir = !importer || dedupe(importee) ? rootDir : dirname(importer);
@@ -457,62 +460,61 @@ function nodeResolve(opts = {}) {
457
460
  importSpecifierList.push(importee);
458
461
  resolveOptions = Object.assign(resolveOptions, customResolveOptions);
459
462
 
460
- try {
461
- let resolved = await resolveImportSpecifiers(importSpecifierList, resolveOptions);
463
+ let resolved = await resolveImportSpecifiers(importSpecifierList, resolveOptions);
464
+ if (!resolved) {
465
+ return null;
466
+ }
462
467
 
463
- if (resolved && packageBrowserField) {
464
- if (Object.prototype.hasOwnProperty.call(packageBrowserField, resolved)) {
465
- if (!packageBrowserField[resolved]) {
466
- browserMapCache.set(resolved, packageBrowserField);
467
- return ES6_BROWSER_EMPTY;
468
- }
469
- resolved = packageBrowserField[resolved];
468
+ if (packageBrowserField) {
469
+ if (Object.prototype.hasOwnProperty.call(packageBrowserField, resolved)) {
470
+ if (!packageBrowserField[resolved]) {
471
+ browserMapCache.set(resolved, packageBrowserField);
472
+ return ES6_BROWSER_EMPTY;
470
473
  }
471
- browserMapCache.set(resolved, packageBrowserField);
474
+ resolved = packageBrowserField[resolved];
472
475
  }
476
+ browserMapCache.set(resolved, packageBrowserField);
477
+ }
473
478
 
474
- if (hasPackageEntry && !preserveSymlinks && resolved) {
475
- const fileExists = await exists(resolved);
476
- if (fileExists) {
477
- resolved = await realpath(resolved);
478
- }
479
+ if (hasPackageEntry && !preserveSymlinks) {
480
+ const fileExists = await exists(resolved);
481
+ if (fileExists) {
482
+ resolved = await realpath(resolved);
479
483
  }
484
+ }
480
485
 
481
- idToPackageInfo.set(resolved, packageInfo);
482
-
483
- if (hasPackageEntry) {
484
- if (builtins.has(resolved) && preferBuiltins && isPreferBuiltinsSet) {
485
- return null;
486
- } else if (importeeIsBuiltin && preferBuiltins) {
487
- if (!isPreferBuiltinsSet) {
488
- this.warn(
489
- `preferring built-in module '${importee}' over local alternative at '${resolved}', pass 'preferBuiltins: false' to disable this behavior or 'preferBuiltins: true' to disable this warning`
490
- );
491
- }
492
- return null;
493
- } else if (jail && resolved.indexOf(normalize(jail.trim(sep))) !== 0) {
494
- return null;
495
- }
496
- }
486
+ idToPackageInfo.set(resolved, packageInfo);
497
487
 
498
- if (resolved && options.modulesOnly) {
499
- const code = await readFile(resolved, 'utf-8');
500
- if (isModule(code)) {
501
- return {
502
- id: `${resolved}${importSuffix}`,
503
- moduleSideEffects: hasModuleSideEffects(resolved)
504
- };
488
+ if (hasPackageEntry) {
489
+ if (builtins.has(resolved) && preferBuiltins && isPreferBuiltinsSet) {
490
+ return null;
491
+ } else if (importeeIsBuiltin && preferBuiltins) {
492
+ if (!isPreferBuiltinsSet) {
493
+ this.warn(
494
+ `preferring built-in module '${importee}' over local alternative at '${resolved}', pass 'preferBuiltins: false' to disable this behavior or 'preferBuiltins: true' to disable this warning`
495
+ );
505
496
  }
506
497
  return null;
498
+ } else if (jail && resolved.indexOf(normalize(jail.trim(sep))) !== 0) {
499
+ return null;
500
+ }
501
+ }
502
+
503
+ if (options.modulesOnly && (await exists(resolved))) {
504
+ const code = await readFile(resolved, 'utf-8');
505
+ if (isModule(code)) {
506
+ return {
507
+ id: `${resolved}${importSuffix}`,
508
+ moduleSideEffects: hasModuleSideEffects(resolved)
509
+ };
507
510
  }
508
- const result = {
509
- id: `${resolved}${importSuffix}`,
510
- moduleSideEffects: hasModuleSideEffects(resolved)
511
- };
512
- return result;
513
- } catch (error) {
514
511
  return null;
515
512
  }
513
+ const result = {
514
+ id: `${resolved}${importSuffix}`,
515
+ moduleSideEffects: hasModuleSideEffects(resolved)
516
+ };
517
+ return result;
516
518
  },
517
519
 
518
520
  load(importee) {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@rollup/plugin-node-resolve",
3
- "version": "9.0.0",
3
+ "version": "10.0.0",
4
4
  "publishConfig": {
5
5
  "access": "public"
6
6
  },
@@ -12,6 +12,11 @@
12
12
  "bugs": "https://github.com/rollup/plugins/issues",
13
13
  "main": "./dist/cjs/index.js",
14
14
  "module": "./dist/es/index.js",
15
+ "type": "commonjs",
16
+ "exports": {
17
+ "require": "./dist/cjs/index.js",
18
+ "import": "./dist/es/index.js"
19
+ },
15
20
  "engines": {
16
21
  "node": ">= 10.0.0"
17
22
  },
@@ -78,10 +83,5 @@
78
83
  "!**/recipes/**",
79
84
  "!**/types.ts"
80
85
  ]
81
- },
82
- "exports": {
83
- "require": "./dist/cjs/index.js",
84
- "import": "./dist/es/index.js"
85
- },
86
- "type": "commonjs"
86
+ }
87
87
  }