perliedman / geojson-path-finder

Find shortest path through a network of GeoJSON
https://www.liedman.net/geojson-path-finder/
ISC License
300 stars 86 forks source link

Mixing default and named exports makes i hard to import #85

Open pbvahlst opened 1 year ago

pbvahlst commented 1 year ago

After the named export pathToGeoJSON was added it has become hard to use the module in node.js without a bundler (rollup/webpack) as the mixing of default and named exports requires multiple steps to import the default export in barebones node.js. The problem is discussed here https://github.com/rollup/rollup/issues/1961#issuecomment-423037881

In our case we use both a bundler and node.js worker threads to calculate the path-finder graph in a worker thread, so to reuse the code to construct the path finder we have to do this to be able to handle the import in both scenarios.

import geoJsonPathFinder from "geojson-path-finder";
let GeoJsonPathFinder = geoJsonPathFinder;
if (GeoJsonPathFinder.default) {
    GeoJsonPathFinder = GeoJsonPathFinder.default;
}

is it possible to change to all named exports. Or maybe just rewrite the export to have both a default export and named export PathFinder?

perliedman commented 1 year ago

Hi @pbvahlst, sorry about not getting back to you on this before.

Supporting both CJS and ESM through various bundlers continues to be a real pain!

To avoid breaking compatibility and forcing a new major version upgrade, I guess we could use your second suggestion, using both default exports as well as named exports.

An unrelated question, you seem to use this library quite a lot and have posted some nice replies. How would you feel about being added as a maintainer? Personally, I only use geojson-path-finder in a project that is currently in "low maintenance" mode, so I don't get to spend much time on it...

pbvahlst commented 1 year ago

Thanks for the nice offer I am currently wrapping up the project where I used geojson-path-finder and am moving on to a new project without a path-finder requirement, so I will not use the package that much for the next period of time. (sadly, it has been a lot of fun). If a new project comes up with path-finder requirements I will be have to help out if the offer still stands. If you wish I will keep helping answering questions when needed.

/peter