Skip to content

Commit 702dd5b

Browse files
filipesilvahansl
authored andcommitted
fix(@angular/cli): allow update to work without workspace
1 parent 36b2dae commit 702dd5b

File tree

4 files changed

+22
-3
lines changed

4 files changed

+22
-3
lines changed

packages/@angular/cli/commands/update.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@ export default class UpdateCommand extends SchematicCommand {
1616
public readonly options: Option[] = [
1717
...this.coreOptions,
1818
];
19+
public readonly allowMissingWorkspace = true;
1920

2021
public async run(options: UpdateOptions) {
2122
const collectionName = '@schematics/update';

packages/@angular/cli/models/command-runner.ts

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -76,7 +76,9 @@ export async function runCommand(commandMap: CommandMap,
7676
return await runHelp(command, options);
7777
} else {
7878
verifyCommandInScope(command, executionScope);
79-
verifyWorkspace(command, executionScope, context.project.root);
79+
if (!command.allowMissingWorkspace) {
80+
verifyWorkspace(command, executionScope, context.project.root);
81+
}
8082
delete options.h;
8183
delete options.help;
8284
return await validateAndRunCommand(command, options);

packages/@angular/cli/models/command.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@ export enum ArgumentStrategy {
2020

2121
export abstract class Command {
2222
protected _rawArgs: string[];
23+
public allowMissingWorkspace = false;
2324

2425
constructor(context: CommandContext, logger: logging.Logger) {
2526
this.logger = logger;

packages/@angular/cli/models/schematic-command.ts

Lines changed: 17 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -299,8 +299,23 @@ export abstract class SchematicCommand extends Command {
299299
}
300300
const workspaceLoader = new WorkspaceLoader(this._host);
301301

302-
workspaceLoader.loadWorkspace().pipe(take(1))
303-
.subscribe((workspace: experimental.workspace.Workspace) => this._workspace = workspace);
302+
try {
303+
workspaceLoader.loadWorkspace().pipe(take(1))
304+
.subscribe(
305+
(workspace: experimental.workspace.Workspace) => this._workspace = workspace,
306+
(err: Error) => {
307+
if (!this.allowMissingWorkspace) {
308+
// Ignore missing workspace
309+
throw err;
310+
}
311+
}
312+
);
313+
} catch (err) {
314+
if (!this.allowMissingWorkspace) {
315+
// Ignore missing workspace
316+
throw err;
317+
}
318+
}
304319
}
305320

306321
private readDefaults(collectionName: string, schematicName: string, options: any): any {

0 commit comments

Comments
 (0)