tungsten 0.2.19 → 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.
- package/dist/_client/cjsHelpers.d.ts.map +1 -1
- package/dist/_client/cjsHelpers.js +3 -0
- package/dist/isDev.d.ts.map +1 -1
- package/dist/isDev.js +13 -2
- package/dist/render/processBody.d.ts +1 -3
- package/dist/render/processBody.d.ts.map +1 -1
- package/dist/render/processBody.js +8 -67
- package/package.json +1 -1
- package/types/index.d.ts +12 -0
|
@@ -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;
|
|
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
|
},
|
package/dist/isDev.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"isDev.d.ts","sourceRoot":"","sources":["../src/isDev.ts"],"names":[],"mappings":"AAGA,QAAA,IAAI,KAAK,SAAQ,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,10 +1,21 @@
|
|
|
1
1
|
import { TungstenError } from "./TungstenError.js";
|
|
2
2
|
let isDev = false;
|
|
3
|
-
//
|
|
4
|
-
|
|
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
|
|
5
13
|
isDev = process.env.__TUNGSTEN_ENV === 'development';
|
|
6
14
|
} else {
|
|
7
15
|
// browser
|
|
16
|
+
// typed as boolean, but it is set by an inline script in <head>, so it really can be
|
|
17
|
+
// missing at runtime if that script did not run
|
|
18
|
+
// eslint-disable-next-line @typescript-eslint/no-unnecessary-condition
|
|
8
19
|
if (window.__tungsten_prod__ === undefined) throw new TungstenError('Err: window.__tungsten_prod__ is undefined');
|
|
9
20
|
isDev = !window.__tungsten_prod__;
|
|
10
21
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"processBody.d.ts","sourceRoot":"","sources":["../../src/render/processBody.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"processBody.d.ts","sourceRoot":"","sources":["../../src/render/processBody.ts"],"names":[],"mappings":"AA4FA,OAAO,EAAE,CAAA"}
|
|
@@ -1,67 +1,8 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
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
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
|