-
-
Notifications
You must be signed in to change notification settings - Fork 739
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Migrate to typescript #209
Conversation
Bundle size report: Size Change: -8.55 kB
ℹ️ View Details
|
@folke any chance to recruit you back to this? As a side note, there's a need also to convert the test folder and the tests themselves, which will be interesting (and a lot of work)... |
Initial check-in. |
So how do I get started? Running the following produces an error:
|
Currently I'm not using yarn. See the linked issue, there's a comment about a fork that has some of the information how to run stuff. |
So now we are down to 30 lint errors?
|
@wipfli I've committed package json. lint should run the lint only for the src folder, added build-tsc to allow fixing stuff in typescript compilation. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Let's not forget to remove cf52cc9 once we are done.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Was b5035a3 done with an automatic tool?
Yes. |
I think I did in recent commits. |
OK, I have now incorporated all the relevant changes from the following fork: |
5f29228 seems to be a mix of manual changes to |
I'm not sure it's worth the re-work. the changes there are mainly to make lint work and then run it. I agree this could've been handled better, but I'm not very good with git history re-writing, if you feel strongly about it, feel free. |
I agree that the rework will be quite some effort and I am happy to help here out. We have to keep in mind that this pull request will modify almost all files in this repo which means reviewing it will be tough. |
I regrouped the changes into manual and automatic steps here: https://github.com/wipfli/maplibre-gl-js/tree/typescript Instead of rewriting the history I did some cherry-picking :) My branch and this one here are identical up to |
I think we should delete yarn.lock and add package-lock.json to start migrating out of yarn. |
Yes let's commit |
I am re-running CI manually because it has failed for no good reason in #285. |
Turn on @typescript-eslint/quotes rule to standardize on single quotes for all strings.
* move point.ts from symbol/ to util/ * Remove empty line
Unnecessary casts for 'undefined' or 'null' as 'any'.
BOOM! |
* Update README.md * Initial commit - only rename and flow to typescript conversion * Iint upgrade * More lint fixes * Updated lint command, added build typescript command * Add non typed modules according to ts fork. * Switch from yarn to npm * Fix hasOwnProperty lint errors See https://eslint.org/docs/rules/no-prototype-builtins * I used this command for the conversions: * sed -i -E "s/([\(\!])([]/[a-zA-Z_.-]*).hasOwnProperty\(/ \1Object.prototype.hasOwnProperty.call(\2, /g" <file-name> * Fix extension from .js to .ts * Remove types file * Ignore lint errors * Remove .ts extension in import * Update CI from node v10 to v14 * Replace yarn with npm * Remove circleci * Fixed some typings errors * Explicitly convert matrix-gl types * Automatically fix lint errors * Avoid Function as callback type * Add missing MapOptions * Add pitchWithRotate to MapOptions and pass explicit options to HandlerManager and Camera * Set type of MapOptions.style to StyleSpecification of string * Make Camera an abstract class * Use Float32Array instead of Float64Array and cast types * Make object dynamically extendable See https://stackoverflow.com/questions/12710905/how-do-i-dynamically-assign-properties-to-an-object-in-typescript * Make more objects dynamically extenable * Explicit cast of array to length 2 * Do not provide type any in for..in loop * Make more objects dynamically extenable * Cast layout.get return value to Number * Cast number | void to number * Specify Rect type * Make thhird argument of getKey optional * Cast number | void to number * Define return type of parse() in subclasses of Expression * Cast return type of context.error() from void to null * Cast style-spec types to Type * Cast return type of context.error() from void to null * Cast style-spec types to Type * Cast dict to StylePropertySpecification * Specify array type as any to fix string[] inference * Make third argument of coalesce() optional * Explicit casts to Evaluate, Varargs, and Signature * Revert "Cast style-spec types to Type" This reverts commit 4af74a6. * Revert "Cast style-spec types to Type" This reverts commit efc4b1f. * Cast style-spec types at their source * Typescript: Remove @mapbox/geojson-types and replace with @types/GeoJSON' (#221) * remove @mapbox/geojson-types and replace with @types/GeoJSON * update toJSON using spread operator * add type to import GLSL as strings (#222) * Typescript: Use library to handle Window type (#223) * add window type lib * remove internal window type file and use lib * Fix issues related to possibly evaluated design * Move IControl interface to a new class, Fix timeoutID type. * remove flow-typed folder (#225) * Typescript: Remove reference to @mapbox/point-geometry TBC (#226) * Remove reference to @mapbox/point-geometry and replace with local point module with types Remove commented out types Fix cannot find type Point errors Add static to fix convert does not exist on typeof Point errors * Remove @mapbox/point-geometry from packkage.json * Fix lint * Typescript: fix lint and update .eslintrc with alternate TS rule (#227) * fix lint and .eslintrc with alternate TS rule * remove comment * Typescript: a number of minor fixes from WIP branch (#228) * fix minor ID type issues * minor casting fix non bool to bool * fix thrown Error message issue * fix a couple of import issues * match date comparison types * remove commented out code * fixes from WIP branch * remove redundant import for lint * more fixes * Fix small typings issues * More typescript fixes * More fixes to typings, lint fixes * Change base calls to be abstract * More type fixes * More types fixes * More types fixes * update use of mat4 (#219) updating types as gl-matrix more types to gl-matrix cleanup cast vs constructor cleanup more gl-matrix types more using gl-matrix instead of Float32Array fixes from WIP squashed into one commit minor cleanup and comments * Added some "as any" to places in the code where the typing were not just right and the method are proplemeatic... * More types fixing, not perfect but good enough. * Fix last typescript errors * Fix incorrect typings and code errors. * Remove flow from rollup and add tsc to build * Format file * Fix rollup build * Initial commit to make the render test run * Remove unneeded window import from all files * Remove version from API * More mock fixes to be able to run tests * fix running of test-expression (#232) * Add build phase before running some of the tests * Fix tests get stuck, still tests are failing... * get node query tests running (#233) * Fix mocking of case of tilejson implementation. * Typescript: Fix unit-tests (#235) * Move all referneces in unit test to use the build output * Fixes to window related stuff in unit tests, fixes to unneeded requires. * Fix to dem data test * Fix tests - remove window restore, fix __dirname. * Fix stub_loader due to function this usage. * Fix more tests * Fix tests and code that causes tests to fail. * Fix usage of ajax.js by subbing it correctly * Added missing window element to tests * removing window in 2 places gains 1601 passing (#236) * Adding missing windows to tests * Fix tests, revert some changes from typescript migration * More fixes related to removal of window * remove warnings, fix attribution test * Fix more tests * Fix more tests * Added missing stubs * Fixed tests related to version removal * More test fixes related to file path * Typescript: unit tests Frustum issues (#238) * fix minor file errors in stub_loader.js * matrix tests pass but not sure the tests represent actual usage * Fix primitive tests with minimal usage of "bad" types * Minor fixes to reduce incorrect typings * Fix image load for image source and style tests * Fix tests, added missing stub_loader * Fix uuid incorrect implemetation * Fix ajax tests. imporved image mock * Fix camera tests * Revert changes related to incorrect typescript solution Co-authored-by: James Hamilton <chippieTV@users.noreply.github.com> * Incorrect invocation of build-dev... * Fix lint errors * Removed test flow * Fix build csp, started to fix style build * Fix css build * Remove to vec3 as to code review requirements * Remove flow from build in ci * Remove references to @mapbox/point-geometry * Allow building style-spec * Fix build tests * Remove window, fix missing references to FeatureIndex using typescript config, update rollup dependencies * Fix lint * Fix production build * Remove buble, stop compiling for es5 * Added missing global definitions after removing window * Fix tests, bring back web_worker mock file, fix maplibre-gl loading issue, revert tsconfig. * Fix build? * Fix lint * Typescript: Fix query-tests (#240) * Initial commit to fix query-tests * Fix query tests * Fix some lint issues * Typescript: minor fixes to formatting (#241) * minor fixes * fix formatting of object key value types * Remove unneeded comments * Fix according to code review * Remove undefined as any * Fix according to code review requirements. * Fix lint * More lint cover and fixes * Fix lint for windows, update versions. * Fix browser tests due to incorrect lint fix * Fix lint for land.html * Fix minimal node version to 14 * Typescript: merge from main (#243) * Highlight backport rules * Add backport rules * Add backport rules * Use organization secret NPM_ORG_TOKEN (#231) * Fix link in README and CONTRIBUTING. Fix typo in README. (#237) * one yarn forgotten (#242) Co-authored-by: Marcel Normann <marcel.normann@wheregroup.com> Co-authored-by: Oliver Wipfli <oliver.wipfli@leichteralsluft.ch> Co-authored-by: tunnelpuzzle <79618312+tunnelpuzzle@users.noreply.github.com> * Update Life of a tile docs (#247) * rename .js to .ts in doc/life-of-a-tile.md * Update Developer Doc - Life of a tile (#245) * life of a tile * correction * Update package.json (#248) * rename .js to .ts in doc/life-of-a-tile.md * life of a tile * correction * package.json * some updates from review (#252) * Fix WritingMode cast (#254) * Run CI on all pull requests (#255) * Remove redundant parentheses (#257) * Remove (minify = false) * Review cleanup (#259) * Remove redundant parentheses * Remove eslint typescript exceptions * Remove flow comments * Remove `Number()` casts * Remove parentheses * Remove commented lint plugin * Remove `HM TODO` comments * Remove TODO, Fix according to code review changes * Remove last TODOs. * Updated changelog * Change publish style spec to reflect latest changes in typescript * Fix code review comments * Declare `emplace()` with variable number of arguments (#262) * Fix comment of generated files * Fix according to code review * remove comment and update type in jsdoc (#269) * Copy dist folder with `cp -r` (#274) * Fix typo * Fix last comments about generated files. * Fix typos in comments (#283) * Remove polyfill support for IE11 (#284) * Use native endsWith function * Use native Object.values function * Use native Number.MAX_SAFE_INTEGER value * Fix typos, remove unused functions The functions are already defined in `src/util/mapbox.ts` * Enforce semicolons as member delimters (#282) * eslint - enforce single quotes (#285) Turn on @typescript-eslint/quotes rule to standardize on single quotes for all strings. * move point.ts from symbol/ to util/ (#287) * move point.ts from symbol/ to util/ * Remove empty line * Remove undefined as any casts (#292) Unnecessary casts for 'undefined' or 'null' as 'any'. * Remove feature detection for {passive: false} support (#291) * Changed version in package.json before merge * Remove the usage of devicePixelRatio as a getter from browser.ts (#294) Co-authored-by: Oliver Wipfli <oliver.wipfli@leichteralsluft.ch> Co-authored-by: James Hamilton <chippieTV@users.noreply.github.com> Co-authored-by: Astrid <astridx@users.noreply.github.com> Co-authored-by: Marcel Normann <marcel.normann@wheregroup.com> Co-authored-by: tunnelpuzzle <79618312+tunnelpuzzle@users.noreply.github.com> Co-authored-by: Frédéric Junod <frederic.junod@camptocamp.com> Co-authored-by: Derek Westcott <drwestco@gmail.com>
I restored the typescript branch for easier bisection with respect to #326. |
* Update README.md * Initial commit - only rename and flow to typescript conversion * Iint upgrade * More lint fixes * Updated lint command, added build typescript command * Add non typed modules according to ts fork. * Switch from yarn to npm * Fix hasOwnProperty lint errors See https://eslint.org/docs/rules/no-prototype-builtins * I used this command for the conversions: * sed -i -E "s/([\(\!])([]/[a-zA-Z_.-]*).hasOwnProperty\(/ \1Object.prototype.hasOwnProperty.call(\2, /g" <file-name> * Fix extension from .js to .ts * Remove types file * Ignore lint errors * Remove .ts extension in import * Update CI from node v10 to v14 * Replace yarn with npm * Remove circleci * Fixed some typings errors * Explicitly convert matrix-gl types * Automatically fix lint errors * Avoid Function as callback type * Add missing MapOptions * Add pitchWithRotate to MapOptions and pass explicit options to HandlerManager and Camera * Set type of MapOptions.style to StyleSpecification of string * Make Camera an abstract class * Use Float32Array instead of Float64Array and cast types * Make object dynamically extendable See https://stackoverflow.com/questions/12710905/how-do-i-dynamically-assign-properties-to-an-object-in-typescript * Make more objects dynamically extenable * Explicit cast of array to length 2 * Do not provide type any in for..in loop * Make more objects dynamically extenable * Cast layout.get return value to Number * Cast number | void to number * Specify Rect type * Make thhird argument of getKey optional * Cast number | void to number * Define return type of parse() in subclasses of Expression * Cast return type of context.error() from void to null * Cast style-spec types to Type * Cast return type of context.error() from void to null * Cast style-spec types to Type * Cast dict to StylePropertySpecification * Specify array type as any to fix string[] inference * Make third argument of coalesce() optional * Explicit casts to Evaluate, Varargs, and Signature * Revert "Cast style-spec types to Type" This reverts commit 4af74a6. * Revert "Cast style-spec types to Type" This reverts commit efc4b1f. * Cast style-spec types at their source * Typescript: Remove @mapbox/geojson-types and replace with @types/GeoJSON' (#221) * remove @mapbox/geojson-types and replace with @types/GeoJSON * update toJSON using spread operator * add type to import GLSL as strings (#222) * Typescript: Use library to handle Window type (#223) * add window type lib * remove internal window type file and use lib * Fix issues related to possibly evaluated design * Move IControl interface to a new class, Fix timeoutID type. * remove flow-typed folder (#225) * Typescript: Remove reference to @mapbox/point-geometry TBC (#226) * Remove reference to @mapbox/point-geometry and replace with local point module with types Remove commented out types Fix cannot find type Point errors Add static to fix convert does not exist on typeof Point errors * Remove @mapbox/point-geometry from packkage.json * Fix lint * Typescript: fix lint and update .eslintrc with alternate TS rule (#227) * fix lint and .eslintrc with alternate TS rule * remove comment * Typescript: a number of minor fixes from WIP branch (#228) * fix minor ID type issues * minor casting fix non bool to bool * fix thrown Error message issue * fix a couple of import issues * match date comparison types * remove commented out code * fixes from WIP branch * remove redundant import for lint * more fixes * Fix small typings issues * More typescript fixes * More fixes to typings, lint fixes * Change base calls to be abstract * More type fixes * More types fixes * More types fixes * update use of mat4 (#219) updating types as gl-matrix more types to gl-matrix cleanup cast vs constructor cleanup more gl-matrix types more using gl-matrix instead of Float32Array fixes from WIP squashed into one commit minor cleanup and comments * Added some "as any" to places in the code where the typing were not just right and the method are proplemeatic... * More types fixing, not perfect but good enough. * Fix last typescript errors * Fix incorrect typings and code errors. * Remove flow from rollup and add tsc to build * Format file * Fix rollup build * Initial commit to make the render test run * Remove unneeded window import from all files * Remove version from API * More mock fixes to be able to run tests * fix running of test-expression (#232) * Add build phase before running some of the tests * Fix tests get stuck, still tests are failing... * get node query tests running (#233) * Fix mocking of case of tilejson implementation. * Typescript: Fix unit-tests (#235) * Move all referneces in unit test to use the build output * Fixes to window related stuff in unit tests, fixes to unneeded requires. * Fix to dem data test * Fix tests - remove window restore, fix __dirname. * Fix stub_loader due to function this usage. * Fix more tests * Fix tests and code that causes tests to fail. * Fix usage of ajax.js by subbing it correctly * Added missing window element to tests * removing window in 2 places gains 1601 passing (#236) * Adding missing windows to tests * Fix tests, revert some changes from typescript migration * More fixes related to removal of window * remove warnings, fix attribution test * Fix more tests * Fix more tests * Added missing stubs * Fixed tests related to version removal * More test fixes related to file path * Typescript: unit tests Frustum issues (#238) * fix minor file errors in stub_loader.js * matrix tests pass but not sure the tests represent actual usage * Fix primitive tests with minimal usage of "bad" types * Minor fixes to reduce incorrect typings * Fix image load for image source and style tests * Fix tests, added missing stub_loader * Fix uuid incorrect implemetation * Fix ajax tests. imporved image mock * Fix camera tests * Revert changes related to incorrect typescript solution Co-authored-by: James Hamilton <chippieTV@users.noreply.github.com> * Incorrect invocation of build-dev... * Fix lint errors * Removed test flow * Fix build csp, started to fix style build * Fix css build * Remove to vec3 as to code review requirements * Remove flow from build in ci * Remove references to @mapbox/point-geometry * Allow building style-spec * Fix build tests * Remove window, fix missing references to FeatureIndex using typescript config, update rollup dependencies * Fix lint * Fix production build * Remove buble, stop compiling for es5 * Added missing global definitions after removing window * Fix tests, bring back web_worker mock file, fix maplibre-gl loading issue, revert tsconfig. * Fix build? * Fix lint * Typescript: Fix query-tests (#240) * Initial commit to fix query-tests * Fix query tests * Fix some lint issues * Typescript: minor fixes to formatting (#241) * minor fixes * fix formatting of object key value types * Remove unneeded comments * Fix according to code review * Remove undefined as any * Fix according to code review requirements. * Fix lint * More lint cover and fixes * Fix lint for windows, update versions. * Fix browser tests due to incorrect lint fix * Fix lint for land.html * Fix minimal node version to 14 * Typescript: merge from main (#243) * Highlight backport rules * Add backport rules * Add backport rules * Use organization secret NPM_ORG_TOKEN (#231) * Fix link in README and CONTRIBUTING. Fix typo in README. (#237) * one yarn forgotten (#242) Co-authored-by: Marcel Normann <marcel.normann@wheregroup.com> Co-authored-by: Oliver Wipfli <oliver.wipfli@leichteralsluft.ch> Co-authored-by: tunnelpuzzle <79618312+tunnelpuzzle@users.noreply.github.com> * Update Life of a tile docs (#247) * rename .js to .ts in doc/life-of-a-tile.md * Update Developer Doc - Life of a tile (#245) * life of a tile * correction * Update package.json (#248) * rename .js to .ts in doc/life-of-a-tile.md * life of a tile * correction * package.json * some updates from review (#252) * Fix WritingMode cast (#254) * Run CI on all pull requests (#255) * Remove redundant parentheses (#257) * Remove (minify = false) * Review cleanup (#259) * Remove redundant parentheses * Remove eslint typescript exceptions * Remove flow comments * Remove `Number()` casts * Remove parentheses * Remove commented lint plugin * Remove `HM TODO` comments * Remove TODO, Fix according to code review changes * Remove last TODOs. * Updated changelog * Change publish style spec to reflect latest changes in typescript * Fix code review comments * Declare `emplace()` with variable number of arguments (#262) * Fix comment of generated files * Fix according to code review * remove comment and update type in jsdoc (#269) * Copy dist folder with `cp -r` (#274) * Fix typo * Fix last comments about generated files. * Fix typos in comments (#283) * Remove polyfill support for IE11 (#284) * Use native endsWith function * Use native Object.values function * Use native Number.MAX_SAFE_INTEGER value * Fix typos, remove unused functions The functions are already defined in `src/util/mapbox.ts` * Enforce semicolons as member delimters (#282) * eslint - enforce single quotes (#285) Turn on @typescript-eslint/quotes rule to standardize on single quotes for all strings. * move point.ts from symbol/ to util/ (#287) * move point.ts from symbol/ to util/ * Remove empty line * Remove undefined as any casts (#292) Unnecessary casts for 'undefined' or 'null' as 'any'. * Remove feature detection for {passive: false} support (#291) * Changed version in package.json before merge * Remove the usage of devicePixelRatio as a getter from browser.ts (#294) Co-authored-by: Oliver Wipfli <oliver.wipfli@leichteralsluft.ch> Co-authored-by: James Hamilton <chippieTV@users.noreply.github.com> Co-authored-by: Astrid <astridx@users.noreply.github.com> Co-authored-by: Marcel Normann <marcel.normann@wheregroup.com> Co-authored-by: tunnelpuzzle <79618312+tunnelpuzzle@users.noreply.github.com> Co-authored-by: Frédéric Junod <frederic.junod@camptocamp.com> Co-authored-by: Derek Westcott <drwestco@gmail.com>
Launch Checklist
version
from library API.maplibre-gl-js
changelog:<changelog></changelog>
Motivation and some background:
The current code run on node 10, the migration to node 14 is difficult since some of the libraries are no longer supported.
This is also true regarding documentation of essential libraries such as flow (for typings) and tap (for testing).
The goal of this PR is to update the stack to a more widely used technologies and differentiate this library from mapbox-gl to avoid license breach.
Techonologies
Typescript for type checking
Jest for testing
rollup for packaging
eslint for code checking
The following boilerplate code would be used to facilitate the above widely used technologies.
https://github.com/VitorLuizC/typescript-library-boilerplate
This is a very large task and we'd appreciate any help from anyone :-)
Task by priority:
@mapbox/geojson-types
and use@types/geosjon
.@mapbox/point-geometry
and bring it in to this library (after converting it to typescript as this is only one file).Convert test, debug, benchmark code to typescriptMake all linters pass (not just for the main library) [Typescript] Add more folders to lint #272Make their tsc passConvert tests to use jest [Typescript] Convert tests to jest and karma #273Removetap
and related code around it [Typescript] Convert tests to jest and karma #273Update dependencies (referenced inpackage.json
) [Typescript] Update dependencies #270Change types only declarations to.d.ts
files [Typescript] Rename declarations only files tod.ts
#271@maplibre/style-spec
is workingI have decided to reduce the number of changes introduced in this migration - i.e. keep the tests as they are now, do not convert unit tests to typescript.
There will be an option later to do all these changes after things starts to work as expected in other PRs.