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/dist/jq79.cjs +10 -10
- package/dist/jq79.cjs.map +1 -1
- package/dist/jq79.global.js +10 -10
- package/dist/jq79.global.js.map +1 -1
- package/dist/jq79.js +10 -10
- package/dist/jq79.js.map +1 -1
- package/package.json +1 -1
- package/src/jq79.ts +22 -20
package/package.json
CHANGED
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
|
-
//
|
|
1692
|
-
//
|
|
1693
|
-
//
|
|
1694
|
-
//
|
|
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
|
-
|
|
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 (
|
|
1715
|
+
if (!RESOLVABLE_SPECIFIER_RE.test(spec)) return spec
|
|
1708
1716
|
try {
|
|
1709
|
-
|
|
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
|
}
|