@lwrjs/config 0.10.0-alpha.2 → 0.10.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/defaults.cjs +7 -2
- package/build/cjs/global-config.cjs +20 -8
- package/build/cjs/hooks.cjs +21 -0
- package/build/cjs/index.cjs +1 -0
- package/build/cjs/modules.cjs +4 -2
- package/build/cjs/utils/assets.cjs +3 -1
- package/build/cjs/utils/routes.cjs +28 -5
- package/build/cjs/validation/app-config-context.cjs +49 -14
- package/build/cjs/validation/app-config.cjs +65 -5
- package/build/es/defaults.d.ts +2 -0
- package/build/es/defaults.js +5 -2
- package/build/es/global-config.js +20 -8
- package/build/es/hooks.d.ts +1 -0
- package/build/es/hooks.js +20 -0
- package/build/es/index.d.ts +1 -1
- package/build/es/index.js +1 -1
- package/build/es/modules.js +4 -2
- package/build/es/utils/assets.d.ts +1 -1
- package/build/es/utils/assets.js +4 -1
- package/build/es/utils/global-data.d.ts +1 -1
- package/build/es/utils/routes.d.ts +5 -4
- package/build/es/utils/routes.js +28 -6
- package/build/es/validation/app-config-context.d.ts +14 -8
- package/build/es/validation/app-config-context.js +54 -19
- package/build/es/validation/app-config.d.ts +1 -1
- package/build/es/validation/app-config.js +73 -6
- package/build/es/validation/helpers.d.ts +1 -1
- package/package.cjs +8 -3
- package/package.json +18 -7
package/build/cjs/defaults.cjs
CHANGED
|
@@ -24,8 +24,10 @@ var __toModule = (module2) => {
|
|
|
24
24
|
// packages/@lwrjs/config/src/defaults.ts
|
|
25
25
|
__markAsModule(exports);
|
|
26
26
|
__export(exports, {
|
|
27
|
+
DEFAULT_AMD_BUNDLE_EXCLUSIONS: () => DEFAULT_AMD_BUNDLE_EXCLUSIONS,
|
|
27
28
|
DEFAULT_AMD_LOADER: () => DEFAULT_AMD_LOADER,
|
|
28
29
|
DEFAULT_AMD_LOADER_LEGACY: () => DEFAULT_AMD_LOADER_LEGACY,
|
|
30
|
+
DEFAULT_ESM_BUNDLE_EXCLUSIONS: () => DEFAULT_ESM_BUNDLE_EXCLUSIONS,
|
|
29
31
|
DEFAULT_ESM_LOADER: () => DEFAULT_ESM_LOADER,
|
|
30
32
|
DEFAULT_GENERATOR_CONFIG: () => DEFAULT_GENERATOR_CONFIG,
|
|
31
33
|
DEFAULT_LWR_CONFIG: () => DEFAULT_LWR_CONFIG,
|
|
@@ -84,6 +86,7 @@ var DEFAULT_VIEW_TRANSFORM_PLUGINS = ["@lwrjs/base-view-transformer"];
|
|
|
84
86
|
var SSR_VIEW_TRANSFORM_PLUGIN = "@lwrjs/lwc-ssr/viewTransformer";
|
|
85
87
|
var DEFAULT_ASSET_PROVIDERS = ["@lwrjs/fs-asset-provider"];
|
|
86
88
|
var DEFAULT_ASSET_TRANSFORM_PLUGINS = ["@lwrjs/asset-transformer"];
|
|
89
|
+
var DEFAULT_URI_TRANSFORM_PLUGINS = [];
|
|
87
90
|
var DEFAULT_AMD_LOADER = "lwr/loader";
|
|
88
91
|
var DEFAULT_AMD_LOADER_LEGACY = "lwr/loaderLegacy";
|
|
89
92
|
var DEFAULT_ESM_LOADER = "lwr/esmLoader";
|
|
@@ -101,7 +104,8 @@ var DEFAULT_ESM_BUNDLE_EXCLUSIONS = [
|
|
|
101
104
|
"@lwc/synthetic-shadow",
|
|
102
105
|
"lwr/navigation",
|
|
103
106
|
"lwr/esmLoader",
|
|
104
|
-
"lwr/profiler"
|
|
107
|
+
"lwr/profiler",
|
|
108
|
+
"@salesforce/lds-default-luvio"
|
|
105
109
|
];
|
|
106
110
|
var DEFAULT_AMD_BUNDLE_EXCLUSIONS = ["lwc", "lwr/navigation"];
|
|
107
111
|
var DEFAULT_ESM_BUNDLE_EXTERNALS = {};
|
|
@@ -152,5 +156,6 @@ var DEFAULT_LWR_CONFIG = {
|
|
|
152
156
|
routeHandlers: {},
|
|
153
157
|
bundleConfig: getDefaultBundleConfig(MODE),
|
|
154
158
|
serverType: DEFAULT_SERVER_TYPE,
|
|
155
|
-
locker: import_shared_utils.DEFAULT_LWR_LOCKER_CONFIG
|
|
159
|
+
locker: import_shared_utils.DEFAULT_LWR_LOCKER_CONFIG,
|
|
160
|
+
uriTransformers: DEFAULT_URI_TRANSFORM_PLUGINS
|
|
156
161
|
};
|
|
@@ -44,6 +44,7 @@ var import_merge = __toModule(require("./utils/merge.cjs"));
|
|
|
44
44
|
var import_lwc = __toModule(require("./utils/lwc.cjs"));
|
|
45
45
|
var import_runtime_config = __toModule(require("./runtime-config.cjs"));
|
|
46
46
|
var import_global_data = __toModule(require("./utils/global-data.cjs"));
|
|
47
|
+
var import_instrumentation = __toModule(require("@lwrjs/instrumentation"));
|
|
47
48
|
function getLwrConfigFromFile(rootDir, lwrConfigPath = import_defaults2.DEFAULT_LWR_CONFIG_JSON) {
|
|
48
49
|
const resolvedLwrConfigPath = import_path.default.resolve((0, import_shared_utils.normalizeDirectory)(lwrConfigPath, rootDir));
|
|
49
50
|
if (!import_fs.default.existsSync(resolvedLwrConfigPath)) {
|
|
@@ -93,10 +94,12 @@ function normalizeConfig(config) {
|
|
|
93
94
|
assetProviders: (0, import_services.normalizeServices)(config.assetProviders),
|
|
94
95
|
assetTransformers: (0, import_services.normalizeServices)(config.assetTransformers),
|
|
95
96
|
resourceProviders: (0, import_services.normalizeServices)(config.resourceProviders),
|
|
97
|
+
uriTransformers: (0, import_services.normalizeServices)(config.uriTransformers),
|
|
96
98
|
viewProviders: (0, import_services.normalizeServices)(config.viewProviders),
|
|
97
99
|
viewTransformers: (0, import_services.normalizeServices)(config.viewTransformers),
|
|
98
100
|
routes: (0, import_routes.normalizeRoutes)(config.routes, config.routeHandlers),
|
|
99
|
-
errorRoutes: (0, import_routes.normalizeRoutes)(config.errorRoutes, config.routeHandlers)
|
|
101
|
+
errorRoutes: (0, import_routes.normalizeRoutes)(config.errorRoutes, config.routeHandlers),
|
|
102
|
+
routeHandlers: (0, import_routes.normalizeRouteHandlers)(config.routeHandlers)
|
|
100
103
|
};
|
|
101
104
|
}
|
|
102
105
|
function normalizeConfigPaths(config) {
|
|
@@ -122,6 +125,7 @@ function normalizeConfigPaths(config) {
|
|
|
122
125
|
assetProviders: (0, import_services.normalizeServicePaths)(config.assetProviders, rootDir),
|
|
123
126
|
assetTransformers: (0, import_services.normalizeServicePaths)(config.assetTransformers, rootDir),
|
|
124
127
|
resourceProviders: (0, import_services.normalizeServicePaths)(config.resourceProviders, rootDir),
|
|
128
|
+
uriTransformers: (0, import_services.normalizeServicePaths)(config.uriTransformers, rootDir),
|
|
125
129
|
viewProviders: (0, import_services.normalizeServicePaths)(config.viewProviders, rootDir),
|
|
126
130
|
viewTransformers: (0, import_services.normalizeServicePaths)(config.viewTransformers, rootDir),
|
|
127
131
|
routes: (0, import_routes.normalizeRoutePaths)(config.routes, resourcePaths),
|
|
@@ -145,17 +149,19 @@ function applySsrConfig(config) {
|
|
|
145
149
|
function applyStaticProviderConfig(config) {
|
|
146
150
|
return {
|
|
147
151
|
...config,
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
152
|
+
assetProviders: [["@lwrjs/static/asset-provider", void 0]],
|
|
153
|
+
assetTransformers: [],
|
|
154
|
+
resourceProviders: [["@lwrjs/static/resource-provider", {}]],
|
|
155
|
+
moduleProviders: [["@lwrjs/static/module-provider", void 0]],
|
|
151
156
|
bundleProviders: [
|
|
152
|
-
["@lwrjs/
|
|
157
|
+
["@lwrjs/static/bundle-provider", void 0],
|
|
153
158
|
["@lwrjs/module-bundler/amd-runtime-bundle-provider", void 0]
|
|
154
159
|
],
|
|
155
|
-
|
|
160
|
+
uriTransformers: [["@lwrjs/lambda/mrt-static-uri-transformer", void 0]]
|
|
156
161
|
};
|
|
157
162
|
}
|
|
158
163
|
function resolveGlobalConfig(configArg, options) {
|
|
164
|
+
const span = (0, import_instrumentation.getTracer)().startSpan({name: import_instrumentation.ConfigSpan.ResolveConfig});
|
|
159
165
|
const mergedConfig = mergeConfig(configArg);
|
|
160
166
|
let normalizedConfig = normalizeConfig(mergedConfig);
|
|
161
167
|
if (options?.useStaticProviders) {
|
|
@@ -166,20 +172,26 @@ function resolveGlobalConfig(configArg, options) {
|
|
|
166
172
|
createCacheFolder(normalizedConfig.cacheDir, normalizedConfig.rootDir);
|
|
167
173
|
}
|
|
168
174
|
if (options?.skipDirNormalization) {
|
|
175
|
+
span.end();
|
|
169
176
|
return normalizedConfig;
|
|
170
177
|
}
|
|
171
|
-
|
|
178
|
+
const retVal = normalizeConfigPaths(normalizedConfig);
|
|
179
|
+
span.end();
|
|
180
|
+
return retVal;
|
|
172
181
|
}
|
|
173
182
|
function loadConfig(config, options) {
|
|
183
|
+
const span = (0, import_instrumentation.getTracer)().startSpan({name: import_instrumentation.ConfigSpan.LoadConfig});
|
|
174
184
|
const appConfig = resolveGlobalConfig(config, options);
|
|
175
185
|
const runtimeEnvironment = (0, import_runtime_config.getRuntimeEnvironment)(appConfig);
|
|
176
186
|
const globalData = (0, import_global_data.getGlobalData)(appConfig.globalDataDir, appConfig.globalData);
|
|
177
187
|
if (!appConfig.hooks.length) {
|
|
178
188
|
(0, import_app_config.validateLwrAppConfig)(appConfig, "post");
|
|
179
189
|
}
|
|
180
|
-
|
|
190
|
+
const retVal = {
|
|
181
191
|
appConfig,
|
|
182
192
|
runtimeEnvironment,
|
|
183
193
|
globalData
|
|
184
194
|
};
|
|
195
|
+
span.end();
|
|
196
|
+
return retVal;
|
|
185
197
|
}
|
package/build/cjs/hooks.cjs
CHANGED
|
@@ -25,13 +25,17 @@ var __toModule = (module2) => {
|
|
|
25
25
|
__markAsModule(exports);
|
|
26
26
|
__export(exports, {
|
|
27
27
|
executeConfigHooks: () => executeConfigHooks,
|
|
28
|
+
executeInstrumentationHooks: () => executeInstrumentationHooks,
|
|
28
29
|
executeStartHooks: () => executeStartHooks
|
|
29
30
|
});
|
|
30
31
|
var import_routes = __toModule(require("./utils/routes.cjs"));
|
|
31
32
|
var import_app_config = __toModule(require("./validation/app-config.cjs"));
|
|
32
33
|
var import_global_config = __toModule(require("./global-config.cjs"));
|
|
34
|
+
var import_instrumentation = __toModule(require("@lwrjs/instrumentation"));
|
|
33
35
|
async function executeConfigHooks(hooks, globalConfig, runtimeEnvironment, globalData, skipValidate = false) {
|
|
36
|
+
const span = (0, import_instrumentation.getTracer)().startSpan({name: import_instrumentation.ConfigSpan.ExecuteConfigHooks});
|
|
34
37
|
if (!hooks.length) {
|
|
38
|
+
span.end();
|
|
35
39
|
return;
|
|
36
40
|
}
|
|
37
41
|
for (const hook of hooks) {
|
|
@@ -48,9 +52,12 @@ async function executeConfigHooks(hooks, globalConfig, runtimeEnvironment, globa
|
|
|
48
52
|
if (!skipValidate) {
|
|
49
53
|
(0, import_app_config.validateLwrAppConfig)(globalConfig, "post");
|
|
50
54
|
}
|
|
55
|
+
span.end();
|
|
51
56
|
}
|
|
52
57
|
function executeStartHooks(hooks, globalConfig, skipValidate = false) {
|
|
58
|
+
const span = (0, import_instrumentation.getTracer)().startSpan({name: import_instrumentation.ConfigSpan.ExecuteStartHooks});
|
|
53
59
|
if (!hooks.length) {
|
|
60
|
+
span.end();
|
|
54
61
|
return;
|
|
55
62
|
}
|
|
56
63
|
for (const hook of hooks) {
|
|
@@ -66,4 +73,18 @@ function executeStartHooks(hooks, globalConfig, skipValidate = false) {
|
|
|
66
73
|
if (!skipValidate) {
|
|
67
74
|
(0, import_app_config.validateLwrAppConfig)(globalConfig, "post");
|
|
68
75
|
}
|
|
76
|
+
span.end();
|
|
77
|
+
}
|
|
78
|
+
function executeInstrumentationHooks(hooks) {
|
|
79
|
+
const span = (0, import_instrumentation.getTracer)().startSpan({name: import_instrumentation.ConfigSpan.ExecuteInstrHooks});
|
|
80
|
+
let retVal = false;
|
|
81
|
+
for (const hook of hooks) {
|
|
82
|
+
if (!hook.initInstrumentation) {
|
|
83
|
+
continue;
|
|
84
|
+
}
|
|
85
|
+
retVal = true;
|
|
86
|
+
hook.initInstrumentation();
|
|
87
|
+
}
|
|
88
|
+
span.end();
|
|
89
|
+
return retVal;
|
|
69
90
|
}
|
package/build/cjs/index.cjs
CHANGED
|
@@ -27,6 +27,7 @@ __export(exports, {
|
|
|
27
27
|
LWC_VERSION: () => import_package.lwcVersion,
|
|
28
28
|
LWR_VERSION: () => import_package.version,
|
|
29
29
|
executeConfigHooks: () => import_hooks.executeConfigHooks,
|
|
30
|
+
executeInstrumentationHooks: () => import_hooks.executeInstrumentationHooks,
|
|
30
31
|
executeStartHooks: () => import_hooks.executeStartHooks,
|
|
31
32
|
getLwrConfigFromFile: () => import_global_config.getLwrConfigFromFile,
|
|
32
33
|
getRuntimeEnvironment: () => import_runtime_config.getRuntimeEnvironment,
|
package/build/cjs/modules.cjs
CHANGED
|
@@ -69,6 +69,7 @@ async function loadServices(config) {
|
|
|
69
69
|
const assetProviders = await loadServiceEntries(config.assetProviders, config.rootDir, config.cacheDir);
|
|
70
70
|
const assetTransformers = await loadServiceEntries(config.assetTransformers, config.rootDir, config.cacheDir);
|
|
71
71
|
const resourceProviders = await loadServiceEntries(config.resourceProviders, config.rootDir, config.cacheDir);
|
|
72
|
+
const uriTransformers = await loadServiceEntries(config.uriTransformers, config.rootDir, config.cacheDir);
|
|
72
73
|
const viewProviders = await loadServiceEntries(config.viewProviders, config.rootDir, config.cacheDir);
|
|
73
74
|
const viewTransformers = await loadServiceEntries(config.viewTransformers, config.rootDir, config.cacheDir);
|
|
74
75
|
return {
|
|
@@ -77,6 +78,7 @@ async function loadServices(config) {
|
|
|
77
78
|
assetProviders,
|
|
78
79
|
assetTransformers,
|
|
79
80
|
resourceProviders,
|
|
81
|
+
uriTransformers,
|
|
80
82
|
viewProviders,
|
|
81
83
|
viewTransformers
|
|
82
84
|
};
|
|
@@ -84,9 +86,9 @@ async function loadServices(config) {
|
|
|
84
86
|
async function loadRouteHandlers(config) {
|
|
85
87
|
const routeHandlers = {};
|
|
86
88
|
await Promise.all(Object.keys(config.routeHandlers).map(async (id) => {
|
|
87
|
-
const handlerPath = config.routeHandlers[id];
|
|
89
|
+
const [handlerPath, handlerOptions] = config.routeHandlers[id];
|
|
88
90
|
const handler = await importModule(handlerPath, config.rootDir, import_path.default.join(config.cacheDir, "routeHandlers"));
|
|
89
|
-
routeHandlers[id] = handler;
|
|
91
|
+
routeHandlers[id] = [handler, handlerOptions];
|
|
90
92
|
}));
|
|
91
93
|
return routeHandlers;
|
|
92
94
|
}
|
|
@@ -42,10 +42,12 @@ function normalizeAssets(assets) {
|
|
|
42
42
|
}
|
|
43
43
|
function normalizeAssetPaths(assets, rootDir) {
|
|
44
44
|
return assets.map((asset) => {
|
|
45
|
-
const
|
|
45
|
+
const assetDirConfig = asset;
|
|
46
|
+
const assetDir = assetDirConfig.dir;
|
|
46
47
|
if (assetDir) {
|
|
47
48
|
return {
|
|
48
49
|
...asset,
|
|
50
|
+
urlPath: assetDirConfig.root ? "/" : asset.urlPath,
|
|
49
51
|
dir: assetDir && (0, import_shared_utils.normalizeDirectory)(assetDir, rootDir)
|
|
50
52
|
};
|
|
51
53
|
}
|
|
@@ -25,16 +25,28 @@ var __toModule = (module2) => {
|
|
|
25
25
|
__markAsModule(exports);
|
|
26
26
|
__export(exports, {
|
|
27
27
|
normalizeRouteHandlerPaths: () => normalizeRouteHandlerPaths,
|
|
28
|
+
normalizeRouteHandlers: () => normalizeRouteHandlers,
|
|
28
29
|
normalizeRoutePaths: () => normalizeRoutePaths,
|
|
29
30
|
normalizeRoutes: () => normalizeRoutes
|
|
30
31
|
});
|
|
32
|
+
var import_fs = __toModule(require("fs"));
|
|
31
33
|
var import_path = __toModule(require("path"));
|
|
32
34
|
var import_shared_utils = __toModule(require("@lwrjs/shared-utils"));
|
|
33
35
|
function normalizeRoutes(routes, routeHandlers) {
|
|
34
36
|
return routes.map((route) => {
|
|
35
|
-
if (route.routeHandler
|
|
36
|
-
const
|
|
37
|
-
routeHandlers[
|
|
37
|
+
if (route.routeHandler) {
|
|
38
|
+
const [handler, options] = typeof route.routeHandler === "string" ? [route.routeHandler, void 0] : route.routeHandler;
|
|
39
|
+
if (!routeHandlers[handler]) {
|
|
40
|
+
routeHandlers[handler] = [handler, options];
|
|
41
|
+
}
|
|
42
|
+
return {
|
|
43
|
+
...route,
|
|
44
|
+
routeHandler: [handler, options],
|
|
45
|
+
bootstrap: {
|
|
46
|
+
...import_shared_utils.DEFAULT_LWR_BOOTSTRAP_CONFIG,
|
|
47
|
+
...route.bootstrap
|
|
48
|
+
}
|
|
49
|
+
};
|
|
38
50
|
}
|
|
39
51
|
return {
|
|
40
52
|
...route,
|
|
@@ -60,9 +72,20 @@ function normalizeRoutePaths(routes = [], resourcePaths) {
|
|
|
60
72
|
return route;
|
|
61
73
|
});
|
|
62
74
|
}
|
|
75
|
+
function normalizeRouteHandlers(routeHandlers) {
|
|
76
|
+
for (const [id, config] of Object.entries(routeHandlers)) {
|
|
77
|
+
if (typeof config === "string") {
|
|
78
|
+
routeHandlers[id] = [config, void 0];
|
|
79
|
+
}
|
|
80
|
+
}
|
|
81
|
+
return routeHandlers;
|
|
82
|
+
}
|
|
63
83
|
function normalizeRouteHandlerPaths(routeHandlers, resourcePaths) {
|
|
64
|
-
for (const [id,
|
|
65
|
-
|
|
84
|
+
for (const [id, [handler, options]] of Object.entries(routeHandlers)) {
|
|
85
|
+
const normalizedPath = import_path.default.resolve((0, import_shared_utils.normalizeDirectory)(handler, resourcePaths.rootDir));
|
|
86
|
+
if (import_fs.default.existsSync(normalizedPath)) {
|
|
87
|
+
routeHandlers[id] = [normalizedPath, options];
|
|
88
|
+
}
|
|
66
89
|
}
|
|
67
90
|
return routeHandlers;
|
|
68
91
|
}
|
|
@@ -73,10 +73,11 @@ var ROOT_ATTRIBUTE_KEYS = createKeys("root", [
|
|
|
73
73
|
"serverMode",
|
|
74
74
|
"minify",
|
|
75
75
|
"serverType",
|
|
76
|
+
"uriTransformers",
|
|
76
77
|
"viewProviders",
|
|
77
78
|
"viewTransformers"
|
|
78
79
|
]);
|
|
79
|
-
var ASSET_DIR_ATTRIBUTE_KEYS = createKeys("assetDir", ["alias", "dir", "urlPath"]);
|
|
80
|
+
var ASSET_DIR_ATTRIBUTE_KEYS = createKeys("assetDir", ["alias", "dir", "urlPath", "root"]);
|
|
80
81
|
var ASSET_FILE_ATTRIBUTE_KEYS = createKeys("assetFile", ["alias", "file", "urlPath"]);
|
|
81
82
|
var LOCKER_ATTRIBUTE_KEYS = createKeys("locker", ["enabled", "trustedComponents", "clientOnly"]);
|
|
82
83
|
var ROUTE_ATTRIBUTE_KEYS = createKeys("routes", [
|
|
@@ -348,19 +349,23 @@ var ValidationContext = class {
|
|
|
348
349
|
location: this.getLocationFromNode(node)
|
|
349
350
|
});
|
|
350
351
|
} else if (node.children && node.children.length > 0) {
|
|
351
|
-
node.children.forEach((n, index) =>
|
|
352
|
-
|
|
353
|
-
|
|
354
|
-
|
|
355
|
-
|
|
356
|
-
|
|
357
|
-
|
|
358
|
-
|
|
359
|
-
|
|
360
|
-
|
|
361
|
-
|
|
362
|
-
|
|
363
|
-
|
|
352
|
+
node.children.forEach((n, index) => this.assertIsService(n, property, index));
|
|
353
|
+
}
|
|
354
|
+
}
|
|
355
|
+
assertIsService(node, property, index) {
|
|
356
|
+
if (!node) {
|
|
357
|
+
return;
|
|
358
|
+
}
|
|
359
|
+
if (node.type !== "string" && node.type !== "array") {
|
|
360
|
+
this.diagnostics.push({
|
|
361
|
+
description: import_diagnostics.descriptions.CONFIG_PARSER.INCORRECT_NODE_TYPE(index !== void 0 ? `${property}[${index}]` : property, "string or array", node.type),
|
|
362
|
+
location: this.getLocationFromNode(node)
|
|
363
|
+
});
|
|
364
|
+
}
|
|
365
|
+
if (node.type === "string" && node.value.length === 0 || node.type === "array" && node.children && (node.children.length !== 2 || !isNotEmptyString(node.children[0]))) {
|
|
366
|
+
this.diagnostics.push({
|
|
367
|
+
description: import_diagnostics.descriptions.CONFIG_PARSER.INVALID_SERVICE(index !== void 0 ? `${property}[${index}]` : property, node.value === void 0 && node.children ? `invalid Array[${node.children.length}]` : node.value),
|
|
368
|
+
location: this.getLocationFromNode(node)
|
|
364
369
|
});
|
|
365
370
|
}
|
|
366
371
|
}
|
|
@@ -377,6 +382,28 @@ var ValidationContext = class {
|
|
|
377
382
|
});
|
|
378
383
|
}
|
|
379
384
|
}
|
|
385
|
+
assertClientLockerSSR(routesNode, lockerNode) {
|
|
386
|
+
if (routesNode && lockerNode) {
|
|
387
|
+
const enabled = (0, import_jsonc_parser.findNodeAtLocation)(lockerNode, ["enabled"]);
|
|
388
|
+
const clientOnly = (0, import_jsonc_parser.findNodeAtLocation)(lockerNode, ["clientOnly"]);
|
|
389
|
+
const compileTimeLocker = enabled && enabled.value === true && (!clientOnly || clientOnly.value === false);
|
|
390
|
+
if (compileTimeLocker && routesNode.children) {
|
|
391
|
+
const hasSSR = routesNode.children.some((n) => {
|
|
392
|
+
const bootstrap = (0, import_jsonc_parser.findNodeAtLocation)(n, ["bootstrap"]);
|
|
393
|
+
if (bootstrap) {
|
|
394
|
+
const ssr = (0, import_jsonc_parser.findNodeAtLocation)(bootstrap, ["ssr"]);
|
|
395
|
+
return ssr?.value === true;
|
|
396
|
+
}
|
|
397
|
+
});
|
|
398
|
+
if (hasSSR) {
|
|
399
|
+
this.diagnostics.push({
|
|
400
|
+
description: import_diagnostics.descriptions.CONFIG_PARSER.COMPILE_LOCKER_SSR(),
|
|
401
|
+
location: this.getLocationFromNode(lockerNode)
|
|
402
|
+
});
|
|
403
|
+
}
|
|
404
|
+
}
|
|
405
|
+
}
|
|
406
|
+
}
|
|
380
407
|
assertRequiredKeys(node, property, requiredPropertyKeys) {
|
|
381
408
|
const missingProps = requiredPropertyKeys.filter((p) => (0, import_jsonc_parser.findNodeAtLocation)(node, [p]) === void 0);
|
|
382
409
|
if (missingProps.length > 0) {
|
|
@@ -409,4 +436,12 @@ var ValidationContext = class {
|
|
|
409
436
|
}
|
|
410
437
|
}
|
|
411
438
|
}
|
|
439
|
+
assertNoBundleConfigDupes(node, dupes) {
|
|
440
|
+
if (dupes.length) {
|
|
441
|
+
this.diagnostics.push({
|
|
442
|
+
description: import_diagnostics.descriptions.CONFIG_PARSER.DUPLICATE_BUNDLE_CONFIG(dupes),
|
|
443
|
+
location: this.getLocationFromNode(node)
|
|
444
|
+
});
|
|
445
|
+
}
|
|
446
|
+
}
|
|
412
447
|
};
|
|
@@ -31,6 +31,8 @@ var import_jsonc_parser = __toModule(require("jsonc-parser"));
|
|
|
31
31
|
var import_diagnostics = __toModule(require("@lwrjs/diagnostics"));
|
|
32
32
|
var import_app_config_context = __toModule(require("./app-config-context.cjs"));
|
|
33
33
|
var import_helpers = __toModule(require("./helpers.cjs"));
|
|
34
|
+
var import_defaults = __toModule(require("../defaults.cjs"));
|
|
35
|
+
var import_instrumentation = __toModule(require("@lwrjs/instrumentation"));
|
|
34
36
|
var SOURCE_BY_PHASE = {
|
|
35
37
|
file: "lwr.config.json",
|
|
36
38
|
pre: "argument passed to createServer",
|
|
@@ -67,7 +69,7 @@ function validateRouteCommon(node, validationContext, propPrefix) {
|
|
|
67
69
|
validationContext.assertIsSpecifier((0, import_jsonc_parser.findNodeAtLocation)(node, ["rootComponent"]), `${propPrefix}.rootComponent`);
|
|
68
70
|
validationContext.assertNotEmptyString((0, import_jsonc_parser.findNodeAtLocation)(node, ["contentTemplate"]), `${propPrefix}.contentTemplate`);
|
|
69
71
|
validationContext.assertNotEmptyString((0, import_jsonc_parser.findNodeAtLocation)(node, ["layoutTemplate"]), `${propPrefix}.layoutTemplate`);
|
|
70
|
-
validationContext.
|
|
72
|
+
validationContext.assertIsService((0, import_jsonc_parser.findNodeAtLocation)(node, ["routeHandler"]), `${propPrefix}.routeHandler`);
|
|
71
73
|
validateBootstrap((0, import_jsonc_parser.findNodeAtLocation)(node, ["bootstrap"]), validationContext, `${propPrefix}.bootstrap`);
|
|
72
74
|
}
|
|
73
75
|
function validateRoutes(node, validationContext, preMerge) {
|
|
@@ -88,6 +90,50 @@ function validateRoutes(node, validationContext, preMerge) {
|
|
|
88
90
|
}
|
|
89
91
|
}
|
|
90
92
|
}
|
|
93
|
+
function validateBundleConfig(node, validationContext) {
|
|
94
|
+
if (node) {
|
|
95
|
+
validationContext.assertIsObject(node, "bundleConfig");
|
|
96
|
+
const dupeMap = new Map();
|
|
97
|
+
const dupes = new Set();
|
|
98
|
+
const excludeNode = (0, import_jsonc_parser.findNodeAtLocation)(node, ["exclude"]);
|
|
99
|
+
validationContext.assertArrayOfSpecifiers(excludeNode, "bundleConfig.exclude");
|
|
100
|
+
excludeNode?.children?.forEach((n) => {
|
|
101
|
+
dupeMap.set(n.value, true);
|
|
102
|
+
});
|
|
103
|
+
const external = (0, import_jsonc_parser.findNodeAtLocation)(node, ["external"]);
|
|
104
|
+
if (external) {
|
|
105
|
+
external?.children?.forEach((n) => {
|
|
106
|
+
const specifier = (n?.children && n.children[0])?.value;
|
|
107
|
+
if (specifier && dupeMap.has(specifier)) {
|
|
108
|
+
dupes.add(specifier);
|
|
109
|
+
} else {
|
|
110
|
+
dupeMap.set(specifier, true);
|
|
111
|
+
}
|
|
112
|
+
});
|
|
113
|
+
}
|
|
114
|
+
const groups = (0, import_jsonc_parser.findNodeAtLocation)(node, ["groups"]);
|
|
115
|
+
if (groups) {
|
|
116
|
+
validationContext.assertIsObject(groups, "bundleConfig.groups");
|
|
117
|
+
groups?.children?.forEach((n) => {
|
|
118
|
+
const groupKey = n?.children && n.children[0];
|
|
119
|
+
const group = n?.children && n.children[1];
|
|
120
|
+
if (group && groupKey) {
|
|
121
|
+
validationContext.assertNotEmptyArray(group, `bundleConfig.groups.${groupKey.value}`);
|
|
122
|
+
validationContext.assertArrayOfSpecifiers(group, `bundleConfig.groups.${groupKey.value}`);
|
|
123
|
+
const groupies = group?.children;
|
|
124
|
+
groupies?.forEach((n2) => {
|
|
125
|
+
if (dupeMap.has(n2.value)) {
|
|
126
|
+
dupes.add(n2.value);
|
|
127
|
+
}
|
|
128
|
+
});
|
|
129
|
+
}
|
|
130
|
+
});
|
|
131
|
+
}
|
|
132
|
+
const defaultExcludes = new Set([...import_defaults.DEFAULT_AMD_BUNDLE_EXCLUSIONS, ...import_defaults.DEFAULT_ESM_BUNDLE_EXCLUSIONS]);
|
|
133
|
+
const dupesFiltered = Array.from(dupes).filter((specifier) => !defaultExcludes.has(specifier));
|
|
134
|
+
validationContext.assertNoBundleConfigDupes(node, dupesFiltered);
|
|
135
|
+
}
|
|
136
|
+
}
|
|
91
137
|
function validateErrorRoutes(node, validationContext) {
|
|
92
138
|
if (node) {
|
|
93
139
|
validationContext.assertIsArray(node, "errorRoutes");
|
|
@@ -116,20 +162,27 @@ function validateAssets(node, validationContext, preMerge) {
|
|
|
116
162
|
validationContext.assertNotEmptyArray(node, "assets");
|
|
117
163
|
if (node.children) {
|
|
118
164
|
node.children.forEach((n, index) => {
|
|
165
|
+
const rootDirNode = (0, import_jsonc_parser.findNodeAtLocation)(n, ["root"]);
|
|
119
166
|
const dirNode = (0, import_jsonc_parser.findNodeAtLocation)(n, ["dir"]);
|
|
120
167
|
const fileNode = (0, import_jsonc_parser.findNodeAtLocation)(n, ["file"]);
|
|
121
|
-
if (
|
|
168
|
+
if (rootDirNode?.type === "boolean") {
|
|
169
|
+
validationContext.assertIsObject(n, "assetDir");
|
|
170
|
+
validationContext.assertValidKeys(n, "assetDir", import_app_config_context.ASSET_DIR_ATTRIBUTE_KEYS);
|
|
171
|
+
} else if (dirNode?.type === "string") {
|
|
122
172
|
validationContext.assertIsObject(n, "assetDir");
|
|
123
173
|
validationContext.assertValidKeys(n, "assetDir", import_app_config_context.ASSET_DIR_ATTRIBUTE_KEYS);
|
|
174
|
+
validationContext.assertRequiredKeys(n, `assets[${index}]`, ["urlPath"]);
|
|
175
|
+
validationContext.assertIsPath((0, import_jsonc_parser.findNodeAtLocation)(n, ["urlPath"]), `assets[${index}].urlPath`);
|
|
124
176
|
} else if (fileNode?.type === "string") {
|
|
125
177
|
validationContext.assertIsObject(n, "assetFile");
|
|
126
178
|
validationContext.assertValidKeys(n, "assetFile", import_app_config_context.ASSET_FILE_ATTRIBUTE_KEYS);
|
|
179
|
+
validationContext.assertRequiredKeys(n, `assets[${index}]`, ["urlPath"]);
|
|
180
|
+
validationContext.assertIsPath((0, import_jsonc_parser.findNodeAtLocation)(n, ["urlPath"]), `assets[${index}].urlPath`);
|
|
127
181
|
}
|
|
128
|
-
validationContext.assertRequiredKeys(n, `assets[${index}]`, ["urlPath"]);
|
|
129
182
|
validationContext.assertHasOnlyOne(n, `assets[${index}]`, ["dir", "file"]);
|
|
130
183
|
validationContext.assertNotEmptyString(dirNode, `assets[${index}].dir`);
|
|
131
184
|
validationContext.assertNotEmptyString(fileNode, `assets[${index}].file`);
|
|
132
|
-
validationContext.
|
|
185
|
+
validationContext.assertIsBoolean(rootDirNode, `assets[${index}].root`);
|
|
133
186
|
validationContext.assertNotEmptyString((0, import_jsonc_parser.findNodeAtLocation)(n, ["alias"]), `assets[${index}].alias`);
|
|
134
187
|
});
|
|
135
188
|
}
|
|
@@ -152,11 +205,15 @@ function validateRoot(node, validationContext, preMerge) {
|
|
|
152
205
|
const routes = (0, import_jsonc_parser.findNodeAtLocation)(node, ["routes"]);
|
|
153
206
|
const errorRoutes = (0, import_jsonc_parser.findNodeAtLocation)(node, ["errorRoutes"]);
|
|
154
207
|
validationContext.assertUniqueIds([...routes?.children || [], ...errorRoutes?.children || []], "routes");
|
|
208
|
+
const lockerNode = (0, import_jsonc_parser.findNodeAtLocation)(node, ["locker"]);
|
|
209
|
+
const bundleConfigNode = (0, import_jsonc_parser.findNodeAtLocation)(node, ["bundleConfig"]);
|
|
155
210
|
validateRoutes(routes, validationContext, preMerge);
|
|
156
211
|
validateErrorRoutes(errorRoutes, validationContext);
|
|
157
212
|
validateRouteHandlers((0, import_jsonc_parser.findNodeAtLocation)(node, ["routeHandlers"]), validationContext);
|
|
158
213
|
validateAssets((0, import_jsonc_parser.findNodeAtLocation)(node, ["assets"]), validationContext, preMerge);
|
|
159
|
-
validateLocker(
|
|
214
|
+
validateLocker(lockerNode, validationContext);
|
|
215
|
+
validateBundleConfig(bundleConfigNode, validationContext);
|
|
216
|
+
validationContext.assertClientLockerSSR(routes, lockerNode);
|
|
160
217
|
validationContext.assertNotEmptyString((0, import_jsonc_parser.findNodeAtLocation)(node, ["apiVersion"]), "apiVersion");
|
|
161
218
|
validationContext.assertNotEmptyString((0, import_jsonc_parser.findNodeAtLocation)(node, ["lwrVersion"]), "lwrVersion");
|
|
162
219
|
validationContext.assertIsSpecifier((0, import_jsonc_parser.findNodeAtLocation)(node, ["amdLoader"]), "amdLoader");
|
|
@@ -181,6 +238,7 @@ function validateRoot(node, validationContext, preMerge) {
|
|
|
181
238
|
validationContext.assertIsBasePath((0, import_jsonc_parser.findNodeAtLocation)(node, ["basePath"]), "basePath");
|
|
182
239
|
}
|
|
183
240
|
function validateLwrAppConfig(config, phase) {
|
|
241
|
+
const span = (0, import_instrumentation.getTracer)().startSpan({name: import_instrumentation.ConfigSpan.ValidateConfig});
|
|
184
242
|
try {
|
|
185
243
|
const jsonSourceText = typeof config === "string" ? config : JSON.stringify(config);
|
|
186
244
|
const errors = [];
|
|
@@ -200,8 +258,10 @@ function validateLwrAppConfig(config, phase) {
|
|
|
200
258
|
if (validationContext.diagnostics.length) {
|
|
201
259
|
throw new import_diagnostics.LwrConfigValidationError(`Configuration validation errors in ${SOURCE_BY_PHASE[phase]}`, validationContext.diagnostics);
|
|
202
260
|
}
|
|
261
|
+
span.end();
|
|
203
262
|
return;
|
|
204
263
|
} catch (err) {
|
|
264
|
+
span.end();
|
|
205
265
|
if (process.env.UNSAFE_IGNORE_CONFIG_VALIDATION === "true") {
|
|
206
266
|
console.warn("ignoring config validation errors due to UNSAFE_IGNORE_CONFIG_VALIDATION flag...proceed with caution");
|
|
207
267
|
console.dir(err, {depth: null});
|
package/build/es/defaults.d.ts
CHANGED
|
@@ -19,6 +19,8 @@ export declare const DEFAULT_SERVICE_PACKAGE_NAME: RegExp;
|
|
|
19
19
|
export declare const DEFAULT_LWR_MODULES: {
|
|
20
20
|
npm: string;
|
|
21
21
|
}[];
|
|
22
|
+
export declare const DEFAULT_ESM_BUNDLE_EXCLUSIONS: string[];
|
|
23
|
+
export declare const DEFAULT_AMD_BUNDLE_EXCLUSIONS: string[];
|
|
22
24
|
export declare function getDefaultBundleConfig(mode?: string): BundleConfig;
|
|
23
25
|
export declare const DEFAULT_LWR_CONFIG: Required<LwrGlobalConfig>;
|
|
24
26
|
//# sourceMappingURL=defaults.d.ts.map
|
package/build/es/defaults.js
CHANGED
|
@@ -46,6 +46,7 @@ const DEFAULT_VIEW_TRANSFORM_PLUGINS = ['@lwrjs/base-view-transformer'];
|
|
|
46
46
|
export const SSR_VIEW_TRANSFORM_PLUGIN = '@lwrjs/lwc-ssr/viewTransformer';
|
|
47
47
|
const DEFAULT_ASSET_PROVIDERS = ['@lwrjs/fs-asset-provider'];
|
|
48
48
|
const DEFAULT_ASSET_TRANSFORM_PLUGINS = ['@lwrjs/asset-transformer'];
|
|
49
|
+
const DEFAULT_URI_TRANSFORM_PLUGINS = [];
|
|
49
50
|
export const DEFAULT_AMD_LOADER = 'lwr/loader';
|
|
50
51
|
export const DEFAULT_AMD_LOADER_LEGACY = 'lwr/loaderLegacy';
|
|
51
52
|
export const DEFAULT_ESM_LOADER = 'lwr/esmLoader';
|
|
@@ -58,14 +59,15 @@ export const DEFAULT_LWR_MODULES = [
|
|
|
58
59
|
{ npm: '@lwrjs/router' },
|
|
59
60
|
{ npm: '@lwc/synthetic-shadow' },
|
|
60
61
|
];
|
|
61
|
-
const DEFAULT_ESM_BUNDLE_EXCLUSIONS = [
|
|
62
|
+
export const DEFAULT_ESM_BUNDLE_EXCLUSIONS = [
|
|
62
63
|
'lwc',
|
|
63
64
|
'@lwc/synthetic-shadow',
|
|
64
65
|
'lwr/navigation',
|
|
65
66
|
'lwr/esmLoader',
|
|
66
67
|
'lwr/profiler',
|
|
68
|
+
'@salesforce/lds-default-luvio',
|
|
67
69
|
];
|
|
68
|
-
const DEFAULT_AMD_BUNDLE_EXCLUSIONS = ['lwc', 'lwr/navigation'];
|
|
70
|
+
export const DEFAULT_AMD_BUNDLE_EXCLUSIONS = ['lwc', 'lwr/navigation'];
|
|
69
71
|
const DEFAULT_ESM_BUNDLE_EXTERNALS = {};
|
|
70
72
|
const DEFAULT_AMD_BUNDLE_EXTERNALS = {
|
|
71
73
|
'lwr/loader': 'lwr-loader-shim.bundle.min.js',
|
|
@@ -119,5 +121,6 @@ export const DEFAULT_LWR_CONFIG = {
|
|
|
119
121
|
bundleConfig: getDefaultBundleConfig(MODE),
|
|
120
122
|
serverType: DEFAULT_SERVER_TYPE,
|
|
121
123
|
locker: DEFAULT_LWR_LOCKER_CONFIG,
|
|
124
|
+
uriTransformers: DEFAULT_URI_TRANSFORM_PLUGINS,
|
|
122
125
|
};
|
|
123
126
|
//# sourceMappingURL=defaults.js.map
|
|
@@ -7,11 +7,12 @@ import { DEFAULT_AMD_LOADER, DEFAULT_AMD_LOADER_LEGACY, DEFAULT_ESM_LOADER, DEFA
|
|
|
7
7
|
import { validateLwrAppConfig } from './validation/app-config.js';
|
|
8
8
|
import { normalizeAssetPaths, normalizeAssets } from './utils/assets.js';
|
|
9
9
|
import { normalizeServicePaths, normalizeServices } from './utils/services.js';
|
|
10
|
-
import {
|
|
10
|
+
import { normalizeRoutePaths, normalizeRoutes, normalizeRouteHandlers, normalizeRouteHandlerPaths, } from './utils/routes.js';
|
|
11
11
|
import { mergeBundleConfig, mergeLockerConfig, mergeLwcConfig, mergeStaticGenerationConfig, trimLwrConfig, } from './utils/merge.js';
|
|
12
12
|
import { normalizeLwcConfig, normalizeModulePaths } from './utils/lwc.js';
|
|
13
13
|
import { getRuntimeEnvironment } from './runtime-config.js';
|
|
14
14
|
import { getGlobalData } from './utils/global-data.js';
|
|
15
|
+
import { getTracer, ConfigSpan } from '@lwrjs/instrumentation';
|
|
15
16
|
/**
|
|
16
17
|
* Load and validate the global config file.
|
|
17
18
|
*
|
|
@@ -118,11 +119,13 @@ function normalizeConfig(config) {
|
|
|
118
119
|
assetProviders: normalizeServices(config.assetProviders),
|
|
119
120
|
assetTransformers: normalizeServices(config.assetTransformers),
|
|
120
121
|
resourceProviders: normalizeServices(config.resourceProviders),
|
|
122
|
+
uriTransformers: normalizeServices(config.uriTransformers),
|
|
121
123
|
viewProviders: normalizeServices(config.viewProviders),
|
|
122
124
|
viewTransformers: normalizeServices(config.viewTransformers),
|
|
123
125
|
// normalize routes and capture all route handlers
|
|
124
126
|
routes: normalizeRoutes(config.routes, config.routeHandlers),
|
|
125
127
|
errorRoutes: normalizeRoutes(config.errorRoutes, config.routeHandlers),
|
|
128
|
+
routeHandlers: normalizeRouteHandlers(config.routeHandlers),
|
|
126
129
|
};
|
|
127
130
|
}
|
|
128
131
|
/**
|
|
@@ -159,6 +162,7 @@ function normalizeConfigPaths(config) {
|
|
|
159
162
|
assetProviders: normalizeServicePaths(config.assetProviders, rootDir),
|
|
160
163
|
assetTransformers: normalizeServicePaths(config.assetTransformers, rootDir),
|
|
161
164
|
resourceProviders: normalizeServicePaths(config.resourceProviders, rootDir),
|
|
165
|
+
uriTransformers: normalizeServicePaths(config.uriTransformers, rootDir),
|
|
162
166
|
viewProviders: normalizeServicePaths(config.viewProviders, rootDir),
|
|
163
167
|
viewTransformers: normalizeServicePaths(config.viewTransformers, rootDir),
|
|
164
168
|
// normalize all route paths
|
|
@@ -203,14 +207,15 @@ export function applySsrConfig(config) {
|
|
|
203
207
|
export function applyStaticProviderConfig(config) {
|
|
204
208
|
return {
|
|
205
209
|
...config,
|
|
206
|
-
|
|
207
|
-
|
|
208
|
-
|
|
210
|
+
assetProviders: [['@lwrjs/static/asset-provider', undefined]],
|
|
211
|
+
assetTransformers: [],
|
|
212
|
+
resourceProviders: [['@lwrjs/static/resource-provider', {}]],
|
|
213
|
+
moduleProviders: [['@lwrjs/static/module-provider', undefined]],
|
|
209
214
|
bundleProviders: [
|
|
210
|
-
['@lwrjs/
|
|
215
|
+
['@lwrjs/static/bundle-provider', undefined],
|
|
211
216
|
['@lwrjs/module-bundler/amd-runtime-bundle-provider', undefined],
|
|
212
217
|
],
|
|
213
|
-
|
|
218
|
+
uriTransformers: [['@lwrjs/lambda/mrt-static-uri-transformer', undefined]],
|
|
214
219
|
};
|
|
215
220
|
}
|
|
216
221
|
/**
|
|
@@ -229,6 +234,7 @@ export function applyStaticProviderConfig(config) {
|
|
|
229
234
|
* @returns {NormalizedLwrGlobalConfig} a normalized global config relative to the provided options
|
|
230
235
|
*/
|
|
231
236
|
export function resolveGlobalConfig(configArg, options) {
|
|
237
|
+
const span = getTracer().startSpan({ name: ConfigSpan.ResolveConfig });
|
|
232
238
|
const mergedConfig = mergeConfig(configArg);
|
|
233
239
|
let normalizedConfig = normalizeConfig(mergedConfig);
|
|
234
240
|
// Add static providers if applicable
|
|
@@ -243,9 +249,12 @@ export function resolveGlobalConfig(configArg, options) {
|
|
|
243
249
|
}
|
|
244
250
|
// skip dir normalization when the option is set
|
|
245
251
|
if (options?.skipDirNormalization) {
|
|
252
|
+
span.end();
|
|
246
253
|
return normalizedConfig;
|
|
247
254
|
}
|
|
248
|
-
|
|
255
|
+
const retVal = normalizeConfigPaths(normalizedConfig);
|
|
256
|
+
span.end();
|
|
257
|
+
return retVal;
|
|
249
258
|
}
|
|
250
259
|
/**
|
|
251
260
|
* Resolve all application configurations by loading and merging global data, applying config hooks, and
|
|
@@ -255,6 +264,7 @@ export function resolveGlobalConfig(configArg, options) {
|
|
|
255
264
|
* @returns {Configurations} all of the fully resolved configurations
|
|
256
265
|
*/
|
|
257
266
|
export function loadConfig(config, options) {
|
|
267
|
+
const span = getTracer().startSpan({ name: ConfigSpan.LoadConfig });
|
|
258
268
|
const appConfig = resolveGlobalConfig(config, options);
|
|
259
269
|
const runtimeEnvironment = getRuntimeEnvironment(appConfig);
|
|
260
270
|
const globalData = getGlobalData(appConfig.globalDataDir, appConfig.globalData);
|
|
@@ -263,10 +273,12 @@ export function loadConfig(config, options) {
|
|
|
263
273
|
// route length validation happens in the `post` phase of validation
|
|
264
274
|
validateLwrAppConfig(appConfig, 'post');
|
|
265
275
|
}
|
|
266
|
-
|
|
276
|
+
const retVal = {
|
|
267
277
|
appConfig,
|
|
268
278
|
runtimeEnvironment,
|
|
269
279
|
globalData,
|
|
270
280
|
};
|
|
281
|
+
span.end();
|
|
282
|
+
return retVal;
|
|
271
283
|
}
|
|
272
284
|
//# sourceMappingURL=global-config.js.map
|
package/build/es/hooks.d.ts
CHANGED
|
@@ -29,4 +29,5 @@ export declare function executeConfigHooks(hooks: HooksPlugin[], globalConfig: N
|
|
|
29
29
|
* @param globalConfig - global configuration
|
|
30
30
|
*/
|
|
31
31
|
export declare function executeStartHooks(hooks: HooksPlugin[], globalConfig: NormalizedLwrGlobalConfig, skipValidate?: boolean): void;
|
|
32
|
+
export declare function executeInstrumentationHooks(hooks: HooksPlugin[]): boolean;
|
|
32
33
|
//# sourceMappingURL=hooks.d.ts.map
|
package/build/es/hooks.js
CHANGED
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import { normalizeRoutes } from './utils/routes.js';
|
|
2
2
|
import { validateLwrAppConfig } from './validation/app-config.js';
|
|
3
3
|
import { applySsrConfig } from './global-config.js';
|
|
4
|
+
import { getTracer, ConfigSpan } from '@lwrjs/instrumentation';
|
|
4
5
|
/**
|
|
5
6
|
* Run `initConfigs` hooks
|
|
6
7
|
*
|
|
@@ -16,7 +17,9 @@ import { applySsrConfig } from './global-config.js';
|
|
|
16
17
|
* @param globalData - resolved global data
|
|
17
18
|
*/
|
|
18
19
|
export async function executeConfigHooks(hooks, globalConfig, runtimeEnvironment, globalData, skipValidate = false) {
|
|
20
|
+
const span = getTracer().startSpan({ name: ConfigSpan.ExecuteConfigHooks });
|
|
19
21
|
if (!hooks.length) {
|
|
22
|
+
span.end();
|
|
20
23
|
return;
|
|
21
24
|
}
|
|
22
25
|
for (const hook of hooks) {
|
|
@@ -34,6 +37,7 @@ export async function executeConfigHooks(hooks, globalConfig, runtimeEnvironment
|
|
|
34
37
|
if (!skipValidate) {
|
|
35
38
|
validateLwrAppConfig(globalConfig, 'post');
|
|
36
39
|
}
|
|
40
|
+
span.end();
|
|
37
41
|
}
|
|
38
42
|
/**
|
|
39
43
|
* Run `onStart` hooks
|
|
@@ -50,7 +54,9 @@ export async function executeConfigHooks(hooks, globalConfig, runtimeEnvironment
|
|
|
50
54
|
* @param globalConfig - global configuration
|
|
51
55
|
*/
|
|
52
56
|
export function executeStartHooks(hooks, globalConfig, skipValidate = false) {
|
|
57
|
+
const span = getTracer().startSpan({ name: ConfigSpan.ExecuteStartHooks });
|
|
53
58
|
if (!hooks.length) {
|
|
59
|
+
span.end();
|
|
54
60
|
return;
|
|
55
61
|
}
|
|
56
62
|
for (const hook of hooks) {
|
|
@@ -66,5 +72,19 @@ export function executeStartHooks(hooks, globalConfig, skipValidate = false) {
|
|
|
66
72
|
if (!skipValidate) {
|
|
67
73
|
validateLwrAppConfig(globalConfig, 'post');
|
|
68
74
|
}
|
|
75
|
+
span.end();
|
|
76
|
+
}
|
|
77
|
+
export function executeInstrumentationHooks(hooks) {
|
|
78
|
+
const span = getTracer().startSpan({ name: ConfigSpan.ExecuteInstrHooks });
|
|
79
|
+
let retVal = false;
|
|
80
|
+
for (const hook of hooks) {
|
|
81
|
+
if (!hook.initInstrumentation) {
|
|
82
|
+
continue;
|
|
83
|
+
}
|
|
84
|
+
retVal = true;
|
|
85
|
+
hook.initInstrumentation();
|
|
86
|
+
}
|
|
87
|
+
span.end();
|
|
88
|
+
return retVal;
|
|
69
89
|
}
|
|
70
90
|
//# sourceMappingURL=hooks.js.map
|
package/build/es/index.d.ts
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
export { version as LWR_VERSION, lwcVersion as LWC_VERSION } from '@lwrjs/config/package';
|
|
2
2
|
export { loadConfig, resolveGlobalConfig as normalizeConfig, getLwrConfigFromFile } from './global-config.js';
|
|
3
3
|
export { getRuntimeEnvironment } from './runtime-config.js';
|
|
4
|
-
export { executeConfigHooks, executeStartHooks } from './hooks.js';
|
|
4
|
+
export { executeConfigHooks, executeStartHooks, executeInstrumentationHooks } from './hooks.js';
|
|
5
5
|
export { validateLwrAppConfig } from './validation/app-config.js';
|
|
6
6
|
//# sourceMappingURL=index.d.ts.map
|
package/build/es/index.js
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
export { version as LWR_VERSION, lwcVersion as LWC_VERSION } from '@lwrjs/config/package';
|
|
2
2
|
export { loadConfig, resolveGlobalConfig as normalizeConfig, getLwrConfigFromFile } from './global-config.js';
|
|
3
3
|
export { getRuntimeEnvironment } from './runtime-config.js';
|
|
4
|
-
export { executeConfigHooks, executeStartHooks } from './hooks.js';
|
|
4
|
+
export { executeConfigHooks, executeStartHooks, executeInstrumentationHooks } from './hooks.js';
|
|
5
5
|
export { validateLwrAppConfig } from './validation/app-config.js';
|
|
6
6
|
//# sourceMappingURL=index.js.map
|
package/build/es/modules.js
CHANGED
|
@@ -59,6 +59,7 @@ export async function loadServices(config) {
|
|
|
59
59
|
const assetProviders = await loadServiceEntries(config.assetProviders, config.rootDir, config.cacheDir);
|
|
60
60
|
const assetTransformers = await loadServiceEntries(config.assetTransformers, config.rootDir, config.cacheDir);
|
|
61
61
|
const resourceProviders = await loadServiceEntries(config.resourceProviders, config.rootDir, config.cacheDir);
|
|
62
|
+
const uriTransformers = await loadServiceEntries(config.uriTransformers, config.rootDir, config.cacheDir);
|
|
62
63
|
const viewProviders = await loadServiceEntries(config.viewProviders, config.rootDir, config.cacheDir);
|
|
63
64
|
const viewTransformers = await loadServiceEntries(config.viewTransformers, config.rootDir, config.cacheDir);
|
|
64
65
|
return {
|
|
@@ -67,6 +68,7 @@ export async function loadServices(config) {
|
|
|
67
68
|
assetProviders,
|
|
68
69
|
assetTransformers,
|
|
69
70
|
resourceProviders,
|
|
71
|
+
uriTransformers,
|
|
70
72
|
viewProviders,
|
|
71
73
|
viewTransformers,
|
|
72
74
|
};
|
|
@@ -83,9 +85,9 @@ export async function loadServices(config) {
|
|
|
83
85
|
export async function loadRouteHandlers(config) {
|
|
84
86
|
const routeHandlers = {};
|
|
85
87
|
await Promise.all(Object.keys(config.routeHandlers).map(async (id) => {
|
|
86
|
-
const handlerPath = config.routeHandlers[id];
|
|
88
|
+
const [handlerPath, handlerOptions] = config.routeHandlers[id];
|
|
87
89
|
const handler = await importModule(handlerPath, config.rootDir, path.join(config.cacheDir, 'routeHandlers'));
|
|
88
|
-
routeHandlers[id] = handler;
|
|
90
|
+
routeHandlers[id] = [handler, handlerOptions];
|
|
89
91
|
}));
|
|
90
92
|
return routeHandlers;
|
|
91
93
|
}
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { AssetConfig } from '@lwrjs/types';
|
|
1
|
+
import type { AssetConfig } from '@lwrjs/types';
|
|
2
2
|
export declare function normalizeAssets(assets: string | AssetConfig[]): AssetConfig[];
|
|
3
3
|
export declare function normalizeAssetPaths(assets: AssetConfig[], rootDir: string): AssetConfig[];
|
|
4
4
|
//# sourceMappingURL=assets.d.ts.map
|
package/build/es/utils/assets.js
CHANGED
|
@@ -13,10 +13,13 @@ export function normalizeAssets(assets) {
|
|
|
13
13
|
}
|
|
14
14
|
export function normalizeAssetPaths(assets, rootDir) {
|
|
15
15
|
return assets.map((asset) => {
|
|
16
|
-
const
|
|
16
|
+
const assetDirConfig = asset;
|
|
17
|
+
const assetDir = assetDirConfig.dir;
|
|
17
18
|
if (assetDir) {
|
|
18
19
|
return {
|
|
19
20
|
...asset,
|
|
21
|
+
// Add a wild card URL paths for root assets
|
|
22
|
+
urlPath: assetDirConfig.root ? '/' : asset.urlPath,
|
|
20
23
|
dir: assetDir && normalizeDirectory(assetDir, rootDir),
|
|
21
24
|
};
|
|
22
25
|
}
|
|
@@ -1,8 +1,9 @@
|
|
|
1
|
-
import type { LwrErrorRoute, LwrRoute, NormalizedLwrErrorRoute, NormalizedLwrRoute, ResourcePaths, RouteHandlersConfig } from '@lwrjs/types';
|
|
2
|
-
|
|
3
|
-
|
|
1
|
+
import type { LwrErrorRoute, LwrRoute, NormalizedLwrErrorRoute, NormalizedLwrRoute, NormalizedRouteHandlersConfig, ResourcePaths, RouteHandlersConfig } from '@lwrjs/types';
|
|
2
|
+
type ViewOrErrorRoute = LwrRoute | LwrErrorRoute;
|
|
3
|
+
type NormalizedRoute<T extends ViewOrErrorRoute> = T extends LwrRoute ? NormalizedLwrRoute : NormalizedLwrErrorRoute;
|
|
4
4
|
export declare function normalizeRoutes<T extends ViewOrErrorRoute>(routes: T[], routeHandlers: RouteHandlersConfig): NormalizedRoute<T>[];
|
|
5
5
|
export declare function normalizeRoutePaths<T extends ViewOrErrorRoute>(routes: T[] | undefined, resourcePaths: ResourcePaths): NormalizedRoute<T>[];
|
|
6
|
-
export declare function
|
|
6
|
+
export declare function normalizeRouteHandlers(routeHandlers: RouteHandlersConfig): NormalizedRouteHandlersConfig;
|
|
7
|
+
export declare function normalizeRouteHandlerPaths(routeHandlers: NormalizedRouteHandlersConfig, resourcePaths: ResourcePaths): NormalizedRouteHandlersConfig;
|
|
7
8
|
export {};
|
|
8
9
|
//# sourceMappingURL=routes.d.ts.map
|
package/build/es/utils/routes.js
CHANGED
|
@@ -1,12 +1,22 @@
|
|
|
1
|
+
import fs from 'fs';
|
|
1
2
|
import path from 'path';
|
|
2
3
|
import { DEFAULT_LWR_BOOTSTRAP_CONFIG, normalizeDirectory, normalizeResourcePath } from '@lwrjs/shared-utils';
|
|
3
4
|
export function normalizeRoutes(routes, routeHandlers) {
|
|
4
5
|
return routes.map((route) => {
|
|
5
6
|
// when a route handler is set, ensure it is set in the route handler config
|
|
6
|
-
if (route.routeHandler
|
|
7
|
-
const
|
|
8
|
-
|
|
9
|
-
|
|
7
|
+
if (route.routeHandler) {
|
|
8
|
+
const [handler, options] = typeof route.routeHandler === 'string' ? [route.routeHandler, undefined] : route.routeHandler;
|
|
9
|
+
if (!routeHandlers[handler]) {
|
|
10
|
+
routeHandlers[handler] = [handler, options];
|
|
11
|
+
}
|
|
12
|
+
return {
|
|
13
|
+
...route,
|
|
14
|
+
routeHandler: [handler, options],
|
|
15
|
+
bootstrap: {
|
|
16
|
+
...DEFAULT_LWR_BOOTSTRAP_CONFIG,
|
|
17
|
+
...route.bootstrap,
|
|
18
|
+
},
|
|
19
|
+
};
|
|
10
20
|
}
|
|
11
21
|
return {
|
|
12
22
|
...route,
|
|
@@ -33,9 +43,21 @@ export function normalizeRoutePaths(routes = [], resourcePaths) {
|
|
|
33
43
|
return route;
|
|
34
44
|
});
|
|
35
45
|
}
|
|
46
|
+
export function normalizeRouteHandlers(routeHandlers) {
|
|
47
|
+
for (const [id, config] of Object.entries(routeHandlers)) {
|
|
48
|
+
if (typeof config === 'string') {
|
|
49
|
+
routeHandlers[id] = [config, undefined];
|
|
50
|
+
}
|
|
51
|
+
}
|
|
52
|
+
return routeHandlers;
|
|
53
|
+
}
|
|
36
54
|
export function normalizeRouteHandlerPaths(routeHandlers, resourcePaths) {
|
|
37
|
-
for (const [id,
|
|
38
|
-
|
|
55
|
+
for (const [id, [handler, options]] of Object.entries(routeHandlers)) {
|
|
56
|
+
const normalizedPath = path.resolve(normalizeDirectory(handler, resourcePaths.rootDir));
|
|
57
|
+
// use the normalized path if it exists; otherwise the handler is module specifier
|
|
58
|
+
if (fs.existsSync(normalizedPath)) {
|
|
59
|
+
routeHandlers[id] = [normalizedPath, options];
|
|
60
|
+
}
|
|
39
61
|
}
|
|
40
62
|
return routeHandlers;
|
|
41
63
|
}
|
|
@@ -1,11 +1,11 @@
|
|
|
1
|
-
import { AssetDirConfig, AssetFileConfig, LwrErrorRoute, LwrRoute, NormalizedLwrGlobalConfig, NormalizedLwrAppBootstrapConfig, LwrLockerConfig, RouteHandlersConfig } from '@lwrjs/types';
|
|
1
|
+
import type { AssetDirConfig, AssetFileConfig, LwrErrorRoute, LwrRoute, NormalizedLwrGlobalConfig, NormalizedLwrAppBootstrapConfig, LwrLockerConfig, RouteHandlersConfig, BundleConfig } from '@lwrjs/types';
|
|
2
2
|
import { Node } from 'jsonc-parser';
|
|
3
3
|
import { Diagnostic } from '@lwrjs/diagnostics';
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
4
|
+
type RequiredAssetDirConfig = Required<AssetDirConfig>;
|
|
5
|
+
type RequiredAssetFileConfig = Required<AssetFileConfig>;
|
|
6
|
+
type RequiredLwrRoute = Required<LwrRoute>;
|
|
7
|
+
type RequiredLwrErrorRoute = Required<LwrErrorRoute>;
|
|
8
|
+
type RequiredLwrLockerConfig = Required<LwrLockerConfig>;
|
|
9
9
|
interface ConfigMap {
|
|
10
10
|
root: NormalizedLwrGlobalConfig;
|
|
11
11
|
assetDir: RequiredAssetDirConfig;
|
|
@@ -15,9 +15,12 @@ interface ConfigMap {
|
|
|
15
15
|
routeHandlers: RouteHandlersConfig;
|
|
16
16
|
bootstrap: NormalizedLwrAppBootstrapConfig;
|
|
17
17
|
locker: RequiredLwrLockerConfig;
|
|
18
|
+
bundleConfig: BundleConfig;
|
|
19
|
+
'bundleConfig.external': BundleConfig;
|
|
20
|
+
'bundleConfig.groups': BundleConfig;
|
|
18
21
|
}
|
|
19
|
-
export declare const ROOT_ATTRIBUTE_KEYS: ["amdLoader", "apiVersion", "assets", "assetProviders", "assetTransformers", "bundleConfig", "bundleProviders", "cacheDir", "contentDir", "environment", "errorRoutes", "esmLoader", "staticSiteGenerator", "globalData", "globalDataDir", "hooks", "ignoreLwrConfigFile", "lwrConfigFile", "layoutsDir", "locker", "lwc", "lwrVersion", "moduleProviders", "port", "basePath", "resourceProviders", "rootDir", "routeHandlers", "routes", "serverMode", "minify", "serverType", "viewProviders", "viewTransformers"];
|
|
20
|
-
export declare const ASSET_DIR_ATTRIBUTE_KEYS: ["alias", "dir", "urlPath"];
|
|
22
|
+
export declare const ROOT_ATTRIBUTE_KEYS: ["amdLoader", "apiVersion", "assets", "assetProviders", "assetTransformers", "bundleConfig", "bundleProviders", "cacheDir", "contentDir", "environment", "errorRoutes", "esmLoader", "staticSiteGenerator", "globalData", "globalDataDir", "hooks", "ignoreLwrConfigFile", "lwrConfigFile", "layoutsDir", "locker", "lwc", "lwrVersion", "moduleProviders", "port", "basePath", "resourceProviders", "rootDir", "routeHandlers", "routes", "serverMode", "minify", "serverType", "uriTransformers", "viewProviders", "viewTransformers"];
|
|
23
|
+
export declare const ASSET_DIR_ATTRIBUTE_KEYS: ["alias", "dir", "urlPath", "root"];
|
|
21
24
|
export declare const ASSET_FILE_ATTRIBUTE_KEYS: ["alias", "file", "urlPath"];
|
|
22
25
|
export declare const LOCKER_ATTRIBUTE_KEYS: ["enabled", "trustedComponents", "clientOnly"];
|
|
23
26
|
export declare const ROUTE_ATTRIBUTE_KEYS: ["bootstrap", "subRoutes", "contentTemplate", "id", "cache", "layoutTemplate", "method", "path", "rootComponent", "routeHandler", "properties"];
|
|
@@ -48,9 +51,12 @@ export declare class ValidationContext {
|
|
|
48
51
|
assertArrayOfStrings(node: Node | undefined, property: string): void;
|
|
49
52
|
assertArrayOfSpecifiers(node: Node | undefined, property: string): void;
|
|
50
53
|
assertArrayOfServices(node: Node | undefined, property: string): void;
|
|
54
|
+
assertIsService(node: Node | undefined, property: string, index?: number): void;
|
|
51
55
|
assertUniqueIds(nodes: Node[], property: string): void;
|
|
56
|
+
assertClientLockerSSR(routesNode: Node | undefined, lockerNode: Node | undefined): void;
|
|
52
57
|
assertRequiredKeys(node: Node, property: string, requiredPropertyKeys: string[]): void;
|
|
53
58
|
assertValidKeys<T extends keyof ConfigMap>(node: Node, property: T, validPropertyKeys: (keyof ConfigMap[T])[]): void;
|
|
59
|
+
assertNoBundleConfigDupes(node: Node, dupes: string[]): void;
|
|
54
60
|
}
|
|
55
61
|
export {};
|
|
56
62
|
//# sourceMappingURL=app-config-context.d.ts.map
|
|
@@ -39,10 +39,11 @@ export const ROOT_ATTRIBUTE_KEYS = createKeys('root', [
|
|
|
39
39
|
'serverMode',
|
|
40
40
|
'minify',
|
|
41
41
|
'serverType',
|
|
42
|
+
'uriTransformers',
|
|
42
43
|
'viewProviders',
|
|
43
44
|
'viewTransformers',
|
|
44
45
|
]);
|
|
45
|
-
export const ASSET_DIR_ATTRIBUTE_KEYS = createKeys('assetDir', ['alias', 'dir', 'urlPath']);
|
|
46
|
+
export const ASSET_DIR_ATTRIBUTE_KEYS = createKeys('assetDir', ['alias', 'dir', 'urlPath', 'root']);
|
|
46
47
|
export const ASSET_FILE_ATTRIBUTE_KEYS = createKeys('assetFile', ['alias', 'file', 'urlPath']);
|
|
47
48
|
export const LOCKER_ATTRIBUTE_KEYS = createKeys('locker', ['enabled', 'trustedComponents', 'clientOnly']);
|
|
48
49
|
export const ROUTE_ATTRIBUTE_KEYS = createKeys('routes', [
|
|
@@ -323,24 +324,28 @@ export class ValidationContext {
|
|
|
323
324
|
});
|
|
324
325
|
}
|
|
325
326
|
else if (node.children && node.children.length > 0) {
|
|
326
|
-
node.children.forEach((n, index) =>
|
|
327
|
-
|
|
328
|
-
|
|
329
|
-
|
|
330
|
-
|
|
331
|
-
|
|
332
|
-
|
|
333
|
-
|
|
334
|
-
|
|
335
|
-
|
|
336
|
-
|
|
337
|
-
|
|
338
|
-
|
|
339
|
-
|
|
340
|
-
|
|
341
|
-
|
|
342
|
-
|
|
343
|
-
|
|
327
|
+
node.children.forEach((n, index) => this.assertIsService(n, property, index));
|
|
328
|
+
}
|
|
329
|
+
}
|
|
330
|
+
assertIsService(node, property, index) {
|
|
331
|
+
if (!node) {
|
|
332
|
+
return;
|
|
333
|
+
}
|
|
334
|
+
if (node.type !== 'string' && node.type !== 'array') {
|
|
335
|
+
this.diagnostics.push({
|
|
336
|
+
description: descriptions.CONFIG_PARSER.INCORRECT_NODE_TYPE(index !== undefined ? `${property}[${index}]` : property, 'string or array', node.type),
|
|
337
|
+
location: this.getLocationFromNode(node),
|
|
338
|
+
});
|
|
339
|
+
}
|
|
340
|
+
if ((node.type === 'string' && node.value.length === 0) ||
|
|
341
|
+
(node.type === 'array' &&
|
|
342
|
+
node.children &&
|
|
343
|
+
(node.children.length !== 2 || !isNotEmptyString(node.children[0])))) {
|
|
344
|
+
this.diagnostics.push({
|
|
345
|
+
description: descriptions.CONFIG_PARSER.INVALID_SERVICE(index !== undefined ? `${property}[${index}]` : property, node.value === undefined && node.children
|
|
346
|
+
? `invalid Array[${node.children.length}]`
|
|
347
|
+
: node.value),
|
|
348
|
+
location: this.getLocationFromNode(node),
|
|
344
349
|
});
|
|
345
350
|
}
|
|
346
351
|
}
|
|
@@ -359,6 +364,28 @@ export class ValidationContext {
|
|
|
359
364
|
});
|
|
360
365
|
}
|
|
361
366
|
}
|
|
367
|
+
assertClientLockerSSR(routesNode, lockerNode) {
|
|
368
|
+
if (routesNode && lockerNode) {
|
|
369
|
+
const enabled = findNodeAtLocation(lockerNode, ['enabled']);
|
|
370
|
+
const clientOnly = findNodeAtLocation(lockerNode, ['clientOnly']);
|
|
371
|
+
const compileTimeLocker = enabled && enabled.value === true && (!clientOnly || clientOnly.value === false);
|
|
372
|
+
if (compileTimeLocker && routesNode.children) {
|
|
373
|
+
const hasSSR = routesNode.children.some((n) => {
|
|
374
|
+
const bootstrap = findNodeAtLocation(n, ['bootstrap']);
|
|
375
|
+
if (bootstrap) {
|
|
376
|
+
const ssr = findNodeAtLocation(bootstrap, ['ssr']);
|
|
377
|
+
return ssr?.value === true;
|
|
378
|
+
}
|
|
379
|
+
});
|
|
380
|
+
if (hasSSR) {
|
|
381
|
+
this.diagnostics.push({
|
|
382
|
+
description: descriptions.CONFIG_PARSER.COMPILE_LOCKER_SSR(),
|
|
383
|
+
location: this.getLocationFromNode(lockerNode),
|
|
384
|
+
});
|
|
385
|
+
}
|
|
386
|
+
}
|
|
387
|
+
}
|
|
388
|
+
}
|
|
362
389
|
assertRequiredKeys(node, property, requiredPropertyKeys) {
|
|
363
390
|
// All of the given properties must exist on the node
|
|
364
391
|
const missingProps = requiredPropertyKeys.filter((p) => findNodeAtLocation(node, [p]) === undefined);
|
|
@@ -393,5 +420,13 @@ export class ValidationContext {
|
|
|
393
420
|
}
|
|
394
421
|
}
|
|
395
422
|
}
|
|
423
|
+
assertNoBundleConfigDupes(node, dupes) {
|
|
424
|
+
if (dupes.length) {
|
|
425
|
+
this.diagnostics.push({
|
|
426
|
+
description: descriptions.CONFIG_PARSER.DUPLICATE_BUNDLE_CONFIG(dupes),
|
|
427
|
+
location: this.getLocationFromNode(node),
|
|
428
|
+
});
|
|
429
|
+
}
|
|
430
|
+
}
|
|
396
431
|
}
|
|
397
432
|
//# sourceMappingURL=app-config-context.js.map
|
|
@@ -4,7 +4,7 @@ export declare const SOURCE_BY_PHASE: {
|
|
|
4
4
|
pre: string;
|
|
5
5
|
post: string;
|
|
6
6
|
};
|
|
7
|
-
|
|
7
|
+
type ConfigPhase = 'file' | 'pre' | 'post';
|
|
8
8
|
export declare function validateLwrAppConfig(config: string | LwrGlobalConfig, phase: ConfigPhase): void | never;
|
|
9
9
|
export {};
|
|
10
10
|
//# sourceMappingURL=app-config.d.ts.map
|
|
@@ -2,6 +2,8 @@ import { parseTree, printParseErrorCode, findNodeAtLocation as findNode, } from
|
|
|
2
2
|
import { createSingleDiagnosticError, descriptions, LwrConfigValidationError } from '@lwrjs/diagnostics';
|
|
3
3
|
import { ASSET_DIR_ATTRIBUTE_KEYS, ASSET_FILE_ATTRIBUTE_KEYS, BOOTSTRAP_ATTRIBUTE_KEYS, ERROR_ROUTE_ATTRIBUTE_KEYS, LOCKER_ATTRIBUTE_KEYS, ROOT_ATTRIBUTE_KEYS, ROUTE_ATTRIBUTE_KEYS, ValidationContext, } from './app-config-context.js';
|
|
4
4
|
import { calculatePositionFromSource } from './helpers.js';
|
|
5
|
+
import { DEFAULT_ESM_BUNDLE_EXCLUSIONS, DEFAULT_AMD_BUNDLE_EXCLUSIONS } from '../defaults.js';
|
|
6
|
+
import { ConfigSpan, getTracer } from '@lwrjs/instrumentation';
|
|
5
7
|
export const SOURCE_BY_PHASE = {
|
|
6
8
|
file: 'lwr.config.json',
|
|
7
9
|
pre: 'argument passed to createServer',
|
|
@@ -63,7 +65,7 @@ function validateRouteCommon(node, validationContext, propPrefix) {
|
|
|
63
65
|
validationContext.assertIsSpecifier(findNode(node, ['rootComponent']), `${propPrefix}.rootComponent`);
|
|
64
66
|
validationContext.assertNotEmptyString(findNode(node, ['contentTemplate']), `${propPrefix}.contentTemplate`);
|
|
65
67
|
validationContext.assertNotEmptyString(findNode(node, ['layoutTemplate']), `${propPrefix}.layoutTemplate`);
|
|
66
|
-
validationContext.
|
|
68
|
+
validationContext.assertIsService(findNode(node, ['routeHandler']), `${propPrefix}.routeHandler`);
|
|
67
69
|
validateBootstrap(findNode(node, ['bootstrap']), validationContext, `${propPrefix}.bootstrap`);
|
|
68
70
|
}
|
|
69
71
|
/**
|
|
@@ -93,6 +95,55 @@ function validateRoutes(node, validationContext, preMerge) {
|
|
|
93
95
|
}
|
|
94
96
|
}
|
|
95
97
|
}
|
|
98
|
+
function validateBundleConfig(node, validationContext) {
|
|
99
|
+
if (node) {
|
|
100
|
+
validationContext.assertIsObject(node, 'bundleConfig');
|
|
101
|
+
// keep track of dupes
|
|
102
|
+
const dupeMap = new Map();
|
|
103
|
+
const dupes = new Set();
|
|
104
|
+
const excludeNode = findNode(node, ['exclude']);
|
|
105
|
+
validationContext.assertArrayOfSpecifiers(excludeNode, 'bundleConfig.exclude');
|
|
106
|
+
excludeNode?.children?.forEach((n) => {
|
|
107
|
+
dupeMap.set(n.value, true);
|
|
108
|
+
});
|
|
109
|
+
const external = findNode(node, ['external']);
|
|
110
|
+
if (external) {
|
|
111
|
+
external?.children?.forEach((n) => {
|
|
112
|
+
const specifier = (n?.children && n.children[0])?.value;
|
|
113
|
+
if (specifier && dupeMap.has(specifier)) {
|
|
114
|
+
dupes.add(specifier);
|
|
115
|
+
}
|
|
116
|
+
else {
|
|
117
|
+
dupeMap.set(specifier, true);
|
|
118
|
+
}
|
|
119
|
+
});
|
|
120
|
+
// TODO: add RHS externals validation once we finish support for externals in <>
|
|
121
|
+
}
|
|
122
|
+
const groups = findNode(node, ['groups']);
|
|
123
|
+
if (groups) {
|
|
124
|
+
validationContext.assertIsObject(groups, 'bundleConfig.groups');
|
|
125
|
+
groups?.children?.forEach((n) => {
|
|
126
|
+
const groupKey = n?.children && n.children[0];
|
|
127
|
+
const group = n?.children && n.children[1];
|
|
128
|
+
if (group && groupKey) {
|
|
129
|
+
validationContext.assertNotEmptyArray(group, `bundleConfig.groups.${groupKey.value}`);
|
|
130
|
+
validationContext.assertArrayOfSpecifiers(group, `bundleConfig.groups.${groupKey.value}`);
|
|
131
|
+
const groupies = group?.children;
|
|
132
|
+
groupies?.forEach((n) => {
|
|
133
|
+
if (dupeMap.has(n.value)) {
|
|
134
|
+
dupes.add(n.value);
|
|
135
|
+
}
|
|
136
|
+
});
|
|
137
|
+
}
|
|
138
|
+
});
|
|
139
|
+
}
|
|
140
|
+
// For now, allow dupes w/ default excludes
|
|
141
|
+
// TODO W-13651948: remove this once we get rid of UNSAFE_lwrDefaultExcludes
|
|
142
|
+
const defaultExcludes = new Set([...DEFAULT_AMD_BUNDLE_EXCLUSIONS, ...DEFAULT_ESM_BUNDLE_EXCLUSIONS]);
|
|
143
|
+
const dupesFiltered = Array.from(dupes).filter((specifier) => !defaultExcludes.has(specifier));
|
|
144
|
+
validationContext.assertNoBundleConfigDupes(node, dupesFiltered);
|
|
145
|
+
}
|
|
146
|
+
}
|
|
96
147
|
/**
|
|
97
148
|
* Check config.errorRoutes[]:
|
|
98
149
|
* - status: required 404 | 500
|
|
@@ -137,21 +188,29 @@ function validateAssets(node, validationContext, preMerge) {
|
|
|
137
188
|
validationContext.assertNotEmptyArray(node, 'assets');
|
|
138
189
|
if (node.children) {
|
|
139
190
|
node.children.forEach((n, index) => {
|
|
191
|
+
const rootDirNode = findNode(n, ['root']);
|
|
140
192
|
const dirNode = findNode(n, ['dir']);
|
|
141
193
|
const fileNode = findNode(n, ['file']);
|
|
142
|
-
if (
|
|
194
|
+
if (rootDirNode?.type === 'boolean') {
|
|
195
|
+
validationContext.assertIsObject(n, 'assetDir');
|
|
196
|
+
validationContext.assertValidKeys(n, 'assetDir', ASSET_DIR_ATTRIBUTE_KEYS);
|
|
197
|
+
}
|
|
198
|
+
else if (dirNode?.type === 'string') {
|
|
143
199
|
validationContext.assertIsObject(n, 'assetDir');
|
|
144
200
|
validationContext.assertValidKeys(n, 'assetDir', ASSET_DIR_ATTRIBUTE_KEYS);
|
|
201
|
+
validationContext.assertRequiredKeys(n, `assets[${index}]`, ['urlPath']);
|
|
202
|
+
validationContext.assertIsPath(findNode(n, ['urlPath']), `assets[${index}].urlPath`);
|
|
145
203
|
}
|
|
146
204
|
else if (fileNode?.type === 'string') {
|
|
147
205
|
validationContext.assertIsObject(n, 'assetFile');
|
|
148
206
|
validationContext.assertValidKeys(n, 'assetFile', ASSET_FILE_ATTRIBUTE_KEYS);
|
|
207
|
+
validationContext.assertRequiredKeys(n, `assets[${index}]`, ['urlPath']);
|
|
208
|
+
validationContext.assertIsPath(findNode(n, ['urlPath']), `assets[${index}].urlPath`);
|
|
149
209
|
}
|
|
150
|
-
validationContext.assertRequiredKeys(n, `assets[${index}]`, ['urlPath']);
|
|
151
210
|
validationContext.assertHasOnlyOne(n, `assets[${index}]`, ['dir', 'file']);
|
|
152
211
|
validationContext.assertNotEmptyString(dirNode, `assets[${index}].dir`);
|
|
153
212
|
validationContext.assertNotEmptyString(fileNode, `assets[${index}].file`);
|
|
154
|
-
validationContext.
|
|
213
|
+
validationContext.assertIsBoolean(rootDirNode, `assets[${index}].root`);
|
|
155
214
|
validationContext.assertNotEmptyString(findNode(n, ['alias']), `assets[${index}].alias`);
|
|
156
215
|
});
|
|
157
216
|
}
|
|
@@ -178,6 +237,8 @@ function validateLocker(node, validationContext) {
|
|
|
178
237
|
* - routes...
|
|
179
238
|
* - errorRoutes...
|
|
180
239
|
* - assets...
|
|
240
|
+
* - locker...
|
|
241
|
+
* - SSR is only used with clientOnly locker (or locker is disabled)
|
|
181
242
|
* - route and errorRoute ids must be unique
|
|
182
243
|
* - apiVersion: string
|
|
183
244
|
* - lwrVersion: string
|
|
@@ -196,7 +257,6 @@ function validateLocker(node, validationContext) {
|
|
|
196
257
|
* - lwc.modules: array
|
|
197
258
|
* - basePath: valid subdomain part
|
|
198
259
|
* Notes:
|
|
199
|
-
* - ignore `bundleConfig` because it is not yet RFCed
|
|
200
260
|
* - specifier strings are validated for type and shape only, NOT if they are resolvable
|
|
201
261
|
*/
|
|
202
262
|
function validateRoot(node, validationContext, preMerge) {
|
|
@@ -206,11 +266,15 @@ function validateRoot(node, validationContext, preMerge) {
|
|
|
206
266
|
const routes = findNode(node, ['routes']);
|
|
207
267
|
const errorRoutes = findNode(node, ['errorRoutes']);
|
|
208
268
|
validationContext.assertUniqueIds([...(routes?.children || []), ...(errorRoutes?.children || [])], 'routes');
|
|
269
|
+
const lockerNode = findNode(node, ['locker']);
|
|
270
|
+
const bundleConfigNode = findNode(node, ['bundleConfig']);
|
|
209
271
|
validateRoutes(routes, validationContext, preMerge);
|
|
210
272
|
validateErrorRoutes(errorRoutes, validationContext);
|
|
211
273
|
validateRouteHandlers(findNode(node, ['routeHandlers']), validationContext);
|
|
212
274
|
validateAssets(findNode(node, ['assets']), validationContext, preMerge);
|
|
213
|
-
validateLocker(
|
|
275
|
+
validateLocker(lockerNode, validationContext);
|
|
276
|
+
validateBundleConfig(bundleConfigNode, validationContext);
|
|
277
|
+
validationContext.assertClientLockerSSR(routes, lockerNode);
|
|
214
278
|
validationContext.assertNotEmptyString(findNode(node, ['apiVersion']), 'apiVersion');
|
|
215
279
|
validationContext.assertNotEmptyString(findNode(node, ['lwrVersion']), 'lwrVersion');
|
|
216
280
|
validationContext.assertIsSpecifier(findNode(node, ['amdLoader']), 'amdLoader');
|
|
@@ -235,6 +299,7 @@ function validateRoot(node, validationContext, preMerge) {
|
|
|
235
299
|
validationContext.assertIsBasePath(findNode(node, ['basePath']), 'basePath');
|
|
236
300
|
}
|
|
237
301
|
export function validateLwrAppConfig(config, phase) {
|
|
302
|
+
const span = getTracer().startSpan({ name: ConfigSpan.ValidateConfig });
|
|
238
303
|
try {
|
|
239
304
|
const jsonSourceText = typeof config === 'string' ? config : JSON.stringify(config);
|
|
240
305
|
const errors = [];
|
|
@@ -257,9 +322,11 @@ export function validateLwrAppConfig(config, phase) {
|
|
|
257
322
|
if (validationContext.diagnostics.length) {
|
|
258
323
|
throw new LwrConfigValidationError(`Configuration validation errors in ${SOURCE_BY_PHASE[phase]}`, validationContext.diagnostics);
|
|
259
324
|
}
|
|
325
|
+
span.end();
|
|
260
326
|
return;
|
|
261
327
|
}
|
|
262
328
|
catch (err) {
|
|
329
|
+
span.end();
|
|
263
330
|
if (process.env.UNSAFE_IGNORE_CONFIG_VALIDATION === 'true') {
|
|
264
331
|
console.warn('ignoring config validation errors due to UNSAFE_IGNORE_CONFIG_VALIDATION flag...proceed with caution');
|
|
265
332
|
console.dir(err, { depth: null });
|
package/package.cjs
CHANGED
|
@@ -16,9 +16,14 @@ let lwcVersion;
|
|
|
16
16
|
if (globalThis.LWC_VERSION) {
|
|
17
17
|
version = globalThis.LWC_VERSION;
|
|
18
18
|
} else {
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
19
|
+
try {
|
|
20
|
+
const packageJsonPath = resolve.sync(`lwc/package.json`);
|
|
21
|
+
const { version: packageVersion } = JSON.parse(fs.readFileSync(packageJsonPath), 'utf-8');
|
|
22
|
+
lwcVersion = packageVersion;
|
|
23
|
+
} catch(err) {
|
|
24
|
+
console.log(`[config] peer dependency lwc was not provided`);
|
|
25
|
+
lwcVersion = 'not-provided';
|
|
26
|
+
}
|
|
22
27
|
}
|
|
23
28
|
|
|
24
29
|
module.exports = {
|
package/package.json
CHANGED
|
@@ -4,7 +4,7 @@
|
|
|
4
4
|
"publishConfig": {
|
|
5
5
|
"access": "public"
|
|
6
6
|
},
|
|
7
|
-
"version": "0.10.0-alpha.
|
|
7
|
+
"version": "0.10.0-alpha.20",
|
|
8
8
|
"homepage": "https://developer.salesforce.com/docs/platform/lwr/overview",
|
|
9
9
|
"repository": {
|
|
10
10
|
"type": "git",
|
|
@@ -35,20 +35,31 @@
|
|
|
35
35
|
"build/**/*.d.ts",
|
|
36
36
|
"package.cjs"
|
|
37
37
|
],
|
|
38
|
+
"scripts": {
|
|
39
|
+
"build": "tsc -b",
|
|
40
|
+
"clean": "rm -rf build node_modules",
|
|
41
|
+
"test": "jest"
|
|
42
|
+
},
|
|
38
43
|
"dependencies": {
|
|
39
|
-
"@lwrjs/diagnostics": "0.10.0-alpha.
|
|
40
|
-
"@lwrjs/
|
|
41
|
-
"
|
|
44
|
+
"@lwrjs/diagnostics": "0.10.0-alpha.20",
|
|
45
|
+
"@lwrjs/instrumentation": "0.10.0-alpha.20",
|
|
46
|
+
"@lwrjs/shared-utils": "0.10.0-alpha.20",
|
|
47
|
+
"fs-extra": "^11.1.1",
|
|
42
48
|
"jsonc-parser": "^3.0.0"
|
|
43
49
|
},
|
|
44
50
|
"devDependencies": {
|
|
45
|
-
"@lwrjs/types": "0.10.0-alpha.
|
|
51
|
+
"@lwrjs/types": "0.10.0-alpha.20",
|
|
52
|
+
"jest": "^26.6.3",
|
|
53
|
+
"ts-jest": "^26.5.6"
|
|
46
54
|
},
|
|
47
55
|
"peerDependencies": {
|
|
48
56
|
"lwc": "2.x"
|
|
49
57
|
},
|
|
50
58
|
"engines": {
|
|
51
|
-
"node": ">=16.0.0
|
|
59
|
+
"node": ">=16.0.0"
|
|
60
|
+
},
|
|
61
|
+
"volta": {
|
|
62
|
+
"extends": "../../../package.json"
|
|
52
63
|
},
|
|
53
|
-
"gitHead": "
|
|
64
|
+
"gitHead": "45a867fc54e98f77dd442ccd5f668e23027b9246"
|
|
54
65
|
}
|