@ngtools/webpack 8.1.0-beta.3 → 8.1.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/package.json +3 -4
- package/src/benchmark.js +1 -0
- package/src/compiler_host.js +29 -24
- package/src/ngcc_processor.js +5 -10
- package/src/transformers/ctor-parameters.js +15 -4
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@ngtools/webpack",
|
|
3
|
-
"version": "8.1.
|
|
3
|
+
"version": "8.1.2",
|
|
4
4
|
"description": "Webpack plugin that AoT compiles your Angular components and modules.",
|
|
5
5
|
"main": "./src/index.js",
|
|
6
6
|
"typings": "src/index.d.ts",
|
|
@@ -25,14 +25,14 @@
|
|
|
25
25
|
},
|
|
26
26
|
"homepage": "https://github.com/angular/angular-cli",
|
|
27
27
|
"dependencies": {
|
|
28
|
-
"@angular-devkit/core": "8.1.
|
|
28
|
+
"@angular-devkit/core": "8.1.2",
|
|
29
29
|
"enhanced-resolve": "4.1.0",
|
|
30
30
|
"rxjs": "6.4.0",
|
|
31
31
|
"tree-kill": "1.2.1",
|
|
32
32
|
"webpack-sources": "1.3.0"
|
|
33
33
|
},
|
|
34
34
|
"peerDependencies": {
|
|
35
|
-
"@angular/compiler-cli": "
|
|
35
|
+
"@angular/compiler-cli": "^8.0.0-beta.0 || ^8.1.0-beta.0 || ^8.2.0-beta.0 || ^8.3.0-beta.0 || ^8.4.0-beta.0 || >=9.0.0-beta < 9",
|
|
36
36
|
"typescript": ">=3.4 < 3.5",
|
|
37
37
|
"webpack": "^4.0.0"
|
|
38
38
|
},
|
|
@@ -42,7 +42,6 @@
|
|
|
42
42
|
},
|
|
43
43
|
"husky": {
|
|
44
44
|
"hooks": {
|
|
45
|
-
"pre-commit": "lint-staged",
|
|
46
45
|
"pre-push": "node ./bin/devkit-admin hooks/pre-push"
|
|
47
46
|
}
|
|
48
47
|
}
|
package/src/benchmark.js
CHANGED
|
@@ -11,6 +11,7 @@ Object.defineProperty(exports, "__esModule", { value: true });
|
|
|
11
11
|
// Use with CLI --no-progress flag for best results.
|
|
12
12
|
// This should be false for commited code.
|
|
13
13
|
const _benchmark = false;
|
|
14
|
+
// tslint:disable:no-console
|
|
14
15
|
function time(label) {
|
|
15
16
|
if (_benchmark) {
|
|
16
17
|
console.time(label);
|
package/src/compiler_host.js
CHANGED
|
@@ -22,9 +22,12 @@ class WebpackCompilerHost {
|
|
|
22
22
|
this._readResourceFiles = new Set();
|
|
23
23
|
this._sourceFileCache = new Map();
|
|
24
24
|
this._virtualFileExtensions = [
|
|
25
|
-
'.js',
|
|
26
|
-
'.
|
|
27
|
-
'.
|
|
25
|
+
'.js',
|
|
26
|
+
'.js.map',
|
|
27
|
+
'.ngfactory.js',
|
|
28
|
+
'.ngfactory.js.map',
|
|
29
|
+
'.ngstyle.js',
|
|
30
|
+
'.ngstyle.js.map',
|
|
28
31
|
'.ngsummary.json',
|
|
29
32
|
];
|
|
30
33
|
this._syncHost = new core_1.virtualFs.SyncDelegateHost(host);
|
|
@@ -32,8 +35,7 @@ class WebpackCompilerHost {
|
|
|
32
35
|
this._basePath = core_1.normalize(basePath);
|
|
33
36
|
}
|
|
34
37
|
get virtualFiles() {
|
|
35
|
-
return [...this._memoryHost.delegate
|
|
36
|
-
._cache.keys()];
|
|
38
|
+
return [...this._memoryHost.delegate._cache.keys()];
|
|
37
39
|
}
|
|
38
40
|
denormalizePath(path) {
|
|
39
41
|
return core_1.getSystemPath(core_1.normalize(path));
|
|
@@ -54,10 +56,10 @@ class WebpackCompilerHost {
|
|
|
54
56
|
return [...this._changedFiles];
|
|
55
57
|
}
|
|
56
58
|
getNgFactoryPaths() {
|
|
57
|
-
return this.virtualFiles
|
|
59
|
+
return (this.virtualFiles
|
|
58
60
|
.filter(fileName => fileName.endsWith('.ngfactory.js') || fileName.endsWith('.ngstyle.js'))
|
|
59
61
|
// These paths are used by the virtual file system decorator so we must denormalize them.
|
|
60
|
-
.map(path => this.denormalizePath(path));
|
|
62
|
+
.map(path => this.denormalizePath(path)));
|
|
61
63
|
}
|
|
62
64
|
invalidate(fileName) {
|
|
63
65
|
const fullPath = this.resolve(fileName);
|
|
@@ -66,13 +68,15 @@ class WebpackCompilerHost {
|
|
|
66
68
|
try {
|
|
67
69
|
exists = this._syncHost.isFile(fullPath);
|
|
68
70
|
if (exists) {
|
|
69
|
-
this._changedFiles.add(fullPath);
|
|
71
|
+
this._changedFiles.add(utils_1.workaroundResolve(fullPath));
|
|
70
72
|
}
|
|
71
73
|
}
|
|
72
74
|
catch (_a) { }
|
|
73
75
|
// File doesn't exist anymore and is not a factory, so we should delete the related
|
|
74
76
|
// virtual files.
|
|
75
|
-
if (!exists &&
|
|
77
|
+
if (!exists &&
|
|
78
|
+
fullPath.endsWith('.ts') &&
|
|
79
|
+
!(fullPath.endsWith('.ngfactory.ts') || fullPath.endsWith('.shim.ngstyle.ts'))) {
|
|
76
80
|
this._virtualFileExtensions.forEach(ext => {
|
|
77
81
|
const virtualFile = (fullPath.slice(0, -3) + ext);
|
|
78
82
|
if (this._memoryHost.exists(virtualFile)) {
|
|
@@ -82,8 +86,8 @@ class WebpackCompilerHost {
|
|
|
82
86
|
}
|
|
83
87
|
// In case resolveJsonModule and allowJs we also need to remove virtual emitted files
|
|
84
88
|
// both if they exists or not.
|
|
85
|
-
if ((fullPath.endsWith('.js') || fullPath.endsWith('.json'))
|
|
86
|
-
|
|
89
|
+
if ((fullPath.endsWith('.js') || fullPath.endsWith('.json')) &&
|
|
90
|
+
!/(\.(ngfactory|ngstyle)\.js|ngsummary\.json)$/.test(fullPath)) {
|
|
87
91
|
if (this._memoryHost.exists(fullPath)) {
|
|
88
92
|
this._memoryHost.delete(fullPath);
|
|
89
93
|
}
|
|
@@ -135,11 +139,11 @@ class WebpackCompilerHost {
|
|
|
135
139
|
return {
|
|
136
140
|
isFile: () => stats.isFile(),
|
|
137
141
|
isDirectory: () => stats.isDirectory(),
|
|
138
|
-
isBlockDevice: () => stats.isBlockDevice && stats.isBlockDevice() || false,
|
|
139
|
-
isCharacterDevice: () => stats.isCharacterDevice && stats.isCharacterDevice() || false,
|
|
140
|
-
isFIFO: () => stats.isFIFO && stats.isFIFO() || false,
|
|
141
|
-
isSymbolicLink: () => stats.isSymbolicLink && stats.isSymbolicLink() || false,
|
|
142
|
-
isSocket: () => stats.isSocket && stats.isSocket() || false,
|
|
142
|
+
isBlockDevice: () => (stats.isBlockDevice && stats.isBlockDevice()) || false,
|
|
143
|
+
isCharacterDevice: () => (stats.isCharacterDevice && stats.isCharacterDevice()) || false,
|
|
144
|
+
isFIFO: () => (stats.isFIFO && stats.isFIFO()) || false,
|
|
145
|
+
isSymbolicLink: () => (stats.isSymbolicLink && stats.isSymbolicLink()) || false,
|
|
146
|
+
isSocket: () => (stats.isSocket && stats.isSocket()) || false,
|
|
143
147
|
dev: stats.dev === undefined ? dev : stats.dev,
|
|
144
148
|
ino: stats.ino === undefined ? Math.floor(Math.random() * 100000) : stats.ino,
|
|
145
149
|
mode: stats.mode === undefined ? parseInt('777', 8) : stats.mode,
|
|
@@ -274,14 +278,13 @@ class WebpackCompilerHost {
|
|
|
274
278
|
this._resourceLoader = resourceLoader;
|
|
275
279
|
}
|
|
276
280
|
readResource(fileName) {
|
|
277
|
-
|
|
278
|
-
|
|
279
|
-
|
|
281
|
+
// These paths are meant to be used by the loader so we must denormalize them
|
|
282
|
+
const denormalizedFileName = utils_1.workaroundResolve(fileName);
|
|
283
|
+
this._readResourceFiles.add(denormalizedFileName);
|
|
284
|
+
if (this.directTemplateLoading && (fileName.endsWith('.html') || fileName.endsWith('.svg'))) {
|
|
280
285
|
return this.readFile(fileName);
|
|
281
286
|
}
|
|
282
287
|
if (this._resourceLoader) {
|
|
283
|
-
// These paths are meant to be used by the loader so we must denormalize them.
|
|
284
|
-
const denormalizedFileName = this.denormalizePath(core_1.normalize(fileName));
|
|
285
288
|
return this._resourceLoader.get(denormalizedFileName);
|
|
286
289
|
}
|
|
287
290
|
else {
|
|
@@ -291,19 +294,21 @@ class WebpackCompilerHost {
|
|
|
291
294
|
getModifiedResourceFiles() {
|
|
292
295
|
const modifiedFiles = new Set();
|
|
293
296
|
for (const changedFile of this._changedFiles) {
|
|
294
|
-
|
|
295
|
-
|
|
297
|
+
const denormalizedFileName = utils_1.workaroundResolve(changedFile);
|
|
298
|
+
if (this._readResourceFiles.has(denormalizedFileName)) {
|
|
299
|
+
modifiedFiles.add(denormalizedFileName);
|
|
296
300
|
}
|
|
297
301
|
if (!this._resourceLoader) {
|
|
298
302
|
continue;
|
|
299
303
|
}
|
|
300
|
-
for (const resourcePath of this._resourceLoader.getAffectedResources(
|
|
304
|
+
for (const resourcePath of this._resourceLoader.getAffectedResources(denormalizedFileName)) {
|
|
301
305
|
modifiedFiles.add(resourcePath);
|
|
302
306
|
}
|
|
303
307
|
}
|
|
304
308
|
return modifiedFiles;
|
|
305
309
|
}
|
|
306
310
|
trace(message) {
|
|
311
|
+
// tslint:disable-next-line: no-console
|
|
307
312
|
console.log(message);
|
|
308
313
|
}
|
|
309
314
|
resolveModuleNames(moduleNames, containingFile) {
|
package/src/ngcc_processor.js
CHANGED
|
@@ -39,9 +39,7 @@ class NgccProcessor {
|
|
|
39
39
|
}
|
|
40
40
|
processModule(moduleName, resolvedModule) {
|
|
41
41
|
const resolvedFileName = resolvedModule.resolvedFileName;
|
|
42
|
-
if (!resolvedFileName
|
|
43
|
-
|| moduleName.startsWith('.')
|
|
44
|
-
|| this._processedModules.has(moduleName)) {
|
|
42
|
+
if (!resolvedFileName || moduleName.startsWith('.') || this._processedModules.has(moduleName)) {
|
|
45
43
|
// Skip when module is unknown, relative or NGCC compiler is not found or already processed.
|
|
46
44
|
return;
|
|
47
45
|
}
|
|
@@ -74,22 +72,19 @@ class NgccProcessor {
|
|
|
74
72
|
*/
|
|
75
73
|
tryResolvePackage(moduleName, resolvedFileName) {
|
|
76
74
|
try {
|
|
77
|
-
let packageJsonPath = path.resolve(resolvedFileName, '../package.json');
|
|
78
|
-
if (fs_1.existsSync(packageJsonPath)) {
|
|
79
|
-
return packageJsonPath;
|
|
80
|
-
}
|
|
81
75
|
// This is based on the logic in the NGCC compiler
|
|
82
76
|
// tslint:disable-next-line:max-line-length
|
|
83
77
|
// See: https://github.com/angular/angular/blob/b93c1dffa17e4e6900b3ab1b9e554b6da92be0de/packages/compiler-cli/src/ngcc/src/packages/dependency_host.ts#L85-L121
|
|
84
|
-
|
|
78
|
+
return require.resolve(`${moduleName}/package.json`, {
|
|
85
79
|
paths: [resolvedFileName],
|
|
86
80
|
});
|
|
87
|
-
return packageJsonPath;
|
|
88
81
|
}
|
|
89
82
|
catch (_a) {
|
|
90
83
|
// if it fails this might be a deep import which doesn't have a package.json
|
|
91
84
|
// Ex: @angular/compiler/src/i18n/i18n_ast/package.json
|
|
92
|
-
|
|
85
|
+
// or local libraries which don't reside in node_modules
|
|
86
|
+
const packageJsonPath = path.resolve(resolvedFileName, '../package.json');
|
|
87
|
+
return fs_1.existsSync(packageJsonPath) ? packageJsonPath : undefined;
|
|
93
88
|
}
|
|
94
89
|
}
|
|
95
90
|
findNodeModulesDirectory(startPoint) {
|
|
@@ -75,7 +75,7 @@ function extractMetadataFromSingleDecorator(decorator, diagnostics) {
|
|
|
75
75
|
* }]
|
|
76
76
|
* }];
|
|
77
77
|
*/
|
|
78
|
-
function createCtorParametersClassProperty(diagnostics, entityNameToExpression, ctorParameters) {
|
|
78
|
+
function createCtorParametersClassProperty(diagnostics, entityNameToExpression, ctorParameters, typeChecker) {
|
|
79
79
|
const params = [];
|
|
80
80
|
for (const ctorParam of ctorParameters) {
|
|
81
81
|
if (!ctorParam.type && ctorParam.decorators.length === 0) {
|
|
@@ -83,7 +83,7 @@ function createCtorParametersClassProperty(diagnostics, entityNameToExpression,
|
|
|
83
83
|
continue;
|
|
84
84
|
}
|
|
85
85
|
const paramType = ctorParam.type
|
|
86
|
-
? typeReferenceToExpression(entityNameToExpression, ctorParam.type)
|
|
86
|
+
? typeReferenceToExpression(entityNameToExpression, ctorParam.type, typeChecker)
|
|
87
87
|
: undefined;
|
|
88
88
|
const members = [
|
|
89
89
|
ts.createPropertyAssignment('type', paramType || ts.createIdentifier('undefined')),
|
|
@@ -109,7 +109,7 @@ function createCtorParametersClassProperty(diagnostics, entityNameToExpression,
|
|
|
109
109
|
* not being exposed). In practice this implementation is sufficient for Angular's use of type
|
|
110
110
|
* metadata.
|
|
111
111
|
*/
|
|
112
|
-
function typeReferenceToExpression(entityNameToExpression, node) {
|
|
112
|
+
function typeReferenceToExpression(entityNameToExpression, node, typeChecker) {
|
|
113
113
|
let kind = node.kind;
|
|
114
114
|
if (ts.isLiteralTypeNode(node)) {
|
|
115
115
|
// Treat literal types like their base type (boolean, string, number).
|
|
@@ -137,6 +137,17 @@ function typeReferenceToExpression(entityNameToExpression, node) {
|
|
|
137
137
|
return ts.createIdentifier('Number');
|
|
138
138
|
case ts.SyntaxKind.TypeReference:
|
|
139
139
|
const typeRef = node;
|
|
140
|
+
let typeSymbol = typeChecker.getSymbolAtLocation(typeRef.typeName);
|
|
141
|
+
if (typeSymbol && typeSymbol.flags & ts.SymbolFlags.Alias) {
|
|
142
|
+
typeSymbol = typeChecker.getAliasedSymbol(typeSymbol);
|
|
143
|
+
}
|
|
144
|
+
if (!typeSymbol || !(typeSymbol.flags & ts.SymbolFlags.Value)) {
|
|
145
|
+
return undefined;
|
|
146
|
+
}
|
|
147
|
+
const type = typeChecker.getTypeOfSymbolAtLocation(typeSymbol, typeRef);
|
|
148
|
+
if (!type || typeChecker.getSignaturesOfType(type, ts.SignatureKind.Construct).length === 0) {
|
|
149
|
+
return undefined;
|
|
150
|
+
}
|
|
140
151
|
// Ignore any generic types, just return the base type.
|
|
141
152
|
return entityNameToExpression(typeRef.typeName);
|
|
142
153
|
default:
|
|
@@ -197,7 +208,7 @@ function decoratorDownlevelTransformer(typeChecker, diagnostics) {
|
|
|
197
208
|
parametersInfo.push(paramInfo);
|
|
198
209
|
}
|
|
199
210
|
if (parametersInfo.length > 0) {
|
|
200
|
-
const ctorProperty = createCtorParametersClassProperty(diagnostics, entityNameToExpression, parametersInfo);
|
|
211
|
+
const ctorProperty = createCtorParametersClassProperty(diagnostics, entityNameToExpression, parametersInfo, typeChecker);
|
|
201
212
|
return [node, ctorProperty];
|
|
202
213
|
}
|
|
203
214
|
else {
|