@symbo.ls/utils 3.14.691 → 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 +6 -0
- package/dist/cjs/env.js +2 -2
- package/dist/esm/env.js +1 -1
- package/env.js +56 -0
- package/package.json +1 -1
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};
|
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};
|
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
|
+
}
|