From 5e58e10c0b5bafe3bf91631ec8bfd67012554cc2 Mon Sep 17 00:00:00 2001 From: Sergey Petushkov Date: Wed, 3 Dec 2025 15:22:13 +0100 Subject: [PATCH 1/2] chore(web): produce manifest file listing all compass-web assets as part of compilation --- packages/compass-web/webpack.config.js | 42 +++++++++++++++++++++++++- 1 file changed, 41 insertions(+), 1 deletion(-) diff --git a/packages/compass-web/webpack.config.js b/packages/compass-web/webpack.config.js index bff3ec5ad3b..52b1b1785e7 100644 --- a/packages/compass-web/webpack.config.js +++ b/packages/compass-web/webpack.config.js @@ -8,6 +8,7 @@ const { } = require('@mongodb-js/webpack-config-compass'); const { execFile } = require('child_process'); const { promisify } = require('util'); +const fs = require('fs'); const execFileAsync = promisify(execFile); @@ -163,6 +164,43 @@ module.exports = (env, args) => { process: [localPolyfill('process'), 'process'], }), + // Plugin to collect entrypoint filename information and save it in a + // manifest file + function (compiler) { + compiler.hooks.afterEmit.tapPromise( + 'manifest', + async function (compilation) { + const stats = compilation.getStats().toJson({ + all: false, + outputPath: true, + entrypoints: true, + }); + + if (!('index' in stats.entrypoints)) { + throw new Error( + 'Missing expected entrypoint in the stats object' + ); + } + + await fs.promises.writeFile( + path.join(stats.outputPath, 'assets-manifest.json'), + JSON.stringify( + stats.entrypoints.index.assets + .map((asset) => { + return asset.name; + }) + // The root entrypoint is at the end of the assets list, but + // we'd want to preload it first, reversing here puts the + // manifest list in the load order we want + .reverse(), + null, + 2 + ) + ); + } + ); + }, + // Only applied when running webpack in --watch mode. In this mode we want // to constantly rebuild d.ts files when source changes, we also don't // want to fail and stop compilation if we failed to generate definitions @@ -251,7 +289,9 @@ module.exports = (env, args) => { config.output = { path: config.output.path, filename: (pathData) => { - return pathData.chunk.hasEntryModule() ? 'compass-web.mjs' : '[name].mjs'; + return pathData.chunk.hasEntryModule() + ? 'compass-web.mjs' + : '[name].[contenthash].mjs'; }, library: { type: 'module', From 6acfb6359ab9913d0edaa61d99981e82cf106ade Mon Sep 17 00:00:00 2001 From: Sergey Petushkov Date: Tue, 9 Dec 2025 12:19:15 +0100 Subject: [PATCH 2/2] fix(web): use emitAssets instead of direct fs call to account for webpack in-memory fs --- packages/compass-web/webpack.config.js | 58 ++++++++++++-------------- 1 file changed, 27 insertions(+), 31 deletions(-) diff --git a/packages/compass-web/webpack.config.js b/packages/compass-web/webpack.config.js index 52b1b1785e7..8d63c2b2d75 100644 --- a/packages/compass-web/webpack.config.js +++ b/packages/compass-web/webpack.config.js @@ -8,7 +8,6 @@ const { } = require('@mongodb-js/webpack-config-compass'); const { execFile } = require('child_process'); const { promisify } = require('util'); -const fs = require('fs'); const execFileAsync = promisify(execFile); @@ -167,38 +166,35 @@ module.exports = (env, args) => { // Plugin to collect entrypoint filename information and save it in a // manifest file function (compiler) { - compiler.hooks.afterEmit.tapPromise( - 'manifest', - async function (compilation) { - const stats = compilation.getStats().toJson({ - all: false, - outputPath: true, - entrypoints: true, - }); - - if (!('index' in stats.entrypoints)) { - throw new Error( - 'Missing expected entrypoint in the stats object' - ); - } + compiler.hooks.emit.tap('manifest', function (compilation) { + const stats = compilation.getStats().toJson({ + all: false, + outputPath: true, + entrypoints: true, + }); - await fs.promises.writeFile( - path.join(stats.outputPath, 'assets-manifest.json'), - JSON.stringify( - stats.entrypoints.index.assets - .map((asset) => { - return asset.name; - }) - // The root entrypoint is at the end of the assets list, but - // we'd want to preload it first, reversing here puts the - // manifest list in the load order we want - .reverse(), - null, - 2 - ) - ); + if (!('index' in stats.entrypoints)) { + throw new Error('Missing expected entrypoint in the stats object'); } - ); + + const assets = JSON.stringify( + stats.entrypoints.index.assets + .map((asset) => { + return asset.name; + }) + // The root entrypoint is at the end of the assets list, but + // we'd want to preload it first, reversing here puts the + // manifest list in the load order we want + .reverse(), + null, + 2 + ); + + compilation.emitAsset( + 'assets-manifest.json', + new webpack.sources.RawSource(assets) + ); + }); }, // Only applied when running webpack in --watch mode. In this mode we want