Skip to content

Commit

Permalink
fix(@schematics/angular): skip SSR routing prompt in webcontainer
Browse files Browse the repository at this point in the history
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)
  • Loading branch information
dgp1130 authored and clydin committed Nov 25, 2024
1 parent f9da163 commit 2f53e2a
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 0 deletions.
6 changes: 6 additions & 0 deletions packages/schematics/angular/ssr/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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?',
Expand Down
17 changes: 17 additions & 0 deletions packages/schematics/angular/ssr/index_spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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 () => {
Expand Down Expand Up @@ -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', () => {
Expand Down

0 comments on commit 2f53e2a

Please sign in to comment.