lucsoft / esbuild-plugin-http-imports

persistent cached http import resolution for esbuild
https://deno.land/x/esbuild_plugin_http_imports
Creative Commons Zero v1.0 Universal
11 stars 2 forks source link

Use full path for fetch instead of pathname #1

Closed MariusVatasoiu closed 1 year ago

MariusVatasoiu commented 1 year ago

Currently, the plugin fetches resources only by using the pathname, ignoring the query strings. It should also work with query strings, since they can change entirely a file.

For example, using esm.sh with pinned version:

import styleToJS from 'https://esm.sh/style-to-js@1.1.3?pin=v113';

The plugin will fetch import styleToJS from 'https://esm.sh/style-to-js@1.1.3';, which is a different URL and the last version of esm.sh is used, instead of v113.

The fix should be here, at line 71:

From:

return responseCache[ path ] = await fetch(path.split("?")[ 0 ], { headers });

to

return responseCache[ path ] = await fetch(path, { headers });

I opened a PR #2 for this change.

lucsoft commented 1 year ago

Hey really thanks for the PR and also Great Work!

I have actually made a more refined version of this http import plugin under https://github.com/lucsoft/esbuild_serve/blob/main/features/httpImports.ts

it has some more bugfixes and new features.

Seeing here new people popup, I wonder if it would be useful if we just reexport it this "internal plugin" here.

MariusVatasoiu commented 1 year ago

I think it would be a nice idea if the plugin would be a separated module. This way, people will easily discover it. I know you can export it from esbuild_serve, but won't have the same visibility. It really is a fantastic plugin 👏.

Also, it won't have any impact on the esbuild_serve module since you can import it there.

And a description on deno.land/x listing would help too.