typia 13.0.0-dev.20260506 → 13.0.0-dev.20260509

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.
Files changed (72) hide show
  1. package/lib/executable/TypiaGenerateWizard.js +54 -45
  2. package/lib/executable/TypiaGenerateWizard.js.map +1 -1
  3. package/lib/executable/TypiaGenerateWizard2.mjs +64 -55
  4. package/lib/executable/TypiaGenerateWizard2.mjs.map +1 -1
  5. package/lib/executable/typia.d.ts +1 -1
  6. package/lib/executable/typia.js +1 -14
  7. package/lib/executable/typia.js.map +1 -1
  8. package/lib/executable/typia2.mjs +1 -16
  9. package/lib/executable/typia2.mjs.map +1 -1
  10. package/package.json +9 -6
  11. package/src/executable/TypiaGenerateWizard.ts +25 -23
  12. package/src/executable/typia.ts +1 -13
  13. package/lib/_virtual/ArgumentParser.mjs +0 -4
  14. package/lib/_virtual/ArgumentParser.mjs.map +0 -1
  15. package/lib/_virtual/CommandExecutor.mjs +0 -4
  16. package/lib/_virtual/CommandExecutor.mjs.map +0 -1
  17. package/lib/_virtual/FileRetriever.mjs +0 -4
  18. package/lib/_virtual/FileRetriever.mjs.map +0 -1
  19. package/lib/_virtual/PackageManager.mjs +0 -4
  20. package/lib/_virtual/PackageManager.mjs.map +0 -1
  21. package/lib/_virtual/PluginConfigurator.mjs +0 -4
  22. package/lib/_virtual/PluginConfigurator.mjs.map +0 -1
  23. package/lib/_virtual/TypiaSetupWizard.mjs +0 -4
  24. package/lib/_virtual/TypiaSetupWizard.mjs.map +0 -1
  25. package/lib/executable/TypiaSetupWizard.d.ts +0 -7
  26. package/lib/executable/TypiaSetupWizard.js +0 -133
  27. package/lib/executable/TypiaSetupWizard.js.map +0 -1
  28. package/lib/executable/TypiaSetupWizard.mjs +0 -3
  29. package/lib/executable/TypiaSetupWizard.mjs.map +0 -1
  30. package/lib/executable/TypiaSetupWizard2.mjs +0 -144
  31. package/lib/executable/TypiaSetupWizard2.mjs.map +0 -1
  32. package/lib/executable/setup/ArgumentParser.d.ts +0 -7
  33. package/lib/executable/setup/ArgumentParser.js +0 -36
  34. package/lib/executable/setup/ArgumentParser.js.map +0 -1
  35. package/lib/executable/setup/ArgumentParser.mjs +0 -3
  36. package/lib/executable/setup/ArgumentParser.mjs.map +0 -1
  37. package/lib/executable/setup/ArgumentParser2.mjs +0 -41
  38. package/lib/executable/setup/ArgumentParser2.mjs.map +0 -1
  39. package/lib/executable/setup/CommandExecutor.d.ts +0 -3
  40. package/lib/executable/setup/CommandExecutor.js +0 -15
  41. package/lib/executable/setup/CommandExecutor.js.map +0 -1
  42. package/lib/executable/setup/CommandExecutor.mjs +0 -3
  43. package/lib/executable/setup/CommandExecutor.mjs.map +0 -1
  44. package/lib/executable/setup/CommandExecutor2.mjs +0 -19
  45. package/lib/executable/setup/CommandExecutor2.mjs.map +0 -1
  46. package/lib/executable/setup/FileRetriever.d.ts +0 -7
  47. package/lib/executable/setup/FileRetriever.js +0 -25
  48. package/lib/executable/setup/FileRetriever.js.map +0 -1
  49. package/lib/executable/setup/FileRetriever.mjs +0 -3
  50. package/lib/executable/setup/FileRetriever.mjs.map +0 -1
  51. package/lib/executable/setup/FileRetriever2.mjs +0 -30
  52. package/lib/executable/setup/FileRetriever2.mjs.map +0 -1
  53. package/lib/executable/setup/PackageManager.d.ts +0 -24
  54. package/lib/executable/setup/PackageManager.js +0 -79
  55. package/lib/executable/setup/PackageManager.js.map +0 -1
  56. package/lib/executable/setup/PackageManager.mjs +0 -3
  57. package/lib/executable/setup/PackageManager.mjs.map +0 -1
  58. package/lib/executable/setup/PackageManager2.mjs +0 -88
  59. package/lib/executable/setup/PackageManager2.mjs.map +0 -1
  60. package/lib/executable/setup/PluginConfigurator.d.ts +0 -4
  61. package/lib/executable/setup/PluginConfigurator.js +0 -60
  62. package/lib/executable/setup/PluginConfigurator.js.map +0 -1
  63. package/lib/executable/setup/PluginConfigurator.mjs +0 -3
  64. package/lib/executable/setup/PluginConfigurator.mjs.map +0 -1
  65. package/lib/executable/setup/PluginConfigurator2.mjs +0 -65
  66. package/lib/executable/setup/PluginConfigurator2.mjs.map +0 -1
  67. package/src/executable/TypiaSetupWizard.ts +0 -167
  68. package/src/executable/setup/ArgumentParser.ts +0 -42
  69. package/src/executable/setup/CommandExecutor.ts +0 -8
  70. package/src/executable/setup/FileRetriever.ts +0 -19
  71. package/src/executable/setup/PackageManager.ts +0 -87
  72. package/src/executable/setup/PluginConfigurator.ts +0 -65
