Skip to content
This repository has been archived by the owner on May 15, 2024. It is now read-only.

fix(one-app-server-bundler): include legacy bundle on serve-module even if it does not exist #629

Merged
merged 1 commit into from
Mar 26, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ exports[`serve-module adds to the existing module map 1`] = `
}"
`;

exports[`serve-module adds to the existing module map without legacy when legacy bundle does not exist 1`] = `
exports[`serve-module adds to the existing module map with a warning in place of the legacy browser SRI when legacy bundle does not exist 1`] = `
"{
\\"key\\": \\"--- omitted for development ---\\",
\\"modules\\": {
Expand All @@ -58,6 +58,10 @@ exports[`serve-module adds to the existing module map without legacy when legacy
\\"node\\": {
\\"integrity\\": \\"123\\",
\\"url\\": \\"[one-app-dev-cdn-url]/static/modules/my-module-name/1.0.0/my-module-name.node.js\\"
},
\\"legacyBrowser\\": {
\\"integrity\\": \\"[No legacy bundle generated for my-module-name. This will 404.]\\",
\\"url\\": \\"[one-app-dev-cdn-url]/static/modules/my-module-name/1.0.0/my-module-name.legacy.browser.js\\"
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -152,7 +152,7 @@ describe('serve-module', () => {
expect(fs._.getFiles()['/mocked/static/module-map.json']).toMatchSnapshot();
});

it('adds to the existing module map without legacy when legacy bundle does not exist', () => {
it('adds to the existing module map with a warning in place of the legacy browser SRI when legacy bundle does not exist', () => {
process.env.NODE_ENV = 'development';
fs._.setFiles({
'../my-module-name/package.json': JSON.stringify({ name: 'my-module-name', version: '1.0.0' }),
Expand Down
11 changes: 3 additions & 8 deletions packages/one-app-server-bundler/bin/serve-module.js
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ util.parseArgs({ allowPositionals: true }).positionals.forEach((modulePath) => {
fs.writeFileSync(moduleMapPath, JSON.stringify({ key: 'not-used-in-development', modules: {} }, null, 2));
} finally {
const moduleMap = JSON.parse(fs.readFileSync(moduleMapPath));
const generalConfig = {
moduleMap.modules[moduleName] = {
browser: {
integrity: browserSri,
url: `[one-app-dev-cdn-url]/static/modules/${moduleName}/${version}/${moduleName}.browser.js`,
Expand All @@ -74,16 +74,11 @@ util.parseArgs({ allowPositionals: true }).positionals.forEach((modulePath) => {
integrity: nodeSri,
url: `[one-app-dev-cdn-url]/static/modules/${moduleName}/${version}/${moduleName}.node.js`,
},
};

const legacyConfig = legacyBrowserSri ? {
legacyBrowser: {
integrity: legacyBrowserSri,
integrity: legacyBrowserSri || `[No legacy bundle generated for ${moduleName}. This will 404.]`,
url: `[one-app-dev-cdn-url]/static/modules/${moduleName}/${version}/${moduleName}.legacy.browser.js`,
},
} : {};

moduleMap.modules[moduleName] = { ...generalConfig, ...legacyConfig };
};

fs.writeFileSync(moduleMapPath, JSON.stringify(moduleMap, null, 2));
}
Expand Down
Loading