@ngtools/webpack 9.0.0 → 9.0.1
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.0.
|
|
3
|
+
"version": "9.0.1",
|
|
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.0.
|
|
28
|
+
"@angular-devkit/core": "9.0.1",
|
|
29
29
|
"enhanced-resolve": "4.1.1",
|
|
30
30
|
"rxjs": "6.5.3",
|
|
31
31
|
"webpack-sources": "1.4.3"
|
|
@@ -1,10 +1,11 @@
|
|
|
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
|
-
import { WebpackCompilerHost } from '../compiler_host';
|
|
3
9
|
export declare function collectDeepNodes<T extends ts.Node>(node: ts.Node, kind: ts.SyntaxKind | ts.SyntaxKind[]): T[];
|
|
4
10
|
export declare function getFirstNode(sourceFile: ts.SourceFile): ts.Node;
|
|
5
11
|
export declare function getLastNode(sourceFile: ts.SourceFile): ts.Node | null;
|
|
6
|
-
export declare function createTypescriptContext(content: string, additionalFiles?: Record<string, string>, useLibs?: boolean, extraCompilerOptions?: ts.CompilerOptions): {
|
|
7
|
-
compilerHost: WebpackCompilerHost;
|
|
8
|
-
program: ts.Program;
|
|
9
|
-
};
|
|
10
|
-
export declare function transformTypescript(content: string | undefined, transformers: ts.TransformerFactory<ts.SourceFile>[], program?: ts.Program, compilerHost?: WebpackCompilerHost): string | undefined;
|
|
@@ -7,11 +7,7 @@ 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
|
-
const fs_1 = require("fs");
|
|
12
|
-
const path_1 = require("path");
|
|
13
10
|
const ts = require("typescript");
|
|
14
|
-
const compiler_host_1 = require("../compiler_host");
|
|
15
11
|
// Find all nodes from the AST in the subtree of node of SyntaxKind kind.
|
|
16
12
|
function collectDeepNodes(node, kind) {
|
|
17
13
|
const kinds = Array.isArray(kind) ? kind : [kind];
|
|
@@ -40,95 +36,3 @@ function getLastNode(sourceFile) {
|
|
|
40
36
|
return null;
|
|
41
37
|
}
|
|
42
38
|
exports.getLastNode = getLastNode;
|
|
43
|
-
// Test transform helpers.
|
|
44
|
-
const basePath = '/project/src/';
|
|
45
|
-
const fileName = basePath + 'test-file.ts';
|
|
46
|
-
const typeScriptLibFiles = loadTypeScriptLibFiles();
|
|
47
|
-
const tsLibFiles = loadTsLibFiles();
|
|
48
|
-
function createTypescriptContext(content, additionalFiles, useLibs = false, extraCompilerOptions = {}) {
|
|
49
|
-
// Set compiler options.
|
|
50
|
-
const compilerOptions = {
|
|
51
|
-
noEmitOnError: useLibs,
|
|
52
|
-
allowJs: true,
|
|
53
|
-
newLine: ts.NewLineKind.LineFeed,
|
|
54
|
-
moduleResolution: ts.ModuleResolutionKind.NodeJs,
|
|
55
|
-
module: ts.ModuleKind.ESNext,
|
|
56
|
-
target: ts.ScriptTarget.ESNext,
|
|
57
|
-
skipLibCheck: true,
|
|
58
|
-
sourceMap: false,
|
|
59
|
-
importHelpers: true,
|
|
60
|
-
experimentalDecorators: true,
|
|
61
|
-
...extraCompilerOptions,
|
|
62
|
-
};
|
|
63
|
-
// Create compiler host.
|
|
64
|
-
const compilerHost = new compiler_host_1.WebpackCompilerHost(compilerOptions, basePath, new core_1.virtualFs.SimpleMemoryHost(), false);
|
|
65
|
-
// Add a dummy file to host content.
|
|
66
|
-
compilerHost.writeFile(fileName, content, false);
|
|
67
|
-
if (useLibs) {
|
|
68
|
-
// Write the default libs.
|
|
69
|
-
// These are needed for tests that use import(), because it relies on a Promise being there.
|
|
70
|
-
const compilerLibFolder = path_1.dirname(compilerHost.getDefaultLibFileName(compilerOptions));
|
|
71
|
-
for (const [k, v] of Object.entries(typeScriptLibFiles)) {
|
|
72
|
-
compilerHost.writeFile(path_1.join(compilerLibFolder, k), v, false);
|
|
73
|
-
}
|
|
74
|
-
}
|
|
75
|
-
if (compilerOptions.importHelpers) {
|
|
76
|
-
for (const [k, v] of Object.entries(tsLibFiles)) {
|
|
77
|
-
compilerHost.writeFile(k, v, false);
|
|
78
|
-
}
|
|
79
|
-
}
|
|
80
|
-
if (additionalFiles) {
|
|
81
|
-
for (const key in additionalFiles) {
|
|
82
|
-
compilerHost.writeFile(basePath + key, additionalFiles[key], false);
|
|
83
|
-
}
|
|
84
|
-
}
|
|
85
|
-
// Create the TypeScript program.
|
|
86
|
-
const program = ts.createProgram([fileName], compilerOptions, compilerHost);
|
|
87
|
-
return { compilerHost, program };
|
|
88
|
-
}
|
|
89
|
-
exports.createTypescriptContext = createTypescriptContext;
|
|
90
|
-
function transformTypescript(content, transformers, program, compilerHost) {
|
|
91
|
-
// Use given context or create a new one.
|
|
92
|
-
if (content !== undefined) {
|
|
93
|
-
const typescriptContext = createTypescriptContext(content);
|
|
94
|
-
if (!program) {
|
|
95
|
-
program = typescriptContext.program;
|
|
96
|
-
}
|
|
97
|
-
if (!compilerHost) {
|
|
98
|
-
compilerHost = typescriptContext.compilerHost;
|
|
99
|
-
}
|
|
100
|
-
}
|
|
101
|
-
else if (!program || !compilerHost) {
|
|
102
|
-
throw new Error('transformTypescript needs either `content` or a `program` and `compilerHost');
|
|
103
|
-
}
|
|
104
|
-
// Emit.
|
|
105
|
-
const { emitSkipped, diagnostics } = program.emit(undefined, undefined, undefined, undefined, { before: transformers });
|
|
106
|
-
// Throw error with diagnostics if emit wasn't successfull.
|
|
107
|
-
if (emitSkipped) {
|
|
108
|
-
throw new Error(ts.formatDiagnostics(diagnostics, compilerHost));
|
|
109
|
-
}
|
|
110
|
-
// Return the transpiled js.
|
|
111
|
-
return compilerHost.readFile(fileName.replace(/\.tsx?$/, '.js'));
|
|
112
|
-
}
|
|
113
|
-
exports.transformTypescript = transformTypescript;
|
|
114
|
-
function loadTypeScriptLibFiles() {
|
|
115
|
-
const libFolderPath = path_1.dirname(require.resolve('typescript/lib/lib.d.ts'));
|
|
116
|
-
const libFolderFiles = fs_1.readdirSync(libFolderPath);
|
|
117
|
-
const libFileNames = libFolderFiles.filter(f => f.startsWith('lib.') && f.endsWith('.d.ts'));
|
|
118
|
-
// Return a map of the lib names to their content.
|
|
119
|
-
const libs = {};
|
|
120
|
-
for (const f of libFileNames) {
|
|
121
|
-
libs[f] = fs_1.readFileSync(path_1.join(libFolderPath, f), 'utf-8');
|
|
122
|
-
}
|
|
123
|
-
return libs;
|
|
124
|
-
}
|
|
125
|
-
function loadTsLibFiles() {
|
|
126
|
-
const libFolderPath = path_1.dirname(require.resolve('tslib/package.json'));
|
|
127
|
-
const libFolderFiles = fs_1.readdirSync(libFolderPath);
|
|
128
|
-
// Return a map of the lib names to their content.
|
|
129
|
-
const libs = {};
|
|
130
|
-
for (const f of libFolderFiles) {
|
|
131
|
-
libs[path_1.join('node_modules/tslib', f)] = fs_1.readFileSync(path_1.join(libFolderPath, f), 'utf-8');
|
|
132
|
-
}
|
|
133
|
-
return libs;
|
|
134
|
-
}
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
import * as ts from 'typescript';
|
|
2
|
+
import { WebpackCompilerHost } from '../compiler_host';
|
|
3
|
+
export declare function createTypescriptContext(content: string, additionalFiles?: Record<string, string>, useLibs?: boolean, extraCompilerOptions?: ts.CompilerOptions): {
|
|
4
|
+
compilerHost: WebpackCompilerHost;
|
|
5
|
+
program: ts.Program;
|
|
6
|
+
};
|
|
7
|
+
export declare function transformTypescript(content: string | undefined, transformers: ts.TransformerFactory<ts.SourceFile>[], program?: ts.Program, compilerHost?: WebpackCompilerHost): string | undefined;
|
|
@@ -0,0 +1,106 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
/**
|
|
4
|
+
* @license
|
|
5
|
+
* Copyright Google Inc. All Rights Reserved.
|
|
6
|
+
*
|
|
7
|
+
* Use of this source code is governed by an MIT-style license that can be
|
|
8
|
+
* found in the LICENSE file at https://angular.io/license
|
|
9
|
+
*/
|
|
10
|
+
const core_1 = require("@angular-devkit/core");
|
|
11
|
+
const fs_1 = require("fs");
|
|
12
|
+
const path_1 = require("path");
|
|
13
|
+
const ts = require("typescript");
|
|
14
|
+
const compiler_host_1 = require("../compiler_host");
|
|
15
|
+
// Test transform helpers.
|
|
16
|
+
const basePath = '/project/src/';
|
|
17
|
+
const fileName = basePath + 'test-file.ts';
|
|
18
|
+
const typeScriptLibFiles = loadTypeScriptLibFiles();
|
|
19
|
+
const tsLibFiles = loadTsLibFiles();
|
|
20
|
+
function createTypescriptContext(content, additionalFiles, useLibs = false, extraCompilerOptions = {}) {
|
|
21
|
+
// Set compiler options.
|
|
22
|
+
const compilerOptions = {
|
|
23
|
+
noEmitOnError: useLibs,
|
|
24
|
+
allowJs: true,
|
|
25
|
+
newLine: ts.NewLineKind.LineFeed,
|
|
26
|
+
moduleResolution: ts.ModuleResolutionKind.NodeJs,
|
|
27
|
+
module: ts.ModuleKind.ESNext,
|
|
28
|
+
target: ts.ScriptTarget.ESNext,
|
|
29
|
+
skipLibCheck: true,
|
|
30
|
+
sourceMap: false,
|
|
31
|
+
importHelpers: true,
|
|
32
|
+
experimentalDecorators: true,
|
|
33
|
+
...extraCompilerOptions,
|
|
34
|
+
};
|
|
35
|
+
// Create compiler host.
|
|
36
|
+
const compilerHost = new compiler_host_1.WebpackCompilerHost(compilerOptions, basePath, new core_1.virtualFs.SimpleMemoryHost(), false);
|
|
37
|
+
// Add a dummy file to host content.
|
|
38
|
+
compilerHost.writeFile(fileName, content, false);
|
|
39
|
+
if (useLibs) {
|
|
40
|
+
// Write the default libs.
|
|
41
|
+
// These are needed for tests that use import(), because it relies on a Promise being there.
|
|
42
|
+
const compilerLibFolder = path_1.dirname(compilerHost.getDefaultLibFileName(compilerOptions));
|
|
43
|
+
for (const [k, v] of Object.entries(typeScriptLibFiles)) {
|
|
44
|
+
compilerHost.writeFile(path_1.join(compilerLibFolder, k), v, false);
|
|
45
|
+
}
|
|
46
|
+
}
|
|
47
|
+
if (compilerOptions.importHelpers) {
|
|
48
|
+
for (const [k, v] of Object.entries(tsLibFiles)) {
|
|
49
|
+
compilerHost.writeFile(k, v, false);
|
|
50
|
+
}
|
|
51
|
+
}
|
|
52
|
+
if (additionalFiles) {
|
|
53
|
+
for (const key in additionalFiles) {
|
|
54
|
+
compilerHost.writeFile(basePath + key, additionalFiles[key], false);
|
|
55
|
+
}
|
|
56
|
+
}
|
|
57
|
+
// Create the TypeScript program.
|
|
58
|
+
const program = ts.createProgram([fileName], compilerOptions, compilerHost);
|
|
59
|
+
return { compilerHost, program };
|
|
60
|
+
}
|
|
61
|
+
exports.createTypescriptContext = createTypescriptContext;
|
|
62
|
+
function transformTypescript(content, transformers, program, compilerHost) {
|
|
63
|
+
// Use given context or create a new one.
|
|
64
|
+
if (content !== undefined) {
|
|
65
|
+
const typescriptContext = createTypescriptContext(content);
|
|
66
|
+
if (!program) {
|
|
67
|
+
program = typescriptContext.program;
|
|
68
|
+
}
|
|
69
|
+
if (!compilerHost) {
|
|
70
|
+
compilerHost = typescriptContext.compilerHost;
|
|
71
|
+
}
|
|
72
|
+
}
|
|
73
|
+
else if (!program || !compilerHost) {
|
|
74
|
+
throw new Error('transformTypescript needs either `content` or a `program` and `compilerHost');
|
|
75
|
+
}
|
|
76
|
+
// Emit.
|
|
77
|
+
const { emitSkipped, diagnostics } = program.emit(undefined, undefined, undefined, undefined, { before: transformers });
|
|
78
|
+
// Throw error with diagnostics if emit wasn't successfull.
|
|
79
|
+
if (emitSkipped) {
|
|
80
|
+
throw new Error(ts.formatDiagnostics(diagnostics, compilerHost));
|
|
81
|
+
}
|
|
82
|
+
// Return the transpiled js.
|
|
83
|
+
return compilerHost.readFile(fileName.replace(/\.tsx?$/, '.js'));
|
|
84
|
+
}
|
|
85
|
+
exports.transformTypescript = transformTypescript;
|
|
86
|
+
function loadTypeScriptLibFiles() {
|
|
87
|
+
const libFolderPath = path_1.dirname(require.resolve('typescript/lib/lib.d.ts'));
|
|
88
|
+
const libFolderFiles = fs_1.readdirSync(libFolderPath);
|
|
89
|
+
const libFileNames = libFolderFiles.filter(f => f.startsWith('lib.') && f.endsWith('.d.ts'));
|
|
90
|
+
// Return a map of the lib names to their content.
|
|
91
|
+
const libs = {};
|
|
92
|
+
for (const f of libFileNames) {
|
|
93
|
+
libs[f] = fs_1.readFileSync(path_1.join(libFolderPath, f), 'utf-8');
|
|
94
|
+
}
|
|
95
|
+
return libs;
|
|
96
|
+
}
|
|
97
|
+
function loadTsLibFiles() {
|
|
98
|
+
const libFolderPath = path_1.dirname(require.resolve('tslib/package.json'));
|
|
99
|
+
const libFolderFiles = fs_1.readdirSync(libFolderPath);
|
|
100
|
+
// Return a map of the lib names to their content.
|
|
101
|
+
const libs = {};
|
|
102
|
+
for (const f of libFolderFiles) {
|
|
103
|
+
libs[path_1.join('node_modules/tslib', f)] = fs_1.readFileSync(path_1.join(libFolderPath, f), 'utf-8');
|
|
104
|
+
}
|
|
105
|
+
return libs;
|
|
106
|
+
}
|