@lwrjs/tools 0.9.0-alpha.16 → 0.9.0-alpha.18

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.
@@ -40,27 +40,17 @@ function processHooks(hooksConfig, hooks, rootDir) {
40
40
  }
41
41
  return output;
42
42
  }
43
- function processRoutes(routes, rootDir) {
43
+ function processRouteHandlers(routeHandlers, rootDir) {
44
44
  const output = {
45
45
  imports: [],
46
- routes: [],
46
+ routeHandlers: {},
47
47
  };
48
- const handlers = {};
49
- for (const route of routes) {
50
- if (!route.routeHandler) {
51
- output.routes.push(route);
52
- continue;
53
- }
54
- const handler = route.routeHandler;
55
- if (!handlers[handler]) {
56
- const name = `routeHandler${Object.keys(handlers).length}`;
57
- handlers[handler] = name;
58
- output.imports.push(`import ${name} from '${normalizeDirectory(handler, rootDir)}';`);
48
+ for (const [id, handlerPath] of Object.entries(routeHandlers)) {
49
+ if (!output.routeHandlers[id]) {
50
+ const name = `routeHandler${output.imports.length}`;
51
+ output.imports.push(`import ${name} from '${normalizeDirectory(handlerPath, rootDir)}';`);
52
+ output.routeHandlers[id] = name;
59
53
  }
60
- output.routes.push({
61
- ...route,
62
- routeHandler: handlers[handler],
63
- });
64
54
  }
65
55
  return output;
66
56
  }
@@ -79,19 +69,12 @@ function printHooks(hooks) {
79
69
  })
80
70
  .join(',')}]`;
81
71
  }
82
- function printRoutes(routes) {
83
- return `[${routes
84
- .map((route) => {
85
- return `{${Object.entries(route)
86
- .map(([key, value]) => {
87
- if (key !== 'routeHandler') {
88
- return `${key}: ${JSON.stringify(value)}`;
89
- }
90
- return `${key}: ${value}`;
91
- })
92
- .join(',')}}`;
72
+ function printRouteHandlers(routeHandlers) {
73
+ return `{${Object.entries(routeHandlers)
74
+ .map(([id, handler]) => {
75
+ return `'${id}': ${handler}`;
93
76
  })
94
- .join(',')}]`;
77
+ .join(',')}}`;
95
78
  }
96
79
  /**
97
80
  * Creates an esbuild plugin that generates a server build module
@@ -140,21 +123,18 @@ export default function buildLwrServer(config) {
140
123
  serviceConfig[service] = entries.entries;
141
124
  }
142
125
  const hooksConfig = processHooks(appConfig.hooks, hooks, appConfig.rootDir);
143
- const routesConfig = processRoutes(appConfig.routes, appConfig.rootDir);
144
- const errorRoutesConfig = processRoutes(appConfig.errorRoutes, appConfig.rootDir);
126
+ const routeHandlersConfig = processRouteHandlers(appConfig.routeHandlers, appConfig.rootDir);
145
127
  return {
146
128
  contents: [
147
129
  ...serviceImports,
148
130
  ...hooksConfig.imports,
149
- ...routesConfig.imports,
150
- ...errorRoutesConfig.imports,
131
+ ...routeHandlersConfig.imports,
151
132
  `export const appConfig = ${JSON.stringify(remoteAppConfig)};`,
152
133
  `export const runtimeEnvironment = ${JSON.stringify(runtimeEnvironment)};`,
153
134
  `export const globalData = ${JSON.stringify(globalData)};`,
154
135
  `export const services = ${printServices(serviceConfig)};`,
155
136
  `export const hooks = ${printHooks(hooksConfig.entries)};`,
156
- `export const routes = ${printRoutes(routesConfig.routes)};`,
157
- `export const errorRoutes = ${printRoutes(errorRoutesConfig.routes)};`,
137
+ `export const routeHandlers = ${printRouteHandlers(routeHandlersConfig.routeHandlers)};`,
158
138
  ].join('\n'),
159
139
  loader: 'ts',
160
140
  resolveDir: path.dirname(args.path),
package/package.json CHANGED
@@ -4,7 +4,7 @@
4
4
  "publishConfig": {
5
5
  "access": "public"
6
6
  },
7
- "version": "0.9.0-alpha.16",
7
+ "version": "0.9.0-alpha.18",
8
8
  "homepage": "https://developer.salesforce.com/docs/platform/lwr/overview",
9
9
  "repository": {
10
10
  "type": "git",
@@ -32,11 +32,11 @@
32
32
  "package.cjs"
33
33
  ],
34
34
  "dependencies": {
35
- "@lwrjs/core": "0.9.0-alpha.16",
35
+ "@lwrjs/core": "0.9.0-alpha.18",
36
36
  "esbuild": "^0.17.4"
37
37
  },
38
38
  "devDependencies": {
39
- "@lwrjs/types": "0.9.0-alpha.16"
39
+ "@lwrjs/types": "0.9.0-alpha.18"
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": "03fe3982780e7c63b96ef0733b58529057db61fa"
47
+ "gitHead": "0d612ec0c74c679ce422f7bbae9fae14134f7d9f"
48
48
  }