@ngtools/webpack 12.1.0-next.6 → 12.1.3
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/README.md
CHANGED
|
@@ -37,4 +37,4 @@ The loader works with webpack plugin to compile the application's TypeScript. It
|
|
|
37
37
|
- `jitMode` [default: `false`] - Enables JIT compilation and do not refactor the code to bootstrap. This replaces `templateUrl: "string"` with `template: require("string")` (and similar for styles) to allow for webpack to properly link the resources.
|
|
38
38
|
- `directTemplateLoading` [default: `true`] - Causes the plugin to load component templates (HTML) directly from the filesystem. This is more efficient if only using the `raw-loader` to load component templates. Do not enable this option if additional loaders are configured for component templates.
|
|
39
39
|
- `fileReplacements` [default: none] - Allows replacing TypeScript files with other TypeScript files in the build. This option acts on fully resolved file paths.
|
|
40
|
-
- `
|
|
40
|
+
- `inlineStyleFileExtension` [default: none] - When set inline component styles will be processed by Webpack as files with the provided extension.
|
package/package.json
CHANGED
package/src/ivy/host.js
CHANGED
|
@@ -30,7 +30,6 @@ exports.augmentHostWithCaching = exports.augmentProgramWithVersioning = exports.
|
|
|
30
30
|
const crypto_1 = require("crypto");
|
|
31
31
|
const path = __importStar(require("path"));
|
|
32
32
|
const ts = __importStar(require("typescript"));
|
|
33
|
-
const transformers_1 = require("../transformers");
|
|
34
33
|
const paths_1 = require("./paths");
|
|
35
34
|
function augmentHostWithResources(host, resourceLoader, options = {}) {
|
|
36
35
|
const resourceHost = host;
|
|
@@ -248,10 +247,6 @@ function augmentHostWithCaching(host, cache) {
|
|
|
248
247
|
}
|
|
249
248
|
const file = baseGetSourceFile.call(host, fileName, languageVersion, onError, true, ...parameters);
|
|
250
249
|
if (file) {
|
|
251
|
-
// Temporary workaround for upstream transform resource defect
|
|
252
|
-
if (file && !file.isDeclarationFile && file.text.includes('@Component')) {
|
|
253
|
-
transformers_1.workaroundStylePreprocessing(file);
|
|
254
|
-
}
|
|
255
250
|
cache.set(fileName, file);
|
|
256
251
|
}
|
|
257
252
|
return file;
|
package/src/ivy/plugin.d.ts
CHANGED
|
@@ -16,6 +16,7 @@ export interface AngularWebpackPluginOptions {
|
|
|
16
16
|
emitClassMetadata: boolean;
|
|
17
17
|
emitNgModuleScope: boolean;
|
|
18
18
|
jitMode: boolean;
|
|
19
|
+
/** @deprecated use `inlineStyleFileExtension` instead. */
|
|
19
20
|
inlineStyleMimeType?: string;
|
|
20
21
|
inlineStyleFileExtension?: string;
|
|
21
22
|
}
|
package/src/ivy/plugin.js
CHANGED
|
@@ -362,17 +362,17 @@ class AngularWebpackPlugin {
|
|
|
362
362
|
affectedFiles.add(result.affected);
|
|
363
363
|
}
|
|
364
364
|
}
|
|
365
|
-
// Collect
|
|
365
|
+
// Collect program level diagnostics
|
|
366
366
|
const diagnostics = [
|
|
367
367
|
...angularCompiler.getOptionDiagnostics(),
|
|
368
368
|
...builder.getOptionsDiagnostics(),
|
|
369
369
|
...builder.getGlobalDiagnostics(),
|
|
370
|
-
...builder.getSyntacticDiagnostics(),
|
|
371
370
|
];
|
|
372
371
|
diagnosticsReporter(diagnostics);
|
|
373
|
-
// Collect
|
|
372
|
+
// Collect source file specific diagnostics
|
|
374
373
|
for (const sourceFile of builder.getSourceFiles()) {
|
|
375
374
|
if (!ignoreForDiagnostics.has(sourceFile)) {
|
|
375
|
+
diagnosticsReporter(builder.getSyntacticDiagnostics(sourceFile));
|
|
376
376
|
diagnosticsReporter(builder.getSemanticDiagnostics(sourceFile));
|
|
377
377
|
}
|
|
378
378
|
}
|
package/src/resource_loader.js
CHANGED
|
@@ -188,13 +188,38 @@ class WebpackResourceLoader {
|
|
|
188
188
|
const parent = childCompiler.parentCompilation;
|
|
189
189
|
if (parent) {
|
|
190
190
|
parent.children = parent.children.filter((child) => child !== childCompilation);
|
|
191
|
-
|
|
192
|
-
|
|
191
|
+
let fileDependencies;
|
|
192
|
+
for (const dependency of childCompilation.fileDependencies) {
|
|
193
|
+
// Skip paths that do not appear to be files (have no extension).
|
|
194
|
+
// `fileDependencies` can contain directories and not just files which can
|
|
195
|
+
// cause incorrect cache invalidation on rebuilds.
|
|
196
|
+
if (!path.extname(dependency)) {
|
|
197
|
+
continue;
|
|
198
|
+
}
|
|
199
|
+
if (data && containingFile && dependency.endsWith(entry)) {
|
|
193
200
|
// use containing file if the resource was inline
|
|
194
201
|
parent.fileDependencies.add(containingFile);
|
|
195
202
|
}
|
|
196
203
|
else {
|
|
197
|
-
parent.fileDependencies.add(
|
|
204
|
+
parent.fileDependencies.add(dependency);
|
|
205
|
+
}
|
|
206
|
+
// Save the dependencies for this resource.
|
|
207
|
+
if (filePath) {
|
|
208
|
+
const resolvedFile = paths_1.normalizePath(dependency);
|
|
209
|
+
const entry = this._reverseDependencies.get(resolvedFile);
|
|
210
|
+
if (entry) {
|
|
211
|
+
entry.add(filePath);
|
|
212
|
+
}
|
|
213
|
+
else {
|
|
214
|
+
this._reverseDependencies.set(resolvedFile, new Set([filePath]));
|
|
215
|
+
}
|
|
216
|
+
if (fileDependencies) {
|
|
217
|
+
fileDependencies.add(dependency);
|
|
218
|
+
}
|
|
219
|
+
else {
|
|
220
|
+
fileDependencies = new Set([dependency]);
|
|
221
|
+
this._fileDependencies.set(filePath, fileDependencies);
|
|
222
|
+
}
|
|
198
223
|
}
|
|
199
224
|
}
|
|
200
225
|
parent.contextDependencies.addAll(childCompilation.contextDependencies);
|
|
@@ -202,30 +227,12 @@ class WebpackResourceLoader {
|
|
|
202
227
|
parent.buildDependencies.addAll(childCompilation.buildDependencies);
|
|
203
228
|
parent.warnings.push(...childCompilation.warnings);
|
|
204
229
|
parent.errors.push(...childCompilation.errors);
|
|
205
|
-
|
|
206
|
-
|
|
207
|
-
|
|
208
|
-
|
|
209
|
-
|
|
210
|
-
|
|
211
|
-
}
|
|
212
|
-
// Save the dependencies for this resource.
|
|
213
|
-
if (filePath) {
|
|
214
|
-
this._fileDependencies.set(filePath, new Set(childCompilation.fileDependencies));
|
|
215
|
-
for (const file of childCompilation.fileDependencies) {
|
|
216
|
-
const resolvedFile = paths_1.normalizePath(file);
|
|
217
|
-
// Skip paths that do not appear to be files (have no extension).
|
|
218
|
-
// `fileDependencies` can contain directories and not just files which can
|
|
219
|
-
// cause incorrect cache invalidation on rebuilds.
|
|
220
|
-
if (!path.extname(resolvedFile)) {
|
|
221
|
-
continue;
|
|
222
|
-
}
|
|
223
|
-
const entry = this._reverseDependencies.get(resolvedFile);
|
|
224
|
-
if (entry) {
|
|
225
|
-
entry.add(filePath);
|
|
226
|
-
}
|
|
227
|
-
else {
|
|
228
|
-
this._reverseDependencies.set(resolvedFile, new Set([filePath]));
|
|
230
|
+
if (this.assetCache) {
|
|
231
|
+
for (const { info, name, source } of childCompilation.getAssets()) {
|
|
232
|
+
// Use the originating file as the cache key if present
|
|
233
|
+
// Otherwise, generate a cache key based on the generated name
|
|
234
|
+
const cacheKey = (_a = info.sourceFilename) !== null && _a !== void 0 ? _a : `!![GENERATED]:${name}`;
|
|
235
|
+
this.assetCache.set(cacheKey, { info, name, source });
|
|
229
236
|
}
|
|
230
237
|
}
|
|
231
238
|
}
|
|
@@ -8,4 +8,3 @@
|
|
|
8
8
|
import * as ts from 'typescript';
|
|
9
9
|
export declare function replaceResources(shouldTransform: (fileName: string) => boolean, getTypeChecker: () => ts.TypeChecker, directTemplateLoading?: boolean, inlineStyleMimeType?: string, inlineStyleFileExtension?: string): ts.TransformerFactory<ts.SourceFile>;
|
|
10
10
|
export declare function getResourceUrl(node: ts.Node, loader?: string): string | null;
|
|
11
|
-
export declare function workaroundStylePreprocessing(sourceFile: ts.SourceFile): void;
|
|
@@ -26,7 +26,7 @@ var __importStar = (this && this.__importStar) || function (mod) {
|
|
|
26
26
|
return result;
|
|
27
27
|
};
|
|
28
28
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
29
|
-
exports.
|
|
29
|
+
exports.getResourceUrl = exports.replaceResources = void 0;
|
|
30
30
|
const ts = __importStar(require("typescript"));
|
|
31
31
|
const inlineDataLoaderPath = require.resolve('../inline-data-loader');
|
|
32
32
|
function replaceResources(shouldTransform, getTypeChecker, directTemplateLoading = false, inlineStyleMimeType, inlineStyleFileExtension) {
|
|
@@ -127,7 +127,7 @@ function visitComponentMetadata(nodeFactory, node, styleReplacements, directTemp
|
|
|
127
127
|
else if (inlineStyleFileExtension) {
|
|
128
128
|
const data = Buffer.from(node.text).toString('base64');
|
|
129
129
|
const containingFile = node.getSourceFile().fileName;
|
|
130
|
-
url = `${containingFile}.${inlineStyleFileExtension}!=!${inlineDataLoaderPath}?data=${data}!${containingFile}`;
|
|
130
|
+
url = `${containingFile}.${inlineStyleFileExtension}!=!${inlineDataLoaderPath}?data=${encodeURIComponent(data)}!${containingFile}`;
|
|
131
131
|
}
|
|
132
132
|
else {
|
|
133
133
|
return nodeFactory.createStringLiteral(node.text);
|
|
@@ -222,62 +222,3 @@ function getDecoratorOrigin(decorator, typeChecker) {
|
|
|
222
222
|
}
|
|
223
223
|
return null;
|
|
224
224
|
}
|
|
225
|
-
function workaroundStylePreprocessing(sourceFile) {
|
|
226
|
-
const visitNode = (node) => {
|
|
227
|
-
var _a;
|
|
228
|
-
if (ts.isClassDeclaration(node) && ((_a = node.decorators) === null || _a === void 0 ? void 0 : _a.length)) {
|
|
229
|
-
for (const decorator of node.decorators) {
|
|
230
|
-
visitDecoratorWorkaround(decorator);
|
|
231
|
-
}
|
|
232
|
-
}
|
|
233
|
-
return ts.forEachChild(node, visitNode);
|
|
234
|
-
};
|
|
235
|
-
ts.forEachChild(sourceFile, visitNode);
|
|
236
|
-
}
|
|
237
|
-
exports.workaroundStylePreprocessing = workaroundStylePreprocessing;
|
|
238
|
-
function visitDecoratorWorkaround(node) {
|
|
239
|
-
if (!ts.isCallExpression(node.expression)) {
|
|
240
|
-
return;
|
|
241
|
-
}
|
|
242
|
-
const decoratorFactory = node.expression;
|
|
243
|
-
if (!ts.isIdentifier(decoratorFactory.expression) ||
|
|
244
|
-
decoratorFactory.expression.text !== 'Component') {
|
|
245
|
-
return;
|
|
246
|
-
}
|
|
247
|
-
const args = decoratorFactory.arguments;
|
|
248
|
-
if (args.length !== 1 || !ts.isObjectLiteralExpression(args[0])) {
|
|
249
|
-
// Unsupported component metadata
|
|
250
|
-
return;
|
|
251
|
-
}
|
|
252
|
-
const objectExpression = args[0];
|
|
253
|
-
// check if a `styles` property is present
|
|
254
|
-
let hasStyles = false;
|
|
255
|
-
for (const element of objectExpression.properties) {
|
|
256
|
-
if (!ts.isPropertyAssignment(element) || ts.isComputedPropertyName(element.name)) {
|
|
257
|
-
continue;
|
|
258
|
-
}
|
|
259
|
-
if (element.name.text === 'styles') {
|
|
260
|
-
hasStyles = true;
|
|
261
|
-
break;
|
|
262
|
-
}
|
|
263
|
-
}
|
|
264
|
-
if (hasStyles) {
|
|
265
|
-
return;
|
|
266
|
-
}
|
|
267
|
-
const nodeFactory = ts.factory;
|
|
268
|
-
// add a `styles` property to workaround upstream compiler defect
|
|
269
|
-
const emptyArray = nodeFactory.createArrayLiteralExpression();
|
|
270
|
-
const stylePropertyName = nodeFactory.createIdentifier('styles');
|
|
271
|
-
const styleProperty = nodeFactory.createPropertyAssignment(stylePropertyName, emptyArray);
|
|
272
|
-
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
273
|
-
stylePropertyName.parent = styleProperty;
|
|
274
|
-
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
275
|
-
emptyArray.parent = styleProperty;
|
|
276
|
-
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
277
|
-
styleProperty.parent = objectExpression;
|
|
278
|
-
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
279
|
-
objectExpression.properties = nodeFactory.createNodeArray([
|
|
280
|
-
...objectExpression.properties,
|
|
281
|
-
styleProperty,
|
|
282
|
-
]);
|
|
283
|
-
}
|