Update library build and test configuration.

This commit is contained in:
Madeorsk 2024-09-28 14:43:16 +02:00
parent 13c852cd52
commit 0876c59c98
Signed by: Madeorsk
GPG key ID: 677E51CA765BB79F
7 changed files with 88 additions and 87 deletions

View file

@ -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");

View file

@ -1,5 +1,6 @@
/** @type {import('ts-jest/dist/types').InitialOptionsTsJest} */
module.exports = {
export default {
preset: "ts-jest",
testEnvironment: "node",

View file

@ -15,24 +15,29 @@
"author": "Madeorsk <madeorsk@protonmail.com>",
"license": "MIT",
"scripts": {
"build": "parcel build",
"build": "tsc && vite build",
"test": "jest"
},
"type": "module",
"source": "src/index.ts",
"main": "lib/index.js",
"types": "lib/index.d.ts",
"main": "lib/index.js",
"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"
}
"@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"
}

View file

@ -1,5 +1,4 @@
export * from "./Model/Model";
export * from "./Model/Definition";

View file

@ -33,7 +33,7 @@ class Author extends Model<Author>
};
}
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();

View file

@ -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,
"esModuleInterop": true,
"allowSyntheticDefaultImports": true,
"resolveJsonModule": true,
"experimentalDecorators": true,
"emitDecoratorMetadata": true,
"declaration": true,
"declarationMap": true,
"sourceMap": true,
"module": "ES6",
"moduleResolution": "Node",
"target": "ES6",
"moduleResolution": "Bundler",
"lib": [
"ESNext",
"DOM"
]
],
}
}

30
vite.config.ts Normal file
View file

@ -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"],
}),
]
});
});