Skip to content

Commit 529452e

Browse files
authored
chore(test): fix undefined __dirname in node 19 (#60)
* chore(ci): add current and latest LTS node versions to matrix * chore(ci): disable fail-fast * chore(test): fix undefined __dirname in node 19
1 parent cb4e0c9 commit 529452e

File tree

3 files changed

+6
-10
lines changed

3 files changed

+6
-10
lines changed

.github/workflows/nodejs.yml

+2-1
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,8 @@ jobs:
1515

1616
strategy:
1717
matrix:
18-
node-version: [16.x]
18+
node-version: [16.x, 18.x, 19.x]
19+
fail-fast: false
1920

2021
steps:
2122
- uses: actions/checkout@v3

test/Test.mjs

+3-5
Original file line numberDiff line numberDiff line change
@@ -5,9 +5,7 @@ import * as Path from "path";
55
import * as Curry from "rescript/lib/es6/curry.js";
66
import * as CodeFrame from "@babel/code-frame";
77

8-
var dirname = typeof __dirname === "undefined" ? undefined : __dirname;
9-
10-
var dirname$1 = dirname !== undefined ? dirname : "";
8+
var dirname = (new URL('.', import.meta.url).pathname);
119

1210
function cleanUpStackTrace(stack) {
1311
var removeInternalLines = function (lines, _i) {
@@ -35,7 +33,7 @@ function run(loc, left, comparator, right) {
3533
var match = loc[0];
3634
var line = match[1];
3735
var file = match[0];
38-
var fileContent = Fs.readFileSync(Path.join(dirname$1, file), {
36+
var fileContent = Fs.readFileSync(Path.join(dirname, file), {
3937
encoding: "utf-8"
4038
});
4139
var left$1 = JSON.stringify(left);
@@ -55,7 +53,7 @@ function run(loc, left, comparator, right) {
5553
}
5654

5755
export {
58-
dirname$1 as dirname,
56+
dirname ,
5957
cleanUpStackTrace ,
6058
run ,
6159
}

test/Test.res

+1-4
Original file line numberDiff line numberDiff line change
@@ -9,10 +9,7 @@ external codeFrameColumns: (string, {..}, {..}) => string = "codeFrameColumns"
99
@module("fs") @val external readFileSync: (string, {..}) => string = "readFileSync"
1010
@module("path") @val external join: (string, string) => string = "join"
1111

12-
let dirname = switch %external(__dirname) {
13-
| None => ""
14-
| Some(dirname) => dirname
15-
}
12+
let dirname = %raw("new URL('.', import.meta.url).pathname")
1613

1714
let cleanUpStackTrace = stack => {
1815
// Stack format: https://nodejs.org/api/errors.html#errors_error_stack

0 commit comments

Comments
 (0)