@csedl/svelte-on-rails 12.3.0 → 12.3.1
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/bin/svelte-ssr-server.js +1 -6
- package/package.json +1 -1
- package/src/ssr/render.js +6 -7
- package/src/utils.js +2 -2
- package/src/ssr/loadComponent.js +0 -25
package/bin/svelte-ssr-server.js
CHANGED
|
@@ -1,10 +1,7 @@
|
|
|
1
1
|
import http from 'node:http';
|
|
2
2
|
import fs from 'node:fs';
|
|
3
|
-
import path
|
|
3
|
+
import path from 'node:path';
|
|
4
4
|
import {render} from 'svelte/server';
|
|
5
|
-
import {loadComponentModule} from "../src/ssr/loadComponent.js";
|
|
6
|
-
import {componentRenderError} from "../src/utils.js";
|
|
7
|
-
import {fileURLToPath} from "node:url";
|
|
8
5
|
|
|
9
6
|
const SOCKET_PATH = process.argv[2];
|
|
10
7
|
const PORT = (/^\d+$/.test(SOCKET_PATH) ? SOCKET_PATH : null);
|
|
@@ -91,8 +88,6 @@ const server = http.createServer(async (req, res) => {
|
|
|
91
88
|
res.writeHead(500, {'Content-Type': 'application/json'});
|
|
92
89
|
res.end(JSON.stringify({
|
|
93
90
|
status: 'FAILED',
|
|
94
|
-
html: componentRenderError(basename, err, true),
|
|
95
|
-
head: '',
|
|
96
91
|
errorLog: errorLog
|
|
97
92
|
}));
|
|
98
93
|
}
|
package/package.json
CHANGED
package/src/ssr/render.js
CHANGED
|
@@ -1,7 +1,5 @@
|
|
|
1
1
|
import {render} from 'svelte/server';
|
|
2
2
|
import {readPropsFromStdin} from "./readStdin.js";
|
|
3
|
-
import {loadComponentModule} from "./loadComponent.js";
|
|
4
|
-
import {componentRenderError} from "../utils.js";
|
|
5
3
|
|
|
6
4
|
const compiledComponentPath = process.argv[2];
|
|
7
5
|
|
|
@@ -9,10 +7,13 @@ const compiledComponentPath = process.argv[2];
|
|
|
9
7
|
(async () => {
|
|
10
8
|
|
|
11
9
|
try {
|
|
12
|
-
console.log(`Awaiting load component:
|
|
13
|
-
const
|
|
10
|
+
console.log(`Awaiting load component: ${compiledComponentPath}`);
|
|
11
|
+
const module = await import(`file://${compiledComponentPath}`);
|
|
14
12
|
|
|
15
|
-
|
|
13
|
+
const compiledComponent = module.default;
|
|
14
|
+
if (!compiledComponent) {
|
|
15
|
+
throw new Error(`Module at ${compiledComponentPath} does not export a default component`);
|
|
16
|
+
}
|
|
16
17
|
|
|
17
18
|
const props = await readPropsFromStdin();
|
|
18
19
|
console.log(`Props read: «${JSON.stringify(props)}»`);
|
|
@@ -32,8 +33,6 @@ const compiledComponentPath = process.argv[2];
|
|
|
32
33
|
|
|
33
34
|
const res = {
|
|
34
35
|
status: 'FAILED',
|
|
35
|
-
html: componentRenderError(compiledComponentPath, error, true),
|
|
36
|
-
head: '',
|
|
37
36
|
};
|
|
38
37
|
|
|
39
38
|
console.log('$$ResponseSeparator$$' + JSON.stringify(res));
|
package/src/utils.js
CHANGED
|
@@ -4,7 +4,7 @@ export function componentRenderError(component, error, ssr = false) {
|
|
|
4
4
|
const ssrHint = 'This is Server Side rendered. When Hydrated, you will see a more detailed error message.'
|
|
5
5
|
|
|
6
6
|
return (`
|
|
7
|
-
<div class="
|
|
7
|
+
<div class="client-side-svelte-render-error"
|
|
8
8
|
style="
|
|
9
9
|
padding: 1.5rem;
|
|
10
10
|
margin: 1rem 0;
|
|
@@ -14,7 +14,7 @@ export function componentRenderError(component, error, ssr = false) {
|
|
|
14
14
|
border-radius: 0.5rem;
|
|
15
15
|
font-family: system-ui, sans-serif;
|
|
16
16
|
">
|
|
17
|
-
<strong style="font-size: 1.2em;">Component failed to render${ssr ? ' server-side' : '
|
|
17
|
+
<strong style="font-size: 1.2em;">Component failed to render${ssr ? ' server-side' : ''}</strong>
|
|
18
18
|
|
|
19
19
|
<p class="error-message"
|
|
20
20
|
style="margin: 0.4rem 0 0.4rem;"
|
package/src/ssr/loadComponent.js
DELETED
|
@@ -1,25 +0,0 @@
|
|
|
1
|
-
import {fileURLToPath} from 'node:url';
|
|
2
|
-
import {dirname, resolve} from 'node:path';
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
export async function loadComponentModule(compiledFile) {
|
|
6
|
-
// Get the directory of the current script
|
|
7
|
-
const __filename = fileURLToPath(import.meta.url);
|
|
8
|
-
const __dirname = dirname(__filename);
|
|
9
|
-
|
|
10
|
-
try {
|
|
11
|
-
// Convert relative path to absolute path
|
|
12
|
-
const absolutePath = resolve(__dirname, compiledFile);
|
|
13
|
-
|
|
14
|
-
// Convert absolute path to a file URL
|
|
15
|
-
const modulePath = `file://${absolutePath}`;
|
|
16
|
-
|
|
17
|
-
// Import the module
|
|
18
|
-
const module = await import(modulePath);
|
|
19
|
-
return module.default;
|
|
20
|
-
} catch (error) {
|
|
21
|
-
console.error(`=> compiledFile: «${compiledFile}»`);
|
|
22
|
-
console.error(`[loadComponentModule] Error loading component from ${compiledFile}:`, error);
|
|
23
|
-
process.exit(1);
|
|
24
|
-
}
|
|
25
|
-
}
|