ng-packagr 22.2.0-next.1 → 22.2.0-next.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/package.json
CHANGED
|
@@ -48,7 +48,10 @@ async function rolldownBundleFile(opts) {
|
|
|
48
48
|
const jail = path.dirname(opts.entry);
|
|
49
49
|
if (dtsMode) {
|
|
50
50
|
outExtension = '.d.ts';
|
|
51
|
-
plugins = [
|
|
51
|
+
plugins = [
|
|
52
|
+
(0, file_loader_plugin_1.fileLoaderPlugin)(opts.fileCache, ['.d.ts', '/index.d.ts'], dtsMode),
|
|
53
|
+
(0, rolldown_plugin_dts_1.dts)({ generator: 'oxc', sourcemap: opts.sourcemap }),
|
|
54
|
+
];
|
|
52
55
|
}
|
|
53
56
|
else {
|
|
54
57
|
outExtension = '.mjs';
|
|
@@ -72,6 +75,9 @@ async function rolldownBundleFile(opts) {
|
|
|
72
75
|
break;
|
|
73
76
|
}
|
|
74
77
|
},
|
|
78
|
+
experimental: {
|
|
79
|
+
attachDebugInfo: 'none',
|
|
80
|
+
},
|
|
75
81
|
resolve: {
|
|
76
82
|
symlinks: false,
|
|
77
83
|
},
|
|
@@ -89,13 +95,11 @@ async function rolldownBundleFile(opts) {
|
|
|
89
95
|
entryFileNames: opts.entryName + outExtension,
|
|
90
96
|
banner: '',
|
|
91
97
|
sourcemap: opts.sourcemap,
|
|
92
|
-
comments:
|
|
93
|
-
|
|
94
|
-
:
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
jsdoc: false,
|
|
98
|
-
},
|
|
98
|
+
comments: {
|
|
99
|
+
legal: true,
|
|
100
|
+
annotation: true,
|
|
101
|
+
jsdoc: dtsMode,
|
|
102
|
+
},
|
|
99
103
|
});
|
|
100
104
|
// Close the bundle to let plugins clean up their external processes or services
|
|
101
105
|
await bundle.close();
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"rolldown.js","sourceRoot":"","sources":["../../../../src/lib/flatten/r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E;YAC3B,wGAAwG;YACxG,IAAI,CAAC,CAAC,IAAI,KAAK,OAAO,EAAE,CAAC;gBACvB,MAAM,CAAC,cAAc,CAAC,CAAC,EAAE,KAAK,EAAE,EAAE,KAAK,EAAE,IAAI,EAAE,YAAY,EAAE,IAAI,EAAE,CAAC,CAAC;YACvE,CAAC;YAED,OAAO,CAAC,CAAC;QACX,CAAC,CAAC;KACH,CAAC;AACJ,CAAC;AAED,SAAS,oBAAoB,CAAC,QAAgB,EAAE,QAA4B,EAAE,IAAY;IACxF,oEAAoE;IACpE,yFAAyF;IACzF,IAAI,QAAQ,CAAC,CAAC,CAAC,KAAK,GAAG,IAAI,QAAQ,CAAC,CAAC,CAAC,KAAK,GAAG,IAAI,IAAI,CAAC,UAAU,CAAC,QAAQ,CAAC,EAAE,CAAC;QAC5E,yGAAyG;QACzG,OAAO,CAAC,QAAQ,IAAI,CAAC,IAAI,CAAC,IAAI,CAAC,QAAQ,EAAE,QAAQ,CAAC,CAAC,UAAU,CAAC,IAAI,CAAC,CAAC;IACtE,CAAC;IAED,OAAO,IAAI,CAAC;AACd,CAAC","sourcesContent":["import * as path from 'path';\nimport { type OutputAsset, type OutputChunk, type RolldownPluginOption, rolldown } from 'rolldown';\nimport { dts } from 'rolldown-plugin-dts';\nimport { OutputFileCache } from '../ng-package/nodes';\nimport * as log from '../utils/log';\nimport { fileLoaderPlugin } from './file-loader-plugin';\n\n/**\n * Options used in `ng-packagr` for writing flat bundle files.\n *\n * These options are passed through to rolldown.\n */\nexport interface RolldownOptions {\n moduleName: string;\n entry: string;\n entryName: string;\n dir: string;\n fileCache: OutputFileCache;\n sourcemap: boolean;\n}\n\n/** Runs rolldown over the given entry file, writes a bundle file. */\nexport async function rolldownBundleFile(opts: RolldownOptions): Promise<{ files: (OutputChunk | OutputAsset)[] }> {\n log.debug(`rolldown ${opts.entry} to ${opts.dir}`);\n const dtsMode = opts.entry.endsWith('.d.ts');\n let outExtension: string;\n let plugins: RolldownPluginOption[];\n const jail = path.dirname(opts.entry);\n\n if (dtsMode) {\n outExtension = '.d.ts';\n plugins = [\n fileLoaderPlugin(opts.fileCache, ['.d.ts', '/index.d.ts'], dtsMode),\n dts({ generator: 'oxc', sourcemap: opts.sourcemap }),\n ];\n } else {\n outExtension = '.mjs';\n plugins = [fileLoaderPlugin(opts.fileCache, ['.js', '/index.js'], dtsMode)];\n }\n\n // Create the bundle\n const bundle = await rolldown({\n context: 'this',\n external: (moduleId, parentId) => isExternalDependency(moduleId, parentId, jail),\n input: opts.entry,\n plugins,\n onwarn: warning => {\n switch (warning.code) {\n case 'CIRCULAR_DEPENDENCY':\n case 'UNUSED_EXTERNAL_IMPORT':\n case 'THIS_IS_UNDEFINED':\n case 'EMPTY_BUNDLE':\n break;\n\n default:\n log.warn(warning.message);\n break;\n }\n },\n experimental: {\n attachDebugInfo: 'none',\n },\n resolve: {\n symlinks: false,\n },\n // Disable treeshaking when generating bundles\n // see: https://github.com/angular/angular/pull/32069\n treeshake: false,\n });\n\n // Output the bundle to disk\n const output = await bundle.write({\n name: opts.moduleName,\n format: 'es',\n dir: opts.dir,\n hoistTransitiveImports: false,\n chunkFileNames: `${opts.entryName}-[name]-[hash]${outExtension}`,\n entryFileNames: opts.entryName + outExtension,\n banner: '',\n sourcemap: opts.sourcemap,\n comments: {\n legal: true,\n annotation: true,\n jsdoc: dtsMode,\n },\n });\n\n // Close the bundle to let plugins clean up their external processes or services\n await bundle.close();\n\n return {\n files: output.output.map(f => {\n /** The map contents are in an asset file type, which makes storing the map in the cache as redudant. */\n if (f.type === 'chunk') {\n Object.defineProperty(f, 'map', { value: null, configurable: true });\n }\n\n return f;\n }),\n };\n}\n\nfunction isExternalDependency(moduleId: string, parentId: string | undefined, jail: string): boolean {\n // more information about why we don't check for 'node_modules' path\n // https://github.com/rollup/rollup-plugin-node-resolve/issues/110#issuecomment-350353632\n if (moduleId[0] === '.' || moduleId[0] === '/' || path.isAbsolute(moduleId)) {\n // if it's either 'absolute', marked to embed, starts with a '.' or '/' or is the umd bundle and is tslib\n return !parentId || !path.join(parentId, moduleId).startsWith(jail);\n }\n\n return true;\n}\n"]}
|
|
@@ -72,7 +72,7 @@ function cacheCompilerHost(graph, entryPoint, compilerOptions, moduleResolutionC
|
|
|
72
72
|
fileExists: (fileName) => {
|
|
73
73
|
const cache = sourcesFileCache.getOrCreate(fileName);
|
|
74
74
|
if (cache.exists === undefined) {
|
|
75
|
-
cache.exists = compilerHost.fileExists
|
|
75
|
+
cache.exists = compilerHost.fileExists(fileName);
|
|
76
76
|
}
|
|
77
77
|
return cache.exists;
|
|
78
78
|
},
|
|
@@ -80,7 +80,7 @@ function cacheCompilerHost(graph, entryPoint, compilerOptions, moduleResolutionC
|
|
|
80
80
|
addDependee(fileName);
|
|
81
81
|
const cache = sourcesFileCache.getOrCreate(fileName);
|
|
82
82
|
if (shouldCreateNewSourceFile || !cache.sourceFile) {
|
|
83
|
-
cache.sourceFile = compilerHost.getSourceFile
|
|
83
|
+
cache.sourceFile = compilerHost.getSourceFile(fileName, languageVersion, onError, true, ...parameters);
|
|
84
84
|
}
|
|
85
85
|
return cache.sourceFile;
|
|
86
86
|
},
|
|
@@ -91,7 +91,7 @@ function cacheCompilerHost(graph, entryPoint, compilerOptions, moduleResolutionC
|
|
|
91
91
|
const extension = path.extname(fileName);
|
|
92
92
|
if (!sourceFiles?.length && extension === '.tsbuildinfo') {
|
|
93
93
|
// Save builder info contents to specified location
|
|
94
|
-
compilerHost.writeFile
|
|
94
|
+
compilerHost.writeFile(fileName, data, writeByteOrderMark, onError, sourceFiles);
|
|
95
95
|
return;
|
|
96
96
|
}
|
|
97
97
|
(0, node_assert_1.default)(sourceFiles?.length === 1, 'Invalid TypeScript program emit for ' + fileName);
|
|
@@ -108,7 +108,7 @@ function cacheCompilerHost(graph, entryPoint, compilerOptions, moduleResolutionC
|
|
|
108
108
|
addDependee(fileName);
|
|
109
109
|
const cache = sourcesFileCache.getOrCreate(fileName);
|
|
110
110
|
if (cache.content === undefined) {
|
|
111
|
-
cache.content = compilerHost.readFile
|
|
111
|
+
cache.content = compilerHost.readFile(fileName);
|
|
112
112
|
}
|
|
113
113
|
return cache.content;
|
|
114
114
|
},
|
|
@@ -128,23 +128,26 @@ function cacheCompilerHost(graph, entryPoint, compilerOptions, moduleResolutionC
|
|
|
128
128
|
}
|
|
129
129
|
if (/(?:html?|svg)$/.test(path.extname(fileName))) {
|
|
130
130
|
// template
|
|
131
|
-
cache.content = compilerHost.readFile
|
|
131
|
+
cache.content = compilerHost.readFile(fileName);
|
|
132
132
|
}
|
|
133
133
|
else {
|
|
134
134
|
// stylesheet
|
|
135
|
+
if (!stylesheetProcessor) {
|
|
136
|
+
throw new Error('stylesheetProcessor is not available for processing stylesheets');
|
|
137
|
+
}
|
|
135
138
|
const { referencedFiles, contents, errors: esbuildErrors, warnings: esBuildWarnings, } = await stylesheetProcessor.bundleFile(fileName);
|
|
136
139
|
const node = getNode(fileName);
|
|
137
|
-
const depNodes = [...referencedFiles].map(getNode).filter(n => n !== node);
|
|
140
|
+
const depNodes = [...(referencedFiles ?? [])].map(getNode).filter(n => n !== node);
|
|
138
141
|
node.dependsOn(depNodes);
|
|
139
142
|
for (const n of node.dependees) {
|
|
140
143
|
if (n.url.endsWith('.ts')) {
|
|
141
144
|
n.dependsOn(depNodes);
|
|
142
145
|
}
|
|
143
146
|
}
|
|
144
|
-
if (esBuildWarnings?.length
|
|
147
|
+
if (esBuildWarnings?.length) {
|
|
145
148
|
(await (0, esbuild_1.formatMessages)(esBuildWarnings, { kind: 'warning' })).forEach(msg => (0, log_1.warn)(msg));
|
|
146
149
|
}
|
|
147
|
-
if (esbuildErrors?.length
|
|
150
|
+
if (esbuildErrors?.length) {
|
|
148
151
|
(await (0, esbuild_1.formatMessages)(esbuildErrors, { kind: 'error' })).forEach(msg => (0, log_1.error)(msg));
|
|
149
152
|
throw new Error(`An error has occuried while processing ${fileName}.`);
|
|
150
153
|
}
|
|
@@ -152,7 +155,7 @@ function cacheCompilerHost(graph, entryPoint, compilerOptions, moduleResolutionC
|
|
|
152
155
|
}
|
|
153
156
|
cache.exists = true;
|
|
154
157
|
}
|
|
155
|
-
return cache.content;
|
|
158
|
+
return cache.content ?? '';
|
|
156
159
|
},
|
|
157
160
|
transformResource: async (data, context) => {
|
|
158
161
|
const { containingFile, resourceFile, type } = context;
|
|
@@ -163,10 +166,10 @@ function cacheCompilerHost(graph, entryPoint, compilerOptions, moduleResolutionC
|
|
|
163
166
|
const { contents, referencedFiles, errors: esbuildErrors, warnings: esBuildWarnings, } = await stylesheetProcessor.bundleInline(data, containingFile, containingFile.endsWith('.html') ? 'css' : inlineStyleLanguage);
|
|
164
167
|
const node = getNode(containingFile);
|
|
165
168
|
node.dependsOn([...referencedFiles].map(getNode));
|
|
166
|
-
if (esBuildWarnings?.length
|
|
169
|
+
if (esBuildWarnings?.length) {
|
|
167
170
|
(await (0, esbuild_1.formatMessages)(esBuildWarnings, { kind: 'warning' })).forEach(msg => (0, log_1.warn)(msg));
|
|
168
171
|
}
|
|
169
|
-
if (esbuildErrors?.length
|
|
172
|
+
if (esbuildErrors?.length) {
|
|
170
173
|
(await (0, esbuild_1.formatMessages)(esbuildErrors, { kind: 'error' })).forEach(msg => (0, log_1.error)(msg));
|
|
171
174
|
throw new Error(`An error has occuried while processing ${containingFile}.`);
|
|
172
175
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"cache-compiler-host.js","sourceRoot":"","sources":["../../../../src/lib/ts/cache-compiler-host.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAeA,8CAyMC;AAED,oEAaC;AAtOD,mCAAoC;AACpC,qCAAyC;AACzC,8DAAiC;AACjC,2CAA6B;AAC7B,4DAA4B;AAI5B,wCAAqC;AACrC,+CAA8D;AAE9D,sCAA2C;AAC3C,wCAA+C;AAE/C,SAAgB,iBAAiB,CAC/B,KAAiB,EACjB,UAA0B,EAC1B,eAAgC,EAChC,qBAA+C,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AC,IAAA,UAAI,EAAC,GAAG,CAAC,CAAC,CAAC;gBACzF,CAAC;gBAED,IAAI,aAAa,EAAE,MAAM,GAAG,CAAC,EAAE,CAAC;oBAC9B,CAAC,MAAM,IAAA,wBAAc,EAAC,aAAa,EAAE,EAAE,IAAI,EAAE,OAAO,EAAE,CAAC,CAAC,CAAC,OAAO,CAAC,GAAG,CAAC,EAAE,CAAC,IAAA,WAAK,EAAC,GAAG,CAAC,CAAC,CAAC;oBAEpF,MAAM,IAAI,KAAK,CAAC,0CAA0C,cAAc,GAAG,CAAC,CAAC;gBAC/E,CAAC;gBAED,OAAO,EAAE,OAAO,EAAE,QAAQ,EAAE,CAAC;YAC/B,CAAC;YAED,OAAO,IAAI,CAAC;QACd,CAAC;KACF,CAAC;AACJ,CAAC;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,CAAC,GAAG,UAAU,CAAC,CAAC;QAEnG,KAAK,MAAM,IAAI,IAAI,KAAK,EAAE,CAAC;YACzB,IAAI,IAAI,CAAC,OAAO,KAAK,SAAS,EAAE,CAAC;gBAC/B,IAAI,CAAC,OAAO,GAAG,IAAA,mBAAU,EAAC,QAAQ,CAAC,CAAC,MAAM,CAAC,IAAI,CAAC,IAAI,CAAC,CAAC,MAAM,CAAC,KAAK,CAAC,CAAC;YACtE,CAAC;QACH,CAAC;QAED,OAAO,KAAK,CAAC;IACf,CAAC,CAAC;AACJ,CAAC","sourcesContent":["import type { CompilerHost, CompilerOptions } from '@angular/compiler-cli';\nimport { createHash } from 'crypto';\nimport { formatMessages } from 'esbuild';\nimport assert from 'node:assert';\nimport * as path from 'path';\nimport ts from 'typescript';\nimport { NgPackageConfig } from '../../ng-package.schema';\nimport { FileCache } from '../file-system/file-cache';\nimport { BuildGraph } from '../graph/build-graph';\nimport { Node } from '../graph/node';\nimport { EntryPointNode, fileUrl } from '../ng-package/nodes';\nimport { StylesheetProcessor } from '../styles/stylesheet-processor';\nimport { error, warn } from '../utils/log';\nimport { ensureUnixPath } from '../utils/path';\n\nexport function cacheCompilerHost(\n graph: BuildGraph,\n entryPoint: EntryPointNode,\n compilerOptions: CompilerOptions,\n moduleResolutionCache: ts.ModuleResolutionCache,\n stylesheetProcessor?: StylesheetProcessor,\n inlineStyleLanguage?: NgPackageConfig['inlineStyleLanguage'],\n sourcesFileCache: FileCache = entryPoint.cache.sourcesFileCache,\n): 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 // Set the parsing mode to the same as TS 5.3+ default for tsc. This provides a parse\n // performance improvement by skipping non-type related JSDoc parsing.\n jsDocParsingMode: ts.JSDocParsingMode.ParseForTypeErrors,\n\n // ts specific\n getModuleResolutionCache: () => moduleResolutionCache,\n\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\n return cache.exists;\n },\n\n getSourceFile: (fileName, languageVersion, onError, shouldCreateNewSourceFile, ...parameters) => {\n addDependee(fileName);\n const cache = sourcesFileCache.getOrCreate(fileName);\n\n if (shouldCreateNewSourceFile || !cache.sourceFile) {\n cache.sourceFile = compilerHost.getSourceFile.call(\n this,\n fileName,\n languageVersion,\n onError,\n true,\n ...parameters,\n );\n }\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.includes('.ngtypecheck.')) {\n return;\n }\n\n const extension = path.extname(fileName);\n if (!sourceFiles?.length && extension === '.tsbuildinfo') {\n // Save builder info contents to specified location\n compilerHost.writeFile.call(this, fileName, data, writeByteOrderMark, onError, sourceFiles);\n\n return;\n }\n\n assert(sourceFiles?.length === 1, 'Invalid TypeScript program emit for ' + fileName);\n const outputCache = entryPoint.cache.outputCache;\n if (outputCache.get(fileName)?.content === data) {\n return;\n }\n\n outputCache.set(fileName, {\n content: data,\n version: createHash('sha256').update(data).digest('hex'),\n });\n },\n\n readFile: (fileName: string) => {\n addDependee(fileName);\n const cache = sourcesFileCache.getOrCreate(fileName);\n if (cache.content === undefined) {\n cache.content = compilerHost.readFile.call(this, fileName);\n }\n\n return cache.content;\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 (!compilerHost.fileExists(fileName)) {\n throw new Error(`Cannot read file ${fileName}.`);\n }\n\n if (/(?:html?|svg)$/.test(path.extname(fileName))) {\n // template\n cache.content = compilerHost.readFile.call(this, fileName);\n } else {\n // stylesheet\n const {\n referencedFiles,\n contents,\n errors: esbuildErrors,\n warnings: esBuildWarnings,\n } = await stylesheetProcessor.bundleFile(fileName);\n const node = getNode(fileName);\n const depNodes = [...referencedFiles].map(getNode).filter(n => n !== node);\n node.dependsOn(depNodes);\n\n for (const n of node.dependees) {\n if (n.url.endsWith('.ts')) {\n n.dependsOn(depNodes);\n }\n }\n\n if (esBuildWarnings?.length > 0) {\n (await formatMessages(esBuildWarnings, { kind: 'warning' })).forEach(msg => warn(msg));\n }\n\n if (esbuildErrors?.length > 0) {\n (await formatMessages(esbuildErrors, { kind: 'error' })).forEach(msg => error(msg));\n\n throw new Error(`An error has occuried while processing ${fileName}.`);\n }\n\n return contents;\n }\n\n cache.exists = true;\n }\n\n return cache.content;\n },\n transformResource: async (data, context) => {\n const { containingFile, resourceFile, type } = context;\n\n if (resourceFile || type !== 'style') {\n return null;\n }\n\n if (inlineStyleLanguage) {\n const {\n contents,\n referencedFiles,\n errors: esbuildErrors,\n warnings: esBuildWarnings,\n } = await stylesheetProcessor.bundleInline(\n data,\n containingFile,\n containingFile.endsWith('.html') ? 'css' : inlineStyleLanguage,\n );\n\n const node = getNode(containingFile);\n node.dependsOn([...referencedFiles].map(getNode));\n\n if (esBuildWarnings?.length > 0) {\n (await formatMessages(esBuildWarnings, { kind: 'warning' })).forEach(msg => warn(msg));\n }\n\n if (esbuildErrors?.length > 0) {\n (await formatMessages(esbuildErrors, { kind: 'error' })).forEach(msg => error(msg));\n\n throw new Error(`An error has occuried while processing ${containingFile}.`);\n }\n\n return { content: contents };\n }\n\n return null;\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"]}
|
|
1
|
+
{"version":3,"file":"cache-compiler-host.js","sourceRoot":"","sources":["../../../../src/lib/ts/cache-compiler-host.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAeA,8CAqMC;AAED,oEAaC;AAlOD,mCAAoC;AACpC,qCAAyC;AACzC,8DAAiC;AACjC,2CAA6B;AAC7B,4DAA4B;AAI5B,wCAAqC;AACrC,+CAA8D;AAE9D,sCAA2C;AAC3C,wCAA+C;AAE/C,SAAgB,iBAAiB,CAC/B,KAAiB,EACjB,UAA0B,EAC1B,e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EAAE,CAAC,IAAA,UAAI,EAAC,GAAG,CAAC,CAAC,CAAC;gBACzF,CAAC;gBAED,IAAI,aAAa,EAAE,MAAM,EAAE,CAAC;oBAC1B,CAAC,MAAM,IAAA,wBAAc,EAAC,aAAa,EAAE,EAAE,IAAI,EAAE,OAAO,EAAE,CAAC,CAAC,CAAC,OAAO,CAAC,GAAG,CAAC,EAAE,CAAC,IAAA,WAAK,EAAC,GAAG,CAAC,CAAC,CAAC;oBAEpF,MAAM,IAAI,KAAK,CAAC,0CAA0C,cAAc,GAAG,CAAC,CAAC;gBAC/E,CAAC;gBAED,OAAO,EAAE,OAAO,EAAE,QAAQ,EAAE,CAAC;YAC/B,CAAC;YAED,OAAO,IAAI,CAAC;QACd,CAAC;KACF,CAAC;AACJ,CAAC;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,CAAC,GAAG,UAAU,CAAC,CAAC;QAEnG,KAAK,MAAM,IAAI,IAAI,KAAK,EAAE,CAAC;YACzB,IAAI,IAAI,CAAC,OAAO,KAAK,SAAS,EAAE,CAAC;gBAC/B,IAAI,CAAC,OAAO,GAAG,IAAA,mBAAU,EAAC,QAAQ,CAAC,CAAC,MAAM,CAAC,IAAI,CAAC,IAAI,CAAC,CAAC,MAAM,CAAC,KAAK,CAAC,CAAC;YACtE,CAAC;QACH,CAAC;QAED,OAAO,KAAK,CAAC;IACf,CAAC,CAAC;AACJ,CAAC","sourcesContent":["import type { CompilerHost, CompilerOptions } from '@angular/compiler-cli';\nimport { createHash } from 'crypto';\nimport { formatMessages } from 'esbuild';\nimport assert from 'node:assert';\nimport * as path from 'path';\nimport ts from 'typescript';\nimport { NgPackageConfig } from '../../ng-package.schema';\nimport { FileCache } from '../file-system/file-cache';\nimport { BuildGraph } from '../graph/build-graph';\nimport { Node } from '../graph/node';\nimport { EntryPointNode, fileUrl } from '../ng-package/nodes';\nimport { StylesheetProcessor } from '../styles/stylesheet-processor';\nimport { error, warn } from '../utils/log';\nimport { ensureUnixPath } from '../utils/path';\n\nexport function cacheCompilerHost(\n graph: BuildGraph,\n entryPoint: EntryPointNode,\n compilerOptions: CompilerOptions,\n moduleResolutionCache: ts.ModuleResolutionCache,\n stylesheetProcessor?: StylesheetProcessor,\n inlineStyleLanguage?: NgPackageConfig['inlineStyleLanguage'],\n sourcesFileCache: FileCache = entryPoint.cache.sourcesFileCache,\n): 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 // Set the parsing mode to the same as TS 5.3+ default for tsc. This provides a parse\n // performance improvement by skipping non-type related JSDoc parsing.\n jsDocParsingMode: ts.JSDocParsingMode.ParseForTypeErrors,\n\n // ts specific\n getModuleResolutionCache: () => moduleResolutionCache,\n\n fileExists: (fileName: string) => {\n const cache = sourcesFileCache.getOrCreate(fileName);\n if (cache.exists === undefined) {\n cache.exists = compilerHost.fileExists(fileName);\n }\n\n return cache.exists;\n },\n\n getSourceFile: (fileName, languageVersion, onError, shouldCreateNewSourceFile, ...parameters) => {\n addDependee(fileName);\n const cache = sourcesFileCache.getOrCreate(fileName);\n\n if (shouldCreateNewSourceFile || !cache.sourceFile) {\n cache.sourceFile = compilerHost.getSourceFile(fileName, languageVersion, onError, true, ...parameters);\n }\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.includes('.ngtypecheck.')) {\n return;\n }\n\n const extension = path.extname(fileName);\n if (!sourceFiles?.length && extension === '.tsbuildinfo') {\n // Save builder info contents to specified location\n compilerHost.writeFile(fileName, data, writeByteOrderMark, onError, sourceFiles);\n\n return;\n }\n\n assert(sourceFiles?.length === 1, 'Invalid TypeScript program emit for ' + fileName);\n const outputCache = entryPoint.cache.outputCache;\n if (outputCache.get(fileName)?.content === data) {\n return;\n }\n\n outputCache.set(fileName, {\n content: data,\n version: createHash('sha256').update(data).digest('hex'),\n });\n },\n\n readFile: (fileName: string) => {\n addDependee(fileName);\n const cache = sourcesFileCache.getOrCreate(fileName);\n if (cache.content === undefined) {\n cache.content = compilerHost.readFile(fileName);\n }\n\n return cache.content;\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): Promise<string> => {\n addDependee(fileName);\n\n const cache = sourcesFileCache.getOrCreate(fileName);\n if (cache.content === undefined) {\n if (!compilerHost.fileExists(fileName)) {\n throw new Error(`Cannot read file ${fileName}.`);\n }\n\n if (/(?:html?|svg)$/.test(path.extname(fileName))) {\n // template\n cache.content = compilerHost.readFile(fileName);\n } else {\n // stylesheet\n if (!stylesheetProcessor) {\n throw new Error('stylesheetProcessor is not available for processing stylesheets');\n }\n const {\n referencedFiles,\n contents,\n errors: esbuildErrors,\n warnings: esBuildWarnings,\n } = await stylesheetProcessor.bundleFile(fileName);\n const node = getNode(fileName);\n const depNodes = [...(referencedFiles ?? [])].map(getNode).filter(n => n !== node);\n node.dependsOn(depNodes);\n\n for (const n of node.dependees) {\n if (n.url.endsWith('.ts')) {\n n.dependsOn(depNodes);\n }\n }\n\n if (esBuildWarnings?.length) {\n (await formatMessages(esBuildWarnings, { kind: 'warning' })).forEach(msg => warn(msg));\n }\n\n if (esbuildErrors?.length) {\n (await formatMessages(esbuildErrors, { kind: 'error' })).forEach(msg => error(msg));\n\n throw new Error(`An error has occuried while processing ${fileName}.`);\n }\n\n return contents;\n }\n\n cache.exists = true;\n }\n\n return cache.content ?? '';\n },\n transformResource: async (data, context) => {\n const { containingFile, resourceFile, type } = context;\n\n if (resourceFile || type !== 'style') {\n return null;\n }\n\n if (inlineStyleLanguage) {\n const {\n contents,\n referencedFiles,\n errors: esbuildErrors,\n warnings: esBuildWarnings,\n } = await stylesheetProcessor.bundleInline(\n data,\n containingFile,\n containingFile.endsWith('.html') ? 'css' : inlineStyleLanguage,\n );\n\n const node = getNode(containingFile);\n node.dependsOn([...referencedFiles].map(getNode));\n\n if (esBuildWarnings?.length) {\n (await formatMessages(esBuildWarnings, { kind: 'warning' })).forEach(msg => warn(msg));\n }\n\n if (esbuildErrors?.length) {\n (await formatMessages(esbuildErrors, { kind: 'error' })).forEach(msg => error(msg));\n\n throw new Error(`An error has occuried while processing ${containingFile}.`);\n }\n\n return { content: contents };\n }\n\n return null;\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"]}
|