@defold-typescript/types 0.41.0 → 0.42.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@defold-typescript/types",
3
- "version": "0.41.0",
3
+ "version": "0.42.0",
4
4
  "description": "TypeScript types for the Defold engine's Lua APIs.",
5
5
  "license": "MIT",
6
6
  "repository": {
@@ -64,6 +64,7 @@
64
64
  "fixtures/messages_doc.json",
65
65
  "fixtures/defold-*",
66
66
  "!fixtures/defold-*/engine-bindings",
67
+ "!fixtures/defold-*/annotations",
67
68
  "examples/translations.json",
68
69
  "!src/**/*.test.ts",
69
70
  "!scripts/**/*.test.ts",
@@ -82,7 +83,11 @@
82
83
  "!scripts/engine-binding-verdicts.ts",
83
84
  "!scripts/engine-binding-verdicts.json",
84
85
  "!scripts/lua-kind.ts",
85
- "!scripts/index-slot-scan.ts"
86
+ "!scripts/index-slot-scan.ts",
87
+ "!scripts/lua-annotations.ts",
88
+ "!scripts/lua-annotation-diff.ts",
89
+ "!scripts/lua-annotation-verdicts.ts",
90
+ "!scripts/lua-annotation-verdicts.json"
86
91
  ],
87
92
  "publishConfig": {
88
93
  "access": "public"
@@ -5,6 +5,8 @@ import { refDocCacheDir, resolveRefDoc } from "./doc-source";
5
5
  import {
6
6
  apiElementIdentity,
7
7
  EDITOR_MANIFEST,
8
+ type ExtractedFixture,
9
+ extractAnnotationFixtures,
8
10
  IGNORED_UPSTREAM,
9
11
  mergeApiDocs,
10
12
  readZip,
@@ -153,6 +155,9 @@ export interface ReleaseImportManifest {
153
155
  readonly unknownTypes: UnknownTypeBlocker[];
154
156
  readonly unmappedFunctionNamespaces: UnmappedNamespaceBlocker[];
155
157
  };
158
+ // The file names vendored under `annotations/`, which `loadAnnotations` holds
159
+ // the directory to. Empty before 1.13.2; absent from manifests written earlier.
160
+ readonly annotationFiles: readonly string[];
156
161
  readonly snapshots: Array<{
157
162
  readonly namespace: string;
158
163
  readonly fixture: string;
@@ -164,6 +169,8 @@ export interface ReleaseImportManifest {
164
169
  export type ReleaseImportPlan = Omit<ReleaseImportManifest, "snapshots"> & {
165
170
  readonly manifest: ReleaseImportManifest;
166
171
  readonly snapshots: ReleaseImportSnapshot[];
172
+ // The release's LuaLS annotation files, vendored verbatim. Empty before 1.13.2.
173
+ readonly annotations: ExtractedFixture[];
167
174
  };
168
175
 
169
176
  function isRecord(value: unknown): value is Record<string, unknown> {
@@ -259,7 +266,9 @@ function unknownTypeBlockers(
259
266
  return out;
260
267
  }
261
268
 
262
- function reportWithoutSnapshots(plan: Omit<ReleaseImportPlan, "manifest">): ReleaseImportManifest {
269
+ function reportWithoutSnapshots(
270
+ plan: Omit<ReleaseImportPlan, "manifest" | "annotations">,
271
+ ): ReleaseImportManifest {
263
272
  return {
264
273
  version: plan.version,
265
274
  baseline: plan.baseline,
@@ -269,6 +278,7 @@ function reportWithoutSnapshots(plan: Omit<ReleaseImportPlan, "manifest">): Rele
269
278
  moved: plan.moved,
270
279
  symbols: plan.symbols,
271
280
  blockers: plan.blockers,
281
+ annotationFiles: plan.annotationFiles,
272
282
  snapshots: plan.snapshots.map(({ namespace, fixture, sourceEntries, symbolSources }) => ({
273
283
  namespace,
274
284
  fixture,
@@ -417,6 +427,7 @@ export function buildReleaseImportPlan(input: {
417
427
  (a, b) => a.namespace.localeCompare(b.namespace) || a.symbol.localeCompare(b.symbol),
418
428
  );
419
429
  const ready = unknownTypes.length === 0 && unmappedFunctionNamespaces.length === 0;
430
+ const annotations = extractAnnotationFixtures(input.zip);
420
431
  const planBase = {
421
432
  version: input.version,
422
433
  baseline: input.baseline.id,
@@ -426,10 +437,11 @@ export function buildReleaseImportPlan(input: {
426
437
  moved,
427
438
  symbols,
428
439
  blockers: { unknownTypes, unmappedFunctionNamespaces },
440
+ annotationFiles: annotations.map((annotation) => annotation.namespace).sort(),
429
441
  snapshots,
430
442
  };
431
443
  const manifest = reportWithoutSnapshots(planBase);
432
- return { ...planBase, manifest };
444
+ return { ...planBase, manifest, annotations };
433
445
  }
434
446
 
435
447
  export function releaseImportReportJson(plan: ReleaseImportPlan): string {
@@ -448,6 +460,13 @@ export function applyReleaseImport(plan: ReleaseImportPlan, packageRoot = PACKAG
448
460
  writeFileSync(path, `${JSON.stringify(snapshot.doc, null, 2)}\n`);
449
461
  written.push(relative);
450
462
  }
463
+ for (const annotation of plan.annotations) {
464
+ const relative = `${relativeRoot}/${annotation.fixture}`;
465
+ const path = resolve(packageRoot, relative);
466
+ mkdirSync(dirname(path), { recursive: true });
467
+ writeFileSync(path, annotation.contents);
468
+ written.push(relative);
469
+ }
451
470
  // The prefixless builtins (`hash`, `pprint`, ...) are hand-vendored rather than
452
471
  // generated, so no upstream snapshot carries them. Seeding the canonical copy
453
472
  // here is what keeps a newly imported target from being born without a globals
@@ -1,6 +1,6 @@
1
- import { mkdtempSync, readFileSync, writeFileSync } from "node:fs";
1
+ import { mkdirSync, mkdtempSync, readFileSync, writeFileSync } from "node:fs";
2
2
  import { tmpdir } from "node:os";
3
- import { join, resolve } from "node:path";
3
+ import { dirname, join, resolve } from "node:path";
4
4
  import { type ApiModule, parseDefoldApiDoc } from "../src/api-doc";
5
5
  import { DEFOLD_TYPE_MAP } from "../src/core-types";
6
6
  import { parseScriptApi } from "../src/script-api";
@@ -404,6 +404,21 @@ export function extractFixtures(
404
404
  });
405
405
  }
406
406
 
407
+ // Since 1.13.2 the ref-doc zip ships LuaLS annotation files beside the JSON:
408
+ // `doc/<namespace>.lua` for the game runtime and `doc/<namespace>.editor_script`
409
+ // for the editor VM. They are vendored verbatim, never parsed at sync time.
410
+ const ANNOTATION_ENTRY = /^doc\/([^/]+\.(?:lua|editor_script))$/;
411
+
412
+ export function extractAnnotationFixtures(zip: ZipAccessor): ExtractedFixture[] {
413
+ const out: ExtractedFixture[] = [];
414
+ for (const zipEntry of [...zip.entries()].sort()) {
415
+ const file = ANNOTATION_ENTRY.exec(zipEntry)?.[1];
416
+ if (file === undefined) continue;
417
+ out.push({ namespace: file, fixture: `annotations/${file}`, contents: zip.read(zipEntry) });
418
+ }
419
+ return out;
420
+ }
421
+
407
422
  export type FixtureSyncStatus = "clean" | "drift" | "created";
408
423
 
409
424
  export interface FixtureSyncResult {
@@ -442,7 +457,8 @@ export function syncFixtures(zip: ZipAccessor, options: SyncOptions = {}): Fixtu
442
457
 
443
458
  // Compare/write a set of already-extracted fixtures against disk. Shared by
444
459
  // the core (zip) and extension (`.script_api`) sync paths so both honor the
445
- // identical created/clean/drift + format-on-write semantics.
460
+ // identical created/clean/drift + format-on-write semantics. A non-JSON fixture
461
+ // (a vendored annotation file) compares and writes byte-for-byte.
446
462
  export function syncExtractedFixtures(
447
463
  items: readonly ExtractedFixture[],
448
464
  options: Omit<SyncOptions, "manifest"> = {},
@@ -453,15 +469,21 @@ export function syncExtractedFixtures(
453
469
  const results: FixtureSyncResult[] = [];
454
470
  for (const item of items) {
455
471
  const path = resolve(root, item.fixture);
472
+ const json = item.fixture.endsWith(".json");
456
473
  const existing = readFixtureOrNull(path);
457
474
  const status: FixtureSyncStatus =
458
475
  existing === null
459
476
  ? "created"
460
- : canonicalJson(existing) === canonicalJson(item.contents)
477
+ : (
478
+ json
479
+ ? canonicalJson(existing) === canonicalJson(item.contents)
480
+ : existing === item.contents
481
+ )
461
482
  ? "clean"
462
483
  : "drift";
463
484
  if (!check && status !== "clean") {
464
- writeFileSync(path, format(item.contents));
485
+ mkdirSync(dirname(path), { recursive: true });
486
+ writeFileSync(path, json ? format(item.contents) : item.contents);
465
487
  }
466
488
  results.push({ namespace: item.namespace, fixture: item.fixture, status });
467
489
  }
@@ -641,11 +663,16 @@ if (import.meta.main) {
641
663
  const luaStdlibFixtures = extractFixtures(zip, LUA_STDLIB_MANIFEST);
642
664
  const editorFixtures = extractFixtures(zip, EDITOR_MANIFEST);
643
665
  const editorVmFixtures = extractFixtures(zip, EDITOR_VM_MANIFEST);
666
+ const annotationFixtures = extractAnnotationFixtures(zip);
644
667
  const results = [
645
668
  ...syncExtractedFixtures(coreFixtures, { check }),
646
669
  ...syncExtractedFixtures(luaStdlibFixtures, { check }),
647
670
  ...syncExtractedFixtures(editorFixtures, { check }),
648
671
  ...syncExtractedFixtures(editorVmFixtures, { check }),
672
+ ...syncExtractedFixtures(annotationFixtures, {
673
+ check,
674
+ fixturesRoot: resolve(PACKAGE_ROOT, `fixtures/defold-${DEFOLD_VERSION}`),
675
+ }),
649
676
  ];
650
677
  const syncedDocs = coreFixtures.map((f) => ({
651
678
  namespace: f.namespace,