@rollup/plugin-node-resolve 8.4.0 → 9.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 +7 -22
- package/dist/cjs/index.js +268 -445
- package/dist/es/index.js +268 -445
- package/package.json +14 -13
package/dist/es/index.js
CHANGED
@@ -1,6 +1,5 @@
|
|
1
1
|
import { dirname, resolve, extname, normalize, sep } from 'path';
|
2
2
|
import builtinList from 'builtin-modules';
|
3
|
-
import deepFreeze from 'deep-freeze';
|
4
3
|
import deepMerge from 'deepmerge';
|
5
4
|
import isModule from 'is-module';
|
6
5
|
import fs, { realpathSync } from 'fs';
|
@@ -8,303 +7,141 @@ import { promisify } from 'util';
|
|
8
7
|
import { createFilter } from '@rollup/pluginutils';
|
9
8
|
import resolveModule from 'resolve';
|
10
9
|
|
11
|
-
function asyncGeneratorStep(gen, resolve, reject, _next, _throw, key, arg) {
|
12
|
-
try {
|
13
|
-
var info = gen[key](arg);
|
14
|
-
var value = info.value;
|
15
|
-
} catch (error) {
|
16
|
-
reject(error);
|
17
|
-
return;
|
18
|
-
}
|
19
|
-
|
20
|
-
if (info.done) {
|
21
|
-
resolve(value);
|
22
|
-
} else {
|
23
|
-
Promise.resolve(value).then(_next, _throw);
|
24
|
-
}
|
25
|
-
}
|
26
|
-
|
27
|
-
function _asyncToGenerator(fn) {
|
28
|
-
return function () {
|
29
|
-
var self = this,
|
30
|
-
args = arguments;
|
31
|
-
return new Promise(function (resolve, reject) {
|
32
|
-
var gen = fn.apply(self, args);
|
33
|
-
|
34
|
-
function _next(value) {
|
35
|
-
asyncGeneratorStep(gen, resolve, reject, _next, _throw, "next", value);
|
36
|
-
}
|
37
|
-
|
38
|
-
function _throw(err) {
|
39
|
-
asyncGeneratorStep(gen, resolve, reject, _next, _throw, "throw", err);
|
40
|
-
}
|
41
|
-
|
42
|
-
_next(undefined);
|
43
|
-
});
|
44
|
-
};
|
45
|
-
}
|
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
|
-
|
158
10
|
const exists = promisify(fs.exists);
|
159
11
|
const readFile = promisify(fs.readFile);
|
160
12
|
const realpath = promisify(fs.realpath);
|
161
13
|
const stat = promisify(fs.stat);
|
162
14
|
|
163
|
-
const onError = error => {
|
15
|
+
const onError = (error) => {
|
164
16
|
if (error.code === 'ENOENT') {
|
165
17
|
return false;
|
166
18
|
}
|
167
|
-
|
168
19
|
throw error;
|
169
20
|
};
|
170
21
|
|
171
|
-
const makeCache = fn => {
|
22
|
+
const makeCache = (fn) => {
|
172
23
|
const cache = new Map();
|
173
|
-
|
174
|
-
|
175
|
-
|
176
|
-
|
177
|
-
|
24
|
+
const wrapped = async (param, done) => {
|
25
|
+
if (cache.has(param) === false) {
|
26
|
+
cache.set(
|
27
|
+
param,
|
28
|
+
fn(param).catch((err) => {
|
178
29
|
cache.delete(param);
|
179
30
|
throw err;
|
180
|
-
})
|
181
|
-
|
182
|
-
|
183
|
-
try {
|
184
|
-
const result = cache.get(param);
|
185
|
-
const value = yield result;
|
186
|
-
return done(null, value);
|
187
|
-
} catch (error) {
|
188
|
-
return done(error);
|
189
|
-
}
|
190
|
-
});
|
31
|
+
})
|
32
|
+
);
|
33
|
+
}
|
191
34
|
|
192
|
-
|
193
|
-
|
194
|
-
|
195
|
-
|
35
|
+
try {
|
36
|
+
const result = cache.get(param);
|
37
|
+
const value = await result;
|
38
|
+
return done(null, value);
|
39
|
+
} catch (error) {
|
40
|
+
return done(error);
|
41
|
+
}
|
42
|
+
};
|
196
43
|
|
197
44
|
wrapped.clear = () => cache.clear();
|
198
45
|
|
199
46
|
return wrapped;
|
200
47
|
};
|
201
48
|
|
202
|
-
const isDirCached = makeCache(
|
203
|
-
|
204
|
-
|
205
|
-
|
206
|
-
|
207
|
-
|
208
|
-
|
209
|
-
|
210
|
-
});
|
49
|
+
const isDirCached = makeCache(async (file) => {
|
50
|
+
try {
|
51
|
+
const stats = await stat(file);
|
52
|
+
return stats.isDirectory();
|
53
|
+
} catch (error) {
|
54
|
+
return onError(error);
|
55
|
+
}
|
56
|
+
});
|
211
57
|
|
212
|
-
|
213
|
-
|
214
|
-
|
215
|
-
|
216
|
-
|
217
|
-
|
218
|
-
|
219
|
-
|
220
|
-
return stats.isFile();
|
221
|
-
} catch (error) {
|
222
|
-
return onError(error);
|
223
|
-
}
|
224
|
-
});
|
58
|
+
const isFileCached = makeCache(async (file) => {
|
59
|
+
try {
|
60
|
+
const stats = await stat(file);
|
61
|
+
return stats.isFile();
|
62
|
+
} catch (error) {
|
63
|
+
return onError(error);
|
64
|
+
}
|
65
|
+
});
|
225
66
|
|
226
|
-
return function (_x4) {
|
227
|
-
return _ref3.apply(this, arguments);
|
228
|
-
};
|
229
|
-
}());
|
230
67
|
const readCachedFile = makeCache(readFile);
|
231
68
|
|
232
|
-
const resolveId = promisify(resolveModule);
|
69
|
+
const resolveId = promisify(resolveModule);
|
233
70
|
|
71
|
+
// returns the imported package name for bare module imports
|
234
72
|
function getPackageName(id) {
|
235
73
|
if (id.startsWith('.') || id.startsWith('/')) {
|
236
74
|
return null;
|
237
75
|
}
|
238
76
|
|
239
|
-
const split = id.split('/');
|
240
|
-
// @my-scope/my-package -> @my-scope/my-package
|
77
|
+
const split = id.split('/');
|
241
78
|
|
79
|
+
// @my-scope/my-package/foo.js -> @my-scope/my-package
|
80
|
+
// @my-scope/my-package -> @my-scope/my-package
|
242
81
|
if (split[0][0] === '@') {
|
243
82
|
return `${split[0]}/${split[1]}`;
|
244
|
-
}
|
245
|
-
// my-package -> my-package
|
246
|
-
|
83
|
+
}
|
247
84
|
|
85
|
+
// my-package/foo.js -> my-package
|
86
|
+
// my-package -> my-package
|
248
87
|
return split[0];
|
249
88
|
}
|
89
|
+
|
250
90
|
function getMainFields(options) {
|
251
91
|
let mainFields;
|
252
|
-
|
253
92
|
if (options.mainFields) {
|
254
|
-
mainFields = options
|
93
|
+
({ mainFields } = options);
|
255
94
|
} else {
|
256
95
|
mainFields = ['module', 'main'];
|
257
96
|
}
|
258
|
-
|
259
97
|
if (options.browser && mainFields.indexOf('browser') === -1) {
|
260
98
|
return ['browser'].concat(mainFields);
|
261
99
|
}
|
262
|
-
|
263
100
|
if (!mainFields.length) {
|
264
101
|
throw new Error('Please ensure at least one `mainFields` value is specified');
|
265
102
|
}
|
266
|
-
|
267
103
|
return mainFields;
|
268
104
|
}
|
105
|
+
|
269
106
|
function getPackageInfo(options) {
|
270
|
-
const cache = options
|
271
|
-
|
272
|
-
pkg = options.pkg,
|
273
|
-
mainFields = options.mainFields,
|
274
|
-
preserveSymlinks = options.preserveSymlinks,
|
275
|
-
useBrowserOverrides = options.useBrowserOverrides;
|
276
|
-
let pkgPath = options.pkgPath;
|
107
|
+
const { cache, extensions, pkg, mainFields, preserveSymlinks, useBrowserOverrides } = options;
|
108
|
+
let { pkgPath } = options;
|
277
109
|
|
278
110
|
if (cache.has(pkgPath)) {
|
279
111
|
return cache.get(pkgPath);
|
280
|
-
}
|
281
|
-
|
112
|
+
}
|
282
113
|
|
114
|
+
// browserify/resolve doesn't realpath paths returned in its packageFilter callback
|
283
115
|
if (!preserveSymlinks) {
|
284
116
|
pkgPath = realpathSync(pkgPath);
|
285
117
|
}
|
286
118
|
|
287
119
|
const pkgRoot = dirname(pkgPath);
|
120
|
+
|
288
121
|
const packageInfo = {
|
289
122
|
// copy as we are about to munge the `main` field of `pkg`.
|
290
123
|
packageJson: Object.assign({}, pkg),
|
124
|
+
|
291
125
|
// path to package.json file
|
292
126
|
packageJsonPath: pkgPath,
|
127
|
+
|
293
128
|
// directory containing the package.json
|
294
129
|
root: pkgRoot,
|
130
|
+
|
295
131
|
// which main field was used during resolution of this module (main, module, or browser)
|
296
132
|
resolvedMainField: 'main',
|
133
|
+
|
297
134
|
// whether the browser map was used to resolve the entry point to this module
|
298
135
|
browserMappedMain: false,
|
136
|
+
|
299
137
|
// the entry point of the module with respect to the selected main field and any
|
300
138
|
// relevant browser mappings.
|
301
139
|
resolvedEntryPoint: ''
|
302
140
|
};
|
303
|
-
let overriddenMain = false;
|
304
141
|
|
142
|
+
let overriddenMain = false;
|
305
143
|
for (let i = 0; i < mainFields.length; i++) {
|
306
144
|
const field = mainFields[i];
|
307
|
-
|
308
145
|
if (typeof pkg[field] === 'string') {
|
309
146
|
pkg.main = pkg[field];
|
310
147
|
packageInfo.resolvedMainField = field;
|
@@ -317,37 +154,38 @@ function getPackageInfo(options) {
|
|
317
154
|
cachedPkg: pkg,
|
318
155
|
hasModuleSideEffects: () => null,
|
319
156
|
hasPackageEntry: overriddenMain !== false || mainFields.indexOf('main') !== -1,
|
320
|
-
packageBrowserField:
|
321
|
-
|
322
|
-
|
323
|
-
|
324
|
-
resolved =
|
325
|
-
|
326
|
-
|
327
|
-
|
328
|
-
|
329
|
-
browser[key] = resolved;
|
330
|
-
|
331
|
-
if (key[0] === '.') {
|
332
|
-
const absoluteKey = resolve(pkgRoot, key);
|
333
|
-
browser[absoluteKey] = resolved;
|
334
|
-
|
335
|
-
if (!extname(key)) {
|
336
|
-
extensions.reduce((subBrowser, ext) => {
|
337
|
-
subBrowser[absoluteKey + ext] = subBrowser[key];
|
338
|
-
return subBrowser;
|
339
|
-
}, browser);
|
157
|
+
packageBrowserField:
|
158
|
+
useBrowserOverrides &&
|
159
|
+
typeof pkg.browser === 'object' &&
|
160
|
+
Object.keys(pkg.browser).reduce((browser, key) => {
|
161
|
+
let resolved = pkg.browser[key];
|
162
|
+
if (resolved && resolved[0] === '.') {
|
163
|
+
resolved = resolve(pkgRoot, resolved);
|
340
164
|
}
|
341
|
-
|
342
|
-
|
343
|
-
|
344
|
-
|
165
|
+
/* eslint-disable no-param-reassign */
|
166
|
+
browser[key] = resolved;
|
167
|
+
if (key[0] === '.') {
|
168
|
+
const absoluteKey = resolve(pkgRoot, key);
|
169
|
+
browser[absoluteKey] = resolved;
|
170
|
+
if (!extname(key)) {
|
171
|
+
extensions.reduce((subBrowser, ext) => {
|
172
|
+
subBrowser[absoluteKey + ext] = subBrowser[key];
|
173
|
+
return subBrowser;
|
174
|
+
}, browser);
|
175
|
+
}
|
176
|
+
}
|
177
|
+
return browser;
|
178
|
+
}, {}),
|
345
179
|
packageInfo
|
346
180
|
};
|
347
|
-
const browserMap = internalPackageInfo.packageBrowserField;
|
348
181
|
|
349
|
-
|
350
|
-
|
182
|
+
const browserMap = internalPackageInfo.packageBrowserField;
|
183
|
+
if (
|
184
|
+
useBrowserOverrides &&
|
185
|
+
typeof pkg.browser === 'object' &&
|
186
|
+
// eslint-disable-next-line no-prototype-builtins
|
187
|
+
browserMap.hasOwnProperty(pkg.main)
|
188
|
+
) {
|
351
189
|
packageInfo.resolvedEntryPoint = browserMap[pkg.main];
|
352
190
|
packageInfo.browserMappedMain = true;
|
353
191
|
} else {
|
@@ -357,7 +195,6 @@ function getPackageInfo(options) {
|
|
357
195
|
}
|
358
196
|
|
359
197
|
const packageSideEffects = pkg.sideEffects;
|
360
|
-
|
361
198
|
if (typeof packageSideEffects === 'boolean') {
|
362
199
|
internalPackageInfo.hasModuleSideEffects = () => packageSideEffects;
|
363
200
|
} else if (Array.isArray(packageSideEffects)) {
|
@@ -369,40 +206,41 @@ function getPackageInfo(options) {
|
|
369
206
|
cache.set(pkgPath, internalPackageInfo);
|
370
207
|
return internalPackageInfo;
|
371
208
|
}
|
209
|
+
|
372
210
|
function normalizeInput(input) {
|
373
211
|
if (Array.isArray(input)) {
|
374
212
|
return input;
|
375
213
|
} else if (typeof input === 'object') {
|
376
214
|
return Object.values(input);
|
377
|
-
}
|
378
|
-
|
215
|
+
}
|
379
216
|
|
217
|
+
// otherwise it's a string
|
380
218
|
return [input];
|
381
|
-
}
|
382
|
-
// successfully, or the error that resulted from the last attempted module resolution.
|
219
|
+
}
|
383
220
|
|
221
|
+
// Resolve module specifiers in order. Promise resolves to the first module that resolves
|
222
|
+
// successfully, or the error that resulted from the last attempted module resolution.
|
384
223
|
function resolveImportSpecifiers(importSpecifierList, resolveOptions) {
|
385
224
|
let promise = Promise.resolve();
|
386
225
|
|
387
226
|
for (let i = 0; i < importSpecifierList.length; i++) {
|
388
|
-
promise = promise.then(value => {
|
227
|
+
promise = promise.then((value) => {
|
389
228
|
// if we've already resolved to something, just return it.
|
390
229
|
if (value) {
|
391
230
|
return value;
|
392
231
|
}
|
393
232
|
|
394
|
-
return resolveId(importSpecifierList[i], resolveOptions).then(result => {
|
233
|
+
return resolveId(importSpecifierList[i], resolveOptions).then((result) => {
|
395
234
|
if (!resolveOptions.preserveSymlinks) {
|
396
235
|
result = realpathSync(result);
|
397
236
|
}
|
398
|
-
|
399
237
|
return result;
|
400
238
|
});
|
401
239
|
});
|
402
240
|
|
403
241
|
if (i < importSpecifierList.length - 1) {
|
404
242
|
// swallow MODULE_NOT_FOUND errors from all but the last resolution
|
405
|
-
promise = promise.catch(error => {
|
243
|
+
promise = promise.catch((error) => {
|
406
244
|
if (error.code !== 'MODULE_NOT_FOUND') {
|
407
245
|
throw error;
|
408
246
|
}
|
@@ -413,11 +251,22 @@ function resolveImportSpecifiers(importSpecifierList, resolveOptions) {
|
|
413
251
|
return promise;
|
414
252
|
}
|
415
253
|
|
254
|
+
/* eslint-disable no-param-reassign, no-shadow, no-undefined */
|
255
|
+
|
416
256
|
const builtins = new Set(builtinList);
|
417
257
|
const ES6_BROWSER_EMPTY = '\0node-resolve:empty.js';
|
418
|
-
|
419
258
|
const nullFn = () => null;
|
259
|
+
const deepFreeze = (object) => {
|
260
|
+
Object.freeze(object);
|
261
|
+
|
262
|
+
for (const value of Object.values(object)) {
|
263
|
+
if (typeof value === 'object' && !Object.isFrozen(value)) {
|
264
|
+
deepFreeze(value);
|
265
|
+
}
|
266
|
+
}
|
420
267
|
|
268
|
+
return object;
|
269
|
+
};
|
421
270
|
const defaults = {
|
422
271
|
customResolveOptions: {},
|
423
272
|
dedupe: [],
|
@@ -427,11 +276,10 @@ const defaults = {
|
|
427
276
|
resolveOnly: []
|
428
277
|
};
|
429
278
|
const DEFAULTS = deepFreeze(deepMerge({}, defaults));
|
279
|
+
|
430
280
|
function nodeResolve(opts = {}) {
|
431
281
|
const options = Object.assign({}, defaults, opts);
|
432
|
-
const customResolveOptions = options
|
433
|
-
extensions = options.extensions,
|
434
|
-
jail = options.jail;
|
282
|
+
const { customResolveOptions, extensions, jail } = options;
|
435
283
|
const warnings = [];
|
436
284
|
const packageInfoCache = new Map();
|
437
285
|
const idToPackageInfo = new Map();
|
@@ -440,7 +288,7 @@ function nodeResolve(opts = {}) {
|
|
440
288
|
const isPreferBuiltinsSet = options.preferBuiltins === true || options.preferBuiltins === false;
|
441
289
|
const preferBuiltins = isPreferBuiltinsSet ? options.preferBuiltins : true;
|
442
290
|
const rootDir = options.rootDir || process.cwd();
|
443
|
-
let dedupe = options
|
291
|
+
let { dedupe } = options;
|
444
292
|
let rollupOptions;
|
445
293
|
|
446
294
|
if (options.only) {
|
@@ -449,40 +297,32 @@ function nodeResolve(opts = {}) {
|
|
449
297
|
}
|
450
298
|
|
451
299
|
if (typeof dedupe !== 'function') {
|
452
|
-
dedupe =
|
300
|
+
dedupe = (importee) =>
|
301
|
+
options.dedupe.includes(importee) || options.dedupe.includes(getPackageName(importee));
|
453
302
|
}
|
454
303
|
|
455
|
-
const resolveOnly = options.resolveOnly.map(pattern => {
|
304
|
+
const resolveOnly = options.resolveOnly.map((pattern) => {
|
456
305
|
if (pattern instanceof RegExp) {
|
457
306
|
return pattern;
|
458
307
|
}
|
459
|
-
|
460
308
|
const normalized = pattern.replace(/[\\^$*+?.()|[\]{}]/g, '\\$&');
|
461
309
|
return new RegExp(`^${normalized}$`);
|
462
310
|
});
|
311
|
+
|
463
312
|
const browserMapCache = new Map();
|
464
313
|
let preserveSymlinks;
|
314
|
+
|
465
315
|
return {
|
466
316
|
name: 'node-resolve',
|
467
317
|
|
468
318
|
buildStart(options) {
|
469
319
|
rollupOptions = options;
|
470
320
|
|
471
|
-
|
472
|
-
|
473
|
-
|
474
|
-
try {
|
475
|
-
for (_iterator.s(); !(_step = _iterator.n()).done;) {
|
476
|
-
const warning = _step.value;
|
477
|
-
this.warn(warning);
|
478
|
-
}
|
479
|
-
} catch (err) {
|
480
|
-
_iterator.e(err);
|
481
|
-
} finally {
|
482
|
-
_iterator.f();
|
321
|
+
for (const warning of warnings) {
|
322
|
+
this.warn(warning);
|
483
323
|
}
|
484
324
|
|
485
|
-
preserveSymlinks = options
|
325
|
+
({ preserveSymlinks } = options);
|
486
326
|
},
|
487
327
|
|
488
328
|
generateBundle() {
|
@@ -491,217 +331,200 @@ function nodeResolve(opts = {}) {
|
|
491
331
|
isDirCached.clear();
|
492
332
|
},
|
493
333
|
|
494
|
-
resolveId(importee, importer) {
|
495
|
-
|
496
|
-
|
497
|
-
|
498
|
-
|
499
|
-
|
500
|
-
|
501
|
-
|
502
|
-
|
503
|
-
|
504
|
-
|
505
|
-
|
506
|
-
|
507
|
-
|
508
|
-
|
509
|
-
|
510
|
-
|
511
|
-
|
512
|
-
|
513
|
-
|
514
|
-
|
515
|
-
const importSuffix = `${params ? `?${params}` : ''}${hash ? `#${hash}` : ''}`;
|
516
|
-
importee = importPath;
|
517
|
-
const basedir = !importer || dedupe(importee) ? rootDir : dirname(importer); // https://github.com/defunctzombie/package-browser-field-spec
|
518
|
-
|
519
|
-
const browser = browserMapCache.get(importer);
|
520
|
-
|
521
|
-
if (useBrowserOverrides && browser) {
|
522
|
-
const resolvedImportee = resolve(basedir, importee);
|
523
|
-
|
524
|
-
if (browser[importee] === false || browser[resolvedImportee] === false) {
|
525
|
-
return ES6_BROWSER_EMPTY;
|
526
|
-
}
|
527
|
-
|
528
|
-
const browserImportee = browser[importee] || browser[resolvedImportee] || browser[`${resolvedImportee}.js`] || browser[`${resolvedImportee}.json`];
|
529
|
-
|
530
|
-
if (browserImportee) {
|
531
|
-
importee = browserImportee;
|
532
|
-
}
|
334
|
+
async resolveId(importee, importer) {
|
335
|
+
if (importee === ES6_BROWSER_EMPTY) {
|
336
|
+
return importee;
|
337
|
+
}
|
338
|
+
// ignore IDs with null character, these belong to other plugins
|
339
|
+
if (/\0/.test(importee)) return null;
|
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}` : ''}`;
|
345
|
+
importee = importPath;
|
346
|
+
|
347
|
+
const basedir = !importer || dedupe(importee) ? rootDir : dirname(importer);
|
348
|
+
|
349
|
+
// https://github.com/defunctzombie/package-browser-field-spec
|
350
|
+
const browser = browserMapCache.get(importer);
|
351
|
+
if (useBrowserOverrides && browser) {
|
352
|
+
const resolvedImportee = resolve(basedir, importee);
|
353
|
+
if (browser[importee] === false || browser[resolvedImportee] === false) {
|
354
|
+
return ES6_BROWSER_EMPTY;
|
533
355
|
}
|
534
|
-
|
535
|
-
|
536
|
-
|
537
|
-
|
538
|
-
|
539
|
-
if (
|
540
|
-
|
541
|
-
id += `/${parts.shift()}`;
|
542
|
-
} else if (id[0] === '.') {
|
543
|
-
// an import relative to the parent dir of the importer
|
544
|
-
id = resolve(basedir, importee);
|
545
|
-
isRelativeImport = true;
|
356
|
+
const browserImportee =
|
357
|
+
browser[importee] ||
|
358
|
+
browser[resolvedImportee] ||
|
359
|
+
browser[`${resolvedImportee}.js`] ||
|
360
|
+
browser[`${resolvedImportee}.json`];
|
361
|
+
if (browserImportee) {
|
362
|
+
importee = browserImportee;
|
546
363
|
}
|
364
|
+
}
|
547
365
|
|
548
|
-
|
549
|
-
|
550
|
-
|
551
|
-
|
366
|
+
const parts = importee.split(/[/\\]/);
|
367
|
+
let id = parts.shift();
|
368
|
+
let isRelativeImport = false;
|
369
|
+
|
370
|
+
if (id[0] === '@' && parts.length > 0) {
|
371
|
+
// scoped packages
|
372
|
+
id += `/${parts.shift()}`;
|
373
|
+
} else if (id[0] === '.') {
|
374
|
+
// an import relative to the parent dir of the importer
|
375
|
+
id = resolve(basedir, importee);
|
376
|
+
isRelativeImport = true;
|
377
|
+
}
|
552
378
|
|
553
|
-
|
379
|
+
if (
|
380
|
+
!isRelativeImport &&
|
381
|
+
resolveOnly.length &&
|
382
|
+
!resolveOnly.some((pattern) => pattern.test(id))
|
383
|
+
) {
|
384
|
+
if (normalizeInput(rollupOptions.input).includes(importee)) {
|
385
|
+
return null;
|
554
386
|
}
|
387
|
+
return false;
|
388
|
+
}
|
555
389
|
|
556
|
-
|
557
|
-
|
558
|
-
|
559
|
-
|
560
|
-
|
561
|
-
|
562
|
-
|
563
|
-
|
564
|
-
|
565
|
-
|
566
|
-
|
567
|
-
|
568
|
-
|
569
|
-
|
570
|
-
|
571
|
-
|
572
|
-
|
573
|
-
|
574
|
-
|
575
|
-
|
576
|
-
};
|
577
|
-
|
578
|
-
let resolveOptions = {
|
579
|
-
basedir,
|
580
|
-
packageFilter: filter,
|
581
|
-
readFile: readCachedFile,
|
582
|
-
isFile: isFileCached,
|
583
|
-
isDirectory: isDirCached,
|
584
|
-
extensions
|
585
|
-
};
|
586
|
-
|
587
|
-
if (preserveSymlinks !== undefined) {
|
588
|
-
resolveOptions.preserveSymlinks = preserveSymlinks;
|
589
|
-
}
|
390
|
+
let hasModuleSideEffects = nullFn;
|
391
|
+
let hasPackageEntry = true;
|
392
|
+
let packageBrowserField = false;
|
393
|
+
let packageInfo;
|
394
|
+
|
395
|
+
const filter = (pkg, pkgPath) => {
|
396
|
+
const info = getPackageInfo({
|
397
|
+
cache: packageInfoCache,
|
398
|
+
extensions,
|
399
|
+
pkg,
|
400
|
+
pkgPath,
|
401
|
+
mainFields,
|
402
|
+
preserveSymlinks,
|
403
|
+
useBrowserOverrides
|
404
|
+
});
|
405
|
+
|
406
|
+
({ packageInfo, hasModuleSideEffects, hasPackageEntry, packageBrowserField } = info);
|
407
|
+
|
408
|
+
return info.cachedPkg;
|
409
|
+
};
|
590
410
|
|
591
|
-
|
411
|
+
let resolveOptions = {
|
412
|
+
basedir,
|
413
|
+
packageFilter: filter,
|
414
|
+
readFile: readCachedFile,
|
415
|
+
isFile: isFileCached,
|
416
|
+
isDirectory: isDirCached,
|
417
|
+
extensions
|
418
|
+
};
|
592
419
|
|
593
|
-
|
594
|
-
|
595
|
-
|
596
|
-
// found in rollup config files. If importee doesn't look like a
|
597
|
-
// relative or absolute path, we make it relative and attempt to
|
598
|
-
// resolve it. If we don't find anything, we try resolving it as we
|
599
|
-
// got it.
|
600
|
-
importSpecifierList.push(`./${importee}`);
|
601
|
-
}
|
420
|
+
if (preserveSymlinks !== undefined) {
|
421
|
+
resolveOptions.preserveSymlinks = preserveSymlinks;
|
422
|
+
}
|
602
423
|
|
603
|
-
|
424
|
+
const importSpecifierList = [];
|
604
425
|
|
605
|
-
|
606
|
-
|
607
|
-
|
608
|
-
|
609
|
-
|
610
|
-
|
611
|
-
|
612
|
-
|
613
|
-
|
426
|
+
if (importer === undefined && !importee[0].match(/^\.?\.?\//)) {
|
427
|
+
// For module graph roots (i.e. when importer is undefined), we
|
428
|
+
// need to handle 'path fragments` like `foo/bar` that are commonly
|
429
|
+
// found in rollup config files. If importee doesn't look like a
|
430
|
+
// relative or absolute path, we make it relative and attempt to
|
431
|
+
// resolve it. If we don't find anything, we try resolving it as we
|
432
|
+
// got it.
|
433
|
+
importSpecifierList.push(`./${importee}`);
|
434
|
+
}
|
614
435
|
|
436
|
+
const importeeIsBuiltin = builtins.has(importee);
|
615
437
|
|
616
|
-
|
617
|
-
|
618
|
-
|
438
|
+
if (importeeIsBuiltin && (!preferBuiltins || !isPreferBuiltinsSet)) {
|
439
|
+
// The `resolve` library will not resolve packages with the same
|
440
|
+
// name as a node built-in module. If we're resolving something
|
441
|
+
// that's a builtin, and we don't prefer to find built-ins, we
|
442
|
+
// first try to look up a local module with that name. If we don't
|
443
|
+
// find anything, we resolve the builtin which just returns back
|
444
|
+
// the built-in's name.
|
445
|
+
importSpecifierList.push(`${importee}/`);
|
446
|
+
}
|
619
447
|
|
620
|
-
|
621
|
-
|
622
|
-
|
448
|
+
// TypeScript files may import '.js' to refer to either '.ts' or '.tsx'
|
449
|
+
if (importer && importee.endsWith('.js')) {
|
450
|
+
for (const ext of ['.ts', '.tsx']) {
|
451
|
+
if (importer.endsWith(ext) && extensions.includes(ext)) {
|
452
|
+
importSpecifierList.push(importee.replace(/.js$/, ext));
|
623
453
|
}
|
624
454
|
}
|
455
|
+
}
|
625
456
|
|
626
|
-
|
627
|
-
|
628
|
-
|
629
|
-
try {
|
630
|
-
let resolved = yield resolveImportSpecifiers(importSpecifierList, resolveOptions);
|
631
|
-
|
632
|
-
if (resolved && packageBrowserField) {
|
633
|
-
if (Object.prototype.hasOwnProperty.call(packageBrowserField, resolved)) {
|
634
|
-
if (!packageBrowserField[resolved]) {
|
635
|
-
browserMapCache.set(resolved, packageBrowserField);
|
636
|
-
return ES6_BROWSER_EMPTY;
|
637
|
-
}
|
638
|
-
|
639
|
-
resolved = packageBrowserField[resolved];
|
640
|
-
}
|
641
|
-
|
642
|
-
browserMapCache.set(resolved, packageBrowserField);
|
643
|
-
}
|
457
|
+
importSpecifierList.push(importee);
|
458
|
+
resolveOptions = Object.assign(resolveOptions, customResolveOptions);
|
644
459
|
|
645
|
-
|
646
|
-
|
460
|
+
try {
|
461
|
+
let resolved = await resolveImportSpecifiers(importSpecifierList, resolveOptions);
|
647
462
|
|
648
|
-
|
649
|
-
|
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;
|
650
468
|
}
|
469
|
+
resolved = packageBrowserField[resolved];
|
651
470
|
}
|
471
|
+
browserMapCache.set(resolved, packageBrowserField);
|
472
|
+
}
|
652
473
|
|
653
|
-
|
654
|
-
|
655
|
-
if (
|
656
|
-
|
657
|
-
return null;
|
658
|
-
} else if (importeeIsBuiltin && preferBuiltins) {
|
659
|
-
if (!isPreferBuiltinsSet) {
|
660
|
-
_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`);
|
661
|
-
}
|
662
|
-
|
663
|
-
return null;
|
664
|
-
} else if (jail && resolved.indexOf(normalize(jail.trim(sep))) !== 0) {
|
665
|
-
return null;
|
666
|
-
}
|
474
|
+
if (hasPackageEntry && !preserveSymlinks && resolved) {
|
475
|
+
const fileExists = await exists(resolved);
|
476
|
+
if (fileExists) {
|
477
|
+
resolved = await realpath(resolved);
|
667
478
|
}
|
479
|
+
}
|
668
480
|
|
669
|
-
|
670
|
-
const code = yield readFile(resolved, 'utf-8');
|
481
|
+
idToPackageInfo.set(resolved, packageInfo);
|
671
482
|
|
672
|
-
|
673
|
-
|
674
|
-
|
675
|
-
|
676
|
-
|
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
|
+
);
|
677
491
|
}
|
678
|
-
|
492
|
+
return null;
|
493
|
+
} else if (jail && resolved.indexOf(normalize(jail.trim(sep))) !== 0) {
|
679
494
|
return null;
|
680
495
|
}
|
496
|
+
}
|
681
497
|
|
682
|
-
|
683
|
-
|
684
|
-
|
685
|
-
|
686
|
-
|
687
|
-
|
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
|
+
};
|
505
|
+
}
|
688
506
|
return null;
|
689
507
|
}
|
690
|
-
|
508
|
+
const result = {
|
509
|
+
id: `${resolved}${importSuffix}`,
|
510
|
+
moduleSideEffects: hasModuleSideEffects(resolved)
|
511
|
+
};
|
512
|
+
return result;
|
513
|
+
} catch (error) {
|
514
|
+
return null;
|
515
|
+
}
|
691
516
|
},
|
692
517
|
|
693
518
|
load(importee) {
|
694
519
|
if (importee === ES6_BROWSER_EMPTY) {
|
695
520
|
return 'export default {};';
|
696
521
|
}
|
697
|
-
|
698
522
|
return null;
|
699
523
|
},
|
700
524
|
|
701
525
|
getPackageInfoForId(id) {
|
702
526
|
return idToPackageInfo.get(id);
|
703
527
|
}
|
704
|
-
|
705
528
|
};
|
706
529
|
}
|
707
530
|
|