Skip to content

Commit

Permalink
feat(build): 🏗️ Build plain JS for NPM
Browse files Browse the repository at this point in the history
  • Loading branch information
CPlusPatch committed Jul 22, 2024
1 parent 8a4b246 commit 2bf97bc
Show file tree
Hide file tree
Showing 4 changed files with 25 additions and 14 deletions.
5 changes: 2 additions & 3 deletions .github/workflows/publish.yml
Original file line number Diff line number Diff line change
Expand Up @@ -53,9 +53,8 @@ jobs:
node-version: "22"
registry-url: "https://registry.npmjs.org"

# Code is not minified and bundled anymore
#- name: Build
# run: bun run build
- name: Build
run: bun run build

- name: Change version in package.json to ${{ github.event.inputs.version }}, defaulting to the truncated commit hash
run: 'sed -i ''s/"version": ".*"/"version": "${{ github.event.inputs.version }}"/'' package.json ${{ github.event.inputs.package }}/package.json ${{ github.event.inputs.package }}/jsr.jsonc'
Expand Down
9 changes: 8 additions & 1 deletion build.ts
Original file line number Diff line number Diff line change
@@ -1,11 +1,18 @@
import dts from "bun-plugin-dts";
import ora from "ora";

const entrypoints = {
federation: ["index.ts", "schemas.ts", "requester.ts"],
client: ["index.ts", "types.ts"],
};

for (const pkg of ["federation", "client"]) {
const subSpinner = ora(`Building ${pkg} module`).start();

await Bun.build({
entrypoints: [`${pkg}/index.ts`],
entrypoints: entrypoints[pkg as "federation" | "client"].map(
(entrypoint) => `${pkg}/${entrypoint}`,
),
outdir: `${pkg}/dist`,
format: "esm",
minify: true,
Expand Down
10 changes: 6 additions & 4 deletions client/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -39,12 +39,14 @@
},
"exports": {
".": {
"import": "./index.ts",
"default": "./index.ts"
"import": "./dist/index.js",
"default": "./dist/index.js",
"types": "./dist/index.d.ts"
},
"./types": {
"import": "./types.ts",
"default": "./types.ts"
"import": "./dist/types.js",
"default": "./dist/types.js",
"types": "./dist/types.d.ts"
}
},
"funding": {
Expand Down
15 changes: 9 additions & 6 deletions federation/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -39,16 +39,19 @@
},
"exports": {
".": {
"import": "./index.ts",
"default": "./index.ts"
"import": "./dist/index.js",
"default": "./dist/index.js",
"types": "./dist/index.d.ts"
},
"./requester": {
"import": "./requester.ts",
"default": "./requester.ts"
"import": "./dist/requester.js",
"default": "./dist/requester.js",
"types": "./dist/requester.d.ts"
},
"./types": {
"import": "./schemas.ts",
"default": "./schemas.ts"
"import": "./dist/schema.js",
"default": "./dist/schema.js",
"types": "./dist/schema.d.ts"
}
},
"funding": {
Expand Down

0 comments on commit 2bf97bc

Please sign in to comment.