build: publish a real build to npm, and the source to JSR
CI / dco (pull_request) Successful in 4s
CI / runtimes (bun) (pull_request) Successful in 10s
CI / build (pull_request) Successful in 18s
CI / runtimes (deno) (pull_request) Successful in 11s
CI / runtimes (edge) (pull_request) Successful in 9s

Every package exported `./src/index.ts` and had no build at all, which made the
npm half of the dual publish unusable. Measured against a staging registry with
`@green-tea/metrics` installed into a clean project: Node threw
ERR_UNSUPPORTED_NODE_MODULES_TYPE_STRIPPING, `--experimental-strip-types` threw
the same error because Node refuses to strip types under `node_modules`
unconditionally, and Deno-via-npm threw it too. Only Bun could import it. The
release pipeline would have published that to both registries at once.

JSR needs no help — it transpiles on publish and hands Node an ESM package with
generated declarations — so `deno.json` keeps exporting `src/`. The build exists
for npm alone, as CJS and ESM: core is `"type": "commonjs"` and publishes both,
so a CJS application has to be able to `require()` a plugin.

Core stays external in the declarations. tsup bundles devDependencies by
default, and convention rule 8 puts core there, so without that line every
plugin would have shipped a frozen private copy of a contract core owns.

Verified by packing all three and consuming them from outside the workspace:
`require()` and `import` both resolve under Node, Bun and Deno, and `tsc`
type-checks clean under `node16` and `bundler` resolution.

Signed-off-by: Diego Resendez <diego.resendez@zero-oneit.com>
This commit is contained in:
chrnx committed 2026-09-19 11:58:54 -05:00
1 parent a7253196dc
commit 3b1eceecb9
12 files changed
+1522 -5

No files matched your search

