Skip to content

Commit

Permalink
Merge pull request #8 from hildjj/min-version
Browse files Browse the repository at this point in the history
Half-support node 18
  • Loading branch information
hildjj authored Feb 26, 2024
2 parents f381ff6 + 4065161 commit fa59fc1
Show file tree
Hide file tree
Showing 4 changed files with 35 additions and 25 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/node.js.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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 }}
Expand Down
9 changes: 5 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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)
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,6 @@
},
"packageManager": "[email protected]",
"engines": {
"node": ">=20.8"
"node": ">=18"
}
}
47 changes: 28 additions & 19 deletions test/index.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -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/);
Expand Down Expand Up @@ -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"),
Expand All @@ -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",
Expand Down

0 comments on commit fa59fc1

Please sign in to comment.