Skip to content

Commit

Permalink
feat(misc): do not prompt for project name and root format when they …
Browse files Browse the repository at this point in the history
…produce the same result (#19221)
  • Loading branch information
leosvelperez authored Sep 20, 2023
1 parent 8530b45 commit a020f1d
Show file tree
Hide file tree
Showing 2 changed files with 31 additions and 0 deletions.
27 changes: 27 additions & 0 deletions packages/devkit/src/generators/project-name-and-root-utils.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -394,6 +394,33 @@ describe('determineProjectNameAndRootOptions', () => {
// restore original interactive mode
restoreOriginalInteractiveMode();
});

it('should not prompt when the resulting name and root are the same for both formats', async () => {
// simulate interactive mode
ensureInteractiveMode();
const promptSpy = jest.spyOn(enquirer, 'prompt');

const result = await determineProjectNameAndRootOptions(tree, {
name: 'libName',
projectType: 'library',
callingGenerator: '',
});

expect(promptSpy).not.toHaveBeenCalled();
expect(result).toEqual({
projectName: 'lib-name',
names: {
projectSimpleName: 'lib-name',
projectFileName: 'lib-name',
},
importPath: '@proj/lib-name',
projectRoot: 'lib-name',
projectNameAndRootFormat: 'as-provided',
});

// restore original interactive mode
restoreOriginalInteractiveMode();
});
});

describe('with layout', () => {
Expand Down
4 changes: 4 additions & 0 deletions packages/devkit/src/generators/project-name-and-root-utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -155,6 +155,10 @@ async function determineFormat(
Root: ${formats['derived'].projectRoot}`;
const derivedSelectedValue = `${formats['derived'].projectName} @ ${formats['derived'].projectRoot}`;

if (asProvidedSelectedValue === derivedSelectedValue) {
return 'as-provided';
}

const result = await prompt<{ format: ProjectNameAndRootFormat }>({
type: 'select',
name: 'format',
Expand Down

0 comments on commit a020f1d

Please sign in to comment.