@lwrjs/shared-utils 0.9.0-alpha.13 → 0.9.0-alpha.14
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/compiler.cjs +80 -0
- package/build/cjs/env.cjs +3 -9
- package/build/cjs/graph.cjs +1 -1
- package/build/cjs/identity.cjs +0 -9
- package/build/cjs/index.cjs +1 -1
- package/build/cjs/logger.cjs +25 -11
- package/build/cjs/mappings.cjs +7 -7
- package/build/cjs/site-metadata.cjs +137 -0
- package/build/es/compiler.d.ts +15 -0
- package/build/es/compiler.js +65 -0
- package/build/es/env.d.ts +1 -1
- package/build/es/env.js +11 -12
- package/build/es/graph.js +1 -1
- package/build/es/identity.d.ts +0 -23
- package/build/es/identity.js +0 -31
- package/build/es/index.d.ts +1 -1
- package/build/es/index.js +1 -1
- package/build/es/logger.js +27 -10
- package/build/es/mappings.d.ts +1 -1
- package/build/es/mappings.js +7 -7
- package/build/es/site-metadata.d.ts +27 -0
- package/build/es/site-metadata.js +136 -0
- package/build/es/typescript.js +2 -1
- package/package.json +16 -6
|
@@ -0,0 +1,80 @@
|
|
|
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/compiler.ts
|
|
25
|
+
__markAsModule(exports);
|
|
26
|
+
__export(exports, {
|
|
27
|
+
AMD_DEFINE: () => AMD_DEFINE,
|
|
28
|
+
convertToAmd: () => convertToAmd,
|
|
29
|
+
lockerize: () => lockerize
|
|
30
|
+
});
|
|
31
|
+
var import_identity = __toModule(require("./identity.cjs"));
|
|
32
|
+
var import_compiler = __toModule(require("@locker/compiler"));
|
|
33
|
+
var import_rollup = __toModule(require("rollup"));
|
|
34
|
+
var AMD_DEFINE = "LWR.define";
|
|
35
|
+
var AMD_ROLLUP_PLUGIN = function(rootId, source) {
|
|
36
|
+
return {
|
|
37
|
+
name: "lwr-amd-inline",
|
|
38
|
+
resolveId(id) {
|
|
39
|
+
return rootId === id ? id : void 0;
|
|
40
|
+
},
|
|
41
|
+
load(id) {
|
|
42
|
+
return rootId === id ? source : void 0;
|
|
43
|
+
}
|
|
44
|
+
};
|
|
45
|
+
};
|
|
46
|
+
async function convertToAmd(source, {id}, forceNamedExports = true) {
|
|
47
|
+
const bundler = await (0, import_rollup.rollup)({
|
|
48
|
+
input: id,
|
|
49
|
+
plugins: [AMD_ROLLUP_PLUGIN(id, source)],
|
|
50
|
+
onwarn(warning, warn) {
|
|
51
|
+
if (warning.code === "UNRESOLVED_IMPORT")
|
|
52
|
+
return;
|
|
53
|
+
warn(warning);
|
|
54
|
+
}
|
|
55
|
+
});
|
|
56
|
+
const {output} = await bundler.generate({
|
|
57
|
+
amd: {id, define: AMD_DEFINE},
|
|
58
|
+
exports: forceNamedExports ? "named" : "auto",
|
|
59
|
+
format: "amd"
|
|
60
|
+
});
|
|
61
|
+
const {code} = output[0];
|
|
62
|
+
return {code, map: null};
|
|
63
|
+
}
|
|
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
|
@@ -11,15 +11,9 @@ __export(exports, {
|
|
|
11
11
|
getFeatureFlags: () => getFeatureFlags
|
|
12
12
|
});
|
|
13
13
|
function getFeatureFlags() {
|
|
14
|
-
let legacyLoader = process.env.LEGACY_LOADER !== void 0 && process.env.LEGACY_LOADER === "true" ? true : false;
|
|
15
|
-
try {
|
|
16
|
-
if (LWR) {
|
|
17
|
-
legacyLoader = LWR.LEGACY_LOADER;
|
|
18
|
-
}
|
|
19
|
-
} catch (e) {
|
|
20
|
-
}
|
|
21
14
|
return {
|
|
22
|
-
LEGACY_LOADER:
|
|
23
|
-
SSR_STATIC_BUNDLES: process.env.SSR_STATIC_BUNDLES !== void 0 && process.env.SSR_STATIC_BUNDLES === "true" ? true : false
|
|
15
|
+
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
|
+
SSR_SANDBOX_WORKER: process.env.SSR_SANDBOX_WORKER !== void 0 && process.env.SSR_SANDBOX_WORKER.toLowerCase() === "true" ? true : false
|
|
24
18
|
};
|
|
25
19
|
}
|
package/build/cjs/graph.cjs
CHANGED
|
@@ -121,7 +121,7 @@ async function getModuleGraphs(specifier, options, moduleRegistry, defRegistry,
|
|
|
121
121
|
if (options.includeUris) {
|
|
122
122
|
for (const visitedSpecifier of acc.keys()) {
|
|
123
123
|
const moduleId = await (0, import_identity.getVersionedModuleId)(visitedSpecifier, moduleRegistry);
|
|
124
|
-
const uri = await
|
|
124
|
+
const uri = await defRegistry.resolveModuleUri(moduleId, runtimeEnvironment, runtimeParams);
|
|
125
125
|
uriMap[visitedSpecifier] = uri;
|
|
126
126
|
}
|
|
127
127
|
}
|
package/build/cjs/identity.cjs
CHANGED
|
@@ -43,7 +43,6 @@ __export(exports, {
|
|
|
43
43
|
getPropFromAttrName: () => getPropFromAttrName,
|
|
44
44
|
getSpecifier: () => getSpecifier,
|
|
45
45
|
getVersionedModuleId: () => getVersionedModuleId,
|
|
46
|
-
getVersionedSpecifier: () => getVersionedSpecifier,
|
|
47
46
|
isBundleDefinition: () => isBundleDefinition,
|
|
48
47
|
isExternalUrl: () => isExternalUrl,
|
|
49
48
|
kebabCaseToModuleSpecifer: () => kebabCaseToModuleSpecifer,
|
|
@@ -119,14 +118,6 @@ function getSpecifier({specifier, namespace, name = "", version}) {
|
|
|
119
118
|
const bareSpecifier = namespace ? `${namespace}/${name}` : name;
|
|
120
119
|
return version ? `${bareSpecifier}${VERSION_SIGIL}${normalizeVersionToUri(version)}` : bareSpecifier;
|
|
121
120
|
}
|
|
122
|
-
async function getVersionedSpecifier(rawSpecifier, moduleRegistry) {
|
|
123
|
-
const {specifier, namespace, name, version} = explodeSpecifier(rawSpecifier);
|
|
124
|
-
if (version) {
|
|
125
|
-
return normalizeVersionToUri(rawSpecifier);
|
|
126
|
-
}
|
|
127
|
-
const moduleEntry = await moduleRegistry.getModuleEntry({specifier});
|
|
128
|
-
return getSpecifier({namespace, name, version: normalizeVersionToUri(moduleEntry.version)});
|
|
129
|
-
}
|
|
130
121
|
async function getVersionedModuleId(rawSpecifier, moduleRegistry) {
|
|
131
122
|
const moduleId = explodeSpecifier(rawSpecifier);
|
|
132
123
|
if (moduleId.version) {
|
package/build/cjs/index.cjs
CHANGED
|
@@ -27,7 +27,6 @@ __exportStar(exports, __toModule(require("./link.cjs")));
|
|
|
27
27
|
__exportStar(exports, __toModule(require("./object.cjs")));
|
|
28
28
|
__exportStar(exports, __toModule(require("./serialize.cjs")));
|
|
29
29
|
__exportStar(exports, __toModule(require("./tasks.cjs")));
|
|
30
|
-
__exportStar(exports, __toModule(require("./typescript.cjs")));
|
|
31
30
|
__exportStar(exports, __toModule(require("./import-metadata.cjs")));
|
|
32
31
|
__exportStar(exports, __toModule(require("./graph.cjs")));
|
|
33
32
|
__exportStar(exports, __toModule(require("./mappings.cjs")));
|
|
@@ -35,3 +34,4 @@ __exportStar(exports, __toModule(require("./urls.cjs")));
|
|
|
35
34
|
__exportStar(exports, __toModule(require("./env.cjs")));
|
|
36
35
|
__exportStar(exports, __toModule(require("./logger.cjs")));
|
|
37
36
|
__exportStar(exports, __toModule(require("./lwr-app-observer.cjs")));
|
|
37
|
+
__exportStar(exports, __toModule(require("./site-metadata.cjs")));
|
package/build/cjs/logger.cjs
CHANGED
|
@@ -74,19 +74,21 @@ function log(level, message, additionalInfo) {
|
|
|
74
74
|
}
|
|
75
75
|
}
|
|
76
76
|
if (shouldLog) {
|
|
77
|
-
let
|
|
78
|
-
if (
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
logMethod = console.warn;
|
|
77
|
+
let logMessage;
|
|
78
|
+
if (additionalInfo) {
|
|
79
|
+
logMessage = `[${level}]${gap(message)}${message}
|
|
80
|
+
Additional Info: ${JSON.stringify(additionalInfo)}`;
|
|
82
81
|
} else {
|
|
83
|
-
|
|
82
|
+
logMessage = `[${level}]${gap(message)}${message}`;
|
|
84
83
|
}
|
|
85
|
-
if (
|
|
86
|
-
|
|
87
|
-
|
|
84
|
+
if (level == ERROR) {
|
|
85
|
+
console.error("[31m%s[0m", logMessage);
|
|
86
|
+
} else if (level == WARN) {
|
|
87
|
+
console.warn("[33m%s[0m", logMessage);
|
|
88
|
+
} else if (level == DEBUG || level == VERBOSE) {
|
|
89
|
+
console.log("[2m%s[0m", logMessage);
|
|
88
90
|
} else {
|
|
89
|
-
|
|
91
|
+
console.log(logMessage);
|
|
90
92
|
}
|
|
91
93
|
}
|
|
92
94
|
}
|
|
@@ -110,12 +112,24 @@ var stringifyError = (error) => {
|
|
|
110
112
|
return JSON.stringify(retObj);
|
|
111
113
|
}
|
|
112
114
|
};
|
|
115
|
+
function gap(message) {
|
|
116
|
+
return String(message)?.indexOf("[") === 0 ? "" : " ";
|
|
117
|
+
}
|
|
118
|
+
function logError(err, additionalInfo) {
|
|
119
|
+
if (err instanceof import_diagnostics.DiagnosticsError || !err || !err.message) {
|
|
120
|
+
log(ERROR, stringifyError(err), additionalInfo);
|
|
121
|
+
}
|
|
122
|
+
if (err && err.message) {
|
|
123
|
+
err.message = `[${ERROR}]${gap(err.message)}${err.message}`;
|
|
124
|
+
console.error("[31m%s[0m", err);
|
|
125
|
+
}
|
|
126
|
+
}
|
|
113
127
|
var logger = {
|
|
114
128
|
verbose: (message, additionalInfo) => log(VERBOSE, message, additionalInfo),
|
|
115
129
|
debug: (message, additionalInfo) => log(DEBUG, message, additionalInfo),
|
|
116
130
|
info: (message, additionalInfo) => log(INFO, message, additionalInfo),
|
|
117
131
|
warn: (message, additionalInfo) => log(WARN, message, additionalInfo),
|
|
118
|
-
error: (error, additionalInfo) =>
|
|
132
|
+
error: (error, additionalInfo) => logError(error, additionalInfo),
|
|
119
133
|
log,
|
|
120
134
|
setOptions: (opts) => {
|
|
121
135
|
options = opts;
|
package/build/cjs/mappings.cjs
CHANGED
|
@@ -57,7 +57,7 @@ async function getImportMetadataMappings(moduleIds, runtimeEnvironment, runtimeP
|
|
|
57
57
|
}
|
|
58
58
|
return importMetadata;
|
|
59
59
|
}
|
|
60
|
-
async function toImportMetadata(moduleGraph, existingImportMetadata = {imports: {}, index: {}},
|
|
60
|
+
async function toImportMetadata(moduleGraph, existingImportMetadata = {imports: {}, index: {}}, defRegistry, runtimeEnvironment, runtimeParams = {}) {
|
|
61
61
|
const specifier = moduleGraph.graphs[0].specifier;
|
|
62
62
|
const uri = moduleGraph.uriMap[specifier];
|
|
63
63
|
const definition = moduleGraph.linkedDefinitions[specifier];
|
|
@@ -67,7 +67,7 @@ async function toImportMetadata(moduleGraph, existingImportMetadata = {imports:
|
|
|
67
67
|
if (!definition) {
|
|
68
68
|
throw new Error("Linked module definition was not included in the graph: " + specifier);
|
|
69
69
|
}
|
|
70
|
-
const rootMetadata = await normalizeImportMetadata(specifier, uri, definition,
|
|
70
|
+
const rootMetadata = await normalizeImportMetadata(specifier, uri, definition, defRegistry, runtimeEnvironment, runtimeParams);
|
|
71
71
|
let importMetadata = mergeImportMetadata(existingImportMetadata, rootMetadata);
|
|
72
72
|
const depSpecifiers = runtimeEnvironment.format === "esm" ? moduleGraph.graphs[0].dynamicRefs : moduleGraph.graphs[0].static;
|
|
73
73
|
for (const depSpecifier of depSpecifiers) {
|
|
@@ -85,7 +85,7 @@ async function toImportMetadata(moduleGraph, existingImportMetadata = {imports:
|
|
|
85
85
|
continue;
|
|
86
86
|
}
|
|
87
87
|
if (!importMetadata.imports[depUri]) {
|
|
88
|
-
const depMetadata = await normalizeImportMetadata((0, import_identity.getSpecifier)(depDef), depUri, depDef,
|
|
88
|
+
const depMetadata = await normalizeImportMetadata((0, import_identity.getSpecifier)(depDef), depUri, depDef, defRegistry, runtimeEnvironment, runtimeParams);
|
|
89
89
|
importMetadata = mergeImportMetadata(importMetadata, depMetadata);
|
|
90
90
|
}
|
|
91
91
|
}
|
|
@@ -103,11 +103,11 @@ function mergeImportMetadata(existing, newMetadata) {
|
|
|
103
103
|
}
|
|
104
104
|
};
|
|
105
105
|
}
|
|
106
|
-
async function normalizeImportMetadata(specifier, uri, definition,
|
|
106
|
+
async function normalizeImportMetadata(specifier, uri, definition, defRegistry, moduleRuntimeEnvironment, runtimeParams) {
|
|
107
107
|
const specifiers = normalizedIncludedModules(definition);
|
|
108
108
|
const imports = {};
|
|
109
109
|
imports[uri] = specifiers;
|
|
110
|
-
const index = await createIndex(specifiers,
|
|
110
|
+
const index = await createIndex(specifiers, defRegistry, moduleRuntimeEnvironment, runtimeParams);
|
|
111
111
|
if (!(specifier in index)) {
|
|
112
112
|
index[specifier] = uri;
|
|
113
113
|
}
|
|
@@ -119,7 +119,7 @@ async function normalizeImportMetadata(specifier, uri, definition, moduleRegistr
|
|
|
119
119
|
function normalizedIncludedModules(definition) {
|
|
120
120
|
return (0, import_identity.isBundleDefinition)(definition) ? [(0, import_identity.getSpecifier)(definition), ...definition.bundleRecord.includedModules] : [(0, import_identity.getSpecifier)(definition)];
|
|
121
121
|
}
|
|
122
|
-
async function createIndex(specifiers,
|
|
122
|
+
async function createIndex(specifiers, defRegistry, runtimeEnvironment, runtimeParams) {
|
|
123
123
|
const index = {};
|
|
124
124
|
const moduleRuntimeEnvironment = {...runtimeEnvironment, bundle: false};
|
|
125
125
|
async function getUri(specifier) {
|
|
@@ -127,7 +127,7 @@ async function createIndex(specifiers, moduleRegistry, runtimeEnvironment, runti
|
|
|
127
127
|
if (!moduleId.version) {
|
|
128
128
|
throw new Error("Module specifier must include a version: " + specifier);
|
|
129
129
|
}
|
|
130
|
-
index[specifier] = await
|
|
130
|
+
index[specifier] = await defRegistry.resolveModuleUri({...moduleId, version: moduleId.version}, moduleRuntimeEnvironment, runtimeParams);
|
|
131
131
|
}
|
|
132
132
|
const promises = [];
|
|
133
133
|
for (const specifier of specifiers) {
|
|
@@ -0,0 +1,137 @@
|
|
|
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 = "site-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
|
+
getSiteBundles() {
|
|
44
|
+
return this.siteBundles;
|
|
45
|
+
}
|
|
46
|
+
getSiteResources() {
|
|
47
|
+
return this.siteResources;
|
|
48
|
+
}
|
|
49
|
+
getSiteAssets() {
|
|
50
|
+
return this.siteAssets;
|
|
51
|
+
}
|
|
52
|
+
async persistSiteMetadata() {
|
|
53
|
+
const siteMetadataPath = import_path.default.join(this.options.rootDir, SITE_METADATA_PATH);
|
|
54
|
+
if (!await import_fs_extra.default.pathExists(siteMetadataPath)) {
|
|
55
|
+
await import_fs_extra.default.mkdir(siteMetadataPath, {recursive: true});
|
|
56
|
+
}
|
|
57
|
+
const bundleMetadataPath = import_path.default.join(this.options.rootDir, STATIC_BUNDLE_METADATA_PATH);
|
|
58
|
+
await import_fs_extra.default.writeJSON(bundleMetadataPath, this.siteBundles, {spaces: 2});
|
|
59
|
+
const resourceMetadataPath = import_path.default.join(this.options.rootDir, STATIC_RESOURCE_METADATA_PATH);
|
|
60
|
+
await import_fs_extra.default.writeJSON(resourceMetadataPath, this.siteResources, {spaces: 2});
|
|
61
|
+
const assetMetadataPath = import_path.default.join(this.options.rootDir, STATIC_ASSET_METADATA_PATH);
|
|
62
|
+
return import_fs_extra.default.writeJSON(assetMetadataPath, this.siteAssets, {spaces: 2});
|
|
63
|
+
}
|
|
64
|
+
readStaticBundleMetadata(staticRoot) {
|
|
65
|
+
let bundleMetadataPath;
|
|
66
|
+
let siteBundles = {
|
|
67
|
+
bundles: {},
|
|
68
|
+
environment: {
|
|
69
|
+
format: this.options.runtimeEnvironment.format,
|
|
70
|
+
...this.options.runtimeEnvironment.featureFlags?.LEGACY_LOADER && {
|
|
71
|
+
featureFlags: {LEGACY_LOADER: true}
|
|
72
|
+
}
|
|
73
|
+
}
|
|
74
|
+
};
|
|
75
|
+
try {
|
|
76
|
+
bundleMetadataPath = import_path.default.join(staticRoot, STATIC_BUNDLE_METADATA_PATH);
|
|
77
|
+
const savedMetadata = import_fs_extra.default.readJSONSync(bundleMetadataPath);
|
|
78
|
+
if (this.options.runtimeEnvironment.format !== savedMetadata.environment?.format || this.options.runtimeEnvironment.featureFlags?.LEGACY_LOADER != savedMetadata.environment?.featureFlags?.LEGACY_LOADER) {
|
|
79
|
+
import_logger.logger.warn("[SiteMetadata] Saved bundles do not match the current runtime. They will not be used.", {expected: savedMetadata.environment, actual: this.options.runtimeEnvironment});
|
|
80
|
+
} else {
|
|
81
|
+
siteBundles = savedMetadata;
|
|
82
|
+
}
|
|
83
|
+
} catch (error) {
|
|
84
|
+
if (error.code === "ENOENT") {
|
|
85
|
+
import_logger.logger.debug(`[SiteMetadata] Failed to load Static Bundle Metadata: ${bundleMetadataPath}`);
|
|
86
|
+
} else {
|
|
87
|
+
throw error;
|
|
88
|
+
}
|
|
89
|
+
}
|
|
90
|
+
return siteBundles;
|
|
91
|
+
}
|
|
92
|
+
readStaticResourceMetadata(staticRoot) {
|
|
93
|
+
let resourceMetadataPath;
|
|
94
|
+
let siteResources = {
|
|
95
|
+
resources: {},
|
|
96
|
+
environment: {
|
|
97
|
+
format: this.options.runtimeEnvironment.format,
|
|
98
|
+
...this.options.runtimeEnvironment.featureFlags?.LEGACY_LOADER && {
|
|
99
|
+
featureFlags: {LEGACY_LOADER: true}
|
|
100
|
+
}
|
|
101
|
+
}
|
|
102
|
+
};
|
|
103
|
+
try {
|
|
104
|
+
resourceMetadataPath = import_path.default.join(staticRoot, STATIC_RESOURCE_METADATA_PATH);
|
|
105
|
+
const savedMetadata = import_fs_extra.default.readJSONSync(resourceMetadataPath);
|
|
106
|
+
if (this.options.runtimeEnvironment.format !== savedMetadata.environment?.format || this.options.runtimeEnvironment.featureFlags?.LEGACY_LOADER != savedMetadata.environment?.featureFlags?.LEGACY_LOADER) {
|
|
107
|
+
import_logger.logger.warn("[SiteMetadata] Saved resources do not match the current runtime. They will not be used.", {expected: savedMetadata.environment, actual: this.options.runtimeEnvironment});
|
|
108
|
+
} else {
|
|
109
|
+
siteResources = savedMetadata;
|
|
110
|
+
}
|
|
111
|
+
} catch (error) {
|
|
112
|
+
if (error.code === "ENOENT") {
|
|
113
|
+
import_logger.logger.debug(`[SiteMetadata] Failed to load Static Resource Metadata: ${resourceMetadataPath}`);
|
|
114
|
+
} else {
|
|
115
|
+
throw error;
|
|
116
|
+
}
|
|
117
|
+
}
|
|
118
|
+
return siteResources;
|
|
119
|
+
}
|
|
120
|
+
readStaticAssetsMetadata(staticRoot) {
|
|
121
|
+
let assetMetadataPath;
|
|
122
|
+
let siteAssets = {
|
|
123
|
+
assets: {}
|
|
124
|
+
};
|
|
125
|
+
try {
|
|
126
|
+
assetMetadataPath = import_path.default.join(staticRoot, STATIC_ASSET_METADATA_PATH);
|
|
127
|
+
siteAssets = import_fs_extra.default.readJSONSync(assetMetadataPath);
|
|
128
|
+
} catch (error) {
|
|
129
|
+
if (error.code === "ENOENT") {
|
|
130
|
+
import_logger.logger.debug(`[SiteMetadata] Failed to load Static Resource Metadata: ${assetMetadataPath}`);
|
|
131
|
+
} else {
|
|
132
|
+
throw error;
|
|
133
|
+
}
|
|
134
|
+
}
|
|
135
|
+
return siteAssets;
|
|
136
|
+
}
|
|
137
|
+
};
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
import type { CompilerResult, LwrLockerConfig, ModuleCompiled } from '@lwrjs/types';
|
|
2
|
+
/**
|
|
3
|
+
* When importing these modules make sure the optional dependencies are installed:
|
|
4
|
+
* - 'rollup' for convertToAmd()
|
|
5
|
+
* - '@locker/compiler' for lockerize()
|
|
6
|
+
*/
|
|
7
|
+
export declare const AMD_DEFINE = "LWR.define";
|
|
8
|
+
export declare function convertToAmd(source: string, { id }: {
|
|
9
|
+
id: string;
|
|
10
|
+
}, 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
|
+
//# sourceMappingURL=compiler.d.ts.map
|
|
@@ -0,0 +1,65 @@
|
|
|
1
|
+
import { explodeSpecifier } from './identity.js';
|
|
2
|
+
import { Compiler as Locker } from '@locker/compiler';
|
|
3
|
+
import { rollup } from 'rollup';
|
|
4
|
+
/**
|
|
5
|
+
* When importing these modules make sure the optional dependencies are installed:
|
|
6
|
+
* - 'rollup' for convertToAmd()
|
|
7
|
+
* - '@locker/compiler' for lockerize()
|
|
8
|
+
*/
|
|
9
|
+
export const AMD_DEFINE = 'LWR.define';
|
|
10
|
+
const AMD_ROLLUP_PLUGIN = function (rootId, source) {
|
|
11
|
+
return {
|
|
12
|
+
name: 'lwr-amd-inline',
|
|
13
|
+
resolveId(id) {
|
|
14
|
+
return rootId === id ? id : undefined;
|
|
15
|
+
},
|
|
16
|
+
load(id) {
|
|
17
|
+
return rootId === id ? source : undefined;
|
|
18
|
+
},
|
|
19
|
+
};
|
|
20
|
+
};
|
|
21
|
+
export async function convertToAmd(source, { id }, forceNamedExports = true) {
|
|
22
|
+
const bundler = await rollup({
|
|
23
|
+
input: id,
|
|
24
|
+
plugins: [AMD_ROLLUP_PLUGIN(id, source)],
|
|
25
|
+
onwarn(warning, warn) {
|
|
26
|
+
// do not print out these: 'a' is imported by b, but could not be resolved – treating it as an external dependency
|
|
27
|
+
if (warning.code === 'UNRESOLVED_IMPORT')
|
|
28
|
+
return;
|
|
29
|
+
warn(warning);
|
|
30
|
+
},
|
|
31
|
+
});
|
|
32
|
+
const { output } = await bundler.generate({
|
|
33
|
+
amd: { id, define: AMD_DEFINE },
|
|
34
|
+
exports: forceNamedExports ? 'named' : 'auto',
|
|
35
|
+
format: 'amd',
|
|
36
|
+
});
|
|
37
|
+
const { code } = output[0];
|
|
38
|
+
return { code, map: null };
|
|
39
|
+
}
|
|
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
|
+
//# sourceMappingURL=compiler.js.map
|
package/build/es/env.d.ts
CHANGED
package/build/es/env.js
CHANGED
|
@@ -1,19 +1,18 @@
|
|
|
1
1
|
export function getFeatureFlags() {
|
|
2
|
-
|
|
3
|
-
try {
|
|
4
|
-
// Use the Shim for MRT since we don't have access to managing environment variables
|
|
5
|
-
if (LWR) {
|
|
6
|
-
legacyLoader = LWR.LEGACY_LOADER;
|
|
7
|
-
}
|
|
8
|
-
}
|
|
9
|
-
catch (e) {
|
|
10
|
-
// No shim, ignore error
|
|
11
|
-
}
|
|
2
|
+
// Add any new feature flags here to parse from environment variables
|
|
12
3
|
return {
|
|
13
4
|
// DEFAULT LEGACY_LOADER = false;
|
|
14
|
-
LEGACY_LOADER:
|
|
5
|
+
LEGACY_LOADER: process.env.LEGACY_LOADER !== undefined && process.env.LEGACY_LOADER.toLowerCase() === 'true'
|
|
6
|
+
? true
|
|
7
|
+
: false,
|
|
15
8
|
// SSR should concatenate bundles, default = false
|
|
16
|
-
SSR_STATIC_BUNDLES: process.env.SSR_STATIC_BUNDLES !== undefined &&
|
|
9
|
+
SSR_STATIC_BUNDLES: process.env.SSR_STATIC_BUNDLES !== undefined &&
|
|
10
|
+
process.env.SSR_STATIC_BUNDLES.toLowerCase() === 'true'
|
|
11
|
+
? true
|
|
12
|
+
: false,
|
|
13
|
+
// Should we use a js worker for SSR, sandboxing = false (use locker for ssr sandboxing)
|
|
14
|
+
SSR_SANDBOX_WORKER: process.env.SSR_SANDBOX_WORKER !== undefined &&
|
|
15
|
+
process.env.SSR_SANDBOX_WORKER.toLowerCase() === 'true'
|
|
17
16
|
? true
|
|
18
17
|
: false,
|
|
19
18
|
};
|
package/build/es/graph.js
CHANGED
|
@@ -129,7 +129,7 @@ options, moduleRegistry, defRegistry, runtimeEnvironment, runtimeParams, visited
|
|
|
129
129
|
// eslint-disable-next-line no-await-in-loop
|
|
130
130
|
const moduleId = await getVersionedModuleId(visitedSpecifier, moduleRegistry);
|
|
131
131
|
// eslint-disable-next-line no-await-in-loop
|
|
132
|
-
const uri = await
|
|
132
|
+
const uri = await defRegistry.resolveModuleUri(moduleId, runtimeEnvironment, runtimeParams);
|
|
133
133
|
uriMap[visitedSpecifier] = uri;
|
|
134
134
|
}
|
|
135
135
|
}
|
package/build/es/identity.d.ts
CHANGED
|
@@ -57,29 +57,6 @@ export declare function explodeSpecifiers(rawSpecifiers: string): PartialModuleI
|
|
|
57
57
|
* @example - { namespace: '@salesforce', name: 'label/my.label', version: '1' } => '@salesforce/label/my.label/v/1'
|
|
58
58
|
*/
|
|
59
59
|
export declare function getSpecifier({ specifier, namespace, name, version }: ModuleIdentifierPartial): string;
|
|
60
|
-
/**
|
|
61
|
-
* Create a versioned specifier based on the module registry
|
|
62
|
-
*
|
|
63
|
-
* @remarks
|
|
64
|
-
* If the incoming specifier is already versioned, it will be returned as is.
|
|
65
|
-
*
|
|
66
|
-
* The returned specifier's version conforms to the format expected to be used
|
|
67
|
-
* external to the framework (e.g. via the identity in the URL, mapping metadata,
|
|
68
|
-
* AMD define module name). This format conforms to the `normalizeVersionToUri`
|
|
69
|
-
* implementation (e.g. version semver format -- major_minor_patch).
|
|
70
|
-
*
|
|
71
|
-
* This method is analogous to `getSpecifier` but supports non-versioned `rawSpecifiers`
|
|
72
|
-
* The inverse of this method is `explodeSpecifier`
|
|
73
|
-
|
|
74
|
-
* @param specifier - the module specifier
|
|
75
|
-
* @param moduleRegistry - the public module registry
|
|
76
|
-
*
|
|
77
|
-
* @returns the specifier for the latest version
|
|
78
|
-
*
|
|
79
|
-
* @example - 'c/form' => 'c/form/v/0_0_1'
|
|
80
|
-
* @example - 'c/form/v/0.0.2' => 'c/form/v/0_0_2'
|
|
81
|
-
*/
|
|
82
|
-
export declare function getVersionedSpecifier(rawSpecifier: string, moduleRegistry: PublicModuleRegistry): Promise<string>;
|
|
83
60
|
interface VersionedAbstractModuleId extends AbstractModuleId {
|
|
84
61
|
version: string;
|
|
85
62
|
}
|
package/build/es/identity.js
CHANGED
|
@@ -96,37 +96,6 @@ export function getSpecifier({ specifier, namespace, name = '', version }) {
|
|
|
96
96
|
const bareSpecifier = namespace ? `${namespace}/${name}` : name;
|
|
97
97
|
return version ? `${bareSpecifier}${VERSION_SIGIL}${normalizeVersionToUri(version)}` : bareSpecifier;
|
|
98
98
|
}
|
|
99
|
-
/**
|
|
100
|
-
* Create a versioned specifier based on the module registry
|
|
101
|
-
*
|
|
102
|
-
* @remarks
|
|
103
|
-
* If the incoming specifier is already versioned, it will be returned as is.
|
|
104
|
-
*
|
|
105
|
-
* The returned specifier's version conforms to the format expected to be used
|
|
106
|
-
* external to the framework (e.g. via the identity in the URL, mapping metadata,
|
|
107
|
-
* AMD define module name). This format conforms to the `normalizeVersionToUri`
|
|
108
|
-
* implementation (e.g. version semver format -- major_minor_patch).
|
|
109
|
-
*
|
|
110
|
-
* This method is analogous to `getSpecifier` but supports non-versioned `rawSpecifiers`
|
|
111
|
-
* The inverse of this method is `explodeSpecifier`
|
|
112
|
-
|
|
113
|
-
* @param specifier - the module specifier
|
|
114
|
-
* @param moduleRegistry - the public module registry
|
|
115
|
-
*
|
|
116
|
-
* @returns the specifier for the latest version
|
|
117
|
-
*
|
|
118
|
-
* @example - 'c/form' => 'c/form/v/0_0_1'
|
|
119
|
-
* @example - 'c/form/v/0.0.2' => 'c/form/v/0_0_2'
|
|
120
|
-
*/
|
|
121
|
-
export async function getVersionedSpecifier(rawSpecifier, moduleRegistry) {
|
|
122
|
-
const { specifier, namespace, name, version } = explodeSpecifier(rawSpecifier);
|
|
123
|
-
if (version) {
|
|
124
|
-
return normalizeVersionToUri(rawSpecifier);
|
|
125
|
-
}
|
|
126
|
-
// Get version from Module Registry
|
|
127
|
-
const moduleEntry = await moduleRegistry.getModuleEntry({ specifier });
|
|
128
|
-
return getSpecifier({ namespace, name, version: normalizeVersionToUri(moduleEntry.version) });
|
|
129
|
-
}
|
|
130
99
|
/**
|
|
131
100
|
* Create a AbstractModuleId using the module registry to resolve the version
|
|
132
101
|
* if a version is not provided in the `rawSpecifier`
|
package/build/es/index.d.ts
CHANGED
|
@@ -6,7 +6,6 @@ export * from './link.js';
|
|
|
6
6
|
export * from './object.js';
|
|
7
7
|
export * from './serialize.js';
|
|
8
8
|
export * from './tasks.js';
|
|
9
|
-
export * from './typescript.js';
|
|
10
9
|
export * from './import-metadata.js';
|
|
11
10
|
export * from './graph.js';
|
|
12
11
|
export * from './mappings.js';
|
|
@@ -14,4 +13,5 @@ export * from './urls.js';
|
|
|
14
13
|
export * from './env.js';
|
|
15
14
|
export * from './logger.js';
|
|
16
15
|
export * from './lwr-app-observer.js';
|
|
16
|
+
export * from './site-metadata.js';
|
|
17
17
|
//# sourceMappingURL=index.d.ts.map
|
package/build/es/index.js
CHANGED
|
@@ -6,7 +6,6 @@ export * from './link.js';
|
|
|
6
6
|
export * from './object.js';
|
|
7
7
|
export * from './serialize.js';
|
|
8
8
|
export * from './tasks.js';
|
|
9
|
-
export * from './typescript.js';
|
|
10
9
|
export * from './import-metadata.js';
|
|
11
10
|
export * from './graph.js';
|
|
12
11
|
export * from './mappings.js';
|
|
@@ -14,4 +13,5 @@ export * from './urls.js';
|
|
|
14
13
|
export * from './env.js';
|
|
15
14
|
export * from './logger.js';
|
|
16
15
|
export * from './lwr-app-observer.js';
|
|
16
|
+
export * from './site-metadata.js';
|
|
17
17
|
//# sourceMappingURL=index.js.map
|
package/build/es/logger.js
CHANGED
|
@@ -43,21 +43,24 @@ function log(level, message, additionalInfo) {
|
|
|
43
43
|
}
|
|
44
44
|
}
|
|
45
45
|
if (shouldLog) {
|
|
46
|
-
let
|
|
46
|
+
let logMessage;
|
|
47
|
+
if (additionalInfo) {
|
|
48
|
+
logMessage = `[${level}]${gap(message)}${message} \nAdditional Info: ${JSON.stringify(additionalInfo)}`;
|
|
49
|
+
}
|
|
50
|
+
else {
|
|
51
|
+
logMessage = `[${level}]${gap(message)}${message}`;
|
|
52
|
+
}
|
|
47
53
|
if (level == ERROR) {
|
|
48
|
-
|
|
54
|
+
console.error('\x1b[31m%s\x1b[0m', logMessage); // red
|
|
49
55
|
}
|
|
50
56
|
else if (level == WARN) {
|
|
51
|
-
|
|
57
|
+
console.warn('\x1b[33m%s\x1b[0m', logMessage); // yellow
|
|
52
58
|
}
|
|
53
|
-
else {
|
|
54
|
-
|
|
55
|
-
}
|
|
56
|
-
if (additionalInfo) {
|
|
57
|
-
logMethod(`[${level}] ${message} \nAdditional Info: ${JSON.stringify(additionalInfo)}`);
|
|
59
|
+
else if (level == DEBUG || level == VERBOSE) {
|
|
60
|
+
console.log('\x1b[2m%s\x1b[0m', logMessage); // dim
|
|
58
61
|
}
|
|
59
62
|
else {
|
|
60
|
-
|
|
63
|
+
console.log(logMessage);
|
|
61
64
|
}
|
|
62
65
|
}
|
|
63
66
|
}
|
|
@@ -83,12 +86,26 @@ export const stringifyError = (error) => {
|
|
|
83
86
|
return JSON.stringify(retObj);
|
|
84
87
|
}
|
|
85
88
|
};
|
|
89
|
+
// Return a space if there should be a space between the message and the level
|
|
90
|
+
function gap(message) {
|
|
91
|
+
return String(message)?.indexOf('[') === 0 ? '' : ' ';
|
|
92
|
+
}
|
|
93
|
+
function logError(err, additionalInfo) {
|
|
94
|
+
if (err instanceof DiagnosticsError || !err || !err.message) {
|
|
95
|
+
log(ERROR, stringifyError(err), additionalInfo);
|
|
96
|
+
}
|
|
97
|
+
// If this is an error with a message update the message header and log as is...
|
|
98
|
+
if (err && err.message) {
|
|
99
|
+
err.message = `[${ERROR}]${gap(err.message)}${err.message}`;
|
|
100
|
+
console.error('\x1b[31m%s\x1b[0m', err);
|
|
101
|
+
}
|
|
102
|
+
}
|
|
86
103
|
export const logger = {
|
|
87
104
|
verbose: (message, additionalInfo) => log(VERBOSE, message, additionalInfo),
|
|
88
105
|
debug: (message, additionalInfo) => log(DEBUG, message, additionalInfo),
|
|
89
106
|
info: (message, additionalInfo) => log(INFO, message, additionalInfo),
|
|
90
107
|
warn: (message, additionalInfo) => log(WARN, message, additionalInfo),
|
|
91
|
-
error: (error, additionalInfo) =>
|
|
108
|
+
error: (error, additionalInfo) => logError(error, additionalInfo),
|
|
92
109
|
log,
|
|
93
110
|
setOptions: (opts) => {
|
|
94
111
|
options = opts;
|
package/build/es/mappings.d.ts
CHANGED
|
@@ -15,5 +15,5 @@ export declare function getImportMetadataMappings(moduleIds: AbstractModuleId[],
|
|
|
15
15
|
* @param existingImportMetadata Optional existing ImportMetadata. If provided the results will be a merge the two sets of URI mappings.
|
|
16
16
|
* @returns Returns ImportMetadata from a module graph in the format here -> https://rfcs.lwc.dev/rfcs/lwr/0000-mapping-api#uri-mapping-resource-specification
|
|
17
17
|
*/
|
|
18
|
-
export declare function toImportMetadata(moduleGraph: FlattenedModuleGraphs, existingImportMetadata: ImportMetadata | undefined,
|
|
18
|
+
export declare function toImportMetadata(moduleGraph: FlattenedModuleGraphs, existingImportMetadata: ImportMetadata | undefined, defRegistry: ModuleRegistry | ModuleBundler, runtimeEnvironment: RuntimeEnvironment, runtimeParams?: RuntimeParams): Promise<ImportMetadata>;
|
|
19
19
|
//# sourceMappingURL=mappings.d.ts.map
|
package/build/es/mappings.js
CHANGED
|
@@ -53,7 +53,7 @@ export async function getImportMetadataMappings(moduleIds, runtimeEnvironment, r
|
|
|
53
53
|
* @param existingImportMetadata Optional existing ImportMetadata. If provided the results will be a merge the two sets of URI mappings.
|
|
54
54
|
* @returns Returns ImportMetadata from a module graph in the format here -> https://rfcs.lwc.dev/rfcs/lwr/0000-mapping-api#uri-mapping-resource-specification
|
|
55
55
|
*/
|
|
56
|
-
export async function toImportMetadata(moduleGraph, existingImportMetadata = { imports: {}, index: {} },
|
|
56
|
+
export async function toImportMetadata(moduleGraph, existingImportMetadata = { imports: {}, index: {} }, defRegistry, runtimeEnvironment, runtimeParams = {}) {
|
|
57
57
|
// root module specifier
|
|
58
58
|
const specifier = moduleGraph.graphs[0].specifier;
|
|
59
59
|
const uri = moduleGraph.uriMap[specifier];
|
|
@@ -65,7 +65,7 @@ export async function toImportMetadata(moduleGraph, existingImportMetadata = { i
|
|
|
65
65
|
throw new Error('Linked module definition was not included in the graph: ' + specifier);
|
|
66
66
|
}
|
|
67
67
|
// Merge in the existing metadata with imports for the root specifier
|
|
68
|
-
const rootMetadata = await normalizeImportMetadata(specifier, uri, definition,
|
|
68
|
+
const rootMetadata = await normalizeImportMetadata(specifier, uri, definition, defRegistry, runtimeEnvironment, runtimeParams);
|
|
69
69
|
let importMetadata = mergeImportMetadata(existingImportMetadata, rootMetadata);
|
|
70
70
|
// root module dependencies:
|
|
71
71
|
// - static for AMD; dynamic dependencies require a new mapping request
|
|
@@ -91,7 +91,7 @@ export async function toImportMetadata(moduleGraph, existingImportMetadata = { i
|
|
|
91
91
|
}
|
|
92
92
|
if (!importMetadata.imports[depUri]) {
|
|
93
93
|
// eslint-disable-next-line no-await-in-loop
|
|
94
|
-
const depMetadata = await normalizeImportMetadata(getSpecifier(depDef), depUri, depDef,
|
|
94
|
+
const depMetadata = await normalizeImportMetadata(getSpecifier(depDef), depUri, depDef, defRegistry, runtimeEnvironment, runtimeParams);
|
|
95
95
|
importMetadata = mergeImportMetadata(importMetadata, depMetadata);
|
|
96
96
|
}
|
|
97
97
|
}
|
|
@@ -110,12 +110,12 @@ function mergeImportMetadata(existing, newMetadata) {
|
|
|
110
110
|
},
|
|
111
111
|
};
|
|
112
112
|
}
|
|
113
|
-
async function normalizeImportMetadata(specifier, uri, definition,
|
|
113
|
+
async function normalizeImportMetadata(specifier, uri, definition, defRegistry, moduleRuntimeEnvironment, runtimeParams) {
|
|
114
114
|
const specifiers = normalizedIncludedModules(definition);
|
|
115
115
|
const imports = {};
|
|
116
116
|
imports[uri] = specifiers;
|
|
117
117
|
// The index info for the modules included in a bundle
|
|
118
|
-
const index = await createIndex(specifiers,
|
|
118
|
+
const index = await createIndex(specifiers, defRegistry, moduleRuntimeEnvironment, runtimeParams);
|
|
119
119
|
// If root specifier was not included in createIndex add an entry where the uri is the index
|
|
120
120
|
if (!(specifier in index)) {
|
|
121
121
|
index[specifier] = uri;
|
|
@@ -132,7 +132,7 @@ function normalizedIncludedModules(definition) {
|
|
|
132
132
|
? [getSpecifier(definition), ...definition.bundleRecord.includedModules]
|
|
133
133
|
: [getSpecifier(definition)];
|
|
134
134
|
}
|
|
135
|
-
async function createIndex(specifiers,
|
|
135
|
+
async function createIndex(specifiers, defRegistry, runtimeEnvironment, runtimeParams) {
|
|
136
136
|
const index = {};
|
|
137
137
|
// We need a runtime environment for modules when building the index for a bundle
|
|
138
138
|
const moduleRuntimeEnvironment = { ...runtimeEnvironment, bundle: false };
|
|
@@ -141,7 +141,7 @@ async function createIndex(specifiers, moduleRegistry, runtimeEnvironment, runti
|
|
|
141
141
|
if (!moduleId.version) {
|
|
142
142
|
throw new Error('Module specifier must include a version: ' + specifier);
|
|
143
143
|
}
|
|
144
|
-
index[specifier] = await
|
|
144
|
+
index[specifier] = await defRegistry.resolveModuleUri({ ...moduleId, version: moduleId.version }, moduleRuntimeEnvironment, runtimeParams);
|
|
145
145
|
}
|
|
146
146
|
// Queue up uri requests
|
|
147
147
|
const promises = [];
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
import type { RuntimeEnvironment, SiteAssets, SiteBundles, SiteMetadata, SiteResources } from '@lwrjs/types';
|
|
2
|
+
declare type Options = {
|
|
3
|
+
rootDir: string;
|
|
4
|
+
runtimeEnvironment: RuntimeEnvironment;
|
|
5
|
+
};
|
|
6
|
+
export declare class SiteMetadataImpl implements SiteMetadata {
|
|
7
|
+
private options;
|
|
8
|
+
private siteBundles;
|
|
9
|
+
private siteResources;
|
|
10
|
+
private siteAssets;
|
|
11
|
+
constructor(options: Options);
|
|
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
|
|
@@ -0,0 +1,136 @@
|
|
|
1
|
+
import path from 'path';
|
|
2
|
+
import fs from 'fs-extra';
|
|
3
|
+
import { logger } from './logger.js';
|
|
4
|
+
const SITE_METADATA_PATH = 'site-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
|
+
getSiteBundles() {
|
|
16
|
+
return this.siteBundles;
|
|
17
|
+
}
|
|
18
|
+
getSiteResources() {
|
|
19
|
+
return this.siteResources;
|
|
20
|
+
}
|
|
21
|
+
getSiteAssets() {
|
|
22
|
+
return this.siteAssets;
|
|
23
|
+
}
|
|
24
|
+
async persistSiteMetadata() {
|
|
25
|
+
// Create the metadata directory if if does not exist
|
|
26
|
+
const siteMetadataPath = path.join(this.options.rootDir, SITE_METADATA_PATH);
|
|
27
|
+
if (!(await fs.pathExists(siteMetadataPath))) {
|
|
28
|
+
await fs.mkdir(siteMetadataPath, { recursive: true });
|
|
29
|
+
}
|
|
30
|
+
// Save Bundle Metadata
|
|
31
|
+
const bundleMetadataPath = path.join(this.options.rootDir, STATIC_BUNDLE_METADATA_PATH);
|
|
32
|
+
await fs.writeJSON(bundleMetadataPath, this.siteBundles, { spaces: 2 });
|
|
33
|
+
// Save Resource Metadata
|
|
34
|
+
const resourceMetadataPath = path.join(this.options.rootDir, STATIC_RESOURCE_METADATA_PATH);
|
|
35
|
+
await fs.writeJSON(resourceMetadataPath, this.siteResources, { spaces: 2 });
|
|
36
|
+
// Save Resource Metadata
|
|
37
|
+
const assetMetadataPath = path.join(this.options.rootDir, STATIC_ASSET_METADATA_PATH);
|
|
38
|
+
return fs.writeJSON(assetMetadataPath, this.siteAssets, { spaces: 2 });
|
|
39
|
+
}
|
|
40
|
+
readStaticBundleMetadata(staticRoot) {
|
|
41
|
+
let bundleMetadataPath;
|
|
42
|
+
// Default metadata based on the current runtime environment
|
|
43
|
+
let siteBundles = {
|
|
44
|
+
bundles: {},
|
|
45
|
+
environment: {
|
|
46
|
+
format: this.options.runtimeEnvironment.format,
|
|
47
|
+
...(this.options.runtimeEnvironment.featureFlags?.LEGACY_LOADER && {
|
|
48
|
+
featureFlags: { LEGACY_LOADER: true },
|
|
49
|
+
}),
|
|
50
|
+
},
|
|
51
|
+
};
|
|
52
|
+
try {
|
|
53
|
+
bundleMetadataPath = path.join(staticRoot, STATIC_BUNDLE_METADATA_PATH);
|
|
54
|
+
const savedMetadata = fs.readJSONSync(bundleMetadataPath);
|
|
55
|
+
// Make sure the saved metadata runtime environment match the current runtime environment
|
|
56
|
+
if (this.options.runtimeEnvironment.format !== savedMetadata.environment?.format ||
|
|
57
|
+
this.options.runtimeEnvironment.featureFlags?.LEGACY_LOADER !=
|
|
58
|
+
savedMetadata.environment?.featureFlags?.LEGACY_LOADER) {
|
|
59
|
+
logger.warn('[SiteMetadata] Saved bundles do not match the current runtime. They will not be used.', { expected: savedMetadata.environment, actual: this.options.runtimeEnvironment });
|
|
60
|
+
}
|
|
61
|
+
else {
|
|
62
|
+
siteBundles = savedMetadata;
|
|
63
|
+
}
|
|
64
|
+
}
|
|
65
|
+
catch (error) {
|
|
66
|
+
if (error.code === 'ENOENT') {
|
|
67
|
+
logger.debug(`[SiteMetadata] Failed to load Static Bundle Metadata: ${bundleMetadataPath}`);
|
|
68
|
+
}
|
|
69
|
+
else {
|
|
70
|
+
throw error;
|
|
71
|
+
}
|
|
72
|
+
}
|
|
73
|
+
return siteBundles;
|
|
74
|
+
}
|
|
75
|
+
/**
|
|
76
|
+
* Read the metadata about the pre-built resources of the current site.
|
|
77
|
+
*/
|
|
78
|
+
readStaticResourceMetadata(staticRoot) {
|
|
79
|
+
let resourceMetadataPath;
|
|
80
|
+
// Default metadata based on the current runtime environment
|
|
81
|
+
let siteResources = {
|
|
82
|
+
resources: {},
|
|
83
|
+
environment: {
|
|
84
|
+
format: this.options.runtimeEnvironment.format,
|
|
85
|
+
...(this.options.runtimeEnvironment.featureFlags?.LEGACY_LOADER && {
|
|
86
|
+
featureFlags: { LEGACY_LOADER: true },
|
|
87
|
+
}),
|
|
88
|
+
},
|
|
89
|
+
};
|
|
90
|
+
try {
|
|
91
|
+
resourceMetadataPath = path.join(staticRoot, STATIC_RESOURCE_METADATA_PATH);
|
|
92
|
+
const savedMetadata = fs.readJSONSync(resourceMetadataPath);
|
|
93
|
+
// Make sure the savedMetaadta runtime environment match the current runtime environment
|
|
94
|
+
if (this.options.runtimeEnvironment.format !== savedMetadata.environment?.format ||
|
|
95
|
+
this.options.runtimeEnvironment.featureFlags?.LEGACY_LOADER !=
|
|
96
|
+
savedMetadata.environment?.featureFlags?.LEGACY_LOADER) {
|
|
97
|
+
logger.warn('[SiteMetadata] Saved resources do not match the current runtime. They will not be used.', { expected: savedMetadata.environment, actual: this.options.runtimeEnvironment });
|
|
98
|
+
}
|
|
99
|
+
else {
|
|
100
|
+
siteResources = savedMetadata;
|
|
101
|
+
}
|
|
102
|
+
}
|
|
103
|
+
catch (error) {
|
|
104
|
+
if (error.code === 'ENOENT') {
|
|
105
|
+
logger.debug(`[SiteMetadata] Failed to load Static Resource Metadata: ${resourceMetadataPath}`);
|
|
106
|
+
}
|
|
107
|
+
else {
|
|
108
|
+
throw error;
|
|
109
|
+
}
|
|
110
|
+
}
|
|
111
|
+
return siteResources;
|
|
112
|
+
}
|
|
113
|
+
/**
|
|
114
|
+
* Read the metadata about the pre-built assets of the current site.
|
|
115
|
+
*/
|
|
116
|
+
readStaticAssetsMetadata(staticRoot) {
|
|
117
|
+
let assetMetadataPath;
|
|
118
|
+
let siteAssets = {
|
|
119
|
+
assets: {},
|
|
120
|
+
};
|
|
121
|
+
try {
|
|
122
|
+
assetMetadataPath = path.join(staticRoot, STATIC_ASSET_METADATA_PATH);
|
|
123
|
+
siteAssets = fs.readJSONSync(assetMetadataPath);
|
|
124
|
+
}
|
|
125
|
+
catch (error) {
|
|
126
|
+
if (error.code === 'ENOENT') {
|
|
127
|
+
logger.debug(`[SiteMetadata] Failed to load Static Resource Metadata: ${assetMetadataPath}`);
|
|
128
|
+
}
|
|
129
|
+
else {
|
|
130
|
+
throw error;
|
|
131
|
+
}
|
|
132
|
+
}
|
|
133
|
+
return siteAssets;
|
|
134
|
+
}
|
|
135
|
+
}
|
|
136
|
+
//# sourceMappingURL=site-metadata.js.map
|
package/build/es/typescript.js
CHANGED
|
@@ -1,8 +1,9 @@
|
|
|
1
1
|
import fs from 'fs';
|
|
2
2
|
import { join, dirname, extname } from 'path';
|
|
3
3
|
import esbuildEsm from 'esbuild';
|
|
4
|
-
// Workaround until this is fixed:
|
|
5
4
|
// https://github.com/evanw/esbuild/issues/706
|
|
5
|
+
// Fixed in 0.11.0 but upgrading past 0.9.7 has caused breaking changes for consumers...
|
|
6
|
+
// https://github.com/salesforce-experience-platform/lwr/issues/1014
|
|
6
7
|
let esbuild = esbuildEsm;
|
|
7
8
|
if (!esbuildEsm) {
|
|
8
9
|
try {
|
package/package.json
CHANGED
|
@@ -4,7 +4,7 @@
|
|
|
4
4
|
"publishConfig": {
|
|
5
5
|
"access": "public"
|
|
6
6
|
},
|
|
7
|
-
"version": "0.9.0-alpha.
|
|
7
|
+
"version": "0.9.0-alpha.14",
|
|
8
8
|
"homepage": "https://developer.salesforce.com/docs/platform/lwr/overview",
|
|
9
9
|
"repository": {
|
|
10
10
|
"type": "git",
|
|
@@ -29,6 +29,14 @@
|
|
|
29
29
|
"./fs-watch": {
|
|
30
30
|
"import": "./build/es/fs-watch.js",
|
|
31
31
|
"require": "./build/cjs/fs-watch.cjs"
|
|
32
|
+
},
|
|
33
|
+
"./typescript": {
|
|
34
|
+
"import": "./build/es/typescript.js",
|
|
35
|
+
"require": "./build/cjs/typescript.cjs"
|
|
36
|
+
},
|
|
37
|
+
"./compiler": {
|
|
38
|
+
"import": "./build/es/compiler.js",
|
|
39
|
+
"require": "./build/cjs/compiler.cjs"
|
|
32
40
|
}
|
|
33
41
|
},
|
|
34
42
|
"files": [
|
|
@@ -38,7 +46,6 @@
|
|
|
38
46
|
],
|
|
39
47
|
"dependencies": {
|
|
40
48
|
"es-module-lexer": "^0.3.18",
|
|
41
|
-
"esbuild": "^0.9.7",
|
|
42
49
|
"fast-json-stable-stringify": "^2.1.0",
|
|
43
50
|
"magic-string": "^0.25.7",
|
|
44
51
|
"mime-types": "^2.1.33",
|
|
@@ -48,16 +55,19 @@
|
|
|
48
55
|
"slugify": "^1.4.5"
|
|
49
56
|
},
|
|
50
57
|
"optionalDependencies": {
|
|
51
|
-
"
|
|
58
|
+
"@locker/compiler": "0.18.2",
|
|
59
|
+
"chokidar": "^3.5.3",
|
|
60
|
+
"esbuild": "^0.9.7",
|
|
61
|
+
"rollup": "~2.45.2"
|
|
52
62
|
},
|
|
53
63
|
"devDependencies": {
|
|
54
|
-
"@lwrjs/diagnostics": "0.9.0-alpha.
|
|
55
|
-
"@lwrjs/types": "0.9.0-alpha.
|
|
64
|
+
"@lwrjs/diagnostics": "0.9.0-alpha.14",
|
|
65
|
+
"@lwrjs/types": "0.9.0-alpha.14",
|
|
56
66
|
"@types/mime-types": "2.1.1",
|
|
57
67
|
"@types/path-to-regexp": "^1.7.0"
|
|
58
68
|
},
|
|
59
69
|
"engines": {
|
|
60
70
|
"node": ">=14.15.4 <19"
|
|
61
71
|
},
|
|
62
|
-
"gitHead": "
|
|
72
|
+
"gitHead": "64e0ba617151429da6e09f1a9686628f64183d25"
|
|
63
73
|
}
|