@mxpicture/build-api 0.2.57 → 0.2.59
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/dist/common/common.json.d.ts +6 -0
- package/dist/common/common.json.d.ts.map +1 -1
- package/dist/common/common.json.js +18 -0
- package/dist/common/common.json.js.map +1 -1
- package/dist/exp/ExportsExtractor.d.ts +44 -0
- package/dist/exp/ExportsExtractor.d.ts.map +1 -0
- package/dist/exp/ExportsExtractor.js +179 -0
- package/dist/exp/ExportsExtractor.js.map +1 -0
- package/dist/exp/ExportsJsonFile.d.ts +13 -0
- package/dist/exp/ExportsJsonFile.d.ts.map +1 -0
- package/dist/exp/ExportsJsonFile.js +59 -0
- package/dist/exp/ExportsJsonFile.js.map +1 -0
- package/dist/exp/ExportsTsFile.d.ts +9 -0
- package/dist/exp/ExportsTsFile.d.ts.map +1 -0
- package/dist/exp/ExportsTsFile.js +29 -0
- package/dist/exp/ExportsTsFile.js.map +1 -0
- package/dist/exp/exports.d.ts +3 -0
- package/dist/exp/exports.d.ts.map +1 -0
- package/dist/exp/exports.js +945 -0
- package/dist/exp/exports.js.map +1 -0
- package/dist/exp/index.d.ts +5 -0
- package/dist/exp/index.d.ts.map +1 -0
- package/dist/exp/index.js +6 -0
- package/dist/exp/index.js.map +1 -0
- package/dist/pkg/pkg.fs.d.ts.map +1 -1
- package/dist/pkg/pkg.fs.js +4 -5
- package/dist/pkg/pkg.fs.js.map +1 -1
- package/dist/scripts/generateOwnExports.d.ts +2 -0
- package/dist/scripts/generateOwnExports.d.ts.map +1 -0
- package/dist/scripts/generateOwnExports.js +24 -0
- package/dist/scripts/generateOwnExports.js.map +1 -0
- package/dist/types/index.d.ts +1 -0
- package/dist/types/index.d.ts.map +1 -1
- package/dist/types/index.js +1 -0
- package/dist/types/index.js.map +1 -1
- package/dist/types/types.exports.d.ts +42 -0
- package/dist/types/types.exports.d.ts.map +1 -0
- package/dist/types/types.exports.js +2 -0
- package/dist/types/types.exports.js.map +1 -0
- package/dist/vscode/vscode.settings.d.ts.map +1 -1
- package/dist/vscode/vscode.settings.js +2 -2
- package/dist/vscode/vscode.settings.js.map +1 -1
- package/dist/vscode/vscode.storage.d.ts.map +1 -1
- package/dist/vscode/vscode.storage.js +2 -2
- package/dist/vscode/vscode.storage.js.map +1 -1
- package/dist/vscode/vscode.workspace.js +2 -2
- package/dist/vscode/vscode.workspace.js.map +1 -1
- package/package.json +8 -3
|
@@ -27,4 +27,10 @@ export declare const jsonEqual: <T>(a: T, b: T) => boolean;
|
|
|
27
27
|
* ```
|
|
28
28
|
*/
|
|
29
29
|
export declare const jsonClone: <T>(value: T) => T;
|
|
30
|
+
export declare enum JsonStringifyFormat {
|
|
31
|
+
json = "json",
|
|
32
|
+
jsonStringify = "jsonStringify"
|
|
33
|
+
}
|
|
34
|
+
export declare const jsonStringify: (content: unknown, format?: JsonStringifyFormat) => Promise<string>;
|
|
35
|
+
export declare const jsonParse: <T>(content: string) => T;
|
|
30
36
|
//# sourceMappingURL=common.json.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"common.json.d.ts","sourceRoot":"","sources":["../../src/common/common.json.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"common.json.d.ts","sourceRoot":"","sources":["../../src/common/common.json.ts"],"names":[],"mappings":"AAIA;;;;;;;;;;;;GAYG;AACH,eAAO,MAAM,SAAS,GAAI,CAAC,EAAE,GAAG,CAAC,EAAE,GAAG,CAAC,KAAG,OAAkC,CAAC;AAE7E;;;;;;;;;;;;;GAaG;AACH,eAAO,MAAM,SAAS,GAAI,CAAC,EAAE,OAAO,CAAC,KAAG,CAA2B,CAAC;AAEpE,oBAAY,mBAAmB;IAC7B,IAAI,SAAS;IACb,aAAa,kBAAkB;CAChC;AAED,eAAO,MAAM,aAAa,GACxB,SAAS,OAAO,EAChB,SAAS,mBAAmB,KAC3B,OAAO,CAAC,MAAM,CAQhB,CAAC;AAEF,eAAO,MAAM,SAAS,GAAI,CAAC,EAAE,SAAS,MAAM,KAAG,CAAyB,CAAC"}
|
|
@@ -1,4 +1,6 @@
|
|
|
1
1
|
import { isDeepStrictEqual } from "node:util";
|
|
2
|
+
import json5 from "json5";
|
|
3
|
+
import { formatJson, formatJsonStringify } from "../code/code.format.js";
|
|
2
4
|
/**
|
|
3
5
|
* Performs a deep-equality comparison of two values.
|
|
4
6
|
*
|
|
@@ -28,4 +30,20 @@ export const jsonEqual = (a, b) => isDeepStrictEqual(a, b);
|
|
|
28
30
|
* ```
|
|
29
31
|
*/
|
|
30
32
|
export const jsonClone = (value) => structuredClone(value);
|
|
33
|
+
export var JsonStringifyFormat;
|
|
34
|
+
(function (JsonStringifyFormat) {
|
|
35
|
+
JsonStringifyFormat["json"] = "json";
|
|
36
|
+
JsonStringifyFormat["jsonStringify"] = "jsonStringify";
|
|
37
|
+
})(JsonStringifyFormat || (JsonStringifyFormat = {}));
|
|
38
|
+
export const jsonStringify = async (content, format) => {
|
|
39
|
+
let result = json5.stringify(content);
|
|
40
|
+
if (format === JsonStringifyFormat.json) {
|
|
41
|
+
result = await formatJson(result);
|
|
42
|
+
}
|
|
43
|
+
else if (format === JsonStringifyFormat.jsonStringify) {
|
|
44
|
+
result = await formatJsonStringify(result);
|
|
45
|
+
}
|
|
46
|
+
return result;
|
|
47
|
+
};
|
|
48
|
+
export const jsonParse = (content) => json5.parse(content);
|
|
31
49
|
//# sourceMappingURL=common.json.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"common.json.js","sourceRoot":"","sources":["../../src/common/common.json.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,iBAAiB,EAAE,MAAM,WAAW,CAAC;
|
|
1
|
+
{"version":3,"file":"common.json.js","sourceRoot":"","sources":["../../src/common/common.json.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,iBAAiB,EAAE,MAAM,WAAW,CAAC;AAC9C,OAAO,KAAK,MAAM,OAAO,CAAC;AAC1B,OAAO,EAAE,UAAU,EAAE,mBAAmB,EAAE,MAAM,wBAAwB,CAAC;AAEzE;;;;;;;;;;;;GAYG;AACH,MAAM,CAAC,MAAM,SAAS,GAAG,CAAI,CAAI,EAAE,CAAI,EAAW,EAAE,CAAC,iBAAiB,CAAC,CAAC,EAAE,CAAC,CAAC,CAAC;AAE7E;;;;;;;;;;;;;GAaG;AACH,MAAM,CAAC,MAAM,SAAS,GAAG,CAAI,KAAQ,EAAK,EAAE,CAAC,eAAe,CAAC,KAAK,CAAC,CAAC;AAEpE,MAAM,CAAN,IAAY,mBAGX;AAHD,WAAY,mBAAmB;IAC7B,oCAAa,CAAA;IACb,sDAA+B,CAAA;AACjC,CAAC,EAHW,mBAAmB,KAAnB,mBAAmB,QAG9B;AAED,MAAM,CAAC,MAAM,aAAa,GAAG,KAAK,EAChC,OAAgB,EAChB,MAA4B,EACX,EAAE;IACnB,IAAI,MAAM,GAAG,KAAK,CAAC,SAAS,CAAC,OAAO,CAAC,CAAC;IACtC,IAAI,MAAM,KAAK,mBAAmB,CAAC,IAAI,EAAE,CAAC;QACxC,MAAM,GAAG,MAAM,UAAU,CAAC,MAAM,CAAC,CAAC;IACpC,CAAC;SAAM,IAAI,MAAM,KAAK,mBAAmB,CAAC,aAAa,EAAE,CAAC;QACxD,MAAM,GAAG,MAAM,mBAAmB,CAAC,MAAM,CAAC,CAAC;IAC7C,CAAC;IACD,OAAO,MAAM,CAAC;AAChB,CAAC,CAAC;AAEF,MAAM,CAAC,MAAM,SAAS,GAAG,CAAI,OAAe,EAAK,EAAE,CAAC,KAAK,CAAC,KAAK,CAAC,OAAO,CAAC,CAAC","sourcesContent":["import { isDeepStrictEqual } from \"node:util\";\nimport json5 from \"json5\";\nimport { formatJson, formatJsonStringify } from \"../code/code.format.js\";\n\n/**\n * Performs a deep-equality comparison of two values.\n *\n * @param a - The first value to compare.\n * @param b - The second value to compare.\n * @returns `true` if `a` and `b` are deeply equal, `false` otherwise.\n *\n * @example\n * ```ts\n * jsonEqual({ x: 1 }, { x: 1 }); // true\n * jsonEqual([1, 2], [1, 3]); // false\n * ```\n */\nexport const jsonEqual = <T>(a: T, b: T): boolean => isDeepStrictEqual(a, b);\n\n/**\n * Creates a deep clone of the given value using the structured clone algorithm.\n *\n * @param value - The value to clone.\n * @returns A deep copy of `value`.\n *\n * @example\n * ```ts\n * const original = { nested: { key: \"value\" } };\n * const copy = jsonClone(original);\n * copy.nested.key = \"changed\";\n * console.log(original.nested.key); // \"value\"\n * ```\n */\nexport const jsonClone = <T>(value: T): T => structuredClone(value);\n\nexport enum JsonStringifyFormat {\n json = \"json\",\n jsonStringify = \"jsonStringify\",\n}\n\nexport const jsonStringify = async (\n content: unknown,\n format?: JsonStringifyFormat,\n): Promise<string> => {\n let result = json5.stringify(content);\n if (format === JsonStringifyFormat.json) {\n result = await formatJson(result);\n } else if (format === JsonStringifyFormat.jsonStringify) {\n result = await formatJsonStringify(result);\n }\n return result;\n};\n\nexport const jsonParse = <T>(content: string): T => json5.parse(content);\n"]}
|
|
@@ -0,0 +1,44 @@
|
|
|
1
|
+
import { EntryPoint, ExportsExtractorParams, ExportNode, PackageAPI } from "../types/types.exports.js";
|
|
2
|
+
import { PackageJson } from "../types/types.package.js";
|
|
3
|
+
import { ExportsJsonFile } from "./ExportsJsonFile.js";
|
|
4
|
+
export declare const runExportsExtractor: (params: ExportsExtractorParams) => Promise<void>;
|
|
5
|
+
export declare class ExportsExtractor {
|
|
6
|
+
protected file: ExportsJsonFile;
|
|
7
|
+
/**
|
|
8
|
+
* Analyze an installed package and produce
|
|
9
|
+
* a structured API representation.
|
|
10
|
+
*
|
|
11
|
+
* @param pkg package name
|
|
12
|
+
*/
|
|
13
|
+
constructor(file: ExportsJsonFile);
|
|
14
|
+
/**
|
|
15
|
+
* Analyze an installed package and build its API model.
|
|
16
|
+
*/
|
|
17
|
+
run(): Promise<PackageAPI>;
|
|
18
|
+
writeJson(): Promise<void>;
|
|
19
|
+
/**
|
|
20
|
+
* Resolve the root directory of an installed package.
|
|
21
|
+
*/
|
|
22
|
+
protected resolvePackageRoot(pkg: string): string;
|
|
23
|
+
/**
|
|
24
|
+
* Resolve entrypoints using the Node exports algorithm.
|
|
25
|
+
*/
|
|
26
|
+
protected resolveEntrypoints(pkg: string, pkgJson: PackageJson): EntryPoint[];
|
|
27
|
+
/**
|
|
28
|
+
* Expand wildcard export patterns.
|
|
29
|
+
*/
|
|
30
|
+
protected expandWildcardEntrypoints(root: string, entrypoints: EntryPoint[]): Promise<EntryPoint[]>;
|
|
31
|
+
/**
|
|
32
|
+
* Dynamically import a module supporting ESM and CommonJS.
|
|
33
|
+
*/
|
|
34
|
+
protected loadModule(id: string): Promise<Record<string, unknown>>;
|
|
35
|
+
/**
|
|
36
|
+
* Extract runtime exports from entrypoints.
|
|
37
|
+
*/
|
|
38
|
+
protected inspectRuntimeExports(entrypoints: EntryPoint[]): Promise<ExportNode[]>;
|
|
39
|
+
/**
|
|
40
|
+
* Parse TypeScript declaration files to extract exported types.
|
|
41
|
+
*/
|
|
42
|
+
protected parseTypeExports(root: string): Promise<ExportNode[]>;
|
|
43
|
+
}
|
|
44
|
+
//# sourceMappingURL=ExportsExtractor.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"ExportsExtractor.d.ts","sourceRoot":"","sources":["../../src/exp/ExportsExtractor.ts"],"names":[],"mappings":"AAMA,OAAO,EACL,UAAU,EACV,sBAAsB,EACtB,UAAU,EACV,UAAU,EACX,MAAM,2BAA2B,CAAC;AAEnC,OAAO,EAAE,WAAW,EAAE,MAAM,2BAA2B,CAAC;AAExD,OAAO,EAAE,eAAe,EAAE,MAAM,sBAAsB,CAAC;AAIvD,eAAO,MAAM,mBAAmB,GAAU,QAAQ,sBAAsB,kBAgBvE,CAAC;AAEF,qBAAa,gBAAgB;IAOR,SAAS,CAAC,IAAI,EAAE,eAAe;IANlD;;;;;OAKG;gBAC0B,IAAI,EAAE,eAAe;IAElD;;OAEG;IACU,GAAG,IAAI,OAAO,CAAC,UAAU,CAAC;IAmB1B,SAAS,IAAI,OAAO,CAAC,IAAI,CAAC;IAIvC;;OAEG;IACH,SAAS,CAAC,kBAAkB,CAAC,GAAG,EAAE,MAAM,GAAG,MAAM;IAKjD;;OAEG;IACH,SAAS,CAAC,kBAAkB,CAC1B,GAAG,EAAE,MAAM,EACX,OAAO,EAAE,WAAW,GACnB,UAAU,EAAE;IAmCf;;OAEG;cACa,yBAAyB,CACvC,IAAI,EAAE,MAAM,EACZ,WAAW,EAAE,UAAU,EAAE,GACxB,OAAO,CAAC,UAAU,EAAE,CAAC;IAuBxB;;OAEG;cACa,UAAU,CAAC,EAAE,EAAE,MAAM,GAAG,OAAO,CAAC,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAAC;IAQxE;;OAEG;cACa,qBAAqB,CACnC,WAAW,EAAE,UAAU,EAAE,GACxB,OAAO,CAAC,UAAU,EAAE,CAAC;IAiBxB;;OAEG;cACa,gBAAgB,CAAC,IAAI,EAAE,MAAM,GAAG,OAAO,CAAC,UAAU,EAAE,CAAC;CA0CtE"}
|
|
@@ -0,0 +1,179 @@
|
|
|
1
|
+
import { dirname, join, relative } from "node:path";
|
|
2
|
+
import ts from "typescript";
|
|
3
|
+
import { glob } from "glob";
|
|
4
|
+
import { createRequire } from "node:module";
|
|
5
|
+
import { resolve as resolveExports } from "resolve.exports";
|
|
6
|
+
import { readPackageJson } from "../pkg/pkg.fs.js";
|
|
7
|
+
import { initWorkspace } from "../workspace/Workspace.js";
|
|
8
|
+
import { createSourceFileMap } from "../code/code.common.js";
|
|
9
|
+
import { ExportsJsonFile } from "./ExportsJsonFile.js";
|
|
10
|
+
const require = createRequire(import.meta.url);
|
|
11
|
+
export const runExportsExtractor = async (params) => {
|
|
12
|
+
initWorkspace(params.repoRoot);
|
|
13
|
+
if (!params.json)
|
|
14
|
+
params.json = join(params.repoRoot, "exports.json");
|
|
15
|
+
const file = new ExportsJsonFile(params.package, params.json);
|
|
16
|
+
const exp = new ExportsExtractor(file);
|
|
17
|
+
const result = await exp.run();
|
|
18
|
+
await exp.writeJson();
|
|
19
|
+
console.log("{");
|
|
20
|
+
console.log(` packageName: ${result.packageName}`);
|
|
21
|
+
console.log(` entrypoints: ${result.entrypoints.length}`);
|
|
22
|
+
console.log(` runtimeExports: ${result.runtimeExports.length}`);
|
|
23
|
+
console.log(` typeExports: ${result.typeExports.length}`);
|
|
24
|
+
console.log("}");
|
|
25
|
+
};
|
|
26
|
+
export class ExportsExtractor {
|
|
27
|
+
file;
|
|
28
|
+
/**
|
|
29
|
+
* Analyze an installed package and produce
|
|
30
|
+
* a structured API representation.
|
|
31
|
+
*
|
|
32
|
+
* @param pkg package name
|
|
33
|
+
*/
|
|
34
|
+
constructor(file) {
|
|
35
|
+
this.file = file;
|
|
36
|
+
}
|
|
37
|
+
/**
|
|
38
|
+
* Analyze an installed package and build its API model.
|
|
39
|
+
*/
|
|
40
|
+
async run() {
|
|
41
|
+
const pkgFile = this.file.content;
|
|
42
|
+
const root = this.resolvePackageRoot(pkgFile.packageName);
|
|
43
|
+
const pkgJson = await readPackageJson(root);
|
|
44
|
+
let entrypoints = this.resolveEntrypoints(pkgFile.packageName, pkgJson);
|
|
45
|
+
entrypoints = await this.expandWildcardEntrypoints(root, entrypoints);
|
|
46
|
+
const runtimeExports = await this.inspectRuntimeExports(entrypoints);
|
|
47
|
+
const typeExports = await this.parseTypeExports(root);
|
|
48
|
+
pkgFile.packageName = pkgJson.name;
|
|
49
|
+
pkgFile.entrypoints = entrypoints;
|
|
50
|
+
pkgFile.runtimeExports = runtimeExports;
|
|
51
|
+
pkgFile.typeExports = typeExports;
|
|
52
|
+
return pkgFile;
|
|
53
|
+
}
|
|
54
|
+
async writeJson() {
|
|
55
|
+
return this.file.write();
|
|
56
|
+
}
|
|
57
|
+
/**
|
|
58
|
+
* Resolve the root directory of an installed package.
|
|
59
|
+
*/
|
|
60
|
+
resolvePackageRoot(pkg) {
|
|
61
|
+
const pkgJson = require.resolve(`${pkg}/package.json`);
|
|
62
|
+
return dirname(pkgJson);
|
|
63
|
+
}
|
|
64
|
+
/**
|
|
65
|
+
* Resolve entrypoints using the Node exports algorithm.
|
|
66
|
+
*/
|
|
67
|
+
resolveEntrypoints(pkg, pkgJson) {
|
|
68
|
+
const entrypoints = [];
|
|
69
|
+
if (!pkgJson.exports) {
|
|
70
|
+
entrypoints.push({ id: pkg });
|
|
71
|
+
return entrypoints;
|
|
72
|
+
}
|
|
73
|
+
const keys = Object.keys(pkgJson.exports);
|
|
74
|
+
for (const key of keys) {
|
|
75
|
+
try {
|
|
76
|
+
const resolved = resolveExports(pkgJson, key, {
|
|
77
|
+
conditions: ["node", "import", "require", "default"],
|
|
78
|
+
});
|
|
79
|
+
if (!resolved)
|
|
80
|
+
continue;
|
|
81
|
+
const files = Array.isArray(resolved) ? resolved : [resolved];
|
|
82
|
+
for (const file of files) {
|
|
83
|
+
const specifier = key === "." ? pkg : `${pkg}/${key.replace("./", "")}`;
|
|
84
|
+
entrypoints.push({
|
|
85
|
+
id: specifier,
|
|
86
|
+
file,
|
|
87
|
+
});
|
|
88
|
+
}
|
|
89
|
+
}
|
|
90
|
+
catch { }
|
|
91
|
+
}
|
|
92
|
+
return entrypoints;
|
|
93
|
+
}
|
|
94
|
+
/**
|
|
95
|
+
* Expand wildcard export patterns.
|
|
96
|
+
*/
|
|
97
|
+
async expandWildcardEntrypoints(root, entrypoints) {
|
|
98
|
+
return (await Promise.allSettled(entrypoints.map(async (entry) => {
|
|
99
|
+
if (!entry.file?.includes("*"))
|
|
100
|
+
return [entry];
|
|
101
|
+
const pattern = entry.file;
|
|
102
|
+
const files = await glob.glob(pattern, {
|
|
103
|
+
cwd: root,
|
|
104
|
+
absolute: true,
|
|
105
|
+
});
|
|
106
|
+
return files.map((file) => ({
|
|
107
|
+
id: relative(root, file).replace(/\.(js|mjs|cjs)$/, ""),
|
|
108
|
+
file,
|
|
109
|
+
}));
|
|
110
|
+
})))
|
|
111
|
+
.filter((r) => r.status === "fulfilled")
|
|
112
|
+
.flatMap((r) => r.value);
|
|
113
|
+
}
|
|
114
|
+
/**
|
|
115
|
+
* Dynamically import a module supporting ESM and CommonJS.
|
|
116
|
+
*/
|
|
117
|
+
async loadModule(id) {
|
|
118
|
+
try {
|
|
119
|
+
return await import(id);
|
|
120
|
+
}
|
|
121
|
+
catch {
|
|
122
|
+
return require(id);
|
|
123
|
+
}
|
|
124
|
+
}
|
|
125
|
+
/**
|
|
126
|
+
* Extract runtime exports from entrypoints.
|
|
127
|
+
*/
|
|
128
|
+
async inspectRuntimeExports(entrypoints) {
|
|
129
|
+
return (await Promise.allSettled(entrypoints.map(async (entry) => {
|
|
130
|
+
const mod = await this.loadModule(entry.id);
|
|
131
|
+
return Object.keys(mod).map((name) => ({
|
|
132
|
+
name,
|
|
133
|
+
kind: typeof mod[name],
|
|
134
|
+
source: entry.id,
|
|
135
|
+
}));
|
|
136
|
+
})))
|
|
137
|
+
.filter((r) => r.status === "fulfilled")
|
|
138
|
+
.flatMap((r) => r.value);
|
|
139
|
+
}
|
|
140
|
+
/**
|
|
141
|
+
* Parse TypeScript declaration files to extract exported types.
|
|
142
|
+
*/
|
|
143
|
+
async parseTypeExports(root) {
|
|
144
|
+
const nodes = [];
|
|
145
|
+
const filePaths = await glob.glob("**/*.d.ts", {
|
|
146
|
+
cwd: root,
|
|
147
|
+
absolute: true,
|
|
148
|
+
});
|
|
149
|
+
const srcMap = createSourceFileMap(filePaths);
|
|
150
|
+
for (const filePath of filePaths) {
|
|
151
|
+
const file = srcMap.get(filePath);
|
|
152
|
+
if (!file)
|
|
153
|
+
continue;
|
|
154
|
+
ts.forEachChild(file.sourceFile, (node) => {
|
|
155
|
+
if (ts.isInterfaceDeclaration(node) ||
|
|
156
|
+
ts.isTypeAliasDeclaration(node) ||
|
|
157
|
+
ts.isClassDeclaration(node) ||
|
|
158
|
+
ts.isFunctionDeclaration(node)) {
|
|
159
|
+
if (!node.name)
|
|
160
|
+
return;
|
|
161
|
+
nodes.push({
|
|
162
|
+
name: node.name.text,
|
|
163
|
+
kind: ts.SyntaxKind[node.kind],
|
|
164
|
+
source: filePath,
|
|
165
|
+
});
|
|
166
|
+
}
|
|
167
|
+
if (ts.isEnumDeclaration(node)) {
|
|
168
|
+
nodes.push({
|
|
169
|
+
name: node.name.text,
|
|
170
|
+
kind: "enum",
|
|
171
|
+
source: filePath,
|
|
172
|
+
});
|
|
173
|
+
}
|
|
174
|
+
});
|
|
175
|
+
}
|
|
176
|
+
return nodes;
|
|
177
|
+
}
|
|
178
|
+
}
|
|
179
|
+
//# sourceMappingURL=ExportsExtractor.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"ExportsExtractor.js","sourceRoot":"","sources":["../../src/exp/ExportsExtractor.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,OAAO,EAAE,IAAI,EAAE,QAAQ,EAAE,MAAM,WAAW,CAAC;AACpD,OAAO,EAAE,MAAM,YAAY,CAAC;AAC5B,OAAO,EAAE,IAAI,EAAE,MAAM,MAAM,CAAC;AAC5B,OAAO,EAAE,aAAa,EAAE,MAAM,aAAa,CAAC;AAC5C,OAAO,EAAE,OAAO,IAAI,cAAc,EAAE,MAAM,iBAAiB,CAAC;AAC5D,OAAO,EAAE,eAAe,EAAE,MAAM,kBAAkB,CAAC;AAOnD,OAAO,EAAE,aAAa,EAAE,MAAM,2BAA2B,CAAC;AAE1D,OAAO,EAAE,mBAAmB,EAAE,MAAM,wBAAwB,CAAC;AAC7D,OAAO,EAAE,eAAe,EAAE,MAAM,sBAAsB,CAAC;AAEvD,MAAM,OAAO,GAAG,aAAa,CAAC,MAAM,CAAC,IAAI,CAAC,GAAG,CAAC,CAAC;AAE/C,MAAM,CAAC,MAAM,mBAAmB,GAAG,KAAK,EAAE,MAA8B,EAAE,EAAE;IAC1E,aAAa,CAAC,MAAM,CAAC,QAAQ,CAAC,CAAC;IAE/B,IAAI,CAAC,MAAM,CAAC,IAAI;QAAE,M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IAAI,CAAC,IAAI,CAAC,WAAW,EAAE;YAC7C,GAAG,EAAE,IAAI;YACT,QAAQ,EAAE,IAAI;SACf,CAAC,CAAC;QAEH,MAAM,MAAM,GAAG,mBAAmB,CAAC,SAAS,CAAC,CAAC;QAE9C,KAAK,MAAM,QAAQ,IAAI,SAAS,EAAE,CAAC;YACjC,MAAM,IAAI,GAAG,MAAM,CAAC,GAAG,CAAC,QAAQ,CAAC,CAAC;YAClC,IAAI,CAAC,IAAI;gBAAE,SAAS;YAEpB,EAAE,CAAC,YAAY,CAAC,IAAI,CAAC,UAAU,EAAE,CAAC,IAAI,EAAE,EAAE;gBACxC,IACE,EAAE,CAAC,sBAAsB,CAAC,IAAI,CAAC;oBAC/B,EAAE,CAAC,sBAAsB,CAAC,IAAI,CAAC;oBAC/B,EAAE,CAAC,kBAAkB,CAAC,IAAI,CAAC;oBAC3B,EAAE,CAAC,qBAAqB,CAAC,IAAI,CAAC,EAC9B,CAAC;oBACD,IAAI,CAAC,IAAI,CAAC,IAAI;wBAAE,OAAO;oBAEvB,KAAK,CAAC,IAAI,CAAC;wBACT,IAAI,EAAE,IAAI,CAAC,IAAI,CAAC,IAAI;wBACpB,IAAI,EAAE,EAAE,CAAC,UAAU,CAAC,IAAI,CAAC,IAAI,CAAC;wBAC9B,MAAM,EAAE,QAAQ;qBACjB,CAAC,CAAC;gBACL,CAAC;gBAED,IAAI,EAAE,CAAC,iBAAiB,CAAC,IAAI,CAAC,EAAE,CAAC;oBAC/B,KAAK,CAAC,IAAI,CAAC;wBACT,IAAI,EAAE,IAAI,CAAC,IAAI,CAAC,IAAI;wBACpB,IAAI,EAAE,MAAM;wBACZ,MAAM,EAAE,QAAQ;qBACjB,CAAC,CAAC;gBACL,CAAC;YACH,CAAC,CAAC,CAAC;QACL,CAAC;QAED,OAAO,KAAK,CAAC;IACf,CAAC;CACF","sourcesContent":["import { dirname, join, relative } from \"node:path\";\nimport ts from \"typescript\";\nimport { glob } from \"glob\";\nimport { createRequire } from \"node:module\";\nimport { resolve as resolveExports } from \"resolve.exports\";\nimport { readPackageJson } from \"../pkg/pkg.fs.js\";\nimport {\n EntryPoint,\n ExportsExtractorParams,\n ExportNode,\n PackageAPI,\n} from \"../types/types.exports.js\";\nimport { initWorkspace } from \"../workspace/Workspace.js\";\nimport { PackageJson } from \"../types/types.package.js\";\nimport { createSourceFileMap } from \"../code/code.common.js\";\nimport { ExportsJsonFile } from \"./ExportsJsonFile.js\";\n\nconst require = createRequire(import.meta.url);\n\nexport const runExportsExtractor = async (params: ExportsExtractorParams) => {\n initWorkspace(params.repoRoot);\n\n if (!params.json) params.json = join(params.repoRoot, \"exports.json\");\n\n const file = new ExportsJsonFile(params.package, params.json);\n const exp = new ExportsExtractor(file);\n const result = await exp.run();\n await exp.writeJson();\n\n console.log(\"{\");\n console.log(` packageName: ${result.packageName}`);\n console.log(` entrypoints: ${result.entrypoints.length}`);\n console.log(` runtimeExports: ${result.runtimeExports.length}`);\n console.log(` typeExports: ${result.typeExports.length}`);\n console.log(\"}\");\n};\n\nexport class ExportsExtractor {\n /**\n * Analyze an installed package and produce\n * a structured API representation.\n *\n * @param pkg package name\n */\n public constructor(protected file: ExportsJsonFile) {}\n\n /**\n * Analyze an installed package and build its API model.\n */\n public async run(): Promise<PackageAPI> {\n const pkgFile = this.file.content;\n\n const root = this.resolvePackageRoot(pkgFile.packageName);\n const pkgJson = await readPackageJson(root);\n\n let entrypoints = this.resolveEntrypoints(pkgFile.packageName, pkgJson);\n entrypoints = await this.expandWildcardEntrypoints(root, entrypoints);\n\n const runtimeExports = await this.inspectRuntimeExports(entrypoints);\n const typeExports = await this.parseTypeExports(root);\n\n pkgFile.packageName = pkgJson.name;\n pkgFile.entrypoints = entrypoints;\n pkgFile.runtimeExports = runtimeExports;\n pkgFile.typeExports = typeExports;\n return pkgFile;\n }\n\n public async writeJson(): Promise<void> {\n return this.file.write();\n }\n\n /**\n * Resolve the root directory of an installed package.\n */\n protected resolvePackageRoot(pkg: string): string {\n const pkgJson = require.resolve(`${pkg}/package.json`);\n return dirname(pkgJson);\n }\n\n /**\n * Resolve entrypoints using the Node exports algorithm.\n */\n protected resolveEntrypoints(\n pkg: string,\n pkgJson: PackageJson,\n ): EntryPoint[] {\n const entrypoints: EntryPoint[] = [];\n\n if (!pkgJson.exports) {\n entrypoints.push({ id: pkg });\n return entrypoints;\n }\n\n const keys = Object.keys(pkgJson.exports);\n\n for (const key of keys) {\n try {\n const resolved = resolveExports(pkgJson, key, {\n conditions: [\"node\", \"import\", \"require\", \"default\"],\n });\n\n if (!resolved) continue;\n\n const files = Array.isArray(resolved) ? resolved : [resolved];\n\n for (const file of files) {\n const specifier =\n key === \".\" ? pkg : `${pkg}/${key.replace(\"./\", \"\")}`;\n\n entrypoints.push({\n id: specifier,\n file,\n });\n }\n } catch {}\n }\n\n return entrypoints;\n }\n\n /**\n * Expand wildcard export patterns.\n */\n protected async expandWildcardEntrypoints(\n root: string,\n entrypoints: EntryPoint[],\n ): Promise<EntryPoint[]> {\n return (\n await Promise.allSettled(\n entrypoints.map(async (entry) => {\n if (!entry.file?.includes(\"*\")) return [entry];\n\n const pattern = entry.file;\n const files = await glob.glob(pattern, {\n cwd: root,\n absolute: true,\n });\n\n return files.map((file) => ({\n id: relative(root, file).replace(/\\.(js|mjs|cjs)$/, \"\"),\n file,\n }));\n }),\n )\n )\n .filter((r) => r.status === \"fulfilled\")\n .flatMap((r) => r.value);\n }\n\n /**\n * Dynamically import a module supporting ESM and CommonJS.\n */\n protected async loadModule(id: string): Promise<Record<string, unknown>> {\n try {\n return await import(id);\n } catch {\n return require(id);\n }\n }\n\n /**\n * Extract runtime exports from entrypoints.\n */\n protected async inspectRuntimeExports(\n entrypoints: EntryPoint[],\n ): Promise<ExportNode[]> {\n return (\n await Promise.allSettled(\n entrypoints.map(async (entry) => {\n const mod = await this.loadModule(entry.id);\n return Object.keys(mod).map((name) => ({\n name,\n kind: typeof mod[name],\n source: entry.id,\n }));\n }),\n )\n )\n .filter((r) => r.status === \"fulfilled\")\n .flatMap((r) => r.value);\n }\n\n /**\n * Parse TypeScript declaration files to extract exported types.\n */\n protected async parseTypeExports(root: string): Promise<ExportNode[]> {\n const nodes: ExportNode[] = [];\n\n const filePaths = await glob.glob(\"**/*.d.ts\", {\n cwd: root,\n absolute: true,\n });\n\n const srcMap = createSourceFileMap(filePaths);\n\n for (const filePath of filePaths) {\n const file = srcMap.get(filePath);\n if (!file) continue;\n\n ts.forEachChild(file.sourceFile, (node) => {\n if (\n ts.isInterfaceDeclaration(node) ||\n ts.isTypeAliasDeclaration(node) ||\n ts.isClassDeclaration(node) ||\n ts.isFunctionDeclaration(node)\n ) {\n if (!node.name) return;\n\n nodes.push({\n name: node.name.text,\n kind: ts.SyntaxKind[node.kind],\n source: filePath,\n });\n }\n\n if (ts.isEnumDeclaration(node)) {\n nodes.push({\n name: node.name.text,\n kind: \"enum\",\n source: filePath,\n });\n }\n });\n }\n\n return nodes;\n }\n}\n"]}
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
import { PackageAPI } from "../types/types.exports.js";
|
|
2
|
+
export declare const loadExportsJsonFile: (filePath: string) => Promise<ExportsJsonFile>;
|
|
3
|
+
export declare class ExportsJsonFile {
|
|
4
|
+
readonly filePath: string;
|
|
5
|
+
protected _content: PackageAPI;
|
|
6
|
+
constructor(packageName: string, filePath: string);
|
|
7
|
+
get packageName(): string;
|
|
8
|
+
get content(): PackageAPI;
|
|
9
|
+
read(): Promise<PackageAPI>;
|
|
10
|
+
write(): Promise<void>;
|
|
11
|
+
json(): Promise<string>;
|
|
12
|
+
}
|
|
13
|
+
//# sourceMappingURL=ExportsJsonFile.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"ExportsJsonFile.d.ts","sourceRoot":"","sources":["../../src/exp/ExportsJsonFile.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,UAAU,EAAE,MAAM,2BAA2B,CAAC;AA6BvD,eAAO,MAAM,mBAAmB,GAC9B,UAAU,MAAM,KACf,OAAO,CAAC,eAAe,CAIzB,CAAC;AAEF,qBAAa,eAAe;aAKR,QAAQ,EAAE,MAAM;IAJlC,SAAS,CAAC,QAAQ,EAAE,UAAU,CAAC;gBAG7B,WAAW,EAAE,MAAM,EACH,QAAQ,EAAE,MAAM;IAUlC,IAAW,WAAW,IAAI,MAAM,CAE/B;IAED,IAAW,OAAO,IAAI,UAAU,CAE/B;IAEY,IAAI,IAAI,OAAO,CAAC,UAAU,CAAC;IAM3B,KAAK,IAAI,OAAO,CAAC,IAAI,CAAC;IAKtB,IAAI,IAAI,OAAO,CAAC,MAAM,CAAC;CAGrC"}
|
|
@@ -0,0 +1,59 @@
|
|
|
1
|
+
import { dirname } from "node:path";
|
|
2
|
+
import { mkdir, readFile, writeFile } from "node:fs/promises";
|
|
3
|
+
import { jsonStringify, JsonStringifyFormat } from "../common/common.json.js";
|
|
4
|
+
import { array, object, string } from "zod";
|
|
5
|
+
const entryPointShape = {
|
|
6
|
+
id: string(),
|
|
7
|
+
file: string().optional(),
|
|
8
|
+
};
|
|
9
|
+
const entryPointSchema = object(entryPointShape);
|
|
10
|
+
const exportNodeShape = {
|
|
11
|
+
name: string(),
|
|
12
|
+
kind: string(),
|
|
13
|
+
source: string(),
|
|
14
|
+
};
|
|
15
|
+
const exportNodeSchema = object(exportNodeShape);
|
|
16
|
+
const fileShape = {
|
|
17
|
+
packageName: string(),
|
|
18
|
+
entrypoints: array(entryPointSchema),
|
|
19
|
+
runtimeExports: array(exportNodeSchema),
|
|
20
|
+
typeExports: array(exportNodeSchema),
|
|
21
|
+
};
|
|
22
|
+
const fileSchema = object(fileShape);
|
|
23
|
+
export const loadExportsJsonFile = async (filePath) => {
|
|
24
|
+
const exp = new ExportsJsonFile("", filePath);
|
|
25
|
+
await exp.read();
|
|
26
|
+
return exp;
|
|
27
|
+
};
|
|
28
|
+
export class ExportsJsonFile {
|
|
29
|
+
filePath;
|
|
30
|
+
_content;
|
|
31
|
+
constructor(packageName, filePath) {
|
|
32
|
+
this.filePath = filePath;
|
|
33
|
+
this._content = {
|
|
34
|
+
packageName,
|
|
35
|
+
entrypoints: [],
|
|
36
|
+
runtimeExports: [],
|
|
37
|
+
typeExports: [],
|
|
38
|
+
};
|
|
39
|
+
}
|
|
40
|
+
get packageName() {
|
|
41
|
+
return this._content.packageName;
|
|
42
|
+
}
|
|
43
|
+
get content() {
|
|
44
|
+
return this._content;
|
|
45
|
+
}
|
|
46
|
+
async read() {
|
|
47
|
+
const cont = await readFile(this.filePath, { encoding: "utf8" });
|
|
48
|
+
this._content = await fileSchema.parseAsync(cont);
|
|
49
|
+
return this._content;
|
|
50
|
+
}
|
|
51
|
+
async write() {
|
|
52
|
+
await mkdir(dirname(this.filePath), { recursive: true });
|
|
53
|
+
return writeFile(this.filePath, await this.json(), { encoding: "utf8" });
|
|
54
|
+
}
|
|
55
|
+
async json() {
|
|
56
|
+
return jsonStringify(this._content, JsonStringifyFormat.jsonStringify);
|
|
57
|
+
}
|
|
58
|
+
}
|
|
59
|
+
//# sourceMappingURL=ExportsJsonFile.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"ExportsJsonFile.js","sourceRoot":"","sources":["../../src/exp/ExportsJsonFile.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,OAAO,EAAE,MAAM,WAAW,CAAC;AAEpC,OAAO,EAAE,KAAK,EAAE,QAAQ,EAAE,SAAS,EAAE,MAAM,kBAAkB,CAAC;AAC9D,OAAO,EAAE,aAAa,EAAE,mBAAmB,EAAE,MAAM,0BAA0B,CAAC;AAC9E,OAAO,EAAE,KAAK,EAAE,MAAM,EAAE,MAAM,EAAE,MAAM,KAAK,CAAC;AAE5C,MAAM,eAAe,GAAG;IACtB,EAAE,EAAE,MAAM,EAAE;IACZ,IAAI,EAAE,MAAM,EAAE,CAAC,QAAQ,EAAE;CAC1B,CAAC;AAEF,MAAM,gBAAgB,GAAG,MAAM,CAAC,eAAe,CAAC,CAAC;AAE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AU,CAAC,UAAU,CAAC,IAAI,CAAC,CAAC;QAClD,OAAO,IAAI,CAAC,QAAQ,CAAC;IACvB,CAAC;IAEM,KAAK,CAAC,KAAK;QAChB,MAAM,KAAK,CAAC,OAAO,CAAC,IAAI,CAAC,QAAQ,CAAC,EAAE,EAAE,SAAS,EAAE,IAAI,EAAE,CAAC,CAAC;QACzD,OAAO,SAAS,CAAC,IAAI,CAAC,QAAQ,EAAE,MAAM,IAAI,CAAC,IAAI,EAAE,EAAE,EAAE,QAAQ,EAAE,MAAM,EAAE,CAAC,CAAC;IAC3E,CAAC;IAEM,KAAK,CAAC,IAAI;QACf,OAAO,aAAa,CAAC,IAAI,CAAC,QAAQ,EAAE,mBAAmB,CAAC,aAAa,CAAC,CAAC;IACzE,CAAC;CACF","sourcesContent":["import { dirname } from \"node:path\";\nimport { PackageAPI } from \"../types/types.exports.js\";\nimport { mkdir, readFile, writeFile } from \"node:fs/promises\";\nimport { jsonStringify, JsonStringifyFormat } from \"../common/common.json.js\";\nimport { array, object, string } from \"zod\";\n\nconst entryPointShape = {\n id: string(),\n file: string().optional(),\n};\n\nconst entryPointSchema = object(entryPointShape);\n\nconst exportNodeShape = {\n name: string(),\n kind: string(),\n source: string(),\n};\n\nconst exportNodeSchema = object(exportNodeShape);\n\nconst fileShape = {\n packageName: string(),\n entrypoints: array(entryPointSchema),\n runtimeExports: array(exportNodeSchema),\n typeExports: array(exportNodeSchema),\n};\n\nconst fileSchema = object(fileShape);\n\nexport const loadExportsJsonFile = async (\n filePath: string,\n): Promise<ExportsJsonFile> => {\n const exp = new ExportsJsonFile(\"\", filePath);\n await exp.read();\n return exp;\n};\n\nexport class ExportsJsonFile {\n protected _content: PackageAPI;\n\n public constructor(\n packageName: string,\n public readonly filePath: string,\n ) {\n this._content = {\n packageName,\n entrypoints: [],\n runtimeExports: [],\n typeExports: [],\n };\n }\n\n public get packageName(): string {\n return this._content.packageName;\n }\n\n public get content(): PackageAPI {\n return this._content;\n }\n\n public async read(): Promise<PackageAPI> {\n const cont = await readFile(this.filePath, { encoding: \"utf8\" });\n this._content = await fileSchema.parseAsync(cont);\n return this._content;\n }\n\n public async write(): Promise<void> {\n await mkdir(dirname(this.filePath), { recursive: true });\n return writeFile(this.filePath, await this.json(), { encoding: \"utf8\" });\n }\n\n public async json(): Promise<string> {\n return jsonStringify(this._content, JsonStringifyFormat.jsonStringify);\n }\n}\n"]}
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
import { PackageAPI } from "../types/types.exports.js";
|
|
2
|
+
import { ExportsJsonFile } from "./ExportsJsonFile.js";
|
|
3
|
+
export declare class ExportsTsFile extends ExportsJsonFile {
|
|
4
|
+
static linkByJson(json: ExportsJsonFile): ExportsTsFile;
|
|
5
|
+
read(): Promise<PackageAPI>;
|
|
6
|
+
write(): Promise<void>;
|
|
7
|
+
ts(): Promise<string>;
|
|
8
|
+
}
|
|
9
|
+
//# sourceMappingURL=ExportsTsFile.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"ExportsTsFile.d.ts","sourceRoot":"","sources":["../../src/exp/ExportsTsFile.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,UAAU,EAAE,MAAM,2BAA2B,CAAC;AAGvD,OAAO,EAAE,eAAe,EAAE,MAAM,sBAAsB,CAAC;AAGvD,qBAAa,aAAc,SAAQ,eAAe;WAClC,UAAU,CAAC,IAAI,EAAE,eAAe,GAAG,aAAa;IAOxC,IAAI,IAAI,OAAO,CAAC,UAAU,CAAC;IAI3B,KAAK,IAAI,OAAO,CAAC,IAAI,CAAC;IAK/B,EAAE,IAAI,OAAO,CAAC,MAAM,CAAC;CAQnC"}
|
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
import { dirname } from "node:path";
|
|
2
|
+
import { mkdir, writeFile } from "node:fs/promises";
|
|
3
|
+
import { jsonStringify, JsonStringifyFormat } from "../common/common.json.js";
|
|
4
|
+
import { ExportsJsonFile } from "./ExportsJsonFile.js";
|
|
5
|
+
import { formatCode } from "../code/code.format.js";
|
|
6
|
+
export class ExportsTsFile extends ExportsJsonFile {
|
|
7
|
+
static linkByJson(json) {
|
|
8
|
+
const filePath = json.filePath.replace(/\.json$/, ".ts");
|
|
9
|
+
const ts = new ExportsTsFile(json.packageName, filePath);
|
|
10
|
+
ts._content = json.content;
|
|
11
|
+
return ts;
|
|
12
|
+
}
|
|
13
|
+
async read() {
|
|
14
|
+
throw new Error("Read not implemented for ExportsTsFile");
|
|
15
|
+
}
|
|
16
|
+
async write() {
|
|
17
|
+
await mkdir(dirname(this.filePath), { recursive: true });
|
|
18
|
+
return writeFile(this.filePath, await this.ts(), { encoding: "utf8" });
|
|
19
|
+
}
|
|
20
|
+
async ts() {
|
|
21
|
+
const code = [
|
|
22
|
+
'import { PackageAPI } from "../types/types.exports.js";',
|
|
23
|
+
"",
|
|
24
|
+
`export const pkgExport: PackageAPI = ${await jsonStringify(this._content, JsonStringifyFormat.jsonStringify)}`,
|
|
25
|
+
];
|
|
26
|
+
return await formatCode(code.join("\n"));
|
|
27
|
+
}
|
|
28
|
+
}
|
|
29
|
+
//# sourceMappingURL=ExportsTsFile.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"ExportsTsFile.js","sourceRoot":"","sources":["../../src/exp/ExportsTsFile.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,OAAO,EAAE,MAAM,WAAW,CAAC;AAEpC,OAAO,EAAE,KAAK,EAAE,SAAS,EAAE,MAAM,kBAAkB,CAAC;AACpD,OAAO,EAAE,aAAa,EAAE,mBAAmB,EAAE,MAAM,0BAA0B,CAAC;AAC9E,OAAO,EAAE,eAAe,EAAE,MAAM,sBAAsB,CAAC;AACvD,OAAO,EAAE,UAAU,EAAE,MAAM,wBAAwB,CAAC;AAEpD,MAAM,OAAO,aAAc,SAAQ,eAAe;IACzC,MAAM,CAAC,UAAU,CAAC,IAAqB;QAC5C,MAAM,QAAQ,GAAG,IAAI,CAAC,QAAQ,CAAC,OAAO,CAAC,SAAS,EAAE,KAAK,CAAC,CAAC;QACzD,MAAM,EAAE,GAAG,IAAI,aAAa,CAAC,IAAI,CAAC,WAAW,EAAE,QAAQ,CAAC,CAAC;QACzD,EAAE,CAAC,QAAQ,GAAG,IAAI,CAAC,OAAO,CAAC;QAC3B,OAAO,EAAE,CAAC;IACZ,CAAC;IAEe,KAAK,CAAC,IAAI;QACxB,MAAM,IAAI,KAAK,CAAC,wCAAwC,CAAC,CAAC;IAC5D,CAAC;IAEe,KAAK,CAAC,KAAK;QACzB,MAAM,KAAK,CAAC,OAAO,CAAC,IAAI,CAAC,QAAQ,CAAC,EAAE,EAAE,SAAS,EAAE,IAAI,EAAE,CAAC,CAAC;QACzD,OAAO,SAAS,CAAC,IAAI,CAAC,QAAQ,EAAE,MAAM,IAAI,CAAC,EAAE,EAAE,EAAE,EAAE,QAAQ,EAAE,MAAM,EAAE,CAAC,CAAC;IACzE,CAAC;IAEM,KAAK,CAAC,EAAE;QACb,MAAM,IAAI,GAAa;YACrB,yDAAyD;YACzD,EAAE;YACF,wCAAwC,MAAM,aAAa,CAAC,IAAI,CAAC,QAAQ,EAAE,mBAAmB,CAAC,aAAa,CAAC,EAAE;SAChH,CAAC;QACF,OAAO,MAAM,UAAU,CAAC,IAAI,CAAC,IAAI,CAAC,IAAI,CAAC,CAAC,CAAC;IAC3C,CAAC;CACF","sourcesContent":["import { dirname } from \"node:path\";\nimport { PackageAPI } from \"../types/types.exports.js\";\nimport { mkdir, writeFile } from \"node:fs/promises\";\nimport { jsonStringify, JsonStringifyFormat } from \"../common/common.json.js\";\nimport { ExportsJsonFile } from \"./ExportsJsonFile.js\";\nimport { formatCode } from \"../code/code.format.js\";\n\nexport class ExportsTsFile extends ExportsJsonFile {\n public static linkByJson(json: ExportsJsonFile): ExportsTsFile {\n const filePath = json.filePath.replace(/\\.json$/, \".ts\");\n const ts = new ExportsTsFile(json.packageName, filePath);\n ts._content = json.content;\n return ts;\n }\n\n public override async read(): Promise<PackageAPI> {\n throw new Error(\"Read not implemented for ExportsTsFile\");\n }\n\n public override async write(): Promise<void> {\n await mkdir(dirname(this.filePath), { recursive: true });\n return writeFile(this.filePath, await this.ts(), { encoding: \"utf8\" });\n }\n\n public async ts(): Promise<string> {\n const code: string[] = [\n 'import { PackageAPI } from \"../types/types.exports.js\";',\n \"\",\n `export const pkgExport: PackageAPI = ${await jsonStringify(this._content, JsonStringifyFormat.jsonStringify)}`,\n ];\n return await formatCode(code.join(\"\\n\"));\n }\n}\n"]}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"exports.d.ts","sourceRoot":"","sources":["../../src/exp/exports.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,UAAU,EAAE,MAAM,2BAA2B,CAAC;AAEvD,eAAO,MAAM,SAAS,EAAE,UAg/BvB,CAAC"}
|