Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit 9c7a7ea

Browse files
committed
fix(@angular/cli): allow node_modules to be linked somewhere else.
Fixes #6499.
1 parent bbe3a35 commit 9c7a7ea

File tree

4 files changed

+47
-3
lines changed

4 files changed

+47
-3
lines changed

‎packages/@angular/cli/models/webpack-configs/browser.ts‎

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
import * as fs from 'fs';
12
import * as webpack from 'webpack';
23
import * as path from 'path';
34
const HtmlWebpackPlugin = require('html-webpack-plugin');
@@ -24,14 +25,20 @@ export function getBrowserConfig(wco: WebpackConfigOptions) {
2425
if (buildOptions.vendorChunk) {
2526
// Separate modules from node_modules into a vendor chunk.
2627
const nodeModules = path.resolve(projectRoot, 'node_modules');
28+
// Resolves all symlink to get the actual node modules folder.
29+
const realNodeModules = fs.realpathSync(nodeModules);
2730
// --aot puts the generated *.ngfactory.ts in src/$$_gendir/node_modules.
2831
const genDirNodeModules = path.resolve(appRoot, '$$_gendir', 'node_modules');
2932

3033
extraPlugins.push(new webpack.optimize.CommonsChunkPlugin({
3134
name: 'vendor',
3235
chunks: ['main'],
33-
minChunks: (module: any) => module.resource &&
34-
(module.resource.startsWith(nodeModules) || module.resource.startsWith(genDirNodeModules))
36+
minChunks: (module: any) => {
37+
return module.resource
38+
&& ( module.resource.startsWith(nodeModules)
39+
|| module.resource.startsWith(genDirNodeModules)
40+
|| module.resource.startsWith(realNodeModules));
41+
}
3542
}));
3643
}
3744

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

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,10 +35,12 @@ const pree2eNpmScript = `webdriver-manager update --standalone false --gecko fal
3535
class JsonWebpackSerializer {
3636
public imports: {[name: string]: string[]} = {};
3737
public variableImports: {[name: string]: string} = {
38-
'path': 'path'
38+
'fs': 'fs',
39+
'path': 'path',
3940
};
4041
public variables: {[name: string]: string} = {
4142
'nodeModules': `path.join(process.cwd(), 'node_modules')`,
43+
'realNodeModules': `fs.realpathSync(nodeModules)`,
4244
'genDirNodeModules':
4345
`path.join(process.cwd(), '${this._appRoot}', '$$_gendir', 'node_modules')`,
4446
};
Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
import {ng} from '../../utils/process';
2+
import {deleteFile, expectFileToExist, moveFile, symlinkFile} from '../../utils/fs';
3+
4+
5+
// THIS TEST REQUIRES TO MOVE NODE_MODULES AND MOVE IT BACK.
6+
export default function() {
7+
return Promise.resolve()
8+
.then(() => moveFile('node_modules', '../node_modules'))
9+
.then(() => symlinkFile('../node_modules', 'node_modules', 'dir'))
10+
.then(() => ng('build'))
11+
.then(() => expectFileToExist('dist/vendor.bundle.js'))
12+
.then(() => expectFileToExist('dist/vendor.bundle.js.map'))
13+
// Cleanup
14+
.then(() => {
15+
return deleteFile('node_modules')
16+
.then(() => moveFile('../node_modules', 'node_modules'));
17+
}, (err: any) => {
18+
return deleteFile('node_modules')
19+
.then(() => moveFile('../node_modules', 'node_modules'))
20+
.then(() => { throw err; });
21+
})
22+
}

‎tests/e2e/utils/fs.ts‎

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -67,6 +67,19 @@ export function moveFile(from: string, to: string) {
6767
});
6868
}
6969

70+
71+
export function symlinkFile(from: string, to: string, type?: string) {
72+
return new Promise<void>((resolve, reject) => {
73+
fs.symlink(from, to, type, (err) => {
74+
if (err) {
75+
reject(err);
76+
} else {
77+
resolve();
78+
}
79+
});
80+
});
81+
}
82+
7083
export function createDir(path: string) {
7184
_recursiveMkDir(path);
7285
}

0 commit comments

Comments
(0)

AltStyle によって変換されたページ (->オリジナル) /