Skip to content

Commit 8c96654

Browse files
authored
Fix ESM compatibility in resolveBinary and add CI smoke test (#743)
Replace bare require.resolve() with createRequire(import.meta.url) to fix ReferenceError when running as an ES module (package.json has "type": "module"). Add an npm test script that imports the built output and calls resolveBinary() to catch ESM/CJS incompatibilities before publish. <!-- CURSOR_SUMMARY --> --- > [!NOTE] > **Low Risk** > Low risk: small, targeted change to module resolution plus a new CI test step; main risk is potential path-resolution differences across Node environments. > > **Overview** > Fixes ESM compatibility in the TypeScript `dbmate` package by switching `resolveBinary()` to use `createRequire(import.meta.url)` for `require.resolve()`. > > Adds a lightweight `npm test` smoke test (and runs it in the GitHub Actions NPM job) that imports the built `dist` output and verifies `resolveBinary()` can resolve the platform binary before `publish`. > > <sup>Written by [Cursor Bugbot](https://cursor.com/dashboard?tab=bugbot) for commit 538facd. This will update automatically on new commits. Configure [here](https://cursor.com/dashboard?tab=bugbot).</sup> <!-- /CURSOR_SUMMARY -->
1 parent 0e1e83a commit 8c96654

File tree

3 files changed

+7
-0
lines changed

3 files changed

+7
-0
lines changed

.github/workflows/ci.yml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -211,6 +211,9 @@ jobs:
211211
- run: npm run generate
212212
working-directory: typescript
213213

214+
- run: npm test
215+
working-directory: typescript
216+
214217
- run: npm run publish
215218
if: ${{ startsWith(github.ref, 'refs/tags/v') }}
216219
working-directory: typescript

typescript/package.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
"clean": "rimraf dist packages/dbmate/dist",
77
"lint": "eslint --report-unused-disable-directives --fix .",
88
"lint:ci": "eslint --report-unused-disable-directives .",
9+
"test": "mkdir -p dist/dbmate/node_modules && ln -sfn ../../@dbmate dist/dbmate/node_modules/@dbmate && node --input-type=module -e \"const { resolveBinary } = await import('./dist/dbmate/dist/index.js'); const bin = resolveBinary(); console.log('resolved binary:', bin);\"",
910
"generate": "tsx generate.ts",
1011
"publish": "tsx publish.ts"
1112
},

typescript/packages/dbmate/src/resolveBinary.ts

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,8 @@
1+
import { createRequire } from "node:module";
12
import { arch, platform } from "node:process";
23

4+
const require = createRequire(import.meta.url);
5+
36
/**
47
* Resolve path to dbmate for the current platform
58
* */

0 commit comments

Comments
 (0)