Skip to content

Commit

Permalink
feat: ESM distribution
Browse files Browse the repository at this point in the history
BREAKING CHANGE: The itowns library drops the CommonJS distribution in favor of
a standard ECMAScript module (ESM) distribution.
  • Loading branch information
Desplandis committed Mar 21, 2024
1 parent f1c3c9d commit 04391f4
Show file tree
Hide file tree
Showing 38 changed files with 72 additions and 42 deletions.
3 changes: 2 additions & 1 deletion .babelrc
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
"targets": {
"browsers": "defaults and supports webgl2"
},
"modules": "auto"
"modules": false
}]
],
"plugins": [
Expand All @@ -17,6 +17,7 @@
".css"
]
}],
["module-extension-resolver"],
["@babel/plugin-transform-runtime", {
"regenerator": false
}],
Expand Down
23 changes: 23 additions & 0 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

5 changes: 4 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand All @@ -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",
Expand Down Expand Up @@ -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",
Expand Down
2 changes: 1 addition & 1 deletion test/functional/.eslintrc.cjs
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ module.exports = {
],
parserOptions: {
ecmaVersion: 2017,
sourceType: 'script',
sourceType: 'module',
ecmaFeatures: {
impliedStrict: true,
},
Expand Down
2 changes: 1 addition & 1 deletion test/functional/3dtiles_25d.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
const assert = require('assert');
import assert from 'assert';

describe('3dtiles_25d', function _() {
let result;
Expand Down
2 changes: 1 addition & 1 deletion test/functional/3dtiles_basic.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
const assert = require('assert');
import assert from 'assert';

describe('3dtiles_basic', function _() {
let result;
Expand Down
2 changes: 1 addition & 1 deletion test/functional/3dtiles_batch_table.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
const assert = require('assert');
import assert from 'assert';

describe('3dtiles_batch_table', function _() {
let result;
Expand Down
2 changes: 1 addition & 1 deletion test/functional/3dtiles_ion.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
const assert = require('assert');
import assert from 'assert';

describe('3dtiles_ion', function _() {
let result;
Expand Down
2 changes: 1 addition & 1 deletion test/functional/3dtiles_pointcloud.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
const assert = require('assert');
import assert from 'assert';

describe('3dtiles_pointcloud', function _() {
let result;
Expand Down
2 changes: 1 addition & 1 deletion test/functional/CameraUtils.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
const assert = require('assert');
import assert from 'assert';

describe('Camera utils with globe example', function _() {
before(async () => {
Expand Down
2 changes: 1 addition & 1 deletion test/functional/GlobeControls.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
const assert = require('assert');
import assert from 'assert';

// global variables
let middleWidth;
Expand Down
2 changes: 1 addition & 1 deletion test/functional/effects_postprocessing.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
const assert = require('assert');
import assert from 'assert';

describe('effects_postprocessing', function _() {
let result;
Expand Down
2 changes: 1 addition & 1 deletion test/functional/effects_split.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
const assert = require('assert');
import assert from 'assert';

describe('effects_split', function _() {
let result;
Expand Down
2 changes: 1 addition & 1 deletion test/functional/effects_stereo.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
const assert = require('assert');
import assert from 'assert';

describe('effects_stereo', function _() {
let result;
Expand Down
2 changes: 1 addition & 1 deletion test/functional/misc_clamp_ground.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
const assert = require('assert');
import assert from 'assert';

describe('misc_clamp_ground', function _() {
let result;
Expand Down
2 changes: 1 addition & 1 deletion test/functional/misc_collada.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
const assert = require('assert');
import assert from 'assert';

describe('misc_collada', function _() {
let result;
Expand Down
2 changes: 1 addition & 1 deletion test/functional/misc_colorlayer_visibility.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
const assert = require('assert');
import assert from 'assert';

describe('misc_colorlayer_visibility', function _() {
let result;
Expand Down
2 changes: 1 addition & 1 deletion test/functional/misc_instancing.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
const assert = require('assert');
import assert from 'assert';

describe('misc_instancing', function _() {
let result;
Expand Down
2 changes: 1 addition & 1 deletion test/functional/oriented_images.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
const assert = require('assert');
import assert from 'assert';

describe('misc_georeferenced_images', function _() {
let result;
Expand Down
2 changes: 1 addition & 1 deletion test/functional/potree_25d_map.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
const assert = require('assert');
import assert from 'assert';

describe('potree_25d_map', function _() {
let result;
Expand Down
2 changes: 1 addition & 1 deletion test/functional/potree_3d_map.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
const assert = require('assert');
import assert from 'assert';

describe('potree_3d_map', function _() {
let result;
Expand Down
2 changes: 1 addition & 1 deletion test/functional/source_file_geojson_raster.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
const assert = require('assert');
import assert from 'assert';

describe('source_file_geojson_raster', function _() {
let result;
Expand Down
2 changes: 1 addition & 1 deletion test/functional/source_file_gpx_3d.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
const assert = require('assert');
import assert from 'assert';

describe('source_file_gpx_3d', function _() {
let result;
Expand Down
2 changes: 1 addition & 1 deletion test/functional/source_file_kml_raster.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
const assert = require('assert');
import assert from 'assert';

describe('source_file_kml_raster', function _() {
let result;
Expand Down
2 changes: 1 addition & 1 deletion test/functional/source_file_kml_raster_usgs.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
const assert = require('assert');
import assert from 'assert';

describe('source_file_kml_raster_usgs', function _() {
let result;
Expand Down
2 changes: 1 addition & 1 deletion test/functional/source_stream_wfs_25d.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
const assert = require('assert');
import assert from 'assert';

describe('source_stream_wfs_25d', function _() {
let result;
Expand Down
2 changes: 1 addition & 1 deletion test/functional/source_stream_wfs_3d.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
const assert = require('assert');
import assert from 'assert';

describe('source_stream_wfs_3d', function _() {
let result;
Expand Down
2 changes: 1 addition & 1 deletion test/functional/source_stream_wfs_raster.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
const assert = require('assert');
import assert from 'assert';

describe('source_stream_wfs_raster', function _() {
let result;
Expand Down
2 changes: 1 addition & 1 deletion test/functional/vector_tile_3d_mesh_mapbox.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
const assert = require('assert');
import assert from 'assert';

describe('vector_tile_3d_mesh_mapbox', function _describe() {
let result;
Expand Down
2 changes: 1 addition & 1 deletion test/functional/vector_tile_raster_2d.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
const assert = require('assert');
import assert from 'assert';

describe('vector_tile_raster_2d', function _() {
let result;
Expand Down
2 changes: 1 addition & 1 deletion test/functional/vector_tile_raster_3d.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
const assert = require('assert');
import assert from 'assert';

describe('vector_tile_raster_3d', function _() {
let result;
Expand Down
2 changes: 1 addition & 1 deletion test/functional/view_25d_map.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
const assert = require('assert');
import assert from 'assert';

describe('view_25d_map', function _() {
let result;
Expand Down
2 changes: 1 addition & 1 deletion test/functional/view_2d_map.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
const assert = require('assert');
import assert from 'assert';

describe('view_2d_map', function _() {
let result;
Expand Down
2 changes: 1 addition & 1 deletion test/functional/view_3d_map.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
const assert = require('assert');
import assert from 'assert';

describe('view_3d_map', function _() {
let result;
Expand Down
2 changes: 1 addition & 1 deletion test/functional/view_multi_25d.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
const assert = require('assert');
import assert from 'assert';

describe('view_multi_25d', function _() {
let result;
Expand Down
2 changes: 1 addition & 1 deletion test/functional/view_multiglobe.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
const assert = require('assert');
import assert from 'assert';

describe('view_multiglobe', function _() {
let result;
Expand Down
2 changes: 1 addition & 1 deletion test/functional/widgets_3dtiles_style.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
const assert = require('assert');
import assert from 'assert';

describe('Widget C3dTilesStyle', function _() {
let result;
Expand Down
15 changes: 9 additions & 6 deletions test/hooks_functional.js
Original file line number Diff line number Diff line change
@@ -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
Expand All @@ -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;
Expand Down Expand Up @@ -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) {
Expand Down

0 comments on commit 04391f4

Please sign in to comment.