Skip to content

Commit 596f35d

Browse files
committed
feat(@angular/cli): disable invalid commands on ejected apps
1 parent 8f2b1ce commit 596f35d

File tree

5 files changed

+47
-4
lines changed

5 files changed

+47
-4
lines changed

packages/@angular/cli/tasks/build.ts

+6-2
Original file line numberDiff line numberDiff line change
@@ -14,10 +14,14 @@ export default Task.extend({
1414
run: function (runTaskOptions: BuildTaskOptions) {
1515

1616
const project = this.cliProject;
17+
const config = CliConfig.fromProject().config;
1718

18-
const outputPath = runTaskOptions.outputPath || CliConfig.fromProject().config.apps[0].outDir;
19+
const outputPath = runTaskOptions.outputPath || config.apps[0].outDir;
1920
if (project.root === outputPath) {
20-
throw new SilentError ('Output path MUST not be project root directory!');
21+
throw new SilentError('Output path MUST not be project root directory!');
22+
}
23+
if (config.project && config.project.ejected) {
24+
throw new SilentError('An ejected project cannot use the build command anymore.');
2125
}
2226
rimraf.sync(path.resolve(project.root, outputPath));
2327

packages/@angular/cli/tasks/e2e.ts

+8
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,23 @@
11
import * as url from 'url';
22

33
import { E2eTaskOptions } from '../commands/e2e';
4+
import { CliConfig } from '../models/config';
45
import { requireProjectModule } from '../utilities/require-project-module';
6+
57
const Task = require('../ember-cli/lib/models/task');
8+
const SilentError = require('silent-error');
69

710

811
export const E2eTask = Task.extend({
912
run: function (e2eTaskOptions: E2eTaskOptions) {
13+
const projectConfig = CliConfig.fromProject().config;
1014
const projectRoot = this.project.root;
1115
const protractorLauncher = requireProjectModule(projectRoot, 'protractor/built/launcher');
1216

17+
if (projectConfig.project && projectConfig.project.ejected) {
18+
throw new SilentError('An ejected project cannot use the build command anymore.');
19+
}
20+
1321
return new Promise(function () {
1422
let promise = Promise.resolve();
1523
let additionalProtractorConfig: any = {

packages/@angular/cli/tasks/serve.ts

+3
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,9 @@ export default Task.extend({
2727
if (this.project.root === outputPath) {
2828
throw new SilentError('Output path MUST not be project root directory!');
2929
}
30+
if (projectConfig.project && projectConfig.project.ejected) {
31+
throw new SilentError('An ejected project cannot use the build command anymore.');
32+
}
3033
rimraf.sync(path.resolve(this.project.root, outputPath));
3134

3235
const serveDefaults = {

packages/@angular/cli/tasks/test.ts

+13-2
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,22 @@
1-
const Task = require('../ember-cli/lib/models/task');
2-
import { TestOptions } from '../commands/test';
31
import * as path from 'path';
2+
3+
import { TestOptions } from '../commands/test';
4+
import { CliConfig } from '../models/config';
45
import { requireProjectModule } from '../utilities/require-project-module';
56

7+
const Task = require('../ember-cli/lib/models/task');
8+
const SilentError = require('silent-error');
9+
10+
611
export default Task.extend({
712
run: function (options: TestOptions) {
13+
const projectConfig = CliConfig.fromProject().config;
814
const projectRoot = this.project.root;
15+
16+
if (projectConfig.project && projectConfig.project.ejected) {
17+
throw new SilentError('An ejected project cannot use the build command anymore.');
18+
}
19+
920
return new Promise((resolve) => {
1021
const karma = requireProjectModule(projectRoot, 'karma');
1122
const karmaConfig = path.join(projectRoot, options.config ||
+17
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
import * as path from 'path';
2+
3+
import {ng, silentNpm, exec} from '../../../utils/process';
4+
import {expectToFail} from '../../../utils/utils';
5+
import {expectGitToBeClean} from '../../../utils/git';
6+
7+
8+
export default function() {
9+
return ng('eject')
10+
.then(() => expectToFail(() => ng('build')))
11+
.then(() => expectToFail(() => ng('test')))
12+
.then(() => expectToFail(() => ng('e2e')))
13+
.then(() => expectToFail(() => ng('serve')))
14+
.then(() => expectToFail(() => expectGitToBeClean()))
15+
.then(() => silentNpm('install'))
16+
.then(() => exec(path.join('node_modules', '.bin', 'webpack')));
17+
}

0 commit comments

Comments
 (0)