From 70caf0455d3ff3d5af1b72d0e8ecf7ea690dbda1 Mon Sep 17 00:00:00 2001 From: Edward Faulkner Date: Fri, 5 Jul 2024 16:05:03 -0400 Subject: [PATCH] Don't publish empty modules 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. --- rollup.config.mjs | 16 +++++++++++++++- 1 file changed, 15 insertions(+), 1 deletion(-) diff --git a/rollup.config.mjs b/rollup.config.mjs index 1bccd355e88..3ac746b5cc5 100644 --- a/rollup.config.mjs +++ b/rollup.config.mjs @@ -58,6 +58,7 @@ function esmConfig() { resolveTS(), version(), resolvePackages(exposedDependencies(), hiddenDependencies()), + pruneEmptyBundles(), ], }; } @@ -443,7 +444,7 @@ function templateCompilerConfig() { }); config.output.globals = (id) => { return `(() => { - try { + try { return require('${id}'); } catch (err) { return ${externals[id]} @@ -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]; + } + } + }, + }; +}