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

Commit

Permalink
feat(one-app-runner): use new entry command in 6.11.0 (#631)
Browse files Browse the repository at this point in the history
  • Loading branch information
10xLaCroixDrinker authored Mar 26, 2024
1 parent 03dcfc9 commit 3aba75e
Show file tree
Hide file tree
Showing 2 changed files with 44 additions and 11 deletions.
36 changes: 30 additions & 6 deletions packages/one-app-runner/__tests__/src/startApp.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -358,7 +358,7 @@ Array [
moduleMapUrl: 'https://example.com/module-map.json', rootModuleName: 'frank-lloyd-root', appDockerImage: 'one-app:5.0.0', modulesToServe: ['/path/to/module-a'], useDebug: true,
});
expect(mockSpawn.calls[1].args[mockSpawn.calls[1].args.indexOf('-c') + 1]).toMatch(
'--inspect=0.0.0.0:9229'
'node --inspect=0.0.0.0:9229 lib/server/index.js'
);
});

Expand All @@ -372,7 +372,7 @@ Array [
});
expect(mockSpawn.calls[1].args.filter((arg) => arg.startsWith('-p'))).toContain('-p=9221:9221');
expect(mockSpawn.calls[1].args[mockSpawn.calls[1].args.indexOf('-c') + 1]).toMatch(
'--inspect=0.0.0.0:9221'
'node --inspect=0.0.0.0:9221 lib/server/index.js'
);
});

Expand Down Expand Up @@ -492,27 +492,51 @@ Array [
);
});

it('adds node flags when one-app version 6 is specified', async () => {
it('uses start.sh when one-app version 6.11.0 or greater is specified', async () => {
expect.assertions(1);
const mockSpawn = makeMockSpawn();
childProcess.spawn.mockImplementation(mockSpawn);
await startApp({
moduleMapUrl: 'https://example.com/module-map.json', rootModuleName: 'frank-lloyd-root', appDockerImage: 'one-app:6.11.0', modulesToServe: ['/path/to/module-a'],
});
expect(mockSpawn.calls[1].args[mockSpawn.calls[1].args.indexOf('-c') + 1]).toMatch(
'scripts/start.sh'
);
});

it('uses start.sh when one-app version 6 is specified', async () => {
expect.assertions(1);
const mockSpawn = makeMockSpawn();
childProcess.spawn.mockImplementation(mockSpawn);
await startApp({
moduleMapUrl: 'https://example.com/module-map.json', rootModuleName: 'frank-lloyd-root', appDockerImage: 'one-app:6', modulesToServe: ['/path/to/module-a'],
});
expect(mockSpawn.calls[1].args[mockSpawn.calls[1].args.indexOf('-c') + 1]).toMatch(
'--dns-result-order=ipv4first --no-experimental-fetch'
'scripts/start.sh'
);
});

it('adds node flags when one-app version is specified as :latest', async () => {
it('uses start.sh when one-app version is specified as :latest', async () => {
expect.assertions(1);
const mockSpawn = makeMockSpawn();
childProcess.spawn.mockImplementation(mockSpawn);
await startApp({
moduleMapUrl: 'https://example.com/module-map.json', rootModuleName: 'frank-lloyd-root', appDockerImage: 'one-app:latest', modulesToServe: ['/path/to/module-a'],
});
expect(mockSpawn.calls[1].args[mockSpawn.calls[1].args.indexOf('-c') + 1]).toMatch(
'--dns-result-order=ipv4first --no-experimental-fetch'
'scripts/start.sh'
);
});

it('applies inspect mode to node process when useDebug is passed when starting with sh', async () => {
expect.assertions(1);
const mockSpawn = makeMockSpawn();
childProcess.spawn.mockImplementation(mockSpawn);
await startApp({
moduleMapUrl: 'https://example.com/module-map.json', rootModuleName: 'frank-lloyd-root', appDockerImage: 'one-app:latest', modulesToServe: ['/path/to/module-a'], useDebug: true,
});
expect(mockSpawn.calls[1].args[mockSpawn.calls[1].args.indexOf('-c') + 1]).toMatch(
'scripts/start.sh --inspect=0.0.0.0:9229'
);
});

Expand Down
19 changes: 14 additions & 5 deletions packages/one-app-runner/src/startApp.js
Original file line number Diff line number Diff line change
Expand Up @@ -138,12 +138,23 @@ const generateDebug = (port, useDebug) => (useDebug ? `--inspect=0.0.0.0:${port}
// So we have to remove those flags if the one-app version does not intersect ^5.13.0 or ^6.6.0
// 5.13.0 is when node 16 was introduced.
const generateNodeFlags = (appVersion) => {
if (appVersion === 'latest' || semver.intersects(appVersion, '^5.13.0 || ^6.6.0', { includePrerelease: true })) {
if (semver.intersects(appVersion, '^5.13.0 || ^6.6.0', { includePrerelease: true })) {
return '--dns-result-order=ipv4first --no-experimental-fetch';
}
return '';
};

const generateEntryCommand = (appVersion, debugPort, useDebug) => {
const debug = generateDebug(debugPort, useDebug);
let entry;
if (appVersion === 'latest' || semver.intersects(appVersion, '>=6.11.0-0', { includePrerelease: true })) {
entry = ['scripts/start.sh', debug];
} else {
entry = ['node', generateNodeFlags(appVersion), debug, 'lib/server/index.js'];
}
return entry.filter(Boolean).join(' ');
};

module.exports = async function startApp({
moduleMapUrl,
rootModuleName,
Expand Down Expand Up @@ -217,10 +228,8 @@ module.exports = async function startApp({
generateServeModuleCommands(modulesToServe),
generateSetMiddlewareCommand(parrotMiddlewareFile),
generateSetDevEndpointsCommand(devEndpointsFile),
'node',
generateNodeFlags(appVersion),
generateDebug(debugPort, useDebug),
`lib/server/index.js --root-module-name=${rootModuleName}`,
generateEntryCommand(appVersion, debugPort, useDebug),
`--root-module-name=${rootModuleName}`,
generateModuleMap(moduleMapUrl),
generateUseMocksFlag(parrotMiddlewareFile),
generateUseHostFlag(),
Expand Down

0 comments on commit 3aba75e

Please sign in to comment.