@sigil-dev/grimoire 0.7.3 → 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 CHANGED
@@ -3,7 +3,7 @@
3
3
  "module": "index.ts",
4
4
  "type": "module",
5
5
  "private": false,
6
- "version": "0.7.3",
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.3",
32
- "@sigil-dev/runtime": "0.7.3",
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
- Bun.plugin({
8
- name: "sigil-ssr",
9
- setup(build) {
10
- const transpiler = new Bun.Transpiler({ loader: "tsx", target: "bun" });
11
- build.onLoad({ filter: /\.[jt]sx$/ }, async ({ path }) => {
12
- const source = await Bun.file(path).text();
13
- const result = transformSync(source, {
14
- parserOpts: {
15
- plugins: [["typescript", { isTSX: true }], "jsx"],
16
- },
17
- plugins: [[sigilPlugin, { mode: "ssr" }]],
18
- filename: path,
19
- });
20
- let contents = transpiler.transformSync(result?.code ?? "");
21
- for (const plugin of plugins) {
22
- if (plugin.transform)
23
- contents = (await plugin.transform(contents, path)) ?? contents;
24
- }
25
- return {
26
- contents,
27
- loader: "js" as const,
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
  }