From 9c59fa10b612225b75720e977e29bfbc5b26f1a4 Mon Sep 17 00:00:00 2001 From: Norbert Renner Date: Thu, 14 Jul 2022 17:19:46 +0200 Subject: [PATCH] Switch scripts to module because of node-fetch v3 --- .eslintignore | 4 ++-- layers/collection/{extract.js => extract.mjs} | 12 ++++++++---- layers/josm/{extract.js => extract.mjs} | 10 ++++++---- package.json | 2 +- 4 files changed, 17 insertions(+), 11 deletions(-) rename layers/collection/{extract.js => extract.mjs} (81%) rename layers/josm/{extract.js => extract.mjs} (87%) diff --git a/.eslintignore b/.eslintignore index abede04..1b360c0 100644 --- a/.eslintignore +++ b/.eslintignore @@ -1,5 +1,5 @@ -layers/josm/extract.js -layers/collection/extract.js +layers/josm/extract.mjs +layers/collection/extract.mjs gulpfile.js dist/brouter-web.js dist/turf.min.js diff --git a/layers/collection/extract.js b/layers/collection/extract.mjs similarity index 81% rename from layers/collection/extract.js rename to layers/collection/extract.mjs index d95cf0b..4ea0de1 100644 --- a/layers/collection/extract.js +++ b/layers/collection/extract.mjs @@ -1,8 +1,12 @@ +import fs from 'fs'; +import path from 'path'; +import fetch from 'node-fetch'; +import { fileURLToPath } from 'url'; -const fs = require('fs'); -const path = require('path'); -const fetch = require('node-fetch'); +import vm from 'vm'; +const __filename = fileURLToPath(import.meta.url); +const __dirname = path.dirname(__filename); const outDir = __dirname; var includeList = [ @@ -18,7 +22,7 @@ var includeList = [ ]; function extract(constantsJs) { - eval(constantsJs); + const getLayerDataByID = vm.runInNewContext(constantsJs + '; getLayerDataByID'); for (let i = 0; i < includeList.length; i++) { let id = includeList[i]; diff --git a/layers/josm/extract.js b/layers/josm/extract.mjs similarity index 87% rename from layers/josm/extract.js rename to layers/josm/extract.mjs index 7d965ec..7ebb408 100644 --- a/layers/josm/extract.js +++ b/layers/josm/extract.mjs @@ -1,8 +1,10 @@ +import fs from 'fs'; +import path from 'path'; +import fetch from 'node-fetch'; +import { fileURLToPath } from 'url'; -const fs = require('fs'); -const path = require('path'); -const fetch = require('node-fetch'); - +const __filename = fileURLToPath(import.meta.url); +const __dirname = path.dirname(__filename); const outDir = __dirname; const includeList = [ diff --git a/package.json b/package.json index f39766b..c2081ea 100644 --- a/package.json +++ b/package.json @@ -7,7 +7,7 @@ "build": "gulp", "transifex-push": "gulp i18next && tx push --source", "transifex-pull": "tx pull --all --minimum-perc 1 --force && (git add locales/*.json && git commit locales/*.json -m 'Update translations' || true)", - "layers": "node layers/josm/extract.js && node layers/collection/extract.js", + "layers": "node layers/josm/extract.mjs && node layers/collection/extract.mjs", "test": "jest", "lint": "eslint .", "prettier": "prettier --write '**/*'",