@kizunajs/cli 2.0.0-beta.2 → 2.0.0-beta.3
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/dist/cli.cjs +6 -6
- package/dist/cli.mjs +6 -6
- package/dist/index.cjs +1 -1
- package/dist/index.d.cts +4 -1
- package/dist/index.d.mts +4 -1
- package/dist/index.mjs +1 -1
- package/dist/{route-map-DW2UUkD_.cjs → route-map-BUq6Iw3_.cjs} +26 -7
- package/dist/{route-map-D7cBgYmT.mjs → route-map-BZVDVH7m.mjs} +27 -8
- package/package.json +4 -3
package/dist/cli.cjs
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
#!/usr/bin/env node
|
|
2
|
-
const require_route_map = require("./route-map-
|
|
2
|
+
const require_route_map = require("./route-map-BUq6Iw3_.cjs");
|
|
3
3
|
let node_fs = require("node:fs");
|
|
4
4
|
let node_path = require("node:path");
|
|
5
5
|
let node_util = require("node:util");
|
|
@@ -58,17 +58,17 @@ const loadOrDie = async (configPath) => {
|
|
|
58
58
|
};
|
|
59
59
|
const runGenerate = async (values) => {
|
|
60
60
|
const configPath = configPathFrom(values.config);
|
|
61
|
+
const config = await loadOrDie(configPath);
|
|
62
|
+
const typesOutput = values.types ?? config.typesOutput;
|
|
63
|
+
if (typesOutput === void 0) die(`${displayPath(configPath)} declares no \`typescript.outputFile\`, which is where the \`Config\` is written. Add one, or pass --types.`);
|
|
64
|
+
const typesPath = (0, node_path.resolve)((0, node_path.dirname)(configPath), typesOutput);
|
|
61
65
|
let types;
|
|
62
66
|
try {
|
|
63
|
-
types = require_route_map.generateConfigTypes((0, node_fs.readFileSync)(configPath, "utf8"), configPath);
|
|
67
|
+
types = require_route_map.generateConfigTypes((0, node_fs.readFileSync)(configPath, "utf8"), configPath, typesPath);
|
|
64
68
|
} catch (error) {
|
|
65
69
|
if (error instanceof require_route_map.ConfigSyntaxError) die(`${displayPath(configPath)}: ${error.message}`);
|
|
66
70
|
throw error;
|
|
67
71
|
}
|
|
68
|
-
const config = await loadOrDie(configPath);
|
|
69
|
-
const typesOutput = values.types ?? config.typesOutput;
|
|
70
|
-
if (typesOutput === void 0) die(`${displayPath(configPath)} declares no \`typescript.outputFile\`, which is where the \`Config\` is written. Add one, or pass --types.`);
|
|
71
|
-
const typesPath = (0, node_path.resolve)((0, node_path.dirname)(configPath), typesOutput);
|
|
72
72
|
const typesCurrent = (0, node_fs.existsSync)(typesPath) ? (0, node_fs.readFileSync)(typesPath, "utf8") : void 0;
|
|
73
73
|
const typesBehind = typesCurrent !== types;
|
|
74
74
|
if (values.check) {
|
package/dist/cli.mjs
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
#!/usr/bin/env node
|
|
2
|
-
import { a as generateConfigTypes, c as writeClients, d as hasBreakingChange, i as ConfigSyntaxError, n as routeMap, o as checkClients, p as loadConfig, r as diffAgainst, s as formatStale, t as formatRoutes, u as formatChange } from "./route-map-
|
|
2
|
+
import { a as generateConfigTypes, c as writeClients, d as hasBreakingChange, i as ConfigSyntaxError, n as routeMap, o as checkClients, p as loadConfig, r as diffAgainst, s as formatStale, t as formatRoutes, u as formatChange } from "./route-map-BZVDVH7m.mjs";
|
|
3
3
|
import { existsSync, readFileSync, writeFileSync } from "node:fs";
|
|
4
4
|
import { dirname, relative, resolve } from "node:path";
|
|
5
5
|
import { parseArgs } from "node:util";
|
|
@@ -58,17 +58,17 @@ const loadOrDie = async (configPath) => {
|
|
|
58
58
|
};
|
|
59
59
|
const runGenerate = async (values) => {
|
|
60
60
|
const configPath = configPathFrom(values.config);
|
|
61
|
+
const config = await loadOrDie(configPath);
|
|
62
|
+
const typesOutput = values.types ?? config.typesOutput;
|
|
63
|
+
if (typesOutput === void 0) die(`${displayPath(configPath)} declares no \`typescript.outputFile\`, which is where the \`Config\` is written. Add one, or pass --types.`);
|
|
64
|
+
const typesPath = resolve(dirname(configPath), typesOutput);
|
|
61
65
|
let types;
|
|
62
66
|
try {
|
|
63
|
-
types = generateConfigTypes(readFileSync(configPath, "utf8"), configPath);
|
|
67
|
+
types = generateConfigTypes(readFileSync(configPath, "utf8"), configPath, typesPath);
|
|
64
68
|
} catch (error) {
|
|
65
69
|
if (error instanceof ConfigSyntaxError) die(`${displayPath(configPath)}: ${error.message}`);
|
|
66
70
|
throw error;
|
|
67
71
|
}
|
|
68
|
-
const config = await loadOrDie(configPath);
|
|
69
|
-
const typesOutput = values.types ?? config.typesOutput;
|
|
70
|
-
if (typesOutput === void 0) die(`${displayPath(configPath)} declares no \`typescript.outputFile\`, which is where the \`Config\` is written. Add one, or pass --types.`);
|
|
71
|
-
const typesPath = resolve(dirname(configPath), typesOutput);
|
|
72
72
|
const typesCurrent = existsSync(typesPath) ? readFileSync(typesPath, "utf8") : void 0;
|
|
73
73
|
const typesBehind = typesCurrent !== types;
|
|
74
74
|
if (values.check) {
|
package/dist/index.cjs
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
|
|
2
|
-
const require_route_map = require("./route-map-
|
|
2
|
+
const require_route_map = require("./route-map-BUq6Iw3_.cjs");
|
|
3
3
|
let kizunajs_generator = require("kizunajs/generator");
|
|
4
4
|
//#region src/api-notices.ts
|
|
5
5
|
const readSunset = (route) => {
|
package/dist/index.d.cts
CHANGED
|
@@ -150,8 +150,11 @@ declare class ConfigSyntaxError extends Error {}
|
|
|
150
150
|
* Read from the config's syntax rather than by running it: the generated file
|
|
151
151
|
* imports the same names the config did, and a config that loads is not a
|
|
152
152
|
* prerequisite for typing the routes it serves.
|
|
153
|
+
*
|
|
154
|
+
* `outputPath` is what the imports are written relative to. Left out, they stay
|
|
155
|
+
* relative to the config.
|
|
153
156
|
*/
|
|
154
|
-
declare const generateConfigTypes: (configSource: string, fileName?: string) => string;
|
|
157
|
+
declare const generateConfigTypes: (configSource: string, fileName?: string, outputPath?: string) => string;
|
|
155
158
|
//#endregion
|
|
156
159
|
//#region src/diff-schemas.d.ts
|
|
157
160
|
/**
|
package/dist/index.d.mts
CHANGED
|
@@ -150,8 +150,11 @@ declare class ConfigSyntaxError extends Error {}
|
|
|
150
150
|
* Read from the config's syntax rather than by running it: the generated file
|
|
151
151
|
* imports the same names the config did, and a config that loads is not a
|
|
152
152
|
* prerequisite for typing the routes it serves.
|
|
153
|
+
*
|
|
154
|
+
* `outputPath` is what the imports are written relative to. Left out, they stay
|
|
155
|
+
* relative to the config.
|
|
153
156
|
*/
|
|
154
|
-
declare const generateConfigTypes: (configSource: string, fileName?: string) => string;
|
|
157
|
+
declare const generateConfigTypes: (configSource: string, fileName?: string, outputPath?: string) => string;
|
|
155
158
|
//#endregion
|
|
156
159
|
//#region src/diff-schemas.d.ts
|
|
157
160
|
/**
|
package/dist/index.mjs
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { a as generateConfigTypes, c as writeClients, d as hasBreakingChange, f as diffSchemas, i as ConfigSyntaxError, l as diffApis, n as routeMap, o as checkClients, p as loadConfig, r as diffAgainst, s as formatStale, t as formatRoutes, u as formatChange } from "./route-map-
|
|
1
|
+
import { a as generateConfigTypes, c as writeClients, d as hasBreakingChange, f as diffSchemas, i as ConfigSyntaxError, l as diffApis, n as routeMap, o as checkClients, p as loadConfig, r as diffAgainst, s as formatStale, t as formatRoutes, u as formatChange } from "./route-map-BZVDVH7m.mjs";
|
|
2
2
|
import { createGenerator } from "kizunajs/generator";
|
|
3
3
|
//#region src/api-notices.ts
|
|
4
4
|
const readSunset = (route) => {
|
|
@@ -39,7 +39,11 @@ let node_child_process = require("node:child_process");
|
|
|
39
39
|
* a config.
|
|
40
40
|
*/
|
|
41
41
|
const loadConfig = async (configPath) => {
|
|
42
|
-
return (0, kizunajs.apiEntries)(await (0, jiti.createJiti)(require("url").pathToFileURL(__filename).href, {
|
|
42
|
+
return (0, kizunajs.apiEntries)(await (0, jiti.createJiti)(require("url").pathToFileURL(__filename).href, {
|
|
43
|
+
interopDefault: true,
|
|
44
|
+
jsx: true,
|
|
45
|
+
tsconfigPaths: true
|
|
46
|
+
}).import(configPath)).map(([name, entry]) => ({
|
|
43
47
|
name,
|
|
44
48
|
api: entry.api,
|
|
45
49
|
clients: entry.clients ?? [],
|
|
@@ -588,22 +592,32 @@ const HEADER = `/**
|
|
|
588
592
|
* and re-run \`kizuna generate\` to regenerate this file.
|
|
589
593
|
*/`;
|
|
590
594
|
/**
|
|
595
|
+
* Points a relative specifier at the same file from somewhere else, so a
|
|
596
|
+
* `Config` written outside the config's own directory still resolves.
|
|
597
|
+
*/
|
|
598
|
+
const rebaseSpecifier = (specifier, configDir, outputDir) => {
|
|
599
|
+
if (!specifier.startsWith("./") && !specifier.startsWith("../")) return specifier;
|
|
600
|
+
const rebased = (0, node_path.relative)(outputDir, (0, node_path.resolve)(configDir, specifier)).split(node_path.sep).join("/");
|
|
601
|
+
return rebased.startsWith(".") ? rebased : `./${rebased}`;
|
|
602
|
+
};
|
|
603
|
+
/**
|
|
591
604
|
* The `import type` lines the interface needs, grouped by module and written in
|
|
592
605
|
* the order the config imported them.
|
|
593
606
|
*/
|
|
594
|
-
const renderImports = (imports, used) => {
|
|
607
|
+
const renderImports = (imports, used, rebase) => {
|
|
595
608
|
const byModule = /* @__PURE__ */ new Map();
|
|
596
609
|
const defaults = [];
|
|
597
610
|
for (const [local, imported] of imports) {
|
|
598
611
|
if (!used.has(local)) continue;
|
|
612
|
+
const module = rebase(imported.module);
|
|
599
613
|
if (imported.isDefault) {
|
|
600
|
-
defaults.push(`import type ${local} from '${
|
|
614
|
+
defaults.push(`import type ${local} from '${module}';`);
|
|
601
615
|
continue;
|
|
602
616
|
}
|
|
603
617
|
const specifier = imported.exported === local ? local : `${imported.exported} as ${local}`;
|
|
604
|
-
const existing = byModule.get(
|
|
618
|
+
const existing = byModule.get(module);
|
|
605
619
|
if (existing) existing.push(specifier);
|
|
606
|
-
else byModule.set(
|
|
620
|
+
else byModule.set(module, [specifier]);
|
|
607
621
|
}
|
|
608
622
|
const named = [...byModule].map(([module, names]) => `import type { ${names.join(", ")} } from '${module}';`);
|
|
609
623
|
return [...defaults, ...named].join("\n");
|
|
@@ -615,8 +629,11 @@ const renderImports = (imports, used) => {
|
|
|
615
629
|
* Read from the config's syntax rather than by running it: the generated file
|
|
616
630
|
* imports the same names the config did, and a config that loads is not a
|
|
617
631
|
* prerequisite for typing the routes it serves.
|
|
632
|
+
*
|
|
633
|
+
* `outputPath` is what the imports are written relative to. Left out, they stay
|
|
634
|
+
* relative to the config.
|
|
618
635
|
*/
|
|
619
|
-
const generateConfigTypes = (configSource, fileName = "kizuna.config.ts") => {
|
|
636
|
+
const generateConfigTypes = (configSource, fileName = "kizuna.config.ts", outputPath) => {
|
|
620
637
|
const source = typescript.default.createSourceFile(fileName, configSource, typescript.default.ScriptTarget.Latest, true);
|
|
621
638
|
const imports = collectImports(source);
|
|
622
639
|
const configObject = findConfigObject(source);
|
|
@@ -643,7 +660,9 @@ const generateConfigTypes = (configSource, fileName = "kizuna.config.ts") => {
|
|
|
643
660
|
} else if (key === "plugins") lines.push(` ${key}: ${typeOfPluginList(value, used)};`);
|
|
644
661
|
else lines.push(` ${key}: ${typeOfValue(value, used, key)};`);
|
|
645
662
|
}
|
|
646
|
-
const
|
|
663
|
+
const configDir = (0, node_path.dirname)((0, node_path.resolve)(fileName));
|
|
664
|
+
const outputDir = outputPath === void 0 ? configDir : (0, node_path.dirname)((0, node_path.resolve)(outputPath));
|
|
665
|
+
const importBlock = renderImports(imports, used, (specifier) => outputDir === configDir ? specifier : rebaseSpecifier(specifier, configDir, outputDir));
|
|
647
666
|
const body = `export interface Config {\n${lines.join("\n")}\n}`;
|
|
648
667
|
return `${importBlock === "" ? HEADER : `${HEADER}\n${importBlock}`}\n\n${body}\n`;
|
|
649
668
|
};
|
|
@@ -3,7 +3,7 @@ import { apiEntries } from "kizunajs";
|
|
|
3
3
|
import { createGenerator, deriveToolNames, flattenJobs, readDef, readObjectShape, resolveResponseBody, toToolName, unwrapOptionalWrappers } from "kizunajs/generator";
|
|
4
4
|
import { flattenRoutes } from "kizunajs/adapter";
|
|
5
5
|
import { mkdirSync, mkdtempSync, readFileSync, rmSync, writeFileSync } from "node:fs";
|
|
6
|
-
import { dirname, isAbsolute, join, relative, resolve } from "node:path";
|
|
6
|
+
import { dirname, isAbsolute, join, relative, resolve, sep } from "node:path";
|
|
7
7
|
import ts from "typescript";
|
|
8
8
|
import { execFileSync } from "node:child_process";
|
|
9
9
|
//#region src/load-config.ts
|
|
@@ -16,7 +16,11 @@ import { execFileSync } from "node:child_process";
|
|
|
16
16
|
* a config.
|
|
17
17
|
*/
|
|
18
18
|
const loadConfig = async (configPath) => {
|
|
19
|
-
return apiEntries(await createJiti(import.meta.url, {
|
|
19
|
+
return apiEntries(await createJiti(import.meta.url, {
|
|
20
|
+
interopDefault: true,
|
|
21
|
+
jsx: true,
|
|
22
|
+
tsconfigPaths: true
|
|
23
|
+
}).import(configPath)).map(([name, entry]) => ({
|
|
20
24
|
name,
|
|
21
25
|
api: entry.api,
|
|
22
26
|
clients: entry.clients ?? [],
|
|
@@ -565,22 +569,32 @@ const HEADER = `/**
|
|
|
565
569
|
* and re-run \`kizuna generate\` to regenerate this file.
|
|
566
570
|
*/`;
|
|
567
571
|
/**
|
|
572
|
+
* Points a relative specifier at the same file from somewhere else, so a
|
|
573
|
+
* `Config` written outside the config's own directory still resolves.
|
|
574
|
+
*/
|
|
575
|
+
const rebaseSpecifier = (specifier, configDir, outputDir) => {
|
|
576
|
+
if (!specifier.startsWith("./") && !specifier.startsWith("../")) return specifier;
|
|
577
|
+
const rebased = relative(outputDir, resolve(configDir, specifier)).split(sep).join("/");
|
|
578
|
+
return rebased.startsWith(".") ? rebased : `./${rebased}`;
|
|
579
|
+
};
|
|
580
|
+
/**
|
|
568
581
|
* The `import type` lines the interface needs, grouped by module and written in
|
|
569
582
|
* the order the config imported them.
|
|
570
583
|
*/
|
|
571
|
-
const renderImports = (imports, used) => {
|
|
584
|
+
const renderImports = (imports, used, rebase) => {
|
|
572
585
|
const byModule = /* @__PURE__ */ new Map();
|
|
573
586
|
const defaults = [];
|
|
574
587
|
for (const [local, imported] of imports) {
|
|
575
588
|
if (!used.has(local)) continue;
|
|
589
|
+
const module = rebase(imported.module);
|
|
576
590
|
if (imported.isDefault) {
|
|
577
|
-
defaults.push(`import type ${local} from '${
|
|
591
|
+
defaults.push(`import type ${local} from '${module}';`);
|
|
578
592
|
continue;
|
|
579
593
|
}
|
|
580
594
|
const specifier = imported.exported === local ? local : `${imported.exported} as ${local}`;
|
|
581
|
-
const existing = byModule.get(
|
|
595
|
+
const existing = byModule.get(module);
|
|
582
596
|
if (existing) existing.push(specifier);
|
|
583
|
-
else byModule.set(
|
|
597
|
+
else byModule.set(module, [specifier]);
|
|
584
598
|
}
|
|
585
599
|
const named = [...byModule].map(([module, names]) => `import type { ${names.join(", ")} } from '${module}';`);
|
|
586
600
|
return [...defaults, ...named].join("\n");
|
|
@@ -592,8 +606,11 @@ const renderImports = (imports, used) => {
|
|
|
592
606
|
* Read from the config's syntax rather than by running it: the generated file
|
|
593
607
|
* imports the same names the config did, and a config that loads is not a
|
|
594
608
|
* prerequisite for typing the routes it serves.
|
|
609
|
+
*
|
|
610
|
+
* `outputPath` is what the imports are written relative to. Left out, they stay
|
|
611
|
+
* relative to the config.
|
|
595
612
|
*/
|
|
596
|
-
const generateConfigTypes = (configSource, fileName = "kizuna.config.ts") => {
|
|
613
|
+
const generateConfigTypes = (configSource, fileName = "kizuna.config.ts", outputPath) => {
|
|
597
614
|
const source = ts.createSourceFile(fileName, configSource, ts.ScriptTarget.Latest, true);
|
|
598
615
|
const imports = collectImports(source);
|
|
599
616
|
const configObject = findConfigObject(source);
|
|
@@ -620,7 +637,9 @@ const generateConfigTypes = (configSource, fileName = "kizuna.config.ts") => {
|
|
|
620
637
|
} else if (key === "plugins") lines.push(` ${key}: ${typeOfPluginList(value, used)};`);
|
|
621
638
|
else lines.push(` ${key}: ${typeOfValue(value, used, key)};`);
|
|
622
639
|
}
|
|
623
|
-
const
|
|
640
|
+
const configDir = dirname(resolve(fileName));
|
|
641
|
+
const outputDir = outputPath === void 0 ? configDir : dirname(resolve(outputPath));
|
|
642
|
+
const importBlock = renderImports(imports, used, (specifier) => outputDir === configDir ? specifier : rebaseSpecifier(specifier, configDir, outputDir));
|
|
624
643
|
const body = `export interface Config {\n${lines.join("\n")}\n}`;
|
|
625
644
|
return `${importBlock === "" ? HEADER : `${HEADER}\n${importBlock}`}\n\n${body}\n`;
|
|
626
645
|
};
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@kizunajs/cli",
|
|
3
|
-
"version": "2.0.0-beta.
|
|
3
|
+
"version": "2.0.0-beta.3",
|
|
4
4
|
"description": "Command line tooling for Kizuna.js",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"kizunajs",
|
|
@@ -61,13 +61,14 @@
|
|
|
61
61
|
},
|
|
62
62
|
"peerDependencies": {
|
|
63
63
|
"zod": "^4.0.0",
|
|
64
|
-
"kizunajs": "2.0.0-beta.
|
|
64
|
+
"kizunajs": "2.0.0-beta.3"
|
|
65
65
|
},
|
|
66
66
|
"devDependencies": {
|
|
67
67
|
"@types/node": "^24",
|
|
68
|
+
"@types/react": "^19.2.18",
|
|
68
69
|
"tsdown": "^0.21.0",
|
|
69
70
|
"zod": "^4.0.0",
|
|
70
|
-
"kizunajs": "2.0.0-beta.
|
|
71
|
+
"kizunajs": "2.0.0-beta.3"
|
|
71
72
|
},
|
|
72
73
|
"scripts": {
|
|
73
74
|
"build": "tsdown src/index.ts src/cli.ts --format esm,cjs --dts --clean --external kizunajs --external zod --external jiti --external typescript",
|