@sigil-dev/grimoire 0.9.22 → 0.9.24
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 +9 -8
- package/src/client/deferred.ts +1 -1
- package/src/client/router.ts +1 -0
- package/src/rendering/preload.ts +1 -0
- package/src/rendering/ssrPlugin.ts +108 -108
- package/src/server/index.ts +1154 -1138
- package/src/server/plugin-routes.ts +38 -0
- package/src/server/resolver.ts +5 -1
- package/src/types.ts +7 -0
- package/test/env.test.ts +4 -1
- package/test/parser-plugins.test.ts +92 -92
- package/test/plugin-routes.test.ts +42 -0
- package/test/rendering.test.ts +2 -1
- package/test/resolver-windows.test.ts +23 -0
- package/test/streaming.test.ts +4 -1
- package/test/typegen.test.ts +3 -0
- package/test/workspace-versions.test.ts +131 -131
package/package.json
CHANGED
|
@@ -11,7 +11,7 @@
|
|
|
11
11
|
"module": "index.ts",
|
|
12
12
|
"type": "module",
|
|
13
13
|
"private": false,
|
|
14
|
-
"version": "0.9.
|
|
14
|
+
"version": "0.9.24",
|
|
15
15
|
"exports": {
|
|
16
16
|
".": "./index.ts",
|
|
17
17
|
"./server": "./server.ts",
|
|
@@ -35,8 +35,8 @@
|
|
|
35
35
|
"test": "bun test"
|
|
36
36
|
},
|
|
37
37
|
"dependencies": {
|
|
38
|
-
"@sigil-dev/compiler": "0.9.
|
|
39
|
-
"@sigil-dev/runtime": "0.9.
|
|
38
|
+
"@sigil-dev/compiler": "0.9.24",
|
|
39
|
+
"@sigil-dev/runtime": "0.9.24",
|
|
40
40
|
"vite": "^8.0.16"
|
|
41
41
|
},
|
|
42
42
|
"peerDependencies": {
|
|
@@ -49,11 +49,12 @@
|
|
|
49
49
|
}
|
|
50
50
|
},
|
|
51
51
|
"devDependencies": {
|
|
52
|
-
"@babel/core": "8.0.
|
|
53
|
-
"@babel/
|
|
54
|
-
"@babel/plugin-syntax-
|
|
55
|
-
"@babel/
|
|
56
|
-
"@babel/
|
|
52
|
+
"@babel/core": "^8.0.7",
|
|
53
|
+
"@babel/parser": "^8.0.7",
|
|
54
|
+
"@babel/plugin-syntax-jsx": "^8.0.1",
|
|
55
|
+
"@babel/plugin-syntax-typescript": "^8.0.3",
|
|
56
|
+
"@babel/preset-typescript": "^8.0.7",
|
|
57
|
+
"@babel/types": "^8.0.6",
|
|
57
58
|
"@types/bun": "latest"
|
|
58
59
|
}
|
|
59
60
|
}
|
package/src/client/deferred.ts
CHANGED
|
@@ -69,7 +69,7 @@ function readDeferredValue<T>(key?: string): T | undefined {
|
|
|
69
69
|
// mirror does not. Reading the wrong one silently loses the value, so
|
|
70
70
|
// this guard is the difference between working and not.
|
|
71
71
|
if (!held) return undefined;
|
|
72
|
-
const data =
|
|
72
|
+
const data = "nodeType" in held ? undefined : held.data;
|
|
73
73
|
if (!data) return undefined;
|
|
74
74
|
if (key !== undefined) {
|
|
75
75
|
const one = data[key];
|
package/src/client/router.ts
CHANGED
package/src/rendering/preload.ts
CHANGED
|
@@ -1,108 +1,108 @@
|
|
|
1
|
-
import { transformSync } from "@babel/core";
|
|
2
|
-
import sigilPlugin from "@sigil-dev/compiler/babel";
|
|
3
|
-
import {
|
|
4
|
-
computeHash,
|
|
5
|
-
extractStyles,
|
|
6
|
-
serverStyleSnippet,
|
|
7
|
-
} from "@sigil-dev/compiler/css";
|
|
8
|
-
import { log } from "../logger/instance";
|
|
9
|
-
import { rewriteAliases } from "../server/resolver";
|
|
10
|
-
import type { GrimoirePlugin } from "../types";
|
|
11
|
-
import type { ParserPlugin } from "@babel/
|
|
12
|
-
|
|
13
|
-
const logger = log.scope("scope");
|
|
14
|
-
let registered = false;
|
|
15
|
-
|
|
16
|
-
/**
|
|
17
|
-
* `aliases` (prefix → absolute directory, see projectAliases) are rewritten
|
|
18
|
-
* to file paths in every compiled module: Bun's runtime plugins can't
|
|
19
|
-
* resolve them for static imports.
|
|
20
|
-
*/
|
|
21
|
-
export function registerSSRPlugin(
|
|
22
|
-
plugins: GrimoirePlugin[] = [],
|
|
23
|
-
aliases: Record<string, string> = {},
|
|
24
|
-
) {
|
|
25
|
-
if (registered) return;
|
|
26
|
-
registered = true;
|
|
27
|
-
|
|
28
|
-
Bun.plugin({
|
|
29
|
-
name: "sigil-ssr",
|
|
30
|
-
|
|
31
|
-
setup(build) {
|
|
32
|
-
// loader: "ts" not "tsx" — Babel already consumed the JSX,
|
|
33
|
-
// Bun only needs to strip remaining TypeScript types
|
|
34
|
-
const transpiler = new Bun.Transpiler({ loader: "ts", target: "bun" });
|
|
35
|
-
build.onResolve({ filter: /^@sigil-dev\/runtime($|\/)/ }, (args) => {
|
|
36
|
-
try {
|
|
37
|
-
const resolved = Bun.resolveSync(args.path, process.cwd());
|
|
38
|
-
return { path: resolved.replaceAll("\\", "/") };
|
|
39
|
-
} catch {
|
|
40
|
-
return undefined;
|
|
41
|
-
}
|
|
42
|
-
});
|
|
43
|
-
|
|
44
|
-
build.onLoad({ filter: /\.tsx?$/ }, async ({ path }) => {
|
|
45
|
-
if (path.includes("index.tsx"))
|
|
46
|
-
logger.debug("[ssr-plugin] onLoad:", path);
|
|
47
|
-
const source = await Bun.file(path).text();
|
|
48
|
-
|
|
49
|
-
// node_modules and .grimoire files are plain TypeScript (no sigil JSX).
|
|
50
|
-
// Still must return { contents, loader } — never return undefined from onLoad.
|
|
51
|
-
if (path.includes("node_modules") || path.includes(".grimoire")) {
|
|
52
|
-
return {
|
|
53
|
-
contents: transpiler.transformSync(source),
|
|
54
|
-
loader: "js" as const,
|
|
55
|
-
};
|
|
56
|
-
}
|
|
57
|
-
|
|
58
|
-
if (process.env.SIGIL_VERBOSE) {
|
|
59
|
-
logger.debug("[sigil-ssr] XFORM:", path);
|
|
60
|
-
}
|
|
61
|
-
// must match the client build, or scoped classes differ per side;
|
|
62
|
-
// files without a <style> block get no scope class at all. The
|
|
63
|
-
// CSS is registered for the renderer, which puts it in <head>.
|
|
64
|
-
const styles = extractStyles(source, computeHash(path), path);
|
|
65
|
-
const hash = styles.css ? computeHash(path) : undefined;
|
|
66
|
-
const sourceNoStyle = styles.code;
|
|
67
|
-
const result = transformSync(sourceNoStyle, {
|
|
68
|
-
configFile: false,
|
|
69
|
-
babelrc: false,
|
|
70
|
-
parserOpts: {
|
|
71
|
-
// The jsx plugin goes on .tsx files only.
|
|
72
|
-
//
|
|
73
|
-
// With it enabled everywhere, Babel parses `<R>(x: R) => x`
|
|
74
|
-
// as the opening of a JSX element and fails with
|
|
75
|
-
// "Unexpected token `>`". So a generic arrow function in a
|
|
76
|
-
// plain .ts file — completely ordinary TypeScript — could
|
|
77
|
-
// not be compiled. Found while writing the Drizzle adapter
|
|
78
|
-
// recipe, where `transaction: <R>(db, fn) => ...` is the
|
|
79
|
-
// form that removes an `as any`.
|
|
80
|
-
//
|
|
81
|
-
// A .tsx file is genuinely ambiguous (`<R>(x) => x` is
|
|
82
|
-
// JSX there), so .tsx keeps both and users write `<R,>`.
|
|
83
|
-
plugins: path.endsWith(".tsx")
|
|
84
|
-
? (["typescript", "jsx"] as ParserPlugin[])
|
|
85
|
-
: (["typescript"] as ParserPlugin[]),
|
|
86
|
-
},
|
|
87
|
-
plugins: [[sigilPlugin, { mode: "ssr", hash }]],
|
|
88
|
-
filename: path,
|
|
89
|
-
});
|
|
90
|
-
|
|
91
|
-
let contents = rewriteAliases(
|
|
92
|
-
transpiler.transformSync(result?.code ?? ""),
|
|
93
|
-
aliases,
|
|
94
|
-
);
|
|
95
|
-
if (styles.css && hash) {
|
|
96
|
-
contents = serverStyleSnippet(hash, styles.css) + contents;
|
|
97
|
-
}
|
|
98
|
-
|
|
99
|
-
for (const plugin of plugins) {
|
|
100
|
-
if (plugin.transform)
|
|
101
|
-
contents = (await plugin.transform(contents, path)) ?? contents;
|
|
102
|
-
}
|
|
103
|
-
|
|
104
|
-
return { contents, loader: "js" as const };
|
|
105
|
-
});
|
|
106
|
-
},
|
|
107
|
-
});
|
|
108
|
-
}
|
|
1
|
+
import { transformSync } from "@babel/core";
|
|
2
|
+
import sigilPlugin from "@sigil-dev/compiler/babel";
|
|
3
|
+
import {
|
|
4
|
+
computeHash,
|
|
5
|
+
extractStyles,
|
|
6
|
+
serverStyleSnippet,
|
|
7
|
+
} from "@sigil-dev/compiler/css";
|
|
8
|
+
import { log } from "../logger/instance";
|
|
9
|
+
import { rewriteAliases } from "../server/resolver";
|
|
10
|
+
import type { GrimoirePlugin } from "../types";
|
|
11
|
+
import type { ParserPlugin } from "@babel/parser";
|
|
12
|
+
|
|
13
|
+
const logger = log.scope("scope");
|
|
14
|
+
let registered = false;
|
|
15
|
+
|
|
16
|
+
/**
|
|
17
|
+
* `aliases` (prefix → absolute directory, see projectAliases) are rewritten
|
|
18
|
+
* to file paths in every compiled module: Bun's runtime plugins can't
|
|
19
|
+
* resolve them for static imports.
|
|
20
|
+
*/
|
|
21
|
+
export function registerSSRPlugin(
|
|
22
|
+
plugins: GrimoirePlugin[] = [],
|
|
23
|
+
aliases: Record<string, string> = {},
|
|
24
|
+
) {
|
|
25
|
+
if (registered) return;
|
|
26
|
+
registered = true;
|
|
27
|
+
|
|
28
|
+
Bun.plugin({
|
|
29
|
+
name: "sigil-ssr",
|
|
30
|
+
|
|
31
|
+
setup(build) {
|
|
32
|
+
// loader: "ts" not "tsx" — Babel already consumed the JSX,
|
|
33
|
+
// Bun only needs to strip remaining TypeScript types
|
|
34
|
+
const transpiler = new Bun.Transpiler({ loader: "ts", target: "bun" });
|
|
35
|
+
build.onResolve({ filter: /^@sigil-dev\/runtime($|\/)/ }, (args) => {
|
|
36
|
+
try {
|
|
37
|
+
const resolved = Bun.resolveSync(args.path, process.cwd());
|
|
38
|
+
return { path: resolved.replaceAll("\\", "/") };
|
|
39
|
+
} catch {
|
|
40
|
+
return undefined;
|
|
41
|
+
}
|
|
42
|
+
});
|
|
43
|
+
|
|
44
|
+
build.onLoad({ filter: /\.tsx?$/ }, async ({ path }) => {
|
|
45
|
+
if (path.includes("index.tsx"))
|
|
46
|
+
logger.debug("[ssr-plugin] onLoad:", path);
|
|
47
|
+
const source = await Bun.file(path).text();
|
|
48
|
+
|
|
49
|
+
// node_modules and .grimoire files are plain TypeScript (no sigil JSX).
|
|
50
|
+
// Still must return { contents, loader } — never return undefined from onLoad.
|
|
51
|
+
if (path.includes("node_modules") || path.includes(".grimoire")) {
|
|
52
|
+
return {
|
|
53
|
+
contents: transpiler.transformSync(source),
|
|
54
|
+
loader: "js" as const,
|
|
55
|
+
};
|
|
56
|
+
}
|
|
57
|
+
|
|
58
|
+
if (process.env.SIGIL_VERBOSE) {
|
|
59
|
+
logger.debug("[sigil-ssr] XFORM:", path);
|
|
60
|
+
}
|
|
61
|
+
// must match the client build, or scoped classes differ per side;
|
|
62
|
+
// files without a <style> block get no scope class at all. The
|
|
63
|
+
// CSS is registered for the renderer, which puts it in <head>.
|
|
64
|
+
const styles = extractStyles(source, computeHash(path), path);
|
|
65
|
+
const hash = styles.css ? computeHash(path) : undefined;
|
|
66
|
+
const sourceNoStyle = styles.code;
|
|
67
|
+
const result = transformSync(sourceNoStyle, {
|
|
68
|
+
configFile: false,
|
|
69
|
+
babelrc: false,
|
|
70
|
+
parserOpts: {
|
|
71
|
+
// The jsx plugin goes on .tsx files only.
|
|
72
|
+
//
|
|
73
|
+
// With it enabled everywhere, Babel parses `<R>(x: R) => x`
|
|
74
|
+
// as the opening of a JSX element and fails with
|
|
75
|
+
// "Unexpected token `>`". So a generic arrow function in a
|
|
76
|
+
// plain .ts file — completely ordinary TypeScript — could
|
|
77
|
+
// not be compiled. Found while writing the Drizzle adapter
|
|
78
|
+
// recipe, where `transaction: <R>(db, fn) => ...` is the
|
|
79
|
+
// form that removes an `as any`.
|
|
80
|
+
//
|
|
81
|
+
// A .tsx file is genuinely ambiguous (`<R>(x) => x` is
|
|
82
|
+
// JSX there), so .tsx keeps both and users write `<R,>`.
|
|
83
|
+
plugins: path.endsWith(".tsx")
|
|
84
|
+
? (["typescript", "jsx"] as ParserPlugin[])
|
|
85
|
+
: (["typescript"] as ParserPlugin[]),
|
|
86
|
+
},
|
|
87
|
+
plugins: [[sigilPlugin, { mode: "ssr", hash }]],
|
|
88
|
+
filename: path,
|
|
89
|
+
});
|
|
90
|
+
|
|
91
|
+
let contents = rewriteAliases(
|
|
92
|
+
transpiler.transformSync(result?.code ?? ""),
|
|
93
|
+
aliases,
|
|
94
|
+
);
|
|
95
|
+
if (styles.css && hash) {
|
|
96
|
+
contents = serverStyleSnippet(hash, styles.css) + contents;
|
|
97
|
+
}
|
|
98
|
+
|
|
99
|
+
for (const plugin of plugins) {
|
|
100
|
+
if (plugin.transform)
|
|
101
|
+
contents = (await plugin.transform(contents, path)) ?? contents;
|
|
102
|
+
}
|
|
103
|
+
|
|
104
|
+
return { contents, loader: "js" as const };
|
|
105
|
+
});
|
|
106
|
+
},
|
|
107
|
+
});
|
|
108
|
+
}
|