ng-packagr 22.2.0-next.2 → 22.2.0-next.4
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 +4 -4
- package/src/lib/file-system/file-watcher.js +2 -1
- package/src/lib/file-system/file-watcher.js.map +1 -1
- package/src/lib/flatten/file-loader-plugin.d.ts +1 -1
- package/src/lib/flatten/file-loader-plugin.js +48 -22
- package/src/lib/flatten/file-loader-plugin.js.map +1 -1
- package/src/lib/flatten/rolldown.js +2 -8
- package/src/lib/flatten/rolldown.js.map +1 -1
- package/src/lib/ng-package/entry-point/analyse-sources.transform.js +169 -61
- package/src/lib/ng-package/entry-point/analyse-sources.transform.js.map +1 -1
- package/src/lib/ng-package/entry-point/entry-point.d.ts +1 -1
- package/src/lib/ng-package/entry-point/entry-point.js.map +1 -1
- package/src/lib/ng-package/entry-point/write-bundles.transform.js +23 -12
- package/src/lib/ng-package/entry-point/write-bundles.transform.js.map +1 -1
- package/src/lib/ng-package/nodes.d.ts +4 -4
- package/src/lib/ng-package/nodes.js +3 -2
- package/src/lib/ng-package/nodes.js.map +1 -1
- package/src/lib/ngc/compile-source-files.js +23 -9
- package/src/lib/ngc/compile-source-files.js.map +1 -1
- package/src/lib/styles/bundler-context.d.ts +3 -2
- package/src/lib/styles/bundler-context.js +120 -28
- package/src/lib/styles/bundler-context.js.map +1 -1
- package/src/lib/styles/cache.d.ts +10 -0
- package/src/lib/styles/cache.js +18 -0
- package/src/lib/styles/cache.js.map +1 -1
- package/src/lib/styles/component-stylesheets.d.ts +3 -3
- package/src/lib/styles/component-stylesheets.js +34 -7
- package/src/lib/styles/component-stylesheets.js.map +1 -1
- package/src/lib/styles/css-url.enum.d.ts +4 -0
- package/src/lib/styles/css-url.enum.js +9 -0
- package/src/lib/styles/css-url.enum.js.map +1 -0
- package/src/lib/styles/load-result-cache.d.ts +2 -0
- package/src/lib/styles/load-result-cache.js +7 -3
- package/src/lib/styles/load-result-cache.js.map +1 -1
- package/src/lib/styles/stylesheet-processor.d.ts +1 -4
- package/src/lib/styles/stylesheet-processor.js +1 -6
- package/src/lib/styles/stylesheet-processor.js.map +1 -1
- package/src/lib/styles/stylesheets/css-resource-plugin.d.ts +1 -1
- package/src/lib/styles/stylesheets/css-resource-plugin.js +2 -2
- package/src/lib/styles/stylesheets/css-resource-plugin.js.map +1 -1
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "ng-packagr",
|
|
3
|
-
"version": "22.2.0-next.
|
|
3
|
+
"version": "22.2.0-next.4",
|
|
4
4
|
"description": "Compile and package Angular libraries in Angular Package Format (APF)",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"apf",
|
|
@@ -38,7 +38,7 @@
|
|
|
38
38
|
"chokidar": "^5.0.0",
|
|
39
39
|
"commander": "^15.0.0",
|
|
40
40
|
"dependency-graph": "^1.0.0",
|
|
41
|
-
"esbuild": "^0.28.
|
|
41
|
+
"esbuild": "^0.28.2",
|
|
42
42
|
"find-cache-directory": "^6.0.0",
|
|
43
43
|
"injection-js": "^2.4.0",
|
|
44
44
|
"jsonc-parser": "^3.3.1",
|
|
@@ -47,13 +47,13 @@
|
|
|
47
47
|
"piscina": "^5.0.0",
|
|
48
48
|
"postcss": "^8.4.47",
|
|
49
49
|
"rolldown": "^1.2.0",
|
|
50
|
-
"rolldown-plugin-dts": "^0.
|
|
50
|
+
"rolldown-plugin-dts": "^0.28.0",
|
|
51
51
|
"rxjs": "^7.8.1",
|
|
52
52
|
"sass": "^1.81.0",
|
|
53
53
|
"tinyglobby": "^0.2.12"
|
|
54
54
|
},
|
|
55
55
|
"peerDependencies": {
|
|
56
|
-
"@angular/compiler-cli": "^22.
|
|
56
|
+
"@angular/compiler-cli": "^22.2.0-next",
|
|
57
57
|
"tailwindcss": "^2.0.0 || ^3.0.0 || ^4.0.0",
|
|
58
58
|
"tslib": "^2.3.0",
|
|
59
59
|
"typescript": ">=6.0 <6.1"
|
|
@@ -134,7 +134,8 @@ function invalidateEntryPointsAndCacheOnFileChange(graph, files, sourcesFileCach
|
|
|
134
134
|
continue;
|
|
135
135
|
}
|
|
136
136
|
entryPoint.cache.angularDiagnosticCache.delete(filePath);
|
|
137
|
-
entryPoint.cache.
|
|
137
|
+
entryPoint.cache.declarationDiagnosticCache?.delete(filePath);
|
|
138
|
+
entryPoint.cache.analyseSourcesFileCache.delete(filePath);
|
|
138
139
|
isDirty = true;
|
|
139
140
|
}
|
|
140
141
|
if (isDirty) {
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"file-watcher.js","sourceRoot":"","sources":["../../../../src/lib/file-system/file-watcher.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAmBA,0CAyDC;AAOD,
|
|
1
|
+
{"version":3,"file":"file-watcher.js","sourceRoot":"","sources":["../../../../src/lib/file-system/file-watcher.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAmBA,0CAyDC;AAOD,8FAqEC;AAxJD,mDAAqC;AACrC,2BAA8B;AAC9B,2CAA6B;AAC7B,+BAA4C;AAE5C,wCAAoD;AACpD,+CAAyE;AACzE,kDAAoC;AACpC,wCAA+C;AAW/C,SAAgB,eAAe,CAC7B,SAA4B,EAC5B,eAAyB,EAAE,EAC3B,IAAa;IAKb,GAAG,CAAC,KAAK,CAAC,mCAAmC,SAAS,mBAAmB,YAAY,EAAE,CAAC,CAAC;IAEzF,MAAM,KAAK,GAAG,QAAQ,CAAC,KAAK,CAAC,EAAE,EAAE;QAC/B,aAAa,EAAE,IAAI;QACnB,OAAO,EAAE;YACP,QAAQ;YACR,eAAe;YACf,IAAI,CAAC,EAAE;gBACL,MAAM,cAAc,GAAG,IAAA,qBAAc,EAAC,IAAI,CAAC,CAAC;gBAE5C,OAAO,YAAY,CAAC,IAAI,CAAC,CAAC,CAAC,EAAE,CAAC,cAAc,CAAC,UAAU,CAAC,CAAC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EAAE,CAAC;gBAC9B,wBAAwB,CAAC,GAAG,CAAC,QAAQ,CAAC,CAAC;YACzC,CAAC;QACH,CAAC;IACH,CAAC;IAED,MAAM,WAAW,GAAG,KAAK,CAAC,MAAM,CAAC,oBAAY,CAAC,CAAC;IAC/C,KAAK,MAAM,UAAU,IAAI,WAAW,EAAE,CAAC;QACrC,IAAI,OAAO,GAAG,KAAK,CAAC;QACpB,IAAI,wBAAwB,CAAC,IAAI,GAAG,CAAC,EAAE,CAAC;YACtC,OAAO,GAAG,CAAC,CAAC,UAAU,CAAC,KAAK,CAAC,mBAAmB,EAAE,UAAU,CAAC,wBAAwB,CAAC,EAAE,MAAM,CAAC;QACjG,CAAC;QAED,KAAK,MAAM,CAAC,QAAQ,EAAE,SAAS,CAAC,IAAI,eAAe,EAAE,CAAC;YACpD,IAAI,CAAC,UAAU,CAAC,UAAU,CAAC,GAAG,CAAC,SAAS,CAAC,EAAE,CAAC;gBAC1C,SAAS;YACX,CAAC;YAED,UAAU,CAAC,KAAK,CAAC,sBAAsB,CAAC,MAAM,CAAC,QAAQ,CAAC,CAAC;YACzD,UAAU,CAAC,KAAK,CAAC,0BAA0B,EAAE,MAAM,CAAC,QAAQ,CAAC,CAAC;YAC9D,UAAU,CAAC,KAAK,CAAC,uBAAuB,CAAC,MAAM,CAAC,QAAQ,CAAC,CAAC;YAC1D,OAAO,GAAG,IAAI,CAAC;QACjB,CAAC;QAED,IAAI,OAAO,EAAE,CAAC;YACZ,UAAU,CAAC,KAAK,GAAG,oBAAa,CAAC;YACjC,qBAAqB,GAAG,IAAI,CAAC;QAC/B,CAAC;IACH,CAAC;IAED,OAAO,qBAAqB,CAAC;AAC/B,CAAC","sourcesContent":["import * as chokidar from 'chokidar';\nimport { platform } from 'os';\nimport * as path from 'path';\nimport { Observable, Observer } from 'rxjs';\nimport { BuildGraph } from '../graph/build-graph';\nimport { Node, STATE_PENDING } from '../graph/node';\nimport { fileUrl, fileUrlPath, isEntryPoint } from '../ng-package/nodes';\nimport * as log from '../utils/log';\nimport { ensureUnixPath } from '../utils/path';\nimport { FileCache } from './file-cache';\n\ntype AllFileWatchEvents = 'change' | 'unlink' | 'add' | 'unlinkDir' | 'addDir';\nexport type FileWatchEvent = Exclude<AllFileWatchEvents, 'unlinkDir' | 'addDir'>;\n\nexport interface FileChangedEvent {\n filePath: string;\n event: FileWatchEvent;\n}\n\nexport function createFileWatch(\n basePaths: string | string[],\n ignoredPaths: string[] = [],\n poll?: number,\n): {\n watcher: chokidar.FSWatcher;\n onFileChange: Observable<FileChangedEvent>;\n} {\n log.debug(`Watching for changes: basePath: ${basePaths}, ignoredPaths: ${ignoredPaths}`);\n\n const watch = chokidar.watch([], {\n ignoreInitial: true,\n ignored: [\n /\\.map$/,\n /.tsbuildinfo$/,\n file => {\n const normalizedPath = ensureUnixPath(file);\n\n return ignoredPaths.some(f => normalizedPath.startsWith(f));\n },\n ],\n persistent: true,\n usePolling: typeof poll === 'number' ? true : false,\n interval: typeof poll === 'number' ? poll : undefined,\n });\n\n const isLinux = platform() === 'linux';\n const handleFileChange = (event: AllFileWatchEvents, filePath: string, observer: Observer<FileChangedEvent>) => {\n log.debug(`Watch: Path changed. Event: ${event}, Path: ${filePath}`);\n\n if (isLinux) {\n // Workaround for Linux where chokidar will not handle future events\n // for files that were unlinked and immediately recreated.\n watch.unwatch(filePath);\n watch.add(filePath);\n }\n\n if (event === 'unlinkDir' || event === 'addDir') {\n // we don't need to trigger on directory removed or renamed as chokidar will fire the changes for each file\n return;\n }\n\n observer.next({\n filePath: ensureUnixPath(path.resolve(filePath)),\n event,\n });\n };\n\n return {\n watcher: watch,\n onFileChange: new Observable(observer => {\n watch.on('all', (event: AllFileWatchEvents, filePath: string) => handleFileChange(event, filePath, observer));\n\n // eslint-disable-next-line @typescript-eslint/no-misused-promises\n return () => watch.close();\n }),\n };\n}\n\n/**\n * Invalidates entry points and cache when specified files change.\n *\n * @returns - Returns `true` if any entry point was invalidated, otherwise `false`.\n */\nexport function invalidateEntryPointsAndCacheOnFileChange(\n graph: BuildGraph,\n files: string[],\n sourcesFileCache: FileCache,\n): boolean {\n let invalidatedEntryPoint = false;\n const allNodesToClean: Map<string, Node> = new Map();\n\n for (const filePath of files) {\n const changedFileUrl = fileUrl(filePath);\n const nodeToClean = graph.find(node => changedFileUrl === node.url);\n if (!nodeToClean) {\n continue;\n }\n\n allNodesToClean.set(filePath, nodeToClean);\n }\n\n // delete node that changes\n const potentialStylesResources = new Set<string>();\n for (const [filePath, nodeToClean] of allNodesToClean) {\n sourcesFileCache.delete(filePath);\n\n if (filePath.endsWith('.ts')) {\n continue;\n }\n\n // if a non ts file changes we need to clean up its direct dependees\n // this is mainly done for resources such as html and css\n potentialStylesResources.add(filePath);\n for (const dependees of nodeToClean.dependees) {\n const filePath = fileUrlPath(dependees.url);\n if (!filePath) {\n continue;\n }\n\n allNodesToClean.set(filePath, dependees);\n\n if (!filePath.endsWith('.ts')) {\n potentialStylesResources.add(filePath);\n }\n }\n }\n\n const entryPoints = graph.filter(isEntryPoint);\n for (const entryPoint of entryPoints) {\n let isDirty = false;\n if (potentialStylesResources.size > 0) {\n isDirty = !!entryPoint.cache.stylesheetProcessor?.invalidate(potentialStylesResources)?.length;\n }\n\n for (const [filePath, dependent] of allNodesToClean) {\n if (!entryPoint.dependents.has(dependent)) {\n continue;\n }\n\n entryPoint.cache.angularDiagnosticCache.delete(filePath);\n entryPoint.cache.declarationDiagnosticCache?.delete(filePath);\n entryPoint.cache.analyseSourcesFileCache.delete(filePath);\n isDirty = true;\n }\n\n if (isDirty) {\n entryPoint.state = STATE_PENDING;\n invalidatedEntryPoint = true;\n }\n }\n\n return invalidatedEntryPoint;\n}\n"]}
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import type { Plugin } from 'rolldown';
|
|
2
2
|
import { OutputFileCache } from '../ng-package/nodes';
|
|
3
3
|
/**
|
|
4
|
-
* Loads a file and
|
|
4
|
+
* Loads a file and its map.
|
|
5
5
|
*/
|
|
6
6
|
export declare function fileLoaderPlugin(fileCache: OutputFileCache, resolutionExtensions: string[], dtsMode: boolean): Plugin;
|
|
@@ -38,38 +38,64 @@ const node_path_1 = require("node:path");
|
|
|
38
38
|
const log = __importStar(require("../utils/log"));
|
|
39
39
|
const path_1 = require("../utils/path");
|
|
40
40
|
/**
|
|
41
|
-
*
|
|
42
|
-
*/
|
|
43
|
-
const FILE_EXT_REGEXP = /\.(c|m)?(t|j)s$/;
|
|
44
|
-
/**
|
|
45
|
-
* Loads a file and it's map.
|
|
41
|
+
* Loads a file and its map.
|
|
46
42
|
*/
|
|
47
43
|
function fileLoaderPlugin(fileCache, resolutionExtensions, dtsMode) {
|
|
48
44
|
return {
|
|
49
45
|
name: 'file-loader',
|
|
50
46
|
resolveId: function (id, importer) {
|
|
51
|
-
|
|
52
|
-
if (
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
: normalizedId.replace(FILE_EXT_REGEXP, (_match, p1) => {
|
|
58
|
-
if (dtsMode) {
|
|
59
|
-
return p1 ? `.d.${p1}ts` : '.d.ts';
|
|
60
|
-
}
|
|
61
|
-
return p1 ? `.${p1}js` : '.js';
|
|
62
|
-
});
|
|
63
|
-
if (fileCache.has(potentialId)) {
|
|
64
|
-
return potentialId;
|
|
47
|
+
let resolved;
|
|
48
|
+
if (importer) {
|
|
49
|
+
if (id[0] !== '.' && id[0] !== '/' && !(0, node_path_1.isAbsolute)(id)) {
|
|
50
|
+
return;
|
|
51
|
+
}
|
|
52
|
+
resolved = (0, path_1.ensureUnixPath)((0, node_path_1.resolve)((0, node_path_1.dirname)(importer), id));
|
|
65
53
|
}
|
|
66
|
-
|
|
67
|
-
|
|
54
|
+
else {
|
|
55
|
+
resolved = (0, path_1.ensureUnixPath)(id);
|
|
68
56
|
}
|
|
69
|
-
const resolved = (0, path_1.ensureUnixPath)((0, node_path_1.resolve)((0, node_path_1.dirname)(importer), potentialId));
|
|
70
57
|
if (fileCache.has(resolved)) {
|
|
71
58
|
return resolved;
|
|
72
59
|
}
|
|
60
|
+
const ext = (0, node_path_1.extname)(resolved);
|
|
61
|
+
const base = resolved.slice(0, -ext.length);
|
|
62
|
+
if (dtsMode) {
|
|
63
|
+
let potential;
|
|
64
|
+
switch (ext) {
|
|
65
|
+
case '.js':
|
|
66
|
+
case '.ts':
|
|
67
|
+
potential = `${base}.d.ts`;
|
|
68
|
+
break;
|
|
69
|
+
case '.mjs':
|
|
70
|
+
case '.mts':
|
|
71
|
+
potential = `${base}.d.mts`;
|
|
72
|
+
break;
|
|
73
|
+
case '.cjs':
|
|
74
|
+
case '.cts':
|
|
75
|
+
potential = `${base}.d.cts`;
|
|
76
|
+
break;
|
|
77
|
+
}
|
|
78
|
+
if (potential && fileCache.has(potential)) {
|
|
79
|
+
return potential;
|
|
80
|
+
}
|
|
81
|
+
}
|
|
82
|
+
else {
|
|
83
|
+
let potential;
|
|
84
|
+
switch (ext) {
|
|
85
|
+
case '.ts':
|
|
86
|
+
potential = `${base}.js`;
|
|
87
|
+
break;
|
|
88
|
+
case '.mts':
|
|
89
|
+
potential = `${base}.mjs`;
|
|
90
|
+
break;
|
|
91
|
+
case '.cts':
|
|
92
|
+
potential = `${base}.cjs`;
|
|
93
|
+
break;
|
|
94
|
+
}
|
|
95
|
+
if (potential && fileCache.has(potential)) {
|
|
96
|
+
return potential;
|
|
97
|
+
}
|
|
98
|
+
}
|
|
73
99
|
for (const suffix of resolutionExtensions) {
|
|
74
100
|
const potential = resolved + suffix;
|
|
75
101
|
if (fileCache.has(potential)) {
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"file-loader-plugin.js","sourceRoot":"","sources":["../../../../src/lib/flatten/file-loader-plugin.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
|
|
1
|
+
{"version":3,"file":"file-loader-plugin.js","sourceRoot":"","sources":["../../../../src/lib/flatten/file-loader-plugin.ts"],"names":[],"mappings":";;;;;;;;;;;;;;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AS,CAAC,GAAG,CAAC,GAAG,EAAE,MAAM,CAAC,EAAE,OAAO;aACzC,CAAC;QACJ,CAAC;KACF,CAAC;AACJ,CAAC","sourcesContent":["import { dirname, extname, isAbsolute, resolve } from 'node:path';\nimport type { Plugin } from 'rolldown';\nimport { OutputFileCache } from '../ng-package/nodes';\n\nimport * as log from '../utils/log';\nimport { ensureUnixPath } from '../utils/path';\n\n/**\n * Loads a file and its map.\n */\nexport function fileLoaderPlugin(fileCache: OutputFileCache, resolutionExtensions: string[], dtsMode: boolean): Plugin {\n return {\n name: 'file-loader',\n resolveId: function (id, importer) {\n let resolved: string;\n if (importer) {\n if (id[0] !== '.' && id[0] !== '/' && !isAbsolute(id)) {\n return;\n }\n\n resolved = ensureUnixPath(resolve(dirname(importer), id));\n } else {\n resolved = ensureUnixPath(id);\n }\n\n if (fileCache.has(resolved)) {\n return resolved;\n }\n\n const ext = extname(resolved);\n const base = resolved.slice(0, -ext.length);\n if (dtsMode) {\n let potential: string | undefined;\n switch (ext) {\n case '.js':\n case '.ts':\n potential = `${base}.d.ts`;\n break;\n case '.mjs':\n case '.mts':\n potential = `${base}.d.mts`;\n break;\n case '.cjs':\n case '.cts':\n potential = `${base}.d.cts`;\n break;\n }\n\n if (potential && fileCache.has(potential)) {\n return potential;\n }\n } else {\n let potential: string | undefined;\n switch (ext) {\n case '.ts':\n potential = `${base}.js`;\n break;\n case '.mts':\n potential = `${base}.mjs`;\n break;\n case '.cts':\n potential = `${base}.cjs`;\n break;\n }\n\n if (potential && fileCache.has(potential)) {\n return potential;\n }\n }\n\n for (const suffix of resolutionExtensions) {\n const potential = resolved + suffix;\n if (fileCache.has(potential)) {\n return potential;\n }\n }\n },\n load: function (id) {\n log.debug(`file-loader ${id}`);\n const data = fileCache.get(id);\n if (!data) {\n throw new Error(`Could not load '${id}' from memory.`);\n }\n\n return {\n code: data.content,\n map: fileCache.get(`${id}.map`)?.content,\n };\n },\n };\n}\n"]}
|
|
@@ -34,7 +34,7 @@ var __importStar = (this && this.__importStar) || (function () {
|
|
|
34
34
|
})();
|
|
35
35
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
36
36
|
exports.rolldownBundleFile = rolldownBundleFile;
|
|
37
|
-
const path = __importStar(require("path"));
|
|
37
|
+
const path = __importStar(require("node:path"));
|
|
38
38
|
const rolldown_1 = require("rolldown");
|
|
39
39
|
const rolldown_plugin_dts_1 = require("rolldown-plugin-dts");
|
|
40
40
|
const log = __importStar(require("../utils/log"));
|
|
@@ -104,13 +104,7 @@ async function rolldownBundleFile(opts) {
|
|
|
104
104
|
// Close the bundle to let plugins clean up their external processes or services
|
|
105
105
|
await bundle.close();
|
|
106
106
|
return {
|
|
107
|
-
files: output.output
|
|
108
|
-
/** The map contents are in an asset file type, which makes storing the map in the cache as redudant. */
|
|
109
|
-
if (f.type === 'chunk') {
|
|
110
|
-
Object.defineProperty(f, 'map', { value: null, configurable: true });
|
|
111
|
-
}
|
|
112
|
-
return f;
|
|
113
|
-
}),
|
|
107
|
+
files: output.output,
|
|
114
108
|
};
|
|
115
109
|
}
|
|
116
110
|
function isExternalDependency(moduleId, parentId, jail) {
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"rolldown.js","sourceRoot":"","sources":["../../../../src/lib/flatten/rolldown.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAsBA,
|
|
1
|
+
{"version":3,"file":"rolldown.js","sourceRoot":"","sources":["../../../../src/lib/flatten/rolldown.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAsBA,gDAuEC;AA7FD,gDAAkC;AAClC,uCAAmG;AACnG,6DAA0C;AAE1C,kDAAoC;AACpC,6DAAwD;AAgBxD,qEAAqE;AAC9D,KAAK,UAAU,kBAAkB,CAAC,IAAqB;IAC5D,GAAG,CAAC,KAAK,CAAC,YAAY,IAAI,CAAC,KAAK,OAAO,IAAI,CAAC,GAAG,EAAE,CAAC,CA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putAsset, 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,\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"]}
|
|
@@ -1,103 +1,211 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
+
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
3
|
+
if (k2 === undefined) k2 = k;
|
|
4
|
+
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
5
|
+
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
6
|
+
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
7
|
+
}
|
|
8
|
+
Object.defineProperty(o, k2, desc);
|
|
9
|
+
}) : (function(o, m, k, k2) {
|
|
10
|
+
if (k2 === undefined) k2 = k;
|
|
11
|
+
o[k2] = m[k];
|
|
12
|
+
}));
|
|
13
|
+
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
|
|
14
|
+
Object.defineProperty(o, "default", { enumerable: true, value: v });
|
|
15
|
+
}) : function(o, v) {
|
|
16
|
+
o["default"] = v;
|
|
17
|
+
});
|
|
18
|
+
var __importStar = (this && this.__importStar) || (function () {
|
|
19
|
+
var ownKeys = function(o) {
|
|
20
|
+
ownKeys = Object.getOwnPropertyNames || function (o) {
|
|
21
|
+
var ar = [];
|
|
22
|
+
for (var k in o) if (Object.prototype.hasOwnProperty.call(o, k)) ar[ar.length] = k;
|
|
23
|
+
return ar;
|
|
24
|
+
};
|
|
25
|
+
return ownKeys(o);
|
|
26
|
+
};
|
|
27
|
+
return function (mod) {
|
|
28
|
+
if (mod && mod.__esModule) return mod;
|
|
29
|
+
var result = {};
|
|
30
|
+
if (mod != null) for (var k = ownKeys(mod), i = 0; i < k.length; i++) if (k[i] !== "default") __createBinding(result, mod, k[i]);
|
|
31
|
+
__setModuleDefault(result, mod);
|
|
32
|
+
return result;
|
|
33
|
+
};
|
|
34
|
+
})();
|
|
2
35
|
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
36
|
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
37
|
};
|
|
5
38
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
39
|
exports.analyseSourcesTransform = void 0;
|
|
7
|
-
const
|
|
40
|
+
const fs = __importStar(require("node:fs"));
|
|
41
|
+
const node_path_1 = require("node:path");
|
|
8
42
|
const rxjs_1 = require("rxjs");
|
|
9
43
|
const typescript_1 = __importDefault(require("typescript"));
|
|
10
44
|
const node_1 = require("../../graph/node");
|
|
11
|
-
const cache_compiler_host_1 = require("../../ts/cache-compiler-host");
|
|
12
45
|
const log_1 = require("../../utils/log");
|
|
13
|
-
const
|
|
46
|
+
const path_1 = require("../../utils/path");
|
|
14
47
|
const nodes_1 = require("../nodes");
|
|
15
48
|
exports.analyseSourcesTransform = (0, rxjs_1.pipe)((0, rxjs_1.map)(graph => {
|
|
16
49
|
const entryPoints = graph.filter(nodes_1.isEntryPoint);
|
|
50
|
+
const entryPointsMapped = new Map(entryPoints.map(ep => [ep.data.entryPoint.moduleId, ep]));
|
|
51
|
+
const packageNode = (0, nodes_1.findPackageNode)(graph);
|
|
52
|
+
const primaryModuleId = packageNode.data.primary.moduleId;
|
|
17
53
|
for (const entryPoint of entryPoints) {
|
|
18
54
|
if (entryPoint.state !== node_1.STATE_DONE) {
|
|
19
|
-
analyseEntryPoint(
|
|
55
|
+
analyseEntryPoint(entryPoint, entryPointsMapped, primaryModuleId);
|
|
20
56
|
}
|
|
21
57
|
}
|
|
22
58
|
return graph;
|
|
23
59
|
}));
|
|
60
|
+
const JS_TO_TS_EXTENSIONS = {
|
|
61
|
+
'.js': ['.ts', '.tsx', '.d.ts'],
|
|
62
|
+
'.mjs': ['.mts', '.d.mts'],
|
|
63
|
+
'.cjs': ['.cts', '.d.cts'],
|
|
64
|
+
};
|
|
65
|
+
const RESOLUTION_EXTENSIONS = [
|
|
66
|
+
'.ts',
|
|
67
|
+
'.tsx',
|
|
68
|
+
'.mts',
|
|
69
|
+
'.cts',
|
|
70
|
+
'.d.ts',
|
|
71
|
+
'.d.mts',
|
|
72
|
+
'.d.cts',
|
|
73
|
+
'/index.ts',
|
|
74
|
+
'/index.tsx',
|
|
75
|
+
'/index.mts',
|
|
76
|
+
'/index.cts',
|
|
77
|
+
'/index.d.ts',
|
|
78
|
+
'/index.d.mts',
|
|
79
|
+
'/index.d.cts',
|
|
80
|
+
'.js',
|
|
81
|
+
'.mjs',
|
|
82
|
+
'.cjs',
|
|
83
|
+
'/index.js',
|
|
84
|
+
'/index.mjs',
|
|
85
|
+
'/index.cjs',
|
|
86
|
+
];
|
|
87
|
+
function checkFile(filePath, fileCache) {
|
|
88
|
+
const entry = fileCache.getOrCreate(filePath);
|
|
89
|
+
if (entry.exists === undefined) {
|
|
90
|
+
const stat = fs.statSync(filePath, { throwIfNoEntry: false });
|
|
91
|
+
if (stat?.isFile()) {
|
|
92
|
+
entry.exists = true;
|
|
93
|
+
}
|
|
94
|
+
else {
|
|
95
|
+
return false;
|
|
96
|
+
}
|
|
97
|
+
}
|
|
98
|
+
return entry.exists;
|
|
99
|
+
}
|
|
100
|
+
function resolveRelativeSourceFile(dir, moduleName, fileCache) {
|
|
101
|
+
const target = (0, node_path_1.resolve)(dir, moduleName);
|
|
102
|
+
if (target.includes('/node_modules/') || target.includes('\\node_modules\\')) {
|
|
103
|
+
return undefined;
|
|
104
|
+
}
|
|
105
|
+
const ext = (0, node_path_1.extname)(target);
|
|
106
|
+
const tsExtensions = JS_TO_TS_EXTENSIONS[ext];
|
|
107
|
+
if (tsExtensions) {
|
|
108
|
+
const base = target.slice(0, -ext.length);
|
|
109
|
+
for (const tsExt of tsExtensions) {
|
|
110
|
+
const candidate = base + tsExt;
|
|
111
|
+
if (checkFile(candidate, fileCache)) {
|
|
112
|
+
return (0, path_1.ensureUnixPath)(candidate);
|
|
113
|
+
}
|
|
114
|
+
}
|
|
115
|
+
}
|
|
116
|
+
if (checkFile(target, fileCache)) {
|
|
117
|
+
return (0, path_1.ensureUnixPath)(target);
|
|
118
|
+
}
|
|
119
|
+
for (const suffix of RESOLUTION_EXTENSIONS) {
|
|
120
|
+
const candidate = target + suffix;
|
|
121
|
+
if (checkFile(candidate, fileCache)) {
|
|
122
|
+
return (0, path_1.ensureUnixPath)(candidate);
|
|
123
|
+
}
|
|
124
|
+
}
|
|
125
|
+
return undefined;
|
|
126
|
+
}
|
|
24
127
|
/**
|
|
25
|
-
* Analyses an entrypoint, searching for TypeScript dependencies and
|
|
128
|
+
* Analyses an entrypoint, searching for TypeScript dependencies and internal package imports.
|
|
26
129
|
*
|
|
27
|
-
* @param graph Build graph
|
|
28
130
|
* @param entryPoint Current entry point that should be analysed.
|
|
29
|
-
* @param
|
|
131
|
+
* @param entryPointsMapped Map of all entry points by moduleId.
|
|
132
|
+
* @param primaryModuleId The moduleId of the primary entry point.
|
|
30
133
|
*/
|
|
31
|
-
function analyseEntryPoint(
|
|
32
|
-
const {
|
|
33
|
-
const
|
|
34
|
-
const { moduleId } = entryPoint.data.entryPoint;
|
|
35
|
-
const packageNode = (0, nodes_1.findPackageNode)(graph);
|
|
36
|
-
const primaryModuleId = packageNode.data.primary.moduleId;
|
|
134
|
+
function analyseEntryPoint(entryPoint, entryPointsMapped, primaryModuleId) {
|
|
135
|
+
const { analyseSourcesFileCache } = entryPoint.cache;
|
|
136
|
+
const { moduleId, entryFilePath } = entryPoint.data.entryPoint;
|
|
37
137
|
(0, log_1.debug)(`Analysing sources for ${moduleId}`);
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
}
|
|
48
|
-
|
|
138
|
+
// If an index file exists parallel to the entryFilePath it is not valid as index should be reserved as an
|
|
139
|
+
// entry file of an entry-point based on node resolution strategy.
|
|
140
|
+
if ((0, node_path_1.basename)(entryFilePath) !== 'index.ts') {
|
|
141
|
+
const potentialIndexPath = (0, node_path_1.join)((0, node_path_1.dirname)(entryFilePath), 'index.ts');
|
|
142
|
+
if (fs.existsSync(potentialIndexPath)) {
|
|
143
|
+
throw new Error(`Entry point '${moduleId}' has an 'index.ts' parallel to the 'entryFilePath'. ` +
|
|
144
|
+
`The 'entryFilePath' should be updated to point to the 'index.ts' file.\n` +
|
|
145
|
+
`Full path: ${potentialIndexPath}`);
|
|
146
|
+
}
|
|
147
|
+
}
|
|
148
|
+
// Remove previously discovered entry point dependencies in watch mode
|
|
149
|
+
for (const dep of entryPoint.dependents) {
|
|
150
|
+
if ((0, nodes_1.isEntryPoint)(dep)) {
|
|
151
|
+
dep.dependees.delete(entryPoint);
|
|
152
|
+
entryPoint.dependents.delete(dep);
|
|
153
|
+
}
|
|
154
|
+
}
|
|
49
155
|
const potentialDependencies = new Set();
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
156
|
+
const filesToScan = [...(entryPoint.data.tsConfig?.rootNames ?? [entryFilePath])];
|
|
157
|
+
const visited = new Set();
|
|
158
|
+
while (filesToScan.length > 0) {
|
|
159
|
+
const file = filesToScan.pop();
|
|
160
|
+
if (!file) {
|
|
161
|
+
continue;
|
|
162
|
+
}
|
|
163
|
+
const currentFile = (0, path_1.ensureUnixPath)(file);
|
|
164
|
+
if (visited.has(currentFile)) {
|
|
165
|
+
continue;
|
|
166
|
+
}
|
|
167
|
+
visited.add(currentFile);
|
|
168
|
+
const fileEntry = analyseSourcesFileCache.getOrCreate(currentFile);
|
|
169
|
+
if (fileEntry.content === undefined) {
|
|
170
|
+
try {
|
|
171
|
+
fileEntry.content = fs.readFileSync(currentFile, 'utf-8');
|
|
172
|
+
fileEntry.exists = true;
|
|
173
|
+
}
|
|
174
|
+
catch {
|
|
175
|
+
continue;
|
|
176
|
+
}
|
|
177
|
+
}
|
|
178
|
+
const { importedFiles, typeReferenceDirectives, referencedFiles } = typescript_1.default.preProcessFile(fileEntry.content, true, // readImportFiles
|
|
179
|
+
true);
|
|
180
|
+
for (const ref of referencedFiles) {
|
|
181
|
+
const resolvedPath = resolveRelativeSourceFile((0, node_path_1.dirname)(currentFile), ref.fileName, analyseSourcesFileCache);
|
|
182
|
+
if (resolvedPath && !visited.has(resolvedPath)) {
|
|
183
|
+
filesToScan.push(resolvedPath);
|
|
184
|
+
}
|
|
185
|
+
}
|
|
186
|
+
for (const ref of [...importedFiles, ...typeReferenceDirectives]) {
|
|
187
|
+
const moduleName = ref.fileName;
|
|
188
|
+
if (moduleName[0] !== '.') {
|
|
54
189
|
if (moduleName === primaryModuleId || moduleName.startsWith(`${primaryModuleId}/`)) {
|
|
55
190
|
potentialDependencies.add(moduleName);
|
|
56
191
|
}
|
|
57
|
-
return undefined;
|
|
58
192
|
}
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
compilerHost.resolveModuleNames = (moduleNames, containingFile, _reusedNames, redirectedReference, options) => {
|
|
64
|
-
return moduleNames.map(moduleName => {
|
|
65
|
-
if (!moduleName.startsWith('.')) {
|
|
66
|
-
if (moduleName === primaryModuleId || moduleName.startsWith(`${primaryModuleId}/`)) {
|
|
67
|
-
potentialDependencies.add(moduleName);
|
|
193
|
+
else {
|
|
194
|
+
const resolvedPath = resolveRelativeSourceFile((0, node_path_1.dirname)(currentFile), moduleName, analyseSourcesFileCache);
|
|
195
|
+
if (resolvedPath && !visited.has(resolvedPath)) {
|
|
196
|
+
filesToScan.push(resolvedPath);
|
|
68
197
|
}
|
|
69
|
-
return undefined;
|
|
70
198
|
}
|
|
71
|
-
const { resolvedModule } = typescript_1.default.resolveModuleName(moduleName, (0, path_2.ensureUnixPath)(containingFile), options, compilerHost, moduleResolutionCache, redirectedReference);
|
|
72
|
-
return resolvedModule;
|
|
73
|
-
});
|
|
74
|
-
};
|
|
75
|
-
const program = typescript_1.default.createProgram(entryPoint.data.tsConfig.rootNames, tsConfigOptions, compilerHost, oldProgram);
|
|
76
|
-
// If an index file exists parallel to the entryFilePath it is not valid as index should be reserved as an
|
|
77
|
-
// entry file of an entry-point based on node resolution strategy.
|
|
78
|
-
if ((0, path_1.basename)(entryPoint.data.entryPoint.entryFilePath) !== 'index.ts') {
|
|
79
|
-
const potentialIndexPath = (0, path_1.join)((0, path_1.dirname)(entryPoint.data.entryPoint.entryFilePath), 'index.ts');
|
|
80
|
-
const sf = program.getSourceFile((0, path_2.ensureUnixPath)(potentialIndexPath));
|
|
81
|
-
if (sf) {
|
|
82
|
-
throw new Error(`Entry point '${moduleId}' has an 'index.ts' parallel to the 'entryFilePath'. ` +
|
|
83
|
-
`The 'entryFilePath' should be updated to point to the 'index.ts' file.\n` +
|
|
84
|
-
`Full path: ${potentialIndexPath}`);
|
|
85
199
|
}
|
|
86
200
|
}
|
|
87
|
-
(0, log_1.debug)(`tsc program structure is reused: ${oldProgram ? oldProgram.structureIsReused : 'No old program'}`);
|
|
88
|
-
entryPoint.cache.oldPrograms = { ...entryPoint.cache.oldPrograms, ['analysis']: program };
|
|
89
|
-
const entryPointsMapped = {};
|
|
90
|
-
for (const dep of entryPoints) {
|
|
91
|
-
entryPointsMapped[dep.data.entryPoint.moduleId] = dep;
|
|
92
|
-
}
|
|
93
201
|
for (const moduleName of potentialDependencies) {
|
|
94
|
-
const dep = entryPointsMapped
|
|
202
|
+
const dep = entryPointsMapped.get(moduleName);
|
|
95
203
|
if (dep) {
|
|
96
204
|
(0, log_1.debug)(`Found entry point dependency: ${moduleId} -> ${moduleName}`);
|
|
97
205
|
if (moduleId === moduleName) {
|
|
98
206
|
throw new Error(`Entry point ${moduleName} has a circular dependency on itself.`);
|
|
99
207
|
}
|
|
100
|
-
if (dep.
|
|
208
|
+
if (dep.dependents.has(entryPoint)) {
|
|
101
209
|
throw new Error(`Entry point ${moduleName} has a circular dependency on ${moduleId}.`);
|
|
102
210
|
}
|
|
103
211
|
entryPoint.dependsOn(dep);
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"analyse-sources.transform.js","sourceRoot":"","sources":["../../../../../src/lib/ng-package/entry-point/analyse-sources.transform.ts"],"names":[],"mappings":";;;;;;AAAA,+BAA+C;AAC/C,+BAAiC;AACjC,4DAA4B;AAE5B,2CAA8C;AAE9C,sEAAiE;AACjE,yCAAwC;AACxC,2CAAkD;AAClD,oCAAyE;AAE5D,QAAA,uBAAuB,GAAc,IAAA,WAAI,EACpD,IAAA,UAAG,EAAC,KAAK,CAAC,EAAE;IACV,MAAM,WAAW,GAAqB,KAAK,CAAC,MAAM,CAAC,oBAAY,CAAC,CAAC;IAEjE,KAAK,MAAM,UAAU,IAAI,WAAW,EAAE,CAAC;QACrC,IAAI,UAAU,CAAC,KAAK,KAAK,iBAAU,EAAE,CAAC;YACpC,iBAAiB,CAAC,KAAK,EAAE,UAAU,EAAE,WAAW,CAAC,CAAC;QACpD,CAAC;IACH,CAAC;IAED,OAAO,KAAK,CAAC;AACf,CAAC,CAAC,CACH,CAAC;AAEF;;;;;;GAMG;AACH,SAAS,iBAAiB,CAAC,KAAiB,EAAE,UAA0B,EAAE,WAA6B;IACrG,MAAM,EAAE,WAAW,EAAE,wBAAwB,EAAE,qBAAqB,EAAE,GAAG,UAAU,CAAC,KAAK,CAAC;IAC1F,MAAM,UAAU,GAAG,WAAW,IAAK,WAAW,CAAC,UAAU,CAA4B,CAAC;IACtF,MAAM,EAAE,QAAQ,EAAE,GAAG,UAAU,CAAC,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iCAAiC,QAAQ,GAAG,CAAC,CAAC;YACzF,CAAC;YAED,UAAU,CAAC,SAAS,CAAC,GAAG,CAAC,CAAC;QAC5B,CAAC;aAAM,CAAC;YACN,MAAM,IAAI,KAAK,CAAC,eAAe,UAAU,yBAAyB,QAAQ,iBAAiB,CAAC,CAAC;QAC/F,CAAC;IACH,CAAC;AACH,CAAC","sourcesContent":["import { basename, dirname, join } from 'path';\nimport { map, pipe } from 'rxjs';\nimport ts from 'typescript';\nimport { BuildGraph } from '../../graph/build-graph';\nimport { STATE_DONE } from '../../graph/node';\nimport { Transform } from '../../graph/transform';\nimport { cacheCompilerHost } from '../../ts/cache-compiler-host';\nimport { debug } from '../../utils/log';\nimport { ensureUnixPath } from '../../utils/path';\nimport { EntryPointNode, findPackageNode, isEntryPoint } from '../nodes';\n\nexport const analyseSourcesTransform: Transform = pipe(\n map(graph => {\n const entryPoints: EntryPointNode[] = graph.filter(isEntryPoint);\n\n for (const entryPoint of entryPoints) {\n if (entryPoint.state !== STATE_DONE) {\n analyseEntryPoint(graph, entryPoint, entryPoints);\n }\n }\n\n return graph;\n }),\n);\n\n/**\n * Analyses an entrypoint, searching for TypeScript dependencies and additional resources (Templates and Stylesheets).\n *\n * @param graph Build graph\n * @param entryPoint Current entry point that should be analysed.\n * @param entryPoints List of all entry points.\n */\nfunction analyseEntryPoint(graph: BuildGraph, entryPoint: EntryPointNode, entryPoints: EntryPointNode[]) {\n const { oldPrograms, analysesSourcesFileCache, moduleResolutionCache } = entryPoint.cache;\n const oldProgram = oldPrograms && (oldPrograms['analysis'] as ts.Program | undefined);\n const { moduleId } = entryPoint.data.entryPoint;\n const packageNode = findPackageNode(graph);\n const primaryModuleId = packageNode.data.primary.moduleId;\n\n debug(`Analysing sources for ${moduleId}`);\n const tsConfigOptions: ts.CompilerOptions = {\n // Needed because of `Property 'extendedDiagnostics' is incompatible with index signature.`\n ...(entryPoint.data.tsConfig.options as ts.CompilerOptions),\n skipLibCheck: true,\n noLib: true,\n noEmit: true,\n types: [],\n target: ts.ScriptTarget.Latest,\n strict: false,\n };\n\n const compilerHost = cacheCompilerHost(\n graph,\n entryPoint,\n tsConfigOptions,\n moduleResolutionCache,\n undefined,\n undefined,\n analysesSourcesFileCache,\n );\n\n const potentialDependencies = new Set<string>();\n\n compilerHost.resolveTypeReferenceDirectives = (\n moduleNames: string[] | ts.FileReference[],\n containingFile: string,\n redirectedReference: ts.ResolvedProjectReference | undefined,\n options: ts.CompilerOptions,\n ) => {\n return moduleNames.map(name => {\n const moduleName = typeof name === 'string' ? name : name.fileName;\n\n if (!moduleName.startsWith('.')) {\n if (moduleName === primaryModuleId || moduleName.startsWith(`${primaryModuleId}/`)) {\n potentialDependencies.add(moduleName);\n }\n\n return undefined;\n }\n\n const result = ts.resolveTypeReferenceDirective(\n moduleName,\n ensureUnixPath(containingFile),\n options,\n compilerHost,\n redirectedReference,\n ).resolvedTypeReferenceDirective;\n\n return result;\n });\n };\n\n compilerHost.resolveModuleNames = (\n moduleNames: string[],\n containingFile: string,\n _reusedNames: string[] | undefined,\n redirectedReference: ts.ResolvedProjectReference | undefined,\n options: ts.CompilerOptions,\n ) => {\n return moduleNames.map(moduleName => {\n if (!moduleName.startsWith('.')) {\n if (moduleName === primaryModuleId || moduleName.startsWith(`${primaryModuleId}/`)) {\n potentialDependencies.add(moduleName);\n }\n\n return undefined;\n }\n\n const { resolvedModule } = ts.resolveModuleName(\n moduleName,\n ensureUnixPath(containingFile),\n options,\n compilerHost,\n moduleResolutionCache,\n redirectedReference,\n );\n\n return resolvedModule;\n });\n };\n\n const program: ts.Program = ts.createProgram(\n entryPoint.data.tsConfig.rootNames,\n tsConfigOptions,\n compilerHost,\n oldProgram,\n );\n\n // If an index file exists parallel to the entryFilePath it is not valid as index should be reserved as an\n // entry file of an entry-point based on node resolution strategy.\n if (basename(entryPoint.data.entryPoint.entryFilePath) !== 'index.ts') {\n const potentialIndexPath = join(dirname(entryPoint.data.entryPoint.entryFilePath), 'index.ts');\n const sf = program.getSourceFile(ensureUnixPath(potentialIndexPath));\n\n if (sf) {\n throw new Error(\n `Entry point '${moduleId}' has an 'index.ts' parallel to the 'entryFilePath'. ` +\n `The 'entryFilePath' should be updated to point to the 'index.ts' file.\\n` +\n `Full path: ${potentialIndexPath}`,\n );\n }\n }\n\n debug(`tsc program structure is reused: ${oldProgram ? (oldProgram as any).structureIsReused : 'No old program'}`);\n\n entryPoint.cache.oldPrograms = { ...entryPoint.cache.oldPrograms, ['analysis']: program };\n\n const entryPointsMapped: Record<string, EntryPointNode> = {};\n for (const dep of entryPoints) {\n entryPointsMapped[dep.data.entryPoint.moduleId] = dep;\n }\n\n for (const moduleName of potentialDependencies) {\n const dep = entryPointsMapped[moduleName];\n\n if (dep) {\n debug(`Found entry point dependency: ${moduleId} -> ${moduleName}`);\n\n if (moduleId === moduleName) {\n throw new Error(`Entry point ${moduleName} has a circular dependency on itself.`);\n }\n\n if (dep.some(n => entryPoint === n)) {\n throw new Error(`Entry point ${moduleName} has a circular dependency on ${moduleId}.`);\n }\n\n entryPoint.dependsOn(dep);\n } else {\n throw new Error(`Entry point ${moduleName} which is required by ${moduleId} doesn't exist.`);\n }\n }\n}\n"]}
|
|
1
|
+
{"version":3,"file":"analyse-sources.transform.js","sourceRoot":"","sources":["../../../../../src/lib/ng-package/entry-point/analyse-sources.transform.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA,4CAA8B;AAC9B,yCAAsE;AACtE,+BAAiC;AACjC,4DAA4B;AAE5B,2CAA8C;AAE9C,yCAAwC;AACxC,2CAAkD;AAClD,oCAAyE;AAE5D,QAAA,uBAAuB,GAAc,IAAA,WAAI,EACpD,IAAA,UAAG,EAAC,KAAK,CAAC,EAAE;IACV,MAAM,WAAW,GAAqB,KAAK,CAAC,MAAM,CAAC,oBAAY,CAAC,CAAC;IACjE,MAAM,iBAAiB,GAAG,IAAI,GAAG,CAAyB,WAAW,CAAC,GAAG,CAAC,EAAE,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CAAC;aAAM,CAAC;YACN,MAAM,IAAI,KAAK,CAAC,eAAe,UAAU,yBAAyB,QAAQ,iBAAiB,CAAC,CAAC;QAC/F,CAAC;IACH,CAAC;AACH,CAAC","sourcesContent":["import * as fs from 'node:fs';\nimport { basename, dirname, extname, join, resolve } from 'node:path';\nimport { map, pipe } from 'rxjs';\nimport ts from 'typescript';\nimport { FileCache } from '../../file-system/file-cache';\nimport { STATE_DONE } from '../../graph/node';\nimport { Transform } from '../../graph/transform';\nimport { debug } from '../../utils/log';\nimport { ensureUnixPath } from '../../utils/path';\nimport { EntryPointNode, findPackageNode, isEntryPoint } from '../nodes';\n\nexport const analyseSourcesTransform: Transform = pipe(\n map(graph => {\n const entryPoints: EntryPointNode[] = graph.filter(isEntryPoint);\n const entryPointsMapped = new Map<string, EntryPointNode>(entryPoints.map(ep => [ep.data.entryPoint.moduleId, ep]));\n const packageNode = findPackageNode(graph);\n const primaryModuleId = packageNode.data.primary.moduleId;\n\n for (const entryPoint of entryPoints) {\n if (entryPoint.state !== STATE_DONE) {\n analyseEntryPoint(entryPoint, entryPointsMapped, primaryModuleId);\n }\n }\n\n return graph;\n }),\n);\n\nconst JS_TO_TS_EXTENSIONS: Readonly<Record<string, readonly string[]>> = {\n '.js': ['.ts', '.tsx', '.d.ts'],\n '.mjs': ['.mts', '.d.mts'],\n '.cjs': ['.cts', '.d.cts'],\n};\n\nconst RESOLUTION_EXTENSIONS: readonly string[] = [\n '.ts',\n '.tsx',\n '.mts',\n '.cts',\n '.d.ts',\n '.d.mts',\n '.d.cts',\n '/index.ts',\n '/index.tsx',\n '/index.mts',\n '/index.cts',\n '/index.d.ts',\n '/index.d.mts',\n '/index.d.cts',\n '.js',\n '.mjs',\n '.cjs',\n '/index.js',\n '/index.mjs',\n '/index.cjs',\n];\n\nfunction checkFile(filePath: string, fileCache: FileCache): boolean {\n const entry = fileCache.getOrCreate(filePath);\n if (entry.exists === undefined) {\n const stat = fs.statSync(filePath, { throwIfNoEntry: false });\n if (stat?.isFile()) {\n entry.exists = true;\n } else {\n return false;\n }\n }\n\n return entry.exists;\n}\n\nfunction resolveRelativeSourceFile(dir: string, moduleName: string, fileCache: FileCache): string | undefined {\n const target = resolve(dir, moduleName);\n if (target.includes('/node_modules/') || target.includes('\\\\node_modules\\\\')) {\n return undefined;\n }\n\n const ext = extname(target);\n const tsExtensions = JS_TO_TS_EXTENSIONS[ext];\n if (tsExtensions) {\n const base = target.slice(0, -ext.length);\n for (const tsExt of tsExtensions) {\n const candidate = base + tsExt;\n if (checkFile(candidate, fileCache)) {\n return ensureUnixPath(candidate);\n }\n }\n }\n\n if (checkFile(target, fileCache)) {\n return ensureUnixPath(target);\n }\n\n for (const suffix of RESOLUTION_EXTENSIONS) {\n const candidate = target + suffix;\n if (checkFile(candidate, fileCache)) {\n return ensureUnixPath(candidate);\n }\n }\n\n return undefined;\n}\n\n/**\n * Analyses an entrypoint, searching for TypeScript dependencies and internal package imports.\n *\n * @param entryPoint Current entry point that should be analysed.\n * @param entryPointsMapped Map of all entry points by moduleId.\n * @param primaryModuleId The moduleId of the primary entry point.\n */\nfunction analyseEntryPoint(\n entryPoint: EntryPointNode,\n entryPointsMapped: Map<string, EntryPointNode>,\n primaryModuleId: string,\n) {\n const { analyseSourcesFileCache } = entryPoint.cache;\n const { moduleId, entryFilePath } = entryPoint.data.entryPoint;\n\n debug(`Analysing sources for ${moduleId}`);\n\n // If an index file exists parallel to the entryFilePath it is not valid as index should be reserved as an\n // entry file of an entry-point based on node resolution strategy.\n if (basename(entryFilePath) !== 'index.ts') {\n const potentialIndexPath = join(dirname(entryFilePath), 'index.ts');\n if (fs.existsSync(potentialIndexPath)) {\n throw new Error(\n `Entry point '${moduleId}' has an 'index.ts' parallel to the 'entryFilePath'. ` +\n `The 'entryFilePath' should be updated to point to the 'index.ts' file.\\n` +\n `Full path: ${potentialIndexPath}`,\n );\n }\n }\n\n // Remove previously discovered entry point dependencies in watch mode\n for (const dep of entryPoint.dependents) {\n if (isEntryPoint(dep)) {\n dep.dependees.delete(entryPoint);\n entryPoint.dependents.delete(dep);\n }\n }\n\n const potentialDependencies = new Set<string>();\n const filesToScan = [...(entryPoint.data.tsConfig?.rootNames ?? [entryFilePath])];\n const visited = new Set<string>();\n\n while (filesToScan.length > 0) {\n const file = filesToScan.pop();\n if (!file) {\n continue;\n }\n\n const currentFile = ensureUnixPath(file);\n if (visited.has(currentFile)) {\n continue;\n }\n visited.add(currentFile);\n\n const fileEntry = analyseSourcesFileCache.getOrCreate(currentFile);\n if (fileEntry.content === undefined) {\n try {\n fileEntry.content = fs.readFileSync(currentFile, 'utf-8');\n fileEntry.exists = true;\n } catch {\n continue;\n }\n }\n\n const { importedFiles, typeReferenceDirectives, referencedFiles } = ts.preProcessFile(\n fileEntry.content,\n true, // readImportFiles\n true, // detectJavaScriptImports\n );\n\n for (const ref of referencedFiles) {\n const resolvedPath = resolveRelativeSourceFile(dirname(currentFile), ref.fileName, analyseSourcesFileCache);\n if (resolvedPath && !visited.has(resolvedPath)) {\n filesToScan.push(resolvedPath);\n }\n }\n\n for (const ref of [...importedFiles, ...typeReferenceDirectives]) {\n const moduleName = ref.fileName;\n\n if (moduleName[0] !== '.') {\n if (moduleName === primaryModuleId || moduleName.startsWith(`${primaryModuleId}/`)) {\n potentialDependencies.add(moduleName);\n }\n } else {\n const resolvedPath = resolveRelativeSourceFile(dirname(currentFile), moduleName, analyseSourcesFileCache);\n if (resolvedPath && !visited.has(resolvedPath)) {\n filesToScan.push(resolvedPath);\n }\n }\n }\n }\n\n for (const moduleName of potentialDependencies) {\n const dep = entryPointsMapped.get(moduleName);\n\n if (dep) {\n debug(`Found entry point dependency: ${moduleId} -> ${moduleName}`);\n\n if (moduleId === moduleName) {\n throw new Error(`Entry point ${moduleName} has a circular dependency on itself.`);\n }\n\n if (dep.dependents.has(entryPoint)) {\n throw new Error(`Entry point ${moduleName} has a circular dependency on ${moduleId}.`);\n }\n\n entryPoint.dependsOn(dep);\n } else {\n throw new Error(`Entry point ${moduleName} which is required by ${moduleId} doesn't exist.`);\n }\n }\n}\n"]}
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { NgPackageEntryConfig } from '../../../ng-entrypoint.schema';
|
|
2
2
|
import { NgPackageConfig } from '../../../ng-package.schema';
|
|
3
|
-
import { CssUrl } from '../../styles/
|
|
3
|
+
import { CssUrl } from '../../styles/css-url.enum';
|
|
4
4
|
/** A list of output absolute paths for various formats */
|
|
5
5
|
export interface DestinationFiles {
|
|
6
6
|
/** Absolute path of this entry point `declarations` */
|