+4
View File
@@ -55,6 +55,10 @@ jobs:
- run: npm run complexity:check - run: npm run complexity:check
- run: npm run typecheck - run: npm run typecheck
- run: npm test - run: npm test
# The npm tarball is a build artifact, so a broken build is a broken release. `typecheck` will
# not catch it: that runs with `noEmit`, and tsup emits through esbuild, which resolves and
# bundles on its own terms.
- run: npm run build
# A fixed matrix, not `fromJSON`: Gitea Actions support for a dynamic matrix was not verified. Each # A fixed matrix, not `fromJSON`: Gitea Actions support for a dynamic matrix was not verified. Each
# entry runs only the packages whose engines name that runtime (scripts/run-runtime.mjs). # entry runs only the packages whose engines name that runtime (scripts/run-runtime.mjs).
+7
View File
@@ -18,6 +18,7 @@ npm run typecheck
npm test # Node: every package's contract tests + the workspace checks npm test # Node: every package's contract tests + the workspace checks
npm run test:deno # packages whose engines declare deno npm run test:deno # packages whose engines declare deno
npm run test:bun # packages whose engines declare bun npm run test:bun # packages whose engines declare bun
npm run build # tsup, every package: dist/ as CJS + ESM + declarations, for npm only
``` ```
Run all of them before proposing anything as finished. CI runs each one and each gates a merge. Run all of them before proposing anything as finished. CI runs each one and each gates a merge.
@@ -48,6 +49,12 @@ a pull request. Until core is consumed from npm (Plan B3), CI runs on Gitea only
beside every one that is not supported. Nobody should have to open an issue to learn where a beside every one that is not supported. Nobody should have to open an issue to learn where a
plugin runs. plugin runs.
10. A breaking change goes under `### Breaking`, first in the package's CHANGELOG. 10. A breaking change goes under `### Breaking`, first in the package's CHANGELOG.
11. **The two registries are served different things.** `deno.json` exports `./src/index.ts`, because
JSR transpiles TypeScript itself and hands Node a typed ESM package. `package.json` exports
`./dist/`, built by tsup as CJS *and* ESM, because npm transpiles nothing and Node refuses to
strip types under `node_modules` — `--experimental-strip-types` does not lift that, so a package
exporting `.ts` installs cleanly and then throws on the first import, everywhere but Bun.
`test/workspace.test.ts` pins both halves.
## Conventions ## Conventions
+3 -1
View File
@@ -3,7 +3,9 @@ import tseslint from 'typescript-eslint';
import stylistic from '@stylistic/eslint-plugin'; import stylistic from '@stylistic/eslint-plugin';
export default tseslint.config( export default tseslint.config(
{ ignores: ['dist', 'node_modules', 'coverage'] }, // Flat-config ignores are literal paths unless globbed, and the build output now lives one level
// down in every package — a bare 'dist' would only have covered a root directory that does not exist.
{ ignores: ['**/dist', '**/node_modules', '**/coverage'] },
js.configs.recommended, js.configs.recommended,
...tseslint.configs.recommended, ...tseslint.configs.recommended,
{ {
+1353
View File
File diff suppressed because it is too large. Load diff
+5 -1
View File
@@ -3,11 +3,14 @@
"private": true, "private": true,
"license": "MIT", "license": "MIT",
"type": "module", "type": "module",
"workspaces": ["packages/*"], "workspaces": [
"packages/*"
],
"engines": { "engines": {
"node": ">=22" "node": ">=22"
}, },
"scripts": { "scripts": {
"build": "npm run build --workspaces",
"lint": "eslint --no-error-on-unmatched-pattern packages test", "lint": "eslint --no-error-on-unmatched-pattern packages test",
"format": "prettier --write \"packages/*/{src,test}/**/*.ts\" \"test/**/*.ts\"", "format": "prettier --write \"packages/*/{src,test}/**/*.ts\" \"test/**/*.ts\"",
"format:check": "prettier --check \"packages/*/{src,test}/**/*.ts\" \"test/**/*.ts\"", "format:check": "prettier --check \"packages/*/{src,test}/**/*.ts\" \"test/**/*.ts\"",
@@ -26,6 +29,7 @@
"cognitive-complexity-ts": "^0.8.2", "cognitive-complexity-ts": "^0.8.2",
"eslint": "^9.39.5", "eslint": "^9.39.5",
"prettier": "^3.9.6", "prettier": "^3.9.6",
"tsup": "^8.5.1",
"tsx": "^4.23.5", "tsx": "^4.23.5",
"typescript": "^5.5.0", "typescript": "^5.5.0",
"typescript-eslint": "^8.70.0" "typescript-eslint": "^8.70.0"
+22 -1
View File
@@ -16,8 +16,29 @@
"deno": ">=2", "deno": ">=2",
"bun": ">=1.3" "bun": ">=1.3"
}, },
"main": "./dist/index.cjs",
"module": "./dist/index.js",
"types": "./dist/index.d.ts",
"files": [
"dist",
"README.md",
"CHANGELOG.md"
],
"exports": { "exports": {
".": "./src/index.ts" ".": {
"import": {
"types": "./dist/index.d.ts",
"default": "./dist/index.js"
},
"require": {
"types": "./dist/index.d.cts",
"default": "./dist/index.cjs"
}
}
},
"scripts": {
"build": "tsup",
"prepublishOnly": "npm run build"
}, },
"dependencies": { "dependencies": {
"jose": "^6.2.12" "jose": "^6.2.12"
+17
View File
@@ -0,0 +1,17 @@
import { defineConfig } from 'tsup';
// The npm half of the dual publish. JSR serves `src/` straight from `deno.json` and transpiles it
// itself, so nothing here is JSR's problem — this exists because a plain `npm i` gets none of that
// and Node refuses to strip types under `node_modules`.
export default defineConfig({
entry: ['src/index.ts'],
format: ['cjs', 'esm'],
dts: true,
clean: true,
sourcemap: true,
target: 'node22',
// Convention rule 8 keeps core in `devDependencies`, and tsup bundles devDependencies by default.
// Without this line the emitted declarations would inline core's types rather than import them,
// and every plugin would ship a frozen private copy of a contract core owns.
external: ['@green-tea/core'],
});
+22 -1
View File
@@ -16,8 +16,29 @@
"deno": ">=2", "deno": ">=2",
"bun": ">=1.3" "bun": ">=1.3"
}, },
"main": "./dist/index.cjs",
"module": "./dist/index.js",
"types": "./dist/index.d.ts",
"files": [
"dist",
"README.md",
"CHANGELOG.md"
],
"exports": { "exports": {
".": "./src/index.ts" ".": {
"import": {
"types": "./dist/index.d.ts",
"default": "./dist/index.js"
},
"require": {
"types": "./dist/index.d.cts",
"default": "./dist/index.cjs"
}
}
},
"scripts": {
"build": "tsup",
"prepublishOnly": "npm run build"
}, },
"devDependencies": { "devDependencies": {
"@green-tea/core": "26.9.0-beta.2" "@green-tea/core": "26.9.0-beta.2"
+17
View File
@@ -0,0 +1,17 @@
import { defineConfig } from 'tsup';
// The npm half of the dual publish. JSR serves `src/` straight from `deno.json` and transpiles it
// itself, so nothing here is JSR's problem — this exists because a plain `npm i` gets none of that
// and Node refuses to strip types under `node_modules`.
export default defineConfig({
entry: ['src/index.ts'],
format: ['cjs', 'esm'],
dts: true,
clean: true,
sourcemap: true,
target: 'node22',
// Convention rule 8 keeps core in `devDependencies`, and tsup bundles devDependencies by default.
// Without this line the emitted declarations would inline core's types rather than import them,
// and every plugin would ship a frozen private copy of a contract core owns.
external: ['@green-tea/core'],
});
+22 -1
View File
@@ -16,8 +16,29 @@
"deno": ">=2", "deno": ">=2",
"bun": ">=1.3" "bun": ">=1.3"
}, },
"main": "./dist/index.cjs",
"module": "./dist/index.js",
"types": "./dist/index.d.ts",
"files": [
"dist",
"README.md",
"CHANGELOG.md"
],
"exports": { "exports": {
".": "./src/index.ts" ".": {
"import": {
"types": "./dist/index.d.ts",
"default": "./dist/index.js"
},
"require": {
"types": "./dist/index.d.cts",
"default": "./dist/index.cjs"
}
}
},
"scripts": {
"build": "tsup",
"prepublishOnly": "npm run build"
}, },
"devDependencies": { "devDependencies": {
"@green-tea/core": "26.9.0-beta.2" "@green-tea/core": "26.9.0-beta.2"
+17
View File
@@ -0,0 +1,17 @@
import { defineConfig } from 'tsup';
// The npm half of the dual publish. JSR serves `src/` straight from `deno.json` and transpiles it
// itself, so nothing here is JSR's problem — this exists because a plain `npm i` gets none of that
// and Node refuses to strip types under `node_modules`.
export default defineConfig({
entry: ['src/index.ts'],
format: ['cjs', 'esm'],
dts: true,
clean: true,
sourcemap: true,
target: 'node22',
// Convention rule 8 keeps core in `devDependencies`, and tsup bundles devDependencies by default.
// Without this line the emitted declarations would inline core's types rather than import them,
// and every plugin would ship a frozen private copy of a contract core owns.
external: ['@green-tea/core'],
});
+33
View File
@@ -19,6 +19,12 @@ interface PackageJson {
devDependencies?: Record<string, string>; devDependencies?: Record<string, string>;
peerDependencies?: Record<string, string>; peerDependencies?: Record<string, string>;
repository?: { type?: string; url?: string; directory?: string }; repository?: { type?: string; url?: string; directory?: string };
main?: string;
module?: string;
types?: string;
files?: string[];
exports?: unknown;
scripts?: Record<string, string>;
} }
interface DenoJson { interface DenoJson {
@@ -26,6 +32,7 @@ interface DenoJson {
version?: string; version?: string;
imports?: Record<string, string>; imports?: Record<string, string>;
workspace?: string[]; workspace?: string[];
exports?: string;
} }
const readJson = <T>(...path: string[]): T => JSON.parse(readFileSync(join(ROOT, ...path), 'utf8')) as T; const readJson = <T>(...path: string[]): T => JSON.parse(readFileSync(join(ROOT, ...path), 'utf8')) as T;
@@ -97,4 +104,30 @@ for (const dir of packages) {
test(`${dir}: the Deno workspace includes it`, () => { test(`${dir}: the Deno workspace includes it`, () => {
assert.ok(readJson<DenoJson>('deno.json').workspace?.includes(`./packages/${dir}`)); assert.ok(readJson<DenoJson>('deno.json').workspace?.includes(`./packages/${dir}`));
}); });
test(`${dir}: npm is served the build and JSR the source`, () => {
// The two registries are fed different things on purpose. JSR transpiles TypeScript itself, so
// it gets `src/`. npm does not, and Node refuses to strip types under `node_modules` — a package
// whose `exports` pointed at a `.ts` file installed fine and then threw on the first import.
assert.equal(deno.exports, './src/index.ts', 'JSR should publish the TypeScript source');
assert.deepEqual(pkg.exports, {
'.': {
import: { types: './dist/index.d.ts', default: './dist/index.js' },
require: { types: './dist/index.d.cts', default: './dist/index.cjs' },
},
});
assert.equal(pkg.main, './dist/index.cjs');
assert.equal(pkg.module, './dist/index.js');
assert.equal(pkg.types, './dist/index.d.ts');
});
test(`${dir}: the tarball ships the build and nothing else`, () => {
// Without `files`, npm packs the whole directory — the first tarball carried `test/` along.
assert.deepEqual(pkg.files, ['dist', 'README.md', 'CHANGELOG.md']);
assert.equal(pkg.scripts?.build, 'tsup');
// A stale `dist/` is the one packaging failure no static check can see, so the build runs again
// on the way out rather than trusting whatever CI left behind.
assert.equal(pkg.scripts?.prepublishOnly, 'npm run build');
});
} }