@pajecawav/json2code 0.1.0 → 0.2.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 +2 -0
- package/dist/cli.mjs +5 -0
- package/dist/cli.mjs.map +1 -1
- package/dist/core/linker/index.d.mts.map +1 -1
- package/dist/core/linker/index.mjs +7 -6
- package/dist/core/linker/index.mjs.map +1 -1
- package/dist/core/types.d.mts +2 -0
- package/dist/core/types.d.mts.map +1 -1
- package/dist/core/types.mjs +1 -0
- package/dist/core/types.mjs.map +1 -1
- package/dist/package.mjs +1 -1
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -63,6 +63,7 @@ json2code [input...] -o <dir> [flags]
|
|
|
63
63
|
| `--import-extension <ext>` | Extension in relative imports: `js` \| `ts` \| `none` (default: `js`) |
|
|
64
64
|
| `--readonly-arrays` | Emit `readonly T[]` in the typescript target |
|
|
65
65
|
| `--naming <style>` | Export name style: `origin` \| `camel` \| `pascal` (default: `pascal`) |
|
|
66
|
+
| `--export-suffix <str>` | Literal appended to every export name, after the naming style (e.g. `Schema`) |
|
|
66
67
|
| `--header <template>` | Header template with `{{version}}` / `{{date}}` placeholders (`\n` escapes a newline) |
|
|
67
68
|
| `--no-header` | Don't emit the file header |
|
|
68
69
|
| `--zod-import-path <spec>` | Import specifier for zod in the zod target (default: `zod`) |
|
|
@@ -99,6 +100,7 @@ await generate({
|
|
|
99
100
|
importPaths: { zod: "zod", valibot: "valibot" },
|
|
100
101
|
defaults: true,
|
|
101
102
|
naming: "pascal", // or "origin" / "camel"
|
|
103
|
+
exportSuffix: "", // e.g. "Schema" → export const UserSchema = ...
|
|
102
104
|
header: "// generated by json2code v{{version}} on {{date}}", // or false
|
|
103
105
|
},
|
|
104
106
|
clean: true,
|
package/dist/cli.mjs
CHANGED
|
@@ -51,6 +51,10 @@ const command = defineCommand({
|
|
|
51
51
|
type: "string",
|
|
52
52
|
description: `Export name style: ${NAMING_STYLES.join("|")} (default: pascal)`
|
|
53
53
|
},
|
|
54
|
+
"export-suffix": {
|
|
55
|
+
type: "string",
|
|
56
|
+
description: "Literal appended to every export name (e.g. Schema → UsersUserSchema)"
|
|
57
|
+
},
|
|
54
58
|
header: {
|
|
55
59
|
type: "string",
|
|
56
60
|
description: "Header template ({{version}}, {{date}} placeholders, \"\\n\" for newlines); empty disables"
|
|
@@ -103,6 +107,7 @@ const command = defineCommand({
|
|
|
103
107
|
},
|
|
104
108
|
defaults: !(args["no-defaults"] ?? false) && (file.options?.defaults ?? true),
|
|
105
109
|
naming: namingArg,
|
|
110
|
+
exportSuffix: args["export-suffix"] ?? file.options?.exportSuffix,
|
|
106
111
|
header: headerArg
|
|
107
112
|
},
|
|
108
113
|
clean: args.clean ?? file.clean,
|
package/dist/cli.mjs.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"cli.mjs","names":["pkg.version"],"sources":["../src/cli.ts"],"sourcesContent":["#!/usr/bin/env node\nimport { defineCommand, runMain } from \"citty\";\nimport pkg from \"../package.json\" with { type: \"json\" };\nimport { loadFileConfig } from \"./core/config.js\";\nimport { generate } from \"./core/generate.js\";\nimport type { GenerateConfig, ImportExtension, NamingStyle, TargetName } from \"./core/types.js\";\nimport { NAMING_STYLES } from \"./core/types.js\";\nimport { Json2CodeError } from \"./diagnostics/errors.js\";\n\nconst command = defineCommand({\n\tmeta: {\n\t\tname: \"json2code\",\n\t\tversion: pkg.version,\n\t\tdescription: \"Generate TypeScript code from JSON Schema.\",\n\t},\n\targs: {\n\t\toutput: { type: \"string\", alias: \"o\", description: \"Output directory\" },\n\t\ttarget: {\n\t\t\ttype: \"string\",\n\t\t\talias: \"t\",\n\t\t\tdescription: \"Target(s), comma-separated (typescript,zod,valibot)\",\n\t\t},\n\t\tconfig: {\n\t\t\ttype: \"string\",\n\t\t\tdescription: \"Path to config file (default: json2code.config.* in cwd)\",\n\t\t},\n\t\t\"import-extension\": {\n\t\t\ttype: \"string\",\n\t\t\tdescription: \"Import extension: js|ts|none\",\n\t\t},\n\t\t\"readonly-arrays\": { type: \"boolean\", description: \"Emit readonly arrays\" },\n\t\t\"zod-import-path\": { type: \"string\", description: \"Zod import specifier\" },\n\t\t\"valibot-import-path\": { type: \"string\", description: \"Valibot import specifier\" },\n\t\t\"no-defaults\": {\n\t\t\ttype: \"boolean\",\n\t\t\tdescription: \"Don't apply JSON Schema `default` in validator targets\",\n\t\t},\n\t\tnaming: {\n\t\t\ttype: \"string\",\n\t\t\tdescription: `Export name style: ${NAMING_STYLES.join(\"|\")} (default: pascal)`,\n\t\t},\n\t\theader: {\n\t\t\ttype: \"string\",\n\t\t\tdescription:\n\t\t\t\t'Header template ({{version}}, {{date}} placeholders, \"\\\\n\" for newlines); empty disables',\n\t\t},\n\t\t\"no-header\": { type: \"boolean\", description: \"Omit the file header\" },\n\t\t\"dry-run\": { type: \"boolean\", description: \"Don't write, show the plan\" },\n\t\tclean: { type: \"boolean\", description: \"Remove stale generated files\" },\n\t\tverbose: { type: \"boolean\", alias: \"V\", description: \"Verbose logging\" },\n\t},\n\tasync run({ args }) {\n\t\tconst { config: file } = await loadFileConfig(args.config);\n\t\tconst input =\n\t\t\targs._.length > 0 ? [...args._] : file.input ? [...file.input] : [\"schemas/**/*.json\"];\n\t\tconst output = args.output ?? file.output;\n\t\tif (!output) {\n\t\t\tconsole.error(\"error: missing output directory (-o or `output` in the config file)\");\n\t\t\tprocess.exit(1);\n\t\t}\n\t\tconst targets = (\n\t\t\targs.target\n\t\t\t\t? args.target\n\t\t\t\t\t\t.split(\",\")\n\t\t\t\t\t\t.map(s => s.trim())\n\t\t\t\t\t\t.filter(Boolean)\n\t\t\t\t: (file.targets ?? [\"typescript\"])\n\t\t) as TargetName[];\n\t\tconst namingArg = (args.naming as NamingStyle | undefined) ?? file.options?.naming;\n\t\tif (namingArg !== undefined && !NAMING_STYLES.includes(namingArg)) {\n\t\t\tconsole.error(\n\t\t\t\t`error: invalid naming style \"${namingArg}\" (expected one of: ${NAMING_STYLES.join(\", \")})`,\n\t\t\t);\n\t\t\tprocess.exit(1);\n\t\t}\n\t\t// citty maps `--no-header` to `header === false`; `--header <text>` gives a string\n\t\tconst rawHeader = args.header as string | boolean | undefined;\n\t\tconst headerArg =\n\t\t\trawHeader === false || args[\"no-header\"] === true\n\t\t\t\t? false\n\t\t\t\t: typeof rawHeader === \"string\"\n\t\t\t\t\t? rawHeader.replaceAll(\"\\\\n\", \"\\n\")\n\t\t\t\t\t: file.options?.header;\n\t\tconst config: GenerateConfig = {\n\t\t\tinput,\n\t\t\toutput,\n\t\t\ttargets,\n\t\t\toptions: {\n\t\t\t\timportExtension:\n\t\t\t\t\t(args[\"import-extension\"] as ImportExtension | undefined) ??\n\t\t\t\t\tfile.options?.importExtension,\n\t\t\t\treadonlyArrays: args[\"readonly-arrays\"] ?? file.options?.readonlyArrays,\n\t\t\t\timportPaths: {\n\t\t\t\t\t...file.options?.importPaths,\n\t\t\t\t\t...(args[\"zod-import-path\"] ? { zod: args[\"zod-import-path\"] } : {}),\n\t\t\t\t\t...(args[\"valibot-import-path\"]\n\t\t\t\t\t\t? { valibot: args[\"valibot-import-path\"] }\n\t\t\t\t\t\t: {}),\n\t\t\t\t},\n\t\t\t\tdefaults: !(args[\"no-defaults\"] ?? false) && (file.options?.defaults ?? true),\n\t\t\t\tnaming: namingArg,\n\t\t\t\theader: headerArg,\n\t\t\t},\n\t\t\tclean: args.clean ?? file.clean,\n\t\t\tdryRun: args[\"dry-run\"] ?? file.dryRun,\n\t\t\tverbose: args.verbose ?? file.verbose,\n\t\t};\n\t\ttry {\n\t\t\tawait generate(config);\n\t\t\tprocess.exit(0);\n\t\t} catch (e) {\n\t\t\tif (e instanceof Json2CodeError) {\n\t\t\t\tprocess.exit(1);\n\t\t\t}\n\t\t\tconsole.error(e);\n\t\t\tprocess.exit(1);\n\t\t}\n\t},\n});\n\nawait runMain(command);\n"],"mappings":";;;;;;;;AASA,MAAM,UAAU,cAAc;CAC7B,MAAM;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,IAAI,cAAc,KAAA,KAAa,CAAC,cAAc,SAAS,SAAS,GAAG;GAClE,QAAQ,MACP,gCAAgC,UAAU,sBAAsB,cAAc,KAAK,IAAI,EAAE,EAC1F;GACA,QAAQ,KAAK,CAAC;EACf;EAEA,MAAM,YAAY,KAAK;EACvB,MAAM,YACL,cAAc,SAAS,KAAK,iBAAiB,OAC1C,QACA,OAAO,cAAc,WACpB,UAAU,WAAW,OAAO,IAAI,IAChC,KAAK,SAAS;EACnB,MAAM,SAAyB;GAC9B;GACA;GACA;GACA,SAAS;IACR,iBACE,KAAK,uBACN,KAAK,SAAS;IACf,gBAAgB,KAAK,sBAAsB,KAAK,SAAS;IACzD,aAAa;KACZ,GAAG,KAAK,SAAS;KACjB,GAAI,KAAK,qBAAqB,EAAE,KAAK,KAAK,mBAAmB,IAAI,CAAC;KAClE,GAAI,KAAK,yBACN,EAAE,SAAS,KAAK,uBAAuB,IACvC,CAAC;IACL;IACA,UAAU,EAAE,KAAK,kBAAkB,WAAW,KAAK,SAAS,YAAY;IACxE,QAAQ;IACR,QAAQ;GACT;GACA,OAAO,KAAK,SAAS,KAAK;GAC1B,QAAQ,KAAK,cAAc,KAAK;GAChC,SAAS,KAAK,WAAW,KAAK;EAC/B;EACA,IAAI;GACH,MAAM,SAAS,MAAM;GACrB,QAAQ,KAAK,CAAC;EACf,SAAS,GAAG;GACX,IAAI,aAAa,gBAChB,QAAQ,KAAK,CAAC;GAEf,QAAQ,MAAM,CAAC;GACf,QAAQ,KAAK,CAAC;EACf;CACD;AACD,CAAC;AAED,MAAM,QAAQ,OAAO"}
|
|
1
|
+
{"version":3,"file":"cli.mjs","names":["pkg.version"],"sources":["../src/cli.ts"],"sourcesContent":["#!/usr/bin/env node\nimport { defineCommand, runMain } from \"citty\";\nimport pkg from \"../package.json\" with { type: \"json\" };\nimport { loadFileConfig } from \"./core/config.js\";\nimport { generate } from \"./core/generate.js\";\nimport type { GenerateConfig, ImportExtension, NamingStyle, TargetName } from \"./core/types.js\";\nimport { NAMING_STYLES } from \"./core/types.js\";\nimport { Json2CodeError } from \"./diagnostics/errors.js\";\n\nconst command = defineCommand({\n\tmeta: {\n\t\tname: \"json2code\",\n\t\tversion: pkg.version,\n\t\tdescription: \"Generate TypeScript code from JSON Schema.\",\n\t},\n\targs: {\n\t\toutput: { type: \"string\", alias: \"o\", description: \"Output directory\" },\n\t\ttarget: {\n\t\t\ttype: \"string\",\n\t\t\talias: \"t\",\n\t\t\tdescription: \"Target(s), comma-separated (typescript,zod,valibot)\",\n\t\t},\n\t\tconfig: {\n\t\t\ttype: \"string\",\n\t\t\tdescription: \"Path to config file (default: json2code.config.* in cwd)\",\n\t\t},\n\t\t\"import-extension\": {\n\t\t\ttype: \"string\",\n\t\t\tdescription: \"Import extension: js|ts|none\",\n\t\t},\n\t\t\"readonly-arrays\": { type: \"boolean\", description: \"Emit readonly arrays\" },\n\t\t\"zod-import-path\": { type: \"string\", description: \"Zod import specifier\" },\n\t\t\"valibot-import-path\": { type: \"string\", description: \"Valibot import specifier\" },\n\t\t\"no-defaults\": {\n\t\t\ttype: \"boolean\",\n\t\t\tdescription: \"Don't apply JSON Schema `default` in validator targets\",\n\t\t},\n\t\tnaming: {\n\t\t\ttype: \"string\",\n\t\t\tdescription: `Export name style: ${NAMING_STYLES.join(\"|\")} (default: pascal)`,\n\t\t},\n\t\t\"export-suffix\": {\n\t\t\ttype: \"string\",\n\t\t\tdescription: \"Literal appended to every export name (e.g. Schema → UsersUserSchema)\",\n\t\t},\n\t\theader: {\n\t\t\ttype: \"string\",\n\t\t\tdescription:\n\t\t\t\t'Header template ({{version}}, {{date}} placeholders, \"\\\\n\" for newlines); empty disables',\n\t\t},\n\t\t\"no-header\": { type: \"boolean\", description: \"Omit the file header\" },\n\t\t\"dry-run\": { type: \"boolean\", description: \"Don't write, show the plan\" },\n\t\tclean: { type: \"boolean\", description: \"Remove stale generated files\" },\n\t\tverbose: { type: \"boolean\", alias: \"V\", description: \"Verbose logging\" },\n\t},\n\tasync run({ args }) {\n\t\tconst { config: file } = await loadFileConfig(args.config);\n\t\tconst input =\n\t\t\targs._.length > 0 ? [...args._] : file.input ? [...file.input] : [\"schemas/**/*.json\"];\n\t\tconst output = args.output ?? file.output;\n\t\tif (!output) {\n\t\t\tconsole.error(\"error: missing output directory (-o or `output` in the config file)\");\n\t\t\tprocess.exit(1);\n\t\t}\n\t\tconst targets = (\n\t\t\targs.target\n\t\t\t\t? args.target\n\t\t\t\t\t\t.split(\",\")\n\t\t\t\t\t\t.map(s => s.trim())\n\t\t\t\t\t\t.filter(Boolean)\n\t\t\t\t: (file.targets ?? [\"typescript\"])\n\t\t) as TargetName[];\n\t\tconst namingArg = (args.naming as NamingStyle | undefined) ?? file.options?.naming;\n\t\tif (namingArg !== undefined && !NAMING_STYLES.includes(namingArg)) {\n\t\t\tconsole.error(\n\t\t\t\t`error: invalid naming style \"${namingArg}\" (expected one of: ${NAMING_STYLES.join(\", \")})`,\n\t\t\t);\n\t\t\tprocess.exit(1);\n\t\t}\n\t\t// citty maps `--no-header` to `header === false`; `--header <text>` gives a string\n\t\tconst rawHeader = args.header as string | boolean | undefined;\n\t\tconst headerArg =\n\t\t\trawHeader === false || args[\"no-header\"] === true\n\t\t\t\t? false\n\t\t\t\t: typeof rawHeader === \"string\"\n\t\t\t\t\t? rawHeader.replaceAll(\"\\\\n\", \"\\n\")\n\t\t\t\t\t: file.options?.header;\n\t\tconst config: GenerateConfig = {\n\t\t\tinput,\n\t\t\toutput,\n\t\t\ttargets,\n\t\t\toptions: {\n\t\t\t\timportExtension:\n\t\t\t\t\t(args[\"import-extension\"] as ImportExtension | undefined) ??\n\t\t\t\t\tfile.options?.importExtension,\n\t\t\t\treadonlyArrays: args[\"readonly-arrays\"] ?? file.options?.readonlyArrays,\n\t\t\t\timportPaths: {\n\t\t\t\t\t...file.options?.importPaths,\n\t\t\t\t\t...(args[\"zod-import-path\"] ? { zod: args[\"zod-import-path\"] } : {}),\n\t\t\t\t\t...(args[\"valibot-import-path\"]\n\t\t\t\t\t\t? { valibot: args[\"valibot-import-path\"] }\n\t\t\t\t\t\t: {}),\n\t\t\t\t},\n\t\t\t\tdefaults: !(args[\"no-defaults\"] ?? false) && (file.options?.defaults ?? true),\n\t\t\t\tnaming: namingArg,\n\t\t\t\texportSuffix: args[\"export-suffix\"] ?? file.options?.exportSuffix,\n\t\t\t\theader: headerArg,\n\t\t\t},\n\t\t\tclean: args.clean ?? file.clean,\n\t\t\tdryRun: args[\"dry-run\"] ?? file.dryRun,\n\t\t\tverbose: args.verbose ?? file.verbose,\n\t\t};\n\t\ttry {\n\t\t\tawait generate(config);\n\t\t\tprocess.exit(0);\n\t\t} catch (e) {\n\t\t\tif (e instanceof Json2CodeError) {\n\t\t\t\tprocess.exit(1);\n\t\t\t}\n\t\t\tconsole.error(e);\n\t\t\tprocess.exit(1);\n\t\t}\n\t},\n});\n\nawait runMain(command);\n"],"mappings":";;;;;;;;AASA,MAAM,UAAU,cAAc;CAC7B,MAAM;EACL,MAAM;EACGA;EACT,aAAa;CACd;CACA,MAAM;EACL,QAAQ;GAAE,MAAM;GAAU,OAAO;GAAK,aAAa;EAAmB;EACtE,QAAQ;GACP,MAAM;GACN,OAAO;GACP,aAAa;EACd;EACA,QAAQ;GACP,MAAM;GACN,aAAa;EACd;EACA,oBAAoB;GACnB,MAAM;GACN,aAAa;EACd;EACA,mBAAmB;GAAE,MAAM;GAAW,aAAa;EAAuB;EAC1E,mBAAmB;GAAE,MAAM;GAAU,aAAa;EAAuB;EACzE,uBAAuB;GAAE,MAAM;GAAU,aAAa;EAA2B;EACjF,eAAe;GACd,MAAM;GACN,aAAa;EACd;EACA,QAAQ;GACP,MAAM;GACN,aAAa,sBAAsB,cAAc,KAAK,GAAG,EAAE;EAC5D;EACA,iBAAiB;GAChB,MAAM;GACN,aAAa;EACd;EACA,QAAQ;GACP,MAAM;GACN,aACC;EACF;EACA,aAAa;GAAE,MAAM;GAAW,aAAa;EAAuB;EACpE,WAAW;GAAE,MA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AC;IACL;IACA,UAAU,EAAE,KAAK,kBAAkB,WAAW,KAAK,SAAS,YAAY;IACxE,QAAQ;IACR,cAAc,KAAK,oBAAoB,KAAK,SAAS;IACrD,QAAQ;GACT;GACA,OAAO,KAAK,SAAS,KAAK;GAC1B,QAAQ,KAAK,cAAc,KAAK;GAChC,SAAS,KAAK,WAAW,KAAK;EAC/B;EACA,IAAI;GACH,MAAM,SAAS,MAAM;GACrB,QAAQ,KAAK,CAAC;EACf,SAAS,GAAG;GACX,IAAI,aAAa,gBAChB,QAAQ,KAAK,CAAC;GAEf,QAAQ,MAAM,CAAC;GACf,QAAQ,KAAK,CAAC;EACf;CACD;AACD,CAAC;AAED,MAAM,QAAQ,OAAO"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.mts","names":[],"sources":["../../../src/core/linker/index.ts"],"mappings":";;;;;;iBAOiB;WACP,SAAS;WACT;;WAEA,YAAY;;WAEZ,aAAa;;;;;;qBAOV;mBACK;mBACA;EAEjB,YAAmB,MAAM;;SAKX,iBAAiB,oBAAoB;EAKnD,WAAkB;EAIlB,cAAqB,mBAAmB;EAUxC,kBAAyB,KAAK,WAAW;
|
|
1
|
+
{"version":3,"file":"index.d.mts","names":[],"sources":["../../../src/core/linker/index.ts"],"mappings":";;;;;;iBAOiB;WACP,SAAS;WACT;;WAEA,YAAY;;WAEZ,aAAa;;;;;;qBAOV;mBACK;mBACA;EAEjB,YAAmB,MAAM;;SAKX,iBAAiB,oBAAoB;EAKnD,WAAkB;EAIlB,cAAqB,mBAAmB;EAUxC,kBAAyB,KAAK,WAAW;EAczC,mBAA0B,QAAQ,QAAQ,aAAa,eAAe;UAY9D"}
|
|
@@ -27,13 +27,14 @@ var Linker = class {
|
|
|
27
27
|
}
|
|
28
28
|
resolveExportName(doc, exportName) {
|
|
29
29
|
const style = this.opts.options.naming;
|
|
30
|
-
|
|
30
|
+
const suffix = this.opts.options.exportSuffix;
|
|
31
|
+
if (style === "origin") return exportName + suffix;
|
|
31
32
|
let names = this.namesByDoc.get(doc.docId);
|
|
32
33
|
if (!names) {
|
|
33
|
-
names = buildNames(doc, style, this.opts.diagnostics ?? []);
|
|
34
|
+
names = buildNames(doc, style, suffix, this.opts.diagnostics ?? []);
|
|
34
35
|
this.namesByDoc.set(doc.docId, names);
|
|
35
36
|
}
|
|
36
|
-
return names.get(exportName) ?? exportName;
|
|
37
|
+
return names.get(exportName) ?? exportName + suffix;
|
|
37
38
|
}
|
|
38
39
|
createPrintContext(logger, diagnostics) {
|
|
39
40
|
return {
|
|
@@ -55,14 +56,14 @@ var Linker = class {
|
|
|
55
56
|
}
|
|
56
57
|
};
|
|
57
58
|
/**
|
|
58
|
-
* Assign final export names for a document in the given style.
|
|
59
|
+
* Assign final export names for a document in the given style plus an export suffix.
|
|
59
60
|
* Deterministic: follows `exportOrder`; collisions get numeric suffixes + a warning.
|
|
60
61
|
*/
|
|
61
|
-
function buildNames(doc, style, diagnostics) {
|
|
62
|
+
function buildNames(doc, style, exportSuffix, diagnostics) {
|
|
62
63
|
const names = /* @__PURE__ */ new Map();
|
|
63
64
|
const used = /* @__PURE__ */ new Set();
|
|
64
65
|
for (const name of doc.exportOrder) {
|
|
65
|
-
let candidate = styleName(name, style);
|
|
66
|
+
let candidate = styleName(name, style) + exportSuffix;
|
|
66
67
|
if (used.has(candidate)) {
|
|
67
68
|
const base = candidate;
|
|
68
69
|
let i = 2;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.mjs","names":[],"sources":["../../../src/core/linker/index.ts"],"sourcesContent":["import { posix } from \"node:path\";\nimport { createDiagnostic, DiagnosticCode, type Diagnostic } from \"../../diagnostics/errors.js\";\nimport type { Logger } from \"../../diagnostics/logger.js\";\nimport type { SourceDoc } from \"../ir/types.js\";\nimport type { PrintContext } from \"../printer/abstract.js\";\nimport type { NamingStyle, PrintedFile, ResolvedOptions } from \"../types.js\";\n\nexport interface LinkerOptions {\n\treadonly options: ResolvedOptions;\n\treadonly targetName: string;\n\t/** Maps a doc id to its output subpath (relative to output root, without extension). */\n\treadonly mapOutput: (docId: string) => string;\n\t/** Diagnostics sink for naming warnings. */\n\treadonly diagnostics: Diagnostic[];\n}\n\n/**\n * Resolves abstract {@link Ref}s into relative import specifiers and output paths.\n * One Linker per target; builds the {@link PrintContext} handed to printers.\n */\nexport class Linker {\n\tprivate readonly opts: LinkerOptions;\n\tprivate readonly namesByDoc = new Map<string, ReadonlyMap<string, string>>();\n\n\tpublic constructor(opts: LinkerOptions) {\n\t\tthis.opts = opts;\n\t}\n\n\t/** Default output subpath for a doc id: `<targetName>/<stem>` (strips the source extension). */\n\tpublic static defaultMapOutput(targetName: string, docId: string): string {\n\t\tconst stem = stripExt(docId);\n\t\treturn `${targetName}/${stem}`;\n\t}\n\n\tpublic outputPath(docId: string): string {\n\t\treturn `${this.opts.mapOutput(docId)}.ts`;\n\t}\n\n\tpublic resolveImport(fromDocId: string, toDocId: string): string {\n\t\tconst fromDir = posix.dirname(this.opts.mapOutput(fromDocId));\n\t\tconst toPath = this.opts.mapOutput(toDocId);\n\t\tlet rel = posix.relative(fromDir, toPath);\n\t\tif (!rel.startsWith(\".\")) {\n\t\t\trel = `./${rel}`;\n\t\t}\n\t\treturn `${rel}${this.extension()}`;\n\t}\n\n\tpublic resolveExportName(doc: SourceDoc, exportName: string): string {\n\t\tconst style = this.opts.options.naming;\n\t\tif (style === \"origin\") {\n\t\t\treturn exportName;\n\t\t}\n\t\tlet names = this.namesByDoc.get(doc.docId);\n\t\tif (!names) {\n\t\t\tnames = buildNames(doc, style, this.opts.diagnostics ?? []);\n\t\t\tthis.namesByDoc.set(doc.docId, names);\n\t\t}\n\t\treturn names.get(exportName) ?? exportName;\n\t}\n\n\tpublic createPrintContext(logger: Logger, diagnostics: Diagnostic[]): PrintContext {\n\t\treturn {\n\t\t\tlogger,\n\t\t\toptions: this.opts.options,\n\t\t\tdiagnostics,\n\t\t\ttargetName: this.opts.targetName,\n\t\t\toutputPath: docId => this.outputPath(docId),\n\t\t\tresolveImport: (from, to) => this.resolveImport(from, to),\n\t\t\tresolveExportName: (doc, name) => this.resolveExportName(doc, name),\n\t\t};\n\t}\n\n\tprivate extension(): string {\n\t\tswitch (this.opts.options.importExtension) {\n\t\t\tcase \"js\":\n\t\t\t\treturn \".js\";\n\t\t\tcase \"ts\":\n\t\t\t\treturn \".ts\";\n\t\t\tcase \"none\":\n\t\t\t\treturn \"\";\n\t\t}\n\t}\n}\n\nexport interface PrintPlan {\n\treadonly targetName: string;\n\treadonly files: readonly PrintedFile[];\n}\n\n/**\n * Assign final export names for a document in the given style.\n * Deterministic: follows `exportOrder`; collisions get numeric suffixes + a warning.\n */\nfunction buildNames(\n\tdoc: SourceDoc,\n\tstyle: NamingStyle,\n\tdiagnostics: Diagnostic[],\n): ReadonlyMap<string, string> {\n\tconst names = new Map<string, string>();\n\tconst used = new Set<string>();\n\tfor (const name of doc.exportOrder) {\n\t\tlet candidate = styleName(name, style);\n\t\tif (used.has(candidate)) {\n\t\t\tconst base = candidate;\n\t\t\tlet i = 2;\n\t\t\twhile (used.has(candidate)) {\n\t\t\t\tcandidate = `${base}${i}`;\n\t\t\t\ti++;\n\t\t\t}\n\t\t\tdiagnostics.push(\n\t\t\t\tcreateDiagnostic(\n\t\t\t\t\tDiagnosticCode.NameCollision,\n\t\t\t\t\t\"warning\",\n\t\t\t\t\t`Export \"${name}\" maps to an existing \"${base}\" name; using \"${candidate}\"`,\n\t\t\t\t\t{ docId: doc.docId },\n\t\t\t\t),\n\t\t\t);\n\t\t}\n\t\tnames.set(name, candidate);\n\t\tused.add(candidate);\n\t}\n\treturn names;\n}\n\n/** Split a name into words: by separators (non-alphanumerics) and camelCase boundaries. */\nfunction words(name: string): readonly string[] {\n\treturn name\n\t\t.split(/[^$A-Za-z0-9]+/)\n\t\t.filter(Boolean)\n\t\t.flatMap(w => w.split(/(?<=[a-z0-9])(?=[A-Z])/))\n\t\t.filter(Boolean);\n}\n\nexport function styleName(name: string, style: NamingStyle): string {\n\tconst ws = words(name);\n\tif (ws.length === 0) {\n\t\treturn name;\n\t}\n\tconst [first, ...rest] = ws;\n\tconst joined = [\n\t\tstyle === \"camel\" ? (first ?? \"\").toLowerCase() : first,\n\t\t...rest.map(w => w.charAt(0).toUpperCase() + w.slice(1)),\n\t].join(\"\");\n\tswitch (style) {\n\t\tcase \"camel\":\n\t\t\treturn `${joined.charAt(0).toLowerCase()}${joined.slice(1)}`;\n\t\tcase \"pascal\":\n\t\t\treturn `${joined.charAt(0).toUpperCase()}${joined.slice(1)}`;\n\t\tcase \"origin\":\n\t\t\treturn name;\n\t}\n}\n\nfunction stripExt(p: string): string {\n\tconst dot = p.lastIndexOf(\".\");\n\tconst slash = p.lastIndexOf(\"/\");\n\tif (dot > slash) {\n\t\treturn p.slice(0, dot);\n\t}\n\treturn p;\n}\n"],"mappings":";;;;;;;AAoBA,IAAa,SAAb,MAAoB;CACnB;CACA,6BAA8B,IAAI,IAAyC;CAE3E,YAAmB,MAAqB;EACvC,KAAK,OAAO;CACb;;CAGA,OAAc,iBAAiB,YAAoB,OAAuB;EAEzE,OAAO,GAAG,WAAW,GADR,SAAS,KACK;CAC5B;CAEA,WAAkB,OAAuB;EACxC,OAAO,GAAG,KAAK,KAAK,UAAU,KAAK,EAAE;CACtC;CAEA,cAAqB,WAAmB,SAAyB;EAChE,MAAM,UAAU,MAAM,QAAQ,KAAK,KAAK,UAAU,SAAS,CAAC;EAC5D,MAAM,SAAS,KAAK,KAAK,UAAU,OAAO;EAC1C,IAAI,MAAM,MAAM,SAAS,SAAS,MAAM;EACxC,IAAI,CAAC,IAAI,WAAW,GAAG,GACtB,MAAM,KAAK;EAEZ,OAAO,GAAG,MAAM,KAAK,UAAU;CAChC;CAEA,kBAAyB,KAAgB,YAA4B;EACpE,MAAM,QAAQ,KAAK,KAAK,QAAQ;EAChC,IAAI,UAAU,UACb,OAAO;
|
|
1
|
+
{"version":3,"file":"index.mjs","names":[],"sources":["../../../src/core/linker/index.ts"],"sourcesContent":["import { posix } from \"node:path\";\nimport { createDiagnostic, DiagnosticCode, type Diagnostic } from \"../../diagnostics/errors.js\";\nimport type { Logger } from \"../../diagnostics/logger.js\";\nimport type { SourceDoc } from \"../ir/types.js\";\nimport type { PrintContext } from \"../printer/abstract.js\";\nimport type { NamingStyle, PrintedFile, ResolvedOptions } from \"../types.js\";\n\nexport interface LinkerOptions {\n\treadonly options: ResolvedOptions;\n\treadonly targetName: string;\n\t/** Maps a doc id to its output subpath (relative to output root, without extension). */\n\treadonly mapOutput: (docId: string) => string;\n\t/** Diagnostics sink for naming warnings. */\n\treadonly diagnostics: Diagnostic[];\n}\n\n/**\n * Resolves abstract {@link Ref}s into relative import specifiers and output paths.\n * One Linker per target; builds the {@link PrintContext} handed to printers.\n */\nexport class Linker {\n\tprivate readonly opts: LinkerOptions;\n\tprivate readonly namesByDoc = new Map<string, ReadonlyMap<string, string>>();\n\n\tpublic constructor(opts: LinkerOptions) {\n\t\tthis.opts = opts;\n\t}\n\n\t/** Default output subpath for a doc id: `<targetName>/<stem>` (strips the source extension). */\n\tpublic static defaultMapOutput(targetName: string, docId: string): string {\n\t\tconst stem = stripExt(docId);\n\t\treturn `${targetName}/${stem}`;\n\t}\n\n\tpublic outputPath(docId: string): string {\n\t\treturn `${this.opts.mapOutput(docId)}.ts`;\n\t}\n\n\tpublic resolveImport(fromDocId: string, toDocId: string): string {\n\t\tconst fromDir = posix.dirname(this.opts.mapOutput(fromDocId));\n\t\tconst toPath = this.opts.mapOutput(toDocId);\n\t\tlet rel = posix.relative(fromDir, toPath);\n\t\tif (!rel.startsWith(\".\")) {\n\t\t\trel = `./${rel}`;\n\t\t}\n\t\treturn `${rel}${this.extension()}`;\n\t}\n\n\tpublic resolveExportName(doc: SourceDoc, exportName: string): string {\n\t\tconst style = this.opts.options.naming;\n\t\tconst suffix = this.opts.options.exportSuffix;\n\t\tif (style === \"origin\") {\n\t\t\treturn exportName + suffix;\n\t\t}\n\t\tlet names = this.namesByDoc.get(doc.docId);\n\t\tif (!names) {\n\t\t\tnames = buildNames(doc, style, suffix, this.opts.diagnostics ?? []);\n\t\t\tthis.namesByDoc.set(doc.docId, names);\n\t\t}\n\t\treturn names.get(exportName) ?? exportName + suffix;\n\t}\n\n\tpublic createPrintContext(logger: Logger, diagnostics: Diagnostic[]): PrintContext {\n\t\treturn {\n\t\t\tlogger,\n\t\t\toptions: this.opts.options,\n\t\t\tdiagnostics,\n\t\t\ttargetName: this.opts.targetName,\n\t\t\toutputPath: docId => this.outputPath(docId),\n\t\t\tresolveImport: (from, to) => this.resolveImport(from, to),\n\t\t\tresolveExportName: (doc, name) => this.resolveExportName(doc, name),\n\t\t};\n\t}\n\n\tprivate extension(): string {\n\t\tswitch (this.opts.options.importExtension) {\n\t\t\tcase \"js\":\n\t\t\t\treturn \".js\";\n\t\t\tcase \"ts\":\n\t\t\t\treturn \".ts\";\n\t\t\tcase \"none\":\n\t\t\t\treturn \"\";\n\t\t}\n\t}\n}\n\nexport interface PrintPlan {\n\treadonly targetName: string;\n\treadonly files: readonly PrintedFile[];\n}\n\n/**\n * Assign final export names for a document in the given style plus an export suffix.\n * Deterministic: follows `exportOrder`; collisions get numeric suffixes + a warning.\n */\nfunction buildNames(\n\tdoc: SourceDoc,\n\tstyle: NamingStyle,\n\texportSuffix: string,\n\tdiagnostics: Diagnostic[],\n): ReadonlyMap<string, string> {\n\tconst names = new Map<string, string>();\n\tconst used = new Set<string>();\n\tfor (const name of doc.exportOrder) {\n\t\tlet candidate = styleName(name, style) + exportSuffix;\n\t\tif (used.has(candidate)) {\n\t\t\tconst base = candidate;\n\t\t\tlet i = 2;\n\t\t\twhile (used.has(candidate)) {\n\t\t\t\tcandidate = `${base}${i}`;\n\t\t\t\ti++;\n\t\t\t}\n\t\t\tdiagnostics.push(\n\t\t\t\tcreateDiagnostic(\n\t\t\t\t\tDiagnosticCode.NameCollision,\n\t\t\t\t\t\"warning\",\n\t\t\t\t\t`Export \"${name}\" maps to an existing \"${base}\" name; using \"${candidate}\"`,\n\t\t\t\t\t{ docId: doc.docId },\n\t\t\t\t),\n\t\t\t);\n\t\t}\n\t\tnames.set(name, candidate);\n\t\tused.add(candidate);\n\t}\n\treturn names;\n}\n\n/** Split a name into words: by separators (non-alphanumerics) and camelCase boundaries. */\nfunction words(name: string): readonly string[] {\n\treturn name\n\t\t.split(/[^$A-Za-z0-9]+/)\n\t\t.filter(Boolean)\n\t\t.flatMap(w => w.split(/(?<=[a-z0-9])(?=[A-Z])/))\n\t\t.filter(Boolean);\n}\n\nexport function styleName(name: string, style: NamingStyle): string {\n\tconst ws = words(name);\n\tif (ws.length === 0) {\n\t\treturn name;\n\t}\n\tconst [first, ...rest] = ws;\n\tconst joined = [\n\t\tstyle === \"camel\" ? (first ?? \"\").toLowerCase() : first,\n\t\t...rest.map(w => w.charAt(0).toUpperCase() + w.slice(1)),\n\t].join(\"\");\n\tswitch (style) {\n\t\tcase \"camel\":\n\t\t\treturn `${joined.charAt(0).toLowerCase()}${joined.slice(1)}`;\n\t\tcase \"pascal\":\n\t\t\treturn `${joined.charAt(0).toUpperCase()}${joined.slice(1)}`;\n\t\tcase \"origin\":\n\t\t\treturn name;\n\t}\n}\n\nfunction stripExt(p: string): string {\n\tconst dot = p.lastIndexOf(\".\");\n\tconst slash = p.lastIndexOf(\"/\");\n\tif (dot > slash) {\n\t\treturn p.slice(0, dot);\n\t}\n\treturn p;\n}\n"],"mappings":";;;;;;;AAoBA,IAAa,SAAb,MAAoB;CACnB;CACA,6BAA8B,IAAI,IAAyC;CAE3E,YAAmB,MAAqB;EACvC,KAAK,OAAO;CACb;;CAGA,OAAc,iBAAiB,YAAoB,OAAuB;EAEzE,OAAO,GAAG,WAAW,GADR,SAAS,KACK;CAC5B;CAEA,WAAkB,OAAuB;EACxC,OAAO,GAAG,KAAK,KAAK,UAAU,KAAK,EAAE;CACtC;CAEA,cAAqB,WAAmB,SAAyB;EAChE,MAAM,UAAU,MAAM,QAAQ,KAAK,KAAK,UAAU,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
35
|
/** Export name style (default: `pascal`). */
|
|
36
36
|
readonly naming: NamingStyle;
|
|
37
|
+
/** Literal appended to every export name, after the naming style (default: `""`). */
|
|
38
|
+
readonly exportSuffix: string;
|
|
37
39
|
/** File header template; `false` disables it. */
|
|
38
40
|
readonly header: string | false;
|
|
39
41
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"types.d.mts","names":[],"sources":["../../src/core/types.ts"],"mappings":";;;;iBAIiB;;WAEP;;WAEA;;WAEA;;;iBAIO;;WAEP;WACA;;YAGE;;iBAGK;WACP;WACA;;;YAIE;;iBAYK;WACP,iBAAiB;WACjB;;WAEA,aAAa;;WAEb;;WAEA,QAAQ;;WAER;;qBAGG,iBAAiB;;
|
|
1
|
+
{"version":3,"file":"types.d.mts","names":[],"sources":["../../src/core/types.ts"],"mappings":";;;;iBAIiB;;WAEP;;WAEA;;WAEA;;;iBAIO;;WAEP;WACA;;YAGE;;iBAGK;WACP;WACA;;;YAIE;;iBAYK;WACP,iBAAiB;WACjB;;WAEA,aAAa;;WAEb;;WAEA,QAAQ;;WAER;;WAEA;;qBAGG,iBAAiB;;iBAWb,wBAAwB;;WAE/B;;WAEA;;YAGE;;YAGA,aAAa,aAAa;;;;;iBAMrB;WACP;WACA,SAAS;;WAET,SAAS;;WAET,aAAa;;;iBAIN;WACP;WACA;WACA,SAAS;WACT,UAAU,QAAQ;WAClB;WACA;WACA"}
|
package/dist/core/types.mjs
CHANGED
package/dist/core/types.mjs.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"types.mjs","names":[],"sources":["../../src/core/types.ts"],"sourcesContent":["import type { AbstractPrinter } from \"./printer/abstract.js\";\nimport type { AbstractWalker } from \"./walker/abstract.js\";\n\n/** A discovered input schema file. */\nexport interface SchemaFile {\n\t/** Absolute path on disk. */\n\treadonly path: string;\n\t/** Normalized document id (posix, relative to the input root). */\n\treadonly docId: string;\n\t/** Raw JSON text. */\n\treadonly content: string;\n}\n\n/** A file produced by a Printer. */\nexport interface PrintedFile {\n\t/** Path relative to the target's output root. */\n\treadonly path: string;\n\treadonly content: string;\n}\n\nexport type ImportExtension = \"js\" | \"ts\" | \"none\";\n\n/** Import specifiers per validator target. */\nexport interface ImportPaths {\n\treadonly zod?: string;\n\treadonly valibot?: string;\n}\n\n/** Style applied to exported type/schema names. */\nexport type NamingStyle = \"origin\" | \"camel\" | \"pascal\";\n\nexport const NAMING_STYLES: readonly NamingStyle[] = [\"origin\", \"camel\", \"pascal\"];\n\n/**\n * Template of the `@generated` header prepended to every written file.\n * Supported placeholders: `{{version}}` (generator version), `{{date}}` (generation date, YYYY-MM-DD).\n * `false` disables the header entirely.\n */\nexport const DEFAULT_HEADER_TEMPLATE = \"// @generated by json2code v{{version}} — DO NOT EDIT\";\n\n/** User-tunable codegen options (with defaults). */\nexport interface GenerateOptions {\n\treadonly importExtension: ImportExtension;\n\treadonly readonlyArrays: boolean;\n\t/** Import specifiers per validator target (default: the package name). */\n\treadonly importPaths: ImportPaths;\n\t/** Apply JSON Schema `default` in validator targets. */\n\treadonly defaults: boolean;\n\t/** Export name style (default: `pascal`). */\n\treadonly naming: NamingStyle;\n\t/** File header template; `false` disables it. */\n\treadonly header: string | false;\n}\n\nexport const DEFAULT_OPTIONS: GenerateOptions = {\n\timportExtension: \"js\",\n\treadonlyArrays: false,\n\timportPaths: { zod: \"zod\", valibot: \"valibot\" },\n\tdefaults: true,\n\tnaming: \"pascal\",\n\theader: DEFAULT_HEADER_TEMPLATE,\n};\n\n/** Resolved options (paths made absolute). Passed through contexts. */\nexport interface ResolvedOptions extends GenerateOptions {\n\t/** Absolute output directory. */\n\treadonly output: string;\n\t/** Absolute common input root (used to compute doc ids). */\n\treadonly rootDir: string;\n}\n\nexport type TargetName = \"typescript\" | \"zod\" | \"valibot\";\n\n/** Either a built-in preset name or a fully custom generator definition. */\nexport type TargetSpec = TargetName | GeneratorDefinition;\n\n/**\n * Defines a target generator. Built-in targets are preset instances of this;\n * users supply their own to build custom generators.\n */\nexport interface GeneratorDefinition {\n\treadonly name: string;\n\treadonly printer: AbstractPrinter;\n\t/** Custom walker. Defaults to the built-in JsonSchemaWalker. */\n\treadonly walker?: AbstractWalker;\n\t/** Custom input doc-id → output subpath mapping. Default mirrors input structure. */\n\treadonly mapOutput?: (docId: string) => string;\n}\n\n/** User-facing top-level config for the API and the config file. */\nexport interface GenerateConfig {\n\treadonly input: string | string[];\n\treadonly output: string;\n\treadonly targets: TargetSpec[];\n\treadonly options?: Partial<GenerateOptions>;\n\treadonly clean?: boolean;\n\treadonly dryRun?: boolean;\n\treadonly verbose?: boolean;\n}\n"],"mappings":";AA+BA,MAAa,gBAAwC;CAAC;CAAU;CAAS;AAAQ;;;;;;AAOjF,MAAa,0BAA0B;
|
|
1
|
+
{"version":3,"file":"types.mjs","names":[],"sources":["../../src/core/types.ts"],"sourcesContent":["import type { AbstractPrinter } from \"./printer/abstract.js\";\nimport type { AbstractWalker } from \"./walker/abstract.js\";\n\n/** A discovered input schema file. */\nexport interface SchemaFile {\n\t/** Absolute path on disk. */\n\treadonly path: string;\n\t/** Normalized document id (posix, relative to the input root). */\n\treadonly docId: string;\n\t/** Raw JSON text. */\n\treadonly content: string;\n}\n\n/** A file produced by a Printer. */\nexport interface PrintedFile {\n\t/** Path relative to the target's output root. */\n\treadonly path: string;\n\treadonly content: string;\n}\n\nexport type ImportExtension = \"js\" | \"ts\" | \"none\";\n\n/** Import specifiers per validator target. */\nexport interface ImportPaths {\n\treadonly zod?: string;\n\treadonly valibot?: string;\n}\n\n/** Style applied to exported type/schema names. */\nexport type NamingStyle = \"origin\" | \"camel\" | \"pascal\";\n\nexport const NAMING_STYLES: readonly NamingStyle[] = [\"origin\", \"camel\", \"pascal\"];\n\n/**\n * Template of the `@generated` header prepended to every written file.\n * Supported placeholders: `{{version}}` (generator version), `{{date}}` (generation date, YYYY-MM-DD).\n * `false` disables the header entirely.\n */\nexport const DEFAULT_HEADER_TEMPLATE = \"// @generated by json2code v{{version}} — DO NOT EDIT\";\n\n/** User-tunable codegen options (with defaults). */\nexport interface GenerateOptions {\n\treadonly importExtension: ImportExtension;\n\treadonly readonlyArrays: boolean;\n\t/** Import specifiers per validator target (default: the package name). */\n\treadonly importPaths: ImportPaths;\n\t/** Apply JSON Schema `default` in validator targets. */\n\treadonly defaults: boolean;\n\t/** Export name style (default: `pascal`). */\n\treadonly naming: NamingStyle;\n\t/** Literal appended to every export name, after the naming style (default: `\"\"`). */\n\treadonly exportSuffix: string;\n\t/** File header template; `false` disables it. */\n\treadonly header: string | false;\n}\n\nexport const DEFAULT_OPTIONS: GenerateOptions = {\n\timportExtension: \"js\",\n\treadonlyArrays: false,\n\timportPaths: { zod: \"zod\", valibot: \"valibot\" },\n\tdefaults: true,\n\tnaming: \"pascal\",\n\texportSuffix: \"\",\n\theader: DEFAULT_HEADER_TEMPLATE,\n};\n\n/** Resolved options (paths made absolute). Passed through contexts. */\nexport interface ResolvedOptions extends GenerateOptions {\n\t/** Absolute output directory. */\n\treadonly output: string;\n\t/** Absolute common input root (used to compute doc ids). */\n\treadonly rootDir: string;\n}\n\nexport type TargetName = \"typescript\" | \"zod\" | \"valibot\";\n\n/** Either a built-in preset name or a fully custom generator definition. */\nexport type TargetSpec = TargetName | GeneratorDefinition;\n\n/**\n * Defines a target generator. Built-in targets are preset instances of this;\n * users supply their own to build custom generators.\n */\nexport interface GeneratorDefinition {\n\treadonly name: string;\n\treadonly printer: AbstractPrinter;\n\t/** Custom walker. Defaults to the built-in JsonSchemaWalker. */\n\treadonly walker?: AbstractWalker;\n\t/** Custom input doc-id → output subpath mapping. Default mirrors input structure. */\n\treadonly mapOutput?: (docId: string) => string;\n}\n\n/** User-facing top-level config for the API and the config file. */\nexport interface GenerateConfig {\n\treadonly input: string | string[];\n\treadonly output: string;\n\treadonly targets: TargetSpec[];\n\treadonly options?: Partial<GenerateOptions>;\n\treadonly clean?: boolean;\n\treadonly dryRun?: boolean;\n\treadonly verbose?: boolean;\n}\n"],"mappings":";AA+BA,MAAa,gBAAwC;CAAC;CAAU;CAAS;AAAQ;;;;;;AAOjF,MAAa,0BAA0B;AAkBvC,MAAa,kBAAmC;CAC/C,iBAAiB;CACjB,gBAAgB;CAChB,aAAa;EAAE,KAAK;EAAO,SAAS;CAAU;CAC9C,UAAU;CACV,QAAQ;CACR,cAAc;CACd,QAAQ;AACT"}
|
package/dist/package.mjs
CHANGED