@rollup/plugin-commonjs 20.0.0 → 21.0.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/index.js CHANGED
@@ -161,7 +161,7 @@ export function commonjsRegister (path, loader) {
161
161
  }
162
162
 
163
163
  export function commonjsRegisterOrShort (path, to) {
164
- const resolvedPath = commonjsResolveImpl(path, null, true);
164
+ var resolvedPath = commonjsResolveImpl(path, null, true);
165
165
  if (resolvedPath !== null && DYNAMIC_REQUIRE_CACHE[resolvedPath]) {
166
166
  DYNAMIC_REQUIRE_CACHE[path] = DYNAMIC_REQUIRE_CACHE[resolvedPath];
167
167
  } else {
@@ -169,24 +169,24 @@ export function commonjsRegisterOrShort (path, to) {
169
169
  }
170
170
  }
171
171
 
172
- const DYNAMIC_REQUIRE_LOADERS = Object.create(null);
173
- const DYNAMIC_REQUIRE_CACHE = Object.create(null);
174
- const DYNAMIC_REQUIRE_SHORTS = Object.create(null);
175
- const DEFAULT_PARENT_MODULE = {
172
+ var DYNAMIC_REQUIRE_LOADERS = Object.create(null);
173
+ var DYNAMIC_REQUIRE_CACHE = Object.create(null);
174
+ var DYNAMIC_REQUIRE_SHORTS = Object.create(null);
175
+ var DEFAULT_PARENT_MODULE = {
176
176
  id: '<' + 'rollup>', exports: {}, parent: undefined, filename: null, loaded: false, children: [], paths: []
177
177
  };
178
- const CHECKED_EXTENSIONS = ['', '.js', '.json'];
178
+ var CHECKED_EXTENSIONS = ['', '.js', '.json'];
179
179
 
180
180
  function normalize (path) {
181
181
  path = path.replace(/\\\\/g, '/');
182
- const parts = path.split('/');
183
- const slashed = parts[0] === '';
184
- for (let i = 1; i < parts.length; i++) {
182
+ var parts = path.split('/');
183
+ var slashed = parts[0] === '';
184
+ for (var i = 1; i < parts.length; i++) {
185
185
  if (parts[i] === '.' || parts[i] === '') {
186
186
  parts.splice(i--, 1);
187
187
  }
188
188
  }
189
- for (let i = 1; i < parts.length; i++) {
189
+ for (var i = 1; i < parts.length; i++) {
190
190
  if (parts[i] !== '..') continue;
191
191
  if (i > 0 && parts[i - 1] !== '..' && parts[i - 1] !== '.') {
192
192
  parts.splice(--i, 2);
@@ -204,9 +204,9 @@ function normalize (path) {
204
204
  function join () {
205
205
  if (arguments.length === 0)
206
206
  return '.';
207
- let joined;
208
- for (let i = 0; i < arguments.length; ++i) {
209
- let arg = arguments[i];
207
+ var joined;
208
+ for (var i = 0; i < arguments.length; ++i) {
209
+ var arg = arguments[i];
210
210
  if (arg.length > 0) {
211
211
  if (joined === undefined)
212
212
  joined = arg;
@@ -221,9 +221,9 @@ function join () {
221
221
  }
222
222
 
223
223
  function isPossibleNodeModulesPath (modulePath) {
224
- let c0 = modulePath[0];
224
+ var c0 = modulePath[0];
225
225
  if (c0 === '/' || c0 === '\\\\') return false;
226
- let c1 = modulePath[1], c2 = modulePath[2];
226
+ var c1 = modulePath[1], c2 = modulePath[2];
227
227
  if ((c0 === '.' && (!c1 || c1 === '/' || c1 === '\\\\')) ||
228
228
  (c0 === '.' && c1 === '.' && (!c2 || c2 === '/' || c2 === '\\\\'))) return false;
229
229
  if (c1 === ':' && (c2 === '/' || c2 === '\\\\'))
@@ -235,9 +235,9 @@ function dirname (path) {
235
235
  if (path.length === 0)
236
236
  return '.';
237
237
 
238
- let i = path.length - 1;
238
+ var i = path.length - 1;
239
239
  while (i > 0) {
240
- const c = path.charCodeAt(i);
240
+ var c = path.charCodeAt(i);
241
241
  if ((c === 47 || c === 92) && i !== path.length - 1)
242
242
  break;
243
243
  i--;
@@ -253,9 +253,9 @@ function dirname (path) {
253
253
  }
254
254
 
255
255
  export function commonjsResolveImpl (path, originalModuleDir, testCache) {
256
- const shouldTryNodeModules = isPossibleNodeModulesPath(path);
256
+ var shouldTryNodeModules = isPossibleNodeModulesPath(path);
257
257
  path = normalize(path);
258
- let relPath;
258
+ var relPath;
259
259
  if (path[0] === '/') {
260
260
  originalModuleDir = '/';
261
261
  }
@@ -272,8 +272,8 @@ export function commonjsResolveImpl (path, originalModuleDir, testCache) {
272
272
  break; // Travelled too far up, avoid infinite loop
273
273
  }
274
274
 
275
- for (let extensionIndex = 0; extensionIndex < CHECKED_EXTENSIONS.length; extensionIndex++) {
276
- const resolvedPath = relPath + CHECKED_EXTENSIONS[extensionIndex];
275
+ for (var extensionIndex = 0; extensionIndex < CHECKED_EXTENSIONS.length; extensionIndex++) {
276
+ var resolvedPath = relPath + CHECKED_EXTENSIONS[extensionIndex];
277
277
  if (DYNAMIC_REQUIRE_CACHE[resolvedPath]) {
278
278
  return resolvedPath;
279
279
  }
@@ -285,7 +285,7 @@ export function commonjsResolveImpl (path, originalModuleDir, testCache) {
285
285
  }
286
286
  }
287
287
  if (!shouldTryNodeModules) break;
288
- const nextDir = normalize(originalModuleDir + '/..');
288
+ var nextDir = normalize(originalModuleDir + '/..');
289
289
  if (nextDir === originalModuleDir) break;
290
290
  originalModuleDir = nextDir;
291
291
  }
@@ -293,7 +293,7 @@ export function commonjsResolveImpl (path, originalModuleDir, testCache) {
293
293
  }
294
294
 
295
295
  export function commonjsResolve (path, originalModuleDir) {
296
- const resolvedPath = commonjsResolveImpl(path, originalModuleDir);
296
+ var resolvedPath = commonjsResolveImpl(path, originalModuleDir);
297
297
  if (resolvedPath !== null) {
298
298
  return resolvedPath;
299
299
  }
@@ -301,18 +301,18 @@ export function commonjsResolve (path, originalModuleDir) {
301
301
  }
302
302
 
303
303
  export function commonjsRequire (path, originalModuleDir) {
304
- let resolvedPath = commonjsResolveImpl(path, originalModuleDir, true);
304
+ var resolvedPath = commonjsResolveImpl(path, originalModuleDir, true);
305
305
  if (resolvedPath !== null) {
306
- let cachedModule = DYNAMIC_REQUIRE_CACHE[resolvedPath];
306
+ var cachedModule = DYNAMIC_REQUIRE_CACHE[resolvedPath];
307
307
  if (cachedModule) return cachedModule.exports;
308
- let shortTo = DYNAMIC_REQUIRE_SHORTS[resolvedPath];
308
+ var shortTo = DYNAMIC_REQUIRE_SHORTS[resolvedPath];
309
309
  if (shortTo) {
310
310
  cachedModule = DYNAMIC_REQUIRE_CACHE[shortTo];
311
311
  if (cachedModule)
312
312
  return cachedModule.exports;
313
313
  resolvedPath = commonjsResolveImpl(shortTo, null, true);
314
314
  }
315
- const loader = DYNAMIC_REQUIRE_LOADERS[resolvedPath];
315
+ var loader = DYNAMIC_REQUIRE_LOADERS[resolvedPath];
316
316
  if (loader) {
317
317
  DYNAMIC_REQUIRE_CACHE[resolvedPath] = cachedModule = {
318
318
  id: resolvedPath,
@@ -455,7 +455,7 @@ function getDynamicRequirePaths(patterns) {
455
455
  for (const pattern of !patterns || Array.isArray(patterns) ? patterns || [] : [patterns]) {
456
456
  const isNegated = pattern.startsWith('!');
457
457
  const modifySet = Set.prototype[isNegated ? 'delete' : 'add'].bind(dynamicRequireModuleSet);
458
- for (const path$1 of glob__default['default'].sync(isNegated ? pattern.substr(1) : pattern)) {
458
+ for (const path$1 of glob__default["default"].sync(isNegated ? pattern.substr(1) : pattern)) {
459
459
  modifySet(normalizePathSlashes(path.resolve(path$1)));
460
460
  if (isDirectory(path$1)) {
461
461
  modifySet(normalizePathSlashes(path.resolve(path.join(path$1, getPackageEntryPoint(path$1)))));
@@ -595,7 +595,7 @@ function getResolveId(extensions) {
595
595
  return undefined;
596
596
  }
597
597
 
598
- return function resolveId(importee, rawImporter) {
598
+ return function resolveId(importee, rawImporter, resolveOptions) {
599
599
  if (isWrappedId(importee, MODULE_SUFFIX) || isWrappedId(importee, EXPORTS_SUFFIX)) {
600
600
  return importee;
601
601
  }
@@ -638,10 +638,16 @@ function getResolveId(extensions) {
638
638
  return null;
639
639
  }
640
640
 
641
- return this.resolve(importee, importer, {
642
- skipSelf: true,
643
- custom: { 'node-resolve': { isRequire: isProxyModule || isRequiredModule } }
644
- }).then((resolved) => {
641
+ return this.resolve(
642
+ importee,
643
+ importer,
644
+ Object.assign({}, resolveOptions, {
645
+ skipSelf: true,
646
+ custom: Object.assign({}, resolveOptions.custom, {
647
+ 'node-resolve': { isRequire: isProxyModule || isRequiredModule }
648
+ })
649
+ })
650
+ ).then((resolved) => {
645
651
  if (!resolved) {
646
652
  resolved = resolveExtensions(importee, importer);
647
653
  }
@@ -1187,7 +1193,7 @@ function transformCommonjs(
1187
1193
  defaultIsModuleExports
1188
1194
  ) {
1189
1195
  const ast = astCache || tryParse(parse, code, id);
1190
- const magicString = new MagicString__default['default'](code);
1196
+ const magicString = new MagicString__default["default"](code);
1191
1197
  const uses = {
1192
1198
  module: false,
1193
1199
  exports: false,
@@ -1446,7 +1452,7 @@ function transformCommonjs(
1446
1452
  return;
1447
1453
  case 'Identifier': {
1448
1454
  const { name } = node;
1449
- if (!(isReference__default['default'](node, parent) && !scope.contains(name))) return;
1455
+ if (!(isReference__default["default"](node, parent) && !scope.contains(name))) return;
1450
1456
  switch (name) {
1451
1457
  case 'require':
1452
1458
  if (isNodeRequirePropertyAccess(parent)) {
@@ -1692,7 +1698,7 @@ function commonjs(options = {}) {
1692
1698
  );
1693
1699
  const isDynamicRequireModulesEnabled = dynamicRequireModuleSet.size > 0;
1694
1700
  const commonDir = isDynamicRequireModulesEnabled
1695
- ? getCommonDir__default['default'](null, Array.from(dynamicRequireModuleSet).concat(process.cwd()))
1701
+ ? getCommonDir__default["default"](null, Array.from(dynamicRequireModuleSet).concat(process.cwd()))
1696
1702
  : null;
1697
1703
 
1698
1704
  const esModulesWithDefaultExport = new Set();
@@ -1712,7 +1718,9 @@ function commonjs(options = {}) {
1712
1718
  ? options.ignoreTryCatch(id)
1713
1719
  : Array.isArray(options.ignoreTryCatch)
1714
1720
  ? options.ignoreTryCatch.includes(id)
1715
- : options.ignoreTryCatch || false;
1721
+ : typeof options.ignoreTryCatch !== 'undefined'
1722
+ ? options.ignoreTryCatch
1723
+ : true;
1716
1724
 
1717
1725
  return {
1718
1726
  canConvertRequire: mode !== 'remove' && mode !== true,