Skip to content

Commit 53e84fe

Browse files
committed
fix(@angular/cli): eject now remove all hardcoded paths
In favor of process.cwd(). Also added a new eject e2e test that verifies the webpack.config.js does NOT have the project path in it at any place. Fixed #9335.
1 parent bf87508 commit 53e84fe

File tree

2 files changed

+24
-6
lines changed

2 files changed

+24
-6
lines changed

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

Lines changed: 19 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -213,6 +213,7 @@ class JsonWebpackSerializer {
213213
break;
214214
case CircularDependencyPlugin:
215215
this.variableImports['circular-dependency-plugin'] = 'CircularDependencyPlugin';
216+
args.cwd = this._escape('projectRoot');
216217
break;
217218
case AotPlugin:
218219
args = this._aotPluginSerialize(plugin);
@@ -252,11 +253,13 @@ class JsonWebpackSerializer {
252253
// CopyWebpackPlugin doesn't have a constructor nor save args.
253254
this.variableImports['copy-webpack-plugin'] = 'CopyWebpackPlugin';
254255
const patternOptions = plugin['copyWebpackPluginPatterns'].map((pattern: any) => {
255-
if (!pattern.context) {
256-
return pattern;
256+
if (pattern.context) {
257+
pattern.context = path.relative(process.cwd(), pattern.context);
257258
}
258-
const context = path.relative(process.cwd(), pattern.context);
259-
return { ...pattern, context };
259+
if (pattern.from && pattern.from.glob) {
260+
pattern.from.glob = path.relative(process.cwd(), pattern.from.glob);
261+
}
262+
return pattern;
260263
});
261264
const patternsSerialized = serializer(patternOptions);
262265
const optionsSerialized = serializer(plugin['copyWebpackPluginOptions']) || 'undefined';
@@ -303,7 +306,7 @@ class JsonWebpackSerializer {
303306
if (loader.match(/\/node_modules\/extract-text-webpack-plugin\//)) {
304307
return 'extract-text-webpack-plugin';
305308
} else if (loader.match(/@ngtools\/webpack\/src\/index.ts/)) {
306-
// return '@ngtools/webpack';
309+
return '@ngtools/webpack';
307310
}
308311
} else {
309312
if (loader.loader) {
@@ -315,7 +318,17 @@ class JsonWebpackSerializer {
315318
Object.keys(args.variableImports)
316319
.forEach(key => this.variableImports[key] = args.variableImports[key]);
317320
Object.keys(args.variables)
318-
.forEach(key => this.variables[key] = JSON.stringify(args.variables[key]));
321+
.forEach(key => {
322+
const value = args.variables[key];
323+
if (value === process.cwd()) {
324+
this.variables[key] = 'process.cwd()';
325+
} else if (typeof value == 'string' && value.startsWith(process.cwd())) {
326+
this.variables[key] = 'process.cwd() + '
327+
+ JSON.stringify(value.substr(process.cwd().length));
328+
} else {
329+
this.variables[key] = JSON.stringify(value);
330+
}
331+
});
319332

320333
this.variables['postcssPlugins'] = loader.options.plugins;
321334
loader.options.plugins = this._escape('postcssPlugins');

tests/e2e/tests/commands/eject/eject.ts

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
import * as path from 'path';
2+
import { expectFileToMatch, readFile } from '../../../utils/fs';
23

34
import {ng, silentNpm, exec} from '../../../utils/process';
45
import {expectToFail} from '../../../utils/utils';
@@ -12,6 +13,10 @@ export default function() {
1213
.then(() => expectToFail(() => ng('e2e')))
1314
.then(() => expectToFail(() => ng('serve')))
1415
.then(() => expectToFail(() => expectGitToBeClean()))
16+
17+
// Check that no path appears anymore.
18+
.then(() => expectToFail(() => expectFileToMatch('webpack.config.js', process.cwd())))
19+
1520
.then(() => silentNpm('install'))
1621
.then(() => exec(path.join('node_modules', '.bin', 'webpack')));
1722
}

0 commit comments

Comments
 (0)