Skip to content

Support enhanced resolve #7169

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 2 commits into from
Jul 27, 2017
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
4 changes: 2 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@
"diff": "^3.1.0",
"ember-cli-normalize-entity-name": "^1.0.0",
"ember-cli-string-utils": "^1.0.0",
"enhanced-resolve": "3.3.0",
"enhanced-resolve": "^3.4.1",
"exports-loader": "^0.6.3",
"extract-text-webpack-plugin": "3.0.0",
"file-loader": "^0.10.0",
Expand Down Expand Up @@ -98,7 +98,7 @@
"typescript": "~2.4.2",
"url-loader": "^0.5.7",
"walk-sync": "^0.3.1",
"webpack": "3.3.0",
"webpack": "~3.4.1",
"webpack-dev-middleware": "^1.11.0",
"webpack-dev-server": "~2.5.1",
"webpack-merge": "^4.1.0",
Expand Down
2 changes: 1 addition & 1 deletion packages/@angular/cli/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,7 @@
"typescript": ">=2.0.0 <2.5.0",
"url-loader": "^0.5.7",
"walk-sync": "^0.3.1",
"webpack": "3.3.0",
"webpack": "~3.4.1",
"webpack-dev-middleware": "^1.11.0",
"webpack-dev-server": "~2.5.1",
"webpack-merge": "^4.1.0",
Expand Down
2 changes: 1 addition & 1 deletion packages/@ngtools/webpack/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -25,12 +25,12 @@
"npm": ">= 3.0.0"
},
"dependencies": {
"enhanced-resolve": "3.3.0",
"loader-utils": "^1.0.2",
"magic-string": "^0.22.3",
"source-map": "^0.5.6"
},
"peerDependencies": {
"enhanced-resolve": "^3.1.0",
"typescript": "^2.0.2",
"webpack": "^2.2.0 || ^3.0.0"
}
Expand Down
44 changes: 38 additions & 6 deletions packages/@ngtools/webpack/src/compiler_host.ts
Original file line number Diff line number Diff line change
Expand Up @@ -152,19 +152,49 @@ export class WebpackCompilerHost implements ts.CompilerHost {
return;
}

/**
* storageDataSetter is a temporary hack to address these two issues:
* - https://github.com/angular/angular-cli/issues/7113
* - https://github.com/angular/angular-cli/issues/7136
*
* This way we set values correctly in both a Map (enhanced-resove>=3.4.0) and
* object (enhanced-resolve >= 3.1.0 <3.4.0).
*
* The right solution is to create a virtual filesystem by decorating the filesystem,
* instead of injecting data into the private cache of the filesystem.
*
* Doing it the right way should fix other related bugs, but meanwhile we hack it since:
* - it's affecting a lot of users.
* - the real solution is non-trivial.
*/
function storageDataSetter(data: Map<string, any> | {[k: string]: any}, k: string, v: any) {

if (data instanceof Map) {
data.set(k, v);
} else {
data[k] = v;
}
}



const isWindows = process.platform.startsWith('win');
for (const fileName of this.getChangedFilePaths()) {
const stats = this._files[fileName];
if (stats) {
// If we're on windows, we need to populate with the proper path separator.
const path = isWindows ? fileName.replace(/\//g, '\\') : fileName;
fs._statStorage.data[path] = [null, stats];
fs._readFileStorage.data[path] = [null, stats.content];
// fs._statStorage.data[path] = [null, stats];
// fs._readFileStorage.data[path] = [null, stats.content];
storageDataSetter(fs._statStorage.data, path, [null, stats]);
storageDataSetter(fs._readFileStorage.data, path, [null, stats.content]);
} else {
// Support removing files as well.
const path = isWindows ? fileName.replace(/\//g, '\\') : fileName;
fs._statStorage.data[path] = [new Error(), null];
fs._readFileStorage.data[path] = [new Error(), null];
// fs._statStorage.data[path] = [new Error(), null];
// fs._readFileStorage.data[path] = [new Error(), null];
storageDataSetter(fs._statStorage.data, path, [new Error(), null]);
storageDataSetter(fs._readFileStorage.data, path, [new Error(), null]);
}
}
for (const dirName of Object.keys(this._changedDirs)) {
Expand All @@ -173,8 +203,10 @@ export class WebpackCompilerHost implements ts.CompilerHost {
const files = this.getFiles(dirName);
// If we're on windows, we need to populate with the proper path separator.
const path = isWindows ? dirName.replace(/\//g, '\\') : dirName;
fs._statStorage.data[path] = [null, stats];
fs._readdirStorage.data[path] = [null, files.concat(dirs)];
// fs._statStorage.data[path] = [null, stats];
// fs._readdirStorage.data[path] = [null, files.concat(dirs)];
storageDataSetter(fs._statStorage.data, path, [null, stats]);
storageDataSetter(fs._readFileStorage.data, path, [null, files.concat(dirs)]);
}
}

Expand Down
Loading