From a225d86d13489f8880e4dfe68dea260a184d371c Mon Sep 17 00:00:00 2001 From: YieldRay Date: Mon, 17 Jun 2024 20:12:51 +0800 Subject: [PATCH] update build script to use unbuild --- build.ts | 27 +++++++++++++++------------ deno.json | 2 +- tsconfig.json | 19 +++++++++++++++++++ 3 files changed, 35 insertions(+), 13 deletions(-) create mode 100644 tsconfig.json diff --git a/build.ts b/build.ts index e3f60f4..24a917f 100644 --- a/build.ts +++ b/build.ts @@ -1,25 +1,25 @@ -import * as esbuild from 'npm:esbuild' - -console.log( - await esbuild.build({ - entryPoints: ['src/index.ts'], - bundle: true, - outdir: 'dist', - format: 'esm', - }), -) +import { execSync } from 'node:child_process' const pkg = JSON.parse(Deno.readTextFileSync('./deno.json')) try { Deno.removeSync('./package.json') + console.log('Previous package.json removed.') } catch { // NOOP } const packageJson = { name: pkg.name, version: pkg.version, - main: 'dist/index.js', + type: 'module', + exports: { + '.': { + import: './dist/index.mjs', + require: './dist/index.cjs', + }, + }, + main: './dist/index.cjs', + types: './dist/index.d.ts', files: ['dist'], author: 'YieldRay', license: 'MIT', @@ -33,6 +33,9 @@ const packageJson = { homepage: 'https://github.com/YieldRay/json-rpc-ts#readme', } +Deno.writeTextFileSync('./package.json', JSON.stringify(packageJson, null, 4)) +console.log('New package.json created.') console.log(packageJson) -Deno.writeTextFileSync('./package.json', JSON.stringify(packageJson, null, 4)) +console.log('Building package using unbuild...') +execSync('npx unbuild@2.0.0', { stdio: ['ignore', 'inherit', 'inherit'] }) diff --git a/deno.json b/deno.json index f741d30..6ac1802 100644 --- a/deno.json +++ b/deno.json @@ -21,7 +21,7 @@ "noImplicitOverride": true }, "imports": { - "std/": "https://deno.land/std@0.221.0/" + "std/": "https://deno.land/std@0.224.0/" }, "tasks": { "lint": "deno lint", diff --git a/tsconfig.json b/tsconfig.json new file mode 100644 index 0000000..181f60d --- /dev/null +++ b/tsconfig.json @@ -0,0 +1,19 @@ +// This file is redundant for Deno +// But necessary for unbuild, as it indirectly reads this config +// https://docs.deno.com/runtime/manual/advanced/typescript/configuration +{ + "compilerOptions": { + "allowJs": true, + "esModuleInterop": true, + "experimentalDecorators": false, + "inlineSourceMap": true, + "isolatedModules": true, + "jsx": "react", + "module": "esnext", + "moduleDetection": "force", + "strict": true, + "target": "esnext", + "useDefineForClassFields": true, + "allowImportingTsExtensions": true + } + } \ No newline at end of file