@ngtools/webpack 14.0.0-next.9 → 14.0.0-rc.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 +4 -4
- package/src/ivy/host.js +6 -4
- package/src/ivy/plugin.d.ts +1 -0
- package/src/ivy/plugin.js +3 -2
- package/src/paths-plugin.js +45 -18
- package/src/resource_loader.js +6 -4
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@ngtools/webpack",
|
|
3
|
-
"version": "14.0.0-
|
|
3
|
+
"version": "14.0.0-rc.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",
|
|
@@ -26,9 +26,9 @@
|
|
|
26
26
|
"homepage": "https://github.com/angular/angular-cli",
|
|
27
27
|
"dependencies": {},
|
|
28
28
|
"peerDependencies": {
|
|
29
|
-
"@angular/compiler-cli": "^14.0.0 || ^14.0.0-
|
|
30
|
-
"typescript": "
|
|
31
|
-
"webpack": "^5.
|
|
29
|
+
"@angular/compiler-cli": "^14.0.0 || ^14.0.0-rc",
|
|
30
|
+
"typescript": ">=4.6.2 <4.8",
|
|
31
|
+
"webpack": "^5.54.0"
|
|
32
32
|
},
|
|
33
33
|
"engines": {
|
|
34
34
|
"node": "^14.15.0 || >=16.10.0",
|
package/src/ivy/host.js
CHANGED
|
@@ -155,9 +155,10 @@ function augmentHostWithNgcc(host, ngcc, moduleResolutionCache) {
|
|
|
155
155
|
const baseResolveTypeReferenceDirectives = host.resolveTypeReferenceDirectives;
|
|
156
156
|
host.resolveTypeReferenceDirectives = function (names, ...parameters) {
|
|
157
157
|
return names.map((name) => {
|
|
158
|
-
const
|
|
158
|
+
const fileName = typeof name === 'string' ? name : name.fileName;
|
|
159
|
+
const result = baseResolveTypeReferenceDirectives.call(host, [fileName], ...parameters);
|
|
159
160
|
if (result[0] && ngcc) {
|
|
160
|
-
ngcc.processModule(
|
|
161
|
+
ngcc.processModule(fileName, result[0]);
|
|
161
162
|
}
|
|
162
163
|
return result[0];
|
|
163
164
|
});
|
|
@@ -166,9 +167,10 @@ function augmentHostWithNgcc(host, ngcc, moduleResolutionCache) {
|
|
|
166
167
|
else {
|
|
167
168
|
host.resolveTypeReferenceDirectives = function (moduleNames, containingFile, redirectedReference, options) {
|
|
168
169
|
return moduleNames.map((name) => {
|
|
169
|
-
const
|
|
170
|
+
const fileName = typeof name === 'string' ? name : name.fileName;
|
|
171
|
+
const result = ts.resolveTypeReferenceDirective(fileName, containingFile, options, host, redirectedReference).resolvedTypeReferenceDirective;
|
|
170
172
|
if (result && ngcc) {
|
|
171
|
-
ngcc.processModule(
|
|
173
|
+
ngcc.processModule(fileName, result);
|
|
172
174
|
}
|
|
173
175
|
return result;
|
|
174
176
|
});
|
package/src/ivy/plugin.d.ts
CHANGED
|
@@ -27,6 +27,7 @@ export declare class AngularWebpackPlugin {
|
|
|
27
27
|
private builder?;
|
|
28
28
|
private sourceFileCache?;
|
|
29
29
|
private webpackCache?;
|
|
30
|
+
private webpackCreateHash?;
|
|
30
31
|
private readonly fileDependencies;
|
|
31
32
|
private readonly requiredFilesToEmit;
|
|
32
33
|
private readonly requiredFilesToEmitCache;
|
package/src/ivy/plugin.js
CHANGED
|
@@ -32,7 +32,6 @@ var __importStar = (this && this.__importStar) || function (mod) {
|
|
|
32
32
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
33
33
|
exports.AngularWebpackPlugin = void 0;
|
|
34
34
|
const assert_1 = require("assert");
|
|
35
|
-
const crypto_1 = require("crypto");
|
|
36
35
|
const ts = __importStar(require("typescript"));
|
|
37
36
|
const ngcc_processor_1 = require("../ngcc_processor");
|
|
38
37
|
const paths_plugin_1 = require("../paths-plugin");
|
|
@@ -101,6 +100,7 @@ class AngularWebpackPlugin {
|
|
|
101
100
|
// eslint-disable-next-line max-lines-per-function
|
|
102
101
|
apply(compiler) {
|
|
103
102
|
const { NormalModuleReplacementPlugin, util } = compiler.webpack;
|
|
103
|
+
this.webpackCreateHash = util.createHash;
|
|
104
104
|
// Setup file replacements with webpack
|
|
105
105
|
for (const [key, value] of Object.entries(this.pluginOptions.fileReplacements)) {
|
|
106
106
|
new NormalModuleReplacementPlugin(new RegExp('^' + key.replace(/[.*+\-?^${}()|[\]\\]/g, '\\$&') + '$'), value).apply(compiler);
|
|
@@ -533,9 +533,10 @@ class AngularWebpackPlugin {
|
|
|
533
533
|
this.compilerNgccModule = await new Function(`return import('@angular/compiler-cli/ngcc');`)();
|
|
534
534
|
}
|
|
535
535
|
async addFileEmitHistory(filePath, content) {
|
|
536
|
+
assert_1.strict.ok(this.webpackCreateHash, 'File emitter is used prior to Webpack compilation');
|
|
536
537
|
const historyData = {
|
|
537
538
|
length: content.length,
|
|
538
|
-
hash:
|
|
539
|
+
hash: this.webpackCreateHash('xxhash64').update(content).digest(),
|
|
539
540
|
};
|
|
540
541
|
if (this.webpackCache) {
|
|
541
542
|
const history = await this.getFileEmitHistory(filePath);
|
package/src/paths-plugin.js
CHANGED
|
@@ -105,6 +105,7 @@ class TypeScriptPathsPlugin {
|
|
|
105
105
|
resolver.getHook('described-resolve').tapAsync('TypeScriptPathsPlugin',
|
|
106
106
|
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
107
107
|
(request, resolveContext, callback) => {
|
|
108
|
+
var _a;
|
|
108
109
|
// Preprocessing of the options will ensure that `patterns` is either undefined or has elements to check
|
|
109
110
|
if (!this.patterns) {
|
|
110
111
|
callback();
|
|
@@ -142,33 +143,59 @@ class TypeScriptPathsPlugin {
|
|
|
142
143
|
// For example, if the first one resolves, any others are not needed and do not need
|
|
143
144
|
// to be created.
|
|
144
145
|
const replacements = findReplacements(originalRequest, this.patterns);
|
|
145
|
-
const
|
|
146
|
-
|
|
146
|
+
const basePath = (_a = this.baseUrl) !== null && _a !== void 0 ? _a : '';
|
|
147
|
+
const attemptResolveRequest = (request) => {
|
|
148
|
+
return new Promise((resolve, reject) => {
|
|
149
|
+
resolver.doResolve(target, request, '', resolveContext, (error, result) => {
|
|
150
|
+
if (error) {
|
|
151
|
+
reject(error);
|
|
152
|
+
}
|
|
153
|
+
else if (result) {
|
|
154
|
+
resolve(result);
|
|
155
|
+
}
|
|
156
|
+
else {
|
|
157
|
+
resolve(null);
|
|
158
|
+
}
|
|
159
|
+
});
|
|
160
|
+
});
|
|
161
|
+
};
|
|
162
|
+
const tryNextReplacement = () => {
|
|
147
163
|
const next = replacements.next();
|
|
148
164
|
if (next.done) {
|
|
149
165
|
callback();
|
|
150
166
|
return;
|
|
151
167
|
}
|
|
152
|
-
const
|
|
168
|
+
const targetPath = path.resolve(basePath, next.value);
|
|
169
|
+
// If there is no extension. i.e. the target does not refer to an explicit
|
|
170
|
+
// file, then this is a candidate for module/package resolution.
|
|
171
|
+
const canBeModule = path.extname(targetPath) === '';
|
|
172
|
+
// Resolution in the target location, preserving the original request.
|
|
173
|
+
// This will work with the `resolve-in-package` resolution hook, supporting
|
|
174
|
+
// package exports for e.g. locally-built APF libraries.
|
|
175
|
+
const potentialRequestAsPackage = {
|
|
153
176
|
...request,
|
|
154
|
-
|
|
177
|
+
path: targetPath,
|
|
155
178
|
typescriptPathMapped: true,
|
|
156
179
|
};
|
|
157
|
-
|
|
158
|
-
//
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
}
|
|
180
|
+
// Resolution in the original callee location, but with the updated request
|
|
181
|
+
// to point to the mapped target location.
|
|
182
|
+
const potentialRequestAsFile = {
|
|
183
|
+
...request,
|
|
184
|
+
request: targetPath,
|
|
185
|
+
typescriptPathMapped: true,
|
|
186
|
+
};
|
|
187
|
+
let resultPromise = attemptResolveRequest(potentialRequestAsFile);
|
|
188
|
+
// If the request can be a module, we configure the resolution to try package/module
|
|
189
|
+
// resolution if the file resolution did not have a result.
|
|
190
|
+
if (canBeModule) {
|
|
191
|
+
resultPromise = resultPromise.then((result) => result !== null && result !== void 0 ? result : attemptResolveRequest(potentialRequestAsPackage));
|
|
192
|
+
}
|
|
193
|
+
// If we have a result, complete. If not, and no error, try the next replacement.
|
|
194
|
+
resultPromise
|
|
195
|
+
.then((res) => (res === null ? tryNextReplacement() : callback(undefined, res)))
|
|
196
|
+
.catch((error) => callback(error));
|
|
170
197
|
};
|
|
171
|
-
|
|
198
|
+
tryNextReplacement();
|
|
172
199
|
});
|
|
173
200
|
}
|
|
174
201
|
}
|
package/src/resource_loader.js
CHANGED
|
@@ -31,7 +31,6 @@ var __importStar = (this && this.__importStar) || function (mod) {
|
|
|
31
31
|
};
|
|
32
32
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
33
33
|
exports.WebpackResourceLoader = void 0;
|
|
34
|
-
const crypto_1 = require("crypto");
|
|
35
34
|
const path = __importStar(require("path"));
|
|
36
35
|
const vm = __importStar(require("vm"));
|
|
37
36
|
const paths_1 = require("./ivy/paths");
|
|
@@ -94,10 +93,13 @@ class WebpackResourceLoader {
|
|
|
94
93
|
setAffectedResources(file, resources) {
|
|
95
94
|
this._reverseDependencies.set(file, new Set(resources));
|
|
96
95
|
}
|
|
96
|
+
// eslint-disable-next-line max-lines-per-function
|
|
97
97
|
async _compile(filePath, data, fileExtension, resourceType, containingFile) {
|
|
98
98
|
if (!this._parentCompilation) {
|
|
99
99
|
throw new Error('WebpackResourceLoader cannot be used without parentCompilation');
|
|
100
100
|
}
|
|
101
|
+
const { context, webpack } = this._parentCompilation.compiler;
|
|
102
|
+
const { EntryPlugin, NormalModule, library, node, sources, util: { createHash }, } = webpack;
|
|
101
103
|
const getEntry = () => {
|
|
102
104
|
if (filePath) {
|
|
103
105
|
return `${filePath}?${replace_resources_1.NG_COMPONENT_RESOURCE_QUERY}`;
|
|
@@ -110,7 +112,9 @@ class WebpackResourceLoader {
|
|
|
110
112
|
}
|
|
111
113
|
else if (data) {
|
|
112
114
|
// Create a special URL for reading the resource from memory
|
|
113
|
-
return `angular-resource:${resourceType},${
|
|
115
|
+
return `angular-resource:${resourceType},${createHash('xxhash64')
|
|
116
|
+
.update(data)
|
|
117
|
+
.digest('hex')}`;
|
|
114
118
|
}
|
|
115
119
|
throw new Error(`"filePath", "resourceType" or "data" must be specified.`);
|
|
116
120
|
};
|
|
@@ -128,8 +132,6 @@ class WebpackResourceLoader {
|
|
|
128
132
|
name: 'resource',
|
|
129
133
|
},
|
|
130
134
|
};
|
|
131
|
-
const { context, webpack } = this._parentCompilation.compiler;
|
|
132
|
-
const { EntryPlugin, NormalModule, library, node, sources } = webpack;
|
|
133
135
|
const childCompiler = this._parentCompilation.createChildCompiler('angular-compiler:resource', outputOptions, [
|
|
134
136
|
new node.NodeTemplatePlugin(outputOptions),
|
|
135
137
|
new node.NodeTargetPlugin(),
|