Skip to content

Commit db34f58

Browse files
committed
fix(@ngtools/webpack): support [email protected]
Followup to angular#7123
1 parent 3f4722e commit db34f58

File tree

4 files changed

+53
-12
lines changed

4 files changed

+53
-12
lines changed

package.json

+1-1
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",

packages/@ngtools/webpack/package.json

+1-1
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

+38-6
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

yarn.lock

+13-4
Original file line numberDiff line numberDiff line change
@@ -1571,7 +1571,7 @@ encodeurl@~1.0.1:
15711571
version "1.0.1"
15721572
resolved "https://registry.yarnpkg.com/encodeurl/-/encodeurl-1.0.1.tgz#79e3d58655346909fe6f0f45a5de68103b294d20"
15731573

1574-
[email protected], enhanced-resolve@^3.3.0:
1574+
15751575
version "3.3.0"
15761576
resolved "https://registry.yarnpkg.com/enhanced-resolve/-/enhanced-resolve-3.3.0.tgz#950964ecc7f0332a42321b673b38dc8ff15535b3"
15771577
dependencies:
@@ -1580,6 +1580,15 @@ [email protected], enhanced-resolve@^3.3.0:
15801580
object-assign "^4.0.1"
15811581
tapable "^0.2.5"
15821582

1583+
enhanced-resolve@^3.3.0:
1584+
version "3.4.1"
1585+
resolved "https://registry.yarnpkg.com/enhanced-resolve/-/enhanced-resolve-3.4.1.tgz#0421e339fd71419b3da13d129b3979040230476e"
1586+
dependencies:
1587+
graceful-fs "^4.1.2"
1588+
memory-fs "^0.4.0"
1589+
object-assign "^4.0.1"
1590+
tapable "^0.2.7"
1591+
15831592
ensure-posix-path@^1.0.0:
15841593
version "1.0.2"
15851594
resolved "https://registry.yarnpkg.com/ensure-posix-path/-/ensure-posix-path-1.0.2.tgz#a65b3e42d0b71cfc585eb774f9943c8d9b91b0c2"
@@ -5083,9 +5092,9 @@ table@^3.7.8:
50835092
slice-ansi "0.0.4"
50845093
string-width "^2.0.0"
50855094

5086-
tapable@^0.2.5, tapable@~0.2.5:
5087-
version "0.2.6"
5088-
resolved "https://registry.yarnpkg.com/tapable/-/tapable-0.2.6.tgz#206be8e188860b514425375e6f1ae89bfb01fd8d"
5095+
tapable@^0.2.5, tapable@^0.2.7, tapable@~0.2.5:
5096+
version "0.2.7"
5097+
resolved "https://registry.yarnpkg.com/tapable/-/tapable-0.2.7.tgz#e46c0daacbb2b8a98b9b0cea0f4052105817ed5c"
50895098

50905099
tar-pack@^3.4.0:
50915100
version "3.4.0"

0 commit comments

Comments
 (0)