@symbo.ls/utils 3.14.685 → 3.14.702
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/dist/cjs/env.js +2 -2
- package/dist/cjs/sharedLibraries.js +1 -1
- package/dist/esm/env.js +1 -1
- package/dist/esm/sharedLibraries.js +1 -1
- package/env.js +56 -0
- package/package.json +1 -1
- package/sharedLibraries.js +18 -11
package/CHANGELOG.md
CHANGED
package/dist/cjs/env.js
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
"use strict";var
|
|
2
|
-
const
|
|
1
|
+
"use strict";var c=Object.defineProperty;var u=Object.getOwnPropertyDescriptor;var a=Object.getOwnPropertyNames;var l=Object.prototype.hasOwnProperty;var d=(t,o)=>{for(var n in o)c(t,n,{get:o[n],enumerable:!0})},x=(t,o,n,i)=>{if(o&&typeof o=="object"||typeof o=="function")for(let s of a(o))!l.call(t,s)&&s!==n&&c(t,s,{get:()=>o[s],enumerable:!(i=u(o,s))||i.enumerable});return t};var f=t=>x(c({},"__esModule",{value:!0}),t);var y={};d(y,{ENV:()=>N,NODE_ENV:()=>e,getNev:()=>D,isDevelopment:()=>E,isLocal:()=>m,isLoudDevRuntime:()=>v,isNotProduction:()=>V,isProduction:()=>p,isStaging:()=>h,isTest:()=>r,isTesting:()=>g});module.exports=f(y);// @preserve-env
|
|
2
|
+
const e="production",N=e,p=(t=e)=>t==="production",r=(t=e)=>t==="testing"||t==="test",g=r,h=(t=e)=>t==="staging",m=(t=e)=>t==="local",E=(t=e)=>t==="development"||t==="dev"||t==="local",D=(t,o=e)=>o[t],V=(t=e)=>!p(t),v=t=>{const o=t&&"env"in t?t.env:typeof process<"u"&&process.env?"production":void 0;if(o&&o!=="production")return!0;const n=t&&"hostname"in t?t.hostname:typeof location<"u"?location.hostname:void 0;return typeof n=="string"&&n?n==="localhost"||n==="127.0.0.1"||n.endsWith(".localhost"):!1};
|
|
@@ -1 +1 @@
|
|
|
1
|
-
"use strict";var u=Object.defineProperty;var
|
|
1
|
+
"use strict";var u=Object.defineProperty;var A=Object.getOwnPropertyDescriptor;var R=Object.getOwnPropertyNames;var U=Object.prototype.hasOwnProperty;var j=(n,e)=>{for(var t in e)u(n,t,{get:e[t],enumerable:!0})},I=(n,e,t,r)=>{if(e&&typeof e=="object"||typeof e=="function")for(let i of R(e))!U.call(n,i)&&i!==t&&u(n,i,{get:()=>e[i],enumerable:!(r=A(e,i))||r.enumerable});return n};var S=n=>I(u({},"__esModule",{value:!0}),n);var K={};j(K,{deepDefaults:()=>f,fetchLibraryData:()=>k,isWrappedLibrary:()=>p,mergeSharedLibraries:()=>T,normalizeIgnoreList:()=>d,normalizeLibraryKey:()=>c,resolveSharedLibraries:()=>G,sharedLibrary:()=>P});module.exports=S(K);var s=require("./types.js");const h="system",E="https://smbls-kv.nika-980.workers.dev",_="https://api.symbols.app";function c(n){const e=String(n||"").trim();if(!e)return{owner:h,key:"",full:""};let t=null,r=e;if(e.includes("/")){const o=e.indexOf("/");t=e.slice(0,o),r=e.slice(o+1)}r=r.replace(/\.symbo\.ls$/iu,""),t||(t=h);const i=r?`${t}/${r}`:"";return{owner:t,key:r,full:i}}const f=(n,e,t,r)=>{for(const i in e){const o=r?`${r}/${i}`:i;t&&t.has(o)||(i in n?(0,s.isObject)(n[i])&&(0,s.isObject)(e[i])&&f(n[i],e[i],t,o):n[i]=e[i])}},O=new Set,B=n=>n.replace(/\.js$/iu,""),d=n=>{const e=new Set;if(!Array.isArray(n))return e;for(const t of n){if(!(0,s.isString)(t))continue;const r=t.split("/").map(i=>B(i.trim())).filter(Boolean).join("/");r&&e.add(r)}return e},P=(n,e={})=>({library:n,ignoreList:Array.isArray(e.ignoreList)?e.ignoreList:[]}),p=n=>(0,s.isObject)(n)&&Array.isArray(n.ignoreList)&&("library"in n||"key"in n||"name"in n),x=n=>n.library!==void 0?n.library:n.key??n.name,C=(n,e,t)=>{const r=d(e.sharedLibIgnore);e.sharePages===!1&&r.add("pages");const i=r.size?new Set([...t,...r]):t;for(const o in e)if(Object.prototype.hasOwnProperty.call(e,o)&&!(o==="sharePages"||o==="sharedLibIgnore")&&!i.has(o))if((0,s.isObject)(e[o])&&(0,s.isObject)(n[o]))if(o==="designSystem")f(n[o],e[o],i,o);else for(const a in e[o])i.has(`${o}/${a}`)||a in n[o]||(n[o][a]=e[o][a]);else o in n||(n[o]=e[o])},T=(n,e)=>{if(!(!e||!e.length))for(let t=0;t<e.length;t++){let r=e[t],i=O;p(r)&&(i=d(r.ignoreList),r=r.library),(0,s.isObject)(r)&&C(n,r,i)}};async function k(n,e={}){if((e.provider||"kv")==="api")return b(n,e);const r=await F(n,e);return r||b(n,e)}async function F(n,e={}){const t=e.kvBaseUrl||E,r=e.env||"production",i=`${t}/kv/${encodeURIComponent(n)}?env=${r}`;try{const o=await fetch(i,{method:"GET"});return o.ok&&(await o.json())?.value||null}catch{return null}}async function b(n,e={}){const t=e.apiBaseUrl||_,{key:r}=c(n);try{const i=`${t}/core/projects/libraries/available?search=${encodeURIComponent(r)}&limit=10`,o=await fetch(i,{method:"GET"});if(!o.ok)return null;const a=await o.json(),l=(a?.items||a?.data||(Array.isArray(a)?a:[])).find(g=>{const{key:$}=c(g?.key);return $.toLowerCase()===r.toLowerCase()});if(!l?.id&&!l?._id)return null;const L=l.id||l._id,v=`${t}/core/projects/${encodeURIComponent(L)}/data?branch=main`,y=await fetch(v,{method:"GET"});if(!y.ok)return null;const m=await y.json();return m?.data||m||null}catch{return null}}async function w(n,e={}){if((0,s.isObject)(n))return n;if((0,s.isString)(n)){const{full:t}=c(n);if(!t)return null;try{const r=await k(t,e);return r||console.warn(`[smbls] Shared library "${t}" not found`),r}catch(r){return console.warn(`[smbls] Failed to fetch shared library "${t}":`,r.message),null}}return null}async function G(n,e={}){return!n||!n.length?[]:(await Promise.all(n.map(async r=>{if(p(r)){const i=await w(x(r),e);return i?{library:i,ignoreList:r.ignoreList}:null}return w(r,e)}))).filter(Boolean)}
|
package/dist/esm/env.js
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
1
|
// @preserve-env
|
|
2
|
-
const o="production",
|
|
2
|
+
const o="production",i=o,s=(t=o)=>t==="production",c=(t=o)=>t==="testing"||t==="test",p=c,r=(t=o)=>t==="staging",u=(t=o)=>t==="local",a=(t=o)=>t==="development"||t==="dev"||t==="local",l=(t,e=o)=>e[t],d=(t=o)=>!s(t),x=t=>{const e=t&&"env"in t?t.env:typeof process<"u"&&process.env?"production":void 0;if(e&&e!=="production")return!0;const n=t&&"hostname"in t?t.hostname:typeof location<"u"?location.hostname:void 0;return typeof n=="string"&&n?n==="localhost"||n==="127.0.0.1"||n.endsWith(".localhost"):!1};export{i as ENV,o as NODE_ENV,l as getNev,a as isDevelopment,u as isLocal,x as isLoudDevRuntime,d as isNotProduction,s as isProduction,r as isStaging,c as isTest,p as isTesting};
|
|
@@ -1 +1 @@
|
|
|
1
|
-
import{isObject as
|
|
1
|
+
import{isObject as a,isString as d}from"./types.js";const p="system",$="https://smbls-kv.nika-980.workers.dev",A="https://api.symbols.app";function c(n){const e=String(n||"").trim();if(!e)return{owner:p,key:"",full:""};let t=null,r=e;if(e.includes("/")){const i=e.indexOf("/");t=e.slice(0,i),r=e.slice(i+1)}r=r.replace(/\.symbo\.ls$/iu,""),t||(t=p);const o=r?`${t}/${r}`:"";return{owner:t,key:r,full:o}}const y=(n,e,t,r)=>{for(const o in e){const i=r?`${r}/${o}`:o;t&&t.has(i)||(o in n?a(n[o])&&a(e[o])&&y(n[o],e[o],t,i):n[o]=e[o])}},R=new Set,U=n=>n.replace(/\.js$/iu,""),m=n=>{const e=new Set;if(!Array.isArray(n))return e;for(const t of n){if(!d(t))continue;const r=t.split("/").map(o=>U(o.trim())).filter(Boolean).join("/");r&&e.add(r)}return e},B=(n,e={})=>({library:n,ignoreList:Array.isArray(e.ignoreList)?e.ignoreList:[]}),h=n=>a(n)&&Array.isArray(n.ignoreList)&&("library"in n||"key"in n||"name"in n),j=n=>n.library!==void 0?n.library:n.key??n.name,I=(n,e,t)=>{const r=m(e.sharedLibIgnore);e.sharePages===!1&&r.add("pages");const o=r.size?new Set([...t,...r]):t;for(const i in e)if(Object.prototype.hasOwnProperty.call(e,i)&&!(i==="sharePages"||i==="sharedLibIgnore")&&!o.has(i))if(a(e[i])&&a(n[i]))if(i==="designSystem")y(n[i],e[i],o,i);else for(const s in e[i])o.has(`${i}/${s}`)||s in n[i]||(n[i][s]=e[i][s]);else i in n||(n[i]=e[i])},P=(n,e)=>{if(!(!e||!e.length))for(let t=0;t<e.length;t++){let r=e[t],o=R;h(r)&&(o=m(r.ignoreList),r=r.library),a(r)&&I(n,r,o)}};async function S(n,e={}){if((e.provider||"kv")==="api")return b(n,e);const r=await E(n,e);return r||b(n,e)}async function E(n,e={}){const t=e.kvBaseUrl||$,r=e.env||"production",o=`${t}/kv/${encodeURIComponent(n)}?env=${r}`;try{const i=await fetch(o,{method:"GET"});return i.ok&&(await i.json())?.value||null}catch{return null}}async function b(n,e={}){const t=e.apiBaseUrl||A,{key:r}=c(n);try{const o=`${t}/core/projects/libraries/available?search=${encodeURIComponent(r)}&limit=10`,i=await fetch(o,{method:"GET"});if(!i.ok)return null;const s=await i.json(),l=(s?.items||s?.data||(Array.isArray(s)?s:[])).find(v=>{const{key:g}=c(v?.key);return g.toLowerCase()===r.toLowerCase()});if(!l?.id&&!l?._id)return null;const k=l.id||l._id,L=`${t}/core/projects/${encodeURIComponent(k)}/data?branch=main`,u=await fetch(L,{method:"GET"});if(!u.ok)return null;const f=await u.json();return f?.data||f||null}catch{return null}}async function w(n,e={}){if(a(n))return n;if(d(n)){const{full:t}=c(n);if(!t)return null;try{const r=await S(t,e);return r||console.warn(`[smbls] Shared library "${t}" not found`),r}catch(r){return console.warn(`[smbls] Failed to fetch shared library "${t}":`,r.message),null}}return null}async function x(n,e={}){return!n||!n.length?[]:(await Promise.all(n.map(async r=>{if(h(r)){const o=await w(j(r),e);return o?{library:o,ignoreList:r.ignoreList}:null}return w(r,e)}))).filter(Boolean)}export{y as deepDefaults,S as fetchLibraryData,h as isWrappedLibrary,P as mergeSharedLibraries,m as normalizeIgnoreList,c as normalizeLibraryKey,x as resolveSharedLibraries,B as sharedLibrary};
|
package/env.js
CHANGED
|
@@ -13,3 +13,59 @@ export const isDevelopment = (env = NODE_ENV) =>
|
|
|
13
13
|
env === 'development' || env === 'dev' || env === 'local'
|
|
14
14
|
export const getNev = (key, env = NODE_ENV) => env[key]
|
|
15
15
|
export const isNotProduction = (env = NODE_ENV) => !isProduction(env)
|
|
16
|
+
|
|
17
|
+
/**
|
|
18
|
+
* FRAMEWORK-6: shared gate for dev-only loud-failure diagnostics, usable by
|
|
19
|
+
* any package (originally lived only in `@symbo.ls/element/src/devRuntime.js`
|
|
20
|
+
* — moved here so `@symbo.ls/scratch`, which `element` itself depends on,
|
|
21
|
+
* can gate its own loud-dev warnings without a reverse dependency).
|
|
22
|
+
*
|
|
23
|
+
* Why a hybrid gate instead of `process.env.NODE_ENV !== 'production'` alone:
|
|
24
|
+
* the dist build (`esbuild --minify`, default platform=browser) auto-defines
|
|
25
|
+
* `process.env.NODE_ENV` to `"production"` and dead-code-eliminates any
|
|
26
|
+
* branch gated on it — verified against `dist/esm/src/create.js`, where a
|
|
27
|
+
* NODE_ENV-only-gated warning was compiled out entirely. Consumers resolve
|
|
28
|
+
* `dist/esm`, not `src` (see the workspace bundle), so a NODE_ENV-only gate
|
|
29
|
+
* can never fire in a real dev browser session.
|
|
30
|
+
*
|
|
31
|
+
* Why not hostname alone: node/test consumers (vitest, SSR) resolve source,
|
|
32
|
+
* where NODE_ENV is live and `location` may not exist.
|
|
33
|
+
*
|
|
34
|
+
* So:
|
|
35
|
+
* - build-time leg — `process.env.NODE_ENV` — live for source/test
|
|
36
|
+
* consumers; folds to `false` at dist build time (esbuild substitutes the
|
|
37
|
+
* literal, leaving the guarded `process` reference unreachable).
|
|
38
|
+
* - runtime leg — `location.hostname` is `localhost`, `127.0.0.1`, or any
|
|
39
|
+
* `*.localhost` — survives the dist build, so dev servers
|
|
40
|
+
* (`workspace.localhost:1355` etc.) still get loud failures.
|
|
41
|
+
*
|
|
42
|
+
* A visitor on a production domain (`my.symbols.app`, `*.symbo.ls`, custom
|
|
43
|
+
* domains) matches neither leg and never sees console noise from this.
|
|
44
|
+
*
|
|
45
|
+
* @param {object} [overrides] test-only injection: `{ env, hostname }`
|
|
46
|
+
* @returns {boolean}
|
|
47
|
+
*/
|
|
48
|
+
export const isLoudDevRuntime = (overrides) => {
|
|
49
|
+
const env =
|
|
50
|
+
overrides && 'env' in overrides
|
|
51
|
+
? overrides.env
|
|
52
|
+
: typeof process !== 'undefined' && process.env
|
|
53
|
+
? process.env.NODE_ENV
|
|
54
|
+
: undefined
|
|
55
|
+
if (env && env !== 'production') return true
|
|
56
|
+
|
|
57
|
+
const hostname =
|
|
58
|
+
overrides && 'hostname' in overrides
|
|
59
|
+
? overrides.hostname
|
|
60
|
+
: typeof location !== 'undefined'
|
|
61
|
+
? location.hostname
|
|
62
|
+
: undefined
|
|
63
|
+
if (typeof hostname === 'string' && hostname) {
|
|
64
|
+
return (
|
|
65
|
+
hostname === 'localhost' ||
|
|
66
|
+
hostname === '127.0.0.1' ||
|
|
67
|
+
hostname.endsWith('.localhost')
|
|
68
|
+
)
|
|
69
|
+
}
|
|
70
|
+
return false
|
|
71
|
+
}
|
package/package.json
CHANGED
package/sharedLibraries.js
CHANGED
|
@@ -123,23 +123,30 @@ const wrappedLibraryRef = (entry) =>
|
|
|
123
123
|
entry.library !== undefined ? entry.library : (entry.key ?? entry.name)
|
|
124
124
|
|
|
125
125
|
const mergeOneLibrary = (context, sharedLib, ignore) => {
|
|
126
|
-
// A library can declare
|
|
127
|
-
// context
|
|
128
|
-
//
|
|
129
|
-
// own doc site (e.g. system/brand
|
|
130
|
-
//
|
|
131
|
-
|
|
126
|
+
// A library can declare parts of itself private via `sharedLibIgnore` on
|
|
127
|
+
// its own context — same path grammar as the consumer-side `ignoreList`
|
|
128
|
+
// (top-level keys or nested 'components/Header'). A library serving its
|
|
129
|
+
// own doc site (e.g. system/brand with `sharedLibIgnore: ['pages']`)
|
|
130
|
+
// must be able to keep its routes out of every consumer; without it,
|
|
131
|
+
// library pages auto-mount into any consumer that doesn't define the same
|
|
132
|
+
// route key. `sharePages: false` is the earlier, narrower alias — kept
|
|
133
|
+
// working, superseded by sharedLibIgnore.
|
|
134
|
+
const libIgnore = normalizeIgnoreList(sharedLib.sharedLibIgnore)
|
|
135
|
+
if (sharedLib.sharePages === false) libIgnore.add('pages')
|
|
136
|
+
const skip = libIgnore.size
|
|
137
|
+
? new Set([...ignore, ...libIgnore])
|
|
138
|
+
: ignore
|
|
132
139
|
for (const key in sharedLib) {
|
|
133
140
|
if (!Object.prototype.hasOwnProperty.call(sharedLib, key)) continue
|
|
134
|
-
|
|
135
|
-
if (key === '
|
|
136
|
-
if (
|
|
141
|
+
// merge directives, not library content
|
|
142
|
+
if (key === 'sharePages' || key === 'sharedLibIgnore') continue
|
|
143
|
+
if (skip.has(key)) continue // top-level skip: 'designSystem', 'app', 'state'
|
|
137
144
|
if (isObject(sharedLib[key]) && isObject(context[key])) {
|
|
138
145
|
if (key === 'designSystem') {
|
|
139
|
-
deepDefaults(context[key], sharedLib[key],
|
|
146
|
+
deepDefaults(context[key], sharedLib[key], skip, key)
|
|
140
147
|
} else {
|
|
141
148
|
for (const k in sharedLib[key]) {
|
|
142
|
-
if (
|
|
149
|
+
if (skip.has(`${key}/${k}`)) continue // nested skip: 'components/Header'
|
|
143
150
|
if (!(k in context[key])) context[key][k] = sharedLib[key][k]
|
|
144
151
|
}
|
|
145
152
|
}
|