diff --git a/.github/workflows/test-token.yml b/.github/workflows/test-token.yml index fb9bbfa..b75c9f8 100644 --- a/.github/workflows/test-token.yml +++ b/.github/workflows/test-token.yml @@ -1,6 +1,8 @@ name: Test get-installation-token on: + push: + branches: [main] workflow_dispatch: permissions: diff --git a/esbuild.config.js b/esbuild.config.js index 0294e97..a4997af 100644 --- a/esbuild.config.js +++ b/esbuild.config.js @@ -1,10 +1,13 @@ // @ts-check import { build } from "esbuild"; -import { readFileSync, writeFileSync } from "fs"; +import { mkdirSync, readFileSync, rmSync, writeFileSync } from "fs"; const pkg = JSON.parse(readFileSync("package.json", "utf-8")); +rmSync("./dist", { recursive: true, force: true }); +mkdirSync("./dist", { recursive: true }); + // Plugin to strip shebangs from output files /** * @type {import("esbuild").Plugin} @@ -73,6 +76,21 @@ await build({ }, }); +// Build ESM library entrypoints for programmatic imports +await build({ + ...sharedConfig, + entryPoints: ["./index.ts"], + outfile: "./dist/index.js", + target: "node20", +}); + +await build({ + ...sharedConfig, + entryPoints: ["./internal/index.ts"], + outfile: "./dist/internal.js", + target: "node20", +}); + // prepend shebang after strip (esbuild banner can't guarantee line 1 placement) const cliPath = "./dist/cli.mjs"; const cliContent = readFileSync(cliPath, "utf8"); diff --git a/package.json b/package.json index 420c363..da8750f 100644 --- a/package.json +++ b/package.json @@ -13,7 +13,7 @@ "scripts": { "test": "vitest", "typecheck": "tsc --noEmit", - "build": "node esbuild.config.js", + "build": "node esbuild.config.js && tsc -p tsconfig.exports.json", "check:entrypoints": "node scripts/check-entrypoint-imports.ts", "play": "node play.ts", "runtest": "node test/run.ts", @@ -74,14 +74,21 @@ "url": "https://github.com/pullfrog/pullfrog/issues" }, "homepage": "https://github.com/pullfrog/pullfrog#readme", + "main": "./dist/index.js", + "module": "./dist/index.js", + "types": "./dist/index.d.ts", "exports": { ".": { "@pullfrog/source": "./index.ts", - "default": "./index.ts" + "types": "./dist/index.d.ts", + "import": "./dist/index.js", + "default": "./dist/index.js" }, "./internal": { "@pullfrog/source": "./internal/index.ts", - "default": "./internal/index.ts" + "types": "./dist/internal/index.d.ts", + "import": "./dist/internal.js", + "default": "./dist/internal.js" }, "./package.json": "./package.json" }, diff --git a/tsconfig.exports.json b/tsconfig.exports.json new file mode 100644 index 0000000..ed67409 --- /dev/null +++ b/tsconfig.exports.json @@ -0,0 +1,10 @@ +{ + "extends": "./tsconfig.json", + "compilerOptions": { + "noEmit": false, + "emitDeclarationOnly": true, + "declarationMap": false, + "outDir": "./dist" + }, + "include": ["index.ts", "internal/index.ts"] +}