@mxpicture/build-api 0.2.48 → 0.2.49
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/barrel/Barrel.d.ts +0 -4
- package/dist/barrel/Barrel.d.ts.map +1 -1
- package/dist/barrel/Barrel.js +56 -50
- package/dist/barrel/Barrel.js.map +1 -1
- package/dist/code/code.common.d.ts +6 -0
- package/dist/code/code.common.d.ts.map +1 -0
- package/dist/code/code.common.js +40 -0
- package/dist/code/code.common.js.map +1 -0
- package/dist/code/code.exports.d.ts +8 -0
- package/dist/code/code.exports.d.ts.map +1 -0
- package/dist/code/code.exports.js +70 -0
- package/dist/code/code.exports.js.map +1 -0
- package/dist/{format/format.code.d.ts → code/code.format.d.ts} +1 -3
- package/dist/code/code.format.d.ts.map +1 -0
- package/dist/code/code.format.js +5 -0
- package/dist/code/code.format.js.map +1 -0
- package/dist/code/index.d.ts +4 -0
- package/dist/code/index.d.ts.map +1 -0
- package/dist/code/index.js +5 -0
- package/dist/code/index.js.map +1 -0
- package/dist/pkg/pkg.fs.js +1 -1
- package/dist/pkg/pkg.fs.js.map +1 -1
- package/dist/types/types.code.d.ts +11 -0
- package/dist/types/types.code.d.ts.map +1 -1
- package/dist/types/types.code.js.map +1 -1
- package/package.json +3 -5
- package/dist/format/format.code.d.ts.map +0 -1
- package/dist/format/format.code.js +0 -22
- package/dist/format/format.code.js.map +0 -1
- package/dist/format/index.d.ts +0 -2
- package/dist/format/index.d.ts.map +0 -1
- package/dist/format/index.js +0 -3
- package/dist/format/index.js.map +0 -1
package/dist/barrel/Barrel.d.ts
CHANGED
|
@@ -10,10 +10,6 @@ export declare class Barrel {
|
|
|
10
10
|
run(): Promise<void>;
|
|
11
11
|
protected isExcluded(fileName: string): boolean;
|
|
12
12
|
protected persistBarrel(group: BarrelGroup): Promise<BarrelGroup>;
|
|
13
|
-
protected extractExportsFromFile(filePath: string): Promise<{
|
|
14
|
-
exports: string[];
|
|
15
|
-
hasDefault: boolean;
|
|
16
|
-
}>;
|
|
17
13
|
protected updatePackageExports(pkg: Pkg, exports: Record<string, string>): Promise<void>;
|
|
18
14
|
protected hasExportsChanged(a: Record<string, string> | undefined, b: Record<string, string> | undefined): boolean;
|
|
19
15
|
protected extractExports(result: BarrelResult): Record<string, string>;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"Barrel.d.ts","sourceRoot":"","sources":["../../src/barrel/Barrel.ts"],"names":[],"mappings":"AACA,OAAO,EACL,WAAW,EACX,YAAY,EACZ,YAAY,EACb,MAAM,0BAA0B,CAAC;AAIlC,OAAO,EAAE,GAAG,EAAE,MAAM,eAAe,CAAC;
|
|
1
|
+
{"version":3,"file":"Barrel.d.ts","sourceRoot":"","sources":["../../src/barrel/Barrel.ts"],"names":[],"mappings":"AACA,OAAO,EACL,WAAW,EACX,YAAY,EACZ,YAAY,EACb,MAAM,0BAA0B,CAAC;AAIlC,OAAO,EAAE,GAAG,EAAE,MAAM,eAAe,CAAC;AAKpC,eAAO,MAAM,yBAAyB,EAAE,MAAM,EAQ7C,CAAC;AAGF,eAAO,MAAM,cAAc,4DACgC,CAAC;AAE5D,eAAO,MAAM,SAAS,GAAU,QAAQ,YAAY,kBAMnD,CAAC;AAEF,qBAAa,MAAM;IAEf,SAAS,CAAC,QAAQ,CAAC,QAAQ,EAAE,MAAM,EAAE;IACrC,SAAS,CAAC,QAAQ,CAAC,UAAU,EAAE,MAAM;gBADlB,QAAQ,EAAE,MAAM,EAAE,EAClB,UAAU,EAAE,MAAM;IAG1B,GAAG,IAAI,OAAO,CAAC,IAAI,CAAC;IAkFjC,SAAS,CAAC,UAAU,CAAC,QAAQ,EAAE,MAAM,GAAG,OAAO;cAI/B,aAAa,CAAC,KAAK,EAAE,WAAW,GAAG,OAAO,CAAC,WAAW,CAAC;cAsFvD,oBAAoB,CAClC,GAAG,EAAE,GAAG,EACR,OAAO,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC;IAoBjC,SAAS,CAAC,iBAAiB,CACzB,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,GAAG,SAAS,EACrC,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,GAAG,SAAS,GACpC,OAAO;IAcV,SAAS,CAAC,cAAc,CAAC,MAAM,EAAE,YAAY,GAAG,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC;CASvE"}
|
package/dist/barrel/Barrel.js
CHANGED
|
@@ -1,8 +1,9 @@
|
|
|
1
1
|
import { basename, dirname, join, relative } from "node:path";
|
|
2
|
-
import { readdir,
|
|
2
|
+
import { readdir, rm, writeFile } from "node:fs/promises";
|
|
3
3
|
import { logInfo, logSuccess } from "../logger/Logger.js";
|
|
4
4
|
import { initWorkspace, workspace } from "../workspace/Workspace.js";
|
|
5
|
-
import { formatCode } from "../
|
|
5
|
+
import { formatCode } from "../code/code.format.js";
|
|
6
|
+
import { fileExports } from "../code/code.exports.js";
|
|
6
7
|
// /** File patterns to exclude from barrel exports */
|
|
7
8
|
export const DEFAULT_EXCLUDED_PATTERNS = [
|
|
8
9
|
/\.test\.ts$/,
|
|
@@ -96,9 +97,12 @@ export class Barrel {
|
|
|
96
97
|
const exportLines = [];
|
|
97
98
|
for (const file of group.files.sort()) {
|
|
98
99
|
const filePath = join(group.dirPath, file);
|
|
99
|
-
const
|
|
100
|
+
const expResult = fileExports(filePath);
|
|
101
|
+
if (expResult.items.length === 0)
|
|
102
|
+
continue;
|
|
103
|
+
const exports = expResult.items.map((item) => item.name);
|
|
100
104
|
const moduleRef = `./${basename(file, ".ts")}.js`;
|
|
101
|
-
if (hasDefault) {
|
|
105
|
+
if (expResult.hasDefault) {
|
|
102
106
|
exportLines.push(`export * from "${moduleRef}";`);
|
|
103
107
|
}
|
|
104
108
|
else if (exports.length > 0) {
|
|
@@ -110,52 +114,54 @@ export class Barrel {
|
|
|
110
114
|
await writeFile(barrelPath, content);
|
|
111
115
|
return group;
|
|
112
116
|
}
|
|
113
|
-
async extractExportsFromFile(
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
}
|
|
117
|
+
// protected async extractExportsFromFile(
|
|
118
|
+
// filePath: string,
|
|
119
|
+
// ): Promise<{ exports: string[]; hasDefault: boolean }> {
|
|
120
|
+
// try {
|
|
121
|
+
// const content = await readFile(filePath, "utf-8");
|
|
122
|
+
// const exports: Set<string> = new Set();
|
|
123
|
+
// let hasDefault = false;
|
|
124
|
+
// // Detect any default export
|
|
125
|
+
// if (/export\s+default\b/.test(content)) hasDefault = true;
|
|
126
|
+
// // Match named exports: export const|function|class Name
|
|
127
|
+
// const namedExportPattern =
|
|
128
|
+
// /export\s+(?:const|let|var|function|class|interface|type|enum)\s+([a-zA-Z_$][a-zA-Z0-9_$]*)/g;
|
|
129
|
+
// let match;
|
|
130
|
+
// while ((match = namedExportPattern.exec(content)) !== null) {
|
|
131
|
+
// const name = match[1];
|
|
132
|
+
// if (
|
|
133
|
+
// !name.startsWith("_") &&
|
|
134
|
+
// !name.startsWith("//") &&
|
|
135
|
+
// !name.startsWith("/*")
|
|
136
|
+
// )
|
|
137
|
+
// exports.add(name);
|
|
138
|
+
// }
|
|
139
|
+
// // Match export { a, b, c } and export { a, b, c } from '...'
|
|
140
|
+
// const exportBracePattern = /export\s*\{\s*([^}]+)\s*\}/g;
|
|
141
|
+
// while ((match = exportBracePattern.exec(content)) !== null) {
|
|
142
|
+
// const items = match[1].split(",");
|
|
143
|
+
// for (const item of items) {
|
|
144
|
+
// const trimmed = item.trim();
|
|
145
|
+
// if (!trimmed) continue;
|
|
146
|
+
// // Handle "export { name as alias }"
|
|
147
|
+
// const parts = trimmed.split(/\s+as\s+/);
|
|
148
|
+
// const name = parts[0].trim();
|
|
149
|
+
// const alias = parts[1]?.trim();
|
|
150
|
+
// // Skip default exports (e.g. "export { Foo as default }")
|
|
151
|
+
// if (alias === "default") {
|
|
152
|
+
// hasDefault = true;
|
|
153
|
+
// continue;
|
|
154
|
+
// }
|
|
155
|
+
// if (name && name !== "default" && !name.startsWith("_")) {
|
|
156
|
+
// exports.add(name);
|
|
157
|
+
// }
|
|
158
|
+
// }
|
|
159
|
+
// }
|
|
160
|
+
// return { exports: Array.from(exports).sort(), hasDefault };
|
|
161
|
+
// } catch {
|
|
162
|
+
// return { exports: [], hasDefault: false };
|
|
163
|
+
// }
|
|
164
|
+
// }
|
|
159
165
|
async updatePackageExports(pkg, exports) {
|
|
160
166
|
try {
|
|
161
167
|
// const pkgName = relative(this.paths.workspacesDir, packageDir);
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"Barrel.js","sourceRoot":"","sources":["../../src/barrel/Barrel.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,QAAQ,EAAE,OAAO,EAAE,IAAI,EAAE,QAAQ,EAAE,MAAM,WAAW,CAAC;AAM9D,OAAO,EAAE,OAAO,EAAE,QAAQ,EAAE,EAAE,EAAE,SAAS,EAAE,MAAM,kBAAkB,CAAC;AACpE,OAAO,EAAE,OAAO,EAAE,UAAU,EAAE,MAAM,qBAAqB,CAAC;AAC1D,OAAO,EAAE,aAAa,EAAE,SAAS,EAAE,MAAM,2BAA2B,C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AAC;CACF","sourcesContent":["import { basename, dirname, join, relative } from \"node:path\";\nimport {\n BarrelGroup,\n BarrelParams,\n BarrelResult,\n} from \"../types/types.barrel.js\";\nimport { readdir, readFile, rm, writeFile } from \"node:fs/promises\";\nimport { logInfo, logSuccess } from \"../logger/Logger.js\";\nimport { initWorkspace, workspace } from \"../workspace/Workspace.js\";\nimport { Pkg } from \"../pkg/Pkg.js\";\nimport { formatCode } from \"../format/format.code.js\";\n\n// /** File patterns to exclude from barrel exports */\nexport const DEFAULT_EXCLUDED_PATTERNS: RegExp[] = [\n /\\.test\\.ts$/,\n /\\.spec\\.ts$/,\n /(^|\\/)__tests__(\\/|$)/,\n /\\.d\\.ts$/,\n /index\\.ts$/,\n /(.+\\/|^)src\\/(.+\\/|)scripts?\\/.+\\.m?ts$/,\n /\\/4testing(\\/|$)/,\n];\n\n// /** Header comment added to every generated barrel file */\nexport const DEFAULT_HEADER =\n \"// This file is auto-generated. Do not edit manually.\\n\";\n\nexport const runBarrel = async (params: BarrelParams) => {\n initWorkspace(params.repoRoot);\n return new Barrel(\n params.excludes ?? DEFAULT_EXCLUDED_PATTERNS,\n params.fileHeader ?? DEFAULT_HEADER,\n ).run();\n};\n\nexport class Barrel {\n public constructor(\n protected readonly excludes: RegExp[],\n protected readonly fileHeader: string,\n ) {}\n\n public async run(): Promise<void> {\n const ws = workspace();\n await ws.read();\n\n const promises: Promise<BarrelGroup>[] = [];\n\n for (const pkg of ws.packages) {\n try {\n const items = (await readdir(pkg.srcPath, { recursive: true })).sort();\n let currentGroup: BarrelGroup | undefined;\n\n for (const item of items) {\n const filename = basename(item);\n const dirPath = join(pkg.srcPath, dirname(item));\n const filePath = join(dirPath, filename);\n\n if (dirPath !== currentGroup?.dirPath) {\n if (currentGroup)\n promises.push(this.persistBarrel({ ...currentGroup }));\n currentGroup = {\n dirPath,\n files: [],\n pkg,\n };\n }\n\n if (\n this.isExcluded(filePath) ||\n (!filename.endsWith(\".ts\") && !filename.endsWith(\".mts\"))\n )\n continue;\n\n currentGroup.files.push(filename);\n }\n\n if (currentGroup)\n promises.push(this.persistBarrel({ ...currentGroup }));\n } catch {\n continue;\n }\n }\n\n const barrelGroups = (await Promise.all(promises)).filter(\n (prom) => prom.files.length > 0,\n );\n\n const results: BarrelResult[] = [];\n\n for (const barrelGroup of barrelGroups) {\n let found = results.find(\n (res) => barrelGroup.dirPath === res.pkg.dirPath,\n );\n if (!found) {\n found = {\n barrelDirs: [],\n pkg: barrelGroup.pkg,\n };\n results.push(found);\n }\n\n found.barrelDirs.push(barrelGroup.dirPath);\n }\n\n const pkgExps: Record<string, { pkg: Pkg; exps: Record<string, string> }> =\n {};\n for (const res of results) {\n if (!(res.pkg.content.name in pkgExps))\n pkgExps[res.pkg.content.name] = { pkg: res.pkg, exps: {} };\n\n pkgExps[res.pkg.content.name].exps = {\n ...pkgExps[res.pkg.content.name].exps,\n ...this.extractExports(res),\n };\n }\n\n await Promise.all(\n Object.values(pkgExps).map(async (pkgExp) =>\n this.updatePackageExports(pkgExp.pkg, pkgExp.exps),\n ),\n );\n }\n\n protected isExcluded(fileName: string): boolean {\n return this.excludes.some((pattern) => pattern.test(fileName));\n }\n\n protected async persistBarrel(group: BarrelGroup): Promise<BarrelGroup> {\n const barrelPath = join(group.dirPath, \"index.ts\");\n // no files --> skip/delete index.ts\n if (group.files.length === 0) {\n await rm(barrelPath, { recursive: true, force: true });\n return group;\n }\n\n const exportLines: string[] = [];\n for (const file of group.files.sort()) {\n const filePath = join(group.dirPath, file);\n const { exports, hasDefault } =\n await this.extractExportsFromFile(filePath);\n const moduleRef = `./${basename(file, \".ts\")}.js`;\n if (hasDefault) {\n exportLines.push(`export * from \"${moduleRef}\";`);\n } else if (exports.length > 0) {\n exportLines.push(\n `export { ${exports.join(\", \")} } from \"${moduleRef}\";`,\n );\n }\n }\n\n let content = `${this.fileHeader}${exportLines.length > 0 ? exportLines.join(\"\\n\") + \"\\n\" : \"\"}`;\n content = await formatCode(content);\n await writeFile(barrelPath, content);\n return group;\n }\n\n protected async extractExportsFromFile(\n filePath: string,\n ): Promise<{ exports: string[]; hasDefault: boolean }> {\n try {\n const content = await readFile(filePath, \"utf-8\");\n const exports: Set<string> = new Set();\n let hasDefault = false;\n\n // Detect any default export\n if (/export\\s+default\\b/.test(content)) hasDefault = true;\n\n // Match named exports: export const|function|class Name\n const namedExportPattern =\n /export\\s+(?:const|let|var|function|class|interface|type|enum)\\s+([a-zA-Z_$][a-zA-Z0-9_$]*)/g;\n let match;\n while ((match = namedExportPattern.exec(content)) !== null) {\n const name = match[1];\n if (\n !name.startsWith(\"_\") &&\n !name.startsWith(\"//\") &&\n !name.startsWith(\"/*\")\n )\n exports.add(name);\n }\n\n // Match export { a, b, c } and export { a, b, c } from '...'\n const exportBracePattern = /export\\s*\\{\\s*([^}]+)\\s*\\}/g;\n while ((match = exportBracePattern.exec(content)) !== null) {\n const items = match[1].split(\",\");\n for (const item of items) {\n const trimmed = item.trim();\n if (!trimmed) continue;\n // Handle \"export { name as alias }\"\n const parts = trimmed.split(/\\s+as\\s+/);\n const name = parts[0].trim();\n const alias = parts[1]?.trim();\n // Skip default exports (e.g. \"export { Foo as default }\")\n if (alias === \"default\") {\n hasDefault = true;\n continue;\n }\n if (name && name !== \"default\" && !name.startsWith(\"_\")) {\n exports.add(name);\n }\n }\n }\n\n return { exports: Array.from(exports).sort(), hasDefault };\n } catch {\n return { exports: [], hasDefault: false };\n }\n }\n\n protected async updatePackageExports(\n pkg: Pkg,\n exports: Record<string, string>,\n ) {\n try {\n // const pkgName = relative(this.paths.workspacesDir, packageDir);\n // // const pkgs = await workspace().loadPackages();\n\n logInfo(`📦 updating ${pkg.repoDirPath} package.json ...`);\n // const pkg = await readPackageJsonThrow(packageJsonPath);\n if (!this.hasExportsChanged(exports, pkg.content.exports)) {\n logInfo(`🧹 No changes in ${pkg.repoDirPath}, nothing to do`);\n return;\n }\n pkg.content.exports = { ...exports };\n await pkg.write();\n logSuccess(`✅ ${pkg.repoDirPath} update successful`);\n } catch (error) {\n logInfo(error);\n }\n }\n\n protected hasExportsChanged(\n a: Record<string, string> | undefined,\n b: Record<string, string> | undefined,\n ): boolean {\n if (!a) a = {};\n if (!b) b = {};\n\n if (Object.keys(a).length !== Object.keys(b).length) return true;\n if (!a && !b) return false;\n if (!a || !b) return true;\n\n for (const entryA of Object.entries(a)) {\n if (b[entryA[0]] !== entryA[1]) return true;\n }\n return false;\n }\n\n protected extractExports(result: BarrelResult): Record<string, string> {\n const record: Record<string, string> = {};\n for (const barrelDir of result.barrelDirs) {\n const ex = relative(result.pkg.srcPath, barrelDir);\n record[`./${ex}`] = `./dist/${ex}/index.js`;\n }\n record[\"./package.json\"] = \"./package.json\";\n return record;\n }\n}\n"]}
|
|
1
|
+
{"version":3,"file":"Barrel.js","sourceRoot":"","sources":["../../src/barrel/Barrel.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,QAAQ,EAAE,OAAO,EAAE,IAAI,EAAE,QAAQ,EAAE,MAAM,WAAW,CAAC;AAM9D,OAAO,EAAE,OAAO,EAAE,EAAE,EAAE,SAAS,EAAE,MAAM,kBAAkB,CAAC;AAC1D,OAAO,EAAE,OAAO,EAAE,UAAU,EAAE,MAAM,qBAAqB,CAAC;AAC1D,OAAO,EAAE,aAAa,EAAE,SAAS,EAAE,MAAM,2BAA2B,CAAC;AAErE,OAAO,EAAE,UAAU,EAAE,MAAM,wBAAwB,CAAC;AACpD,OAAO,EAAE,WAAW,EAAE,MAAM,yBAAyB,CAAC;AAEtD,sDAAsD;AACtD,MAAM,CAAC,MAAM,yBAAyB,GAAa;IACjD,aAAa;IACb,aAAa;IACb,uBAAuB;IACvB,UAAU;IACV,YAAY;IACZ,yCAAyC;IACzC,kBAAkB;CACnB,CAAC;AAEF,6DAA6D;AAC7D,MAAM,CAAC,MAAM,cAAc,GACzB,yDAAyD,CAAC;AAE5D,MAAM,CAAC,MAAM,SAAS,GAAG,KAAK,EAAE,MAAoB,EAAE,EAAE;IACtD,aAAa,CAAC,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rC,CAAqC;QAErC,IAAI,CAAC,CAAC;YAAE,CAAC,GAAG,EAAE,CAAC;QACf,IAAI,CAAC,CAAC;YAAE,CAAC,GAAG,EAAE,CAAC;QAEf,IAAI,MAAM,CAAC,IAAI,CAAC,CAAC,CAAC,CAAC,MAAM,KAAK,MAAM,CAAC,IAAI,CAAC,CAAC,CAAC,CAAC,MAAM;YAAE,OAAO,IAAI,CAAC;QACjE,IAAI,CAAC,CAAC,IAAI,CAAC,CAAC;YAAE,OAAO,KAAK,CAAC;QAC3B,IAAI,CAAC,CAAC,IAAI,CAAC,CAAC;YAAE,OAAO,IAAI,CAAC;QAE1B,KAAK,MAAM,MAAM,IAAI,MAAM,CAAC,OAAO,CAAC,CAAC,CAAC,EAAE,CAAC;YACvC,IAAI,CAAC,CAAC,MAAM,CAAC,CAAC,CAAC,CAAC,KAAK,MAAM,CAAC,CAAC,CAAC;gBAAE,OAAO,IAAI,CAAC;QAC9C,CAAC;QACD,OAAO,KAAK,CAAC;IACf,CAAC;IAES,cAAc,CAAC,MAAoB;QAC3C,MAAM,MAAM,GAA2B,EAAE,CAAC;QAC1C,KAAK,MAAM,SAAS,IAAI,MAAM,CAAC,UAAU,EAAE,CAAC;YAC1C,MAAM,EAAE,GAAG,QAAQ,CAAC,MAAM,CAAC,GAAG,CAAC,OAAO,EAAE,SAAS,CAAC,CAAC;YACnD,MAAM,CAAC,KAAK,EAAE,EAAE,CAAC,GAAG,UAAU,EAAE,WAAW,CAAC;QAC9C,CAAC;QACD,MAAM,CAAC,gBAAgB,CAAC,GAAG,gBAAgB,CAAC;QAC5C,OAAO,MAAM,CAAC;IAChB,CAAC;CACF","sourcesContent":["import { basename, dirname, join, relative } from \"node:path\";\nimport {\n BarrelGroup,\n BarrelParams,\n BarrelResult,\n} from \"../types/types.barrel.js\";\nimport { readdir, rm, writeFile } from \"node:fs/promises\";\nimport { logInfo, logSuccess } from \"../logger/Logger.js\";\nimport { initWorkspace, workspace } from \"../workspace/Workspace.js\";\nimport { Pkg } from \"../pkg/Pkg.js\";\nimport { formatCode } from \"../code/code.format.js\";\nimport { fileExports } from \"../code/code.exports.js\";\n\n// /** File patterns to exclude from barrel exports */\nexport const DEFAULT_EXCLUDED_PATTERNS: RegExp[] = [\n /\\.test\\.ts$/,\n /\\.spec\\.ts$/,\n /(^|\\/)__tests__(\\/|$)/,\n /\\.d\\.ts$/,\n /index\\.ts$/,\n /(.+\\/|^)src\\/(.+\\/|)scripts?\\/.+\\.m?ts$/,\n /\\/4testing(\\/|$)/,\n];\n\n// /** Header comment added to every generated barrel file */\nexport const DEFAULT_HEADER =\n \"// This file is auto-generated. Do not edit manually.\\n\";\n\nexport const runBarrel = async (params: BarrelParams) => {\n initWorkspace(params.repoRoot);\n return new Barrel(\n params.excludes ?? DEFAULT_EXCLUDED_PATTERNS,\n params.fileHeader ?? DEFAULT_HEADER,\n ).run();\n};\n\nexport class Barrel {\n public constructor(\n protected readonly excludes: RegExp[],\n protected readonly fileHeader: string,\n ) {}\n\n public async run(): Promise<void> {\n const ws = workspace();\n await ws.read();\n\n const promises: Promise<BarrelGroup>[] = [];\n\n for (const pkg of ws.packages) {\n try {\n const items = (await readdir(pkg.srcPath, { recursive: true })).sort();\n let currentGroup: BarrelGroup | undefined;\n\n for (const item of items) {\n const filename = basename(item);\n const dirPath = join(pkg.srcPath, dirname(item));\n const filePath = join(dirPath, filename);\n\n if (dirPath !== currentGroup?.dirPath) {\n if (currentGroup)\n promises.push(this.persistBarrel({ ...currentGroup }));\n currentGroup = {\n dirPath,\n files: [],\n pkg,\n };\n }\n\n if (\n this.isExcluded(filePath) ||\n (!filename.endsWith(\".ts\") && !filename.endsWith(\".mts\"))\n )\n continue;\n\n currentGroup.files.push(filename);\n }\n\n if (currentGroup)\n promises.push(this.persistBarrel({ ...currentGroup }));\n } catch {\n continue;\n }\n }\n\n const barrelGroups = (await Promise.all(promises)).filter(\n (prom) => prom.files.length > 0,\n );\n\n const results: BarrelResult[] = [];\n\n for (const barrelGroup of barrelGroups) {\n let found = results.find(\n (res) => barrelGroup.dirPath === res.pkg.dirPath,\n );\n if (!found) {\n found = {\n barrelDirs: [],\n pkg: barrelGroup.pkg,\n };\n results.push(found);\n }\n\n found.barrelDirs.push(barrelGroup.dirPath);\n }\n\n const pkgExps: Record<string, { pkg: Pkg; exps: Record<string, string> }> =\n {};\n for (const res of results) {\n if (!(res.pkg.content.name in pkgExps))\n pkgExps[res.pkg.content.name] = { pkg: res.pkg, exps: {} };\n\n pkgExps[res.pkg.content.name].exps = {\n ...pkgExps[res.pkg.content.name].exps,\n ...this.extractExports(res),\n };\n }\n\n await Promise.all(\n Object.values(pkgExps).map(async (pkgExp) =>\n this.updatePackageExports(pkgExp.pkg, pkgExp.exps),\n ),\n );\n }\n\n protected isExcluded(fileName: string): boolean {\n return this.excludes.some((pattern) => pattern.test(fileName));\n }\n\n protected async persistBarrel(group: BarrelGroup): Promise<BarrelGroup> {\n const barrelPath = join(group.dirPath, \"index.ts\");\n // no files --> skip/delete index.ts\n if (group.files.length === 0) {\n await rm(barrelPath, { recursive: true, force: true });\n return group;\n }\n\n const exportLines: string[] = [];\n for (const file of group.files.sort()) {\n const filePath = join(group.dirPath, file);\n\n const expResult = fileExports(filePath);\n if (expResult.items.length === 0) continue;\n\n const exports = expResult.items.map((item) => item.name);\n const moduleRef = `./${basename(file, \".ts\")}.js`;\n\n if (expResult.hasDefault) {\n exportLines.push(`export * from \"${moduleRef}\";`);\n } else if (exports.length > 0) {\n exportLines.push(\n `export { ${exports.join(\", \")} } from \"${moduleRef}\";`,\n );\n }\n }\n\n let content = `${this.fileHeader}${exportLines.length > 0 ? exportLines.join(\"\\n\") + \"\\n\" : \"\"}`;\n content = await formatCode(content);\n await writeFile(barrelPath, content);\n return group;\n }\n\n // protected async extractExportsFromFile(\n // filePath: string,\n // ): Promise<{ exports: string[]; hasDefault: boolean }> {\n // try {\n // const content = await readFile(filePath, \"utf-8\");\n // const exports: Set<string> = new Set();\n // let hasDefault = false;\n\n // // Detect any default export\n // if (/export\\s+default\\b/.test(content)) hasDefault = true;\n\n // // Match named exports: export const|function|class Name\n // const namedExportPattern =\n // /export\\s+(?:const|let|var|function|class|interface|type|enum)\\s+([a-zA-Z_$][a-zA-Z0-9_$]*)/g;\n // let match;\n // while ((match = namedExportPattern.exec(content)) !== null) {\n // const name = match[1];\n // if (\n // !name.startsWith(\"_\") &&\n // !name.startsWith(\"//\") &&\n // !name.startsWith(\"/*\")\n // )\n // exports.add(name);\n // }\n\n // // Match export { a, b, c } and export { a, b, c } from '...'\n // const exportBracePattern = /export\\s*\\{\\s*([^}]+)\\s*\\}/g;\n // while ((match = exportBracePattern.exec(content)) !== null) {\n // const items = match[1].split(\",\");\n // for (const item of items) {\n // const trimmed = item.trim();\n // if (!trimmed) continue;\n // // Handle \"export { name as alias }\"\n // const parts = trimmed.split(/\\s+as\\s+/);\n // const name = parts[0].trim();\n // const alias = parts[1]?.trim();\n // // Skip default exports (e.g. \"export { Foo as default }\")\n // if (alias === \"default\") {\n // hasDefault = true;\n // continue;\n // }\n // if (name && name !== \"default\" && !name.startsWith(\"_\")) {\n // exports.add(name);\n // }\n // }\n // }\n\n // return { exports: Array.from(exports).sort(), hasDefault };\n // } catch {\n // return { exports: [], hasDefault: false };\n // }\n // }\n\n protected async updatePackageExports(\n pkg: Pkg,\n exports: Record<string, string>,\n ) {\n try {\n // const pkgName = relative(this.paths.workspacesDir, packageDir);\n // // const pkgs = await workspace().loadPackages();\n\n logInfo(`📦 updating ${pkg.repoDirPath} package.json ...`);\n // const pkg = await readPackageJsonThrow(packageJsonPath);\n if (!this.hasExportsChanged(exports, pkg.content.exports)) {\n logInfo(`🧹 No changes in ${pkg.repoDirPath}, nothing to do`);\n return;\n }\n pkg.content.exports = { ...exports };\n await pkg.write();\n logSuccess(`✅ ${pkg.repoDirPath} update successful`);\n } catch (error) {\n logInfo(error);\n }\n }\n\n protected hasExportsChanged(\n a: Record<string, string> | undefined,\n b: Record<string, string> | undefined,\n ): boolean {\n if (!a) a = {};\n if (!b) b = {};\n\n if (Object.keys(a).length !== Object.keys(b).length) return true;\n if (!a && !b) return false;\n if (!a || !b) return true;\n\n for (const entryA of Object.entries(a)) {\n if (b[entryA[0]] !== entryA[1]) return true;\n }\n return false;\n }\n\n protected extractExports(result: BarrelResult): Record<string, string> {\n const record: Record<string, string> = {};\n for (const barrelDir of result.barrelDirs) {\n const ex = relative(result.pkg.srcPath, barrelDir);\n record[`./${ex}`] = `./dist/${ex}/index.js`;\n }\n record[\"./package.json\"] = \"./package.json\";\n return record;\n }\n}\n"]}
|
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
import ts from "typescript";
|
|
2
|
+
import { SourceFile } from "../types/types.code.js";
|
|
3
|
+
export declare const createSourceFiles: (filePaths: string[]) => SourceFile[];
|
|
4
|
+
export declare const declarationKindName: (d: ts.Declaration) => string;
|
|
5
|
+
export declare const guessKindFromFlags: (sym: ts.Symbol) => string;
|
|
6
|
+
//# sourceMappingURL=code.common.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"code.common.d.ts","sourceRoot":"","sources":["../../src/code/code.common.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,MAAM,YAAY,CAAC;AAC5B,OAAO,EAAE,UAAU,EAAE,MAAM,wBAAwB,CAAC;AAEpD,eAAO,MAAM,iBAAiB,GAAI,WAAW,MAAM,EAAE,KAAG,UAAU,EAgBjE,CAAC;AAEF,eAAO,MAAM,mBAAmB,GAAI,GAAG,EAAE,CAAC,WAAW,WACjB,CAAC;AAErC,eAAO,MAAM,kBAAkB,GAAI,KAAK,EAAE,CAAC,MAAM,KAAG,MAYnD,CAAC"}
|
|
@@ -0,0 +1,40 @@
|
|
|
1
|
+
import ts from "typescript";
|
|
2
|
+
export const createSourceFiles = (filePaths) => {
|
|
3
|
+
const program = ts.createProgram(filePaths, {
|
|
4
|
+
target: ts.ScriptTarget.ES2023,
|
|
5
|
+
module: ts.ModuleKind.Node20,
|
|
6
|
+
strict: true,
|
|
7
|
+
});
|
|
8
|
+
const checker = program.getTypeChecker();
|
|
9
|
+
const results = [];
|
|
10
|
+
for (const filePath of filePaths) {
|
|
11
|
+
const sourceFile = program.getSourceFile(filePath);
|
|
12
|
+
if (!sourceFile)
|
|
13
|
+
continue;
|
|
14
|
+
results.push({ sourceFile, filePath, checker });
|
|
15
|
+
}
|
|
16
|
+
return results;
|
|
17
|
+
};
|
|
18
|
+
export const declarationKindName = (d) => ts.SyntaxKind[d.kind] ?? "Unknown";
|
|
19
|
+
export const guessKindFromFlags = (sym) => {
|
|
20
|
+
// Not perfect, but good enough for reporting.
|
|
21
|
+
const f = sym.getFlags();
|
|
22
|
+
if (f & ts.SymbolFlags.Function)
|
|
23
|
+
return "function";
|
|
24
|
+
if (f & ts.SymbolFlags.Class)
|
|
25
|
+
return "class";
|
|
26
|
+
if (f & ts.SymbolFlags.Enum)
|
|
27
|
+
return "enum";
|
|
28
|
+
if (f & ts.SymbolFlags.ValueModule)
|
|
29
|
+
return "namespace";
|
|
30
|
+
if (f & ts.SymbolFlags.TypeAlias)
|
|
31
|
+
return "type";
|
|
32
|
+
if (f & ts.SymbolFlags.Interface)
|
|
33
|
+
return "interface";
|
|
34
|
+
if (f & ts.SymbolFlags.Variable)
|
|
35
|
+
return "variable";
|
|
36
|
+
if (f & ts.SymbolFlags.Alias)
|
|
37
|
+
return "alias";
|
|
38
|
+
return "unknown";
|
|
39
|
+
};
|
|
40
|
+
//# sourceMappingURL=code.common.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"code.common.js","sourceRoot":"","sources":["../../src/code/code.common.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,MAAM,YAAY,CAAC;AAG5B,MAAM,CAAC,MAAM,iBAAiB,GAAG,CAAC,SAAmB,EAAgB,EAAE;IACrE,MAAM,OAAO,GAAG,EAAE,CAAC,aAAa,CAAC,SAAS,EAAE;QAC1C,MAAM,EAAE,EAAE,CAAC,YAAY,CAA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,IAAI,CAAC,GAAG,EAAE,CAAC,WAAW,CAAC,QAAQ;QAAE,OAAO,UAAU,CAAC;IACnD,IAAI,CAAC,GAAG,EAAE,CAAC,WAAW,CAAC,KAAK;QAAE,OAAO,OAAO,CAAC;IAC7C,OAAO,SAAS,CAAC;AACnB,CAAC,CAAC","sourcesContent":["import ts from \"typescript\";\nimport { SourceFile } from \"../types/types.code.js\";\n\nexport const createSourceFiles = (filePaths: string[]): SourceFile[] => {\n const program = ts.createProgram(filePaths, {\n target: ts.ScriptTarget.ES2023,\n module: ts.ModuleKind.Node20,\n strict: true,\n });\n const checker = program.getTypeChecker();\n const results: SourceFile[] = [];\n\n for (const filePath of filePaths) {\n const sourceFile = program.getSourceFile(filePath);\n if (!sourceFile) continue;\n results.push({ sourceFile, filePath, checker });\n }\n\n return results;\n};\n\nexport const declarationKindName = (d: ts.Declaration) =>\n ts.SyntaxKind[d.kind] ?? \"Unknown\";\n\nexport const guessKindFromFlags = (sym: ts.Symbol): string => {\n // Not perfect, but good enough for reporting.\n const f = sym.getFlags();\n if (f & ts.SymbolFlags.Function) return \"function\";\n if (f & ts.SymbolFlags.Class) return \"class\";\n if (f & ts.SymbolFlags.Enum) return \"enum\";\n if (f & ts.SymbolFlags.ValueModule) return \"namespace\";\n if (f & ts.SymbolFlags.TypeAlias) return \"type\";\n if (f & ts.SymbolFlags.Interface) return \"interface\";\n if (f & ts.SymbolFlags.Variable) return \"variable\";\n if (f & ts.SymbolFlags.Alias) return \"alias\";\n return \"unknown\";\n};\n"]}
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
import { SourceExport } from "../types/types.code.js";
|
|
2
|
+
export declare const fileExports: (filePath: string, opts?: {
|
|
3
|
+
includeTypeOnly?: boolean;
|
|
4
|
+
includeReExports?: boolean;
|
|
5
|
+
includeDefault?: boolean;
|
|
6
|
+
includePrivate?: boolean;
|
|
7
|
+
}) => SourceExport;
|
|
8
|
+
//# sourceMappingURL=code.exports.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"code.exports.d.ts","sourceRoot":"","sources":["../../src/code/code.exports.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,YAAY,EAAE,MAAM,wBAAwB,CAAC;AAQtD,eAAO,MAAM,WAAW,GACtB,UAAU,MAAM,EAChB,OAAO;IACL,eAAe,CAAC,EAAE,OAAO,CAAC;IAC1B,gBAAgB,CAAC,EAAE,OAAO,CAAC;IAC3B,cAAc,CAAC,EAAE,OAAO,CAAC;IACzB,cAAc,CAAC,EAAE,OAAO,CAAC;CAC1B,KACA,YAyEF,CAAC"}
|
|
@@ -0,0 +1,70 @@
|
|
|
1
|
+
import ts from "typescript";
|
|
2
|
+
import { resolve } from "node:path";
|
|
3
|
+
import { createSourceFiles, declarationKindName, guessKindFromFlags, } from "./code.common.js";
|
|
4
|
+
export const fileExports = (filePath, opts) => {
|
|
5
|
+
const includeTypeOnly = opts?.includeTypeOnly ?? true;
|
|
6
|
+
const includeReExports = opts?.includeReExports ?? true;
|
|
7
|
+
const abs = resolve(filePath);
|
|
8
|
+
const files = createSourceFiles([filePath]);
|
|
9
|
+
if (files.length === 0)
|
|
10
|
+
throw new Error(`Could not load source file: ${abs}`);
|
|
11
|
+
const { checker, sourceFile } = files[0];
|
|
12
|
+
const result = {
|
|
13
|
+
items: [],
|
|
14
|
+
hasDefault: false,
|
|
15
|
+
};
|
|
16
|
+
const moduleSymbol = checker.getSymbolAtLocation(sourceFile);
|
|
17
|
+
if (!moduleSymbol)
|
|
18
|
+
return result;
|
|
19
|
+
// This gives the "export surface" of the module (including re-exports).
|
|
20
|
+
const exports = checker.getExportsOfModule(moduleSymbol);
|
|
21
|
+
for (const sym of exports) {
|
|
22
|
+
const name = sym.getName();
|
|
23
|
+
if (name === "default") {
|
|
24
|
+
result.hasDefault = true;
|
|
25
|
+
if (!opts?.includeDefault)
|
|
26
|
+
continue;
|
|
27
|
+
}
|
|
28
|
+
else if (name.startsWith("_")) {
|
|
29
|
+
if (!opts?.includePrivate)
|
|
30
|
+
continue;
|
|
31
|
+
}
|
|
32
|
+
// Determine if it's type-only (TypeScript 5.x provides isTypeOnlySymbol).
|
|
33
|
+
// Fallback: approximate using flags.
|
|
34
|
+
const isTypeOnly =
|
|
35
|
+
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
36
|
+
typeof checker.isTypeOnlySymbol === "function"
|
|
37
|
+
? // eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
38
|
+
checker.isTypeOnlySymbol(sym)
|
|
39
|
+
: !!(sym.getFlags() &
|
|
40
|
+
(ts.SymbolFlags.Type |
|
|
41
|
+
ts.SymbolFlags.Interface |
|
|
42
|
+
ts.SymbolFlags.TypeAlias));
|
|
43
|
+
if (!includeTypeOnly && isTypeOnly)
|
|
44
|
+
continue;
|
|
45
|
+
// Re-export detection: if symbol is an alias and resolves elsewhere
|
|
46
|
+
let isReExport = false;
|
|
47
|
+
let resolved = sym;
|
|
48
|
+
if (sym.getFlags() & ts.SymbolFlags.Alias) {
|
|
49
|
+
const aliased = checker.getAliasedSymbol(sym);
|
|
50
|
+
if (aliased && aliased !== sym) {
|
|
51
|
+
isReExport = true;
|
|
52
|
+
resolved = aliased;
|
|
53
|
+
}
|
|
54
|
+
}
|
|
55
|
+
if (!includeReExports && isReExport)
|
|
56
|
+
continue;
|
|
57
|
+
const decls = (resolved.getDeclarations() ?? []).map(declarationKindName);
|
|
58
|
+
result.items.push({
|
|
59
|
+
name,
|
|
60
|
+
kind: guessKindFromFlags(resolved),
|
|
61
|
+
isTypeOnly,
|
|
62
|
+
isReExport,
|
|
63
|
+
declarations: decls,
|
|
64
|
+
});
|
|
65
|
+
}
|
|
66
|
+
// stable-ish output
|
|
67
|
+
result.items.sort((a, b) => a.name.localeCompare(b.name));
|
|
68
|
+
return result;
|
|
69
|
+
};
|
|
70
|
+
//# sourceMappingURL=code.exports.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"code.exports.js","sourceRo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;YACV,UAAU;YACV,YAAY,EAAE,KAAK;SACpB,CAAC,CAAC;IACL,CAAC;IAED,oBAAoB;IACpB,MAAM,CAAC,KAAK,CAAC,IAAI,CAAC,CAAC,CAAC,EAAE,CAAC,EAAE,EAAE,CAAC,CAAC,CAAC,IAAI,CAAC,aAAa,CAAC,CAAC,CAAC,IAAI,CAAC,CAAC,CAAC;IAC1D,OAAO,MAAM,CAAC;AAChB,CAAC,CAAC","sourcesContent":["import ts from \"typescript\";\nimport { SourceExport } from \"../types/types.code.js\";\nimport { resolve } from \"node:path\";\nimport {\n createSourceFiles,\n declarationKindName,\n guessKindFromFlags,\n} from \"./code.common.js\";\n\nexport const fileExports = (\n filePath: string,\n opts?: {\n includeTypeOnly?: boolean;\n includeReExports?: boolean;\n includeDefault?: boolean;\n includePrivate?: boolean;\n },\n): SourceExport => {\n const includeTypeOnly = opts?.includeTypeOnly ?? true;\n const includeReExports = opts?.includeReExports ?? true;\n const abs = resolve(filePath);\n\n const files = createSourceFiles([filePath]);\n if (files.length === 0) throw new Error(`Could not load source file: ${abs}`);\n\n const { checker, sourceFile } = files[0];\n\n const result: SourceExport = {\n items: [],\n hasDefault: false,\n };\n\n const moduleSymbol = checker.getSymbolAtLocation(sourceFile);\n if (!moduleSymbol) return result;\n\n // This gives the \"export surface\" of the module (including re-exports).\n const exports = checker.getExportsOfModule(moduleSymbol);\n\n for (const sym of exports) {\n const name = sym.getName();\n if (name === \"default\") {\n result.hasDefault = true;\n if (!opts?.includeDefault) continue;\n } else if (name.startsWith(\"_\")) {\n if (!opts?.includePrivate) continue;\n }\n\n // Determine if it's type-only (TypeScript 5.x provides isTypeOnlySymbol).\n // Fallback: approximate using flags.\n const isTypeOnly =\n // eslint-disable-next-line @typescript-eslint/no-explicit-any\n typeof (checker as any).isTypeOnlySymbol === \"function\"\n ? // eslint-disable-next-line @typescript-eslint/no-explicit-any\n ((checker as any).isTypeOnlySymbol(sym) as boolean)\n : !!(\n sym.getFlags() &\n (ts.SymbolFlags.Type |\n ts.SymbolFlags.Interface |\n ts.SymbolFlags.TypeAlias)\n );\n\n if (!includeTypeOnly && isTypeOnly) continue;\n\n // Re-export detection: if symbol is an alias and resolves elsewhere\n let isReExport = false;\n let resolved = sym;\n if (sym.getFlags() & ts.SymbolFlags.Alias) {\n const aliased = checker.getAliasedSymbol(sym);\n if (aliased && aliased !== sym) {\n isReExport = true;\n resolved = aliased;\n }\n }\n\n if (!includeReExports && isReExport) continue;\n\n const decls = (resolved.getDeclarations() ?? []).map(declarationKindName);\n\n result.items.push({\n name,\n kind: guessKindFromFlags(resolved),\n isTypeOnly,\n isReExport,\n declarations: decls,\n });\n }\n\n // stable-ish output\n result.items.sort((a, b) => a.name.localeCompare(b.name));\n return result;\n};\n"]}
|
|
@@ -1,6 +1,4 @@
|
|
|
1
|
-
import { SourceFile } from "../types/types.code.js";
|
|
2
1
|
export declare const formatCode: (...lines: string[]) => Promise<string>;
|
|
3
2
|
export declare const formatJson: (...lines: string[]) => Promise<string>;
|
|
4
3
|
export declare const formatJsonStringify: (...lines: string[]) => Promise<string>;
|
|
5
|
-
|
|
6
|
-
//# sourceMappingURL=format.code.d.ts.map
|
|
4
|
+
//# sourceMappingURL=code.format.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"code.format.d.ts","sourceRoot":"","sources":["../../src/code/code.format.ts"],"names":[],"mappings":"AAEA,eAAO,MAAM,UAAU,GAAU,GAAG,OAAO,MAAM,EAAE,KAAG,OAAO,CAAC,MAAM,CAChB,CAAC;AAErD,eAAO,MAAM,UAAU,GAAU,GAAG,OAAO,MAAM,EAAE,KAAG,OAAO,CAAC,MAAM,CACtB,CAAC;AAE/C,eAAO,MAAM,mBAAmB,GAC9B,GAAG,OAAO,MAAM,EAAE,KACjB,OAAO,CAAC,MAAM,CAA2D,CAAC"}
|
|
@@ -0,0 +1,5 @@
|
|
|
1
|
+
import { format } from "prettier";
|
|
2
|
+
export const formatCode = async (...lines) => format(lines.join("\n"), { parser: "typescript" });
|
|
3
|
+
export const formatJson = async (...lines) => format(lines.join("\n"), { parser: "json" });
|
|
4
|
+
export const formatJsonStringify = async (...lines) => format(lines.join("\n"), { parser: "json-stringify" });
|
|
5
|
+
//# sourceMappingURL=code.format.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"code.format.js","sourceRoot":"","sources":["../../src/code/code.format.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,MAAM,EAAE,MAAM,UAAU,CAAC;AAElC,MAAM,CAAC,MAAM,UAAU,GAAG,KAAK,EAAE,GAAG,KAAe,EAAmB,EAAE,CACtE,MAAM,CAAC,KAAK,CAAC,IAAI,CAAC,IAAI,CAAC,EAAE,EAAE,MAAM,EAAE,YAAY,EAAE,CAAC,CAAC;AAErD,MAAM,CAAC,MAAM,UAAU,GAAG,KAAK,EAAE,GAAG,KAAe,EAAmB,EAAE,CACtE,MAAM,CAAC,KAAK,CAAC,IAAI,CAAC,IAAI,CAAC,EAAE,EAAE,MAAM,EAAE,MAAM,EAAE,CAAC,CAAC;AAE/C,MAAM,CAAC,MAAM,mBAAmB,GAAG,KAAK,EACtC,GAAG,KAAe,EACD,EAAE,CAAC,MAAM,CAAC,KAAK,CAAC,IAAI,CAAC,IAAI,CAAC,EAAE,EAAE,MAAM,EAAE,gBAAgB,EAAE,CAAC,CAAC","sourcesContent":["import { format } from \"prettier\";\n\nexport const formatCode = async (...lines: string[]): Promise<string> =>\n format(lines.join(\"\\n\"), { parser: \"typescript\" });\n\nexport const formatJson = async (...lines: string[]): Promise<string> =>\n format(lines.join(\"\\n\"), { parser: \"json\" });\n\nexport const formatJsonStringify = async (\n ...lines: string[]\n): Promise<string> => format(lines.join(\"\\n\"), { parser: \"json-stringify\" });\n"]}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/code/index.ts"],"names":[],"mappings":"AACA,cAAc,kBAAkB,CAAC;AACjC,cAAc,mBAAmB,CAAC;AAClC,cAAc,kBAAkB,CAAC"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/code/index.ts"],"names":[],"mappings":"AAAA,qDAAqD;AACrD,cAAc,kBAAkB,CAAC;AACjC,cAAc,mBAAmB,CAAC;AAClC,cAAc,kBAAkB,CAAC","sourcesContent":["// This file is auto-generated. Do not edit manually.\nexport * from \"./code.common.js\";\nexport * from \"./code.exports.js\";\nexport * from \"./code.format.js\";\n"]}
|
package/dist/pkg/pkg.fs.js
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import json5 from "json5";
|
|
2
2
|
import { readFile, writeFile } from "node:fs/promises";
|
|
3
3
|
import { join } from "node:path";
|
|
4
|
-
import { formatJsonStringify } from "../
|
|
4
|
+
import { formatJsonStringify } from "../code/code.format.js";
|
|
5
5
|
import { readFileSync } from "node:fs";
|
|
6
6
|
export const readPackageJson = async (dirOrFilepath) => json5.parse(await readFile(ensurePkgJsonPath(dirOrFilepath), "utf8"));
|
|
7
7
|
export const readPackageJsonSync = (dirOrFilepath) => json5.parse(readFileSync(ensurePkgJsonPath(dirOrFilepath), "utf8"));
|
package/dist/pkg/pkg.fs.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"pkg.fs.js","sourceRoot":"","sources":["../../src/pkg/pkg.fs.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,MAAM,OAAO,CAAC;AAC1B,OAAO,EAAE,QAAQ,EAAE,SAAS,EAAE,MAAM,kBAAkB,CAAC;AAEvD,OAAO,EAAE,IAAI,EAAE,MAAM,WAAW,CAAC;AACjC,OAAO,EAAE,mBAAmB,EAAE,MAAM,
|
|
1
|
+
{"version":3,"file":"pkg.fs.js","sourceRoot":"","sources":["../../src/pkg/pkg.fs.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,MAAM,OAAO,CAAC;AAC1B,OAAO,EAAE,QAAQ,EAAE,SAAS,EAAE,MAAM,kBAAkB,CAAC;AAEvD,OAAO,EAAE,IAAI,EAAE,MAAM,WAAW,CAAC;AACjC,OAAO,EAAE,mBAAmB,EAAE,MAAM,wBAAwB,CAAC;AAC7D,OAAO,EAAE,YAAY,EAAE,MAAM,SAAS,CAAC;AAEvC,MAAM,CAAC,MAAM,eAAe,GAAG,KAAK,EAClC,aAAqB,EACC,EAAE,CACxB,KAAK,CAAC,KAAK,CAAC,MAAM,QAAQ,CAAC,iBAAiB,CAAC,aAAa,CAAC,EAAE,MAAM,CAAC,CAAC,CAAC;AAExE,MAAM,CAAC,MAAM,mBAAmB,GAAG,CAAC,aAAqB,EAAe,EAAE,CACxE,KAAK,CAAC,KAAK,CAAC,YAAY,CAAC,iBAAiB,CAAC,aAAa,CAAC,EAAE,MAAM,CAAC,CAAC,CAAC;AAEtE,MAAM,CAAC,MAAM,gBAAgB,GAAG,KAAK,EACnC,QAAgB,EAChB,OAAoB,EACL,EAAE,CACjB,SAAS,CAAC,QAAQ,EAAE,MAAM,mBAAmB,CAAC,KAAK,CAAC,SAAS,CAAC,OAAO,CAAC,CAAC,CAAC,CAAC;AAE3E,MAAM,CAAC,MAAM,iBAAiB,GAAG,CAAC,aAAqB,EAAU,EAAE,CACjE,aAAa,CAAC,QAAQ,CAAC,eAAe,CAAC;IACrC,CAAC,CAAC,aAAa;IACf,CAAC,CAAC,IAAI,CAAC,aAAa,EAAE,cAAc,CAAC,CAAC","sourcesContent":["import json5 from \"json5\";\nimport { readFile, writeFile } from \"node:fs/promises\";\nimport { PackageJson } from \"../types/types.package.js\";\nimport { join } from \"node:path\";\nimport { formatJsonStringify } from \"../code/code.format.js\";\nimport { readFileSync } from \"node:fs\";\n\nexport const readPackageJson = async (\n dirOrFilepath: string,\n): Promise<PackageJson> =>\n json5.parse(await readFile(ensurePkgJsonPath(dirOrFilepath), \"utf8\"));\n\nexport const readPackageJsonSync = (dirOrFilepath: string): PackageJson =>\n json5.parse(readFileSync(ensurePkgJsonPath(dirOrFilepath), \"utf8\"));\n\nexport const writePackageJson = async (\n jsonPath: string,\n content: PackageJson,\n): Promise<void> =>\n writeFile(jsonPath, await formatJsonStringify(json5.stringify(content)));\n\nexport const ensurePkgJsonPath = (dirOrFilepath: string): string =>\n dirOrFilepath.endsWith(\"/package.json\")\n ? dirOrFilepath\n : join(dirOrFilepath, \"package.json\");\n"]}
|
|
@@ -4,4 +4,15 @@ export interface SourceFile {
|
|
|
4
4
|
checker: ts.TypeChecker;
|
|
5
5
|
sourceFile: ts.SourceFile;
|
|
6
6
|
}
|
|
7
|
+
export interface SourceExportItem {
|
|
8
|
+
name: string;
|
|
9
|
+
kind: string;
|
|
10
|
+
isTypeOnly: boolean;
|
|
11
|
+
isReExport: boolean;
|
|
12
|
+
declarations: string[];
|
|
13
|
+
}
|
|
14
|
+
export interface SourceExport {
|
|
15
|
+
items: SourceExportItem[];
|
|
16
|
+
hasDefault: boolean;
|
|
17
|
+
}
|
|
7
18
|
//# sourceMappingURL=types.code.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"types.code.d.ts","sourceRoot":"","sources":["../../src/types/types.code.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,MAAM,YAAY,CAAC;AAE5B,MAAM,WAAW,UAAU;IACzB,QAAQ,EAAE,MAAM,CAAC;IACjB,OAAO,EAAE,EAAE,CAAC,WAAW,CAAC;IACxB,UAAU,EAAE,EAAE,CAAC,UAAU,CAAC;CAC3B"}
|
|
1
|
+
{"version":3,"file":"types.code.d.ts","sourceRoot":"","sources":["../../src/types/types.code.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,MAAM,YAAY,CAAC;AAE5B,MAAM,WAAW,UAAU;IACzB,QAAQ,EAAE,MAAM,CAAC;IACjB,OAAO,EAAE,EAAE,CAAC,WAAW,CAAC;IACxB,UAAU,EAAE,EAAE,CAAC,UAAU,CAAC;CAC3B;AAED,MAAM,WAAW,gBAAgB;IAC/B,IAAI,EAAE,MAAM,CAAC;IACb,IAAI,EAAE,MAAM,CAAC;IACb,UAAU,EAAE,OAAO,CAAC;IACpB,UAAU,EAAE,OAAO,CAAC;IACpB,YAAY,EAAE,MAAM,EAAE,CAAC;CACxB;AAED,MAAM,WAAW,YAAY;IAC3B,KAAK,EAAE,gBAAgB,EAAE,CAAC;IAC1B,UAAU,EAAE,OAAO,CAAC;CACrB"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"types.code.js","sourceRoot":"","sources":["../../src/types/types.code.ts"],"names":[],"mappings":"","sourcesContent":["import ts from \"typescript\";\n\nexport interface SourceFile {\n filePath: string;\n checker: ts.TypeChecker;\n sourceFile: ts.SourceFile;\n}\n"]}
|
|
1
|
+
{"version":3,"file":"types.code.js","sourceRoot":"","sources":["../../src/types/types.code.ts"],"names":[],"mappings":"","sourcesContent":["import ts from \"typescript\";\n\nexport interface SourceFile {\n filePath: string;\n checker: ts.TypeChecker;\n sourceFile: ts.SourceFile;\n}\n\nexport interface SourceExportItem {\n name: string; // export name (e.g. \"foo\", \"default\")\n kind: string; // human-ish kind (e.g. \"function\", \"class\", \"type\", \"namespace\", \"unknown\")\n isTypeOnly: boolean; // true if TS considers it type-only\n isReExport: boolean; // true if it comes from another module via export-from / export *\n declarations: string[]; // declaration kinds for debugging (e.g. [\"FunctionDeclaration\"])\n}\n\nexport interface SourceExport {\n items: SourceExportItem[];\n hasDefault: boolean;\n}\n"]}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@mxpicture/build-api",
|
|
3
|
-
"version": "0.2.
|
|
3
|
+
"version": "0.2.49",
|
|
4
4
|
"description": "Build utilities API",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"author": "MXPicture",
|
|
@@ -12,9 +12,9 @@
|
|
|
12
12
|
"exports": {
|
|
13
13
|
"./barrel": "./dist/barrel/index.js",
|
|
14
14
|
"./cleanup": "./dist/cleanup/index.js",
|
|
15
|
+
"./code": "./dist/code/index.js",
|
|
15
16
|
"./common": "./dist/common/index.js",
|
|
16
17
|
"./deps": "./dist/deps/index.js",
|
|
17
|
-
"./format": "./dist/format/index.js",
|
|
18
18
|
"./git": "./dist/git/index.js",
|
|
19
19
|
"./logger": "./dist/logger/index.js",
|
|
20
20
|
"./npmPublish": "./dist/npmPublish/index.js",
|
|
@@ -39,9 +39,6 @@
|
|
|
39
39
|
"publishConfig": {
|
|
40
40
|
"access": "public"
|
|
41
41
|
},
|
|
42
|
-
"devDependencies": {
|
|
43
|
-
"typescript": "^5.9.3"
|
|
44
|
-
},
|
|
45
42
|
"dependencies": {
|
|
46
43
|
"@mxpicture/dep-analyzer": "^0.1.0",
|
|
47
44
|
"@types/micromatch": "^4.0.10",
|
|
@@ -49,6 +46,7 @@
|
|
|
49
46
|
"micromatch": "^4.0.8",
|
|
50
47
|
"prettier": "^3.8.1",
|
|
51
48
|
"simple-git": "^3.32.3",
|
|
49
|
+
"typescript": "^5.9.3",
|
|
52
50
|
"yaml": "^2.8.2"
|
|
53
51
|
}
|
|
54
52
|
}
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"format.code.d.ts","sourceRoot":"","sources":["../../src/format/format.code.ts"],"names":[],"mappings":"AAEA,OAAO,EAAE,UAAU,EAAE,MAAM,wBAAwB,CAAC;AAEpD,eAAO,MAAM,UAAU,GAAU,GAAG,OAAO,MAAM,EAAE,KAAG,OAAO,CAAC,MAAM,CAChB,CAAC;AAErD,eAAO,MAAM,UAAU,GAAU,GAAG,OAAO,MAAM,EAAE,KAAG,OAAO,CAAC,MAAM,CACtB,CAAC;AAE/C,eAAO,MAAM,mBAAmB,GAC9B,GAAG,OAAO,MAAM,EAAE,KACjB,OAAO,CAAC,MAAM,CAA2D,CAAC;AAE7E,eAAO,MAAM,iBAAiB,GAAI,WAAW,MAAM,EAAE,KAAG,UAAU,EAgBjE,CAAC"}
|
|
@@ -1,22 +0,0 @@
|
|
|
1
|
-
import ts from "typescript";
|
|
2
|
-
import { format } from "prettier";
|
|
3
|
-
export const formatCode = async (...lines) => format(lines.join("\n"), { parser: "typescript" });
|
|
4
|
-
export const formatJson = async (...lines) => format(lines.join("\n"), { parser: "json" });
|
|
5
|
-
export const formatJsonStringify = async (...lines) => format(lines.join("\n"), { parser: "json-stringify" });
|
|
6
|
-
export const createSourceFiles = (filePaths) => {
|
|
7
|
-
const program = ts.createProgram(filePaths, {
|
|
8
|
-
target: ts.ScriptTarget.ES2023,
|
|
9
|
-
module: ts.ModuleKind.Node20,
|
|
10
|
-
strict: true,
|
|
11
|
-
});
|
|
12
|
-
const checker = program.getTypeChecker();
|
|
13
|
-
const results = [];
|
|
14
|
-
for (const filePath of filePaths) {
|
|
15
|
-
const sourceFile = program.getSourceFile(filePath);
|
|
16
|
-
if (!sourceFile)
|
|
17
|
-
continue;
|
|
18
|
-
results.push({ sourceFile, filePath, checker });
|
|
19
|
-
}
|
|
20
|
-
return results;
|
|
21
|
-
};
|
|
22
|
-
//# sourceMappingURL=format.code.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"format.code.js","sourceRoot":"","sources":["../../src/format/format.code.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,MAAM,YAAY,CAAC;AAC5B,OAAO,EAAE,MAAM,EAAE,MAAM,UAAU,CAAC;AAGlC,MAAM,CAAC,MAAM,UAAU,GAAG,KAAK,EAAE,GAAG,KAAe,EAAmB,EAAE,CACtE,MAAM,CAAC,KAAK,CAAC,IAAI,CAAC,IAAI,CAAC,EAAE,EAAE,MAAM,EAAE,YAAY,EAAE,CAAC,CAAC;AAErD,MAAM,CAAC,MAAM,UAAU,GAAG,KAAK,EAAE,GAAG,KAAe,EAAmB,EAAE,CACtE,MAAM,CAAC,KAAK,CAAC,IAAI,CAAC,IAAI,CAAC,EAAE,EAAE,MAAM,EAAE,MAAM,EAAE,CAAC,CAAC;AAE/C,MAAM,CAAC,MAAM,mBAAmB,GAAG,KAAK,EACtC,GAAG,KAAe,EACD,EAAE,CAAC,MAAM,CAAC,KAAK,CAAC,IAAI,CAAC,IAAI,CAAC,EAAE,EAAE,MAAM,EAAE,gBAAgB,EAAE,CAAC,CAAC;AAE7E,MAAM,CAAC,MAAM,iBAAiB,GAAG,CAAC,SAAmB,EAAgB,EAAE;IACrE,MAAM,OAAO,GAAG,EAAE,CAAC,aAAa,CAAC,SAAS,EAAE;QAC1C,MAAM,EAAE,EAAE,CAAC,YAAY,CAAC,MAAM;QAC9B,MAAM,EAAE,EAAE,CAAC,UAAU,CAAC,MAAM;QAC5B,MAAM,EAAE,IAAI;KACb,CAAC,CAAC;IACH,MAAM,OAAO,GAAG,OAAO,CAAC,cAAc,EAAE,CAAC;IACzC,MAAM,OAAO,GAAiB,EAAE,CAAC;IAEjC,KAAK,MAAM,QAAQ,IAAI,SAAS,EAAE,CAAC;QACjC,MAAM,UAAU,GAAG,OAAO,CAAC,aAAa,CAAC,QAAQ,CAAC,CAAC;QACnD,IAAI,CAAC,UAAU;YAAE,SAAS;QAC1B,OAAO,CAAC,IAAI,CAAC,EAAE,UAAU,EAAE,QAAQ,EAAE,OAAO,EAAE,CAAC,CAAC;IAClD,CAAC;IAED,OAAO,OAAO,CAAC;AACjB,CAAC,CAAC","sourcesContent":["import ts from \"typescript\";\nimport { format } from \"prettier\";\nimport { SourceFile } from \"../types/types.code.js\";\n\nexport const formatCode = async (...lines: string[]): Promise<string> =>\n format(lines.join(\"\\n\"), { parser: \"typescript\" });\n\nexport const formatJson = async (...lines: string[]): Promise<string> =>\n format(lines.join(\"\\n\"), { parser: \"json\" });\n\nexport const formatJsonStringify = async (\n ...lines: string[]\n): Promise<string> => format(lines.join(\"\\n\"), { parser: \"json-stringify\" });\n\nexport const createSourceFiles = (filePaths: string[]): SourceFile[] => {\n const program = ts.createProgram(filePaths, {\n target: ts.ScriptTarget.ES2023,\n module: ts.ModuleKind.Node20,\n strict: true,\n });\n const checker = program.getTypeChecker();\n const results: SourceFile[] = [];\n\n for (const filePath of filePaths) {\n const sourceFile = program.getSourceFile(filePath);\n if (!sourceFile) continue;\n results.push({ sourceFile, filePath, checker });\n }\n\n return results;\n};\n"]}
|
package/dist/format/index.d.ts
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/format/index.ts"],"names":[],"mappings":"AACA,cAAc,kBAAkB,CAAC"}
|
package/dist/format/index.js
DELETED
package/dist/format/index.js.map
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/format/index.ts"],"names":[],"mappings":"AAAA,qDAAqD;AACrD,cAAc,kBAAkB,CAAC","sourcesContent":["// This file is auto-generated. Do not edit manually.\nexport * from \"./format.code.js\";\n"]}
|