From 40651613e9281809f508178cd778eac85d4654a5 Mon Sep 17 00:00:00 2001 From: Joe Hildebrand Date: Mon, 26 Feb 2024 08:28:27 -0700 Subject: [PATCH] Half-support node 18 --- .github/workflows/node.js.yml | 2 +- README.md | 9 ++++--- package.json | 2 +- test/index.test.js | 47 +++++++++++++++++++++-------------- 4 files changed, 35 insertions(+), 25 deletions(-) diff --git a/.github/workflows/node.js.yml b/.github/workflows/node.js.yml index 7c4fec5..6b4fe66 100644 --- a/.github/workflows/node.js.yml +++ b/.github/workflows/node.js.yml @@ -12,7 +12,7 @@ jobs: strategy: matrix: - node-version: [20.x, 21.x] + node-version: [18.x, 20.x, 21.x] os: [ubuntu-latest, windows-latest, macos-latest] runs-on: ${{ matrix.os }} diff --git a/README.md b/README.md index 26b87fe..9c9d7d2 100644 --- a/README.md +++ b/README.md @@ -81,11 +81,12 @@ export type FromMemOptions = { ## Caveats -- This module has a strong requirement for node 20.8+ at runtime, due to a bug -that crashes node in node's vm module that got fixed there and in 21.0. +- This module has a strong requirement for node 20.8+ at runtime when using + the es6 format, due to a bug that crashes node in node's vm module that got + fixed there and in 21.0. There is a runtime check to prevent the crash. - This module requires being run with the `--experimental-vm-modules` flag -for node for the moment. Hopefully, we will track changes to the API as they -happen. + for node for the moment. Hopefully, we will track changes to the API as + they happen. [![Tests](https://github.com/peggyjs/from-mem/actions/workflows/node.js.yml/badge.svg)](https://github.com/peggyjs/from-mem/actions/workflows/node.js.yml) [![codecov](https://codecov.io/gh/peggyjs/from-mem/graph/badge.svg?token=CWQ7GSH0ZI)](https://codecov.io/gh/peggyjs/from-mem) diff --git a/package.json b/package.json index d699538..bd41a24 100644 --- a/package.json +++ b/package.json @@ -29,6 +29,6 @@ }, "packageManager": "pnpm@8.15.4", "engines": { - "node": ">=20.8" + "node": ">=18" } } diff --git a/test/index.test.js b/test/index.test.js index 384538e..4f52058 100644 --- a/test/index.test.js +++ b/test/index.test.js @@ -4,9 +4,12 @@ const assert = require("node:assert"); const fromMem = require("../index.js"); const { join, parse } = require("node:path"); const { pathToFileURL } = require("node:url"); +const semver = require("semver"); const test = require("node:test"); const vm = require("node:vm"); +const is20 = semver.satisfies(process.version, ">=20.8"); + test("options", async() => { assert.equal(typeof fromMem, "function"); await assert.rejects(() => fromMem(""), /filename is required/); @@ -69,24 +72,26 @@ test("guess", async() => { }); assert.equal(cjs3, 4); - const mjs = await fromMem("export default 4", { - filename: join(__dirname, "test_guess3.mjs"), - format: "guess", - }); - assert.equal(mjs.default, 4); - - const mjs2 = await fromMem("export default 4", { - filename: join(__dirname, "fixtures", "mjs", "test_guess4.js"), - format: "guess", - }); - assert.equal(mjs2.default, 4); - - // Hit the cache - const mjs3 = await fromMem("export default 4", { - filename: join(__dirname, "fixtures", "mjs", "test_guess4.js"), - format: "guess", - }); - assert.equal(mjs3.default, 4); + if (is20) { + const mjs = await fromMem("export default 4", { + filename: join(__dirname, "test_guess3.mjs"), + format: "guess", + }); + assert.equal(mjs.default, 4); + + const mjs2 = await fromMem("export default 4", { + filename: join(__dirname, "fixtures", "mjs", "test_guess4.js"), + format: "guess", + }); + assert.equal(mjs2.default, 4); + + // Hit the cache + const mjs3 = await fromMem("export default 4", { + filename: join(__dirname, "fixtures", "mjs", "test_guess4.js"), + format: "guess", + }); + assert.equal(mjs3.default, 4); + } await assert.rejects(() => fromMem("export default 4", { filename: join(__dirname, "fixtures", "bad", "test_guess5.js"), @@ -96,7 +101,11 @@ test("guess", async() => { fromMem.guessModuleType.clearCache(); }); -test("esm", async() => { +test("esm", async t => { + if (!is20) { + t.skip(`Skipping esm tests on ${process.version}`); + return; + } const mjs4 = await fromMem("export default 5", { filename: join(__dirname, "test4.js"), format: "es",