@symbo.ls/utils 3.14.702 → 3.14.707
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/CHANGELOG.md +6 -0
- package/cdn.js +33 -12
- package/dist/cjs/cdn.js +3 -3
- package/dist/esm/cdn.js +3 -3
- package/package.json +1 -1
package/CHANGELOG.md
CHANGED
package/cdn.js
CHANGED
|
@@ -1,9 +1,5 @@
|
|
|
1
1
|
'use strict'
|
|
2
2
|
|
|
3
|
-
function onlyDotsAndNumbers (str) {
|
|
4
|
-
return /^[0-9.]+$/.test(str) && str !== ''
|
|
5
|
-
}
|
|
6
|
-
|
|
7
3
|
export const CDN_PROVIDERS = {
|
|
8
4
|
skypack: {
|
|
9
5
|
url: 'https://cdn.skypack.dev',
|
|
@@ -25,14 +21,25 @@ export const CDN_PROVIDERS = {
|
|
|
25
21
|
formatUrl: (pkg, version) =>
|
|
26
22
|
`${CDN_PROVIDERS.jsdelivr.url}/${pkg}${version !== 'latest' ? `@${version}` : ''}/+esm`
|
|
27
23
|
},
|
|
24
|
+
// pkg.symbo.ls — our own proxy (server/workers/packages). It is a raw file
|
|
25
|
+
// PASSTHROUGH (GCS bucket → jsDelivr → unpkg), not a CJS→ESM transformer,
|
|
26
|
+
// so the artifact you get is entirely decided by the path you ask for:
|
|
27
|
+
//
|
|
28
|
+
// /smbls@3.14.706 → jsDelivr's default file = dist/smbls.iife.js
|
|
29
|
+
// /smbls@3.14.706/+esm → jsDelivr's ESM build ✅ importable
|
|
30
|
+
//
|
|
31
|
+
// This provider previously emitted the bare/`/<version>.js` forms, both of
|
|
32
|
+
// which resolve to the IIFE — `var Smbls=(()=>{…})()`, a script with zero
|
|
33
|
+
// exports. Any `import … from 'smbls'` against an importmap built that way
|
|
34
|
+
// fails at link time, and `smbls init --runtime browser` scaffolds shipped
|
|
35
|
+
// exactly that. `/+esm` is jsDelivr's on-the-fly ESM transform and works
|
|
36
|
+
// for CJS-only third-party packages too (js-beautify, prismjs, lottie-web
|
|
37
|
+
// all verified), which is what makes this a complete esm.sh replacement on
|
|
38
|
+
// a domain we control rather than a smbls-only special case.
|
|
28
39
|
symbols: {
|
|
29
40
|
url: 'https://pkg.symbo.ls',
|
|
30
|
-
formatUrl: (pkg, version) =>
|
|
31
|
-
|
|
32
|
-
return `${CDN_PROVIDERS.symbols.url}/${pkg}`
|
|
33
|
-
}
|
|
34
|
-
return `${CDN_PROVIDERS.symbols.url}/${pkg}/${version}.js`
|
|
35
|
-
}
|
|
41
|
+
formatUrl: (pkg, version) =>
|
|
42
|
+
`${CDN_PROVIDERS.symbols.url}/${pkg}${version !== 'latest' ? `@${version}` : ''}/+esm`
|
|
36
43
|
}
|
|
37
44
|
}
|
|
38
45
|
|
|
@@ -77,15 +84,29 @@ export const getCDNUrl = (
|
|
|
77
84
|
* bundle onto the page as raw HTML (tickets/smbls.md — the ~355KB "fake
|
|
78
85
|
* importmap" bug). Splitting the tag here means neither the source nor any
|
|
79
86
|
* minified/bundled copy of it ever carries that literal substring.
|
|
87
|
+
*
|
|
88
|
+
* `options.pin` — `{ [pkgName]: version }` — overrides the version declared in
|
|
89
|
+
* the project's dependencies. A host that INJECTS a runtime into the page must
|
|
90
|
+
* pin the matching importmap entry to the version it injected, or the page
|
|
91
|
+
* carries two different copies of the same package: one inlined, one resolved
|
|
92
|
+
* from whatever the registry's floating tag points at that hour. Deployed
|
|
93
|
+
* *.at.symbo.ls pages shipped `"smbls": "latest"` against an inlined IIFE from
|
|
94
|
+
* a months-old pin, and the client half moved 683 → 704 in a single evening
|
|
95
|
+
* under already-published sites (tickets/smbls.md).
|
|
80
96
|
*/
|
|
81
|
-
export const getImportMapScript = (
|
|
97
|
+
export const getImportMapScript = (
|
|
98
|
+
data,
|
|
99
|
+
defaultProvider = 'skypack',
|
|
100
|
+
options = {}
|
|
101
|
+
) => {
|
|
82
102
|
const dependencies = data.dependencies || {}
|
|
83
103
|
const keys = Object.keys(dependencies)
|
|
84
104
|
if (!keys.length) return ''
|
|
85
105
|
|
|
106
|
+
const pin = options.pin || {}
|
|
86
107
|
const imports = {}
|
|
87
108
|
for (const pkgName of keys) {
|
|
88
|
-
const version = dependencies[pkgName] || 'latest'
|
|
109
|
+
const version = pin[pkgName] || dependencies[pkgName] || 'latest'
|
|
89
110
|
imports[pkgName] = getCDNUrl(pkgName, version, defaultProvider)
|
|
90
111
|
}
|
|
91
112
|
|
package/dist/cjs/cdn.js
CHANGED
|
@@ -1,3 +1,3 @@
|
|
|
1
|
-
"use strict";var p=Object.defineProperty;var
|
|
2
|
-
"imports": ${JSON.stringify(
|
|
3
|
-
}`;return`${
|
|
1
|
+
"use strict";var p=Object.defineProperty;var d=Object.getOwnPropertyDescriptor;var y=Object.getOwnPropertyNames;var f=Object.prototype.hasOwnProperty;var h=(t,s)=>{for(var e in s)p(t,e,{get:s[e],enumerable:!0})},C=(t,s,e,n)=>{if(s&&typeof s=="object"||typeof s=="function")for(let r of y(s))!f.call(t,r)&&r!==e&&p(t,r,{get:()=>s[r],enumerable:!(n=d(s,r))||n.enumerable});return t};var b=t=>C(p({},"__esModule",{value:!0}),t);var N={};h(N,{CDN_PROVIDERS:()=>o,PACKAGE_MANAGER_TO_CDN:()=>m,getCDNUrl:()=>a,getCdnProviderFromConfig:()=>U,getImportMapScript:()=>j});module.exports=b(N);const o={skypack:{url:"https://cdn.skypack.dev",formatUrl:(t,s)=>`${o.skypack.url}/${t}${s!=="latest"?`@${s}`:""}`},esmsh:{url:"https://esm.sh",formatUrl:(t,s)=>`${o.esmsh.url}/${t}${s!=="latest"?`@${s}`:""}`},unpkg:{url:"https://unpkg.com",formatUrl:(t,s)=>`${o.unpkg.url}/${t}${s!=="latest"?`@${s}`:""}?module`},jsdelivr:{url:"https://cdn.jsdelivr.net/npm",formatUrl:(t,s)=>`${o.jsdelivr.url}/${t}${s!=="latest"?`@${s}`:""}/+esm`},symbols:{url:"https://pkg.symbo.ls",formatUrl:(t,s)=>`${o.symbols.url}/${t}${s!=="latest"?`@${s}`:""}/+esm`}},m={"esm.sh":"esmsh",unpkg:"unpkg",skypack:"skypack",jsdelivr:"jsdelivr","pkg.symbo.ls":"symbols"},U=(t={})=>{const{packageManager:s}=t;return m[s]||null},a=(t,s="latest",e="esmsh")=>(o[e]||o.esmsh).formatUrl(t,s),j=(t,s="skypack",e={})=>{const n=t.dependencies||{},r=Object.keys(n);if(!r.length)return"";const $=e.pin||{},c={};for(const l of r){const i=$[l]||n[l]||"latest";c[l]=a(l,i,s)}const k='<script type="importmap">',u="<\/script>",g=`{
|
|
2
|
+
"imports": ${JSON.stringify(c,null,2)}
|
|
3
|
+
}`;return`${k}${g}${u}`};
|
package/dist/esm/cdn.js
CHANGED
|
@@ -1,3 +1,3 @@
|
|
|
1
|
-
|
|
2
|
-
"imports": ${JSON.stringify(
|
|
3
|
-
}`;return`${
|
|
1
|
+
const e={skypack:{url:"https://cdn.skypack.dev",formatUrl:(t,s)=>`${e.skypack.url}/${t}${s!=="latest"?`@${s}`:""}`},esmsh:{url:"https://esm.sh",formatUrl:(t,s)=>`${e.esmsh.url}/${t}${s!=="latest"?`@${s}`:""}`},unpkg:{url:"https://unpkg.com",formatUrl:(t,s)=>`${e.unpkg.url}/${t}${s!=="latest"?`@${s}`:""}?module`},jsdelivr:{url:"https://cdn.jsdelivr.net/npm",formatUrl:(t,s)=>`${e.jsdelivr.url}/${t}${s!=="latest"?`@${s}`:""}/+esm`},symbols:{url:"https://pkg.symbo.ls",formatUrl:(t,s)=>`${e.symbols.url}/${t}${s!=="latest"?`@${s}`:""}/+esm`}},u={"esm.sh":"esmsh",unpkg:"unpkg",skypack:"skypack",jsdelivr:"jsdelivr","pkg.symbo.ls":"symbols"},i=(t={})=>{const{packageManager:s}=t;return u[s]||null},g=(t,s="latest",o="esmsh")=>(e[o]||e.esmsh).formatUrl(t,s),d=(t,s="skypack",o={})=>{const n=t.dependencies||{},l=Object.keys(n);if(!l.length)return"";const c=o.pin||{},p={};for(const r of l){const k=c[r]||n[r]||"latest";p[r]=g(r,k,s)}const m='<script type="importmap">',a="<\/script>",$=`{
|
|
2
|
+
"imports": ${JSON.stringify(p,null,2)}
|
|
3
|
+
}`;return`${m}${$}${a}`};export{e as CDN_PROVIDERS,u as PACKAGE_MANAGER_TO_CDN,g as getCDNUrl,i as getCdnProviderFromConfig,d as getImportMapScript};
|