@rollup/plugin-commonjs 19.0.0 → 19.0.1

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 CHANGED
@@ -1,5 +1,13 @@
1
1
  # @rollup/plugin-commonjs ChangeLog
2
2
 
3
+ ## v19.0.1
4
+
5
+ _2021-07-15_
6
+
7
+ ### Bugfixes
8
+
9
+ - fix: short-circuit to actual module entry point when using circular ref through a different entry (#888)
10
+
3
11
  ## v19.0.0
4
12
 
5
13
  _2021-05-07_
package/dist/index.es.js CHANGED
@@ -151,8 +151,18 @@ export function commonjsRegister (path, loader) {
151
151
  DYNAMIC_REQUIRE_LOADERS[path] = loader;
152
152
  }
153
153
 
154
+ export function commonjsRegisterOrShort (path, to) {
155
+ const resolvedPath = commonjsResolveImpl(path, null, true);
156
+ if (resolvedPath !== null && DYNAMIC_REQUIRE_CACHE[resolvedPath]) {
157
+ DYNAMIC_REQUIRE_CACHE[path] = DYNAMIC_REQUIRE_CACHE[resolvedPath];
158
+ } else {
159
+ DYNAMIC_REQUIRE_SHORTS[path] = to;
160
+ }
161
+ }
162
+
154
163
  const DYNAMIC_REQUIRE_LOADERS = Object.create(null);
155
164
  const DYNAMIC_REQUIRE_CACHE = Object.create(null);
165
+ const DYNAMIC_REQUIRE_SHORTS = Object.create(null);
156
166
  const DEFAULT_PARENT_MODULE = {
157
167
  id: '<' + 'rollup>', exports: {}, parent: undefined, filename: null, loaded: false, children: [], paths: []
158
168
  };
@@ -257,10 +267,13 @@ export function commonjsResolveImpl (path, originalModuleDir, testCache) {
257
267
  const resolvedPath = relPath + CHECKED_EXTENSIONS[extensionIndex];
258
268
  if (DYNAMIC_REQUIRE_CACHE[resolvedPath]) {
259
269
  return resolvedPath;
260
- };
270
+ }
271
+ if (DYNAMIC_REQUIRE_SHORTS[resolvedPath]) {
272
+ return resolvedPath;
273
+ }
261
274
  if (DYNAMIC_REQUIRE_LOADERS[resolvedPath]) {
262
275
  return resolvedPath;
263
- };
276
+ }
264
277
  }
265
278
  if (!shouldTryNodeModules) break;
266
279
  const nextDir = normalize(originalModuleDir + '/..');
@@ -279,10 +292,17 @@ export function commonjsResolve (path, originalModuleDir) {
279
292
  }
280
293
 
281
294
  export function commonjsRequire (path, originalModuleDir) {
282
- const resolvedPath = commonjsResolveImpl(path, originalModuleDir, true);
295
+ let resolvedPath = commonjsResolveImpl(path, originalModuleDir, true);
283
296
  if (resolvedPath !== null) {
284
297
  let cachedModule = DYNAMIC_REQUIRE_CACHE[resolvedPath];
285
298
  if (cachedModule) return cachedModule.exports;
299
+ let shortTo = DYNAMIC_REQUIRE_SHORTS[resolvedPath];
300
+ if (shortTo) {
301
+ cachedModule = DYNAMIC_REQUIRE_CACHE[shortTo];
302
+ if (cachedModule)
303
+ return cachedModule.exports;
304
+ resolvedPath = commonjsResolveImpl(shortTo, null, true);
305
+ }
286
306
  const loader = DYNAMIC_REQUIRE_LOADERS[resolvedPath];
287
307
  if (loader) {
288
308
  DYNAMIC_REQUIRE_CACHE[resolvedPath] = cachedModule = {
@@ -379,15 +399,13 @@ function getPackageEntryPoint(dirPath) {
379
399
  }
380
400
 
381
401
  function getDynamicPackagesModule(dynamicRequireModuleDirPaths, commonDir) {
382
- let code = `const commonjsRegister = require('${HELPERS_ID}?commonjsRegister');`;
402
+ let code = `const commonjsRegisterOrShort = require('${HELPERS_ID}?commonjsRegisterOrShort');`;
383
403
  for (const dir of dynamicRequireModuleDirPaths) {
384
404
  const entryPoint = getPackageEntryPoint(dir);
385
405
 
386
- code += `\ncommonjsRegister(${JSON.stringify(
406
+ code += `\ncommonjsRegisterOrShort(${JSON.stringify(
387
407
  getVirtualPathForDynamicRequirePath(dir, commonDir)
388
- )}, function (module, exports) {
389
- module.exports = require(${JSON.stringify(normalizePathSlashes(join(dir, entryPoint)))});
390
- });`;
408
+ )}, ${JSON.stringify(getVirtualPathForDynamicRequirePath(join(dir, entryPoint), commonDir))});`;
391
409
  }
392
410
  return code;
393
411
  }