Skip to content

Commit

Permalink
Don't publish empty modules
Browse files Browse the repository at this point in the history
The ES modules build (which is only used by embroider, not classic builds) includes several empty modules. They're type-only, and result in empty files after transpiling typescript.

This isn't necessarily wrong but it's unnecessary and it can trigger bugs in systems that are trying to use the presence of import/export to detect ESM format.

(cherry picked from commit 70caf04)
  • Loading branch information
ef4 authored and kategengler committed Aug 6, 2024
1 parent c63a995 commit bd90fd0
Showing 1 changed file with 15 additions and 1 deletion.
16 changes: 15 additions & 1 deletion rollup.config.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,7 @@ function esmConfig() {
resolveTS(),
version(),
resolvePackages(exposedDependencies(), hiddenDependencies()),
pruneEmptyBundles(),
],
};
}
Expand Down Expand Up @@ -443,7 +444,7 @@ function templateCompilerConfig() {
});
config.output.globals = (id) => {
return `(() => {
try {
try {
return require('${id}');
} catch (err) {
return ${externals[id]}
Expand All @@ -452,3 +453,16 @@ function templateCompilerConfig() {
};
return config;
}

function pruneEmptyBundles() {
return {
name: 'prune-empty-bundles',
generateBundle(options, bundles) {
for (let [key, bundle] of Object.entries(bundles)) {
if (bundle.code.trim() === '') {
delete bundles[key];
}
}
},
};
}

0 comments on commit bd90fd0

Please sign in to comment.