Skip to content
Permalink

Comparing changes

Choose two branches to see what’s changed or to start a new pull request. If you need to, you can also or learn more about diff comparisons.

Open a pull request

Create a new pull request by comparing changes across two branches. If you need to, you can also . Learn more about diff comparisons here.
base repository: rollup/plugins
Failed to load repositories. Confirm that selected base ref is valid, then try again.
Loading
base: 007acf15c7605e4ebe77afc7f4e6f3c0c8e6a1b1
Choose a base ref
...
head repository: rollup/plugins
Failed to load repositories. Confirm that selected head ref is valid, then try again.
Loading
compare: 8fa358e0168418ffc93b9a38e4809199ac913484
Choose a head ref
  • 15 commits
  • 96 files changed
  • 8 contributors

Commits on Apr 9, 2023

  1. chore(release): terser v0.4.1

    Release Workflow committed Apr 9, 2023
    1
    Copy the full SHA
    1bcd739 View commit details

Commits on Apr 11, 2023

  1. 1
    Copy the full SHA
    f061dc3 View commit details
  2. chore(release): commonjs v24.1.0

    Release Workflow committed Apr 11, 2023
    1
    Copy the full SHA
    8319720 View commit details

Commits on May 12, 2023

  1. 1
    Copy the full SHA
    72c56dd View commit details
  2. chore(release): eslint v9.0.4

    Release Workflow committed May 12, 2023
    1
    Copy the full SHA
    5f719f5 View commit details
  3. docs(wasm): Fix typo in README (#1473)

    * docs(wasm): Fix typo in README
    
    * Update README.md
    jfmengels authored May 12, 2023
    1
    Copy the full SHA
    eaf405e View commit details
  4. chore(release): wasm v6.1.3

    Release Workflow committed May 12, 2023
    1
    Copy the full SHA
    089a51e View commit details
  5. fix(typescript): Allow for using compilerOptions.moduleResolution (#…

    …1453)
    
    * fix(typescript): Add test for setting moduleResolution
    
    This adds a test case for resolving types with node ESM `exports` feature
    and `compilerOptions.moduleResolution` option configured.
    
    Signed-off-by: Ferdinand Thiessen <rpm@fthiessen.de>
    
    * fix(typescript): Allow for using `compilerOptions.moduleResolution`
    
    Signed-off-by: Ferdinand Thiessen <rpm@fthiessen.de>
    
    ---------
    
    Signed-off-by: Ferdinand Thiessen <rpm@fthiessen.de>
    susnux authored May 12, 2023
    1
    Copy the full SHA
    eb0cfe0 View commit details
  6. chore(release): typescript v11.1.1

    Release Workflow committed May 12, 2023
    Copy the full SHA
    5d477ec View commit details
  7. fix(commonjs)!: dynamic require root check was broken in some cases (#…

    …1461)
    
    * fix(commonjs): dynamic require root check was broken in some cases
    
    * fix(commonjs): fixed a commonjs unit test based on OS paths
    
    * test(commonjs): attempt 2 at having tests not fail in CI
    
    Using the normalized path in _all_ the properties of the error
    
    * test: 1st try at the test
    
    * test(commonjs): the dynamic root must ignore conflicting backslashes
    
    * test(commonjs): added a test specifically for Windows
    Elarcis authored May 12, 2023
    Copy the full SHA
    0339f93 View commit details
  8. chore(release): commonjs v25.0.0

    Release Workflow committed May 12, 2023
    Copy the full SHA
    7dfc876 View commit details
  9. feat(yaml): support specifying custom file extensions (#1445)

    * make yaml plugin extensions configurable
    
    * prettier
    
    * add tests for extensions option
    janosh authored May 12, 2023
    Copy the full SHA
    59a2dc2 View commit details
  10. chore(release): yaml v4.1.0

    Release Workflow committed May 12, 2023
    Copy the full SHA
    b3a65b9 View commit details

Commits on May 16, 2023

  1. fix(terser): don't assume code is running in worker created by the wo…

    …rker pool (#1483)
    
    * fix(terser): don't assume code is running in worker created by the worker pool
    
    * sort imports
    dasa authored May 16, 2023
    Copy the full SHA
    4e92bc2 View commit details
  2. chore(release): terser v0.4.2

    Release Workflow committed May 16, 2023
    Copy the full SHA
    8fa358e View commit details
Showing with 1,008 additions and 636 deletions.
  1. +16 −0 packages/commonjs/CHANGELOG.md
  2. +2 −2 packages/commonjs/package.json
  3. +8 −3 packages/commonjs/src/ast-utils.js
  4. +112 −72 packages/commonjs/src/generate-exports.js
  5. +7 −8 packages/commonjs/src/generate-imports.js
  6. +11 −15 packages/commonjs/src/index.js
  7. +6 −3 packages/commonjs/src/proxies.js
  8. +24 −28 packages/commonjs/src/transform-commonjs.js
  9. +1 −1 packages/commonjs/test/fixtures/form/async-function/output.js
  10. +1 −1 packages/commonjs/test/fixtures/form/compiled-esm-assign-exports/output.js
  11. +1 −1 packages/commonjs/test/fixtures/form/compiled-esm-assign-module/output.js
  12. +1 −1 packages/commonjs/test/fixtures/form/compiled-esm-deconflict/output.js
  13. +1 −1 packages/commonjs/test/fixtures/form/compiled-esm-define-exports-empty/output.js
  14. +1 −1 packages/commonjs/test/fixtures/form/compiled-esm-define-exports/output.js
  15. +1 −1 packages/commonjs/test/fixtures/form/compiled-esm-define-module/output.js
  16. +1 −1 packages/commonjs/test/fixtures/form/compiled-esm-minified/output.js
  17. +1 −1 packages/commonjs/test/fixtures/form/compiled-esm-only-named/output.js
  18. +5 −3 packages/commonjs/test/fixtures/form/compiled-esm-reassign-exports/output.js
  19. +1 −1 packages/commonjs/test/fixtures/form/constant-template-literal/output.js
  20. +1 −1 packages/commonjs/test/fixtures/form/defaultIsModuleExports-auto-__esModule/output.js
  21. +1 −1 packages/commonjs/test/fixtures/form/defaultIsModuleExports-auto-no-__esModule/output.js
  22. +1 −4 ...ges/commonjs/test/fixtures/form/defaultIsModuleExports-auto-reassign-exports-__esModule/output.js
  23. +1 −1 .../commonjs/test/fixtures/form/defaultIsModuleExports-auto-reassign-exports-no-__esModule/output.js
  24. +1 −1 packages/commonjs/test/fixtures/form/defaultIsModuleExports-false-__esModule/output.js
  25. +2 −2 packages/commonjs/test/fixtures/form/defaultIsModuleExports-false-no-__esModule/output.js
  26. +1 −1 packages/commonjs/test/fixtures/form/defaultIsModuleExports-false-no-default/output.js
  27. +1 −4 ...es/commonjs/test/fixtures/form/defaultIsModuleExports-false-reassign-exports-__esModule/output.js
  28. +1 −4 ...commonjs/test/fixtures/form/defaultIsModuleExports-false-reassign-exports-no-__esModule/output.js
  29. +1 −1 packages/commonjs/test/fixtures/form/defaultIsModuleExports-true-__esModule/output.js
  30. +1 −1 packages/commonjs/test/fixtures/form/defaultIsModuleExports-true-no-__esModule/output.js
  31. +1 −1 packages/commonjs/test/fixtures/form/ignore-ids-function/output.js
  32. +1 −1 packages/commonjs/test/fixtures/form/ignore-ids/output.js
  33. +1 −1 packages/commonjs/test/fixtures/form/multi-entry-module-exports/output1.js
  34. +1 −1 packages/commonjs/test/fixtures/form/multi-entry-module-exports/output2.js
  35. +1 −1 packages/commonjs/test/fixtures/form/multiple-var-declarations-b/output.js
  36. +1 −1 packages/commonjs/test/fixtures/form/multiple-var-declarations-c/output.js
  37. +1 −1 packages/commonjs/test/fixtures/form/multiple-var-declarations/output.js
  38. +1 −1 packages/commonjs/test/fixtures/form/no-exports-entry/output.js
  39. +1 −1 packages/commonjs/test/fixtures/form/no-toplevel-return/output.js
  40. +1 −1 packages/commonjs/test/fixtures/form/node-require-methods/output.js
  41. +1 −1 packages/commonjs/test/fixtures/form/optimised-default-export-function-double-assign/output.js
  42. +1 −1 packages/commonjs/test/fixtures/form/optimised-default-export-function/output.js
  43. +1 −1 packages/commonjs/test/fixtures/form/optimised-default-export-iife/output.js
  44. +1 −1 packages/commonjs/test/fixtures/form/optimised-default-export/output.js
  45. +1 −1 packages/commonjs/test/fixtures/form/optimised-named-export-conflicts/output.js
  46. +1 −1 packages/commonjs/test/fixtures/form/optimised-named-export/output.js
  47. +1 −1 packages/commonjs/test/fixtures/form/require-collision/output.js
  48. +7 −5 packages/commonjs/test/fixtures/form/typeof-module-exports/output.js
  49. +6 −0 packages/commonjs/test/fixtures/function/compiled-esm-default-is-module-exports-false/_config.js
  50. +2 −0 packages/commonjs/test/fixtures/function/compiled-esm-default-is-module-exports-false/dep.js
  51. +3 −0 packages/commonjs/test/fixtures/function/compiled-esm-default-is-module-exports-false/main.js
  52. +2 −2 packages/commonjs/test/fixtures/function/custom-options/_config.js
  53. +6 −0 packages/commonjs/test/fixtures/function/reassign-module-exports-delayed/_config.js
  54. +2 −0 packages/commonjs/test/fixtures/function/reassign-module-exports-delayed/dep.js
  55. +5 −0 packages/commonjs/test/fixtures/function/reassign-module-exports-delayed/main.js
  56. +1 −1 packages/commonjs/test/fixtures/function/reassigned-module-exports-object/dep.js
  57. +1 −1 packages/commonjs/test/fixtures/function/reassigned-module-exports-object/main.js
  58. +1 −1 packages/commonjs/test/fixtures/function/transpiled-esm-reexported-mixed/_config.js
  59. +5 −0 packages/commonjs/test/helpers/util.js
  60. +440 −367 packages/commonjs/test/snapshots/function.js.md
  61. BIN packages/commonjs/test/snapshots/function.js.snap
  62. +41 −27 packages/commonjs/test/snapshots/test.js.md
  63. BIN packages/commonjs/test/snapshots/test.js.snap
  64. +62 −4 packages/commonjs/test/test.js
  65. +8 −0 packages/eslint/CHANGELOG.md
  66. +1 −1 packages/eslint/README.md
  67. +1 −1 packages/eslint/package.json
  68. +16 −0 packages/terser/CHANGELOG.md
  69. +1 −1 packages/terser/package.json
  70. +1 −0 packages/terser/src/constants.ts
  71. +4 −2 packages/terser/src/worker-pool.ts
  72. +4 −2 packages/terser/src/worker.ts
  73. +8 −0 packages/typescript/CHANGELOG.md
  74. +1 −1 packages/typescript/package.json
  75. +3 −2 packages/typescript/src/options/tsconfig.ts
  76. +4 −0 packages/typescript/test/fixtures/nodenext-module/index.ts
  77. 0 ...ges/typescript/test/fixtures/{nodenext-resolution → nodenext-module}/node_modules/foo/index.d.cts
  78. 0 ...ages/typescript/test/fixtures/{nodenext-resolution → nodenext-module}/node_modules/foo/index.d.ts
  79. 0 packages/typescript/test/fixtures/{nodenext-resolution → nodenext-module}/node_modules/foo/index.js
  80. +10 −0 packages/typescript/test/fixtures/nodenext-module/node_modules/foo/package.json
  81. +3 −0 packages/typescript/test/fixtures/nodenext-module/package.json
  82. +5 −0 packages/typescript/test/fixtures/nodenext-module/tsconfig.json
  83. +1 −0 packages/typescript/test/fixtures/nodenext-resolution/node_modules/foo/dist/index.js
  84. +3 −3 packages/typescript/test/fixtures/nodenext-resolution/node_modules/foo/package.json
  85. +2 −0 packages/typescript/test/fixtures/nodenext-resolution/node_modules/foo/types/index.d.cts
  86. +2 −0 packages/typescript/test/fixtures/nodenext-resolution/node_modules/foo/types/index.d.ts
  87. +1 −1 packages/typescript/test/fixtures/nodenext-resolution/tsconfig.json
  88. +21 −1 packages/typescript/test/test.js
  89. +8 −0 packages/wasm/CHANGELOG.md
  90. +2 −2 packages/wasm/README.md
  91. +1 −1 packages/wasm/package.json
  92. +8 −0 packages/yaml/CHANGELOG.md
  93. +1 −1 packages/yaml/package.json
  94. +4 −4 packages/yaml/src/index.js
  95. +45 −0 packages/yaml/test/test.js
  96. +25 −23 pnpm-lock.yaml
16 changes: 16 additions & 0 deletions packages/commonjs/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,21 @@
# @rollup/plugin-commonjs ChangeLog

## v25.0.0

_2023-05-12_

### Breaking Changes

- fix: dynamic require root check was broken in some cases [#1461](https://github.com/rollup/plugins/pull/1461)

## v24.1.0

_2023-04-11_

### Features

- feat: Do not use getters for module.exports [#1455](https://github.com/rollup/plugins/pull/1455)

## v24.0.1

_2023-01-20_
4 changes: 2 additions & 2 deletions packages/commonjs/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@rollup/plugin-commonjs",
"version": "24.0.1",
"version": "25.0.0",
"publishConfig": {
"access": "public"
},
@@ -74,7 +74,7 @@
"@rollup/plugin-node-resolve": "^15.0.0",
"locate-character": "^2.0.5",
"require-relative": "^0.8.7",
"rollup": "3.0.0-7",
"rollup": "^3.19.0",
"shx": "^0.3.4",
"source-map": "^0.7.4",
"source-map-support": "^0.5.21",
11 changes: 8 additions & 3 deletions packages/commonjs/src/ast-utils.js
Original file line number Diff line number Diff line change
@@ -60,11 +60,16 @@ export function getKeypath(node) {

export const KEY_COMPILED_ESM = '__esModule';

export function isDefineCompiledEsm(node) {
export function getDefineCompiledEsmType(node) {
const definedPropertyWithExports = getDefinePropertyCallName(node, 'exports');
const definedProperty =
getDefinePropertyCallName(node, 'exports') || getDefinePropertyCallName(node, 'module.exports');
definedPropertyWithExports || getDefinePropertyCallName(node, 'module.exports');
if (definedProperty && definedProperty.key === KEY_COMPILED_ESM) {
return isTruthy(definedProperty.value);
return isTruthy(definedProperty.value)
? definedPropertyWithExports
? 'exports'
: 'module'
: false;
}
return false;
}
184 changes: 112 additions & 72 deletions packages/commonjs/src/generate-exports.js
Original file line number Diff line number Diff line change
@@ -7,19 +7,22 @@ export function wrapCode(magicString, uses, moduleName, exportsName, indentExclu
}
if (uses.exports) {
args.push('exports');
passedArgs.push(exportsName);
passedArgs.push(uses.module ? `${moduleName}.exports` : exportsName);
}
magicString
.trim()
.indent('\t', { exclude: indentExclusionRanges })
.prepend(`(function (${args.join(', ')}) {\n`)
.append(`\n} (${passedArgs.join(', ')}));`);
// For some reason, this line is only indented correctly when using a
// require-wrapper if we have this leading space
.append(` \n} (${passedArgs.join(', ')}));`);
}

export function rewriteExportsAndGetExportsBlock(
magicString,
moduleName,
exportsName,
exportedExportsName,
wrapped,
moduleExportsAssignments,
firstTopLevelModuleExportsAssignment,
@@ -30,7 +33,6 @@ export function rewriteExportsAndGetExportsBlock(
code,
HELPERS_NAME,
exportMode,
detectWrappedDefault,
defaultIsModuleExports,
usesRequireWrapper,
requireName
@@ -58,17 +60,20 @@ export function rewriteExportsAndGetExportsBlock(
exportDeclarations,
moduleExportsAssignments,
firstTopLevelModuleExportsAssignment,
exportsName
exportsName,
defaultIsModuleExports,
HELPERS_NAME
);
} else {
exports.push(`${exportsName} as __moduleExports`);
if (exportMode === 'module') {
exportDeclarations.push(`var ${exportedExportsName} = ${moduleName}.exports`);
exports.push(`${exportedExportsName} as __moduleExports`);
} else {
exports.push(`${exportsName} as __moduleExports`);
}
if (wrapped) {
getExportsWhenWrapping(
exportDeclarations,
exportsName,
detectWrappedDefault,
HELPERS_NAME,
defaultIsModuleExports
exportDeclarations.push(
getDefaultExportDeclaration(exportedExportsName, defaultIsModuleExports, HELPERS_NAME)
);
} else {
getExports(
@@ -81,17 +86,19 @@ export function rewriteExportsAndGetExportsBlock(
topLevelAssignments,
moduleName,
exportsName,
exportedExportsName,
defineCompiledEsmExpressions,
HELPERS_NAME,
defaultIsModuleExports
defaultIsModuleExports,
exportMode
);
}
}
if (exports.length) {
exportDeclarations.push(`export { ${exports.join(', ')} };`);
exportDeclarations.push(`export { ${exports.join(', ')} }`);
}

return `\n\n${exportDeclarations.join('\n')}`;
return `\n\n${exportDeclarations.join(';\n')};`;
}

function getExportsWhenUsingRequireWrapper(
@@ -106,35 +113,32 @@ function getExportsWhenUsingRequireWrapper(
requireName,
defineCompiledEsmExpressions
) {
if (!wrapped) {
if (exportMode === 'replace') {
for (const { left } of moduleExportsAssignments) {
magicString.overwrite(left.start, left.end, exportsName);
}
} else {
// Collect and rewrite module.exports assignments
for (const { left } of moduleExportsAssignments) {
magicString.overwrite(left.start, left.end, `${moduleName}.exports`);
}
// Collect and rewrite named exports
for (const [exportName, { nodes }] of exportsAssignmentsByName) {
for (const node of nodes) {
magicString.overwrite(node.start, node.left.end, `${exportsName}.${exportName}`);
}
}
// Collect and rewrite exports.__esModule assignments
for (const expression of defineCompiledEsmExpressions) {
const moduleExportsExpression =
expression.type === 'CallExpression' ? expression.arguments[0] : expression.left.object;
exports.push(`${requireName} as __require`);
if (wrapped) return;
if (exportMode === 'replace') {
rewriteModuleExportsAssignments(magicString, moduleExportsAssignments, exportsName);
} else {
rewriteModuleExportsAssignments(magicString, moduleExportsAssignments, `${moduleName}.exports`);
// Collect and rewrite named exports
for (const [exportName, { nodes }] of exportsAssignmentsByName) {
for (const { node, type } of nodes) {
magicString.overwrite(
moduleExportsExpression.start,
moduleExportsExpression.end,
exportsName
node.start,
node.left.end,
`${
exportMode === 'module' && type === 'module' ? `${moduleName}.exports` : exportsName
}.${exportName}`
);
}
}
replaceDefineCompiledEsmExpressionsAndGetIfRestorable(
defineCompiledEsmExpressions,
magicString,
exportMode,
moduleName,
exportsName
);
}
exports.push(`${requireName} as __require`);
}

function getExportsForReplacedModuleExports(
@@ -143,34 +147,30 @@ function getExportsForReplacedModuleExports(
exportDeclarations,
moduleExportsAssignments,
firstTopLevelModuleExportsAssignment,
exportsName
exportsName,
defaultIsModuleExports,
HELPERS_NAME
) {
for (const { left } of moduleExportsAssignments) {
magicString.overwrite(left.start, left.end, exportsName);
}
magicString.prependRight(firstTopLevelModuleExportsAssignment.left.start, 'var ');
exports.push(`${exportsName} as __moduleExports`);
exportDeclarations.push(`export default ${exportsName};`);
}

function getExportsWhenWrapping(
exportDeclarations,
exportsName,
detectWrappedDefault,
HELPERS_NAME,
defaultIsModuleExports
) {
exportDeclarations.push(
`export default ${
detectWrappedDefault && defaultIsModuleExports === 'auto'
? `/*@__PURE__*/${HELPERS_NAME}.getDefaultExportFromCjs(${exportsName})`
: defaultIsModuleExports === false
? `${exportsName}.default`
: exportsName
};`
getDefaultExportDeclaration(exportsName, defaultIsModuleExports, HELPERS_NAME)
);
}

function getDefaultExportDeclaration(exportedExportsName, defaultIsModuleExports, HELPERS_NAME) {
return `export default ${
defaultIsModuleExports === true
? exportedExportsName
: defaultIsModuleExports === false
? `${exportedExportsName}.default`
: `/*@__PURE__*/${HELPERS_NAME}.getDefaultExportFromCjs(${exportedExportsName})`
}`;
}

function getExports(
magicString,
exports,
@@ -181,9 +181,11 @@ function getExports(
topLevelAssignments,
moduleName,
exportsName,
exportedExportsName,
defineCompiledEsmExpressions,
HELPERS_NAME,
defaultIsModuleExports
defaultIsModuleExports,
exportMode
) {
let deconflictedDefaultExportName;
// Collect and rewrite module.exports assignments
@@ -195,8 +197,10 @@ function getExports(
for (const [exportName, { nodes }] of exportsAssignmentsByName) {
const deconflicted = deconflictedExportNames[exportName];
let needsDeclaration = true;
for (const node of nodes) {
let replacement = `${deconflicted} = ${exportsName}.${exportName}`;
for (const { node, type } of nodes) {
let replacement = `${deconflicted} = ${
exportMode === 'module' && type === 'module' ? `${moduleName}.exports` : exportsName
}.${exportName}`;
if (needsDeclaration && topLevelAssignments.has(node)) {
replacement = `var ${replacement}`;
needsDeclaration = false;
@@ -214,22 +218,58 @@ function getExports(
}
}

// Collect and rewrite exports.__esModule assignments
let isRestorableCompiledEsm = false;
for (const expression of defineCompiledEsmExpressions) {
isRestorableCompiledEsm = true;
const moduleExportsExpression =
expression.type === 'CallExpression' ? expression.arguments[0] : expression.left.object;
magicString.overwrite(moduleExportsExpression.start, moduleExportsExpression.end, exportsName);
}
const isRestorableCompiledEsm = replaceDefineCompiledEsmExpressionsAndGetIfRestorable(
defineCompiledEsmExpressions,
magicString,
exportMode,
moduleName,
exportsName
);

if (!isRestorableCompiledEsm || defaultIsModuleExports === true) {
exports.push(`${exportsName} as default`);
} else if (moduleExportsAssignments.length === 0 || defaultIsModuleExports === false) {
exports.push(`${deconflictedDefaultExportName || exportsName} as default`);
if (
defaultIsModuleExports === false ||
(defaultIsModuleExports === 'auto' &&
isRestorableCompiledEsm &&
moduleExportsAssignments.length === 0)
) {
// If there is no deconflictedDefaultExportName, then we use the namespace as
// fallback because there can be no "default" property on the namespace
exports.push(`${deconflictedDefaultExportName || exportedExportsName} as default`);
} else if (
defaultIsModuleExports === true ||
(!isRestorableCompiledEsm && moduleExportsAssignments.length === 0)
) {
exports.push(`${exportedExportsName} as default`);
} else {
exportDeclarations.push(
`export default /*@__PURE__*/${HELPERS_NAME}.getDefaultExportFromCjs(${exportsName});`
getDefaultExportDeclaration(exportedExportsName, defaultIsModuleExports, HELPERS_NAME)
);
}
}

function rewriteModuleExportsAssignments(magicString, moduleExportsAssignments, exportsName) {
for (const { left } of moduleExportsAssignments) {
magicString.overwrite(left.start, left.end, exportsName);
}
}

function replaceDefineCompiledEsmExpressionsAndGetIfRestorable(
defineCompiledEsmExpressions,
magicString,
exportMode,
moduleName,
exportsName
) {
let isRestorableCompiledEsm = false;
for (const { node, type } of defineCompiledEsmExpressions) {
isRestorableCompiledEsm = true;
const moduleExportsExpression =
node.type === 'CallExpression' ? node.arguments[0] : node.left.object;
magicString.overwrite(
moduleExportsExpression.start,
moduleExportsExpression.end,
exportMode === 'module' && type === 'module' ? `${moduleName}.exports` : exportsName
);
}
return isRestorableCompiledEsm;
}
15 changes: 7 additions & 8 deletions packages/commonjs/src/generate-imports.js
Original file line number Diff line number Diff line change
@@ -98,19 +98,18 @@ export function getRequireHandlers() {
commonjsMeta
) {
const imports = [];
imports.push(`import * as ${helpersName} from "${HELPERS_ID}";`);
imports.push(`import * as ${helpersName} from "${HELPERS_ID}"`);
if (dynamicRequireName) {
imports.push(
`import { ${
isDynamicRequireModulesEnabled ? CREATE_COMMONJS_REQUIRE_EXPORT : COMMONJS_REQUIRE_EXPORT
} as ${dynamicRequireName} } from "${DYNAMIC_MODULES_ID}";`
} as ${dynamicRequireName} } from "${DYNAMIC_MODULES_ID}"`
);
}
if (exportMode === 'module') {
imports.push(
`import { __module as ${moduleName}, exports as ${exportsName} } from ${JSON.stringify(
wrapId(id, MODULE_SUFFIX)
)}`
`import { __module as ${moduleName} } from ${JSON.stringify(wrapId(id, MODULE_SUFFIX))}`,
`var ${exportsName} = ${moduleName}.exports`
);
} else if (exportMode === 'exports') {
imports.push(
@@ -136,7 +135,7 @@ export function getRequireHandlers() {
getIgnoreTryCatchRequireStatementMode,
magicString
);
return imports.length ? `${imports.join('\n')}\n\n` : '';
return imports.length ? `${imports.join(';\n')};\n\n` : '';
}

return {
@@ -196,9 +195,9 @@ function processRequireExpressions(
}
if (needsImport) {
if (isCommonJS === IS_WRAPPED_COMMONJS) {
imports.push(`import { __require as ${name} } from ${JSON.stringify(resolvedId)};`);
imports.push(`import { __require as ${name} } from ${JSON.stringify(resolvedId)}`);
} else {
imports.push(`import ${usesRequired ? `${name} from ` : ''}${JSON.stringify(resolvedId)};`);
imports.push(`import ${usesRequired ? `${name} from ` : ''}${JSON.stringify(resolvedId)}`);
}
}
}
Loading