@lwrjs/static 0.13.0-alpha.6 → 0.13.0-alpha.8
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/{utils/static-utils.cjs → index.cjs} +2 -19
- package/build/cjs/providers/static-bundle-provider.cjs +31 -27
- package/build/cjs/providers/static-module-provider.cjs +32 -13
- package/build/cjs/providers/static-resource-provider.cjs +5 -5
- package/build/cjs/site-metadata.cjs +65 -1
- package/build/cjs/tools/dedupe-bundles.cjs +108 -0
- package/build/cjs/utils/decision-tree.cjs +201 -0
- package/build/es/index.d.ts +2 -0
- package/build/es/index.js +2 -0
- package/build/es/providers/static-bundle-provider.d.ts +8 -4
- package/build/es/providers/static-bundle-provider.js +37 -29
- package/build/es/providers/static-module-provider.d.ts +4 -2
- package/build/es/providers/static-module-provider.js +32 -13
- package/build/es/providers/static-resource-provider.d.ts +1 -2
- package/build/es/providers/static-resource-provider.js +9 -7
- package/build/es/site-metadata.d.ts +48 -1
- package/build/es/site-metadata.js +101 -0
- package/build/es/tools/dedupe-bundles.d.ts +3 -0
- package/build/es/tools/dedupe-bundles.js +89 -0
- package/build/es/utils/decision-tree.d.ts +29 -0
- package/build/es/utils/decision-tree.js +267 -0
- package/package.json +9 -5
- package/build/es/utils/static-utils.d.ts +0 -12
- package/build/es/utils/static-utils.js +0 -23
|
@@ -5,10 +5,6 @@ var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
|
5
5
|
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
6
6
|
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
7
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
8
|
var __exportStar = (target, module2, desc) => {
|
|
13
9
|
if (module2 && typeof module2 === "object" || typeof module2 === "function") {
|
|
14
10
|
for (let key of __getOwnPropNames(module2))
|
|
@@ -21,19 +17,6 @@ var __toModule = (module2) => {
|
|
|
21
17
|
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
18
|
};
|
|
23
19
|
|
|
24
|
-
// packages/@lwrjs/static/src/
|
|
20
|
+
// packages/@lwrjs/static/src/index.ts
|
|
25
21
|
__markAsModule(exports);
|
|
26
|
-
|
|
27
|
-
getLocalizedBundle: () => getLocalizedBundle,
|
|
28
|
-
resolveStaticBundleVersion: () => resolveStaticBundleVersion
|
|
29
|
-
});
|
|
30
|
-
var import_shared_utils = __toModule(require("@lwrjs/shared-utils"));
|
|
31
|
-
function resolveStaticBundleVersion(metadataVersion, requestedVersion) {
|
|
32
|
-
return metadataVersion || requestedVersion || import_shared_utils.VERSION_NOT_PROVIDED;
|
|
33
|
-
}
|
|
34
|
-
async function getLocalizedBundle(specifier, siteBundles, initialLocaleId, i18n) {
|
|
35
|
-
return (0, import_shared_utils.walkLocaleFallbacks)(initialLocaleId, i18n, async (localeId) => {
|
|
36
|
-
const localizedSpecifier = localeId === i18n.defaultLocale ? specifier : `${specifier}|l/${localeId}`;
|
|
37
|
-
return siteBundles.bundles[localizedSpecifier];
|
|
38
|
-
});
|
|
39
|
-
}
|
|
22
|
+
__exportStar(exports, __toModule(require("./tools/dedupe-bundles.cjs")));
|
|
@@ -30,15 +30,14 @@ var import_diagnostics = __toModule(require("@lwrjs/diagnostics"));
|
|
|
30
30
|
var import_shared_utils = __toModule(require("@lwrjs/shared-utils"));
|
|
31
31
|
var import_path = __toModule(require("path"));
|
|
32
32
|
var import_fs_extra = __toModule(require("fs-extra"));
|
|
33
|
-
var
|
|
33
|
+
var import_site_metadata = __toModule(require("../site-metadata.cjs"));
|
|
34
34
|
var StaticBundleProvider = class {
|
|
35
35
|
constructor(_config, context) {
|
|
36
36
|
this.name = "static-bundle-provider";
|
|
37
37
|
if (!context.siteMetadata) {
|
|
38
38
|
throw new Error(`[${this.name}] Site metadata was not found`);
|
|
39
39
|
}
|
|
40
|
-
this.
|
|
41
|
-
this.debugSiteBundles = context.siteMetadata.getDebugSiteBundles();
|
|
40
|
+
this.siteMetadata = context.siteMetadata;
|
|
42
41
|
this.siteRootDir = context.siteMetadata.getSiteRootDir();
|
|
43
42
|
this.bundleConfig = context.config.bundleConfig;
|
|
44
43
|
this.i18n = context.config.i18n;
|
|
@@ -50,32 +49,23 @@ var StaticBundleProvider = class {
|
|
|
50
49
|
i18n: {defaultLocale}
|
|
51
50
|
} = runtimeEnvironment;
|
|
52
51
|
const localeId = runtimeParams?.locale || defaultLocale;
|
|
53
|
-
const
|
|
54
|
-
const metadata = await (0, import_static_utils.getLocalizedBundle)(specifier, siteBundles, localeId, this.i18n);
|
|
52
|
+
const metadata = this.getBundleMetadata(moduleId, localeId, debug);
|
|
55
53
|
if (!metadata) {
|
|
56
54
|
return void 0;
|
|
57
55
|
}
|
|
58
56
|
const bundlePath = import_path.default.join(this.siteRootDir, metadata.path);
|
|
59
|
-
const code = await this.getCode(bundlePath, debug, specifier, localeId);
|
|
60
|
-
const imports = metadata.imports.map((
|
|
61
|
-
|
|
62
|
-
if (!importModule.version) {
|
|
63
|
-
importModule.version = (0, import_static_utils.resolveStaticBundleVersion)(this.siteBundles.bundles[specifier2]?.version);
|
|
64
|
-
}
|
|
65
|
-
return importModule;
|
|
66
|
-
});
|
|
67
|
-
const dynamicImports = metadata.dynamicImports?.map((specifier2) => {
|
|
68
|
-
const dynamicImportModule = (0, import_shared_utils.explodeSpecifier)(specifier2);
|
|
69
|
-
if (!dynamicImportModule.version) {
|
|
70
|
-
dynamicImportModule.version = (0, import_static_utils.resolveStaticBundleVersion)(this.siteBundles.bundles[specifier2]?.version);
|
|
71
|
-
}
|
|
72
|
-
return dynamicImportModule;
|
|
73
|
-
});
|
|
57
|
+
const code = await this.getCode(bundlePath, debug, specifier, version, localeId);
|
|
58
|
+
const imports = metadata.imports.map((importSpecifier) => this.getModuleReference(importSpecifier, localeId, debug));
|
|
59
|
+
const dynamicImports = metadata.dynamicImports?.map((importSpecifier) => this.getModuleReference(importSpecifier, localeId, debug));
|
|
74
60
|
const id = (0, import_shared_utils.getSpecifier)(moduleId);
|
|
75
61
|
const exploded = (0, import_shared_utils.explodeSpecifier)(id);
|
|
76
|
-
const resolvedName = name
|
|
77
|
-
const resolvedNamespace = namespace
|
|
78
|
-
const resolvedVersion = (0,
|
|
62
|
+
const resolvedName = name ?? exploded.name;
|
|
63
|
+
const resolvedNamespace = namespace ?? exploded.namespace;
|
|
64
|
+
const resolvedVersion = (0, import_site_metadata.resolveStaticBundleVersion)(metadata.version, version);
|
|
65
|
+
const includedModules = metadata.includedModules?.map((includedId) => {
|
|
66
|
+
const includedModule = this.getModuleReference(includedId, localeId, debug);
|
|
67
|
+
return (0, import_shared_utils.getSpecifier)(includedModule);
|
|
68
|
+
}) || [];
|
|
79
69
|
return {
|
|
80
70
|
code,
|
|
81
71
|
id: (0, import_shared_utils.getSpecifier)({
|
|
@@ -90,20 +80,34 @@ var StaticBundleProvider = class {
|
|
|
90
80
|
specifier,
|
|
91
81
|
config: this.bundleConfig,
|
|
92
82
|
bundleRecord: {
|
|
93
|
-
includedModules
|
|
83
|
+
includedModules,
|
|
94
84
|
imports,
|
|
95
85
|
dynamicImports
|
|
96
86
|
},
|
|
97
87
|
src: bundlePath
|
|
98
88
|
};
|
|
99
89
|
}
|
|
100
|
-
|
|
90
|
+
getBundleMetadata(moduleId, localeId, debug) {
|
|
91
|
+
const siteBundleId = (0, import_site_metadata.getSiteBundleId)(moduleId, localeId, this.i18n);
|
|
92
|
+
return this.siteMetadata.getSiteBundlesDecisionTree().find(siteBundleId, debug);
|
|
93
|
+
}
|
|
94
|
+
getModuleReference(siteBundleIdStr, localeId, debug) {
|
|
95
|
+
const siteBundleId = (0, import_site_metadata.parseSiteId)(siteBundleIdStr);
|
|
96
|
+
const includedModule = (0, import_shared_utils.explodeSpecifier)(siteBundleId.specifier);
|
|
97
|
+
if (!siteBundleId.variants[import_shared_utils.VERSION_SIGIL]) {
|
|
98
|
+
const importBundleMetadata = this.siteMetadata.getSiteBundlesDecisionTree().find(siteBundleIdStr, debug, localeId);
|
|
99
|
+
includedModule.version = (0, import_site_metadata.resolveStaticBundleVersion)(importBundleMetadata?.version);
|
|
100
|
+
} else {
|
|
101
|
+
includedModule.version = siteBundleId.variants[import_shared_utils.VERSION_SIGIL];
|
|
102
|
+
}
|
|
103
|
+
return includedModule;
|
|
104
|
+
}
|
|
105
|
+
async getCode(bundlePath, debug, specifier, version, localeId) {
|
|
101
106
|
const isLambda = process.env.AWS_LAMBDA_FUNCTION_NAME !== void 0;
|
|
102
107
|
let bundleSourcePath = bundlePath;
|
|
103
108
|
try {
|
|
104
109
|
if (debug && isLambda) {
|
|
105
|
-
const
|
|
106
|
-
const metadata = await (0, import_static_utils.getLocalizedBundle)(specifier, siteBundles, localeId, this.i18n);
|
|
110
|
+
const metadata = this.getBundleMetadata({specifier, version}, localeId, false);
|
|
107
111
|
if (!metadata) {
|
|
108
112
|
import_diagnostics.logger.warn({
|
|
109
113
|
label: "static-bundle-provider",
|
|
@@ -29,7 +29,7 @@ __export(exports, {
|
|
|
29
29
|
var import_diagnostics = __toModule(require("@lwrjs/diagnostics"));
|
|
30
30
|
var import_shared_utils = __toModule(require("@lwrjs/shared-utils"));
|
|
31
31
|
var import_path = __toModule(require("path"));
|
|
32
|
-
var
|
|
32
|
+
var import_site_metadata = __toModule(require("../site-metadata.cjs"));
|
|
33
33
|
var StaticModuleProvider = class {
|
|
34
34
|
constructor(_config, context) {
|
|
35
35
|
this.name = "static-module-provider";
|
|
@@ -37,15 +37,14 @@ var StaticModuleProvider = class {
|
|
|
37
37
|
throw new Error(`[${this.name}] Site metadata was not found`);
|
|
38
38
|
}
|
|
39
39
|
this.externals = Object.keys(context.config.bundleConfig.external || {});
|
|
40
|
-
this.siteBundles = context.siteMetadata.getSiteBundles();
|
|
41
40
|
this.siteRootDir = context.siteMetadata.getSiteRootDir();
|
|
42
41
|
this.i18n = context.config.i18n;
|
|
42
|
+
this.siteMetadata = context.siteMetadata;
|
|
43
43
|
this.fingerprintIndex = buildFingerprintsIndex(context);
|
|
44
44
|
}
|
|
45
45
|
async getModule(moduleId, runtimeParams) {
|
|
46
|
-
const {specifier} = moduleId;
|
|
47
46
|
const localeId = runtimeParams?.locale || this.i18n.defaultLocale;
|
|
48
|
-
const metadata =
|
|
47
|
+
const metadata = this.getBundleMetadata(moduleId, localeId, false);
|
|
49
48
|
if (metadata) {
|
|
50
49
|
import_diagnostics.logger.warn({
|
|
51
50
|
label: `${this.name}`,
|
|
@@ -58,14 +57,14 @@ var StaticModuleProvider = class {
|
|
|
58
57
|
async getModuleEntry(moduleId, runtimeParams) {
|
|
59
58
|
const {specifier, version} = moduleId;
|
|
60
59
|
const localeId = runtimeParams?.locale || this.i18n.defaultLocale;
|
|
61
|
-
const metadata =
|
|
60
|
+
const metadata = this.getBundleMetadata(moduleId, localeId, false);
|
|
62
61
|
if (metadata) {
|
|
63
62
|
import_diagnostics.logger.debug({
|
|
64
63
|
label: `${this.name}`,
|
|
65
64
|
message: `Module Entry request for static bundle ${specifier}`
|
|
66
65
|
});
|
|
67
66
|
const bundlePath = import_path.default.join(this.siteRootDir, metadata.path);
|
|
68
|
-
const resolvedVersion = (0,
|
|
67
|
+
const resolvedVersion = (0, import_site_metadata.resolveStaticBundleVersion)(metadata.version, version);
|
|
69
68
|
return {
|
|
70
69
|
id: (0, import_shared_utils.getSpecifier)({...moduleId, version: resolvedVersion}),
|
|
71
70
|
version: resolvedVersion,
|
|
@@ -74,17 +73,23 @@ var StaticModuleProvider = class {
|
|
|
74
73
|
src: bundlePath
|
|
75
74
|
};
|
|
76
75
|
} else if (this.externals.includes(specifier)) {
|
|
77
|
-
const resolvedVersion = (0,
|
|
76
|
+
const resolvedVersion = (0, import_site_metadata.resolveStaticBundleVersion)(void 0, version);
|
|
78
77
|
return {
|
|
79
78
|
id: (0, import_shared_utils.getSpecifier)({...moduleId, version: resolvedVersion}),
|
|
80
79
|
version: resolvedVersion,
|
|
81
80
|
specifier,
|
|
82
81
|
entry: "entry-not-provided"
|
|
83
82
|
};
|
|
84
|
-
} else if (this.fingerprintIndex[specifier]) {
|
|
85
|
-
return this.fingerprintIndex[specifier];
|
|
86
83
|
}
|
|
87
|
-
return
|
|
84
|
+
return this.getEntryFromFingerprintIndex(moduleId);
|
|
85
|
+
}
|
|
86
|
+
getEntryFromFingerprintIndex(moduleId) {
|
|
87
|
+
const versionedSpecifier = (0, import_shared_utils.getSpecifier)(moduleId);
|
|
88
|
+
return this.fingerprintIndex[versionedSpecifier] || this.fingerprintIndex[moduleId.specifier];
|
|
89
|
+
}
|
|
90
|
+
getBundleMetadata(moduleId, localeId, debug) {
|
|
91
|
+
const siteBundleId = (0, import_site_metadata.getSiteBundleId)(moduleId, localeId, this.i18n);
|
|
92
|
+
return this.siteMetadata.getSiteBundlesDecisionTree().find(siteBundleId, debug);
|
|
88
93
|
}
|
|
89
94
|
};
|
|
90
95
|
var static_module_provider_default = StaticModuleProvider;
|
|
@@ -96,11 +101,21 @@ function buildFingerprintsIndex(context) {
|
|
|
96
101
|
const bundlePath = import_path.default.join(String(context.siteMetadata?.getSiteRootDir()), bundle.path);
|
|
97
102
|
const includedModules = bundle.includedModules || [];
|
|
98
103
|
for (const includedModule of includedModules) {
|
|
99
|
-
const
|
|
104
|
+
const versionedSpecifier = convertSiteIdToVersionedSpecifier(includedModule);
|
|
105
|
+
const moduleId = (0, import_shared_utils.explodeSpecifier)(versionedSpecifier);
|
|
106
|
+
if (!fingerprintIndex[versionedSpecifier]) {
|
|
107
|
+
fingerprintIndex[versionedSpecifier] = {
|
|
108
|
+
id: versionedSpecifier,
|
|
109
|
+
version: (0, import_site_metadata.resolveStaticBundleVersion)(moduleId.version),
|
|
110
|
+
specifier: moduleId.specifier,
|
|
111
|
+
entry: "entry-not-provided",
|
|
112
|
+
src: bundlePath
|
|
113
|
+
};
|
|
114
|
+
}
|
|
100
115
|
if (!fingerprintIndex[moduleId.specifier]) {
|
|
101
116
|
fingerprintIndex[moduleId.specifier] = {
|
|
102
|
-
id:
|
|
103
|
-
version: (0,
|
|
117
|
+
id: moduleId.specifier,
|
|
118
|
+
version: (0, import_site_metadata.resolveStaticBundleVersion)(moduleId.version),
|
|
104
119
|
specifier: moduleId.specifier,
|
|
105
120
|
entry: "entry-not-provided",
|
|
106
121
|
src: bundlePath
|
|
@@ -111,3 +126,7 @@ function buildFingerprintsIndex(context) {
|
|
|
111
126
|
}
|
|
112
127
|
return fingerprintIndex;
|
|
113
128
|
}
|
|
129
|
+
function convertSiteIdToVersionedSpecifier(siteId) {
|
|
130
|
+
const parsedSiteId = (0, import_site_metadata.parseSiteId)(siteId);
|
|
131
|
+
return (0, import_shared_utils.getSpecifier)({specifier: parsedSiteId.specifier, version: parsedSiteId.variants[import_shared_utils.VERSION_SIGIL]});
|
|
132
|
+
}
|
|
@@ -30,6 +30,7 @@ var import_diagnostics = __toModule(require("@lwrjs/diagnostics"));
|
|
|
30
30
|
var import_shared_utils = __toModule(require("@lwrjs/shared-utils"));
|
|
31
31
|
var import_path = __toModule(require("path"));
|
|
32
32
|
var import_fs_extra = __toModule(require("fs-extra"));
|
|
33
|
+
var import_site_metadata = __toModule(require("../site-metadata.cjs"));
|
|
33
34
|
var StaticResourceProvider = class {
|
|
34
35
|
constructor(_config, context) {
|
|
35
36
|
this.name = "static-resource-provider";
|
|
@@ -37,15 +38,14 @@ var StaticResourceProvider = class {
|
|
|
37
38
|
throw new Error(`[${this.name}] Site metadata was not found`);
|
|
38
39
|
}
|
|
39
40
|
this.resourceRegistry = context.resourceRegistry;
|
|
40
|
-
this.siteResources = context.siteMetadata.getSiteResources();
|
|
41
|
-
this.debugSiteResources = context.siteMetadata.getDebugSiteResources();
|
|
42
41
|
this.siteRootDir = context.siteMetadata.getSiteRootDir();
|
|
42
|
+
this.siteMetadata = context.siteMetadata;
|
|
43
43
|
}
|
|
44
44
|
async getResource(resourceIdentity, runtimeEnvironment) {
|
|
45
45
|
const {debug} = runtimeEnvironment;
|
|
46
|
-
const metadata = this.
|
|
47
|
-
const debugMetadata = this.
|
|
48
|
-
if (!metadata
|
|
46
|
+
const metadata = this.siteMetadata.getSiteResourcesDecisionTree().find((0, import_site_metadata.getSiteResourceId)(resourceIdentity));
|
|
47
|
+
const debugMetadata = this.siteMetadata.getSiteResourcesDecisionTree().find((0, import_site_metadata.getSiteResourceId)(resourceIdentity), true);
|
|
48
|
+
if (!metadata) {
|
|
49
49
|
import_diagnostics.logger.warn({
|
|
50
50
|
label: `${this.name}`,
|
|
51
51
|
message: `Did not find requested specifier ${resourceIdentity.specifier}`
|
|
@@ -24,17 +24,27 @@ var __toModule = (module2) => {
|
|
|
24
24
|
// packages/@lwrjs/static/src/site-metadata.ts
|
|
25
25
|
__markAsModule(exports);
|
|
26
26
|
__export(exports, {
|
|
27
|
-
|
|
27
|
+
SITE_LOCALE_PREFIX: () => SITE_LOCALE_PREFIX,
|
|
28
|
+
SITE_VERSION_PREFIX: () => SITE_VERSION_PREFIX,
|
|
29
|
+
SiteMetadataImpl: () => SiteMetadataImpl,
|
|
30
|
+
getSiteBundleId: () => getSiteBundleId,
|
|
31
|
+
getSiteResourceId: () => getSiteResourceId,
|
|
32
|
+
parseSiteId: () => parseSiteId,
|
|
33
|
+
resolveStaticBundleVersion: () => resolveStaticBundleVersion
|
|
28
34
|
});
|
|
29
35
|
var import_path = __toModule(require("path"));
|
|
30
36
|
var import_fs_extra = __toModule(require("fs-extra"));
|
|
31
37
|
var import_diagnostics = __toModule(require("@lwrjs/diagnostics"));
|
|
38
|
+
var import_decision_tree = __toModule(require("./utils/decision-tree.cjs"));
|
|
39
|
+
var import_shared_utils = __toModule(require("@lwrjs/shared-utils"));
|
|
32
40
|
var SITE_METADATA_PATH = ".metadata";
|
|
33
41
|
var STATIC_BUNDLE_METADATA_PATH = import_path.default.join(SITE_METADATA_PATH, "/bundle-metadata.json");
|
|
34
42
|
var DEBUG_STATIC_BUNDLE_METADATA_PATH = import_path.default.join(SITE_METADATA_PATH, "/bundle-metadata-debug.json");
|
|
35
43
|
var STATIC_RESOURCE_METADATA_PATH = import_path.default.join(SITE_METADATA_PATH, "/resource-metadata.json");
|
|
36
44
|
var DEBUG_STATIC_RESOURCE_METADATA_PATH = import_path.default.join(SITE_METADATA_PATH, "/resource-metadata-debug.json");
|
|
37
45
|
var STATIC_ASSET_METADATA_PATH = import_path.default.join(SITE_METADATA_PATH, "/asset-metadata.json");
|
|
46
|
+
var SITE_VERSION_PREFIX = `|${import_shared_utils.VERSION_SIGIL}/`;
|
|
47
|
+
var SITE_LOCALE_PREFIX = `|${import_shared_utils.LOCALE_SIGIL}/`;
|
|
38
48
|
var SiteMetadataImpl = class {
|
|
39
49
|
constructor(options) {
|
|
40
50
|
this.options = options;
|
|
@@ -62,6 +72,31 @@ var SiteMetadataImpl = class {
|
|
|
62
72
|
getSiteAssets() {
|
|
63
73
|
return this.siteAssets;
|
|
64
74
|
}
|
|
75
|
+
getSiteBundlesDecisionTree() {
|
|
76
|
+
if (!this.bundleDecisionTree) {
|
|
77
|
+
this.bundleDecisionTree = new import_decision_tree.default();
|
|
78
|
+
const localeFallbacks = (0, import_decision_tree.createFallbackMap)(this.options.i18n);
|
|
79
|
+
for (const [key, bundle] of Object.entries(this.siteBundles.bundles)) {
|
|
80
|
+
this.bundleDecisionTree.insert(key, bundle, false, localeFallbacks);
|
|
81
|
+
}
|
|
82
|
+
for (const [key, bundle] of Object.entries(this.debugSiteBundles.bundles)) {
|
|
83
|
+
this.bundleDecisionTree.insert(key, bundle, true, localeFallbacks);
|
|
84
|
+
}
|
|
85
|
+
}
|
|
86
|
+
return this.bundleDecisionTree;
|
|
87
|
+
}
|
|
88
|
+
getSiteResourcesDecisionTree() {
|
|
89
|
+
if (!this.resourceDecisionTree) {
|
|
90
|
+
this.resourceDecisionTree = new import_decision_tree.default();
|
|
91
|
+
for (const [key, resource] of Object.entries(this.siteResources.resources)) {
|
|
92
|
+
this.resourceDecisionTree.insert(key, resource, false);
|
|
93
|
+
}
|
|
94
|
+
for (const [key, resource] of Object.entries(this.debugSiteResources.resources)) {
|
|
95
|
+
this.resourceDecisionTree.insert(key, resource, true);
|
|
96
|
+
}
|
|
97
|
+
}
|
|
98
|
+
return this.resourceDecisionTree;
|
|
99
|
+
}
|
|
65
100
|
async persistSiteMetadata() {
|
|
66
101
|
const siteMetadataPath = import_path.default.join(this.options.rootDir, SITE_METADATA_PATH);
|
|
67
102
|
if (siteMetadataPath.indexOf("__skip_directory_creation__") !== -1)
|
|
@@ -144,3 +179,32 @@ var SiteMetadataImpl = class {
|
|
|
144
179
|
return siteAssets;
|
|
145
180
|
}
|
|
146
181
|
};
|
|
182
|
+
function resolveStaticBundleVersion(metadataVersion, requestedVersion) {
|
|
183
|
+
return metadataVersion || requestedVersion || import_shared_utils.VERSION_NOT_PROVIDED;
|
|
184
|
+
}
|
|
185
|
+
function parseSiteId(input) {
|
|
186
|
+
const parts = input.split("|");
|
|
187
|
+
const specifier = parts[0];
|
|
188
|
+
const variants = {};
|
|
189
|
+
for (let i = 1; i < parts.length; i++) {
|
|
190
|
+
const [sigil, value] = parts[i].split("/");
|
|
191
|
+
if (sigil && value) {
|
|
192
|
+
variants[sigil] = value;
|
|
193
|
+
}
|
|
194
|
+
}
|
|
195
|
+
return {
|
|
196
|
+
specifier,
|
|
197
|
+
variants
|
|
198
|
+
};
|
|
199
|
+
}
|
|
200
|
+
function getSiteBundleId({specifier, namespace, name = "", version}, locale, i18n) {
|
|
201
|
+
if (!specifier) {
|
|
202
|
+
specifier = namespace ? `${namespace}/${name}` : name;
|
|
203
|
+
}
|
|
204
|
+
const versionedSpecifier = version && version !== import_shared_utils.VERSION_NOT_PROVIDED ? `${specifier}${SITE_VERSION_PREFIX}${(0, import_shared_utils.normalizeVersionToUri)(version)}` : specifier;
|
|
205
|
+
return i18n?.defaultLocale === locale ? versionedSpecifier : `${versionedSpecifier}${SITE_LOCALE_PREFIX}${locale}`;
|
|
206
|
+
}
|
|
207
|
+
function getSiteResourceId({specifier, version}) {
|
|
208
|
+
const versionedSpecifier = version && version !== import_shared_utils.VERSION_NOT_PROVIDED ? `${specifier}${SITE_VERSION_PREFIX}${(0, import_shared_utils.normalizeVersionToUri)(version)}` : specifier;
|
|
209
|
+
return versionedSpecifier;
|
|
210
|
+
}
|
|
@@ -0,0 +1,108 @@
|
|
|
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/static/src/tools/dedupe-bundles.ts
|
|
25
|
+
__markAsModule(exports);
|
|
26
|
+
__export(exports, {
|
|
27
|
+
dedupeBundles: () => dedupeBundles
|
|
28
|
+
});
|
|
29
|
+
var import_fs_extra = __toModule(require("fs-extra"));
|
|
30
|
+
var import_path = __toModule(require("path"));
|
|
31
|
+
var import_diagnostics = __toModule(require("@lwrjs/diagnostics"));
|
|
32
|
+
var import_site_metadata = __toModule(require("../site-metadata.cjs"));
|
|
33
|
+
var import_shared_utils = __toModule(require("@lwrjs/shared-utils"));
|
|
34
|
+
async function dedupeBundles(rootDir, i18n) {
|
|
35
|
+
const siteMetadata = new import_site_metadata.SiteMetadataImpl({
|
|
36
|
+
rootDir,
|
|
37
|
+
i18n
|
|
38
|
+
});
|
|
39
|
+
const siteBundles = siteMetadata.getSiteBundles();
|
|
40
|
+
const decisionTree = siteMetadata.getSiteBundlesDecisionTree();
|
|
41
|
+
import_diagnostics.logger.info({
|
|
42
|
+
label: `dedupeBundles`,
|
|
43
|
+
message: `Deduplicating ${Object.keys(siteBundles.bundles).length} bundles`
|
|
44
|
+
});
|
|
45
|
+
for (const [siteIdStr, metadata] of Object.entries(siteBundles.bundles)) {
|
|
46
|
+
const siteId = (0, import_site_metadata.parseSiteId)(siteIdStr);
|
|
47
|
+
const localeId = siteId.variants[import_shared_utils.LOCALE_SIGIL];
|
|
48
|
+
if (!localeId || localeId === i18n.defaultLocale) {
|
|
49
|
+
continue;
|
|
50
|
+
}
|
|
51
|
+
const currentPath = import_path.default.join(rootDir, metadata.path);
|
|
52
|
+
const currentSrc = import_fs_extra.default.readFileSync(currentPath);
|
|
53
|
+
import_diagnostics.logger.debug({
|
|
54
|
+
label: `dedupeBundles`,
|
|
55
|
+
message: `${siteIdStr} -> ${(0, import_shared_utils.hashContent)(currentSrc)}`
|
|
56
|
+
});
|
|
57
|
+
const locale = i18n.locales.find((l) => l.id === localeId);
|
|
58
|
+
const fallBackLocale = locale?.fallback ?? i18n.defaultLocale;
|
|
59
|
+
const fallbackMetadata = decisionTree.find(siteIdStr, false, fallBackLocale);
|
|
60
|
+
if (fallbackMetadata) {
|
|
61
|
+
const fallbackSrc = import_fs_extra.default.readFileSync(import_path.default.join(rootDir, fallbackMetadata.path));
|
|
62
|
+
import_diagnostics.logger.debug({
|
|
63
|
+
label: `dedupeBundles`,
|
|
64
|
+
message: `fallback ${siteIdStr},${fallBackLocale} -> ${(0, import_shared_utils.hashContent)(fallbackSrc)}`
|
|
65
|
+
});
|
|
66
|
+
if (currentSrc.equals(fallbackSrc)) {
|
|
67
|
+
import_diagnostics.logger.debug({
|
|
68
|
+
label: `dedupeBundles`,
|
|
69
|
+
message: `Remove duplicate variant ${siteIdStr}`
|
|
70
|
+
});
|
|
71
|
+
delete siteBundles.bundles[siteIdStr];
|
|
72
|
+
if (metadata.path != fallbackMetadata.path) {
|
|
73
|
+
import_fs_extra.default.removeSync(currentPath);
|
|
74
|
+
}
|
|
75
|
+
}
|
|
76
|
+
}
|
|
77
|
+
}
|
|
78
|
+
import_diagnostics.logger.info({
|
|
79
|
+
label: `dedupeBundles`,
|
|
80
|
+
message: `Deduplicated down to ${Object.keys(siteBundles.bundles).length} bundles`
|
|
81
|
+
});
|
|
82
|
+
await siteMetadata.persistSiteMetadata();
|
|
83
|
+
deleteEmptyFolders(rootDir);
|
|
84
|
+
}
|
|
85
|
+
function deleteEmptyFolders(directory) {
|
|
86
|
+
if (!import_fs_extra.default.existsSync(directory)) {
|
|
87
|
+
import_diagnostics.logger.warn({label: `dedupeBundles`, message: `Directory does not exist: ${directory}`});
|
|
88
|
+
return;
|
|
89
|
+
}
|
|
90
|
+
const files = import_fs_extra.default.readdirSync(directory);
|
|
91
|
+
if (files.length === 0) {
|
|
92
|
+
import_fs_extra.default.rmdirSync(directory);
|
|
93
|
+
import_diagnostics.logger.debug({label: `dedupeBundles`, message: `Deleted empty folder: ${directory}`});
|
|
94
|
+
return;
|
|
95
|
+
}
|
|
96
|
+
files.forEach((file) => {
|
|
97
|
+
const filePath = import_path.default.join(directory, file);
|
|
98
|
+
const isDirectory = import_fs_extra.default.statSync(filePath).isDirectory();
|
|
99
|
+
if (isDirectory) {
|
|
100
|
+
deleteEmptyFolders(filePath);
|
|
101
|
+
}
|
|
102
|
+
});
|
|
103
|
+
const updatedFiles = import_fs_extra.default.readdirSync(directory);
|
|
104
|
+
if (updatedFiles.length === 0) {
|
|
105
|
+
import_fs_extra.default.rmdirSync(directory);
|
|
106
|
+
import_diagnostics.logger.debug({label: `dedupeBundles`, message: `Deleted empty folder: ${directory}`});
|
|
107
|
+
}
|
|
108
|
+
}
|
|
@@ -0,0 +1,201 @@
|
|
|
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/static/src/utils/decision-tree.ts
|
|
25
|
+
__markAsModule(exports);
|
|
26
|
+
__export(exports, {
|
|
27
|
+
createFallbackMap: () => createFallbackMap,
|
|
28
|
+
default: () => decision_tree_default
|
|
29
|
+
});
|
|
30
|
+
var import_diagnostics = __toModule(require("@lwrjs/diagnostics"));
|
|
31
|
+
var import_shared_utils = __toModule(require("@lwrjs/shared-utils"));
|
|
32
|
+
var import_site_metadata = __toModule(require("../site-metadata.cjs"));
|
|
33
|
+
var CHOICE_WILDCARD = "*";
|
|
34
|
+
var CHOICE_EMPTY = "";
|
|
35
|
+
var CHOICE_PROD = "prod";
|
|
36
|
+
var CHOICE_DEBUG = "debug";
|
|
37
|
+
var DecisionTreeImpl = class {
|
|
38
|
+
constructor() {
|
|
39
|
+
this.root = new TreeNode();
|
|
40
|
+
}
|
|
41
|
+
insert(siteArtifactId, artifact, debug, localeFallbacks) {
|
|
42
|
+
const decisionPath = this.createPossibleArtifactChoices({
|
|
43
|
+
id: siteArtifactId,
|
|
44
|
+
localeFallbacks,
|
|
45
|
+
debug
|
|
46
|
+
});
|
|
47
|
+
const choices = decisionPath[0];
|
|
48
|
+
const isLeaf = decisionPath.length == 1;
|
|
49
|
+
for (const [index, key] of choices.entries()) {
|
|
50
|
+
const rank = [index];
|
|
51
|
+
if (!this.root.getChild(key, false)) {
|
|
52
|
+
this.root.addChild(key, new TreeNode(key, ""));
|
|
53
|
+
}
|
|
54
|
+
const nextNode = this.root.getChild(key, false);
|
|
55
|
+
if (isLeaf) {
|
|
56
|
+
nextNode.setArtifact(artifact, rank);
|
|
57
|
+
} else {
|
|
58
|
+
this.deepInsert(1, decisionPath, key, nextNode, artifact, rank);
|
|
59
|
+
}
|
|
60
|
+
}
|
|
61
|
+
}
|
|
62
|
+
deepInsert(level, decisionPath, currentPath, currentNode, artifact, rank) {
|
|
63
|
+
if (level >= decisionPath.length)
|
|
64
|
+
return;
|
|
65
|
+
const choices = decisionPath[level];
|
|
66
|
+
const isLeaf = level === decisionPath.length - 1;
|
|
67
|
+
for (const [index, key] of choices.entries()) {
|
|
68
|
+
const nextRank = [...rank, index];
|
|
69
|
+
if (!currentNode.getChild(key, false)) {
|
|
70
|
+
currentNode.addChild(key, new TreeNode(key, currentPath));
|
|
71
|
+
}
|
|
72
|
+
const nextNode = currentNode.getChild(key, false);
|
|
73
|
+
if (isLeaf) {
|
|
74
|
+
nextNode.setArtifact(artifact, nextRank);
|
|
75
|
+
} else {
|
|
76
|
+
this.deepInsert(level + 1, decisionPath, `${currentPath}/${key}`, nextNode, artifact, nextRank);
|
|
77
|
+
}
|
|
78
|
+
}
|
|
79
|
+
}
|
|
80
|
+
find(siteArtifactId, debug, localeId) {
|
|
81
|
+
const parsedArtifactId = (0, import_site_metadata.parseSiteId)(siteArtifactId);
|
|
82
|
+
const decisionPath = this.createArtifactChoices({
|
|
83
|
+
specifier: parsedArtifactId.specifier,
|
|
84
|
+
version: parsedArtifactId.variants[import_shared_utils.VERSION_SIGIL],
|
|
85
|
+
localeId: localeId ?? parsedArtifactId.variants[import_shared_utils.LOCALE_SIGIL],
|
|
86
|
+
debug
|
|
87
|
+
});
|
|
88
|
+
let currentNode = this.root;
|
|
89
|
+
for (const key of decisionPath) {
|
|
90
|
+
const lastPath = currentNode.getPath();
|
|
91
|
+
currentNode = currentNode.getChild(key);
|
|
92
|
+
if (!currentNode) {
|
|
93
|
+
import_diagnostics.logger.debug(`Module ${key} not found at ${lastPath}`);
|
|
94
|
+
return void 0;
|
|
95
|
+
}
|
|
96
|
+
}
|
|
97
|
+
if (!currentNode.artifact) {
|
|
98
|
+
import_diagnostics.logger.debug(`Artifact not found at ${currentNode.getPath()}`);
|
|
99
|
+
}
|
|
100
|
+
return currentNode.artifact;
|
|
101
|
+
}
|
|
102
|
+
createArtifactChoices({specifier, version, localeId, debug}) {
|
|
103
|
+
const envChoice = debug ? CHOICE_DEBUG : CHOICE_PROD;
|
|
104
|
+
const versionChoice = getVersionChoice(version);
|
|
105
|
+
const uriVersion = (0, import_shared_utils.normalizeVersionToUri)(versionChoice);
|
|
106
|
+
return [specifier, envChoice, uriVersion, localeId || CHOICE_WILDCARD];
|
|
107
|
+
}
|
|
108
|
+
createPossibleArtifactChoices({
|
|
109
|
+
id,
|
|
110
|
+
localeFallbacks,
|
|
111
|
+
debug
|
|
112
|
+
}) {
|
|
113
|
+
const match = (0, import_site_metadata.parseSiteId)(id);
|
|
114
|
+
const specifier = match.specifier;
|
|
115
|
+
if (!specifier) {
|
|
116
|
+
throw new Error(`Unable to parse${debug ? " debug" : ""} static bundle specifier: ${id}`);
|
|
117
|
+
}
|
|
118
|
+
const versionChoice = getVersionChoice(match.variants[import_shared_utils.VERSION_SIGIL]);
|
|
119
|
+
const versions = versionChoice === CHOICE_EMPTY ? [...new Set([CHOICE_EMPTY, CHOICE_WILDCARD])] : [...new Set([versionChoice, CHOICE_EMPTY])];
|
|
120
|
+
const envChoice = debug ? [CHOICE_DEBUG] : [CHOICE_PROD];
|
|
121
|
+
const localeChoice = match.variants[import_shared_utils.LOCALE_SIGIL];
|
|
122
|
+
const localeId = localeChoice && localeFallbacks ? localeFallbacks[localeChoice] : [CHOICE_WILDCARD];
|
|
123
|
+
return [[specifier], envChoice, versions, localeId];
|
|
124
|
+
}
|
|
125
|
+
};
|
|
126
|
+
var decision_tree_default = DecisionTreeImpl;
|
|
127
|
+
var TreeNode = class {
|
|
128
|
+
constructor(value = "", parentPath = "") {
|
|
129
|
+
this.children = new Map();
|
|
130
|
+
this.artifact = void 0;
|
|
131
|
+
this.decisionValue = value;
|
|
132
|
+
this.parentPath = parentPath;
|
|
133
|
+
}
|
|
134
|
+
addChild(value, node) {
|
|
135
|
+
this.children.set(value, node);
|
|
136
|
+
}
|
|
137
|
+
setArtifact(artifact, rank) {
|
|
138
|
+
if (this.artifact && isLowerOrEqualRank(rank, this.rank)) {
|
|
139
|
+
import_diagnostics.logger.debug({
|
|
140
|
+
label: "DecisionTree",
|
|
141
|
+
message: `Ignored Artifact ${this.getPath()} ${this.rank} <= ${rank}`
|
|
142
|
+
});
|
|
143
|
+
return;
|
|
144
|
+
}
|
|
145
|
+
import_diagnostics.logger.debug({
|
|
146
|
+
label: "DecisionTree",
|
|
147
|
+
message: `Added artifact at ${this.getPath()}`
|
|
148
|
+
});
|
|
149
|
+
this.rank = rank;
|
|
150
|
+
this.artifact = artifact;
|
|
151
|
+
}
|
|
152
|
+
getChild(key, allowWildcard = true) {
|
|
153
|
+
return allowWildcard ? this.children.get(key) || this.children.get(CHOICE_WILDCARD) : this.children.get(key);
|
|
154
|
+
}
|
|
155
|
+
getPath() {
|
|
156
|
+
return this.parentPath ? this.parentPath + "|" + this.decisionValue : this.decisionValue;
|
|
157
|
+
}
|
|
158
|
+
};
|
|
159
|
+
function isLowerOrEqualRank(contender, existing) {
|
|
160
|
+
if (!existing) {
|
|
161
|
+
return true;
|
|
162
|
+
}
|
|
163
|
+
if (existing.length !== contender.length) {
|
|
164
|
+
throw new Error(`Paths must be of the same length ${existing} not found at ${contender}`);
|
|
165
|
+
}
|
|
166
|
+
for (let i = 0; i < existing.length; i++) {
|
|
167
|
+
if (contender[i] > existing[i]) {
|
|
168
|
+
return true;
|
|
169
|
+
} else if (contender[i] < existing[i]) {
|
|
170
|
+
return false;
|
|
171
|
+
}
|
|
172
|
+
}
|
|
173
|
+
return true;
|
|
174
|
+
}
|
|
175
|
+
function getVersionChoice(version) {
|
|
176
|
+
if (!version || version === import_shared_utils.VERSION_NOT_PROVIDED) {
|
|
177
|
+
return CHOICE_EMPTY;
|
|
178
|
+
}
|
|
179
|
+
return (0, import_shared_utils.normalizeVersionToUri)(version);
|
|
180
|
+
}
|
|
181
|
+
function createFallbackMap(config) {
|
|
182
|
+
const map = {};
|
|
183
|
+
function findFallbacks(localeId, visited = new Set()) {
|
|
184
|
+
if (visited.has(localeId) || localeId === config.defaultLocale) {
|
|
185
|
+
return [];
|
|
186
|
+
}
|
|
187
|
+
visited.add(localeId);
|
|
188
|
+
const locale = config.locales.find((l) => l.id === localeId);
|
|
189
|
+
if (!locale || !locale.fallback) {
|
|
190
|
+
return [localeId];
|
|
191
|
+
}
|
|
192
|
+
return [localeId, ...findFallbacks(locale.fallback, visited)];
|
|
193
|
+
}
|
|
194
|
+
config.locales.forEach((locale) => {
|
|
195
|
+
if (locale.id !== config.defaultLocale) {
|
|
196
|
+
map[locale.id] = [...new Set([...findFallbacks(locale.id)])];
|
|
197
|
+
}
|
|
198
|
+
});
|
|
199
|
+
map[CHOICE_WILDCARD] = [CHOICE_WILDCARD];
|
|
200
|
+
return map;
|
|
201
|
+
}
|