Skip to content

Commit

Permalink
Use import assertions syntax for importing JSON files
Browse files Browse the repository at this point in the history
(closes #6014)
  • Loading branch information
bhousel committed Feb 16, 2022
1 parent 4bc1f6b commit 85015fe
Show file tree
Hide file tree
Showing 13 changed files with 28 additions and 27 deletions.
3 changes: 1 addition & 2 deletions .github/workflows/build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -11,12 +11,11 @@ on:

jobs:
build:

runs-on: ubuntu-latest

strategy:
matrix:
node-version: [12.x, 14.x, 16.x]
node-version: [16.14]

steps:
- uses: actions/checkout@v2
Expand Down
1 change: 1 addition & 0 deletions data/brands/shop/e-cigarette.json
Original file line number Diff line number Diff line change
Expand Up @@ -90,6 +90,7 @@
},
{
"displayName": "VPZ",
"id": "vpz-a06c95",
"locationSet": {"include": ["gb"]},
"matchNames": ["vaporized"],
"tags": {
Expand Down
4 changes: 2 additions & 2 deletions lib/file_tree.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,9 +13,9 @@ import { sortObject } from './sort_object.js';
import { validate } from './validate.js';

// JSON
import treesJSON from '../config/trees.json';
import treesJSON from '../config/trees.json' assert {type: 'json'};
const trees = treesJSON.trees;
import categoriesSchemaJSON from '../schema/categories.json';
import categoriesSchemaJSON from '../schema/categories.json' assert {type: 'json'};


// The code in here
Expand Down
6 changes: 3 additions & 3 deletions lib/matcher.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,9 @@ import whichPolygon from 'which-polygon';
import { simplify } from './simplify.js';

// JSON
import matchGroupsJSON from '../config/matchGroups.json';
import genericWordsJSON from '../config/genericWords.json';
import treesJSON from '../config/trees.json';
import matchGroupsJSON from '../config/matchGroups.json' assert {type: 'json'};
import genericWordsJSON from '../config/genericWords.json' assert {type: 'json'};
import treesJSON from '../config/trees.json' assert {type: 'json'};

const matchGroups = matchGroupsJSON.matchGroups;
const trees = treesJSON.trees;
Expand Down
2 changes: 1 addition & 1 deletion lib/write_file_with_meta.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import fs from 'node:fs';
import JSON5 from 'json5';

// JSON
import packageJSON from '../package.json';
import packageJSON from '../package.json' assert {type: 'json'};

const URLRoot = 'https://raw.githubusercontent.com/osmlab/name-suggestion-index/main';

Expand Down
4 changes: 2 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,7 @@
"build:index": "node scripts/build_index.js",
"tap": "c8 tap --reporter terse --no-cov tests/*.js",
"lint": "eslint scripts/*.js lib/*.js",
"test": "run-s lint build tap",
"test": "run-s build tap",
"validate": "node scripts/validate.js",
"wikicheck": "node scripts/check_wikiTags.js",
"wikidata": "node scripts/build_wikidata.js"
Expand Down Expand Up @@ -137,6 +137,6 @@
"xmlbuilder2": "^3.0.1"
},
"engines": {
"node": "^12.20.0 || ^14.13.1 || ^16.0.0"
"node": "^16.14.0"
}
}
4 changes: 2 additions & 2 deletions scripts/build_features.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,8 @@ import stringify from '@aitodotai/json-stringify-pretty-compact';
import { writeFileWithMeta } from '../lib/write_file_with_meta.js';

// JSON
import geojsonSchemaJSON from '../schema/geojson.json';
import featureSchemaJSON from '../schema/feature.json';
import geojsonSchemaJSON from '../schema/geojson.json' assert {type: 'json'};
import featureSchemaJSON from '../schema/feature.json' assert {type: 'json'};

const Validator = jsonschema.Validator;
let v = new Validator();
Expand Down
4 changes: 2 additions & 2 deletions scripts/build_index.js
Original file line number Diff line number Diff line change
Expand Up @@ -20,11 +20,11 @@ import { writeFileWithMeta } from '../lib/write_file_with_meta.js';
const matcher = new Matcher();

