stitchkit 0.136.1 → 0.136.2
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/CHANGELOG.md +7 -0
- package/dist/entrypoints/files/packaging.js +72 -36
- package/dist/files/client-declarations.d.ts +11 -3
- package/dist/files/client-declarations.d.ts.map +1 -1
- package/dist/files/client-package.d.ts.map +1 -1
- package/llms/process.2.txt +2 -3
- package/llms-full.txt +2 -3
- package/package.json +1 -1
package/CHANGELOG.md
CHANGED
|
@@ -15,6 +15,13 @@ additive**; the first breaking change landed in 0.10.0. Grep the file for
|
|
|
15
15
|
|
|
16
16
|
## [Unreleased]
|
|
17
17
|
|
|
18
|
+
## [0.136.2] - 2026-12-02
|
|
19
|
+
|
|
20
|
+
### Fixed
|
|
21
|
+
|
|
22
|
+
- `stitchkit/files/packaging` — `buildClientPackage` writes its temporary declaration tsconfig inside its temporary build directory instead of beside the project's `tsconfig.json`, so no `.client-package-*.tsconfig.json` file flickers as untracked in Git or editor source control during declaration emission or lingers after an abrupt abort. The temporary host nests symlinks (junctions on Windows) mirroring the project's ancestor `node_modules` chain so monorepo `@types/*` shadowing, non-`@types` `types` packages and explicit relative `typeRoots` keep resolving. → ADR 0343
|
|
23
|
+
**Affects:** `stitchkit/files/packaging` buildClientPackage
|
|
24
|
+
|
|
18
25
|
## [0.136.1] - 2026-12-01
|
|
19
26
|
|
|
20
27
|
### Fixed
|
|
@@ -157,13 +157,12 @@ async function buildClientArtifact(options) {
|
|
|
157
157
|
// src/files/client-package.ts
|
|
158
158
|
import { createHash as createHash3 } from "node:crypto";
|
|
159
159
|
import { existsSync as existsSync3 } from "node:fs";
|
|
160
|
-
import { copyFile as copyFile2, mkdir as
|
|
160
|
+
import { copyFile as copyFile2, mkdir as mkdir4, mkdtemp as mkdtemp3, readFile as readFile4, realpath as realpath4, rm as rm3, writeFile as writeFile5 } from "node:fs/promises";
|
|
161
161
|
import { tmpdir as tmpdir2 } from "node:os";
|
|
162
162
|
import { dirname as dirname5, extname, isAbsolute, join as join6, normalize, relative as relative3, resolve as resolve4 } from "node:path";
|
|
163
163
|
|
|
164
164
|
// src/files/client-declarations.ts
|
|
165
|
-
import {
|
|
166
|
-
import { rm as rm2, writeFile as writeFile2 } from "node:fs/promises";
|
|
165
|
+
import { mkdir as mkdir2, mkdtemp as mkdtemp2, realpath, rm as rm2, stat, symlink, writeFile as writeFile2 } from "node:fs/promises";
|
|
167
166
|
import { builtinModules } from "node:module";
|
|
168
167
|
import { dirname as dirname3, join as join3, relative } from "node:path";
|
|
169
168
|
|
|
@@ -412,34 +411,70 @@ function rewriteDeclarationTree(directory, rewrite) {
|
|
|
412
411
|
}
|
|
413
412
|
|
|
414
413
|
// src/files/client-declarations.ts
|
|
414
|
+
async function ancestorNodeModules(from) {
|
|
415
|
+
const nearestFirst = [];
|
|
416
|
+
const seen = new Set;
|
|
417
|
+
for (let directory = from;; directory = dirname3(directory)) {
|
|
418
|
+
const candidate = join3(directory, "node_modules");
|
|
419
|
+
const info = await stat(candidate).catch(() => {
|
|
420
|
+
return;
|
|
421
|
+
});
|
|
422
|
+
if (info?.isDirectory()) {
|
|
423
|
+
const target = await realpath(candidate).catch(() => {
|
|
424
|
+
return;
|
|
425
|
+
});
|
|
426
|
+
if (target !== undefined && !seen.has(target)) {
|
|
427
|
+
seen.add(target);
|
|
428
|
+
nearestFirst.push(target);
|
|
429
|
+
}
|
|
430
|
+
}
|
|
431
|
+
const parent = dirname3(directory);
|
|
432
|
+
if (parent === directory)
|
|
433
|
+
break;
|
|
434
|
+
}
|
|
435
|
+
return nearestFirst.reverse();
|
|
436
|
+
}
|
|
437
|
+
async function prepareDeclarationConfigHost(hostRoot, root) {
|
|
438
|
+
const targets = await ancestorNodeModules(root);
|
|
439
|
+
const linkType = process.platform === "win32" ? "junction" : "dir";
|
|
440
|
+
let current = hostRoot;
|
|
441
|
+
for (const [index, target] of targets.entries()) {
|
|
442
|
+
current = join3(current, `d${index}`);
|
|
443
|
+
await mkdir2(current);
|
|
444
|
+
await symlink(target, join3(current, "node_modules"), linkType);
|
|
445
|
+
}
|
|
446
|
+
return current;
|
|
447
|
+
}
|
|
415
448
|
async function emitClientDeclarations(input) {
|
|
416
449
|
const root = dirname3(input.tsconfig);
|
|
417
|
-
const
|
|
418
|
-
await writeFile2(generated, `${JSON.stringify({
|
|
419
|
-
extends: input.tsconfig,
|
|
420
|
-
compilerOptions: {
|
|
421
|
-
noEmit: false,
|
|
422
|
-
declaration: true,
|
|
423
|
-
emitDeclarationOnly: true,
|
|
424
|
-
declarationMap: false,
|
|
425
|
-
composite: false,
|
|
426
|
-
incremental: false,
|
|
427
|
-
rootDir: root,
|
|
428
|
-
outDir: input.outDir,
|
|
429
|
-
declarationDir: input.outDir
|
|
430
|
-
},
|
|
431
|
-
files: input.entries,
|
|
432
|
-
include: []
|
|
433
|
-
}, null, 2)}
|
|
434
|
-
`);
|
|
450
|
+
const hostRoot = await mkdtemp2(join3(input.work, "declarations-"));
|
|
435
451
|
try {
|
|
452
|
+
const configHost = await prepareDeclarationConfigHost(hostRoot, root);
|
|
453
|
+
const generated = join3(configHost, "tsconfig.json");
|
|
454
|
+
await writeFile2(generated, `${JSON.stringify({
|
|
455
|
+
extends: input.tsconfig,
|
|
456
|
+
compilerOptions: {
|
|
457
|
+
noEmit: false,
|
|
458
|
+
declaration: true,
|
|
459
|
+
emitDeclarationOnly: true,
|
|
460
|
+
declarationMap: false,
|
|
461
|
+
composite: false,
|
|
462
|
+
incremental: false,
|
|
463
|
+
rootDir: root,
|
|
464
|
+
outDir: input.outDir,
|
|
465
|
+
declarationDir: input.outDir
|
|
466
|
+
},
|
|
467
|
+
files: input.entries,
|
|
468
|
+
include: []
|
|
469
|
+
}, null, 2)}
|
|
470
|
+
`);
|
|
436
471
|
const [compiler, ...leading] = input.tsc;
|
|
437
472
|
const emitted = await runClientTool(input.step, compiler, [...leading, "-p", generated], root);
|
|
438
473
|
if (!emitted.ok) {
|
|
439
474
|
throw new ClientPackageError("declarations", `Client package declarations failed (exit ${emitted.exit}): ${emitted.output}`, { output: emitted.output });
|
|
440
475
|
}
|
|
441
476
|
} finally {
|
|
442
|
-
await rm2(
|
|
477
|
+
await rm2(hostRoot, { recursive: true, force: true });
|
|
443
478
|
}
|
|
444
479
|
}
|
|
445
480
|
function packageOf(specifier) {
|
|
@@ -481,7 +516,7 @@ function undeclared(file, specifier, name) {
|
|
|
481
516
|
|
|
482
517
|
// src/files/client-package-bundle.ts
|
|
483
518
|
import { realpathSync } from "node:fs";
|
|
484
|
-
import { realpath, writeFile as writeFile3 } from "node:fs/promises";
|
|
519
|
+
import { realpath as realpath2, writeFile as writeFile3 } from "node:fs/promises";
|
|
485
520
|
import { join as join4 } from "node:path";
|
|
486
521
|
var REPLACEMENT_LOADERS = {
|
|
487
522
|
".json": "json",
|
|
@@ -562,7 +597,7 @@ async function bundleClientPackage(input) {
|
|
|
562
597
|
const graph = await readClientBuildGraph(metafile, input.root);
|
|
563
598
|
const bundled = new Set;
|
|
564
599
|
for (const module of graph.modules.keys())
|
|
565
|
-
bundled.add(await
|
|
600
|
+
bundled.add(await realpath2(module).catch(() => module));
|
|
566
601
|
for (const module of input.replacements.keys()) {
|
|
567
602
|
if (bundled.has(realpathSync(module)))
|
|
568
603
|
continue;
|
|
@@ -574,7 +609,7 @@ async function bundleClientPackage(input) {
|
|
|
574
609
|
// src/files/client-package-proof.ts
|
|
575
610
|
import { createHash as createHash2 } from "node:crypto";
|
|
576
611
|
import { existsSync as existsSync2 } from "node:fs";
|
|
577
|
-
import { copyFile, mkdir as
|
|
612
|
+
import { copyFile, mkdir as mkdir3, readdir, readFile as readFile3, realpath as realpath3, writeFile as writeFile4 } from "node:fs/promises";
|
|
578
613
|
import { basename as basename2, dirname as dirname4, join as join5, relative as relative2 } from "node:path";
|
|
579
614
|
import { z as z3 } from "zod";
|
|
580
615
|
var InstalledManifestSchema = z3.object({ version: z3.string() });
|
|
@@ -582,7 +617,7 @@ async function resolveExternalPackage(from, name) {
|
|
|
582
617
|
for (let directory = from;; directory = dirname4(directory)) {
|
|
583
618
|
const candidate = join5(directory, "node_modules", name);
|
|
584
619
|
if (existsSync2(join5(candidate, "package.json"))) {
|
|
585
|
-
const real = await
|
|
620
|
+
const real = await realpath3(candidate);
|
|
586
621
|
const manifest = InstalledManifestSchema.parse(safeJsonParse(await readFile3(join5(real, "package.json"), "utf8")));
|
|
587
622
|
return { directory: real, version: manifest.version };
|
|
588
623
|
}
|
|
@@ -765,7 +800,7 @@ async function proveTypes(input) {
|
|
|
765
800
|
export { J${index} };
|
|
766
801
|
`;
|
|
767
802
|
})).join(""));
|
|
768
|
-
await
|
|
803
|
+
await mkdir3(join5(consumer, "typecheck"));
|
|
769
804
|
for (const [index, source] of (options.proof?.typecheck ?? []).entries()) {
|
|
770
805
|
const copy = `typecheck/${index}-${basename2(source)}`;
|
|
771
806
|
await copyFile(source, join5(consumer, copy));
|
|
@@ -895,7 +930,7 @@ function planReplacements(options) {
|
|
|
895
930
|
}
|
|
896
931
|
async function refuseBundledExternals(graph, externals) {
|
|
897
932
|
for (const module of graph.modules.keys()) {
|
|
898
|
-
const real = await
|
|
933
|
+
const real = await realpath4(module);
|
|
899
934
|
for (const [name, external] of externals) {
|
|
900
935
|
if (!real.startsWith(`${external.directory}/`))
|
|
901
936
|
continue;
|
|
@@ -916,7 +951,7 @@ async function stage(options, planned, graph, staged) {
|
|
|
916
951
|
for (const [subpath, path] of planned.exportedFiles)
|
|
917
952
|
exported[subpath] = path;
|
|
918
953
|
for (const [target, source] of planned.files) {
|
|
919
|
-
await
|
|
954
|
+
await mkdir4(dirname5(join6(staged, target)), { recursive: true });
|
|
920
955
|
await copyFile2(source, join6(staged, target));
|
|
921
956
|
}
|
|
922
957
|
const present = (record) => record !== undefined && Object.keys(record).length > 0 ? record : undefined;
|
|
@@ -939,7 +974,7 @@ async function buildClientPackage(options) {
|
|
|
939
974
|
signal: options.signal
|
|
940
975
|
};
|
|
941
976
|
const bun = options.executables?.bun ?? "bun";
|
|
942
|
-
const work = await
|
|
977
|
+
const work = await mkdtemp3(join6(tmpdir2(), "stitchkit-client-package-"));
|
|
943
978
|
await rm3(planned.tarball, { force: true });
|
|
944
979
|
try {
|
|
945
980
|
const externals = new Map;
|
|
@@ -970,6 +1005,7 @@ async function buildClientPackage(options) {
|
|
|
970
1005
|
tsc,
|
|
971
1006
|
tsconfig: planned.tsconfig,
|
|
972
1007
|
entries: [...planned.entries.values()],
|
|
1008
|
+
work,
|
|
973
1009
|
outDir: join6(staged, "dist")
|
|
974
1010
|
});
|
|
975
1011
|
normalizeClientDeclarations(join6(staged, "dist"), {
|
|
@@ -977,13 +1013,13 @@ async function buildClientPackage(options) {
|
|
|
977
1013
|
runtime: options.runtime ?? "node"
|
|
978
1014
|
});
|
|
979
1015
|
await stage(options, planned, graph, staged);
|
|
980
|
-
await
|
|
1016
|
+
await mkdir4(dirname5(planned.tarball), { recursive: true });
|
|
981
1017
|
const packed = await runClientTool(step, bun, ["pm", "pack", "--filename", planned.tarball, "--ignore-scripts", "--quiet"], staged);
|
|
982
1018
|
if (!packed.ok) {
|
|
983
1019
|
throw new ClientPackageError("install", `Client package pack failed (exit ${packed.exit}): ${packed.output}`, { output: packed.output });
|
|
984
1020
|
}
|
|
985
1021
|
const consumer = join6(work, "consumer");
|
|
986
|
-
await
|
|
1022
|
+
await mkdir4(consumer);
|
|
987
1023
|
const proven = await proveClientPackage({
|
|
988
1024
|
options,
|
|
989
1025
|
step,
|
|
@@ -1101,7 +1137,7 @@ import { z as z5 } from "zod";
|
|
|
1101
1137
|
// src/files/native-packaging-plugin.ts
|
|
1102
1138
|
import { existsSync as existsSync4, readFileSync as readFileSync2, realpathSync as realpathSync2 } from "node:fs";
|
|
1103
1139
|
import { basename as basename3, join as join7 } from "node:path";
|
|
1104
|
-
var
|
|
1140
|
+
var realpath5 = (path) => {
|
|
1105
1141
|
try {
|
|
1106
1142
|
return realpathSync2(path);
|
|
1107
1143
|
} catch {
|
|
@@ -1132,7 +1168,7 @@ function loaderInstallation(path, loaderName) {
|
|
|
1132
1168
|
function nativePlugin(owner, specifiers, embedded, companionEntry) {
|
|
1133
1169
|
const contents = nativeLoaderSource(specifiers, "static");
|
|
1134
1170
|
const external = new Set(Object.values(specifiers));
|
|
1135
|
-
const ownLoader =
|
|
1171
|
+
const ownLoader = realpath5(owner.loaderPath);
|
|
1136
1172
|
const loaderFile = basename3(owner.loaderName);
|
|
1137
1173
|
return {
|
|
1138
1174
|
name: "stitchkit-native-packaging",
|
|
@@ -1152,7 +1188,7 @@ function nativePlugin(owner, specifiers, embedded, companionEntry) {
|
|
|
1152
1188
|
return { contents, loader: "js" };
|
|
1153
1189
|
if (basename3(args.path) !== loaderFile)
|
|
1154
1190
|
return;
|
|
1155
|
-
if (
|
|
1191
|
+
if (realpath5(args.path) === ownLoader)
|
|
1156
1192
|
return { contents, loader: "js" };
|
|
1157
1193
|
const foreign = loaderInstallation(args.path, owner.loaderName);
|
|
1158
1194
|
if (!foreign)
|
|
@@ -1165,7 +1201,7 @@ function nativePlugin(owner, specifiers, embedded, companionEntry) {
|
|
|
1165
1201
|
return bytes ? { contents: bytes, loader: "napi" } : undefined;
|
|
1166
1202
|
});
|
|
1167
1203
|
if (companionEntry !== undefined)
|
|
1168
|
-
build.onResolve({ filter: /./ }, (args) => (args.importer === owner.loaderPath ||
|
|
1204
|
+
build.onResolve({ filter: /./ }, (args) => (args.importer === owner.loaderPath || realpath5(args.importer) === ownLoader) && external.has(args.path) ? { path: args.path, external: true } : undefined);
|
|
1169
1205
|
}
|
|
1170
1206
|
};
|
|
1171
1207
|
}
|
|
@@ -7,6 +7,8 @@ export interface ClientDeclarationsInput {
|
|
|
7
7
|
tsconfig: string;
|
|
8
8
|
/** Absolute paths of the entry modules. */
|
|
9
9
|
entries: readonly string[];
|
|
10
|
+
/** Temporary build directory that hosts the generated tsconfig outside the project tree. */
|
|
11
|
+
work: string;
|
|
10
12
|
/** Where the declaration tree is written, mirroring the tsconfig's directory. */
|
|
11
13
|
outDir: string;
|
|
12
14
|
}
|
|
@@ -14,9 +16,15 @@ export interface ClientDeclarationsInput {
|
|
|
14
16
|
* Emit declarations for the entries and what they import, and nothing else of
|
|
15
17
|
* the project: an unrelated file with a type error does not fail a client.
|
|
16
18
|
*
|
|
17
|
-
* The generated config
|
|
18
|
-
*
|
|
19
|
-
*
|
|
19
|
+
* The generated config lives inside `input.work`, never in the project tree.
|
|
20
|
+
* Because TypeScript resolves default `typeRoots` and non-`@types` `types`
|
|
21
|
+
* entries by walking `node_modules` upward from the config's directory, the
|
|
22
|
+
* config is nested under symlinks mirroring the project's ancestor
|
|
23
|
+
* `node_modules` chain while `extends` preserves every relative path declared
|
|
24
|
+
* in the project tsconfig. Known boundaries: `${configDir}` in non-overridden
|
|
25
|
+
* base-config options resolves to the temporary host directory, `preserveSymlinks`
|
|
26
|
+
* exposes symlinked type paths separately from imported modules, and an ambient
|
|
27
|
+
* `node_modules` above `input.work` remains reachable after the mirrored chain.
|
|
20
28
|
*/
|
|
21
29
|
export declare function emitClientDeclarations(input: ClientDeclarationsInput): Promise<void>;
|
|
22
30
|
/** What the declarations of a package may name besides their own files. */
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"client-declarations.d.ts","sourceRoot":"","sources":["../../src/files/client-declarations.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"client-declarations.d.ts","sourceRoot":"","sources":["../../src/files/client-declarations.ts"],"names":[],"mappings":"AAeA,OAAO,EAAE,KAAK,eAAe,EAAE,KAAK,iBAAiB,EAAiB,MAAM,gBAAgB,CAAC;AAQ7F,sDAAsD;AACtD,MAAM,WAAW,uBAAuB;IACtC,IAAI,EAAE,eAAe,CAAC;IACtB,GAAG,EAAE,iBAAiB,CAAC;IACvB,6CAA6C;IAC7C,QAAQ,EAAE,MAAM,CAAC;IACjB,2CAA2C;IAC3C,OAAO,EAAE,SAAS,MAAM,EAAE,CAAC;IAC3B,4FAA4F;IAC5F,IAAI,EAAE,MAAM,CAAC;IACb,iFAAiF;IACjF,MAAM,EAAE,MAAM,CAAC;CAChB;AA6CD;;;;;;;;;;;;;GAaG;AACH,wBAAsB,sBAAsB,CAAC,KAAK,EAAE,uBAAuB,GAAG,OAAO,CAAC,IAAI,CAAC,CA+C1F;AAQD,2EAA2E;AAC3E,MAAM,WAAW,kBAAkB;IACjC,6CAA6C;IAC7C,QAAQ,EAAE,WAAW,CAAC,MAAM,CAAC,CAAC;IAC9B,OAAO,EAAE,MAAM,GAAG,KAAK,GAAG,SAAS,CAAC;CACrC;AAOD;;;;;GAKG;AACH,wBAAgB,2BAA2B,CACzC,SAAS,EAAE,MAAM,EACjB,OAAO,EAAE,kBAAkB,GAC1B,IAAI,CAgCN"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"client-package.d.ts","sourceRoot":"","sources":["../../src/files/client-package.ts"],"names":[],"mappings":"AA8BA,OAAO,EAEL,KAAK,aAAa,EAGlB,KAAK,oBAAoB,EAC1B,MAAM,2BAA2B,CAAC;AAwNnC;;;;;;;;;;;;;GAaG;AACH,wBAAsB,kBAAkB,CACtC,OAAO,EAAE,oBAAoB,GAC5B,OAAO,CAAC,aAAa,CAAC,
|
|
1
|
+
{"version":3,"file":"client-package.d.ts","sourceRoot":"","sources":["../../src/files/client-package.ts"],"names":[],"mappings":"AA8BA,OAAO,EAEL,KAAK,aAAa,EAGlB,KAAK,oBAAoB,EAC1B,MAAM,2BAA2B,CAAC;AAwNnC;;;;;;;;;;;;;GAaG;AACH,wBAAsB,kBAAkB,CACtC,OAAO,EAAE,oBAAoB,GAC5B,OAAO,CAAC,aAAa,CAAC,CAmGxB"}
|
package/llms/process.2.txt
CHANGED
|
@@ -316,9 +316,8 @@ version is outside the range you declared.
|
|
|
316
316
|
Declarations are emitted with `tsconfig`, for the entries and what they import — nothing else of
|
|
317
317
|
the project is typechecked or shipped. The tsconfig's directory is the root: every entry lies
|
|
318
318
|
under it, and `dist/` in the archive mirrors it. A `typescript` package must be installed in the
|
|
319
|
-
project; the build runs its compiler with the runtime that runs the build (Bun or Node)
|
|
320
|
-
|
|
321
|
-
emit.
|
|
319
|
+
project; the build runs its compiler with the runtime that runs the build (Bun or Node) from a
|
|
320
|
+
generated tsconfig inside the build's temporary directory, leaving the project tree untouched.
|
|
322
321
|
|
|
323
322
|
The compiler leaves relative specifiers in a declaration as the source wrote them, and a
|
|
324
323
|
consumer under `moduleResolution: NodeNext` cannot resolve an extensionless one. The build
|
package/llms-full.txt
CHANGED
|
@@ -11757,9 +11757,8 @@ version is outside the range you declared.
|
|
|
11757
11757
|
Declarations are emitted with `tsconfig`, for the entries and what they import — nothing else of
|
|
11758
11758
|
the project is typechecked or shipped. The tsconfig's directory is the root: every entry lies
|
|
11759
11759
|
under it, and `dist/` in the archive mirrors it. A `typescript` package must be installed in the
|
|
11760
|
-
project; the build runs its compiler with the runtime that runs the build (Bun or Node)
|
|
11761
|
-
|
|
11762
|
-
emit.
|
|
11760
|
+
project; the build runs its compiler with the runtime that runs the build (Bun or Node) from a
|
|
11761
|
+
generated tsconfig inside the build's temporary directory, leaving the project tree untouched.
|
|
11763
11762
|
|
|
11764
11763
|
The compiler leaves relative specifiers in a declaration as the source wrote them, and a
|
|
11765
11764
|
consumer under `moduleResolution: NodeNext` cannot resolve an extensionless one. The build
|
package/package.json
CHANGED