Skip to content

Commit 9522213

Browse files
filipesilvadond2clouds
authored andcommitted
Support enhanced resolve (angular#7169)
* fix(@ngtools/webpack): support [email protected] Followup to angular#7123 * fix(@angular/cli): unpin webpack 3.3.0 Followup to angular#7130
1 parent d93d1ce commit 9522213

File tree

5 files changed

+181
-25
lines changed

5 files changed

+181
-25
lines changed

package.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,7 @@
5252
"diff": "^3.1.0",
5353
"ember-cli-normalize-entity-name": "^1.0.0",
5454
"ember-cli-string-utils": "^1.0.0",
55-
"enhanced-resolve": "3.3.0",
55+
"enhanced-resolve": "^3.4.1",
5656
"exports-loader": "^0.6.3",
5757
"extract-text-webpack-plugin": "3.0.0",
5858
"file-loader": "^0.10.0",
@@ -98,7 +98,7 @@
9898
"typescript": "~2.4.2",
9999
"url-loader": "^0.5.7",
100100
"walk-sync": "^0.3.1",
101-
"webpack": "3.3.0",
101+
"webpack": "~3.4.1",
102102
"webpack-dev-middleware": "^1.11.0",
103103
"webpack-dev-server": "~2.5.1",
104104
"webpack-merge": "^4.1.0",

packages/@angular/cli/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -83,7 +83,7 @@
8383
"typescript": ">=2.0.0 <2.5.0",
8484
"url-loader": "^0.5.7",
8585
"walk-sync": "^0.3.1",
86-
"webpack": "3.3.0",
86+
"webpack": "~3.4.1",
8787
"webpack-dev-middleware": "^1.11.0",
8888
"webpack-dev-server": "~2.5.1",
8989
"webpack-merge": "^4.1.0",

packages/@ngtools/webpack/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,12 +25,12 @@
2525
"npm": ">= 3.0.0"
2626
},
2727
"dependencies": {
28-
"enhanced-resolve": "3.3.0",
2928
"loader-utils": "^1.0.2",
3029
"magic-string": "^0.22.3",
3130
"source-map": "^0.5.6"
3231
},
3332
"peerDependencies": {
33+
"enhanced-resolve": "^3.1.0",
3434
"typescript": "^2.0.2",
3535
"webpack": "^2.2.0 || ^3.0.0"
3636
}

packages/@ngtools/webpack/src/compiler_host.ts

Lines changed: 38 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -152,19 +152,49 @@ export class WebpackCompilerHost implements ts.CompilerHost {
152152
return;
153153
}
154154

155+
/**
156+
* storageDataSetter is a temporary hack to address these two issues:
157+
* - https://github.com/angular/angular-cli/issues/7113
158+
* - https://github.com/angular/angular-cli/issues/7136
159+
*
160+
* This way we set values correctly in both a Map (enhanced-resove>=3.4.0) and
161+
* object (enhanced-resolve >= 3.1.0 <3.4.0).
162+
*
163+
* The right solution is to create a virtual filesystem by decorating the filesystem,
164+
* instead of injecting data into the private cache of the filesystem.
165+
*
166+
* Doing it the right way should fix other related bugs, but meanwhile we hack it since:
167+
* - it's affecting a lot of users.
168+
* - the real solution is non-trivial.
169+
*/
170+
function storageDataSetter(data: Map<string, any> | {[k: string]: any}, k: string, v: any) {
171+
172+
if (data instanceof Map) {
173+
data.set(k, v);
174+
} else {
175+
data[k] = v;
176+
}
177+
}
178+
179+
180+
155181
const isWindows = process.platform.startsWith('win');
156182
for (const fileName of this.getChangedFilePaths()) {
157183
const stats = this._files[fileName];
158184
if (stats) {
159185
// If we're on windows, we need to populate with the proper path separator.
160186
const path = isWindows ? fileName.replace(/\//g, '\\') : fileName;
161-
fs._statStorage.data[path] = [null, stats];
162-
fs._readFileStorage.data[path] = [null, stats.content];
187+
// fs._statStorage.data[path] = [null, stats];
188+
// fs._readFileStorage.data[path] = [null, stats.content];
189+
storageDataSetter(fs._statStorage.data, path, [null, stats]);
190+
storageDataSetter(fs._readFileStorage.data, path, [null, stats.content]);
163191
} else {
164192
// Support removing files as well.
165193
const path = isWindows ? fileName.replace(/\//g, '\\') : fileName;
166-
fs._statStorage.data[path] = [new Error(), null];
167-
fs._readFileStorage.data[path] = [new Error(), null];
194+
// fs._statStorage.data[path] = [new Error(), null];
195+
// fs._readFileStorage.data[path] = [new Error(), null];
196+
storageDataSetter(fs._statStorage.data, path, [new Error(), null]);
197+
storageDataSetter(fs._readFileStorage.data, path, [new Error(), null]);
168198
}
169199
}
170200
for (const dirName of Object.keys(this._changedDirs)) {
@@ -173,8 +203,10 @@ export class WebpackCompilerHost implements ts.CompilerHost {
173203
const files = this.getFiles(dirName);
174204
// If we're on windows, we need to populate with the proper path separator.
175205
const path = isWindows ? dirName.replace(/\//g, '\\') : dirName;
176-
fs._statStorage.data[path] = [null, stats];
177-
fs._readdirStorage.data[path] = [null, files.concat(dirs)];
206+
// fs._statStorage.data[path] = [null, stats];
207+
// fs._readdirStorage.data[path] = [null, files.concat(dirs)];
208+
storageDataSetter(fs._statStorage.data, path, [null, stats]);
209+
storageDataSetter(fs._readFileStorage.data, path, [null, files.concat(dirs)]);
178210
}
179211
}
180212

0 commit comments

Comments
 (0)