@lwrjs/tools 0.9.0-alpha.14 → 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,6 +1,7 @@
1
1
  import path from 'path';
2
- import { loadConfig } from '@lwrjs/config';
3
- import { normalizeDirectory } from '@lwrjs/shared-utils';
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
7
  'assetProviders',
@@ -21,6 +22,24 @@ function processServices(kind, entries, rootDir) {
21
22
  }
22
23
  return output;
23
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
+ }
24
43
  function processRoutes(routes, rootDir) {
25
44
  const output = {
26
45
  imports: [],
@@ -53,6 +72,13 @@ function printServices(config) {
53
72
  })
54
73
  .join(',')}}`;
55
74
  }
75
+ function printHooks(hooks) {
76
+ return `[${hooks
77
+ .map(([ctor, config = {}]) => {
78
+ return `new ${ctor}(${JSON.stringify(config)})`;
79
+ })
80
+ .join(',')}]`;
81
+ }
56
82
  function printRoutes(routes) {
57
83
  return `[${routes
58
84
  .map((route) => {
@@ -95,6 +121,11 @@ export default function buildLwrServer(config) {
95
121
  const { appConfig, runtimeEnvironment, globalData } = await loadConfig(config, {
96
122
  skipDirNormalization: true,
97
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
+ }
98
129
  const remoteAppConfig = {
99
130
  ...appConfig,
100
131
  ignoreLwrConfigFile: true,
@@ -108,17 +139,20 @@ export default function buildLwrServer(config) {
108
139
  serviceImports.push(...entries.imports);
109
140
  serviceConfig[service] = entries.entries;
110
141
  }
142
+ const hooksConfig = processHooks(appConfig.hooks, hooks, appConfig.rootDir);
111
143
  const routesConfig = processRoutes(appConfig.routes, appConfig.rootDir);
112
144
  const errorRoutesConfig = processRoutes(appConfig.errorRoutes, appConfig.rootDir);
113
145
  return {
114
146
  contents: [
115
147
  ...serviceImports,
148
+ ...hooksConfig.imports,
116
149
  ...routesConfig.imports,
117
150
  ...errorRoutesConfig.imports,
118
151
  `export const appConfig = ${JSON.stringify(remoteAppConfig)};`,
119
152
  `export const runtimeEnvironment = ${JSON.stringify(runtimeEnvironment)};`,
120
153
  `export const globalData = ${JSON.stringify(globalData)};`,
121
154
  `export const services = ${printServices(serviceConfig)};`,
155
+ `export const hooks = ${printHooks(hooksConfig.entries)};`,
122
156
  `export const routes = ${printRoutes(routesConfig.routes)};`,
123
157
  `export const errorRoutes = ${printRoutes(errorRoutesConfig.routes)};`,
124
158
  ].join('\n'),
@@ -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 ans should be omitted at runtime
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 initFatureFlagsString = '';
70
+ let initFeatureFlagsString = '';
69
71
  for (const [key, val] of Object.entries(currentFeatureFlags)) {
70
72
  if (val) {
71
- initFatureFlagsString += `process.env.${key} = 'true'`;
73
+ initFeatureFlagsString += `process.env.${key} = 'true';`;
72
74
  }
73
75
  }
74
- return `globalThis.LWR_VERSION='${LWR_VERSION}';${initFatureFlagsString}`;
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.14",
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.14",
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.14"
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": "64e0ba617151429da6e09f1a9686628f64183d25"
47
+ "gitHead": "03fe3982780e7c63b96ef0733b58529057db61fa"
48
48
  }