// JSON
import treesJSON from '../config/trees.json';
import treesJSON from '../config/trees.json' assert {type: 'json'};
const trees = treesJSON.trees;

// We use LocationConflation for validating and processing the locationSets
import featureCollectionJSON from '../dist/featureCollection.json';
import featureCollectionJSON from '../dist/featureCollection.json' assert {type: 'json'};
const loco = new LocationConflation(featureCollectionJSON);

console.log(chalk.blue('-'.repeat(70)));
Expand Down
6 changes: 3 additions & 3 deletions scripts/build_wikidata.js
Original file line number Diff line number Diff line change
Expand Up @@ -21,12 +21,12 @@ import { fileTree } from '../lib/file_tree.js';
import { writeFileWithMeta } from '../lib/write_file_with_meta.js';

// JSON
import packageJSON from '../package.json';
import treesJSON from '../config/trees.json';
import packageJSON from '../package.json' assert {type: 'json'};
import treesJSON from '../config/trees.json' assert {type: 'json'};
const trees = treesJSON.trees;

// We use LocationConflation for validating and processing the locationSets
import featureCollectionJSON from '../dist/featureCollection.json';
import featureCollectionJSON from '../dist/featureCollection.json' assert {type: 'json'};
const loco = new LocationConflation(featureCollectionJSON);

const wbk = wikibase({
Expand Down
2 changes: 1 addition & 1 deletion scripts/check_wikiTags.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ import { fileTree } from '../lib/file_tree.js';

// JSON
// We use LocationConflation for validating and processing the locationSets
import featureCollectionJSON from '../dist/featureCollection.json';
import featureCollectionJSON from '../dist/featureCollection.json' assert {type: 'json'};
const loco = new LocationConflation(featureCollectionJSON);

const wbk = wikibase({
Expand Down
12 changes: 6 additions & 6 deletions scripts/dist_files.js
Original file line number Diff line number Diff line change
Expand Up @@ -17,20 +17,20 @@ import { sortObject } from '../lib/sort_object.js';
import { writeFileWithMeta } from '../lib/write_file_with_meta.js';

// JSON
import dissolvedJSON from '../dist/dissolved.json';
import packageJSON from '../package.json';
import treesJSON from '../config/trees.json';
import wikidataJSON from '../dist/wikidata.json';
import dissolvedJSON from '../dist/dissolved.json' assert {type: 'json'};
import packageJSON from '../package.json' assert {type: 'json'};
import treesJSON from '../config/trees.json' assert {type: 'json'};
import wikidataJSON from '../dist/wikidata.json' assert {type: 'json'};

const dissolved = dissolvedJSON.dissolved;
const trees = treesJSON.trees;
const wikidata = wikidataJSON.wikidata;

// iD's presets which we will build on
import presetsJSON from '@openstreetmap/id-tagging-schema/dist/presets.json';
import presetsJSON from '@openstreetmap/id-tagging-schema/dist/presets.json' assert {type: 'json'};

// We use LocationConflation for validating and processing the locationSets
import featureCollectionJSON from '../dist/featureCollection.json';
import featureCollectionJSON from '../dist/featureCollection.json' assert {type: 'json'};
const loco = new LocationConflation(featureCollectionJSON);

let _cache = {};
Expand Down
2 changes: 1 addition & 1 deletion scripts/dist_version.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import chalk from 'chalk';
import fs from 'node:fs';

// JSON
import packageJSON from '../package.json';
import packageJSON from '../package.json' assert {type: 'json'};

// YYYYMMDD
const now = new Date();
Expand Down
5 changes: 3 additions & 2 deletions tests/matcher.test.js
Original file line number Diff line number Diff line change
@@ -1,10 +1,11 @@
import { test } from 'tap';
import LocationConflation from '@ideditor/location-conflation';
import { Matcher } from '../index.mjs';
import data from './matcher.data.json';

import data from './matcher.data.json' assert {type: 'json'};

// We use LocationConflation for validating and processing the locationSets
import featureCollection from '../dist/featureCollection.json';
import featureCollection from '../dist/featureCollection.json' assert {type: 'json'};
const loco = new LocationConflation(featureCollection);

const USA = [-98.58, 39.828];
Expand Down

0 comments on commit 85015fe

Please sign in to comment.