@@ -1,167 +0,0 @@
1
- import fs from "fs";
2
- import { DetectResult, detect } from "package-manager-detector";
3
-
4
- import { ArgumentParser } from "./setup/ArgumentParser";
5
- import { PackageManager } from "./setup/PackageManager";
6
- import { PluginConfigurator } from "./setup/PluginConfigurator";
7
-
8
- export namespace TypiaSetupWizard {
9
- const TTSC_PACKAGE = "ttsc";
10
- const TSGO_COMPILER_PACKAGE = "@typescript/native-preview";
11
-
12
- export interface IArguments {
13
- manager: "npm" | "pnpm" | "yarn" | "bun";
14
- project: string | null;
15
- }
16
-
17
- export const setup = async (): Promise<void> => {
18
- console.log("----------------------------------------");
19
- console.log(" Typia Setup Wizard");
20
- console.log("----------------------------------------");
21
-
22
- // PREPARE ASSETS
23
- const pack: PackageManager = await PackageManager.mount();
24
- const args: IArguments = await ArgumentParser.parse(pack, inquiry);
25
-
26
- args.project ??= (() => {
27
- fs.writeFileSync(
28
- "tsconfig.json",
29
- `${JSON.stringify({ compilerOptions: {} }, null, 2)}\n`,
30
- "utf8",
31
- );
32
- return (args.project = "tsconfig.json");
33
- })();
34
-
35
- // CONFIGURE TYPIA
36
- await PluginConfigurator.configure(args);
37
-
38
- // NORMALIZE PROJECT SETTINGS
39
- await pack.save((data) => {
40
- if (typeof data.scripts?.prepare === "string") {
41
- const prepare = removeLegacyCompilerPatchSteps(data.scripts.prepare);
42
- if (prepare.length !== 0) data.scripts.prepare = prepare;
43
- else delete data.scripts.prepare;
44
- if (Object.keys(data.scripts).length === 0) delete data.scripts;
45
- }
46
- if (data.devDependencies?.["ts-patch"] !== undefined) {
47
- delete data.devDependencies["ts-patch"];
48
- if (Object.keys(data.devDependencies).length === 0)
49
- delete data.devDependencies;
50
- }
51
- if (data.dependencies?.["ts-patch"] !== undefined) {
52
- delete data.dependencies["ts-patch"];
53
- if (Object.keys(data.dependencies).length === 0)
54
- delete data.dependencies;
55
- }
56
- });
57
-
58
- // INSTALL TSGO TOOLCHAIN
59
- pack.install({
60
- dev: true,
61
- modulo: TSGO_COMPILER_PACKAGE,
62
- version: "latest",
63
- });
64
- pack.install({ dev: true, modulo: TTSC_PACKAGE, version: "latest" });
65
- };
66
-
67
- const inquiry: ArgumentParser.Inquiry<IArguments> = async (
68
- pack,
69
- command,
70
- prompt,
71
- action,
72
- ) => {
73
- // PREPARE ASSETS
74
- command.option("--manager [manager", "package manager");
75
- command.option("--project [project]", "tsconfig.json file location");
76
-
77
- // INTERNAL PROCEDURES
78
- const questioned = { value: false };
79
- const select =
80
- (name: string) =>
81
- (message: string) =>
82
- async <Choice extends string>(
83
- choices: Choice[],
84
- filter?: (choice: string) => Choice,
85
- ): Promise<Choice> => {
86
- questioned.value = true;
87
- return (
88
- await prompt()({
89
- type: "list",
90
- name: name,
91
- message: message,
92
- choices: choices,
93
- ...(filter ? { filter } : {}),
94
- })
95
- )[name];
96
- };
97
- const configure = async (): Promise<string | null> => {
98
- const fileList: string[] = await (
99
- await fs.promises.readdir(process.cwd())
100
- )
101
- .filter(
102
- (str) =>
103
- str.substring(0, 8) === "tsconfig" &&
104
- str.substring(str.length - 5) === ".json",
105
- )
106
- .sort((x, y) =>
107
- x === "tsconfig.json"
108
- ? -1
109
- : y === "tsconfig.json"
110
- ? 1
111
- : x < y
112
- ? -1
113
- : 1,
114
- );
115
- if (fileList.length === 0) {
116
- if (process.cwd() !== pack.directory)
117
- throw new URIError(`Unable to find "tsconfig.json" file.`);
118
- return null;
119
- } else if (fileList.length === 1) return fileList[0]!;
120
- return select("tsconfig")("TS Config File")(fileList);
121
- };
122
-
123
- // DO CONSTRUCT
124
- return action(async (options) => {
125
- pack.manager = options.manager ??=
126
- (await detectManager()) ??
127
- (await select("manager")("Package Manager")(
128
- [
129
- "npm" as const,
130
- "pnpm" as const,
131
- "bun" as const,
132
- "yarn (berry is not supported)" as "yarn",
133
- ],
134
- (value) => value.split(" ")[0] as "yarn",
135
- ));
136
- options.project ??= await configure();
137
-
138
- if (questioned.value) console.log("");
139
- return options as IArguments;
140
- });
141
- };
142
-
143
- const detectManager = async (): Promise<
144
- "npm" | "pnpm" | "yarn" | "bun" | null
145
- > => {
146
- const result: DetectResult | null = await detect({ cwd: process.cwd() });
147
- switch (result?.name) {
148
- case "npm":
149
- case "deno":
150
- return null; // NPM case is still selectable & Deno is not supported
151
- default:
152
- return result?.name ?? null;
153
- }
154
- };
155
-
156
- const isLegacyCompilerPatchStep = (str: string): boolean =>
157
- str === "typia patch" || str.includes("ts-patch install");
158
-
159
- const removeLegacyCompilerPatchSteps = (script: string): string =>
160
- script
161
- .split("&&")
162
- .map((str) => str.trim())
163
- .filter(
164
- (str) => str.length !== 0 && isLegacyCompilerPatchStep(str) === false,
165
- )
166
- .join(" && ");
167
- }
@@ -1,42 +0,0 @@
1
- import commander from "commander";
2
- import inquirer from "inquirer";
3
-
4
- import { PackageManager } from "./PackageManager";
5
-
6
- export namespace ArgumentParser {
7
- export type Inquiry<T> = (
8
- pack: PackageManager,
9
- command: commander.Command,
10
- prompt: (opt?: inquirer.StreamOptions) => inquirer.PromptModule,
11
- action: (closure: (options: Partial<T>) => Promise<T>) => Promise<T>,
12
- ) => Promise<T>;
13
-
14
- export const parse = async <T>(
15
- pack: PackageManager,
16
- inquiry: (
17
- pack: PackageManager,
18
- command: commander.Command,
19
- prompt: (opt?: inquirer.StreamOptions) => inquirer.PromptModule,
20
- action: (closure: (options: Partial<T>) => Promise<T>) => Promise<T>,
21
- ) => Promise<T>,
22
- ): Promise<T> => {
23
- // TAKE OPTIONS
24
- const action = (closure: (options: Partial<T>) => Promise<T>) =>
25
- new Promise<T>((resolve, reject) => {
26
- commander.program.action(async (options) => {
27
- try {
28
- resolve(await closure(options));
29
- } catch (exp) {
30
- reject(exp);
31
- }
32
- });
33
- commander.program.parseAsync().catch(reject);
34
- });
35
- return inquiry(
36
- pack,
37
- commander.program,
38
- inquirer.createPromptModule,
39
- action,
40
- );
41
- };
42
- }
@@ -1,8 +0,0 @@
1
- import cp from "child_process";
2
-
3
- export namespace CommandExecutor {
4
- export const run = (str: string): void => {
5
- console.log(`\n$ ${str}`);
6
- cp.execSync(str, { stdio: "inherit" });
7
- };
8
- }
@@ -1,19 +0,0 @@
1
- import fs from "fs";
2
- import path from "path";
3
-
4
- export namespace FileRetriever {
5
- export const directory = (props: {
6
- file: string;
7
- location: string;
8
- depth?: number;
9
- }): string | null => {
10
- const location: string = path.join(props.location, props.file);
11
- if (fs.existsSync(location)) return props.location;
12
- else if ((props.depth ?? 0) > 2) return null;
13
- return directory({
14
- file: props.file,
15
- location: path.join(props.location, ".."),
16
- depth: (props.depth ?? 0) + 1,
17
- });
18
- };
19
- }
@@ -1,87 +0,0 @@
1
- import fs from "fs";
2
- import path from "path";
3
-
4
- import { CommandExecutor } from "./CommandExecutor";
5
- import { FileRetriever } from "./FileRetriever";
6
-
7
- export class PackageManager {
8
- public manager: Manager = "npm";
9
- public get file(): string {
10
- return path.join(this.directory, "package.json");
11
- }
12
-
13
- public static async mount(): Promise<PackageManager> {
14
- const location: string | null = await FileRetriever.directory({
15
- file: "package.json",
16
- location: process.cwd(),
17
- });
18
- if (location === null)
19
- throw new URIError(`Unable to find "package.json" file`);
20
-
21
- return new PackageManager(
22
- location,
23
- await this.load(path.join(location, "package.json")),
24
- );
25
- }
26
-
27
- public async save(modifier: (data: Package.Data) => void): Promise<void> {
28
- const content: string = await fs.promises.readFile(this.file, "utf8");
29
- this.data = JSON.parse(content);
30
- modifier(this.data);
31
-
32
- return fs.promises.writeFile(
33
- this.file,
34
- JSON.stringify(this.data, null, 2),
35
- "utf8",
36
- );
37
- }
38
-
39
- public install(props: {
40
- dev: boolean;
41
- modulo: string;
42
- version: string;
43
- }): boolean {
44
- const middle: string = [
45
- installCmdTable[this.manager],
46
- props.dev ? devOptionTable[this.manager] : "",
47
- ]
48
- .filter((str) => !!str.length)
49
- .join(" ");
50
- const modulo: string = `${props.modulo}${props.version ? `@${props.version}` : ""}`;
51
- CommandExecutor.run([this.manager, middle, modulo].join(" "));
52
- return true;
53
- }
54
-
55
- private constructor(
56
- public readonly directory: string,
57
- public data: Package.Data,
58
- ) {}
59
-
60
- private static async load(file: string): Promise<Package.Data> {
61
- const content: string = await fs.promises.readFile(file, "utf8");
62
- return JSON.parse(content);
63
- }
64
- }
65
- export namespace Package {
66
- export interface Data {
67
- scripts?: Record<string, string>;
68
- dependencies?: Record<string, string>;
69
- devDependencies?: Record<string, string>;
70
- }
71
- }
72
-
73
- type Manager = "npm" | "pnpm" | "yarn" | "bun";
74
-
75
- const installCmdTable = {
76
- npm: "i",
77
- pnpm: "add",
78
- yarn: "add",
79
- bun: "add",
80
- } as const satisfies Record<Manager, string>;
81
-
82
- const devOptionTable = {
83
- npm: "-D",
84
- pnpm: "-D",
85
- yarn: "-D",
86
- bun: "-d",
87
- } as const satisfies Record<Manager, string>;
@@ -1,65 +0,0 @@
1
- import comments from "comment-json";
2
- import fs from "fs";
3
-
4
- import type { TypiaSetupWizard } from "../TypiaSetupWizard";
5
-
6
- export namespace PluginConfigurator {
7
- const TYPIA_TRANSFORM = "typia/lib/transform";
8
-
9
- export async function configure(
10
- args: TypiaSetupWizard.IArguments,
11
- ): Promise<void> {
12
- // GET COMPILER-OPTIONS
13
- const config: comments.CommentObject = comments.parse(
14
- await fs.promises.readFile(args.project!, "utf8"),
15
- ) as comments.CommentObject;
16
- const compilerOptions = (config.compilerOptions ??=
17
- {} as comments.CommentObject) as comments.CommentObject;
18
-
19
- // PREPARE PLUGINS
20
- const plugins: comments.CommentArray<comments.CommentObject> = (() => {
21
- const plugins = compilerOptions.plugins as
22
- | comments.CommentArray<comments.CommentObject>
23
- | undefined;
24
- if (plugins === undefined) return (compilerOptions.plugins = [] as any);
25
- else if (!Array.isArray(plugins))
26
- throw new TypeError(
27
- `"plugins" property of ${args.project} must be array type.`,
28
- );
29
- return plugins;
30
- })();
31
-
32
- const strict: boolean | undefined = compilerOptions.strict as
33
- | boolean
34
- | undefined;
35
- const strictNullChecks: boolean | undefined =
36
- compilerOptions.strictNullChecks as boolean | undefined;
37
- const skipLibCheck: boolean | undefined = compilerOptions.skipLibCheck as
38
- | boolean
39
- | undefined;
40
- const filtered: comments.CommentObject[] = plugins.filter(
41
- (p) =>
42
- typeof p === "object" && p !== null && p.transform !== TYPIA_TRANSFORM,
43
- ) as comments.CommentObject[];
44
- filtered.push({
45
- transform: TYPIA_TRANSFORM,
46
- } as unknown as comments.CommentObject);
47
- const changed: boolean =
48
- JSON.stringify(filtered) !== JSON.stringify(plugins) ||
49
- strictNullChecks === false ||
50
- (strict !== true && strictNullChecks !== true) ||
51
- skipLibCheck !== true;
52
- if (changed === false) return;
53
-
54
- // DO CONFIGURE
55
- compilerOptions.skipLibCheck = true;
56
- compilerOptions.strictNullChecks = true;
57
- if (strict === undefined && strictNullChecks === undefined)
58
- compilerOptions.strict = true;
59
- compilerOptions.plugins = filtered as any;
60
- await fs.promises.writeFile(
61
- args.project!,
62
- comments.stringify(config, null, 2),
63
- );
64
- }
65
- }