Skip to content

Commit 2df2af0

Browse files
authored
Improve compat across node versions (#297)
Import Assertions were removed from Node v22 and replaced with Import Attributes. To be compatible with both, the simplest thing is to just use the filesystem APIs, even though they're more awkward. Once everyone's on Node v22 or above, we can switch to using `import pkg from './package.json' with {type: 'json'};`
1 parent 3004d3b commit 2df2af0

File tree

2 files changed

+15
-1
lines changed

2 files changed

+15
-1
lines changed

.changeset/thirty-moons-count.md

+4
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
---
2+
---
3+
4+
Internal change. Improve node version compatibility in the build script.

rollup.config.mjs

+11-1
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,17 @@ import replace from "rollup-plugin-replace";
1919
import typescriptPlugin from "rollup-plugin-typescript2";
2020
import typescript from "typescript";
2121
import json from "@rollup/plugin-json";
22-
import pkg from "./package.json" assert { type: "json" };
22+
import * as fs from "node:fs";
23+
import * as path from "node:path";
24+
import { fileURLToPath } from "node:url";
25+
26+
const __filename = fileURLToPath(import.meta.url);
27+
const __dirname = path.dirname(__filename);
28+
29+
// Once we drop support for Node versions <22 we can replace this line with
30+
// just:
31+
// import pkg from './package.json' with {type: 'json'};
32+
const pkg = JSON.parse(fs.readFileSync(path.join(__dirname, "package.json")));
2333

2434
const es2017BuildPlugins = [
2535
typescriptPlugin({

0 commit comments

Comments
 (0)