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

Commit

Permalink
fix(one-app-runner): include legacy bundle on serve-module even if it…
Browse files Browse the repository at this point in the history
… does not exist (#629)
  • Loading branch information
10xLaCroixDrinker committed Mar 26, 2024
1 parent 05c80cd commit f48ef4f
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 10 deletions.
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

0 comments on commit f48ef4f

Please sign in to comment.