Skip to content
Draft
Show file tree
Hide file tree
Changes from 4 commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 12 additions & 0 deletions .github/workflows/test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -21,3 +21,15 @@ jobs:
test_target: "*.test.ts"
jsr_dependencies: "@std/assert @std/async @cross/runtime"
npm_dependencies: "sinon"
npm_build:
runs-on: ubuntu-latest
permissions:
contents: read
steps:
- uses: actions/checkout@v4
- name: Setup Deno
uses: denoland/setup-deno@v1
with:
deno-version: v2.x
- name: Build npm package
run: deno task build:dist

Copilot AI Mar 1, 2026

Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The new npm_build job only checks that deno task build:dist completes. It doesn’t validate that the produced Node artifact can actually be loaded (e.g., a simple node -e "import('./dist/mod.js')" or importing the generated package entry). Adding a minimal runtime smoke-check here would catch externals/dependency mismatches that still allow bundling to succeed.

Suggested change
run: deno task build:dist
run: deno task build:dist
- name: Setup Node.js
uses: actions/setup-node@v4
with:
node-version: 'lts/*'
- name: Smoke test Node artifact
run: node -e "import('./dist/mod.js')"

Copilot uses AI. Check for mistakes.
41 changes: 8 additions & 33 deletions build/build.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
import esbuild from "esbuild";
import { dtsPlugin } from "esbuild-plugin-d.ts";
import { cp, readFile, writeFile } from "@cross/fs";
import { readFile, writeFile } from "@cross/fs";
import { dirname, fromFileUrl, resolve } from "@std/path";

/**
Expand Down Expand Up @@ -68,50 +67,26 @@ if (command === "clean") {

/* Handle argument `build`: Transpile and generate typings */
} else if (command === "build") {
// Build the ESM JavaScript bundle
await build({
entryPoints: [resolve(relativeProjectRoot, "mod.ts")],
bundle: true,
minify: true,
sourcemap: false,
outdir: resolvedDistPath,
platform: "node",
format: "esm",
// Mark runtime-specific modules as external - they won't be bundled
// node:test is a Node.js built-in, bun:test is a Bun built-in
external: ["bun:test", "node:test"],
// @cross/runtime is a JSR dependency that must be externalized
external: ["bun:test", "node:test", "@cross/runtime"],

Copilot AI Mar 1, 2026

Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@cross/runtime is now marked as an esbuild external, which means the generated dist/mod.js will keep import "@cross/runtime" at runtime. The npm package template currently doesn’t declare any dependency/peerDependency on @cross/runtime, so consumers installing from npm will likely hit a Cannot find package '@cross/runtime' error unless they manually install it. Consider either bundling @cross/runtime (remove it from external) or adding it to the generated package.json (dependencies/peerDependencies) with a version aligned to deno.json.

Suggested change
// @cross/runtime is a JSR dependency that must be externalized
external: ["bun:test", "node:test", "@cross/runtime"],
external: ["bun:test", "node:test"],

Copilot uses AI. Check for mistakes.
// Use banner to add a comment
banner: {
js: `// @cross/test - Cross-runtime testing for Deno, Bun, and Node.js
// This build is for Node.js. For Deno, use JSR: jsr:@cross/test
`,
},
}, [
{
outdir: resolvedDistPath,
platform: "node",
format: "cjs",
outExtension: { ".js": ".cjs" },
},
{
outdir: resolvedDistPath,
platform: "node",
format: "esm",
plugins: [dtsPlugin({
experimentalBundling: true,
tsconfig: {
compilerOptions: {
declaration: true,
emitDeclarationOnly: true,
allowImportingTsExtensions: true,
lib: ["es6", "dom"],
},
},
})],
},
]);

// Just re-use the .d.ts for commonjs, as .d.cts
await cp(
resolve(resolvedDistPath, "mod.d.ts"),
resolve(resolvedDistPath, "mod.d.cts"),
);
});

/* Handle argument `package`: Generate package.json based on a base config and values from deno.json */
} else if (command === "package") {
Expand Down
15 changes: 2 additions & 13 deletions build/package.template.json
Original file line number Diff line number Diff line change
Expand Up @@ -26,21 +26,10 @@
"framework"
],
"type": "module",
"main": "./dist/mod.cjs",
"module": "./dist/mod.js",
"types": "./dist/mod.d.ts",
"main": "./dist/mod.js",
"exports": {
"./package.json": "./package.json",
".": {
"import": {
"types": "./dist/mod.d.ts",
"default": "./dist/mod.js"
},
"require": {
"types": "./dist/mod.d.cts",
"default": "./dist/mod.cjs"
}
}
".": "./dist/mod.js"
},
"license": "MIT"
}
Loading