tungsten 0.2.20 → 0.2.21

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.
@@ -1 +1 @@
1
- {"version":3,"file":"cjsHelpers.d.ts","sourceRoot":"","sources":["../../src/_client/cjsHelpers.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,MAAM,EAAa,MAAM,gBAAgB,CAAA;AAkCvD,OAAO,CAAC,MAAM,CAAC;IACX,UAAU,MAAM;QACZ,qBAAqB,EAAE,CAAC,QAAQ,EAAE,MAAM,KAAK,OAAO,CAAC;YAAE,CAAC,GAAG,EAAE,MAAM,GAAG,GAAG,CAAA;SAAE,CAAC,CAAA;KAC/E;CACJ;AA6BD,wBAAsB,QAAQ,CAAC,IAAI,EAAE,MAAM,EAAE,mCAuC5C"}
1
+ {"version":3,"file":"cjsHelpers.d.ts","sourceRoot":"","sources":["../../src/_client/cjsHelpers.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,MAAM,EAAa,MAAM,gBAAgB,CAAA;AAqCvD,OAAO,CAAC,MAAM,CAAC;IACX,UAAU,MAAM;QACZ,qBAAqB,EAAE,CAAC,QAAQ,EAAE,MAAM,KAAK,OAAO,CAAC;YAAE,CAAC,GAAG,EAAE,MAAM,GAAG,GAAG,CAAA;SAAE,CAAC,CAAA;KAC/E;CACJ;AA6BD,wBAAsB,QAAQ,CAAC,IAAI,EAAE,MAAM,EAAE,mCAuC5C"}
@@ -3,8 +3,11 @@ function _toPropertyKey(t) { var i = _toPrimitive(t, "string"); return "symbol"
3
3
  function _toPrimitive(t, r) { if ("object" != typeof t || !t) return t; var e = t[Symbol.toPrimitive]; if (void 0 !== e) { var i = e.call(t, r || "default"); if ("object" != typeof i) return i; throw new TypeError("@@toPrimitive must return a primitive value."); } return ("string" === r ? String : Number)(t); }
4
4
  // CommonJS browser packages commonly branch on process.env.NODE_ENV.
5
5
  // Provide the minimal Node-compatible shape before any converted module runs.
6
+ // __tungstenCjsShim marks this as our shim and not a real node process, so that code
7
+ // testing for node (isDev.ts) is not fooled by it. See the Process augmentation in isDev.ts.
6
8
  const browserGlobal = globalThis;
7
9
  browserGlobal.process = {
10
+ __tungstenCjsShim: true,
8
11
  env: {
9
12
  NODE_ENV: 'development'
10
13
  },
@@ -1 +1 @@
1
- {"version":3,"file":"isDev.d.ts","sourceRoot":"","sources":["../src/isDev.ts"],"names":[],"mappings":"AAGA,QAAA,IAAI,KAAK,SAAQ,CAAA;AAgBjB,OAAO,EAAE,KAAK,EAAE,CAAA"}
1
+ {"version":3,"file":"isDev.d.ts","sourceRoot":"","sources":["../src/isDev.ts"],"names":[],"mappings":"AAGA,QAAA,IAAI,KAAK,SAAQ,CAAA;AAoBjB,OAAO,EAAE,KAAK,EAAE,CAAA"}
package/dist/isDev.js CHANGED
@@ -1,18 +1,22 @@
1
1
  import { TungstenError } from "./TungstenError.js";
2
2
  let isDev = false;
3
- // browser must be checked first: in dev the client loads cjsHelpers.js, which installs a
4
- // `process` shim so that converted CJS packages can read process.env.NODE_ENV. That shim
5
- // makes `typeof process !== 'undefined'` true in the browser, so a node-first check picks
6
- // the node branch, finds no __TUNGSTEN_ENV, and reports isDev === false in dev.
7
- if (typeof window !== 'undefined') {
3
+ // Neither global alone identifies the environment:
4
+ // - `process` exists in the browser in dev, because cjsHelpers.js installs a shim so that
5
+ // converted CJS packages can read process.env.NODE_ENV. A plain `typeof process` check
6
+ // therefore takes the node branch in the browser, finds no __TUNGSTEN_ENV, and reports
7
+ // isDev === false in dev.
8
+ // - `window` exists in node under the DOM test environment, so a plain `typeof window`
9
+ // check takes the browser branch in tests and throws on the missing __tungsten_prod__.
10
+ // So the shim marks itself (__tungstenCjsShim, declared in types/index.d.ts), and we exclude it.
11
+ if (typeof process !== 'undefined' && process.__tungstenCjsShim !== true) {
12
+ // server
13
+ isDev = process.env.__TUNGSTEN_ENV === 'development';
14
+ } else {
8
15
  // browser
9
16
  // typed as boolean, but it is set by an inline script in <head>, so it really can be
10
17
  // missing at runtime if that script did not run
11
18
  // eslint-disable-next-line @typescript-eslint/no-unnecessary-condition
12
19
  if (window.__tungsten_prod__ === undefined) throw new TungstenError('Err: window.__tungsten_prod__ is undefined');
13
20
  isDev = !window.__tungsten_prod__;
14
- } else {
15
- // node
16
- isDev = process.env.__TUNGSTEN_ENV === 'development';
17
21
  }
18
22
  export { isDev };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "tungsten",
3
- "version": "0.2.20",
3
+ "version": "0.2.21",
4
4
  "description": "",
5
5
  "type": "module",
6
6
  "bin": {
package/types/index.d.ts CHANGED
@@ -19,6 +19,18 @@ declare global {
19
19
  var tungstenPublicEnv: TungstenPublicEnv
20
20
  }
21
21
 
22
+ //// In dev, cjsHelpers.ts installs a partial `process` on the browser global so that converted
23
+ //// CommonJS packages can read process.env.NODE_ENV. It flags itself with __tungstenCjsShim so
24
+ //// that environment checks (isDev.ts) can tell it apart from a real node process.
25
+ //// Never present on real node.
26
+ declare global {
27
+ namespace NodeJS {
28
+ interface Process {
29
+ __tungstenCjsShim?: true
30
+ }
31
+ }
32
+ }
33
+
22
34
 
23
35
  // declare global {
24
36
  // var __T_CurrentElement: TElement // eslint-disable-line no-var