Skip to content
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

chore: Replace osmtogeojson #11438

Open
wants to merge 7 commits into
base: main
Choose a base branch
from

Conversation

hangy
Copy link
Member

@hangy hangy commented Feb 16, 2025

Replaces npm module osmtogeojson, which requires a vulnerable version of an XML parser, and is unmaintained, with an API that returns GeoJSON natively.

Additionally rewrites display-tag.js and display-map.js files to use ES modules, which are now well supported by browser, to reduce the usage of /* global */ to avoid eslint complaining about an error.

Fixes https://github.com/openfoodfacts/openfoodfacts-server/security/dependabot/32 by removing the transitive dependency.

@github-actions github-actions bot added 📖 Knowledge Panels https://wiki.openfoodfacts.org/Knowledge_panels 🗺️ Maps dependencies Pull requests that update a dependency file Template::Toolkit The templating toolkit used by product opener. The starting point for HTML/JS/CSS fixes. Tags labels Feb 16, 2025
@codecov-commenter
Copy link

codecov-commenter commented Feb 17, 2025

Codecov Report

All modified and coverable lines are covered by tests ✅

Project coverage is 49.85%. Comparing base (42415bd) to head (9598a82).
Report is 30 commits behind head on main.

Additional details and impacted files
@@            Coverage Diff             @@
##             main   #11438      +/-   ##
==========================================
+ Coverage   49.71%   49.85%   +0.14%     
==========================================
  Files          82       83       +1     
  Lines       22896    22964      +68     
  Branches     5492     5501       +9     
==========================================
+ Hits        11383    11449      +66     
+ Misses      10124    10121       -3     
- Partials     1389     1394       +5     

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

@github-actions github-actions bot added the 💥 Merge Conflicts 💥 Merge Conflicts label Feb 17, 2025
@hangy hangy marked this pull request as ready for review February 19, 2025 08:35
@hangy hangy requested a review from a team as a code owner February 19, 2025 08:35
@github-actions github-actions bot removed the 💥 Merge Conflicts 💥 Merge Conflicts label Feb 20, 2025
/*global L */
/*exported displayMap*/
import * as L from './leaflet-src.esm.js';
import { MarkerClusterGroup } from './leaflet.markercluster.js';
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I tried to test it locally, but I'm getting an error when displaying search results on a map:

display-map.js:22 Uncaught SyntaxError: The requested module './leaflet.markercluster.js' does not provide an export named 'MarkerClusterGroup' (at display-map.js:22:10)

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sorry, I'll take a look

@hangy hangy requested a review from Copilot February 28, 2025 10:53
Copy link

@Copilot Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

PR Overview

This PR replaces the deprecated and vulnerable osmtogeojson module with a native GeoJSON API and updates the affected JavaScript files to use ES modules.

  • Removed osmtogeojson dependency and updated code to use native fetch and ES module imports.
  • Updated both display-tag.js and display-map.js to use ES modules and improved code structure.
  • Adjusted gulpfile.ts to remove the vulnerable module and include the correct Leaflet ES module file.

Reviewed Changes

File Description
html/js/display-tag.js Rewritten to use async/await and ES modules for fetching and processing GeoJSON data.
gulpfile.ts Removed osmtogeojson and updated to reference leaflet-src.esm.js.
html/js/display-map.js Converted to ES modules and updated MarkerClusterGroup import and usage.

Copilot reviewed 16 out of 16 changed files in this pull request and generated 1 comment.

Co-authored-by: Copilot <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
dependencies Pull requests that update a dependency file 📖 Knowledge Panels https://wiki.openfoodfacts.org/Knowledge_panels 🗺️ Maps Tags Template::Toolkit The templating toolkit used by product opener. The starting point for HTML/JS/CSS fixes. 🧪 tests
Projects
Status: In progress
Development

Successfully merging this pull request may close these issues.

3 participants