@ts-kizuna/cli 1.49.5
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/LICENSE.MD +9 -0
- package/README.md +21 -0
- package/dist/cli.cjs +61 -0
- package/dist/cli.d.cts +1 -0
- package/dist/cli.d.mts +1 -0
- package/dist/cli.mjs +62 -0
- package/dist/index.cjs +8 -0
- package/dist/index.d.cts +71 -0
- package/dist/index.d.mts +72 -0
- package/dist/index.mjs +2 -0
- package/dist/lint-deprecations-CmqMnr7K.cjs +735 -0
- package/dist/lint-deprecations-Dx9WRFQa.mjs +669 -0
- package/package.json +78 -0
package/LICENSE.MD
ADDED
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2026 Sondre Ørland
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the 'Software'), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
|
|
6
|
+
|
|
7
|
+
The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
|
|
8
|
+
|
|
9
|
+
THE SOFTWARE IS PROVIDED 'AS IS', WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
package/README.md
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
# @ts-kizuna/cli
|
|
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.
|
|
4
|
+
|
|
5
|
+
## Installation
|
|
6
|
+
|
|
7
|
+
```sh
|
|
8
|
+
pnpm add -D @ts-kizuna/cli
|
|
9
|
+
```
|
|
10
|
+
|
|
11
|
+
## Usage
|
|
12
|
+
|
|
13
|
+
Prepend it to your dev and build scripts, so the generators always read current data:
|
|
14
|
+
|
|
15
|
+
```sh
|
|
16
|
+
kizuna deprecations src/contract/index.ts
|
|
17
|
+
```
|
|
18
|
+
|
|
19
|
+
## Documentation
|
|
20
|
+
|
|
21
|
+
[Deprecations](https://ts-kizuna.com/docs/deprecations)
|
package/dist/cli.cjs
ADDED
|
@@ -0,0 +1,61 @@
|
|
|
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
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export { };
|
package/dist/cli.d.mts
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export { };
|
package/dist/cli.mjs
ADDED
|
@@ -0,0 +1,62 @@
|
|
|
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 {};
|
package/dist/index.cjs
ADDED
|
@@ -0,0 +1,8 @@
|
|
|
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;
|
package/dist/index.d.cts
ADDED
|
@@ -0,0 +1,71 @@
|
|
|
1
|
+
import { DeprecationMap } from "@ts-kizuna/core/generator";
|
|
2
|
+
import { Contract } from "@ts-kizuna/core";
|
|
3
|
+
|
|
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
|
+
//#region src/load-contract.d.ts
|
|
51
|
+
/**
|
|
52
|
+
* Imports a contract module with jiti (so a `.ts` entry works without a build
|
|
53
|
+
* step) and returns the named export (default `contract`) or the default export.
|
|
54
|
+
* Returns undefined when neither is present.
|
|
55
|
+
*/
|
|
56
|
+
declare const loadContract: (contractPath: string, exportName?: string) => Promise<Contract | undefined>;
|
|
57
|
+
//#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 };
|
package/dist/index.d.mts
ADDED
|
@@ -0,0 +1,72 @@
|
|
|
1
|
+
import ts from "typescript";
|
|
2
|
+
import { DeprecationMap } from "@ts-kizuna/core/generator";
|
|
3
|
+
import { Contract } from "@ts-kizuna/core";
|
|
4
|
+
|
|
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
|
+
//#region src/load-contract.d.ts
|
|
52
|
+
/**
|
|
53
|
+
* Imports a contract module with jiti (so a `.ts` entry works without a build
|
|
54
|
+
* step) and returns the named export (default `contract`) or the default export.
|
|
55
|
+
* Returns undefined when neither is present.
|
|
56
|
+
*/
|
|
57
|
+
declare const loadContract: (contractPath: string, exportName?: string) => Promise<Contract | undefined>;
|
|
58
|
+
//#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 };
|
package/dist/index.mjs
ADDED
|
@@ -0,0 +1,2 @@
|
|
|
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 };
|