@lwrjs/config 0.8.0-alpha.3
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/LICENSE +10 -0
- package/build/cjs/env-config.cjs +339 -0
- package/build/cjs/index.cjs +32 -0
- package/build/cjs/validation/app-config-context.cjs +406 -0
- package/build/cjs/validation/app-config.cjs +192 -0
- package/build/cjs/validation/helpers.cjs +34 -0
- package/build/es/env-config.d.ts +14 -0
- package/build/es/env-config.js +352 -0
- package/build/es/index.d.ts +4 -0
- package/build/es/index.js +5 -0
- package/build/es/validation/app-config-context.d.ts +55 -0
- package/build/es/validation/app-config-context.js +391 -0
- package/build/es/validation/app-config.d.ts +10 -0
- package/build/es/validation/app-config.js +245 -0
- package/build/es/validation/helpers.d.ts +8 -0
- package/build/es/validation/helpers.js +23 -0
- package/package.cjs +9 -0
- package/package.json +48 -0
- package/runtime-configs/compat.json +13 -0
- package/runtime-configs/dev.json +13 -0
- package/runtime-configs/prod-compat.json +13 -0
- package/runtime-configs/prod.json +13 -0
|
@@ -0,0 +1,406 @@
|
|
|
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/config/src/validation/app-config-context.ts
|
|
25
|
+
__markAsModule(exports);
|
|
26
|
+
__export(exports, {
|
|
27
|
+
ASSET_DIR_ATTRIBUTE_KEYS: () => ASSET_DIR_ATTRIBUTE_KEYS,
|
|
28
|
+
ASSET_FILE_ATTRIBUTE_KEYS: () => ASSET_FILE_ATTRIBUTE_KEYS,
|
|
29
|
+
BASE_PATH_REGEX: () => BASE_PATH_REGEX,
|
|
30
|
+
BOOTSTRAP_ATTRIBUTE_KEYS: () => BOOTSTRAP_ATTRIBUTE_KEYS,
|
|
31
|
+
ERROR_ROUTE_ATTRIBUTE_KEYS: () => ERROR_ROUTE_ATTRIBUTE_KEYS,
|
|
32
|
+
LOCKER_ATTRIBUTE_KEYS: () => LOCKER_ATTRIBUTE_KEYS,
|
|
33
|
+
ROOT_ATTRIBUTE_KEYS: () => ROOT_ATTRIBUTE_KEYS,
|
|
34
|
+
ROUTE_ATTRIBUTE_KEYS: () => ROUTE_ATTRIBUTE_KEYS,
|
|
35
|
+
ValidationContext: () => ValidationContext
|
|
36
|
+
});
|
|
37
|
+
var import_jsonc_parser = __toModule(require("jsonc-parser"));
|
|
38
|
+
var import_diagnostics = __toModule(require("@lwrjs/diagnostics"));
|
|
39
|
+
var import_helpers = __toModule(require("./helpers.cjs"));
|
|
40
|
+
function createKeys(p, t) {
|
|
41
|
+
return p && t;
|
|
42
|
+
}
|
|
43
|
+
var ROOT_ATTRIBUTE_KEYS = createKeys("root", [
|
|
44
|
+
"amdLoader",
|
|
45
|
+
"apiVersion",
|
|
46
|
+
"assets",
|
|
47
|
+
"assetProviders",
|
|
48
|
+
"assetTransformers",
|
|
49
|
+
"bundleConfig",
|
|
50
|
+
"cacheDir",
|
|
51
|
+
"contentDir",
|
|
52
|
+
"environment",
|
|
53
|
+
"errorRoutes",
|
|
54
|
+
"esmLoader",
|
|
55
|
+
"staticSiteGenerator",
|
|
56
|
+
"globalData",
|
|
57
|
+
"globalDataDir",
|
|
58
|
+
"hooks",
|
|
59
|
+
"ignoreLwrConfigFile",
|
|
60
|
+
"lwrConfigFile",
|
|
61
|
+
"layoutsDir",
|
|
62
|
+
"locker",
|
|
63
|
+
"lwc",
|
|
64
|
+
"lwrVersion",
|
|
65
|
+
"moduleProviders",
|
|
66
|
+
"port",
|
|
67
|
+
"basePath",
|
|
68
|
+
"resourceProviders",
|
|
69
|
+
"rootDir",
|
|
70
|
+
"routes",
|
|
71
|
+
"serverMode",
|
|
72
|
+
"serverType",
|
|
73
|
+
"templateEngine",
|
|
74
|
+
"viewProviders",
|
|
75
|
+
"viewTransformers"
|
|
76
|
+
]);
|
|
77
|
+
var ASSET_DIR_ATTRIBUTE_KEYS = createKeys("assetDir", ["alias", "dir", "urlPath"]);
|
|
78
|
+
var ASSET_FILE_ATTRIBUTE_KEYS = createKeys("assetFile", ["alias", "file", "urlPath"]);
|
|
79
|
+
var LOCKER_ATTRIBUTE_KEYS = createKeys("locker", ["enabled", "trustedComponents", "clientOnly"]);
|
|
80
|
+
var ROUTE_ATTRIBUTE_KEYS = createKeys("routes", [
|
|
81
|
+
"bootstrap",
|
|
82
|
+
"contentTemplate",
|
|
83
|
+
"id",
|
|
84
|
+
"cache",
|
|
85
|
+
"layoutTemplate",
|
|
86
|
+
"method",
|
|
87
|
+
"path",
|
|
88
|
+
"rootComponent",
|
|
89
|
+
"routeHandler",
|
|
90
|
+
"properties"
|
|
91
|
+
]);
|
|
92
|
+
var ERROR_ROUTE_ATTRIBUTE_KEYS = createKeys("errorRoutes", [
|
|
93
|
+
"bootstrap",
|
|
94
|
+
"contentTemplate",
|
|
95
|
+
"id",
|
|
96
|
+
"layoutTemplate",
|
|
97
|
+
"rootComponent",
|
|
98
|
+
"routeHandler",
|
|
99
|
+
"status",
|
|
100
|
+
"properties",
|
|
101
|
+
"cache"
|
|
102
|
+
]);
|
|
103
|
+
var BOOTSTRAP_ATTRIBUTE_KEYS = createKeys("bootstrap", [
|
|
104
|
+
"autoBoot",
|
|
105
|
+
"syntheticShadow",
|
|
106
|
+
"workers",
|
|
107
|
+
"services",
|
|
108
|
+
"configAsSrc",
|
|
109
|
+
"experimentalSSR"
|
|
110
|
+
]);
|
|
111
|
+
var SPECIFIER_REGEX = /^@?[\w-]+(\/[\w-]+)*$/;
|
|
112
|
+
function isNotEmptyString(node) {
|
|
113
|
+
return node.type === "string" && node.value.length > 0;
|
|
114
|
+
}
|
|
115
|
+
var BASE_PATH_REGEX = /^(\/[A-Za-z0-9](?:[A-Za-z0-9-]{0,61}[A-Za-z0-9])?)+$/g;
|
|
116
|
+
var ValidationContext = class {
|
|
117
|
+
constructor(sourceText) {
|
|
118
|
+
this.diagnostics = [];
|
|
119
|
+
this.sourceText = sourceText;
|
|
120
|
+
}
|
|
121
|
+
getLocationFromNode(node) {
|
|
122
|
+
return (0, import_helpers.calculatePositionFromSource)(this.sourceText, node);
|
|
123
|
+
}
|
|
124
|
+
assertIsObject(node, property) {
|
|
125
|
+
if (node.type !== "object") {
|
|
126
|
+
this.diagnostics.push({
|
|
127
|
+
description: import_diagnostics.descriptions.CONFIG_PARSER.INCORRECT_NODE_TYPE(property, "object", node.type),
|
|
128
|
+
location: this.getLocationFromNode(node)
|
|
129
|
+
});
|
|
130
|
+
}
|
|
131
|
+
}
|
|
132
|
+
assertIsBoolean(node, property) {
|
|
133
|
+
if (node && node.type !== "boolean") {
|
|
134
|
+
this.diagnostics.push({
|
|
135
|
+
description: import_diagnostics.descriptions.CONFIG_PARSER.INCORRECT_NODE_TYPE(property, "boolean", node.type),
|
|
136
|
+
location: this.getLocationFromNode(node)
|
|
137
|
+
});
|
|
138
|
+
}
|
|
139
|
+
}
|
|
140
|
+
assertIsArray(node, property) {
|
|
141
|
+
if (node && node.type !== "array") {
|
|
142
|
+
this.diagnostics.push({
|
|
143
|
+
description: import_diagnostics.descriptions.CONFIG_PARSER.INCORRECT_NODE_TYPE(property, "array", node.type),
|
|
144
|
+
location: this.getLocationFromNode(node)
|
|
145
|
+
});
|
|
146
|
+
}
|
|
147
|
+
}
|
|
148
|
+
assertIsSpecifier(node, property) {
|
|
149
|
+
if (node && (node.type !== "string" || !SPECIFIER_REGEX.test(node.value))) {
|
|
150
|
+
this.diagnostics.push({
|
|
151
|
+
description: import_diagnostics.descriptions.CONFIG_PARSER.INVALID_SPECIFIER(property, node.value),
|
|
152
|
+
location: this.getLocationFromNode(node)
|
|
153
|
+
});
|
|
154
|
+
}
|
|
155
|
+
}
|
|
156
|
+
assertIsPath(node, property) {
|
|
157
|
+
if (node && (node.type !== "string" || node.value[0] !== "/")) {
|
|
158
|
+
this.diagnostics.push({
|
|
159
|
+
description: import_diagnostics.descriptions.CONFIG_PARSER.INVALID_PATH(property, node.value),
|
|
160
|
+
location: this.getLocationFromNode(node)
|
|
161
|
+
});
|
|
162
|
+
}
|
|
163
|
+
}
|
|
164
|
+
assertIsPort(node, property) {
|
|
165
|
+
if (node && (node.type !== "number" || node.value < 0 || node.value > 65353)) {
|
|
166
|
+
this.diagnostics.push({
|
|
167
|
+
description: import_diagnostics.descriptions.CONFIG_PARSER.INVALID_PORT(property, node.value),
|
|
168
|
+
location: this.getLocationFromNode(node)
|
|
169
|
+
});
|
|
170
|
+
}
|
|
171
|
+
}
|
|
172
|
+
assertIsServerType(node, property) {
|
|
173
|
+
if (node && node.value !== "express" && node.value !== "koa" && node.value !== "fs") {
|
|
174
|
+
this.diagnostics.push({
|
|
175
|
+
description: import_diagnostics.descriptions.CONFIG_PARSER.INVALID_SERVER_TYPE(property, node.value),
|
|
176
|
+
location: this.getLocationFromNode(node)
|
|
177
|
+
});
|
|
178
|
+
}
|
|
179
|
+
}
|
|
180
|
+
assertIsStaticSiteGenerator(node, property) {
|
|
181
|
+
if (node && node.type !== "object") {
|
|
182
|
+
this.diagnostics.push({
|
|
183
|
+
description: import_diagnostics.descriptions.CONFIG_PARSER.INVALID_GENERATOR_CONFIG(property, node.value),
|
|
184
|
+
location: this.getLocationFromNode(node)
|
|
185
|
+
});
|
|
186
|
+
}
|
|
187
|
+
}
|
|
188
|
+
assertIsMethod(node, property) {
|
|
189
|
+
if (node && node.value !== "get" && node.value !== "post") {
|
|
190
|
+
this.diagnostics.push({
|
|
191
|
+
description: import_diagnostics.descriptions.CONFIG_PARSER.INVALID_METHOD(property, node.value),
|
|
192
|
+
location: this.getLocationFromNode(node)
|
|
193
|
+
});
|
|
194
|
+
}
|
|
195
|
+
}
|
|
196
|
+
assertIsStatus(node, property) {
|
|
197
|
+
if (node && node.value !== 404 && node.value !== 500) {
|
|
198
|
+
this.diagnostics.push({
|
|
199
|
+
description: import_diagnostics.descriptions.CONFIG_PARSER.INVALID_STATUS(property, node.value),
|
|
200
|
+
location: this.getLocationFromNode(node)
|
|
201
|
+
});
|
|
202
|
+
}
|
|
203
|
+
}
|
|
204
|
+
assertIsEnvironment(node, property) {
|
|
205
|
+
if (!node) {
|
|
206
|
+
return;
|
|
207
|
+
}
|
|
208
|
+
let defaultProperty;
|
|
209
|
+
let supportedProperty;
|
|
210
|
+
if (node.type === "object" && node.children?.length) {
|
|
211
|
+
for (const child of node.children) {
|
|
212
|
+
if (child.type === "property" && child.children?.length) {
|
|
213
|
+
if (child.children[0].value === "default" && isNotEmptyString(child.children[1])) {
|
|
214
|
+
defaultProperty = child;
|
|
215
|
+
}
|
|
216
|
+
if (child.children[0].value === "supported") {
|
|
217
|
+
supportedProperty = child;
|
|
218
|
+
}
|
|
219
|
+
}
|
|
220
|
+
}
|
|
221
|
+
}
|
|
222
|
+
if (node.type !== "object" || supportedProperty && !defaultProperty) {
|
|
223
|
+
this.diagnostics.push({
|
|
224
|
+
description: import_diagnostics.descriptions.CONFIG_PARSER.INVALID_ENVIRONMENT(property),
|
|
225
|
+
location: this.getLocationFromNode(node)
|
|
226
|
+
});
|
|
227
|
+
}
|
|
228
|
+
}
|
|
229
|
+
assertIsBasePath(node, property) {
|
|
230
|
+
if (!node) {
|
|
231
|
+
return;
|
|
232
|
+
}
|
|
233
|
+
if (node.type !== "string") {
|
|
234
|
+
this.diagnostics.push({
|
|
235
|
+
description: import_diagnostics.descriptions.CONFIG_PARSER.INCORRECT_NODE_TYPE(property, "string", node.type),
|
|
236
|
+
location: this.getLocationFromNode(node)
|
|
237
|
+
});
|
|
238
|
+
} else if (node.value === "") {
|
|
239
|
+
return;
|
|
240
|
+
} else if (node.value.match(BASE_PATH_REGEX) === null) {
|
|
241
|
+
this.diagnostics.push({
|
|
242
|
+
description: import_diagnostics.descriptions.CONFIG_PARSER.INVALID_BASEPATH(property, node.value),
|
|
243
|
+
location: this.getLocationFromNode(node)
|
|
244
|
+
});
|
|
245
|
+
}
|
|
246
|
+
}
|
|
247
|
+
assertNotEmptyString(node, property) {
|
|
248
|
+
if (!node) {
|
|
249
|
+
return;
|
|
250
|
+
}
|
|
251
|
+
if (node.type !== "string") {
|
|
252
|
+
this.diagnostics.push({
|
|
253
|
+
description: import_diagnostics.descriptions.CONFIG_PARSER.INCORRECT_NODE_TYPE(property, "string", node.type),
|
|
254
|
+
location: this.getLocationFromNode(node)
|
|
255
|
+
});
|
|
256
|
+
} else if (!isNotEmptyString(node)) {
|
|
257
|
+
this.diagnostics.push({
|
|
258
|
+
description: import_diagnostics.descriptions.CONFIG_PARSER.NON_EMPTY_STRING(property, node.value),
|
|
259
|
+
location: this.getLocationFromNode(node)
|
|
260
|
+
});
|
|
261
|
+
}
|
|
262
|
+
}
|
|
263
|
+
assertNotEmptyArray(node, property) {
|
|
264
|
+
if (!node) {
|
|
265
|
+
return;
|
|
266
|
+
}
|
|
267
|
+
if (node.type !== "array") {
|
|
268
|
+
this.diagnostics.push({
|
|
269
|
+
description: import_diagnostics.descriptions.CONFIG_PARSER.INCORRECT_NODE_TYPE(property, "array", node.type),
|
|
270
|
+
location: this.getLocationFromNode(node)
|
|
271
|
+
});
|
|
272
|
+
} else if (!node.children || node.children.length === 0) {
|
|
273
|
+
this.diagnostics.push({
|
|
274
|
+
description: import_diagnostics.descriptions.CONFIG_PARSER.NON_EMPTY_ARRAY(property, "[]"),
|
|
275
|
+
location: this.getLocationFromNode(node)
|
|
276
|
+
});
|
|
277
|
+
}
|
|
278
|
+
}
|
|
279
|
+
assertHasOneOrMore(node, property, childProps) {
|
|
280
|
+
if (!childProps.some((p) => (0, import_jsonc_parser.findNodeAtLocation)(node, [p]) !== void 0)) {
|
|
281
|
+
this.diagnostics.push({
|
|
282
|
+
description: import_diagnostics.descriptions.CONFIG_PARSER.MISSING_ONE_OF(property, childProps),
|
|
283
|
+
location: this.getLocationFromNode(node)
|
|
284
|
+
});
|
|
285
|
+
}
|
|
286
|
+
}
|
|
287
|
+
assertHasOnlyOne(node, property, childProps) {
|
|
288
|
+
if (childProps.filter((p) => (0, import_jsonc_parser.findNodeAtLocation)(node, [p])).length !== 1) {
|
|
289
|
+
this.diagnostics.push({
|
|
290
|
+
description: import_diagnostics.descriptions.CONFIG_PARSER.TOO_MANY(property, childProps),
|
|
291
|
+
location: this.getLocationFromNode(node)
|
|
292
|
+
});
|
|
293
|
+
}
|
|
294
|
+
}
|
|
295
|
+
assertArrayOfStrings(node, property) {
|
|
296
|
+
if (!node) {
|
|
297
|
+
return;
|
|
298
|
+
}
|
|
299
|
+
if (node.type !== "array") {
|
|
300
|
+
this.diagnostics.push({
|
|
301
|
+
description: import_diagnostics.descriptions.CONFIG_PARSER.INCORRECT_NODE_TYPE(property, "array", node.type),
|
|
302
|
+
location: this.getLocationFromNode(node)
|
|
303
|
+
});
|
|
304
|
+
} else if (node.children && node.children.length > 0) {
|
|
305
|
+
node.children.forEach((n, index) => {
|
|
306
|
+
if (!isNotEmptyString(n)) {
|
|
307
|
+
this.diagnostics.push({
|
|
308
|
+
description: import_diagnostics.descriptions.CONFIG_PARSER.NON_EMPTY_STRING(`${property}[${index}]`, n.value),
|
|
309
|
+
location: this.getLocationFromNode(n)
|
|
310
|
+
});
|
|
311
|
+
}
|
|
312
|
+
});
|
|
313
|
+
}
|
|
314
|
+
}
|
|
315
|
+
assertArrayOfSpecifiers(node, property) {
|
|
316
|
+
if (!node) {
|
|
317
|
+
return;
|
|
318
|
+
}
|
|
319
|
+
if (node.type !== "array") {
|
|
320
|
+
this.diagnostics.push({
|
|
321
|
+
description: import_diagnostics.descriptions.CONFIG_PARSER.INCORRECT_NODE_TYPE(property, "array", node.type),
|
|
322
|
+
location: this.getLocationFromNode(node)
|
|
323
|
+
});
|
|
324
|
+
} else if (node.children && node.children.length > 0) {
|
|
325
|
+
node.children.forEach((n, index) => {
|
|
326
|
+
if (n.type !== "string" || !SPECIFIER_REGEX.test(n.value)) {
|
|
327
|
+
this.diagnostics.push({
|
|
328
|
+
description: import_diagnostics.descriptions.CONFIG_PARSER.INVALID_SPECIFIER(`${property}[${index}]`, n.value),
|
|
329
|
+
location: this.getLocationFromNode(n)
|
|
330
|
+
});
|
|
331
|
+
}
|
|
332
|
+
});
|
|
333
|
+
}
|
|
334
|
+
}
|
|
335
|
+
assertArrayOfServices(node, property) {
|
|
336
|
+
if (!node) {
|
|
337
|
+
return;
|
|
338
|
+
}
|
|
339
|
+
if (node.type !== "array") {
|
|
340
|
+
this.diagnostics.push({
|
|
341
|
+
description: import_diagnostics.descriptions.CONFIG_PARSER.INCORRECT_NODE_TYPE(property, "array", node.type),
|
|
342
|
+
location: this.getLocationFromNode(node)
|
|
343
|
+
});
|
|
344
|
+
} else if (node.children && node.children.length > 0) {
|
|
345
|
+
node.children.forEach((n, index) => {
|
|
346
|
+
if (n.type !== "string" && n.type !== "array") {
|
|
347
|
+
this.diagnostics.push({
|
|
348
|
+
description: import_diagnostics.descriptions.CONFIG_PARSER.INCORRECT_NODE_TYPE(`${property}[${index}]`, "string or array", n.type),
|
|
349
|
+
location: this.getLocationFromNode(n)
|
|
350
|
+
});
|
|
351
|
+
}
|
|
352
|
+
if (n.type === "string" && n.value.length === 0 || n.type === "array" && n.children && (n.children.length !== 2 || !isNotEmptyString(n.children[0]))) {
|
|
353
|
+
this.diagnostics.push({
|
|
354
|
+
description: import_diagnostics.descriptions.CONFIG_PARSER.INVALID_SERVICE(`${property}[${index}]`, n.value === void 0 && n.children ? `invalid Array[${n.children.length}]` : n.value),
|
|
355
|
+
location: this.getLocationFromNode(n)
|
|
356
|
+
});
|
|
357
|
+
}
|
|
358
|
+
});
|
|
359
|
+
}
|
|
360
|
+
}
|
|
361
|
+
assertUniqueIds(nodes, property) {
|
|
362
|
+
const ids = nodes.map((n) => {
|
|
363
|
+
const idNode = (0, import_jsonc_parser.findNodeAtLocation)(n, ["id"]);
|
|
364
|
+
return idNode ? idNode.value : void 0;
|
|
365
|
+
}).filter((id) => id !== void 0);
|
|
366
|
+
const dupeIds = ids.filter((id, index) => ids.indexOf(id) !== index);
|
|
367
|
+
if (dupeIds.length > 0) {
|
|
368
|
+
this.diagnostics.push({
|
|
369
|
+
description: import_diagnostics.descriptions.CONFIG_PARSER.DUPLICATE_IDS(property, dupeIds),
|
|
370
|
+
location: this.getLocationFromNode(nodes[0])
|
|
371
|
+
});
|
|
372
|
+
}
|
|
373
|
+
}
|
|
374
|
+
assertRequiredKeys(node, property, requiredPropertyKeys) {
|
|
375
|
+
const missingProps = requiredPropertyKeys.filter((p) => (0, import_jsonc_parser.findNodeAtLocation)(node, [p]) === void 0);
|
|
376
|
+
if (missingProps.length > 0) {
|
|
377
|
+
this.diagnostics.push({
|
|
378
|
+
description: import_diagnostics.descriptions.CONFIG_PARSER.MISSING_REQUIRED(property, missingProps),
|
|
379
|
+
location: this.getLocationFromNode(node)
|
|
380
|
+
});
|
|
381
|
+
}
|
|
382
|
+
}
|
|
383
|
+
assertValidKeys(node, property, validPropertyKeys) {
|
|
384
|
+
const {children} = node;
|
|
385
|
+
if (!children) {
|
|
386
|
+
this.diagnostics.push({
|
|
387
|
+
description: import_diagnostics.descriptions.CONFIG_PARSER.INVALID_EMPTY_NODE(property),
|
|
388
|
+
location: this.getLocationFromNode(node)
|
|
389
|
+
});
|
|
390
|
+
return;
|
|
391
|
+
} else {
|
|
392
|
+
for (const propertyNode of children) {
|
|
393
|
+
if (propertyNode.type === "property" && propertyNode.children) {
|
|
394
|
+
const [keyNode] = propertyNode.children;
|
|
395
|
+
const {type, value} = keyNode;
|
|
396
|
+
if (type === "string" && !validPropertyKeys.includes(value)) {
|
|
397
|
+
this.diagnostics.push({
|
|
398
|
+
description: import_diagnostics.descriptions.CONFIG_PARSER.INVALID_PROPERTY(property, value),
|
|
399
|
+
location: this.getLocationFromNode(keyNode)
|
|
400
|
+
});
|
|
401
|
+
}
|
|
402
|
+
}
|
|
403
|
+
}
|
|
404
|
+
}
|
|
405
|
+
}
|
|
406
|
+
};
|
|
@@ -0,0 +1,192 @@
|
|
|
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/config/src/validation/app-config.ts
|
|
25
|
+
__markAsModule(exports);
|
|
26
|
+
__export(exports, {
|
|
27
|
+
SOURCE_BY_PHASE: () => SOURCE_BY_PHASE,
|
|
28
|
+
validateLwrAppConfig: () => validateLwrAppConfig
|
|
29
|
+
});
|
|
30
|
+
var import_jsonc_parser = __toModule(require("jsonc-parser"));
|
|
31
|
+
var import_diagnostics = __toModule(require("@lwrjs/diagnostics"));
|
|
32
|
+
var import_app_config_context = __toModule(require("./app-config-context.cjs"));
|
|
33
|
+
var import_helpers = __toModule(require("./helpers.cjs"));
|
|
34
|
+
var SOURCE_BY_PHASE = {
|
|
35
|
+
file: "lwr.config.json",
|
|
36
|
+
pre: "argument passed to createServer",
|
|
37
|
+
post: "configuration hooks"
|
|
38
|
+
};
|
|
39
|
+
function validateBootstrap(node, validationContext, propPrefix) {
|
|
40
|
+
if (node) {
|
|
41
|
+
validationContext.assertIsObject(node, "bootstrap");
|
|
42
|
+
validationContext.assertValidKeys(node, "bootstrap", import_app_config_context.BOOTSTRAP_ATTRIBUTE_KEYS);
|
|
43
|
+
validationContext.assertArrayOfSpecifiers((0, import_jsonc_parser.findNodeAtLocation)(node, ["services"]), `${propPrefix}.services`);
|
|
44
|
+
validationContext.assertIsBoolean((0, import_jsonc_parser.findNodeAtLocation)(node, ["autoBoot"]), `${propPrefix}.autoBoot`);
|
|
45
|
+
validationContext.assertIsBoolean((0, import_jsonc_parser.findNodeAtLocation)(node, ["experimentalSSR"]), `${propPrefix}.experimentalSSR`);
|
|
46
|
+
validationContext.assertIsBoolean((0, import_jsonc_parser.findNodeAtLocation)(node, ["configAsSrc"]), `${propPrefix}.configAsSrc`);
|
|
47
|
+
validationContext.assertIsBoolean((0, import_jsonc_parser.findNodeAtLocation)(node, ["syntheticShadow"]), `${propPrefix}.syntheticShadow`);
|
|
48
|
+
const workers = (0, import_jsonc_parser.findNodeAtLocation)(node, ["workers"]);
|
|
49
|
+
if (workers && workers.children) {
|
|
50
|
+
workers.children.forEach((w, index) => {
|
|
51
|
+
if (w.children && w.children.length > 1) {
|
|
52
|
+
validationContext.assertIsSpecifier(w.children[1], `${propPrefix}.workers[${index}]`);
|
|
53
|
+
}
|
|
54
|
+
});
|
|
55
|
+
}
|
|
56
|
+
}
|
|
57
|
+
}
|
|
58
|
+
function validateRouteCommon(node, validationContext, propPrefix) {
|
|
59
|
+
validationContext.assertHasOneOrMore(node, propPrefix, [
|
|
60
|
+
"rootComponent",
|
|
61
|
+
"contentTemplate",
|
|
62
|
+
"routeHandler"
|
|
63
|
+
]);
|
|
64
|
+
validationContext.assertNotEmptyString((0, import_jsonc_parser.findNodeAtLocation)(node, ["id"]), `${propPrefix}.id`);
|
|
65
|
+
validationContext.assertIsSpecifier((0, import_jsonc_parser.findNodeAtLocation)(node, ["rootComponent"]), `${propPrefix}.rootComponent`);
|
|
66
|
+
validationContext.assertNotEmptyString((0, import_jsonc_parser.findNodeAtLocation)(node, ["contentTemplate"]), `${propPrefix}.contentTemplate`);
|
|
67
|
+
validationContext.assertNotEmptyString((0, import_jsonc_parser.findNodeAtLocation)(node, ["layoutTemplate"]), `${propPrefix}.layoutTemplate`);
|
|
68
|
+
validationContext.assertNotEmptyString((0, import_jsonc_parser.findNodeAtLocation)(node, ["routeHandler"]), `${propPrefix}.routeHandler`);
|
|
69
|
+
validateBootstrap((0, import_jsonc_parser.findNodeAtLocation)(node, ["bootstrap"]), validationContext, `${propPrefix}.bootstrap`);
|
|
70
|
+
}
|
|
71
|
+
function validateRoutes(node, validationContext) {
|
|
72
|
+
if (node) {
|
|
73
|
+
validationContext.assertNotEmptyArray(node, "routes");
|
|
74
|
+
if (node.children) {
|
|
75
|
+
node.children.forEach((n, index) => {
|
|
76
|
+
const propPrefix = `routes[${index}]`;
|
|
77
|
+
validationContext.assertIsObject(n, "routes");
|
|
78
|
+
validationContext.assertValidKeys(n, "routes", import_app_config_context.ROUTE_ATTRIBUTE_KEYS);
|
|
79
|
+
validationContext.assertRequiredKeys(n, propPrefix, ["id", "path"]);
|
|
80
|
+
validationContext.assertIsPath((0, import_jsonc_parser.findNodeAtLocation)(n, ["path"]), `${propPrefix}.path`);
|
|
81
|
+
validationContext.assertIsMethod((0, import_jsonc_parser.findNodeAtLocation)(n, ["method"]), `${propPrefix}.method`);
|
|
82
|
+
validateRouteCommon(n, validationContext, propPrefix);
|
|
83
|
+
});
|
|
84
|
+
}
|
|
85
|
+
}
|
|
86
|
+
}
|
|
87
|
+
function validateErrorRoutes(node, validationContext) {
|
|
88
|
+
if (node) {
|
|
89
|
+
validationContext.assertIsArray(node, "errorRoutes");
|
|
90
|
+
if (node.children) {
|
|
91
|
+
node.children.forEach((n, index) => {
|
|
92
|
+
const propPrefix = `errorRoutes[${index}]`;
|
|
93
|
+
validationContext.assertIsObject(n, "errorRoutes");
|
|
94
|
+
validationContext.assertValidKeys(n, "errorRoutes", import_app_config_context.ERROR_ROUTE_ATTRIBUTE_KEYS);
|
|
95
|
+
validationContext.assertRequiredKeys(n, propPrefix, ["id", "status"]);
|
|
96
|
+
validationContext.assertIsStatus((0, import_jsonc_parser.findNodeAtLocation)(n, ["status"]), `${propPrefix}.status`);
|
|
97
|
+
validateRouteCommon(n, validationContext, propPrefix);
|
|
98
|
+
});
|
|
99
|
+
}
|
|
100
|
+
}
|
|
101
|
+
}
|
|
102
|
+
function validateAssets(node, validationContext, preMerge) {
|
|
103
|
+
if (node) {
|
|
104
|
+
if (preMerge && node.type === "string") {
|
|
105
|
+
validationContext.assertNotEmptyString(node, "assets");
|
|
106
|
+
} else {
|
|
107
|
+
validationContext.assertNotEmptyArray(node, "assets");
|
|
108
|
+
if (node.children) {
|
|
109
|
+
node.children.forEach((n, index) => {
|
|
110
|
+
const dirNode = (0, import_jsonc_parser.findNodeAtLocation)(n, ["dir"]);
|
|
111
|
+
const fileNode = (0, import_jsonc_parser.findNodeAtLocation)(n, ["file"]);
|
|
112
|
+
if (dirNode?.type === "string") {
|
|
113
|
+
validationContext.assertIsObject(n, "assetDir");
|
|
114
|
+
validationContext.assertValidKeys(n, "assetDir", import_app_config_context.ASSET_DIR_ATTRIBUTE_KEYS);
|
|
115
|
+
} else if (fileNode?.type === "string") {
|
|
116
|
+
validationContext.assertIsObject(n, "assetFile");
|
|
117
|
+
validationContext.assertValidKeys(n, "assetFile", import_app_config_context.ASSET_FILE_ATTRIBUTE_KEYS);
|
|
118
|
+
}
|
|
119
|
+
validationContext.assertRequiredKeys(n, `assets[${index}]`, ["urlPath"]);
|
|
120
|
+
validationContext.assertHasOnlyOne(n, `assets[${index}]`, ["dir", "file"]);
|
|
121
|
+
validationContext.assertNotEmptyString(dirNode, `assets[${index}].dir`);
|
|
122
|
+
validationContext.assertNotEmptyString(fileNode, `assets[${index}].file`);
|
|
123
|
+
validationContext.assertIsPath((0, import_jsonc_parser.findNodeAtLocation)(n, ["urlPath"]), `assets[${index}].urlPath`);
|
|
124
|
+
validationContext.assertNotEmptyString((0, import_jsonc_parser.findNodeAtLocation)(n, ["alias"]), `assets[${index}].alias`);
|
|
125
|
+
});
|
|
126
|
+
}
|
|
127
|
+
}
|
|
128
|
+
}
|
|
129
|
+
}
|
|
130
|
+
function validateLocker(node, validationContext) {
|
|
131
|
+
if (node) {
|
|
132
|
+
validationContext.assertIsObject(node, "locker");
|
|
133
|
+
validationContext.assertValidKeys(node, "locker", import_app_config_context.LOCKER_ATTRIBUTE_KEYS);
|
|
134
|
+
validationContext.assertRequiredKeys(node, "locker", ["enabled"]);
|
|
135
|
+
validationContext.assertIsBoolean((0, import_jsonc_parser.findNodeAtLocation)(node, ["enabled"]), "locker.enabled");
|
|
136
|
+
validationContext.assertArrayOfStrings((0, import_jsonc_parser.findNodeAtLocation)(node, ["trustedComponents"]), "locker.trustedComponents");
|
|
137
|
+
}
|
|
138
|
+
}
|
|
139
|
+
function validateRoot(node, validationContext, preMerge) {
|
|
140
|
+
validationContext.assertIsObject(node, "root");
|
|
141
|
+
validationContext.assertValidKeys(node, "root", import_app_config_context.ROOT_ATTRIBUTE_KEYS);
|
|
142
|
+
!preMerge && validationContext.assertRequiredKeys(node, "root", import_app_config_context.ROOT_ATTRIBUTE_KEYS);
|
|
143
|
+
const routes = (0, import_jsonc_parser.findNodeAtLocation)(node, ["routes"]);
|
|
144
|
+
const errorRoutes = (0, import_jsonc_parser.findNodeAtLocation)(node, ["errorRoutes"]);
|
|
145
|
+
validationContext.assertUniqueIds([...routes?.children || [], ...errorRoutes?.children || []], "routes");
|
|
146
|
+
validateRoutes(routes, validationContext);
|
|
147
|
+
validateErrorRoutes(errorRoutes, validationContext);
|
|
148
|
+
validateAssets((0, import_jsonc_parser.findNodeAtLocation)(node, ["assets"]), validationContext, preMerge);
|
|
149
|
+
validateLocker((0, import_jsonc_parser.findNodeAtLocation)(node, ["locker"]), validationContext);
|
|
150
|
+
validationContext.assertNotEmptyString((0, import_jsonc_parser.findNodeAtLocation)(node, ["apiVersion"]), "apiVersion");
|
|
151
|
+
validationContext.assertNotEmptyString((0, import_jsonc_parser.findNodeAtLocation)(node, ["lwrVersion"]), "lwrVersion");
|
|
152
|
+
validationContext.assertIsSpecifier((0, import_jsonc_parser.findNodeAtLocation)(node, ["amdLoader"]), "amdLoader");
|
|
153
|
+
validationContext.assertIsSpecifier((0, import_jsonc_parser.findNodeAtLocation)(node, ["esmLoader"]), "esmLoader");
|
|
154
|
+
validationContext.assertIsPort((0, import_jsonc_parser.findNodeAtLocation)(node, ["port"]), "port");
|
|
155
|
+
validationContext.assertNotEmptyString((0, import_jsonc_parser.findNodeAtLocation)(node, ["serverMode"]), "serverMode");
|
|
156
|
+
validationContext.assertIsServerType((0, import_jsonc_parser.findNodeAtLocation)(node, ["serverType"]), "serverType");
|
|
157
|
+
validationContext.assertIsStaticSiteGenerator((0, import_jsonc_parser.findNodeAtLocation)(node, ["staticSiteGenerator"]), "staticSiteGenerator");
|
|
158
|
+
validationContext.assertNotEmptyString((0, import_jsonc_parser.findNodeAtLocation)(node, ["rootDir"]), "rootDir");
|
|
159
|
+
validationContext.assertNotEmptyString((0, import_jsonc_parser.findNodeAtLocation)(node, ["cacheDir"]), "cacheDir");
|
|
160
|
+
validationContext.assertNotEmptyString((0, import_jsonc_parser.findNodeAtLocation)(node, ["contentDir"]), "contentDir");
|
|
161
|
+
validationContext.assertNotEmptyString((0, import_jsonc_parser.findNodeAtLocation)(node, ["layoutsDir"]), "layoutsDir");
|
|
162
|
+
validationContext.assertNotEmptyString((0, import_jsonc_parser.findNodeAtLocation)(node, ["globalDataDir"]), "globalDataDir");
|
|
163
|
+
validationContext.assertArrayOfServices((0, import_jsonc_parser.findNodeAtLocation)(node, ["hooks"]), "hooks");
|
|
164
|
+
validationContext.assertNotEmptyString((0, import_jsonc_parser.findNodeAtLocation)(node, ["templateEngine"]), "templateEngine");
|
|
165
|
+
validationContext.assertArrayOfServices((0, import_jsonc_parser.findNodeAtLocation)(node, ["moduleProviders"]), "moduleProviders");
|
|
166
|
+
validationContext.assertArrayOfServices((0, import_jsonc_parser.findNodeAtLocation)(node, ["viewProviders"]), "viewProviders");
|
|
167
|
+
validationContext.assertArrayOfServices((0, import_jsonc_parser.findNodeAtLocation)(node, ["resourceProviders"]), "resourceProviders");
|
|
168
|
+
validationContext.assertArrayOfServices((0, import_jsonc_parser.findNodeAtLocation)(node, ["assetProviders"]), "assetProviders");
|
|
169
|
+
validationContext.assertNotEmptyArray((0, import_jsonc_parser.findNodeAtLocation)(node, ["lwc", "modules"]), "lwc.modules");
|
|
170
|
+
validationContext.assertIsEnvironment((0, import_jsonc_parser.findNodeAtLocation)(node, ["environment"]), "environment");
|
|
171
|
+
validationContext.assertIsBasePath((0, import_jsonc_parser.findNodeAtLocation)(node, ["basePath"]), "basePath");
|
|
172
|
+
}
|
|
173
|
+
function validateLwrAppConfig(jsonSourceText, phase) {
|
|
174
|
+
const errors = [];
|
|
175
|
+
const preMerge = phase !== "post";
|
|
176
|
+
const rootNode = (0, import_jsonc_parser.parseTree)(jsonSourceText, errors);
|
|
177
|
+
if (errors.length) {
|
|
178
|
+
const {error, length, offset} = errors[0];
|
|
179
|
+
const message = (0, import_jsonc_parser.printParseErrorCode)(error);
|
|
180
|
+
const sourceLocation = (0, import_helpers.calculatePositionFromSource)(jsonSourceText, {length, offset});
|
|
181
|
+
throw (0, import_diagnostics.createSingleDiagnosticError)({
|
|
182
|
+
location: sourceLocation,
|
|
183
|
+
description: import_diagnostics.descriptions.CONFIG_PARSER.INVALID_JSON(message)
|
|
184
|
+
}, import_diagnostics.LwrConfigValidationError);
|
|
185
|
+
}
|
|
186
|
+
const validationContext = new import_app_config_context.ValidationContext(jsonSourceText);
|
|
187
|
+
validateRoot(rootNode, validationContext, preMerge);
|
|
188
|
+
if (validationContext.diagnostics.length) {
|
|
189
|
+
throw new import_diagnostics.LwrConfigValidationError(`Configuration validation errors in ${SOURCE_BY_PHASE[phase]}`, validationContext.diagnostics);
|
|
190
|
+
}
|
|
191
|
+
return (0, import_jsonc_parser.parse)(jsonSourceText);
|
|
192
|
+
}
|
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
var __defProp = Object.defineProperty;
|
|
2
|
+
var __markAsModule = (target) => __defProp(target, "__esModule", {value: true});
|
|
3
|
+
var __export = (target, all) => {
|
|
4
|
+
for (var name in all)
|
|
5
|
+
__defProp(target, name, {get: all[name], enumerable: true});
|
|
6
|
+
};
|
|
7
|
+
|
|
8
|
+
// packages/@lwrjs/config/src/validation/helpers.ts
|
|
9
|
+
__markAsModule(exports);
|
|
10
|
+
__export(exports, {
|
|
11
|
+
calculatePositionFromSource: () => calculatePositionFromSource
|
|
12
|
+
});
|
|
13
|
+
function calculatePositionFromSource(source, partialPosition) {
|
|
14
|
+
const lines = source.split("\n");
|
|
15
|
+
const {offset, length} = partialPosition;
|
|
16
|
+
let countedChars = 0;
|
|
17
|
+
for (const [index, line] of lines.entries()) {
|
|
18
|
+
const newLength = countedChars + line.length;
|
|
19
|
+
if (newLength >= offset - 1) {
|
|
20
|
+
return {
|
|
21
|
+
start: {
|
|
22
|
+
line: index + 1,
|
|
23
|
+
column: offset - countedChars
|
|
24
|
+
},
|
|
25
|
+
end: {
|
|
26
|
+
line: index + 1,
|
|
27
|
+
column: offset - countedChars + length
|
|
28
|
+
}
|
|
29
|
+
};
|
|
30
|
+
}
|
|
31
|
+
countedChars = newLength + 1;
|
|
32
|
+
}
|
|
33
|
+
throw new Error("Unable to calculate position from source: Unreachable offset");
|
|
34
|
+
}
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
import { LwrGlobalConfig, NormalizedLwrGlobalConfig, ServerModeConfig } from '@lwrjs/types';
|
|
2
|
+
export declare function explodeMode(mode: string): ServerModeConfig;
|
|
3
|
+
/**
|
|
4
|
+
* Merge and normalize all LWR configurations.
|
|
5
|
+
*
|
|
6
|
+
* @remarks
|
|
7
|
+
* Configurations are merged in the following order:
|
|
8
|
+
* defaults -> optional config file (lwr.config.json) -> optional config arg
|
|
9
|
+
*
|
|
10
|
+
* @param config - optional config supplied separate from the config file
|
|
11
|
+
* @returns the merged and normalized LWR configuration
|
|
12
|
+
*/
|
|
13
|
+
export declare function normalizeConfig(config?: LwrGlobalConfig): NormalizedLwrGlobalConfig;
|
|
14
|
+
//# sourceMappingURL=env-config.d.ts.map
|