From 0876c59c983ff69511eed9a8eaff3faa757025af Mon Sep 17 00:00:00 2001 From: Madeorsk Date: Sat, 28 Sep 2024 14:43:16 +0200 Subject: [PATCH] Update library build and test configuration. --- build.ts | 38 ---------------------- jest.config.js | 5 +-- package.json | 77 ++++++++++++++++++++++++--------------------- src/index.ts | 1 - tests/Model.test.ts | 2 +- tsconfig.json | 22 +++++++------ vite.config.ts | 30 ++++++++++++++++++ 7 files changed, 88 insertions(+), 87 deletions(-) delete mode 100644 build.ts create mode 100644 vite.config.ts diff --git a/build.ts b/build.ts deleted file mode 100644 index c5a832e..0000000 --- a/build.ts +++ /dev/null @@ -1,38 +0,0 @@ -import {build} from "esbuild"; - -/** - * Build the library. - * @param devMode - Dev mode. - */ -function buildLibrary(devMode: boolean = false): void -{ - // Compilation de l'application. - build({ - entryPoints: ["src/index.ts"], - outfile: "lib/index.js", - bundle: true, - minify: true, - sourcemap: true, - format: "esm", - loader: { - ".ts": "ts", - }, - watch: devMode ? { - // Affichage suite à une recompilation. - onRebuild(error, result) { - console.log(new Date()); - if (!error && result.errors.length == 0) - console.log("Successfully built."); - else - console.error("Error!"); - } - } : false, - }) - // Fonction lancée pour une compilation réussie. - .then(() => { console.log(new Date()); console.log("Success."); }) - // Fonction lancée pour une compilation échouée. - .catch((e) => console.error(e.message)); -} - -// @ts-ignore -buildLibrary(process.argv?.[2] == "dev"); diff --git a/jest.config.js b/jest.config.js index c66b70d..77a9c90 100644 --- a/jest.config.js +++ b/jest.config.js @@ -1,9 +1,10 @@ /** @type {import('ts-jest/dist/types').InitialOptionsTsJest} */ -module.exports = { + +export default { preset: "ts-jest", testEnvironment: "node", roots: [ "./tests", ], -}; \ No newline at end of file +}; diff --git a/package.json b/package.json index b7c1f6d..3770f79 100644 --- a/package.json +++ b/package.json @@ -1,38 +1,43 @@ { - "name": "@sharkitek/core", - "version": "2.0.1", - "description": "Sharkitek core models library.", - "keywords": [ - "sharkitek", - "model", - "serialization", - "diff", - "dirty", - "deserialization", - "property" - ], - "repository": "https://git.madeorsk.com/Sharkitek/core", - "author": "Madeorsk ", - "license": "MIT", - "scripts": { - "build": "parcel build", - "test": "jest" - }, - "source": "src/index.ts", - "main": "lib/index.js", - "types": "lib/index.d.ts", - "files": [ - "lib/**/*" - ], - "devDependencies": { - "@parcel/packager-ts": "2.7.0", - "@parcel/transformer-typescript-types": "2.7.0", - "@types/jest": "^28.1.6", - "esbuild": "^0.15.8", - "jest": "^28.1.3", - "parcel": "^2.7.0", - "ts-jest": "^28.0.7", - "ts-node": "^10.9.1", - "typescript": "^4.7.4" - } + "name": "@sharkitek/core", + "version": "2.0.1", + "description": "Sharkitek core models library.", + "keywords": [ + "sharkitek", + "model", + "serialization", + "diff", + "dirty", + "deserialization", + "property" + ], + "repository": "https://git.madeorsk.com/Sharkitek/core", + "author": "Madeorsk ", + "license": "MIT", + "scripts": { + "build": "tsc && vite build", + "test": "jest" + }, + "type": "module", + "source": "src/index.ts", + "types": "lib/index.d.ts", + "main": "lib/index.js", + "files": [ + "lib/**/*" + ], + "devDependencies": { + "@types/jest": "^29.5.13", + "@types/node": "^22.7.4", + "jest": "^29.7.0", + "reflect-metadata": "^0.2.2", + "ts-jest": "^29.2.5", + "ts-node": "^10.9.2", + "typescript": "^5.6.2", + "vite": "^5.4.8", + "vite-plugin-dts": "^4.2.2" + }, + "peerDependencies": { + "reflect-metadata": "^0.2.2" + }, + "packageManager": "yarn@4.5.0" } diff --git a/src/index.ts b/src/index.ts index aa82848..fa04563 100644 --- a/src/index.ts +++ b/src/index.ts @@ -1,5 +1,4 @@ - export * from "./Model/Model"; export * from "./Model/Definition"; diff --git a/tests/Model.test.ts b/tests/Model.test.ts index ed197e6..a5a4112 100644 --- a/tests/Model.test.ts +++ b/tests/Model.test.ts @@ -33,7 +33,7 @@ class Author extends Model }; } - constructor(name: string = undefined, firstName: string = undefined, email: string = undefined, createdAt: Date = undefined) + constructor(name: string = "", firstName: string = "", email: string = "", createdAt: Date = new Date()) { super(); diff --git a/tsconfig.json b/tsconfig.json index af1362b..38dfc55 100644 --- a/tsconfig.json +++ b/tsconfig.json @@ -1,25 +1,29 @@ { "ts-node": { "compilerOptions": { - "module": "CommonJS" + "module": "ESNext", + "types": ["node"], } }, - "files": ["src/index.ts"], "compilerOptions": { "outDir": "./lib/", + "incremental": true, + "sourceMap": true, "noImplicitAny": true, - "allowSyntheticDefaultImports": true, - "declaration": true, + "esModuleInterop": true, + "allowSyntheticDefaultImports": true, + "resolveJsonModule": true, + "experimentalDecorators": true, + "emitDecoratorMetadata": true, + "declaration": true, "declarationMap": true, - "sourceMap": true, "module": "ES6", - "moduleResolution": "Node", - "target": "ES6", - + "target": "ES6", + "moduleResolution": "Bundler", "lib": [ "ESNext", "DOM" - ] + ], } } diff --git a/vite.config.ts b/vite.config.ts new file mode 100644 index 0000000..1544229 --- /dev/null +++ b/vite.config.ts @@ -0,0 +1,30 @@ +import {ConfigEnv, defineConfig, UserConfig} from "vite"; +import dts from "vite-plugin-dts"; + +// https://vitejs.dev/config/ + +export default defineConfig(({ mode }: ConfigEnv): UserConfig => { + return ({ + build: { + outDir: "lib", + sourcemap: true, + minify: "esbuild", + lib: { + entry: "src/index.ts", + formats: ["es"], + fileName: "index", + }, + rollupOptions: { + external: ["reflect-metadata"], + }, + }, + + plugins: [ + dts({ + insertTypesEntry: true, + rollupTypes: true, + exclude: ["node_modules"], + }), + ] + }); +});