@rollup/plugin-commonjs 21.0.1 → 21.1.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/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,
@@ -1677,6 +1677,7 @@ function commonjs(options = {}) {
1677
1677
  ignoreGlobal,
1678
1678
  ignoreDynamicRequires,
1679
1679
  requireReturnsDefault: requireReturnsDefaultOption,
1680
+ defaultIsModuleExports: defaultIsModuleExportsOption,
1680
1681
  esmExternals
1681
1682
  } = options;
1682
1683
  const getRequireReturnsDefault =
@@ -1690,8 +1691,11 @@ function commonjs(options = {}) {
1690
1691
  : Array.isArray(esmExternals)
1691
1692
  ? ((esmExternalIds = new Set(esmExternals)), (id) => esmExternalIds.has(id))
1692
1693
  : () => esmExternals;
1693
- const defaultIsModuleExports =
1694
- typeof options.defaultIsModuleExports === 'boolean' ? options.defaultIsModuleExports : 'auto';
1694
+ const getDefaultIsModuleExports =
1695
+ typeof defaultIsModuleExportsOption === 'function'
1696
+ ? defaultIsModuleExportsOption
1697
+ : () =>
1698
+ typeof defaultIsModuleExportsOption === 'boolean' ? defaultIsModuleExportsOption : 'auto';
1695
1699
 
1696
1700
  const { dynamicRequireModuleSet, dynamicRequireModuleDirPaths } = getDynamicRequirePaths(
1697
1701
  options.dynamicRequireTargets
@@ -1780,7 +1784,7 @@ function commonjs(options = {}) {
1780
1784
  disableWrap,
1781
1785
  commonDir,
1782
1786
  ast,
1783
- defaultIsModuleExports
1787
+ getDefaultIsModuleExports(id)
1784
1788
  );
1785
1789
  }
1786
1790