Skip to content

Commit 1b57f12

Browse files
committedJan 24, 2018
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 ac9c599 commit 1b57f12

File tree

2 files changed

+24
-6
lines changed

2 files changed

+24
-6
lines changed
 

Diff for: ‎packages/@angular/cli/tasks/eject.ts

+19-6
Original file line numberDiff line numberDiff line change
@@ -225,6 +225,7 @@ class JsonWebpackSerializer {
225225
break;
226226
case CircularDependencyPlugin:
227227
this.variableImports['circular-dependency-plugin'] = 'CircularDependencyPlugin';
228+
args.cwd = this._escape('projectRoot');
228229
break;
229230
case AotPlugin:
230231
args = this._aotPluginSerialize(plugin);
@@ -264,11 +265,13 @@ class JsonWebpackSerializer {
264265
// CopyWebpackPlugin doesn't have a constructor nor save args.
265266
this.variableImports['copy-webpack-plugin'] = 'CopyWebpackPlugin';
266267
const patternOptions = plugin['copyWebpackPluginPatterns'].map((pattern: any) => {
267-
if (!pattern.context) {
268-
return pattern;
268+
if (pattern.context) {
269+
pattern.context = path.relative(process.cwd(), pattern.context);
269270
}
270-
const context = path.relative(process.cwd(), pattern.context);
271-
return { ...pattern, context };
271+
if (pattern.from && pattern.from.glob) {
272+
pattern.from.glob = path.relative(process.cwd(), pattern.from.glob);
273+
}
274+
return pattern;
272275
});
273276
const patternsSerialized = serializer(patternOptions);
274277
const optionsSerialized = serializer(plugin['copyWebpackPluginOptions']) || 'undefined';
@@ -315,7 +318,7 @@ class JsonWebpackSerializer {
315318
if (loader.match(/\/node_modules\/extract-text-webpack-plugin\//)) {
316319
return 'extract-text-webpack-plugin';
317320
} else if (loader.match(/@ngtools\/webpack\/src\/index.ts/)) {
318-
// return '@ngtools/webpack';
321+
return '@ngtools/webpack';
319322
}
320323
} else {
321324
if (loader.loader) {
@@ -327,7 +330,17 @@ class JsonWebpackSerializer {
327330
Object.keys(args.variableImports)
328331
.forEach(key => this.variableImports[key] = args.variableImports[key]);
329332
Object.keys(args.variables)
330-
.forEach(key => this.variables[key] = JSON.stringify(args.variables[key]));
333+
.forEach(key => {
334+
const value = args.variables[key];
335+
if (value === process.cwd()) {
336+
this.variables[key] = 'process.cwd()';
337+
} else if (typeof value == 'string' && value.startsWith(process.cwd())) {
338+
this.variables[key] = 'process.cwd() + '
339+
+ JSON.stringify(value.substr(process.cwd().length));
340+
} else {
341+
this.variables[key] = JSON.stringify(value);
342+
}
343+
});
331344

332345
this.variables['postcssPlugins'] = loader.options.plugins;
333346
loader.options.plugins = this._escape('postcssPlugins');

Diff for: ‎tests/e2e/tests/commands/eject/eject.ts

+5
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)