Skip to content

Commit 2f53e2a

Browse files
dgp1130clydin
authored andcommitted
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: SBoudrias/Inquirer.js#1426 (cherry picked from commit 173dc0e)
1 parent f9da163 commit 2f53e2a

File tree

2 files changed

+23
-0
lines changed

2 files changed

+23
-0
lines changed

packages/schematics/angular/ssr/index.ts

+6
Original file line numberDiff line numberDiff line change
@@ -451,6 +451,12 @@ async function isServerRoutingEnabled(
451451
return serverRoutingDefault;
452452
}
453453

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

packages/schematics/angular/ssr/index_spec.ts

+17
Original file line numberDiff line numberDiff line change
@@ -108,6 +108,7 @@ describe('SSR Schematic', () => {
108108

109109
afterEach(() => {
110110
process.env['NG_FORCE_TTY'] = originalTty;
111+
delete process.versions.webcontainer;
111112
});
112113

113114
it('should add script section in package.json', async () => {
@@ -230,6 +231,22 @@ describe('SSR Schematic', () => {
230231

231232
expect(tree.exists('/projects/test-app/src/app/app.routes.server.ts')).toBeFalse();
232233
});
234+
235+
it('does not prompt when running in a web container', async () => {
236+
const prompter = jasmine.createSpy<Prompt>('prompt').and.resolveTo(false);
237+
setPrompterForTestOnly(prompter);
238+
239+
process.versions.webcontainer = 'abc123'; // Simulate webcontainer.
240+
const tree = await schematicRunner.runSchematic(
241+
'ssr',
242+
{ ...defaultOptions, serverRouting: undefined },
243+
appTree,
244+
);
245+
246+
expect(prompter).not.toHaveBeenCalled();
247+
248+
expect(tree.exists('/projects/test-app/src/app/app.routes.server.ts')).toBeFalse();
249+
});
233250
});
234251

235252
describe('Legacy browser builder', () => {

0 commit comments

Comments
 (0)