Skip to content

Commit

Permalink
Fix #744 - change setup wizard to deprecate yarn berry.
Browse files Browse the repository at this point in the history
  - Changed setup wizard
  - Introduce not to support `yarn berry`
  - Use `npm run postinstall` command instead

Unfortunately, `ts-patch` does not support `yarn berry`. Therefore, it is not possible to use transform mode of `typia` in the `yarn berry`. Therefore, to inform it and recommend not to use `yarn berry` in `typia`, I've changed setup wizard program.

Also, `yarn` berry` does not support the `npm run prepare` command. I think this nonsensible story because the `npm run prepare` command is a standard feature of NPM, but this is the reality, so I can't help it. By the way, if `ts-patch` starts supporting `yarn berry`, configuring `npm run prepare` command by setup wizard can be a big problem. So, I've changed setup wizard to use `npm run postinstall` command instead of the previous `npm run prepare` command.
  • Loading branch information
samchon committed Aug 7, 2023
1 parent cea1b45 commit f5a475d
Show file tree
Hide file tree
Showing 8 changed files with 211 additions and 43 deletions.
4 changes: 2 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "typia",
"version": "4.1.16",
"version": "4.2.0",
"description": "Superfast runtime validators with only one line",
"main": "lib/index.js",
"typings": "lib/index.d.ts",
Expand Down Expand Up @@ -128,7 +128,7 @@
"zod": "^3.19.1"
},
"stackblitzs": {
"startCommand": "npm run prepare && npm run build && npm run build:test && npm run test"
"startCommand": "npm run postinstall && npm run build && npm run build:test && npm run test"
},
"files": [
"LICENSE",
Expand Down
6 changes: 3 additions & 3 deletions packages/typescript-json/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "typescript-json",
"version": "4.1.16",
"version": "4.2.0",
"description": "Superfast runtime validators with only one line",
"main": "lib/index.js",
"typings": "lib/index.d.ts",
Expand Down Expand Up @@ -68,13 +68,13 @@
},
"homepage": "https://typia.io",
"dependencies": {
"typia": "4.1.16"
"typia": "4.2.0"
},
"peerDependencies": {
"typescript": ">= 4.7.4"
},
"stackblitzs": {
"startCommand": "npm run prepare && npm run build && npm run build:test && npm run test"
"startCommand": "npm run postinstall && npm run build && npm run build:test && npm run test"
},
"files": [
"LICENSE",
Expand Down
38 changes: 27 additions & 11 deletions src/executable/TypiaSetupWizard.ts
Original file line number Diff line number Diff line change
Expand Up @@ -40,23 +40,37 @@ export namespace TypiaSetupWizard {
})(),
});
args.project ??= (() => {
CommandExecutor.run("npx tsc --init");
const runner: string =
pack.manager === "npm" ? "npx" : pack.manager;
CommandExecutor.run(`${runner} tsc --init`);
return (args.project = "tsconfig.json");
})();

// SETUP TRANSFORMER
await pack.save((data) => {
// COMPOSE POSTINSTALL COMMAND
data.scripts ??= {};
if (
typeof data.scripts.prepare === "string" &&
data.scripts.prepare.length
typeof data.scripts.postinstall === "string" &&
data.scripts.postinstall.trim().length
) {
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";
if (data.scripts.postinstall.indexOf("ts-patch install") === -1)
data.scripts.postinstall =
"ts-patch install && " + data.scripts.postinstall;
} else data.scripts.postinstall = "ts-patch install";

// FOR OLDER VERSIONS
if (typeof data.scripts.prepare === "string") {
data.scripts.prepare = data.scripts.prepare
.split("&&")
.map((str) => str.trim())
.filter((str) => str.indexOf("ts-patch install") === -1)
.join(" && ");
if (data.scripts.prepare.length === 0)
delete data.scripts.prepare;
}
});
CommandExecutor.run("npm run prepare");
CommandExecutor.run(`${pack.manager} run postinstall`);

// CONFIGURE TYPIA
await PluginConfigurator.configure(args);
Expand Down Expand Up @@ -87,6 +101,7 @@ export namespace TypiaSetupWizard {
name: name,
message: message,
choices: choices,
filter: (value) => value.split(" ")[0],
})
)[name];
};
Expand Down Expand Up @@ -118,12 +133,13 @@ export namespace TypiaSetupWizard {

// DO CONSTRUCT
return action(async (options) => {
options.manager ??= await select("manager")("Package Manager")([
pack.manager = options.manager ??= await select("manager")(
"Package Manager",
)([
"npm" as const,
"pnpm" as const,
"yarn" as const,
"yarn (berry is not supported)" as "yarn",
]);
pack.manager = options.manager;
options.project ??= await configure();

if (questioned.value) console.log("");
Expand Down
3 changes: 2 additions & 1 deletion src/executable/setup/CommandExecutor.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ import cp from "child_process";
export namespace CommandExecutor {
export const run = (str: string): void => {
console.log(str);
cp.execSync(str, { stdio: "ignore" });
cp.execSync(str, { stdio: "inherit" });
// @todo - rollback to ignore
};
}
8 changes: 4 additions & 4 deletions website/package-lock.json

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

2 changes: 1 addition & 1 deletion website/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@
"react": "^18.2.0",
"react-dom": "^18.2.0",
"typescript": "5.1.6",
"typia": "^4.1.14"
"typia": "^4.2.0"
},
"devDependencies": {
"@trivago/prettier-plugin-sort-imports": "^4.1.1",
Expand Down
Loading

0 comments on commit f5a475d

Please sign in to comment.