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