@lwrjs/shared-utils 0.17.2-alpha.9 → 0.18.0
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/build/cjs/env.cjs +51 -7
- package/build/cjs/html-meta.cjs +0 -1
- package/build/cjs/identity.cjs +1 -1
- package/build/cjs/launch.cjs +6 -2
- package/build/cjs/serialize.cjs +58 -0
- package/build/es/env.d.ts +26 -2
- package/build/es/env.js +54 -5
- package/build/es/html-meta.d.ts +2 -2
- package/build/es/html-meta.js +0 -1
- package/build/es/identity.js +1 -1
- package/build/es/interchangeable-modules.js +1 -1
- package/build/es/launch.d.ts +1 -1
- package/build/es/launch.js +7 -2
- package/build/es/lwr-app-observer.js +1 -0
- package/build/es/serialize.d.ts +19 -1
- package/build/es/serialize.js +78 -0
- package/build/es/tasks.js +8 -5
- package/package.json +5 -5
package/build/cjs/env.cjs
CHANGED
|
@@ -8,12 +8,22 @@ var __export = (target, all) => {
|
|
|
8
8
|
// packages/@lwrjs/shared-utils/src/env.ts
|
|
9
9
|
__markAsModule(exports);
|
|
10
10
|
__export(exports, {
|
|
11
|
+
B3_PARENT_ID: () => B3_PARENT_ID,
|
|
12
|
+
B3_SAMPLED: () => B3_SAMPLED,
|
|
13
|
+
B3_SPAN_ID: () => B3_SPAN_ID,
|
|
14
|
+
B3_TRACE_ID: () => B3_TRACE_ID,
|
|
15
|
+
CORRELATION_ID: () => CORRELATION_ID,
|
|
16
|
+
MRT_REQUEST_CLASS: () => MRT_REQUEST_CLASS,
|
|
11
17
|
REQUEST_DEPTH_HEADER: () => REQUEST_DEPTH_HEADER,
|
|
12
|
-
|
|
18
|
+
ROUTE_CORE_HEADER: () => ROUTE_CORE_HEADER,
|
|
19
|
+
TRUE_CLIENT_IP: () => TRUE_CLIENT_IP,
|
|
13
20
|
buildEnvironmentContext: () => buildEnvironmentContext,
|
|
14
21
|
getFeatureFlags: () => getFeatureFlags,
|
|
22
|
+
getTraceHeaders: () => getTraceHeaders,
|
|
15
23
|
isLambdaEnv: () => isLambdaEnv,
|
|
24
|
+
isLocalAuthEnabled: () => isLocalAuthEnabled,
|
|
16
25
|
isLocalDev: () => isLocalDev,
|
|
26
|
+
isLocalPreview: () => isLocalPreview,
|
|
17
27
|
parseRequestDepth: () => parseRequestDepth
|
|
18
28
|
});
|
|
19
29
|
if (getFeatureFlags().REEVALUATE_MODULES && !getFeatureFlags().LEGACY_LOADER) {
|
|
@@ -27,12 +37,15 @@ function getFeatureFlags() {
|
|
|
27
37
|
EXPERIMENTAL_UNVERSIONED_ALIASES: parseBooleanFlag("EXPERIMENTAL_UNVERSIONED_ALIASES"),
|
|
28
38
|
LEGACY_LOADER: parseBooleanFlag("LEGACY_LOADER"),
|
|
29
39
|
LWR_TRACING: parseTracingFlag(),
|
|
40
|
+
DISABLE_B3_TRACING: parseBooleanFlag("DISABLE_B3_TRACING"),
|
|
30
41
|
MAX_VIEW_CACHE_TTL: parseStringFlag("MAX_VIEW_CACHE_TTL"),
|
|
31
42
|
REEVALUATE_MODULES: parseBooleanFlag("REEVALUATE_MODULES"),
|
|
32
43
|
SSR_COMPILER_ENABLED: parseBooleanFlag("SSR_COMPILER_ENABLED"),
|
|
33
44
|
SSR_LOADER_PER_REQUEST: parseBooleanFlag("SSR_LOADER_PER_REQUEST"),
|
|
34
45
|
VIEW_CACHE_SIZE: parseStringFlag("VIEW_CACHE_SIZE"),
|
|
35
|
-
EXPERIMENTAL_ASSET_HEADERS: parseStringFlag("EXPERIMENTAL_ASSET_HEADERS")
|
|
46
|
+
EXPERIMENTAL_ASSET_HEADERS: parseStringFlag("EXPERIMENTAL_ASSET_HEADERS"),
|
|
47
|
+
SSR_TIMEOUT: parseStringFlag("SSR_TIMEOUT"),
|
|
48
|
+
PRELOAD_INCLUDED_MODULES: parseBooleanFlag("PRELOAD_INCLUDED_MODULES")
|
|
36
49
|
};
|
|
37
50
|
}
|
|
38
51
|
function parseBooleanFlag(flag) {
|
|
@@ -52,6 +65,12 @@ function isLambdaEnv() {
|
|
|
52
65
|
function isLocalDev() {
|
|
53
66
|
return process.env.MRT_HMR === "true";
|
|
54
67
|
}
|
|
68
|
+
function isLocalPreview() {
|
|
69
|
+
return process.env.LOCAL_PREVIEW_MODE === "true";
|
|
70
|
+
}
|
|
71
|
+
function isLocalAuthEnabled() {
|
|
72
|
+
return process.env.AUTH_TOKEN !== void 0;
|
|
73
|
+
}
|
|
55
74
|
function buildEnvironmentContext(runtimeParams) {
|
|
56
75
|
const basePath = runtimeParams.basePath;
|
|
57
76
|
const locale = runtimeParams.locale;
|
|
@@ -64,11 +83,18 @@ function buildEnvironmentContext(runtimeParams) {
|
|
|
64
83
|
uiBasePath
|
|
65
84
|
};
|
|
66
85
|
}
|
|
67
|
-
var
|
|
68
|
-
var
|
|
86
|
+
var TRUE_CLIENT_IP = "true-client-ip";
|
|
87
|
+
var CORRELATION_ID = "x-correlation-id";
|
|
88
|
+
var B3_TRACE_ID = "x-b3-traceid";
|
|
89
|
+
var B3_SPAN_ID = "x-b3-spanid";
|
|
90
|
+
var B3_PARENT_ID = "x-b3-parentspanid";
|
|
91
|
+
var B3_SAMPLED = "x-b3-sampled";
|
|
92
|
+
var MRT_REQUEST_CLASS = "x-mobify-request-class";
|
|
93
|
+
var ROUTE_CORE_HEADER = "x-sfdc-route-core";
|
|
94
|
+
var REQUEST_DEPTH_HEADER = "x-sfdc-request-depth";
|
|
69
95
|
function parseRequestDepth(headers = {}, query = {}) {
|
|
70
96
|
let maxDepth = 0;
|
|
71
|
-
const value = headers && headers[
|
|
97
|
+
const value = headers && headers[REQUEST_DEPTH_HEADER];
|
|
72
98
|
if (value) {
|
|
73
99
|
if (Array.isArray(value)) {
|
|
74
100
|
for (const depth of value) {
|
|
@@ -86,11 +112,29 @@ function parseRequestDepth(headers = {}, query = {}) {
|
|
|
86
112
|
}
|
|
87
113
|
}
|
|
88
114
|
}
|
|
89
|
-
if (query[
|
|
90
|
-
const queryValue = parseInt(query[
|
|
115
|
+
if (query[REQUEST_DEPTH_HEADER]) {
|
|
116
|
+
const queryValue = parseInt(query[REQUEST_DEPTH_HEADER], 10);
|
|
91
117
|
if (!isNaN(queryValue) && queryValue > maxDepth) {
|
|
92
118
|
maxDepth = queryValue;
|
|
93
119
|
}
|
|
94
120
|
}
|
|
95
121
|
return maxDepth;
|
|
96
122
|
}
|
|
123
|
+
function getTraceHeaders(runtimeParams, span) {
|
|
124
|
+
const headers = {};
|
|
125
|
+
if (runtimeParams.trueClientIP)
|
|
126
|
+
headers[TRUE_CLIENT_IP] = runtimeParams.trueClientIP;
|
|
127
|
+
if (runtimeParams.correlationID)
|
|
128
|
+
headers[CORRELATION_ID] = runtimeParams.correlationID;
|
|
129
|
+
if (!getFeatureFlags().DISABLE_B3_TRACING) {
|
|
130
|
+
if (span?.traceId) {
|
|
131
|
+
headers[B3_TRACE_ID] = span.traceId;
|
|
132
|
+
headers[B3_SAMPLED] = parseTracingFlag() ? "1" : "0";
|
|
133
|
+
}
|
|
134
|
+
if (span?.spanId)
|
|
135
|
+
headers[B3_SPAN_ID] = span.spanId;
|
|
136
|
+
if (span?.parentSpanId)
|
|
137
|
+
headers[B3_PARENT_ID] = span.parentSpanId;
|
|
138
|
+
}
|
|
139
|
+
return headers;
|
|
140
|
+
}
|
package/build/cjs/html-meta.cjs
CHANGED
package/build/cjs/identity.cjs
CHANGED
|
@@ -127,7 +127,7 @@ async function getVersionedModuleId(rawSpecifier, moduleRegistry, runtimeParams)
|
|
|
127
127
|
return {...moduleId, version: moduleEntry.version};
|
|
128
128
|
}
|
|
129
129
|
function isSpecifier(specifier) {
|
|
130
|
-
return !!specifier && /^@?[\w
|
|
130
|
+
return !!specifier && /^@?[\w-.]+(\/[\w-.]+)*$/.test(specifier);
|
|
131
131
|
}
|
|
132
132
|
var RE_SCOPED = /^(@[^/]+\/[^/@]+)(?:\/([^@]+))?(?:@([\s\S]+))?/;
|
|
133
133
|
var RE_NORMAL = /^([^/@]+)(?:\/([^@]+))?(?:@([\s\S]+))?/;
|
package/build/cjs/launch.cjs
CHANGED
|
@@ -27,7 +27,7 @@ __export(exports, {
|
|
|
27
27
|
launch: () => launch
|
|
28
28
|
});
|
|
29
29
|
var import_os = __toModule(require("os"));
|
|
30
|
-
async function launch(port, https) {
|
|
30
|
+
async function launch(port, https, path) {
|
|
31
31
|
const {exec} = await Promise.resolve().then(() => __toModule(require("child_process")));
|
|
32
32
|
let cmd = "open";
|
|
33
33
|
if (process.platform == "win32") {
|
|
@@ -39,5 +39,9 @@ async function launch(port, https) {
|
|
|
39
39
|
cmd = "xdg-open";
|
|
40
40
|
}
|
|
41
41
|
}
|
|
42
|
-
|
|
42
|
+
const finalPath = path ? path.startsWith("/") ? path : `/${path}` : "";
|
|
43
|
+
const protocol = https ? "https" : "http";
|
|
44
|
+
const url = `${protocol}://localhost:${port}${finalPath}/`;
|
|
45
|
+
exec(`${cmd} ${url}`);
|
|
46
|
+
return url;
|
|
43
47
|
}
|
package/build/cjs/serialize.cjs
CHANGED
|
@@ -24,11 +24,15 @@ var __toModule = (module2) => {
|
|
|
24
24
|
// packages/@lwrjs/shared-utils/src/serialize.ts
|
|
25
25
|
__markAsModule(exports);
|
|
26
26
|
__export(exports, {
|
|
27
|
+
addHeadMarkup: () => addHeadMarkup,
|
|
28
|
+
addToHead: () => addToHead,
|
|
29
|
+
createHeadMarkup: () => createHeadMarkup,
|
|
27
30
|
replaceStringFromLocation: () => replaceStringFromLocation,
|
|
28
31
|
serializeModuleToJson: () => serializeModuleToJson,
|
|
29
32
|
shortestTtl: () => shortestTtl
|
|
30
33
|
});
|
|
31
34
|
var import_ms = __toModule(require("ms"));
|
|
35
|
+
var import_diagnostics = __toModule(require("@lwrjs/diagnostics"));
|
|
32
36
|
async function createJsonModule(moduleId, moduleRegistry, runtimeEnvironment, runtimeParams) {
|
|
33
37
|
const {
|
|
34
38
|
ownHash,
|
|
@@ -84,3 +88,57 @@ function shortestTtl(newTtl, oldTtl, maxTtl) {
|
|
|
84
88
|
}
|
|
85
89
|
return shortest;
|
|
86
90
|
}
|
|
91
|
+
function createMetaTags(meta) {
|
|
92
|
+
return meta.reduce((metaStr, {name, content, httpEquiv}) => {
|
|
93
|
+
if (!name && !content && !httpEquiv)
|
|
94
|
+
return metaStr;
|
|
95
|
+
const nameStr = name ? ` name="${name}"` : "", httpEquivStr = httpEquiv ? ` http-equiv="${httpEquiv}"` : "", contentStr = content ? ` content="${content}"` : "";
|
|
96
|
+
return metaStr + `<meta${nameStr}${httpEquivStr}${contentStr}>
|
|
97
|
+
`;
|
|
98
|
+
}, "");
|
|
99
|
+
}
|
|
100
|
+
function createScriptTags(scripts) {
|
|
101
|
+
return scripts.reduce((scriptStr, {body}) => scriptStr + `<script type="application/ld+json">${body}</script>
|
|
102
|
+
`, "");
|
|
103
|
+
}
|
|
104
|
+
function createLinkTags(links) {
|
|
105
|
+
return links.reduce((linkStr, {href, rel, as, fetchpriority}) => {
|
|
106
|
+
const relStr = rel ? ` rel="${rel}"` : "", asStr = as ? ` as="${as}"` : "", fetchStr = fetchpriority ? ` fetchpriority="${fetchpriority}"` : "";
|
|
107
|
+
return linkStr + `<link href="${href}"${relStr}${asStr}${fetchStr}>
|
|
108
|
+
`;
|
|
109
|
+
}, "");
|
|
110
|
+
}
|
|
111
|
+
function createStyleTags(styles) {
|
|
112
|
+
return styles.reduce((styleStr, {body, id}) => {
|
|
113
|
+
const idStr = id ? ` id="${id}"` : "";
|
|
114
|
+
return styleStr + `<style type="text/css"${idStr}>${body}</style>
|
|
115
|
+
`;
|
|
116
|
+
}, "");
|
|
117
|
+
}
|
|
118
|
+
function createHeadMarkup(markup) {
|
|
119
|
+
let hasTitle = false;
|
|
120
|
+
return markup.reduce((str, {title, scripts = [], meta = [], links = [], styles = []} = {}) => {
|
|
121
|
+
if (title && !hasTitle) {
|
|
122
|
+
hasTitle = true;
|
|
123
|
+
str += `<title>${title}</title>
|
|
124
|
+
`;
|
|
125
|
+
}
|
|
126
|
+
return str + createMetaTags(meta) + createScriptTags(scripts) + createLinkTags(links) + createStyleTags(styles);
|
|
127
|
+
}, "");
|
|
128
|
+
}
|
|
129
|
+
function addHeadMarkup(markup, stringBuilder) {
|
|
130
|
+
const headMarkup = createHeadMarkup(markup);
|
|
131
|
+
if (headMarkup) {
|
|
132
|
+
addToHead(headMarkup, stringBuilder);
|
|
133
|
+
}
|
|
134
|
+
}
|
|
135
|
+
function addToHead(markup, stringBuilder) {
|
|
136
|
+
if (markup) {
|
|
137
|
+
const headIndex = stringBuilder.original.indexOf("</head>");
|
|
138
|
+
if (headIndex >= 0) {
|
|
139
|
+
stringBuilder.prependLeft(headIndex, markup);
|
|
140
|
+
} else {
|
|
141
|
+
import_diagnostics.logger.error("Adding head markup failed. Could not find the </head> tag.");
|
|
142
|
+
}
|
|
143
|
+
}
|
|
144
|
+
}
|
package/build/es/env.d.ts
CHANGED
|
@@ -12,11 +12,35 @@ export declare function isLambdaEnv(): boolean;
|
|
|
12
12
|
* @returns true if running in localdev mode
|
|
13
13
|
*/
|
|
14
14
|
export declare function isLocalDev(): boolean;
|
|
15
|
+
/**
|
|
16
|
+
* This function is used to determine if lwr is running in the context of local preview.
|
|
17
|
+
*
|
|
18
|
+
* @returns true if running in preview mode
|
|
19
|
+
*/
|
|
20
|
+
export declare function isLocalPreview(): boolean;
|
|
21
|
+
/**
|
|
22
|
+
* This function is used to determine if lwr is running with an authenticated context locally
|
|
23
|
+
*
|
|
24
|
+
* @returns true if local dev/preview authentication is enabled
|
|
25
|
+
*/
|
|
26
|
+
export declare function isLocalAuthEnabled(): boolean;
|
|
15
27
|
/**
|
|
16
28
|
* Create a serializable context for user-land exposed environment variables
|
|
17
29
|
*/
|
|
18
30
|
export declare function buildEnvironmentContext(runtimeParams: RuntimeParams): EnvironmentContext;
|
|
19
|
-
export declare const
|
|
20
|
-
export declare const
|
|
31
|
+
export declare const TRUE_CLIENT_IP = "true-client-ip";
|
|
32
|
+
export declare const CORRELATION_ID = "x-correlation-id";
|
|
33
|
+
export declare const B3_TRACE_ID = "x-b3-traceid";
|
|
34
|
+
export declare const B3_SPAN_ID = "x-b3-spanid";
|
|
35
|
+
export declare const B3_PARENT_ID = "x-b3-parentspanid";
|
|
36
|
+
export declare const B3_SAMPLED = "x-b3-sampled";
|
|
37
|
+
export declare const MRT_REQUEST_CLASS = "x-mobify-request-class";
|
|
38
|
+
export declare const ROUTE_CORE_HEADER = "x-sfdc-route-core";
|
|
39
|
+
export declare const REQUEST_DEPTH_HEADER = "x-sfdc-request-depth";
|
|
21
40
|
export declare function parseRequestDepth(headers?: Headers, query?: Record<string, string>): number;
|
|
41
|
+
export declare function getTraceHeaders(runtimeParams: RuntimeParams, span?: {
|
|
42
|
+
traceId: string;
|
|
43
|
+
spanId: string;
|
|
44
|
+
parentSpanId?: string;
|
|
45
|
+
}): HeadersInit;
|
|
22
46
|
//# sourceMappingURL=env.d.ts.map
|
package/build/es/env.js
CHANGED
|
@@ -14,6 +14,8 @@ export function getFeatureFlags() {
|
|
|
14
14
|
LEGACY_LOADER: parseBooleanFlag('LEGACY_LOADER'),
|
|
15
15
|
// Enable metrics log level 'off', 'default' or 'verbose'
|
|
16
16
|
LWR_TRACING: parseTracingFlag(),
|
|
17
|
+
// Turn off distributed tracing (B3 headers, traceparent meta tag, MRT span exporting)
|
|
18
|
+
DISABLE_B3_TRACING: parseBooleanFlag('DISABLE_B3_TRACING'),
|
|
17
19
|
// Max size of ViewDefinition time to live
|
|
18
20
|
MAX_VIEW_CACHE_TTL: parseStringFlag('MAX_VIEW_CACHE_TTL'),
|
|
19
21
|
// Forces SSR to re-evaluate modules for every page render. By default, modules are evaluated only once.
|
|
@@ -28,6 +30,10 @@ export function getFeatureFlags() {
|
|
|
28
30
|
// Expected format is `<header_key_1>: <header_value_1>, header_value_2>; <header_key_2>: <header_value_2>`
|
|
29
31
|
// E.g., assetHeadersString Cloudflare-CDN-Cache-Control: max-age=2813308004; Cache-Tag: ABC123;
|
|
30
32
|
EXPERIMENTAL_ASSET_HEADERS: parseStringFlag('EXPERIMENTAL_ASSET_HEADERS'),
|
|
33
|
+
// Sets the timeout for SSR on lambda in ms
|
|
34
|
+
SSR_TIMEOUT: parseStringFlag('SSR_TIMEOUT'),
|
|
35
|
+
// Pushes the includedModules of each root component bundle into clientBootstrapConfig.preloadModules
|
|
36
|
+
PRELOAD_INCLUDED_MODULES: parseBooleanFlag('PRELOAD_INCLUDED_MODULES'),
|
|
31
37
|
};
|
|
32
38
|
}
|
|
33
39
|
/**
|
|
@@ -70,6 +76,22 @@ export function isLocalDev() {
|
|
|
70
76
|
// TODO still need to formalize environment variable names
|
|
71
77
|
return process.env.MRT_HMR === 'true';
|
|
72
78
|
}
|
|
79
|
+
/**
|
|
80
|
+
* This function is used to determine if lwr is running in the context of local preview.
|
|
81
|
+
*
|
|
82
|
+
* @returns true if running in preview mode
|
|
83
|
+
*/
|
|
84
|
+
export function isLocalPreview() {
|
|
85
|
+
return process.env.LOCAL_PREVIEW_MODE === 'true';
|
|
86
|
+
}
|
|
87
|
+
/**
|
|
88
|
+
* This function is used to determine if lwr is running with an authenticated context locally
|
|
89
|
+
*
|
|
90
|
+
* @returns true if local dev/preview authentication is enabled
|
|
91
|
+
*/
|
|
92
|
+
export function isLocalAuthEnabled() {
|
|
93
|
+
return process.env.AUTH_TOKEN !== undefined;
|
|
94
|
+
}
|
|
73
95
|
/**
|
|
74
96
|
* Create a serializable context for user-land exposed environment variables
|
|
75
97
|
*/
|
|
@@ -89,11 +111,20 @@ export function buildEnvironmentContext(runtimeParams) {
|
|
|
89
111
|
uiBasePath,
|
|
90
112
|
};
|
|
91
113
|
}
|
|
92
|
-
|
|
93
|
-
export const
|
|
114
|
+
// headers used by LWR-Node and LWR@MRT
|
|
115
|
+
export const TRUE_CLIENT_IP = 'true-client-ip'; // public IP of the original request source, eg: 13.123.12.3
|
|
116
|
+
export const CORRELATION_ID = 'x-correlation-id'; // shared correlation ID for the request
|
|
117
|
+
export const B3_TRACE_ID = 'x-b3-traceid'; // trace ID shared across service boundaries for a page request, set to inbound B3 header || lwr.handle.view trace ID
|
|
118
|
+
export const B3_SPAN_ID = 'x-b3-spanid'; // span ID for a trace
|
|
119
|
+
export const B3_PARENT_ID = 'x-b3-parentspanid'; // parent span ID for a trace
|
|
120
|
+
export const B3_SAMPLED = 'x-b3-sampled'; // "0" = tracing is off, "1" = tracing is on
|
|
121
|
+
export const MRT_REQUEST_CLASS = 'x-mobify-request-class'; // contains the site base path, eg: basePath=/mysite
|
|
122
|
+
export const ROUTE_CORE_HEADER = 'x-sfdc-route-core'; // helps route requests to Core efficiently, value: true
|
|
123
|
+
export const REQUEST_DEPTH_HEADER = 'x-sfdc-request-depth'; // tracks the request depth to prevent cycles to the LWR server, eg: 2
|
|
124
|
+
// standard headers: Forwarded (eg: host=dev.testing.com;proto=https), Host (eg: darrell.sandbox.my.site.com), Cookie (holds the SID for auth'ed requests)
|
|
94
125
|
export function parseRequestDepth(headers = {}, query = {}) {
|
|
95
126
|
let maxDepth = 0;
|
|
96
|
-
const value = headers && headers[
|
|
127
|
+
const value = headers && headers[REQUEST_DEPTH_HEADER];
|
|
97
128
|
if (value) {
|
|
98
129
|
if (Array.isArray(value)) {
|
|
99
130
|
for (const depth of value) {
|
|
@@ -112,12 +143,30 @@ export function parseRequestDepth(headers = {}, query = {}) {
|
|
|
112
143
|
}
|
|
113
144
|
}
|
|
114
145
|
}
|
|
115
|
-
if (query[
|
|
116
|
-
const queryValue = parseInt(query[
|
|
146
|
+
if (query[REQUEST_DEPTH_HEADER]) {
|
|
147
|
+
const queryValue = parseInt(query[REQUEST_DEPTH_HEADER], 10);
|
|
117
148
|
if (!isNaN(queryValue) && queryValue > maxDepth) {
|
|
118
149
|
maxDepth = queryValue;
|
|
119
150
|
}
|
|
120
151
|
}
|
|
121
152
|
return maxDepth;
|
|
122
153
|
}
|
|
154
|
+
export function getTraceHeaders(runtimeParams, span) {
|
|
155
|
+
const headers = {};
|
|
156
|
+
if (runtimeParams.trueClientIP)
|
|
157
|
+
headers[TRUE_CLIENT_IP] = runtimeParams.trueClientIP;
|
|
158
|
+
if (runtimeParams.correlationID)
|
|
159
|
+
headers[CORRELATION_ID] = runtimeParams.correlationID;
|
|
160
|
+
if (!getFeatureFlags().DISABLE_B3_TRACING) {
|
|
161
|
+
if (span?.traceId) {
|
|
162
|
+
headers[B3_TRACE_ID] = span.traceId;
|
|
163
|
+
headers[B3_SAMPLED] = parseTracingFlag() ? '1' : '0';
|
|
164
|
+
}
|
|
165
|
+
if (span?.spanId)
|
|
166
|
+
headers[B3_SPAN_ID] = span.spanId;
|
|
167
|
+
if (span?.parentSpanId)
|
|
168
|
+
headers[B3_PARENT_ID] = span.parentSpanId;
|
|
169
|
+
}
|
|
170
|
+
return headers;
|
|
171
|
+
}
|
|
123
172
|
//# sourceMappingURL=env.js.map
|
package/build/es/html-meta.d.ts
CHANGED
|
@@ -1,11 +1,11 @@
|
|
|
1
|
-
import type { NormalizedLwrGlobalConfig, RenderedViewMetadata } from '@lwrjs/types';
|
|
1
|
+
import type { HtmlMetadata, NormalizedLwrGlobalConfig, RenderedViewMetadata } from '@lwrjs/types';
|
|
2
2
|
export declare function isRelative(url: string): boolean;
|
|
3
3
|
export declare function isSelfUrl(url: string): boolean;
|
|
4
4
|
/**
|
|
5
5
|
* Pull the custom elements and img tags out of an HTML string, to use as metadata
|
|
6
6
|
* @param htmlSource - An HTML string to parse
|
|
7
7
|
*/
|
|
8
|
-
export declare function extractMetadataFromHtml(htmlSource: string, viewMetadata: RenderedViewMetadata, appConfig: NormalizedLwrGlobalConfig):
|
|
8
|
+
export declare function extractMetadataFromHtml(htmlSource: string, viewMetadata: RenderedViewMetadata, appConfig: NormalizedLwrGlobalConfig): HtmlMetadata;
|
|
9
9
|
export declare const HYDRATE_DIRECTIVE = "lwr:hydrate";
|
|
10
10
|
export declare const HYDRATE_LOAD_VALUE = "load";
|
|
11
11
|
export declare const HYDRATE_CLIENT_VALUE = "client-only";
|
package/build/es/html-meta.js
CHANGED
|
@@ -165,7 +165,6 @@ export function extractMetadataFromHtml(htmlSource, viewMetadata, appConfig) {
|
|
|
165
165
|
},
|
|
166
166
|
});
|
|
167
167
|
return {
|
|
168
|
-
...viewMetadata,
|
|
169
168
|
customElements: customElements.filter((ce) => !nestedIslands || hasHydrationDirective(ce.props)),
|
|
170
169
|
assetReferences,
|
|
171
170
|
};
|
package/build/es/identity.js
CHANGED
|
@@ -128,7 +128,7 @@ export async function getVersionedModuleId(rawSpecifier, moduleRegistry, runtime
|
|
|
128
128
|
return { ...moduleId, version: moduleEntry.version };
|
|
129
129
|
}
|
|
130
130
|
export function isSpecifier(specifier) {
|
|
131
|
-
return !!specifier && /^@?[\w
|
|
131
|
+
return !!specifier && /^@?[\w-.]+(\/[\w-.]+)*$/.test(specifier);
|
|
132
132
|
}
|
|
133
133
|
const RE_SCOPED = /^(@[^/]+\/[^/@]+)(?:\/([^@]+))?(?:@([\s\S]+))?/;
|
|
134
134
|
const RE_NORMAL = /^([^/@]+)(?:\/([^@]+))?(?:@([\s\S]+))?/;
|
|
@@ -4,9 +4,9 @@ import resolve from 'resolve';
|
|
|
4
4
|
import { readFile } from './fs.js';
|
|
5
5
|
const CONFIG_FILES = ['package.json', 'lwc.config.json', 'lwr.config.json'];
|
|
6
6
|
class NoLwcModuleError extends Error {
|
|
7
|
+
code = 'NO_LWC_MODULE_FOUND';
|
|
7
8
|
constructor() {
|
|
8
9
|
super('No LWC module found');
|
|
9
|
-
this.code = 'NO_LWC_MODULE_FOUND';
|
|
10
10
|
}
|
|
11
11
|
}
|
|
12
12
|
function isNpmModuleRecord(module) {
|
package/build/es/launch.d.ts
CHANGED
|
@@ -4,5 +4,5 @@
|
|
|
4
4
|
* @param port - the port number
|
|
5
5
|
* @param https - if true, use https
|
|
6
6
|
*/
|
|
7
|
-
export declare function launch(port: number, https?: boolean): Promise<
|
|
7
|
+
export declare function launch(port: number, https?: boolean, path?: string): Promise<string>;
|
|
8
8
|
//# sourceMappingURL=launch.d.ts.map
|
package/build/es/launch.js
CHANGED
|
@@ -5,7 +5,7 @@ import { release } from 'os';
|
|
|
5
5
|
* @param port - the port number
|
|
6
6
|
* @param https - if true, use https
|
|
7
7
|
*/
|
|
8
|
-
export async function launch(port, https) {
|
|
8
|
+
export async function launch(port, https, path) {
|
|
9
9
|
const { exec } = await import('child_process');
|
|
10
10
|
let cmd = 'open';
|
|
11
11
|
if (process.platform == 'win32') {
|
|
@@ -19,6 +19,11 @@ export async function launch(port, https) {
|
|
|
19
19
|
cmd = 'xdg-open';
|
|
20
20
|
}
|
|
21
21
|
}
|
|
22
|
-
|
|
22
|
+
// Ensure the path begins with '/' if provided
|
|
23
|
+
const finalPath = path ? (path.startsWith('/') ? path : `/${path}`) : '';
|
|
24
|
+
const protocol = https ? 'https' : 'http';
|
|
25
|
+
const url = `${protocol}://localhost:${port}${finalPath}/`;
|
|
26
|
+
exec(`${cmd} ${url}`);
|
|
27
|
+
return url;
|
|
23
28
|
}
|
|
24
29
|
//# sourceMappingURL=launch.js.map
|
|
@@ -4,6 +4,7 @@ const MODULE_SOURCE_CHANGED_EVENT = 'module_source_changed';
|
|
|
4
4
|
const VIEW_SOURCE_CHANGED_EVENT = 'view_source_changed';
|
|
5
5
|
const ASSET_SOURCE_CHANGED_EVENT = 'asset_source_changed';
|
|
6
6
|
class LwrEmitter {
|
|
7
|
+
observer;
|
|
7
8
|
constructor(observer) {
|
|
8
9
|
this.observer = observer;
|
|
9
10
|
}
|
package/build/es/serialize.d.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import type { LinkedModuleDefinition, ModuleJsonDefinition, ModuleRegistry, RuntimeParams } from '@lwrjs/types';
|
|
1
|
+
import type { HeadMarkup, LinkedModuleDefinition, LwrStringBuilder, ModuleJsonDefinition, ModuleRegistry, RuntimeParams } from '@lwrjs/types';
|
|
2
2
|
/**
|
|
3
3
|
* Take a Module Definition and return its JSON serialization
|
|
4
4
|
*
|
|
@@ -26,4 +26,22 @@ export declare function replaceStringFromLocation(src: string, { startOffset, en
|
|
|
26
26
|
* @returns - the shorter of the two TTLs IN SECONDS, undefined if both TTLs are missing
|
|
27
27
|
*/
|
|
28
28
|
export declare function shortestTtl(newTtl?: string | number, oldTtl?: string | number, maxTtl?: string | number): number | undefined;
|
|
29
|
+
/**
|
|
30
|
+
* Serialize head markup metadata into an HTML string
|
|
31
|
+
* @param markup An array of markup metadata objects
|
|
32
|
+
* @returns A string of HTML generated from markup metadata
|
|
33
|
+
*/
|
|
34
|
+
export declare function createHeadMarkup(markup: (HeadMarkup | undefined)[]): string;
|
|
35
|
+
/**
|
|
36
|
+
* Serialize HeadMarkup config into HTML, then add it to the <head> of a base doc
|
|
37
|
+
* @param markup An array of markup metadata objects
|
|
38
|
+
* @param stringBuilder The string builder for a base document
|
|
39
|
+
*/
|
|
40
|
+
export declare function addHeadMarkup(markup: (HeadMarkup | undefined)[], stringBuilder: LwrStringBuilder): void;
|
|
41
|
+
/**
|
|
42
|
+
* Add an HTML string to the <head> of a base doc
|
|
43
|
+
* @param markup An HTML string
|
|
44
|
+
* @param stringBuilder The string builder for a base document
|
|
45
|
+
*/
|
|
46
|
+
export declare function addToHead(markup: string, stringBuilder: LwrStringBuilder): void;
|
|
29
47
|
//# sourceMappingURL=serialize.d.ts.map
|
package/build/es/serialize.js
CHANGED
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import ms from 'ms';
|
|
2
|
+
import { logger } from '@lwrjs/diagnostics';
|
|
2
3
|
// Given a Module Identifier, return a JSON entry
|
|
3
4
|
async function createJsonModule(moduleId, moduleRegistry, runtimeEnvironment, runtimeParams) {
|
|
4
5
|
const { ownHash, moduleEntry: { version }, } = await moduleRegistry.getModule(moduleId, runtimeParams);
|
|
@@ -67,4 +68,81 @@ export function shortestTtl(newTtl, oldTtl, maxTtl) {
|
|
|
67
68
|
}
|
|
68
69
|
return shortest;
|
|
69
70
|
}
|
|
71
|
+
/** HEAD MARKUP UTILS */
|
|
72
|
+
function createMetaTags(meta) {
|
|
73
|
+
return meta.reduce((metaStr, { name, content, httpEquiv }) => {
|
|
74
|
+
if (!name && !content && !httpEquiv)
|
|
75
|
+
return metaStr; // do not create empty <meta> tags
|
|
76
|
+
const nameStr = name ? ` name="${name}"` : '', httpEquivStr = httpEquiv ? ` http-equiv="${httpEquiv}"` : '', contentStr = content ? ` content="${content}"` : '';
|
|
77
|
+
return metaStr + `<meta${nameStr}${httpEquivStr}${contentStr}>\n`;
|
|
78
|
+
}, '');
|
|
79
|
+
}
|
|
80
|
+
function createScriptTags(scripts) {
|
|
81
|
+
return scripts.reduce((scriptStr, { body }) => scriptStr + `<script type="application/ld+json">${body}</script>\n`, '');
|
|
82
|
+
}
|
|
83
|
+
function createLinkTags(links) {
|
|
84
|
+
return links.reduce((linkStr, { href, rel, as, fetchpriority }) => {
|
|
85
|
+
const relStr = rel ? ` rel="${rel}"` : '', asStr = as ? ` as="${as}"` : '', fetchStr = fetchpriority ? ` fetchpriority="${fetchpriority}"` : '';
|
|
86
|
+
return linkStr + `<link href="${href}"${relStr}${asStr}${fetchStr}>\n`;
|
|
87
|
+
}, '');
|
|
88
|
+
}
|
|
89
|
+
function createStyleTags(styles) {
|
|
90
|
+
return styles.reduce((styleStr, { body, id }) => {
|
|
91
|
+
const idStr = id ? ` id="${id}"` : '';
|
|
92
|
+
return styleStr + `<style type="text/css"${idStr}>${body}</style>\n`;
|
|
93
|
+
}, '');
|
|
94
|
+
}
|
|
95
|
+
/**
|
|
96
|
+
* Serialize head markup metadata into an HTML string
|
|
97
|
+
* @param markup An array of markup metadata objects
|
|
98
|
+
* @returns A string of HTML generated from markup metadata
|
|
99
|
+
*/
|
|
100
|
+
export function createHeadMarkup(markup) {
|
|
101
|
+
// Loop through the <title>, <script>, <meta>, and <link> tag information
|
|
102
|
+
// Create an HTML string for each tag
|
|
103
|
+
let hasTitle = false;
|
|
104
|
+
return markup.reduce((str, { title, scripts = [], meta = [], links = [], styles = [] } = {}) => {
|
|
105
|
+
if (title && !hasTitle) {
|
|
106
|
+
// first <title> wins
|
|
107
|
+
hasTitle = true;
|
|
108
|
+
str += `<title>${title}</title>\n`;
|
|
109
|
+
}
|
|
110
|
+
return (str +
|
|
111
|
+
createMetaTags(meta) +
|
|
112
|
+
createScriptTags(scripts) +
|
|
113
|
+
createLinkTags(links) +
|
|
114
|
+
createStyleTags(styles));
|
|
115
|
+
}, '');
|
|
116
|
+
}
|
|
117
|
+
/**
|
|
118
|
+
* Serialize HeadMarkup config into HTML, then add it to the <head> of a base doc
|
|
119
|
+
* @param markup An array of markup metadata objects
|
|
120
|
+
* @param stringBuilder The string builder for a base document
|
|
121
|
+
*/
|
|
122
|
+
export function addHeadMarkup(markup, stringBuilder) {
|
|
123
|
+
// Create HTML tags for each item in the SsrDataResponse.markup bag
|
|
124
|
+
const headMarkup = createHeadMarkup(markup);
|
|
125
|
+
if (headMarkup) {
|
|
126
|
+
// Add all the links to the <head> section of the base document
|
|
127
|
+
addToHead(headMarkup, stringBuilder);
|
|
128
|
+
}
|
|
129
|
+
}
|
|
130
|
+
/**
|
|
131
|
+
* Add an HTML string to the <head> of a base doc
|
|
132
|
+
* @param markup An HTML string
|
|
133
|
+
* @param stringBuilder The string builder for a base document
|
|
134
|
+
*/
|
|
135
|
+
export function addToHead(markup, stringBuilder) {
|
|
136
|
+
// Create HTML tags for each item in the SsrDataResponse.markup bag
|
|
137
|
+
if (markup) {
|
|
138
|
+
// Add all the links to the <head> section of the base document
|
|
139
|
+
const headIndex = stringBuilder.original.indexOf('</head>');
|
|
140
|
+
if (headIndex >= 0) {
|
|
141
|
+
stringBuilder.prependLeft(headIndex, markup);
|
|
142
|
+
}
|
|
143
|
+
else {
|
|
144
|
+
logger.error('Adding head markup failed. Could not find the </head> tag.');
|
|
145
|
+
}
|
|
146
|
+
}
|
|
147
|
+
}
|
|
70
148
|
//# sourceMappingURL=serialize.js.map
|
package/build/es/tasks.js
CHANGED
|
@@ -1,4 +1,8 @@
|
|
|
1
1
|
class Task {
|
|
2
|
+
taskFunction;
|
|
3
|
+
caller;
|
|
4
|
+
resolve;
|
|
5
|
+
reject;
|
|
2
6
|
constructor(taskFunction, caller, resolve, reject) {
|
|
3
7
|
this.taskFunction = taskFunction;
|
|
4
8
|
this.caller = caller;
|
|
@@ -11,9 +15,10 @@ class Task {
|
|
|
11
15
|
* If more tasks than that are asked to execute they are put in a queue until there is space in the pool
|
|
12
16
|
*/
|
|
13
17
|
export class TaskPool {
|
|
18
|
+
size;
|
|
19
|
+
queue = [];
|
|
20
|
+
running = 0;
|
|
14
21
|
constructor(size) {
|
|
15
|
-
this.queue = [];
|
|
16
|
-
this.running = 0;
|
|
17
22
|
this.size = size || 15;
|
|
18
23
|
}
|
|
19
24
|
/**
|
|
@@ -67,9 +72,7 @@ export class TaskPool {
|
|
|
67
72
|
* If no task of that id is running a new task is created
|
|
68
73
|
*/
|
|
69
74
|
export class InflightTasks {
|
|
70
|
-
|
|
71
|
-
this.tasks = new Map();
|
|
72
|
-
}
|
|
75
|
+
tasks = new Map();
|
|
73
76
|
/**
|
|
74
77
|
* Return a promise per id. If one is already in flight return the promise.
|
|
75
78
|
* If not use the constructor to create a new
|
package/package.json
CHANGED
|
@@ -4,7 +4,7 @@
|
|
|
4
4
|
"publishConfig": {
|
|
5
5
|
"access": "public"
|
|
6
6
|
},
|
|
7
|
-
"version": "0.
|
|
7
|
+
"version": "0.18.0",
|
|
8
8
|
"homepage": "https://developer.salesforce.com/docs/platform/lwr/overview",
|
|
9
9
|
"repository": {
|
|
10
10
|
"type": "git",
|
|
@@ -37,7 +37,7 @@
|
|
|
37
37
|
"build/**/*.d.ts"
|
|
38
38
|
],
|
|
39
39
|
"dependencies": {
|
|
40
|
-
"@lwrjs/diagnostics": "0.
|
|
40
|
+
"@lwrjs/diagnostics": "0.18.0",
|
|
41
41
|
"es-module-lexer": "^1.5.4",
|
|
42
42
|
"fast-json-stable-stringify": "^2.1.0",
|
|
43
43
|
"magic-string": "^0.30.9",
|
|
@@ -50,13 +50,13 @@
|
|
|
50
50
|
"slugify": "^1.4.5"
|
|
51
51
|
},
|
|
52
52
|
"devDependencies": {
|
|
53
|
-
"@lwrjs/types": "0.
|
|
53
|
+
"@lwrjs/types": "0.18.0",
|
|
54
54
|
"@types/mime-types": "2.1.4",
|
|
55
55
|
"@types/path-to-regexp": "^1.7.0",
|
|
56
56
|
"memfs": "^4.13.0"
|
|
57
57
|
},
|
|
58
58
|
"engines": {
|
|
59
|
-
"node": ">=
|
|
59
|
+
"node": ">=20.0.0"
|
|
60
60
|
},
|
|
61
|
-
"gitHead": "
|
|
61
|
+
"gitHead": "763c7c558ea75fe34a91162c9793de63e55f1d2f"
|
|
62
62
|
}
|