@rollup/plugin-node-resolve 7.1.3 → 8.4.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 +75 -0
- package/README.md +3 -3
- package/dist/{index.js → cjs/index.js} +160 -33
- package/dist/{index.es.js → es/index.js} +156 -32
- package/dist/es/package.json +1 -0
- package/package.json +20 -12
- package/types/index.d.ts +10 -2
package/CHANGELOG.md
CHANGED
@@ -1,5 +1,80 @@
|
|
1
1
|
# @rollup/plugin-node-resolve ChangeLog
|
2
2
|
|
3
|
+
## v8.4.0
|
4
|
+
|
5
|
+
_2020-07-12_
|
6
|
+
|
7
|
+
### Features
|
8
|
+
|
9
|
+
- feat: preserve search params and hashes (#487)
|
10
|
+
- feat: support .js imports in TypeScript (#480)
|
11
|
+
|
12
|
+
### Updates
|
13
|
+
|
14
|
+
- docs: fix named export use in readme (#456)
|
15
|
+
- docs: correct mainFields valid values (#469)
|
16
|
+
|
17
|
+
## v8.3.0
|
18
|
+
|
19
|
+
_2020-07-12_
|
20
|
+
|
21
|
+
### Features
|
22
|
+
|
23
|
+
- feat: preserve search params and hashes (#487)
|
24
|
+
- feat: support .js imports in TypeScript (#480)
|
25
|
+
|
26
|
+
### Updates
|
27
|
+
|
28
|
+
- docs: fix named export use in readme (#456)
|
29
|
+
- docs: correct mainFields valid values (#469)
|
30
|
+
|
31
|
+
## v8.2.0
|
32
|
+
|
33
|
+
_2020-07-12_
|
34
|
+
|
35
|
+
### Features
|
36
|
+
|
37
|
+
- feat: preserve search params and hashes (#487)
|
38
|
+
- feat: support .js imports in TypeScript (#480)
|
39
|
+
|
40
|
+
### Updates
|
41
|
+
|
42
|
+
- docs: fix named export use in readme (#456)
|
43
|
+
- docs: correct mainFields valid values (#469)
|
44
|
+
|
45
|
+
## v8.1.0
|
46
|
+
|
47
|
+
_2020-06-22_
|
48
|
+
|
49
|
+
### Features
|
50
|
+
|
51
|
+
- feat: add native node es modules support (#413)
|
52
|
+
|
53
|
+
## v8.0.1
|
54
|
+
|
55
|
+
_2020-06-05_
|
56
|
+
|
57
|
+
### Bugfixes
|
58
|
+
|
59
|
+
- fix: handle nested entry modules with the resolveOnly option (#430)
|
60
|
+
|
61
|
+
## v8.0.0
|
62
|
+
|
63
|
+
_2020-05-20_
|
64
|
+
|
65
|
+
### Breaking Changes
|
66
|
+
|
67
|
+
- feat: Add default export (#361)
|
68
|
+
- feat: export defaults (#301)
|
69
|
+
|
70
|
+
### Bugfixes
|
71
|
+
|
72
|
+
- fix: resolve local files if `resolveOption` is set (#337)
|
73
|
+
|
74
|
+
### Updates
|
75
|
+
|
76
|
+
- docs: correct misspelling (#343)
|
77
|
+
|
3
78
|
## v7.1.3
|
4
79
|
|
5
80
|
_2020-04-12_
|
package/README.md
CHANGED
@@ -28,7 +28,7 @@ npm install @rollup/plugin-node-resolve --save-dev
|
|
28
28
|
Create a `rollup.config.js` [configuration file](https://www.rollupjs.org/guide/en/#configuration-files) and import the plugin:
|
29
29
|
|
30
30
|
```js
|
31
|
-
import
|
31
|
+
import { nodeResolve } from '@rollup/plugin-node-resolve';
|
32
32
|
|
33
33
|
export default {
|
34
34
|
input: 'src/index.js',
|
@@ -36,7 +36,7 @@ export default {
|
|
36
36
|
dir: 'output',
|
37
37
|
format: 'cjs'
|
38
38
|
},
|
39
|
-
plugins: [
|
39
|
+
plugins: [nodeResolve()]
|
40
40
|
};
|
41
41
|
```
|
42
42
|
|
@@ -107,7 +107,7 @@ Locks the module search within specified path (e.g. chroot). Modules defined out
|
|
107
107
|
|
108
108
|
Type: `Array[...String]`<br>
|
109
109
|
Default: `['module', 'main']`<br>
|
110
|
-
Valid values: `['browser', 'jsnext', 'module', 'main']`
|
110
|
+
Valid values: `['browser', 'jsnext:main', 'module', 'main']`
|
111
111
|
|
112
112
|
Specifies the properties to scan within a `package.json`, used to determine the bundle entry point. The order of property names is significant, as the first-found property is used as the resolved entry point. If the array contains `'browser'`, key/values specified in the `package.json` `browser` property will be used.
|
113
113
|
|
@@ -1,9 +1,13 @@
|
|
1
1
|
'use strict';
|
2
2
|
|
3
|
+
Object.defineProperty(exports, '__esModule', { value: true });
|
4
|
+
|
3
5
|
function _interopDefault (ex) { return (ex && (typeof ex === 'object') && 'default' in ex) ? ex['default'] : ex; }
|
4
6
|
|
5
7
|
var path = require('path');
|
6
8
|
var builtinList = _interopDefault(require('builtin-modules'));
|
9
|
+
var deepFreeze = _interopDefault(require('deep-freeze'));
|
10
|
+
var deepMerge = _interopDefault(require('deepmerge'));
|
7
11
|
var isModule = _interopDefault(require('is-module'));
|
8
12
|
var fs = require('fs');
|
9
13
|
var fs__default = _interopDefault(fs);
|
@@ -47,6 +51,117 @@ function _asyncToGenerator(fn) {
|
|
47
51
|
};
|
48
52
|
}
|
49
53
|
|
54
|
+
function _slicedToArray(arr, i) {
|
55
|
+
return _arrayWithHoles(arr) || _iterableToArrayLimit(arr, i) || _unsupportedIterableToArray(arr, i) || _nonIterableRest();
|
56
|
+
}
|
57
|
+
|
58
|
+
function _arrayWithHoles(arr) {
|
59
|
+
if (Array.isArray(arr)) return arr;
|
60
|
+
}
|
61
|
+
|
62
|
+
function _iterableToArrayLimit(arr, i) {
|
63
|
+
if (typeof Symbol === "undefined" || !(Symbol.iterator in Object(arr))) return;
|
64
|
+
var _arr = [];
|
65
|
+
var _n = true;
|
66
|
+
var _d = false;
|
67
|
+
var _e = undefined;
|
68
|
+
|
69
|
+
try {
|
70
|
+
for (var _i = arr[Symbol.iterator](), _s; !(_n = (_s = _i.next()).done); _n = true) {
|
71
|
+
_arr.push(_s.value);
|
72
|
+
|
73
|
+
if (i && _arr.length === i) break;
|
74
|
+
}
|
75
|
+
} catch (err) {
|
76
|
+
_d = true;
|
77
|
+
_e = err;
|
78
|
+
} finally {
|
79
|
+
try {
|
80
|
+
if (!_n && _i["return"] != null) _i["return"]();
|
81
|
+
} finally {
|
82
|
+
if (_d) throw _e;
|
83
|
+
}
|
84
|
+
}
|
85
|
+
|
86
|
+
return _arr;
|
87
|
+
}
|
88
|
+
|
89
|
+
function _unsupportedIterableToArray(o, minLen) {
|
90
|
+
if (!o) return;
|
91
|
+
if (typeof o === "string") return _arrayLikeToArray(o, minLen);
|
92
|
+
var n = Object.prototype.toString.call(o).slice(8, -1);
|
93
|
+
if (n === "Object" && o.constructor) n = o.constructor.name;
|
94
|
+
if (n === "Map" || n === "Set") return Array.from(n);
|
95
|
+
if (n === "Arguments" || /^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(n)) return _arrayLikeToArray(o, minLen);
|
96
|
+
}
|
97
|
+
|
98
|
+
function _arrayLikeToArray(arr, len) {
|
99
|
+
if (len == null || len > arr.length) len = arr.length;
|
100
|
+
|
101
|
+
for (var i = 0, arr2 = new Array(len); i < len; i++) arr2[i] = arr[i];
|
102
|
+
|
103
|
+
return arr2;
|
104
|
+
}
|
105
|
+
|
106
|
+
function _nonIterableRest() {
|
107
|
+
throw new TypeError("Invalid attempt to destructure non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.");
|
108
|
+
}
|
109
|
+
|
110
|
+
function _createForOfIteratorHelper(o) {
|
111
|
+
if (typeof Symbol === "undefined" || o[Symbol.iterator] == null) {
|
112
|
+
if (Array.isArray(o) || (o = _unsupportedIterableToArray(o))) {
|
113
|
+
var i = 0;
|
114
|
+
|
115
|
+
var F = function () {};
|
116
|
+
|
117
|
+
return {
|
118
|
+
s: F,
|
119
|
+
n: function () {
|
120
|
+
if (i >= o.length) return {
|
121
|
+
done: true
|
122
|
+
};
|
123
|
+
return {
|
124
|
+
done: false,
|
125
|
+
value: o[i++]
|
126
|
+
};
|
127
|
+
},
|
128
|
+
e: function (e) {
|
129
|
+
throw e;
|
130
|
+
},
|
131
|
+
f: F
|
132
|
+
};
|
133
|
+
}
|
134
|
+
|
135
|
+
throw new TypeError("Invalid attempt to iterate non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.");
|
136
|
+
}
|
137
|
+
|
138
|
+
var it,
|
139
|
+
normalCompletion = true,
|
140
|
+
didErr = false,
|
141
|
+
err;
|
142
|
+
return {
|
143
|
+
s: function () {
|
144
|
+
it = o[Symbol.iterator]();
|
145
|
+
},
|
146
|
+
n: function () {
|
147
|
+
var step = it.next();
|
148
|
+
normalCompletion = step.done;
|
149
|
+
return step;
|
150
|
+
},
|
151
|
+
e: function (e) {
|
152
|
+
didErr = true;
|
153
|
+
err = e;
|
154
|
+
},
|
155
|
+
f: function () {
|
156
|
+
try {
|
157
|
+
if (!normalCompletion && it.return != null) it.return();
|
158
|
+
} finally {
|
159
|
+
if (didErr) throw err;
|
160
|
+
}
|
161
|
+
}
|
162
|
+
};
|
163
|
+
}
|
164
|
+
|
50
165
|
const exists = util.promisify(fs__default.exists);
|
51
166
|
const readFile = util.promisify(fs__default.readFile);
|
52
167
|
const realpath = util.promisify(fs__default.realpath);
|
@@ -63,9 +178,7 @@ const onError = error => {
|
|
63
178
|
const makeCache = fn => {
|
64
179
|
const cache = new Map();
|
65
180
|
|
66
|
-
const wrapped =
|
67
|
-
/*#__PURE__*/
|
68
|
-
function () {
|
181
|
+
const wrapped = /*#__PURE__*/function () {
|
69
182
|
var _ref = _asyncToGenerator(function* (param, done) {
|
70
183
|
if (cache.has(param) === false) {
|
71
184
|
cache.set(param, fn(param).catch(err => {
|
@@ -93,9 +206,7 @@ const makeCache = fn => {
|
|
93
206
|
return wrapped;
|
94
207
|
};
|
95
208
|
|
96
|
-
const isDirCached = makeCache(
|
97
|
-
/*#__PURE__*/
|
98
|
-
function () {
|
209
|
+
const isDirCached = makeCache( /*#__PURE__*/function () {
|
99
210
|
var _ref2 = _asyncToGenerator(function* (file) {
|
100
211
|
try {
|
101
212
|
const stats = yield stat(file);
|
@@ -109,9 +220,7 @@ function () {
|
|
109
220
|
return _ref2.apply(this, arguments);
|
110
221
|
};
|
111
222
|
}());
|
112
|
-
const isFileCached = makeCache(
|
113
|
-
/*#__PURE__*/
|
114
|
-
function () {
|
223
|
+
const isFileCached = makeCache( /*#__PURE__*/function () {
|
115
224
|
var _ref3 = _asyncToGenerator(function* (file) {
|
116
225
|
try {
|
117
226
|
const stats = yield stat(file);
|
@@ -275,7 +384,7 @@ function normalizeInput(input) {
|
|
275
384
|
} // otherwise it's a string
|
276
385
|
|
277
386
|
|
278
|
-
return input;
|
387
|
+
return [input];
|
279
388
|
} // Resolve module specifiers in order. Promise resolves to the first module that resolves
|
280
389
|
// successfully, or the error that resulted from the last attempted module resolution.
|
281
390
|
|
@@ -324,6 +433,7 @@ const defaults = {
|
|
324
433
|
extensions: ['.mjs', '.js', '.json', '.node'],
|
325
434
|
resolveOnly: []
|
326
435
|
};
|
436
|
+
const DEFAULTS = deepFreeze(deepMerge({}, defaults));
|
327
437
|
function nodeResolve(opts = {}) {
|
328
438
|
const options = Object.assign({}, defaults, opts);
|
329
439
|
const customResolveOptions = options.customResolveOptions,
|
@@ -364,28 +474,19 @@ function nodeResolve(opts = {}) {
|
|
364
474
|
|
365
475
|
buildStart(options) {
|
366
476
|
rollupOptions = options;
|
367
|
-
|
368
|
-
var
|
369
|
-
|
477
|
+
|
478
|
+
var _iterator = _createForOfIteratorHelper(warnings),
|
479
|
+
_step;
|
370
480
|
|
371
481
|
try {
|
372
|
-
for (
|
482
|
+
for (_iterator.s(); !(_step = _iterator.n()).done;) {
|
373
483
|
const warning = _step.value;
|
374
484
|
this.warn(warning);
|
375
485
|
}
|
376
486
|
} catch (err) {
|
377
|
-
|
378
|
-
_iteratorError = err;
|
487
|
+
_iterator.e(err);
|
379
488
|
} finally {
|
380
|
-
|
381
|
-
if (!_iteratorNormalCompletion && _iterator.return != null) {
|
382
|
-
_iterator.return();
|
383
|
-
}
|
384
|
-
} finally {
|
385
|
-
if (_didIteratorError) {
|
386
|
-
throw _iteratorError;
|
387
|
-
}
|
388
|
-
}
|
489
|
+
_iterator.f();
|
389
490
|
}
|
390
491
|
|
391
492
|
preserveSymlinks = options.preserveSymlinks;
|
@@ -406,7 +507,20 @@ function nodeResolve(opts = {}) {
|
|
406
507
|
} // ignore IDs with null character, these belong to other plugins
|
407
508
|
|
408
509
|
|
409
|
-
if (/\0/.test(importee)) return null;
|
510
|
+
if (/\0/.test(importee)) return null; // strip hash and query params from import
|
511
|
+
|
512
|
+
const _importee$split = importee.split('#'),
|
513
|
+
_importee$split2 = _slicedToArray(_importee$split, 2),
|
514
|
+
withoutHash = _importee$split2[0],
|
515
|
+
hash = _importee$split2[1];
|
516
|
+
|
517
|
+
const _withoutHash$split = withoutHash.split('?'),
|
518
|
+
_withoutHash$split2 = _slicedToArray(_withoutHash$split, 2),
|
519
|
+
importPath = _withoutHash$split2[0],
|
520
|
+
params = _withoutHash$split2[1];
|
521
|
+
|
522
|
+
const importSuffix = `${params ? `?${params}` : ''}${hash ? `#${hash}` : ''}`;
|
523
|
+
importee = importPath;
|
410
524
|
const basedir = !importer || dedupe(importee) ? rootDir : path.dirname(importer); // https://github.com/defunctzombie/package-browser-field-spec
|
411
525
|
|
412
526
|
const browser = browserMapCache.get(importer);
|
@@ -427,6 +541,7 @@ function nodeResolve(opts = {}) {
|
|
427
541
|
|
428
542
|
const parts = importee.split(/[/\\]/);
|
429
543
|
let id = parts.shift();
|
544
|
+
let isRelativeImport = false;
|
430
545
|
|
431
546
|
if (id[0] === '@' && parts.length > 0) {
|
432
547
|
// scoped packages
|
@@ -434,12 +549,11 @@ function nodeResolve(opts = {}) {
|
|
434
549
|
} else if (id[0] === '.') {
|
435
550
|
// an import relative to the parent dir of the importer
|
436
551
|
id = path.resolve(basedir, importee);
|
552
|
+
isRelativeImport = true;
|
437
553
|
}
|
438
554
|
|
439
|
-
|
440
|
-
|
441
|
-
if (resolveOnly.length && !resolveOnly.some(pattern => pattern.test(id))) {
|
442
|
-
if (input.includes(id)) {
|
555
|
+
if (!isRelativeImport && resolveOnly.length && !resolveOnly.some(pattern => pattern.test(id))) {
|
556
|
+
if (normalizeInput(rollupOptions.input).includes(importee)) {
|
443
557
|
return null;
|
444
558
|
}
|
445
559
|
|
@@ -503,6 +617,17 @@ function nodeResolve(opts = {}) {
|
|
503
617
|
// find anything, we resolve the builtin which just returns back
|
504
618
|
// the built-in's name.
|
505
619
|
importSpecifierList.push(`${importee}/`);
|
620
|
+
} // TypeScript files may import '.js' to refer to either '.ts' or '.tsx'
|
621
|
+
|
622
|
+
|
623
|
+
if (importer && importee.endsWith('.js')) {
|
624
|
+
for (var _i = 0, _arr = ['.ts', '.tsx']; _i < _arr.length; _i++) {
|
625
|
+
const ext = _arr[_i];
|
626
|
+
|
627
|
+
if (importer.endsWith(ext) && extensions.includes(ext)) {
|
628
|
+
importSpecifierList.push(importee.replace(/.js$/, ext));
|
629
|
+
}
|
630
|
+
}
|
506
631
|
}
|
507
632
|
|
508
633
|
importSpecifierList.push(importee);
|
@@ -553,7 +678,7 @@ function nodeResolve(opts = {}) {
|
|
553
678
|
|
554
679
|
if (isModule(code)) {
|
555
680
|
return {
|
556
|
-
id: resolved
|
681
|
+
id: `${resolved}${importSuffix}`,
|
557
682
|
moduleSideEffects: hasModuleSideEffects(resolved)
|
558
683
|
};
|
559
684
|
}
|
@@ -562,7 +687,7 @@ function nodeResolve(opts = {}) {
|
|
562
687
|
}
|
563
688
|
|
564
689
|
const result = {
|
565
|
-
id: resolved
|
690
|
+
id: `${resolved}${importSuffix}`,
|
566
691
|
moduleSideEffects: hasModuleSideEffects(resolved)
|
567
692
|
};
|
568
693
|
return result;
|
@@ -587,4 +712,6 @@ function nodeResolve(opts = {}) {
|
|
587
712
|
};
|
588
713
|
}
|
589
714
|
|
590
|
-
|
715
|
+
exports.DEFAULTS = DEFAULTS;
|
716
|
+
exports.default = nodeResolve;
|
717
|
+
exports.nodeResolve = nodeResolve;
|
@@ -1,5 +1,7 @@
|
|
1
1
|
import { dirname, resolve, extname, normalize, sep } from 'path';
|
2
2
|
import builtinList from 'builtin-modules';
|
3
|
+
import deepFreeze from 'deep-freeze';
|
4
|
+
import deepMerge from 'deepmerge';
|
3
5
|
import isModule from 'is-module';
|
4
6
|
import fs, { realpathSync } from 'fs';
|
5
7
|
import { promisify } from 'util';
|
@@ -42,6 +44,117 @@ function _asyncToGenerator(fn) {
|
|
42
44
|
};
|
43
45
|
}
|
44
46
|
|
47
|
+
function _slicedToArray(arr, i) {
|
48
|
+
return _arrayWithHoles(arr) || _iterableToArrayLimit(arr, i) || _unsupportedIterableToArray(arr, i) || _nonIterableRest();
|
49
|
+
}
|
50
|
+
|
51
|
+
function _arrayWithHoles(arr) {
|
52
|
+
if (Array.isArray(arr)) return arr;
|
53
|
+
}
|
54
|
+
|
55
|
+
function _iterableToArrayLimit(arr, i) {
|
56
|
+
if (typeof Symbol === "undefined" || !(Symbol.iterator in Object(arr))) return;
|
57
|
+
var _arr = [];
|
58
|
+
var _n = true;
|
59
|
+
var _d = false;
|
60
|
+
var _e = undefined;
|
61
|
+
|
62
|
+
try {
|
63
|
+
for (var _i = arr[Symbol.iterator](), _s; !(_n = (_s = _i.next()).done); _n = true) {
|
64
|
+
_arr.push(_s.value);
|
65
|
+
|
66
|
+
if (i && _arr.length === i) break;
|
67
|
+
}
|
68
|
+
} catch (err) {
|
69
|
+
_d = true;
|
70
|
+
_e = err;
|
71
|
+
} finally {
|
72
|
+
try {
|
73
|
+
if (!_n && _i["return"] != null) _i["return"]();
|
74
|
+
} finally {
|
75
|
+
if (_d) throw _e;
|
76
|
+
}
|
77
|
+
}
|
78
|
+
|
79
|
+
return _arr;
|
80
|
+
}
|
81
|
+
|
82
|
+
function _unsupportedIterableToArray(o, minLen) {
|
83
|
+
if (!o) return;
|
84
|
+
if (typeof o === "string") return _arrayLikeToArray(o, minLen);
|
85
|
+
var n = Object.prototype.toString.call(o).slice(8, -1);
|
86
|
+
if (n === "Object" && o.constructor) n = o.constructor.name;
|
87
|
+
if (n === "Map" || n === "Set") return Array.from(n);
|
88
|
+
if (n === "Arguments" || /^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(n)) return _arrayLikeToArray(o, minLen);
|
89
|
+
}
|
90
|
+
|
91
|
+
function _arrayLikeToArray(arr, len) {
|
92
|
+
if (len == null || len > arr.length) len = arr.length;
|
93
|
+
|
94
|
+
for (var i = 0, arr2 = new Array(len); i < len; i++) arr2[i] = arr[i];
|
95
|
+
|
96
|
+
return arr2;
|
97
|
+
}
|
98
|
+
|
99
|
+
function _nonIterableRest() {
|
100
|
+
throw new TypeError("Invalid attempt to destructure non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.");
|
101
|
+
}
|
102
|
+
|
103
|
+
function _createForOfIteratorHelper(o) {
|
104
|
+
if (typeof Symbol === "undefined" || o[Symbol.iterator] == null) {
|
105
|
+
if (Array.isArray(o) || (o = _unsupportedIterableToArray(o))) {
|
106
|
+
var i = 0;
|
107
|
+
|
108
|
+
var F = function () {};
|
109
|
+
|
110
|
+
return {
|
111
|
+
s: F,
|
112
|
+
n: function () {
|
113
|
+
if (i >= o.length) return {
|
114
|
+
done: true
|
115
|
+
};
|
116
|
+
return {
|
117
|
+
done: false,
|
118
|
+
value: o[i++]
|
119
|
+
};
|
120
|
+
},
|
121
|
+
e: function (e) {
|
122
|
+
throw e;
|
123
|
+
},
|
124
|
+
f: F
|
125
|
+
};
|
126
|
+
}
|
127
|
+
|
128
|
+
throw new TypeError("Invalid attempt to iterate non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.");
|
129
|
+
}
|
130
|
+
|
131
|
+
var it,
|
132
|
+
normalCompletion = true,
|
133
|
+
didErr = false,
|
134
|
+
err;
|
135
|
+
return {
|
136
|
+
s: function () {
|
137
|
+
it = o[Symbol.iterator]();
|
138
|
+
},
|
139
|
+
n: function () {
|
140
|
+
var step = it.next();
|
141
|
+
normalCompletion = step.done;
|
142
|
+
return step;
|
143
|
+
},
|
144
|
+
e: function (e) {
|
145
|
+
didErr = true;
|
146
|
+
err = e;
|
147
|
+
},
|
148
|
+
f: function () {
|
149
|
+
try {
|
150
|
+
if (!normalCompletion && it.return != null) it.return();
|
151
|
+
} finally {
|
152
|
+
if (didErr) throw err;
|
153
|
+
}
|
154
|
+
}
|
155
|
+
};
|
156
|
+
}
|
157
|
+
|
45
158
|
const exists = promisify(fs.exists);
|
46
159
|
const readFile = promisify(fs.readFile);
|
47
160
|
const realpath = promisify(fs.realpath);
|
@@ -58,9 +171,7 @@ const onError = error => {
|
|
58
171
|
const makeCache = fn => {
|
59
172
|
const cache = new Map();
|
60
173
|
|
61
|
-
const wrapped =
|
62
|
-
/*#__PURE__*/
|
63
|
-
function () {
|
174
|
+
const wrapped = /*#__PURE__*/function () {
|
64
175
|
var _ref = _asyncToGenerator(function* (param, done) {
|
65
176
|
if (cache.has(param) === false) {
|
66
177
|
cache.set(param, fn(param).catch(err => {
|
@@ -88,9 +199,7 @@ const makeCache = fn => {
|
|
88
199
|
return wrapped;
|
89
200
|
};
|
90
201
|
|
91
|
-
const isDirCached = makeCache(
|
92
|
-
/*#__PURE__*/
|
93
|
-
function () {
|
202
|
+
const isDirCached = makeCache( /*#__PURE__*/function () {
|
94
203
|
var _ref2 = _asyncToGenerator(function* (file) {
|
95
204
|
try {
|
96
205
|
const stats = yield stat(file);
|
@@ -104,9 +213,7 @@ function () {
|
|
104
213
|
return _ref2.apply(this, arguments);
|
105
214
|
};
|
106
215
|
}());
|
107
|
-
const isFileCached = makeCache(
|
108
|
-
/*#__PURE__*/
|
109
|
-
function () {
|
216
|
+
const isFileCached = makeCache( /*#__PURE__*/function () {
|
110
217
|
var _ref3 = _asyncToGenerator(function* (file) {
|
111
218
|
try {
|
112
219
|
const stats = yield stat(file);
|
@@ -270,7 +377,7 @@ function normalizeInput(input) {
|
|
270
377
|
} // otherwise it's a string
|
271
378
|
|
272
379
|
|
273
|
-
return input;
|
380
|
+
return [input];
|
274
381
|
} // Resolve module specifiers in order. Promise resolves to the first module that resolves
|
275
382
|
// successfully, or the error that resulted from the last attempted module resolution.
|
276
383
|
|
@@ -319,6 +426,7 @@ const defaults = {
|
|
319
426
|
extensions: ['.mjs', '.js', '.json', '.node'],
|
320
427
|
resolveOnly: []
|
321
428
|
};
|
429
|
+
const DEFAULTS = deepFreeze(deepMerge({}, defaults));
|
322
430
|
function nodeResolve(opts = {}) {
|
323
431
|
const options = Object.assign({}, defaults, opts);
|
324
432
|
const customResolveOptions = options.customResolveOptions,
|
@@ -359,28 +467,19 @@ function nodeResolve(opts = {}) {
|
|
359
467
|
|
360
468
|
buildStart(options) {
|
361
469
|
rollupOptions = options;
|
362
|
-
|
363
|
-
var
|
364
|
-
|
470
|
+
|
471
|
+
var _iterator = _createForOfIteratorHelper(warnings),
|
472
|
+
_step;
|
365
473
|
|
366
474
|
try {
|
367
|
-
for (
|
475
|
+
for (_iterator.s(); !(_step = _iterator.n()).done;) {
|
368
476
|
const warning = _step.value;
|
369
477
|
this.warn(warning);
|
370
478
|
}
|
371
479
|
} catch (err) {
|
372
|
-
|
373
|
-
_iteratorError = err;
|
480
|
+
_iterator.e(err);
|
374
481
|
} finally {
|
375
|
-
|
376
|
-
if (!_iteratorNormalCompletion && _iterator.return != null) {
|
377
|
-
_iterator.return();
|
378
|
-
}
|
379
|
-
} finally {
|
380
|
-
if (_didIteratorError) {
|
381
|
-
throw _iteratorError;
|
382
|
-
}
|
383
|
-
}
|
482
|
+
_iterator.f();
|
384
483
|
}
|
385
484
|
|
386
485
|
preserveSymlinks = options.preserveSymlinks;
|
@@ -401,7 +500,20 @@ function nodeResolve(opts = {}) {
|
|
401
500
|
} // ignore IDs with null character, these belong to other plugins
|
402
501
|
|
403
502
|
|
404
|
-
if (/\0/.test(importee)) return null;
|
503
|
+
if (/\0/.test(importee)) return null; // strip hash and query params from import
|
504
|
+
|
505
|
+
const _importee$split = importee.split('#'),
|
506
|
+
_importee$split2 = _slicedToArray(_importee$split, 2),
|
507
|
+
withoutHash = _importee$split2[0],
|
508
|
+
hash = _importee$split2[1];
|
509
|
+
|
510
|
+
const _withoutHash$split = withoutHash.split('?'),
|
511
|
+
_withoutHash$split2 = _slicedToArray(_withoutHash$split, 2),
|
512
|
+
importPath = _withoutHash$split2[0],
|
513
|
+
params = _withoutHash$split2[1];
|
514
|
+
|
515
|
+
const importSuffix = `${params ? `?${params}` : ''}${hash ? `#${hash}` : ''}`;
|
516
|
+
importee = importPath;
|
405
517
|
const basedir = !importer || dedupe(importee) ? rootDir : dirname(importer); // https://github.com/defunctzombie/package-browser-field-spec
|
406
518
|
|
407
519
|
const browser = browserMapCache.get(importer);
|
@@ -422,6 +534,7 @@ function nodeResolve(opts = {}) {
|
|
422
534
|
|
423
535
|
const parts = importee.split(/[/\\]/);
|
424
536
|
let id = parts.shift();
|
537
|
+
let isRelativeImport = false;
|
425
538
|
|
426
539
|
if (id[0] === '@' && parts.length > 0) {
|
427
540
|
// scoped packages
|
@@ -429,12 +542,11 @@ function nodeResolve(opts = {}) {
|
|
429
542
|
} else if (id[0] === '.') {
|
430
543
|
// an import relative to the parent dir of the importer
|
431
544
|
id = resolve(basedir, importee);
|
545
|
+
isRelativeImport = true;
|
432
546
|
}
|
433
547
|
|
434
|
-
|
435
|
-
|
436
|
-
if (resolveOnly.length && !resolveOnly.some(pattern => pattern.test(id))) {
|
437
|
-
if (input.includes(id)) {
|
548
|
+
if (!isRelativeImport && resolveOnly.length && !resolveOnly.some(pattern => pattern.test(id))) {
|
549
|
+
if (normalizeInput(rollupOptions.input).includes(importee)) {
|
438
550
|
return null;
|
439
551
|
}
|
440
552
|
|
@@ -498,6 +610,17 @@ function nodeResolve(opts = {}) {
|
|
498
610
|
// find anything, we resolve the builtin which just returns back
|
499
611
|
// the built-in's name.
|
500
612
|
importSpecifierList.push(`${importee}/`);
|
613
|
+
} // TypeScript files may import '.js' to refer to either '.ts' or '.tsx'
|
614
|
+
|
615
|
+
|
616
|
+
if (importer && importee.endsWith('.js')) {
|
617
|
+
for (var _i = 0, _arr = ['.ts', '.tsx']; _i < _arr.length; _i++) {
|
618
|
+
const ext = _arr[_i];
|
619
|
+
|
620
|
+
if (importer.endsWith(ext) && extensions.includes(ext)) {
|
621
|
+
importSpecifierList.push(importee.replace(/.js$/, ext));
|
622
|
+
}
|
623
|
+
}
|
501
624
|
}
|
502
625
|
|
503
626
|
importSpecifierList.push(importee);
|
@@ -548,7 +671,7 @@ function nodeResolve(opts = {}) {
|
|
548
671
|
|
549
672
|
if (isModule(code)) {
|
550
673
|
return {
|
551
|
-
id: resolved
|
674
|
+
id: `${resolved}${importSuffix}`,
|
552
675
|
moduleSideEffects: hasModuleSideEffects(resolved)
|
553
676
|
};
|
554
677
|
}
|
@@ -557,7 +680,7 @@ function nodeResolve(opts = {}) {
|
|
557
680
|
}
|
558
681
|
|
559
682
|
const result = {
|
560
|
-
id: resolved
|
683
|
+
id: `${resolved}${importSuffix}`,
|
561
684
|
moduleSideEffects: hasModuleSideEffects(resolved)
|
562
685
|
};
|
563
686
|
return result;
|
@@ -583,3 +706,4 @@ function nodeResolve(opts = {}) {
|
|
583
706
|
}
|
584
707
|
|
585
708
|
export default nodeResolve;
|
709
|
+
export { DEFAULTS, nodeResolve };
|
@@ -0,0 +1 @@
|
|
1
|
+
{"type":"module"}
|
package/package.json
CHANGED
@@ -1,6 +1,6 @@
|
|
1
1
|
{
|
2
2
|
"name": "@rollup/plugin-node-resolve",
|
3
|
-
"version": "
|
3
|
+
"version": "8.4.0",
|
4
4
|
"publishConfig": {
|
5
5
|
"access": "public"
|
6
6
|
},
|
@@ -10,7 +10,7 @@
|
|
10
10
|
"author": "Rich Harris <richard.a.harris@gmail.com>",
|
11
11
|
"homepage": "https://github.com/rollup/plugins/tree/master/packages/node-resolve/#readme",
|
12
12
|
"bugs": "https://github.com/rollup/plugins/issues",
|
13
|
-
"main": "dist/index.js",
|
13
|
+
"main": "./dist/cjs/index.js",
|
14
14
|
"engines": {
|
15
15
|
"node": ">= 8.0.0"
|
16
16
|
},
|
@@ -48,20 +48,23 @@
|
|
48
48
|
"rollup": "^1.20.0||^2.0.0"
|
49
49
|
},
|
50
50
|
"dependencies": {
|
51
|
-
"@rollup/pluginutils": "^3.0
|
52
|
-
"@types/resolve": "
|
51
|
+
"@rollup/pluginutils": "^3.1.0",
|
52
|
+
"@types/resolve": "1.17.1",
|
53
53
|
"builtin-modules": "^3.1.0",
|
54
|
+
"deep-freeze": "^0.0.1",
|
55
|
+
"deepmerge": "^4.2.2",
|
54
56
|
"is-module": "^1.0.0",
|
55
|
-
"resolve": "^1.
|
57
|
+
"resolve": "^1.17.0"
|
56
58
|
},
|
57
59
|
"devDependencies": {
|
58
|
-
"@babel/core": "^7.
|
59
|
-
"@babel/
|
60
|
-
"@
|
60
|
+
"@babel/core": "^7.10.4",
|
61
|
+
"@babel/plugin-transform-typescript": "^7.10.4",
|
62
|
+
"@babel/preset-env": "^7.10.4",
|
63
|
+
"@rollup/plugin-babel": "^5.0.4",
|
64
|
+
"@rollup/plugin-commonjs": "^13.0.0",
|
65
|
+
"@rollup/plugin-json": "^4.1.0",
|
61
66
|
"es5-ext": "^0.10.53",
|
62
|
-
"rollup": "^2.
|
63
|
-
"rollup-plugin-babel": "^4.3.3",
|
64
|
-
"rollup-plugin-commonjs": "^10.1.0",
|
67
|
+
"rollup": "^2.12.0",
|
65
68
|
"source-map": "^0.7.3",
|
66
69
|
"string-capitalize": "^1.0.1"
|
67
70
|
},
|
@@ -73,6 +76,11 @@
|
|
73
76
|
"!**/types.ts"
|
74
77
|
]
|
75
78
|
},
|
76
|
-
"
|
79
|
+
"exports": {
|
80
|
+
"require": "./dist/cjs/index.js",
|
81
|
+
"import": "./dist/es/index.js"
|
82
|
+
},
|
83
|
+
"module": "./dist/es/index.js",
|
84
|
+
"type": "commonjs",
|
77
85
|
"types": "types/index.d.ts"
|
78
86
|
}
|
package/types/index.d.ts
CHANGED
@@ -1,7 +1,14 @@
|
|
1
1
|
import { Plugin } from 'rollup';
|
2
2
|
import { AsyncOpts } from 'resolve';
|
3
3
|
|
4
|
-
export
|
4
|
+
export const DEFAULTS: {
|
5
|
+
customResolveOptions: {};
|
6
|
+
dedupe: [];
|
7
|
+
extensions: ['.mjs', '.js', '.json', '.node'];
|
8
|
+
resolveOnly: [];
|
9
|
+
};
|
10
|
+
|
11
|
+
export interface RollupNodeResolveOptions {
|
5
12
|
/**
|
6
13
|
* If `true`, instructs the plugin to use the `"browser"` property in `package.json`
|
7
14
|
* files to specify alternative files to load for bundling. This is useful when
|
@@ -81,4 +88,5 @@ export interface Options {
|
|
81
88
|
/**
|
82
89
|
* Locate modules using the Node resolution algorithm, for using third party modules in node_modules
|
83
90
|
*/
|
84
|
-
export
|
91
|
+
export function nodeResolve(options?: RollupNodeResolveOptions): Plugin;
|
92
|
+
export default nodeResolve;
|