@lwrjs/tools 0.9.0-alpha.15 → 0.9.0-alpha.16
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.
|
@@ -1,9 +1,9 @@
|
|
|
1
1
|
import path from 'path';
|
|
2
|
-
import { loadConfig } from '@lwrjs/config';
|
|
3
|
-
import {
|
|
2
|
+
import { executeConfigHooks, loadConfig } from '@lwrjs/config';
|
|
3
|
+
import { loadHooks } from '@lwrjs/config/modules';
|
|
4
|
+
import { logger, normalizeDirectory } from '@lwrjs/shared-utils';
|
|
4
5
|
const services = [
|
|
5
6
|
'moduleProviders',
|
|
6
|
-
'bundleProviders',
|
|
7
7
|
'assetProviders',
|
|
8
8
|
'assetTransformers',
|
|
9
9
|
'viewProviders',
|
|
@@ -22,6 +22,24 @@ function processServices(kind, entries, rootDir) {
|
|
|
22
22
|
}
|
|
23
23
|
return output;
|
|
24
24
|
}
|
|
25
|
+
function processHooks(hooksConfig, hooks, rootDir) {
|
|
26
|
+
const output = {
|
|
27
|
+
imports: [],
|
|
28
|
+
entries: [],
|
|
29
|
+
};
|
|
30
|
+
for (const [index, [entry, config]] of hooksConfig.entries()) {
|
|
31
|
+
if (!hooks[index].onStart) {
|
|
32
|
+
continue;
|
|
33
|
+
}
|
|
34
|
+
if (hooks[index].initConfigs) {
|
|
35
|
+
logger.warn('Consider splitting `initConfigs` hooks to a file separate from `onStart`.');
|
|
36
|
+
}
|
|
37
|
+
const name = 'hook' + index;
|
|
38
|
+
output.imports.push(`import ${name} from '${normalizeDirectory(entry, rootDir)}';`);
|
|
39
|
+
output.entries.push([name, config]);
|
|
40
|
+
}
|
|
41
|
+
return output;
|
|
42
|
+
}
|
|
25
43
|
function processRoutes(routes, rootDir) {
|
|
26
44
|
const output = {
|
|
27
45
|
imports: [],
|
|
@@ -54,6 +72,13 @@ function printServices(config) {
|
|
|
54
72
|
})
|
|
55
73
|
.join(',')}}`;
|
|
56
74
|
}
|
|
75
|
+
function printHooks(hooks) {
|
|
76
|
+
return `[${hooks
|
|
77
|
+
.map(([ctor, config = {}]) => {
|
|
78
|
+
return `new ${ctor}(${JSON.stringify(config)})`;
|
|
79
|
+
})
|
|
80
|
+
.join(',')}]`;
|
|
81
|
+
}
|
|
57
82
|
function printRoutes(routes) {
|
|
58
83
|
return `[${routes
|
|
59
84
|
.map((route) => {
|
|
@@ -96,6 +121,11 @@ export default function buildLwrServer(config) {
|
|
|
96
121
|
const { appConfig, runtimeEnvironment, globalData } = await loadConfig(config, {
|
|
97
122
|
skipDirNormalization: true,
|
|
98
123
|
});
|
|
124
|
+
// apply config hooks at build time
|
|
125
|
+
const hooks = await loadHooks(appConfig);
|
|
126
|
+
if (hooks.length) {
|
|
127
|
+
await executeConfigHooks(hooks, appConfig, runtimeEnvironment, globalData);
|
|
128
|
+
}
|
|
99
129
|
const remoteAppConfig = {
|
|
100
130
|
...appConfig,
|
|
101
131
|
ignoreLwrConfigFile: true,
|
|
@@ -109,17 +139,20 @@ export default function buildLwrServer(config) {
|
|
|
109
139
|
serviceImports.push(...entries.imports);
|
|
110
140
|
serviceConfig[service] = entries.entries;
|
|
111
141
|
}
|
|
142
|
+
const hooksConfig = processHooks(appConfig.hooks, hooks, appConfig.rootDir);
|
|
112
143
|
const routesConfig = processRoutes(appConfig.routes, appConfig.rootDir);
|
|
113
144
|
const errorRoutesConfig = processRoutes(appConfig.errorRoutes, appConfig.rootDir);
|
|
114
145
|
return {
|
|
115
146
|
contents: [
|
|
116
147
|
...serviceImports,
|
|
148
|
+
...hooksConfig.imports,
|
|
117
149
|
...routesConfig.imports,
|
|
118
150
|
...errorRoutesConfig.imports,
|
|
119
151
|
`export const appConfig = ${JSON.stringify(remoteAppConfig)};`,
|
|
120
152
|
`export const runtimeEnvironment = ${JSON.stringify(runtimeEnvironment)};`,
|
|
121
153
|
`export const globalData = ${JSON.stringify(globalData)};`,
|
|
122
154
|
`export const services = ${printServices(serviceConfig)};`,
|
|
155
|
+
`export const hooks = ${printHooks(hooksConfig.entries)};`,
|
|
123
156
|
`export const routes = ${printRoutes(routesConfig.routes)};`,
|
|
124
157
|
`export const errorRoutes = ${printRoutes(errorRoutesConfig.routes)};`,
|
|
125
158
|
].join('\n'),
|
package/build/es/server-build.js
CHANGED
|
@@ -11,6 +11,8 @@ async function build(outputDir, config) {
|
|
|
11
11
|
await esbuild.build({
|
|
12
12
|
entryPoints: ['./lwr.entry.js'],
|
|
13
13
|
bundle: true,
|
|
14
|
+
// TODO default to minify and no source map. Enable a debug build mode to set these up
|
|
15
|
+
minify: true,
|
|
14
16
|
sourcemap: true,
|
|
15
17
|
format: 'cjs',
|
|
16
18
|
platform: 'node',
|
|
@@ -22,16 +24,16 @@ async function build(outputDir, config) {
|
|
|
22
24
|
'node:*',
|
|
23
25
|
// fsevents used by chokidar used by nunjucks
|
|
24
26
|
'fsevents',
|
|
25
|
-
// Used for express compression. Should be an optional dependency
|
|
27
|
+
// Used for express compression. Should be an optional dependency and should be omitted at runtime
|
|
26
28
|
'iltorb',
|
|
27
29
|
'shrink-ray-current',
|
|
28
|
-
// Work in progress to isolate
|
|
29
|
-
'esbuild*',
|
|
30
|
-
// Used in the NPM module provider. Once Static Module Bundler is done we should be able to remove this
|
|
31
|
-
'esinstall',
|
|
32
30
|
// Rollup resolves plugins in node_modules at runtime. More investigation needed.
|
|
33
31
|
'rollup',
|
|
34
32
|
'rollup-plugin-*',
|
|
33
|
+
// These dependencies are not needed to serve a basic generated site, but they are still excluded
|
|
34
|
+
// in case there is a need to add a custom module provider.
|
|
35
|
+
'esbuild*',
|
|
36
|
+
'esinstall',
|
|
35
37
|
// We can remove this once we have the module bundler working
|
|
36
38
|
'@lwrjs/loader',
|
|
37
39
|
],
|
|
@@ -65,12 +67,12 @@ export async function buildServer(configArg, options) {
|
|
|
65
67
|
function createEnvVarHeader() {
|
|
66
68
|
// Setup global environment variables
|
|
67
69
|
const currentFeatureFlags = getFeatureFlags();
|
|
68
|
-
let
|
|
70
|
+
let initFeatureFlagsString = '';
|
|
69
71
|
for (const [key, val] of Object.entries(currentFeatureFlags)) {
|
|
70
72
|
if (val) {
|
|
71
|
-
|
|
73
|
+
initFeatureFlagsString += `process.env.${key} = 'true';`;
|
|
72
74
|
}
|
|
73
75
|
}
|
|
74
|
-
return `globalThis.LWR_VERSION='${LWR_VERSION}';${
|
|
76
|
+
return `globalThis.LWR_VERSION='${LWR_VERSION}';${initFeatureFlagsString}`;
|
|
75
77
|
}
|
|
76
78
|
//# sourceMappingURL=server-build.js.map
|
package/package.json
CHANGED
|
@@ -4,15 +4,15 @@
|
|
|
4
4
|
"publishConfig": {
|
|
5
5
|
"access": "public"
|
|
6
6
|
},
|
|
7
|
-
"version": "0.9.0-alpha.
|
|
7
|
+
"version": "0.9.0-alpha.16",
|
|
8
8
|
"homepage": "https://developer.salesforce.com/docs/platform/lwr/overview",
|
|
9
9
|
"repository": {
|
|
10
10
|
"type": "git",
|
|
11
|
-
"url": "https://github.com/salesforce/lwr.git",
|
|
11
|
+
"url": "https://github.com/salesforce-experience-platform-emu/lwr.git",
|
|
12
12
|
"directory": "packages/@lwrjs/tools"
|
|
13
13
|
},
|
|
14
14
|
"bugs": {
|
|
15
|
-
"url": "https://github.com/salesforce/lwr/issues"
|
|
15
|
+
"url": "https://github.com/salesforce-experience-platform-emu/lwr/issues"
|
|
16
16
|
},
|
|
17
17
|
"type": "module",
|
|
18
18
|
"types": "build/es/index.d.ts",
|
|
@@ -32,11 +32,11 @@
|
|
|
32
32
|
"package.cjs"
|
|
33
33
|
],
|
|
34
34
|
"dependencies": {
|
|
35
|
-
"@lwrjs/core": "0.9.0-alpha.
|
|
35
|
+
"@lwrjs/core": "0.9.0-alpha.16",
|
|
36
36
|
"esbuild": "^0.17.4"
|
|
37
37
|
},
|
|
38
38
|
"devDependencies": {
|
|
39
|
-
"@lwrjs/types": "0.9.0-alpha.
|
|
39
|
+
"@lwrjs/types": "0.9.0-alpha.16"
|
|
40
40
|
},
|
|
41
41
|
"peerDependencies": {
|
|
42
42
|
"lwc": "2.x"
|
|
@@ -44,5 +44,5 @@
|
|
|
44
44
|
"engines": {
|
|
45
45
|
"node": ">=14.15.4 <19"
|
|
46
46
|
},
|
|
47
|
-
"gitHead": "
|
|
47
|
+
"gitHead": "03fe3982780e7c63b96ef0733b58529057db61fa"
|
|
48
48
|
}
|