diff --git a/.babelrc b/.babelrc index 728dc8aae5..ded830aa4d 100644 --- a/.babelrc +++ b/.babelrc @@ -4,7 +4,7 @@ "targets": { "browsers": "defaults and supports webgl2" }, - "modules": "auto" + "modules": false }] ], "plugins": [ @@ -17,6 +17,7 @@ ".css" ] }], + ["module-extension-resolver"], ["@babel/plugin-transform-runtime", { "regenerator": false }], diff --git a/.eslintrc.js b/.eslintrc.cjs similarity index 98% rename from .eslintrc.js rename to .eslintrc.cjs index 29a549723d..c2544517f6 100644 --- a/.eslintrc.js +++ b/.eslintrc.cjs @@ -14,7 +14,7 @@ module.exports = { settings: { 'import/resolver': { webpack: { - config: 'webpack.config.js', + config: './webpack.config.cjs', }, }, }, diff --git a/Gruntfile.js b/Gruntfile.cjs similarity index 100% rename from Gruntfile.js rename to Gruntfile.cjs diff --git a/config/conventionalChangelog/config.js b/config/conventionalChangelog/config.cjs similarity index 100% rename from config/conventionalChangelog/config.js rename to config/conventionalChangelog/config.cjs diff --git a/docs/.eslintrc.js b/docs/.eslintrc.cjs similarity index 90% rename from docs/.eslintrc.js rename to docs/.eslintrc.cjs index 5de11505c7..d6e1f067a0 100644 --- a/docs/.eslintrc.js +++ b/docs/.eslintrc.cjs @@ -2,7 +2,7 @@ module.exports = { extends: [ 'eslint-config-airbnb-base', 'eslint-config-airbnb-base/rules/strict', - '../.eslintrc.js', + '../.eslintrc.cjs', ], env: { node: true, diff --git a/docs/package.json b/docs/package.json new file mode 100644 index 0000000000..fc697a9e02 --- /dev/null +++ b/docs/package.json @@ -0,0 +1,5 @@ +{ + "private": true, + "description": "JSDoc loads publish.js files with require(), so we need to configure everything under this path as a CommonJS module.", + "type": "commonjs" +} diff --git a/examples/.eslintrc.js b/examples/.eslintrc.cjs similarity index 97% rename from examples/.eslintrc.js rename to examples/.eslintrc.cjs index 33a388a22a..601cce023d 100644 --- a/examples/.eslintrc.js +++ b/examples/.eslintrc.cjs @@ -2,7 +2,7 @@ module.exports = { extends: [ 'eslint-config-airbnb-base', 'eslint-config-airbnb-base/rules/strict', - '../.eslintrc.js', + '../.eslintrc.cjs', ], parserOptions: { ecmaVersion: 13, diff --git a/package-lock.json b/package-lock.json index 52bbc7a710..60970aa34d 100644 --- a/package-lock.json +++ b/package-lock.json @@ -31,7 +31,9 @@ "babel-plugin-inline-import": "^3.0.0", "babel-plugin-minify-dead-code-elimination": "^0.5.2", "babel-plugin-minify-replace": "^0.5.0", + "babel-plugin-module-extension-resolver": "^1.0.0", "babel-plugin-module-resolver": "^5.0.0", + "babel-register-esm": "^1.2.5", "c8": "^9.1.0", "chalk": "^5.3.0", "chart.js": "^4.4.1", @@ -3449,6 +3451,15 @@ "dev": true, "license": "MIT" }, + "node_modules/babel-plugin-module-extension-resolver": { + "version": "1.0.0", + "resolved": "https://registry.npmjs.org/babel-plugin-module-extension-resolver/-/babel-plugin-module-extension-resolver-1.0.0.tgz", + "integrity": "sha512-TIwNuS8jfdmoyn+tKMM9T6fczI5y6hHbicbCTIF+RyPSNSnQMlZNnCs/pQceOEZ/0qFNbaj5p0LCLG2VS1EF7g==", + "dev": true, + "engines": { + "node": ">=6.9.0" + } + }, "node_modules/babel-plugin-module-resolver": { "version": "5.0.0", "resolved": "https://registry.npmjs.org/babel-plugin-module-resolver/-/babel-plugin-module-resolver-5.0.0.tgz", @@ -3541,6 +3552,18 @@ "@babel/core": "^7.0.0-0" } }, + "node_modules/babel-register-esm": { + "version": "1.2.5", + "resolved": "https://registry.npmjs.org/babel-register-esm/-/babel-register-esm-1.2.5.tgz", + "integrity": "sha512-WaVd3Rm42kndYnufn8u1SbUUwuCxL2GAQX/7QXUL3w/7PffB+HcXrzmAqk1x01TjhFh/npSZ9Z3MNBc6dDb6Uw==", + "dev": true, + "engines": { + "node": ">=12.17.0" + }, + "peerDependencies": { + "@babel/core": "*" + } + }, "node_modules/balanced-match": { "version": "1.0.2", "resolved": "https://registry.npmjs.org/balanced-match/-/balanced-match-1.0.2.tgz", diff --git a/package.json b/package.json index 126259e73f..1b509c0ce0 100644 --- a/package.json +++ b/package.json @@ -2,6 +2,7 @@ "name": "itowns", "version": "2.42.0", "description": "A JS/WebGL framework for 3D geospatial data visualization", + "type": "module", "main": "lib/Main.js", "exports": { ".": "./lib/Main.js", @@ -17,7 +18,7 @@ "test-functional": "mocha -t 100000 --require test/hooks_functional.js --recursive test/functional", "test-with-coverage": "c8 -n src -r html cross-env npm run test-unit", "test-with-coverage_lcov": "c8 -n src --reporter=lcov cross-env npm run test-unit", - "base-test-unit": "cross-env BABEL_DISABLE_CACHE=1 mocha --require @babel/register --file test/unit/bootstrap.js", + "base-test-unit": "cross-env BABEL_DISABLE_CACHE=1 mocha --file test/unit/bootstrap.js --loader=babel-register-esm", "build": "cross-env NODE_ENV=production webpack", "build-dev": "cross-env NODE_ENV=development webpack", "transpile": "cross-env BABEL_DISABLE_CACHE=1 babel src --out-dir lib", @@ -27,7 +28,7 @@ "prepublishOnly": "npm run build && npm run transpile", "prepare": "cross-env NO_UPDATE_NOTIFIER=true node ./config/prepare.mjs && node ./config/replace.config.mjs", "watch": "cross-env BABEL_DISABLE_CACHE=1 babel --watch src --out-dir lib", - "changelog": "conventional-changelog -n ./config/conventionalChangelog/config.js -i changelog.md -s", + "changelog": "conventional-changelog -n ./config/conventionalChangelog/config.cjs -i changelog.md -s", "bump": "if [ -z $npm_config_level ]; then grunt bump:minor; else grunt bump:$npm_config_level; fi && npm run changelog && npm install && git add -A && git commit --amend --no-edit", "publish-next": "npm version prerelease --preid next && npm publish --access public --tag=next --provenance", "publish-latest": "npm publish --access public --tag=latest --provenance" @@ -82,7 +83,9 @@ "babel-plugin-inline-import": "^3.0.0", "babel-plugin-minify-dead-code-elimination": "^0.5.2", "babel-plugin-minify-replace": "^0.5.0", + "babel-plugin-module-extension-resolver": "^1.0.0", "babel-plugin-module-resolver": "^5.0.0", + "babel-register-esm": "^1.2.5", "c8": "^9.1.0", "chalk": "^5.3.0", "chart.js": "^4.4.1", diff --git a/test/.eslintrc.js b/test/.eslintrc.cjs similarity index 100% rename from test/.eslintrc.js rename to test/.eslintrc.cjs diff --git a/test/functional/.eslintrc.js b/test/functional/.eslintrc.cjs similarity index 98% rename from test/functional/.eslintrc.js rename to test/functional/.eslintrc.cjs index abb7f61076..6807fb6b0c 100644 --- a/test/functional/.eslintrc.js +++ b/test/functional/.eslintrc.cjs @@ -5,7 +5,7 @@ module.exports = { ], parserOptions: { ecmaVersion: 2017, - sourceType: 'script', + sourceType: 'module', ecmaFeatures: { impliedStrict: true, }, diff --git a/test/functional/3dtiles_25d.js b/test/functional/3dtiles_25d.js index 28b1415bb0..533b3c6ca3 100644 --- a/test/functional/3dtiles_25d.js +++ b/test/functional/3dtiles_25d.js @@ -1,4 +1,4 @@ -const assert = require('assert'); +import assert from 'assert'; describe('3dtiles_25d', function _() { let result; diff --git a/test/functional/3dtiles_basic.js b/test/functional/3dtiles_basic.js index e4fd1765e7..6ffa74bc58 100644 --- a/test/functional/3dtiles_basic.js +++ b/test/functional/3dtiles_basic.js @@ -1,4 +1,4 @@ -const assert = require('assert'); +import assert from 'assert'; describe('3dtiles_basic', function _() { let result; diff --git a/test/functional/3dtiles_batch_table.js b/test/functional/3dtiles_batch_table.js index 6852bea081..662a082de4 100644 --- a/test/functional/3dtiles_batch_table.js +++ b/test/functional/3dtiles_batch_table.js @@ -1,4 +1,4 @@ -const assert = require('assert'); +import assert from 'assert'; describe('3dtiles_batch_table', function _() { let result; diff --git a/test/functional/3dtiles_ion.js b/test/functional/3dtiles_ion.js index b45186dac3..d402d22442 100644 --- a/test/functional/3dtiles_ion.js +++ b/test/functional/3dtiles_ion.js @@ -1,4 +1,4 @@ -const assert = require('assert'); +import assert from 'assert'; describe('3dtiles_ion', function _() { let result; diff --git a/test/functional/3dtiles_pointcloud.js b/test/functional/3dtiles_pointcloud.js index 167341d351..4c88639e8d 100644 --- a/test/functional/3dtiles_pointcloud.js +++ b/test/functional/3dtiles_pointcloud.js @@ -1,4 +1,4 @@ -const assert = require('assert'); +import assert from 'assert'; describe('3dtiles_pointcloud', function _() { let result; diff --git a/test/functional/CameraUtils.js b/test/functional/CameraUtils.js index 3914db0603..f9b32e7c8d 100644 --- a/test/functional/CameraUtils.js +++ b/test/functional/CameraUtils.js @@ -1,4 +1,4 @@ -const assert = require('assert'); +import assert from 'assert'; describe('Camera utils with globe example', function _() { before(async () => { diff --git a/test/functional/GlobeControls.js b/test/functional/GlobeControls.js index bccf81257c..6dbef35b97 100644 --- a/test/functional/GlobeControls.js +++ b/test/functional/GlobeControls.js @@ -1,4 +1,4 @@ -const assert = require('assert'); +import assert from 'assert'; // global variables let middleWidth; diff --git a/test/functional/effects_postprocessing.js b/test/functional/effects_postprocessing.js index 99e88ca954..0b67ec41df 100644 --- a/test/functional/effects_postprocessing.js +++ b/test/functional/effects_postprocessing.js @@ -1,4 +1,4 @@ -const assert = require('assert'); +import assert from 'assert'; describe('effects_postprocessing', function _() { let result; diff --git a/test/functional/effects_split.js b/test/functional/effects_split.js index e615e05276..05b66f5b80 100644 --- a/test/functional/effects_split.js +++ b/test/functional/effects_split.js @@ -1,4 +1,4 @@ -const assert = require('assert'); +import assert from 'assert'; describe('effects_split', function _() { let result; diff --git a/test/functional/effects_stereo.js b/test/functional/effects_stereo.js index da84bd8682..40277afeed 100644 --- a/test/functional/effects_stereo.js +++ b/test/functional/effects_stereo.js @@ -1,4 +1,4 @@ -const assert = require('assert'); +import assert from 'assert'; describe('effects_stereo', function _() { let result; diff --git a/test/functional/misc_clamp_ground.js b/test/functional/misc_clamp_ground.js index f673259431..0ec85739ca 100644 --- a/test/functional/misc_clamp_ground.js +++ b/test/functional/misc_clamp_ground.js @@ -1,4 +1,4 @@ -const assert = require('assert'); +import assert from 'assert'; describe('misc_clamp_ground', function _() { let result; diff --git a/test/functional/misc_collada.js b/test/functional/misc_collada.js index e0f6e237e8..f559e82d9b 100644 --- a/test/functional/misc_collada.js +++ b/test/functional/misc_collada.js @@ -1,4 +1,4 @@ -const assert = require('assert'); +import assert from 'assert'; describe('misc_collada', function _() { let result; diff --git a/test/functional/misc_colorlayer_visibility.js b/test/functional/misc_colorlayer_visibility.js index d5a8e09fe9..7c1d6be2f3 100644 --- a/test/functional/misc_colorlayer_visibility.js +++ b/test/functional/misc_colorlayer_visibility.js @@ -1,4 +1,4 @@ -const assert = require('assert'); +import assert from 'assert'; describe('misc_colorlayer_visibility', function _() { let result; diff --git a/test/functional/misc_instancing.js b/test/functional/misc_instancing.js index add160eefa..fa4f9f122b 100644 --- a/test/functional/misc_instancing.js +++ b/test/functional/misc_instancing.js @@ -1,4 +1,4 @@ -const assert = require('assert'); +import assert from 'assert'; describe('misc_instancing', function _() { let result; diff --git a/test/functional/oriented_images.js b/test/functional/oriented_images.js index 519a01e0c6..3863b119ac 100644 --- a/test/functional/oriented_images.js +++ b/test/functional/oriented_images.js @@ -1,4 +1,4 @@ -const assert = require('assert'); +import assert from 'assert'; describe('misc_georeferenced_images', function _() { let result; diff --git a/test/functional/potree_25d_map.js b/test/functional/potree_25d_map.js index d822232455..fec05ae4db 100644 --- a/test/functional/potree_25d_map.js +++ b/test/functional/potree_25d_map.js @@ -1,4 +1,4 @@ -const assert = require('assert'); +import assert from 'assert'; describe('potree_25d_map', function _() { let result; diff --git a/test/functional/potree_3d_map.js b/test/functional/potree_3d_map.js index 67a467c6b3..10597b0a68 100644 --- a/test/functional/potree_3d_map.js +++ b/test/functional/potree_3d_map.js @@ -1,4 +1,4 @@ -const assert = require('assert'); +import assert from 'assert'; describe('potree_3d_map', function _() { let result; diff --git a/test/functional/source_file_geojson_raster.js b/test/functional/source_file_geojson_raster.js index 0223aeded4..c45bee1392 100644 --- a/test/functional/source_file_geojson_raster.js +++ b/test/functional/source_file_geojson_raster.js @@ -1,4 +1,4 @@ -const assert = require('assert'); +import assert from 'assert'; describe('source_file_geojson_raster', function _() { let result; diff --git a/test/functional/source_file_gpx_3d.js b/test/functional/source_file_gpx_3d.js index 7e38c5227d..6a5fb97ec8 100644 --- a/test/functional/source_file_gpx_3d.js +++ b/test/functional/source_file_gpx_3d.js @@ -1,4 +1,4 @@ -const assert = require('assert'); +import assert from 'assert'; describe('source_file_gpx_3d', function _() { let result; diff --git a/test/functional/source_file_kml_raster.js b/test/functional/source_file_kml_raster.js index 68e107f8c7..e081b59720 100644 --- a/test/functional/source_file_kml_raster.js +++ b/test/functional/source_file_kml_raster.js @@ -1,4 +1,4 @@ -const assert = require('assert'); +import assert from 'assert'; describe('source_file_kml_raster', function _() { let result; diff --git a/test/functional/source_file_kml_raster_usgs.js b/test/functional/source_file_kml_raster_usgs.js index ec63524e63..2647faa2b8 100644 --- a/test/functional/source_file_kml_raster_usgs.js +++ b/test/functional/source_file_kml_raster_usgs.js @@ -1,4 +1,4 @@ -const assert = require('assert'); +import assert from 'assert'; describe('source_file_kml_raster_usgs', function _() { let result; diff --git a/test/functional/source_stream_wfs_25d.js b/test/functional/source_stream_wfs_25d.js index fc4db4af36..7e542e702a 100644 --- a/test/functional/source_stream_wfs_25d.js +++ b/test/functional/source_stream_wfs_25d.js @@ -1,4 +1,4 @@ -const assert = require('assert'); +import assert from 'assert'; describe('source_stream_wfs_25d', function _() { let result; diff --git a/test/functional/source_stream_wfs_3d.js b/test/functional/source_stream_wfs_3d.js index 64a5b47b7b..3434f45b6a 100644 --- a/test/functional/source_stream_wfs_3d.js +++ b/test/functional/source_stream_wfs_3d.js @@ -1,4 +1,4 @@ -const assert = require('assert'); +import assert from 'assert'; describe('source_stream_wfs_3d', function _() { let result; diff --git a/test/functional/source_stream_wfs_raster.js b/test/functional/source_stream_wfs_raster.js index cc62a5f245..51aacd6287 100644 --- a/test/functional/source_stream_wfs_raster.js +++ b/test/functional/source_stream_wfs_raster.js @@ -1,4 +1,4 @@ -const assert = require('assert'); +import assert from 'assert'; describe('source_stream_wfs_raster', function _() { let result; diff --git a/test/functional/vector_tile_3d_mesh_mapbox.js b/test/functional/vector_tile_3d_mesh_mapbox.js index 903514c45b..98093a678b 100644 --- a/test/functional/vector_tile_3d_mesh_mapbox.js +++ b/test/functional/vector_tile_3d_mesh_mapbox.js @@ -1,4 +1,4 @@ -const assert = require('assert'); +import assert from 'assert'; describe('vector_tile_3d_mesh_mapbox', function _describe() { let result; diff --git a/test/functional/vector_tile_raster_2d.js b/test/functional/vector_tile_raster_2d.js index a45c731f1e..f02c9eb998 100644 --- a/test/functional/vector_tile_raster_2d.js +++ b/test/functional/vector_tile_raster_2d.js @@ -1,4 +1,4 @@ -const assert = require('assert'); +import assert from 'assert'; describe('vector_tile_raster_2d', function _() { let result; diff --git a/test/functional/vector_tile_raster_3d.js b/test/functional/vector_tile_raster_3d.js index 122bf49ee1..9d636267a5 100644 --- a/test/functional/vector_tile_raster_3d.js +++ b/test/functional/vector_tile_raster_3d.js @@ -1,4 +1,4 @@ -const assert = require('assert'); +import assert from 'assert'; describe('vector_tile_raster_3d', function _() { let result; diff --git a/test/functional/view_25d_map.js b/test/functional/view_25d_map.js index 8493b17d46..be3f034a33 100644 --- a/test/functional/view_25d_map.js +++ b/test/functional/view_25d_map.js @@ -1,4 +1,4 @@ -const assert = require('assert'); +import assert from 'assert'; describe('view_25d_map', function _() { let result; diff --git a/test/functional/view_2d_map.js b/test/functional/view_2d_map.js index ff1d99cf69..1c65b1d543 100644 --- a/test/functional/view_2d_map.js +++ b/test/functional/view_2d_map.js @@ -1,4 +1,4 @@ -const assert = require('assert'); +import assert from 'assert'; describe('view_2d_map', function _() { let result; diff --git a/test/functional/view_3d_map.js b/test/functional/view_3d_map.js index c3722f5ee2..79b0165ec8 100644 --- a/test/functional/view_3d_map.js +++ b/test/functional/view_3d_map.js @@ -1,4 +1,4 @@ -const assert = require('assert'); +import assert from 'assert'; describe('view_3d_map', function _() { let result; diff --git a/test/functional/view_multi_25d.js b/test/functional/view_multi_25d.js index 233b43f167..b4ea295a51 100644 --- a/test/functional/view_multi_25d.js +++ b/test/functional/view_multi_25d.js @@ -1,4 +1,4 @@ -const assert = require('assert'); +import assert from 'assert'; describe('view_multi_25d', function _() { let result; diff --git a/test/functional/view_multiglobe.js b/test/functional/view_multiglobe.js index a2866887a6..23a78835bf 100644 --- a/test/functional/view_multiglobe.js +++ b/test/functional/view_multiglobe.js @@ -1,4 +1,4 @@ -const assert = require('assert'); +import assert from 'assert'; describe('view_multiglobe', function _() { let result; diff --git a/test/functional/widgets_3dtiles_style.js b/test/functional/widgets_3dtiles_style.js index 147f3ee836..9e7ad730e5 100644 --- a/test/functional/widgets_3dtiles_style.js +++ b/test/functional/widgets_3dtiles_style.js @@ -1,4 +1,4 @@ -const assert = require('assert'); +import assert from 'assert'; describe('Widget C3dTilesStyle', function _() { let result; diff --git a/test/hooks_functional.js b/test/hooks_functional.js index 257bef4ae7..3d4340dd92 100644 --- a/test/hooks_functional.js +++ b/test/hooks_functional.js @@ -1,9 +1,9 @@ /* global page, itowns, view, initialPosition */ // eslint-disable-next-line import/no-extraneous-dependencies -const puppeteer = require('puppeteer'); -const net = require('net'); -const fs = require('fs'); -const http = require('http'); +import puppeteer from 'puppeteer'; +import net from 'net'; +import fs from 'fs'; +import http from 'http'; // this line allows to disable a warning generated by node when more than 10 // listeners are added for a particular event (this default warning helps // finding memory leaks). In our case, the listener to blame is @@ -12,7 +12,9 @@ const http = require('http'); // listener is added for every example test but this is intentional and it // is not related to a memory leak so we disable this warning. // More info: https://nodejs.org/docs/latest/api/events.html#events_emitter_setmaxlisteners_n -require('events').EventEmitter.prototype._maxListeners = 100; +import events from 'events'; + +events.EventEmitter.prototype._maxListeners = 100; let itownsServer; let itownsPort; @@ -159,7 +161,8 @@ const waitUntilItownsIsIdle = async (screenshotName) => { return result; }; -exports.mochaHooks = { +// eslint-disable-next-line import/prefer-default-export +export const mochaHooks = { beforeAll: async () => { let server; if (!process.env.USE_DEV_SERVER) { diff --git a/webpack.config.js b/webpack.config.cjs similarity index 100% rename from webpack.config.js rename to webpack.config.cjs