@sigil-dev/grimoire 0.7.2 → 0.7.4
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/package.json +3 -3
- package/src/rendering/ssrPlugin.ts +36 -26
package/package.json
CHANGED
|
@@ -3,7 +3,7 @@
|
|
|
3
3
|
"module": "index.ts",
|
|
4
4
|
"type": "module",
|
|
5
5
|
"private": false,
|
|
6
|
-
"version": "0.7.
|
|
6
|
+
"version": "0.7.4",
|
|
7
7
|
"devDependencies": {
|
|
8
8
|
"@types/bun": "latest"
|
|
9
9
|
},
|
|
@@ -28,8 +28,8 @@
|
|
|
28
28
|
"@babel/plugin-syntax-jsx": "^8.0.0-rc.6",
|
|
29
29
|
"@babel/plugin-syntax-typescript": "^8.0.0-rc.6",
|
|
30
30
|
"@babel/types": "^8.0.0-rc.6",
|
|
31
|
-
"@sigil-dev/compiler": "0.7.
|
|
32
|
-
"@sigil-dev/runtime": "0.7.
|
|
31
|
+
"@sigil-dev/compiler": "0.7.4",
|
|
32
|
+
"@sigil-dev/runtime": "0.7.4",
|
|
33
33
|
"vite": "^8.0.16"
|
|
34
34
|
},
|
|
35
35
|
"peerDependencies": {
|
|
@@ -1,32 +1,42 @@
|
|
|
1
|
-
// packages/grimoire/src/ssr-plugin.ts
|
|
2
1
|
import { transformSync } from "@babel/core";
|
|
3
2
|
import sigilPlugin from "@sigil-dev/compiler/babel";
|
|
3
|
+
import { createHash } from "node:crypto";
|
|
4
4
|
import type { GrimoirePlugin } from "../types";
|
|
5
5
|
|
|
6
|
+
let registered = false;
|
|
7
|
+
|
|
6
8
|
export function registerSSRPlugin(plugins: GrimoirePlugin[] = []) {
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
9
|
+
if (registered) return;
|
|
10
|
+
registered = true;
|
|
11
|
+
|
|
12
|
+
Bun.plugin({
|
|
13
|
+
name: "sigil-ssr",
|
|
14
|
+
setup(build) {
|
|
15
|
+
// loader: "ts" not "tsx" — Babel already consumed the JSX,
|
|
16
|
+
// Bun only needs to strip remaining TypeScript types
|
|
17
|
+
const transpiler = new Bun.Transpiler({ loader: "ts", target: "bun" });
|
|
18
|
+
|
|
19
|
+
build.onLoad({ filter: /\.[jt]sx$/ }, async ({ path }) => {
|
|
20
|
+
const source = await Bun.file(path).text();
|
|
21
|
+
const hash = createHash("md5").update(path).digest("hex").slice(0, 8);
|
|
22
|
+
|
|
23
|
+
const result = transformSync(source, {
|
|
24
|
+
parserOpts: {
|
|
25
|
+
plugins: ["typescript", "jsx"],
|
|
26
|
+
},
|
|
27
|
+
plugins: [[sigilPlugin, { mode: "ssr", hash }]],
|
|
28
|
+
filename: path,
|
|
29
|
+
});
|
|
30
|
+
|
|
31
|
+
let contents = transpiler.transformSync(result?.code ?? "");
|
|
32
|
+
|
|
33
|
+
for (const plugin of plugins) {
|
|
34
|
+
if (plugin.transform)
|
|
35
|
+
contents = (await plugin.transform(contents, path)) ?? contents;
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
return { contents, loader: "js" as const };
|
|
39
|
+
});
|
|
40
|
+
},
|
|
41
|
+
});
|
|
32
42
|
}
|