forked from microsoft/node-jsonc-parser
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathbuild.mjs
More file actions
57 lines (51 loc) · 1.41 KB
/
build.mjs
File metadata and controls
57 lines (51 loc) · 1.41 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
import * as esbuild from "esbuild"
import { execSync } from "node:child_process"
import { renameSync, rmSync } from "node:fs"
// Clean
rmSync("dist", { recursive: true, force: true })
// 1. Generate declarations with tsc
console.log("Generating type declarations...")
execSync("npx tsc -p src/tsconfig.json", { stdio: "inherit" })
// tsc outputs main.d.ts; rename to index.d.ts to match package.json exports
renameSync("dist/main.d.ts", "dist/index.d.ts")
// 2. Bundle ESM (single file, all impl/ inlined)
console.log("Bundling ESM...")
await esbuild.build({
entryPoints: ["src/main.ts"],
bundle: true,
format: "esm",
platform: "neutral",
target: "es2020",
outfile: "dist/index.js",
minifySyntax: true,
treeShaking: true,
})
// 3. Bundle CJS (for backwards compat with require())
console.log("Bundling CJS...")
await esbuild.build({
entryPoints: ["src/main.ts"],
bundle: true,
format: "cjs",
platform: "neutral",
target: "es2020",
outfile: "dist/index.cjs",
minifySyntax: true,
treeShaking: true,
})
// 4. Bundle tests (esbuild handles TS interface imports correctly)
console.log("Bundling tests...")
await esbuild.build({
entryPoints: [
"src/test/json.test.ts",
"src/test/edit.test.ts",
"src/test/format.test.ts",
"src/test/string-intern.test.ts",
],
bundle: true,
format: "esm",
platform: "node",
target: "es2020",
outdir: "dist/test",
external: ["mocha", "assert"],
})
console.log("✓ Build complete")