Skip to content

Commit c39daf9

Browse files
authored
PRO-8530 autodetect ES bundles (#5120)
* autodetect ES bundles * formatting
1 parent b65d88a commit c39daf9

File tree

2 files changed

+17
-6
lines changed

2 files changed

+17
-6
lines changed

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@
2424
* The `render-areas` query parameter now works correctly with areas nested in array items.
2525
* Fix min size calculation for image widgets configured with an aspect ratio.
2626
* Added missing `await` in helper library function for the asset module, ensuring JS assets build reliably.
27+
* Autodetection of bundles, and automatic activation of "improvements" shipped in those bundles, now works correctly when the bundle is delivered in ES module format rather than commonjs format.
2728

2829
## 4.22.0 (2025-10-01)
2930

index.js

Lines changed: 16 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,8 @@ const glob = require('./lib/glob.js');
1414
const moogRequire = require('./lib/moog-require');
1515
let defaults = require('./defaults.js');
1616

17+
const importFresh = moduleName => import(`${moduleName}?${Date.now()}`);
18+
1719
// ## Top-level options
1820
//
1921
// `cluster`
@@ -435,16 +437,24 @@ async function apostrophe(options, telemetry, rootSpan) {
435437
continue;
436438
}
437439

438-
const apostropheModule = await self.root.import(npmPath);
439-
if (apostropheModule.bundle) {
440-
self.options.bundles = (self.options.bundles || []).concat(apostropheModuleName);
441-
const bundleModules = apostropheModule.bundle.modules;
440+
const { default: apostropheModule } = await importFresh(npmPath);
441+
const bundle = apostropheModule.bundle;
442+
if (bundle) {
443+
self.options.bundles = [
444+
...new Set(
445+
[
446+
...(self.options.bundles || []),
447+
apostropheModuleName
448+
]
449+
)
450+
];
451+
const bundleModules = bundle.modules;
442452
for (const bundleModuleName of bundleModules) {
443453
if (!apostropheModules.includes(bundleModuleName)) {
444-
const bundledModule = await self.root.import(
454+
const { default: bundledModule } = await importFresh(
445455
path.resolve(
446456
path.dirname(npmPath),
447-
apostropheModule.bundle.directory,
457+
bundle.directory,
448458
bundleModuleName,
449459
'index.js'
450460
)

0 commit comments

Comments
 (0)