From 8ca5c3833a456ddc4d70a22974cff548424f296c Mon Sep 17 00:00:00 2001 From: Michael Tichopad Date: Sat, 20 Sep 2025 11:45:13 +0200 Subject: [PATCH 1/2] Switch generated test runner file to CJS Fixes ESM compatibility of the transformed output by changing the generated test_runner.js to a .cjs extension. --- README.md | 2 +- lib/npm_ignore.test.ts | 2 +- lib/npm_ignore.ts | 2 +- lib/package_json.test.ts | 4 ++-- lib/package_json.ts | 2 +- mod.ts | 2 +- tests/integration.test.ts | 34 +++++++++++++++++----------------- 7 files changed, 24 insertions(+), 24 deletions(-) diff --git a/README.md b/README.md index 8394625..e0932df 100644 --- a/README.md +++ b/README.md @@ -92,7 +92,7 @@ There are several steps done in a pipeline: [dnt] Running tests... > test -> node test_runner.js +> node test_runner.cjs Running tests in ./script/mod.test.js... diff --git a/lib/npm_ignore.test.ts b/lib/npm_ignore.test.ts index bd52948..4e6454a 100644 --- a/lib/npm_ignore.test.ts +++ b/lib/npm_ignore.test.ts @@ -144,7 +144,7 @@ function runTest(options: { } return startText + - `/test_runner.js + `/test_runner.cjs yarn.lock pnpm-lock.yaml `; diff --git a/lib/npm_ignore.ts b/lib/npm_ignore.ts index f160c16..fd92d3f 100644 --- a/lib/npm_ignore.ts +++ b/lib/npm_ignore.ts @@ -51,7 +51,7 @@ export function getNpmIgnoreText(options: { yield `/types/${dtsFilePath}`; } } - yield "/test_runner.js"; + yield "/test_runner.cjs"; } function isUsingSourceMaps() { diff --git a/lib/package_json.test.ts b/lib/package_json.test.ts index 490ecd0..0df34eb 100644 --- a/lib/package_json.test.ts +++ b/lib/package_json.test.ts @@ -79,7 +79,7 @@ Deno.test("single entrypoint", () => { }, }, scripts: { - test: "node test_runner.js", + test: "node test_runner.cjs", }, _generatedBy: "dnt@dev", }); @@ -499,7 +499,7 @@ Deno.test("peer dependencies", () => { }, }, scripts: { - test: "node test_runner.js", + test: "node test_runner.cjs", }, dependencies: { dep: "^1.0.0", diff --git a/lib/package_json.ts b/lib/package_json.ts index ecdc31d..485080e 100644 --- a/lib/package_json.ts +++ b/lib/package_json.ts @@ -90,7 +90,7 @@ export function getPackageJson({ }; const scripts = testEnabled ? ({ - test: "node test_runner.js", + test: "node test_runner.cjs", // override with specified scripts ...(packageJsonObj.scripts ?? {}), }) diff --git a/mod.ts b/mod.ts index 29fc8e0..0988648 100644 --- a/mod.ts +++ b/mod.ts @@ -606,7 +606,7 @@ export async function build(options: BuildOptions): Promise { const denoTestShimPackage = getDependencyByName("@deno/shim-deno-test") ?? getDependencyByName("@deno/shim-deno"); writeFile( - path.join(options.outDir, "test_runner.js"), + path.join(options.outDir, "test_runner.cjs"), transformCodeToTarget( getTestRunnerCode({ denoTestShimPackageName: denoTestShimPackage == null diff --git a/tests/integration.test.ts b/tests/integration.test.ts index f6a8668..bf7ce82 100644 --- a/tests/integration.test.ts +++ b/tests/integration.test.ts @@ -72,7 +72,7 @@ Deno.test("should build test project - basic", async () => { }, }, scripts: { - test: "node test_runner.js", + test: "node test_runner.cjs", }, dependencies: { tslib: versions.tsLib, @@ -116,7 +116,7 @@ Deno.test("should build test project - basic", async () => { /esm/_dnt.test_shims.d.ts /script/_dnt.test_shims.js /script/_dnt.test_shims.d.ts -/test_runner.js +/test_runner.cjs yarn.lock pnpm-lock.yaml `, @@ -150,7 +150,7 @@ Deno.test("should build test project without esm", async () => { version: "1.0.0", main: "./script/mod.js", scripts: { - test: "node test_runner.js", + test: "node test_runner.cjs", }, types: "./types/mod.d.ts", dependencies: { @@ -181,7 +181,7 @@ Deno.test("should build test project without esm", async () => { /types/_dnt.test_polyfills.d.ts /script/_dnt.test_shims.js /types/_dnt.test_shims.d.ts -/test_runner.js +/test_runner.cjs yarn.lock pnpm-lock.yaml `, @@ -231,7 +231,7 @@ Deno.test("should build with all options off", async () => { assertEquals( output.npmIgnore, `/src/ -/test_runner.js +/test_runner.cjs yarn.lock pnpm-lock.yaml `, @@ -297,7 +297,7 @@ Deno.test("should build test project with declarations inline by default", async }, }, scripts: { - test: "node test_runner.js", + test: "node test_runner.cjs", }, dependencies: { tslib: versions.tsLib, @@ -373,7 +373,7 @@ Deno.test("should build bin project", async () => { add: "./esm/mod.js", }, scripts: { - test: "node test_runner.js", + test: "node test_runner.cjs", }, devDependencies: { "@types/node": versions.nodeTypes, @@ -418,7 +418,7 @@ Deno.test("should build bin project with a shebang", async () => { hello: "./esm/main.js", }, scripts: { - test: "node test_runner.js", + test: "node test_runner.cjs", }, devDependencies: { picocolors: versions.picocolors, @@ -515,7 +515,7 @@ Deno.test("not error for TLA when not using CommonJS", async () => { }, }, scripts: { - test: "node test_runner.js", + test: "node test_runner.cjs", }, types: "./types/mod.d.ts", devDependencies: { @@ -590,7 +590,7 @@ Deno.test("should build with source maps", async () => { /script/_dnt.test_shims.js /script/_dnt.test_shims.js.map /script/_dnt.test_shims.d.ts -/test_runner.js +/test_runner.cjs yarn.lock pnpm-lock.yaml `, @@ -636,7 +636,7 @@ Deno.test("should build with package mappings", async () => { }, }, scripts: { - test: "node test_runner.js", + test: "node test_runner.cjs", }, types: "./types/mod.d.ts", dependencies: { @@ -659,7 +659,7 @@ Deno.test("should build with package mappings", async () => { /esm/_dnt.test_shims.js /script/_dnt.test_shims.js /types/_dnt.test_shims.d.ts -/test_runner.js +/test_runner.cjs yarn.lock pnpm-lock.yaml `, @@ -705,7 +705,7 @@ Deno.test("should build with peer dependencies in mappings", async () => { }, }, scripts: { - test: "node test_runner.js", + test: "node test_runner.cjs", }, types: "./types/mod.d.ts", peerDependencies: { @@ -1171,7 +1171,7 @@ Deno.test("should build jsr project", async () => { }, }, scripts: { - test: "node test_runner.js", + test: "node test_runner.cjs", }, dependencies: { tslib: versions.tsLib, @@ -1195,7 +1195,7 @@ Deno.test("should build jsr project", async () => { /esm/_dnt.test_shims.d.ts /script/_dnt.test_shims.js /script/_dnt.test_shims.d.ts -/test_runner.js +/test_runner.cjs yarn.lock pnpm-lock.yaml `, @@ -1241,7 +1241,7 @@ Deno.test("should build workspace project", async () => { }, }, scripts: { - test: "node test_runner.js", + test: "node test_runner.cjs", }, dependencies: { tslib: versions.tsLib, @@ -1254,7 +1254,7 @@ Deno.test("should build workspace project", async () => { assertEquals( output.npmIgnore, `/src/ -/test_runner.js +/test_runner.cjs yarn.lock pnpm-lock.yaml `, From da266aa780797686d248831c45219c618a0a5cc6 Mon Sep 17 00:00:00 2001 From: Michael Tichopad Date: Sat, 20 Sep 2025 13:20:51 +0200 Subject: [PATCH 2/2] Exclude no-import-prefix lint rule + add a version specifier to @std/csv import --- deno.jsonc | 3 ++- deno.lock | 3 ++- tests/jsr_project/mod.ts | 2 +- 3 files changed, 5 insertions(+), 3 deletions(-) diff --git a/deno.jsonc b/deno.jsonc index 2d1fed1..7db211e 100644 --- a/deno.jsonc +++ b/deno.jsonc @@ -8,7 +8,8 @@ "rules": { "exclude": [ "no-explicit-any", - "camelcase" + "camelcase", + "no-import-prefix" ] } }, diff --git a/deno.lock b/deno.lock index ecf57bf..8104a47 100644 --- a/deno.lock +++ b/deno.lock @@ -6,13 +6,14 @@ "jsr:@std/assert@1": "1.0.13", "jsr:@std/bytes@^1.0.4": "1.0.4", "jsr:@std/csv@*": "1.0.6", + "jsr:@std/csv@1.0.6": "1.0.6", "jsr:@std/fmt@0.221": "0.221.0", "jsr:@std/fmt@1": "1.0.8", "jsr:@std/fs@1": "1.0.19", "jsr:@std/internal@^1.0.1": "1.0.1", "jsr:@std/internal@^1.0.6": "1.0.9", "jsr:@std/internal@^1.0.9": "1.0.9", - "jsr:@std/path@1": "1.0.2", + "jsr:@std/path@1": "1.1.1", "jsr:@std/path@^1.0.2": "1.0.2", "jsr:@std/path@^1.1.1": "1.1.1", "jsr:@ts-morph/bootstrap@0.27": "0.27.0", diff --git a/tests/jsr_project/mod.ts b/tests/jsr_project/mod.ts index 4fa865a..ab36001 100644 --- a/tests/jsr_project/mod.ts +++ b/tests/jsr_project/mod.ts @@ -1,6 +1,6 @@ // Copyright 2018-2024 the Deno authors. MIT license. -import { parse } from "jsr:@std/csv/parse"; +import { parse } from "jsr:@std/csv@1.0.6/parse"; import { assertEquals } from "jsr:@std/assert@0.221/assert-equals"; import * as fs from "node:fs";