@lwrjs/config 0.9.0-alpha.30 → 0.9.0-alpha.32
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 +10 -0
- package/build/cjs/global-config.cjs +50 -12
- package/build/cjs/hooks.cjs +7 -0
- package/build/cjs/modules.cjs +1 -5
- package/build/cjs/utils/merge.cjs +7 -1
- package/build/cjs/validation/app-config-context.cjs +1 -0
- package/build/cjs/validation/app-config.cjs +1 -0
- package/build/es/defaults.d.ts +3 -0
- package/build/es/defaults.js +8 -0
- package/build/es/global-config.d.ts +15 -0
- package/build/es/global-config.js +63 -5
- package/build/es/hooks.js +7 -0
- package/build/es/modules.js +1 -6
- package/build/es/utils/merge.js +6 -0
- package/build/es/validation/app-config-context.d.ts +1 -1
- package/build/es/validation/app-config-context.js +1 -0
- package/build/es/validation/app-config.js +2 -0
- package/package.json +5 -5
package/build/cjs/defaults.cjs
CHANGED
|
@@ -34,6 +34,8 @@ __export(exports, {
|
|
|
34
34
|
DEFAULT_ROOT_DIR: () => DEFAULT_ROOT_DIR,
|
|
35
35
|
DEFAULT_SERVICE_PACKAGE_NAME: () => DEFAULT_SERVICE_PACKAGE_NAME,
|
|
36
36
|
LWR_VERSION: () => LWR_VERSION,
|
|
37
|
+
SSR_MODULE_PROVIDER: () => SSR_MODULE_PROVIDER,
|
|
38
|
+
SSR_VIEW_TRANSFORM_PLUGIN: () => SSR_VIEW_TRANSFORM_PLUGIN,
|
|
37
39
|
getDefaultBundleConfig: () => getDefaultBundleConfig
|
|
38
40
|
});
|
|
39
41
|
var import_shared_utils = __toModule(require("@lwrjs/shared-utils"));
|
|
@@ -51,6 +53,7 @@ var DEFAULT_GENERATOR_CONFIG = {
|
|
|
51
53
|
locales: ["en-US"],
|
|
52
54
|
skipCleanOutputDir: false,
|
|
53
55
|
skipBaseDocumentGeneration: false,
|
|
56
|
+
_additionalModules: [],
|
|
54
57
|
_additionalRoutePaths: []
|
|
55
58
|
};
|
|
56
59
|
var DEFAULT_ROOT_DIR = process.cwd();
|
|
@@ -65,6 +68,7 @@ var DEFAULT_MODULE_PROVIDERS = [
|
|
|
65
68
|
"@lwrjs/lwc-module-provider",
|
|
66
69
|
"@lwrjs/npm-module-provider"
|
|
67
70
|
];
|
|
71
|
+
var SSR_MODULE_PROVIDER = "@lwrjs/lwc-ssr/moduleProvider";
|
|
68
72
|
var DEFAULT_RESOURCE_PROVIDERS = ["@lwrjs/loader"];
|
|
69
73
|
var DEFAULT_VIEW_PROVIDERS = [
|
|
70
74
|
"@lwrjs/nunjucks-view-provider",
|
|
@@ -72,7 +76,12 @@ var DEFAULT_VIEW_PROVIDERS = [
|
|
|
72
76
|
"@lwrjs/markdown-view-provider",
|
|
73
77
|
"@lwrjs/base-view-provider"
|
|
74
78
|
];
|
|
79
|
+
var DEFAULT_BUNDLE_PROVIDERS = [
|
|
80
|
+
"@lwrjs/module-bundler/amd-bundle-provider",
|
|
81
|
+
"@lwrjs/module-bundler/esm-bundle-provider"
|
|
82
|
+
];
|
|
75
83
|
var DEFAULT_VIEW_TRANSFORM_PLUGINS = ["@lwrjs/base-view-transformer"];
|
|
84
|
+
var SSR_VIEW_TRANSFORM_PLUGIN = "@lwrjs/lwc-ssr/viewTransformer";
|
|
76
85
|
var DEFAULT_ASSET_PROVIDERS = ["@lwrjs/fs-asset-provider"];
|
|
77
86
|
var DEFAULT_ASSET_TRANSFORM_PLUGINS = ["@lwrjs/asset-transformer"];
|
|
78
87
|
var DEFAULT_AMD_LOADER = "lwr/loader";
|
|
@@ -131,6 +140,7 @@ var DEFAULT_LWR_CONFIG = {
|
|
|
131
140
|
globalDataDir: DEFAULT_DATA_DIR,
|
|
132
141
|
globalData: {},
|
|
133
142
|
hooks: [],
|
|
143
|
+
bundleProviders: DEFAULT_BUNDLE_PROVIDERS,
|
|
134
144
|
moduleProviders: DEFAULT_MODULE_PROVIDERS,
|
|
135
145
|
resourceProviders: DEFAULT_RESOURCE_PROVIDERS,
|
|
136
146
|
viewProviders: DEFAULT_VIEW_PROVIDERS,
|
|
@@ -24,14 +24,18 @@ var __toModule = (module2) => {
|
|
|
24
24
|
// packages/@lwrjs/config/src/global-config.ts
|
|
25
25
|
__markAsModule(exports);
|
|
26
26
|
__export(exports, {
|
|
27
|
+
applySsrConfig: () => applySsrConfig,
|
|
28
|
+
applyStaticProviderConfig: () => applyStaticProviderConfig,
|
|
27
29
|
loadConfig: () => loadConfig,
|
|
28
30
|
resolveGlobalConfig: () => resolveGlobalConfig
|
|
29
31
|
});
|
|
30
32
|
var import_fs = __toModule(require("fs"));
|
|
31
33
|
var import_path = __toModule(require("path"));
|
|
34
|
+
var import_resolve = __toModule(require("resolve"));
|
|
32
35
|
var import_jsonc_parser = __toModule(require("jsonc-parser"));
|
|
33
36
|
var import_shared_utils = __toModule(require("@lwrjs/shared-utils"));
|
|
34
37
|
var import_defaults = __toModule(require("./defaults.cjs"));
|
|
38
|
+
var import_defaults2 = __toModule(require("./defaults.cjs"));
|
|
35
39
|
var import_app_config = __toModule(require("./validation/app-config.cjs"));
|
|
36
40
|
var import_assets = __toModule(require("./utils/assets.cjs"));
|
|
37
41
|
var import_services = __toModule(require("./utils/services.cjs"));
|
|
@@ -40,7 +44,7 @@ var import_merge = __toModule(require("./utils/merge.cjs"));
|
|
|
40
44
|
var import_lwc = __toModule(require("./utils/lwc.cjs"));
|
|
41
45
|
var import_runtime_config = __toModule(require("./runtime-config.cjs"));
|
|
42
46
|
var import_global_data = __toModule(require("./utils/global-data.cjs"));
|
|
43
|
-
function getLwrConfigFromFile(rootDir, lwrConfigPath =
|
|
47
|
+
function getLwrConfigFromFile(rootDir, lwrConfigPath = import_defaults2.DEFAULT_LWR_CONFIG_JSON) {
|
|
44
48
|
const resolvedLwrConfigPath = import_path.default.resolve((0, import_shared_utils.normalizeDirectory)(lwrConfigPath, rootDir));
|
|
45
49
|
if (!import_fs.default.existsSync(resolvedLwrConfigPath)) {
|
|
46
50
|
import_shared_utils.logger.warn(`LWR Config not found on "${resolvedLwrConfigPath}"`);
|
|
@@ -61,10 +65,10 @@ function mergeConfig(configArg) {
|
|
|
61
65
|
configArg = (0, import_merge.trimLwrConfig)(configArg);
|
|
62
66
|
(0, import_app_config.validateLwrAppConfig)(configArg, "pre");
|
|
63
67
|
}
|
|
64
|
-
const rootDir = import_path.default.resolve(configArg?.rootDir ||
|
|
68
|
+
const rootDir = import_path.default.resolve(configArg?.rootDir || import_defaults2.DEFAULT_ROOT_DIR);
|
|
65
69
|
const configFile = !configArg?.ignoreLwrConfigFile ? getLwrConfigFromFile(rootDir, configArg?.lwrConfigFile) : void 0;
|
|
66
70
|
return {
|
|
67
|
-
...
|
|
71
|
+
...import_defaults2.DEFAULT_LWR_CONFIG,
|
|
68
72
|
...configFile,
|
|
69
73
|
...configArg,
|
|
70
74
|
lwc: (0, import_merge.mergeLwcConfig)(configFile, configArg),
|
|
@@ -75,15 +79,16 @@ function mergeConfig(configArg) {
|
|
|
75
79
|
};
|
|
76
80
|
}
|
|
77
81
|
function normalizeConfig(config) {
|
|
78
|
-
const amdLoader = (0, import_shared_utils.getFeatureFlags)().LEGACY_LOADER ?
|
|
82
|
+
const amdLoader = (0, import_shared_utils.getFeatureFlags)().LEGACY_LOADER ? import_defaults2.DEFAULT_AMD_LOADER_LEGACY : import_defaults2.DEFAULT_AMD_LOADER;
|
|
79
83
|
return {
|
|
80
84
|
...config,
|
|
81
85
|
amdLoader,
|
|
82
|
-
esmLoader:
|
|
83
|
-
lwrVersion:
|
|
86
|
+
esmLoader: import_defaults2.DEFAULT_ESM_LOADER,
|
|
87
|
+
lwrVersion: import_defaults2.LWR_VERSION,
|
|
84
88
|
assets: (0, import_assets.normalizeAssets)(config.assets),
|
|
85
89
|
lwc: (0, import_lwc.normalizeLwcConfig)(config.lwc),
|
|
86
90
|
hooks: (0, import_services.normalizeServices)(config.hooks),
|
|
91
|
+
bundleProviders: (0, import_services.normalizeServices)(config.bundleProviders),
|
|
87
92
|
moduleProviders: (0, import_services.normalizeServices)(config.moduleProviders),
|
|
88
93
|
assetProviders: (0, import_services.normalizeServices)(config.assetProviders),
|
|
89
94
|
assetTransformers: (0, import_services.normalizeServices)(config.assetTransformers),
|
|
@@ -95,7 +100,7 @@ function normalizeConfig(config) {
|
|
|
95
100
|
};
|
|
96
101
|
}
|
|
97
102
|
function normalizeConfigPaths(config) {
|
|
98
|
-
const rootDir = config.rootDir ||
|
|
103
|
+
const rootDir = config.rootDir || import_defaults2.DEFAULT_ROOT_DIR;
|
|
99
104
|
const resourcePaths = {
|
|
100
105
|
rootDir,
|
|
101
106
|
assets: (0, import_assets.normalizeAssetPaths)(config.assets, rootDir),
|
|
@@ -124,15 +129,48 @@ function normalizeConfigPaths(config) {
|
|
|
124
129
|
routeHandlers: (0, import_routes.normalizeRouteHandlerPaths)(config.routeHandlers, resourcePaths)
|
|
125
130
|
};
|
|
126
131
|
}
|
|
132
|
+
function applySsrConfig(config) {
|
|
133
|
+
const hasSSR = config.routes.some((r) => r.bootstrap.ssr);
|
|
134
|
+
if (!hasSSR) {
|
|
135
|
+
return config;
|
|
136
|
+
}
|
|
137
|
+
try {
|
|
138
|
+
import_resolve.default.sync("@lwrjs/lwc-ssr/package.json");
|
|
139
|
+
} catch (e) {
|
|
140
|
+
throw new Error('The "@lwrjs/lwc-ssr" package must be installed when "bootstrap.ssr" is configured to true on any route.');
|
|
141
|
+
}
|
|
142
|
+
const hasSsrModuleProvider = config.moduleProviders.some(([m]) => m === import_defaults.SSR_MODULE_PROVIDER);
|
|
143
|
+
const hasSsrViewTransformer = config.viewTransformers.some(([v]) => v === import_defaults.SSR_VIEW_TRANSFORM_PLUGIN);
|
|
144
|
+
return {
|
|
145
|
+
...config,
|
|
146
|
+
moduleProviders: hasSsrModuleProvider ? config.moduleProviders : [[import_defaults.SSR_MODULE_PROVIDER, void 0], ...config.moduleProviders],
|
|
147
|
+
viewTransformers: hasSsrViewTransformer ? config.viewTransformers : [...config.viewTransformers, [import_defaults.SSR_VIEW_TRANSFORM_PLUGIN, void 0]]
|
|
148
|
+
};
|
|
149
|
+
}
|
|
150
|
+
function applyStaticProviderConfig(config) {
|
|
151
|
+
return {
|
|
152
|
+
...config,
|
|
153
|
+
resourceProviders: [["@lwrjs/lambda/mrt-static-resource-provider", {}]],
|
|
154
|
+
moduleProviders: [["@lwrjs/lambda/mrt-static-module-provider", void 0]],
|
|
155
|
+
assetProviders: [["@lwrjs/lambda/mrt-static-asset-provider", void 0]],
|
|
156
|
+
bundleProviders: [
|
|
157
|
+
["@lwrjs/lambda/mrt-static-bundle-provider", void 0],
|
|
158
|
+
["@lwrjs/module-bundler/amd-runtime-bundle-provider", void 0]
|
|
159
|
+
],
|
|
160
|
+
assetTransformers: []
|
|
161
|
+
};
|
|
162
|
+
}
|
|
127
163
|
function resolveGlobalConfig(configArg, options) {
|
|
128
|
-
const skipDirNormalization = options?.skipDirNormalization;
|
|
129
|
-
const skipCacheDirCreation = options?.skipDirNormalization;
|
|
130
164
|
const mergedConfig = mergeConfig(configArg);
|
|
131
|
-
|
|
132
|
-
if (
|
|
165
|
+
let normalizedConfig = normalizeConfig(mergedConfig);
|
|
166
|
+
if (options?.useStaticProviders) {
|
|
167
|
+
normalizedConfig = applyStaticProviderConfig(normalizedConfig);
|
|
168
|
+
}
|
|
169
|
+
normalizedConfig = applySsrConfig(normalizedConfig);
|
|
170
|
+
if (!options?.skipCacheDirCreation) {
|
|
133
171
|
createCacheFolder(normalizedConfig.cacheDir, normalizedConfig.rootDir);
|
|
134
172
|
}
|
|
135
|
-
if (skipDirNormalization) {
|
|
173
|
+
if (options?.skipDirNormalization) {
|
|
136
174
|
return normalizedConfig;
|
|
137
175
|
}
|
|
138
176
|
return normalizeConfigPaths(normalizedConfig);
|
package/build/cjs/hooks.cjs
CHANGED
|
@@ -29,6 +29,7 @@ __export(exports, {
|
|
|
29
29
|
});
|
|
30
30
|
var import_routes = __toModule(require("./utils/routes.cjs"));
|
|
31
31
|
var import_app_config = __toModule(require("./validation/app-config.cjs"));
|
|
32
|
+
var import_global_config = __toModule(require("./global-config.cjs"));
|
|
32
33
|
async function executeConfigHooks(hooks, globalConfig, runtimeEnvironment, globalData, skipValidate = false) {
|
|
33
34
|
if (!hooks.length) {
|
|
34
35
|
return;
|
|
@@ -41,6 +42,9 @@ async function executeConfigHooks(hooks, globalConfig, runtimeEnvironment, globa
|
|
|
41
42
|
}
|
|
42
43
|
globalConfig.routes = (0, import_routes.normalizeRoutes)(globalConfig.routes, globalConfig.routeHandlers);
|
|
43
44
|
globalConfig.errorRoutes = (0, import_routes.normalizeRoutes)(globalConfig.errorRoutes, globalConfig.routeHandlers);
|
|
45
|
+
const ssrConfig = (0, import_global_config.applySsrConfig)(globalConfig);
|
|
46
|
+
globalConfig.moduleProviders = ssrConfig.moduleProviders;
|
|
47
|
+
globalConfig.viewTransformers = ssrConfig.viewTransformers;
|
|
44
48
|
if (!skipValidate) {
|
|
45
49
|
(0, import_app_config.validateLwrAppConfig)(globalConfig, "post");
|
|
46
50
|
}
|
|
@@ -56,6 +60,9 @@ function executeStartHooks(hooks, globalConfig, skipValidate = false) {
|
|
|
56
60
|
hook.onStart(globalConfig.routes);
|
|
57
61
|
}
|
|
58
62
|
globalConfig.routes = (0, import_routes.normalizeRoutes)(globalConfig.routes, globalConfig.routeHandlers);
|
|
63
|
+
const ssrConfig = (0, import_global_config.applySsrConfig)(globalConfig);
|
|
64
|
+
globalConfig.moduleProviders = ssrConfig.moduleProviders;
|
|
65
|
+
globalConfig.viewTransformers = ssrConfig.viewTransformers;
|
|
59
66
|
if (!skipValidate) {
|
|
60
67
|
(0, import_app_config.validateLwrAppConfig)(globalConfig, "post");
|
|
61
68
|
}
|
package/build/cjs/modules.cjs
CHANGED
|
@@ -31,10 +31,6 @@ __export(exports, {
|
|
|
31
31
|
var import_path = __toModule(require("path"));
|
|
32
32
|
var import_shared_utils = __toModule(require("@lwrjs/shared-utils"));
|
|
33
33
|
var import_typescript = __toModule(require("@lwrjs/shared-utils/typescript"));
|
|
34
|
-
var BUNDLE_PROVIDERS = [
|
|
35
|
-
["@lwrjs/module-bundler/amd-bundle-provider", void 0],
|
|
36
|
-
["@lwrjs/module-bundler/esm-bundle-provider", void 0]
|
|
37
|
-
];
|
|
38
34
|
async function importModule(filepath, rootDir, cacheDir) {
|
|
39
35
|
let resolvedFilePath = (0, import_shared_utils.normalizeDirectory)(filepath, rootDir);
|
|
40
36
|
const resolvedCacheDir = (0, import_shared_utils.normalizeDirectory)(cacheDir, rootDir);
|
|
@@ -69,7 +65,7 @@ async function loadHooks(config) {
|
|
|
69
65
|
}
|
|
70
66
|
async function loadServices(config) {
|
|
71
67
|
const moduleProviders = await loadServiceEntries(config.moduleProviders, config.rootDir, config.cacheDir);
|
|
72
|
-
const bundleProviders = await loadServiceEntries(
|
|
68
|
+
const bundleProviders = await loadServiceEntries(config.bundleProviders, config.rootDir, config.cacheDir);
|
|
73
69
|
const assetProviders = await loadServiceEntries(config.assetProviders, config.rootDir, config.cacheDir);
|
|
74
70
|
const assetTransformers = await loadServiceEntries(config.assetTransformers, config.rootDir, config.cacheDir);
|
|
75
71
|
const resourceProviders = await loadServiceEntries(config.resourceProviders, config.rootDir, config.cacheDir);
|
|
@@ -82,9 +82,15 @@ function mergeLockerConfig(jsonConfig, config) {
|
|
|
82
82
|
};
|
|
83
83
|
}
|
|
84
84
|
function mergeStaticGenerationConfig(configFile, configArg) {
|
|
85
|
+
const fileAdditionalModules = configFile?.staticSiteGenerator?._additionalModules || [];
|
|
86
|
+
const argAdditionalModules = configArg?.staticSiteGenerator?._additionalModules || [];
|
|
87
|
+
const fileAdditionalPaths = configFile?.staticSiteGenerator?._additionalRoutePaths || [];
|
|
88
|
+
const argAdditionalPaths = configArg?.staticSiteGenerator?._additionalRoutePaths || [];
|
|
85
89
|
return {
|
|
86
90
|
...import_defaults.DEFAULT_GENERATOR_CONFIG,
|
|
87
91
|
...configFile?.staticSiteGenerator,
|
|
88
|
-
...configArg?.staticSiteGenerator
|
|
92
|
+
...configArg?.staticSiteGenerator,
|
|
93
|
+
_additionalModules: [...new Set([...fileAdditionalModules, ...argAdditionalModules])],
|
|
94
|
+
_additionalRoutePaths: [...new Set([...fileAdditionalPaths, ...argAdditionalPaths])]
|
|
89
95
|
};
|
|
90
96
|
}
|
|
@@ -171,6 +171,7 @@ function validateRoot(node, validationContext, preMerge) {
|
|
|
171
171
|
validationContext.assertNotEmptyString((0, import_jsonc_parser.findNodeAtLocation)(node, ["layoutsDir"]), "layoutsDir");
|
|
172
172
|
validationContext.assertNotEmptyString((0, import_jsonc_parser.findNodeAtLocation)(node, ["globalDataDir"]), "globalDataDir");
|
|
173
173
|
validationContext.assertArrayOfServices((0, import_jsonc_parser.findNodeAtLocation)(node, ["hooks"]), "hooks");
|
|
174
|
+
validationContext.assertArrayOfServices((0, import_jsonc_parser.findNodeAtLocation)(node, ["bundleProviders"]), "bundleProviders");
|
|
174
175
|
validationContext.assertArrayOfServices((0, import_jsonc_parser.findNodeAtLocation)(node, ["moduleProviders"]), "moduleProviders");
|
|
175
176
|
validationContext.assertArrayOfServices((0, import_jsonc_parser.findNodeAtLocation)(node, ["viewProviders"]), "viewProviders");
|
|
176
177
|
validationContext.assertArrayOfServices((0, import_jsonc_parser.findNodeAtLocation)(node, ["resourceProviders"]), "resourceProviders");
|
package/build/es/defaults.d.ts
CHANGED
|
@@ -6,9 +6,12 @@ export declare const DEFAULT_GENERATOR_CONFIG: {
|
|
|
6
6
|
locales: string[];
|
|
7
7
|
skipCleanOutputDir: boolean;
|
|
8
8
|
skipBaseDocumentGeneration: boolean;
|
|
9
|
+
_additionalModules: never[];
|
|
9
10
|
_additionalRoutePaths: never[];
|
|
10
11
|
};
|
|
11
12
|
export declare const DEFAULT_ROOT_DIR: string;
|
|
13
|
+
export declare const SSR_MODULE_PROVIDER = "@lwrjs/lwc-ssr/moduleProvider";
|
|
14
|
+
export declare const SSR_VIEW_TRANSFORM_PLUGIN = "@lwrjs/lwc-ssr/viewTransformer";
|
|
12
15
|
export declare const DEFAULT_AMD_LOADER = "lwr/loader";
|
|
13
16
|
export declare const DEFAULT_AMD_LOADER_LEGACY = "lwr/loaderLegacy";
|
|
14
17
|
export declare const DEFAULT_ESM_LOADER = "lwr/esmLoader";
|
package/build/es/defaults.js
CHANGED
|
@@ -13,6 +13,7 @@ export const DEFAULT_GENERATOR_CONFIG = {
|
|
|
13
13
|
locales: ['en-US'],
|
|
14
14
|
skipCleanOutputDir: false,
|
|
15
15
|
skipBaseDocumentGeneration: false,
|
|
16
|
+
_additionalModules: [],
|
|
16
17
|
_additionalRoutePaths: [],
|
|
17
18
|
};
|
|
18
19
|
// Directories
|
|
@@ -29,6 +30,7 @@ const DEFAULT_MODULE_PROVIDERS = [
|
|
|
29
30
|
'@lwrjs/lwc-module-provider',
|
|
30
31
|
'@lwrjs/npm-module-provider',
|
|
31
32
|
];
|
|
33
|
+
export const SSR_MODULE_PROVIDER = '@lwrjs/lwc-ssr/moduleProvider';
|
|
32
34
|
const DEFAULT_RESOURCE_PROVIDERS = ['@lwrjs/loader'];
|
|
33
35
|
const DEFAULT_VIEW_PROVIDERS = [
|
|
34
36
|
'@lwrjs/nunjucks-view-provider',
|
|
@@ -36,7 +38,12 @@ const DEFAULT_VIEW_PROVIDERS = [
|
|
|
36
38
|
'@lwrjs/markdown-view-provider',
|
|
37
39
|
'@lwrjs/base-view-provider',
|
|
38
40
|
];
|
|
41
|
+
const DEFAULT_BUNDLE_PROVIDERS = [
|
|
42
|
+
'@lwrjs/module-bundler/amd-bundle-provider',
|
|
43
|
+
'@lwrjs/module-bundler/esm-bundle-provider',
|
|
44
|
+
];
|
|
39
45
|
const DEFAULT_VIEW_TRANSFORM_PLUGINS = ['@lwrjs/base-view-transformer'];
|
|
46
|
+
export const SSR_VIEW_TRANSFORM_PLUGIN = '@lwrjs/lwc-ssr/viewTransformer';
|
|
40
47
|
const DEFAULT_ASSET_PROVIDERS = ['@lwrjs/fs-asset-provider'];
|
|
41
48
|
const DEFAULT_ASSET_TRANSFORM_PLUGINS = ['@lwrjs/asset-transformer'];
|
|
42
49
|
export const DEFAULT_AMD_LOADER = 'lwr/loader';
|
|
@@ -99,6 +106,7 @@ export const DEFAULT_LWR_CONFIG = {
|
|
|
99
106
|
globalDataDir: DEFAULT_DATA_DIR,
|
|
100
107
|
globalData: {},
|
|
101
108
|
hooks: [],
|
|
109
|
+
bundleProviders: DEFAULT_BUNDLE_PROVIDERS,
|
|
102
110
|
moduleProviders: DEFAULT_MODULE_PROVIDERS,
|
|
103
111
|
resourceProviders: DEFAULT_RESOURCE_PROVIDERS,
|
|
104
112
|
viewProviders: DEFAULT_VIEW_PROVIDERS,
|
|
@@ -2,12 +2,27 @@ import type { GlobalData, LwrGlobalConfig, NormalizedLwrGlobalConfig, RuntimeEnv
|
|
|
2
2
|
export interface ResolveConfigOptions {
|
|
3
3
|
skipDirNormalization?: boolean;
|
|
4
4
|
skipCacheDirCreation?: boolean;
|
|
5
|
+
useStaticProviders?: boolean;
|
|
5
6
|
}
|
|
6
7
|
export interface Configurations {
|
|
7
8
|
appConfig: NormalizedLwrGlobalConfig;
|
|
8
9
|
runtimeEnvironment: RuntimeEnvironment;
|
|
9
10
|
globalData: GlobalData;
|
|
10
11
|
}
|
|
12
|
+
/**
|
|
13
|
+
* Add the SSR module provider and view transformer, if any route has `ssr` turned on.
|
|
14
|
+
*
|
|
15
|
+
* @param {NormalizedLwrGlobalConfig} config - a normalized global config to check / mutate
|
|
16
|
+
* @returns {NormalizedLwrGlobalConfig} an SSR-enabled normalized global config, if needed
|
|
17
|
+
*/
|
|
18
|
+
export declare function applySsrConfig(config: NormalizedLwrGlobalConfig): NormalizedLwrGlobalConfig;
|
|
19
|
+
/**
|
|
20
|
+
* Apply Static Providers for MRT runtime (used exclusively by buildServer)
|
|
21
|
+
*
|
|
22
|
+
* @param {NormalizedLwrGlobalConfig} config - a normalized global config to check / mutate
|
|
23
|
+
* @returns {NormalizedLwrGlobalConfig} an SSR-enabled normalized global config, if needed
|
|
24
|
+
*/
|
|
25
|
+
export declare function applyStaticProviderConfig(config: NormalizedLwrGlobalConfig): NormalizedLwrGlobalConfig;
|
|
11
26
|
/**
|
|
12
27
|
* Load, merge, and normalize all of the config sources.
|
|
13
28
|
*
|
|
@@ -1,7 +1,9 @@
|
|
|
1
1
|
import fs from 'fs';
|
|
2
2
|
import path from 'path';
|
|
3
|
+
import resolve from 'resolve';
|
|
3
4
|
import { parse } from 'jsonc-parser';
|
|
4
5
|
import { readFile, normalizeDirectory, getFeatureFlags, logger, ASSETS_CACHE_DIR } from '@lwrjs/shared-utils';
|
|
6
|
+
import { SSR_MODULE_PROVIDER, SSR_VIEW_TRANSFORM_PLUGIN } from './defaults.js';
|
|
5
7
|
import { DEFAULT_AMD_LOADER, DEFAULT_AMD_LOADER_LEGACY, DEFAULT_ESM_LOADER, DEFAULT_LWR_CONFIG, DEFAULT_LWR_CONFIG_JSON, DEFAULT_ROOT_DIR, LWR_VERSION, } from './defaults.js';
|
|
6
8
|
import { validateLwrAppConfig } from './validation/app-config.js';
|
|
7
9
|
import { normalizeAssetPaths, normalizeAssets } from './utils/assets.js';
|
|
@@ -112,6 +114,7 @@ function normalizeConfig(config) {
|
|
|
112
114
|
lwc: normalizeLwcConfig(config.lwc),
|
|
113
115
|
// normalize all services
|
|
114
116
|
hooks: normalizeServices(config.hooks),
|
|
117
|
+
bundleProviders: normalizeServices(config.bundleProviders),
|
|
115
118
|
moduleProviders: normalizeServices(config.moduleProviders),
|
|
116
119
|
assetProviders: normalizeServices(config.assetProviders),
|
|
117
120
|
assetTransformers: normalizeServices(config.assetTransformers),
|
|
@@ -165,6 +168,57 @@ function normalizeConfigPaths(config) {
|
|
|
165
168
|
routeHandlers: normalizeRouteHandlerPaths(config.routeHandlers, resourcePaths),
|
|
166
169
|
};
|
|
167
170
|
}
|
|
171
|
+
/**
|
|
172
|
+
* Add the SSR module provider and view transformer, if any route has `ssr` turned on.
|
|
173
|
+
*
|
|
174
|
+
* @param {NormalizedLwrGlobalConfig} config - a normalized global config to check / mutate
|
|
175
|
+
* @returns {NormalizedLwrGlobalConfig} an SSR-enabled normalized global config, if needed
|
|
176
|
+
*/
|
|
177
|
+
export function applySsrConfig(config) {
|
|
178
|
+
// check if any route has SSR turned on
|
|
179
|
+
const hasSSR = config.routes.some((r) => r.bootstrap.ssr);
|
|
180
|
+
if (!hasSSR) {
|
|
181
|
+
return config;
|
|
182
|
+
}
|
|
183
|
+
// ensure LWR's SSR package has been installed
|
|
184
|
+
try {
|
|
185
|
+
resolve.sync('@lwrjs/lwc-ssr/package.json');
|
|
186
|
+
}
|
|
187
|
+
catch (e) {
|
|
188
|
+
throw new Error('The "@lwrjs/lwc-ssr" package must be installed when "bootstrap.ssr" is configured to true on any route.');
|
|
189
|
+
}
|
|
190
|
+
// add the SSR configuration, if it's not already there
|
|
191
|
+
const hasSsrModuleProvider = config.moduleProviders.some(([m]) => m === SSR_MODULE_PROVIDER);
|
|
192
|
+
const hasSsrViewTransformer = config.viewTransformers.some(([v]) => v === SSR_VIEW_TRANSFORM_PLUGIN);
|
|
193
|
+
return {
|
|
194
|
+
...config,
|
|
195
|
+
moduleProviders: hasSsrModuleProvider
|
|
196
|
+
? config.moduleProviders
|
|
197
|
+
: [[SSR_MODULE_PROVIDER, undefined], ...config.moduleProviders],
|
|
198
|
+
viewTransformers: hasSsrViewTransformer
|
|
199
|
+
? config.viewTransformers
|
|
200
|
+
: [...config.viewTransformers, [SSR_VIEW_TRANSFORM_PLUGIN, undefined]],
|
|
201
|
+
};
|
|
202
|
+
}
|
|
203
|
+
/**
|
|
204
|
+
* Apply Static Providers for MRT runtime (used exclusively by buildServer)
|
|
205
|
+
*
|
|
206
|
+
* @param {NormalizedLwrGlobalConfig} config - a normalized global config to check / mutate
|
|
207
|
+
* @returns {NormalizedLwrGlobalConfig} an SSR-enabled normalized global config, if needed
|
|
208
|
+
*/
|
|
209
|
+
export function applyStaticProviderConfig(config) {
|
|
210
|
+
return {
|
|
211
|
+
...config,
|
|
212
|
+
resourceProviders: [['@lwrjs/lambda/mrt-static-resource-provider', {}]],
|
|
213
|
+
moduleProviders: [['@lwrjs/lambda/mrt-static-module-provider', undefined]],
|
|
214
|
+
assetProviders: [['@lwrjs/lambda/mrt-static-asset-provider', undefined]],
|
|
215
|
+
bundleProviders: [
|
|
216
|
+
['@lwrjs/lambda/mrt-static-bundle-provider', undefined],
|
|
217
|
+
['@lwrjs/module-bundler/amd-runtime-bundle-provider', undefined],
|
|
218
|
+
],
|
|
219
|
+
assetTransformers: [],
|
|
220
|
+
};
|
|
221
|
+
}
|
|
168
222
|
/**
|
|
169
223
|
* Load, merge, and normalize all of the config sources.
|
|
170
224
|
*
|
|
@@ -181,16 +235,20 @@ function normalizeConfigPaths(config) {
|
|
|
181
235
|
* @returns {NormalizedLwrGlobalConfig} a normalized global config relative to the provided options
|
|
182
236
|
*/
|
|
183
237
|
export function resolveGlobalConfig(configArg, options) {
|
|
184
|
-
const skipDirNormalization = options?.skipDirNormalization;
|
|
185
|
-
const skipCacheDirCreation = options?.skipDirNormalization;
|
|
186
238
|
const mergedConfig = mergeConfig(configArg);
|
|
187
|
-
|
|
239
|
+
let normalizedConfig = normalizeConfig(mergedConfig);
|
|
240
|
+
// Add static providers if applicable
|
|
241
|
+
if (options?.useStaticProviders) {
|
|
242
|
+
normalizedConfig = applyStaticProviderConfig(normalizedConfig);
|
|
243
|
+
}
|
|
244
|
+
// Add SSR config if applicable
|
|
245
|
+
normalizedConfig = applySsrConfig(normalizedConfig);
|
|
188
246
|
// skip cache dir creation when the option is set
|
|
189
|
-
if (!skipCacheDirCreation) {
|
|
247
|
+
if (!options?.skipCacheDirCreation) {
|
|
190
248
|
createCacheFolder(normalizedConfig.cacheDir, normalizedConfig.rootDir);
|
|
191
249
|
}
|
|
192
250
|
// skip dir normalization when the option is set
|
|
193
|
-
if (skipDirNormalization) {
|
|
251
|
+
if (options?.skipDirNormalization) {
|
|
194
252
|
return normalizedConfig;
|
|
195
253
|
}
|
|
196
254
|
return normalizeConfigPaths(normalizedConfig);
|
package/build/es/hooks.js
CHANGED
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import { normalizeRoutes } from './utils/routes.js';
|
|
2
2
|
import { validateLwrAppConfig } from './validation/app-config.js';
|
|
3
|
+
import { applySsrConfig } from './global-config.js';
|
|
3
4
|
/**
|
|
4
5
|
* Run `initConfigs` hooks
|
|
5
6
|
*
|
|
@@ -27,6 +28,9 @@ export async function executeConfigHooks(hooks, globalConfig, runtimeEnvironment
|
|
|
27
28
|
}
|
|
28
29
|
globalConfig.routes = normalizeRoutes(globalConfig.routes, globalConfig.routeHandlers);
|
|
29
30
|
globalConfig.errorRoutes = normalizeRoutes(globalConfig.errorRoutes, globalConfig.routeHandlers);
|
|
31
|
+
const ssrConfig = applySsrConfig(globalConfig);
|
|
32
|
+
globalConfig.moduleProviders = ssrConfig.moduleProviders;
|
|
33
|
+
globalConfig.viewTransformers = ssrConfig.viewTransformers;
|
|
30
34
|
if (!skipValidate) {
|
|
31
35
|
validateLwrAppConfig(globalConfig, 'post');
|
|
32
36
|
}
|
|
@@ -56,6 +60,9 @@ export function executeStartHooks(hooks, globalConfig, skipValidate = false) {
|
|
|
56
60
|
hook.onStart(globalConfig.routes);
|
|
57
61
|
}
|
|
58
62
|
globalConfig.routes = normalizeRoutes(globalConfig.routes, globalConfig.routeHandlers);
|
|
63
|
+
const ssrConfig = applySsrConfig(globalConfig);
|
|
64
|
+
globalConfig.moduleProviders = ssrConfig.moduleProviders;
|
|
65
|
+
globalConfig.viewTransformers = ssrConfig.viewTransformers;
|
|
59
66
|
if (!skipValidate) {
|
|
60
67
|
validateLwrAppConfig(globalConfig, 'post');
|
|
61
68
|
}
|
package/build/es/modules.js
CHANGED
|
@@ -1,11 +1,6 @@
|
|
|
1
1
|
import path from 'path';
|
|
2
2
|
import { normalizeDirectory, resolveFileExtension } from '@lwrjs/shared-utils';
|
|
3
3
|
import { transpileTs } from '@lwrjs/shared-utils/typescript';
|
|
4
|
-
// Bundle Providers are not configurable
|
|
5
|
-
const BUNDLE_PROVIDERS = [
|
|
6
|
-
['@lwrjs/module-bundler/amd-bundle-provider', undefined],
|
|
7
|
-
['@lwrjs/module-bundler/esm-bundle-provider', undefined],
|
|
8
|
-
];
|
|
9
4
|
async function importModule(filepath, rootDir, cacheDir) {
|
|
10
5
|
// ensure paths are fully resolved before loading source
|
|
11
6
|
let resolvedFilePath = normalizeDirectory(filepath, rootDir);
|
|
@@ -60,7 +55,7 @@ export async function loadHooks(config) {
|
|
|
60
55
|
*/
|
|
61
56
|
export async function loadServices(config) {
|
|
62
57
|
const moduleProviders = await loadServiceEntries(config.moduleProviders, config.rootDir, config.cacheDir);
|
|
63
|
-
const bundleProviders = await loadServiceEntries(
|
|
58
|
+
const bundleProviders = await loadServiceEntries(config.bundleProviders, config.rootDir, config.cacheDir);
|
|
64
59
|
const assetProviders = await loadServiceEntries(config.assetProviders, config.rootDir, config.cacheDir);
|
|
65
60
|
const assetTransformers = await loadServiceEntries(config.assetTransformers, config.rootDir, config.cacheDir);
|
|
66
61
|
const resourceProviders = await loadServiceEntries(config.resourceProviders, config.rootDir, config.cacheDir);
|
package/build/es/utils/merge.js
CHANGED
|
@@ -62,10 +62,16 @@ export function mergeLockerConfig(jsonConfig, config) {
|
|
|
62
62
|
};
|
|
63
63
|
}
|
|
64
64
|
export function mergeStaticGenerationConfig(configFile, configArg) {
|
|
65
|
+
const fileAdditionalModules = configFile?.staticSiteGenerator?._additionalModules || [];
|
|
66
|
+
const argAdditionalModules = configArg?.staticSiteGenerator?._additionalModules || [];
|
|
67
|
+
const fileAdditionalPaths = configFile?.staticSiteGenerator?._additionalRoutePaths || [];
|
|
68
|
+
const argAdditionalPaths = configArg?.staticSiteGenerator?._additionalRoutePaths || [];
|
|
65
69
|
return {
|
|
66
70
|
...DEFAULT_GENERATOR_CONFIG,
|
|
67
71
|
...configFile?.staticSiteGenerator,
|
|
68
72
|
...configArg?.staticSiteGenerator,
|
|
73
|
+
_additionalModules: [...new Set([...fileAdditionalModules, ...argAdditionalModules])],
|
|
74
|
+
_additionalRoutePaths: [...new Set([...fileAdditionalPaths, ...argAdditionalPaths])],
|
|
69
75
|
};
|
|
70
76
|
}
|
|
71
77
|
//# sourceMappingURL=merge.js.map
|
|
@@ -16,7 +16,7 @@ interface ConfigMap {
|
|
|
16
16
|
bootstrap: NormalizedLwrAppBootstrapConfig;
|
|
17
17
|
locker: RequiredLwrLockerConfig;
|
|
18
18
|
}
|
|
19
|
-
export declare const ROOT_ATTRIBUTE_KEYS: ["amdLoader", "apiVersion", "assets", "assetProviders", "assetTransformers", "bundleConfig", "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"];
|
|
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
20
|
export declare const ASSET_DIR_ATTRIBUTE_KEYS: ["alias", "dir", "urlPath"];
|
|
21
21
|
export declare const ASSET_FILE_ATTRIBUTE_KEYS: ["alias", "file", "urlPath"];
|
|
22
22
|
export declare const LOCKER_ATTRIBUTE_KEYS: ["enabled", "trustedComponents", "clientOnly"];
|
|
@@ -188,6 +188,7 @@ function validateLocker(node, validationContext) {
|
|
|
188
188
|
* - serverType: string
|
|
189
189
|
* - rootDir, cacheDir, contentDir, layoutsDir, globalDataDir: strings
|
|
190
190
|
* - hooks: array of strings
|
|
191
|
+
* - bundleProviders: array of services
|
|
191
192
|
* - moduleProviders: array of services
|
|
192
193
|
* - viewProviders: array of services
|
|
193
194
|
* - resourceProviders: array of services
|
|
@@ -224,6 +225,7 @@ function validateRoot(node, validationContext, preMerge) {
|
|
|
224
225
|
validationContext.assertNotEmptyString(findNode(node, ['layoutsDir']), 'layoutsDir');
|
|
225
226
|
validationContext.assertNotEmptyString(findNode(node, ['globalDataDir']), 'globalDataDir');
|
|
226
227
|
validationContext.assertArrayOfServices(findNode(node, ['hooks']), 'hooks');
|
|
228
|
+
validationContext.assertArrayOfServices(findNode(node, ['bundleProviders']), 'bundleProviders');
|
|
227
229
|
validationContext.assertArrayOfServices(findNode(node, ['moduleProviders']), 'moduleProviders');
|
|
228
230
|
validationContext.assertArrayOfServices(findNode(node, ['viewProviders']), 'viewProviders');
|
|
229
231
|
validationContext.assertArrayOfServices(findNode(node, ['resourceProviders']), 'resourceProviders');
|
package/package.json
CHANGED
|
@@ -4,7 +4,7 @@
|
|
|
4
4
|
"publishConfig": {
|
|
5
5
|
"access": "public"
|
|
6
6
|
},
|
|
7
|
-
"version": "0.9.0-alpha.
|
|
7
|
+
"version": "0.9.0-alpha.32",
|
|
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.9.0-alpha.
|
|
40
|
-
"@lwrjs/shared-utils": "0.9.0-alpha.
|
|
39
|
+
"@lwrjs/diagnostics": "0.9.0-alpha.32",
|
|
40
|
+
"@lwrjs/shared-utils": "0.9.0-alpha.32",
|
|
41
41
|
"fs-extra": "^11.1.0",
|
|
42
42
|
"jsonc-parser": "^3.0.0"
|
|
43
43
|
},
|
|
44
44
|
"devDependencies": {
|
|
45
|
-
"@lwrjs/types": "0.9.0-alpha.
|
|
45
|
+
"@lwrjs/types": "0.9.0-alpha.32"
|
|
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": "50e1f36c99ce2cd1ea8f6f1a2d3cf3967ca45de5"
|
|
54
54
|
}
|