Skip to content
Draft
Show file tree
Hide file tree
Changes from all 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
18 changes: 18 additions & 0 deletions .github/workflows/test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -21,3 +21,21 @@ 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
Copy link

Copilot AI Mar 1, 2026

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.
- name: Setup Node.js
uses: actions/setup-node@v4
with:
node-version: "lts/*"
- name: Smoke test Node artifact
run: node -e "import('./dist/npm.js')"
66 changes: 33 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,51 @@ if (command === "clean") {

/* Handle argument `build`: Transpile and generate typings */
} else if (command === "build") {
// Plugin to bundle JSR packages like @cross/runtime by resolving them via Deno's cache
const jsrResolverPlugin: esbuild.Plugin = {
name: "jsr-resolver",
setup(pluginBuild) {
pluginBuild.onResolve({ filter: /^@cross\/runtime$/ }, async (_args) => {
const cmd = new Deno.Command("deno", {
args: ["info", "--json", "jsr:@cross/runtime"],
cwd: relativeProjectRoot,
stdout: "piped",
stderr: "piped",
});
const { stdout, success } = await cmd.output();
if (!success) return null;
const info = JSON.parse(new TextDecoder().decode(stdout));
const mod = info.modules?.find((m: { specifier: string; local?: string }) => m.local && m.specifier?.endsWith("mod.ts"));
if (mod?.local) return { path: mod.local, namespace: "jsr-ts" };
return null;
});
pluginBuild.onLoad({ filter: /.*/, namespace: "jsr-ts" }, async (args) => {
const contents = await Deno.readTextFile(args.path);
return { contents, loader: "ts" };
});
},
};

// Build the ESM JavaScript bundle
await build({
entryPoints: [resolve(relativeProjectRoot, "mod.ts")],
entryPoints: [resolve(relativeProjectRoot, "npm.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"],
plugins: [jsrResolverPlugin],
// 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/npm.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/npm.js"
},
"license": "MIT"
}
2 changes: 1 addition & 1 deletion deno.json
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,6 @@
"sinon": "npm:sinon@~19.0.2"
},
"publish": {
"exclude": [".github", "*.test.ts", "build", "dist"]
"exclude": [".github", "*.test.ts", "build", "dist", "npm.ts"]
}
}
30 changes: 30 additions & 0 deletions npm.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
// Entry point for the npm (Node.js) build - uses the Node.js shim directly.
// For cross-runtime usage via JSR, use jsr:@cross/test instead.
import type { BrowserTestResult, TestSubject, WrappedTestOptions } from "./mod.ts";
import { wrappedTest } from "./shims/node.ts";

export type { BrowserTestResult, ContextStepFunction, SimpleStepFunction, StepFunction, StepOptions, StepSubject, TestContext, TestSubject, WrappedTest, WrappedTestOptions } from "./mod.ts";

/**
* Defines and executes a single test (Node.js).
* @param name - The name of the test.
* @param testFn - The function containing the test logic.
* @param options? - Options for the test.
*/
export async function test(name: string, testFn: TestSubject, options: WrappedTestOptions = {}) {
await wrappedTest(name, testFn, options);
}

/**
* Not applicable in Node.js - always returns undefined.
*/
export function getTestResults(): BrowserTestResult[] | undefined {
return undefined;
}

/**
* Not applicable in Node.js - no-op.
*/
export function printTestSummary(): void {
// no-op
}