From 0a464ea2ea40f4c453a016e89d28ea99fe009b8b Mon Sep 17 00:00:00 2001 From: Sumit Arora Date: Wed, 31 May 2017 11:43:23 -0400 Subject: [PATCH] fix(@angular/cli): fix delete path check --- packages/@angular/cli/tasks/build.ts | 2 +- packages/@angular/cli/tasks/eject.ts | 2 +- packages/@angular/cli/tasks/serve.ts | 2 +- tests/e2e/tests/commands/build/build-outdir.ts | 17 +++++++++++++++++ 4 files changed, 20 insertions(+), 3 deletions(-) create mode 100644 tests/e2e/tests/commands/build/build-outdir.ts diff --git a/packages/@angular/cli/tasks/build.ts b/packages/@angular/cli/tasks/build.ts index a7d092c4e661..bf0c55aab6ff 100644 --- a/packages/@angular/cli/tasks/build.ts +++ b/packages/@angular/cli/tasks/build.ts @@ -20,7 +20,7 @@ export default Task.extend({ const app = getAppFromConfig(runTaskOptions.app); const outputPath = runTaskOptions.outputPath || app.outDir; - if (this.project.root === outputPath) { + if (this.project.root === path.resolve(outputPath)) { throw new SilentError('Output path MUST not be project root directory!'); } if (config.project && config.project.ejected) { diff --git a/packages/@angular/cli/tasks/eject.ts b/packages/@angular/cli/tasks/eject.ts index 97f1435dfa2e..c64c93aa61c6 100644 --- a/packages/@angular/cli/tasks/eject.ts +++ b/packages/@angular/cli/tasks/eject.ts @@ -397,7 +397,7 @@ export default Task.extend({ const outputPath = runTaskOptions.outputPath || appConfig.outDir; const force = runTaskOptions.force; - if (project.root === outputPath) { + if (project.root === path.resolve(outputPath)) { throw new SilentError ('Output path MUST not be project root directory!'); } diff --git a/packages/@angular/cli/tasks/serve.ts b/packages/@angular/cli/tasks/serve.ts index 84adb97cd6f7..d656674f0d91 100644 --- a/packages/@angular/cli/tasks/serve.ts +++ b/packages/@angular/cli/tasks/serve.ts @@ -25,7 +25,7 @@ export default Task.extend({ const appConfig = getAppFromConfig(serveTaskOptions.app); const outputPath = serveTaskOptions.outputPath || appConfig.outDir; - if (this.project.root === outputPath) { + if (this.project.root === path.resolve(outputPath)) { throw new SilentError('Output path MUST not be project root directory!'); } if (projectConfig.project && projectConfig.project.ejected) { diff --git a/tests/e2e/tests/commands/build/build-outdir.ts b/tests/e2e/tests/commands/build/build-outdir.ts new file mode 100644 index 000000000000..6259cec5299d --- /dev/null +++ b/tests/e2e/tests/commands/build/build-outdir.ts @@ -0,0 +1,17 @@ +import {ng} from '../../../utils/process'; +import {updateJsonFile} from '../../../utils/project'; +import {expectToFail} from '../../../utils/utils'; + +export default function() { + return Promise.resolve() + .then(() => updateJsonFile('.angular-cli.json', configJson => { + const app = configJson['apps'][0]; + app['outDir'] = './'; + })) + .then(() => expectToFail(() => ng('build'))) + .then(() => expectToFail(() => ng('serve'))) + .then(() => expectToFail(() => ng('eject'))); +} + + +