@ngtools/webpack 14.0.3 → 14.1.0-next.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 +2 -2
- package/src/paths-plugin.d.ts +10 -2
- package/src/paths-plugin.js +88 -93
- package/src/resource_loader.js +7 -2
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@ngtools/webpack",
|
|
3
|
-
"version": "14.0.
|
|
3
|
+
"version": "14.1.0-next.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,7 +26,7 @@
|
|
|
26
26
|
"homepage": "https://github.com/angular/angular-cli",
|
|
27
27
|
"dependencies": {},
|
|
28
28
|
"peerDependencies": {
|
|
29
|
-
"@angular/compiler-cli": "^14.0.0",
|
|
29
|
+
"@angular/compiler-cli": "^14.0.0 || ^14.0.0-next || ^14.1.0-next",
|
|
30
30
|
"typescript": ">=4.6.2 <4.8",
|
|
31
31
|
"webpack": "^5.54.0"
|
|
32
32
|
},
|
package/src/paths-plugin.d.ts
CHANGED
|
@@ -6,10 +6,16 @@
|
|
|
6
6
|
* found in the LICENSE file at https://angular.io/license
|
|
7
7
|
*/
|
|
8
8
|
import { CompilerOptions } from 'typescript';
|
|
9
|
-
import type {
|
|
9
|
+
import type { Resolver } from 'webpack';
|
|
10
10
|
export interface TypeScriptPathsPluginOptions extends Pick<CompilerOptions, 'paths' | 'baseUrl'> {
|
|
11
11
|
}
|
|
12
|
-
declare type
|
|
12
|
+
declare type ResolverRequest = NonNullable<Parameters<Parameters<Resolver['resolve']>[4]>[2]>;
|
|
13
|
+
interface PathPluginResolverRequest extends ResolverRequest {
|
|
14
|
+
context?: {
|
|
15
|
+
issuer?: string;
|
|
16
|
+
};
|
|
17
|
+
typescriptPathMapped?: boolean;
|
|
18
|
+
}
|
|
13
19
|
export declare class TypeScriptPathsPlugin {
|
|
14
20
|
private baseUrl?;
|
|
15
21
|
private patterns?;
|
|
@@ -23,5 +29,7 @@ export declare class TypeScriptPathsPlugin {
|
|
|
23
29
|
*/
|
|
24
30
|
update(options: TypeScriptPathsPluginOptions): void;
|
|
25
31
|
apply(resolver: Resolver): void;
|
|
32
|
+
findReplacements(originalRequest: string): IterableIterator<string>;
|
|
33
|
+
createReplacementRequests(request: PathPluginResolverRequest, originalRequest: string): IterableIterator<PathPluginResolverRequest>;
|
|
26
34
|
}
|
|
27
35
|
export {};
|
package/src/paths-plugin.js
CHANGED
|
@@ -102,10 +102,10 @@ class TypeScriptPathsPlugin {
|
|
|
102
102
|
const target = resolver.ensureHook('resolve');
|
|
103
103
|
// To support synchronous resolvers this hook cannot be promise based.
|
|
104
104
|
// Webpack supports synchronous resolution with `tap` and `tapAsync` hooks.
|
|
105
|
-
resolver
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
var _a;
|
|
105
|
+
resolver
|
|
106
|
+
.getHook('described-resolve')
|
|
107
|
+
.tapAsync('TypeScriptPathsPlugin', (request, resolveContext, callback) => {
|
|
108
|
+
var _a, _b;
|
|
109
109
|
// Preprocessing of the options will ensure that `patterns` is either undefined or has elements to check
|
|
110
110
|
if (!this.patterns) {
|
|
111
111
|
callback();
|
|
@@ -121,7 +121,7 @@ class TypeScriptPathsPlugin {
|
|
|
121
121
|
return;
|
|
122
122
|
}
|
|
123
123
|
// Only work on Javascript/TypeScript issuers.
|
|
124
|
-
if (!request
|
|
124
|
+
if (!((_b = (_a = request === null || request === void 0 ? void 0 : request.context) === null || _a === void 0 ? void 0 : _a.issuer) === null || _b === void 0 ? void 0 : _b.match(/\.[cm]?[jt]sx?$/))) {
|
|
125
125
|
callback();
|
|
126
126
|
return;
|
|
127
127
|
}
|
|
@@ -139,108 +139,103 @@ class TypeScriptPathsPlugin {
|
|
|
139
139
|
}
|
|
140
140
|
break;
|
|
141
141
|
}
|
|
142
|
-
// A generator is used to limit the amount of replacements that need to be created.
|
|
142
|
+
// A generator is used to limit the amount of replacements requests that need to be created.
|
|
143
143
|
// For example, if the first one resolves, any others are not needed and do not need
|
|
144
144
|
// to be created.
|
|
145
|
-
const
|
|
146
|
-
const
|
|
147
|
-
|
|
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 = () => {
|
|
163
|
-
const next = replacements.next();
|
|
145
|
+
const requests = this.createReplacementRequests(request, originalRequest);
|
|
146
|
+
const tryResolve = () => {
|
|
147
|
+
const next = requests.next();
|
|
164
148
|
if (next.done) {
|
|
165
149
|
callback();
|
|
166
150
|
return;
|
|
167
151
|
}
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
};
|
|
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));
|
|
152
|
+
resolver.doResolve(target, next.value, '', resolveContext, (error, result) => {
|
|
153
|
+
if (error) {
|
|
154
|
+
callback(error);
|
|
155
|
+
}
|
|
156
|
+
else if (result) {
|
|
157
|
+
callback(undefined, result);
|
|
158
|
+
}
|
|
159
|
+
else {
|
|
160
|
+
tryResolve();
|
|
161
|
+
}
|
|
162
|
+
});
|
|
197
163
|
};
|
|
198
|
-
|
|
164
|
+
tryResolve();
|
|
199
165
|
});
|
|
200
166
|
}
|
|
201
|
-
|
|
202
|
-
|
|
203
|
-
|
|
204
|
-
// check if any path mapping rules are relevant
|
|
205
|
-
for (const { starIndex, prefix, suffix, potentials } of patterns) {
|
|
206
|
-
let partial;
|
|
207
|
-
if (starIndex === -1) {
|
|
208
|
-
// No star means an exact match is required
|
|
209
|
-
if (prefix === originalRequest) {
|
|
210
|
-
partial = '';
|
|
211
|
-
}
|
|
167
|
+
*findReplacements(originalRequest) {
|
|
168
|
+
if (!this.patterns) {
|
|
169
|
+
return;
|
|
212
170
|
}
|
|
213
|
-
|
|
214
|
-
|
|
215
|
-
partial
|
|
216
|
-
|
|
217
|
-
|
|
218
|
-
|
|
219
|
-
|
|
220
|
-
|
|
171
|
+
// check if any path mapping rules are relevant
|
|
172
|
+
for (const { starIndex, prefix, suffix, potentials } of this.patterns) {
|
|
173
|
+
let partial;
|
|
174
|
+
if (starIndex === -1) {
|
|
175
|
+
// No star means an exact match is required
|
|
176
|
+
if (prefix === originalRequest) {
|
|
177
|
+
partial = '';
|
|
178
|
+
}
|
|
221
179
|
}
|
|
222
|
-
|
|
223
|
-
|
|
224
|
-
|
|
225
|
-
if (originalRequest.startsWith(prefix) && originalRequest.endsWith(suffix)) {
|
|
226
|
-
partial = originalRequest.substring(prefix.length, originalRequest.length - suffix.length);
|
|
180
|
+
else if (starIndex === 0 && !suffix) {
|
|
181
|
+
// Everything matches a single wildcard pattern ("*")
|
|
182
|
+
partial = originalRequest;
|
|
227
183
|
}
|
|
228
|
-
|
|
229
|
-
|
|
230
|
-
|
|
231
|
-
|
|
232
|
-
|
|
233
|
-
|
|
234
|
-
|
|
235
|
-
|
|
236
|
-
|
|
237
|
-
|
|
238
|
-
|
|
239
|
-
|
|
240
|
-
|
|
184
|
+
else if (!suffix) {
|
|
185
|
+
// No suffix means the star is at the end of the pattern
|
|
186
|
+
if (originalRequest.startsWith(prefix)) {
|
|
187
|
+
partial = originalRequest.slice(prefix.length);
|
|
188
|
+
}
|
|
189
|
+
}
|
|
190
|
+
else {
|
|
191
|
+
// Star was in the middle of the pattern
|
|
192
|
+
if (originalRequest.startsWith(prefix) && originalRequest.endsWith(suffix)) {
|
|
193
|
+
partial = originalRequest.substring(prefix.length, originalRequest.length - suffix.length);
|
|
194
|
+
}
|
|
195
|
+
}
|
|
196
|
+
// If request was not matched, move on to the next pattern
|
|
197
|
+
if (partial === undefined) {
|
|
198
|
+
continue;
|
|
199
|
+
}
|
|
200
|
+
// Create the full replacement values based on the original request and the potentials
|
|
201
|
+
// for the successfully matched pattern.
|
|
202
|
+
for (const { hasStar, prefix, suffix } of potentials) {
|
|
203
|
+
let replacement = prefix;
|
|
204
|
+
if (hasStar) {
|
|
205
|
+
replacement += partial;
|
|
206
|
+
if (suffix) {
|
|
207
|
+
replacement += suffix;
|
|
208
|
+
}
|
|
241
209
|
}
|
|
210
|
+
yield replacement;
|
|
211
|
+
}
|
|
212
|
+
}
|
|
213
|
+
}
|
|
214
|
+
*createReplacementRequests(request, originalRequest) {
|
|
215
|
+
var _a;
|
|
216
|
+
for (const replacement of this.findReplacements(originalRequest)) {
|
|
217
|
+
const targetPath = path.resolve((_a = this.baseUrl) !== null && _a !== void 0 ? _a : '', replacement);
|
|
218
|
+
// Resolution in the original callee location, but with the updated request
|
|
219
|
+
// to point to the mapped target location.
|
|
220
|
+
yield {
|
|
221
|
+
...request,
|
|
222
|
+
request: targetPath,
|
|
223
|
+
typescriptPathMapped: true,
|
|
224
|
+
};
|
|
225
|
+
// If there is no extension. i.e. the target does not refer to an explicit
|
|
226
|
+
// file, then this is a candidate for module/package resolution.
|
|
227
|
+
const canBeModule = path.extname(targetPath) === '';
|
|
228
|
+
if (canBeModule) {
|
|
229
|
+
// Resolution in the target location, preserving the original request.
|
|
230
|
+
// This will work with the `resolve-in-package` resolution hook, supporting
|
|
231
|
+
// package exports for e.g. locally-built APF libraries.
|
|
232
|
+
yield {
|
|
233
|
+
...request,
|
|
234
|
+
path: targetPath,
|
|
235
|
+
typescriptPathMapped: true,
|
|
236
|
+
};
|
|
242
237
|
}
|
|
243
|
-
yield replacement;
|
|
244
238
|
}
|
|
245
239
|
}
|
|
246
240
|
}
|
|
241
|
+
exports.TypeScriptPathsPlugin = TypeScriptPathsPlugin;
|
package/src/resource_loader.js
CHANGED
|
@@ -29,8 +29,12 @@ var __importStar = (this && this.__importStar) || function (mod) {
|
|
|
29
29
|
__setModuleDefault(result, mod);
|
|
30
30
|
return result;
|
|
31
31
|
};
|
|
32
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
33
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
34
|
+
};
|
|
32
35
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
33
36
|
exports.WebpackResourceLoader = void 0;
|
|
37
|
+
const assert_1 = __importDefault(require("assert"));
|
|
34
38
|
const path = __importStar(require("path"));
|
|
35
39
|
const vm = __importStar(require("vm"));
|
|
36
40
|
const paths_1 = require("./ivy/paths");
|
|
@@ -99,7 +103,7 @@ class WebpackResourceLoader {
|
|
|
99
103
|
throw new Error('WebpackResourceLoader cannot be used without parentCompilation');
|
|
100
104
|
}
|
|
101
105
|
const { context, webpack } = this._parentCompilation.compiler;
|
|
102
|
-
const { EntryPlugin, NormalModule, library, node, sources, util: { createHash }, } = webpack;
|
|
106
|
+
const { EntryPlugin, NormalModule, WebpackError, library, node, sources, util: { createHash }, } = webpack;
|
|
103
107
|
const getEntry = () => {
|
|
104
108
|
if (filePath) {
|
|
105
109
|
return `${filePath}?${replace_resources_1.NG_COMPONENT_RESOURCE_QUERY}`;
|
|
@@ -167,8 +171,9 @@ class WebpackResourceLoader {
|
|
|
167
171
|
}
|
|
168
172
|
}
|
|
169
173
|
catch (error) {
|
|
174
|
+
(0, assert_1.default)(error instanceof Error, 'catch clause variable is not an Error instance');
|
|
170
175
|
// Use compilation errors, as otherwise webpack will choke
|
|
171
|
-
compilation.errors.push(error);
|
|
176
|
+
compilation.errors.push(new WebpackError(error.message));
|
|
172
177
|
}
|
|
173
178
|
});
|
|
174
179
|
});
|