From ec92d2f1a5ea231ea71adcc7fb2500a5322e1a11 Mon Sep 17 00:00:00 2001 From: Jeongho Nam <samchon.github@gmail.com> Date: Thu, 23 Nov 2023 19:52:47 +0900 Subject: [PATCH 1/2] Prepare temporary way for `jsDocParsingMode` patch. If `ts-patch` update be delayed for a long time, `typia` will hack the `jsDocParsingMode` by itself. Of course, this is beta plan that would be discarded if `ts-patch` supports TypeScript v5.3 in near time. --- package.json | 8 ++++---- src/executable/TypiaPatchWizard.ts | 31 ++++++++++++++++++++++++++++++ src/executable/TypiaSetupWizard.ts | 17 ++++++++++++++-- src/executable/typia.ts | 3 +++ 4 files changed, 53 insertions(+), 6 deletions(-) create mode 100644 src/executable/TypiaPatchWizard.ts diff --git a/package.json b/package.json index dba0e62f97..833164428e 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "typia", - "version": "5.3.0-dev.20231122", + "version": "5.3.0-dev.20231123", "description": "Superfast runtime validators with only one line", "main": "lib/index.js", "typings": "lib/index.d.ts", @@ -81,7 +81,7 @@ "randexp": "^0.5.3" }, "peerDependencies": { - "typescript": ">=4.8.0 <5.3.0" + "typescript": ">=4.8.0 <5.4.0" }, "devDependencies": { "@fastify/type-provider-typebox": "^3.5.0", @@ -128,7 +128,7 @@ "ts-node": "^10.9.1", "ts-patch": "^3.0.2", "tstl": "^2.5.13", - "typescript": "5.2.2", + "typescript": "^5.3.2", "typescript-transform-paths": "^3.4.6", "uuid": "^8.3.2", "zod": "^3.19.1" @@ -144,4 +144,4 @@ "src" ], "private": true -} \ No newline at end of file +} diff --git a/src/executable/TypiaPatchWizard.ts b/src/executable/TypiaPatchWizard.ts new file mode 100644 index 0000000000..01ff6df87e --- /dev/null +++ b/src/executable/TypiaPatchWizard.ts @@ -0,0 +1,31 @@ +import fs from "fs"; + +export namespace TypiaPatchWizard { + export const main = async (): Promise<void> => { + console.log("----------------------------------------"); + console.log(" Typia Setup Wizard"); + console.log("----------------------------------------"); + console.log( + [ + `Since TypeScript v5.3 update, "tsc" no more parses JSDoc comments.`, + ``, + `Therefore, "typia" revives the JSDoc parsing feature by patching "tsc".`, + ``, + `This is a temporary feature of "typia", and it would be removed when "ts-patch" being updated.`, + ].join("\n"), + ); + + await patch(); + }; + + export const patch = async (): Promise<void> => { + const location: string = require.resolve("typescript/lib/tsc.js"); + const content: string = await fs.promises.readFile(location, "utf8"); + if (content.indexOf(TO) === -1) return; + + await fs.promises.writeFile(location, content.replace(FROM, TO), "utf8"); + }; +} + +const FROM = `var defaultJSDocParsingMode = 2 /* ParseForTypeErrors */`; +const TO = `var defaultJSDocParsingMode = 0 /* ParseAll */`; diff --git a/src/executable/TypiaSetupWizard.ts b/src/executable/TypiaSetupWizard.ts index 37045cbfb6..396cece5c5 100644 --- a/src/executable/TypiaSetupWizard.ts +++ b/src/executable/TypiaSetupWizard.ts @@ -1,5 +1,6 @@ import fs from "fs"; +import { TypiaPatchWizard } from "./TypiaPatchWizard"; import { ArgumentParser } from "./setup/ArgumentParser"; import { CommandExecutor } from "./setup/CommandExecutor"; import { PackageManager } from "./setup/PackageManager"; @@ -38,9 +39,20 @@ export namespace TypiaSetupWizard { typeof data.scripts.prepare === "string" && data.scripts.prepare.trim().length ) { - if (data.scripts.prepare.indexOf("ts-patch install") === -1) + if ( + data.scripts.prepare.indexOf("ts-patch install") === -1 && + data.scripts.prepare.indexOf("typia patch") === -1 + ) + data.scripts.prepare = + "ts-patch install && typia patch && " + data.scripts.prepare; + else if (data.scripts.prepare.indexOf("ts-patch install") === -1) data.scripts.prepare = "ts-patch install && " + data.scripts.prepare; - } else data.scripts.prepare = "ts-patch install"; + else if (data.scripts.prepare.indexOf("typia patch") === -1) + data.scripts.prepare = data.scripts.prepare.replace( + "ts-patch install", + "ts-patch install && typia patch", + ); + } else data.scripts.prepare = "ts-patch install && typia patch"; // FOR OLDER VERSIONS if (typeof data.scripts.postinstall === "string") { @@ -53,6 +65,7 @@ export namespace TypiaSetupWizard { delete data.scripts.postinstall; } }); + await TypiaPatchWizard.patch(); CommandExecutor.run(`${pack.manager} run prepare`); // CONFIGURE TYPIA diff --git a/src/executable/typia.ts b/src/executable/typia.ts index e61956c423..bcdde5793a 100644 --- a/src/executable/typia.ts +++ b/src/executable/typia.ts @@ -34,6 +34,9 @@ const main = async (): Promise<void> => { if (type === "setup") { const { TypiaSetupWizard } = await import("./TypiaSetupWizard"); await TypiaSetupWizard.setup(); + } else if (type === "patch") { + const { TypiaPatchWizard } = await import("./TypiaPatchWizard"); + await TypiaPatchWizard.main(); } else if (type === "generate") { try { await import("typescript"); From 7b154d7e18736195795d8aebad695ce187bc2c74 Mon Sep 17 00:00:00 2001 From: Jeongho Nam <samchon.github@gmail.com> Date: Sun, 26 Nov 2023 23:09:45 +0900 Subject: [PATCH 2/2] Complete documentation --- deploy/internal/ReplicaPublisher.ts | 24 ++++++++-------- package.json | 2 +- packages/benchmark/package.json | 2 +- packages/errors/package.json | 2 +- packages/test/package.json | 2 +- packages/typescript-json/package.json | 40 ++++++++------------------- src/executable/TypiaSetupWizard.ts | 2 +- src/transformers/FileTransformer.ts | 6 ++-- website/package-lock.json | 18 ++++++------ website/package.json | 4 +-- website/pages/docs/setup.mdx | 17 +++++++++++- 11 files changed, 58 insertions(+), 61 deletions(-) diff --git a/deploy/internal/ReplicaPublisher.ts b/deploy/internal/ReplicaPublisher.ts index 54e4ad5f24..c9063487bc 100644 --- a/deploy/internal/ReplicaPublisher.ts +++ b/deploy/internal/ReplicaPublisher.ts @@ -4,25 +4,24 @@ import fs from "fs"; export namespace ReplicaPublisher { export function replica(tag: string): void { // PREPARE DIRECTORY - if (fs.existsSync(PACKAGES)) cp.execSync(`rimraf ${PACKAGES}`); - fs.mkdirSync(PACKAGES); - fs.mkdirSync(typia); + if (fs.existsSync(LEGACY)) cp.execSync(`rimraf ${LEGACY}`); + fs.mkdirSync(LEGACY); // COPY ESSENTIAL FILES for (const file of ["package.json", "LICENSE", "tsconfig.json"]) - fs.copyFileSync(`${ROOT}/${file}`, `${typia}/${file}`); + fs.copyFileSync(`${ROOT}/${file}`, `${LEGACY}/${file}`); readme(); // CREATE RE-EXPORT FILES - fs.mkdirSync(`${typia}/src`); - link(LIB, `${typia}/src`); + fs.mkdirSync(`${LEGACY}/src`); + link(LIB, `${LEGACY}/src`); // CHANGE PACKAGE.JSON CONTENT pack(); // DO BUILD & PUBLISH try { - cp.execSync("npx tsc", { cwd: typia }); + cp.execSync("npx tsc", { cwd: LEGACY }); } catch {} console.log("publish typescript-json (replica)"); @@ -32,7 +31,7 @@ export namespace ReplicaPublisher { function readme(): void { const content: string = fs.readFileSync(`${ROOT}/README.md`, "utf8"); fs.writeFileSync( - `${typia}/README.md`, + `${LEGACY}/README.md`, "> ## Deprecated\n" + "> `typescript-json` has been renamed to [`typia`](https://github.com/samchon/typia)" + "\n\n" + @@ -72,7 +71,7 @@ export namespace ReplicaPublisher { function pack(): void { const pack: any = JSON.parse( - fs.readFileSync(`${typia}/package.json`, "utf8"), + fs.readFileSync(`${LEGACY}/package.json`, "utf8"), ); pack.name = "typescript-json"; @@ -84,7 +83,7 @@ export namespace ReplicaPublisher { delete pack.bin; fs.writeFileSync( - `${typia}/package.json`, + `${LEGACY}/package.json`, JSON.stringify(pack, null, 2), "utf8", ); @@ -93,13 +92,12 @@ export namespace ReplicaPublisher { function publish(command: string): void { try { cp.execSync(command, { - cwd: typia, + cwd: LEGACY, }); } catch {} } } const ROOT: string = __dirname + "/../.."; -const PACKAGES: string = ROOT + "/packages"; -const typia: string = PACKAGES + "/typescript-json"; +const LEGACY: string = ROOT + "/packages/typescript-json"; const LIB = `${__dirname}/../../lib`; diff --git a/package.json b/package.json index 452ca91c67..0c028e3b01 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "typia", - "version": "5.3.0-dev.20231123", + "version": "5.3.0-dev.20231126-2", "description": "Superfast runtime validators with only one line", "main": "lib/index.js", "typings": "lib/index.d.ts", diff --git a/packages/benchmark/package.json b/packages/benchmark/package.json index 9d684d27bd..48892ea695 100644 --- a/packages/benchmark/package.json +++ b/packages/benchmark/package.json @@ -73,6 +73,6 @@ "suppress-warnings": "^1.0.2", "tstl": "^2.5.13", "uuid": "^9.0.1", - "typia": "D:\\github\\samchon\\typia\\typia-5.3.0-dev.20231122.tgz" + "typia": "D:\\github\\samchon\\typia\\typia-5.3.0-dev.20231126-2.tgz" } } \ No newline at end of file diff --git a/packages/errors/package.json b/packages/errors/package.json index 26abfa87eb..45189cf6dc 100644 --- a/packages/errors/package.json +++ b/packages/errors/package.json @@ -32,6 +32,6 @@ "typescript": "^5.3.2" }, "dependencies": { - "typia": "D:\\github\\samchon\\typia\\typia-5.3.0-dev.20231123.tgz" + "typia": "D:\\github\\samchon\\typia\\typia-5.3.0-dev.20231126-2.tgz" } } \ No newline at end of file diff --git a/packages/test/package.json b/packages/test/package.json index 9aca8bd3f4..84d5c102f9 100644 --- a/packages/test/package.json +++ b/packages/test/package.json @@ -46,6 +46,6 @@ "suppress-warnings": "^1.0.2", "tstl": "^2.5.13", "uuid": "^9.0.1", - "typia": "D:\\github\\samchon\\typia\\typia-5.3.0-dev.20231123.tgz" + "typia": "D:\\github\\samchon\\typia\\typia-5.3.0-dev.20231126-2.tgz" } } \ No newline at end of file diff --git a/packages/typescript-json/package.json b/packages/typescript-json/package.json index 0c28c5f992..e8d3174b15 100644 --- a/packages/typescript-json/package.json +++ b/packages/typescript-json/package.json @@ -1,39 +1,23 @@ { "name": "typescript-json", - "version": "5.3.0-dev.20231122", + "version": "5.3.0-dev.20231126-2", "description": "Superfast runtime validators with only one line", "main": "lib/index.js", "typings": "lib/index.d.ts", "scripts": { - "benchmark": "npm run build:benchmark && node measure/benchmark", - "benchmark:generate": "ts-node benchmark/generate && npm run build:benchmark", - "test:generate": "npx ts-node src/executable/typia generate --input test/features --output test/generated/output --project test/tsconfig.json", - "test:template": "npx tsc && ts-node -P build/tsconfig.json build/test.ts", - "----------------------------------------------": "", + "test": "npm run package:tgz", + "-------------------------------------------------": "", "build": "rimraf lib && tsc --removeComments --declaration false && tsc --emitDeclarationOnly", - "build:test": "rimraf bin && tsc -p test/tsconfig.json", - "build:test:actions": "rimraf bin && tsc -p test/tsconfig.actions.json", - "build:test:issues": "rimraf bin && tsc -p test/tsconfig.issue.json", - "build:benchmark": "rimraf measure && tsc -p benchmark/tsconfig.json", - "build:test:errors": "rimraf errors/bin && tsc -p errors/tsconfig.json", - "build:test:prettier": "npm run build:test && prettier --write ./bin/**/*.js", "dev": "rimraf lib && tsc --watch", - "dev:test": "rimraf bin && tsc -p test/tsconfig.json --watch", "eslint": "eslint ./**/*.ts", "eslint:fix": "eslint ./**/*.ts --fix", - "prettier": "prettier --write ./**/*.ts", - "-----------------------------------------------": "", - "issue": "node test/issue", - "issue:generate": "ts-node src/executable/typia generate --input test/issues/generate/input --output test/issues/generate --project test/tsconfig.json", - "test": "node bin/test", - "test:errors": "node errors", - "test:manual": "node test/manual", + "prettier": "prettier src --write", "------------------------------------------------": "", - "package:latest": "ts-node build/publish.ts latest", - "package:next": "ts-node build/publish.ts next", - "package:patch": "ts-node build/publish.ts patch", - "package:deprecate": "npm deprecate typescript-json \"Renamed to typia\"", - "prepare": "ts-patch install" + "package:latest": "ts-node deploy latest", + "package:next": "ts-node deploy next", + "package:patch": "ts-node deploy patch", + "package:tgz": "ts-node deploy tgz", + "package:deprecate": "npm deprecate typescript-json \"Renamed to typia\"" }, "repository": { "type": "git", @@ -72,13 +56,13 @@ }, "homepage": "https://typia.io", "dependencies": { - "typia": "5.3.0-dev.20231122" + "typia": "5.3.0-dev.20231126-2" }, "peerDependencies": { - "typescript": ">=4.8.0 <5.3.0" + "typescript": ">=4.8.0 <5.4.0" }, "stackblitzs": { - "startCommand": "npm run prepare && npm run build:test:actions && npm run build:test && npm run test" + "startCommand": "npm install && npm run build && cd packages/test && npm install && npm run build:actions && npm start" }, "files": [ "LICENSE", diff --git a/src/executable/TypiaSetupWizard.ts b/src/executable/TypiaSetupWizard.ts index 396cece5c5..aedd2b6371 100644 --- a/src/executable/TypiaSetupWizard.ts +++ b/src/executable/TypiaSetupWizard.ts @@ -24,7 +24,7 @@ export namespace TypiaSetupWizard { // INSTALL TYPESCRIPT COMPILERS pack.install({ dev: true, modulo: "ts-patch", version: "latest" }); pack.install({ dev: true, modulo: "ts-node", version: "latest" }); - pack.install({ dev: true, modulo: "typescript", version: "5.2.2" }); + pack.install({ dev: true, modulo: "typescript", version: "5.3.2" }); args.project ??= (() => { const runner: string = pack.manager === "npm" ? "npx" : pack.manager; CommandExecutor.run(`${runner} tsc --init`); diff --git a/src/transformers/FileTransformer.ts b/src/transformers/FileTransformer.ts index 7ab8867810..4dbca098b2 100644 --- a/src/transformers/FileTransformer.ts +++ b/src/transformers/FileTransformer.ts @@ -76,11 +76,11 @@ const checkJsDocParsingMode = new Singleton( key: "jsDocParsingMode", category: ts.DiagnosticCategory.Warning, message: [ - `Run "npx typia setup" or "npx ts-patch install" command again.`, + `Run "npx typia setup" or "npx typia patch" command again.`, ``, - `Since TypeScript v5.3 update, "tsc" no more parses JSDoc comments. Therefore, "typia" also cannot utilize those JSDoc comments, and it would damage some features of "typia" like "comment tags" or "JSON schema" generator.`, + `Since TypeScript v5.3 update, "tsc" no more parses JSDoc comments. Therefore, "typia" also cannot utilize those JSDoc comments too, and it damages on some features of "typia" like "comment tags" or "JSON schema" generator.`, ``, - `To solve this problem, run "npx typia setup" or "ts-patch install" command again to hack the TypeScript compiler to revive the JSDoc parsing.`, + `To solve this problem, run "npx typia setup" or "npx typia patch" command to hack the TypeScript compiler to revive the JSDoc parsing feature.`, ``, ` - reference: https://github.com/microsoft/TypeScript/pull/55739`, ].join("\n"), diff --git a/website/package-lock.json b/website/package-lock.json index e5e331c124..542d5d2cd1 100644 --- a/website/package-lock.json +++ b/website/package-lock.json @@ -20,7 +20,7 @@ "nextra-theme-docs": "latest", "react": "^18.2.0", "react-dom": "^18.2.0", - "typescript": "^5.3.0-beta" + "typescript": "^5.3.2" }, "devDependencies": { "@trivago/prettier-plugin-sort-imports": "^4.1.1", @@ -31,7 +31,7 @@ "prettier": "^2.8.8", "rimraf": "^5.0.0", "ts-node": "^10.9.1", - "typia": "^5.3.0-dev.20231117" + "typia": "^5.3.0-dev.20231126-2" } }, "node_modules/@babel/code-frame": { @@ -7630,9 +7630,9 @@ } }, "node_modules/typescript": { - "version": "5.3.0-beta", - "resolved": "https://registry.npmjs.org/typescript/-/typescript-5.3.0-beta.tgz", - "integrity": "sha512-SiTeC1C8wAS6v2SD05iyfojeuIkUZIbb8suZz0d4BR+RErwpG+05iolat+VjM9hqXSrjb3xutEBzh4X3NJ7Jgw==", + "version": "5.3.2", + "resolved": "https://registry.npmjs.org/typescript/-/typescript-5.3.2.tgz", + "integrity": "sha512-6l+RyNy7oAHDfxC4FzSJcz9vnjTKxrLpDG5M2Vu4SHRVNg6xzqZp6LYSR9zjqQTu8DU/f5xwxUdADOkbrIX2gQ==", "bin": { "tsc": "bin/tsc", "tsserver": "bin/tsserver" @@ -7642,9 +7642,9 @@ } }, "node_modules/typia": { - "version": "5.3.0-dev.20231117", - "resolved": "https://registry.npmjs.org/typia/-/typia-5.3.0-dev.20231117.tgz", - "integrity": "sha512-u1oVVCq6t7t5ZSczawr1umHQtr5oiAhI49gP8N4TcOaolrWLQn/Vqd9CXC4q7L0igUBxfjyXrxnbEUZ55IgnJQ==", + "version": "5.3.0-dev.20231126-2", + "resolved": "https://registry.npmjs.org/typia/-/typia-5.3.0-dev.20231126-2.tgz", + "integrity": "sha512-MV8pZFHOol3eWYewhhg2ziGXybFDodPE7TvwW9Bi+sW+3dBEZcb75I6FhUMigzxY1SbyNmN+fcclIcyJqtDe+Q==", "dev": true, "dependencies": { "commander": "^10.0.0", @@ -7656,7 +7656,7 @@ "typia": "lib/executable/typia.js" }, "peerDependencies": { - "typescript": ">=4.8.0 <5.3.0" + "typescript": ">=4.8.0 <5.4.0" } }, "node_modules/typia/node_modules/commander": { diff --git a/website/package.json b/website/package.json index 6c844882d7..193a0da073 100644 --- a/website/package.json +++ b/website/package.json @@ -30,7 +30,7 @@ "nextra-theme-docs": "latest", "react": "^18.2.0", "react-dom": "^18.2.0", - "typescript": "^5.3.0-beta" + "typescript": "^5.3.2" }, "devDependencies": { "@trivago/prettier-plugin-sort-imports": "^4.1.1", @@ -41,6 +41,6 @@ "prettier": "^2.8.8", "rimraf": "^5.0.0", "ts-node": "^10.9.1", - "typia": "^5.3.0-dev.20231117" + "typia": "^5.3.0-dev.20231126-2" } } diff --git a/website/pages/docs/setup.mdx b/website/pages/docs/setup.mdx index e6c13bc385..d22f62f2e5 100644 --- a/website/pages/docs/setup.mdx +++ b/website/pages/docs/setup.mdx @@ -208,7 +208,7 @@ As `typia` generates optimal operation code through transformation, you've to co ```json filename="package.json" copy showLineNumbers {2-4} { "scripts": { - "prepare": "ts-patch install" + "prepare": "ts-patch install && typia patch" }, "dependencies": { "typia": "^4.1.8" @@ -246,6 +246,21 @@ Of course, you've to run the `npm run prepare` command after the configuration. For reference, [`ts-patch`](https://github.com/nonara/ts-patch) is an helper library of TypeScript compiler that supporting custom transformations by plugins. From now on, whenever you run `tsc` command, your `typia` function call statements would be transformed to the optimal operation codes in the compiled JavaScript files. +<br/> +<Alert severity="warning"> + + <AlertTitle> + **`npx typia patch`** + </AlertTitle> + +Since TypeScript v5.3 update, `tsc` no more parses `JSDocComment`s. Therefore, `typia` also cannot utilize those `JSDocComment` related features too, especially ["Comment Tags"](./validators/tags/#comment-tags) and ["JSON schema generator"](./json/schema). + +The `npx typia patch` command has been developed to revive the `JSDocComment` parsing feature of `tsc`. It is temporary solution for the TypeScript v5.3 update instead of [`ts-patch`](https://github.com/nonara/ts-patch), and will be disabled after [`ts-patch`](https://github.com/nonara/ts-patch) starts supporting such TypeScript v5.3 update. + +Of course, if you don't use any ["Comment Tags"](./validators/tags/#comment-tags) and ["JSON schema generator"](./json/schema), you don't need to run `npx typia patch` command. This is not mandatory command, but just optional command. + +</Alert> +