Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

New cli command npx typia patch for hacking defaultJSDocParsingMode value #883

Merged
merged 4 commits into from
Nov 26, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
24 changes: 11 additions & 13 deletions deploy/internal/ReplicaPublisher.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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)");
Expand All @@ -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" +
Expand Down Expand Up @@ -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";
Expand All @@ -84,7 +83,7 @@ export namespace ReplicaPublisher {
delete pack.bin;

fs.writeFileSync(
`${typia}/package.json`,
`${LEGACY}/package.json`,
JSON.stringify(pack, null, 2),
"utf8",
);
Expand All @@ -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`;
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "typia",
"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",
Expand Down
4 changes: 2 additions & 2 deletions packages/benchmark/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
"scripts": {
"build": "rimraf bin && tsc",
"build:actions": "rimraf bin && tsc -p tsconfig.actions.json",
"prepare": "ts-patch install",
"prepare": "ts-patch install && typia patch",
"prettier": "prettier ./src/**/*.ts --write",
"start": "node bin",
"template": "ts-node src/template && npm run prettier && npm run build"
Expand Down Expand Up @@ -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"
}
}
6 changes: 3 additions & 3 deletions packages/errors/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
"main": "index.js",
"scripts": {
"build": "rimraf bin && tsc",
"prepare": "ts-patch install",
"prepare": "ts-patch install && typia patch",
"prettier": "prettier ./src/**/*.ts --write",
"setup": "node build/setup.js",
"start": "node index"
Expand All @@ -29,9 +29,9 @@
"devDependencies": {
"rimraf": "^5.0.5",
"ts-patch": "^3.0.2",
"typescript": "5.2.2"
"typescript": "^5.3.2"
},
"dependencies": {
"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"
}
}
6 changes: 3 additions & 3 deletions packages/test/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
"scripts": {
"build": "rimraf bin && tsc",
"build:actions": "rimraf bin && tsc -p tsconfig.actions.json",
"prepare": "ts-patch install",
"prepare": "ts-patch install && typia patch",
"prettier": "prettier ./src/**/*.ts --write",
"setup": "node build/setup.js",
"start": "node bin",
Expand Down Expand Up @@ -36,7 +36,7 @@
"rimraf": "^5.0.5",
"ts-node": "^10.9.1",
"ts-patch": "^3.0.2",
"typescript": "5.2.2"
"typescript": "^5.3.2"
},
"dependencies": {
"cli": "^1.0.1",
Expand All @@ -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.20231122.tgz"
"typia": "D:\\github\\samchon\\typia\\typia-5.3.0-dev.20231126-2.tgz"
}
}
40 changes: 12 additions & 28 deletions packages/typescript-json/package.json
Original file line number Diff line number Diff line change
@@ -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",
Expand Down Expand Up @@ -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",
Expand Down
31 changes: 31 additions & 0 deletions src/executable/TypiaPatchWizard.ts
Original file line number Diff line number Diff line change
@@ -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(FROM) === -1) return;

await fs.promises.writeFile(location, content.replace(FROM, TO), "utf8");
};
}

const FROM = `var defaultJSDocParsingMode = 2 /* ParseForTypeErrors */`;
const TO = `var defaultJSDocParsingMode = 0 /* ParseAll */`;
19 changes: 16 additions & 3 deletions src/executable/TypiaSetupWizard.ts
Original file line number Diff line number Diff line change
@@ -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";
Expand All @@ -23,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`);
Expand All @@ -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") {
Expand All @@ -53,6 +65,7 @@ export namespace TypiaSetupWizard {
delete data.scripts.postinstall;
}
});
await TypiaPatchWizard.patch();
CommandExecutor.run(`${pack.manager} run prepare`);

// CONFIGURE TYPIA
Expand Down
3 changes: 3 additions & 0 deletions src/executable/typia.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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");
Expand Down
6 changes: 3 additions & 3 deletions src/transformers/FileTransformer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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"),
Expand Down
18 changes: 9 additions & 9 deletions website/package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 2 additions & 2 deletions website/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand All @@ -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"
}
}
Loading
Loading