@lwrjs/shared-utils 0.10.0-alpha.9 → 0.11.0-alpha.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/bundle.cjs +37 -0
- package/build/cjs/compiler.cjs +1 -21
- package/build/cjs/env.cjs +4 -2
- package/build/cjs/fs.cjs +37 -2
- package/build/cjs/html-meta.cjs +22 -0
- package/build/cjs/identity.cjs +2 -2
- package/build/cjs/import-metadata.cjs +26 -4
- package/build/cjs/index.cjs +1 -1
- package/build/cjs/serialize.cjs +3 -3
- package/build/es/bundle.d.ts +16 -0
- package/build/es/bundle.js +39 -0
- package/build/es/compiler.d.ts +1 -6
- package/build/es/compiler.js +0 -28
- package/build/es/env.js +14 -6
- package/build/es/fs.d.ts +4 -0
- package/build/es/fs.js +38 -1
- package/build/es/html-meta.d.ts +7 -1
- package/build/es/html-meta.js +16 -0
- package/build/es/identity.d.ts +2 -2
- package/build/es/identity.js +2 -2
- package/build/es/import-metadata.d.ts +1 -1
- package/build/es/import-metadata.js +29 -3
- package/build/es/index.d.ts +1 -1
- package/build/es/index.js +1 -1
- package/build/es/interchangeable-modules.d.ts +1 -1
- package/build/es/link.d.ts +1 -1
- package/build/es/lwr-app-observer.d.ts +1 -1
- package/build/es/mappings.d.ts +1 -1
- package/build/es/serialize.js +3 -3
- package/build/es/urls.d.ts +1 -1
- package/package.json +6 -7
- package/build/cjs/site-metadata.cjs +0 -121
- package/build/es/site-metadata.d.ts +0 -27
- package/build/es/site-metadata.js +0 -111
|
@@ -0,0 +1,37 @@
|
|
|
1
|
+
var __defProp = Object.defineProperty;
|
|
2
|
+
var __markAsModule = (target) => __defProp(target, "__esModule", {value: true});
|
|
3
|
+
var __export = (target, all) => {
|
|
4
|
+
for (var name in all)
|
|
5
|
+
__defProp(target, name, {get: all[name], enumerable: true});
|
|
6
|
+
};
|
|
7
|
+
|
|
8
|
+
// packages/@lwrjs/shared-utils/src/bundle.ts
|
|
9
|
+
__markAsModule(exports);
|
|
10
|
+
__export(exports, {
|
|
11
|
+
createAmdAlias: () => createAmdAlias,
|
|
12
|
+
getGroupName: () => getGroupName,
|
|
13
|
+
isGroupie: () => isGroupie
|
|
14
|
+
});
|
|
15
|
+
function getGroupName(rawSpecifier, groupsConfig) {
|
|
16
|
+
for (const [groupName, groupies] of Object.entries(groupsConfig)) {
|
|
17
|
+
if (groupies.indexOf(rawSpecifier) >= 0) {
|
|
18
|
+
return groupName;
|
|
19
|
+
}
|
|
20
|
+
}
|
|
21
|
+
}
|
|
22
|
+
function isGroupie(rawSpecifier, groupsConfig) {
|
|
23
|
+
for (const groupies of Object.values(groupsConfig)) {
|
|
24
|
+
if (groupies.indexOf(rawSpecifier) >= 0) {
|
|
25
|
+
return true;
|
|
26
|
+
}
|
|
27
|
+
}
|
|
28
|
+
return false;
|
|
29
|
+
}
|
|
30
|
+
function createAmdAlias(aliasSpecifier, originalSpecifier) {
|
|
31
|
+
const builder = [];
|
|
32
|
+
builder.push(`LWR.define('${aliasSpecifier}',['exports','${originalSpecifier}'],function(e,m){`);
|
|
33
|
+
builder.push(`e.default=m&&'object'==typeof m&&'default'in m?m.default:m;`);
|
|
34
|
+
builder.push(`Object.keys(m).forEach(function(n){'default'===n||e.hasOwnProperty(n)||Object.defineProperty(e,n,{enumerable:!0,get:function(){return m[n]}})});`);
|
|
35
|
+
builder.push("});");
|
|
36
|
+
return builder.join("");
|
|
37
|
+
}
|
package/build/cjs/compiler.cjs
CHANGED
|
@@ -25,11 +25,8 @@ var __toModule = (module2) => {
|
|
|
25
25
|
__markAsModule(exports);
|
|
26
26
|
__export(exports, {
|
|
27
27
|
AMD_DEFINE: () => AMD_DEFINE,
|
|
28
|
-
convertToAmd: () => convertToAmd
|
|
29
|
-
lockerize: () => lockerize
|
|
28
|
+
convertToAmd: () => convertToAmd
|
|
30
29
|
});
|
|
31
|
-
var import_identity = __toModule(require("./identity.cjs"));
|
|
32
|
-
var import_compiler = __toModule(require("@locker/compiler"));
|
|
33
30
|
var import_rollup = __toModule(require("rollup"));
|
|
34
31
|
var AMD_DEFINE = "LWR.define";
|
|
35
32
|
var AMD_ROLLUP_PLUGIN = function(rootId, source) {
|
|
@@ -61,20 +58,3 @@ async function convertToAmd(source, {id}, forceNamedExports = true) {
|
|
|
61
58
|
const {code} = output[0];
|
|
62
59
|
return {code, map: null};
|
|
63
60
|
}
|
|
64
|
-
function lockerize({compiledSource: source, specifier, moduleEntry: {entry: filename}}, {trustedComponents}, sourcemap = false) {
|
|
65
|
-
const {namespace, name: rawName} = (0, import_identity.explodeSpecifier)(specifier);
|
|
66
|
-
const [name] = rawName.split("#");
|
|
67
|
-
const bareSpecifier = namespace ? `${namespace}/${name}` : name;
|
|
68
|
-
const isJS = filename.endsWith(".js") || filename.endsWith(".mjs") || filename.endsWith(".ts");
|
|
69
|
-
if (isJS && trustedComponents && !trustedComponents.includes(`${namespace}/*`) && !trustedComponents.includes(bareSpecifier)) {
|
|
70
|
-
const {code} = import_compiler.Compiler.compile(source, {
|
|
71
|
-
componentName: name,
|
|
72
|
-
filename,
|
|
73
|
-
sandboxKey: namespace || "sandbox",
|
|
74
|
-
sourcemap,
|
|
75
|
-
remapDynamicImport: true
|
|
76
|
-
});
|
|
77
|
-
return {code, map: null};
|
|
78
|
-
}
|
|
79
|
-
return {code: source, map: null};
|
|
80
|
-
}
|
package/build/cjs/env.cjs
CHANGED
|
@@ -12,9 +12,11 @@ __export(exports, {
|
|
|
12
12
|
});
|
|
13
13
|
function getFeatureFlags() {
|
|
14
14
|
return {
|
|
15
|
+
ASSETS_ON_LAMBDA: process.env.ASSETS_ON_LAMBDA !== void 0 && process.env.ASSETS_ON_LAMBDA.toLowerCase() === "true" ? true : false,
|
|
15
16
|
LEGACY_LOADER: process.env.LEGACY_LOADER !== void 0 && process.env.LEGACY_LOADER.toLowerCase() === "true" ? true : false,
|
|
16
|
-
SSR_STATIC_BUNDLES: process.env.SSR_STATIC_BUNDLES !== void 0 && process.env.SSR_STATIC_BUNDLES.toLowerCase() === "true" ? true : false,
|
|
17
17
|
SSR_SANDBOX_WORKER: process.env.SSR_SANDBOX_WORKER !== void 0 && process.env.SSR_SANDBOX_WORKER.toLowerCase() === "true" ? true : false,
|
|
18
|
-
|
|
18
|
+
SSR_STATIC_BUNDLES: process.env.SSR_STATIC_BUNDLES !== void 0 && process.env.SSR_STATIC_BUNDLES.toLowerCase() === "true" ? true : false,
|
|
19
|
+
EXPERIMENTAL_UNVERSIONED_ALIASES: process.env.EXPERIMENTAL_UNVERSIONED_ALIASES !== void 0 && process.env.EXPERIMENTAL_UNVERSIONED_ALIASES.toLowerCase() === "true" ? true : false,
|
|
20
|
+
LWR_TRACING: process.env.LWR_TRACING !== void 0 && process.env.LWR_TRACING.toLowerCase() !== "off" ? true : false
|
|
19
21
|
};
|
|
20
22
|
}
|
package/build/cjs/fs.cjs
CHANGED
|
@@ -32,7 +32,9 @@ __export(exports, {
|
|
|
32
32
|
normalizeDirectory: () => normalizeDirectory,
|
|
33
33
|
normalizeResourcePath: () => normalizeResourcePath,
|
|
34
34
|
readFile: () => readFile,
|
|
35
|
-
resolveFileExtension: () => resolveFileExtension
|
|
35
|
+
resolveFileExtension: () => resolveFileExtension,
|
|
36
|
+
streamToString: () => streamToString,
|
|
37
|
+
stringToStream: () => stringToStream
|
|
36
38
|
});
|
|
37
39
|
var import_fs = __toModule(require("fs"));
|
|
38
40
|
var import_path = __toModule(require("path"));
|
|
@@ -40,6 +42,7 @@ var import_crypto = __toModule(require("crypto"));
|
|
|
40
42
|
var import_identity = __toModule(require("./identity.cjs"));
|
|
41
43
|
var import_diagnostics = __toModule(require("@lwrjs/diagnostics"));
|
|
42
44
|
var import_mime_types = __toModule(require("mime-types"));
|
|
45
|
+
var import_stream = __toModule(require("stream"));
|
|
43
46
|
var import_logger = __toModule(require("./logger.cjs"));
|
|
44
47
|
var fileCount = 0;
|
|
45
48
|
var files = new Map();
|
|
@@ -144,9 +147,41 @@ function normalizeAssetSpecifier(assetId, assetPathMap, resourcePaths, basePath)
|
|
|
144
147
|
}
|
|
145
148
|
for (const [urlPath, fsPath] of assetPathMap.entries()) {
|
|
146
149
|
const slashPath = urlPath.endsWith("/") ? urlPath : `${urlPath}/`;
|
|
147
|
-
|
|
150
|
+
const fsSlashPath = fsPath.endsWith("/") ? fsPath : `${fsPath}/`;
|
|
151
|
+
if (specifier.startsWith(slashPath)) {
|
|
152
|
+
return specifier.replace(slashPath, fsSlashPath);
|
|
153
|
+
} else if (specifier === urlPath) {
|
|
148
154
|
return specifier.replace(urlPath, fsPath);
|
|
149
155
|
}
|
|
150
156
|
}
|
|
151
157
|
return specifier;
|
|
152
158
|
}
|
|
159
|
+
function streamToString(stream, encoding = "utf8") {
|
|
160
|
+
const chunks = [];
|
|
161
|
+
return new Promise((resolve, reject) => {
|
|
162
|
+
stream.on("data", (c) => chunks.push(c));
|
|
163
|
+
stream.on("error", reject);
|
|
164
|
+
stream.on("end", () => resolve(Buffer.concat(chunks).toString(encoding)));
|
|
165
|
+
});
|
|
166
|
+
}
|
|
167
|
+
function stringToStream(str) {
|
|
168
|
+
let index = 0;
|
|
169
|
+
const isBuffer = Buffer.isBuffer(str);
|
|
170
|
+
const readable = new import_stream.Readable({
|
|
171
|
+
read(size) {
|
|
172
|
+
if (index >= str.length) {
|
|
173
|
+
this.push(null);
|
|
174
|
+
return;
|
|
175
|
+
}
|
|
176
|
+
let chunk;
|
|
177
|
+
if (isBuffer) {
|
|
178
|
+
chunk = str.subarray(index, index + size);
|
|
179
|
+
} else {
|
|
180
|
+
chunk = str.slice(index, index + size);
|
|
181
|
+
}
|
|
182
|
+
index += size;
|
|
183
|
+
this.push(chunk);
|
|
184
|
+
}
|
|
185
|
+
});
|
|
186
|
+
return readable;
|
|
187
|
+
}
|
package/build/cjs/html-meta.cjs
CHANGED
|
@@ -24,7 +24,13 @@ var __toModule = (module2) => {
|
|
|
24
24
|
// packages/@lwrjs/shared-utils/src/html-meta.ts
|
|
25
25
|
__markAsModule(exports);
|
|
26
26
|
__export(exports, {
|
|
27
|
+
HYDRATE_CLIENT_VALUE: () => HYDRATE_CLIENT_VALUE,
|
|
28
|
+
HYDRATE_DIRECTIVE: () => HYDRATE_DIRECTIVE,
|
|
29
|
+
HYDRATE_LOAD_VALUE: () => HYDRATE_LOAD_VALUE,
|
|
27
30
|
extractMetadataFromHtml: () => extractMetadataFromHtml,
|
|
31
|
+
getHydrateDirective: () => getHydrateDirective,
|
|
32
|
+
isCsrIsland: () => isCsrIsland,
|
|
33
|
+
isHydrateOnLoad: () => isHydrateOnLoad,
|
|
28
34
|
isRelative: () => isRelative,
|
|
29
35
|
isSelfUrl: () => isSelfUrl
|
|
30
36
|
});
|
|
@@ -117,3 +123,19 @@ async function extractMetadataFromHtml(htmlSource) {
|
|
|
117
123
|
inputStream.pipe(parser);
|
|
118
124
|
});
|
|
119
125
|
}
|
|
126
|
+
var HYDRATE_DIRECTIVE = "lwr:hydrate";
|
|
127
|
+
var HYDRATE_LOAD_VALUE = "load";
|
|
128
|
+
var HYDRATE_CLIENT_VALUE = "client-only";
|
|
129
|
+
var HYDRATION_VALUES = [HYDRATE_LOAD_VALUE, HYDRATE_CLIENT_VALUE];
|
|
130
|
+
function getHydrateDirective(props = {}) {
|
|
131
|
+
const rawValue = props[HYDRATE_DIRECTIVE];
|
|
132
|
+
const value = rawValue === "true" ? HYDRATE_LOAD_VALUE : rawValue;
|
|
133
|
+
if (HYDRATION_VALUES.includes(value))
|
|
134
|
+
return value;
|
|
135
|
+
}
|
|
136
|
+
function isHydrateOnLoad(props = {}) {
|
|
137
|
+
return getHydrateDirective(props) === HYDRATE_LOAD_VALUE;
|
|
138
|
+
}
|
|
139
|
+
function isCsrIsland(props = {}) {
|
|
140
|
+
return getHydrateDirective(props) === HYDRATE_CLIENT_VALUE;
|
|
141
|
+
}
|
package/build/cjs/identity.cjs
CHANGED
|
@@ -182,11 +182,11 @@ function slugify(name) {
|
|
|
182
182
|
function getPropFromAttrName(propName) {
|
|
183
183
|
return propName.replace(/-([a-z])/g, (g) => g[1].toUpperCase());
|
|
184
184
|
}
|
|
185
|
-
function getModuleUriPrefix({apiVersion, bundle, format, compat, basePath}, {locale, environment} = {}) {
|
|
185
|
+
function getModuleUriPrefix({apiVersion, bundle, format, compat, basePath}, {locale, environment} = {}, bundleId) {
|
|
186
186
|
const localePart = locale ? `/${LOCALE_SIGIL}/${locale}` : "";
|
|
187
187
|
const environmentPart = environment ? `/${ENVIRONMENT_SIGIL}/${environment}` : "";
|
|
188
188
|
if (bundle) {
|
|
189
|
-
return `${basePath}/${apiVersion}/bundle/${format}${localePart}${environmentPart}/${BUNDLE_SIGIL}
|
|
189
|
+
return `${basePath}/${apiVersion}/bundle/${format}${localePart}${environmentPart}/${BUNDLE_SIGIL}/${bundleId || "0"}/module/mi/`;
|
|
190
190
|
} else {
|
|
191
191
|
return `${basePath}/${apiVersion}/module/${format}/${compat}${localePart}${environmentPart}/mi/`;
|
|
192
192
|
}
|
|
@@ -28,6 +28,8 @@ __export(exports, {
|
|
|
28
28
|
getImportMetadata: () => getImportMetadata
|
|
29
29
|
});
|
|
30
30
|
var import_es_module_lexer = __toModule(require("es-module-lexer"));
|
|
31
|
+
var import_logger = __toModule(require("./logger.cjs"));
|
|
32
|
+
var IMPORT_META_REGEX = /^import\.meta(\.\w+)+/;
|
|
31
33
|
var ModuleNameType;
|
|
32
34
|
(function(ModuleNameType2) {
|
|
33
35
|
ModuleNameType2["string"] = "string";
|
|
@@ -36,10 +38,13 @@ var ModuleNameType;
|
|
|
36
38
|
async function getImportMetadata(compiledSource) {
|
|
37
39
|
const imports = [];
|
|
38
40
|
const dynamicImports = [];
|
|
41
|
+
const importMeta = [];
|
|
39
42
|
const [moduleImportLocations] = await (0, import_es_module_lexer.parse)(compiledSource);
|
|
40
43
|
for (const moduleImportLocation of moduleImportLocations) {
|
|
41
44
|
let moduleSpecifier = compiledSource.substring(moduleImportLocation.s, moduleImportLocation.e);
|
|
42
|
-
const
|
|
45
|
+
const isStatic = moduleImportLocation.d === -1;
|
|
46
|
+
const isDynamic = moduleImportLocation.d > -1;
|
|
47
|
+
const isMeta = moduleImportLocation.d === -2;
|
|
43
48
|
const location = {
|
|
44
49
|
startColumn: moduleImportLocation.s,
|
|
45
50
|
endColumn: moduleImportLocation.e
|
|
@@ -48,21 +53,38 @@ async function getImportMetadata(compiledSource) {
|
|
|
48
53
|
const isStringLiteral = moduleSpecifier.startsWith("'") || moduleSpecifier.startsWith('"');
|
|
49
54
|
const moduleNameType = isStringLiteral ? ModuleNameType.string : ModuleNameType.unresolved;
|
|
50
55
|
moduleSpecifier = isStringLiteral ? moduleSpecifier.slice(1, -1) : moduleSpecifier;
|
|
56
|
+
if (import_logger.logger.currentLevel === import_logger.DEBUG || import_logger.logger.currentLevel === import_logger.VERBOSE) {
|
|
57
|
+
import_logger.logger.debug(`[import-metadata] Import from dynamic import ${compiledSource.slice(moduleImportLocation.ss, moduleImportLocation.se)} -> ${compiledSource.slice(moduleImportLocation.ss, moduleImportLocation.s)}`);
|
|
58
|
+
}
|
|
51
59
|
dynamicImports.push({
|
|
52
60
|
moduleSpecifier,
|
|
53
61
|
moduleNameType,
|
|
54
62
|
location,
|
|
55
63
|
importLocation: {
|
|
56
|
-
startColumn: moduleImportLocation.
|
|
64
|
+
startColumn: moduleImportLocation.ss,
|
|
57
65
|
endColumn: moduleImportLocation.s
|
|
58
66
|
}
|
|
59
67
|
});
|
|
60
|
-
} else {
|
|
68
|
+
} else if (isStatic) {
|
|
61
69
|
imports.push({moduleSpecifier, location});
|
|
70
|
+
} else if (isMeta) {
|
|
71
|
+
const metaMatch = IMPORT_META_REGEX.exec(compiledSource.substring(moduleImportLocation.s));
|
|
72
|
+
if (metaMatch) {
|
|
73
|
+
const statement = metaMatch[0];
|
|
74
|
+
const extraLength = statement.length - 11;
|
|
75
|
+
importMeta.push({
|
|
76
|
+
statement,
|
|
77
|
+
location: {
|
|
78
|
+
startColumn: moduleImportLocation.s,
|
|
79
|
+
endColumn: moduleImportLocation.e + extraLength
|
|
80
|
+
}
|
|
81
|
+
});
|
|
82
|
+
}
|
|
62
83
|
}
|
|
63
84
|
}
|
|
64
85
|
return {
|
|
65
86
|
imports,
|
|
66
|
-
dynamicImports
|
|
87
|
+
dynamicImports,
|
|
88
|
+
importMeta
|
|
67
89
|
};
|
|
68
90
|
}
|
package/build/cjs/index.cjs
CHANGED
|
@@ -34,4 +34,4 @@ __exportStar(exports, __toModule(require("./urls.cjs")));
|
|
|
34
34
|
__exportStar(exports, __toModule(require("./env.cjs")));
|
|
35
35
|
__exportStar(exports, __toModule(require("./logger.cjs")));
|
|
36
36
|
__exportStar(exports, __toModule(require("./lwr-app-observer.cjs")));
|
|
37
|
-
__exportStar(exports, __toModule(require("./
|
|
37
|
+
__exportStar(exports, __toModule(require("./bundle.cjs")));
|
package/build/cjs/serialize.cjs
CHANGED
|
@@ -67,13 +67,13 @@ function replaceStringFromLocation(src, {startOffset, endOffset}, replaceValue)
|
|
|
67
67
|
return src.substr(0, startOffset) + replaceValue + src.substr(endOffset, src.length);
|
|
68
68
|
}
|
|
69
69
|
function shortestTtl(newTtl, oldTtl) {
|
|
70
|
-
if (
|
|
70
|
+
if (newTtl === void 0 && oldTtl === void 0)
|
|
71
71
|
return void 0;
|
|
72
72
|
const newSeconds = typeof newTtl === "string" ? (0, import_ms.default)(newTtl) / 1e3 : newTtl;
|
|
73
73
|
const oldSeconds = typeof oldTtl === "string" ? (0, import_ms.default)(oldTtl) / 1e3 : oldTtl;
|
|
74
|
-
if (
|
|
74
|
+
if (newSeconds === void 0)
|
|
75
75
|
return oldSeconds;
|
|
76
|
-
if (
|
|
76
|
+
if (oldSeconds === void 0)
|
|
77
77
|
return newSeconds;
|
|
78
78
|
return newSeconds < oldSeconds ? newSeconds : oldSeconds;
|
|
79
79
|
}
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
import type { BundleGroups } from '@lwrjs/types';
|
|
2
|
+
export declare function getGroupName(rawSpecifier: string, groupsConfig: BundleGroups): string | undefined;
|
|
3
|
+
export declare function isGroupie(rawSpecifier: string, groupsConfig: BundleGroups): boolean;
|
|
4
|
+
/**
|
|
5
|
+
* Create an AMD Alias to another AMD module
|
|
6
|
+
*
|
|
7
|
+
* In the spirit of...
|
|
8
|
+
* LWR.define('alias', 'og', og=>og);
|
|
9
|
+
*
|
|
10
|
+
* But if OG has a default it is exposed as exports.default
|
|
11
|
+
*
|
|
12
|
+
* All enumerable properties of og are exposed as enumerable properties of exports.
|
|
13
|
+
*
|
|
14
|
+
*/
|
|
15
|
+
export declare function createAmdAlias(aliasSpecifier: string, originalSpecifier: string): string;
|
|
16
|
+
//# sourceMappingURL=bundle.d.ts.map
|
|
@@ -0,0 +1,39 @@
|
|
|
1
|
+
export function getGroupName(rawSpecifier, groupsConfig) {
|
|
2
|
+
for (const [groupName, groupies] of Object.entries(groupsConfig)) {
|
|
3
|
+
if (groupies.indexOf(rawSpecifier) >= 0) {
|
|
4
|
+
return groupName;
|
|
5
|
+
}
|
|
6
|
+
}
|
|
7
|
+
}
|
|
8
|
+
export function isGroupie(rawSpecifier, groupsConfig) {
|
|
9
|
+
for (const groupies of Object.values(groupsConfig)) {
|
|
10
|
+
if (groupies.indexOf(rawSpecifier) >= 0) {
|
|
11
|
+
return true;
|
|
12
|
+
}
|
|
13
|
+
}
|
|
14
|
+
return false;
|
|
15
|
+
}
|
|
16
|
+
/**
|
|
17
|
+
* Create an AMD Alias to another AMD module
|
|
18
|
+
*
|
|
19
|
+
* In the spirit of...
|
|
20
|
+
* LWR.define('alias', 'og', og=>og);
|
|
21
|
+
*
|
|
22
|
+
* But if OG has a default it is exposed as exports.default
|
|
23
|
+
*
|
|
24
|
+
* All enumerable properties of og are exposed as enumerable properties of exports.
|
|
25
|
+
*
|
|
26
|
+
*/
|
|
27
|
+
export function createAmdAlias(aliasSpecifier, originalSpecifier) {
|
|
28
|
+
const builder = [];
|
|
29
|
+
// Define statement
|
|
30
|
+
builder.push(`LWR.define('${aliasSpecifier}',['exports','${originalSpecifier}'],function(e,m){`);
|
|
31
|
+
// un-wrap default
|
|
32
|
+
builder.push(`e.default=m&&'object'==typeof m&&'default'in m?m.default:m;`);
|
|
33
|
+
// Expose enumerable properties
|
|
34
|
+
builder.push(`Object.keys(m).forEach(function(n){'default'===n||e.hasOwnProperty(n)||Object.defineProperty(e,n,{enumerable:!0,get:function(){return m[n]}})});`);
|
|
35
|
+
// End the define
|
|
36
|
+
builder.push('});');
|
|
37
|
+
return builder.join('');
|
|
38
|
+
}
|
|
39
|
+
//# sourceMappingURL=bundle.js.map
|
package/build/es/compiler.d.ts
CHANGED
|
@@ -1,15 +1,10 @@
|
|
|
1
|
-
import type { CompilerResult
|
|
1
|
+
import type { CompilerResult } from '@lwrjs/types';
|
|
2
2
|
/**
|
|
3
3
|
* When importing these modules make sure the optional dependencies are installed:
|
|
4
4
|
* - 'rollup' for convertToAmd()
|
|
5
|
-
* - '@locker/compiler' for lockerize()
|
|
6
5
|
*/
|
|
7
6
|
export declare const AMD_DEFINE = "LWR.define";
|
|
8
7
|
export declare function convertToAmd(source: string, { id }: {
|
|
9
8
|
id: string;
|
|
10
9
|
}, forceNamedExports?: boolean): Promise<CompilerResult>;
|
|
11
|
-
/** Locker
|
|
12
|
-
* Trusted Components can contain namespaces with wildcard or single component
|
|
13
|
-
*/
|
|
14
|
-
export declare function lockerize({ compiledSource: source, specifier, moduleEntry: { entry: filename } }: ModuleCompiled, { trustedComponents }: LwrLockerConfig, sourcemap?: boolean): CompilerResult;
|
|
15
10
|
//# sourceMappingURL=compiler.d.ts.map
|
package/build/es/compiler.js
CHANGED
|
@@ -1,10 +1,7 @@
|
|
|
1
|
-
import { explodeSpecifier } from './identity.js';
|
|
2
|
-
import { Compiler as Locker } from '@locker/compiler';
|
|
3
1
|
import { rollup } from 'rollup';
|
|
4
2
|
/**
|
|
5
3
|
* When importing these modules make sure the optional dependencies are installed:
|
|
6
4
|
* - 'rollup' for convertToAmd()
|
|
7
|
-
* - '@locker/compiler' for lockerize()
|
|
8
5
|
*/
|
|
9
6
|
export const AMD_DEFINE = 'LWR.define';
|
|
10
7
|
const AMD_ROLLUP_PLUGIN = function (rootId, source) {
|
|
@@ -37,29 +34,4 @@ export async function convertToAmd(source, { id }, forceNamedExports = true) {
|
|
|
37
34
|
const { code } = output[0];
|
|
38
35
|
return { code, map: null };
|
|
39
36
|
}
|
|
40
|
-
/** Locker
|
|
41
|
-
* Trusted Components can contain namespaces with wildcard or single component
|
|
42
|
-
*/
|
|
43
|
-
export function lockerize({ compiledSource: source, specifier, moduleEntry: { entry: filename } }, { trustedComponents }, sourcemap = false) {
|
|
44
|
-
const { namespace, name: rawName } = explodeSpecifier(specifier);
|
|
45
|
-
const [name] = rawName.split('#');
|
|
46
|
-
const bareSpecifier = namespace ? `${namespace}/${name}` : name;
|
|
47
|
-
const isJS = filename.endsWith('.js') || filename.endsWith('.mjs') || filename.endsWith('.ts');
|
|
48
|
-
// lockerize if component is JS and is not explicitly trusted or in a trusted namespace
|
|
49
|
-
if (isJS &&
|
|
50
|
-
trustedComponents &&
|
|
51
|
-
!trustedComponents.includes(`${namespace}/*`) &&
|
|
52
|
-
!trustedComponents.includes(bareSpecifier)) {
|
|
53
|
-
const { code } = Locker.compile(source, {
|
|
54
|
-
componentName: name,
|
|
55
|
-
filename,
|
|
56
|
-
// put non-namespaced modules in a single sandbox - this should only be non-lwc npm modules
|
|
57
|
-
sandboxKey: namespace || 'sandbox',
|
|
58
|
-
sourcemap,
|
|
59
|
-
remapDynamicImport: true, // support for dynamic imports
|
|
60
|
-
});
|
|
61
|
-
return { code, map: null };
|
|
62
|
-
}
|
|
63
|
-
return { code: source, map: null };
|
|
64
|
-
}
|
|
65
37
|
//# sourceMappingURL=compiler.js.map
|
package/build/es/env.js
CHANGED
|
@@ -1,23 +1,31 @@
|
|
|
1
1
|
export function getFeatureFlags() {
|
|
2
2
|
// Add any new feature flags here to parse from environment variables
|
|
3
3
|
return {
|
|
4
|
+
// Should we load load the assets from the lambda on MRT
|
|
5
|
+
ASSETS_ON_LAMBDA: process.env.ASSETS_ON_LAMBDA !== undefined &&
|
|
6
|
+
process.env.ASSETS_ON_LAMBDA.toLowerCase() === 'true'
|
|
7
|
+
? true
|
|
8
|
+
: false,
|
|
4
9
|
// DEFAULT LEGACY_LOADER = false;
|
|
5
10
|
LEGACY_LOADER: process.env.LEGACY_LOADER !== undefined && process.env.LEGACY_LOADER.toLowerCase() === 'true'
|
|
6
11
|
? true
|
|
7
12
|
: false,
|
|
13
|
+
// Should we use a js worker for SSR, sand-boxing = false (use locker for ssr sand-boxing)
|
|
14
|
+
SSR_SANDBOX_WORKER: process.env.SSR_SANDBOX_WORKER !== undefined &&
|
|
15
|
+
process.env.SSR_SANDBOX_WORKER.toLowerCase() === 'true'
|
|
16
|
+
? true
|
|
17
|
+
: false,
|
|
8
18
|
// SSR should concatenate bundles, default = false
|
|
9
19
|
SSR_STATIC_BUNDLES: process.env.SSR_STATIC_BUNDLES !== undefined &&
|
|
10
20
|
process.env.SSR_STATIC_BUNDLES.toLowerCase() === 'true'
|
|
11
21
|
? true
|
|
12
22
|
: false,
|
|
13
|
-
//
|
|
14
|
-
|
|
15
|
-
process.env.
|
|
23
|
+
// AMD Module Bundles include un-versioned aliases
|
|
24
|
+
EXPERIMENTAL_UNVERSIONED_ALIASES: process.env.EXPERIMENTAL_UNVERSIONED_ALIASES !== undefined &&
|
|
25
|
+
process.env.EXPERIMENTAL_UNVERSIONED_ALIASES.toLowerCase() === 'true'
|
|
16
26
|
? true
|
|
17
27
|
: false,
|
|
18
|
-
|
|
19
|
-
ASSETS_ON_LAMBDA: process.env.ASSETS_ON_LAMBDA !== undefined &&
|
|
20
|
-
process.env.ASSETS_ON_LAMBDA.toLowerCase() === 'true'
|
|
28
|
+
LWR_TRACING: process.env.LWR_TRACING !== undefined && process.env.LWR_TRACING.toLowerCase() !== 'off'
|
|
21
29
|
? true
|
|
22
30
|
: false,
|
|
23
31
|
};
|
package/build/es/fs.d.ts
CHANGED
|
@@ -1,6 +1,8 @@
|
|
|
1
1
|
/// <reference types="node" />
|
|
2
|
+
/// <reference types="node" />
|
|
2
3
|
import type { AssetIdentifier, ResourcePaths, ViewSource } from '@lwrjs/types';
|
|
3
4
|
import { lookup } from 'mime-types';
|
|
5
|
+
import { Readable } from 'stream';
|
|
4
6
|
/**
|
|
5
7
|
* Create a hash string for a source
|
|
6
8
|
* @param source
|
|
@@ -36,4 +38,6 @@ export { lookup as mimeLookup };
|
|
|
36
38
|
* Tries to convert any URL or $aliased path into a canonical fs path
|
|
37
39
|
*/
|
|
38
40
|
export declare function normalizeAssetSpecifier(assetId: AssetIdentifier, assetPathMap: Map<string, string>, resourcePaths: ResourcePaths, basePath: string): string;
|
|
41
|
+
export declare function streamToString(stream: Readable, encoding?: BufferEncoding): Promise<string>;
|
|
42
|
+
export declare function stringToStream(str: string | Buffer): Readable;
|
|
39
43
|
//# sourceMappingURL=fs.d.ts.map
|
package/build/es/fs.js
CHANGED
|
@@ -4,6 +4,7 @@ import crypto from 'crypto';
|
|
|
4
4
|
import { slugify } from './identity.js';
|
|
5
5
|
import { LwrUnresolvableError, createSingleDiagnosticError, descriptions } from '@lwrjs/diagnostics';
|
|
6
6
|
import { lookup } from 'mime-types';
|
|
7
|
+
import { Readable } from 'stream';
|
|
7
8
|
import { DEBUG, logger, VERBOSE } from './logger.js';
|
|
8
9
|
let fileCount = 0;
|
|
9
10
|
const files = new Map();
|
|
@@ -157,10 +158,46 @@ export function normalizeAssetSpecifier(assetId, assetPathMap, resourcePaths, ba
|
|
|
157
158
|
// - Individual files: the asset specifier is equal to a configured assets[i].urlPath
|
|
158
159
|
for (const [urlPath, fsPath] of assetPathMap.entries()) {
|
|
159
160
|
const slashPath = urlPath.endsWith('/') ? urlPath : `${urlPath}/`;
|
|
160
|
-
|
|
161
|
+
const fsSlashPath = fsPath.endsWith('/') ? fsPath : `${fsPath}/`;
|
|
162
|
+
// Matches directory
|
|
163
|
+
if (specifier.startsWith(slashPath)) {
|
|
164
|
+
return specifier.replace(slashPath, fsSlashPath);
|
|
165
|
+
// Matches File
|
|
166
|
+
}
|
|
167
|
+
else if (specifier === urlPath) {
|
|
161
168
|
return specifier.replace(urlPath, fsPath);
|
|
162
169
|
}
|
|
163
170
|
}
|
|
164
171
|
return specifier;
|
|
165
172
|
}
|
|
173
|
+
export function streamToString(stream, encoding = 'utf8') {
|
|
174
|
+
const chunks = [];
|
|
175
|
+
return new Promise((resolve, reject) => {
|
|
176
|
+
stream.on('data', (c) => chunks.push(c));
|
|
177
|
+
stream.on('error', reject);
|
|
178
|
+
stream.on('end', () => resolve(Buffer.concat(chunks).toString(encoding)));
|
|
179
|
+
});
|
|
180
|
+
}
|
|
181
|
+
export function stringToStream(str) {
|
|
182
|
+
let index = 0;
|
|
183
|
+
const isBuffer = Buffer.isBuffer(str);
|
|
184
|
+
const readable = new Readable({
|
|
185
|
+
read(size) {
|
|
186
|
+
if (index >= str.length) {
|
|
187
|
+
this.push(null);
|
|
188
|
+
return;
|
|
189
|
+
}
|
|
190
|
+
let chunk;
|
|
191
|
+
if (isBuffer) {
|
|
192
|
+
chunk = str.subarray(index, index + size);
|
|
193
|
+
}
|
|
194
|
+
else {
|
|
195
|
+
chunk = str.slice(index, index + size);
|
|
196
|
+
}
|
|
197
|
+
index += size;
|
|
198
|
+
this.push(chunk);
|
|
199
|
+
},
|
|
200
|
+
});
|
|
201
|
+
return readable;
|
|
202
|
+
}
|
|
166
203
|
//# sourceMappingURL=fs.js.map
|
package/build/es/html-meta.d.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { RenderedViewMetadata } from '@lwrjs/types';
|
|
1
|
+
import type { RenderedViewMetadata } from '@lwrjs/types';
|
|
2
2
|
export declare function isRelative(url: string): boolean;
|
|
3
3
|
export declare function isSelfUrl(url: string): boolean;
|
|
4
4
|
/**
|
|
@@ -6,4 +6,10 @@ export declare function isSelfUrl(url: string): boolean;
|
|
|
6
6
|
* @param htmlSource - An HTML string to parse
|
|
7
7
|
*/
|
|
8
8
|
export declare function extractMetadataFromHtml(htmlSource: string): Promise<RenderedViewMetadata>;
|
|
9
|
+
export declare const HYDRATE_DIRECTIVE = "lwr:hydrate";
|
|
10
|
+
export declare const HYDRATE_LOAD_VALUE = "load";
|
|
11
|
+
export declare const HYDRATE_CLIENT_VALUE = "client-only";
|
|
12
|
+
export declare function getHydrateDirective(props?: Record<string, string>): string | undefined;
|
|
13
|
+
export declare function isHydrateOnLoad(props?: {}): boolean;
|
|
14
|
+
export declare function isCsrIsland(props?: {}): boolean;
|
|
9
15
|
//# sourceMappingURL=html-meta.d.ts.map
|
package/build/es/html-meta.js
CHANGED
|
@@ -105,4 +105,20 @@ export async function extractMetadataFromHtml(htmlSource) {
|
|
|
105
105
|
inputStream.pipe(parser);
|
|
106
106
|
});
|
|
107
107
|
}
|
|
108
|
+
export const HYDRATE_DIRECTIVE = 'lwr:hydrate';
|
|
109
|
+
export const HYDRATE_LOAD_VALUE = 'load';
|
|
110
|
+
export const HYDRATE_CLIENT_VALUE = 'client-only';
|
|
111
|
+
const HYDRATION_VALUES = [HYDRATE_LOAD_VALUE, HYDRATE_CLIENT_VALUE];
|
|
112
|
+
export function getHydrateDirective(props = {}) {
|
|
113
|
+
const rawValue = props[HYDRATE_DIRECTIVE];
|
|
114
|
+
const value = rawValue === 'true' ? HYDRATE_LOAD_VALUE : rawValue; // valueless hyration directives => lwr:hydrate="load"
|
|
115
|
+
if (HYDRATION_VALUES.includes(value))
|
|
116
|
+
return value;
|
|
117
|
+
}
|
|
118
|
+
export function isHydrateOnLoad(props = {}) {
|
|
119
|
+
return getHydrateDirective(props) === HYDRATE_LOAD_VALUE;
|
|
120
|
+
}
|
|
121
|
+
export function isCsrIsland(props = {}) {
|
|
122
|
+
return getHydrateDirective(props) === HYDRATE_CLIENT_VALUE;
|
|
123
|
+
}
|
|
108
124
|
//# sourceMappingURL=html-meta.js.map
|
package/build/es/identity.d.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import getCacheKeyFromJson from 'fast-json-stable-stringify';
|
|
2
|
-
import { AbstractModuleId, AssetSource, BundleDefinition, ModuleDefinition, NormalizedLwrAppBootstrapConfig, PublicModuleRegistry, RuntimeEnvironment, RuntimeParams } from '@lwrjs/types';
|
|
2
|
+
import type { AbstractModuleId, AssetSource, BundleDefinition, ModuleDefinition, NormalizedLwrAppBootstrapConfig, PublicModuleRegistry, RuntimeEnvironment, RuntimeParams } from '@lwrjs/types';
|
|
3
3
|
export declare const VERSION_SIGIL = "/v/";
|
|
4
4
|
export declare const LOCALE_SIGIL = "l";
|
|
5
5
|
export declare const ENVIRONMENT_SIGIL = "e";
|
|
@@ -129,7 +129,7 @@ export declare function getPropFromAttrName(propName: string): string;
|
|
|
129
129
|
* @param param0 - URI props from the Runtime Environment
|
|
130
130
|
* @param param1 - URI props from the Runtime Params
|
|
131
131
|
*/
|
|
132
|
-
export declare function getModuleUriPrefix({ apiVersion, bundle, format, compat, basePath }: RuntimeEnvironment, { locale, environment }?: RuntimeParams): string;
|
|
132
|
+
export declare function getModuleUriPrefix({ apiVersion, bundle, format, compat, basePath }: RuntimeEnvironment, { locale, environment }?: RuntimeParams, bundleId?: string): string;
|
|
133
133
|
/**
|
|
134
134
|
* Create a URI Mapping API URI prefix, stopping where the specifiers would be (at "mp/")
|
|
135
135
|
* @param param0 - URI props from the Runtime Environment
|
package/build/es/identity.js
CHANGED
|
@@ -221,11 +221,11 @@ export function getPropFromAttrName(propName) {
|
|
|
221
221
|
* @param param0 - URI props from the Runtime Environment
|
|
222
222
|
* @param param1 - URI props from the Runtime Params
|
|
223
223
|
*/
|
|
224
|
-
export function getModuleUriPrefix({ apiVersion, bundle, format, compat, basePath }, { locale, environment } = {}) {
|
|
224
|
+
export function getModuleUriPrefix({ apiVersion, bundle, format, compat, basePath }, { locale, environment } = {}, bundleId) {
|
|
225
225
|
const localePart = locale ? `/${LOCALE_SIGIL}/${locale}` : '';
|
|
226
226
|
const environmentPart = environment ? `/${ENVIRONMENT_SIGIL}/${environment}` : '';
|
|
227
227
|
if (bundle) {
|
|
228
|
-
return `${basePath}/${apiVersion}/bundle/${format}${localePart}${environmentPart}/${BUNDLE_SIGIL}
|
|
228
|
+
return `${basePath}/${apiVersion}/bundle/${format}${localePart}${environmentPart}/${BUNDLE_SIGIL}/${bundleId || '0'}/module/mi/`;
|
|
229
229
|
}
|
|
230
230
|
else {
|
|
231
231
|
return `${basePath}/${apiVersion}/module/${format}/${compat}${localePart}${environmentPart}/mi/`;
|
|
@@ -1,4 +1,6 @@
|
|
|
1
1
|
import { parse as parseImports } from 'es-module-lexer';
|
|
2
|
+
import { DEBUG, logger, VERBOSE } from './logger.js';
|
|
3
|
+
const IMPORT_META_REGEX = /^import\.meta(\.\w+)+/;
|
|
2
4
|
export var ModuleNameType;
|
|
3
5
|
(function (ModuleNameType) {
|
|
4
6
|
ModuleNameType["string"] = "string";
|
|
@@ -7,12 +9,15 @@ export var ModuleNameType;
|
|
|
7
9
|
export async function getImportMetadata(compiledSource) {
|
|
8
10
|
const imports = [];
|
|
9
11
|
const dynamicImports = [];
|
|
12
|
+
const importMeta = [];
|
|
10
13
|
// Use very fast parser to get the location of the imports/exports
|
|
11
14
|
const [moduleImportLocations] = await parseImports(compiledSource);
|
|
12
15
|
for (const moduleImportLocation of moduleImportLocations) {
|
|
13
16
|
// This will give us the source specifier of the import (ex. import x from "bar" <= will get us bar)
|
|
14
17
|
let moduleSpecifier = compiledSource.substring(moduleImportLocation.s, moduleImportLocation.e);
|
|
15
|
-
const
|
|
18
|
+
const isStatic = moduleImportLocation.d === -1;
|
|
19
|
+
const isDynamic = moduleImportLocation.d > -1;
|
|
20
|
+
const isMeta = moduleImportLocation.d === -2;
|
|
16
21
|
const location = {
|
|
17
22
|
startColumn: moduleImportLocation.s,
|
|
18
23
|
endColumn: moduleImportLocation.e,
|
|
@@ -21,23 +26,44 @@ export async function getImportMetadata(compiledSource) {
|
|
|
21
26
|
const isStringLiteral = moduleSpecifier.startsWith("'") || moduleSpecifier.startsWith('"');
|
|
22
27
|
const moduleNameType = isStringLiteral ? ModuleNameType.string : ModuleNameType.unresolved;
|
|
23
28
|
moduleSpecifier = isStringLiteral ? moduleSpecifier.slice(1, -1) : moduleSpecifier; // remove quotes
|
|
29
|
+
// Expecting: import(rootSpecifier) -> import(
|
|
30
|
+
if (logger.currentLevel === DEBUG || logger.currentLevel === VERBOSE) {
|
|
31
|
+
logger.debug(`[import-metadata] Import from dynamic import ${compiledSource.slice(moduleImportLocation.ss, moduleImportLocation.se)} -> ${compiledSource.slice(moduleImportLocation.ss, moduleImportLocation.s)}`);
|
|
32
|
+
}
|
|
24
33
|
dynamicImports.push({
|
|
25
34
|
moduleSpecifier,
|
|
26
35
|
moduleNameType,
|
|
27
36
|
location,
|
|
28
37
|
importLocation: {
|
|
29
|
-
startColumn: moduleImportLocation.
|
|
38
|
+
startColumn: moduleImportLocation.ss,
|
|
30
39
|
endColumn: moduleImportLocation.s,
|
|
31
40
|
},
|
|
32
41
|
});
|
|
33
42
|
}
|
|
34
|
-
else {
|
|
43
|
+
else if (isStatic) {
|
|
35
44
|
imports.push({ moduleSpecifier, location });
|
|
36
45
|
}
|
|
46
|
+
else if (isMeta) {
|
|
47
|
+
// moduleImportLocation.s => moduleImportLocation.e only captures "import.meta"
|
|
48
|
+
// this regex will capture the entire statement, eg: `import.meta.env.SSR"
|
|
49
|
+
const metaMatch = IMPORT_META_REGEX.exec(compiledSource.substring(moduleImportLocation.s));
|
|
50
|
+
if (metaMatch) {
|
|
51
|
+
const statement = metaMatch[0];
|
|
52
|
+
const extraLength = statement.length - 11; // to include meta property, eg: ".env.SSR"
|
|
53
|
+
importMeta.push({
|
|
54
|
+
statement,
|
|
55
|
+
location: {
|
|
56
|
+
startColumn: moduleImportLocation.s,
|
|
57
|
+
endColumn: moduleImportLocation.e + extraLength,
|
|
58
|
+
},
|
|
59
|
+
});
|
|
60
|
+
}
|
|
61
|
+
}
|
|
37
62
|
}
|
|
38
63
|
return {
|
|
39
64
|
imports,
|
|
40
65
|
dynamicImports,
|
|
66
|
+
importMeta,
|
|
41
67
|
};
|
|
42
68
|
}
|
|
43
69
|
//# sourceMappingURL=import-metadata.js.map
|
package/build/es/index.d.ts
CHANGED
package/build/es/index.js
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { InterchangeableModuleRecord, LwcConfig, ResolverModuleRecord, InterchangeableModuleMap } from '@lwrjs/types';
|
|
1
|
+
import type { InterchangeableModuleRecord, LwcConfig, ResolverModuleRecord, InterchangeableModuleMap } from '@lwrjs/types';
|
|
2
2
|
/**
|
|
3
3
|
* Traverses LWC configurations to find all possible interchangeable modules
|
|
4
4
|
*
|
package/build/es/link.d.ts
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
/// <reference types="node" />
|
|
2
2
|
import { EventEmitter } from 'events';
|
|
3
|
-
import { ModuleCompiled, LwrAppEmitter, LwrAppObserver, ModuleDefinitionChangedEvent, ModuleSourceChangedEvent, CompiledView, AssetSource, AssetSourceChangedEvent, ViewSourceChangedEvent } from '@lwrjs/types';
|
|
3
|
+
import type { ModuleCompiled, LwrAppEmitter, LwrAppObserver, ModuleDefinitionChangedEvent, ModuleSourceChangedEvent, CompiledView, AssetSource, AssetSourceChangedEvent, ViewSourceChangedEvent } from '@lwrjs/types';
|
|
4
4
|
declare class LwrEmitter implements LwrAppEmitter {
|
|
5
5
|
observer: LwrApplicationObserver;
|
|
6
6
|
constructor(observer: LwrApplicationObserver);
|
package/build/es/mappings.d.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { AbstractModuleId, FlattenedModuleGraphs, ImportMetadata, ModuleBundler, ModuleRegistry, RuntimeEnvironment, RuntimeParams } from '@lwrjs/types';
|
|
1
|
+
import type { AbstractModuleId, FlattenedModuleGraphs, ImportMetadata, ModuleBundler, ModuleRegistry, RuntimeEnvironment, RuntimeParams } from '@lwrjs/types';
|
|
2
2
|
/**
|
|
3
3
|
* Get the Import Metadata for the LWR Mapping Api (https://rfcs.lwc.dev/rfcs/lwr/0000-mapping-api)
|
|
4
4
|
*/
|
package/build/es/serialize.js
CHANGED
|
@@ -50,13 +50,13 @@ export function replaceStringFromLocation(src, { startOffset, endOffset }, repla
|
|
|
50
50
|
* @returns - the shorter of the two TTLs IN SECONDS, undefined if both TTLs are missing
|
|
51
51
|
*/
|
|
52
52
|
export function shortestTtl(newTtl, oldTtl) {
|
|
53
|
-
if (
|
|
53
|
+
if (newTtl === undefined && oldTtl === undefined)
|
|
54
54
|
return undefined;
|
|
55
55
|
const newSeconds = typeof newTtl === 'string' ? ms(newTtl) / 1000 : newTtl;
|
|
56
56
|
const oldSeconds = typeof oldTtl === 'string' ? ms(oldTtl) / 1000 : oldTtl;
|
|
57
|
-
if (
|
|
57
|
+
if (newSeconds === undefined)
|
|
58
58
|
return oldSeconds;
|
|
59
|
-
if (
|
|
59
|
+
if (oldSeconds === undefined)
|
|
60
60
|
return newSeconds;
|
|
61
61
|
return newSeconds < oldSeconds ? newSeconds : oldSeconds;
|
|
62
62
|
}
|
package/build/es/urls.d.ts
CHANGED
package/package.json
CHANGED
|
@@ -4,7 +4,7 @@
|
|
|
4
4
|
"publishConfig": {
|
|
5
5
|
"access": "public"
|
|
6
6
|
},
|
|
7
|
-
"version": "0.
|
|
7
|
+
"version": "0.11.0-alpha.0",
|
|
8
8
|
"homepage": "https://developer.salesforce.com/docs/platform/lwr/overview",
|
|
9
9
|
"repository": {
|
|
10
10
|
"type": "git",
|
|
@@ -45,7 +45,7 @@
|
|
|
45
45
|
"build/**/*.d.ts"
|
|
46
46
|
],
|
|
47
47
|
"dependencies": {
|
|
48
|
-
"es-module-lexer": "^
|
|
48
|
+
"es-module-lexer": "^1.2.1",
|
|
49
49
|
"fast-json-stable-stringify": "^2.1.0",
|
|
50
50
|
"magic-string": "^0.30.0",
|
|
51
51
|
"mime-types": "^2.1.33",
|
|
@@ -56,19 +56,18 @@
|
|
|
56
56
|
"slugify": "^1.4.5"
|
|
57
57
|
},
|
|
58
58
|
"peerDependencies": {
|
|
59
|
-
"@locker/compiler": "0.19.0",
|
|
60
59
|
"chokidar": "^3.5.3",
|
|
61
60
|
"esbuild": "^0.9.7",
|
|
62
61
|
"rollup": "^2.78.0"
|
|
63
62
|
},
|
|
64
63
|
"devDependencies": {
|
|
65
|
-
"@lwrjs/diagnostics": "0.
|
|
66
|
-
"@lwrjs/types": "0.
|
|
64
|
+
"@lwrjs/diagnostics": "0.11.0-alpha.0",
|
|
65
|
+
"@lwrjs/types": "0.11.0-alpha.0",
|
|
67
66
|
"@types/mime-types": "2.1.1",
|
|
68
67
|
"@types/path-to-regexp": "^1.7.0"
|
|
69
68
|
},
|
|
70
69
|
"engines": {
|
|
71
|
-
"node": ">=16.0.0
|
|
70
|
+
"node": ">=16.0.0"
|
|
72
71
|
},
|
|
73
|
-
"gitHead": "
|
|
72
|
+
"gitHead": "6917abefe32752eeed0f9ba98505ca2b76f1df9d"
|
|
74
73
|
}
|
|
@@ -1,121 +0,0 @@
|
|
|
1
|
-
var __create = Object.create;
|
|
2
|
-
var __defProp = Object.defineProperty;
|
|
3
|
-
var __getProtoOf = Object.getPrototypeOf;
|
|
4
|
-
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
5
|
-
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
6
|
-
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
7
|
-
var __markAsModule = (target) => __defProp(target, "__esModule", {value: true});
|
|
8
|
-
var __export = (target, all) => {
|
|
9
|
-
for (var name in all)
|
|
10
|
-
__defProp(target, name, {get: all[name], enumerable: true});
|
|
11
|
-
};
|
|
12
|
-
var __exportStar = (target, module2, desc) => {
|
|
13
|
-
if (module2 && typeof module2 === "object" || typeof module2 === "function") {
|
|
14
|
-
for (let key of __getOwnPropNames(module2))
|
|
15
|
-
if (!__hasOwnProp.call(target, key) && key !== "default")
|
|
16
|
-
__defProp(target, key, {get: () => module2[key], enumerable: !(desc = __getOwnPropDesc(module2, key)) || desc.enumerable});
|
|
17
|
-
}
|
|
18
|
-
return target;
|
|
19
|
-
};
|
|
20
|
-
var __toModule = (module2) => {
|
|
21
|
-
return __exportStar(__markAsModule(__defProp(module2 != null ? __create(__getProtoOf(module2)) : {}, "default", module2 && module2.__esModule && "default" in module2 ? {get: () => module2.default, enumerable: true} : {value: module2, enumerable: true})), module2);
|
|
22
|
-
};
|
|
23
|
-
|
|
24
|
-
// packages/@lwrjs/shared-utils/src/site-metadata.ts
|
|
25
|
-
__markAsModule(exports);
|
|
26
|
-
__export(exports, {
|
|
27
|
-
SiteMetadataImpl: () => SiteMetadataImpl
|
|
28
|
-
});
|
|
29
|
-
var import_path = __toModule(require("path"));
|
|
30
|
-
var import_fs_extra = __toModule(require("fs-extra"));
|
|
31
|
-
var import_logger = __toModule(require("./logger.cjs"));
|
|
32
|
-
var SITE_METADATA_PATH = ".metadata";
|
|
33
|
-
var STATIC_BUNDLE_METADATA_PATH = import_path.default.join(SITE_METADATA_PATH, "/bundle-metadata.json");
|
|
34
|
-
var STATIC_RESOURCE_METADATA_PATH = import_path.default.join(SITE_METADATA_PATH, "/resource-metadata.json");
|
|
35
|
-
var STATIC_ASSET_METADATA_PATH = import_path.default.join(SITE_METADATA_PATH, "/asset-metadata.json");
|
|
36
|
-
var SiteMetadataImpl = class {
|
|
37
|
-
constructor(options) {
|
|
38
|
-
this.options = options;
|
|
39
|
-
this.siteBundles = this.readStaticBundleMetadata(options.rootDir);
|
|
40
|
-
this.siteResources = this.readStaticResourceMetadata(options.rootDir);
|
|
41
|
-
this.siteAssets = this.readStaticAssetsMetadata(options.rootDir);
|
|
42
|
-
}
|
|
43
|
-
getSiteRootDir() {
|
|
44
|
-
return this.options.rootDir;
|
|
45
|
-
}
|
|
46
|
-
getSiteBundles() {
|
|
47
|
-
return this.siteBundles;
|
|
48
|
-
}
|
|
49
|
-
getSiteResources() {
|
|
50
|
-
return this.siteResources;
|
|
51
|
-
}
|
|
52
|
-
getSiteAssets() {
|
|
53
|
-
return this.siteAssets;
|
|
54
|
-
}
|
|
55
|
-
async persistSiteMetadata() {
|
|
56
|
-
const siteMetadataPath = import_path.default.join(this.options.rootDir, SITE_METADATA_PATH);
|
|
57
|
-
try {
|
|
58
|
-
if (!await import_fs_extra.default.pathExists(siteMetadataPath)) {
|
|
59
|
-
await import_fs_extra.default.mkdir(siteMetadataPath, {recursive: true});
|
|
60
|
-
}
|
|
61
|
-
const bundleMetadataPath = import_path.default.join(this.options.rootDir, STATIC_BUNDLE_METADATA_PATH);
|
|
62
|
-
await import_fs_extra.default.writeJSON(bundleMetadataPath, this.siteBundles, {spaces: 2});
|
|
63
|
-
const resourceMetadataPath = import_path.default.join(this.options.rootDir, STATIC_RESOURCE_METADATA_PATH);
|
|
64
|
-
await import_fs_extra.default.writeJSON(resourceMetadataPath, this.siteResources, {spaces: 2});
|
|
65
|
-
const assetMetadataPath = import_path.default.join(this.options.rootDir, STATIC_ASSET_METADATA_PATH);
|
|
66
|
-
return import_fs_extra.default.writeJSON(assetMetadataPath, this.siteAssets, {spaces: 2});
|
|
67
|
-
} catch (err) {
|
|
68
|
-
console.error(`[SiteMetadata] Failed to save site metadata ${siteMetadataPath}`);
|
|
69
|
-
console.error(err);
|
|
70
|
-
}
|
|
71
|
-
}
|
|
72
|
-
readStaticBundleMetadata(staticRoot) {
|
|
73
|
-
let bundleMetadataPath;
|
|
74
|
-
let siteBundles = {bundles: {}};
|
|
75
|
-
try {
|
|
76
|
-
bundleMetadataPath = import_path.default.join(staticRoot, STATIC_BUNDLE_METADATA_PATH);
|
|
77
|
-
const savedMetadata = import_fs_extra.default.readJSONSync(bundleMetadataPath);
|
|
78
|
-
siteBundles = savedMetadata;
|
|
79
|
-
} catch (error) {
|
|
80
|
-
if (error.code === "ENOENT") {
|
|
81
|
-
import_logger.logger.debug(`[SiteMetadata] Failed to load Static Bundle Metadata: ${bundleMetadataPath}`);
|
|
82
|
-
} else {
|
|
83
|
-
throw error;
|
|
84
|
-
}
|
|
85
|
-
}
|
|
86
|
-
return siteBundles;
|
|
87
|
-
}
|
|
88
|
-
readStaticResourceMetadata(staticRoot) {
|
|
89
|
-
let resourceMetadataPath;
|
|
90
|
-
let siteResources = {resources: {}};
|
|
91
|
-
try {
|
|
92
|
-
resourceMetadataPath = import_path.default.join(staticRoot, STATIC_RESOURCE_METADATA_PATH);
|
|
93
|
-
const savedMetadata = import_fs_extra.default.readJSONSync(resourceMetadataPath);
|
|
94
|
-
siteResources = savedMetadata;
|
|
95
|
-
} catch (error) {
|
|
96
|
-
if (error.code === "ENOENT") {
|
|
97
|
-
import_logger.logger.debug(`[SiteMetadata] Failed to load Static Resource Metadata: ${resourceMetadataPath}`);
|
|
98
|
-
} else {
|
|
99
|
-
throw error;
|
|
100
|
-
}
|
|
101
|
-
}
|
|
102
|
-
return siteResources;
|
|
103
|
-
}
|
|
104
|
-
readStaticAssetsMetadata(staticRoot) {
|
|
105
|
-
let assetMetadataPath;
|
|
106
|
-
let siteAssets = {
|
|
107
|
-
assets: {}
|
|
108
|
-
};
|
|
109
|
-
try {
|
|
110
|
-
assetMetadataPath = import_path.default.join(staticRoot, STATIC_ASSET_METADATA_PATH);
|
|
111
|
-
siteAssets = import_fs_extra.default.readJSONSync(assetMetadataPath);
|
|
112
|
-
} catch (error) {
|
|
113
|
-
if (error.code === "ENOENT") {
|
|
114
|
-
import_logger.logger.debug(`[SiteMetadata] Failed to load Static Resource Metadata: ${assetMetadataPath}`);
|
|
115
|
-
} else {
|
|
116
|
-
throw error;
|
|
117
|
-
}
|
|
118
|
-
}
|
|
119
|
-
return siteAssets;
|
|
120
|
-
}
|
|
121
|
-
};
|
|
@@ -1,27 +0,0 @@
|
|
|
1
|
-
import type { SiteAssets, SiteBundles, SiteMetadata, SiteResources } from '@lwrjs/types';
|
|
2
|
-
type Options = {
|
|
3
|
-
rootDir: string;
|
|
4
|
-
};
|
|
5
|
-
export declare class SiteMetadataImpl implements SiteMetadata {
|
|
6
|
-
private options;
|
|
7
|
-
private siteBundles;
|
|
8
|
-
private siteResources;
|
|
9
|
-
private siteAssets;
|
|
10
|
-
constructor(options: Options);
|
|
11
|
-
getSiteRootDir(): string;
|
|
12
|
-
getSiteBundles(): SiteBundles;
|
|
13
|
-
getSiteResources(): SiteResources;
|
|
14
|
-
getSiteAssets(): SiteAssets;
|
|
15
|
-
persistSiteMetadata(): Promise<void>;
|
|
16
|
-
private readStaticBundleMetadata;
|
|
17
|
-
/**
|
|
18
|
-
* Read the metadata about the pre-built resources of the current site.
|
|
19
|
-
*/
|
|
20
|
-
private readStaticResourceMetadata;
|
|
21
|
-
/**
|
|
22
|
-
* Read the metadata about the pre-built assets of the current site.
|
|
23
|
-
*/
|
|
24
|
-
private readStaticAssetsMetadata;
|
|
25
|
-
}
|
|
26
|
-
export {};
|
|
27
|
-
//# sourceMappingURL=site-metadata.d.ts.map
|
|
@@ -1,111 +0,0 @@
|
|
|
1
|
-
import path from 'path';
|
|
2
|
-
import fs from 'fs-extra';
|
|
3
|
-
import { logger } from './logger.js';
|
|
4
|
-
const SITE_METADATA_PATH = '.metadata';
|
|
5
|
-
const STATIC_BUNDLE_METADATA_PATH = path.join(SITE_METADATA_PATH, '/bundle-metadata.json');
|
|
6
|
-
const STATIC_RESOURCE_METADATA_PATH = path.join(SITE_METADATA_PATH, '/resource-metadata.json');
|
|
7
|
-
const STATIC_ASSET_METADATA_PATH = path.join(SITE_METADATA_PATH, '/asset-metadata.json');
|
|
8
|
-
export class SiteMetadataImpl {
|
|
9
|
-
constructor(options) {
|
|
10
|
-
this.options = options;
|
|
11
|
-
this.siteBundles = this.readStaticBundleMetadata(options.rootDir);
|
|
12
|
-
this.siteResources = this.readStaticResourceMetadata(options.rootDir);
|
|
13
|
-
this.siteAssets = this.readStaticAssetsMetadata(options.rootDir);
|
|
14
|
-
}
|
|
15
|
-
getSiteRootDir() {
|
|
16
|
-
return this.options.rootDir;
|
|
17
|
-
}
|
|
18
|
-
getSiteBundles() {
|
|
19
|
-
return this.siteBundles;
|
|
20
|
-
}
|
|
21
|
-
getSiteResources() {
|
|
22
|
-
return this.siteResources;
|
|
23
|
-
}
|
|
24
|
-
getSiteAssets() {
|
|
25
|
-
return this.siteAssets;
|
|
26
|
-
}
|
|
27
|
-
async persistSiteMetadata() {
|
|
28
|
-
// Create the metadata directory if if does not exist
|
|
29
|
-
const siteMetadataPath = path.join(this.options.rootDir, SITE_METADATA_PATH);
|
|
30
|
-
try {
|
|
31
|
-
if (!(await fs.pathExists(siteMetadataPath))) {
|
|
32
|
-
await fs.mkdir(siteMetadataPath, { recursive: true });
|
|
33
|
-
}
|
|
34
|
-
// Save Bundle Metadata
|
|
35
|
-
const bundleMetadataPath = path.join(this.options.rootDir, STATIC_BUNDLE_METADATA_PATH);
|
|
36
|
-
await fs.writeJSON(bundleMetadataPath, this.siteBundles, { spaces: 2 });
|
|
37
|
-
// Save Resource Metadata
|
|
38
|
-
const resourceMetadataPath = path.join(this.options.rootDir, STATIC_RESOURCE_METADATA_PATH);
|
|
39
|
-
await fs.writeJSON(resourceMetadataPath, this.siteResources, { spaces: 2 });
|
|
40
|
-
// Save Resource Metadata
|
|
41
|
-
const assetMetadataPath = path.join(this.options.rootDir, STATIC_ASSET_METADATA_PATH);
|
|
42
|
-
return fs.writeJSON(assetMetadataPath, this.siteAssets, { spaces: 2 });
|
|
43
|
-
}
|
|
44
|
-
catch (err) {
|
|
45
|
-
console.error(`[SiteMetadata] Failed to save site metadata ${siteMetadataPath}`);
|
|
46
|
-
console.error(err);
|
|
47
|
-
}
|
|
48
|
-
}
|
|
49
|
-
readStaticBundleMetadata(staticRoot) {
|
|
50
|
-
let bundleMetadataPath;
|
|
51
|
-
let siteBundles = { bundles: {} };
|
|
52
|
-
try {
|
|
53
|
-
bundleMetadataPath = path.join(staticRoot, STATIC_BUNDLE_METADATA_PATH);
|
|
54
|
-
const savedMetadata = fs.readJSONSync(bundleMetadataPath);
|
|
55
|
-
siteBundles = savedMetadata;
|
|
56
|
-
}
|
|
57
|
-
catch (error) {
|
|
58
|
-
if (error.code === 'ENOENT') {
|
|
59
|
-
logger.debug(`[SiteMetadata] Failed to load Static Bundle Metadata: ${bundleMetadataPath}`);
|
|
60
|
-
}
|
|
61
|
-
else {
|
|
62
|
-
throw error;
|
|
63
|
-
}
|
|
64
|
-
}
|
|
65
|
-
return siteBundles;
|
|
66
|
-
}
|
|
67
|
-
/**
|
|
68
|
-
* Read the metadata about the pre-built resources of the current site.
|
|
69
|
-
*/
|
|
70
|
-
readStaticResourceMetadata(staticRoot) {
|
|
71
|
-
let resourceMetadataPath;
|
|
72
|
-
let siteResources = { resources: {} };
|
|
73
|
-
try {
|
|
74
|
-
resourceMetadataPath = path.join(staticRoot, STATIC_RESOURCE_METADATA_PATH);
|
|
75
|
-
const savedMetadata = fs.readJSONSync(resourceMetadataPath);
|
|
76
|
-
siteResources = savedMetadata;
|
|
77
|
-
}
|
|
78
|
-
catch (error) {
|
|
79
|
-
if (error.code === 'ENOENT') {
|
|
80
|
-
logger.debug(`[SiteMetadata] Failed to load Static Resource Metadata: ${resourceMetadataPath}`);
|
|
81
|
-
}
|
|
82
|
-
else {
|
|
83
|
-
throw error;
|
|
84
|
-
}
|
|
85
|
-
}
|
|
86
|
-
return siteResources;
|
|
87
|
-
}
|
|
88
|
-
/**
|
|
89
|
-
* Read the metadata about the pre-built assets of the current site.
|
|
90
|
-
*/
|
|
91
|
-
readStaticAssetsMetadata(staticRoot) {
|
|
92
|
-
let assetMetadataPath;
|
|
93
|
-
let siteAssets = {
|
|
94
|
-
assets: {},
|
|
95
|
-
};
|
|
96
|
-
try {
|
|
97
|
-
assetMetadataPath = path.join(staticRoot, STATIC_ASSET_METADATA_PATH);
|
|
98
|
-
siteAssets = fs.readJSONSync(assetMetadataPath);
|
|
99
|
-
}
|
|
100
|
-
catch (error) {
|
|
101
|
-
if (error.code === 'ENOENT') {
|
|
102
|
-
logger.debug(`[SiteMetadata] Failed to load Static Resource Metadata: ${assetMetadataPath}`);
|
|
103
|
-
}
|
|
104
|
-
else {
|
|
105
|
-
throw error;
|
|
106
|
-
}
|
|
107
|
-
}
|
|
108
|
-
return siteAssets;
|
|
109
|
-
}
|
|
110
|
-
}
|
|
111
|
-
//# sourceMappingURL=site-metadata.js.map
|