mirror of
https://github.com/angular/angular-cli.git
synced 2025-05-17 11:03:53 +08:00
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:
parent
8f9fc59f2e
commit
173dc0eeac
@ -451,6 +451,12 @@ async function isServerRoutingEnabled(
|
|||||||
return serverRoutingDefault;
|
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.
|
// Prompt the user if in an interactive terminal and no option was provided.
|
||||||
return await prompt(
|
return await prompt(
|
||||||
'Would you like to use the Server Routing and App Engine APIs (Developer Preview) for this server application?',
|
'Would you like to use the Server Routing and App Engine APIs (Developer Preview) for this server application?',
|
||||||
|
@ -108,6 +108,7 @@ describe('SSR Schematic', () => {
|
|||||||
|
|
||||||
afterEach(() => {
|
afterEach(() => {
|
||||||
process.env['NG_FORCE_TTY'] = originalTty;
|
process.env['NG_FORCE_TTY'] = originalTty;
|
||||||
|
delete process.versions.webcontainer;
|
||||||
});
|
});
|
||||||
|
|
||||||
it('should add script section in package.json', async () => {
|
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();
|
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', () => {
|
describe('Legacy browser builder', () => {
|
||||||
|
Loading…
x
Reference in New Issue
Block a user