Skip to content

fix(@angular/cli): eject now remove all hardcoded paths #9346

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Jan 24, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
25 changes: 19 additions & 6 deletions packages/@angular/cli/tasks/eject.ts
Original file line number Diff line number Diff line change
Expand Up @@ -225,6 +225,7 @@ class JsonWebpackSerializer {
break;
case CircularDependencyPlugin:
this.variableImports['circular-dependency-plugin'] = 'CircularDependencyPlugin';
args.cwd = this._escape('projectRoot');
break;
case AotPlugin:
args = this._aotPluginSerialize(plugin);
Expand Down Expand Up @@ -264,11 +265,13 @@ class JsonWebpackSerializer {
// CopyWebpackPlugin doesn't have a constructor nor save args.
this.variableImports['copy-webpack-plugin'] = 'CopyWebpackPlugin';
const patternOptions = plugin['copyWebpackPluginPatterns'].map((pattern: any) => {
if (!pattern.context) {
return pattern;
if (pattern.context) {
pattern.context = path.relative(process.cwd(), pattern.context);
}
const context = path.relative(process.cwd(), pattern.context);
return { ...pattern, context };
if (pattern.from && pattern.from.glob) {
pattern.from.glob = path.relative(process.cwd(), pattern.from.glob);
}
return pattern;
});
const patternsSerialized = serializer(patternOptions);
const optionsSerialized = serializer(plugin['copyWebpackPluginOptions']) || 'undefined';
Expand Down Expand Up @@ -315,7 +318,7 @@ class JsonWebpackSerializer {
if (loader.match(/\/node_modules\/extract-text-webpack-plugin\//)) {
return 'extract-text-webpack-plugin';
} else if (loader.match(/@ngtools\/webpack\/src\/index.ts/)) {
// return '@ngtools/webpack';
return '@ngtools/webpack';
}
} else {
if (loader.loader) {
Expand All @@ -327,7 +330,17 @@ class JsonWebpackSerializer {
Object.keys(args.variableImports)
.forEach(key => this.variableImports[key] = args.variableImports[key]);
Object.keys(args.variables)
.forEach(key => this.variables[key] = JSON.stringify(args.variables[key]));
.forEach(key => {
const value = args.variables[key];
if (value === process.cwd()) {
this.variables[key] = 'process.cwd()';
} else if (typeof value == 'string' && value.startsWith(process.cwd())) {
this.variables[key] = 'process.cwd() + '
+ JSON.stringify(value.substr(process.cwd().length));
} else {
this.variables[key] = JSON.stringify(value);
}
});

this.variables['postcssPlugins'] = loader.options.plugins;
loader.options.plugins = this._escape('postcssPlugins');
Expand Down
5 changes: 5 additions & 0 deletions tests/e2e/tests/commands/eject/eject.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import * as path from 'path';
import { expectFileToMatch, readFile } from '../../../utils/fs';

import {ng, silentNpm, exec} from '../../../utils/process';
import {expectToFail} from '../../../utils/utils';
Expand All @@ -12,6 +13,10 @@ export default function() {
.then(() => expectToFail(() => ng('e2e')))
.then(() => expectToFail(() => ng('serve')))
.then(() => expectToFail(() => expectGitToBeClean()))

// Check that no path appears anymore.
.then(() => expectToFail(() => expectFileToMatch('webpack.config.js', process.cwd())))

.then(() => silentNpm('install'))
.then(() => exec(path.join('node_modules', '.bin', 'webpack')));
}