From 5ed2db4bb376e545e4923282c30a7460d2b0f92e Mon Sep 17 00:00:00 2001 From: ryoppippi <1560508+ryoppippi@users.noreply.github.com> Date: Mon, 3 Jun 2024 11:28:37 +0100 Subject: [PATCH 1/6] feat: Migrate to ESM and use tsup for building This commit includes several changes: - The package.json file has been updated to support ESM with the "type" field set to "module" and the "exports" field properly configured. - The build script in package.json has been changed to use tsup instead of tsc. - tsup has been added as a devDependency. - The tsconfig.json file has been simplified and updated for the new build process. - A new tsup.config.js file has been added to configure the tsup build. feat: Update build process and dependencies This commit updates the build process by replacing `tsc --watch` with `tsup --watch` in the `dev` script. It also removes the `tsp` section from `package.json` and deletes `tsup.config.js`. A new `tsup.config.ts` file is added which uses `fast-glob` and `node:fs/promises` to handle TypeScript compilation and file renaming. This is due to an issue with tsup's dts causing out of memory errors. Additionally, `@microsoft/api-extractor` and `fast-glob` are added as new devDependencies. --- package.json | 32 +++++++------ tsconfig.json | 128 ++++++++++++------------------------------------- tsup.config.ts | 42 ++++++++++++++++ 3 files changed, 90 insertions(+), 112 deletions(-) create mode 100644 tsup.config.ts diff --git a/package.json b/package.json index 8a1dda3dbb..4794b222fe 100644 --- a/package.json +++ b/package.json @@ -2,30 +2,27 @@ "name": "typia", "version": "6.0.5", "description": "Superfast runtime validators with only one line", - "main": "lib/index.js", - "typings": "lib/index.d.ts", + "main": "./lib/index.js", + "module": "./lib/index.mjs", + "types": "./lib/index.d.mts", "bin": { "typia": "./lib/executable/typia.js" }, - "tsp": { - "tscOptions": { - "parseAllJsDoc": true - } - }, "scripts": { "test": "npm run package:tgz", "test:template": "npm run test template", "-------------------------------------------------": "", - "build": "rimraf lib && tsc", - "dev": "rimraf lib && tsc --watch", + "build": "tsup", + "dev": "tsup --watch", "eslint": "eslint ./**/*.ts", "eslint:fix": "eslint ./**/*.ts --fix", "prettier": "prettier src --write", "------------------------------------------------": "", - "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": "tsx deploy/index.ts", + "package:latest": "npm run package latest", + "package:next": "npm run package next", + "package:patch": "npm run package patch", + "package:tgz": "npm run package tgz", "package:deprecate": "npm deprecate typescript-json \"Renamed to typia\"" }, "repository": { @@ -69,12 +66,15 @@ "commander": "^10.0.0", "comment-json": "^4.2.3", "inquirer": "^8.2.5", - "randexp": "^0.5.3" + "randexp": "^0.5.3", + "tsx": "^4.11.2" }, "peerDependencies": { "typescript": ">=4.8.0 <5.5.0" }, "devDependencies": { + "@microsoft/api-extractor": "^7.46.2", + "@swc/core": "^1.5.24", "@trivago/prettier-plugin-sort-imports": "^4.3.0", "@types/inquirer": "^8.2.5", "@types/node": "^18.15.12", @@ -82,10 +82,12 @@ "@typescript-eslint/eslint-plugin": "^7.1.1", "@typescript-eslint/parser": "^7.1.1", "chalk": "^4.0.0", + "fast-glob": "^3.3.2", "prettier": "^3.2.5", "rimraf": "^5.0.5", "suppress-warnings": "^1.0.2", "ts-node": "^10.9.2", + "tsup": "^8.1.0", "typescript": "^5.4.5" }, "stackblitzs": { @@ -99,4 +101,4 @@ "src" ], "private": true -} \ No newline at end of file +} diff --git a/tsconfig.json b/tsconfig.json index 2e9fb09c29..969bb706ec 100644 --- a/tsconfig.json +++ b/tsconfig.json @@ -1,105 +1,39 @@ { + "$schema": "https://json.schemastore.org/tsconfig", "compilerOptions": { - /* Visit https://aka.ms/tsconfig.json to read more about this file */ - - /* Projects */ - // "incremental": true, /* Enable incremental compilation */ - // "composite": true, /* Enable constraints that allow a TypeScript project to be used with project references. */ - // "tsBuildInfoFile": "./", /* Specify the folder for .tsbuildinfo incremental compilation files. */ - // "disableSourceOfProjectReferenceRedirect": true, /* Disable preferring source files instead of declaration files when referencing composite projects */ - // "disableSolutionSearching": true, /* Opt a project out of multi-project reference checking when editing. */ - // "disableReferencedProjectLoad": true, /* Reduce the number of projects loaded automatically by TypeScript. */ - - /* Language and Environment */ - "target": "es5", /* Set the JavaScript language version for emitted JavaScript and include compatible library declarations. */ + "target": "ESNext", "lib": [ "DOM", "ES2020" - ], /* Specify a set of bundled library declaration files that describe the target runtime environment. */ - // "jsx": "preserve", /* Specify what JSX code is generated. */ - "experimentalDecorators": true, /* Enable experimental support for TC39 stage 2 draft decorators. */ - "emitDecoratorMetadata": true, /* Emit design-type metadata for decorated declarations in source files. */ - // "jsxFactory": "", /* Specify the JSX factory function used when targeting React JSX emit, e.g. 'React.createElement' or 'h' */ - // "jsxFragmentFactory": "", /* Specify the JSX Fragment reference used for fragments when targeting React JSX emit e.g. 'React.Fragment' or 'Fragment'. */ - // "jsxImportSource": "", /* Specify module specifier used to import the JSX factory functions when using `jsx: react-jsx*`.` */ - // "reactNamespace": "", /* Specify the object invoked for `createElement`. This only applies when targeting `react` JSX emit. */ - // "noLib": true, /* Disable including any library files, including the default lib.d.ts. */ - // "useDefineForClassFields": true, /* Emit ECMAScript-standard-compliant class fields. */ - - /* Modules */ - "module": "commonjs", /* Specify what module code is generated. */ - // "rootDir": "./", /* Specify the root folder within your source files. */ - // "moduleResolution": "node", /* Specify how TypeScript looks up a file from a given module specifier. */ - // "baseUrl": "./", /* Specify the base directory to resolve non-relative module names. */ - // "paths": {}, /* Specify a set of entries that re-map imports to additional lookup locations. */ - // "rootDirs": [], /* Allow multiple folders to be treated as one when resolving modules. */ - // "typeRoots": [], /* Specify multiple folders that act like `./node_modules/@types`. */ - // "types": [], /* Specify type package names to be included without being referenced in a source file. */ - // "allowUmdGlobalAccess": true, /* Allow accessing UMD globals from modules. */ - // "resolveJsonModule": true, /* Enable importing .json files */ - // "noResolve": true, /* Disallow `import`s, `require`s or ``s from expanding the number of files TypeScript should add to a project. */ - - /* JavaScript Support */ - // "allowJs": true, /* Allow JavaScript files to be a part of your program. Use the `checkJS` option to get errors from these files. */ - // "checkJs": true, /* Enable error reporting in type-checked JavaScript files. */ - // "maxNodeModuleJsDepth": 1, /* Specify the maximum folder depth used for checking JavaScript files from `node_modules`. Only applicable with `allowJs`. */ - - /* Emit */ - "declaration": true, /* Generate .d.ts files from TypeScript and JavaScript files in your project. */ - // "declarationMap": true, /* Create sourcemaps for d.ts files. */ - // "emitDeclarationOnly": true, /* Only output d.ts files and not JavaScript files. */ - "sourceMap": true, /* Create source map files for emitted JavaScript files. */ - // "outFile": "./", /* Specify a file that bundles all outputs into one JavaScript file. If `declaration` is true, also designates a file that bundles all .d.ts output. */ - "outDir": "./lib", /* Specify an output folder for all emitted files. */ - // "removeComments": true, /* Disable emitting comments. */ - // "noEmit": true, /* Disable emitting files from a compilation. */ - // "importHelpers": true, /* Allow importing helper functions from tslib once per project, instead of including them per-file. */ - // "importsNotUsedAsValues": "remove", /* Specify emit/checking behavior for imports that are only used for types */ - "downlevelIteration": true, /* Emit more compliant, but verbose and less performant JavaScript for iteration. */ - // "sourceRoot": "", /* Specify the root path for debuggers to find the reference source code. */ - // "mapRoot": "", /* Specify the location where debugger should locate map files instead of generated locations. */ - // "inlineSourceMap": true, /* Include sourcemap files inside the emitted JavaScript. */ - // "inlineSources": true, /* Include source code in the sourcemaps inside the emitted JavaScript. */ - // "emitBOM": true, /* Emit a UTF-8 Byte Order Mark (BOM) in the beginning of output files. */ - "newLine": "lf", /* Set the newline character for emitting files. */ - "stripInternal": true, /* Disable emitting declarations that have `@internal` in their JSDoc comments. */ - // "noEmitHelpers": true, /* Disable generating custom helper functions like `__extends` in compiled output. */ - // "noEmitOnError": true, /* Disable emitting files if any type checking errors are reported. */ - // "preserveConstEnums": true, /* Disable erasing `const enum` declarations in generated code. */ - // "declarationDir": "./", /* Specify the output directory for generated declaration files. */ - // "preserveValueImports": true, /* Preserve unused imported values in the JavaScript output that would otherwise be removed. */ - - /* Interop Constraints */ - // "isolatedModules": true, /* Ensure that each file can be safely transpiled without relying on other imports. */ - // "allowSyntheticDefaultImports": true, /* Allow 'import x from y' when a module doesn't have a default export. */ - "esModuleInterop": true, /* Emit additional JavaScript to ease support for importing CommonJS modules. This enables `allowSyntheticDefaultImports` for type compatibility. */ - // "preserveSymlinks": true, /* Disable resolving symlinks to their realpath. This correlates to the same flag in node. */ - "forceConsistentCasingInFileNames": true, /* Ensure that casing is correct in imports. */ - - /* Type Checking */ - "strict": true, /* Enable all strict type-checking options. */ - "noImplicitAny": true, /* Enable error reporting for expressions and declarations with an implied `any` type.. */ - "strictNullChecks": true, /* When type checking, take into account `null` and `undefined`. */ - "strictFunctionTypes": true, /* When assigning functions, check to ensure parameters and the return values are subtype-compatible. */ - "strictBindCallApply": true, /* Check that the arguments for `bind`, `call`, and `apply` methods match the original function. */ - "strictPropertyInitialization": true, /* Check for class properties that are declared but not set in the constructor. */ - "noImplicitThis": true, /* Enable error reporting when `this` is given the type `any`. */ - "useUnknownInCatchVariables": true, /* Type catch clause variables as 'unknown' instead of 'any'. */ - "alwaysStrict": true, /* Ensure 'use strict' is always emitted. */ - "noUnusedLocals": true, /* Enable error reporting when a local variables aren't read. */ - "noUnusedParameters": true, /* Raise an error when a function parameter isn't read */ - // "exactOptionalPropertyTypes": true, /* Interpret optional property types as written, rather than adding 'undefined'. */ - "noImplicitReturns": true, /* Enable error reporting for codepaths that do not explicitly return in a function. */ - "noFallthroughCasesInSwitch": true, /* Enable error reporting for fallthrough cases in switch statements. */ - "noUncheckedIndexedAccess": true, /* Include 'undefined' in index signature results */ - "noImplicitOverride": true, /* Ensure overriding members in derived classes are marked with an override modifier. */ - // "noPropertyAccessFromIndexSignature": true, /* Enforces using indexed accessors for keys declared using an indexed type */ - // "allowUnusedLabels": true, /* Disable error reporting for unused labels. */ - // "allowUnreachableCode": true, /* Disable error reporting for unreachable code. */ - - /* Completeness */ - // "skipDefaultLibCheck": true, /* Skip type checking .d.ts files that are included with TypeScript. */ - "skipLibCheck": true /* Skip type checking all .d.ts files. */ + ], + "experimentalDecorators": true, + "emitDecoratorMetadata": true, + "module": "ES2020", + "moduleResolution": "node", + "declaration": true, + "sourceMap": true, + "outDir": "./lib", + "downlevelIteration": true, + "newLine": "lf", + "stripInternal": true, + "esModuleInterop": true, + "forceConsistentCasingInFileNames": true, + "strict": true, + "noImplicitAny": true, + "strictNullChecks": true, + "strictFunctionTypes": true, + "strictBindCallApply": true, + "strictPropertyInitialization": true, + "noImplicitThis": true, + "useUnknownInCatchVariables": true, + "alwaysStrict": true, + "noUnusedLocals": true, + "noUnusedParameters": true, + "noImplicitReturns": true, + "noFallthroughCasesInSwitch": true, + "noUncheckedIndexedAccess": true, + "noImplicitOverride": true, + "skipLibCheck": true }, "include": ["src"] } diff --git a/tsup.config.ts b/tsup.config.ts new file mode 100644 index 0000000000..cce8e450e9 --- /dev/null +++ b/tsup.config.ts @@ -0,0 +1,42 @@ +import glob from "fast-glob"; +import { exec } from "node:child_process"; +import { copyFile } from "node:fs/promises"; +import { promisify } from "node:util"; +import { defineConfig } from "tsup"; + +const outDir = "lib" as const; + +export default defineConfig((options) => ({ + entry: ["src/**/*.ts"], + outDir, + clean: true, + format: ["cjs", "esm"], + sourcemap: true, + splitting: true, + /** + * because tsup's dts causes out of memory, we use tsc + * @link https://github.com/egoist/tsup/issues/920 + */ + dts: false, + async onSuccess() { + const pexec = promisify(exec); + try { + await pexec("tsc --emitDeclarationOnly --declaration"); + const files = await glob(`${outDir}/**/*.d.ts`); + await Promise.all( + /** + * rename `.d.ts` to `.d.mts` for `.cjs` projects + * or to `.d.cjs` for `"type": "module"` projects + */ + files.map((file) => copyFile(file, file.replace(".d.ts", ".d.mts"))), + ); + } catch (err) { + console.error(); + console.error("Typescript compilation error:"); + console.error(); + console.error(err.stdout); + throw err; + } + }, + ...options, +})); From 7f6dee87e838e4e8d9597a8a61ae58cada42d6d0 Mon Sep 17 00:00:00 2001 From: ryoppippi <1560508+ryoppippi@users.noreply.github.com> Date: Mon, 3 Jun 2024 15:46:35 +0100 Subject: [PATCH 2/6] fix: add .js extension to dynamic imports This commit fixes the dynamic imports in the typia.ts file by adding the .js extension. This ensures the correct files are imported when the script is run. --- src/executable/typia.ts | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/executable/typia.ts b/src/executable/typia.ts index bcdde5793a..1079c67088 100644 --- a/src/executable/typia.ts +++ b/src/executable/typia.ts @@ -32,10 +32,10 @@ const main = async (): Promise => { const type: string | undefined = process.argv[2]; if (type === "setup") { - const { TypiaSetupWizard } = await import("./TypiaSetupWizard"); + const { TypiaSetupWizard } = await import("./TypiaSetupWizard.js"); await TypiaSetupWizard.setup(); } else if (type === "patch") { - const { TypiaPatchWizard } = await import("./TypiaPatchWizard"); + const { TypiaPatchWizard } = await import("./TypiaPatchWizard.js"); await TypiaPatchWizard.main(); } else if (type === "generate") { try { @@ -45,7 +45,7 @@ const main = async (): Promise => { `typescript has not been installed. Run "npm i -D typescript" before.`, ); } - const { TypiaGenerateWizard } = await import("./TypiaGenerateWizard"); + const { TypiaGenerateWizard } = await import("./TypiaGenerateWizard.js"); await TypiaGenerateWizard.generate(); } else halt(USAGE); }; From fe289d87bc11370443c991935c79c5bf400077f5 Mon Sep 17 00:00:00 2001 From: ryoppippi <1560508+ryoppippi@users.noreply.github.com> Date: Mon, 3 Jun 2024 16:07:08 +0100 Subject: [PATCH 3/6] feat: Replace ts-node with tsx in scripts This commit replaces the usage of ts-node with tsx in the scripts section of both benchmark and test package.json files. The version of tsx used is 4.11.2. This change is expected to enhance the TypeScript execution environment. --- benchmark/package.json | 7 ++++--- test/package.json | 5 ++--- 2 files changed, 6 insertions(+), 6 deletions(-) diff --git a/benchmark/package.json b/benchmark/package.json index 920b4e9c03..f40888d8f9 100644 --- a/benchmark/package.json +++ b/benchmark/package.json @@ -9,7 +9,7 @@ "prepare": "ts-patch install", "prettier": "prettier ./src/**/*.ts --write", "start": "node bin", - "template": "ts-node src/template && npm run prettier && npm run build" + "template": "tsx src/template && npm run prettier && npm run build" }, "repository": { "type": "git", @@ -59,7 +59,7 @@ "source-map-support": "^0.5.21", "suppress-warnings": "^1.0.2", "tgrid": "^0.10.0", - "ts-node": "^10.9.1", + "tsx": "^4.11.2", "ts-patch": "^3.1.0", "tstl": "^3.0.0", "typescript": "^5.3.2", @@ -75,4 +75,5 @@ "uuid": "^9.0.1", "typia": "../typia-6.0.5.tgz" } -} \ No newline at end of file +} + diff --git a/test/package.json b/test/package.json index 5b9de449da..cef3042ffe 100644 --- a/test/package.json +++ b/test/package.json @@ -15,7 +15,7 @@ "prettier": "prettier ./src/**/*.ts --write", "setup": "node build/setup.js", "start": "node bin", - "template": "ts-node --project build/tsconfig.json build/template.ts" + "template": "tsx --tsconfig build/tsconfig.json build/template.ts" }, "repository": { "type": "git", @@ -38,8 +38,8 @@ "@types/uuid": "^9.0.7", "prettier": "^3.2.5", "rimraf": "^5.0.5", - "ts-node": "^10.9.2", "ts-patch": "^3.1.2", + "tsx": "^4.11.2", "typescript": "^5.4.5" }, "dependencies": { @@ -53,4 +53,3 @@ "uuid": "^9.0.1", "typia": "../typia-6.0.5.tgz" } -} \ No newline at end of file From 6b1ae748f76440a904b5a8c746acf7876484b063 Mon Sep 17 00:00:00 2001 From: ryoppippi <1560508+ryoppippi@users.noreply.github.com> Date: Mon, 3 Jun 2024 16:08:25 +0100 Subject: [PATCH 4/6] feat: Update prepare script in package.json The prepare script in package.json has been updated to include the 'typia patch' command. This change ensures that the typia patch is applied during the preparation phase of the project setup. feat: add typia patch to prepare script This commit modifies the 'prepare' script in the package.json file of the benchmark directory. The 'ts-patch install' command is now followed by 'typia patch'. This change ensures that typia patch is run during the preparation phase. --- benchmark/package.json | 3 +-- test/package.json | 3 ++- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/benchmark/package.json b/benchmark/package.json index f40888d8f9..a29b90d649 100644 --- a/benchmark/package.json +++ b/benchmark/package.json @@ -6,7 +6,7 @@ "main": "bin/index.js", "scripts": { "build": "rimraf bin && tsc", - "prepare": "ts-patch install", + "prepare": "ts-patch install && typia patch", "prettier": "prettier ./src/**/*.ts --write", "start": "node bin", "template": "tsx src/template && npm run prettier && npm run build" @@ -76,4 +76,3 @@ "typia": "../typia-6.0.5.tgz" } } - diff --git a/test/package.json b/test/package.json index cef3042ffe..25ec5e5b9a 100644 --- a/test/package.json +++ b/test/package.json @@ -11,7 +11,7 @@ }, "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 bin", @@ -53,3 +53,4 @@ "uuid": "^9.0.1", "typia": "../typia-6.0.5.tgz" } +} From dbd7c62a6a48bfdac60f032fadc2593b2f4f3d78 Mon Sep 17 00:00:00 2001 From: Jeongho Nam Date: Tue, 4 Jun 2024 22:58:04 +0900 Subject: [PATCH 5/6] Transformer library must be CJS --- benchmark/package.json | 12 +-- debug/package.json | 2 +- deploy/index.ts | 1 + errors/package.json | 4 +- package.json | 38 ++++---- packages/typescript-json/package.json | 7 +- rollup.config.js | 29 ++++++ src/executable/typia.ts | 6 +- test-esm/package.json | 41 +++++++++ test-esm/src/index.ts | 7 ++ test-esm/tsconfig.json | 118 ++++++++++++++++++++++++ test/package.json | 14 +-- tsconfig.json | 128 +++++++++++++++++++------- tsup.config.ts | 42 --------- website/pages/docs/setup.mdx | 6 +- 15 files changed, 339 insertions(+), 116 deletions(-) create mode 100644 rollup.config.js create mode 100644 test-esm/package.json create mode 100644 test-esm/src/index.ts create mode 100644 test-esm/tsconfig.json delete mode 100644 tsup.config.ts diff --git a/benchmark/package.json b/benchmark/package.json index a29b90d649..0b407771e3 100644 --- a/benchmark/package.json +++ b/benchmark/package.json @@ -6,10 +6,10 @@ "main": "bin/index.js", "scripts": { "build": "rimraf bin && tsc", - "prepare": "ts-patch install && typia patch", + "prepare": "ts-patch install", "prettier": "prettier ./src/**/*.ts --write", "start": "node bin", - "template": "tsx src/template && npm run prettier && npm run build" + "template": "ts-node src/template && npm run prettier && npm run build" }, "repository": { "type": "git", @@ -59,8 +59,8 @@ "source-map-support": "^0.5.21", "suppress-warnings": "^1.0.2", "tgrid": "^0.10.0", - "tsx": "^4.11.2", - "ts-patch": "^3.1.0", + "ts-node": "^10.9.1", + "ts-patch": "^3.2.0", "tstl": "^3.0.0", "typescript": "^5.3.2", "uuid": "^8.3.2", @@ -73,6 +73,6 @@ "suppress-warnings": "^1.0.2", "tstl": "^3.0.0", "uuid": "^9.0.1", - "typia": "../typia-6.0.5.tgz" + "typia": "../typia-6.0.6-dev.20240604.tgz" } -} +} \ No newline at end of file diff --git a/debug/package.json b/debug/package.json index 79699f3aa8..58f63ba2f0 100644 --- a/debug/package.json +++ b/debug/package.json @@ -11,7 +11,7 @@ "license": "ISC", "devDependencies": { "ts-node": "^10.9.2", - "ts-patch": "^3.1.2", + "ts-patch": "^3.2.0", "typescript": "^5.4.2" }, "dependencies": { diff --git a/deploy/index.ts b/deploy/index.ts index 23b5f56173..7dc4ccf17d 100644 --- a/deploy/index.ts +++ b/deploy/index.ts @@ -92,6 +92,7 @@ const main = (): void => { ? ["npm run template", "npm run build", "npm start"] : ["npm run build", "npm start"], ); + test(version)("test-esm")(["npm run build", "npm start"]); test(version)("errors")(["npm start"]); test(version)("benchmark")(["npm run build"]); diff --git a/errors/package.json b/errors/package.json index 1abc0f876a..630344df9a 100644 --- a/errors/package.json +++ b/errors/package.json @@ -28,10 +28,10 @@ "homepage": "https://github.com/samchon/typia#readme", "devDependencies": { "rimraf": "^5.0.5", - "ts-patch": "^3.0.2", + "ts-patch": "^3.2.0", "typescript": "^5.3.2" }, "dependencies": { - "typia": "../typia-6.0.5.tgz" + "typia": "../typia-6.0.6-dev.20240604.tgz" } } \ No newline at end of file diff --git a/package.json b/package.json index 4794b222fe..5622d15df4 100644 --- a/package.json +++ b/package.json @@ -1,28 +1,32 @@ { "name": "typia", - "version": "6.0.5", + "version": "6.0.6-dev.20240604", "description": "Superfast runtime validators with only one line", - "main": "./lib/index.js", - "module": "./lib/index.mjs", - "types": "./lib/index.d.mts", + "main": "lib/index.js", + "typings": "lib/index.d.ts", + "module": "lib/index.mjs", "bin": { "typia": "./lib/executable/typia.js" }, + "tsp": { + "tscOptions": { + "parseAllJsDoc": true + } + }, "scripts": { "test": "npm run package:tgz", "test:template": "npm run test template", "-------------------------------------------------": "", - "build": "tsup", - "dev": "tsup --watch", + "build": "rimraf lib && tsc && rollup -c", + "dev": "rimraf lib && tsc --watch", "eslint": "eslint ./**/*.ts", "eslint:fix": "eslint ./**/*.ts --fix", "prettier": "prettier src --write", "------------------------------------------------": "", - "package": "tsx deploy/index.ts", - "package:latest": "npm run package latest", - "package:next": "npm run package next", - "package:patch": "npm run package patch", - "package:tgz": "npm run package tgz", + "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": { @@ -66,15 +70,14 @@ "commander": "^10.0.0", "comment-json": "^4.2.3", "inquirer": "^8.2.5", - "randexp": "^0.5.3", - "tsx": "^4.11.2" + "randexp": "^0.5.3" }, "peerDependencies": { "typescript": ">=4.8.0 <5.5.0" }, "devDependencies": { - "@microsoft/api-extractor": "^7.46.2", - "@swc/core": "^1.5.24", + "@rollup/plugin-terser": "^0.4.4", + "@rollup/plugin-typescript": "^11.1.6", "@trivago/prettier-plugin-sort-imports": "^4.3.0", "@types/inquirer": "^8.2.5", "@types/node": "^18.15.12", @@ -82,12 +85,11 @@ "@typescript-eslint/eslint-plugin": "^7.1.1", "@typescript-eslint/parser": "^7.1.1", "chalk": "^4.0.0", - "fast-glob": "^3.3.2", "prettier": "^3.2.5", "rimraf": "^5.0.5", + "rollup": "^4.18.0", "suppress-warnings": "^1.0.2", "ts-node": "^10.9.2", - "tsup": "^8.1.0", "typescript": "^5.4.5" }, "stackblitzs": { @@ -101,4 +103,4 @@ "src" ], "private": true -} +} \ No newline at end of file diff --git a/packages/typescript-json/package.json b/packages/typescript-json/package.json index 62b4c4daf8..a649752768 100644 --- a/packages/typescript-json/package.json +++ b/packages/typescript-json/package.json @@ -1,9 +1,10 @@ { "name": "typescript-json", - "version": "6.0.5", + "version": "6.0.6-dev.20240604", "description": "Superfast runtime validators with only one line", "main": "lib/index.js", "typings": "lib/index.d.ts", + "module": "lib/index.mjs", "tsp": { "tscOptions": { "parseAllJsDoc": true @@ -13,7 +14,7 @@ "test": "npm run package:tgz", "test:template": "npm run test template", "-------------------------------------------------": "", - "build": "rimraf lib && tsc", + "build": "rimraf lib && tsc && rollup -c", "dev": "rimraf lib && tsc --watch", "eslint": "eslint ./**/*.ts", "eslint:fix": "eslint ./**/*.ts --fix", @@ -62,7 +63,7 @@ }, "homepage": "https://typia.io", "dependencies": { - "typia": "6.0.5" + "typia": "6.0.6-dev.20240604" }, "peerDependencies": { "typescript": ">=4.8.0 <5.5.0" diff --git a/rollup.config.js b/rollup.config.js new file mode 100644 index 0000000000..f948ecc19b --- /dev/null +++ b/rollup.config.js @@ -0,0 +1,29 @@ +const typescript = require("@rollup/plugin-typescript"); +const terser = require("@rollup/plugin-terser"); + +module.exports = { + input: "./src/index.ts", + output: { + dir: "lib", + format: "esm", + entryFileNames: "[name].mjs", + sourcemap: true, + }, + plugins: [ + typescript({ + tsconfig: "tsconfig.json", + module: "ES2020", + target: "ES2020", + }), + terser({ + format: { + comments: "some", + beautify: true, + ecma: "2020", + }, + compress: false, + mangle: false, + module: true, + }), + ], +}; diff --git a/src/executable/typia.ts b/src/executable/typia.ts index 1079c67088..bcdde5793a 100644 --- a/src/executable/typia.ts +++ b/src/executable/typia.ts @@ -32,10 +32,10 @@ const main = async (): Promise => { const type: string | undefined = process.argv[2]; if (type === "setup") { - const { TypiaSetupWizard } = await import("./TypiaSetupWizard.js"); + const { TypiaSetupWizard } = await import("./TypiaSetupWizard"); await TypiaSetupWizard.setup(); } else if (type === "patch") { - const { TypiaPatchWizard } = await import("./TypiaPatchWizard.js"); + const { TypiaPatchWizard } = await import("./TypiaPatchWizard"); await TypiaPatchWizard.main(); } else if (type === "generate") { try { @@ -45,7 +45,7 @@ const main = async (): Promise => { `typescript has not been installed. Run "npm i -D typescript" before.`, ); } - const { TypiaGenerateWizard } = await import("./TypiaGenerateWizard.js"); + const { TypiaGenerateWizard } = await import("./TypiaGenerateWizard"); await TypiaGenerateWizard.generate(); } else halt(USAGE); }; diff --git a/test-esm/package.json b/test-esm/package.json new file mode 100644 index 0000000000..fa9283b3f4 --- /dev/null +++ b/test-esm/package.json @@ -0,0 +1,41 @@ +{ + "private": true, + "type": "module", + "name": "@typia/test-esm", + "version": "0.1.0", + "description": "Test program of ESM for typia", + "main": "bin/index.js", + "tsp": { + "tscOptions": { + "parseAllJsDoc": true + } + }, + "scripts": { + "build": "tsc", + "prepare": "ts-patch install", + "start": "node bin" + }, + "repository": { + "type": "git", + "url": "https://github.com/samchon/typia" + }, + "keywords": [ + "typia", + "test" + ], + "author": "Jeongho Nam", + "license": "MIT", + "bugs": { + "url": "https://github.com/samchon/typia/issues" + }, + "homepage": "https://github.com/samchon/typia#readme", + "devDependencies": { + "@types/cli": "^0.11.25", + "@types/node": "^20.9.4", + "ts-patch": "^3.2.0", + "typescript": "^5.4.5" + }, + "dependencies": { + "typia": "../typia-6.0.6-dev.20240604.tgz" + } +} \ No newline at end of file diff --git a/test-esm/src/index.ts b/test-esm/src/index.ts new file mode 100644 index 0000000000..8add853e25 --- /dev/null +++ b/test-esm/src/index.ts @@ -0,0 +1,7 @@ +import typia from "typia"; + +console.log( + typia.is(true), + typia.assert("something"), + typia.json.stringify(3), +); diff --git a/test-esm/tsconfig.json b/test-esm/tsconfig.json new file mode 100644 index 0000000000..860c7a196b --- /dev/null +++ b/test-esm/tsconfig.json @@ -0,0 +1,118 @@ +{ + "compilerOptions": { + /* Visit https://aka.ms/tsconfig to read more about this file */ + + /* Projects */ + // "incremental": true, /* Save .tsbuildinfo files to allow for incremental compilation of projects. */ + // "composite": true, /* Enable constraints that allow a TypeScript project to be used with project references. */ + // "tsBuildInfoFile": "./.tsbuildinfo", /* Specify the path to .tsbuildinfo incremental compilation file. */ + // "disableSourceOfProjectReferenceRedirect": true, /* Disable preferring source files instead of declaration files when referencing composite projects. */ + // "disableSolutionSearching": true, /* Opt a project out of multi-project reference checking when editing. */ + // "disableReferencedProjectLoad": true, /* Reduce the number of projects loaded automatically by TypeScript. */ + + /* Language and Environment */ + "target": "ESNext", /* Set the JavaScript language version for emitted JavaScript and include compatible library declarations. */ + // "lib": [], /* Specify a set of bundled library declaration files that describe the target runtime environment. */ + // "jsx": "preserve", /* Specify what JSX code is generated. */ + // "experimentalDecorators": true, /* Enable experimental support for legacy experimental decorators. */ + // "emitDecoratorMetadata": true, /* Emit design-type metadata for decorated declarations in source files. */ + // "jsxFactory": "", /* Specify the JSX factory function used when targeting React JSX emit, e.g. 'React.createElement' or 'h'. */ + // "jsxFragmentFactory": "", /* Specify the JSX Fragment reference used for fragments when targeting React JSX emit e.g. 'React.Fragment' or 'Fragment'. */ + // "jsxImportSource": "", /* Specify module specifier used to import the JSX factory functions when using 'jsx: react-jsx*'. */ + // "reactNamespace": "", /* Specify the object invoked for 'createElement'. This only applies when targeting 'react' JSX emit. */ + // "noLib": true, /* Disable including any library files, including the default lib.d.ts. */ + // "useDefineForClassFields": true, /* Emit ECMAScript-standard-compliant class fields. */ + // "moduleDetection": "auto", /* Control what method is used to detect module-format JS files. */ + + /* Modules */ + "module": "ESNext", /* Specify what module code is generated. */ + // "rootDir": "./", /* Specify the root folder within your source files. */ + "moduleResolution": "node10", /* Specify how TypeScript looks up a file from a given module specifier. */ + // "baseUrl": "./", /* Specify the base directory to resolve non-relative module names. */ + // "paths": {}, /* Specify a set of entries that re-map imports to additional lookup locations. */ + // "rootDirs": [], /* Allow multiple folders to be treated as one when resolving modules. */ + // "typeRoots": [], /* Specify multiple folders that act like './node_modules/@types'. */ + // "types": [], /* Specify type package names to be included without being referenced in a source file. */ + // "allowUmdGlobalAccess": true, /* Allow accessing UMD globals from modules. */ + // "moduleSuffixes": [], /* List of file name suffixes to search when resolving a module. */ + // "allowImportingTsExtensions": true, /* Allow imports to include TypeScript file extensions. Requires '--moduleResolution bundler' and either '--noEmit' or '--emitDeclarationOnly' to be set. */ + // "resolvePackageJsonExports": true, /* Use the package.json 'exports' field when resolving package imports. */ + // "resolvePackageJsonImports": true, /* Use the package.json 'imports' field when resolving imports. */ + // "customConditions": [], /* Conditions to set in addition to the resolver-specific defaults when resolving imports. */ + // "resolveJsonModule": true, /* Enable importing .json files. */ + // "allowArbitraryExtensions": true, /* Enable importing files with any extension, provided a declaration file is present. */ + // "noResolve": true, /* Disallow 'import's, 'require's or ''s from expanding the number of files TypeScript should add to a project. */ + + /* JavaScript Support */ + // "allowJs": true, /* Allow JavaScript files to be a part of your program. Use the 'checkJS' option to get errors from these files. */ + // "checkJs": true, /* Enable error reporting in type-checked JavaScript files. */ + // "maxNodeModuleJsDepth": 1, /* Specify the maximum folder depth used for checking JavaScript files from 'node_modules'. Only applicable with 'allowJs'. */ + + /* Emit */ + // "declaration": true, /* Generate .d.ts files from TypeScript and JavaScript files in your project. */ + // "declarationMap": true, /* Create sourcemaps for d.ts files. */ + // "emitDeclarationOnly": true, /* Only output d.ts files and not JavaScript files. */ + // "sourceMap": true, /* Create source map files for emitted JavaScript files. */ + // "inlineSourceMap": true, /* Include sourcemap files inside the emitted JavaScript. */ + // "outFile": "./", /* Specify a file that bundles all outputs into one JavaScript file. If 'declaration' is true, also designates a file that bundles all .d.ts output. */ + "outDir": "./bin", /* Specify an output folder for all emitted files. */ + // "removeComments": true, /* Disable emitting comments. */ + // "noEmit": true, /* Disable emitting files from a compilation. */ + // "importHelpers": true, /* Allow importing helper functions from tslib once per project, instead of including them per-file. */ + // "importsNotUsedAsValues": "remove", /* Specify emit/checking behavior for imports that are only used for types. */ + // "downlevelIteration": true, /* Emit more compliant, but verbose and less performant JavaScript for iteration. */ + // "sourceRoot": "", /* Specify the root path for debuggers to find the reference source code. */ + // "mapRoot": "", /* Specify the location where debugger should locate map files instead of generated locations. */ + // "inlineSources": true, /* Include source code in the sourcemaps inside the emitted JavaScript. */ + // "emitBOM": true, /* Emit a UTF-8 Byte Order Mark (BOM) in the beginning of output files. */ + // "newLine": "crlf", /* Set the newline character for emitting files. */ + // "stripInternal": true, /* Disable emitting declarations that have '@internal' in their JSDoc comments. */ + // "noEmitHelpers": true, /* Disable generating custom helper functions like '__extends' in compiled output. */ + // "noEmitOnError": true, /* Disable emitting files if any type checking errors are reported. */ + // "preserveConstEnums": true, /* Disable erasing 'const enum' declarations in generated code. */ + // "declarationDir": "./", /* Specify the output directory for generated declaration files. */ + // "preserveValueImports": true, /* Preserve unused imported values in the JavaScript output that would otherwise be removed. */ + + /* Interop Constraints */ + // "isolatedModules": true, /* Ensure that each file can be safely transpiled without relying on other imports. */ + // "verbatimModuleSyntax": true, /* Do not transform or elide any imports or exports not marked as type-only, ensuring they are written in the output file's format based on the 'module' setting. */ + // "allowSyntheticDefaultImports": true, /* Allow 'import x from y' when a module doesn't have a default export. */ + "esModuleInterop": true, /* Emit additional JavaScript to ease support for importing CommonJS modules. This enables 'allowSyntheticDefaultImports' for type compatibility. */ + // "preserveSymlinks": true, /* Disable resolving symlinks to their realpath. This correlates to the same flag in node. */ + "forceConsistentCasingInFileNames": true, /* Ensure that casing is correct in imports. */ + + /* Type Checking */ + "strict": true, /* Enable all strict type-checking options. */ + // "noImplicitAny": true, /* Enable error reporting for expressions and declarations with an implied 'any' type. */ + // "strictNullChecks": true, /* When type checking, take into account 'null' and 'undefined'. */ + // "strictFunctionTypes": true, /* When assigning functions, check to ensure parameters and the return values are subtype-compatible. */ + // "strictBindCallApply": true, /* Check that the arguments for 'bind', 'call', and 'apply' methods match the original function. */ + // "strictPropertyInitialization": true, /* Check for class properties that are declared but not set in the constructor. */ + // "noImplicitThis": true, /* Enable error reporting when 'this' is given the type 'any'. */ + // "useUnknownInCatchVariables": true, /* Default catch clause variables as 'unknown' instead of 'any'. */ + // "alwaysStrict": true, /* Ensure 'use strict' is always emitted. */ + // "noUnusedLocals": true, /* Enable error reporting when local variables aren't read. */ + // "noUnusedParameters": true, /* Raise an error when a function parameter isn't read. */ + // "exactOptionalPropertyTypes": true, /* Interpret optional property types as written, rather than adding 'undefined'. */ + // "noImplicitReturns": true, /* Enable error reporting for codepaths that do not explicitly return in a function. */ + // "noFallthroughCasesInSwitch": true, /* Enable error reporting for fallthrough cases in switch statements. */ + // "noUncheckedIndexedAccess": true, /* Add 'undefined' to a type when accessed using an index. */ + // "noImplicitOverride": true, /* Ensure overriding members in derived classes are marked with an override modifier. */ + // "noPropertyAccessFromIndexSignature": true, /* Enforces using indexed accessors for keys declared using an indexed type. */ + // "allowUnusedLabels": true, /* Disable error reporting for unused labels. */ + // "allowUnreachableCode": true, /* Disable error reporting for unreachable code. */ + + /* Completeness */ + // "skipDefaultLibCheck": true, /* Skip type checking .d.ts files that are included with TypeScript. */ + "skipLibCheck": true, /* Skip type checking all .d.ts files. */ + "plugins": [ + { + "transform": "typia/lib/transform", + "functional": true, + "numeric": true, + "finite": true, + }, + ], + }, + "include": ["src"], +} diff --git a/test/package.json b/test/package.json index 25ec5e5b9a..05f91fa17f 100644 --- a/test/package.json +++ b/test/package.json @@ -11,11 +11,11 @@ }, "scripts": { "build": "rimraf bin && tsc", - "prepare": "ts-patch install && typia patch", + "prepare": "ts-patch install", "prettier": "prettier ./src/**/*.ts --write", "setup": "node build/setup.js", "start": "node bin", - "template": "tsx --tsconfig build/tsconfig.json build/template.ts" + "template": "ts-node --project build/tsconfig.json build/template.ts" }, "repository": { "type": "git", @@ -38,12 +38,12 @@ "@types/uuid": "^9.0.7", "prettier": "^3.2.5", "rimraf": "^5.0.5", - "ts-patch": "^3.1.2", - "tsx": "^4.11.2", + "ts-node": "^10.9.2", + "ts-patch": "^3.2.0", "typescript": "^5.4.5" }, "dependencies": { - "@samchon/openapi": "^0.1.21", + "@samchon/openapi": "^0.1.22", "cli": "^1.0.1", "protobufjs": "^7.2.5", "randexp": "^0.5.3", @@ -51,6 +51,6 @@ "suppress-warnings": "^1.0.2", "tstl": "^3.0.0", "uuid": "^9.0.1", - "typia": "../typia-6.0.5.tgz" + "typia": "../typia-6.0.6-dev.20240604.tgz" } -} +} \ No newline at end of file diff --git a/tsconfig.json b/tsconfig.json index 969bb706ec..2e9fb09c29 100644 --- a/tsconfig.json +++ b/tsconfig.json @@ -1,39 +1,105 @@ { - "$schema": "https://json.schemastore.org/tsconfig", "compilerOptions": { - "target": "ESNext", + /* Visit https://aka.ms/tsconfig.json to read more about this file */ + + /* Projects */ + // "incremental": true, /* Enable incremental compilation */ + // "composite": true, /* Enable constraints that allow a TypeScript project to be used with project references. */ + // "tsBuildInfoFile": "./", /* Specify the folder for .tsbuildinfo incremental compilation files. */ + // "disableSourceOfProjectReferenceRedirect": true, /* Disable preferring source files instead of declaration files when referencing composite projects */ + // "disableSolutionSearching": true, /* Opt a project out of multi-project reference checking when editing. */ + // "disableReferencedProjectLoad": true, /* Reduce the number of projects loaded automatically by TypeScript. */ + + /* Language and Environment */ + "target": "es5", /* Set the JavaScript language version for emitted JavaScript and include compatible library declarations. */ "lib": [ "DOM", "ES2020" - ], - "experimentalDecorators": true, - "emitDecoratorMetadata": true, - "module": "ES2020", - "moduleResolution": "node", - "declaration": true, - "sourceMap": true, - "outDir": "./lib", - "downlevelIteration": true, - "newLine": "lf", - "stripInternal": true, - "esModuleInterop": true, - "forceConsistentCasingInFileNames": true, - "strict": true, - "noImplicitAny": true, - "strictNullChecks": true, - "strictFunctionTypes": true, - "strictBindCallApply": true, - "strictPropertyInitialization": true, - "noImplicitThis": true, - "useUnknownInCatchVariables": true, - "alwaysStrict": true, - "noUnusedLocals": true, - "noUnusedParameters": true, - "noImplicitReturns": true, - "noFallthroughCasesInSwitch": true, - "noUncheckedIndexedAccess": true, - "noImplicitOverride": true, - "skipLibCheck": true + ], /* Specify a set of bundled library declaration files that describe the target runtime environment. */ + // "jsx": "preserve", /* Specify what JSX code is generated. */ + "experimentalDecorators": true, /* Enable experimental support for TC39 stage 2 draft decorators. */ + "emitDecoratorMetadata": true, /* Emit design-type metadata for decorated declarations in source files. */ + // "jsxFactory": "", /* Specify the JSX factory function used when targeting React JSX emit, e.g. 'React.createElement' or 'h' */ + // "jsxFragmentFactory": "", /* Specify the JSX Fragment reference used for fragments when targeting React JSX emit e.g. 'React.Fragment' or 'Fragment'. */ + // "jsxImportSource": "", /* Specify module specifier used to import the JSX factory functions when using `jsx: react-jsx*`.` */ + // "reactNamespace": "", /* Specify the object invoked for `createElement`. This only applies when targeting `react` JSX emit. */ + // "noLib": true, /* Disable including any library files, including the default lib.d.ts. */ + // "useDefineForClassFields": true, /* Emit ECMAScript-standard-compliant class fields. */ + + /* Modules */ + "module": "commonjs", /* Specify what module code is generated. */ + // "rootDir": "./", /* Specify the root folder within your source files. */ + // "moduleResolution": "node", /* Specify how TypeScript looks up a file from a given module specifier. */ + // "baseUrl": "./", /* Specify the base directory to resolve non-relative module names. */ + // "paths": {}, /* Specify a set of entries that re-map imports to additional lookup locations. */ + // "rootDirs": [], /* Allow multiple folders to be treated as one when resolving modules. */ + // "typeRoots": [], /* Specify multiple folders that act like `./node_modules/@types`. */ + // "types": [], /* Specify type package names to be included without being referenced in a source file. */ + // "allowUmdGlobalAccess": true, /* Allow accessing UMD globals from modules. */ + // "resolveJsonModule": true, /* Enable importing .json files */ + // "noResolve": true, /* Disallow `import`s, `require`s or ``s from expanding the number of files TypeScript should add to a project. */ + + /* JavaScript Support */ + // "allowJs": true, /* Allow JavaScript files to be a part of your program. Use the `checkJS` option to get errors from these files. */ + // "checkJs": true, /* Enable error reporting in type-checked JavaScript files. */ + // "maxNodeModuleJsDepth": 1, /* Specify the maximum folder depth used for checking JavaScript files from `node_modules`. Only applicable with `allowJs`. */ + + /* Emit */ + "declaration": true, /* Generate .d.ts files from TypeScript and JavaScript files in your project. */ + // "declarationMap": true, /* Create sourcemaps for d.ts files. */ + // "emitDeclarationOnly": true, /* Only output d.ts files and not JavaScript files. */ + "sourceMap": true, /* Create source map files for emitted JavaScript files. */ + // "outFile": "./", /* Specify a file that bundles all outputs into one JavaScript file. If `declaration` is true, also designates a file that bundles all .d.ts output. */ + "outDir": "./lib", /* Specify an output folder for all emitted files. */ + // "removeComments": true, /* Disable emitting comments. */ + // "noEmit": true, /* Disable emitting files from a compilation. */ + // "importHelpers": true, /* Allow importing helper functions from tslib once per project, instead of including them per-file. */ + // "importsNotUsedAsValues": "remove", /* Specify emit/checking behavior for imports that are only used for types */ + "downlevelIteration": true, /* Emit more compliant, but verbose and less performant JavaScript for iteration. */ + // "sourceRoot": "", /* Specify the root path for debuggers to find the reference source code. */ + // "mapRoot": "", /* Specify the location where debugger should locate map files instead of generated locations. */ + // "inlineSourceMap": true, /* Include sourcemap files inside the emitted JavaScript. */ + // "inlineSources": true, /* Include source code in the sourcemaps inside the emitted JavaScript. */ + // "emitBOM": true, /* Emit a UTF-8 Byte Order Mark (BOM) in the beginning of output files. */ + "newLine": "lf", /* Set the newline character for emitting files. */ + "stripInternal": true, /* Disable emitting declarations that have `@internal` in their JSDoc comments. */ + // "noEmitHelpers": true, /* Disable generating custom helper functions like `__extends` in compiled output. */ + // "noEmitOnError": true, /* Disable emitting files if any type checking errors are reported. */ + // "preserveConstEnums": true, /* Disable erasing `const enum` declarations in generated code. */ + // "declarationDir": "./", /* Specify the output directory for generated declaration files. */ + // "preserveValueImports": true, /* Preserve unused imported values in the JavaScript output that would otherwise be removed. */ + + /* Interop Constraints */ + // "isolatedModules": true, /* Ensure that each file can be safely transpiled without relying on other imports. */ + // "allowSyntheticDefaultImports": true, /* Allow 'import x from y' when a module doesn't have a default export. */ + "esModuleInterop": true, /* Emit additional JavaScript to ease support for importing CommonJS modules. This enables `allowSyntheticDefaultImports` for type compatibility. */ + // "preserveSymlinks": true, /* Disable resolving symlinks to their realpath. This correlates to the same flag in node. */ + "forceConsistentCasingInFileNames": true, /* Ensure that casing is correct in imports. */ + + /* Type Checking */ + "strict": true, /* Enable all strict type-checking options. */ + "noImplicitAny": true, /* Enable error reporting for expressions and declarations with an implied `any` type.. */ + "strictNullChecks": true, /* When type checking, take into account `null` and `undefined`. */ + "strictFunctionTypes": true, /* When assigning functions, check to ensure parameters and the return values are subtype-compatible. */ + "strictBindCallApply": true, /* Check that the arguments for `bind`, `call`, and `apply` methods match the original function. */ + "strictPropertyInitialization": true, /* Check for class properties that are declared but not set in the constructor. */ + "noImplicitThis": true, /* Enable error reporting when `this` is given the type `any`. */ + "useUnknownInCatchVariables": true, /* Type catch clause variables as 'unknown' instead of 'any'. */ + "alwaysStrict": true, /* Ensure 'use strict' is always emitted. */ + "noUnusedLocals": true, /* Enable error reporting when a local variables aren't read. */ + "noUnusedParameters": true, /* Raise an error when a function parameter isn't read */ + // "exactOptionalPropertyTypes": true, /* Interpret optional property types as written, rather than adding 'undefined'. */ + "noImplicitReturns": true, /* Enable error reporting for codepaths that do not explicitly return in a function. */ + "noFallthroughCasesInSwitch": true, /* Enable error reporting for fallthrough cases in switch statements. */ + "noUncheckedIndexedAccess": true, /* Include 'undefined' in index signature results */ + "noImplicitOverride": true, /* Ensure overriding members in derived classes are marked with an override modifier. */ + // "noPropertyAccessFromIndexSignature": true, /* Enforces using indexed accessors for keys declared using an indexed type */ + // "allowUnusedLabels": true, /* Disable error reporting for unused labels. */ + // "allowUnreachableCode": true, /* Disable error reporting for unreachable code. */ + + /* Completeness */ + // "skipDefaultLibCheck": true, /* Skip type checking .d.ts files that are included with TypeScript. */ + "skipLibCheck": true /* Skip type checking all .d.ts files. */ }, "include": ["src"] } diff --git a/tsup.config.ts b/tsup.config.ts deleted file mode 100644 index cce8e450e9..0000000000 --- a/tsup.config.ts +++ /dev/null @@ -1,42 +0,0 @@ -import glob from "fast-glob"; -import { exec } from "node:child_process"; -import { copyFile } from "node:fs/promises"; -import { promisify } from "node:util"; -import { defineConfig } from "tsup"; - -const outDir = "lib" as const; - -export default defineConfig((options) => ({ - entry: ["src/**/*.ts"], - outDir, - clean: true, - format: ["cjs", "esm"], - sourcemap: true, - splitting: true, - /** - * because tsup's dts causes out of memory, we use tsc - * @link https://github.com/egoist/tsup/issues/920 - */ - dts: false, - async onSuccess() { - const pexec = promisify(exec); - try { - await pexec("tsc --emitDeclarationOnly --declaration"); - const files = await glob(`${outDir}/**/*.d.ts`); - await Promise.all( - /** - * rename `.d.ts` to `.d.mts` for `.cjs` projects - * or to `.d.cjs` for `"type": "module"` projects - */ - files.map((file) => copyFile(file, file.replace(".d.ts", ".d.mts"))), - ); - } catch (err) { - console.error(); - console.error("Typescript compilation error:"); - console.error(); - console.error(err.stdout); - throw err; - } - }, - ...options, -})); diff --git a/website/pages/docs/setup.mdx b/website/pages/docs/setup.mdx index 3efca11e52..574bb57f2f 100644 --- a/website/pages/docs/setup.mdx +++ b/website/pages/docs/setup.mdx @@ -209,12 +209,12 @@ As `typia` generates optimal operation code through transformation, it must be c "prepare": "ts-patch install && typia patch" }, "dependencies": { - "typia": "^4.1.8" + "typia": "^6.0.5" }, "devDependencies": { "ts-node": "^10.9.1", - "ts-patch": "^3.0.2", - "typescript": "^5.1.6" + "ts-patch": "^3.2.0", + "typescript": "^5.4.5" } } ``` From be37feab51390a5d3afaccf50dcd0f9aebcdcd8e Mon Sep 17 00:00:00 2001 From: Jeongho Nam Date: Tue, 4 Jun 2024 23:08:54 +0900 Subject: [PATCH 6/6] Test internal file import on CJS --- test/src/features/issues/test_issue_1067_cjs_esm.ts | 8 ++++++++ 1 file changed, 8 insertions(+) create mode 100644 test/src/features/issues/test_issue_1067_cjs_esm.ts diff --git a/test/src/features/issues/test_issue_1067_cjs_esm.ts b/test/src/features/issues/test_issue_1067_cjs_esm.ts new file mode 100644 index 0000000000..754a271487 --- /dev/null +++ b/test/src/features/issues/test_issue_1067_cjs_esm.ts @@ -0,0 +1,8 @@ +import { ArrayUtil } from "typia/lib/utils/ArrayUtil"; + +import { TestValidator } from "../../helpers/TestValidator"; + +export const test_issue_1067_cjs_esm = (): void => { + const values: number[] = ArrayUtil.repeat(10, () => 0); + TestValidator.equals("internal")(values)(new Array(10).fill(0)); +};