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): single serve-module invocation
Browse files Browse the repository at this point in the history
avoid repeated overhead with many modules for faster startup times to listening on the port
  • Loading branch information
PixnBits committed Mar 18, 2024
1 parent 62854c6 commit 1917433
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 9 deletions.
4 changes: 2 additions & 2 deletions packages/one-app-runner/__tests__/src/startApp.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -138,7 +138,7 @@ Array [
'-v=/path/to-module-b:/opt/module-workspace/to-module-b',
'-v=/home/user/.one-app:/home/node/.one-app',
]);
expect(mockSpawn.calls[1].args[mockSpawn.calls[1].args.indexOf('-c') + 1]).toMatchInlineSnapshot('"npm config set update-notifier false && npm run serve-module \'/opt/module-workspace/module-a\' &&npm run serve-module \'/opt/module-workspace/to-module-b\' && node lib/server/index.js --root-module-name=frank-lloyd-root --module-map-url=https://example.com/module-map.json"');
expect(mockSpawn.calls[1].args[mockSpawn.calls[1].args.indexOf('-c') + 1]).toMatchInlineSnapshot('"npm config set update-notifier false && npm run serve-module \'/opt/module-workspace/module-a\' \'/opt/module-workspace/to-module-b\' && node lib/server/index.js --root-module-name=frank-lloyd-root --module-map-url=https://example.com/module-map.json"');
});

it('mounts and serves modules in docker run if module paths are provided and moduleMapUrl is not', async () => {
Expand All @@ -153,7 +153,7 @@ Array [
'-v=/path/to-module-b:/opt/module-workspace/to-module-b',
'-v=/home/user/.one-app:/home/node/.one-app',
]);
expect(mockSpawn.calls[1].args[mockSpawn.calls[1].args.indexOf('-c') + 1]).toMatchInlineSnapshot('"npm config set update-notifier false && npm run serve-module \'/opt/module-workspace/module-a\' &&npm run serve-module \'/opt/module-workspace/to-module-b\' && node lib/server/index.js --root-module-name=frank-lloyd-root"');
expect(mockSpawn.calls[1].args[mockSpawn.calls[1].args.indexOf('-c') + 1]).toMatchInlineSnapshot('"npm config set update-notifier false && npm run serve-module \'/opt/module-workspace/module-a\' \'/opt/module-workspace/to-module-b\' && node lib/server/index.js --root-module-name=frank-lloyd-root"');
});

it('runs set middleware command and starts one app with mock flag in docker run if parrot middleware file is provided', async () => {
Expand Down
16 changes: 9 additions & 7 deletions packages/one-app-runner/src/startApp.js
Original file line number Diff line number Diff line change
Expand Up @@ -114,14 +114,16 @@ const generateUseMocksFlag = (shouldUseMocks) => (shouldUseMocks ? '-m' : '');
const generateNpmConfigCommands = () => 'npm config set update-notifier false &&';

const generateServeModuleCommands = (modules) => {
let command = '';
if (modules && modules.length > 0) {
modules.forEach((modulePath) => {
const moduleRootDir = path.basename(modulePath);
command += `npm run serve-module '/opt/module-workspace/${moduleRootDir}' &&`;
});
if (!modules || modules.length === 0) {
return '';
}
return command;

let command = 'npm run serve-module';
modules.forEach((modulePath) => {
const moduleRootDir = path.basename(modulePath);
command += ` '/opt/module-workspace/${moduleRootDir}'`;
});
return `${command} &&`;
};

const generateModuleMap = (moduleMapUrl) => (moduleMapUrl ? `--module-map-url=${moduleMapUrl}` : '');
Expand Down

0 comments on commit 1917433

Please sign in to comment.