diff --git a/.node-version b/.node-version new file mode 100644 index 000000000..f3f52b42d --- /dev/null +++ b/.node-version @@ -0,0 +1 @@ +20.9.0 diff --git a/package-lock.json b/package-lock.json index e15234cda..122c8d714 100644 --- a/package-lock.json +++ b/package-lock.json @@ -74,7 +74,7 @@ "eslint-config-prettier": "^9.0.0", "eslint-plugin-lodash-fp": "^2.2.0-a1", "eslint-plugin-prettier": "^5.0.1", - "flat": "^5.0.2", + "flat": "^6.0.1", "i18next-conv": "^14.0.0", "jest-axe": "^8.0.0", "plausible-tracker": "^0.3.8", @@ -14503,12 +14503,15 @@ } }, "node_modules/flat": { - "version": "5.0.2", - "resolved": "https://registry.npmjs.org/flat/-/flat-5.0.2.tgz", - "integrity": "sha512-b6suED+5/3rTpUBdG1gupIl8MPFCAMA0QXwmljLhvCUKcUvdE4gWky9zpuGCcXHOsz4J9wPGNWq6OKpmIzz3hQ==", + "version": "6.0.1", + "resolved": "https://registry.npmjs.org/flat/-/flat-6.0.1.tgz", + "integrity": "sha512-/3FfIa8mbrg3xE7+wAhWeV+bd7L2Mof+xtZb5dRDKZ+wDvYJK4WDYeIOuOhre5Yv5aQObZrlbRmk3RTSiuQBtw==", "dev": true, "bin": { "flat": "cli.js" + }, + "engines": { + "node": ">=18" } }, "node_modules/flat-cache": { diff --git a/package.json b/package.json index b4c8b4062..4d6ad76c7 100644 --- a/package.json +++ b/package.json @@ -75,9 +75,9 @@ "test-debug": "npm run generate-types && react-scripts --inspect-brk test --runInBand --no-cache", "test-coverage": "npm run generate-types && react-scripts test --coverage --changedSince=origin/main --watchAll=falsed", "analyze": "source-map-explorer 'build/static/js/*.js'", - "localization-to-po": "node scripts/localization/transform-to.js po", - "localization-to-json": "node scripts/localization/transform-to.js json", - "localization-check-missing": "node scripts/localization/missing-check.js", + "localization-to-po": "node scripts/localization/transform-to.mjs po", + "localization-to-json": "node scripts/localization/transform-to.mjs json", + "localization-check-missing": "node scripts/localization/missing-check.mjs", "eject": "react-scripts eject" }, "browserslist": [ @@ -101,7 +101,7 @@ "eslint-config-prettier": "^9.0.0", "eslint-plugin-lodash-fp": "^2.2.0-a1", "eslint-plugin-prettier": "^5.0.1", - "flat": "^5.0.2", + "flat": "^6.0.1", "i18next-conv": "^14.0.0", "jest-axe": "^8.0.0", "plausible-tracker": "^0.3.8", diff --git a/scripts/localization/missing-check.js b/scripts/localization/missing-check.mjs similarity index 81% rename from scripts/localization/missing-check.js rename to scripts/localization/missing-check.mjs index e218b7931..7517996bf 100644 --- a/scripts/localization/missing-check.js +++ b/scripts/localization/missing-check.mjs @@ -15,28 +15,28 @@ * along with this program. If not, see https://www.gnu.org/licenses/. */ -const { readFile } = require('fs').promises; -const path = require('path'); -const flat = require('flat'); -const _ = require('lodash/fp'); +import { readFile } from 'fs/promises'; +import path from 'path'; +import { flatten } from 'flat'; +import _ from 'lodash/fp.js'; -const { filesInFolder } = require('./utils'); +import { filesInFolder } from './utils.mjs'; const SOURCE_LOCALE = 'en-US'; -const LOCALE_FILES_FOLDER = path.join( - __dirname, - '../../src/localization/locales/' +const LOCALE_FILES_FOLDER = new URL( + '../../src/localization/locales/', + import.meta.url ); const getKeys = content => { const json = JSON.parse(content); - const keys = Object.keys(flat(json)); + const keys = Object.keys(flatten(json)); return keys; }; const checkMissingKeys = () => - readFile(path.join(LOCALE_FILES_FOLDER, `${SOURCE_LOCALE}.json`)) + readFile(new URL(`${SOURCE_LOCALE}.json`, LOCALE_FILES_FOLDER)) // Get source locale keys .then(sourceContent => getKeys(sourceContent)) // Get all locale files @@ -53,7 +53,7 @@ const checkMissingKeys = () => return null; } console.log( - `Missing keys for ${path.parse(filePath).name}.`, + `Missing keys for ${path.parse(filePath.pathname).name}.`, 'Missing:', localeDiff ); diff --git a/scripts/localization/transform-to.js b/scripts/localization/transform-to.mjs similarity index 83% rename from scripts/localization/transform-to.js rename to scripts/localization/transform-to.mjs index 1eb77cae2..1086adf87 100644 --- a/scripts/localization/transform-to.js +++ b/scripts/localization/transform-to.mjs @@ -15,12 +15,12 @@ * along with this program. If not, see https://www.gnu.org/licenses/. */ -const path = require('path'); -const { readFileSync } = require('fs'); -const { writeFile } = require('fs').promises; -const { i18nextToPo, gettextToI18next } = require('i18next-conv'); +import { readFileSync } from 'fs'; +import { writeFile } from 'fs/promises'; +import path from 'path'; +import { gettextToI18next, i18nextToPo } from 'i18next-conv'; -const { filesInFolder } = require('./utils'); +import { filesInFolder } from './utils.mjs'; // Script arguments const args = process.argv.slice(2); @@ -37,14 +37,18 @@ const save = target => result => writeFile(target, result); // Base transform function const transform = (process, from, i18Transform) => - filesInFolder(path.join(__dirname, from)) + filesInFolder(new URL(from, import.meta.url)) .then(files => { - console.log(`${process} transform starting.`, 'Files:', files); + console.log( + `${process} transform starting.`, + 'Files:', + files.map(f => f.pathname) + ); return files; }) .then(files => files.map(filePath => { - const locale = path.parse(filePath).name; + const locale = path.parse(filePath.pathname).name; return i18Transform(locale, filePath).then(() => locale); }) ) diff --git a/scripts/localization/utils.js b/scripts/localization/utils.mjs similarity index 78% rename from scripts/localization/utils.js rename to scripts/localization/utils.mjs index 69ed0a8ac..fb5b908fa 100644 --- a/scripts/localization/utils.js +++ b/scripts/localization/utils.mjs @@ -15,12 +15,9 @@ * along with this program. If not, see https://www.gnu.org/licenses/. */ -const { readdir } = require('fs').promises; -const path = require('path'); +import { readdir } from 'fs/promises'; -const filesInFolder = dirname => +export const filesInFolder = dirname => readdir(dirname).then(filenames => - filenames.map(filename => path.join(dirname, filename)) + filenames.map(filename => new URL(filename, dirname)) ); - -module.exports = { filesInFolder };