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
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
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"],
// 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