@symbo.ls/utils 3.14.702 → 3.14.735
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 +12 -0
- package/cdn.js +33 -12
- package/dist/cjs/cdn.js +3 -3
- package/dist/cjs/sharedLibraries.js +1 -1
- package/dist/esm/cdn.js +3 -3
- package/dist/esm/sharedLibraries.js +1 -1
- package/package.json +1 -1
- package/sharedLibraries.js +44 -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}`};
|
|
@@ -1 +1 @@
|
|
|
1
|
-
"use strict";var u=Object.defineProperty;var
|
|
1
|
+
"use strict";var u=Object.defineProperty;var j=Object.getOwnPropertyDescriptor;var R=Object.getOwnPropertyNames;var U=Object.prototype.hasOwnProperty;var S=(n,t)=>{for(var e in t)u(n,e,{get:t[e],enumerable:!0})},E=(n,t,e,r)=>{if(t&&typeof t=="object"||typeof t=="function")for(let o of R(t))!U.call(n,o)&&o!==e&&u(n,o,{get:()=>t[o],enumerable:!(r=j(t,o))||r.enumerable});return n};var O=n=>E(u({},"__esModule",{value:!0}),n);var N={};S(N,{deepDefaults:()=>d,fetchLibraryData:()=>k,isWrappedLibrary:()=>y,mergeSharedLibraries:()=>F,normalizeIgnoreList:()=>p,normalizeLibraryKey:()=>l,resolveSharedLibraries:()=>K,sharedLibrary:()=>C});module.exports=O(N);var a=require("./types.js");const b="system",_="https://smbls-kv.nika-980.workers.dev",P="https://api.symbols.app";function l(n){const t=String(n||"").trim();if(!t)return{owner:b,key:"",full:""};let e=null,r=t;if(t.includes("/")){const s=t.indexOf("/");e=t.slice(0,s),r=t.slice(s+1)}r=r.replace(/\.symbo\.ls$/iu,""),e||(e=b);const o=r?`${e}/${r}`:"";return{owner:e,key:r,full:o}}const d=(n,t,e,r)=>{for(const o in t){const s=r?`${r}/${o}`:o;e&&e.has(s)||(o in n?(0,a.isObject)(n[o])&&(0,a.isObject)(t[o])&&d(n[o],t[o],e,s):n[o]=t[o])}},w=(n,t,e)=>{if(!(0,a.isObject)(n)||!t.size)return n;const r=`${e}/`;let o=!1;for(const i of t)if(i.startsWith(r)){o=!0;break}if(!o)return n;const s={};for(const i in n){if(!Object.prototype.hasOwnProperty.call(n,i))continue;const f=`${e}/${i}`;t.has(f)||(s[i]=w(n[i],t,f))}return s},B=new Set,x=n=>n.replace(/\.js$/iu,""),p=n=>{const t=new Set;if(!Array.isArray(n))return t;for(const e of n){if(!(0,a.isString)(e))continue;const r=e.split("/").map(o=>x(o.trim())).filter(Boolean).join("/");r&&t.add(r)}return t},C=(n,t={})=>({library:n,ignoreList:Array.isArray(t.ignoreList)?t.ignoreList:[]}),y=n=>(0,a.isObject)(n)&&Array.isArray(n.ignoreList)&&("library"in n||"key"in n||"name"in n),T=n=>n.library!==void 0?n.library:n.key??n.name,z=(n,t,e)=>{const r=p(t.sharedLibIgnore);t.sharePages===!1&&r.add("pages");const o=r.size?new Set([...e,...r]):e;for(const s in t)if(Object.prototype.hasOwnProperty.call(t,s)&&!(s==="sharePages"||s==="sharedLibIgnore")&&!o.has(s))if((0,a.isObject)(t[s])&&(0,a.isObject)(n[s]))if(s==="designSystem")d(n[s],t[s],o,s);else for(const i in t[s])o.has(`${s}/${i}`)||i in n[s]||(n[s][i]=t[s][i]);else s in n||(n[s]=w(t[s],o,s))},F=(n,t)=>{if(!(!t||!t.length))for(let e=0;e<t.length;e++){let r=t[e],o=B;y(r)&&(o=p(r.ignoreList),r=r.library),(0,a.isObject)(r)&&z(n,r,o)}};async function k(n,t={}){if((t.provider||"kv")==="api")return $(n,t);const r=await G(n,t);return r||$(n,t)}async function G(n,t={}){const e=t.kvBaseUrl||_,r=t.env||"production",o=`${e}/kv/${encodeURIComponent(n)}?env=${r}`;try{const s=await fetch(o,{method:"GET"});return s.ok&&(await s.json())?.value||null}catch{return null}}async function $(n,t={}){const e=t.apiBaseUrl||P,{key:r}=l(n);try{const o=`${e}/core/projects/libraries/available?search=${encodeURIComponent(r)}&limit=10`,s=await fetch(o,{method:"GET"});if(!s.ok)return null;const i=await s.json(),c=(i?.items||i?.data||(Array.isArray(i)?i:[])).find(v=>{const{key:I}=l(v?.key);return I.toLowerCase()===r.toLowerCase()});if(!c?.id&&!c?._id)return null;const L=c.id||c._id,A=`${e}/core/projects/${encodeURIComponent(L)}/data?branch=main`,h=await fetch(A,{method:"GET"});if(!h.ok)return null;const m=await h.json();return m?.data||m||null}catch{return null}}async function g(n,t={}){if((0,a.isObject)(n))return n;if((0,a.isString)(n)){const{full:e}=l(n);if(!e)return null;try{const r=await k(e,t);return r||console.warn(`[smbls] Shared library "${e}" not found`),r}catch(r){return console.warn(`[smbls] Failed to fetch shared library "${e}":`,r.message),null}}return null}async function K(n,t={}){return!n||!n.length?[]:(await Promise.all(n.map(async r=>{if(y(r)){const o=await g(T(r),t);return o?{library:o,ignoreList:r.ignoreList}:null}return g(r,t)}))).filter(Boolean)}
|
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};
|
|
@@ -1 +1 @@
|
|
|
1
|
-
import{isObject as a,isString as
|
|
1
|
+
import{isObject as a,isString as p}from"./types.js";const y="system",I="https://smbls-kv.nika-980.workers.dev",j="https://api.symbols.app";function f(n){const t=String(n||"").trim();if(!t)return{owner:y,key:"",full:""};let e=null,r=t;if(t.includes("/")){const o=t.indexOf("/");e=t.slice(0,o),r=t.slice(o+1)}r=r.replace(/\.symbo\.ls$/iu,""),e||(e=y);const s=r?`${e}/${r}`:"";return{owner:e,key:r,full:s}}const h=(n,t,e,r)=>{for(const s in t){const o=r?`${r}/${s}`:s;e&&e.has(o)||(s in n?a(n[s])&&a(t[s])&&h(n[s],t[s],e,o):n[s]=t[s])}},m=(n,t,e)=>{if(!a(n)||!t.size)return n;const r=`${e}/`;let s=!1;for(const i of t)if(i.startsWith(r)){s=!0;break}if(!s)return n;const o={};for(const i in n){if(!Object.prototype.hasOwnProperty.call(n,i))continue;const l=`${e}/${i}`;t.has(l)||(o[i]=m(n[i],t,l))}return o},R=new Set,U=n=>n.replace(/\.js$/iu,""),b=n=>{const t=new Set;if(!Array.isArray(n))return t;for(const e of n){if(!p(e))continue;const r=e.split("/").map(s=>U(s.trim())).filter(Boolean).join("/");r&&t.add(r)}return t},B=(n,t={})=>({library:n,ignoreList:Array.isArray(t.ignoreList)?t.ignoreList:[]}),w=n=>a(n)&&Array.isArray(n.ignoreList)&&("library"in n||"key"in n||"name"in n),S=n=>n.library!==void 0?n.library:n.key??n.name,E=(n,t,e)=>{const r=b(t.sharedLibIgnore);t.sharePages===!1&&r.add("pages");const s=r.size?new Set([...e,...r]):e;for(const o in t)if(Object.prototype.hasOwnProperty.call(t,o)&&!(o==="sharePages"||o==="sharedLibIgnore")&&!s.has(o))if(a(t[o])&&a(n[o]))if(o==="designSystem")h(n[o],t[o],s,o);else for(const i in t[o])s.has(`${o}/${i}`)||i in n[o]||(n[o][i]=t[o][i]);else o in n||(n[o]=m(t[o],s,o))},x=(n,t)=>{if(!(!t||!t.length))for(let e=0;e<t.length;e++){let r=t[e],s=R;w(r)&&(s=b(r.ignoreList),r=r.library),a(r)&&E(n,r,s)}};async function O(n,t={}){if((t.provider||"kv")==="api")return $(n,t);const r=await _(n,t);return r||$(n,t)}async function _(n,t={}){const e=t.kvBaseUrl||I,r=t.env||"production",s=`${e}/kv/${encodeURIComponent(n)}?env=${r}`;try{const o=await fetch(s,{method:"GET"});return o.ok&&(await o.json())?.value||null}catch{return null}}async function $(n,t={}){const e=t.apiBaseUrl||j,{key:r}=f(n);try{const s=`${e}/core/projects/libraries/available?search=${encodeURIComponent(r)}&limit=10`,o=await fetch(s,{method:"GET"});if(!o.ok)return null;const i=await o.json(),c=(i?.items||i?.data||(Array.isArray(i)?i:[])).find(A=>{const{key:v}=f(A?.key);return v.toLowerCase()===r.toLowerCase()});if(!c?.id&&!c?._id)return null;const k=c.id||c._id,L=`${e}/core/projects/${encodeURIComponent(k)}/data?branch=main`,u=await fetch(L,{method:"GET"});if(!u.ok)return null;const d=await u.json();return d?.data||d||null}catch{return null}}async function g(n,t={}){if(a(n))return n;if(p(n)){const{full:e}=f(n);if(!e)return null;try{const r=await O(e,t);return r||console.warn(`[smbls] Shared library "${e}" not found`),r}catch(r){return console.warn(`[smbls] Failed to fetch shared library "${e}":`,r.message),null}}return null}async function C(n,t={}){return!n||!n.length?[]:(await Promise.all(n.map(async r=>{if(w(r)){const s=await g(S(r),t);return s?{library:s,ignoreList:r.ignoreList}:null}return g(r,t)}))).filter(Boolean)}export{h as deepDefaults,O as fetchLibraryData,w as isWrappedLibrary,x as mergeSharedLibraries,b as normalizeIgnoreList,f as normalizeLibraryKey,C as resolveSharedLibraries,B as sharedLibrary};
|
package/package.json
CHANGED
package/sharedLibraries.js
CHANGED
|
@@ -60,6 +60,49 @@ export const deepDefaults = (target, source, ignore, prefix) => {
|
|
|
60
60
|
}
|
|
61
61
|
}
|
|
62
62
|
|
|
63
|
+
/**
|
|
64
|
+
* Recursively drop any subtree of `value` whose '/'-joined path (relative to
|
|
65
|
+
* `prefix`) is in `skip`. Used by `mergeOneLibrary`'s wholesale-copy branch:
|
|
66
|
+
* when the consumer has NO object at all at a top-level key, the whole
|
|
67
|
+
* section is copied in one shot — a nested `sharedLibIgnore` path declared
|
|
68
|
+
* under that key (e.g. 'functions/router') must be honored there too, not
|
|
69
|
+
* only in the per-key defaults-fill branch below. Recurses to whatever depth
|
|
70
|
+
* the ignore path names — `normalizeIgnoreList` has no depth cap, so a
|
|
71
|
+
* library author's declaration stays private regardless of which merge
|
|
72
|
+
* branch a given consumer happens to hit.
|
|
73
|
+
*
|
|
74
|
+
* Returns `value` unchanged (same reference) whenever nothing under `prefix`
|
|
75
|
+
* is ignored — the common case — so this never allocates when there is
|
|
76
|
+
* nothing to filter.
|
|
77
|
+
*
|
|
78
|
+
* @param {*} value - the subtree being wholesale-copied
|
|
79
|
+
* @param {Set<string>} skip - normalized '/'-joined ignore paths (whole-key
|
|
80
|
+
* entries already short-circuited by the caller before this runs)
|
|
81
|
+
* @param {string} prefix - the top-level key this subtree lives under
|
|
82
|
+
*/
|
|
83
|
+
const copyWithNestedIgnores = (value, skip, prefix) => {
|
|
84
|
+
if (!isObject(value) || !skip.size) return value
|
|
85
|
+
|
|
86
|
+
const branchPrefix = `${prefix}/`
|
|
87
|
+
let hasNestedIgnore = false
|
|
88
|
+
for (const path of skip) {
|
|
89
|
+
if (path.startsWith(branchPrefix)) {
|
|
90
|
+
hasNestedIgnore = true
|
|
91
|
+
break
|
|
92
|
+
}
|
|
93
|
+
}
|
|
94
|
+
if (!hasNestedIgnore) return value
|
|
95
|
+
|
|
96
|
+
const copy = {}
|
|
97
|
+
for (const k in value) {
|
|
98
|
+
if (!Object.prototype.hasOwnProperty.call(value, k)) continue
|
|
99
|
+
const path = `${prefix}/${k}`
|
|
100
|
+
if (skip.has(path)) continue
|
|
101
|
+
copy[k] = copyWithNestedIgnores(value[k], skip, path)
|
|
102
|
+
}
|
|
103
|
+
return copy
|
|
104
|
+
}
|
|
105
|
+
|
|
63
106
|
const EMPTY_IGNORE = new Set()
|
|
64
107
|
|
|
65
108
|
const stripJsExt = (segment) => segment.replace(/\.js$/iu, '')
|
|
@@ -151,7 +194,7 @@ const mergeOneLibrary = (context, sharedLib, ignore) => {
|
|
|
151
194
|
}
|
|
152
195
|
}
|
|
153
196
|
} else if (!(key in context)) {
|
|
154
|
-
context[key] = sharedLib[key]
|
|
197
|
+
context[key] = copyWithNestedIgnores(sharedLib[key], skip, key)
|
|
155
198
|
}
|
|
156
199
|
}
|
|
157
200
|
}
|