From 173dc0eeac0543e600244d40a2b94505904cbe66 Mon Sep 17 00:00:00 2001 From: Doug Parker Date: Thu, 21 Nov 2024 17:29:38 -0800 Subject: [PATCH] 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 --- packages/schematics/angular/ssr/index.ts | 6 ++++++ packages/schematics/angular/ssr/index_spec.ts | 17 +++++++++++++++++ 2 files changed, 23 insertions(+) diff --git a/packages/schematics/angular/ssr/index.ts b/packages/schematics/angular/ssr/index.ts index 9aa44f6686..6249778a85 100644 --- a/packages/schematics/angular/ssr/index.ts +++ b/packages/schematics/angular/ssr/index.ts @@ -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?', diff --git a/packages/schematics/angular/ssr/index_spec.ts b/packages/schematics/angular/ssr/index_spec.ts index 7f917f8d4d..a7de8d12f2 100644 --- a/packages/schematics/angular/ssr/index_spec.ts +++ b/packages/schematics/angular/ssr/index_spec.ts @@ -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').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', () => {