@rollup/plugin-commonjs 25.0.5 → 25.0.6

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/cjs/index.js CHANGED
@@ -11,7 +11,7 @@ var estreeWalker = require('estree-walker');
11
11
  var MagicString = require('magic-string');
12
12
  var isReference = require('is-reference');
13
13
 
14
- var version = "25.0.5";
14
+ var version = "25.0.6";
15
15
  var peerDependencies = {
16
16
  rollup: "^2.68.0||^3.0.0||^4.0.0"
17
17
  };
@@ -434,7 +434,7 @@ async function getStaticRequireProxy(id, requireReturnsDefault, loadModule) {
434
434
  return `export { default } from ${JSON.stringify(id)};`;
435
435
  }
436
436
 
437
- function getEntryProxy(id, defaultIsModuleExports, getModuleInfo) {
437
+ function getEntryProxy(id, defaultIsModuleExports, getModuleInfo, shebang) {
438
438
  const {
439
439
  meta: { commonjs: commonjsMeta },
440
440
  hasDefaultExport
@@ -445,9 +445,13 @@ function getEntryProxy(id, defaultIsModuleExports, getModuleInfo) {
445
445
  if (hasDefaultExport) {
446
446
  code += `export { default } from ${stringifiedId};`;
447
447
  }
448
- return code;
448
+ return shebang + code;
449
449
  }
450
- return getEsImportProxy(id, defaultIsModuleExports);
450
+ const result = getEsImportProxy(id, defaultIsModuleExports);
451
+ return {
452
+ ...result,
453
+ code: shebang + result.code
454
+ };
451
455
  }
452
456
 
453
457
  function getEsImportProxy(id, defaultIsModuleExports) {
@@ -1901,6 +1905,13 @@ async function transformCommonjs(
1901
1905
  magicString.remove(0, commentEnd).trim();
1902
1906
  }
1903
1907
 
1908
+ let shebang = '';
1909
+ if (code.startsWith('#!')) {
1910
+ const shebangEndPosition = code.indexOf('\n') + 1;
1911
+ shebang = code.slice(0, shebangEndPosition);
1912
+ magicString.remove(0, shebangEndPosition).trim();
1913
+ }
1914
+
1904
1915
  const exportMode = isEsModule
1905
1916
  ? 'none'
1906
1917
  : shouldWrap
@@ -1984,14 +1995,14 @@ function ${requireName} () {
1984
1995
 
1985
1996
  magicString
1986
1997
  .trim()
1987
- .prepend(leadingComment + importBlock)
1998
+ .prepend(shebang + leadingComment + importBlock)
1988
1999
  .append(exportBlock);
1989
2000
 
1990
2001
  return {
1991
2002
  code: magicString.toString(),
1992
2003
  map: sourceMap ? magicString.generateMap() : null,
1993
2004
  syntheticNamedExports: isEsModule || usesRequireWrapper ? false : '__moduleExports',
1994
- meta: { commonjs: commonjsMeta }
2005
+ meta: { commonjs: { ...commonjsMeta, shebang } }
1995
2006
  };
1996
2007
  }
1997
2008
 
@@ -2233,7 +2244,16 @@ function commonjs(options = {}) {
2233
2244
  // entry suffix is just appended to not mess up relative external resolution
2234
2245
  if (id.endsWith(ENTRY_SUFFIX)) {
2235
2246
  const acutalId = id.slice(0, -ENTRY_SUFFIX.length);
2236
- return getEntryProxy(acutalId, getDefaultIsModuleExports(acutalId), this.getModuleInfo);
2247
+ const {
2248
+ meta: { commonjs: commonjsMeta }
2249
+ } = this.getModuleInfo(acutalId);
2250
+ const shebang = commonjsMeta?.shebang ?? '';
2251
+ return getEntryProxy(
2252
+ acutalId,
2253
+ getDefaultIsModuleExports(acutalId),
2254
+ this.getModuleInfo,
2255
+ shebang
2256
+ );
2237
2257
  }
2238
2258
 
2239
2259
  if (isWrappedId(id, ES_IMPORT_SUFFIX)) {
package/dist/es/index.js CHANGED
@@ -7,7 +7,7 @@ import { walk } from 'estree-walker';
7
7
  import MagicString from 'magic-string';
8
8
  import isReference from 'is-reference';
9
9
 
10
- var version = "25.0.5";
10
+ var version = "25.0.6";
11
11
  var peerDependencies = {
12
12
  rollup: "^2.68.0||^3.0.0||^4.0.0"
13
13
  };
@@ -430,7 +430,7 @@ async function getStaticRequireProxy(id, requireReturnsDefault, loadModule) {
430
430
  return `export { default } from ${JSON.stringify(id)};`;
431
431
  }
432
432
 
433
- function getEntryProxy(id, defaultIsModuleExports, getModuleInfo) {
433
+ function getEntryProxy(id, defaultIsModuleExports, getModuleInfo, shebang) {
434
434
  const {
435
435
  meta: { commonjs: commonjsMeta },
436
436
  hasDefaultExport
@@ -441,9 +441,13 @@ function getEntryProxy(id, defaultIsModuleExports, getModuleInfo) {
441
441
  if (hasDefaultExport) {
442
442
  code += `export { default } from ${stringifiedId};`;
443
443
  }
444
- return code;
444
+ return shebang + code;
445
445
  }
446
- return getEsImportProxy(id, defaultIsModuleExports);
446
+ const result = getEsImportProxy(id, defaultIsModuleExports);
447
+ return {
448
+ ...result,
449
+ code: shebang + result.code
450
+ };
447
451
  }
448
452
 
449
453
  function getEsImportProxy(id, defaultIsModuleExports) {
@@ -1897,6 +1901,13 @@ async function transformCommonjs(
1897
1901
  magicString.remove(0, commentEnd).trim();
1898
1902
  }
1899
1903
 
1904
+ let shebang = '';
1905
+ if (code.startsWith('#!')) {
1906
+ const shebangEndPosition = code.indexOf('\n') + 1;
1907
+ shebang = code.slice(0, shebangEndPosition);
1908
+ magicString.remove(0, shebangEndPosition).trim();
1909
+ }
1910
+
1900
1911
  const exportMode = isEsModule
1901
1912
  ? 'none'
1902
1913
  : shouldWrap
@@ -1980,14 +1991,14 @@ function ${requireName} () {
1980
1991
 
1981
1992
  magicString
1982
1993
  .trim()
1983
- .prepend(leadingComment + importBlock)
1994
+ .prepend(shebang + leadingComment + importBlock)
1984
1995
  .append(exportBlock);
1985
1996
 
1986
1997
  return {
1987
1998
  code: magicString.toString(),
1988
1999
  map: sourceMap ? magicString.generateMap() : null,
1989
2000
  syntheticNamedExports: isEsModule || usesRequireWrapper ? false : '__moduleExports',
1990
- meta: { commonjs: commonjsMeta }
2001
+ meta: { commonjs: { ...commonjsMeta, shebang } }
1991
2002
  };
1992
2003
  }
1993
2004
 
@@ -2229,7 +2240,16 @@ function commonjs(options = {}) {
2229
2240
  // entry suffix is just appended to not mess up relative external resolution
2230
2241
  if (id.endsWith(ENTRY_SUFFIX)) {
2231
2242
  const acutalId = id.slice(0, -ENTRY_SUFFIX.length);
2232
- return getEntryProxy(acutalId, getDefaultIsModuleExports(acutalId), this.getModuleInfo);
2243
+ const {
2244
+ meta: { commonjs: commonjsMeta }
2245
+ } = this.getModuleInfo(acutalId);
2246
+ const shebang = commonjsMeta?.shebang ?? '';
2247
+ return getEntryProxy(
2248
+ acutalId,
2249
+ getDefaultIsModuleExports(acutalId),
2250
+ this.getModuleInfo,
2251
+ shebang
2252
+ );
2233
2253
  }
2234
2254
 
2235
2255
  if (isWrappedId(id, ES_IMPORT_SUFFIX)) {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@rollup/plugin-commonjs",
3
- "version": "25.0.5",
3
+ "version": "25.0.6",
4
4
  "publishConfig": {
5
5
  "access": "public"
6
6
  },