Skip to content

Commit

Permalink
To support yarn berry which had banned npm prepare script, I'd ch…
Browse files Browse the repository at this point in the history
…anged setup wizard of `nestia` to define `npm postinstall` script instead.

By the way, unlike the `npm prepare` script which works on only in the local drive and does not work when be installed from remote `npm`, `npm postinstall` script is working even when installing from the remote `npm`. Therefore, when publishing an `npm` module which has installed `tyipa` through setup wizard, it enforces users of derived libraries to run the `npm postinstall` command that requires `ts-patch` module.

To fix this crazy bug, I've decided to ban `yarn berry` on the setup wizard. From now on, when you run the `npx nestia setup` command, it will print a text that "yarn berry is not supported". If you still want to utilize the `yarn berry`, configure it manually by yourself please.
  • Loading branch information
samchon committed Oct 11, 2023
1 parent 2ec3034 commit b17dd10
Show file tree
Hide file tree
Showing 15 changed files with 91 additions and 79 deletions.
2 changes: 1 addition & 1 deletion benchmark/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@
"homepage": "https://nestia.io",
"dependencies": {
"@nestia/core": "^2.0.5-dev.20230921",
"typia": "^5.2.0"
"typia": "^5.2.1"
},
"devDependencies": {
"@trivago/prettier-plugin-sort-imports": "^4.1.1",
Expand Down
5 changes: 3 additions & 2 deletions packages/cli/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "nestia",
"version": "4.5.0",
"version": "5.0.0",
"description": "Nestia CLI tool",
"main": "bin/index.js",
"bin": {
Expand All @@ -9,6 +9,7 @@
"scripts": {
"build": "rimraf bin && tsc",
"prettier": "prettier ./src/**/*.ts --write",
"package:latest": "npm run build && npm publish --access public --tag latest",
"package:next": "npm run build && npm publish --access public --tag next"
},
"repository": {
Expand Down Expand Up @@ -43,7 +44,7 @@
"@types/node": "^18.11.16",
"prettier": "^2.8.7",
"rimraf": "^3.0.2",
"typescript": "^5.2.0"
"typescript": "^5.2.1"
},
"files": [
"bin",
Expand Down
22 changes: 11 additions & 11 deletions packages/cli/src/NestiaSetupWizard.ts
Original file line number Diff line number Diff line change
Expand Up @@ -28,26 +28,26 @@ export namespace NestiaSetupWizard {

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

// FOR OLDER VERSIONS
if (typeof data.scripts.prepare === "string") {
data.scripts.prepare = data.scripts.prepare
if (typeof data.scripts.postinstall === "string") {
data.scripts.postinstall = data.scripts.postinstall
.split("&&")
.map((str) => str.trim())
.filter((str) => str.indexOf("ts-patch install") === -1)
.join(" && ");
if (data.scripts.prepare.length === 0)
delete data.scripts.prepare;
if (data.scripts.postinstall.length === 0)
delete data.scripts.postinstall;
}
});
CommandExecutor.run(`${pack.manager} run postinstall`);
Expand Down
10 changes: 5 additions & 5 deletions packages/core/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@nestia/core",
"version": "2.2.0",
"version": "2.2.1",
"description": "Super-fast validation decorators of NestJS",
"main": "lib/index.js",
"typings": "lib/index.d.ts",
Expand Down Expand Up @@ -34,7 +34,7 @@
},
"homepage": "https://nestia.io",
"dependencies": {
"@nestia/fetcher": "^2.2.0",
"@nestia/fetcher": "^2.2.1",
"@nestjs/common": ">=7.0.1",
"@nestjs/core": ">=7.0.1",
"@nestjs/platform-express": ">=7.0.1",
Expand All @@ -44,10 +44,10 @@
"raw-body": ">=2.0.0",
"reflect-metadata": ">=0.1.12",
"rxjs": ">=6.0.0",
"typia": ">=5.2.0 <6.0.0"
"typia": ">=5.2.1 <6.0.0"
},
"peerDependencies": {
"@nestia/fetcher": ">=2.2.0",
"@nestia/fetcher": ">=2.2.1",
"@nestjs/common": ">=7.0.1",
"@nestjs/core": ">=7.0.1",
"@nestjs/platform-express": ">=7.0.1",
Expand All @@ -56,7 +56,7 @@
"reflect-metadata": ">=0.1.12",
"rxjs": ">=6.0.0",
"typescript": ">=4.8.0",
"typia": ">=5.2.0 <6.0.0"
"typia": ">=5.2.1 <6.0.0"
},
"devDependencies": {
"@trivago/prettier-plugin-sort-imports": "^4.0.0",
Expand Down
2 changes: 1 addition & 1 deletion packages/e2e/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@
"ts-node": "^10.9.1",
"ts-patch": "^3.0.2",
"typescript": "^5.2.2",
"typia": "^5.2.0"
"typia": "^5.2.1"
},
"dependencies": {
"chalk": "^4.1.2",
Expand Down
2 changes: 1 addition & 1 deletion packages/fetcher/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@nestia/fetcher",
"version": "2.2.0",
"version": "2.2.1",
"description": "Fetcher library of Nestia SDK",
"main": "lib/index.js",
"typings": "lib/index.d.ts",
Expand Down
2 changes: 1 addition & 1 deletion packages/migrate/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@
"typescript-transform-paths": "^3.4.6"
},
"dependencies": {
"typia": "^5.2.0"
"typia": "^5.2.1"
},
"files": [
"lib",
Expand Down
10 changes: 5 additions & 5 deletions packages/sdk/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@nestia/sdk",
"version": "2.2.0",
"version": "2.2.1",
"description": "Nestia SDK and Swagger generator",
"main": "lib/index.js",
"typings": "lib/index.d.ts",
Expand Down Expand Up @@ -35,7 +35,7 @@
},
"homepage": "https://nestia.io",
"dependencies": {
"@nestia/fetcher": "^2.2.0",
"@nestia/fetcher": "^2.2.1",
"cli": "^1.0.1",
"glob": "^7.2.0",
"path-to-regexp": "^6.2.1",
Expand All @@ -44,16 +44,16 @@
"tsconfck": "^2.0.1",
"tsconfig-paths": "^4.1.1",
"tstl": "^2.5.13",
"typia": "^5.2.0"
"typia": "^5.2.1"
},
"peerDependencies": {
"@nestia/fetcher": ">=2.2.0",
"@nestia/fetcher": ">=2.2.1",
"@nestjs/common": ">=7.0.1",
"@nestjs/core": ">=7.0.1",
"reflect-metadata": ">=0.1.12",
"ts-node": ">=10.6.0",
"typescript": ">=4.8.0",
"typia": ">=5.2.0 <6.0.0"
"typia": ">=5.2.1 <6.0.0"
},
"devDependencies": {
"@nestjs/common": ">= 7.0.1",
Expand Down
2 changes: 1 addition & 1 deletion packages/sdk/src/generates/SdkGenerator.ts
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@ export namespace SdkGenerator {

// DISTRIBUTION
if (config.distribute !== undefined)
await SdkDistributionComposer.compose(config);
await SdkDistributionComposer.compose(config)(routes);
};

export const BUNDLE_PATH = NodePath.join(
Expand Down
76 changes: 43 additions & 33 deletions packages/sdk/src/generates/internal/SdkDistributionComposer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,48 +3,56 @@ import fs from "fs";
import path from "path";

import { INestiaConfig } from "../../INestiaConfig";
import { IRoute } from "../../structures/IRoute";

export namespace SdkDistributionComposer {
export const compose = async (config: INestiaConfig): Promise<void> => {
if (!fs.existsSync(config.distribute!))
await fs.promises.mkdir(config.distribute!);
export const compose =
(config: INestiaConfig) =>
async (routes: IRoute[]): Promise<void> => {
if (!fs.existsSync(config.distribute!))
await fs.promises.mkdir(config.distribute!);

const root: string = process.cwd();
const output: string = path.resolve(config.output!);
process.chdir(config.distribute!);
const root: string = process.cwd();
const output: string = path.resolve(config.output!);
process.chdir(config.distribute!);

const exit = () => {
process.chdir(root);
};
const exit = () => process.chdir(root);

const typia: boolean =
!!config.assert || !!config.json || !!config.simulate;
const done: boolean = await configured({
typia,
distribute: config.distribute!,
});
if (done) return exit();
const typia: boolean =
!!config.assert ||
!!config.json ||
!!config.simulate ||
routes.some(
(r) =>
r.output.contentType ===
"application/x-www-form-urlencoded",
);
const done: boolean = await configured({
typia,
distribute: config.distribute!,
});
if (done) return exit();

// COPY FILES
console.log("Composing SDK distribution environments...");
for (const file of await fs.promises.readdir(BUNDLE))
await fs.promises.copyFile(`${BUNDLE}/${file}`, file);
// COPY FILES
console.log("Composing SDK distribution environments...");
for (const file of await fs.promises.readdir(BUNDLE))
await fs.promises.copyFile(`${BUNDLE}/${file}`, file);

// CONFIGURE PATHS
for (const file of ["package.json", "tsconfig.json"])
await replace({ root, output })(file);
// CONFIGURE PATHS
for (const file of ["package.json", "tsconfig.json"])
await replace({ root, output })(file);

// INSTALL PACKAGES
const versions: IDependencies = await dependencies();
execute("npm install --save-dev rimraf");
execute(
`npm install --save @nestia/fetcher@${versions["@nestia/fetcher"]}`,
);
execute(`npm install --save typia@${versions["typia"]}`);
execute("npx typia setup --manager npm");
// INSTALL PACKAGES
const versions: IDependencies = await dependencies();
execute("npm install --save-dev rimraf");
execute(
`npm install --save @nestia/fetcher@${versions["@nestia/fetcher"]}`,
);
execute(`npm install --save typia@${versions["typia"]}`);
execute("npx typia setup --manager npm");

exit();
};
exit();
};

const configured = async (config: {
typia: boolean;
Expand All @@ -57,6 +65,8 @@ export namespace SdkDistributionComposer {
);
return (
!!content.dependencies?.["@nestia/fetcher"] &&
(config.typia === false ||
!!content.scripts?.prepare?.includes("ts-patch install")) &&
(config.typia === false || !!content.dependencies?.["typia"])
);
})()) &&
Expand Down
4 changes: 2 additions & 2 deletions test/features/distribute-assert/packages/api/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
"build:sdk": "rimraf ../../src/api/functional && cd ../.. && npx nestia sdk && cd packages/api",
"compile": "rimraf lib && tsc",
"deploy": "npm run build && npm publish",
"postinstall": "ts-patch install"
"prepare": "ts-patch install"
},
"repository": {
"type": "git",
Expand All @@ -34,6 +34,6 @@
},
"dependencies": {
"@nestia/fetcher": "file:../../../../../packages/fetcher/nestia-fetcher-0.0.0-dev.20991231.tgz",
"typia": "^5.2.0"
"typia": "^5.2.1"
}
}
4 changes: 2 additions & 2 deletions test/features/distribute-json/packages/api/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
"build:sdk": "rimraf ../../src/api/functional && cd ../.. && npx nestia sdk && cd packages/api",
"compile": "rimraf lib && tsc",
"deploy": "npm run build && npm publish",
"postinstall": "ts-patch install"
"prepare": "ts-patch install"
},
"repository": {
"type": "git",
Expand All @@ -34,6 +34,6 @@
},
"dependencies": {
"@nestia/fetcher": "file:../../../../../packages/fetcher/nestia-fetcher-0.0.0-dev.20991231.tgz",
"typia": "^5.2.0"
"typia": "^5.2.1"
}
}
4 changes: 2 additions & 2 deletions test/features/distribute/packages/api/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
"build:sdk": "rimraf ../../src/api/functional && cd ../.. && npx nestia sdk && cd packages/api",
"compile": "rimraf lib && tsc",
"deploy": "npm run build && npm publish",
"postinstall": "ts-patch install"
"prepare": "ts-patch install"
},
"repository": {
"type": "git",
Expand All @@ -34,6 +34,6 @@
},
"dependencies": {
"@nestia/fetcher": "file:../../../../../packages/fetcher/nestia-fetcher-0.0.0-dev.20991231.tgz",
"typia": "^5.2.0"
"typia": "^5.2.1"
}
}
12 changes: 6 additions & 6 deletions test/package.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"private": true,
"name": "@nestia/test",
"version": "2.2.0",
"version": "2.2.1",
"description": "Test program of Nestia",
"main": "index.js",
"scripts": {
Expand Down Expand Up @@ -32,14 +32,14 @@
"@types/uuid": "^9.0.0",
"ts-node": "^10.9.1",
"ts-patch": "v3.0.2",
"typescript": "^5.2.0",
"typescript": "^5.2.1",
"typescript-transform-paths": "^3.4.4",
"typia": "^5.2.0",
"typia": "^5.2.1",
"uuid": "^9.0.0",
"nestia": "^4.5.0",
"@nestia/core": "^2.2.0",
"@nestia/core": "^2.2.1",
"@nestia/e2e": "^0.3.6",
"@nestia/fetcher": "^2.2.0",
"@nestia/sdk": "^2.2.0"
"@nestia/fetcher": "^2.2.1",
"@nestia/sdk": "^2.2.1"
}
}
Loading

0 comments on commit b17dd10

Please sign in to comment.