Skip to content

Commit

Permalink
Webpack 설정 변경.
Browse files Browse the repository at this point in the history
이전에 `payment-backend` 에 `webpack` 환경을 구성하기를, `node_modules` 폴더가 필요없이 싱글 파일로 구성 가능하도록 하였다. 그런데 NodeJS v20 에 `fetch` 함수가 기본 탑재되었고, `webpack` 은 이를 이해하지 못하여 `global.fetch` 함수를 망가뜨린다.

이에 `webpack` 설정을 변경, `node_modules` 디렉터리를 사용하는 것으로 바꾸었다.
  • Loading branch information
samchon committed Nov 15, 2023
1 parent 4b94072 commit c1390b3
Show file tree
Hide file tree
Showing 17 changed files with 92 additions and 117 deletions.
2 changes: 1 addition & 1 deletion packages/fake-iamport-server/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "fake-iamport-server",
"version": "5.1.0",
"version": "5.1.1",
"description": "Fake iamport server for testing",
"main": "lib/index.js",
"typings": "lib/index.d.ts",
Expand Down
2 changes: 1 addition & 1 deletion packages/fake-toss-payments-server/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "fake-toss-payments-server",
"version": "5.1.0",
"version": "5.1.1",
"description": "Fake toss-payments server for testing",
"main": "lib/index.js",
"typings": "lib/index.d.ts",
Expand Down
2 changes: 1 addition & 1 deletion packages/iamport-server-api/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "iamport-server-api",
"version": "5.1.0",
"version": "5.1.1",
"description": "API for Iamport Server",
"main": "lib/index.js",
"typings": "lib/index.d.ts",
Expand Down
2 changes: 1 addition & 1 deletion packages/iamport-server-api/swagger.json
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
"info": {
"title": "Iamport API",
"description": "Built by [fake-iamport-server](https://github.com/samchon/payments/tree/master/packages/fake-iamport-server) with [nestia](https://github.com/samchon/nestia)",
"version": "5.1.0",
"version": "5.1.1",
"license": {
"name": "MIT"
}
Expand Down
6 changes: 3 additions & 3 deletions packages/payment-api/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@samchon/payment-api",
"version": "5.1.0",
"version": "5.1.1",
"description": "API for Payment Backend",
"main": "lib/index.js",
"typings": "lib/index.d.ts",
Expand Down Expand Up @@ -35,8 +35,8 @@
},
"dependencies": {
"@nestia/fetcher": "^2.3.9",
"iamport-server-api": "^5.1.0",
"toss-payments-server-api": "^5.1.0",
"iamport-server-api": "^5.1.1",
"toss-payments-server-api": "^5.1.1",
"typia": "^5.2.6"
}
}
2 changes: 1 addition & 1 deletion packages/payment-api/swagger.json
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
}
],
"info": {
"version": "5.1.0",
"version": "5.1.1",
"title": "@samchon/payment-backend",
"description": "Payment Backend Server",
"license": {
Expand Down
26 changes: 13 additions & 13 deletions packages/payment-backend/package.json
Original file line number Diff line number Diff line change
@@ -1,18 +1,17 @@
{
"name": "@samchon/payment-backend",
"version": "5.1.0",
"version": "5.1.1",
"description": "Payment Backend Server",
"main": "lib/index.js",
"typings": "lib/index.d.ts",
"scripts": {
"----------------------------------------------": "",
"build": "npm run build:sdk && npm run build:main && npm run build:test",
"build:api": "rimraf packages/api/lib && nestia sdk && tsc -p packages/api/tsconfig.json",
"build:main": "npm run build:prisma && rimraf lib && tsc",
"build:main": "rimraf lib && tsc",
"build:prisma": "prisma generate --schema=src/schema.prisma",
"build:sdk": "rimraf src/api/functional && nestia sdk",
"build:swagger": "nestia swagger",
"build:test": "npm run build:prisma && rimraf bin && tsc -p test/tsconfig.json",
"build:test": "rimraf bin && tsc -p test/tsconfig.json",
"dev": "npm run build:test -- --watch",
"eslint": "eslint src && eslint test",
"eslint:fix": "eslint src --fix && eslint test --fix",
Expand All @@ -36,7 +35,9 @@
"stop:updator:master": "pm2 delete payments-server-backend-updator-master",
"stop:updator:slave": "pm2 delete payments-server-backend-updator-slave",
"update": "node lib/executable/update",
"-------------------------------------------------": ""
"-------------------------------------------------": "",
"webpack": "webpack",
"prune": "npm ci --omit=dev --ignore-scripts && npm run build:prisma"
},
"repository": {
"type": "git",
Expand All @@ -56,29 +57,27 @@
"@types/cli": "^0.11.19",
"@types/express": "^4.17.12",
"@types/inquirer": "^8.2.5",
"@types/node": "^15.6.1",
"@types/node": "^15.14.9",
"@types/pg": "^8.6.5",
"@types/uuid": "^8.3.0",
"@typescript-eslint/eslint-plugin": "^5.26.0",
"@typescript-eslint/parser": "^5.26.0",
"cli": "^1.0.1",
"copy-webpack-plugin": "^11.0.0",
"copyfiles": "^2.4.1",
"iamport-server-api": "^5.1.0",
"iamport-server-api": "^5.1.1",
"nestia": "^5.0.3",
"pm2": "^4.5.6",
"prisma-markdown": "^1.0.7",
"rimraf": "^3.0.2",
"sloc": "^0.2.1",
"toss-payments-server-api": "^5.1.0",
"toss-payments-server-api": "^5.1.1",
"ts-loader": "^9.5.0",
"ts-node": "^10.9.1",
"ts-patch": "^3.0.2",
"typescript": "^5.2.2",
"typescript-transform-paths": "^3.4.6",
"webpack": "^5.89.0",
"webpack-cli": "^5.1.4",
"write-file-webpack-plugin": "^4.5.1"
"webpack-node-externals": "^3.0.0"
},
"dependencies": {
"@nestia/core": "^2.3.9",
Expand All @@ -89,13 +88,14 @@
"bcryptjs": "^2.4.3",
"dotenv": "^16.3.1",
"dotenv-expand": "^10.0.0",
"fake-iamport-server": "^5.1.0",
"fake-toss-payments-server": "^5.1.0",
"fake-iamport-server": "^5.1.1",
"fake-toss-payments-server": "^5.1.1",
"fastify": "^4.24.3",
"git-last-commit": "^1.0.0",
"inquirer": "^8.2.5",
"mutex-server": "^0.3.1",
"prisma": "^5.3.1",
"prisma-markdown": "^1.0.7",
"serialize-error": "^4.1.0",
"source-map-support": "^0.5.19",
"tstl": "^2.5.13",
Expand Down
9 changes: 8 additions & 1 deletion packages/payment-backend/src/PaymentConfiguration.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import {
} from "@nestjs/common";
import { PrismaClientKnownRequestError } from "@prisma/client/runtime/library";
import { IIamportUser } from "iamport-server-api/lib/structures/IIamportUser";
import path from "path";

import { PaymentGlobal } from "./PaymentGlobal";

Expand Down Expand Up @@ -89,7 +90,13 @@ export namespace PaymentConfiguration {
/**
* @internal
*/
export const ROOT = __dirname.split("\\").join("/") + "/..";
export const ROOT = (() => {
const splitted: string[] = __dirname.split(path.sep);
return splitted[splitted.length - 1] === "src" &&
splitted[splitted.length - 2] === "bin"
? path.resolve(__dirname + "/../..")
: path.resolve(__dirname + "/..");
})();

/**
* @internal
Expand Down
78 changes: 40 additions & 38 deletions packages/payment-backend/src/PaymentGlobal.ts
Original file line number Diff line number Diff line change
Expand Up @@ -70,51 +70,53 @@ export namespace PaymentGlobal {
* 없으니, 이 점을 착각하지 말기 바란다.
*/
export let testing: boolean = false;
}

interface IMode {
value?: "local" | "dev" | "real";
}
const modeWrapper: IMode = {};
export interface IEnvironments {
// DEFAULT CONFIGURATIONS
PAYMENT_MODE: "local" | "dev" | "real";
PAYMENT_API_PORT: `${number}`;
PAYMENT_UPDATOR_PORT: `${number}`;
PAYMENT_SYSTEM_PASSWORD: string;

interface IEnvironments {
// DEFAULT CONFIGURATIONS
PAYMENT_MODE: "local" | "dev" | "real";
PAYMENT_API_PORT: `${number}`;
PAYMENT_UPDATOR_PORT: `${number}`;
PAYMENT_SYSTEM_PASSWORD: string;
// POSTGRES CONNECTION INFO
PAYMENT_POSTGRES_HOST: string;
PAYMENT_POSTGRES_PORT: `${number}`;
PAYMENT_POSTGRES_DATABASE: string;
PAYMENT_POSTGRES_SCHEMA: string;
PAYMENT_POSTGRES_USERNAME: string;
PAYMENT_POSTGRES_USERNAME_READONLY: string;
PAYMENT_POSTGRES_PASSWORD: string;
PAYMENT_POSTGRES_URL: string;

// POSTGRES CONNECTION INFO
PAYMENT_POSTGRES_HOST: string;
PAYMENT_POSTGRES_PORT: `${number}`;
PAYMENT_POSTGRES_DATABASE: string;
PAYMENT_POSTGRES_SCHEMA: string;
PAYMENT_POSTGRES_USERNAME: string;
PAYMENT_POSTGRES_USERNAME_READONLY: string;
PAYMENT_POSTGRES_PASSWORD: string;
PAYMENT_POSTGRES_URL: string;
// ENCRYPTION KEYS
PAYMENT_CONNECTION_ENCRYPTION_KEY: string;
PAYMENT_CONNECTION_ENCRYPTION_IV: string;
PAYMENT_HISTORY_ENCRYPTION_KEY: string;
PAYMENT_HISTORY_ENCRYPTION_IV: string;
PAYMENT_RESERVATION_ENCRYPTION_KEY: string;
PAYMENT_RESERVATION_ENCRYPTION_IV: string;
PAYMENT_CANCEL_HISTORY_ENCRYPTION_KEY: string;
PAYMENT_CANCEL_HISTORY_ENCRYPTION_IV: string;

// ENCRYPTION KEYS
PAYMENT_CONNECTION_ENCRYPTION_KEY: string;
PAYMENT_CONNECTION_ENCRYPTION_IV: string;
PAYMENT_HISTORY_ENCRYPTION_KEY: string;
PAYMENT_HISTORY_ENCRYPTION_IV: string;
PAYMENT_RESERVATION_ENCRYPTION_KEY: string;
PAYMENT_RESERVATION_ENCRYPTION_IV: string;
PAYMENT_CANCEL_HISTORY_ENCRYPTION_KEY: string;
PAYMENT_CANCEL_HISTORY_ENCRYPTION_IV: string;
// VENDOR'S SECRETS
PAYMENT_IAMPORT_KEY: string;
PAYMENT_IAMPORT_SECRET: string;
PAYMENT_TOSS_PAYMENTS_SECRET: string;
}
}

// VENDOR'S SECRETS
PAYMENT_IAMPORT_KEY: string;
PAYMENT_IAMPORT_SECRET: string;
PAYMENT_TOSS_PAYMENTS_SECRET: string;
interface IMode {
value?: "local" | "dev" | "real";
}
const modeWrapper: IMode = {};

const environments: Singleton<IEnvironments> = new Singleton(() => {
const env = dotenv.config();
dotenvExpand.expand(env);
return typia.assert<IEnvironments>(process.env);
});
const environments: Singleton<PaymentGlobal.IEnvironments> = new Singleton(
() => {
const env = dotenv.config();
dotenvExpand.expand(env);
return typia.assert<PaymentGlobal.IEnvironments>(process.env);
},
);

const prismaClient = new Singleton(
() =>
Expand Down
6 changes: 5 additions & 1 deletion packages/payment-backend/src/PaymentSetupWizard.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import cp from "child_process";

import { PaymentConfiguration } from "./PaymentConfiguration";
import { PaymentGlobal } from "./PaymentGlobal";

export namespace PaymentSetupWizard {
Expand All @@ -12,7 +13,10 @@ export namespace PaymentSetupWizard {
const execute = (type: string) => (argv: string) =>
cp.execSync(
`npx prisma migrate ${type} --schema=src/schema.prisma ${argv}`,
{ stdio: "ignore" },
{
stdio: "ignore",
cwd: PaymentConfiguration.ROOT,
},
);
execute("reset")("--force");
execute("dev")("--name init");
Expand Down
5 changes: 5 additions & 0 deletions packages/payment-backend/src/executable/server.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
import { FakeIamportBackend } from "fake-iamport-server";
import { FakeTossBackend } from "fake-toss-payments-server";
import fs from "fs";
import { randint } from "tstl/algorithm/random";
import { Singleton } from "tstl/thread/Singleton";
Expand Down Expand Up @@ -52,6 +54,9 @@ async function main(): Promise<void> {
process.argv.some((str) => str === "testing")
)
PaymentGlobal.testing = true;
else if (PaymentGlobal.mode === "local")
for (const server of [new FakeIamportBackend(), new FakeTossBackend()])
await server.open();

// BACKEND SEVER LATER
const backend: PaymentBackend = new PaymentBackend();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ import git from "git-last-commit";
import { Singleton } from "tstl/thread/Singleton";
import { v4 } from "uuid";

import { PaymentConfiguration } from "../../PaymentConfiguration";
import { ISystem } from "../../api/structures/monitors/ISystem";
import { DateUtil } from "../../utils/DateUtil";

Expand Down Expand Up @@ -43,7 +44,7 @@ const commit_: Singleton<Promise<ISystem.ICommit>> = new Singleton(
const package_: Singleton<Promise<ISystem.IPackage>> = new Singleton(
async () => {
const content: string = await fs.promises.readFile(
`${__dirname}/../../../../package.json`,
`${PaymentConfiguration.ROOT}/package.json`,
"utf8",
);
return JSON.parse(content);
Expand Down
9 changes: 5 additions & 4 deletions packages/payment-backend/src/schema.prisma
Original file line number Diff line number Diff line change
@@ -1,12 +1,13 @@
generator client {
provider = "prisma-client-js"
}

datasource db {
provider = "postgresql"
url = env("PAYMENT_POSTGRES_URL")
}

generator client {
provider = "prisma-client-js"
binaryTargets = ["native", "linux-musl-arm64-openssl-3.0.x"]
}

generator markdown {
provider = "prisma-markdown"
title = "Payments System"
Expand Down
4 changes: 2 additions & 2 deletions packages/payment-backend/tsconfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,9 @@
/* Visit https://aka.ms/tsconfig.json to read more about this file */
/* Basic Options */
// "incremental": true, /* Enable incremental compilation */
"target": "es5", /* Specify ECMAScript target version: 'ES3' (default), 'ES5', 'ES2015', 'ES2016', 'ES2017', 'ES2018', 'ES2019', 'ES2020', or 'ESNEXT'. */
"target": "ES2016", /* Specify ECMAScript target version: 'ES3' (default), 'ES5', 'ES2015', 'ES2016', 'ES2017', 'ES2018', 'ES2019', 'ES2020', or 'ESNEXT'. */
"module": "commonjs", /* Specify module code generation: 'none', 'commonjs', 'amd', 'system', 'umd', 'es2015', 'es2020', or 'ESNext'. */
// "lib": [], /* Specify library files to be included in the compilation. */
"lib": [], /* Specify library files to be included in the compilation. */
// "allowJs": true, /* Allow javascript files to be compiled. */
// "checkJs": true, /* Report errors in .js files. */
// "jsx": "preserve", /* Specify JSX code generation: 'preserve', 'react-native', or 'react'. */
Expand Down
Loading

0 comments on commit c1390b3

Please sign in to comment.