@defold-typescript/library-types 0.20.8 → 0.21.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/api-doc/decore.json +1883 -0
- package/api-doc/druid.json +11818 -0
- package/generated/decore.d.ts +228 -0
- package/generated/druid.d.ts +2067 -0
- package/luals-targets.json +28 -0
- package/package.json +6 -3
- package/scripts/__snapshots__/emit-library-dts.test.ts.snap +22 -0
- package/scripts/__snapshots__/parse-luals.test.ts.snap +127 -1006
- package/scripts/emit-library-dts.ts +252 -0
- package/scripts/lower-api-doc.ts +115 -0
- package/scripts/luals-fidelity.ts +31 -10
- package/scripts/map-luals-types.ts +65 -0
- package/scripts/parse-luals.ts +60 -11
- package/scripts/sync-luals-types.ts +70 -7
|
@@ -1,7 +1,9 @@
|
|
|
1
1
|
import { mkdirSync, readdirSync, readFileSync, writeFileSync } from "node:fs";
|
|
2
2
|
import { dirname, join } from "node:path";
|
|
3
|
+
import { emitLibraryDeclarations } from "./emit-library-dts";
|
|
4
|
+
import { lowerLibraryModel } from "./lower-api-doc";
|
|
3
5
|
import { buildFidelityReport, type FidelityReport } from "./luals-fidelity";
|
|
4
|
-
import { mergeLibraryModels, parseLualsSource } from "./parse-luals";
|
|
6
|
+
import { type LibraryModel, mergeLibraryModels, parseLualsSource } from "./parse-luals";
|
|
5
7
|
|
|
6
8
|
/**
|
|
7
9
|
* The LuaLS ingestion front-end pins its source per-entry: a druid-style library
|
|
@@ -17,6 +19,9 @@ export interface LualsTarget {
|
|
|
17
19
|
namespace: string;
|
|
18
20
|
typeRenames: Record<string, string>;
|
|
19
21
|
ignore: string[];
|
|
22
|
+
// SPDX-style license id, surfaced by the docs-site provenance block. Optional
|
|
23
|
+
// in the config; the docs-site defaults an absent value to "".
|
|
24
|
+
license?: string;
|
|
20
25
|
}
|
|
21
26
|
|
|
22
27
|
export interface LualsTargets {
|
|
@@ -51,6 +56,7 @@ export function readLualsTargets(packageRoot: string): LualsTarget[] {
|
|
|
51
56
|
namespace: entry.namespace as string,
|
|
52
57
|
typeRenames: entry.typeRenames ?? {},
|
|
53
58
|
ignore: entry.ignore ?? [],
|
|
59
|
+
...(entry.license !== undefined ? { license: entry.license } : {}),
|
|
54
60
|
};
|
|
55
61
|
});
|
|
56
62
|
}
|
|
@@ -110,6 +116,9 @@ export type ListLualsTree = (repo: string, ref: string) => Promise<string[]>;
|
|
|
110
116
|
/** Fetch the raw text at a URL. Network seam — mirrors `sync-library-types.ts`. */
|
|
111
117
|
export type FetchText = (url: string) => Promise<string>;
|
|
112
118
|
|
|
119
|
+
/** Recursively enumerate a fixture directory's entries. Filesystem seam. */
|
|
120
|
+
export type ReadFixtureDir = (root: string) => string[];
|
|
121
|
+
|
|
113
122
|
/**
|
|
114
123
|
* A GitHub repo URL reduced to the bare `<owner>/<repo>` slug used to address
|
|
115
124
|
* raw content. Mirrors `repoSlug` in the ts-defold front-end.
|
|
@@ -151,17 +160,43 @@ export async function fetchLualsFixtures(
|
|
|
151
160
|
* the `--fidelity` CLI arm and its round-trip test drive the exact same path and
|
|
152
161
|
* agree byte-for-byte. Fixture files are read in sorted order for determinism,
|
|
153
162
|
* mirroring the parse snapshot.
|
|
163
|
+
*
|
|
164
|
+
* Interfaces and aliases come from the full merge — the module's own signatures
|
|
165
|
+
* reference cross-file classes — but module functions are scoped to the module's
|
|
166
|
+
* own `.lua` file (`moduleId` dotted to a path, e.g. `druid.druid` →
|
|
167
|
+
* `druid/druid.lua`). Merging every file's free functions would export every
|
|
168
|
+
* library file's functions from the one module. A `moduleId` with no matching
|
|
169
|
+
* fixture is a loud misconfiguration, not a silently empty surface.
|
|
154
170
|
*/
|
|
155
|
-
export function
|
|
171
|
+
export function buildTargetModel(
|
|
172
|
+
packageRoot: string,
|
|
173
|
+
target: LualsTarget,
|
|
174
|
+
seams: { readDir?: ReadFixtureDir } = {},
|
|
175
|
+
): LibraryModel {
|
|
176
|
+
const readDir = seams.readDir ?? ((r) => readdirSync(r, { recursive: true }).map(String));
|
|
156
177
|
const root = join(packageRoot, "fixtures/luals", target.namespace);
|
|
157
|
-
const files =
|
|
158
|
-
.map((entry) =>
|
|
178
|
+
const files = readDir(root)
|
|
179
|
+
.map((entry) => entry.replace(/\\/g, "/"))
|
|
159
180
|
.filter((entry) => entry.endsWith(".lua"))
|
|
160
181
|
.sort();
|
|
161
|
-
const
|
|
162
|
-
|
|
182
|
+
const ownFile = `${target.moduleId.replace(/\./g, "/")}.lua`;
|
|
183
|
+
if (!files.includes(ownFile)) {
|
|
184
|
+
throw new Error(
|
|
185
|
+
`buildTargetModel: module "${target.moduleId}" expects fixture "${ownFile}" under fixtures/luals/${target.namespace}, but it is not among the ${files.length} fixture .lua files.`,
|
|
186
|
+
);
|
|
187
|
+
}
|
|
188
|
+
const parsed = new Map<string, LibraryModel>();
|
|
189
|
+
for (const rel of files) parsed.set(rel, parseLualsSource(readFileSync(join(root, rel), "utf8")));
|
|
190
|
+
const merged = mergeLibraryModels([...parsed.values()]);
|
|
191
|
+
return { ...merged, moduleFunctions: parsed.get(ownFile)?.moduleFunctions ?? [] };
|
|
192
|
+
}
|
|
193
|
+
|
|
194
|
+
export function buildTargetFidelity(packageRoot: string, target: LualsTarget): FidelityReport {
|
|
195
|
+
return buildFidelityReport(
|
|
196
|
+
target.namespace,
|
|
197
|
+
buildTargetModel(packageRoot, target),
|
|
198
|
+
target.typeRenames,
|
|
163
199
|
);
|
|
164
|
-
return buildFidelityReport(target.namespace, model, target.typeRenames);
|
|
165
200
|
}
|
|
166
201
|
|
|
167
202
|
/**
|
|
@@ -237,4 +272,32 @@ if (import.meta.main) {
|
|
|
237
272
|
);
|
|
238
273
|
}
|
|
239
274
|
}
|
|
275
|
+
if (argv.includes("--emit")) {
|
|
276
|
+
const targets = readLualsTargets(root);
|
|
277
|
+
for (const target of targets) {
|
|
278
|
+
const model = buildTargetModel(root, target);
|
|
279
|
+
const declarations = emitLibraryDeclarations(model, {
|
|
280
|
+
moduleId: target.moduleId,
|
|
281
|
+
typeRenames: target.typeRenames,
|
|
282
|
+
});
|
|
283
|
+
const dest = join(root, "generated", `${target.namespace}.d.ts`);
|
|
284
|
+
mkdirSync(dirname(dest), { recursive: true });
|
|
285
|
+
writeFileSync(dest, declarations);
|
|
286
|
+
console.log(`emitted ${target.moduleId} -> generated/${target.namespace}.d.ts`);
|
|
287
|
+
}
|
|
288
|
+
}
|
|
289
|
+
if (argv.includes("--api-doc")) {
|
|
290
|
+
const targets = readLualsTargets(root);
|
|
291
|
+
for (const target of targets) {
|
|
292
|
+
const model = buildTargetModel(root, target);
|
|
293
|
+
const lowered = lowerLibraryModel(model, {
|
|
294
|
+
namespace: target.namespace,
|
|
295
|
+
typeRenames: target.typeRenames,
|
|
296
|
+
});
|
|
297
|
+
const dest = join(root, "api-doc", `${target.namespace}.json`);
|
|
298
|
+
mkdirSync(dirname(dest), { recursive: true });
|
|
299
|
+
writeFileSync(dest, `${JSON.stringify(lowered, null, 2)}\n`);
|
|
300
|
+
console.log(`lowered ${target.moduleId} -> api-doc/${target.namespace}.json`);
|
|
301
|
+
}
|
|
302
|
+
}
|
|
240
303
|
}
|