@ts-kizuna/cli 1.53.0 → 1.54.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/README.md CHANGED
@@ -1,6 +1,6 @@
1
1
  # @ts-kizuna/cli
2
2
 
3
- The `kizuna` CLI extracts the deprecations declared on your contract into `.kizuna/deprecations.json`, which the OpenAPI and client generators read at generate time.
3
+ `loadContract` imports a contract module from TypeScript source, no build step needed. The Swift and Kotlin generators use it to load the contract they generate from.
4
4
 
5
5
  ## Installation
6
6
 
@@ -10,12 +10,12 @@ pnpm add -D @ts-kizuna/cli
10
10
 
11
11
  ## Usage
12
12
 
13
- Prepend it to your dev and build scripts, so the generators always read current data:
13
+ ```ts
14
+ import { loadContract } from '@ts-kizuna/cli';
14
15
 
15
- ```sh
16
- kizuna deprecations src/contract/index.ts
16
+ const contract = await loadContract('./src/contract.ts');
17
17
  ```
18
18
 
19
19
  ## Documentation
20
20
 
21
- [Deprecations](https://ts-kizuna.com/docs/deprecations)
21
+ [ts-kizuna docs](https://ts-kizuna.com/docs)
package/dist/index.cjs CHANGED
@@ -1,8 +1,14 @@
1
1
  Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
2
- const require_lint_deprecations = require("./lint-deprecations-CmqMnr7K.cjs");
3
- exports.collectExportedSchemaDocs = require_lint_deprecations.collectExportedSchemaDocs;
4
- exports.createDeprecationMap = require_lint_deprecations.createDeprecationMap;
5
- exports.lintDeprecations = require_lint_deprecations.lintDeprecations;
6
- exports.loadContract = require_lint_deprecations.loadContract;
7
- exports.patchDeclarationDocs = require_lint_deprecations.patchDeclarationDocs;
8
- exports.writeKizunaDeprecations = require_lint_deprecations.writeKizunaDeprecations;
2
+ let jiti = require("jiti");
3
+ //#region src/load-contract.ts
4
+ /**
5
+ * Imports a contract module with jiti (so a `.ts` entry works without a build
6
+ * step) and returns the named export (default `contract`) or the default export.
7
+ * Returns undefined when neither is present.
8
+ */
9
+ const loadContract = async (contractPath, exportName = "contract") => {
10
+ const loaded = await (0, jiti.createJiti)(require("url").pathToFileURL(__filename).href, { interopDefault: true }).import(contractPath);
11
+ return loaded[exportName] ?? loaded.default;
12
+ };
13
+ //#endregion
14
+ exports.loadContract = loadContract;
package/dist/index.d.cts CHANGED
@@ -1,52 +1,5 @@
1
- import { DeprecationMap } from "@ts-kizuna/core/generator";
2
1
  import { Contract } from "@ts-kizuna/core";
3
2
 
4
- //#region src/schema-exports.d.ts
5
- /**
6
- * Maps every exported schema reachable from `entryPath` to the verbatim JSDoc
7
- * block on each of its fields, keyed by the exported const name (and, for
8
- * aliased re-exports, by the original declared name too).
9
- *
10
- * Walks the whole reachable graph, both the entry's re-exports and every file
11
- * it imports, so a schema defined in its own module and used via `import`
12
- * (rather than re-exported from the contract entry) is still collected.
13
- *
14
- * Used to patch emitted `.d.ts` files, where a `z.ZodObject<{...}>` shape is
15
- * keyed by the `declare const` name rather than a route or schema `meta.id`.
16
- */
17
- declare const collectExportedSchemaDocs: (entryPath: string) => Map<string, Map<string, string>>;
18
- //#endregion
19
- //#region src/dts-jsdoc.d.ts
20
- interface PatchResult {
21
- filesScanned: number;
22
- filesChanged: number;
23
- injections: number;
24
- }
25
- /**
26
- * Re-injects the JSDoc blocks from {@link collectExportedSchemaDocs} onto Zod
27
- * schema shape properties in the `.d.ts` files under `distDir`. Declaration emit
28
- * drops the comments an author wrote on schema fields; this restores them, full
29
- * descriptions, `@deprecated`, `@example`, etc., so they reach `z.infer`
30
- * consumers in other repos. Skips properties that already have JSDoc. Idempotent.
31
- */
32
- declare const patchDeclarationDocs: (distDir: string, exportFieldMap: Map<string, Map<string, string>>) => PatchResult;
33
- //#endregion
34
- //#region src/deprecation-parser.d.ts
35
- /**
36
- * Parses a contract's `@deprecated` JSDoc tags into a {@link DeprecationMap}.
37
- */
38
- declare const createDeprecationMap: (contractPath: string) => DeprecationMap;
39
- interface ContractSource {
40
- contract: Contract;
41
- contractPath: string;
42
- }
43
- /**
44
- * Parses each contract's `@deprecated` tags and writes them to
45
- * `<outDir>/deprecations.json`, keyed by contract fingerprint. Generators read
46
- * the entry matching the contract they generate. Returns the written path.
47
- */
48
- declare const writeKizunaDeprecations: (contracts: ContractSource[], outDir: string) => string;
49
- //#endregion
50
3
  //#region src/load-contract.d.ts
51
4
  /**
52
5
  * Imports a contract module with jiti (so a `.ts` entry works without a build
@@ -55,17 +8,4 @@ declare const writeKizunaDeprecations: (contracts: ContractSource[], outDir: str
55
8
  */
56
9
  declare const loadContract: (contractPath: string, exportName?: string) => Promise<Contract | undefined>;
57
10
  //#endregion
58
- //#region src/lint-deprecations.d.ts
59
- interface DeprecationLintWarning {
60
- file: string;
61
- line: number;
62
- message: string;
63
- }
64
- /**
65
- * Warns about JSDoc that would silently disable a deprecation, a misspelled
66
- * `@deprecated` tag, or more than one on the same comment. Scans the contract
67
- * source and the files it imports.
68
- */
69
- declare const lintDeprecations: (entryPath: string) => DeprecationLintWarning[];
70
- //#endregion
71
- export { type ContractSource, type DeprecationLintWarning, type PatchResult, collectExportedSchemaDocs, createDeprecationMap, lintDeprecations, loadContract, patchDeclarationDocs, writeKizunaDeprecations };
11
+ export { loadContract };
package/dist/index.d.mts CHANGED
@@ -1,53 +1,5 @@
1
- import ts from "typescript";
2
- import { DeprecationMap } from "@ts-kizuna/core/generator";
3
1
  import { Contract } from "@ts-kizuna/core";
4
2
 
5
- //#region src/schema-exports.d.ts
6
- /**
7
- * Maps every exported schema reachable from `entryPath` to the verbatim JSDoc
8
- * block on each of its fields, keyed by the exported const name (and, for
9
- * aliased re-exports, by the original declared name too).
10
- *
11
- * Walks the whole reachable graph, both the entry's re-exports and every file
12
- * it imports, so a schema defined in its own module and used via `import`
13
- * (rather than re-exported from the contract entry) is still collected.
14
- *
15
- * Used to patch emitted `.d.ts` files, where a `z.ZodObject<{...}>` shape is
16
- * keyed by the `declare const` name rather than a route or schema `meta.id`.
17
- */
18
- declare const collectExportedSchemaDocs: (entryPath: string) => Map<string, Map<string, string>>;
19
- //#endregion
20
- //#region src/dts-jsdoc.d.ts
21
- interface PatchResult {
22
- filesScanned: number;
23
- filesChanged: number;
24
- injections: number;
25
- }
26
- /**
27
- * Re-injects the JSDoc blocks from {@link collectExportedSchemaDocs} onto Zod
28
- * schema shape properties in the `.d.ts` files under `distDir`. Declaration emit
29
- * drops the comments an author wrote on schema fields; this restores them, full
30
- * descriptions, `@deprecated`, `@example`, etc., so they reach `z.infer`
31
- * consumers in other repos. Skips properties that already have JSDoc. Idempotent.
32
- */
33
- declare const patchDeclarationDocs: (distDir: string, exportFieldMap: Map<string, Map<string, string>>) => PatchResult;
34
- //#endregion
35
- //#region src/deprecation-parser.d.ts
36
- /**
37
- * Parses a contract's `@deprecated` JSDoc tags into a {@link DeprecationMap}.
38
- */
39
- declare const createDeprecationMap: (contractPath: string) => DeprecationMap;
40
- interface ContractSource {
41
- contract: Contract;
42
- contractPath: string;
43
- }
44
- /**
45
- * Parses each contract's `@deprecated` tags and writes them to
46
- * `<outDir>/deprecations.json`, keyed by contract fingerprint. Generators read
47
- * the entry matching the contract they generate. Returns the written path.
48
- */
49
- declare const writeKizunaDeprecations: (contracts: ContractSource[], outDir: string) => string;
50
- //#endregion
51
3
  //#region src/load-contract.d.ts
52
4
  /**
53
5
  * Imports a contract module with jiti (so a `.ts` entry works without a build
@@ -56,17 +8,4 @@ declare const writeKizunaDeprecations: (contracts: ContractSource[], outDir: str
56
8
  */
57
9
  declare const loadContract: (contractPath: string, exportName?: string) => Promise<Contract | undefined>;
58
10
  //#endregion
59
- //#region src/lint-deprecations.d.ts
60
- interface DeprecationLintWarning {
61
- file: string;
62
- line: number;
63
- message: string;
64
- }
65
- /**
66
- * Warns about JSDoc that would silently disable a deprecation, a misspelled
67
- * `@deprecated` tag, or more than one on the same comment. Scans the contract
68
- * source and the files it imports.
69
- */
70
- declare const lintDeprecations: (entryPath: string) => DeprecationLintWarning[];
71
- //#endregion
72
- export { type ContractSource, type DeprecationLintWarning, type PatchResult, collectExportedSchemaDocs, createDeprecationMap, lintDeprecations, loadContract, patchDeclarationDocs, writeKizunaDeprecations };
11
+ export { loadContract };
package/dist/index.mjs CHANGED
@@ -1,2 +1,13 @@
1
- import { a as patchDeclarationDocs, i as writeKizunaDeprecations, n as loadContract, o as collectExportedSchemaDocs, r as createDeprecationMap, t as lintDeprecations } from "./lint-deprecations-Dx9WRFQa.mjs";
2
- export { collectExportedSchemaDocs, createDeprecationMap, lintDeprecations, loadContract, patchDeclarationDocs, writeKizunaDeprecations };
1
+ import { createJiti } from "jiti";
2
+ //#region src/load-contract.ts
3
+ /**
4
+ * Imports a contract module with jiti (so a `.ts` entry works without a build
5
+ * step) and returns the named export (default `contract`) or the default export.
6
+ * Returns undefined when neither is present.
7
+ */
8
+ const loadContract = async (contractPath, exportName = "contract") => {
9
+ const loaded = await createJiti(import.meta.url, { interopDefault: true }).import(contractPath);
10
+ return loaded[exportName] ?? loaded.default;
11
+ };
12
+ //#endregion
13
+ export { loadContract };
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@ts-kizuna/cli",
3
- "version": "1.53.0",
4
- "description": "The kizuna CLI, plus the contract loading its client generators share",
3
+ "version": "1.54.0",
4
+ "description": "The contract loader the Swift and Kotlin client generators share",
5
5
  "keywords": [
6
6
  "ts-kizuna",
7
7
  "typescript",
@@ -11,9 +11,7 @@
11
11
  "type-safe",
12
12
  "rest",
13
13
  "api",
14
- "cli",
15
- "codegen",
16
- "deprecations"
14
+ "codegen"
17
15
  ],
18
16
  "license": "MIT",
19
17
  "homepage": "https://ts-kizuna.com/docs",
@@ -43,9 +41,6 @@
43
41
  }
44
42
  }
45
43
  },
46
- "bin": {
47
- "kizuna": "./dist/cli.mjs"
48
- },
49
44
  "kizuna": {
50
45
  "entries": {
51
46
  ".": "server"
@@ -58,21 +53,20 @@
58
53
  "access": "public"
59
54
  },
60
55
  "dependencies": {
61
- "jiti": "^2.7.0",
62
- "typescript": "^6.0.3"
56
+ "jiti": "^2.7.0"
63
57
  },
64
58
  "peerDependencies": {
65
59
  "zod": "^4.0.0",
66
- "@ts-kizuna/core": "1.53.0"
60
+ "@ts-kizuna/core": "1.54.0"
67
61
  },
68
62
  "devDependencies": {
69
63
  "@types/node": "^24",
70
64
  "tsdown": "^0.21.0",
71
65
  "zod": "^4.0.0",
72
- "@ts-kizuna/core": "1.53.0"
66
+ "@ts-kizuna/core": "1.54.0"
73
67
  },
74
68
  "scripts": {
75
- "build": "tsdown src/index.ts src/cli.ts --format esm,cjs --dts --clean --external @ts-kizuna/core --external zod --external typescript --external jiti",
69
+ "build": "tsdown src/index.ts --format esm,cjs --dts --clean --external @ts-kizuna/core --external zod --external jiti",
76
70
  "typecheck": "tsc --noEmit"
77
71
  }
78
72
  }
package/dist/cli.cjs DELETED
@@ -1,61 +0,0 @@
1
- #!/usr/bin/env node
2
- const require_lint_deprecations = require("./lint-deprecations-CmqMnr7K.cjs");
3
- let node_path = require("node:path");
4
- let node_util = require("node:util");
5
- //#region src/cli.ts
6
- const usage = `Usage: kizuna deprecations <contract.ts...> [--output <dir>] [--export <name>] [--dts <dir>]
7
-
8
- Writes deprecations.json into .kizuna, keyed per contract. Generators read it at
9
- generate time and apply the deprecations.
10
-
11
- A contract path may be suffixed with the export to read: src/workspace.ts:workspaceContract.
12
-
13
- Optional:
14
- --output <dir> Output directory. Default: .kizuna
15
- --export <name> Default export name when none is suffixed. Default: contract
16
- --dts <dir> Re-inject schema-field JSDoc into emitted .d.ts files in <dir>,
17
- so docs survive publishing and reach z.infer consumers.
18
- `;
19
- const die = (message, code = 1) => {
20
- process.stderr.write(`${message}\n`);
21
- process.exit(code);
22
- };
23
- const main = async () => {
24
- const argv = process.argv.slice(2);
25
- if (argv[0] !== "deprecations") die(usage, argv[0] ? 1 : 0);
26
- const { values, positionals } = (0, node_util.parseArgs)({
27
- args: argv.slice(1),
28
- options: {
29
- output: { type: "string" },
30
- export: { type: "string" },
31
- dts: { type: "string" }
32
- },
33
- allowPositionals: true,
34
- strict: true
35
- });
36
- if (positionals.length === 0) die("Missing contract path(s)\n\n" + usage);
37
- const defaultExport = values.export ?? "contract";
38
- const outDir = (0, node_path.resolve)(process.cwd(), values.output ?? ".kizuna");
39
- const contracts = [];
40
- for (const positional of positionals) {
41
- const [pathPart, exportName = defaultExport] = positional.split(":");
42
- const contractPath = (0, node_path.resolve)(process.cwd(), pathPart);
43
- const contract = await require_lint_deprecations.loadContract(contractPath, exportName) ?? die(`No \`${exportName}\` (or default) export found at ${contractPath}`);
44
- contracts.push({
45
- contract,
46
- contractPath
47
- });
48
- }
49
- for (const { contractPath } of contracts) for (const warning of require_lint_deprecations.lintDeprecations(contractPath)) process.stderr.write(`Warning: ${warning.file}:${warning.line} ${warning.message}\n`);
50
- const written = require_lint_deprecations.writeKizunaDeprecations(contracts, outDir);
51
- process.stderr.write(`Wrote ${written}\n`);
52
- if (values.dts !== void 0) {
53
- const dtsDir = (0, node_path.resolve)(process.cwd(), values.dts);
54
- const fields = /* @__PURE__ */ new Map();
55
- for (const { contractPath } of contracts) for (const [name, map] of require_lint_deprecations.collectExportedSchemaDocs(contractPath)) fields.set(name, map);
56
- const result = require_lint_deprecations.patchDeclarationDocs(dtsDir, fields);
57
- process.stderr.write(`Patched JSDoc on ${result.injections} field(s) across ${result.filesChanged} of ${result.filesScanned} .d.ts file(s) in ${dtsDir}\n`);
58
- }
59
- };
60
- main().catch((error) => die(`Error: ${error instanceof Error ? error.message : String(error)}`));
61
- //#endregion
package/dist/cli.d.cts DELETED
@@ -1 +0,0 @@
1
- export { };
package/dist/cli.d.mts DELETED
@@ -1 +0,0 @@
1
- export { };
package/dist/cli.mjs DELETED
@@ -1,62 +0,0 @@
1
- #!/usr/bin/env node
2
- import { a as patchDeclarationDocs, i as writeKizunaDeprecations, n as loadContract, o as collectExportedSchemaDocs, t as lintDeprecations } from "./lint-deprecations-Dx9WRFQa.mjs";
3
- import { resolve } from "node:path";
4
- import { parseArgs } from "node:util";
5
- //#region src/cli.ts
6
- const usage = `Usage: kizuna deprecations <contract.ts...> [--output <dir>] [--export <name>] [--dts <dir>]
7
-
8
- Writes deprecations.json into .kizuna, keyed per contract. Generators read it at
9
- generate time and apply the deprecations.
10
-
11
- A contract path may be suffixed with the export to read: src/workspace.ts:workspaceContract.
12
-
13
- Optional:
14
- --output <dir> Output directory. Default: .kizuna
15
- --export <name> Default export name when none is suffixed. Default: contract
16
- --dts <dir> Re-inject schema-field JSDoc into emitted .d.ts files in <dir>,
17
- so docs survive publishing and reach z.infer consumers.
18
- `;
19
- const die = (message, code = 1) => {
20
- process.stderr.write(`${message}\n`);
21
- process.exit(code);
22
- };
23
- const main = async () => {
24
- const argv = process.argv.slice(2);
25
- if (argv[0] !== "deprecations") die(usage, argv[0] ? 1 : 0);
26
- const { values, positionals } = parseArgs({
27
- args: argv.slice(1),
28
- options: {
29
- output: { type: "string" },
30
- export: { type: "string" },
31
- dts: { type: "string" }
32
- },
33
- allowPositionals: true,
34
- strict: true
35
- });
36
- if (positionals.length === 0) die("Missing contract path(s)\n\n" + usage);
37
- const defaultExport = values.export ?? "contract";
38
- const outDir = resolve(process.cwd(), values.output ?? ".kizuna");
39
- const contracts = [];
40
- for (const positional of positionals) {
41
- const [pathPart, exportName = defaultExport] = positional.split(":");
42
- const contractPath = resolve(process.cwd(), pathPart);
43
- const contract = await loadContract(contractPath, exportName) ?? die(`No \`${exportName}\` (or default) export found at ${contractPath}`);
44
- contracts.push({
45
- contract,
46
- contractPath
47
- });
48
- }
49
- for (const { contractPath } of contracts) for (const warning of lintDeprecations(contractPath)) process.stderr.write(`Warning: ${warning.file}:${warning.line} ${warning.message}\n`);
50
- const written = writeKizunaDeprecations(contracts, outDir);
51
- process.stderr.write(`Wrote ${written}\n`);
52
- if (values.dts !== void 0) {
53
- const dtsDir = resolve(process.cwd(), values.dts);
54
- const fields = /* @__PURE__ */ new Map();
55
- for (const { contractPath } of contracts) for (const [name, map] of collectExportedSchemaDocs(contractPath)) fields.set(name, map);
56
- const result = patchDeclarationDocs(dtsDir, fields);
57
- process.stderr.write(`Patched JSDoc on ${result.injections} field(s) across ${result.filesChanged} of ${result.filesScanned} .d.ts file(s) in ${dtsDir}\n`);
58
- }
59
- };
60
- main().catch((error) => die(`Error: ${error instanceof Error ? error.message : String(error)}`));
61
- //#endregion
62
- export {};