Skip to content

Commit

Permalink
chore: run tests on all supported versions of Node.js (#77)
Browse files Browse the repository at this point in the history
* pin esmock dependency to v2.3

* patch esmock, don't pin version

* update comments

* run patch in `prepare` script
  • Loading branch information
fasttime authored Oct 25, 2023
1 parent 4bde28a commit f7da13a
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 1 deletion.
4 changes: 3 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@
},
"scripts": {
"lint": "eslint . --report-unused-disable-directives",
"prepare": "node tests/patch-esmock.js",
"release:generate:latest": "eslint-generate-release",
"release:generate:alpha": "eslint-generate-prerelease alpha",
"release:generate:beta": "eslint-generate-prerelease beta",
Expand Down Expand Up @@ -58,7 +59,8 @@
"eslint": "^8.48.0",
"eslint-config-eslint": "^9.0.0",
"eslint-release": "^3.2.0",
"esmock": "^2.2.3",
"esmock": "^2.5.8",
"esmock_legacy": "npm:esmock@~2.3.8",
"espree": "^9.0.0",
"globals": "^13.21.0",
"lint-staged": "^12.1.2",
Expand Down
22 changes: 22 additions & 0 deletions tests/patch-esmock.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
/**
* @fileoverview Run by npm to replace esmock with a legacy release on older versions of Node.js.
* @author Francesco Trotta
*/

import { promises as fs } from "fs";

// * esmock < 2.4 works only on Node.js < 19.
// * esmock >= 2.4 works only on Node.js >= 18.6.
// If we are running Node.js < 19, replace the esmock dependency with the legacy release.
// 111 is the ABI version number of Node.js 19: https://nodejs.org/en/download/releases
if (process.versions.modules < 111) {
(async () => {
try {
await fs.access("node_modules/esmock_legacy");
} catch {
return;
}
await fs.rmdir("node_modules/esmock", { recursive: true });
await fs.rename("node_modules/esmock_legacy", "node_modules/esmock");
})();
}

0 comments on commit f7da13a

Please sign in to comment.