@bleedingdev/modern-js-app-tools 3.2.0-ultramodern.30 → 3.2.0-ultramodern.35
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/dist/cjs/builder/generator/getBuilderEnvironments.js +0 -3
- package/dist/cjs/plugins/deploy/platforms/cloudflare.js +10 -20
- package/dist/cjs/plugins/deploy/platforms/templates/cloudflare-entry.mjs +18 -25
- package/dist/esm/builder/generator/getBuilderEnvironments.mjs +0 -3
- package/dist/esm/plugins/deploy/platforms/cloudflare.mjs +10 -20
- package/dist/esm/plugins/deploy/platforms/templates/cloudflare-entry.mjs +18 -25
- package/dist/esm-node/builder/generator/getBuilderEnvironments.mjs +0 -3
- package/dist/esm-node/plugins/deploy/platforms/cloudflare.mjs +10 -20
- package/dist/esm-node/plugins/deploy/platforms/templates/cloudflare-entry.mjs +18 -25
- package/dist/types/types/config/deploy.d.ts +1 -0
- package/package.json +11 -11
|
@@ -180,9 +180,6 @@ function getBuilderEnvironments(normalizedConfig, appContext, tempBuilderConfig)
|
|
|
180
180
|
outputModule: true
|
|
181
181
|
}
|
|
182
182
|
});
|
|
183
|
-
chain.externalsPresets({
|
|
184
|
-
node: true
|
|
185
|
-
});
|
|
186
183
|
chain.target('webworker');
|
|
187
184
|
chain.plugins.delete('plugin-module-federation');
|
|
188
185
|
if (tanstackRouterSsrServerFile) {
|
|
@@ -55,6 +55,10 @@ const getWorkerName = (appDirectory)=>{
|
|
|
55
55
|
const basename = external_node_path_default().basename(appDirectory);
|
|
56
56
|
return basename.replace(/[^a-zA-Z0-9-_]/g, '-') || 'modern-cloudflare-worker';
|
|
57
57
|
};
|
|
58
|
+
const getConfiguredWorkerName = (appDirectory, modernConfig)=>{
|
|
59
|
+
const configuredName = modernConfig.deploy?.worker?.name?.trim();
|
|
60
|
+
return configuredName || getWorkerName(appDirectory);
|
|
61
|
+
};
|
|
58
62
|
const readRouteSpec = async (outputDirectory)=>{
|
|
59
63
|
const routeSpecPath = external_node_path_default().join(outputDirectory, ROUTE_SPEC_OUTPUT);
|
|
60
64
|
if (!await utils_namespaceObject.fs.pathExists(routeSpecPath)) return {
|
|
@@ -76,9 +80,7 @@ const createWorkerManifest = async (outputDirectory, modernConfig)=>{
|
|
|
76
80
|
entryPath: route.entryPath,
|
|
77
81
|
isSSR: Boolean(route.isSSR),
|
|
78
82
|
worker,
|
|
79
|
-
|
|
80
|
-
workerExists: worker ? await utils_namespaceObject.fs.pathExists(external_node_path_default().join(outputDirectory, worker)) : false,
|
|
81
|
-
bundleExists: 'string' == typeof route.bundle ? await utils_namespaceObject.fs.pathExists(external_node_path_default().join(outputDirectory, route.bundle)) : false
|
|
83
|
+
workerExists: worker ? await utils_namespaceObject.fs.pathExists(external_node_path_default().join(outputDirectory, worker)) : false
|
|
82
84
|
};
|
|
83
85
|
}));
|
|
84
86
|
const bffPrefix = modernConfig.bff?.prefix;
|
|
@@ -120,15 +122,9 @@ const createWorkerManifest = async (outputDirectory, modernConfig)=>{
|
|
|
120
122
|
};
|
|
121
123
|
const createWorkerModuleLoaders = (manifest)=>{
|
|
122
124
|
const imports = new Map();
|
|
123
|
-
for (const route of manifest.routeSpec.routes){
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
imports.set(route.worker, `() => import(${JSON.stringify(importPath)})`);
|
|
127
|
-
}
|
|
128
|
-
if (route.bundle && route.bundleExists) {
|
|
129
|
-
const importPath = `../${String(route.bundle).replace(/^\/+/u, '')}`;
|
|
130
|
-
imports.set(route.bundle, `() => import(${JSON.stringify(importPath)})`);
|
|
131
|
-
}
|
|
125
|
+
for (const route of manifest.routeSpec.routes)if (route.worker && route.workerExists) {
|
|
126
|
+
const importPath = `../${String(route.worker).replace(/^\/+/u, '')}`;
|
|
127
|
+
imports.set(route.worker, `() => import(${JSON.stringify(importPath)})`);
|
|
132
128
|
}
|
|
133
129
|
if (manifest.bff?.worker) {
|
|
134
130
|
const importPath = `../${String(manifest.bff.worker).replace(/^\/+/u, '')}`;
|
|
@@ -167,6 +163,7 @@ const createCloudflarePreset = ({ appContext, modernConfig })=>{
|
|
|
167
163
|
const workerManifestPath = external_node_path_default().join(outputDirectory, WORKER_MANIFEST);
|
|
168
164
|
const routeSpecOutputPath = external_node_path_default().join(outputDirectory, ROUTE_SPEC_OUTPUT);
|
|
169
165
|
const wranglerConfigPath = external_node_path_default().join(outputDirectory, 'wrangler.json');
|
|
166
|
+
const workerName = getConfiguredWorkerName(appDirectory, modernConfig);
|
|
170
167
|
return {
|
|
171
168
|
async prepare () {
|
|
172
169
|
await utils_namespaceObject.fs.remove(outputDirectory);
|
|
@@ -183,16 +180,9 @@ const createCloudflarePreset = ({ appContext, modernConfig })=>{
|
|
|
183
180
|
if (await utils_namespaceObject.fs.pathExists(workerBundleSourceDirectory)) await utils_namespaceObject.fs.copy(workerBundleSourceDirectory, external_node_path_default().join(outputDirectory, WORKER_BUNDLE_DIRECTORY), {
|
|
184
181
|
filter: (src)=>shouldCopyToWorkerBundle(src, workerBundleSourceDirectory)
|
|
185
182
|
});
|
|
186
|
-
const serverBundleSourceDirectory = external_node_path_default().join(distDirectory, SERVER_BUNDLE_DIRECTORY);
|
|
187
|
-
if (await utils_namespaceObject.fs.pathExists(serverBundleSourceDirectory)) {
|
|
188
|
-
await utils_namespaceObject.fs.copy(serverBundleSourceDirectory, external_node_path_default().join(outputDirectory, SERVER_BUNDLE_DIRECTORY));
|
|
189
|
-
await utils_namespaceObject.fs.writeJSON(external_node_path_default().join(outputDirectory, SERVER_BUNDLE_DIRECTORY, 'package.json'), {
|
|
190
|
-
type: 'commonjs'
|
|
191
|
-
});
|
|
192
|
-
}
|
|
193
183
|
await utils_namespaceObject.fs.writeJSON(wranglerConfigPath, {
|
|
194
184
|
$schema: 'node_modules/wrangler/config-schema.json',
|
|
195
|
-
name:
|
|
185
|
+
name: workerName,
|
|
196
186
|
main: WORKER_ENTRY,
|
|
197
187
|
compatibility_date: getCompatibilityDate(),
|
|
198
188
|
compatibility_flags: [
|
|
@@ -129,42 +129,35 @@ async function getRequestHandler(workerModule) {
|
|
|
129
129
|
return await workerModule.requestHandler || await defaultRequestHandler || ('function' == typeof defaultExport ? defaultExport : void 0);
|
|
130
130
|
}
|
|
131
131
|
async function dispatchRouteWorker(route, request, env, ctx) {
|
|
132
|
-
const
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
for (const candidatePath of candidatePaths){
|
|
138
|
-
const workerModule = await loadWorkerModule(candidatePath);
|
|
139
|
-
if (!workerModule) {
|
|
140
|
-
missingPath = candidatePath;
|
|
141
|
-
continue;
|
|
142
|
-
}
|
|
143
|
-
const fetchHandler = getFetchHandler(workerModule);
|
|
144
|
-
if (fetchHandler) return fetchHandler(request, env, ctx);
|
|
145
|
-
const requestHandler = await getRequestHandler(workerModule);
|
|
146
|
-
if ('function' == typeof requestHandler) {
|
|
147
|
-
const requestHandlerOptions = await getRequestHandlerOptions(route, request, env);
|
|
148
|
-
return requestHandler(request, requestHandlerOptions);
|
|
132
|
+
const workerPath = route.worker;
|
|
133
|
+
if (!workerPath) return new Response('Worker bundle not configured for SSR route', {
|
|
134
|
+
status: 500,
|
|
135
|
+
headers: {
|
|
136
|
+
'content-type': 'text/plain; charset=utf-8'
|
|
149
137
|
}
|
|
150
|
-
}
|
|
151
|
-
|
|
138
|
+
});
|
|
139
|
+
const workerModule = await loadWorkerModule(workerPath);
|
|
140
|
+
if (!workerModule) return new Response(`Worker bundle not found: ${workerPath}`, {
|
|
152
141
|
status: 500,
|
|
153
142
|
headers: {
|
|
154
143
|
'content-type': 'text/plain; charset=utf-8',
|
|
155
|
-
'x-modern-js-route-worker':
|
|
144
|
+
'x-modern-js-route-worker': workerPath
|
|
156
145
|
}
|
|
157
146
|
});
|
|
158
|
-
|
|
147
|
+
const fetchHandler = getFetchHandler(workerModule);
|
|
148
|
+
if (fetchHandler) return fetchHandler(request, env, ctx);
|
|
149
|
+
const requestHandler = await getRequestHandler(workerModule);
|
|
150
|
+
if ('function' == typeof requestHandler) {
|
|
151
|
+
const requestHandlerOptions = await getRequestHandlerOptions(route, request, env);
|
|
152
|
+
return requestHandler(request, requestHandlerOptions);
|
|
153
|
+
}
|
|
154
|
+
return new Response(`Worker bundle has no fetch or requestHandler export: ${workerPath}`, {
|
|
159
155
|
status: 500,
|
|
160
156
|
headers: {
|
|
161
157
|
'content-type': 'text/plain; charset=utf-8',
|
|
162
|
-
'x-modern-js-route-worker':
|
|
158
|
+
'x-modern-js-route-worker': workerPath
|
|
163
159
|
}
|
|
164
160
|
});
|
|
165
|
-
return new Response('Route has no worker bundle', {
|
|
166
|
-
status: 500
|
|
167
|
-
});
|
|
168
161
|
}
|
|
169
162
|
function matchesPrefix(pathname, prefix) {
|
|
170
163
|
if (!prefix || '/' === prefix) return true;
|
|
@@ -141,9 +141,6 @@ function getBuilderEnvironments(normalizedConfig, appContext, tempBuilderConfig)
|
|
|
141
141
|
outputModule: true
|
|
142
142
|
}
|
|
143
143
|
});
|
|
144
|
-
chain.externalsPresets({
|
|
145
|
-
node: true
|
|
146
|
-
});
|
|
147
144
|
chain.target('webworker');
|
|
148
145
|
chain.plugins.delete('plugin-module-federation');
|
|
149
146
|
if (tanstackRouterSsrServerFile) {
|
|
@@ -17,6 +17,10 @@ const getWorkerName = (appDirectory)=>{
|
|
|
17
17
|
const basename = node_path.basename(appDirectory);
|
|
18
18
|
return basename.replace(/[^a-zA-Z0-9-_]/g, '-') || 'modern-cloudflare-worker';
|
|
19
19
|
};
|
|
20
|
+
const getConfiguredWorkerName = (appDirectory, modernConfig)=>{
|
|
21
|
+
const configuredName = modernConfig.deploy?.worker?.name?.trim();
|
|
22
|
+
return configuredName || getWorkerName(appDirectory);
|
|
23
|
+
};
|
|
20
24
|
const readRouteSpec = async (outputDirectory)=>{
|
|
21
25
|
const routeSpecPath = node_path.join(outputDirectory, ROUTE_SPEC_OUTPUT);
|
|
22
26
|
if (!await fs.pathExists(routeSpecPath)) return {
|
|
@@ -38,9 +42,7 @@ const createWorkerManifest = async (outputDirectory, modernConfig)=>{
|
|
|
38
42
|
entryPath: route.entryPath,
|
|
39
43
|
isSSR: Boolean(route.isSSR),
|
|
40
44
|
worker,
|
|
41
|
-
|
|
42
|
-
workerExists: worker ? await fs.pathExists(node_path.join(outputDirectory, worker)) : false,
|
|
43
|
-
bundleExists: 'string' == typeof route.bundle ? await fs.pathExists(node_path.join(outputDirectory, route.bundle)) : false
|
|
45
|
+
workerExists: worker ? await fs.pathExists(node_path.join(outputDirectory, worker)) : false
|
|
44
46
|
};
|
|
45
47
|
}));
|
|
46
48
|
const bffPrefix = modernConfig.bff?.prefix;
|
|
@@ -82,15 +84,9 @@ const createWorkerManifest = async (outputDirectory, modernConfig)=>{
|
|
|
82
84
|
};
|
|
83
85
|
const createWorkerModuleLoaders = (manifest)=>{
|
|
84
86
|
const imports = new Map();
|
|
85
|
-
for (const route of manifest.routeSpec.routes){
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
imports.set(route.worker, `() => import(${JSON.stringify(importPath)})`);
|
|
89
|
-
}
|
|
90
|
-
if (route.bundle && route.bundleExists) {
|
|
91
|
-
const importPath = `../${String(route.bundle).replace(/^\/+/u, '')}`;
|
|
92
|
-
imports.set(route.bundle, `() => import(${JSON.stringify(importPath)})`);
|
|
93
|
-
}
|
|
87
|
+
for (const route of manifest.routeSpec.routes)if (route.worker && route.workerExists) {
|
|
88
|
+
const importPath = `../${String(route.worker).replace(/^\/+/u, '')}`;
|
|
89
|
+
imports.set(route.worker, `() => import(${JSON.stringify(importPath)})`);
|
|
94
90
|
}
|
|
95
91
|
if (manifest.bff?.worker) {
|
|
96
92
|
const importPath = `../${String(manifest.bff.worker).replace(/^\/+/u, '')}`;
|
|
@@ -129,6 +125,7 @@ const createCloudflarePreset = ({ appContext, modernConfig })=>{
|
|
|
129
125
|
const workerManifestPath = node_path.join(outputDirectory, WORKER_MANIFEST);
|
|
130
126
|
const routeSpecOutputPath = node_path.join(outputDirectory, ROUTE_SPEC_OUTPUT);
|
|
131
127
|
const wranglerConfigPath = node_path.join(outputDirectory, 'wrangler.json');
|
|
128
|
+
const workerName = getConfiguredWorkerName(appDirectory, modernConfig);
|
|
132
129
|
return {
|
|
133
130
|
async prepare () {
|
|
134
131
|
await fs.remove(outputDirectory);
|
|
@@ -145,16 +142,9 @@ const createCloudflarePreset = ({ appContext, modernConfig })=>{
|
|
|
145
142
|
if (await fs.pathExists(workerBundleSourceDirectory)) await fs.copy(workerBundleSourceDirectory, node_path.join(outputDirectory, WORKER_BUNDLE_DIRECTORY), {
|
|
146
143
|
filter: (src)=>shouldCopyToWorkerBundle(src, workerBundleSourceDirectory)
|
|
147
144
|
});
|
|
148
|
-
const serverBundleSourceDirectory = node_path.join(distDirectory, SERVER_BUNDLE_DIRECTORY);
|
|
149
|
-
if (await fs.pathExists(serverBundleSourceDirectory)) {
|
|
150
|
-
await fs.copy(serverBundleSourceDirectory, node_path.join(outputDirectory, SERVER_BUNDLE_DIRECTORY));
|
|
151
|
-
await fs.writeJSON(node_path.join(outputDirectory, SERVER_BUNDLE_DIRECTORY, 'package.json'), {
|
|
152
|
-
type: 'commonjs'
|
|
153
|
-
});
|
|
154
|
-
}
|
|
155
145
|
await fs.writeJSON(wranglerConfigPath, {
|
|
156
146
|
$schema: 'node_modules/wrangler/config-schema.json',
|
|
157
|
-
name:
|
|
147
|
+
name: workerName,
|
|
158
148
|
main: WORKER_ENTRY,
|
|
159
149
|
compatibility_date: getCompatibilityDate(),
|
|
160
150
|
compatibility_flags: [
|
|
@@ -129,42 +129,35 @@ async function getRequestHandler(workerModule) {
|
|
|
129
129
|
return await workerModule.requestHandler || await defaultRequestHandler || ('function' == typeof defaultExport ? defaultExport : void 0);
|
|
130
130
|
}
|
|
131
131
|
async function dispatchRouteWorker(route, request, env, ctx) {
|
|
132
|
-
const
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
for (const candidatePath of candidatePaths){
|
|
138
|
-
const workerModule = await loadWorkerModule(candidatePath);
|
|
139
|
-
if (!workerModule) {
|
|
140
|
-
missingPath = candidatePath;
|
|
141
|
-
continue;
|
|
142
|
-
}
|
|
143
|
-
const fetchHandler = getFetchHandler(workerModule);
|
|
144
|
-
if (fetchHandler) return fetchHandler(request, env, ctx);
|
|
145
|
-
const requestHandler = await getRequestHandler(workerModule);
|
|
146
|
-
if ('function' == typeof requestHandler) {
|
|
147
|
-
const requestHandlerOptions = await getRequestHandlerOptions(route, request, env);
|
|
148
|
-
return requestHandler(request, requestHandlerOptions);
|
|
132
|
+
const workerPath = route.worker;
|
|
133
|
+
if (!workerPath) return new Response('Worker bundle not configured for SSR route', {
|
|
134
|
+
status: 500,
|
|
135
|
+
headers: {
|
|
136
|
+
'content-type': 'text/plain; charset=utf-8'
|
|
149
137
|
}
|
|
150
|
-
}
|
|
151
|
-
|
|
138
|
+
});
|
|
139
|
+
const workerModule = await loadWorkerModule(workerPath);
|
|
140
|
+
if (!workerModule) return new Response(`Worker bundle not found: ${workerPath}`, {
|
|
152
141
|
status: 500,
|
|
153
142
|
headers: {
|
|
154
143
|
'content-type': 'text/plain; charset=utf-8',
|
|
155
|
-
'x-modern-js-route-worker':
|
|
144
|
+
'x-modern-js-route-worker': workerPath
|
|
156
145
|
}
|
|
157
146
|
});
|
|
158
|
-
|
|
147
|
+
const fetchHandler = getFetchHandler(workerModule);
|
|
148
|
+
if (fetchHandler) return fetchHandler(request, env, ctx);
|
|
149
|
+
const requestHandler = await getRequestHandler(workerModule);
|
|
150
|
+
if ('function' == typeof requestHandler) {
|
|
151
|
+
const requestHandlerOptions = await getRequestHandlerOptions(route, request, env);
|
|
152
|
+
return requestHandler(request, requestHandlerOptions);
|
|
153
|
+
}
|
|
154
|
+
return new Response(`Worker bundle has no fetch or requestHandler export: ${workerPath}`, {
|
|
159
155
|
status: 500,
|
|
160
156
|
headers: {
|
|
161
157
|
'content-type': 'text/plain; charset=utf-8',
|
|
162
|
-
'x-modern-js-route-worker':
|
|
158
|
+
'x-modern-js-route-worker': workerPath
|
|
163
159
|
}
|
|
164
160
|
});
|
|
165
|
-
return new Response('Route has no worker bundle', {
|
|
166
|
-
status: 500
|
|
167
|
-
});
|
|
168
161
|
}
|
|
169
162
|
function matchesPrefix(pathname, prefix) {
|
|
170
163
|
if (!prefix || '/' === prefix) return true;
|
|
@@ -143,9 +143,6 @@ function getBuilderEnvironments(normalizedConfig, appContext, tempBuilderConfig)
|
|
|
143
143
|
outputModule: true
|
|
144
144
|
}
|
|
145
145
|
});
|
|
146
|
-
chain.externalsPresets({
|
|
147
|
-
node: true
|
|
148
|
-
});
|
|
149
146
|
chain.target('webworker');
|
|
150
147
|
chain.plugins.delete('plugin-module-federation');
|
|
151
148
|
if (tanstackRouterSsrServerFile) {
|
|
@@ -18,6 +18,10 @@ const getWorkerName = (appDirectory)=>{
|
|
|
18
18
|
const basename = node_path.basename(appDirectory);
|
|
19
19
|
return basename.replace(/[^a-zA-Z0-9-_]/g, '-') || 'modern-cloudflare-worker';
|
|
20
20
|
};
|
|
21
|
+
const getConfiguredWorkerName = (appDirectory, modernConfig)=>{
|
|
22
|
+
const configuredName = modernConfig.deploy?.worker?.name?.trim();
|
|
23
|
+
return configuredName || getWorkerName(appDirectory);
|
|
24
|
+
};
|
|
21
25
|
const readRouteSpec = async (outputDirectory)=>{
|
|
22
26
|
const routeSpecPath = node_path.join(outputDirectory, ROUTE_SPEC_OUTPUT);
|
|
23
27
|
if (!await fs.pathExists(routeSpecPath)) return {
|
|
@@ -39,9 +43,7 @@ const createWorkerManifest = async (outputDirectory, modernConfig)=>{
|
|
|
39
43
|
entryPath: route.entryPath,
|
|
40
44
|
isSSR: Boolean(route.isSSR),
|
|
41
45
|
worker,
|
|
42
|
-
|
|
43
|
-
workerExists: worker ? await fs.pathExists(node_path.join(outputDirectory, worker)) : false,
|
|
44
|
-
bundleExists: 'string' == typeof route.bundle ? await fs.pathExists(node_path.join(outputDirectory, route.bundle)) : false
|
|
46
|
+
workerExists: worker ? await fs.pathExists(node_path.join(outputDirectory, worker)) : false
|
|
45
47
|
};
|
|
46
48
|
}));
|
|
47
49
|
const bffPrefix = modernConfig.bff?.prefix;
|
|
@@ -83,15 +85,9 @@ const createWorkerManifest = async (outputDirectory, modernConfig)=>{
|
|
|
83
85
|
};
|
|
84
86
|
const createWorkerModuleLoaders = (manifest)=>{
|
|
85
87
|
const imports = new Map();
|
|
86
|
-
for (const route of manifest.routeSpec.routes){
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
imports.set(route.worker, `() => import(${JSON.stringify(importPath)})`);
|
|
90
|
-
}
|
|
91
|
-
if (route.bundle && route.bundleExists) {
|
|
92
|
-
const importPath = `../${String(route.bundle).replace(/^\/+/u, '')}`;
|
|
93
|
-
imports.set(route.bundle, `() => import(${JSON.stringify(importPath)})`);
|
|
94
|
-
}
|
|
88
|
+
for (const route of manifest.routeSpec.routes)if (route.worker && route.workerExists) {
|
|
89
|
+
const importPath = `../${String(route.worker).replace(/^\/+/u, '')}`;
|
|
90
|
+
imports.set(route.worker, `() => import(${JSON.stringify(importPath)})`);
|
|
95
91
|
}
|
|
96
92
|
if (manifest.bff?.worker) {
|
|
97
93
|
const importPath = `../${String(manifest.bff.worker).replace(/^\/+/u, '')}`;
|
|
@@ -130,6 +126,7 @@ const createCloudflarePreset = ({ appContext, modernConfig })=>{
|
|
|
130
126
|
const workerManifestPath = node_path.join(outputDirectory, WORKER_MANIFEST);
|
|
131
127
|
const routeSpecOutputPath = node_path.join(outputDirectory, ROUTE_SPEC_OUTPUT);
|
|
132
128
|
const wranglerConfigPath = node_path.join(outputDirectory, 'wrangler.json');
|
|
129
|
+
const workerName = getConfiguredWorkerName(appDirectory, modernConfig);
|
|
133
130
|
return {
|
|
134
131
|
async prepare () {
|
|
135
132
|
await fs.remove(outputDirectory);
|
|
@@ -146,16 +143,9 @@ const createCloudflarePreset = ({ appContext, modernConfig })=>{
|
|
|
146
143
|
if (await fs.pathExists(workerBundleSourceDirectory)) await fs.copy(workerBundleSourceDirectory, node_path.join(outputDirectory, WORKER_BUNDLE_DIRECTORY), {
|
|
147
144
|
filter: (src)=>shouldCopyToWorkerBundle(src, workerBundleSourceDirectory)
|
|
148
145
|
});
|
|
149
|
-
const serverBundleSourceDirectory = node_path.join(distDirectory, SERVER_BUNDLE_DIRECTORY);
|
|
150
|
-
if (await fs.pathExists(serverBundleSourceDirectory)) {
|
|
151
|
-
await fs.copy(serverBundleSourceDirectory, node_path.join(outputDirectory, SERVER_BUNDLE_DIRECTORY));
|
|
152
|
-
await fs.writeJSON(node_path.join(outputDirectory, SERVER_BUNDLE_DIRECTORY, 'package.json'), {
|
|
153
|
-
type: 'commonjs'
|
|
154
|
-
});
|
|
155
|
-
}
|
|
156
146
|
await fs.writeJSON(wranglerConfigPath, {
|
|
157
147
|
$schema: 'node_modules/wrangler/config-schema.json',
|
|
158
|
-
name:
|
|
148
|
+
name: workerName,
|
|
159
149
|
main: WORKER_ENTRY,
|
|
160
150
|
compatibility_date: getCompatibilityDate(),
|
|
161
151
|
compatibility_flags: [
|
|
@@ -129,42 +129,35 @@ async function getRequestHandler(workerModule) {
|
|
|
129
129
|
return await workerModule.requestHandler || await defaultRequestHandler || ('function' == typeof defaultExport ? defaultExport : void 0);
|
|
130
130
|
}
|
|
131
131
|
async function dispatchRouteWorker(route, request, env, ctx) {
|
|
132
|
-
const
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
for (const candidatePath of candidatePaths){
|
|
138
|
-
const workerModule = await loadWorkerModule(candidatePath);
|
|
139
|
-
if (!workerModule) {
|
|
140
|
-
missingPath = candidatePath;
|
|
141
|
-
continue;
|
|
142
|
-
}
|
|
143
|
-
const fetchHandler = getFetchHandler(workerModule);
|
|
144
|
-
if (fetchHandler) return fetchHandler(request, env, ctx);
|
|
145
|
-
const requestHandler = await getRequestHandler(workerModule);
|
|
146
|
-
if ('function' == typeof requestHandler) {
|
|
147
|
-
const requestHandlerOptions = await getRequestHandlerOptions(route, request, env);
|
|
148
|
-
return requestHandler(request, requestHandlerOptions);
|
|
132
|
+
const workerPath = route.worker;
|
|
133
|
+
if (!workerPath) return new Response('Worker bundle not configured for SSR route', {
|
|
134
|
+
status: 500,
|
|
135
|
+
headers: {
|
|
136
|
+
'content-type': 'text/plain; charset=utf-8'
|
|
149
137
|
}
|
|
150
|
-
}
|
|
151
|
-
|
|
138
|
+
});
|
|
139
|
+
const workerModule = await loadWorkerModule(workerPath);
|
|
140
|
+
if (!workerModule) return new Response(`Worker bundle not found: ${workerPath}`, {
|
|
152
141
|
status: 500,
|
|
153
142
|
headers: {
|
|
154
143
|
'content-type': 'text/plain; charset=utf-8',
|
|
155
|
-
'x-modern-js-route-worker':
|
|
144
|
+
'x-modern-js-route-worker': workerPath
|
|
156
145
|
}
|
|
157
146
|
});
|
|
158
|
-
|
|
147
|
+
const fetchHandler = getFetchHandler(workerModule);
|
|
148
|
+
if (fetchHandler) return fetchHandler(request, env, ctx);
|
|
149
|
+
const requestHandler = await getRequestHandler(workerModule);
|
|
150
|
+
if ('function' == typeof requestHandler) {
|
|
151
|
+
const requestHandlerOptions = await getRequestHandlerOptions(route, request, env);
|
|
152
|
+
return requestHandler(request, requestHandlerOptions);
|
|
153
|
+
}
|
|
154
|
+
return new Response(`Worker bundle has no fetch or requestHandler export: ${workerPath}`, {
|
|
159
155
|
status: 500,
|
|
160
156
|
headers: {
|
|
161
157
|
'content-type': 'text/plain; charset=utf-8',
|
|
162
|
-
'x-modern-js-route-worker':
|
|
158
|
+
'x-modern-js-route-worker': workerPath
|
|
163
159
|
}
|
|
164
160
|
});
|
|
165
|
-
return new Response('Route has no worker bundle', {
|
|
166
|
-
status: 500
|
|
167
|
-
});
|
|
168
161
|
}
|
|
169
162
|
function matchesPrefix(pathname, prefix) {
|
|
170
163
|
if (!prefix || '/' === prefix) return true;
|
package/package.json
CHANGED
|
@@ -17,7 +17,7 @@
|
|
|
17
17
|
"modern",
|
|
18
18
|
"modern.js"
|
|
19
19
|
],
|
|
20
|
-
"version": "3.2.0-ultramodern.
|
|
20
|
+
"version": "3.2.0-ultramodern.35",
|
|
21
21
|
"types": "./dist/types/index.d.ts",
|
|
22
22
|
"main": "./dist/cjs/index.js",
|
|
23
23
|
"exports": {
|
|
@@ -98,16 +98,16 @@
|
|
|
98
98
|
"ndepe": "^0.1.13",
|
|
99
99
|
"pkg-types": "^2.3.1",
|
|
100
100
|
"std-env": "4.1.0",
|
|
101
|
-
"@modern-js/
|
|
102
|
-
"@modern-js/
|
|
103
|
-
"@modern-js/
|
|
104
|
-
"@modern-js/server
|
|
105
|
-
"@modern-js/
|
|
106
|
-
"@modern-js/server-
|
|
107
|
-
"@modern-js/
|
|
108
|
-
"@modern-js/
|
|
109
|
-
"@modern-js/
|
|
110
|
-
"@modern-js/
|
|
101
|
+
"@modern-js/builder": "npm:@bleedingdev/modern-js-builder@3.2.0-ultramodern.35",
|
|
102
|
+
"@modern-js/plugin": "npm:@bleedingdev/modern-js-plugin@3.2.0-ultramodern.35",
|
|
103
|
+
"@modern-js/plugin-data-loader": "npm:@bleedingdev/modern-js-plugin-data-loader@3.2.0-ultramodern.35",
|
|
104
|
+
"@modern-js/prod-server": "npm:@bleedingdev/modern-js-prod-server@3.2.0-ultramodern.35",
|
|
105
|
+
"@modern-js/i18n-utils": "npm:@bleedingdev/modern-js-i18n-utils@3.2.0-ultramodern.35",
|
|
106
|
+
"@modern-js/server-core": "npm:@bleedingdev/modern-js-server-core@3.2.0-ultramodern.35",
|
|
107
|
+
"@modern-js/server": "npm:@bleedingdev/modern-js-server@3.2.0-ultramodern.35",
|
|
108
|
+
"@modern-js/server-utils": "npm:@bleedingdev/modern-js-server-utils@3.2.0-ultramodern.35",
|
|
109
|
+
"@modern-js/types": "npm:@bleedingdev/modern-js-types@3.2.0-ultramodern.35",
|
|
110
|
+
"@modern-js/utils": "npm:@bleedingdev/modern-js-utils@3.2.0-ultramodern.35"
|
|
111
111
|
},
|
|
112
112
|
"devDependencies": {
|
|
113
113
|
"@rslib/core": "0.21.5",
|