use nodejs's built-in fetch in build scripts

This commit is contained in:
Martin Raifer
2024-03-14 15:55:54 +01:00
parent 62f56acf23
commit 6f0e87ea44
4 changed files with 32 additions and 15 deletions

25
package-lock.json generated
View File

@@ -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"

View File

@@ -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",

View File

@@ -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);
})

View File

@@ -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;