@sigil-dev/grimoire 0.9.2 → 0.9.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/index.ts +37 -35
- package/package.json +9 -12
- package/preload.js +3 -3
- package/server.ts +19 -19
- package/src/client/deps.ts +31 -8
- package/src/client/enhance.ts +102 -98
- package/src/client/head.ts +30 -30
- package/src/client/index.ts +5 -5
- package/src/client/router.ts +529 -371
- package/src/client/scope.ts +22 -22
- package/src/dev/compile-module.ts +163 -163
- package/src/dev/effect-registry.ts +23 -23
- package/src/dev/graph.ts +114 -114
- package/src/dev/hmr-client.ts +185 -185
- package/src/dev/loader.ts +47 -47
- package/src/dev/paths.ts +14 -14
- package/src/dev/runtime-bundle.ts +52 -52
- package/src/dev/watcher.ts +47 -46
- package/src/env/dynamic-private.ts +19 -19
- package/src/env/dynamic-public.ts +22 -22
- package/src/env/index.ts +25 -25
- package/src/env/plugin.ts +19 -19
- package/src/env/private.ts +5 -5
- package/src/env/public.ts +7 -7
- package/src/env/typegen.ts +61 -61
- package/src/headers.ts +114 -114
- package/src/integrations/vite.ts +73 -73
- package/src/logger/index.ts +4 -4
- package/src/logger/instance.ts +6 -6
- package/src/logger/logger.ts +113 -113
- package/src/logger/request-middleware.ts +24 -24
- package/src/logger/transports.ts +117 -117
- package/src/logger/types.ts +39 -39
- package/src/rendering/head.ts +47 -47
- package/src/rendering/hydrate.ts +146 -119
- package/src/rendering/index.ts +573 -372
- package/src/rendering/ssrPlugin.ts +69 -69
- package/src/routing/manifest-gen.ts +55 -42
- package/src/routing/router.ts +135 -109
- package/src/routing/scanner.ts +187 -141
- package/src/routing/transform-routes.ts +102 -102
- package/src/sentinels/error.ts +52 -52
- package/src/sentinels/fail.ts +41 -41
- package/src/sentinels/redirect.ts +35 -35
- package/src/server/build.ts +255 -219
- package/src/server/context.ts +10 -10
- package/src/server/cookie-utils.ts +66 -66
- package/src/server/coordinator.ts +364 -356
- package/src/server/hooks.ts +114 -114
- package/src/server/index.ts +677 -658
- package/src/server/interactive.ts +56 -56
- package/src/server/plugins.ts +121 -120
- package/src/server/worker.ts +58 -58
- package/src/typegen/index.ts +389 -356
- package/src/types.ts +8 -4
- package/test/client-router.test.ts +295 -35
- package/test/context.test.ts +52 -52
- package/test/env.test.ts +70 -70
- package/test/exports.test.ts +37 -37
- package/test/fail.test.ts +46 -46
- package/test/headers.test.ts +100 -100
- package/test/hydration.test.ts +119 -119
- package/test/middleware.test.ts +223 -223
- package/test/preload.ts +5 -5
- package/test/redirect-error.test.ts +112 -112
- package/test/rendering.test.ts +728 -579
- package/test/routing.test.ts +194 -81
- package/test/scanning.test.ts +254 -200
- package/test/scope.test.ts +195 -195
- package/test/server.test.ts +354 -249
- package/test/streaming.test.ts +242 -125
- package/test/transform-routes.test.ts +87 -84
- package/test/typegen.test.ts +697 -682
- package/tsconfig.json +10 -10
- package/.grimoire/_routes.dom.js +0 -8
- package/.grimoire/_routes.hydrate.js +0 -8
- package/.grimoire/tsconfig.generated.json +0 -11
- package/.grimoire/types/ambient.d.ts +0 -59
- package/.grimoire/types/api/hello/$types.d.ts +0 -50
- package/.grimoire/types/api/items/$types.d.ts +0 -50
- package/.grimoire/types/echo/$types.d.ts +0 -50
- package/.grimoire/types/env-private.d.ts +0 -5
- package/.grimoire/types/env-public.d.ts +0 -5
- package/.grimoire/types/mixed/$types.d.ts +0 -50
- package/.grimoire/types/params/[docId]/$types.d.ts +0 -52
- package/.grimoire/types/reject/$types.d.ts +0 -50
- package/public/__grimoire__/hydrate.js +0 -585
- package/public/__grimoire__/index.js +0 -490
package/src/logger/transports.ts
CHANGED
|
@@ -1,117 +1,117 @@
|
|
|
1
|
-
// packages/grimoire/src/logger/transports.ts
|
|
2
|
-
|
|
3
|
-
import { appendFileSync } from "node:fs";
|
|
4
|
-
import type { LogEntry, LogTransport } from "./types.ts";
|
|
5
|
-
|
|
6
|
-
// ── colours (only applied when stdout is a TTY) ──────────────────────────────
|
|
7
|
-
|
|
8
|
-
const isTTY = process.stdout.isTTY;
|
|
9
|
-
const c = isTTY
|
|
10
|
-
? {
|
|
11
|
-
reset: "\x1b[0m",
|
|
12
|
-
dim: "\x1b[2m",
|
|
13
|
-
bold: "\x1b[1m",
|
|
14
|
-
debug: "\x1b[90m", // grey
|
|
15
|
-
info: "\x1b[36m", // cyan
|
|
16
|
-
warn: "\x1b[33m", // yellow
|
|
17
|
-
error: "\x1b[31m", // red
|
|
18
|
-
fatal: "\x1b[35m", // magenta
|
|
19
|
-
scope: "\x1b[34m", // blue
|
|
20
|
-
req: "\x1b[32m", // green
|
|
21
|
-
}
|
|
22
|
-
: (Object.fromEntries(
|
|
23
|
-
[
|
|
24
|
-
"reset",
|
|
25
|
-
"dim",
|
|
26
|
-
"bold",
|
|
27
|
-
"debug",
|
|
28
|
-
"info",
|
|
29
|
-
"warn",
|
|
30
|
-
"error",
|
|
31
|
-
"fatal",
|
|
32
|
-
"scope",
|
|
33
|
-
"req",
|
|
34
|
-
].map((k) => [k, ""]),
|
|
35
|
-
) as Record<string, string>);
|
|
36
|
-
|
|
37
|
-
const LEVEL_LABEL: Record<string, string> = {
|
|
38
|
-
debug: "DBG",
|
|
39
|
-
info: "INF",
|
|
40
|
-
warn: "WRN",
|
|
41
|
-
error: "ERR",
|
|
42
|
-
fatal: "FTL",
|
|
43
|
-
};
|
|
44
|
-
|
|
45
|
-
function ts(timestamp: number): string {
|
|
46
|
-
return new Date(timestamp).toISOString().slice(11, 23); // HH:mm:ss.ms
|
|
47
|
-
}
|
|
48
|
-
|
|
49
|
-
function formatData(data: unknown): string {
|
|
50
|
-
if (data === undefined) return "";
|
|
51
|
-
if (data instanceof Error) return `\n ${data.stack ?? data.message}`;
|
|
52
|
-
if (typeof data !== "object" || data === null) return ` ${String(data)}`;
|
|
53
|
-
|
|
54
|
-
// flat key=value for simple objects, JSON block only for nested/complex
|
|
55
|
-
const entries = Object.entries(data as Record<string, unknown>);
|
|
56
|
-
const isFlat = entries.every(([, v]) => typeof v !== "object" || v === null);
|
|
57
|
-
if (isFlat) {
|
|
58
|
-
return ` ${entries.map(([k, v]) => `${colors.dim(`${k}=`)}${v}`).join(" ")}`;
|
|
59
|
-
}
|
|
60
|
-
// nested — indent but don't pretty-print the whole thing
|
|
61
|
-
return `\n ${JSON.stringify(data).replace(/,/g, ", ")}`;
|
|
62
|
-
}
|
|
63
|
-
|
|
64
|
-
// ── ConsoleTransport ─────────────────────────────────────────────────────────
|
|
65
|
-
|
|
66
|
-
export class ConsoleTransport implements LogTransport {
|
|
67
|
-
write(entry: LogEntry) {
|
|
68
|
-
const levelColor = c[entry.level] ?? c.info;
|
|
69
|
-
const label = LEVEL_LABEL[entry.level] ?? entry.level.toUpperCase();
|
|
70
|
-
|
|
71
|
-
const worker = entry.worker ? `${c.dim}[${entry.worker}]${c.reset} ` : "";
|
|
72
|
-
const requestId = entry.requestId
|
|
73
|
-
? `${c.req}#${entry.requestId.slice(0, 8)}${c.reset} `
|
|
74
|
-
: "";
|
|
75
|
-
const scope = `${c.scope}${entry.scope}${c.reset}`;
|
|
76
|
-
const time = `${c.dim}${ts(entry.timestamp)}${c.reset}`;
|
|
77
|
-
const lvl = `${levelColor}${c.bold}${label}${c.reset}`;
|
|
78
|
-
const msg = entry.message;
|
|
79
|
-
const data = formatData(entry.data);
|
|
80
|
-
|
|
81
|
-
const line = `${time} ${lvl} ${worker}${requestId}${scope} ${msg}${data}`;
|
|
82
|
-
|
|
83
|
-
if (entry.level === "error" || entry.level === "fatal") {
|
|
84
|
-
process.stderr.write(`${line}\n`);
|
|
85
|
-
} else {
|
|
86
|
-
process.stdout.write(`${line}\n`);
|
|
87
|
-
}
|
|
88
|
-
}
|
|
89
|
-
}
|
|
90
|
-
|
|
91
|
-
// ── FileTransport ────────────────────────────────────────────────────────────
|
|
92
|
-
// Writes newline-delimited JSON for ingestion by log collectors.
|
|
93
|
-
|
|
94
|
-
export class FileTransport implements LogTransport {
|
|
95
|
-
constructor(private path: string) {}
|
|
96
|
-
|
|
97
|
-
write(entry: LogEntry) {
|
|
98
|
-
try {
|
|
99
|
-
appendFileSync(this.path, `${JSON.stringify(entry)}\n`);
|
|
100
|
-
} catch {
|
|
101
|
-
// if the file write fails we can't really do anything useful
|
|
102
|
-
}
|
|
103
|
-
}
|
|
104
|
-
}
|
|
105
|
-
|
|
106
|
-
// ── NullTransport ────────────────────────────────────────────────────────────
|
|
107
|
-
// For tests — captures entries instead of printing them.
|
|
108
|
-
|
|
109
|
-
export class NullTransport implements LogTransport {
|
|
110
|
-
readonly entries: LogEntry[] = [];
|
|
111
|
-
write(entry: LogEntry) {
|
|
112
|
-
this.entries.push(entry);
|
|
113
|
-
}
|
|
114
|
-
clear() {
|
|
115
|
-
this.entries.length = 0;
|
|
116
|
-
}
|
|
117
|
-
}
|
|
1
|
+
// packages/grimoire/src/logger/transports.ts
|
|
2
|
+
|
|
3
|
+
import { appendFileSync } from "node:fs";
|
|
4
|
+
import type { LogEntry, LogTransport } from "./types.ts";
|
|
5
|
+
|
|
6
|
+
// ── colours (only applied when stdout is a TTY) ──────────────────────────────
|
|
7
|
+
|
|
8
|
+
const isTTY = process.stdout.isTTY;
|
|
9
|
+
const c = isTTY
|
|
10
|
+
? {
|
|
11
|
+
reset: "\x1b[0m",
|
|
12
|
+
dim: "\x1b[2m",
|
|
13
|
+
bold: "\x1b[1m",
|
|
14
|
+
debug: "\x1b[90m", // grey
|
|
15
|
+
info: "\x1b[36m", // cyan
|
|
16
|
+
warn: "\x1b[33m", // yellow
|
|
17
|
+
error: "\x1b[31m", // red
|
|
18
|
+
fatal: "\x1b[35m", // magenta
|
|
19
|
+
scope: "\x1b[34m", // blue
|
|
20
|
+
req: "\x1b[32m", // green
|
|
21
|
+
}
|
|
22
|
+
: (Object.fromEntries(
|
|
23
|
+
[
|
|
24
|
+
"reset",
|
|
25
|
+
"dim",
|
|
26
|
+
"bold",
|
|
27
|
+
"debug",
|
|
28
|
+
"info",
|
|
29
|
+
"warn",
|
|
30
|
+
"error",
|
|
31
|
+
"fatal",
|
|
32
|
+
"scope",
|
|
33
|
+
"req",
|
|
34
|
+
].map((k) => [k, ""]),
|
|
35
|
+
) as Record<string, string>);
|
|
36
|
+
|
|
37
|
+
const LEVEL_LABEL: Record<string, string> = {
|
|
38
|
+
debug: "DBG",
|
|
39
|
+
info: "INF",
|
|
40
|
+
warn: "WRN",
|
|
41
|
+
error: "ERR",
|
|
42
|
+
fatal: "FTL",
|
|
43
|
+
};
|
|
44
|
+
|
|
45
|
+
function ts(timestamp: number): string {
|
|
46
|
+
return new Date(timestamp).toISOString().slice(11, 23); // HH:mm:ss.ms
|
|
47
|
+
}
|
|
48
|
+
|
|
49
|
+
function formatData(data: unknown): string {
|
|
50
|
+
if (data === undefined) return "";
|
|
51
|
+
if (data instanceof Error) return `\n ${data.stack ?? data.message}`;
|
|
52
|
+
if (typeof data !== "object" || data === null) return ` ${String(data)}`;
|
|
53
|
+
|
|
54
|
+
// flat key=value for simple objects, JSON block only for nested/complex
|
|
55
|
+
const entries = Object.entries(data as Record<string, unknown>);
|
|
56
|
+
const isFlat = entries.every(([, v]) => typeof v !== "object" || v === null);
|
|
57
|
+
if (isFlat) {
|
|
58
|
+
return ` ${entries.map(([k, v]) => `${colors.dim(`${k}=`)}${v}`).join(" ")}`;
|
|
59
|
+
}
|
|
60
|
+
// nested — indent but don't pretty-print the whole thing
|
|
61
|
+
return `\n ${JSON.stringify(data).replace(/,/g, ", ")}`;
|
|
62
|
+
}
|
|
63
|
+
|
|
64
|
+
// ── ConsoleTransport ─────────────────────────────────────────────────────────
|
|
65
|
+
|
|
66
|
+
export class ConsoleTransport implements LogTransport {
|
|
67
|
+
write(entry: LogEntry) {
|
|
68
|
+
const levelColor = c[entry.level] ?? c.info;
|
|
69
|
+
const label = LEVEL_LABEL[entry.level] ?? entry.level.toUpperCase();
|
|
70
|
+
|
|
71
|
+
const worker = entry.worker ? `${c.dim}[${entry.worker}]${c.reset} ` : "";
|
|
72
|
+
const requestId = entry.requestId
|
|
73
|
+
? `${c.req}#${entry.requestId.slice(0, 8)}${c.reset} `
|
|
74
|
+
: "";
|
|
75
|
+
const scope = `${c.scope}${entry.scope}${c.reset}`;
|
|
76
|
+
const time = `${c.dim}${ts(entry.timestamp)}${c.reset}`;
|
|
77
|
+
const lvl = `${levelColor}${c.bold}${label}${c.reset}`;
|
|
78
|
+
const msg = entry.message;
|
|
79
|
+
const data = formatData(entry.data);
|
|
80
|
+
|
|
81
|
+
const line = `${time} ${lvl} ${worker}${requestId}${scope} ${msg}${data}`;
|
|
82
|
+
|
|
83
|
+
if (entry.level === "error" || entry.level === "fatal") {
|
|
84
|
+
process.stderr.write(`${line}\n`);
|
|
85
|
+
} else {
|
|
86
|
+
process.stdout.write(`${line}\n`);
|
|
87
|
+
}
|
|
88
|
+
}
|
|
89
|
+
}
|
|
90
|
+
|
|
91
|
+
// ── FileTransport ────────────────────────────────────────────────────────────
|
|
92
|
+
// Writes newline-delimited JSON for ingestion by log collectors.
|
|
93
|
+
|
|
94
|
+
export class FileTransport implements LogTransport {
|
|
95
|
+
constructor(private path: string) {}
|
|
96
|
+
|
|
97
|
+
write(entry: LogEntry) {
|
|
98
|
+
try {
|
|
99
|
+
appendFileSync(this.path, `${JSON.stringify(entry)}\n`);
|
|
100
|
+
} catch {
|
|
101
|
+
// if the file write fails we can't really do anything useful
|
|
102
|
+
}
|
|
103
|
+
}
|
|
104
|
+
}
|
|
105
|
+
|
|
106
|
+
// ── NullTransport ────────────────────────────────────────────────────────────
|
|
107
|
+
// For tests — captures entries instead of printing them.
|
|
108
|
+
|
|
109
|
+
export class NullTransport implements LogTransport {
|
|
110
|
+
readonly entries: LogEntry[] = [];
|
|
111
|
+
write(entry: LogEntry) {
|
|
112
|
+
this.entries.push(entry);
|
|
113
|
+
}
|
|
114
|
+
clear() {
|
|
115
|
+
this.entries.length = 0;
|
|
116
|
+
}
|
|
117
|
+
}
|
package/src/logger/types.ts
CHANGED
|
@@ -1,39 +1,39 @@
|
|
|
1
|
-
export type LogLevel = "debug" | "info" | "warn" | "error" | "fatal";
|
|
2
|
-
|
|
3
|
-
export const LOG_LEVELS: Record<LogLevel, number> = {
|
|
4
|
-
debug: 0,
|
|
5
|
-
info: 1,
|
|
6
|
-
warn: 2,
|
|
7
|
-
error: 3,
|
|
8
|
-
fatal: 4,
|
|
9
|
-
};
|
|
10
|
-
|
|
11
|
-
export interface LogEntry {
|
|
12
|
-
level: LogLevel;
|
|
13
|
-
scope: string;
|
|
14
|
-
message: string;
|
|
15
|
-
data?: unknown;
|
|
16
|
-
timestamp: number;
|
|
17
|
-
worker?: string; // injected by loom, e.g. "violet"
|
|
18
|
-
requestId?: string; // injected per-request by middleware
|
|
19
|
-
}
|
|
20
|
-
|
|
21
|
-
export interface LogTransport {
|
|
22
|
-
write(entry: LogEntry): void | Promise<void>;
|
|
23
|
-
}
|
|
24
|
-
|
|
25
|
-
export interface ScopedLogger {
|
|
26
|
-
debug(message: string, ...args: unknown[]): void;
|
|
27
|
-
info(message: string, ...args: unknown[]): void;
|
|
28
|
-
warn(message: string, ...args: unknown[]): void;
|
|
29
|
-
error(message: string, ...args: unknown[]): void;
|
|
30
|
-
fatal(message: string, ...args: unknown[]): void;
|
|
31
|
-
scope(name: string): ScopedLogger;
|
|
32
|
-
withRequest(requestId: string): ScopedLogger;
|
|
33
|
-
}
|
|
34
|
-
|
|
35
|
-
export interface LoggerOptions {
|
|
36
|
-
transports?: LogTransport[];
|
|
37
|
-
level?: LogLevel;
|
|
38
|
-
filter?: (entry: LogEntry) => boolean;
|
|
39
|
-
}
|
|
1
|
+
export type LogLevel = "debug" | "info" | "warn" | "error" | "fatal";
|
|
2
|
+
|
|
3
|
+
export const LOG_LEVELS: Record<LogLevel, number> = {
|
|
4
|
+
debug: 0,
|
|
5
|
+
info: 1,
|
|
6
|
+
warn: 2,
|
|
7
|
+
error: 3,
|
|
8
|
+
fatal: 4,
|
|
9
|
+
};
|
|
10
|
+
|
|
11
|
+
export interface LogEntry {
|
|
12
|
+
level: LogLevel;
|
|
13
|
+
scope: string;
|
|
14
|
+
message: string;
|
|
15
|
+
data?: unknown;
|
|
16
|
+
timestamp: number;
|
|
17
|
+
worker?: string; // injected by loom, e.g. "violet"
|
|
18
|
+
requestId?: string; // injected per-request by middleware
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
export interface LogTransport {
|
|
22
|
+
write(entry: LogEntry): void | Promise<void>;
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
export interface ScopedLogger {
|
|
26
|
+
debug(message: string, ...args: unknown[]): void;
|
|
27
|
+
info(message: string, ...args: unknown[]): void;
|
|
28
|
+
warn(message: string, ...args: unknown[]): void;
|
|
29
|
+
error(message: string, ...args: unknown[]): void;
|
|
30
|
+
fatal(message: string, ...args: unknown[]): void;
|
|
31
|
+
scope(name: string): ScopedLogger;
|
|
32
|
+
withRequest(requestId: string): ScopedLogger;
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
export interface LoggerOptions {
|
|
36
|
+
transports?: LogTransport[];
|
|
37
|
+
level?: LogLevel;
|
|
38
|
+
filter?: (entry: LogEntry) => boolean;
|
|
39
|
+
}
|
package/src/rendering/head.ts
CHANGED
|
@@ -1,47 +1,47 @@
|
|
|
1
|
-
import { createContext, getContext, setContext } from "@sigil-dev/runtime";
|
|
2
|
-
|
|
3
|
-
const HeadKey = createContext<string[]>();
|
|
4
|
-
const NonceKey = createContext<string>();
|
|
5
|
-
|
|
6
|
-
export function initHead(nonce?: string): void {
|
|
7
|
-
setContext(HeadKey, []);
|
|
8
|
-
if (nonce) setContext(NonceKey, nonce);
|
|
9
|
-
}
|
|
10
|
-
|
|
11
|
-
export function setHeadNonce(nonce: string): void {
|
|
12
|
-
setContext(NonceKey, nonce);
|
|
13
|
-
}
|
|
14
|
-
|
|
15
|
-
export function getHeadNonce(): string {
|
|
16
|
-
return getContext(NonceKey) ?? "";
|
|
17
|
-
}
|
|
18
|
-
|
|
19
|
-
export function collectHead(): string {
|
|
20
|
-
return (getContext(HeadKey) ?? []).join("\n ");
|
|
21
|
-
}
|
|
22
|
-
|
|
23
|
-
export function Head({
|
|
24
|
-
children,
|
|
25
|
-
}: {
|
|
26
|
-
children: string | Node;
|
|
27
|
-
}): string | Comment {
|
|
28
|
-
if (typeof document === "undefined") {
|
|
29
|
-
const buf = getContext(HeadKey);
|
|
30
|
-
if (buf) {
|
|
31
|
-
const nonce = getContext(NonceKey);
|
|
32
|
-
if (nonce) {
|
|
33
|
-
const withNonce = String(children)
|
|
34
|
-
.replace(/<script /g, `<script nonce="${nonce}" `)
|
|
35
|
-
.replace(/<style /g, `<style nonce="${nonce}" `);
|
|
36
|
-
buf.push(withNonce);
|
|
37
|
-
} else {
|
|
38
|
-
buf.push(children as string);
|
|
39
|
-
}
|
|
40
|
-
}
|
|
41
|
-
return "";
|
|
42
|
-
}
|
|
43
|
-
if (children instanceof Node) {
|
|
44
|
-
document.head.appendChild(children);
|
|
45
|
-
}
|
|
46
|
-
return document.createComment("head");
|
|
47
|
-
}
|
|
1
|
+
import { createContext, getContext, setContext } from "@sigil-dev/runtime";
|
|
2
|
+
|
|
3
|
+
const HeadKey = createContext<string[]>();
|
|
4
|
+
const NonceKey = createContext<string>();
|
|
5
|
+
|
|
6
|
+
export function initHead(nonce?: string): void {
|
|
7
|
+
setContext(HeadKey, []);
|
|
8
|
+
if (nonce) setContext(NonceKey, nonce);
|
|
9
|
+
}
|
|
10
|
+
|
|
11
|
+
export function setHeadNonce(nonce: string): void {
|
|
12
|
+
setContext(NonceKey, nonce);
|
|
13
|
+
}
|
|
14
|
+
|
|
15
|
+
export function getHeadNonce(): string {
|
|
16
|
+
return getContext(NonceKey) ?? "";
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
export function collectHead(): string {
|
|
20
|
+
return (getContext(HeadKey) ?? []).join("\n ");
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
export function Head({
|
|
24
|
+
children,
|
|
25
|
+
}: {
|
|
26
|
+
children: string | Node;
|
|
27
|
+
}): string | Comment {
|
|
28
|
+
if (typeof document === "undefined") {
|
|
29
|
+
const buf = getContext(HeadKey);
|
|
30
|
+
if (buf) {
|
|
31
|
+
const nonce = getContext(NonceKey);
|
|
32
|
+
if (nonce) {
|
|
33
|
+
const withNonce = String(children)
|
|
34
|
+
.replace(/<script /g, `<script nonce="${nonce}" `)
|
|
35
|
+
.replace(/<style /g, `<style nonce="${nonce}" `);
|
|
36
|
+
buf.push(withNonce);
|
|
37
|
+
} else {
|
|
38
|
+
buf.push(children as string);
|
|
39
|
+
}
|
|
40
|
+
}
|
|
41
|
+
return "";
|
|
42
|
+
}
|
|
43
|
+
if (children instanceof Node) {
|
|
44
|
+
document.head.appendChild(children);
|
|
45
|
+
}
|
|
46
|
+
return document.createComment("head");
|
|
47
|
+
}
|