ng-packagr 12.0.7 → 12.1.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/cli/main.js +5 -1
- package/cli/main.js.map +1 -1
- package/lib/file-system/file-cache.d.ts +3 -0
- package/lib/file-system/file-cache.js +9 -0
- package/lib/file-system/file-cache.js.map +1 -1
- package/lib/ivy/cache-compiler-host.d.ts +8 -0
- package/lib/ivy/cache-compiler-host.js +111 -0
- package/lib/ivy/cache-compiler-host.js.map +1 -0
- package/lib/ivy/compile-source-files.d.ts +6 -0
- package/lib/ivy/compile-source-files.js +123 -0
- package/lib/ivy/compile-source-files.js.map +1 -0
- package/lib/ivy/index.d.ts +2 -0
- package/lib/ivy/index.js +8 -0
- package/lib/ivy/index.js.map +1 -0
- package/lib/ivy/styles/stylesheet-processor.d.ts +20 -0
- package/lib/ivy/styles/stylesheet-processor.js +170 -0
- package/lib/ivy/styles/stylesheet-processor.js.map +1 -0
- package/lib/ng-package/entry-point/compile-ngc.di.js +5 -1
- package/lib/ng-package/entry-point/compile-ngc.di.js.map +1 -1
- package/lib/ng-package/entry-point/compile-ngc.transform.d.ts +2 -1
- package/lib/ng-package/entry-point/compile-ngc.transform.js +38 -16
- package/lib/ng-package/entry-point/compile-ngc.transform.js.map +1 -1
- package/lib/ng-package/nodes.d.ts +5 -2
- package/lib/ng-package/nodes.js.map +1 -1
- package/lib/packagr.js +1 -6
- package/lib/packagr.js.map +1 -1
- package/lib/ts/cache-compiler-host.d.ts +1 -0
- package/lib/ts/cache-compiler-host.js +21 -8
- package/lib/ts/cache-compiler-host.js.map +1 -1
- package/package.json +2 -2
package/cli/main.js
CHANGED
|
@@ -3,6 +3,7 @@
|
|
|
3
3
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
4
4
|
const program = require("commander");
|
|
5
5
|
const path = require("path");
|
|
6
|
+
const log_1 = require("../lib/utils/log");
|
|
6
7
|
const public_api_1 = require("../public_api");
|
|
7
8
|
const DEFAULT_PROJECT_PATH = path.resolve(process.cwd(), 'ng-package.json');
|
|
8
9
|
function parseProjectPath(parsed) {
|
|
@@ -21,5 +22,8 @@ program.on('option:version', () => {
|
|
|
21
22
|
});
|
|
22
23
|
program.parse(process.argv);
|
|
23
24
|
const { config, project, watch } = program.opts();
|
|
24
|
-
public_api_1.execute(public_api_1.build, { config, project, watch: !!watch }).catch(
|
|
25
|
+
public_api_1.execute(public_api_1.build, { config, project, watch: !!watch }).catch(err => {
|
|
26
|
+
log_1.error(err.message);
|
|
27
|
+
process.exit(1);
|
|
28
|
+
});
|
|
25
29
|
//# sourceMappingURL=main.js.map
|
package/cli/main.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"main.js","sourceRoot":"","sources":["../../src/cli/main.ts"],"names":[],"mappings":";;;AAEA,qCAAqC;AACrC,6BAA6B;AAC7B,8CAAwD;AAExD,MAAM,oBAAoB,GAAG,IAAI,CAAC,OAAO,CAAC,OAAO,CAAC,GAAG,EAAE,EAAE,iBAAiB,CAAC,CAAC;AAE5E,SAAS,gBAAgB,CAAC,MAAc;IACtC,OAAO,MAAM,IAAI,oBAAoB,CAAC;AACxC,CAAC;AAED,OAAO;KACJ,IAAI,CAAC,YAAY,CAAC;KAClB,wBAAwB,CAAC,KAAK,CAAC;KAC/B,MAAM,CAAC,eAAe,EAAE,qBAAqB,CAAC;KAC9C,MAAM,CAAC,aAAa,EAAE,wBAAwB,CAAC;KAC/C,MAAM,CACL,sBAAsB,EACtB,uDAAuD,EACvD,gBAAgB,EAChB,oBAAoB,CACrB;KACA,MAAM,CAAC,uBAAuB,EAAE,0BAA0B,EAAE,CAAC,KAAyB,EAAE,EAAE,CACzF,KAAK,CAAC,CAAC,CAAC,IAAI,CAAC,OAAO,CAAC,KAAK,CAAC,CAAC,CAAC,CAAC,SAAS,CACxC,CAAC;AAEJ,OAAO,CAAC,EAAE,CAAC,gBAAgB,EAAE,GAAG,EAAE;IAChC,oBAAO,EA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IAAI,CAAC,CAAC,CAAC,CAAC;AAClB,CAAC,CAAC,CAAC;AAEH,OAAO,CAAC,KAAK,CAAC,OAAO,CAAC,IAAI,CAAC,CAAC;AAE5B,MAAM,EAAE,MAAM,EAAE,OAAO,EAAE,KAAK,EAAE,GAAG,OAAO,CAAC,IAAI,EAAE,CAAC;AAClD,oBAAO,CAAC,kBAAK,EAAE,EAAE,MAAM,EAAE,OAAO,EAAE,KAAK,EAAE,CAAC,CAAC,KAAK,EAAE,CAAC,CAAC,KAAK,CAAC,GAAG,CAAC,EAAE;IAC9D,WAAK,CAAC,GAAG,CAAC,OAAO,CAAC,CAAC;IACnB,OAAO,CAAC,IAAI,CAAC,CAAC,CAAC,CAAC;AAClB,CAAC,CAAC,CAAC","sourcesContent":["#!/usr/bin/env node\n\nimport * as program from 'commander';\nimport * as path from 'path';\nimport { error } from '../lib/utils/log';\nimport { build, execute, version } from '../public_api';\n\nconst DEFAULT_PROJECT_PATH = path.resolve(process.cwd(), 'ng-package.json');\n\nfunction parseProjectPath(parsed: string): string {\n return parsed || DEFAULT_PROJECT_PATH;\n}\n\nprogram\n .name('ng-packagr')\n .storeOptionsAsProperties(false)\n .option('-v, --version', 'Prints version info')\n .option('-w, --watch', 'Watch for file changes')\n .option(\n '-p, --project [path]',\n \"Path to the 'ng-package.json' or 'package.json' file.\",\n parseProjectPath,\n DEFAULT_PROJECT_PATH,\n )\n .option('-c, --config [config]', 'Path to a tsconfig file.', (value: string | undefined) =>\n value ? path.resolve(value) : undefined,\n );\n\nprogram.on('option:version', () => {\n version();\n process.exit(0);\n});\n\nprogram.parse(process.argv);\n\nconst { config, project, watch } = program.opts();\nexecute(build, { config, project, watch: !!watch }).catch(err => {\n error(err.message);\n process.exit(1);\n});\n"]}
|
|
@@ -4,6 +4,7 @@ export interface CacheEntry {
|
|
|
4
4
|
sourceFile?: ts.SourceFile;
|
|
5
5
|
content?: string;
|
|
6
6
|
declarationFileName?: string;
|
|
7
|
+
angularDiagnostics?: ts.Diagnostic[];
|
|
7
8
|
}
|
|
8
9
|
export declare class FileCache {
|
|
9
10
|
private cache;
|
|
@@ -15,4 +16,6 @@ export declare class FileCache {
|
|
|
15
16
|
has(fileName: string): boolean;
|
|
16
17
|
get(fileName: string): CacheEntry | undefined;
|
|
17
18
|
getOrCreate(fileName: string): CacheEntry;
|
|
19
|
+
updateAngularDiagnostics(sourceFile: ts.SourceFile, diagnostics: ts.Diagnostic[]): void;
|
|
20
|
+
getAngularDiagnostics(sourceFile: ts.SourceFile): ts.Diagnostic[] | undefined;
|
|
18
21
|
}
|
|
@@ -32,6 +32,15 @@ class FileCache {
|
|
|
32
32
|
}
|
|
33
33
|
return entry;
|
|
34
34
|
}
|
|
35
|
+
updateAngularDiagnostics(sourceFile, diagnostics) {
|
|
36
|
+
if (this.has(sourceFile.fileName)) {
|
|
37
|
+
this.get(sourceFile.fileName).angularDiagnostics = diagnostics;
|
|
38
|
+
}
|
|
39
|
+
}
|
|
40
|
+
getAngularDiagnostics(sourceFile) {
|
|
41
|
+
var _a;
|
|
42
|
+
return (_a = this.get(sourceFile.fileName)) === null || _a === void 0 ? void 0 : _a.angularDiagnostics;
|
|
43
|
+
}
|
|
35
44
|
}
|
|
36
45
|
exports.FileCache = FileCache;
|
|
37
46
|
//# sourceMappingURL=file-cache.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"file-cache.js","sourceRoot":"","sources":["../../../src/lib/file-system/file-cache.ts"],"names":[],"mappings":";;;AACA,wCAA+C;
|
|
1
|
+
{"version":3,"file":"file-cache.js","sourceRoot":"","sources":["../../../src/lib/file-system/file-cache.ts"],"names":[],"mappings":";;;AACA,wCAA+C;AAU/C,MAAa,SAAS;IAAtB;QACU,UAAK,GAA4B,IAAI,GAAG,EAAE,CAAC;QAEnD,YAAO,GACL,IAAI,CAAC,KAAK,CAAC,OAAO,CAAC,IAAI,CAAC,IAAI,CAAC,KAAK,CAAC,CAAC;QACtC,UAAK,GAAe,IAAI,CAAC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MAAA,IAAI,CAAC,GAAG,CAAC,UAAU,CAAC,QAAQ,CAAC,0CAAE,kBAAkB,CAAC;IAC3D,CAAC;CACF;AAhDD,8BAgDC","sourcesContent":["import * as ts from 'typescript';\nimport { ensureUnixPath } from '../utils/path';\n\nexport interface CacheEntry {\n exists?: boolean;\n sourceFile?: ts.SourceFile;\n content?: string;\n declarationFileName?: string;\n angularDiagnostics?: ts.Diagnostic[];\n}\n\nexport class FileCache {\n private cache: Map<string, CacheEntry> = new Map();\n\n forEach: (callbackfn: (value: CacheEntry, key: string, map: Map<string, CacheEntry>) => void, thisArg?: any) => void =\n this.cache.forEach.bind(this.cache);\n clear: () => void = this.cache.clear.bind(this.cache);\n\n size(): number {\n return this.cache.size;\n }\n\n normalizeKey(fileName: string): string {\n return ensureUnixPath(fileName);\n }\n\n delete(fileName: string): boolean {\n return this.cache.delete(this.normalizeKey(fileName));\n }\n\n has(fileName: string): boolean {\n return this.cache.has(this.normalizeKey(fileName));\n }\n\n get(fileName: string): CacheEntry | undefined {\n return this.cache.get(this.normalizeKey(fileName));\n }\n\n getOrCreate(fileName: string): CacheEntry {\n const normalizedKey = this.normalizeKey(fileName);\n let entry = this.cache.get(normalizedKey);\n\n if (!entry) {\n entry = {};\n this.cache.set(normalizedKey, entry);\n }\n\n return entry;\n }\n\n updateAngularDiagnostics(sourceFile: ts.SourceFile, diagnostics: ts.Diagnostic[]): void {\n if (this.has(sourceFile.fileName)) {\n this.get(sourceFile.fileName).angularDiagnostics = diagnostics;\n }\n }\n\n getAngularDiagnostics(sourceFile: ts.SourceFile): ts.Diagnostic[] | undefined {\n return this.get(sourceFile.fileName)?.angularDiagnostics;\n }\n}\n"]}
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
import * as ts from 'typescript';
|
|
2
|
+
import * as ng from '@angular/compiler-cli';
|
|
3
|
+
import { EntryPointNode } from '../ng-package/nodes';
|
|
4
|
+
import { BuildGraph } from '../graph/build-graph';
|
|
5
|
+
import { FileCache } from '../file-system/file-cache';
|
|
6
|
+
import { StylesheetProcessor } from './styles/stylesheet-processor';
|
|
7
|
+
export declare function cacheCompilerHost(graph: BuildGraph, entryPoint: EntryPointNode, compilerOptions: ng.CompilerOptions, moduleResolutionCache: ts.ModuleResolutionCache, stylesheetProcessor?: StylesheetProcessor, sourcesFileCache?: FileCache): ng.CompilerHost;
|
|
8
|
+
export declare function augmentProgramWithVersioning(program: ts.Program): void;
|
|
@@ -0,0 +1,111 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.augmentProgramWithVersioning = exports.cacheCompilerHost = void 0;
|
|
4
|
+
const ts = require("typescript");
|
|
5
|
+
const path = require("path");
|
|
6
|
+
const path_1 = require("../utils/path");
|
|
7
|
+
const nodes_1 = require("../ng-package/nodes");
|
|
8
|
+
const node_1 = require("../graph/node");
|
|
9
|
+
const crypto_1 = require("crypto");
|
|
10
|
+
function cacheCompilerHost(graph, entryPoint, compilerOptions, moduleResolutionCache, stylesheetProcessor, sourcesFileCache = entryPoint.cache.sourcesFileCache) {
|
|
11
|
+
const compilerHost = ts.createIncrementalCompilerHost(compilerOptions);
|
|
12
|
+
const getNode = (fileName) => {
|
|
13
|
+
const nodeUri = nodes_1.fileUrl(path_1.ensureUnixPath(fileName));
|
|
14
|
+
let node = graph.get(nodeUri);
|
|
15
|
+
if (!node) {
|
|
16
|
+
node = new node_1.Node(nodeUri);
|
|
17
|
+
graph.put(node);
|
|
18
|
+
}
|
|
19
|
+
return node;
|
|
20
|
+
};
|
|
21
|
+
const addDependee = (fileName) => {
|
|
22
|
+
const node = getNode(fileName);
|
|
23
|
+
entryPoint.dependsOn(node);
|
|
24
|
+
};
|
|
25
|
+
return {
|
|
26
|
+
...compilerHost,
|
|
27
|
+
// ts specific
|
|
28
|
+
fileExists: (fileName) => {
|
|
29
|
+
const cache = sourcesFileCache.getOrCreate(fileName);
|
|
30
|
+
if (cache.exists === undefined) {
|
|
31
|
+
cache.exists = compilerHost.fileExists.call(this, fileName);
|
|
32
|
+
}
|
|
33
|
+
return cache.exists;
|
|
34
|
+
},
|
|
35
|
+
getSourceFile: (fileName, languageVersion) => {
|
|
36
|
+
addDependee(fileName);
|
|
37
|
+
const cache = sourcesFileCache.getOrCreate(fileName);
|
|
38
|
+
if (!cache.sourceFile) {
|
|
39
|
+
cache.sourceFile = compilerHost.getSourceFile.call(this, fileName, languageVersion);
|
|
40
|
+
}
|
|
41
|
+
return cache.sourceFile;
|
|
42
|
+
},
|
|
43
|
+
writeFile: (fileName, data, writeByteOrderMark, onError, sourceFiles) => {
|
|
44
|
+
if (fileName.endsWith('.d.ts')) {
|
|
45
|
+
sourceFiles.forEach(source => {
|
|
46
|
+
const cache = sourcesFileCache.getOrCreate(source.fileName);
|
|
47
|
+
if (!cache.declarationFileName) {
|
|
48
|
+
cache.declarationFileName = path_1.ensureUnixPath(fileName);
|
|
49
|
+
}
|
|
50
|
+
});
|
|
51
|
+
}
|
|
52
|
+
compilerHost.writeFile.call(this, fileName, data, writeByteOrderMark, onError, sourceFiles);
|
|
53
|
+
},
|
|
54
|
+
readFile: (fileName) => {
|
|
55
|
+
addDependee(fileName);
|
|
56
|
+
const cache = sourcesFileCache.getOrCreate(fileName);
|
|
57
|
+
if (cache.content === undefined) {
|
|
58
|
+
cache.content = compilerHost.readFile.call(this, fileName);
|
|
59
|
+
}
|
|
60
|
+
return cache.content;
|
|
61
|
+
},
|
|
62
|
+
resolveModuleNames: (moduleNames, containingFile) => {
|
|
63
|
+
return moduleNames.map(moduleName => {
|
|
64
|
+
const { resolvedModule } = ts.resolveModuleName(moduleName, path_1.ensureUnixPath(containingFile), compilerOptions, compilerHost, moduleResolutionCache);
|
|
65
|
+
return resolvedModule;
|
|
66
|
+
});
|
|
67
|
+
},
|
|
68
|
+
resourceNameToFileName: (resourceName, containingFilePath) => {
|
|
69
|
+
const resourcePath = path.resolve(path.dirname(containingFilePath), resourceName);
|
|
70
|
+
const containingNode = getNode(containingFilePath);
|
|
71
|
+
const resourceNode = getNode(resourcePath);
|
|
72
|
+
containingNode.dependsOn(resourceNode);
|
|
73
|
+
return resourcePath;
|
|
74
|
+
},
|
|
75
|
+
readResource: async (fileName) => {
|
|
76
|
+
addDependee(fileName);
|
|
77
|
+
const cache = sourcesFileCache.getOrCreate(fileName);
|
|
78
|
+
if (cache.content === undefined) {
|
|
79
|
+
if (/(?:html?|svg)$/.test(path.extname(fileName))) {
|
|
80
|
+
// template
|
|
81
|
+
cache.content = compilerHost.readFile.call(this, fileName);
|
|
82
|
+
}
|
|
83
|
+
else {
|
|
84
|
+
// stylesheet
|
|
85
|
+
cache.content = await stylesheetProcessor.process(fileName);
|
|
86
|
+
}
|
|
87
|
+
if (cache.content === undefined) {
|
|
88
|
+
throw new Error(`Cannot read file ${fileName}.`);
|
|
89
|
+
}
|
|
90
|
+
;
|
|
91
|
+
cache.exists = true;
|
|
92
|
+
}
|
|
93
|
+
return cache.content;
|
|
94
|
+
},
|
|
95
|
+
};
|
|
96
|
+
}
|
|
97
|
+
exports.cacheCompilerHost = cacheCompilerHost;
|
|
98
|
+
function augmentProgramWithVersioning(program) {
|
|
99
|
+
const baseGetSourceFiles = program.getSourceFiles;
|
|
100
|
+
program.getSourceFiles = function (...parameters) {
|
|
101
|
+
const files = baseGetSourceFiles(...parameters);
|
|
102
|
+
for (const file of files) {
|
|
103
|
+
if (file.version === undefined) {
|
|
104
|
+
file.version = crypto_1.createHash('sha256').update(file.text).digest('hex');
|
|
105
|
+
}
|
|
106
|
+
}
|
|
107
|
+
return files;
|
|
108
|
+
};
|
|
109
|
+
}
|
|
110
|
+
exports.augmentProgramWithVersioning = augmentProgramWithVersioning;
|
|
111
|
+
//# sourceMappingURL=cache-compiler-host.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"cache-compiler-host.js","sourceRoot":"","sources":["../../../src/lib/ivy/cache-compiler-host.ts"],"names":[],"mappings":";;;AAAA,iCAAiC;AAE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7D;gBAED,IAAI,KAAK,CAAC,OAAO,KAAK,SAAS,EAAE;oBAC/B,MAAM,IAAI,KAAK,CAAC,oBAAoB,QAAQ,GAAG,CAAC,CAAC;iBAClD;gBAAA,CAAC;gBAEF,KAAK,CAAC,MAAM,GAAG,IAAI,CAAC;aACrB;YAED,OAAO,KAAK,CAAC,OAAO,CAAC;QACvB,CAAC;KACF,CAAC;AACJ,CAAC;AA3HD,8CA2HC;AAED,SAAgB,4BAA4B,CAAC,OAAmB;IAC9D,MAAM,kBAAkB,GAAG,OAAO,CAAC,cAAc,CAAC;IAClD,OAAO,CAAC,cAAc,GAAG,UAAU,GAAG,UAAU;QAC9C,MAAM,KAAK,GAAsD,kBAAkB,CACjF,GAAG,UAAU,CACd,CAAC;QAEF,KAAK,MAAM,IAAI,IAAI,KAAK,EAAE;YACxB,IAAI,IAAI,CAAC,OAAO,KAAK,SAAS,EAAE;gBAC9B,IAAI,CAAC,OAAO,GAAG,mBAAU,CAAC,QAAQ,CAAC,CAAC,MAAM,CAAC,IAAI,CAAC,IAAI,CAAC,CAAC,MAAM,CAAC,KAAK,CAAC,CAAC;aACrE;SACF;QAED,OAAO,KAAK,CAAC;IACf,CAAC,CAAC;AACJ,CAAC;AAfD,oEAeC","sourcesContent":["import * as ts from 'typescript';\nimport * as ng from '@angular/compiler-cli';\nimport * as path from 'path';\nimport { ensureUnixPath } from '../utils/path';\n\nimport { EntryPointNode, fileUrl } from '../ng-package/nodes';\nimport { BuildGraph } from '../graph/build-graph';\nimport { FileCache } from '../file-system/file-cache';\nimport { Node } from '../graph/node';\nimport { createHash } from 'crypto';\nimport { StylesheetProcessor } from './styles/stylesheet-processor';\n\nexport function cacheCompilerHost(\n graph: BuildGraph,\n entryPoint: EntryPointNode,\n compilerOptions: ng.CompilerOptions,\n moduleResolutionCache: ts.ModuleResolutionCache,\n stylesheetProcessor?: StylesheetProcessor,\n sourcesFileCache: FileCache = entryPoint.cache.sourcesFileCache,\n): ng.CompilerHost {\n const compilerHost = ts.createIncrementalCompilerHost(compilerOptions);\n\n const getNode = (fileName: string) => {\n const nodeUri = fileUrl(ensureUnixPath(fileName));\n let node = graph.get(nodeUri);\n\n if (!node) {\n node = new Node(nodeUri);\n graph.put(node);\n }\n\n return node;\n };\n\n const addDependee = (fileName: string) => {\n const node = getNode(fileName);\n entryPoint.dependsOn(node);\n };\n\n return {\n ...compilerHost,\n\n // ts specific\n fileExists: (fileName: string) => {\n const cache = sourcesFileCache.getOrCreate(fileName);\n if (cache.exists === undefined) {\n cache.exists = compilerHost.fileExists.call(this, fileName);\n }\n return cache.exists;\n },\n\n getSourceFile: (fileName: string, languageVersion: ts.ScriptTarget) => {\n addDependee(fileName);\n const cache = sourcesFileCache.getOrCreate(fileName);\n if (!cache.sourceFile) {\n cache.sourceFile = compilerHost.getSourceFile.call(this, fileName, languageVersion);\n }\n return cache.sourceFile;\n },\n\n writeFile: (\n fileName: string,\n data: string,\n writeByteOrderMark: boolean,\n onError?: (message: string) => void,\n sourceFiles?: ReadonlyArray<ts.SourceFile>,\n ) => {\n if (fileName.endsWith('.d.ts')) {\n sourceFiles.forEach(source => {\n const cache = sourcesFileCache.getOrCreate(source.fileName);\n if (!cache.declarationFileName) {\n cache.declarationFileName = ensureUnixPath(fileName);\n }\n });\n }\n\n compilerHost.writeFile.call(this, fileName, data, writeByteOrderMark, onError, sourceFiles);\n },\n\n readFile: (fileName: string) => {\n addDependee(fileName);\n\n const cache = sourcesFileCache.getOrCreate(fileName);\n if (cache.content === undefined) {\n cache.content = compilerHost.readFile.call(this, fileName);\n }\n return cache.content;\n },\n\n resolveModuleNames: (moduleNames: string[], containingFile: string) => {\n return moduleNames.map(moduleName => {\n const { resolvedModule } = ts.resolveModuleName(\n moduleName,\n ensureUnixPath(containingFile),\n compilerOptions,\n compilerHost,\n moduleResolutionCache,\n );\n\n return resolvedModule;\n });\n },\n\n resourceNameToFileName: (resourceName: string, containingFilePath: string) => {\n const resourcePath = path.resolve(path.dirname(containingFilePath), resourceName);\n const containingNode = getNode(containingFilePath);\n const resourceNode = getNode(resourcePath);\n containingNode.dependsOn(resourceNode);\n\n return resourcePath;\n },\n\n readResource: async (fileName: string) => {\n addDependee(fileName);\n\n const cache = sourcesFileCache.getOrCreate(fileName);\n if (cache.content === undefined) {\n if (/(?:html?|svg)$/.test(path.extname(fileName))) {\n // template\n cache.content = compilerHost.readFile.call(this, fileName);\n } else {\n // stylesheet\n cache.content = await stylesheetProcessor.process(fileName);\n }\n\n if (cache.content === undefined) {\n throw new Error(`Cannot read file ${fileName}.`);\n };\n\n cache.exists = true;\n }\n\n return cache.content;\n },\n };\n}\n\nexport function augmentProgramWithVersioning(program: ts.Program): void {\n const baseGetSourceFiles = program.getSourceFiles;\n program.getSourceFiles = function (...parameters) {\n const files: readonly (ts.SourceFile & { version?: string })[] = baseGetSourceFiles(\n ...parameters,\n );\n\n for (const file of files) {\n if (file.version === undefined) {\n file.version = createHash('sha256').update(file.text).digest('hex');\n }\n }\n\n return files;\n };\n}\n"]}
|
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
import * as ng from '@angular/compiler-cli';
|
|
2
|
+
import * as ts from 'typescript';
|
|
3
|
+
import * as ivy from '../ivy';
|
|
4
|
+
import { BuildGraph } from '../graph/build-graph';
|
|
5
|
+
import { NgccProcessor } from '../ngc/ngcc-processor';
|
|
6
|
+
export declare function compileSourceFiles(graph: BuildGraph, tsConfig: ng.ParsedConfiguration, moduleResolutionCache: ts.ModuleResolutionCache, extraOptions?: Partial<ng.CompilerOptions>, stylesheetProcessor?: ivy.StylesheetProcessor, ngccProcessor?: NgccProcessor, watch?: boolean): Promise<void>;
|
|
@@ -0,0 +1,123 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.compileSourceFiles = void 0;
|
|
4
|
+
const ng = require("@angular/compiler-cli");
|
|
5
|
+
const api_1 = require("@angular/compiler-cli/src/ngtsc/typecheck/api");
|
|
6
|
+
const program_1 = require("@angular/compiler-cli/src/ngtsc/program");
|
|
7
|
+
const ts = require("typescript");
|
|
8
|
+
const log = require("../utils/log");
|
|
9
|
+
const cache_compiler_host_1 = require("./cache-compiler-host");
|
|
10
|
+
const nodes_1 = require("../ng-package/nodes");
|
|
11
|
+
const ngcc_transform_compiler_host_1 = require("../ts/ngcc-transform-compiler-host");
|
|
12
|
+
async function compileSourceFiles(graph, tsConfig, moduleResolutionCache, extraOptions, stylesheetProcessor, ngccProcessor, watch) {
|
|
13
|
+
log.debug(`ngc (v${ng.VERSION.full})`);
|
|
14
|
+
const tsConfigOptions = { ...tsConfig.options, ...extraOptions };
|
|
15
|
+
const entryPoint = graph.find(nodes_1.isEntryPointInProgress());
|
|
16
|
+
const tsCompilerHost = ngcc_transform_compiler_host_1.ngccTransformCompilerHost(cache_compiler_host_1.cacheCompilerHost(graph, entryPoint, tsConfigOptions, moduleResolutionCache, stylesheetProcessor), tsConfigOptions, ngccProcessor, moduleResolutionCache);
|
|
17
|
+
const cache = entryPoint.cache;
|
|
18
|
+
const sourceFileCache = cache.sourcesFileCache;
|
|
19
|
+
// Create the Angular specific program that contains the Angular compiler
|
|
20
|
+
const angularProgram = new program_1.NgtscProgram(tsConfig.rootNames, tsConfigOptions, tsCompilerHost, cache.oldNgtscProgram);
|
|
21
|
+
const angularCompiler = angularProgram.compiler;
|
|
22
|
+
const { ignoreForDiagnostics, ignoreForEmit } = angularCompiler;
|
|
23
|
+
// SourceFile versions are required for builder programs.
|
|
24
|
+
// The wrapped host inside NgtscProgram adds additional files that will not have versions.
|
|
25
|
+
const typeScriptProgram = angularProgram.getTsProgram();
|
|
26
|
+
cache_compiler_host_1.augmentProgramWithVersioning(typeScriptProgram);
|
|
27
|
+
let builder;
|
|
28
|
+
if (watch) {
|
|
29
|
+
builder = cache.oldBuilder = ts.createEmitAndSemanticDiagnosticsBuilderProgram(typeScriptProgram, tsCompilerHost, cache.oldBuilder);
|
|
30
|
+
cache.oldNgtscProgram = angularProgram;
|
|
31
|
+
}
|
|
32
|
+
else {
|
|
33
|
+
// When not in watch mode, the startup cost of the incremental analysis can be avoided by
|
|
34
|
+
// using an abstract builder that only wraps a TypeScript program.
|
|
35
|
+
builder = ts.createAbstractBuilder(typeScriptProgram, tsCompilerHost);
|
|
36
|
+
}
|
|
37
|
+
// Update semantic diagnostics cache
|
|
38
|
+
const affectedFiles = new Set();
|
|
39
|
+
// Analyze affected files when in watch mode for incremental type checking
|
|
40
|
+
if ('getSemanticDiagnosticsOfNextAffectedFile' in builder) {
|
|
41
|
+
while (true) {
|
|
42
|
+
const result = builder.getSemanticDiagnosticsOfNextAffectedFile(undefined, sourceFile => {
|
|
43
|
+
// If the affected file is a TTC shim, add the shim's original source file.
|
|
44
|
+
// This ensures that changes that affect TTC are typechecked even when the changes
|
|
45
|
+
// are otherwise unrelated from a TS perspective and do not result in Ivy codegen changes.
|
|
46
|
+
// For example, changing @Input property types of a directive used in another component's
|
|
47
|
+
// template.
|
|
48
|
+
if (ignoreForDiagnostics.has(sourceFile) && sourceFile.fileName.endsWith('.ngtypecheck.ts')) {
|
|
49
|
+
// This file name conversion relies on internal compiler logic and should be converted
|
|
50
|
+
// to an official method when available. 15 is length of `.ngtypecheck.ts`
|
|
51
|
+
const originalFilename = sourceFile.fileName.slice(0, -15) + '.ts';
|
|
52
|
+
const originalSourceFile = builder.getSourceFile(originalFilename);
|
|
53
|
+
if (originalSourceFile) {
|
|
54
|
+
affectedFiles.add(originalSourceFile);
|
|
55
|
+
}
|
|
56
|
+
return true;
|
|
57
|
+
}
|
|
58
|
+
return false;
|
|
59
|
+
});
|
|
60
|
+
if (!result) {
|
|
61
|
+
break;
|
|
62
|
+
}
|
|
63
|
+
affectedFiles.add(result.affected);
|
|
64
|
+
}
|
|
65
|
+
}
|
|
66
|
+
// Collect program level diagnostics
|
|
67
|
+
const allDiagnostics = [
|
|
68
|
+
...angularCompiler.getOptionDiagnostics(),
|
|
69
|
+
...builder.getOptionsDiagnostics(),
|
|
70
|
+
...builder.getGlobalDiagnostics(),
|
|
71
|
+
];
|
|
72
|
+
// Required to support asynchronous resource loading
|
|
73
|
+
// Must be done before creating transformers or getting template diagnostics
|
|
74
|
+
await angularCompiler.analyzeAsync();
|
|
75
|
+
// Collect source file specific diagnostics
|
|
76
|
+
for (const sourceFile of builder.getSourceFiles()) {
|
|
77
|
+
if (!ignoreForDiagnostics.has(sourceFile)) {
|
|
78
|
+
allDiagnostics.push(...builder.getSyntacticDiagnostics(sourceFile), ...builder.getSemanticDiagnostics(sourceFile));
|
|
79
|
+
}
|
|
80
|
+
if (sourceFile.isDeclarationFile) {
|
|
81
|
+
continue;
|
|
82
|
+
}
|
|
83
|
+
// Collect sources that are required to be emitted
|
|
84
|
+
if (!ignoreForEmit.has(sourceFile) && !angularCompiler.incrementalDriver.safeToSkipEmit(sourceFile)) {
|
|
85
|
+
// If required to emit, diagnostics may have also changed
|
|
86
|
+
if (!ignoreForDiagnostics.has(sourceFile)) {
|
|
87
|
+
affectedFiles.add(sourceFile);
|
|
88
|
+
}
|
|
89
|
+
}
|
|
90
|
+
else if (sourceFileCache && !affectedFiles.has(sourceFile) && !ignoreForDiagnostics.has(sourceFile)) {
|
|
91
|
+
// Use cached Angular diagnostics for unchanged and unaffected files
|
|
92
|
+
const angularDiagnostics = sourceFileCache.getAngularDiagnostics(sourceFile);
|
|
93
|
+
if (angularDiagnostics === null || angularDiagnostics === void 0 ? void 0 : angularDiagnostics.length) {
|
|
94
|
+
allDiagnostics.push(...angularDiagnostics);
|
|
95
|
+
}
|
|
96
|
+
}
|
|
97
|
+
}
|
|
98
|
+
// Collect new Angular diagnostics for files affected by changes
|
|
99
|
+
for (const affectedFile of affectedFiles) {
|
|
100
|
+
const angularDiagnostics = angularCompiler.getDiagnosticsForFile(affectedFile, api_1.OptimizeFor.WholeProgram);
|
|
101
|
+
allDiagnostics.push(...angularDiagnostics);
|
|
102
|
+
sourceFileCache.updateAngularDiagnostics(affectedFile, angularDiagnostics);
|
|
103
|
+
}
|
|
104
|
+
// if we have an error we don't want to transpile.
|
|
105
|
+
const exitCode = ng.exitCodeFromResult(allDiagnostics);
|
|
106
|
+
const formattedDiagnostics = ng.formatDiagnostics(allDiagnostics);
|
|
107
|
+
if (exitCode === 0) {
|
|
108
|
+
if (formattedDiagnostics.length) {
|
|
109
|
+
log.msg(formattedDiagnostics);
|
|
110
|
+
}
|
|
111
|
+
const transformers = angularCompiler.prepareEmit().transformers;
|
|
112
|
+
for (const sourceFile of builder.getSourceFiles()) {
|
|
113
|
+
if (!ignoreForEmit.has(sourceFile)) {
|
|
114
|
+
builder.emit(sourceFile, undefined, undefined, undefined, transformers);
|
|
115
|
+
}
|
|
116
|
+
}
|
|
117
|
+
}
|
|
118
|
+
else {
|
|
119
|
+
throw new Error(formattedDiagnostics);
|
|
120
|
+
}
|
|
121
|
+
}
|
|
122
|
+
exports.compileSourceFiles = compileSourceFiles;
|
|
123
|
+
//# sourceMappingURL=compile-source-files.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"compile-source-files.js","sourceRoot":"","sources":["../../../src/lib/ivy/compile-source-files.ts"],"names":[],"mappings":";;;AAAA,4CAA4C;AAC5C,uEAA4E;AAC5E,qEAAuE;AACvE,iCAAiC;AACjC,oCAAoC;AAEpC,+DAAwF;AAExF,+CAA6E;AAE7E,qFAA+E;AAExE,KAAK,UAAU,kBAAkB,CACtC,KAAiB,EACjB,QAAgC,EAChC,qBAA+C,EAC/C,YAA0C,EAC1C,mBAA6C,EAC7C,aAA6B,EAC7B,KAAe;IAEf,GAAG,CAAC,KAAK,CAAC,SAAS,EAAE,CAAC,OAAO,CAAC,IAAI,GAAG,CAAC,CAAC;IAEvC,MAAM,eAAe,GAAuB,EAAE,GAAG,QAAQ,CAAC,OAAO,EAAE,GAAG,YAAY,EAAE,CAAC;IACrF,MAAM,UAAU,GAAmB,KAAK,CAAC,IAAI,CAAC,8BAAsB,EAAE,CAAC,CAAC;IAExE,MAAM,cAAc,GA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AAW,EAAE,CAAC,YAAY,CAAC;QAChE,KAAK,MAAM,UAAU,IAAI,OAAO,CAAC,cAAc,EAAE,EAAE;YACjD,IAAI,CAAC,aAAa,CAAC,GAAG,CAAC,UAAU,CAAC,EAAE;gBAClC,OAAO,CAAC,IAAI,CAAC,UAAU,EAAE,SAAS,EAAE,SAAS,EAAE,SAAS,EAAE,YAAY,CAAC,CAAC;aACzE;SACF;KACF;SAAM;QACL,MAAM,IAAI,KAAK,CAAC,oBAAoB,CAAC,CAAC;KACvC;AACH,CAAC;AApJD,gDAoJC","sourcesContent":["import * as ng from '@angular/compiler-cli';\nimport { OptimizeFor } from '@angular/compiler-cli/src/ngtsc/typecheck/api';\nimport { NgtscProgram } from '@angular/compiler-cli/src/ngtsc/program';\nimport * as ts from 'typescript';\nimport * as log from '../utils/log';\nimport * as ivy from '../ivy';\nimport { augmentProgramWithVersioning, cacheCompilerHost } from './cache-compiler-host';\nimport { BuildGraph } from '../graph/build-graph';\nimport { EntryPointNode, isEntryPointInProgress } from '../ng-package/nodes';\nimport { NgccProcessor } from '../ngc/ngcc-processor';\nimport { ngccTransformCompilerHost } from '../ts/ngcc-transform-compiler-host';\n\nexport async function compileSourceFiles(\n graph: BuildGraph,\n tsConfig: ng.ParsedConfiguration,\n moduleResolutionCache: ts.ModuleResolutionCache,\n extraOptions?: Partial<ng.CompilerOptions>,\n stylesheetProcessor?: ivy.StylesheetProcessor,\n ngccProcessor?: NgccProcessor,\n watch?: boolean,\n) {\n log.debug(`ngc (v${ng.VERSION.full})`);\n\n const tsConfigOptions: ng.CompilerOptions = { ...tsConfig.options, ...extraOptions };\n const entryPoint: EntryPointNode = graph.find(isEntryPointInProgress());\n\n const tsCompilerHost = ngccTransformCompilerHost(\n cacheCompilerHost(graph, entryPoint, tsConfigOptions, moduleResolutionCache, stylesheetProcessor),\n tsConfigOptions,\n ngccProcessor,\n moduleResolutionCache,\n );\n\n const cache = entryPoint.cache;\n const sourceFileCache = cache.sourcesFileCache;\n\n // Create the Angular specific program that contains the Angular compiler\n const angularProgram = new NgtscProgram(tsConfig.rootNames, tsConfigOptions, tsCompilerHost, cache.oldNgtscProgram);\n\n const angularCompiler = angularProgram.compiler;\n const { ignoreForDiagnostics, ignoreForEmit } = angularCompiler;\n\n // SourceFile versions are required for builder programs.\n // The wrapped host inside NgtscProgram adds additional files that will not have versions.\n const typeScriptProgram = angularProgram.getTsProgram();\n augmentProgramWithVersioning(typeScriptProgram);\n\n let builder: ts.BuilderProgram | ts.EmitAndSemanticDiagnosticsBuilderProgram;\n if (watch) {\n builder = cache.oldBuilder = ts.createEmitAndSemanticDiagnosticsBuilderProgram(\n typeScriptProgram,\n tsCompilerHost,\n cache.oldBuilder,\n );\n cache.oldNgtscProgram = angularProgram;\n } else {\n // When not in watch mode, the startup cost of the incremental analysis can be avoided by\n // using an abstract builder that only wraps a TypeScript program.\n builder = ts.createAbstractBuilder(typeScriptProgram, tsCompilerHost);\n }\n\n // Update semantic diagnostics cache\n const affectedFiles = new Set<ts.SourceFile>();\n\n // Analyze affected files when in watch mode for incremental type checking\n if ('getSemanticDiagnosticsOfNextAffectedFile' in builder) {\n while (true) {\n const result = builder.getSemanticDiagnosticsOfNextAffectedFile(undefined, sourceFile => {\n // If the affected file is a TTC shim, add the shim's original source file.\n // This ensures that changes that affect TTC are typechecked even when the changes\n // are otherwise unrelated from a TS perspective and do not result in Ivy codegen changes.\n // For example, changing @Input property types of a directive used in another component's\n // template.\n if (ignoreForDiagnostics.has(sourceFile) && sourceFile.fileName.endsWith('.ngtypecheck.ts')) {\n // This file name conversion relies on internal compiler logic and should be converted\n // to an official method when available. 15 is length of `.ngtypecheck.ts`\n const originalFilename = sourceFile.fileName.slice(0, -15) + '.ts';\n const originalSourceFile = builder.getSourceFile(originalFilename);\n if (originalSourceFile) {\n affectedFiles.add(originalSourceFile);\n }\n\n return true;\n }\n\n return false;\n });\n\n if (!result) {\n break;\n }\n\n affectedFiles.add(result.affected as ts.SourceFile);\n }\n }\n\n // Collect program level diagnostics\n const allDiagnostics: ts.Diagnostic[] = [\n ...angularCompiler.getOptionDiagnostics(),\n ...builder.getOptionsDiagnostics(),\n ...builder.getGlobalDiagnostics(),\n ];\n\n // Required to support asynchronous resource loading\n // Must be done before creating transformers or getting template diagnostics\n await angularCompiler.analyzeAsync();\n\n // Collect source file specific diagnostics\n for (const sourceFile of builder.getSourceFiles()) {\n if (!ignoreForDiagnostics.has(sourceFile)) {\n allDiagnostics.push(\n ...builder.getSyntacticDiagnostics(sourceFile),\n ...builder.getSemanticDiagnostics(sourceFile),\n );\n }\n\n if (sourceFile.isDeclarationFile) {\n continue;\n }\n\n // Collect sources that are required to be emitted\n if (!ignoreForEmit.has(sourceFile) && !angularCompiler.incrementalDriver.safeToSkipEmit(sourceFile)) {\n // If required to emit, diagnostics may have also changed\n if (!ignoreForDiagnostics.has(sourceFile)) {\n affectedFiles.add(sourceFile);\n }\n } else if (sourceFileCache && !affectedFiles.has(sourceFile) && !ignoreForDiagnostics.has(sourceFile)) {\n // Use cached Angular diagnostics for unchanged and unaffected files\n const angularDiagnostics = sourceFileCache.getAngularDiagnostics(sourceFile);\n if (angularDiagnostics?.length) {\n allDiagnostics.push(...angularDiagnostics);\n }\n }\n }\n\n // Collect new Angular diagnostics for files affected by changes\n for (const affectedFile of affectedFiles) {\n const angularDiagnostics = angularCompiler.getDiagnosticsForFile(affectedFile, OptimizeFor.WholeProgram);\n\n allDiagnostics.push(...angularDiagnostics);\n sourceFileCache.updateAngularDiagnostics(affectedFile, angularDiagnostics);\n }\n\n // if we have an error we don't want to transpile.\n const exitCode = ng.exitCodeFromResult(allDiagnostics);\n const formattedDiagnostics = ng.formatDiagnostics(allDiagnostics);\n if (exitCode === 0) {\n if (formattedDiagnostics.length) {\n log.msg(formattedDiagnostics);\n }\n\n const transformers = angularCompiler.prepareEmit().transformers;\n for (const sourceFile of builder.getSourceFiles()) {\n if (!ignoreForEmit.has(sourceFile)) {\n builder.emit(sourceFile, undefined, undefined, undefined, transformers);\n }\n }\n } else {\n throw new Error(formattedDiagnostics);\n }\n}\n"]}
|
package/lib/ivy/index.js
ADDED
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.StylesheetProcessor = exports.compileSourceFiles = void 0;
|
|
4
|
+
var compile_source_files_1 = require("./compile-source-files");
|
|
5
|
+
Object.defineProperty(exports, "compileSourceFiles", { enumerable: true, get: function () { return compile_source_files_1.compileSourceFiles; } });
|
|
6
|
+
var stylesheet_processor_1 = require("./styles/stylesheet-processor");
|
|
7
|
+
Object.defineProperty(exports, "StylesheetProcessor", { enumerable: true, get: function () { return stylesheet_processor_1.StylesheetProcessor; } });
|
|
8
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../../src/lib/ivy/index.ts"],"names":[],"mappings":";;;AAAA,+DAA4D;AAAnD,0HAAA,kBAAkB,OAAA;AAC3B,sEAAoE;AAA3D,2HAAA,mBAAmB,OAAA","sourcesContent":["export { compileSourceFiles } from './compile-source-files';\nexport { StylesheetProcessor } from './styles/stylesheet-processor';\n"]}
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
export declare enum CssUrl {
|
|
2
|
+
inline = "inline",
|
|
3
|
+
none = "none"
|
|
4
|
+
}
|
|
5
|
+
export interface Result {
|
|
6
|
+
css: string;
|
|
7
|
+
warnings: string[];
|
|
8
|
+
error?: string;
|
|
9
|
+
}
|
|
10
|
+
export declare class StylesheetProcessor {
|
|
11
|
+
private readonly basePath;
|
|
12
|
+
private readonly cssUrl?;
|
|
13
|
+
private readonly styleIncludePaths?;
|
|
14
|
+
private browserslistData;
|
|
15
|
+
private postCssProcessor;
|
|
16
|
+
constructor(basePath: string, cssUrl?: CssUrl, styleIncludePaths?: string[]);
|
|
17
|
+
process(filePath: string): Promise<string>;
|
|
18
|
+
private createPostCssPlugins;
|
|
19
|
+
private renderCss;
|
|
20
|
+
}
|
|
@@ -0,0 +1,170 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.StylesheetProcessor = exports.CssUrl = void 0;
|
|
4
|
+
const browserslist = require("browserslist");
|
|
5
|
+
const findCacheDirectory = require("find-cache-dir");
|
|
6
|
+
const os_1 = require("os");
|
|
7
|
+
const cacache = require("cacache");
|
|
8
|
+
const postcss_1 = require("postcss");
|
|
9
|
+
const postcssUrl = require("postcss-url");
|
|
10
|
+
const cssnano = require("cssnano");
|
|
11
|
+
const postcssPresetEnv = require("postcss-preset-env");
|
|
12
|
+
const log = require("../../utils/log");
|
|
13
|
+
const fs_1 = require("../../utils/fs");
|
|
14
|
+
const crypto_1 = require("crypto");
|
|
15
|
+
const path_1 = require("path");
|
|
16
|
+
var CssUrl;
|
|
17
|
+
(function (CssUrl) {
|
|
18
|
+
CssUrl["inline"] = "inline";
|
|
19
|
+
CssUrl["none"] = "none";
|
|
20
|
+
})(CssUrl = exports.CssUrl || (exports.CssUrl = {}));
|
|
21
|
+
const cachePath = findCacheDirectory({ name: 'ng-packagr-styles' }) || os_1.tmpdir();
|
|
22
|
+
let ngPackagrVersion;
|
|
23
|
+
try {
|
|
24
|
+
ngPackagrVersion = require('../../../package.json').version;
|
|
25
|
+
}
|
|
26
|
+
catch {
|
|
27
|
+
// dev path
|
|
28
|
+
ngPackagrVersion = require('../../../../package.json').version;
|
|
29
|
+
}
|
|
30
|
+
class StylesheetProcessor {
|
|
31
|
+
constructor(basePath, cssUrl, styleIncludePaths) {
|
|
32
|
+
this.basePath = basePath;
|
|
33
|
+
this.cssUrl = cssUrl;
|
|
34
|
+
this.styleIncludePaths = styleIncludePaths;
|
|
35
|
+
log.debug(`determine browserslist for ${this.basePath}`);
|
|
36
|
+
this.browserslistData = browserslist(undefined, { path: this.basePath });
|
|
37
|
+
this.postCssProcessor = this.createPostCssPlugins();
|
|
38
|
+
}
|
|
39
|
+
async process(filePath) {
|
|
40
|
+
const content = await fs_1.readFile(filePath, 'utf8');
|
|
41
|
+
let key;
|
|
42
|
+
if (!content.includes('@import') && !content.includes('@use')) {
|
|
43
|
+
// No transitive deps, we can cache more aggressively.
|
|
44
|
+
key = generateKey(content, this.browserslistData);
|
|
45
|
+
const result = await readCacheEntry(cachePath, key);
|
|
46
|
+
if (result) {
|
|
47
|
+
result.warnings.forEach(msg => log.warn(msg));
|
|
48
|
+
return result.css;
|
|
49
|
+
}
|
|
50
|
+
}
|
|
51
|
+
// Render pre-processor language (sass, styl, less)
|
|
52
|
+
const renderedCss = await this.renderCss(filePath, content);
|
|
53
|
+
// We cannot cache CSS re-rendering phase, because a transitive dependency via (@import) can case different CSS output.
|
|
54
|
+
// Example a change in a mixin or SCSS variable.
|
|
55
|
+
if (!key) {
|
|
56
|
+
key = generateKey(renderedCss, this.browserslistData);
|
|
57
|
+
}
|
|
58
|
+
const cachedResult = await readCacheEntry(cachePath, key);
|
|
59
|
+
if (cachedResult) {
|
|
60
|
+
cachedResult.warnings.forEach(msg => log.warn(msg));
|
|
61
|
+
return cachedResult.css;
|
|
62
|
+
}
|
|
63
|
+
// Render postcss (autoprefixing and friends)
|
|
64
|
+
const result = await this.postCssProcessor.process(renderedCss, {
|
|
65
|
+
from: filePath,
|
|
66
|
+
to: filePath.replace(path_1.extname(filePath), '.css'),
|
|
67
|
+
});
|
|
68
|
+
const warnings = result.warnings().map(w => w.toString());
|
|
69
|
+
// Add to cache
|
|
70
|
+
await cacache.put(cachePath, key, JSON.stringify({
|
|
71
|
+
css: result.css,
|
|
72
|
+
warnings,
|
|
73
|
+
}));
|
|
74
|
+
warnings.forEach(msg => log.warn(msg));
|
|
75
|
+
return result.css;
|
|
76
|
+
}
|
|
77
|
+
createPostCssPlugins() {
|
|
78
|
+
const postCssPlugins = [];
|
|
79
|
+
if (this.cssUrl !== CssUrl.none) {
|
|
80
|
+
postCssPlugins.push(postcssUrl({ url: this.cssUrl }));
|
|
81
|
+
}
|
|
82
|
+
postCssPlugins.push(postcssPresetEnv({
|
|
83
|
+
browsers: this.browserslistData,
|
|
84
|
+
autoprefixer: true,
|
|
85
|
+
stage: 3,
|
|
86
|
+
}), cssnano({
|
|
87
|
+
preset: [
|
|
88
|
+
'default',
|
|
89
|
+
{
|
|
90
|
+
// Disable SVG optimizations, as this can cause optimizations which are not compatible in all browsers.
|
|
91
|
+
svgo: false,
|
|
92
|
+
// Disable `calc` optimizations, due to several issues. #16910, #16875, #17890
|
|
93
|
+
calc: false,
|
|
94
|
+
// Disable CSS rules sorted due to several issues #20693, https://github.com/ionic-team/ionic-framework/issues/23266 and https://github.com/cssnano/cssnano/issues/1054
|
|
95
|
+
cssDeclarationSorter: false,
|
|
96
|
+
},
|
|
97
|
+
],
|
|
98
|
+
}));
|
|
99
|
+
return postcss_1.default(postCssPlugins);
|
|
100
|
+
}
|
|
101
|
+
async renderCss(filePath, css) {
|
|
102
|
+
const ext = path_1.extname(filePath);
|
|
103
|
+
switch (ext) {
|
|
104
|
+
case '.sass':
|
|
105
|
+
case '.scss': {
|
|
106
|
+
/*
|
|
107
|
+
* Please be aware of the few differences in behaviour https://github.com/sass/dart-sass/blob/master/README.md#behavioral-differences-from-ruby-sass
|
|
108
|
+
* By default `npm install` will install sass.
|
|
109
|
+
* To use node-sass you need to use:
|
|
110
|
+
* Npm:
|
|
111
|
+
* `npm install node-sass --save-dev`
|
|
112
|
+
* Yarn:
|
|
113
|
+
* `yarn add node-sass --dev`
|
|
114
|
+
*/
|
|
115
|
+
let sassCompiler;
|
|
116
|
+
try {
|
|
117
|
+
sassCompiler = require('node-sass'); // Check if node-sass is explicitly included.
|
|
118
|
+
}
|
|
119
|
+
catch {
|
|
120
|
+
sassCompiler = await Promise.resolve().then(() => require('sass'));
|
|
121
|
+
}
|
|
122
|
+
return sassCompiler
|
|
123
|
+
.renderSync({
|
|
124
|
+
file: filePath,
|
|
125
|
+
data: css,
|
|
126
|
+
indentedSyntax: '.sass' === ext,
|
|
127
|
+
importer: await Promise.resolve().then(() => require('node-sass-tilde-importer')),
|
|
128
|
+
includePaths: this.styleIncludePaths,
|
|
129
|
+
})
|
|
130
|
+
.css.toString();
|
|
131
|
+
}
|
|
132
|
+
case '.less': {
|
|
133
|
+
const { css: content } = await (await Promise.resolve().then(() => require('less'))).render(css, {
|
|
134
|
+
filename: filePath,
|
|
135
|
+
javascriptEnabled: true,
|
|
136
|
+
paths: this.styleIncludePaths,
|
|
137
|
+
});
|
|
138
|
+
return content;
|
|
139
|
+
}
|
|
140
|
+
case '.styl':
|
|
141
|
+
case '.stylus': {
|
|
142
|
+
const stylus = await Promise.resolve().then(() => require('stylus'));
|
|
143
|
+
return (stylus(css)
|
|
144
|
+
// add paths for resolve
|
|
145
|
+
.set('paths', [this.basePath, '.', ...this.styleIncludePaths, 'node_modules'])
|
|
146
|
+
// add support for resolving plugins from node_modules
|
|
147
|
+
.set('filename', filePath)
|
|
148
|
+
// turn on url resolver in stylus, same as flag --resolve-url
|
|
149
|
+
.set('resolve url', true)
|
|
150
|
+
.define('url', stylus.resolver(undefined))
|
|
151
|
+
.render());
|
|
152
|
+
}
|
|
153
|
+
case '.css':
|
|
154
|
+
default:
|
|
155
|
+
return css;
|
|
156
|
+
}
|
|
157
|
+
}
|
|
158
|
+
}
|
|
159
|
+
exports.StylesheetProcessor = StylesheetProcessor;
|
|
160
|
+
function generateKey(content, browserslistData) {
|
|
161
|
+
return crypto_1.createHash('sha1').update(ngPackagrVersion).update(content).update(browserslistData.join('')).digest('base64');
|
|
162
|
+
}
|
|
163
|
+
async function readCacheEntry(cachePath, key) {
|
|
164
|
+
const entry = await cacache.get.info(cachePath, key);
|
|
165
|
+
if (entry) {
|
|
166
|
+
return JSON.parse(await fs_1.readFile(entry.path, 'utf8'));
|
|
167
|
+
}
|
|
168
|
+
return undefined;
|
|
169
|
+
}
|
|
170
|
+
//# sourceMappingURL=stylesheet-processor.js.map
|
|
@@ -0,0 +1 @@
|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,CAAC,SAAS,CAAC,CAAC;qBACzC,MAAM,EAAE,CACZ,CAAC;aACH;YACD,KAAK,MAAM,CAAC;YACZ;gBACE,OAAO,GAAG,CAAC;SACd;IACH,CAAC;CACF;AA9JD,kDA8JC;AAED,SAAS,WAAW,CAAC,OAAe,EAAE,gBAA0B;IAC9D,OAAO,mBAAU,CAAC,MAAM,CAAC,CAAC,MAAM,CAAC,gBAAgB,CAAC,CAAC,MAAM,CAAC,OAAO,CAAC,CAAC,MAAM,CAAC,gBAAgB,CAAC,IAAI,CAAC,EAAE,CAAC,CAAC,CAAC,MAAM,CAAC,QAAQ,CAAC,CAAC;AACxH,CAAC;AAED,KAAK,UAAU,cAAc,CAAC,SAAiB,EAAE,GAAW;IAC1D,MAAM,KAAK,GAAG,MAAM,OAAO,CAAC,GAAG,CAAC,IAAI,CAAC,SAAS,EAAE,GAAG,CAAC,CAAC;IACrD,IAAI,KAAK,EAAE;QACT,OAAO,IAAI,CAAC,KAAK,CAAC,MAAM,aAAQ,CAAC,KAAK,CAAC,IAAI,EAAE,MAAM,CAAC,CAAC,CAAC;KACvD;IAED,OAAO,SAAS,CAAC;AACnB,CAAC","sourcesContent":["import * as browserslist from 'browserslist';\nimport * as findCacheDirectory from 'find-cache-dir';\nimport { tmpdir } from 'os';\nimport * as cacache from 'cacache';\nimport postcss from 'postcss';\nimport * as postcssUrl from 'postcss-url';\nimport * as cssnano from 'cssnano';\nimport * as postcssPresetEnv from 'postcss-preset-env';\nimport * as log from '../../utils/log';\nimport { readFile } from '../../utils/fs';\nimport { createHash } from 'crypto';\nimport { extname } from 'path';\n\nexport enum CssUrl {\n inline = 'inline',\n none = 'none',\n}\n\nexport interface Result {\n css: string;\n warnings: string[];\n error?: string;\n}\n\nconst cachePath = findCacheDirectory({ name: 'ng-packagr-styles' }) || tmpdir();\nlet ngPackagrVersion: string | undefined;\ntry {\n ngPackagrVersion = require('../../../package.json').version;\n} catch {\n // dev path\n ngPackagrVersion = require('../../../../package.json').version;\n}\n\nexport class StylesheetProcessor {\n private browserslistData: string[];\n private postCssProcessor: ReturnType<typeof postcss>;\n\n constructor(\n private readonly basePath: string,\n private readonly cssUrl?: CssUrl,\n private readonly styleIncludePaths?: string[],\n ) {\n log.debug(`determine browserslist for ${this.basePath}`);\n this.browserslistData = browserslist(undefined, { path: this.basePath });\n this.postCssProcessor = this.createPostCssPlugins();\n }\n\n async process(filePath: string): Promise<string> {\n const content = await readFile(filePath, 'utf8');\n let key: string | undefined;\n\n if (!content.includes('@import') && !content.includes('@use')) {\n // No transitive deps, we can cache more aggressively.\n key = generateKey(content, this.browserslistData);\n const result = await readCacheEntry(cachePath, key);\n if (result) {\n result.warnings.forEach(msg => log.warn(msg));\n return result.css;\n }\n }\n\n // Render pre-processor language (sass, styl, less)\n const renderedCss = await this.renderCss(filePath, content);\n\n // We cannot cache CSS re-rendering phase, because a transitive dependency via (@import) can case different CSS output.\n // Example a change in a mixin or SCSS variable.\n if (!key) {\n key = generateKey(renderedCss, this.browserslistData);\n }\n\n const cachedResult = await readCacheEntry(cachePath, key);\n if (cachedResult) {\n cachedResult.warnings.forEach(msg => log.warn(msg));\n return cachedResult.css;\n }\n\n // Render postcss (autoprefixing and friends)\n const result = await this.postCssProcessor.process(renderedCss, {\n from: filePath,\n to: filePath.replace(extname(filePath), '.css'),\n });\n\n const warnings = result.warnings().map(w => w.toString());\n // Add to cache\n await cacache.put(\n cachePath,\n key,\n JSON.stringify({\n css: result.css,\n warnings,\n }),\n );\n\n warnings.forEach(msg => log.warn(msg));\n return result.css;\n }\n\n private createPostCssPlugins(): ReturnType<typeof postcss> {\n const postCssPlugins = [];\n if (this.cssUrl !== CssUrl.none) {\n postCssPlugins.push(postcssUrl({ url: this.cssUrl }));\n }\n\n postCssPlugins.push(\n postcssPresetEnv({\n browsers: this.browserslistData,\n autoprefixer: true,\n stage: 3,\n }),\n cssnano({\n preset: [\n 'default',\n {\n // Disable SVG optimizations, as this can cause optimizations which are not compatible in all browsers.\n svgo: false,\n // Disable `calc` optimizations, due to several issues. #16910, #16875, #17890\n calc: false,\n // Disable CSS rules sorted due to several issues #20693, https://github.com/ionic-team/ionic-framework/issues/23266 and https://github.com/cssnano/cssnano/issues/1054\n cssDeclarationSorter: false,\n },\n ],\n }),\n );\n\n return postcss(postCssPlugins);\n }\n\n private async renderCss(filePath: string, css: string): Promise<string> {\n const ext = extname(filePath);\n\n switch (ext) {\n case '.sass':\n case '.scss': {\n /*\n * Please be aware of the few differences in behaviour https://github.com/sass/dart-sass/blob/master/README.md#behavioral-differences-from-ruby-sass\n * By default `npm install` will install sass.\n * To use node-sass you need to use:\n * Npm:\n * `npm install node-sass --save-dev`\n * Yarn:\n * `yarn add node-sass --dev`\n */\n let sassCompiler: any | undefined;\n try {\n sassCompiler = require('node-sass'); // Check if node-sass is explicitly included.\n } catch {\n sassCompiler = await import('sass');\n }\n\n return sassCompiler\n .renderSync({\n file: filePath,\n data: css,\n indentedSyntax: '.sass' === ext,\n importer: await import('node-sass-tilde-importer'),\n includePaths: this.styleIncludePaths,\n })\n .css.toString();\n }\n case '.less': {\n const { css: content } = await (\n await import('less')\n ).render(css, {\n filename: filePath,\n javascriptEnabled: true,\n paths: this.styleIncludePaths,\n });\n\n return content;\n }\n case '.styl':\n case '.stylus': {\n const stylus = await import('stylus');\n\n return (\n stylus(css)\n // add paths for resolve\n .set('paths', [this.basePath, '.', ...this.styleIncludePaths, 'node_modules'])\n // add support for resolving plugins from node_modules\n .set('filename', filePath)\n // turn on url resolver in stylus, same as flag --resolve-url\n .set('resolve url', true)\n .define('url', stylus.resolver(undefined))\n .render()\n );\n }\n case '.css':\n default:\n return css;\n }\n }\n}\n\nfunction generateKey(content: string, browserslistData: string[]): string {\n return createHash('sha1').update(ngPackagrVersion).update(content).update(browserslistData.join('')).digest('base64');\n}\n\nasync function readCacheEntry(cachePath: string, key: string): Promise<Result | undefined> {\n const entry = await cacache.get.info(cachePath, key);\n if (entry) {\n return JSON.parse(await readFile(entry.path, 'utf8'));\n }\n\n return undefined;\n}\n"]}
|
|
@@ -5,11 +5,15 @@ const injection_js_1 = require("injection-js");
|
|
|
5
5
|
const transform_di_1 = require("../../graph/transform.di");
|
|
6
6
|
const compile_ngc_transform_1 = require("./compile-ngc.transform");
|
|
7
7
|
const stylesheet_processor_di_1 = require("../../styles/stylesheet-processor.di");
|
|
8
|
+
const options_di_1 = require("../options.di");
|
|
8
9
|
exports.COMPILE_NGC_TOKEN = new injection_js_1.InjectionToken(`ng.v5.compileNgcTransform`);
|
|
9
10
|
exports.COMPILE_NGC_TRANSFORM = transform_di_1.provideTransform({
|
|
10
11
|
provide: exports.COMPILE_NGC_TOKEN,
|
|
11
12
|
useFactory: compile_ngc_transform_1.compileNgcTransformFactory,
|
|
12
|
-
deps: [
|
|
13
|
+
deps: [
|
|
14
|
+
stylesheet_processor_di_1.STYLESHEET_PROCESSOR_TOKEN,
|
|
15
|
+
options_di_1.OPTIONS_TOKEN,
|
|
16
|
+
],
|
|
13
17
|
});
|
|
14
18
|
exports.COMPILE_NGC_PROVIDERS = [stylesheet_processor_di_1.STYLESHEET_PROCESSOR, exports.COMPILE_NGC_TRANSFORM];
|
|
15
19
|
//# sourceMappingURL=compile-ngc.di.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"compile-ngc.di.js","sourceRoot":"","sources":["../../../../src/lib/ng-package/entry-point/compile-ngc.di.ts"],"names":[],"mappings":";;;AAAA,+CAAwD;AAExD,2DAA+E;AAC/E,mEAAqE;AACrE,kFAAwG;
|
|
1
|
+
{"version":3,"file":"compile-ngc.di.js","sourceRoot":"","sources":["../../../../src/lib/ng-package/entry-point/compile-ngc.di.ts"],"names":[],"mappings":";;;AAAA,+CAAwD;AAExD,2DAA+E;AAC/E,mEAAqE;AACrE,kFAAwG;AACxG,8CAA8C;AAEjC,QAAA,iBAAiB,GAAG,IAAI,6BAAc,CAAY,2BAA2B,CAAC,CAAC;AAE/E,QAAA,qBAAqB,GAAsB,+BAAgB,CAAC;IACvE,OAAO,EAAE,yBAAiB;IAC1B,UAAU,EAAE,kDAA0B;IACtC,IAAI,EAAE;QACJ,oDAA0B;QAC1B,0BAAa;KACd;CACF,CAAC,CAAC;AAEU,QAAA,qBAAqB,GAAe,CAAC,8CAAoB,EAAE,6BAAqB,CAAC,CAAC","sourcesContent":["import { InjectionToken, Provider } from 'injection-js';\nimport { Transform } from '../../graph/transform';\nimport { TransformProvider, provideTransform } from '../../graph/transform.di';\nimport { compileNgcTransformFactory } from './compile-ngc.transform';\nimport { STYLESHEET_PROCESSOR_TOKEN, STYLESHEET_PROCESSOR } from '../../styles/stylesheet-processor.di';\nimport { OPTIONS_TOKEN } from '../options.di';\n\nexport const COMPILE_NGC_TOKEN = new InjectionToken<Transform>(`ng.v5.compileNgcTransform`);\n\nexport const COMPILE_NGC_TRANSFORM: TransformProvider = provideTransform({\n provide: COMPILE_NGC_TOKEN,\n useFactory: compileNgcTransformFactory,\n deps: [\n STYLESHEET_PROCESSOR_TOKEN,\n OPTIONS_TOKEN,\n ],\n});\n\nexport const COMPILE_NGC_PROVIDERS: Provider[] = [STYLESHEET_PROCESSOR, COMPILE_NGC_TRANSFORM];\n"]}
|
|
@@ -1,3 +1,4 @@
|
|
|
1
1
|
import { Transform } from '../../graph/transform';
|
|
2
2
|
import { StylesheetProcessor as StylesheetProcessorClass } from '../../styles/stylesheet-processor';
|
|
3
|
-
|
|
3
|
+
import { NgPackagrOptions } from '../options.di';
|
|
4
|
+
export declare const compileNgcTransformFactory: (StylesheetProcessor: typeof StylesheetProcessorClass, options: NgPackagrOptions) => Transform;
|
|
@@ -7,14 +7,20 @@ const ora = require("ora");
|
|
|
7
7
|
const transform_1 = require("../../graph/transform");
|
|
8
8
|
const compile_source_files_1 = require("../../ngc/compile-source-files");
|
|
9
9
|
const ngcc_processor_1 = require("../../ngc/ngcc-processor");
|
|
10
|
+
const ivy = require("../../ivy");
|
|
10
11
|
const tsconfig_1 = require("../../ts/tsconfig");
|
|
11
12
|
const nodes_1 = require("../nodes");
|
|
12
|
-
|
|
13
|
+
function isEnabled(variable) {
|
|
14
|
+
return typeof variable === 'string' && (variable === '1' || variable.toLowerCase() === 'true');
|
|
15
|
+
}
|
|
16
|
+
const compileNgcTransformFactory = (StylesheetProcessor, options) => {
|
|
13
17
|
return transform_1.transformFromPromise(async (graph) => {
|
|
18
|
+
var _a, _b;
|
|
19
|
+
var _c, _d;
|
|
14
20
|
const spinner = ora({
|
|
15
21
|
hideCursor: false,
|
|
16
22
|
discardStdin: false,
|
|
17
|
-
})
|
|
23
|
+
});
|
|
18
24
|
try {
|
|
19
25
|
const entryPoint = graph.find(nodes_1.isEntryPointInProgress());
|
|
20
26
|
const entryPoints = graph.filter(nodes_1.isEntryPoint);
|
|
@@ -23,21 +29,37 @@ const compileNgcTransformFactory = (StylesheetProcessor) => {
|
|
|
23
29
|
// Compile TypeScript sources
|
|
24
30
|
const { esm2015, declarations } = entryPoint.data.destinationFiles;
|
|
25
31
|
const { basePath, cssUrl, styleIncludePaths } = entryPoint.data.entryPoint;
|
|
26
|
-
const { moduleResolutionCache, ngccProcessingCache
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
32
|
+
const { moduleResolutionCache, ngccProcessingCache } = entryPoint.cache;
|
|
33
|
+
let ngccProcessor;
|
|
34
|
+
if (tsConfig.options.enableIvy !== false) {
|
|
35
|
+
spinner.start(`Compiling with Angular sources in Ivy ${tsConfig.options.compilationMode || 'full'} compilation mode.`);
|
|
36
|
+
ngccProcessor = new ngcc_processor_1.NgccProcessor(ngccProcessingCache, tsConfig.project, tsConfig.options, entryPoints);
|
|
37
|
+
if (!entryPoint.data.entryPoint.isSecondaryEntryPoint) {
|
|
38
|
+
// Only run the async version of NGCC during the primary entrypoint processing.
|
|
39
|
+
await ngccProcessor.process();
|
|
40
|
+
}
|
|
41
|
+
}
|
|
42
|
+
else {
|
|
43
|
+
spinner.start(`Compiling with Angular in legacy View Engine compilation mode.`);
|
|
44
|
+
}
|
|
45
|
+
if (tsConfig.options.enableIvy !== false && !isEnabled(process.env['NG_BUILD_LIB_LEGACY'])) {
|
|
46
|
+
(_a = (_c = entryPoint.cache).stylesheetProcessor) !== null && _a !== void 0 ? _a : (_c.stylesheetProcessor = new ivy.StylesheetProcessor(basePath, cssUrl, styleIncludePaths));
|
|
47
|
+
await ivy.compileSourceFiles(graph, tsConfig, moduleResolutionCache, {
|
|
48
|
+
outDir: path.dirname(esm2015),
|
|
49
|
+
declarationDir: path.dirname(declarations),
|
|
50
|
+
declaration: true,
|
|
51
|
+
target: ts.ScriptTarget.ES2015,
|
|
52
|
+
}, entryPoint.cache.stylesheetProcessor, ngccProcessor, options.watch);
|
|
53
|
+
}
|
|
54
|
+
else {
|
|
55
|
+
(_b = (_d = entryPoint.cache).stylesheetProcessor) !== null && _b !== void 0 ? _b : (_d.stylesheetProcessor = new StylesheetProcessor(basePath, cssUrl, styleIncludePaths));
|
|
56
|
+
await compile_source_files_1.compileSourceFiles(graph, tsConfig, moduleResolutionCache, entryPoint.cache.stylesheetProcessor, {
|
|
57
|
+
outDir: path.dirname(esm2015),
|
|
58
|
+
declarationDir: path.dirname(declarations),
|
|
59
|
+
declaration: true,
|
|
60
|
+
target: ts.ScriptTarget.ES2015,
|
|
61
|
+
}, ngccProcessor);
|
|
34
62
|
}
|
|
35
|
-
await compile_source_files_1.compileSourceFiles(graph, tsConfig, moduleResolutionCache, stylesheetProcessor, {
|
|
36
|
-
outDir: path.dirname(esm2015),
|
|
37
|
-
declarationDir: path.dirname(declarations),
|
|
38
|
-
declaration: true,
|
|
39
|
-
target: ts.ScriptTarget.ES2015,
|
|
40
|
-
}, ngccProcessor);
|
|
41
63
|
}
|
|
42
64
|
catch (error) {
|
|
43
65
|
spinner.fail();
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"compile-ngc.transform.js","sourceRoot":"","sources":["../../../../src/lib/ng-package/entry-point/compile-ngc.transform.ts"],"names":[],"mappings":";;;AAAA,6BAA6B;AAC7B,iCAAiC;AACjC,2BAA2B;AAC3B,qDAAwE;AACxE,yEAAoE;AACpE,6DAAyD;AACzD,gDAAiE;AACjE,oCAAgF;
|
|
1
|
+
{"version":3,"file":"compile-ngc.transform.js","sourceRoot":"","sources":["../../../../src/lib/ng-package/entry-point/compile-ngc.transform.ts"],"names":[],"mappings":";;;AAAA,6BAA6B;AAC7B,iCAAiC;AACjC,2BAA2B;AAC3B,qDAAwE;AACxE,yEAAoE;AACpE,6DAAyD;AACzD,iCAAiC;AACjC,gDAAiE;AACjE,oCAAgF;AAIhF,SAAS,SAAS,CAAC,QAA4B;IAC7C,OAAO,OAAO,QAAQ,KAAK,QAAQ,IAAI,CAAC,QAAQ,KAAK,GAAG,IAAI,QAAQ,CAAC,WAAW,EAAE,KAAK,MAAM,CAAC,CAAC;AACjG,CAAC;AAEM,MAAM,0BAA0B,GAAG,CACxC,mBAAoD,EACpD,OAAyB,EACd,EAAE;IACb,OAAO,gCAAoB,CAAC,KAAK,EAAC,KAAK,EAAC,EAAE;;;QACxC,MAAM,OAAO,GAAG,GAAG,CAAC;YAClB,UAAU,EAAE,KAAK;YACjB,YAAY,EAAE,KAAK;SACpB,CAAC,CAAC;QAEH,IAAI;YACF,MAAM,UAAU,GAAmB,KAAK,CAAC,IAAI,CAAC,8BAAsB,EAAE,CAAC,CAAC;YACxE,MAAM,WAAW,GAAqB,KAAK,CAAC,MAAM,CAAC,oBAAY,CAAC,CAAC;YACjE,sCAAsC;YACtC,MAAM,QAAQ,GAAG,uCAA4B,CAAC,UAAU,CAAC,IAAI,CAAC,QAAQ,EAAE,WAAW,CAAC,CAAC;YAErF,6BAA6B;YAC7B,MAAM,EAAE,OAAO,EAAE,YAAY,EAAE,GAAG,UAAU,CAAC,IAAI,CAAC,gBAAgB,CAAC;YACnE,MAAM,EAAE,QAAQ,EAAE,MAAM,EAAE,iBAAiB,EAAE,GAAG,UAAU,CAAC,IAAI,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C,KAAK,CACd,CAAC;aACH;iBAAM;gBACL,YAAA,UAAU,CAAC,KAAK,EAAC,mBAAmB,uCAAnB,mBAAmB,GAAK,IAAI,mBAAmB,CAAC,QAAQ,EAAE,MAAM,EAAE,iBAAiB,CAAC,EAAC;gBACtG,MAAM,yCAAkB,CACtB,KAAK,EACL,QAAQ,EACR,qBAAqB,EACrB,UAAU,CAAC,KAAK,CAAC,mBAA0B,EAC3C;oBACE,MAAM,EAAE,IAAI,CAAC,OAAO,CAAC,OAAO,CAAC;oBAC7B,cAAc,EAAE,IAAI,CAAC,OAAO,CAAC,YAAY,CAAC;oBAC1C,WAAW,EAAE,IAAI;oBACjB,MAAM,EAAE,EAAE,CAAC,YAAY,CAAC,MAAM;iBAC/B,EACD,aAAa,CACd,CAAC;aACH;SACF;QAAC,OAAO,KAAK,EAAE;YACd,OAAO,CAAC,IAAI,EAAE,CAAC;YACf,MAAM,KAAK,CAAC;SACb;QAED,OAAO,CAAC,OAAO,EAAE,CAAC;QAClB,OAAO,KAAK,CAAC;IACf,CAAC,CAAC,CAAC;AACL,CAAC,CAAC;AA1EW,QAAA,0BAA0B,8BA0ErC","sourcesContent":["import * as path from 'path';\nimport * as ts from 'typescript';\nimport * as ora from 'ora';\nimport { Transform, transformFromPromise } from '../../graph/transform';\nimport { compileSourceFiles } from '../../ngc/compile-source-files';\nimport { NgccProcessor } from '../../ngc/ngcc-processor';\nimport * as ivy from '../../ivy';\nimport { setDependenciesTsConfigPaths } from '../../ts/tsconfig';\nimport { isEntryPointInProgress, EntryPointNode, isEntryPoint } from '../nodes';\nimport { StylesheetProcessor as StylesheetProcessorClass } from '../../styles/stylesheet-processor';\nimport { NgPackagrOptions } from '../options.di';\n\nfunction isEnabled(variable: string | undefined): variable is string {\n return typeof variable === 'string' && (variable === '1' || variable.toLowerCase() === 'true');\n}\n\nexport const compileNgcTransformFactory = (\n StylesheetProcessor: typeof StylesheetProcessorClass,\n options: NgPackagrOptions,\n): Transform => {\n return transformFromPromise(async graph => {\n const spinner = ora({\n hideCursor: false,\n discardStdin: false,\n });\n\n try {\n const entryPoint: EntryPointNode = graph.find(isEntryPointInProgress());\n const entryPoints: EntryPointNode[] = graph.filter(isEntryPoint);\n // Add paths mappings for dependencies\n const tsConfig = setDependenciesTsConfigPaths(entryPoint.data.tsConfig, entryPoints);\n\n // Compile TypeScript sources\n const { esm2015, declarations } = entryPoint.data.destinationFiles;\n const { basePath, cssUrl, styleIncludePaths } = entryPoint.data.entryPoint;\n const { moduleResolutionCache, ngccProcessingCache } = entryPoint.cache;\n\n let ngccProcessor: NgccProcessor | undefined;\n if (tsConfig.options.enableIvy !== false) {\n spinner.start(`Compiling with Angular sources in Ivy ${tsConfig.options.compilationMode || 'full'} compilation mode.`);\n ngccProcessor = new NgccProcessor(ngccProcessingCache, tsConfig.project, tsConfig.options, entryPoints);\n if (!entryPoint.data.entryPoint.isSecondaryEntryPoint) {\n // Only run the async version of NGCC during the primary entrypoint processing.\n await ngccProcessor.process();\n }\n } else {\n spinner.start(`Compiling with Angular in legacy View Engine compilation mode.`);\n }\n\n if (tsConfig.options.enableIvy !== false && !isEnabled(process.env['NG_BUILD_LIB_LEGACY'])) {\n entryPoint.cache.stylesheetProcessor ??= new ivy.StylesheetProcessor(basePath, cssUrl, styleIncludePaths);\n\n await ivy.compileSourceFiles(\n graph,\n tsConfig,\n moduleResolutionCache,\n {\n outDir: path.dirname(esm2015),\n declarationDir: path.dirname(declarations),\n declaration: true,\n target: ts.ScriptTarget.ES2015,\n },\n entryPoint.cache.stylesheetProcessor as any,\n ngccProcessor,\n options.watch,\n );\n } else {\n entryPoint.cache.stylesheetProcessor ??= new StylesheetProcessor(basePath, cssUrl, styleIncludePaths);\n await compileSourceFiles(\n graph,\n tsConfig,\n moduleResolutionCache,\n entryPoint.cache.stylesheetProcessor as any,\n {\n outDir: path.dirname(esm2015),\n declarationDir: path.dirname(declarations),\n declaration: true,\n target: ts.ScriptTarget.ES2015,\n },\n ngccProcessor,\n );\n }\n } catch (error) {\n spinner.fail();\n throw error;\n }\n\n spinner.succeed();\n return graph;\n });\n};\n"]}
|
|
@@ -1,12 +1,13 @@
|
|
|
1
1
|
import * as ts from 'typescript';
|
|
2
2
|
import { RollupCache } from 'rollup';
|
|
3
|
-
import { ParsedConfiguration, Program } from '@angular/compiler-cli';
|
|
3
|
+
import { NgtscProgram, ParsedConfiguration, Program } from '@angular/compiler-cli';
|
|
4
4
|
import { Node } from '../graph/node';
|
|
5
5
|
import { NgEntryPoint, DestinationFiles } from './entry-point/entry-point';
|
|
6
6
|
import { NgccProcessingCache } from './ngcc-cache';
|
|
7
7
|
import { NgPackage } from './package';
|
|
8
8
|
import { FileCache } from '../file-system/file-cache';
|
|
9
9
|
import { ComplexPredicate } from '../graph/build-graph';
|
|
10
|
+
import * as ivy from '../ivy';
|
|
10
11
|
import { StylesheetProcessor } from '../styles/stylesheet-processor';
|
|
11
12
|
export declare const TYPE_NG_PACKAGE = "application/ng-package";
|
|
12
13
|
export declare const TYPE_NG_ENTRY_POINT = "application/ng-entry-point";
|
|
@@ -35,7 +36,9 @@ export declare class EntryPointNode extends Node {
|
|
|
35
36
|
analysesSourcesFileCache: FileCache;
|
|
36
37
|
moduleResolutionCache: ts.ModuleResolutionCache;
|
|
37
38
|
rollupFESMCache?: RollupCache;
|
|
38
|
-
stylesheetProcessor?: StylesheetProcessor;
|
|
39
|
+
stylesheetProcessor?: StylesheetProcessor | ivy.StylesheetProcessor;
|
|
40
|
+
oldNgtscProgram?: NgtscProgram;
|
|
41
|
+
oldBuilder?: ts.EmitAndSemanticDiagnosticsBuilderProgram;
|
|
39
42
|
};
|
|
40
43
|
data: {
|
|
41
44
|
destinationFiles: DestinationFiles;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"nodes.js","sourceRoot":"","sources":["../../../src/lib/ng-package/nodes.ts"],"names":[],"mappings":";;;AAAA,iCAAiC;AAGjC,wCAAqC;AACrC,4CAA4D;AAE5D,6CAAmD;AAEnD,0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SAAS,CAAC,yBAAiB,CAAC,MAAM,CAAC,CAAC;KAChD;AACH,CAAC;AAJD,kCAIC;AAED,SAAgB,KAAK,CAAC,IAAY;IAChC,OAAO,GAAG,uBAAe,GAAG,IAAI,EAAE,CAAC;AACrC,CAAC;AAFD,sBAEC;AAED,MAAa,cAAe,SAAQ,WAAI;IAGtC,YACkB,GAAW,EAC3B,gBAA2B,EAC3B,mBAAwC,EACxC,qBAA+C;QAE/C,KAAK,CAAC,GAAG,CAAC,CAAC;QALK,QAAG,GAAH,GAAG,CAAQ;QAHpB,SAAI,GAAG,2BAAmB,CAAC;QAUlC,IAAI,CAAC,KAAK,GAAG;YACX,gBAAgB;YAChB,mBAAmB;YACnB,wBAAwB,EAAE,IAAI,sBAAS,EAAE;YACzC,qBAAqB;SACtB,CAAC;IACJ,CAAC;CAmBF;AApCD,wCAoCC;AAED,MAAa,WAAY,SAAQ,WAAI;IAArC;;QACW,SAAI,GAAG,uBAAe,CAAC;QAGhC,UAAK,GAAG;YACN,SAAS,EAAE,EAAe;YAC1B,gBAAgB,EAAE,IAAI,sBAAS,EAAE;YACjC,mBAAmB,EAAE,IAAI,gCAAmB,EAAE;YAC9C,qBAAqB,EAAE,EAAE,CAAC,2BAA2B,CAAC,OAAO,CAAC,GAAG,EAAE,EAAE,CAAC,CAAC,EAAE,CAAC,CAAC,CAAC;SAC7E,CAAC;IACJ,CAAC;CAAA;AAVD,kCAUC","sourcesContent":["import * as ts from 'typescript';\nimport { RollupCache } from 'rollup';\nimport { NgtscProgram, ParsedConfiguration, Program } from '@angular/compiler-cli';\nimport { Node } from '../graph/node';\nimport { by, isInProgress, isDirty } from '../graph/select';\nimport { NgEntryPoint, DestinationFiles } from './entry-point/entry-point';\nimport { NgccProcessingCache } from './ngcc-cache';\nimport { NgPackage } from './package';\nimport { FileCache } from '../file-system/file-cache';\nimport { ComplexPredicate } from '../graph/build-graph';\nimport * as ivy from '../ivy';\nimport { StylesheetProcessor } from '../styles/stylesheet-processor';\n\nexport const TYPE_NG_PACKAGE = 'application/ng-package';\nexport const TYPE_NG_ENTRY_POINT = 'application/ng-entry-point';\n\nexport type GlobCache = Record<string, boolean | 'DIR' | 'FILE' | string[]>;\n\n/** A node that can be read through the `fs` api. */\nexport const URL_PROTOCOL_FILE = 'file://';\n\n/** A node specific to angular. */\nexport const URL_PROTOCOL_NG = 'ng://';\n\nexport function isEntryPoint(node: Node): node is EntryPointNode {\n return node.type === TYPE_NG_ENTRY_POINT;\n}\n\nexport function isPackage(node: Node): node is PackageNode {\n return node.type === TYPE_NG_PACKAGE;\n}\n\nexport function byEntryPoint(): ComplexPredicate<EntryPointNode> {\n return by(isEntryPoint);\n}\n\nexport function isEntryPointInProgress(): ComplexPredicate<EntryPointNode> {\n return by(isEntryPoint).and(isInProgress);\n}\n\nexport function isEntryPointDirty(): ComplexPredicate<EntryPointNode> {\n return by(isEntryPoint).and(isDirty);\n}\n\nexport function isFileUrl(value: string): boolean {\n return value.startsWith(URL_PROTOCOL_FILE);\n}\n\nexport function fileUrl(path: string): string {\n return `${URL_PROTOCOL_FILE}${path}`;\n}\n\nexport function fileUrlPath(url: string): string {\n if (url.startsWith(URL_PROTOCOL_FILE)) {\n return url.substring(URL_PROTOCOL_FILE.length);\n }\n}\n\nexport function ngUrl(path: string): string {\n return `${URL_PROTOCOL_NG}${path}`;\n}\n\nexport class EntryPointNode extends Node {\n readonly type = TYPE_NG_ENTRY_POINT;\n\n constructor(\n public readonly url: string,\n sourcesFileCache: FileCache,\n ngccProcessingCache: NgccProcessingCache,\n moduleResolutionCache: ts.ModuleResolutionCache,\n ) {\n super(url);\n\n this.cache = {\n sourcesFileCache,\n ngccProcessingCache,\n analysesSourcesFileCache: new FileCache(),\n moduleResolutionCache,\n };\n }\n\n cache: {\n oldPrograms?: Record<ts.ScriptTarget | 'analysis', Program | ts.Program>;\n sourcesFileCache: FileCache;\n ngccProcessingCache: NgccProcessingCache;\n analysesSourcesFileCache: FileCache;\n moduleResolutionCache: ts.ModuleResolutionCache;\n rollupFESMCache?: RollupCache;\n stylesheetProcessor?: StylesheetProcessor | ivy.StylesheetProcessor;\n oldNgtscProgram?: NgtscProgram;\n oldBuilder?: ts.EmitAndSemanticDiagnosticsBuilderProgram;\n };\n\n data: {\n destinationFiles: DestinationFiles;\n entryPoint: NgEntryPoint;\n tsConfig?: ParsedConfiguration;\n };\n}\n\nexport class PackageNode extends Node {\n readonly type = TYPE_NG_PACKAGE;\n data: NgPackage;\n\n cache = {\n globCache: {} as GlobCache,\n sourcesFileCache: new FileCache(),\n ngccProcessingCache: new NgccProcessingCache(),\n moduleResolutionCache: ts.createModuleResolutionCache(process.cwd(), s => s),\n };\n}\n"]}
|
package/lib/packagr.js
CHANGED
|
@@ -5,7 +5,6 @@ const injection_js_1 = require("injection-js");
|
|
|
5
5
|
const rxjs_1 = require("rxjs");
|
|
6
6
|
const operators_1 = require("rxjs/operators");
|
|
7
7
|
const build_graph_1 = require("./graph/build-graph");
|
|
8
|
-
const log = require("./utils/log");
|
|
9
8
|
const init_tsconfig_di_1 = require("./ng-package/entry-point/init-tsconfig.di");
|
|
10
9
|
const entry_point_di_1 = require("./ng-package/entry-point/entry-point.di");
|
|
11
10
|
const package_di_1 = require("./ng-package/package.di");
|
|
@@ -99,11 +98,7 @@ class NgPackagr {
|
|
|
99
98
|
buildAsObservable() {
|
|
100
99
|
const injector = injection_js_1.ReflectiveInjector.resolveAndCreate(this.providers);
|
|
101
100
|
const buildTransformOperator = injector.get(this.buildTransform);
|
|
102
|
-
return rxjs_1.of(new build_graph_1.BuildGraph()).pipe(buildTransformOperator, operators_1.
|
|
103
|
-
// Report error and re-throw to subscribers
|
|
104
|
-
log.error(err);
|
|
105
|
-
return rxjs_1.throwError(err);
|
|
106
|
-
}), operators_1.map(() => undefined));
|
|
101
|
+
return rxjs_1.of(new build_graph_1.BuildGraph()).pipe(buildTransformOperator, operators_1.mapTo(undefined));
|
|
107
102
|
}
|
|
108
103
|
}
|
|
109
104
|
exports.NgPackagr = NgPackagr;
|
package/lib/packagr.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"packagr.js","sourceRoot":"","sources":["../../src/lib/packagr.ts"],"names":[],"mappings":";;;AAAA,+CAA4E;AAE5E,+
|
|
1
|
+
{"version":3,"file":"packagr.js","sourceRoot":"","sources":["../../src/lib/packagr.ts"],"names":[],"mappings":";;;AAAA,+CAA4E;AAE5E,+BAAsD;AACtD,8CAAuC;AACvC,qDAAiD;AAEjD,gFAA4E;AAC5E,4EAAgF;AAChF,wDAA+E;AAC/E,6CAA8C;AAC9C,wDAA2E;AAE3E;;;;;;GAMG;AACH,MAAa,SAAS;IAGpB,YAAoB,SAAqB;QAArB,cAAS,GAAT,SAAS,CAAY;QAFjC,mBAAc,GAA8B,8BAAiB,CAAC,OAAO,CAAC;IAElC,CAAC;IAE7C;;;;;OAKG;IACI,WAAW,CAAC,OAAyB;QAC1C,IAAI,CAAC,SAAS,CAAC,IAAI,CAAC,2BAAc,CAAC,OAAO,CAAC,CAAC,CAAC;QAE7C,OAAO,IAAI,CAAC;IACd,CAAC;IAED;;;;;OAKG;IACI,UAAU,CAAC,OAAe;QAC/B,IAAI,CAAC,SAAS,CAAC,IAAI,CAAC,2BAAc,CAAC,OAAO,CAAC,CAAC,CAAC;QAE7C,OAAO,IAAI,CAAC;IACd,CAAC;IAED;;;;;;OAMG;IACI,aAAa,CAAC,SAAqB;QACxC,IAAI,CAAC,SAAS,GAAG,CAAC,GAAG,IAAI,CAAC,SAAS,EAAE,GAAG,SAAS,CAAC,CAAC;QAEnD,OAAO,IAAI,CAAC;IACd,CAAC;IAED;;;;;OAKG;IACI,YAAY,CAAC,aAA2C;QAC7D,IAAI,CAAC,SAAS,CAAC,IAAI,CAAC,kCAAe,CAAC,aAAa,CAAC,CAAC,CAAC;QAEpD,OAAO,IAAI,CAAC;IACd,CAAC;IAED;;;;;OAKG;IACI,kBAAkB,CAAC,SAAoC;QAC5D,IAAI,CAAC,cAAc,GAAG,SAAS,CAAC;QAEhC,OAAO,IAAI,CAAC;IACd,CAAC;IAED;;;;OAIG;IACI,KAAK;QACV,OAAO,IAAI,CAAC,iBAAiB,EAAE,CAAC,SAAS,EAAE,CAAC;IAC9C,CAAC;IAED;;;;OAIG;IACI,KAAK;QACV,IAAI,CAAC,SAAS,CAAC,IAAI,CAAC,2BAAc,CAAC,EAAE,KAAK,EAAE,IAAI,EAAE,CAAC,CAAC,CAAC;QAErD,OAAO,IAAI,CAAC,iBAAiB,EAAE,CAAC;IAClC,CAAC;IAED;;;;OAIG;IACI,iBAAiB;QACtB,MAAM,QAAQ,GAAG,iCAAkB,CAAC,gBAAgB,CAAC,IAAI,CAAC,SAAS,CAAC,CAAC;QACrE,MAAM,sBAAsB,GAAG,QAAQ,CAAC,GAAG,CAAC,IAAI,CAAC,cAAc,CAAC,CAAC;QAEjE,OAAO,SAAY,CAAC,IAAI,wBAAU,EAAE,CAAC,CAAC,IAAI,CACxC,sBAAsB,EACtB,iBAAK,CAAC,SAAS,CAAC,CACjB,CAAC;IACJ,CAAC;CACF;AApGD,8BAoGC;AAEM,MAAM,SAAS,GAAG,GAAc,EAAE,CACvC,IAAI,SAAS,CAAC;IACZ,sCAAsC;IACtC,GAAG,8BAAiB;IACpB,GAAG,sCAAqB;CACzB,CAAC,CAAC;AALQ,QAAA,SAAS,aAKjB","sourcesContent":["import { InjectionToken, Provider, ReflectiveInjector } from 'injection-js';\nimport { ParsedConfiguration } from '@angular/compiler-cli';\nimport { of as observableOf, Observable } from 'rxjs';\nimport { mapTo } from 'rxjs/operators';\nimport { BuildGraph } from './graph/build-graph';\nimport { Transform } from './graph/transform';\nimport { provideTsConfig } from './ng-package/entry-point/init-tsconfig.di';\nimport { ENTRY_POINT_PROVIDERS } from './ng-package/entry-point/entry-point.di';\nimport { PACKAGE_TRANSFORM, PACKAGE_PROVIDERS } from './ng-package/package.di';\nimport { provideProject } from './project.di';\nimport { provideOptions, NgPackagrOptions } from './ng-package/options.di';\n\n/**\n * The original ng-packagr implemented on top of a rxjs-ified and di-jectable transformation pipeline.\n *\n * See the `docs/transformations.md` for more prose description.\n *\n * @link https://github.com/ng-packagr/ng-packagr/pull/572\n */\nexport class NgPackagr {\n private buildTransform: InjectionToken<Transform> = PACKAGE_TRANSFORM.provide;\n\n constructor(private providers: Provider[]) {}\n\n /**\n * Adds options to ng-packagr\n *\n * @param options Ng Packagr Options\n * @return Self instance for fluent API\n */\n public withOptions(options: NgPackagrOptions): NgPackagr {\n this.providers.push(provideOptions(options));\n\n return this;\n }\n\n /**\n * Sets the path to the user's \"ng-package\" file (either `package.json`, `ng-package.json`, or `ng-package.js`)\n *\n * @param project File path\n * @return Self instance for fluent API\n */\n public forProject(project: string): NgPackagr {\n this.providers.push(provideProject(project));\n\n return this;\n }\n\n /**\n * Adds dependency injection providers.\n *\n * @param providers\n * @return Self instance for fluent API\n * @link https://github.com/mgechev/injection-js\n */\n public withProviders(providers: Provider[]): NgPackagr {\n this.providers = [...this.providers, ...providers];\n\n return this;\n }\n\n /**\n * Overwrites the default TypeScript configuration.\n *\n * @param defaultValues A tsconfig providing default values to the compilation.\n * @return Self instance for fluent API\n */\n public withTsConfig(defaultValues: ParsedConfiguration | string): NgPackagr {\n this.providers.push(provideTsConfig(defaultValues));\n\n return this;\n }\n\n /**\n * Overwrites the 'build' transform.\n *\n * @param transform\n * @return Self instance for fluent API\n */\n public withBuildTransform(transform: InjectionToken<Transform>): NgPackagr {\n this.buildTransform = transform;\n\n return this;\n }\n\n /**\n * Builds the project by kick-starting the 'build' transform over an (initially) empty `BuildGraph``\n *\n * @return A promisified result of the transformation pipeline.\n */\n public build(): Promise<void> {\n return this.buildAsObservable().toPromise();\n }\n\n /**\n * Builds and watch for changes by kick-starting the 'watch' transform over an (initially) empty `BuildGraph``\n *\n * @return An observable result of the transformation pipeline.\n */\n public watch(): Observable<void> {\n this.providers.push(provideOptions({ watch: true }));\n\n return this.buildAsObservable();\n }\n\n /**\n * Builds the project by kick-starting the 'build' transform over an (initially) empty `BuildGraph``\n *\n * @return An observable result of the transformation pipeline.\n */\n public buildAsObservable(): Observable<void> {\n const injector = ReflectiveInjector.resolveAndCreate(this.providers);\n const buildTransformOperator = injector.get(this.buildTransform);\n\n return observableOf(new BuildGraph()).pipe(\n buildTransformOperator,\n mapTo(undefined),\n );\n }\n}\n\nexport const ngPackagr = (): NgPackagr =>\n new NgPackagr([\n // Add default providers to this list.\n ...PACKAGE_PROVIDERS,\n ...ENTRY_POINT_PROVIDERS,\n ]);\n"]}
|
|
@@ -5,3 +5,4 @@ import { EntryPointNode } from '../ng-package/nodes';
|
|
|
5
5
|
import { BuildGraph } from '../graph/build-graph';
|
|
6
6
|
import { FileCache } from '../file-system/file-cache';
|
|
7
7
|
export declare function cacheCompilerHost(graph: BuildGraph, entryPoint: EntryPointNode, compilerOptions: ng.CompilerOptions, moduleResolutionCache: ts.ModuleResolutionCache, stylesheetProcessor?: StylesheetProcessor, sourcesFileCache?: FileCache, setParentNodes?: boolean): ng.CompilerHost;
|
|
8
|
+
export declare function augmentProgramWithVersioning(program: ts.Program): void;
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.cacheCompilerHost = void 0;
|
|
3
|
+
exports.augmentProgramWithVersioning = exports.cacheCompilerHost = void 0;
|
|
4
4
|
const ts = require("typescript");
|
|
5
5
|
const ng = require("@angular/compiler-cli");
|
|
6
6
|
const path = require("path");
|
|
@@ -8,6 +8,7 @@ const path_1 = require("../utils/path");
|
|
|
8
8
|
const log_1 = require("../utils/log");
|
|
9
9
|
const nodes_1 = require("../ng-package/nodes");
|
|
10
10
|
const node_1 = require("../graph/node");
|
|
11
|
+
const crypto_1 = require("crypto");
|
|
11
12
|
function cacheCompilerHost(graph, entryPoint, compilerOptions, moduleResolutionCache, stylesheetProcessor, sourcesFileCache = entryPoint.cache.sourcesFileCache, setParentNodes = true) {
|
|
12
13
|
const tsHost = ts.createCompilerHost(compilerOptions, setParentNodes);
|
|
13
14
|
const compilerHost = ng.createCompilerHost({ options: compilerOptions, tsHost });
|
|
@@ -61,17 +62,17 @@ function cacheCompilerHost(graph, entryPoint, compilerOptions, moduleResolutionC
|
|
|
61
62
|
}
|
|
62
63
|
return cache.content;
|
|
63
64
|
},
|
|
64
|
-
// ng specific
|
|
65
|
-
moduleNameToFileName: (moduleName, containingFile) => {
|
|
66
|
-
const { resolvedModule } = ts.resolveModuleName(moduleName, path_1.ensureUnixPath(containingFile), compilerOptions, compilerHost, moduleResolutionCache);
|
|
67
|
-
return resolvedModule && resolvedModule.resolvedFileName;
|
|
68
|
-
},
|
|
69
65
|
resolveModuleNames: (moduleNames, containingFile) => {
|
|
70
66
|
return moduleNames.map(moduleName => {
|
|
71
67
|
const { resolvedModule } = ts.resolveModuleName(moduleName, path_1.ensureUnixPath(containingFile), compilerOptions, compilerHost, moduleResolutionCache);
|
|
72
68
|
return resolvedModule;
|
|
73
69
|
});
|
|
74
70
|
},
|
|
71
|
+
// ng specific
|
|
72
|
+
moduleNameToFileName: (moduleName, containingFile) => {
|
|
73
|
+
const { resolvedModule } = ts.resolveModuleName(moduleName, path_1.ensureUnixPath(containingFile), compilerOptions, compilerHost, moduleResolutionCache);
|
|
74
|
+
return resolvedModule && resolvedModule.resolvedFileName;
|
|
75
|
+
},
|
|
75
76
|
resourceNameToFileName: (resourceName, containingFilePath) => {
|
|
76
77
|
const resourcePath = path.resolve(path.dirname(containingFilePath), resourceName);
|
|
77
78
|
const containingNode = getNode(containingFilePath);
|
|
@@ -83,7 +84,7 @@ function cacheCompilerHost(graph, entryPoint, compilerOptions, moduleResolutionC
|
|
|
83
84
|
addDependee(fileName);
|
|
84
85
|
const cache = sourcesFileCache.getOrCreate(fileName);
|
|
85
86
|
if (cache.content === undefined) {
|
|
86
|
-
if (/(html
|
|
87
|
+
if (/(?:html?|svg)$/.test(path.extname(fileName))) {
|
|
87
88
|
// template
|
|
88
89
|
cache.content = compilerHost.readFile.call(this, fileName);
|
|
89
90
|
}
|
|
@@ -100,7 +101,6 @@ function cacheCompilerHost(graph, entryPoint, compilerOptions, moduleResolutionC
|
|
|
100
101
|
if (cache.content === undefined) {
|
|
101
102
|
throw new Error(`Cannot read file ${fileName}.`);
|
|
102
103
|
}
|
|
103
|
-
;
|
|
104
104
|
cache.exists = true;
|
|
105
105
|
}
|
|
106
106
|
return cache.content;
|
|
@@ -108,4 +108,17 @@ function cacheCompilerHost(graph, entryPoint, compilerOptions, moduleResolutionC
|
|
|
108
108
|
};
|
|
109
109
|
}
|
|
110
110
|
exports.cacheCompilerHost = cacheCompilerHost;
|
|
111
|
+
function augmentProgramWithVersioning(program) {
|
|
112
|
+
const baseGetSourceFiles = program.getSourceFiles;
|
|
113
|
+
program.getSourceFiles = function (...parameters) {
|
|
114
|
+
const files = baseGetSourceFiles(...parameters);
|
|
115
|
+
for (const file of files) {
|
|
116
|
+
if (file.version === undefined) {
|
|
117
|
+
file.version = crypto_1.createHash('sha256').update(file.text).digest('hex');
|
|
118
|
+
}
|
|
119
|
+
}
|
|
120
|
+
return files;
|
|
121
|
+
};
|
|
122
|
+
}
|
|
123
|
+
exports.augmentProgramWithVersioning = augmentProgramWithVersioning;
|
|
111
124
|
//# sourceMappingURL=cache-compiler-host.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"cache-compiler-host.js","sourceRoot":"","sources":["../../../src/lib/ts/cache-compiler-host.ts"],"names":[],"mappings":";;;AAAA,iCAAiC;AACjC,4CAA4C;AAC5C,6BAA6B;AAC7B,wCAA+C;AAC/C,sCAAqC;AAErC,+CAA8D;AAG9D,wCAAqC;
|
|
1
|
+
{"version":3,"file":"cache-compiler-host.js","sourceRoot":"","sources":["../../../src/lib/ts/cache-compiler-host.ts"],"names":[],"mappings":";;;AAAA,iCAAiC;AACjC,4CAA4C;AAC5C,6BAA6B;AAC7B,wCAA+C;AAC/C,sCAAqC;AAErC,+CAA8D;AAG9D,w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AAK,CAAC;IACf,CAAC,CAAC;AACJ,CAAC;AAbD,oEAaC","sourcesContent":["import * as ts from 'typescript';\nimport * as ng from '@angular/compiler-cli';\nimport * as path from 'path';\nimport { ensureUnixPath } from '../utils/path';\nimport { error } from '../utils/log';\nimport { StylesheetProcessor } from '../styles/stylesheet-processor';\nimport { EntryPointNode, fileUrl } from '../ng-package/nodes';\nimport { BuildGraph } from '../graph/build-graph';\nimport { FileCache } from '../file-system/file-cache';\nimport { Node } from '../graph/node';\nimport { createHash } from 'crypto';\n\nexport function cacheCompilerHost(\n graph: BuildGraph,\n entryPoint: EntryPointNode,\n compilerOptions: ng.CompilerOptions,\n moduleResolutionCache: ts.ModuleResolutionCache,\n stylesheetProcessor?: StylesheetProcessor,\n sourcesFileCache: FileCache = entryPoint.cache.sourcesFileCache,\n setParentNodes = true,\n): ng.CompilerHost {\n const tsHost = ts.createCompilerHost(compilerOptions, setParentNodes);\n const compilerHost = ng.createCompilerHost({ options: compilerOptions, tsHost });\n\n const getNode = (fileName: string) => {\n const nodeUri = fileUrl(ensureUnixPath(fileName));\n let node = graph.get(nodeUri);\n\n if (!node) {\n node = new Node(nodeUri);\n graph.put(node);\n }\n\n return node;\n };\n\n const addDependee = (fileName: string) => {\n const node = getNode(fileName);\n entryPoint.dependsOn(node);\n };\n\n return {\n ...compilerHost,\n\n // ts specific\n fileExists: (fileName: string) => {\n const cache = sourcesFileCache.getOrCreate(fileName);\n if (cache.exists === undefined) {\n cache.exists = compilerHost.fileExists.call(this, fileName);\n }\n return cache.exists;\n },\n\n getSourceFile: (fileName: string, languageVersion: ts.ScriptTarget) => {\n addDependee(fileName);\n const cache = sourcesFileCache.getOrCreate(fileName);\n if (!cache.sourceFile) {\n cache.sourceFile = compilerHost.getSourceFile.call(this, fileName, languageVersion);\n }\n return cache.sourceFile;\n },\n\n writeFile: (\n fileName: string,\n data: string,\n writeByteOrderMark: boolean,\n onError?: (message: string) => void,\n sourceFiles?: ReadonlyArray<ts.SourceFile>,\n ) => {\n if (fileName.endsWith('.d.ts')) {\n sourceFiles.forEach(source => {\n const cache = sourcesFileCache.getOrCreate(source.fileName);\n if (!cache.declarationFileName) {\n cache.declarationFileName = ensureUnixPath(fileName);\n }\n });\n }\n\n compilerHost.writeFile.call(this, fileName, data, writeByteOrderMark, onError, sourceFiles);\n },\n\n readFile: (fileName: string) => {\n addDependee(fileName);\n\n const cache = sourcesFileCache.getOrCreate(fileName);\n if (cache.content === undefined) {\n cache.content = compilerHost.readFile.call(this, fileName);\n }\n return cache.content;\n },\n\n resolveModuleNames: (moduleNames: string[], containingFile: string) => {\n return moduleNames.map(moduleName => {\n const { resolvedModule } = ts.resolveModuleName(\n moduleName,\n ensureUnixPath(containingFile),\n compilerOptions,\n compilerHost,\n moduleResolutionCache,\n );\n\n return resolvedModule;\n });\n },\n\n // ng specific\n moduleNameToFileName: (moduleName: string, containingFile: string) => {\n const { resolvedModule } = ts.resolveModuleName(\n moduleName,\n ensureUnixPath(containingFile),\n compilerOptions,\n compilerHost,\n moduleResolutionCache,\n );\n\n return resolvedModule && resolvedModule.resolvedFileName;\n },\n\n resourceNameToFileName: (resourceName: string, containingFilePath: string) => {\n const resourcePath = path.resolve(path.dirname(containingFilePath), resourceName);\n const containingNode = getNode(containingFilePath);\n const resourceNode = getNode(resourcePath);\n containingNode.dependsOn(resourceNode);\n\n return resourcePath;\n },\n\n readResource: (fileName: string) => {\n addDependee(fileName);\n\n const cache = sourcesFileCache.getOrCreate(fileName);\n if (cache.content === undefined) {\n if (/(?:html?|svg)$/.test(path.extname(fileName))) {\n // template\n cache.content = compilerHost.readFile.call(this, fileName);\n } else {\n // stylesheet\n try {\n cache.content = stylesheetProcessor.process(fileName);\n } catch (err) {\n error('\\n' + err.message + ` in stylesheet file ${fileName}.`);\n throw err;\n }\n }\n\n if (cache.content === undefined) {\n throw new Error(`Cannot read file ${fileName}.`);\n }\n\n cache.exists = true;\n }\n\n return cache.content;\n },\n };\n}\n\nexport function augmentProgramWithVersioning(program: ts.Program): void {\n const baseGetSourceFiles = program.getSourceFiles;\n program.getSourceFiles = function (...parameters) {\n const files: readonly (ts.SourceFile & { version?: string })[] = baseGetSourceFiles(...parameters);\n\n for (const file of files) {\n if (file.version === undefined) {\n file.version = createHash('sha256').update(file.text).digest('hex');\n }\n }\n\n return files;\n };\n}\n"]}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "ng-packagr",
|
|
3
|
-
"version": "12.
|
|
3
|
+
"version": "12.1.1",
|
|
4
4
|
"description": "Compile and package Angular libraries in Angular Package Format (APF)",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"apf",
|
|
@@ -59,6 +59,6 @@
|
|
|
59
59
|
"peerDependencies": {
|
|
60
60
|
"@angular/compiler-cli": "^12.0.0 || ^12.1.0-next.0",
|
|
61
61
|
"tslib": "^2.1.0",
|
|
62
|
-
"typescript": "~4.2.3"
|
|
62
|
+
"typescript": "~4.2.3 || ~4.3.2"
|
|
63
63
|
}
|
|
64
64
|
}
|