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

Include shims for the fs and path dependencies #977

Closed

Conversation

trygveaa
Copy link

Including fs and path in externals is not sufficient when this is used
in a browser. That will just make rollup leave the requires calls, and
when you try to include this library in a webpack project webpack will
complain that fs is missing.

By providing shims for fs and path, those will be used instead of
require calls, so that fixes the issue. Since no code paths in this
library triggers the code that requires fs or path it's safe to just
shim them out with an empty object.

Fixes #970

Including fs and path in externals is not sufficient when this is used
in a browser. That will just make rollup leave the requires calls, and
when you try to include this library in a webpack project webpack will
complain that fs is missing.

By providing shims for fs and path, those will be used instead of
require calls, so that fixes the issue. Since no code paths in this
library triggers the code that requires fs or path it's safe to just
shim them out with an empty object.

Fixes mapbox#970
@trygveaa
Copy link
Author

As an aside, I see that the rollup config makes rollup bundle all of the dependencies into the dist file. This seems like a poor thing to do?

By the way, this happens in master too, it's not because of the change in this PR.

@trygveaa
Copy link
Author

trygveaa commented Mar 20, 2020

I do think that the geojsonhint dependency should probably be dropped instead though. The readme states that development of it has paused, and jsonlint-lines which it depends on isn't developed anymore either and is intended for CLI usage.

Helpful error messages like this provides might be useful for development, but I don't really see the point of it when this library is used in production. It's not like the user calls add themselves.

Furthermore, Mapbox itself doesn't give such detailed error messages when you try to add a source with invalid data. Why should this library do it different than Mapbox?

Including it also adds to the bundle size (unless there is some way to have it as an optional dependency), which is another reason I think that people which want these helpful error messages should validate the json themselves.

In relevance to the previous comment, doing this shim is only possible because the dependencies are bundled. However, I don't think libraries should bundle dependencies, so then this fix can't be used. Therefore, just dropping geojsonhint would be a better solution.

Thoughts?

@karimnaaji karimnaaji closed this Jun 16, 2020
@karimnaaji karimnaaji reopened this Jun 16, 2020
@arindam1993 arindam1993 changed the base branch from master to main June 17, 2020 01:23
@stepankuzmin
Copy link
Contributor

Thanks for the contribution, @trygveaa. Draw no longer depends on geojsonhint, so I will close this.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Built file in master requires fs
3 participants