@lwrjs/core 0.11.0-alpha.3 → 0.11.0-alpha.6

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.
@@ -31,6 +31,7 @@ function createProviderContext(serverContext) {
31
31
  const {
32
32
  assets,
33
33
  cacheDir,
34
+ i18n,
34
35
  lwc: {modules = []},
35
36
  routes,
36
37
  errorRoutes,
@@ -67,6 +68,7 @@ function createProviderContext(serverContext) {
67
68
  config: (0, import_shared_utils.deepFreeze)({
68
69
  assets,
69
70
  cacheDir,
71
+ i18n,
70
72
  modules,
71
73
  routes,
72
74
  errorRoutes,
@@ -12,9 +12,9 @@ __export(exports, {
12
12
  });
13
13
  function localeMiddleware(app, context) {
14
14
  const {defaultLocale} = context.runtimeEnvironment;
15
- app.use(async (req, res, next) => {
15
+ app.use(async (req, _res, next) => {
16
16
  const langs = req.acceptsLanguages();
17
- req.locale = langs?.length > 0 ? langs[0] : defaultLocale;
17
+ req.locale = langs?.length > 0 && langs[0] != "*" ? langs[0] : defaultLocale;
18
18
  await next();
19
19
  });
20
20
  }
@@ -31,12 +31,6 @@ var import_router = __toModule(require("@lwrjs/router"));
31
31
  var import_shared_utils = __toModule(require("@lwrjs/shared-utils"));
32
32
  var import_error_handling = __toModule(require("./utils/error-handling.cjs"));
33
33
  var import_view_registry = __toModule(require("@lwrjs/view-registry"));
34
- var CANONICAL_VIEW_ROUTES = [
35
- `/:apiVersion/application/:format/l/:locale/ai/:appId`,
36
- `/:apiVersion/application/:format/l/:locale/e/:environment/ai/:appId`,
37
- `/:apiVersion/application/:format/ai/:appId`,
38
- `/:apiVersion/application/:format/e/:environment/ai/:appId`
39
- ];
40
34
  function createViewMiddleware(route, errorRoutes, context, viewHandler) {
41
35
  const errorRoute = errorRoutes.find((route2) => route2.status === 500);
42
36
  return async (req, res) => {
@@ -138,7 +132,7 @@ function createNotFoundMiddleware(errorRoutes, context, viewHandler) {
138
132
  }
139
133
  function viewMiddleware(app, context) {
140
134
  const {appConfig, viewRegistry, moduleRegistry, routeHandlers} = context;
141
- const {routes, errorRoutes} = appConfig;
135
+ const {i18n, routes, errorRoutes} = appConfig;
142
136
  const viewHandler = new import_view_registry.LwrViewHandler({viewRegistry, moduleRegistry, routeHandlers}, appConfig);
143
137
  for (const route of routes) {
144
138
  const paths = [route.path];
@@ -147,7 +141,14 @@ function viewMiddleware(app, context) {
147
141
  const prefix = route.path === "/" ? "" : route.path;
148
142
  subRoutes.routes.forEach((subRoute) => subRoute.uri !== route.path && paths.push(`${prefix}${subRoute.uri}`));
149
143
  }
150
- paths.forEach((routePath) => paths.push(...CANONICAL_VIEW_ROUTES.map((viewRoute) => viewRoute + routePath)));
144
+ if (i18n.uriPattern === "path-prefix") {
145
+ const supportedStr = i18n.locales.map((l) => l.id).join("|");
146
+ paths.forEach((routePath) => {
147
+ const localizedPath = `/:locale(${supportedStr})${routePath}`;
148
+ import_shared_utils.logger.debug(`[view-middleware] Add localized path ${localizedPath}`);
149
+ paths.push(localizedPath);
150
+ });
151
+ }
151
152
  app.get(paths, (0, import_error_handling.handleErrors)(createViewMiddleware(route, errorRoutes, context, viewHandler)));
152
153
  }
153
154
  app.get((0, import_shared_utils.getClientBootstrapConfigurationRoutes)(), (0, import_error_handling.handleErrors)(createConfigMiddleware(routes, context, viewHandler)));
@@ -1,7 +1,7 @@
1
1
  import { deepFreeze } from '@lwrjs/shared-utils';
2
2
  export function createProviderContext(serverContext) {
3
3
  // This is a subset of config to user-land code
4
- const { assets, cacheDir, lwc: { modules = [] }, routes, errorRoutes, rootDir, contentDir, layoutsDir, locker, amdLoader, esmLoader, environment, basePath, bundleConfig, } = serverContext.appConfig;
4
+ const { assets, cacheDir, i18n, lwc: { modules = [] }, routes, errorRoutes, rootDir, contentDir, layoutsDir, locker, amdLoader, esmLoader, environment, basePath, bundleConfig, } = serverContext.appConfig;
5
5
  const { onModuleDefinitionChange, onModuleSourceChange } = serverContext.appObserver;
6
6
  const { notifyModuleDefinitionChanged, notifyModuleSourceChanged, notifyViewSourceChanged, notifyAssetSourceChanged, } = serverContext.appEmitter;
7
7
  return {
@@ -20,6 +20,7 @@ export function createProviderContext(serverContext) {
20
20
  config: deepFreeze({
21
21
  assets,
22
22
  cacheDir,
23
+ i18n,
23
24
  modules,
24
25
  routes,
25
26
  errorRoutes,
@@ -1,8 +1,8 @@
1
1
  export function localeMiddleware(app, context) {
2
2
  const { defaultLocale } = context.runtimeEnvironment;
3
- app.use(async (req, res, next) => {
3
+ app.use(async (req, _res, next) => {
4
4
  const langs = req.acceptsLanguages();
5
- req.locale = langs?.length > 0 ? langs[0] : defaultLocale;
5
+ req.locale = langs?.length > 0 && langs[0] != '*' ? langs[0] : defaultLocale;
6
6
  // await is required when calling next to support koa
7
7
  await next();
8
8
  });
@@ -3,12 +3,6 @@ import { getClientRoutes } from '@lwrjs/router';
3
3
  import { decodeViewPath, extractRequestParams, getClientBootstrapConfigurationRoutes, logger, shortestTtl, } from '@lwrjs/shared-utils';
4
4
  import { handleErrors } from './utils/error-handling.js';
5
5
  import { LwrViewHandler } from '@lwrjs/view-registry';
6
- const CANONICAL_VIEW_ROUTES = [
7
- `/:apiVersion/application/:format/l/:locale/ai/:appId`,
8
- `/:apiVersion/application/:format/l/:locale/e/:environment/ai/:appId`,
9
- `/:apiVersion/application/:format/ai/:appId`,
10
- `/:apiVersion/application/:format/e/:environment/ai/:appId`,
11
- ];
12
6
  function createViewMiddleware(route, errorRoutes, context, viewHandler) {
13
7
  const errorRoute = errorRoutes.find((route) => route.status === 500);
14
8
  return async (req, res) => {
@@ -119,7 +113,7 @@ function createNotFoundMiddleware(errorRoutes, context, viewHandler) {
119
113
  }
120
114
  export function viewMiddleware(app, context) {
121
115
  const { appConfig, viewRegistry, moduleRegistry, routeHandlers } = context;
122
- const { routes, errorRoutes } = appConfig;
116
+ const { i18n, routes, errorRoutes } = appConfig;
123
117
  const viewHandler = new LwrViewHandler({ viewRegistry, moduleRegistry, routeHandlers }, appConfig);
124
118
  // create and attach middleware for each route
125
119
  for (const route of routes) {
@@ -129,7 +123,15 @@ export function viewMiddleware(app, context) {
129
123
  const prefix = route.path === '/' ? '' : route.path;
130
124
  subRoutes.routes.forEach((subRoute) => subRoute.uri !== route.path && paths.push(`${prefix}${subRoute.uri}`));
131
125
  }
132
- paths.forEach((routePath) => paths.push(...CANONICAL_VIEW_ROUTES.map((viewRoute) => viewRoute + routePath)));
126
+ // Add localized routes
127
+ if (i18n.uriPattern === 'path-prefix') {
128
+ const supportedStr = i18n.locales.map((l) => l.id).join('|');
129
+ paths.forEach((routePath) => {
130
+ const localizedPath = `/:locale(${supportedStr})${routePath}`;
131
+ logger.debug(`[view-middleware] Add localized path ${localizedPath}`);
132
+ paths.push(localizedPath);
133
+ });
134
+ }
133
135
  app.get(paths, handleErrors(createViewMiddleware(route, errorRoutes, context, viewHandler)));
134
136
  }
135
137
  // create and attach middleware for bootstrap configurations
package/package.json CHANGED
@@ -4,7 +4,7 @@
4
4
  "publishConfig": {
5
5
  "access": "public"
6
6
  },
7
- "version": "0.11.0-alpha.3",
7
+ "version": "0.11.0-alpha.6",
8
8
  "homepage": "https://developer.salesforce.com/docs/platform/lwr/overview",
9
9
  "repository": {
10
10
  "type": "git",
@@ -39,31 +39,31 @@
39
39
  "build": "tsc -b"
40
40
  },
41
41
  "dependencies": {
42
- "@lwrjs/app-service": "0.11.0-alpha.3",
43
- "@lwrjs/asset-registry": "0.11.0-alpha.3",
44
- "@lwrjs/asset-transformer": "0.11.0-alpha.3",
45
- "@lwrjs/base-view-provider": "0.11.0-alpha.3",
46
- "@lwrjs/base-view-transformer": "0.11.0-alpha.3",
47
- "@lwrjs/client-modules": "0.11.0-alpha.3",
48
- "@lwrjs/config": "0.11.0-alpha.3",
49
- "@lwrjs/diagnostics": "0.11.0-alpha.3",
50
- "@lwrjs/fs-asset-provider": "0.11.0-alpha.3",
51
- "@lwrjs/html-view-provider": "0.11.0-alpha.3",
52
- "@lwrjs/instrumentation": "0.11.0-alpha.3",
53
- "@lwrjs/loader": "0.11.0-alpha.3",
54
- "@lwrjs/lwc-module-provider": "0.11.0-alpha.3",
55
- "@lwrjs/markdown-view-provider": "0.11.0-alpha.3",
56
- "@lwrjs/module-bundler": "0.11.0-alpha.3",
57
- "@lwrjs/module-registry": "0.11.0-alpha.3",
58
- "@lwrjs/npm-module-provider": "0.11.0-alpha.3",
59
- "@lwrjs/nunjucks-view-provider": "0.11.0-alpha.3",
60
- "@lwrjs/o11y": "0.11.0-alpha.3",
61
- "@lwrjs/resource-registry": "0.11.0-alpha.3",
62
- "@lwrjs/router": "0.11.0-alpha.3",
63
- "@lwrjs/server": "0.11.0-alpha.3",
64
- "@lwrjs/shared-utils": "0.11.0-alpha.3",
65
- "@lwrjs/static": "0.11.0-alpha.3",
66
- "@lwrjs/view-registry": "0.11.0-alpha.3",
42
+ "@lwrjs/app-service": "0.11.0-alpha.6",
43
+ "@lwrjs/asset-registry": "0.11.0-alpha.6",
44
+ "@lwrjs/asset-transformer": "0.11.0-alpha.6",
45
+ "@lwrjs/base-view-provider": "0.11.0-alpha.6",
46
+ "@lwrjs/base-view-transformer": "0.11.0-alpha.6",
47
+ "@lwrjs/client-modules": "0.11.0-alpha.6",
48
+ "@lwrjs/config": "0.11.0-alpha.6",
49
+ "@lwrjs/diagnostics": "0.11.0-alpha.6",
50
+ "@lwrjs/fs-asset-provider": "0.11.0-alpha.6",
51
+ "@lwrjs/html-view-provider": "0.11.0-alpha.6",
52
+ "@lwrjs/instrumentation": "0.11.0-alpha.6",
53
+ "@lwrjs/loader": "0.11.0-alpha.6",
54
+ "@lwrjs/lwc-module-provider": "0.11.0-alpha.6",
55
+ "@lwrjs/markdown-view-provider": "0.11.0-alpha.6",
56
+ "@lwrjs/module-bundler": "0.11.0-alpha.6",
57
+ "@lwrjs/module-registry": "0.11.0-alpha.6",
58
+ "@lwrjs/npm-module-provider": "0.11.0-alpha.6",
59
+ "@lwrjs/nunjucks-view-provider": "0.11.0-alpha.6",
60
+ "@lwrjs/o11y": "0.11.0-alpha.6",
61
+ "@lwrjs/resource-registry": "0.11.0-alpha.6",
62
+ "@lwrjs/router": "0.11.0-alpha.6",
63
+ "@lwrjs/server": "0.11.0-alpha.6",
64
+ "@lwrjs/shared-utils": "0.11.0-alpha.6",
65
+ "@lwrjs/static": "0.11.0-alpha.6",
66
+ "@lwrjs/view-registry": "0.11.0-alpha.6",
67
67
  "chokidar": "^3.5.3",
68
68
  "esbuild": "^0.9.7",
69
69
  "fs-extra": "^11.1.1",
@@ -73,7 +73,7 @@
73
73
  "ws": "^8.8.1"
74
74
  },
75
75
  "devDependencies": {
76
- "@lwrjs/types": "0.11.0-alpha.3",
76
+ "@lwrjs/types": "0.11.0-alpha.6",
77
77
  "@types/ws": "^8.5.3"
78
78
  },
79
79
  "peerDependencies": {
@@ -85,5 +85,5 @@
85
85
  "volta": {
86
86
  "extends": "../../../package.json"
87
87
  },
88
- "gitHead": "720b7b5525f93c089f8d97bdef692927ad520d39"
88
+ "gitHead": "571d4bac5650765aa818bcb9d5ed752a8cf041af"
89
89
  }