jq79 0.5.3 → 0.5.4

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "jq79",
3
- "version": "0.5.3",
3
+ "version": "0.5.4",
4
4
  "description": "Mini reactive component library: single-file components, Svelte-style setup scripts, fine-grained proxy reactivity. Single-file build, zero dependencies.",
5
5
  "keywords": [
6
6
  "reactive",
package/src/jq79.ts CHANGED
@@ -1688,31 +1688,33 @@ const importResource = (url: string): Promise<any> =>
1688
1688
  // fetch() against the document; a component in a subdirectory gets a 404 from
1689
1689
  // the first and the page's directory from the second.
1690
1690
  //
1691
- // Only `./` and `../` are resolved. A bare specifier ("lodash") belongs to the
1692
- // import map or the native resolver, and resolving it would quietly turn it
1693
- // into a path; anything already absolute means one thing under any base. That
1694
- // keeps this the browser's rule rather than a third one of our own.
1691
+ // What comes back is always a fully absolute URL, and that is the load-bearing
1692
+ // part rather than a detail of formatting. A *path* would be resolved by that
1693
+ // same native import() against the library module's ORIGIN - and the library
1694
+ // is the one file on the page most likely to come from somewhere else:
1695
+ //
1696
+ // page http://localhost:8024/craft/app.html
1697
+ // jq79 https://jgermade.github.io/jq79/jq79.js
1698
+ // "/craft/services/x.js" -> https://jgermade.github.io/craft/services/x.js
1699
+ //
1700
+ // which is a CORS error naming a host the app never mentioned. Only an
1701
+ // absolute URL means the same thing to both branches.
1702
+ //
1703
+ // For the same reason a *root-absolute* specifier is resolved too, not passed
1704
+ // through: `/x.js` means the page's root to whoever wrote it, and the page is
1705
+ // the only base under which the two branches agree. Bare specifiers ("lodash")
1706
+ // are the exception that stays untouched - they belong to the import map or
1707
+ // the bundler, and resolving one would quietly turn it into a path.
1695
1708
  //
1696
1709
  // The base is absolutized first, the way hotKey does and for the same reason:
1697
1710
  // the filename may itself be relative ("./card.html", from an import() in a
1698
- // parent), and a relative URL cannot be a base.
1699
- //
1700
- // What comes back is a path whenever it lands on the page's own origin, and a
1701
- // full URL only when it doesn't (a component served from a CDN resolves its
1702
- // siblings on that CDN). Both are the same request, but the path keeps the
1703
- // value the shape everything downstream already sees - what hotKey keys on,
1704
- // what devtools shows as the script's name - so only the cross-origin case,
1705
- // which has no path form, introduces a new one
1711
+ // parent), and a relative URL cannot be a base
1712
+ const RESOLVABLE_SPECIFIER_RE = /^(?:\.\.?\/|\/|[a-z][a-z0-9+.-]*:)/i
1713
+
1706
1714
  const resolveSpecifier = (spec: string, filename: string | undefined): string => {
1707
- if (!/^\.\.?\//.test(spec)) return spec
1715
+ if (!RESOLVABLE_SPECIFIER_RE.test(spec)) return spec
1708
1716
  try {
1709
- const page = new URL(document.baseURI)
1710
- const url = new URL(spec, new URL(filename ?? "", page))
1711
- // "null" is what an opaque origin (file:, blob:) reports, for both sides
1712
- // and for anything else - it says the origins are unknown, not equal
1713
- return url.origin !== "null" && url.origin === page.origin
1714
- ? `${url.pathname}${url.search}${url.hash}`
1715
- : url.href
1717
+ return new URL(spec, new URL(filename ?? "", document.baseURI)).href
1716
1718
  } catch {
1717
1719
  return spec
1718
1720
  }