Skip to content

Commit ee336a4

Browse files
authored
Merge pull request #14536 from guardian/ravi/remove-load-json-file
Replace `load-json-file` with native node method
2 parents dde1bb7 + 674f717 commit ee336a4

File tree

3 files changed

+83
-43
lines changed

3 files changed

+83
-43
lines changed

dotcom-rendering/package.json

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -137,7 +137,6 @@
137137
"jest": "29.7.0",
138138
"jest-environment-jsdom": "29.7.0",
139139
"jsdom": "22.1.0",
140-
"load-json-file": "6.2.0",
141140
"lodash.debounce": "4.0.8",
142141
"log4js": "6.9.1",
143142
"lz-string": "1.5.0",

dotcom-rendering/scripts/test/build-check.js

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,10 +5,22 @@
55
// 1. That the manifest files are output
66
// 2. That the manifest files contain at least the entry points under the expected property
77

8+
const { readFile } = require('node:fs').promises;
89
const find = require('find');
9-
const loadJsonFile = require('load-json-file');
1010
const { BUILD_VARIANT } = require('../../webpack/bundles');
1111

12+
/**
13+
* Loads a JSON file.
14+
* Inspired by https://github.com/sindresorhus/load-json-file/blob/de8256b9010db73c75a1e2036ff96025e94c0b6e/index.js#L6
15+
* @param {string} filePath The path to the JSON file.
16+
* @returns {Promise<Object>} The parsed JSON object.
17+
*/
18+
async function loadJsonFile(filePath) {
19+
const buffer = await readFile(filePath);
20+
// Unlike `buffer.toString()` and `fs.readFile(path, 'utf8')`, `TextDecoder` will remove BOM.
21+
return JSON.parse(new TextDecoder().decode(buffer));
22+
}
23+
1224
const errorAndThrow = (error) => {
1325
console.error(error);
1426
throw new Error(error);

pnpm-lock.yaml

Lines changed: 70 additions & 41 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)