Skip to content

Commit 9a909ff

Browse files
authored
build: fix wakatime json import bug (#2050)
* build: fix vercel node version * build: remove engine property * fix: add json import workarround This commit adds a workaround for importing the `languageColors` JSON file. This needed to be done since Vercel uses v16.4, which does not support JSON file importing without the `experimental-json-modules` flag. See https://simonplend.com/import-json-in-es-modules/ for more information. The workaround can be found [here](https://stackoverflow.com/questions/66726365/how-should-i-import-json-in-node).
1 parent dbf6560 commit 9a909ff

File tree

3 files changed

+12
-7
lines changed

3 files changed

+12
-7
lines changed

package-lock.json

-3
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

-3
Original file line numberDiff line numberDiff line change
@@ -16,9 +16,6 @@
1616
},
1717
"author": "Anurag Hazra",
1818
"license": "MIT",
19-
"engines": {
20-
"node": ">=13"
21-
},
2219
"devDependencies": {
2320
"@actions/core": "^1.2.4",
2421
"@actions/github": "^4.0.0",

src/cards/wakatime-card.js

+12-1
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@
22
import { Card } from "../common/Card.js";
33
import { createProgressNode } from "../common/createProgressNode.js";
44
import { I18n } from "../common/I18n.js";
5-
import languageColors from "../common/languageColors.json" assert { type: "json" };
65
import {
76
clampValue,
87
flexLayout,
@@ -11,6 +10,18 @@ import {
1110
} from "../common/utils.js";
1211
import { getStyles } from "../getStyles.js";
1312
import { wakatimeCardLocales } from "../translations.js";
13+
14+
/** Import language colors.
15+
*
16+
* @description Here we use the workaround found in
17+
* https://stackoverflow.com/questions/66726365/how-should-i-import-json-in-node
18+
* since vercel is using v16.14.0 which does not yet support json imports without the
19+
* --experimental-json-modules flag.
20+
*/
21+
import { createRequire } from "module";
22+
const require = createRequire(import.meta.url);
23+
const languageColors = require("../common/languageColors.json"); // now works
24+
1425
/**
1526
* @param {{color: string, text: string}} param0
1627
*/

0 commit comments

Comments
 (0)