Skip to content

Commit e48b6e2

Browse files
authored
fix: Rewrite build system using esbuild & tsc (#61)
2 parents 4826de3 + eec2f31 commit e48b6e2

7 files changed

Lines changed: 1804 additions & 3647 deletions

File tree

.changeset/rare-llamas-refuse.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
"windpipe": patch
3+
---
4+
5+
Fix typescript types for ESM default import

.github/workflows/release.yml

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -26,14 +26,17 @@ jobs:
2626
with:
2727
node-version: 20.x
2828

29+
- name: Install pnpm
30+
uses: pnpm/action-setup@v4
31+
2932
- name: Install Dependencies
30-
run: npm ci
33+
run: pnpm i
3134

3235
- name: Create release pull request or publish to npm
3336
id: changesets
3437
uses: changesets/action@v1
3538
with:
36-
publish: npm run ci:release
39+
publish: pnpm run ci:release
3740
env:
3841
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
3942
NPM_TOKEN: ${{ secrets.NPM_TOKEN }}
@@ -59,10 +62,10 @@ jobs:
5962
node-version: 20.x
6063

6164
- name: Install Dependencies
62-
run: npm ci
65+
run: pnpm ci
6366

6467
- name: Generate Docs
65-
run: npm run doc
68+
run: pnpm run doc
6669

6770
- name: Setup pages
6871
uses: actions/configure-pages@v4

.github/workflows/test-prs.yml

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,11 @@ jobs:
1818
with:
1919
node-version: 20.x
2020
cache: 'npm'
21-
- run: npm ci
22-
- run: npm run build
23-
- run: npm test
21+
22+
- name: Install pnpm
23+
uses: pnpm/action-setup@v4
24+
25+
- run: pnpm i
26+
- run: pnpm run build
27+
- run: pnpm test
2428

build.mjs

Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
import { build } from "esbuild";
2+
import { writeFile } from "node:fs/promises";
3+
4+
const ENTRY = "src/index.ts";
5+
6+
function buildEsm() {
7+
return build({
8+
entryPoints: [ENTRY],
9+
outfile: "dist/index.js",
10+
bundle: true,
11+
platform: "node",
12+
format: "esm",
13+
target: "es2022",
14+
sourcemap: true,
15+
external: [], // put deps here if you don't want to bundle them
16+
});
17+
}
18+
19+
async function buildCjs() {
20+
// Build using esm
21+
await build({
22+
entryPoints: [ENTRY],
23+
outfile: "dist/core.cjs",
24+
bundle: true,
25+
platform: "node",
26+
format: "cjs",
27+
target: "es2022",
28+
sourcemap: true,
29+
external: [],
30+
});
31+
32+
// Then build an entry point so we can get a nice default export
33+
await writeFile(
34+
"dist/index.cjs",
35+
'"use strict";\nmodule.exports=require("./core.cjs").default;',
36+
);
37+
38+
return writeFile("dist/index.d.cts", 'import Stream from "./index.js"; export = Stream;');
39+
}
40+
41+
await Promise.all([buildEsm(), buildCjs()]);

package.json

Lines changed: 10 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -6,10 +6,12 @@
66
"scripts": {
77
"lint": "tsc && eslint .",
88
"format": "eslint --fix .",
9-
"build": "tsup ./src/index.ts",
109
"doc": "typedoc ./src --media ./media --plugin typedoc-plugin-extras --favicon ./media/logo.png --footerLastModified true --plugin typedoc-material-theme --themeColor '#03284e' --plugin typedoc-plugin-rename-defaults",
1110
"test": "vitest",
12-
"ci:release": "npm run build && changeset publish"
11+
"build": "rm -rf dist && pnpm run build:js && pnpm run build:types",
12+
"build:js": "node build.mjs",
13+
"build:types": "tsc -p tsconfig.types.json",
14+
"ci:release": "pnpm run build && changeset publish"
1315
},
1416
"keywords": [],
1517
"files": [
@@ -20,14 +22,12 @@
2022
"types": "./dist/index.d.cts",
2123
"exports": {
2224
".": {
23-
"import": {
24-
"types": "./dist/index.d.ts",
25-
"default": "./dist/index.js"
25+
"types": {
26+
"import": "./dist/index.d.ts",
27+
"require": "./dist/index.d.cts"
2628
},
27-
"require": {
28-
"types": "./dist/index.d.cts",
29-
"default": "./dist/index.cjs"
30-
}
29+
"import": "./dist/index.js",
30+
"require": "./dist/index.cjs"
3131
}
3232
},
3333
"author": {
@@ -45,14 +45,13 @@
4545
"@eslint/js": "^9.0.0",
4646
"@types/highland": "^2.13.0",
4747
"@types/node": "^20.10.7",
48+
"esbuild": "^0.27.3",
4849
"eslint": "^8.57.0",
4950
"eslint-config-prettier": "^9.1.0",
5051
"eslint-plugin-prettier": "^5.1.3",
5152
"globals": "^15.0.0",
5253
"highland": "^2.13.5",
53-
"npm-run-all": "^4.1.5",
5454
"prettier": "3.2.5",
55-
"tsup": "^8.0.1",
5655
"typedoc": "^0.25.7",
5756
"typedoc-material-theme": "^1.0.2",
5857
"typedoc-plugin-extras": "^3.0.0",
@@ -64,16 +63,5 @@
6463
"publishConfig": {
6564
"access": "public"
6665
},
67-
"tsup": {
68-
"format": [
69-
"esm",
70-
"cjs"
71-
],
72-
"splitting": true,
73-
"cjsInterop": true,
74-
"dts": {
75-
"footer": "export = Stream"
76-
}
77-
},
7866
"packageManager": "pnpm@8.14.0+sha1.bb42032ff80dba5f9245bc1b03470d2fa0b7fb2f"
7967
}

0 commit comments

Comments
 (0)