-
Notifications
You must be signed in to change notification settings - Fork 12k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix(@angular/cli): provide actionable error when project cannot be de…
…termined When the workspace has multiple projects and we the project to use cannot be determined from the current working directory, we now issue an actionable error message. (cherry picked from commit 79ea0f3)
- Loading branch information
1 parent
613ba31
commit 17fec13
Showing
2 changed files
with
48 additions
and
4 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
36 changes: 36 additions & 0 deletions
36
tests/legacy-cli/e2e/tests/commands/project-cannot-be-determined-by-cwd.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
import { join } from 'path'; | ||
import { execAndWaitForOutputToMatch, ng } from '../../utils/process'; | ||
import { updateJsonFile } from '../../utils/project'; | ||
import { expectToFail } from '../../utils/utils'; | ||
|
||
export default async function () { | ||
const errorMessage = | ||
'Cannot determine project for command. ' + | ||
'Pass the project name as a command line argument or change the current working directory to a project directory'; | ||
|
||
// Delete root project | ||
await updateJsonFile('angular.json', (workspaceJson) => { | ||
delete workspaceJson.projects['test-project']; | ||
}); | ||
|
||
await ng('generate', 'app', 'second-app', '--skip-install'); | ||
await ng('generate', 'app', 'third-app', '--skip-install'); | ||
|
||
const startCwd = process.cwd(); | ||
|
||
try { | ||
const { message } = await expectToFail(() => ng('build')); | ||
if (!message.includes(errorMessage)) { | ||
throw new Error(`Expected build to fail with: '${errorMessage}'.`); | ||
} | ||
|
||
// Help should still work | ||
execAndWaitForOutputToMatch('ng', ['build', '--help'], /--configuration/); | ||
|
||
process.chdir(join(startCwd, 'projects/second-app')); | ||
await ng('build', '--configuration=development'); | ||
} finally { | ||
// Restore path | ||
process.chdir(startCwd); | ||
} | ||
} |