From d53f45896ba641a98601ca87551c577f47659cd3 Mon Sep 17 00:00:00 2001 From: tomastrajan Date: Tue, 5 Dec 2017 17:27:39 +1100 Subject: [PATCH] feat(@angular/cli): add trailing slash to deployUrl when missing Closes #7295 --- packages/@angular/cli/commands/build.ts | 5 +++++ tests/e2e/tests/build/deploy-url.ts | 11 ++++++++++- 2 files changed, 15 insertions(+), 1 deletion(-) diff --git a/packages/@angular/cli/commands/build.ts b/packages/@angular/cli/commands/build.ts index 401a2b2828..2611e66b05 100644 --- a/packages/@angular/cli/commands/build.ts +++ b/packages/@angular/cli/commands/build.ts @@ -239,6 +239,11 @@ const BuildCommand = Command.extend({ commandOptions.forceTsCommonjs = true; } + // Add trailing slash if missing to prevent https://github.com/angular/angular-cli/issues/7295 + if (commandOptions.deployUrl && commandOptions.deployUrl.substr(-1) !== '/') { + commandOptions.deployUrl += '/'; + } + const BuildTask = require('../tasks/build').default; const buildTask = new BuildTask({ diff --git a/tests/e2e/tests/build/deploy-url.ts b/tests/e2e/tests/build/deploy-url.ts index 43293efbdb..36acdcfdda 100644 --- a/tests/e2e/tests/build/deploy-url.ts +++ b/tests/e2e/tests/build/deploy-url.ts @@ -2,6 +2,7 @@ import { ng } from '../../utils/process'; import { copyProjectAsset } from '../../utils/assets'; import { expectFileToMatch, writeMultipleFiles } from '../../utils/fs'; import { updateJsonFile } from '../../utils/project'; +import { getGlobalVariable } from '../../utils/env'; export default function () { @@ -27,5 +28,13 @@ export default function () { // verify --deploy-url is applied to non-extracted css urls .then(() => ng('build', '--deploy-url=deployUrl/', '--extract-css=false')) .then(() => expectFileToMatch('dist/styles.bundle.js', - /__webpack_require__.p \+ \"more\.[0-9a-f]{20}\.png\"/)); + /__webpack_require__.p \+ \"more\.[0-9a-f]{20}\.png\"/)) + .then(() => expectFileToMatch('dist/inline.bundle.js', + /__webpack_require__\.p = "deployUrl\/";/)) + // verify slash is appended to the end of --deploy-url if missing + .then(() => ng('build', '--deploy-url=deployUrl', '--extract-css=false')) + // skip this in ejected tests + .then(() => getGlobalVariable('argv').eject + ? Promise.resolve() + : expectFileToMatch('dist/inline.bundle.js', /__webpack_require__\.p = "deployUrl\/";/)); }