tungsten 0.2.19 → 0.2.20

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":"isDev.d.ts","sourceRoot":"","sources":["../src/isDev.ts"],"names":[],"mappings":"AAGA,QAAA,IAAI,KAAK,SAAQ,CAAA;AAUjB,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;AAgBjB,OAAO,EAAE,KAAK,EAAE,CAAA"}
package/dist/isDev.js CHANGED
@@ -1,11 +1,18 @@
1
1
  import { TungstenError } from "./TungstenError.js";
2
2
  let isDev = false;
3
- // node
4
- if (typeof process !== 'undefined') {
5
- isDev = process.env.__TUNGSTEN_ENV === 'development';
6
- } else {
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') {
7
8
  // browser
9
+ // typed as boolean, but it is set by an inline script in <head>, so it really can be
10
+ // missing at runtime if that script did not run
11
+ // eslint-disable-next-line @typescript-eslint/no-unnecessary-condition
8
12
  if (window.__tungsten_prod__ === undefined) throw new TungstenError('Err: window.__tungsten_prod__ is undefined');
9
13
  isDev = !window.__tungsten_prod__;
14
+ } else {
15
+ // node
16
+ isDev = process.env.__TUNGSTEN_ENV === 'development';
10
17
  }
11
18
  export { isDev };
@@ -1,4 +1,2 @@
1
- import { RenderingNodeElement } from '../RenderingNode.js';
2
- import { HeadData } from './HeadData.js';
3
- export declare function processBody(bodyNode: RenderingNodeElement, headData: HeadData): void;
1
+ export {};
4
2
  //# sourceMappingURL=processBody.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"processBody.d.ts","sourceRoot":"","sources":["../../src/render/processBody.ts"],"names":[],"mappings":"AAEA,OAAO,EAAE,oBAAoB,EAAqB,MAAM,qBAAqB,CAAA;AAG7E,OAAO,EAAE,QAAQ,EAAE,MAAM,eAAe,CAAA;AAIxC,wBAAgB,WAAW,CACvB,QAAQ,EAAE,oBAAoB,EAC9B,QAAQ,EAAE,QAAQ,QAuErB"}
1
+ {"version":3,"file":"processBody.d.ts","sourceRoot":"","sources":["../../src/render/processBody.ts"],"names":[],"mappings":"AA4FA,OAAO,EAAE,CAAA"}
@@ -1,67 +1,8 @@
1
- import { existsSync } from 'fs';
2
- import { $props, $type } from "../contentNodeSymbols.js";
3
- import { clientFolder } from "../settings.js";
4
- import serializeJavascript from 'serialize-javascript';
5
- import { join } from 'path';
6
- export function processBody(bodyNode, headData) {
7
- const {
8
- instance,
9
- dev
10
- } = headData;
11
- if (bodyNode[$props].children === undefined) bodyNode[$props].children = [];else if (!Array.isArray(bodyNode[$props].children)) bodyNode[$props].children = [bodyNode[$props].children];
12
- // entry script
13
- const scriptNode = {
14
- [$type]: 'script',
15
- [$props]: {
16
- 'data--t-internal': undefined,
17
- src: dev ? `/${clientFolder}/client.js` : `/bundle/clientWithEnv.js`
18
- }
19
- };
20
- if (dev) scriptNode[$props].type = 'module';else scriptNode[$props].defer = true;
21
- bodyNode[$props].children.unshift(scriptNode);
22
- if (dev) {
23
- if (existsSync(join(headData.compilationLocation, clientFolder, '.public.env.js'))) {
24
- // env file
25
- const envScriptNode = {
26
- [$type]: 'script',
27
- [$props]: {
28
- 'data--t-internal': undefined,
29
- type: 'module',
30
- src: `/${clientFolder}/.public.env.js`
31
- }
32
- };
33
- bodyNode[$props].children.unshift(envScriptNode);
34
- }
35
- // cjs loading helpers
36
- const cjsHelpersScriptNode = {
37
- [$type]: 'script',
38
- [$props]: {
39
- 'data--t-internal': undefined,
40
- type: 'module',
41
- src: `/${clientFolder}/cjsHelpers.js`
42
- }
43
- };
44
- bodyNode[$props].children.unshift(cjsHelpersScriptNode);
45
- }
46
- const {
47
- content: _,
48
- ...networkMatchedRoundInfo
49
- } = instance.matchedRouteInfo; // @typescript-eslint/no-unused-vars
50
- let varsScriptContent = `var __tungsten_prod__=${String(dev)};` + `var __tungsten_global_data__=${serializeJavascript(instance.globalData)};` + `var __tungsten_matched_route_info__=${serializeJavascript(networkMatchedRoundInfo)};`;
51
- // route Data
52
- if (instance.routeData !== undefined) {
53
- varsScriptContent += `var __tungsten_route_data__=${serializeJavascript(instance.routeData)};`;
54
- }
55
- // router data
56
- // if (instance.routerData !== undefined) {
57
- // varsScriptContent += `var __tungsten_router_data__=${serializeJavascript(instance.routerData)};`
58
- // }
59
- const varsScriptNode = {
60
- [$type]: 'script',
61
- [$props]: {
62
- 'data--t-internal': undefined,
63
- children: varsScriptContent
64
- }
65
- };
66
- bodyNode[$props].children.unshift(varsScriptNode);
67
- }
1
+ // UNUSED. The only reference is the commented-out call at renderingTreeToHtml.ts, and the
2
+ // scripts this would have injected into <body> are injected into <head> by processHead()
3
+ // instead. Kept commented rather than deleted in case body injection is wanted later.
4
+ //
5
+ // Note if reviving this: the __tungsten_prod__ line below has been corrected to `!dev`.
6
+ // It previously read `String(dev)`, which is inverted - that flag is read by isDev.ts in
7
+ // the browser, so shipping it inverted would make the client believe dev is prod.
8
+ export {};
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "tungsten",
3
- "version": "0.2.19",
3
+ "version": "0.2.20",
4
4
  "description": "",
5
5
  "type": "module",
6
6
  "bin": {