From 6f0e87ea44e81d9207923a94a166ef49ab5e2ccd Mon Sep 17 00:00:00 2001 From: Martin Raifer Date: Thu, 14 Mar 2024 15:55:54 +0100 Subject: [PATCH] use nodejs's built-in `fetch` in build scripts --- package-lock.json | 25 ++++++++++++++++++++----- package.json | 1 - scripts/build_data.js | 20 ++++++++++++-------- scripts/update_locales.js | 1 - 4 files changed, 32 insertions(+), 15 deletions(-) diff --git a/package-lock.json b/package-lock.json index acf00a23c..f26a9475f 100644 --- a/package-lock.json +++ b/package-lock.json @@ -75,7 +75,6 @@ "minimist": "^1.2.8", "mocha": "^10.3.0", "name-suggestion-index": "~6.0", - "node-fetch": "^2.7.0", "npm-run-all": "^4.0.0", "osm-community-index": "~5.6.2", "postcss": "^8.4.35", @@ -6149,6 +6148,8 @@ "resolved": "https://registry.npmjs.org/node-fetch/-/node-fetch-2.7.0.tgz", "integrity": "sha512-c4FRfUm/dbcWZ7U+1Wq0AwCyFL+3nt2bEw05wfxSz+DWpWsitgmSgYmy2dQdWyKC1694ELPqMs/YzUSNozLt8A==", "dev": true, + "optional": true, + "peer": true, "dependencies": { "whatwg-url": "^5.0.0" }, @@ -6167,17 +6168,23 @@ "node_modules/node-fetch/node_modules/tr46": { "version": "0.0.3", "dev": true, - "license": "MIT" + "license": "MIT", + "optional": true, + "peer": true }, "node_modules/node-fetch/node_modules/webidl-conversions": { "version": "3.0.1", "dev": true, - "license": "BSD-2-Clause" + "license": "BSD-2-Clause", + "optional": true, + "peer": true }, "node_modules/node-fetch/node_modules/whatwg-url": { "version": "5.0.0", "dev": true, "license": "MIT", + "optional": true, + "peer": true, "dependencies": { "tr46": "~0.0.3", "webidl-conversions": "^3.0.0" @@ -12991,21 +12998,29 @@ "resolved": "https://registry.npmjs.org/node-fetch/-/node-fetch-2.7.0.tgz", "integrity": "sha512-c4FRfUm/dbcWZ7U+1Wq0AwCyFL+3nt2bEw05wfxSz+DWpWsitgmSgYmy2dQdWyKC1694ELPqMs/YzUSNozLt8A==", "dev": true, + "optional": true, + "peer": true, "requires": { "whatwg-url": "^5.0.0" }, "dependencies": { "tr46": { "version": "0.0.3", - "dev": true + "dev": true, + "optional": true, + "peer": true }, "webidl-conversions": { "version": "3.0.1", - "dev": true + "dev": true, + "optional": true, + "peer": true }, "whatwg-url": { "version": "5.0.0", "dev": true, + "optional": true, + "peer": true, "requires": { "tr46": "~0.0.3", "webidl-conversions": "^3.0.0" diff --git a/package.json b/package.json index c8cb9fa32..49b8a9bcf 100644 --- a/package.json +++ b/package.json @@ -110,7 +110,6 @@ "minimist": "^1.2.8", "mocha": "^10.3.0", "name-suggestion-index": "~6.0", - "node-fetch": "^2.7.0", "npm-run-all": "^4.0.0", "osm-community-index": "~5.6.2", "postcss": "^8.4.35", diff --git a/scripts/build_data.js b/scripts/build_data.js index 79852a3df..a5dcd2a79 100644 --- a/scripts/build_data.js +++ b/scripts/build_data.js @@ -4,7 +4,6 @@ const fs = require('fs'); const prettyStringify = require('json-stringify-pretty-compact'); const shell = require('shelljs'); const YAML = require('js-yaml'); -const fetch = require('node-fetch'); const lodash = require('lodash'); const languageNames = require('./language_names.js'); @@ -101,12 +100,7 @@ function buildData() { // Fetch the icons that are needed by the expected tagging schema version fetchOrRequire(`${presetsUrl}/dist/presets.min.json`), fetchOrRequire(`${presetsUrl}/dist/preset_categories.min.json`), - fetchOrRequire(`${presetsUrl}/dist/fields.min.json`), - // WARNING: we fetch the bleeding edge data too to make sure we're always hosting the - // latest icons, but note that the format could break at any time - fetch('https://raw.githubusercontent.com/openstreetmap/id-tagging-schema/main/dist/presets.min.json'), - fetch('https://raw.githubusercontent.com/openstreetmap/id-tagging-schema/main/dist/preset_categories.min.json'), - fetch('https://raw.githubusercontent.com/openstreetmap/id-tagging-schema/main/dist/fields.min.json') + fetchOrRequire(`${presetsUrl}/dist/fields.min.json`) ]) .then(responses => Promise.all(responses.map(response => response.json()))) .then((results) => { @@ -119,10 +113,20 @@ function buildData() { faIcons.add(datum.icon); } if (datum.icons) { - Object.values(datum.icons).filter(icon => /^fa[srb]-/.test(icon)).forEach(faIcons.add); + Object.values(datum.icons) + .filter(icon => /^fa[srb]-/.test(icon)) + .forEach(icon => faIcons.add(icon)); } } }); + }).then(() => + // also fetch the bleeding edge data too to make sure we're always hosting the latest icons + fetch('https://raw.githubusercontent.com/openstreetmap/id-tagging-schema/main/interim/icons.json') + ).then(response => response.json()).then(cuttingEdgeIcons => { + cuttingEdgeIcons + .filter(icon => /^fa[srb]-/.test(icon)) + .forEach(icon => faIcons.add(icon)); + }).then(() => { // copy over only those Font Awesome icons that we need writeFaIcons(faIcons); }) diff --git a/scripts/update_locales.js b/scripts/update_locales.js index 3acd8d702..7ff5a6653 100644 --- a/scripts/update_locales.js +++ b/scripts/update_locales.js @@ -2,7 +2,6 @@ /* Downloads the latest translations from Transifex */ const chalk = require('chalk'); const fs = require('fs'); -const fetch = require('node-fetch'); const YAML = require('js-yaml'); const transifexApi = require('@transifex/api').transifexApi;