From 8db1c1f7f51eb06f42c7bc9506d6b2b3701e9e79 Mon Sep 17 00:00:00 2001 From: Bryan Housel Date: Fri, 2 Jul 2021 10:27:50 -0400 Subject: [PATCH] Construct URL to match version number that package.json has https://github.com/openstreetmap/iD/pull/8305#discussion_r663037548 --- modules/services/nsi.js | 22 +++++++++++++++------- package.json | 3 ++- 2 files changed, 17 insertions(+), 8 deletions(-) diff --git a/modules/services/nsi.js b/modules/services/nsi.js index 946a9941f..e3454c7ec 100644 --- a/modules/services/nsi.js +++ b/modules/services/nsi.js @@ -1,8 +1,13 @@ import { Matcher } from 'name-suggestion-index'; +import parseVersion from 'vparse'; import { fileFetcher, locationManager } from '../core'; import { presetManager } from '../presets'; +// Make very sure this resolves to iD's `package.json` +// If you mess up the `../`s, the resolver may import another random package.json from somewhere else. +import packageJSON from '../../package.json'; + // This service contains all the code related to the **name-suggestion-index** (aka NSI) // NSI contains the most correct tagging for many commonly mapped features. // See https://github.com/osmlab/name-suggestion-index and https://nsi.guide @@ -39,14 +44,17 @@ const notBranches = /(coop|express|wireless|factory|outlet)/i; // Adds the sources to iD's filemap so we can start downloading data. // function setNsiSources() { + const nsiVersion = packageJSON.dependencies['name-suggestion-index'] || packageJSON.devDependencies['name-suggestion-index']; + const v = parseVersion(nsiVersion); + const vMinor = `${v.major}.${v.minor}`; const sources = { - 'nsi_data': 'https://cdn.jsdelivr.net/npm/name-suggestion-index@6.0/dist/nsi.min.json', - 'nsi_dissolved': 'https://cdn.jsdelivr.net/npm/name-suggestion-index@6.0/dist/dissolved.min.json', - 'nsi_features': 'https://cdn.jsdelivr.net/npm/name-suggestion-index@6.0/dist/featureCollection.min.json', - 'nsi_generics': 'https://cdn.jsdelivr.net/npm/name-suggestion-index@6.0/dist/genericWords.min.json', - 'nsi_presets': 'https://cdn.jsdelivr.net/npm/name-suggestion-index@6.0/dist/presets/nsi-id-presets.min.json', - 'nsi_replacements': 'https://cdn.jsdelivr.net/npm/name-suggestion-index@6.0/dist/replacements.min.json', - 'nsi_trees': 'https://cdn.jsdelivr.net/npm/name-suggestion-index@6.0/dist/trees.min.json' + 'nsi_data': `https://cdn.jsdelivr.net/npm/name-suggestion-index@${vMinor}/dist/nsi.min.json`, + 'nsi_dissolved': `https://cdn.jsdelivr.net/npm/name-suggestion-index@${vMinor}/dist/dissolved.min.json`, + 'nsi_features': `https://cdn.jsdelivr.net/npm/name-suggestion-index@${vMinor}/dist/featureCollection.min.json`, + 'nsi_generics': `https://cdn.jsdelivr.net/npm/name-suggestion-index@${vMinor}/dist/genericWords.min.json`, + 'nsi_presets': `https://cdn.jsdelivr.net/npm/name-suggestion-index@${vMinor}/dist/presets/nsi-id-presets.min.json`, + 'nsi_replacements': `https://cdn.jsdelivr.net/npm/name-suggestion-index@${vMinor}/dist/replacements.min.json`, + 'nsi_trees': `https://cdn.jsdelivr.net/npm/name-suggestion-index@${vMinor}/dist/trees.min.json` }; let fileMap = fileFetcher.fileMap(); diff --git a/package.json b/package.json index 0940568ee..78d92a9d5 100644 --- a/package.json +++ b/package.json @@ -119,7 +119,8 @@ "smash": "0.0", "static-server": "^2.2.1", "svg-sprite": "1.5.0", - "uglify-js": "~3.12.0" + "uglify-js": "~3.12.0", + "vparse": "~1.1.0" }, "engines": { "node": ">=10"