Skip to content

Commit a225d86

Browse files
committed
update build script to use unbuild
1 parent d00dd05 commit a225d86

File tree

3 files changed

+35
-13
lines changed

3 files changed

+35
-13
lines changed

build.ts

Lines changed: 15 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,25 +1,25 @@
1-
import * as esbuild from 'npm:esbuild'
2-
3-
console.log(
4-
await esbuild.build({
5-
entryPoints: ['src/index.ts'],
6-
bundle: true,
7-
outdir: 'dist',
8-
format: 'esm',
9-
}),
10-
)
1+
import { execSync } from 'node:child_process'
112

123
const pkg = JSON.parse(Deno.readTextFileSync('./deno.json'))
134

145
try {
156
Deno.removeSync('./package.json')
7+
console.log('Previous package.json removed.')
168
} catch { // NOOP
179
}
1810

1911
const packageJson = {
2012
name: pkg.name,
2113
version: pkg.version,
22-
main: 'dist/index.js',
14+
type: 'module',
15+
exports: {
16+
'.': {
17+
import: './dist/index.mjs',
18+
require: './dist/index.cjs',
19+
},
20+
},
21+
main: './dist/index.cjs',
22+
types: './dist/index.d.ts',
2323
files: ['dist'],
2424
author: 'YieldRay',
2525
license: 'MIT',
@@ -33,6 +33,9 @@ const packageJson = {
3333
homepage: 'https://github.com/YieldRay/json-rpc-ts#readme',
3434
}
3535

36+
Deno.writeTextFileSync('./package.json', JSON.stringify(packageJson, null, 4))
37+
console.log('New package.json created.')
3638
console.log(packageJson)
3739

38-
Deno.writeTextFileSync('./package.json', JSON.stringify(packageJson, null, 4))
40+
console.log('Building package using unbuild...')
41+
execSync('npx unbuild@2.0.0', { stdio: ['ignore', 'inherit', 'inherit'] })

deno.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@
2121
"noImplicitOverride": true
2222
},
2323
"imports": {
24-
"std/": "https://deno.land/std@0.221.0/"
24+
"std/": "https://deno.land/std@0.224.0/"
2525
},
2626
"tasks": {
2727
"lint": "deno lint",

tsconfig.json

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
// This file is redundant for Deno
2+
// But necessary for unbuild, as it indirectly reads this config
3+
// https://docs.deno.com/runtime/manual/advanced/typescript/configuration
4+
{
5+
"compilerOptions": {
6+
"allowJs": true,
7+
"esModuleInterop": true,
8+
"experimentalDecorators": false,
9+
"inlineSourceMap": true,
10+
"isolatedModules": true,
11+
"jsx": "react",
12+
"module": "esnext",
13+
"moduleDetection": "force",
14+
"strict": true,
15+
"target": "esnext",
16+
"useDefineForClassFields": true,
17+
"allowImportingTsExtensions": true
18+
}
19+
}

0 commit comments

Comments
 (0)