@lwrjs/tools 0.13.0-alpha.2 → 0.13.0-alpha.20
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/index.cjs +2 -2
- package/build/es/index.d.ts +1 -1
- package/build/es/index.js +1 -1
- package/package.json +17 -9
- package/build/cjs/dedupe-bundles.cjs +0 -148
- package/build/es/dedupe-bundles.d.ts +0 -8
- package/build/es/dedupe-bundles.js +0 -145
package/build/cjs/index.cjs
CHANGED
|
@@ -25,7 +25,7 @@ var __toModule = (module2) => {
|
|
|
25
25
|
__markAsModule(exports);
|
|
26
26
|
__export(exports, {
|
|
27
27
|
buildServer: () => import_server_build.buildServer,
|
|
28
|
-
dedupeBundles: () =>
|
|
28
|
+
dedupeBundles: () => import_static.dedupeBundles
|
|
29
29
|
});
|
|
30
30
|
var import_server_build = __toModule(require("./server-build.cjs"));
|
|
31
|
-
var
|
|
31
|
+
var import_static = __toModule(require("@lwrjs/static"));
|
package/build/es/index.d.ts
CHANGED
package/build/es/index.js
CHANGED
package/package.json
CHANGED
|
@@ -4,7 +4,7 @@
|
|
|
4
4
|
"publishConfig": {
|
|
5
5
|
"access": "public"
|
|
6
6
|
},
|
|
7
|
-
"version": "0.13.0-alpha.
|
|
7
|
+
"version": "0.13.0-alpha.20",
|
|
8
8
|
"homepage": "https://developer.salesforce.com/docs/platform/lwr/overview",
|
|
9
9
|
"repository": {
|
|
10
10
|
"type": "git",
|
|
@@ -18,7 +18,9 @@
|
|
|
18
18
|
"types": "build/es/index.d.ts",
|
|
19
19
|
"module": "build/es/index.js",
|
|
20
20
|
"scripts": {
|
|
21
|
-
"build": "tsc -b"
|
|
21
|
+
"build": "tsc -b",
|
|
22
|
+
"clean": "rm -rf build node_modules",
|
|
23
|
+
"test": "jest"
|
|
22
24
|
},
|
|
23
25
|
"exports": {
|
|
24
26
|
".": {
|
|
@@ -32,16 +34,19 @@
|
|
|
32
34
|
"package.cjs"
|
|
33
35
|
],
|
|
34
36
|
"dependencies": {
|
|
35
|
-
"@lwrjs/config": "0.13.0-alpha.
|
|
36
|
-
"@lwrjs/core": "0.13.0-alpha.
|
|
37
|
-
"@lwrjs/diagnostics": "0.13.0-alpha.
|
|
38
|
-
"@lwrjs/shared-utils": "0.13.0-alpha.
|
|
37
|
+
"@lwrjs/config": "0.13.0-alpha.20",
|
|
38
|
+
"@lwrjs/core": "0.13.0-alpha.20",
|
|
39
|
+
"@lwrjs/diagnostics": "0.13.0-alpha.20",
|
|
40
|
+
"@lwrjs/shared-utils": "0.13.0-alpha.20",
|
|
41
|
+
"@lwrjs/static": "0.13.0-alpha.20",
|
|
39
42
|
"esbuild": "^0.17.4",
|
|
40
43
|
"fs-extra": "^11.2.0"
|
|
41
44
|
},
|
|
42
45
|
"devDependencies": {
|
|
43
|
-
"@lwrjs/types": "0.13.0-alpha.
|
|
44
|
-
"
|
|
46
|
+
"@lwrjs/types": "0.13.0-alpha.20",
|
|
47
|
+
"jest": "^26.6.3",
|
|
48
|
+
"mock-fs": "^5.2.0",
|
|
49
|
+
"ts-jest": "^26.5.6"
|
|
45
50
|
},
|
|
46
51
|
"peerDependencies": {
|
|
47
52
|
"lwc": ">= 2.x"
|
|
@@ -49,5 +54,8 @@
|
|
|
49
54
|
"engines": {
|
|
50
55
|
"node": ">=18.0.0"
|
|
51
56
|
},
|
|
52
|
-
"
|
|
57
|
+
"volta": {
|
|
58
|
+
"extends": "../../../package.json"
|
|
59
|
+
},
|
|
60
|
+
"gitHead": "2165594f2871f4f20a4083394e4372e67d1fa1b5"
|
|
53
61
|
}
|
|
@@ -1,148 +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/tools/src/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_shared_utils = __toModule(require("@lwrjs/shared-utils"));
|
|
33
|
-
var DEFAULT_KEY = "default";
|
|
34
|
-
async function dedupeBundles(siteRoot, i18n) {
|
|
35
|
-
const bundleMetadataFilePath = import_path.default.join(siteRoot, "/.metadata/bundle-metadata.json");
|
|
36
|
-
const siteBundles = await import_fs_extra.default.readJSON(bundleMetadataFilePath);
|
|
37
|
-
import_diagnostics.logger.info({
|
|
38
|
-
label: `dedupeBundles`,
|
|
39
|
-
message: `Deduplicating ${Object.keys(siteBundles.bundles).length} bundles`
|
|
40
|
-
});
|
|
41
|
-
const groupedBundles = groupBundlesByLocales(siteBundles);
|
|
42
|
-
import_diagnostics.logger.debug({
|
|
43
|
-
label: `dedupeBundles`,
|
|
44
|
-
message: `Found ${Object.keys(groupedBundles).length} grouped bundles`
|
|
45
|
-
});
|
|
46
|
-
const updatedBundleMetadata = {bundles: {}};
|
|
47
|
-
const updatedBundles = updatedBundleMetadata.bundles;
|
|
48
|
-
for (const specifier of Object.keys(groupedBundles)) {
|
|
49
|
-
const variants = groupedBundles[specifier];
|
|
50
|
-
const defaultVariant = variants[DEFAULT_KEY];
|
|
51
|
-
if (defaultVariant) {
|
|
52
|
-
updatedBundles[specifier] = defaultVariant;
|
|
53
|
-
const defaultSource = String(import_fs_extra.default.readFileSync(import_path.default.join(siteRoot, defaultVariant.path)));
|
|
54
|
-
for (const variantKey of Object.keys(variants)) {
|
|
55
|
-
if (variantKey !== DEFAULT_KEY) {
|
|
56
|
-
let dedupeSource = false;
|
|
57
|
-
const variant = variants[variantKey];
|
|
58
|
-
const variantSource = String(import_fs_extra.default.readFileSync(import_path.default.join(siteRoot, variant.path)));
|
|
59
|
-
const localeId = extractLocale(variantKey);
|
|
60
|
-
if (localeId) {
|
|
61
|
-
dedupeSource = await (0, import_shared_utils.walkLocaleFallbacks)(localeId, i18n, async (curLocale) => {
|
|
62
|
-
if (curLocale === localeId) {
|
|
63
|
-
return false;
|
|
64
|
-
}
|
|
65
|
-
if (curLocale === i18n.defaultLocale) {
|
|
66
|
-
return variantSource === defaultSource;
|
|
67
|
-
}
|
|
68
|
-
const curVariant = variants[`l/${curLocale}`];
|
|
69
|
-
if (curVariant) {
|
|
70
|
-
const curPath = import_path.default.join(siteRoot, curVariant.path);
|
|
71
|
-
if (await import_fs_extra.default.pathExists(curPath)) {
|
|
72
|
-
const curVariantSource = String(import_fs_extra.default.readFileSync(curPath));
|
|
73
|
-
return variantSource === curVariantSource;
|
|
74
|
-
}
|
|
75
|
-
}
|
|
76
|
-
return false;
|
|
77
|
-
});
|
|
78
|
-
}
|
|
79
|
-
if (dedupeSource) {
|
|
80
|
-
import_diagnostics.logger.debug({
|
|
81
|
-
label: `dedupeBundles`,
|
|
82
|
-
message: `Remove duplicate variant ${specifier}|${variantKey}`
|
|
83
|
-
});
|
|
84
|
-
import_fs_extra.default.removeSync(import_path.default.join(siteRoot, variant.path));
|
|
85
|
-
} else {
|
|
86
|
-
const variant2 = variants[variantKey];
|
|
87
|
-
updatedBundles[`${specifier}|${variantKey}`] = variant2;
|
|
88
|
-
}
|
|
89
|
-
}
|
|
90
|
-
}
|
|
91
|
-
}
|
|
92
|
-
}
|
|
93
|
-
import_diagnostics.logger.info({
|
|
94
|
-
label: `dedupeBundles`,
|
|
95
|
-
message: `Deduplicated down to ${Object.keys(updatedBundleMetadata.bundles).length} bundles`
|
|
96
|
-
});
|
|
97
|
-
await import_fs_extra.default.writeJSON(bundleMetadataFilePath, updatedBundleMetadata, {spaces: 2});
|
|
98
|
-
deleteEmptyFolders(siteRoot);
|
|
99
|
-
}
|
|
100
|
-
var LOCALE_PATTERN = /(?:^|\/)l\/([\w-_]+)/;
|
|
101
|
-
function extractLocale(variantKey) {
|
|
102
|
-
const match = variantKey.match(LOCALE_PATTERN);
|
|
103
|
-
if (match) {
|
|
104
|
-
return match[1];
|
|
105
|
-
}
|
|
106
|
-
return void 0;
|
|
107
|
-
}
|
|
108
|
-
function groupBundlesByLocales(siteBundles) {
|
|
109
|
-
const groupedBundles = {};
|
|
110
|
-
for (const specifier of Object.keys(siteBundles.bundles)) {
|
|
111
|
-
const parts = specifier.split("|");
|
|
112
|
-
const firstPart = parts[0];
|
|
113
|
-
const secondPart = parts.length > 1 ? parts[1] : DEFAULT_KEY;
|
|
114
|
-
import_diagnostics.logger.debug({
|
|
115
|
-
label: `dedupeBundles`,
|
|
116
|
-
message: `${specifier} -> groupedBundles[${firstPart}][${secondPart}]`
|
|
117
|
-
});
|
|
118
|
-
if (!groupedBundles[firstPart]) {
|
|
119
|
-
groupedBundles[firstPart] = {};
|
|
120
|
-
}
|
|
121
|
-
groupedBundles[firstPart][secondPart] = siteBundles.bundles[specifier];
|
|
122
|
-
}
|
|
123
|
-
return groupedBundles;
|
|
124
|
-
}
|
|
125
|
-
function deleteEmptyFolders(directory) {
|
|
126
|
-
if (!import_fs_extra.default.existsSync(directory)) {
|
|
127
|
-
import_diagnostics.logger.warn({label: `dedupeBundles`, message: `Directory does not exist: ${directory}`});
|
|
128
|
-
return;
|
|
129
|
-
}
|
|
130
|
-
const files = import_fs_extra.default.readdirSync(directory);
|
|
131
|
-
if (files.length === 0) {
|
|
132
|
-
import_fs_extra.default.rmdirSync(directory);
|
|
133
|
-
import_diagnostics.logger.debug({label: `dedupeBundles`, message: `Deleted empty folder: ${directory}`});
|
|
134
|
-
return;
|
|
135
|
-
}
|
|
136
|
-
files.forEach((file) => {
|
|
137
|
-
const filePath = import_path.default.join(directory, file);
|
|
138
|
-
const isDirectory = import_fs_extra.default.statSync(filePath).isDirectory();
|
|
139
|
-
if (isDirectory) {
|
|
140
|
-
deleteEmptyFolders(filePath);
|
|
141
|
-
}
|
|
142
|
-
});
|
|
143
|
-
const updatedFiles = import_fs_extra.default.readdirSync(directory);
|
|
144
|
-
if (updatedFiles.length === 0) {
|
|
145
|
-
import_fs_extra.default.rmdirSync(directory);
|
|
146
|
-
import_diagnostics.logger.debug({label: `dedupeBundles`, message: `Deleted empty folder: ${directory}`});
|
|
147
|
-
}
|
|
148
|
-
}
|
|
@@ -1,8 +0,0 @@
|
|
|
1
|
-
import type { I18NConfig } from '@lwrjs/types';
|
|
2
|
-
/**
|
|
3
|
-
* De-duplicate generated bundles
|
|
4
|
-
*
|
|
5
|
-
* @param siteRoot The root folder for generated bundles
|
|
6
|
-
*/
|
|
7
|
-
export declare function dedupeBundles(siteRoot: string, i18n: I18NConfig): Promise<void>;
|
|
8
|
-
//# sourceMappingURL=dedupe-bundles.d.ts.map
|
|
@@ -1,145 +0,0 @@
|
|
|
1
|
-
import fs from 'fs-extra';
|
|
2
|
-
import path from 'path';
|
|
3
|
-
import { logger } from '@lwrjs/diagnostics';
|
|
4
|
-
import { walkLocaleFallbacks } from '@lwrjs/shared-utils';
|
|
5
|
-
const DEFAULT_KEY = 'default';
|
|
6
|
-
/**
|
|
7
|
-
* De-duplicate generated bundles
|
|
8
|
-
*
|
|
9
|
-
* @param siteRoot The root folder for generated bundles
|
|
10
|
-
*/
|
|
11
|
-
export async function dedupeBundles(siteRoot, i18n) {
|
|
12
|
-
// Read the bundle site metadata
|
|
13
|
-
const bundleMetadataFilePath = path.join(siteRoot, '/.metadata/bundle-metadata.json');
|
|
14
|
-
const siteBundles = await fs.readJSON(bundleMetadataFilePath);
|
|
15
|
-
logger.info({
|
|
16
|
-
label: `dedupeBundles`,
|
|
17
|
-
message: `Deduplicating ${Object.keys(siteBundles.bundles).length} bundles`,
|
|
18
|
-
});
|
|
19
|
-
// Group the bundles by locale
|
|
20
|
-
const groupedBundles = groupBundlesByLocales(siteBundles);
|
|
21
|
-
logger.debug({
|
|
22
|
-
label: `dedupeBundles`,
|
|
23
|
-
message: `Found ${Object.keys(groupedBundles).length} grouped bundles`,
|
|
24
|
-
});
|
|
25
|
-
const updatedBundleMetadata = { bundles: {} };
|
|
26
|
-
const updatedBundles = updatedBundleMetadata.bundles;
|
|
27
|
-
for (const specifier of Object.keys(groupedBundles)) {
|
|
28
|
-
const variants = groupedBundles[specifier];
|
|
29
|
-
const defaultVariant = variants[DEFAULT_KEY];
|
|
30
|
-
if (defaultVariant) {
|
|
31
|
-
updatedBundles[specifier] = defaultVariant;
|
|
32
|
-
const defaultSource = String(fs.readFileSync(path.join(siteRoot, defaultVariant.path)));
|
|
33
|
-
// Wite out each variant
|
|
34
|
-
for (const variantKey of Object.keys(variants)) {
|
|
35
|
-
if (variantKey !== DEFAULT_KEY) {
|
|
36
|
-
// Find the first source that does not match its parent
|
|
37
|
-
let dedupeSource = false;
|
|
38
|
-
// Read the current variant source
|
|
39
|
-
const variant = variants[variantKey];
|
|
40
|
-
const variantSource = String(fs.readFileSync(path.join(siteRoot, variant.path)));
|
|
41
|
-
const localeId = extractLocale(variantKey);
|
|
42
|
-
// If this locale is n
|
|
43
|
-
if (localeId) {
|
|
44
|
-
// eslint-disable-next-line no-await-in-loop
|
|
45
|
-
dedupeSource = await walkLocaleFallbacks(localeId, i18n, async (curLocale) => {
|
|
46
|
-
// If this is the current locale skip
|
|
47
|
-
if (curLocale === localeId) {
|
|
48
|
-
return false;
|
|
49
|
-
}
|
|
50
|
-
// If this is a default local test against the read default
|
|
51
|
-
if (curLocale === i18n.defaultLocale) {
|
|
52
|
-
return variantSource === defaultSource;
|
|
53
|
-
}
|
|
54
|
-
// See if there is a variant for the current locale
|
|
55
|
-
const curVariant = variants[`l/${curLocale}`];
|
|
56
|
-
if (curVariant) {
|
|
57
|
-
const curPath = path.join(siteRoot, curVariant.path);
|
|
58
|
-
if (await fs.pathExists(curPath)) {
|
|
59
|
-
const curVariantSource = String(fs.readFileSync(curPath));
|
|
60
|
-
return variantSource === curVariantSource;
|
|
61
|
-
}
|
|
62
|
-
}
|
|
63
|
-
return false;
|
|
64
|
-
});
|
|
65
|
-
}
|
|
66
|
-
if (dedupeSource) {
|
|
67
|
-
logger.debug({
|
|
68
|
-
label: `dedupeBundles`,
|
|
69
|
-
message: `Remove duplicate variant ${specifier}|${variantKey}`,
|
|
70
|
-
});
|
|
71
|
-
fs.removeSync(path.join(siteRoot, variant.path));
|
|
72
|
-
}
|
|
73
|
-
else {
|
|
74
|
-
// keep the variant in the metadata
|
|
75
|
-
const variant = variants[variantKey];
|
|
76
|
-
updatedBundles[`${specifier}|${variantKey}`] = variant;
|
|
77
|
-
}
|
|
78
|
-
}
|
|
79
|
-
}
|
|
80
|
-
}
|
|
81
|
-
}
|
|
82
|
-
logger.info({
|
|
83
|
-
label: `dedupeBundles`,
|
|
84
|
-
message: `Deduplicated down to ${Object.keys(updatedBundleMetadata.bundles).length} bundles`,
|
|
85
|
-
});
|
|
86
|
-
// Save the updated bundle metadata
|
|
87
|
-
await fs.writeJSON(bundleMetadataFilePath, updatedBundleMetadata, { spaces: 2 });
|
|
88
|
-
// Clean up empty folders
|
|
89
|
-
deleteEmptyFolders(siteRoot);
|
|
90
|
-
}
|
|
91
|
-
const LOCALE_PATTERN = /(?:^|\/)l\/([\w-_]+)/;
|
|
92
|
-
/**
|
|
93
|
-
* Extract the locale definition from a variant key 'l/{localeId}'
|
|
94
|
-
*/
|
|
95
|
-
function extractLocale(variantKey) {
|
|
96
|
-
const match = variantKey.match(LOCALE_PATTERN);
|
|
97
|
-
if (match) {
|
|
98
|
-
return match[1]; // The 'key' is captured in the first capture group
|
|
99
|
-
}
|
|
100
|
-
return undefined;
|
|
101
|
-
}
|
|
102
|
-
function groupBundlesByLocales(siteBundles) {
|
|
103
|
-
const groupedBundles = {};
|
|
104
|
-
for (const specifier of Object.keys(siteBundles.bundles)) {
|
|
105
|
-
const parts = specifier.split('|');
|
|
106
|
-
// Extract the desired parts
|
|
107
|
-
const firstPart = parts[0];
|
|
108
|
-
const secondPart = parts.length > 1 ? parts[1] : DEFAULT_KEY;
|
|
109
|
-
logger.debug({
|
|
110
|
-
label: `dedupeBundles`,
|
|
111
|
-
message: `${specifier} -> groupedBundles[${firstPart}][${secondPart}]`,
|
|
112
|
-
});
|
|
113
|
-
if (!groupedBundles[firstPart]) {
|
|
114
|
-
groupedBundles[firstPart] = {};
|
|
115
|
-
}
|
|
116
|
-
groupedBundles[firstPart][secondPart] = siteBundles.bundles[specifier];
|
|
117
|
-
}
|
|
118
|
-
return groupedBundles;
|
|
119
|
-
}
|
|
120
|
-
function deleteEmptyFolders(directory) {
|
|
121
|
-
if (!fs.existsSync(directory)) {
|
|
122
|
-
logger.warn({ label: `dedupeBundles`, message: `Directory does not exist: ${directory}` });
|
|
123
|
-
return;
|
|
124
|
-
}
|
|
125
|
-
const files = fs.readdirSync(directory);
|
|
126
|
-
if (files.length === 0) {
|
|
127
|
-
fs.rmdirSync(directory);
|
|
128
|
-
logger.debug({ label: `dedupeBundles`, message: `Deleted empty folder: ${directory}` });
|
|
129
|
-
return;
|
|
130
|
-
}
|
|
131
|
-
files.forEach((file) => {
|
|
132
|
-
const filePath = path.join(directory, file);
|
|
133
|
-
const isDirectory = fs.statSync(filePath).isDirectory();
|
|
134
|
-
if (isDirectory) {
|
|
135
|
-
deleteEmptyFolders(filePath);
|
|
136
|
-
}
|
|
137
|
-
});
|
|
138
|
-
// Check if the directory is empty after deleting its subdirectories
|
|
139
|
-
const updatedFiles = fs.readdirSync(directory);
|
|
140
|
-
if (updatedFiles.length === 0) {
|
|
141
|
-
fs.rmdirSync(directory);
|
|
142
|
-
logger.debug({ label: `dedupeBundles`, message: `Deleted empty folder: ${directory}` });
|
|
143
|
-
}
|
|
144
|
-
}
|
|
145
|
-
//# sourceMappingURL=dedupe-bundles.js.map
|