@ngtools/webpack 9.1.2 → 9.1.6
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
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@ngtools/webpack",
|
|
3
|
-
"version": "9.1.
|
|
3
|
+
"version": "9.1.6",
|
|
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,7 +25,7 @@
|
|
|
25
25
|
},
|
|
26
26
|
"homepage": "https://github.com/angular/angular-cli",
|
|
27
27
|
"dependencies": {
|
|
28
|
-
"@angular-devkit/core": "9.1.
|
|
28
|
+
"@angular-devkit/core": "9.1.6",
|
|
29
29
|
"enhanced-resolve": "4.1.1",
|
|
30
30
|
"rxjs": "6.5.4",
|
|
31
31
|
"webpack-sources": "1.4.3"
|
package/src/compiler_host.js
CHANGED
|
@@ -296,8 +296,8 @@ class WebpackCompilerHost {
|
|
|
296
296
|
return utils_1.workaroundResolve(this._basePath);
|
|
297
297
|
}
|
|
298
298
|
getCanonicalFileName(fileName) {
|
|
299
|
-
const path = this.resolve(fileName);
|
|
300
|
-
return this.useCaseSensitiveFileNames ? path : path.toLowerCase();
|
|
299
|
+
const path = utils_1.workaroundResolve(this.resolve(fileName));
|
|
300
|
+
return this.useCaseSensitiveFileNames() ? path : path.toLowerCase();
|
|
301
301
|
}
|
|
302
302
|
useCaseSensitiveFileNames() {
|
|
303
303
|
return !process.platform.startsWith('win32');
|
|
@@ -1,3 +1,10 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @license
|
|
3
|
+
* Copyright Google Inc. All Rights Reserved.
|
|
4
|
+
*
|
|
5
|
+
* Use of this source code is governed by an MIT-style license that can be
|
|
6
|
+
* found in the LICENSE file at https://angular.io/license
|
|
7
|
+
*/
|
|
1
8
|
import * as ts from 'typescript';
|
|
2
9
|
export declare function replaceResources(shouldTransform: (fileName: string) => boolean, getTypeChecker: () => ts.TypeChecker, directTemplateLoading?: boolean): ts.TransformerFactory<ts.SourceFile>;
|
|
3
10
|
export declare function getResourceUrl(node: ts.Expression, loader?: string): string | null;
|
|
@@ -7,32 +7,30 @@ Object.defineProperty(exports, "__esModule", { value: true });
|
|
|
7
7
|
* Use of this source code is governed by an MIT-style license that can be
|
|
8
8
|
* found in the LICENSE file at https://angular.io/license
|
|
9
9
|
*/
|
|
10
|
-
const core_1 = require("@angular-devkit/core");
|
|
11
10
|
const ts = require("typescript");
|
|
11
|
+
// emit helper for `import Name from "foo"`
|
|
12
|
+
// importName is marked as an internal property but is needed for the tslib import.
|
|
13
|
+
const importDefaultHelper = {
|
|
14
|
+
name: 'typescript:commonjsimportdefault',
|
|
15
|
+
importName: '__importDefault',
|
|
16
|
+
scoped: false,
|
|
17
|
+
text: `
|
|
18
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
19
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
20
|
+
};`,
|
|
21
|
+
};
|
|
12
22
|
function replaceResources(shouldTransform, getTypeChecker, directTemplateLoading = false) {
|
|
13
23
|
return (context) => {
|
|
14
24
|
const typeChecker = getTypeChecker();
|
|
15
25
|
const visitNode = (node) => {
|
|
16
26
|
if (ts.isClassDeclaration(node)) {
|
|
17
|
-
const decorators = ts.visitNodes(node.decorators, (node) => visitDecorator(node, typeChecker, directTemplateLoading));
|
|
27
|
+
const decorators = ts.visitNodes(node.decorators, (node) => visitDecorator(context, node, typeChecker, directTemplateLoading));
|
|
18
28
|
return ts.updateClassDeclaration(node, decorators, node.modifiers, node.name, node.typeParameters, node.heritageClauses, node.members);
|
|
19
29
|
}
|
|
20
30
|
return ts.visitEachChild(node, visitNode, context);
|
|
21
31
|
};
|
|
22
|
-
// emit helper for `import Name from "foo"`
|
|
23
|
-
// importName is marked as an internal property but is needed for the tslib import.
|
|
24
|
-
const importDefaultHelper = {
|
|
25
|
-
name: 'typescript:commonjsimportdefault',
|
|
26
|
-
importName: '__importDefault',
|
|
27
|
-
scoped: false,
|
|
28
|
-
text: core_1.tags.stripIndent `
|
|
29
|
-
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
30
|
-
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
31
|
-
};`,
|
|
32
|
-
};
|
|
33
32
|
return (sourceFile) => {
|
|
34
33
|
if (shouldTransform(sourceFile.fileName)) {
|
|
35
|
-
context.requestEmitHelper(importDefaultHelper);
|
|
36
34
|
return ts.visitNode(sourceFile, visitNode);
|
|
37
35
|
}
|
|
38
36
|
return sourceFile;
|
|
@@ -40,7 +38,7 @@ function replaceResources(shouldTransform, getTypeChecker, directTemplateLoading
|
|
|
40
38
|
};
|
|
41
39
|
}
|
|
42
40
|
exports.replaceResources = replaceResources;
|
|
43
|
-
function visitDecorator(node, typeChecker, directTemplateLoading) {
|
|
41
|
+
function visitDecorator(context, node, typeChecker, directTemplateLoading) {
|
|
44
42
|
if (!isComponentDecorator(node, typeChecker)) {
|
|
45
43
|
return node;
|
|
46
44
|
}
|
|
@@ -56,15 +54,17 @@ function visitDecorator(node, typeChecker, directTemplateLoading) {
|
|
|
56
54
|
const objectExpression = args[0];
|
|
57
55
|
const styleReplacements = [];
|
|
58
56
|
// visit all properties
|
|
59
|
-
let properties = ts.visitNodes(objectExpression.properties, (node) => visitComponentMetadata(node, styleReplacements, directTemplateLoading));
|
|
57
|
+
let properties = ts.visitNodes(objectExpression.properties, (node) => visitComponentMetadata(context, node, styleReplacements, directTemplateLoading));
|
|
60
58
|
// replace properties with updated properties
|
|
61
59
|
if (styleReplacements.length > 0) {
|
|
62
60
|
const styleProperty = ts.createPropertyAssignment(ts.createIdentifier('styles'), ts.createArrayLiteral(styleReplacements));
|
|
63
61
|
properties = ts.createNodeArray([...properties, styleProperty]);
|
|
64
62
|
}
|
|
65
|
-
return ts.updateDecorator(node, ts.updateCall(decoratorFactory, decoratorFactory.expression, decoratorFactory.typeArguments, [
|
|
63
|
+
return ts.updateDecorator(node, ts.updateCall(decoratorFactory, decoratorFactory.expression, decoratorFactory.typeArguments, [
|
|
64
|
+
ts.updateObjectLiteral(objectExpression, properties),
|
|
65
|
+
]));
|
|
66
66
|
}
|
|
67
|
-
function visitComponentMetadata(node, styleReplacements, directTemplateLoading) {
|
|
67
|
+
function visitComponentMetadata(context, node, styleReplacements, directTemplateLoading) {
|
|
68
68
|
if (!ts.isPropertyAssignment(node) || ts.isComputedPropertyName(node.name)) {
|
|
69
69
|
return node;
|
|
70
70
|
}
|
|
@@ -73,7 +73,7 @@ function visitComponentMetadata(node, styleReplacements, directTemplateLoading)
|
|
|
73
73
|
case 'moduleId':
|
|
74
74
|
return undefined;
|
|
75
75
|
case 'templateUrl':
|
|
76
|
-
return ts.updatePropertyAssignment(node, ts.createIdentifier('template'), createRequireExpression(node.initializer, directTemplateLoading ? '!raw-loader!' : ''));
|
|
76
|
+
return ts.updatePropertyAssignment(node, ts.createIdentifier('template'), createRequireExpression(context, node.initializer, directTemplateLoading ? '!raw-loader!' : ''));
|
|
77
77
|
case 'styles':
|
|
78
78
|
case 'styleUrls':
|
|
79
79
|
if (!ts.isArrayLiteralExpression(node.initializer)) {
|
|
@@ -84,7 +84,9 @@ function visitComponentMetadata(node, styleReplacements, directTemplateLoading)
|
|
|
84
84
|
if (!ts.isStringLiteral(node) && !ts.isNoSubstitutionTemplateLiteral(node)) {
|
|
85
85
|
return node;
|
|
86
86
|
}
|
|
87
|
-
return isInlineStyles
|
|
87
|
+
return isInlineStyles
|
|
88
|
+
? ts.createLiteral(node.text)
|
|
89
|
+
: createRequireExpression(context, node);
|
|
88
90
|
});
|
|
89
91
|
// Styles should be placed first
|
|
90
92
|
if (isInlineStyles) {
|
|
@@ -116,12 +118,15 @@ function isComponentDecorator(node, typeChecker) {
|
|
|
116
118
|
}
|
|
117
119
|
return false;
|
|
118
120
|
}
|
|
119
|
-
function createRequireExpression(node, loader) {
|
|
121
|
+
function createRequireExpression(context, node, loader) {
|
|
120
122
|
const url = getResourceUrl(node, loader);
|
|
121
123
|
if (!url) {
|
|
122
124
|
return node;
|
|
123
125
|
}
|
|
124
|
-
|
|
126
|
+
context.requestEmitHelper(importDefaultHelper);
|
|
127
|
+
const callExpression = ts.createCall(ts.createIdentifier('require'), undefined, [
|
|
128
|
+
ts.createLiteral(url),
|
|
129
|
+
]);
|
|
125
130
|
return ts.createPropertyAccess(ts.createCall(ts.setEmitFlags(ts.createIdentifier('__importDefault'), ts.EmitFlags.HelperName | ts.EmitFlags.AdviseOnEmitNode), undefined, [callExpression]), 'default');
|
|
126
131
|
}
|
|
127
132
|
function getDecoratorOrigin(decorator, typeChecker) {
|
package/src/utils.js
CHANGED
|
@@ -10,6 +10,8 @@ Object.defineProperty(exports, "__esModule", { value: true });
|
|
|
10
10
|
const core_1 = require("@angular-devkit/core");
|
|
11
11
|
// `TsCompilerAotCompilerTypeCheckHostAdapter` in @angular/compiler-cli seems to resolve module
|
|
12
12
|
// names directly via `resolveModuleName`, which prevents full Path usage.
|
|
13
|
+
// NSTSC also uses Node.JS `path.resolve` which will result in incorrect paths in Windows
|
|
14
|
+
// Example: `/D/MyPath/MyProject` -> `D:/d/mypath/myproject`
|
|
13
15
|
// To work around this we must provide the same path format as TS internally uses in
|
|
14
16
|
// the SourceFile paths.
|
|
15
17
|
function workaroundResolve(path) {
|