From b2d1e2a271b3f2157987908bb284be14732a747b Mon Sep 17 00:00:00 2001 From: Marc Tobias Date: Wed, 16 Nov 2022 12:46:36 +0100 Subject: [PATCH] rollup v2->v3, convert -require- to ESM style -import- --- package.json | 5 +++-- rollup.config.js | 2 +- src/lib/helpers.js | 41 +++++++++++++------------------------ test/_bootstrap.js | 18 ++++++++-------- test/about.js | 2 +- test/api_errors.js | 2 +- test/browser.js | 2 +- test/config_reverse_only.js | 2 +- test/details.js | 2 +- test/reverse.js | 2 +- test/search.js | 2 +- test/status.js | 2 +- test/unit/helpers.js | 18 ++++++++-------- yarn.lock | 8 ++++---- 14 files changed, 48 insertions(+), 60 deletions(-) diff --git a/package.json b/package.json index 70fbba1..a1a9f59 100644 --- a/package.json +++ b/package.json @@ -20,7 +20,7 @@ "http-proxy": "^1.18.1", "mocha": "^10.0", "puppeteer": "^19.0", - "rollup": "^2.3.4", + "rollup": "^3.3.0", "rollup-plugin-css-only": "^4.3.0", "rollup-plugin-livereload": "^2.0.0", "rollup-plugin-svelte": "^7.0.0", @@ -38,5 +38,6 @@ "leaflet": "1.9.2", "leaflet-minimap": "^3.6.1", "timeago.js": "^4.0.2" - } + }, + "type": "module" } diff --git a/rollup.config.js b/rollup.config.js index 1a24b92..757a22d 100644 --- a/rollup.config.js +++ b/rollup.config.js @@ -3,9 +3,9 @@ import commonjs from '@rollup/plugin-commonjs'; import resolve from '@rollup/plugin-node-resolve'; import livereload from 'rollup-plugin-livereload'; import { terser } from 'rollup-plugin-terser'; +import { spawn } from 'child_process'; import css from 'rollup-plugin-css-only'; import { readFileSync, writeFileSync } from 'fs'; -import { spawn } from 'child_process'; const production = !process.env.ROLLUP_WATCH; diff --git a/src/lib/helpers.js b/src/lib/helpers.js index de1cfd4..dfe4ced 100644 --- a/src/lib/helpers.js +++ b/src/lib/helpers.js @@ -1,19 +1,6 @@ -module.exports.formatOSMType = formatOSMType; -module.exports.osmLink = osmLink; -module.exports.formatLabel = formatLabel; -module.exports.wikipediaLink = wikipediaLink; -module.exports.coverageType = coverageType; -module.exports.isAdminBoundary = isAdminBoundary; -module.exports.formatAddressRank = formatAddressRank; -module.exports.formatPlaceType = formatPlaceType; -module.exports.formatAdminLevel = formatAdminLevel; -module.exports.formatDistance = formatDistance; -module.exports.formatKeywordToken = formatKeywordToken; -module.exports.zoomLevels = zoomLevels; - -const escapeHtml = require('escape-html'); - -function formatOSMType(sType, bExcludeExternal) { +import escapeHtml from 'escape-html'; + +export function formatOSMType(sType, bExcludeExternal) { if (sType === 'N') return 'node'; if (sType === 'W') return 'way'; if (sType === 'R') return 'relation'; @@ -26,7 +13,7 @@ function formatOSMType(sType, bExcludeExternal) { return ''; } -function osmLink(aPlace) { +export function osmLink(aPlace) { if (!aPlace.osm_type) return ''; var sOSMType = formatOSMType(aPlace.osm_type, false); if (!sOSMType) return ''; @@ -34,7 +21,7 @@ function osmLink(aPlace) { return '' + sOSMType + ' ' + aPlace.osm_id + ''; } -function formatLabel(aPlace) { +export function formatLabel(aPlace) { if (aPlace.label) return aPlace.label; function capitalize(s) { @@ -51,7 +38,7 @@ function formatLabel(aPlace) { } /* en:London_Borough_of_Redbridge => https://en.wikipedia.org/wiki/London_Borough_of_Redbridge */ -function wikipediaLink(aPlace) { +export function wikipediaLink(aPlace) { if (!aPlace.calculated_wikipedia) return ''; var parts = aPlace.calculated_wikipedia.split(':', 2); @@ -63,15 +50,15 @@ function wikipediaLink(aPlace) { return '' + sTitle + ''; } -function coverageType(aPlace) { +export function coverageType(aPlace) { return (aPlace.isarea ? 'Polygon' : 'Point'); } -function isAdminBoundary(aPlace) { +export function isAdminBoundary(aPlace) { return aPlace.category === 'boundary' && aPlace.type === 'administrative'; } -function formatAddressRank(iRank) { +export function formatAddressRank(iRank) { if (iRank < 4) return 'other'; if (iRank < 6) return 'country'; if (iRank < 8) return 'region'; @@ -90,7 +77,7 @@ function formatAddressRank(iRank) { return 'other'; } -function formatPlaceType(aPlace) { +export function formatPlaceType(aPlace) { var sOut = aPlace.class + ':' + aPlace.type; if (aPlace.type && aPlace.type === 'administrative' && aPlace.place_type) { sOut = sOut + ' (' + aPlace.place_type + ')'; @@ -99,11 +86,11 @@ function formatPlaceType(aPlace) { } // Any over 15 are invalid data in OSM anyway -function formatAdminLevel(iLevel) { +export function formatAdminLevel(iLevel) { return (iLevel && iLevel < 15 ? iLevel : ''); } -function formatDistance(fDistance, bInMeters) { +export function formatDistance(fDistance, bInMeters) { if (bInMeters) { if (fDistance < 1) return '0'; var sFormatted = (fDistance >= 1000) @@ -122,11 +109,11 @@ function formatDistance(fDistance, bInMeters) { } // mark partial tokens (those starting with a space) with a star for readability -function formatKeywordToken(sToken) { +export function formatKeywordToken(sToken) { return (sToken[0] === ' ' ? '*' : '') + escapeHtml(sToken); } -function zoomLevels() { +export function zoomLevels() { const aZoomLevels = [ /* 0 */ 'Continent / Sea', /* 1 */ '', diff --git a/test/_bootstrap.js b/test/_bootstrap.js index b538f5c..ad7733a 100644 --- a/test/_bootstrap.js +++ b/test/_bootstrap.js @@ -1,8 +1,8 @@ -const static_server = require('static-server'); -const http = require('http'); -const httpProxy = require('http-proxy'); -const puppeteer = require('puppeteer'); -const fse = require('fs-extra'); +import static_server from 'static-server'; +import http from 'node:http'; +import httpProxy from 'http-proxy'; +import puppeteer from 'puppeteer'; +import fse from 'fs-extra'; const testing_port = 9999; // this is the port all tests expect nominatim-ui to listen to @@ -17,7 +17,7 @@ const reverse_only = !!process.env.REVERSE_ONLY; // Methods to run at the start and end of the mocha testsuite run // https://mochajs.org/#global-setup-fixtures -exports.mochaGlobalSetup = async function () { +export async function mochaGlobalSetup() { const workdir = 'dist_for_testing'; // 1. Prepare build directory @@ -68,10 +68,10 @@ Nominatim_Config.Reverse_Only = ${reverse_only}; '--user-agent=Nominatim UI test suite Mozilla/5.0 Gecko/20100101 HeadlessChrome/90.0' ] }); -}; +} -exports.mochaGlobalTeardown = async function () { +export async function mochaGlobalTeardown() { global.browser.close(); await this.static_http_server.stop(); @@ -83,4 +83,4 @@ exports.mochaGlobalTeardown = async function () { this.proxy_server.close(() => console.log('proxy server stopped')); } -}; +} diff --git a/test/about.js b/test/about.js index de004ab..819d76d 100644 --- a/test/about.js +++ b/test/about.js @@ -1,4 +1,4 @@ -const assert = require('assert'); +import assert from 'assert'; describe('About Page', function () { let page; diff --git a/test/api_errors.js b/test/api_errors.js index b5eef6d..084159e 100644 --- a/test/api_errors.js +++ b/test/api_errors.js @@ -1,4 +1,4 @@ -const assert = require('assert'); +import assert from 'assert'; describe('Nominatim API errors', function () { let page; diff --git a/test/browser.js b/test/browser.js index 51593ff..58d53ae 100644 --- a/test/browser.js +++ b/test/browser.js @@ -1,4 +1,4 @@ -const assert = require('assert'); +import assert from 'assert'; describe('Browser behaviour', function () { diff --git a/test/config_reverse_only.js b/test/config_reverse_only.js index 5e14312..5247fb6 100644 --- a/test/config_reverse_only.js +++ b/test/config_reverse_only.js @@ -1,4 +1,4 @@ -const assert = require('assert'); +import assert from 'assert'; describe('Reverse Only', function () { let page; diff --git a/test/details.js b/test/details.js index 02b950b..513dcba 100644 --- a/test/details.js +++ b/test/details.js @@ -1,4 +1,4 @@ -const assert = require('assert'); +import assert from 'assert'; const reverse_only = !!process.env.REVERSE_ONLY; diff --git a/test/reverse.js b/test/reverse.js index 8685668..5641a1a 100644 --- a/test/reverse.js +++ b/test/reverse.js @@ -1,4 +1,4 @@ -const assert = require('assert'); +import assert from 'assert'; describe('Reverse Page', function () { let page; diff --git a/test/search.js b/test/search.js index 628edaa..b398b0d 100644 --- a/test/search.js +++ b/test/search.js @@ -1,4 +1,4 @@ -const assert = require('assert'); +import assert from 'assert'; describe('Search Page', function () { let page; diff --git a/test/status.js b/test/status.js index cf58885..78dc020 100644 --- a/test/status.js +++ b/test/status.js @@ -1,4 +1,4 @@ -const assert = require('assert'); +import assert from 'assert'; describe('Status Page', function () { let page; diff --git a/test/unit/helpers.js b/test/unit/helpers.js index 9570059..cea1512 100644 --- a/test/unit/helpers.js +++ b/test/unit/helpers.js @@ -1,36 +1,36 @@ -const assert = require('assert'); -const helpers = require('../../src/lib/helpers'); +import assert from 'assert'; +import { formatLabel, wikipediaLink } from '../../src/lib/helpers.js'; describe('Helpers', function () { it('.formatLabel', function () { // not enough data - assert.equal(helpers.formatLabel({}), ''); + assert.equal(formatLabel({}), ''); // if label set, that becomes the label - assert.equal(helpers.formatLabel({ label: 'A Label' }), 'A Label'); + assert.equal(formatLabel({ label: 'A Label' }), 'A Label'); // type, but nicely formatted - assert.equal(helpers.formatLabel({ category: 'highway', type: 'bus_stop' }), 'Bus stop'); + assert.equal(formatLabel({ category: 'highway', type: 'bus_stop' }), 'Bus stop'); // type=yes, so we use the category - assert.equal(helpers.formatLabel({ category: 'building', type: 'yes' }), 'Building'); + assert.equal(formatLabel({ category: 'building', type: 'yes' }), 'Building'); }); it('.wikipediaLink', function () { assert.equal( - helpers.wikipediaLink({}), + wikipediaLink({}), '' ); assert.equal( - helpers.wikipediaLink({ calculated_wikipedia: 'de:Brandenburg Gate' }), + wikipediaLink({ calculated_wikipedia: 'de:Brandenburg Gate' }), 'de:Brandenburg Gate' ); // title includes HTML assert.equal( - helpers.wikipediaLink({ calculated_wikipedia: 'en:Slug & Lattuce' }), + wikipediaLink({ calculated_wikipedia: 'en:Slug & Lattuce' }), 'en:Slug & Lattuce' ); }); diff --git a/yarn.lock b/yarn.lock index 52ca440..3514b37 100644 --- a/yarn.lock +++ b/yarn.lock @@ -1885,10 +1885,10 @@ rollup-pluginutils@^2.8.2: dependencies: estree-walker "^0.6.1" -rollup@^2.3.4: - version "2.79.1" - resolved "https://registry.yarnpkg.com/rollup/-/rollup-2.79.1.tgz#bedee8faef7c9f93a2647ac0108748f497f081c7" - integrity sha512-uKxbd0IhMZOhjAiD5oAFp7BqvkA4Dv47qpOCtaNvng4HBwdbWtdOh8f5nZNuk2rp51PMGk3bzfWu5oayNEuYnw== +rollup@^3.3.0: + version "3.3.0" + resolved "https://registry.yarnpkg.com/rollup/-/rollup-3.3.0.tgz#ae8dc84808a9c75d775d8b2ed8db1adada31a581" + integrity sha512-wqOV/vUJCYEbWsXvwCkgGWvgaEnsbn4jxBQWKpN816CqsmCimDmCNJI83c6if7QVD4v/zlyRzxN7U2yDT5rfoA== optionalDependencies: fsevents "~2.3.2" -- 2.39.5