Skip to content

Commit

Permalink
fix(@angular/cli): allow update to work without workspace
Browse files Browse the repository at this point in the history
  • Loading branch information
filipesilva authored and hansl committed Apr 3, 2018
1 parent 36b2dae commit 702dd5b
Show file tree
Hide file tree
Showing 4 changed files with 22 additions and 3 deletions.
1 change: 1 addition & 0 deletions packages/@angular/cli/commands/update.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ export default class UpdateCommand extends SchematicCommand {
public readonly options: Option[] = [
...this.coreOptions,
];
public readonly allowMissingWorkspace = true;

public async run(options: UpdateOptions) {
const collectionName = '@schematics/update';
Expand Down
4 changes: 3 additions & 1 deletion packages/@angular/cli/models/command-runner.ts
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,9 @@ export async function runCommand(commandMap: CommandMap,
return await runHelp(command, options);
} else {
verifyCommandInScope(command, executionScope);
verifyWorkspace(command, executionScope, context.project.root);
if (!command.allowMissingWorkspace) {
verifyWorkspace(command, executionScope, context.project.root);
}
delete options.h;
delete options.help;
return await validateAndRunCommand(command, options);
Expand Down
1 change: 1 addition & 0 deletions packages/@angular/cli/models/command.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ export enum ArgumentStrategy {

export abstract class Command {
protected _rawArgs: string[];
public allowMissingWorkspace = false;

constructor(context: CommandContext, logger: logging.Logger) {
this.logger = logger;
Expand Down
19 changes: 17 additions & 2 deletions packages/@angular/cli/models/schematic-command.ts
Original file line number Diff line number Diff line change
Expand Up @@ -299,8 +299,23 @@ export abstract class SchematicCommand extends Command {
}
const workspaceLoader = new WorkspaceLoader(this._host);

workspaceLoader.loadWorkspace().pipe(take(1))
.subscribe((workspace: experimental.workspace.Workspace) => this._workspace = workspace);
try {
workspaceLoader.loadWorkspace().pipe(take(1))
.subscribe(
(workspace: experimental.workspace.Workspace) => this._workspace = workspace,
(err: Error) => {
if (!this.allowMissingWorkspace) {
// Ignore missing workspace
throw err;
}
}
);
} catch (err) {
if (!this.allowMissingWorkspace) {
// Ignore missing workspace
throw err;
}
}
}

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

0 comments on commit 702dd5b

Please sign in to comment.