Closed fabiancook closed 2 years ago
Using an import map, this polyfill can be utilised directly through GitHub:
{
"imports": {
"https://raw.githubusercontent.com/kenchris/urlpattern-polyfill/main/src/url-pattern": "https://raw.githubusercontent.com/kenchris/urlpattern-polyfill/main/src/url-pattern.ts",
"https://raw.githubusercontent.com/kenchris/urlpattern-polyfill/main/src/url-utils": "https://raw.githubusercontent.com/kenchris/urlpattern-polyfill/main/src/url-utils.ts",
"https://raw.githubusercontent.com/kenchris/urlpattern-polyfill/main/src/url-pattern.interfaces": "https://raw.githubusercontent.com/kenchris/urlpattern-polyfill/main/src/url-pattern.interfaces.ts",
"https://raw.githubusercontent.com/kenchris/urlpattern-polyfill/main/src/path-to-regex-modified": "https://raw.githubusercontent.com/kenchris/urlpattern-polyfill/main/src/path-to-regex-modified.ts",
"https://raw.githubusercontent.com/kenchris/urlpattern-polyfill/main/src/url-pattern-parser": "https://raw.githubusercontent.com/kenchris/urlpattern-polyfill/main/src/url-pattern-parser.ts",
"urlpattern-polyfill": "https://raw.githubusercontent.com/kenchris/urlpattern-polyfill/main/src/index.ts",
}
}
This would be similar if it was deployed to deno.land unless these typescript files were process further to include extensions for deployment.
Ignoring the later failing jobs in these actions, we can see this code running across deno, node, webkit, chrome, and firefox:
appHistory.addEventListener("navigate", ({ destination }) => {
const identifiedTest = new URLPattern({
pathname: "/test/:id"
});
if (identifiedTest.test({ pathname: destination.url })) {
body.innerHTML = destination.getState<{ innerHTML: string }>().innerHTML;
} else {
throw new Error(unexpectedPage);
}
});
Running the tests we can see the matcher is working:
START urlPatternExample
Updated window pathname to /test/1
Updated window pathname to /test/2
PASS urlPatternExample
I don't know much about deno land or how to publish it there. Could you share instructions?
Now that your module that is published to npm with exports
, it is also directly compatible with skypack (maybe it was before too?)
I found that I can now just use the import map:
{
"imports": {
"urlpattern-polyfill": "https://cdn.skypack.dev/urlpattern-polyfill"
}
}
However some might still want to access from deno.land, here are steps to publish to the deno.land registry:
src/
here is usable because your source is typescript, deno can directly utilise itI think the problem here would be though... the import map still will be a bit messy because of deno's requirement for extensions to be present for exports, while this isn't common practice when writing typescript
Once deployed the import map would probably look something like:
{
"imports": {
"https://deno.land/x/urlpattern_polyfill/url-pattern": "https://deno.land/x/urlpattern_polyfill/url-pattern.ts",
"https://deno.land/x/urlpattern_polyfill/url-utils": "https://deno.land/x/urlpattern_polyfill/url-utils.ts",
"https://deno.land/x/urlpattern_polyfill/url-pattern.interfaces": "https://deno.land/x/urlpattern_polyfill/url-pattern.interfaces.ts",
"https://deno.land/x/urlpattern_polyfill/path-to-regex-modified": "https://deno.land/x/urlpattern_polyfill/path-to-regex-modified.ts",
"https://deno.land/x/urlpattern_polyfill/url-pattern-parser": "https://deno.land/x/urlpattern_polyfill/url-pattern-parser.ts",
"urlpattern-polyfill": "https://deno.land/x/urlpattern_polyfill"
}
}
Even then, I'm not sure how deno's resolution exactly works, and it might rely on the redirected to url for this individual mapping, meaning possibly this is the required import map with version pinning included:
{
"imports": {
"https://deno.land/x/urlpattern_polyfill@v1.0.0-rc2/url-pattern": "https://deno.land/x/urlpattern_polyfill@v1.0.0-rc2/url-pattern.ts",
"https://deno.land/x/urlpattern_polyfill@v1.0.0-rc2/url-utils": "https://deno.land/x/urlpattern_polyfill@v1.0.0-rc2/url-utils.ts",
"https://deno.land/x/urlpattern_polyfill@v1.0.0-rc2/url-pattern.interfaces": "https://deno.land/x/urlpattern_polyfill@v1.0.0-rc2/url-pattern.interfaces.ts",
"https://deno.land/x/urlpattern_polyfill@v1.0.0-rc2/path-to-regex-modified": "https://deno.land/x/urlpattern_polyfill@v1.0.0-rc2/path-to-regex-modified.ts",
"https://deno.land/x/urlpattern_polyfill@v1.0.0-rc2/url-pattern-parser": "https://deno.land/x/urlpattern_polyfill@v1.0.0-rc2/url-pattern-parser.ts",
"urlpattern-polyfill": "https://deno.land/x/urlpattern_polyfill@v1.0.0-rc2"
}
}
TLDR seems like skypack is a better goto here, no additional steps required there.
Why do you need it in Deno? Deno supports URLPattern natively now
Ha! Well, I guess I could work a local polyfill file to detect globalThis.URLPattern exists!
I'm writing code that is compatible across all platforms, so using the polyfill is a must for others like node or the browser. I would have expected this polyfill to eventually provide the global where it is present.
I see. That is tracked in https://github.com/kenchris/urlpattern-polyfill/issues/47 so closing this one
Would it be possible to have this added to the denoland registry?
This would involve adding a webhook to this module, which would then publish the typescript source.
Details are listed here: https://deno.land/x