@lwrjs/config 0.10.0-alpha.15 → 0.10.0-alpha.17
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/global-config.cjs +2 -1
- package/build/cjs/modules.cjs +2 -2
- package/build/cjs/utils/routes.cjs +28 -5
- package/build/cjs/validation/app-config-context.cjs +17 -13
- package/build/cjs/validation/app-config.cjs +1 -1
- package/build/es/global-config.js +2 -1
- package/build/es/modules.js +2 -2
- package/build/es/utils/assets.d.ts +1 -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 +7 -6
- package/build/es/validation/app-config-context.js +22 -18
- package/build/es/validation/app-config.d.ts +1 -1
- package/build/es/validation/app-config.js +1 -1
- package/build/es/validation/helpers.d.ts +1 -1
- package/package.json +5 -5
|
@@ -97,7 +97,8 @@ function normalizeConfig(config) {
|
|
|
97
97
|
viewProviders: (0, import_services.normalizeServices)(config.viewProviders),
|
|
98
98
|
viewTransformers: (0, import_services.normalizeServices)(config.viewTransformers),
|
|
99
99
|
routes: (0, import_routes.normalizeRoutes)(config.routes, config.routeHandlers),
|
|
100
|
-
errorRoutes: (0, import_routes.normalizeRoutes)(config.errorRoutes, config.routeHandlers)
|
|
100
|
+
errorRoutes: (0, import_routes.normalizeRoutes)(config.errorRoutes, config.routeHandlers),
|
|
101
|
+
routeHandlers: (0, import_routes.normalizeRouteHandlers)(config.routeHandlers)
|
|
101
102
|
};
|
|
102
103
|
}
|
|
103
104
|
function normalizeConfigPaths(config) {
|
package/build/cjs/modules.cjs
CHANGED
|
@@ -86,9 +86,9 @@ async function loadServices(config) {
|
|
|
86
86
|
async function loadRouteHandlers(config) {
|
|
87
87
|
const routeHandlers = {};
|
|
88
88
|
await Promise.all(Object.keys(config.routeHandlers).map(async (id) => {
|
|
89
|
-
const handlerPath = config.routeHandlers[id];
|
|
89
|
+
const [handlerPath, handlerOptions] = config.routeHandlers[id];
|
|
90
90
|
const handler = await importModule(handlerPath, config.rootDir, import_path.default.join(config.cacheDir, "routeHandlers"));
|
|
91
|
-
routeHandlers[id] = handler;
|
|
91
|
+
routeHandlers[id] = [handler, handlerOptions];
|
|
92
92
|
}));
|
|
93
93
|
return routeHandlers;
|
|
94
94
|
}
|
|
@@ -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
|
}
|
|
@@ -349,19 +349,23 @@ var ValidationContext = class {
|
|
|
349
349
|
location: this.getLocationFromNode(node)
|
|
350
350
|
});
|
|
351
351
|
} else if (node.children && node.children.length > 0) {
|
|
352
|
-
node.children.forEach((n, index) =>
|
|
353
|
-
|
|
354
|
-
|
|
355
|
-
|
|
356
|
-
|
|
357
|
-
|
|
358
|
-
|
|
359
|
-
|
|
360
|
-
|
|
361
|
-
|
|
362
|
-
|
|
363
|
-
|
|
364
|
-
|
|
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)
|
|
365
369
|
});
|
|
366
370
|
}
|
|
367
371
|
}
|
|
@@ -67,7 +67,7 @@ function validateRouteCommon(node, validationContext, propPrefix) {
|
|
|
67
67
|
validationContext.assertIsSpecifier((0, import_jsonc_parser.findNodeAtLocation)(node, ["rootComponent"]), `${propPrefix}.rootComponent`);
|
|
68
68
|
validationContext.assertNotEmptyString((0, import_jsonc_parser.findNodeAtLocation)(node, ["contentTemplate"]), `${propPrefix}.contentTemplate`);
|
|
69
69
|
validationContext.assertNotEmptyString((0, import_jsonc_parser.findNodeAtLocation)(node, ["layoutTemplate"]), `${propPrefix}.layoutTemplate`);
|
|
70
|
-
validationContext.
|
|
70
|
+
validationContext.assertIsService((0, import_jsonc_parser.findNodeAtLocation)(node, ["routeHandler"]), `${propPrefix}.routeHandler`);
|
|
71
71
|
validateBootstrap((0, import_jsonc_parser.findNodeAtLocation)(node, ["bootstrap"]), validationContext, `${propPrefix}.bootstrap`);
|
|
72
72
|
}
|
|
73
73
|
function validateRoutes(node, validationContext, preMerge) {
|
|
@@ -7,7 +7,7 @@ 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';
|
|
@@ -124,6 +124,7 @@ function normalizeConfig(config) {
|
|
|
124
124
|
// normalize routes and capture all route handlers
|
|
125
125
|
routes: normalizeRoutes(config.routes, config.routeHandlers),
|
|
126
126
|
errorRoutes: normalizeRoutes(config.errorRoutes, config.routeHandlers),
|
|
127
|
+
routeHandlers: normalizeRouteHandlers(config.routeHandlers),
|
|
127
128
|
};
|
|
128
129
|
}
|
|
129
130
|
/**
|
package/build/es/modules.js
CHANGED
|
@@ -85,9 +85,9 @@ export async function loadServices(config) {
|
|
|
85
85
|
export async function loadRouteHandlers(config) {
|
|
86
86
|
const routeHandlers = {};
|
|
87
87
|
await Promise.all(Object.keys(config.routeHandlers).map(async (id) => {
|
|
88
|
-
const handlerPath = config.routeHandlers[id];
|
|
88
|
+
const [handlerPath, handlerOptions] = config.routeHandlers[id];
|
|
89
89
|
const handler = await importModule(handlerPath, config.rootDir, path.join(config.cacheDir, 'routeHandlers'));
|
|
90
|
-
routeHandlers[id] = handler;
|
|
90
|
+
routeHandlers[id] = [handler, handlerOptions];
|
|
91
91
|
}));
|
|
92
92
|
return routeHandlers;
|
|
93
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
|
|
@@ -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 } 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;
|
|
@@ -48,6 +48,7 @@ export declare class ValidationContext {
|
|
|
48
48
|
assertArrayOfStrings(node: Node | undefined, property: string): void;
|
|
49
49
|
assertArrayOfSpecifiers(node: Node | undefined, property: string): void;
|
|
50
50
|
assertArrayOfServices(node: Node | undefined, property: string): void;
|
|
51
|
+
assertIsService(node: Node | undefined, property: string, index?: number): void;
|
|
51
52
|
assertUniqueIds(nodes: Node[], property: string): void;
|
|
52
53
|
assertClientLockerSSR(routesNode: Node | undefined, lockerNode: Node | undefined): void;
|
|
53
54
|
assertRequiredKeys(node: Node, property: string, requiredPropertyKeys: string[]): void;
|
|
@@ -324,24 +324,28 @@ export class ValidationContext {
|
|
|
324
324
|
});
|
|
325
325
|
}
|
|
326
326
|
else if (node.children && node.children.length > 0) {
|
|
327
|
-
node.children.forEach((n, index) =>
|
|
328
|
-
|
|
329
|
-
|
|
330
|
-
|
|
331
|
-
|
|
332
|
-
|
|
333
|
-
|
|
334
|
-
|
|
335
|
-
|
|
336
|
-
|
|
337
|
-
|
|
338
|
-
|
|
339
|
-
|
|
340
|
-
|
|
341
|
-
|
|
342
|
-
|
|
343
|
-
|
|
344
|
-
|
|
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),
|
|
345
349
|
});
|
|
346
350
|
}
|
|
347
351
|
}
|
|
@@ -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
|
|
@@ -63,7 +63,7 @@ function validateRouteCommon(node, validationContext, propPrefix) {
|
|
|
63
63
|
validationContext.assertIsSpecifier(findNode(node, ['rootComponent']), `${propPrefix}.rootComponent`);
|
|
64
64
|
validationContext.assertNotEmptyString(findNode(node, ['contentTemplate']), `${propPrefix}.contentTemplate`);
|
|
65
65
|
validationContext.assertNotEmptyString(findNode(node, ['layoutTemplate']), `${propPrefix}.layoutTemplate`);
|
|
66
|
-
validationContext.
|
|
66
|
+
validationContext.assertIsService(findNode(node, ['routeHandler']), `${propPrefix}.routeHandler`);
|
|
67
67
|
validateBootstrap(findNode(node, ['bootstrap']), validationContext, `${propPrefix}.bootstrap`);
|
|
68
68
|
}
|
|
69
69
|
/**
|
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.17",
|
|
8
8
|
"homepage": "https://developer.salesforce.com/docs/platform/lwr/overview",
|
|
9
9
|
"repository": {
|
|
10
10
|
"type": "git",
|
|
@@ -36,13 +36,13 @@
|
|
|
36
36
|
"package.cjs"
|
|
37
37
|
],
|
|
38
38
|
"dependencies": {
|
|
39
|
-
"@lwrjs/diagnostics": "0.10.0-alpha.
|
|
40
|
-
"@lwrjs/shared-utils": "0.10.0-alpha.
|
|
39
|
+
"@lwrjs/diagnostics": "0.10.0-alpha.17",
|
|
40
|
+
"@lwrjs/shared-utils": "0.10.0-alpha.17",
|
|
41
41
|
"fs-extra": "^11.1.1",
|
|
42
42
|
"jsonc-parser": "^3.0.0"
|
|
43
43
|
},
|
|
44
44
|
"devDependencies": {
|
|
45
|
-
"@lwrjs/types": "0.10.0-alpha.
|
|
45
|
+
"@lwrjs/types": "0.10.0-alpha.17"
|
|
46
46
|
},
|
|
47
47
|
"peerDependencies": {
|
|
48
48
|
"lwc": "2.x"
|
|
@@ -50,5 +50,5 @@
|
|
|
50
50
|
"engines": {
|
|
51
51
|
"node": ">=16.0.0 <20"
|
|
52
52
|
},
|
|
53
|
-
"gitHead": "
|
|
53
|
+
"gitHead": "36cfce3a18bf3dc71a7d5203bbaa9aa752ccce06"
|
|
54
54
|
}
|