From a2037201d2acaba8cd52fb4901ed7f030de52847 Mon Sep 17 00:00:00 2001 From: Harel M Date: Thu, 11 Jan 2024 13:37:41 +0200 Subject: [PATCH] Export types along the default export (#3564) * Export types along the default export * Fix lint * Export only the types * Fix lint and docs generation * Added import to the test to make sure this won't happen in the future, removed unneeded files * remove unneeded files * Fix tests failure due to build * Move imports to use generated types --- .github/workflows/test-all.yml | 2 +- CHANGELOG.md | 2 + build/generate-typings.ts | 18 -------- package.json | 4 +- src/index.ts | 51 ++++++++++++++++++++- test/integration/assets/tiles/package.json | 5 -- test/integration/assets/tiles/upgrade.js | 46 ------------------- test/integration/browser/browser.test.ts | 6 +-- test/integration/render/run_render_tests.ts | 7 +-- tsconfig.json | 3 +- 10 files changed, 61 insertions(+), 83 deletions(-) delete mode 100644 build/generate-typings.ts delete mode 100644 test/integration/assets/tiles/package.json delete mode 100644 test/integration/assets/tiles/upgrade.js diff --git a/.github/workflows/test-all.yml b/.github/workflows/test-all.yml index d4549c72d9..7d03b20201 100644 --- a/.github/workflows/test-all.yml +++ b/.github/workflows/test-all.yml @@ -98,7 +98,7 @@ jobs: if: runner.os == 'Linux' run: nohup Xvfb & echo "DISPLAY=:0" >> $GITHUB_ENV - - run: npm run build-dev + - run: npm run build-dist - run: npm run test-render env: CURRENT_SPLIT_INDEX: ${{ matrix.split }} diff --git a/CHANGELOG.md b/CHANGELOG.md index edf6aae361..0c82c93112 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -5,6 +5,8 @@ - _...Add new stuff here..._ ### 🐞 Bug fixes + +- Fix missing export `Map` type in the `d.ts` file ([#3564](https://github.com/maplibre/maplibre-gl-js/pull/3564)) - _...Add new stuff here..._ ## 4.0.0-pre.3 diff --git a/build/generate-typings.ts b/build/generate-typings.ts deleted file mode 100644 index 737520d2d8..0000000000 --- a/build/generate-typings.ts +++ /dev/null @@ -1,18 +0,0 @@ - -import fs from 'fs'; -import childProcess from 'child_process'; - -if (!fs.existsSync('dist')) { - fs.mkdirSync('dist'); -} - -console.log('Starting bundling types'); -const outputFile = './dist/maplibre-gl.d.ts'; -childProcess.execSync(`dts-bundle-generator --umd-module-name=maplibregl -o ${outputFile} ./src/index.ts`); -let types = fs.readFileSync(outputFile, 'utf8'); -// Classes are not exported but should be since this is exported as UMD - fixing... -types = types.replace(/declare class/g, 'export declare class'); -fs.writeFileSync(outputFile, types); - -console.log('Finished bundling types for MapLibre GL JS'); - diff --git a/package.json b/package.json index 3e584b9e6a..8f2523048a 100644 --- a/package.json +++ b/package.json @@ -144,10 +144,10 @@ "generate-shaders": "node --no-warnings --loader ts-node/esm build/generate-shaders.ts", "generate-struct-arrays": "node --no-warnings --loader ts-node/esm build/generate-struct-arrays.ts", "generate-style-code": "node --no-warnings --loader ts-node/esm build/generate-style-code.ts", - "generate-typings": "node --no-warnings --loader ts-node/esm build/generate-typings.ts", + "generate-typings": "dts-bundle-generator --umd-module-name=maplibregl -o ./dist/maplibre-gl.d.ts ./src/index.ts", "generate-docs": "typedoc && node --no-warnings --loader ts-node/esm build/generate-docs.ts", "generate-images": "node --no-warnings --loader ts-node/esm build/generate-doc-images.ts", - "build-dist": "run-p --print-label generate-typings build-dev build-prod build-csp build-csp-dev build-css", + "build-dist": "npm run generate-typings && run-p --print-label build-dev build-prod build-csp build-csp-dev build-css", "build-dev": "rollup --configPlugin @rollup/plugin-typescript -c --environment BUILD:dev", "watch-dev": "rollup --configPlugin @rollup/plugin-typescript -c --environment BUILD:dev --watch", "build-prod": "rollup --configPlugin @rollup/plugin-typescript -c --environment BUILD:production", diff --git a/src/index.ts b/src/index.ts index dfca73bcce..d517ed8ad9 100644 --- a/src/index.ts +++ b/src/index.ts @@ -24,7 +24,7 @@ import {prewarm, clearPrewarmedResources} from './util/global_worker_pool'; import {PerformanceUtils} from './util/performance'; import {AJAXError} from './util/ajax'; import {GeoJSONSource} from './source/geojson_source'; -import {CanvasSource} from './source/canvas_source'; +import {CanvasSource, CanvasSourceSpecification} from './source/canvas_source'; import {ImageSource} from './source/image_source'; import {RasterDEMTileSource} from './source/raster_dem_tile_source'; import {RasterTileSource} from './source/raster_tile_source'; @@ -33,6 +33,15 @@ import {VideoSource} from './source/video_source'; import {addSourceType, type SourceClass} from './source/source'; import {addProtocol, removeProtocol} from './source/protocol_crud'; import {getGlobalDispatcher} from './util/dispatcher'; +import {MapContextEvent, MapMouseEvent, MapTouchEvent, MapWheelEvent} from './ui/events'; +import {IControl} from './ui/control/control'; +import {ScrollZoomHandler} from './ui/handler/scroll_zoom'; +import {TwoFingersTouchZoomRotateHandler} from './ui/handler/shim/two_fingers_touch'; +import {DragPanHandler} from './ui/handler/shim/drag_pan'; +import {DoubleClickZoomHandler} from './ui/handler/shim/dblclick_zoom'; +import {BoxZoomHandler} from './ui/handler/box_zoom'; +import {DragRotateHandler} from './ui/handler/shim/drag_rotate'; +import {CustomLayerInterface} from './style/style_layer/custom_style_layer'; const version = packageJSON.version; export type * from '@maplibre/maplibre-gl-style-spec'; @@ -268,4 +277,44 @@ class MapLibreGL { //This gets automatically stripped out in production builds. Debug.extend(MapLibreGL, {isSafari, getPerformanceMetrics: PerformanceUtils.getPerformanceMetrics}); +export { + type Map, + type NavigationControl, + type GeolocateControl, + type AttributionControl, + type LogoControl, + type ScaleControl, + type FullscreenControl, + type TerrainControl, + type Popup, + type Marker, + type Style, + type LngLat, + type LngLatBounds, + type Point, + type MercatorCoordinate, + type Evented, + type AJAXError, + type CanvasSource, + type GeoJSONSource, + type ImageSource, + type RasterDEMTileSource, + type RasterTileSource, + type VectorTileSource, + type VideoSource, + type MapMouseEvent, + type MapTouchEvent, + type MapWheelEvent, + type MapContextEvent, + type IControl, + type ScrollZoomHandler, + type TwoFingersTouchZoomRotateHandler, + type DragPanHandler, + type DoubleClickZoomHandler, + type BoxZoomHandler, + type DragRotateHandler, + type CustomLayerInterface, + type CanvasSourceSpecification +}; + export default MapLibreGL; diff --git a/test/integration/assets/tiles/package.json b/test/integration/assets/tiles/package.json deleted file mode 100644 index 2512409a4b..0000000000 --- a/test/integration/assets/tiles/package.json +++ /dev/null @@ -1,5 +0,0 @@ -{ - "dependencies": { - "mapnik": "~3.6.2" - } -} diff --git a/test/integration/assets/tiles/upgrade.js b/test/integration/assets/tiles/upgrade.js deleted file mode 100644 index 326551b599..0000000000 --- a/test/integration/assets/tiles/upgrade.js +++ /dev/null @@ -1,46 +0,0 @@ -/* eslint-disable import/no-commonjs */ - -const mapnik = require('mapnik'); -const fs = require('fs'); -const queue = require('d3').queue; - -function upgrade(z, x, y, path, callback) { - console.log('Updating ', path); - const buffer = fs.readFileSync(path); - const vt = new mapnik.VectorTile(z, x, y); - vt.addData(buffer, {upgrade: true, validate: true}, (err) => { - if (err) throw err; - fs.writeFileSync(path, vt.getDataSync()); - callback(); - }); -} - -function createExtent1024(callback) { - console.log('Creating extent1024'); - const buffer = fs.readFileSync('14-8802-5374.mvt'); - const vt = new mapnik.VectorTile(14, 8802, 5374, {tileSize: 1024}); - vt.addData(buffer, {validate: true}, (err) => { - if (err) throw err; - fs.writeFileSync('extent1024-14-8802-5374.mvt', vt.getDataSync()); - callback(); - }); -} - -const q = queue(1); - -q.defer(upgrade, 0, 0, 0, '0-0-0.mvt'); -q.defer(upgrade, 14, 8802, 5374, '14-8802-5374.mvt'); -q.defer(upgrade, 14, 8802, 5375, '14-8802-5375.mvt'); -q.defer(upgrade, 14, 8803, 5374, '14-8803-5374.mvt'); -q.defer(upgrade, 14, 8803, 5375, '14-8803-5375.mvt'); -q.defer(upgrade, 2, 1, 1, '2-1-1.mvt'); -q.defer(upgrade, 2, 1, 2, '2-1-2.mvt'); -q.defer(upgrade, 2, 2, 1, '2-2-1.mvt'); -q.defer(upgrade, 2, 2, 2, '2-2-2.mvt'); -q.defer(upgrade, 7, 37, 48, 'counties-7-37-48.mvt'); -q.defer(createExtent1024); - -q.await((err) => { - if (err) throw err; - console.log('Done.'); -}); diff --git a/test/integration/browser/browser.test.ts b/test/integration/browser/browser.test.ts index 5077c5e5ef..cd176d07a0 100644 --- a/test/integration/browser/browser.test.ts +++ b/test/integration/browser/browser.test.ts @@ -1,10 +1,8 @@ import puppeteer, {Page, Browser} from 'puppeteer'; import st from 'st'; -import http from 'http'; -import type {Server} from 'http'; +import http, {type Server} from 'http'; import type {AddressInfo} from 'net'; -import type {Map} from '../../../src/ui/map'; -import type {default as MapLibreGL} from '../../../src/index'; +import type {default as MapLibreGL, Map} from '../../../dist/maplibre-gl'; import {sleep} from '../../../src/util/test/util'; const testWidth = 800; diff --git a/test/integration/render/run_render_tests.ts b/test/integration/render/run_render_tests.ts index 225df5a24b..195315143a 100644 --- a/test/integration/render/run_render_tests.ts +++ b/test/integration/render/run_render_tests.ts @@ -10,13 +10,10 @@ import http from 'http'; import puppeteer, {Page, Browser} from 'puppeteer'; import v8toIstanbul from 'v8-to-istanbul'; import {localizeURLs} from '../lib/localize-urls'; -import maplibregl from '../../../src/index'; -import type {StyleSpecification} from '@maplibre/maplibre-gl-style-spec'; -import type {CanvasSource} from '../../../src/source/canvas_source'; -import type {Map} from '../../../src/ui/map'; -import type {PointLike} from '../../../src/ui/camera'; +import type {default as MapLibreGL, Map, CanvasSource, PointLike, StyleSpecification} from '../../../dist/maplibre-gl'; const __dirname = dirname(fileURLToPath(import.meta.url)); +let maplibregl: typeof MapLibreGL; type TestData = { id: string; diff --git a/tsconfig.json b/tsconfig.json index 78af27bd34..8930946e23 100644 --- a/tsconfig.json +++ b/tsconfig.json @@ -38,7 +38,8 @@ "include": [ "rollup.config.*", "src/**/*", - "test/bench/**/*" + "test/bench/**/*", + "test/integration/**/*" ], "exclude": [ "node_modules",