fix(@schematics/angular): skip SSR routing prompt in webcontainer

Apparently `inquirer` requires `async_hooks` which isn't supported in webcontainers, therefore prompting the user fails. Instead we always fall back to the default option.

See: https://github.com/SBoudrias/Inquirer.js/issues/1426
This commit is contained in:
Doug Parker 2024-11-21 17:29:38 -08:00 committed by Charles
parent 8f9fc59f2e
commit 173dc0eeac
2 changed files with 23 additions and 0 deletions

View File

@ -451,6 +451,12 @@ async function isServerRoutingEnabled(
return serverRoutingDefault;
}
// `inquirer` requires `async_hooks` which isn't supported by webcontainers, therefore we can't prompt in that context.
// See: https://github.com/SBoudrias/Inquirer.js/issues/1426
if (process.versions.webcontainer) {
return serverRoutingDefault;
}
// Prompt the user if in an interactive terminal and no option was provided.
return await prompt(
'Would you like to use the Server Routing and App Engine APIs (Developer Preview) for this server application?',

View File

@ -108,6 +108,7 @@ describe('SSR Schematic', () => {
afterEach(() => {
process.env['NG_FORCE_TTY'] = originalTty;
delete process.versions.webcontainer;
});
it('should add script section in package.json', async () => {
@ -230,6 +231,22 @@ describe('SSR Schematic', () => {
expect(tree.exists('/projects/test-app/src/app/app.routes.server.ts')).toBeFalse();
});
it('does not prompt when running in a web container', async () => {
const prompter = jasmine.createSpy<Prompt>('prompt').and.resolveTo(false);
setPrompterForTestOnly(prompter);
process.versions.webcontainer = 'abc123'; // Simulate webcontainer.
const tree = await schematicRunner.runSchematic(
'ssr',
{ ...defaultOptions, serverRouting: undefined },
appTree,
);
expect(prompter).not.toHaveBeenCalled();
expect(tree.exists('/projects/test-app/src/app/app.routes.server.ts')).toBeFalse();
});
});
describe('Legacy browser builder', () => {