@lwrjs/core 0.9.0-alpha.12 → 0.9.0-alpha.13
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/context/provider.cjs +2 -1
- package/build/cjs/context/server.cjs +4 -1
- package/build/cjs/index.cjs +28 -23
- package/build/cjs/middleware/view-middleware.cjs +12 -16
- package/build/cjs/tools/plugins/build-server-plugin.cjs +137 -0
- package/build/cjs/{context/services.cjs → tools/plugins/generate-entry-plugin.cjs} +26 -21
- package/build/cjs/tools/server-build.cjs +15 -129
- package/build/cjs/tools/server-warmup.cjs +2 -9
- package/build/cjs/tools/static-generation.cjs +8 -11
- package/build/es/context/provider.js +1 -0
- package/build/es/context/server.js +4 -0
- package/build/es/index.js +36 -25
- package/build/es/middleware/view-middleware.d.ts +2 -2
- package/build/es/middleware/view-middleware.js +12 -16
- package/build/es/tools/plugins/build-server-plugin.d.ts +18 -0
- package/build/es/tools/plugins/build-server-plugin.js +132 -0
- package/build/es/tools/plugins/generate-entry-plugin.d.ts +11 -0
- package/build/es/tools/plugins/generate-entry-plugin.js +45 -0
- package/build/es/tools/server-build.d.ts +5 -6
- package/build/es/tools/server-build.js +22 -152
- package/build/es/tools/server-warmup.js +3 -10
- package/build/es/tools/static-generation.js +10 -12
- package/package.json +28 -27
- package/build/cjs/context/configurations.cjs +0 -82
- package/build/cjs/context/global-data.cjs +0 -54
- package/build/es/context/configurations.d.ts +0 -9
- package/build/es/context/configurations.js +0 -53
- package/build/es/context/global-data.d.ts +0 -3
- package/build/es/context/global-data.js +0 -29
- package/build/es/context/services.d.ts +0 -3
- package/build/es/context/services.js +0 -27
|
@@ -77,6 +77,7 @@ function createProviderContext(serverContext) {
|
|
|
77
77
|
esmLoader,
|
|
78
78
|
environment
|
|
79
79
|
}),
|
|
80
|
-
runtimeEnvironment: (0, import_shared_utils.deepFreeze)(serverContext.runtimeEnvironment)
|
|
80
|
+
runtimeEnvironment: (0, import_shared_utils.deepFreeze)(serverContext.runtimeEnvironment),
|
|
81
|
+
watcherFactory: serverContext.watcherFactory
|
|
81
82
|
};
|
|
82
83
|
}
|
|
@@ -33,6 +33,7 @@ var import_module_registry = __toModule(require("@lwrjs/module-registry"));
|
|
|
33
33
|
var import_resource_registry = __toModule(require("@lwrjs/resource-registry"));
|
|
34
34
|
var import_shared_utils = __toModule(require("@lwrjs/shared-utils"));
|
|
35
35
|
var import_view_registry = __toModule(require("@lwrjs/view-registry"));
|
|
36
|
+
var import_fs_watch = __toModule(require("@lwrjs/shared-utils/fs-watch"));
|
|
36
37
|
function createServerContext(appConfig, runtimeEnvironment, globalData) {
|
|
37
38
|
const appObserver = new import_shared_utils.LwrApplicationObserver();
|
|
38
39
|
const appEmitter = appObserver.createLwrEmitter();
|
|
@@ -60,6 +61,7 @@ function createServerContext(appConfig, runtimeEnvironment, globalData) {
|
|
|
60
61
|
globalData,
|
|
61
62
|
runtimeEnvironment
|
|
62
63
|
}, appConfig);
|
|
64
|
+
const watcherFactory = new import_fs_watch.WatcherFactoryImpl();
|
|
63
65
|
return {
|
|
64
66
|
compiler,
|
|
65
67
|
appObserver,
|
|
@@ -70,6 +72,7 @@ function createServerContext(appConfig, runtimeEnvironment, globalData) {
|
|
|
70
72
|
assetRegistry,
|
|
71
73
|
viewRegistry,
|
|
72
74
|
appConfig,
|
|
73
|
-
runtimeEnvironment
|
|
75
|
+
runtimeEnvironment,
|
|
76
|
+
watcherFactory
|
|
74
77
|
};
|
|
75
78
|
}
|
package/build/cjs/index.cjs
CHANGED
|
@@ -33,12 +33,10 @@ var import_shared_utils = __toModule(require("@lwrjs/shared-utils"));
|
|
|
33
33
|
var import_server = __toModule(require("@lwrjs/server"));
|
|
34
34
|
var import_diagnostics = __toModule(require("@lwrjs/diagnostics"));
|
|
35
35
|
var import_config = __toModule(require("@lwrjs/config"));
|
|
36
|
-
var import_services = __toModule(require("./context/services.cjs"));
|
|
37
|
-
var import_configurations = __toModule(require("./context/configurations.cjs"));
|
|
38
|
-
var import_provider = __toModule(require("./context/provider.cjs"));
|
|
39
|
-
var import_server2 = __toModule(require("./context/server.cjs"));
|
|
40
36
|
var import_static_generation = __toModule(require("./tools/static-generation.cjs"));
|
|
41
37
|
var import_server_warmup = __toModule(require("./tools/server-warmup.cjs"));
|
|
38
|
+
var import_server2 = __toModule(require("./context/server.cjs"));
|
|
39
|
+
var import_provider = __toModule(require("./context/provider.cjs"));
|
|
42
40
|
var import_locale_middleware = __toModule(require("./middleware/locale-middleware.cjs"));
|
|
43
41
|
var import_module_middleware = __toModule(require("./middleware/module-middleware.cjs"));
|
|
44
42
|
var import_bundle_middleware = __toModule(require("./middleware/bundle-middleware.cjs"));
|
|
@@ -48,7 +46,7 @@ var import_view_middleware = __toModule(require("./middleware/view-middleware.cj
|
|
|
48
46
|
var import_resource_middleware = __toModule(require("./middleware/resource-middleware.cjs"));
|
|
49
47
|
var import_hmr_middleware = __toModule(require("./middleware/hmr-middleware.cjs"));
|
|
50
48
|
var import_server_build = __toModule(require("./tools/server-build.cjs"));
|
|
51
|
-
function initMiddleware(app, server, serverContext) {
|
|
49
|
+
function initMiddleware(app, server, serverContext, routes, errorRoutes) {
|
|
52
50
|
app.useCompression();
|
|
53
51
|
(0, import_locale_middleware.localeMiddleware)(app, serverContext);
|
|
54
52
|
(0, import_module_middleware.moduleMiddleware)(app, serverContext);
|
|
@@ -56,28 +54,30 @@ function initMiddleware(app, server, serverContext) {
|
|
|
56
54
|
(0, import_mapping_middleware.mappingMiddleware)(app, serverContext);
|
|
57
55
|
(0, import_asset_middleware.assetMiddleware)(app, serverContext);
|
|
58
56
|
(0, import_resource_middleware.resourceMiddleware)(app, serverContext);
|
|
59
|
-
(0, import_view_middleware.viewMiddleware)(app, serverContext);
|
|
57
|
+
(0, import_view_middleware.viewMiddleware)(app, serverContext, routes, errorRoutes);
|
|
60
58
|
app.initRoutes();
|
|
61
59
|
if (serverContext.runtimeEnvironment.hmrEnabled) {
|
|
62
60
|
(0, import_hmr_middleware.hmrMiddleware)(server, serverContext);
|
|
63
61
|
}
|
|
64
62
|
}
|
|
65
|
-
|
|
66
|
-
|
|
63
|
+
function createServices(entries, providerContext) {
|
|
64
|
+
return entries.map(([ctor, providerConfig = {}]) => new ctor(providerConfig, providerContext));
|
|
65
|
+
}
|
|
66
|
+
async function initContext(appConfig, runtimeEnvironment, globalData, services) {
|
|
67
67
|
const serverContext = (0, import_server2.createServerContext)(appConfig, runtimeEnvironment, globalData);
|
|
68
68
|
const providerContext = (0, import_provider.createProviderContext)(serverContext);
|
|
69
69
|
const {moduleRegistry, resourceRegistry, viewRegistry, assetRegistry} = serverContext;
|
|
70
|
-
const moduleProviders =
|
|
70
|
+
const moduleProviders = createServices(services.moduleProviders, providerContext);
|
|
71
71
|
moduleRegistry.addModuleProviders(moduleProviders);
|
|
72
|
-
const resourceProviders = await (
|
|
72
|
+
const resourceProviders = await createServices(services.resourceProviders, providerContext);
|
|
73
73
|
resourceRegistry.addResourceProviders(resourceProviders);
|
|
74
|
-
const viewProviders = await (
|
|
75
|
-
const viewTransformers = await (
|
|
74
|
+
const viewProviders = await createServices(services.viewProviders, providerContext);
|
|
75
|
+
const viewTransformers = await createServices(services.viewTransformers, providerContext);
|
|
76
76
|
viewRegistry.addViewProviders(viewProviders);
|
|
77
77
|
viewRegistry.addViewTransformers(viewTransformers);
|
|
78
78
|
await viewRegistry.initializeViewProviders();
|
|
79
|
-
const assetProviders = await (
|
|
80
|
-
const assetTransformers = await (
|
|
79
|
+
const assetProviders = await createServices(services.assetProviders, providerContext);
|
|
80
|
+
const assetTransformers = await createServices(services.assetTransformers, providerContext);
|
|
81
81
|
assetRegistry.addAssetProviders(assetProviders);
|
|
82
82
|
assetRegistry.addAssetTransformers(assetTransformers);
|
|
83
83
|
return serverContext;
|
|
@@ -97,15 +97,20 @@ var LwrApp = class {
|
|
|
97
97
|
return this.config;
|
|
98
98
|
}
|
|
99
99
|
async init() {
|
|
100
|
-
if (
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
}
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
100
|
+
if (this.initialized) {
|
|
101
|
+
return;
|
|
102
|
+
}
|
|
103
|
+
this.initialized = true;
|
|
104
|
+
try {
|
|
105
|
+
const {appConfig, runtimeEnvironment, globalData} = await (0, import_config.loadConfig)(this.config);
|
|
106
|
+
const services = await (0, import_config.loadServices)(appConfig);
|
|
107
|
+
const {routes, errorRoutes} = await (0, import_config.loadRoutes)(appConfig);
|
|
108
|
+
const context = await initContext(appConfig, runtimeEnvironment, globalData, services);
|
|
109
|
+
initMiddleware(this.app, this.server, context, routes, errorRoutes);
|
|
110
|
+
this.config = appConfig;
|
|
111
|
+
} catch (e) {
|
|
112
|
+
this.initialized = false;
|
|
113
|
+
throw e;
|
|
109
114
|
}
|
|
110
115
|
}
|
|
111
116
|
async listen(callback) {
|
|
@@ -37,9 +37,8 @@ var CANONICAL_VIEW_ROUTES = [
|
|
|
37
37
|
`/:apiVersion/application/:format/ai/:appId`,
|
|
38
38
|
`/:apiVersion/application/:format/e/:environment/ai/:appId`
|
|
39
39
|
];
|
|
40
|
-
function createViewMiddleware(route, context, viewHandler) {
|
|
41
|
-
const
|
|
42
|
-
const errorRoute = appConfig.errorRoutes.find((route2) => route2.status === 500);
|
|
40
|
+
function createViewMiddleware(route, errorRoutes, context, viewHandler) {
|
|
41
|
+
const errorRoute = errorRoutes.find((route2) => route2.status === 500);
|
|
43
42
|
return async (req, res) => {
|
|
44
43
|
if (!req.validateEnvironmentRequest(context.appConfig)) {
|
|
45
44
|
res.status(400);
|
|
@@ -91,9 +90,7 @@ function createViewMiddleware(route, context, viewHandler) {
|
|
|
91
90
|
res.send(viewResponse.body);
|
|
92
91
|
};
|
|
93
92
|
}
|
|
94
|
-
function createConfigMiddleware(context, viewHandler) {
|
|
95
|
-
const {appConfig} = context;
|
|
96
|
-
const {routes} = appConfig;
|
|
93
|
+
function createConfigMiddleware(routes, context, viewHandler) {
|
|
97
94
|
return async (req, res) => {
|
|
98
95
|
const {runtimeEnvironment, runtimeParams} = req.getRuntimeContext(context.runtimeEnvironment);
|
|
99
96
|
const {appId, encodedViewPath} = req.params;
|
|
@@ -126,20 +123,19 @@ function createConfigMiddleware(context, viewHandler) {
|
|
|
126
123
|
res.send(viewResponse.body);
|
|
127
124
|
};
|
|
128
125
|
}
|
|
129
|
-
function createNotFoundMiddleware(context, viewHandler) {
|
|
130
|
-
const
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
return createViewMiddleware(errorRoute, context, viewHandler);
|
|
126
|
+
function createNotFoundMiddleware(errorRoutes, context, viewHandler) {
|
|
127
|
+
const notFoundRoute = errorRoutes.find((route) => route.status === 404);
|
|
128
|
+
if (notFoundRoute) {
|
|
129
|
+
return createViewMiddleware(notFoundRoute, errorRoutes, context, viewHandler);
|
|
134
130
|
}
|
|
135
131
|
return (req, res) => {
|
|
136
132
|
res.status(404).send(import_diagnostics.descriptions.UNRESOLVABLE.VIEW(req.originalUrl).message);
|
|
137
133
|
};
|
|
138
134
|
}
|
|
139
|
-
function viewMiddleware(app, context) {
|
|
135
|
+
function viewMiddleware(app, context, routes, errorRoutes) {
|
|
140
136
|
const {appConfig, viewRegistry, moduleRegistry} = context;
|
|
141
137
|
const viewHandler = new import_view_registry.LwrViewHandler({viewRegistry, moduleRegistry}, appConfig);
|
|
142
|
-
for (const route of
|
|
138
|
+
for (const route of routes) {
|
|
143
139
|
const paths = [route.path];
|
|
144
140
|
const subRoutes = route.subRoutes && (0, import_router.getClientRoutes)(route.subRoutes);
|
|
145
141
|
if (subRoutes) {
|
|
@@ -147,8 +143,8 @@ function viewMiddleware(app, context) {
|
|
|
147
143
|
subRoutes.routes.forEach((subRoute) => subRoute.uri !== route.path && paths.push(`${prefix}${subRoute.uri}`));
|
|
148
144
|
}
|
|
149
145
|
paths.forEach((routePath) => paths.push(...CANONICAL_VIEW_ROUTES.map((viewRoute) => viewRoute + routePath)));
|
|
150
|
-
app.get(paths, (0, import_error_handling.handleErrors)(createViewMiddleware(route, context, viewHandler)));
|
|
146
|
+
app.get(paths, (0, import_error_handling.handleErrors)(createViewMiddleware(route, errorRoutes, context, viewHandler)));
|
|
151
147
|
}
|
|
152
|
-
app.get((0, import_shared_utils.getClientBootstrapConfigurationRoutes)(), (0, import_error_handling.handleErrors)(createConfigMiddleware(context, viewHandler)));
|
|
153
|
-
app.get("/" + app.getRegexWildcard(), (0, import_error_handling.handleErrors)(createNotFoundMiddleware(context, viewHandler)));
|
|
148
|
+
app.get((0, import_shared_utils.getClientBootstrapConfigurationRoutes)(), (0, import_error_handling.handleErrors)(createConfigMiddleware(routes, context, viewHandler)));
|
|
149
|
+
app.get("/" + app.getRegexWildcard(), (0, import_error_handling.handleErrors)(createNotFoundMiddleware(errorRoutes, context, viewHandler)));
|
|
154
150
|
}
|
|
@@ -0,0 +1,137 @@
|
|
|
1
|
+
var __create = Object.create;
|
|
2
|
+
var __defProp = Object.defineProperty;
|
|
3
|
+
var __getProtoOf = Object.getPrototypeOf;
|
|
4
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
5
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
6
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
7
|
+
var __markAsModule = (target) => __defProp(target, "__esModule", {value: true});
|
|
8
|
+
var __export = (target, all) => {
|
|
9
|
+
for (var name in all)
|
|
10
|
+
__defProp(target, name, {get: all[name], enumerable: true});
|
|
11
|
+
};
|
|
12
|
+
var __exportStar = (target, module2, desc) => {
|
|
13
|
+
if (module2 && typeof module2 === "object" || typeof module2 === "function") {
|
|
14
|
+
for (let key of __getOwnPropNames(module2))
|
|
15
|
+
if (!__hasOwnProp.call(target, key) && key !== "default")
|
|
16
|
+
__defProp(target, key, {get: () => module2[key], enumerable: !(desc = __getOwnPropDesc(module2, key)) || desc.enumerable});
|
|
17
|
+
}
|
|
18
|
+
return target;
|
|
19
|
+
};
|
|
20
|
+
var __toModule = (module2) => {
|
|
21
|
+
return __exportStar(__markAsModule(__defProp(module2 != null ? __create(__getProtoOf(module2)) : {}, "default", module2 && module2.__esModule && "default" in module2 ? {get: () => module2.default, enumerable: true} : {value: module2, enumerable: true})), module2);
|
|
22
|
+
};
|
|
23
|
+
|
|
24
|
+
// packages/@lwrjs/core/src/tools/plugins/build-server-plugin.ts
|
|
25
|
+
__markAsModule(exports);
|
|
26
|
+
__export(exports, {
|
|
27
|
+
default: () => buildLwrServer
|
|
28
|
+
});
|
|
29
|
+
var import_path = __toModule(require("path"));
|
|
30
|
+
var import_config = __toModule(require("@lwrjs/config"));
|
|
31
|
+
var import_shared_utils = __toModule(require("@lwrjs/shared-utils"));
|
|
32
|
+
var services = [
|
|
33
|
+
"moduleProviders",
|
|
34
|
+
"assetProviders",
|
|
35
|
+
"assetTransformers",
|
|
36
|
+
"viewProviders",
|
|
37
|
+
"viewTransformers",
|
|
38
|
+
"resourceProviders"
|
|
39
|
+
];
|
|
40
|
+
function processServices(kind, entries, rootDir) {
|
|
41
|
+
const output = {
|
|
42
|
+
imports: [],
|
|
43
|
+
entries: []
|
|
44
|
+
};
|
|
45
|
+
for (const [index, [entry, config]] of entries.entries()) {
|
|
46
|
+
const name = kind + index;
|
|
47
|
+
output.imports.push(`import ${name} from '${(0, import_shared_utils.normalizeDirectory)(entry, rootDir)}';`);
|
|
48
|
+
output.entries.push([name, config]);
|
|
49
|
+
}
|
|
50
|
+
return output;
|
|
51
|
+
}
|
|
52
|
+
function processRoutes(routes, rootDir) {
|
|
53
|
+
const output = {
|
|
54
|
+
imports: [],
|
|
55
|
+
routes: []
|
|
56
|
+
};
|
|
57
|
+
const handlers = {};
|
|
58
|
+
for (const route of routes) {
|
|
59
|
+
if (!route.routeHandler) {
|
|
60
|
+
output.routes.push(route);
|
|
61
|
+
continue;
|
|
62
|
+
}
|
|
63
|
+
const handler = route.routeHandler;
|
|
64
|
+
if (!handlers[handler]) {
|
|
65
|
+
const name = `routeHandler${Object.keys(handlers).length}`;
|
|
66
|
+
handlers[handler] = name;
|
|
67
|
+
output.imports.push(`import ${name} from '${(0, import_shared_utils.normalizeDirectory)(handler, rootDir)}';`);
|
|
68
|
+
}
|
|
69
|
+
output.routes.push({
|
|
70
|
+
...route,
|
|
71
|
+
routeHandler: handlers[handler]
|
|
72
|
+
});
|
|
73
|
+
}
|
|
74
|
+
return output;
|
|
75
|
+
}
|
|
76
|
+
function printServices(config) {
|
|
77
|
+
return `{${Object.entries(config).map(([key, value]) => {
|
|
78
|
+
const entries = value;
|
|
79
|
+
return `${key}: [${entries.map(([ctor, config2 = {}]) => `[${ctor}, ${JSON.stringify(config2)}]`)}]`;
|
|
80
|
+
}).join(",")}}`;
|
|
81
|
+
}
|
|
82
|
+
function printRoutes(routes) {
|
|
83
|
+
return `[${routes.map((route) => {
|
|
84
|
+
return `{${Object.entries(route).map(([key, value]) => {
|
|
85
|
+
if (key !== "routeHandler") {
|
|
86
|
+
return `${key}: ${JSON.stringify(value)}`;
|
|
87
|
+
}
|
|
88
|
+
return `${key}: ${value}`;
|
|
89
|
+
}).join(",")}}`;
|
|
90
|
+
}).join(",")}]`;
|
|
91
|
+
}
|
|
92
|
+
function buildLwrServer(config) {
|
|
93
|
+
return {
|
|
94
|
+
name: "lwr-server-build",
|
|
95
|
+
setup(build) {
|
|
96
|
+
build.onResolve({filter: /.*\/lwr.build.js$/}, (args) => ({
|
|
97
|
+
path: args.path,
|
|
98
|
+
namespace: "lwr-server-build"
|
|
99
|
+
}));
|
|
100
|
+
build.onLoad({filter: /.*/, namespace: "lwr-server-build"}, async (args) => {
|
|
101
|
+
const {appConfig, runtimeEnvironment, globalData} = await (0, import_config.loadConfig)(config, {
|
|
102
|
+
skipDirNormalization: true
|
|
103
|
+
});
|
|
104
|
+
const remoteAppConfig = {
|
|
105
|
+
...appConfig,
|
|
106
|
+
ignoreLwrConfigFile: true,
|
|
107
|
+
rootDir: void 0,
|
|
108
|
+
port: void 0
|
|
109
|
+
};
|
|
110
|
+
const serviceImports = [];
|
|
111
|
+
const serviceConfig = {};
|
|
112
|
+
for (const service of services) {
|
|
113
|
+
const entries = processServices(service, appConfig[service], appConfig.rootDir);
|
|
114
|
+
serviceImports.push(...entries.imports);
|
|
115
|
+
serviceConfig[service] = entries.entries;
|
|
116
|
+
}
|
|
117
|
+
const routesConfig = processRoutes(appConfig.routes, appConfig.rootDir);
|
|
118
|
+
const errorRoutesConfig = processRoutes(appConfig.errorRoutes, appConfig.rootDir);
|
|
119
|
+
return {
|
|
120
|
+
contents: [
|
|
121
|
+
...serviceImports,
|
|
122
|
+
...routesConfig.imports,
|
|
123
|
+
...errorRoutesConfig.imports,
|
|
124
|
+
`export const appConfig = ${JSON.stringify(remoteAppConfig)};`,
|
|
125
|
+
`export const runtimeEnvironment = ${JSON.stringify(runtimeEnvironment)};`,
|
|
126
|
+
`export const globalData = ${JSON.stringify(globalData)};`,
|
|
127
|
+
`export const services = ${printServices(serviceConfig)};`,
|
|
128
|
+
`export const routes = ${printRoutes(routesConfig.routes)};`,
|
|
129
|
+
`export const errorRoutes = ${printRoutes(errorRoutesConfig.routes)};`
|
|
130
|
+
].join("\n"),
|
|
131
|
+
loader: "ts",
|
|
132
|
+
resolveDir: import_path.default.dirname(args.path)
|
|
133
|
+
};
|
|
134
|
+
});
|
|
135
|
+
}
|
|
136
|
+
};
|
|
137
|
+
}
|
|
@@ -21,30 +21,35 @@ var __toModule = (module2) => {
|
|
|
21
21
|
return __exportStar(__markAsModule(__defProp(module2 != null ? __create(__getProtoOf(module2)) : {}, "default", module2 && module2.__esModule && "default" in module2 ? {get: () => module2.default, enumerable: true} : {value: module2, enumerable: true})), module2);
|
|
22
22
|
};
|
|
23
23
|
|
|
24
|
-
// packages/@lwrjs/core/src/
|
|
24
|
+
// packages/@lwrjs/core/src/tools/plugins/generate-entry-plugin.ts
|
|
25
25
|
__markAsModule(exports);
|
|
26
26
|
__export(exports, {
|
|
27
|
-
|
|
27
|
+
default: () => generateLwrEntry
|
|
28
28
|
});
|
|
29
29
|
var import_path = __toModule(require("path"));
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
30
|
+
function generateLwrEntry() {
|
|
31
|
+
return {
|
|
32
|
+
name: "lwr-entry",
|
|
33
|
+
setup(build) {
|
|
34
|
+
build.onResolve({filter: /.*\/lwr.entry.js$/}, ({kind, path: path2}) => {
|
|
35
|
+
if (kind === "entry-point") {
|
|
36
|
+
return {
|
|
37
|
+
path: path2,
|
|
38
|
+
namespace: "lwr-entry"
|
|
39
|
+
};
|
|
40
|
+
}
|
|
41
|
+
});
|
|
42
|
+
build.onLoad({filter: /.*/, namespace: "lwr-entry"}, (args) => ({
|
|
43
|
+
contents: [
|
|
44
|
+
`/* This module is generated */`,
|
|
45
|
+
`import { createHandler } from '@lwrjs/lambda';`,
|
|
46
|
+
`import * as build from './lwr.build.js';`,
|
|
47
|
+
`const handler = createHandler(build);`,
|
|
48
|
+
`export { handler as get };`
|
|
49
|
+
].join("\n"),
|
|
50
|
+
loader: "ts",
|
|
51
|
+
resolveDir: import_path.default.dirname(args.path)
|
|
52
|
+
}));
|
|
36
53
|
}
|
|
37
|
-
|
|
38
|
-
return moduleEntry.default || moduleEntry;
|
|
39
|
-
} catch (err) {
|
|
40
|
-
console.log(err);
|
|
41
|
-
throw new Error(`Unable to get Service: ${path}`);
|
|
42
|
-
}
|
|
43
|
-
}
|
|
44
|
-
async function getServices(services, providerContext, lwrConfig) {
|
|
45
|
-
return Promise.all(services.map(async (serviceEntry) => {
|
|
46
|
-
const [serviceName, serviceConfig = {}] = Array.isArray(serviceEntry) ? serviceEntry : [serviceEntry];
|
|
47
|
-
const ServiceCtor = await getServiceModule(serviceName, lwrConfig);
|
|
48
|
-
return new ServiceCtor(serviceConfig, providerContext);
|
|
49
|
-
}));
|
|
54
|
+
};
|
|
50
55
|
}
|
|
@@ -29,126 +29,17 @@ __export(exports, {
|
|
|
29
29
|
var import_path = __toModule(require("path"));
|
|
30
30
|
var import_fs_extra = __toModule(require("fs-extra"));
|
|
31
31
|
var import_esbuild = __toModule(require("esbuild"));
|
|
32
|
+
var import_shared_utils = __toModule(require("@lwrjs/shared-utils"));
|
|
32
33
|
var import_config = __toModule(require("@lwrjs/config"));
|
|
33
|
-
var
|
|
34
|
-
var
|
|
35
|
-
|
|
36
|
-
function getBuildMetadata(appConfig) {
|
|
37
|
-
const moduleProviders = processServiceEntries("moduleProvider", appConfig.moduleProviders);
|
|
38
|
-
const resourceProviders = processServiceEntries("resourceProvider", appConfig.resourceProviders);
|
|
39
|
-
const viewProviders = processServiceEntries("viewProvider", appConfig.viewProviders);
|
|
40
|
-
const viewTransformers = processServiceEntries("viewTransformer", appConfig.viewTransformers);
|
|
41
|
-
const assetProviders = processServiceEntries("assetProvider", appConfig.assetProviders);
|
|
42
|
-
const assetTransformers = processServiceEntries("assetTransformer", appConfig.assetTransformers);
|
|
43
|
-
const imports = [
|
|
44
|
-
...moduleProviders.imports,
|
|
45
|
-
...resourceProviders.imports,
|
|
46
|
-
...viewProviders.imports,
|
|
47
|
-
...viewTransformers.imports,
|
|
48
|
-
...assetProviders.imports,
|
|
49
|
-
...assetTransformers.imports
|
|
50
|
-
];
|
|
51
|
-
return {
|
|
52
|
-
imports,
|
|
53
|
-
moduleProviders: moduleProviders.services,
|
|
54
|
-
resourceProviders: resourceProviders.services,
|
|
55
|
-
viewProviders: viewProviders.services,
|
|
56
|
-
viewTransformers: viewTransformers.services,
|
|
57
|
-
assetProviders: assetProviders.services,
|
|
58
|
-
assetTransformers: assetTransformers.services
|
|
59
|
-
};
|
|
60
|
-
}
|
|
61
|
-
function processServiceEntries(serviceType, entries) {
|
|
62
|
-
const imports = [];
|
|
63
|
-
const services = [];
|
|
64
|
-
for (const [index, [pkg, config]] of entries.entries()) {
|
|
65
|
-
const name = serviceType + index;
|
|
66
|
-
imports.push(`import ${name} from '${pkg}';`);
|
|
67
|
-
services.push(`[${name}, ${JSON.stringify(config)}]`);
|
|
68
|
-
}
|
|
69
|
-
return {
|
|
70
|
-
imports,
|
|
71
|
-
services
|
|
72
|
-
};
|
|
73
|
-
}
|
|
74
|
-
function generateServices(providerContext) {
|
|
75
|
-
return ([ServiceCtor, serviceConfig = {}]) => new ServiceCtor(serviceConfig, providerContext);
|
|
76
|
-
}
|
|
77
|
-
function isRemote() {
|
|
78
|
-
return process.env.AWS_LAMBDA_FUNCTION_NAME !== void 0;
|
|
79
|
-
}
|
|
80
|
-
function generateServerContextModule(appConfig, runtimeEnvironment, globalData, metadata) {
|
|
81
|
-
const {
|
|
82
|
-
imports,
|
|
83
|
-
moduleProviders,
|
|
84
|
-
resourceProviders,
|
|
85
|
-
viewProviders,
|
|
86
|
-
viewTransformers,
|
|
87
|
-
assetProviders,
|
|
88
|
-
assetTransformers
|
|
89
|
-
} = metadata;
|
|
90
|
-
const config = {
|
|
91
|
-
...appConfig,
|
|
92
|
-
rootDir: void 0,
|
|
93
|
-
ignoreLwrConfigFile: true
|
|
94
|
-
};
|
|
95
|
-
return [
|
|
96
|
-
`/* This module is generated */`,
|
|
97
|
-
`import { LwrCompiler } from '@lwrjs/compiler';`,
|
|
98
|
-
`import { LwrModuleBundler } from '@lwrjs/module-bundler';`,
|
|
99
|
-
`import { LwrModuleRegistry } from '@lwrjs/module-registry';`,
|
|
100
|
-
`import { LwrResourceRegistry } from '@lwrjs/resource-registry';`,
|
|
101
|
-
`import { LwrAssetRegistry } from '@lwrjs/asset-registry';`,
|
|
102
|
-
`import { LwrViewRegistry } from '@lwrjs/view-registry';`,
|
|
103
|
-
`import { LwrApplicationObserver, deepFreeze } from '@lwrjs/shared-utils';`,
|
|
104
|
-
`import { normalizeConfig } from '@lwrjs/config';`,
|
|
105
|
-
...imports,
|
|
106
|
-
import_server.createServerContext.toString(),
|
|
107
|
-
import_provider.createProviderContext.toString(),
|
|
108
|
-
generateServices.toString(),
|
|
109
|
-
isRemote.toString(),
|
|
110
|
-
`const config = ${JSON.stringify(config, null, 4)}`,
|
|
111
|
-
`const runtimeEnvironment = ${JSON.stringify(runtimeEnvironment, null, 4)}`,
|
|
112
|
-
`const globalData = ${JSON.stringify(globalData, null, 4)}`,
|
|
113
|
-
`isRemote() && process.chdir(__dirname);`,
|
|
114
|
-
`isRemote() && (config.rootDir = __dirname);`,
|
|
115
|
-
`isRemote() && (config.cacheDir = '/tmp/__lwr_cache__');`,
|
|
116
|
-
`const normalizedConfig = normalizeConfig(config);`,
|
|
117
|
-
`const serverContext = createServerContext(normalizedConfig, runtimeEnvironment, globalData);`,
|
|
118
|
-
`const providerContext = createProviderContext(serverContext);`,
|
|
119
|
-
`const generate = generateServices(providerContext);`,
|
|
120
|
-
`const moduleProviders = [${moduleProviders}].map(generate);`,
|
|
121
|
-
`const resourceProviders = [${resourceProviders}].map(generate);`,
|
|
122
|
-
`const viewProviders = [${viewProviders}].map(generate);`,
|
|
123
|
-
`const viewTransformers = [${viewTransformers}].map(generate);`,
|
|
124
|
-
`const assetProviders = [${assetProviders}].map(generate);`,
|
|
125
|
-
`const assetTransformers = [${assetTransformers}].map(generate);`,
|
|
126
|
-
`serverContext.moduleRegistry.addModuleProviders(moduleProviders);`,
|
|
127
|
-
`serverContext.resourceRegistry.addResourceProviders(resourceProviders);`,
|
|
128
|
-
`serverContext.viewRegistry.addViewProviders(viewProviders);`,
|
|
129
|
-
`serverContext.viewRegistry.addViewTransformers(viewTransformers);`,
|
|
130
|
-
`serverContext.assetRegistry.addAssetProviders(assetProviders);`,
|
|
131
|
-
`serverContext.assetRegistry.addAssetTransformers(assetTransformers);`,
|
|
132
|
-
`export default serverContext;`
|
|
133
|
-
].join("\n");
|
|
134
|
-
}
|
|
135
|
-
function generateServerSource(target) {
|
|
136
|
-
if (target !== "lambda") {
|
|
137
|
-
throw `Unsupported server build target: ${target}`;
|
|
138
|
-
}
|
|
139
|
-
return [
|
|
140
|
-
`/* This module is generated */`,
|
|
141
|
-
`import { createHandler } from '@lwrjs/lambda';`,
|
|
142
|
-
`import build from './lwr.build.js';`,
|
|
143
|
-
`const handler = createHandler(build);`,
|
|
144
|
-
`export { handler as get };`
|
|
145
|
-
].join("\n");
|
|
146
|
-
}
|
|
147
|
-
async function bundleServer(entryPoint, outputPath) {
|
|
34
|
+
var import_generate_entry_plugin = __toModule(require("./plugins/generate-entry-plugin.cjs"));
|
|
35
|
+
var import_build_server_plugin = __toModule(require("./plugins/build-server-plugin.cjs"));
|
|
36
|
+
async function build(outputDir, config) {
|
|
148
37
|
await import_esbuild.default.build({
|
|
149
|
-
entryPoints: [
|
|
38
|
+
entryPoints: ["./lwr.entry.js"],
|
|
150
39
|
bundle: true,
|
|
151
40
|
sourcemap: true,
|
|
41
|
+
format: "cjs",
|
|
42
|
+
platform: "node",
|
|
152
43
|
logLevel: "silent",
|
|
153
44
|
external: [
|
|
154
45
|
"node:*",
|
|
@@ -160,23 +51,18 @@ async function bundleServer(entryPoint, outputPath) {
|
|
|
160
51
|
"node-fetch",
|
|
161
52
|
"rollup",
|
|
162
53
|
"rollup-plugin-node-polyfills",
|
|
163
|
-
"@lwrjs/config",
|
|
164
54
|
"@lwrjs/loader"
|
|
165
55
|
],
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
56
|
+
banner: {
|
|
57
|
+
js: `globalThis.LWR_VERSION='${import_config.LWR_VERSION};'`
|
|
58
|
+
},
|
|
59
|
+
plugins: [(0, import_generate_entry_plugin.default)(), (0, import_build_server_plugin.default)(config)],
|
|
60
|
+
outfile: import_path.default.join(outputDir, "ssr.js")
|
|
169
61
|
});
|
|
170
62
|
}
|
|
171
63
|
async function buildServer(configArg, options) {
|
|
172
|
-
const
|
|
173
|
-
const {appConfig, runtimeEnvironment, globalData} = await (0, import_configurations.resolveConfigurations)(config);
|
|
174
|
-
const metadata = getBuildMetadata(appConfig);
|
|
175
|
-
const serverContext = generateServerContextModule(appConfig, runtimeEnvironment, globalData, metadata);
|
|
176
|
-
const outputDir = import_path.default.join(appConfig.rootDir, options?.outputDir || "/build");
|
|
177
|
-
const serverSource = generateServerSource(options?.target || "lambda");
|
|
64
|
+
const outputDir = import_path.default.join(configArg?.rootDir || process.cwd(), options?.outputDir || "/build");
|
|
178
65
|
await import_fs_extra.default.ensureDir(outputDir);
|
|
179
|
-
await
|
|
180
|
-
|
|
181
|
-
await bundleServer(import_path.default.join(outputDir, "entry.js"), import_path.default.join(outputDir, "ssr.js"));
|
|
66
|
+
await build(outputDir, configArg);
|
|
67
|
+
import_shared_utils.logger.info("Successfully built the server");
|
|
182
68
|
}
|
|
@@ -36,17 +36,10 @@ async function warmupServer(config, internalRequestKey) {
|
|
|
36
36
|
import_shared_utils.logger.setOptions({dedupe: new Set([import_shared_utils.WARN])});
|
|
37
37
|
}
|
|
38
38
|
import_shared_utils.logger.info("[Server Warmup] starting");
|
|
39
|
-
const {routes, staticSiteGenerator, port,
|
|
39
|
+
const {routes, staticSiteGenerator, port, basePath} = config;
|
|
40
40
|
staticSiteGenerator.outputDir = import_dir.skipDirCreation;
|
|
41
41
|
const urlRewriteMap = new Map();
|
|
42
|
-
const runtimeEnvironment =
|
|
43
|
-
...(0, import_config.explodeMode)(serverMode),
|
|
44
|
-
apiVersion,
|
|
45
|
-
basePath,
|
|
46
|
-
lwrVersion,
|
|
47
|
-
debug: false,
|
|
48
|
-
serverMode
|
|
49
|
-
};
|
|
42
|
+
const runtimeEnvironment = (0, import_config.getRuntimeEnvironment)(config);
|
|
50
43
|
await new import_static_generation.default().generateRoutes(runtimeEnvironment, staticSiteGenerator, routes, basePath, new import_network_dispatcher.default(port, internalRequestKey), staticSiteGenerator.outputDir, urlRewriteMap);
|
|
51
44
|
import_shared_utils.logger.info("[Server Warmup] complete");
|
|
52
45
|
}
|
|
@@ -46,18 +46,15 @@ var SiteGenerator = class {
|
|
|
46
46
|
staticSiteGenerator.outputDir = "__generated_site__";
|
|
47
47
|
}
|
|
48
48
|
const outputDir = (0, import_path.join)(rootDir, staticSiteGenerator.outputDir);
|
|
49
|
-
|
|
50
|
-
|
|
49
|
+
if (!staticSiteGenerator.skipCleanOutputDir) {
|
|
50
|
+
import_shared_utils.logger.info(`Clearing output directory: ${outputDir}`);
|
|
51
|
+
import_fs_extra.default.rmSync(outputDir, {recursive: true, force: true});
|
|
52
|
+
} else {
|
|
53
|
+
import_shared_utils.logger.info(`Reusing existing output directory: ${outputDir}`);
|
|
54
|
+
}
|
|
51
55
|
const urlRewriteMap = new Map();
|
|
52
|
-
const {
|
|
53
|
-
const runtimeEnvironment =
|
|
54
|
-
...(0, import_config.explodeMode)(serverMode),
|
|
55
|
-
apiVersion,
|
|
56
|
-
basePath,
|
|
57
|
-
lwrVersion,
|
|
58
|
-
debug: false,
|
|
59
|
-
serverMode
|
|
60
|
-
};
|
|
56
|
+
const {basePath} = config;
|
|
57
|
+
const runtimeEnvironment = (0, import_config.getRuntimeEnvironment)(config);
|
|
61
58
|
await this.generateRoutes(runtimeEnvironment, staticSiteGenerator, routes, basePath, dispatcher, outputDir, urlRewriteMap);
|
|
62
59
|
this.writeNetlifyRedirectConfig(outputDir, urlRewriteMap);
|
|
63
60
|
this.copyAssets(assets, outputDir, basePath);
|
|
@@ -5,6 +5,8 @@ import { LwrModuleRegistry } from '@lwrjs/module-registry';
|
|
|
5
5
|
import { LwrResourceRegistry } from '@lwrjs/resource-registry';
|
|
6
6
|
import { LwrApplicationObserver } from '@lwrjs/shared-utils';
|
|
7
7
|
import { LwrViewRegistry } from '@lwrjs/view-registry';
|
|
8
|
+
// dependency chokidar in this package.json is to statisfy the optional dependency in shared-utils for fs-watch.
|
|
9
|
+
import { WatcherFactoryImpl } from '@lwrjs/shared-utils/fs-watch';
|
|
8
10
|
export function createServerContext(appConfig, runtimeEnvironment, globalData) {
|
|
9
11
|
const appObserver = new LwrApplicationObserver();
|
|
10
12
|
const appEmitter = appObserver.createLwrEmitter();
|
|
@@ -32,6 +34,7 @@ export function createServerContext(appConfig, runtimeEnvironment, globalData) {
|
|
|
32
34
|
globalData,
|
|
33
35
|
runtimeEnvironment,
|
|
34
36
|
}, appConfig);
|
|
37
|
+
const watcherFactory = new WatcherFactoryImpl();
|
|
35
38
|
return {
|
|
36
39
|
compiler,
|
|
37
40
|
appObserver,
|
|
@@ -43,6 +46,7 @@ export function createServerContext(appConfig, runtimeEnvironment, globalData) {
|
|
|
43
46
|
viewRegistry,
|
|
44
47
|
appConfig,
|
|
45
48
|
runtimeEnvironment,
|
|
49
|
+
watcherFactory,
|
|
46
50
|
};
|
|
47
51
|
}
|
|
48
52
|
//# sourceMappingURL=server.js.map
|