@rsc-kit/core 0.22.2 → 0.22.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
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@rsc-kit/core",
3
- "version": "0.22.2",
3
+ "version": "0.22.4",
4
4
  "description": "React Server Components as a Vite plugin. Routing, streaming, server actions, typed urls and build-time prerendering — deploy to Bun, Node, Workers, Vercel or Deno.",
5
5
  "license": "MIT",
6
6
  "type": "module",
@@ -1,15 +0,0 @@
1
- export interface ImportMetaUse {
2
- line: number;
3
- /** `import.meta.env`, or `import.meta` for the bare object. */
4
- form: string;
5
- }
6
- /** The uses of `import.meta` in a module that bytecode cannot express. */
7
- export declare function unlowerableImportMeta(source: string): ImportMetaUse[];
8
- /** Every server module the binary would compile, with its first unlowerable use. */
9
- export declare function bytecodeBlockers(serverDir: string): {
10
- file: string;
11
- line: number;
12
- form: string;
13
- }[];
14
- /** The note the build prints, or null when the binary can take --bytecode. */
15
- export declare function bytecodeNote(serverDir: string): string | null;
@@ -1,65 +0,0 @@
1
- // What stops `bun build --compile --bytecode` from applying, said by name.
2
- //
3
- // Bun compiles bytecode as CommonJS, and in CommonJS `import.meta` does not
4
- // exist: `import.meta.url`, `.dirname`, `.dir` and `.main` are lowered to
5
- // values, and every other form - `.env`, `.filename`, `.resolve`, the object
6
- // itself - fails the bytecode step. Bun then reports "Failed to generate
7
- // bytecode", names no file, and exits 0, so a CI ships a binary that dies at
8
- // boot with "import.meta is only valid inside modules" and reads green.
9
- // The build scans its own server output and names the file and line.
10
- import { readdirSync, readFileSync } from "node:fs";
11
- import { join, relative } from "node:path";
12
- const LOWERED = new Set(["url", "dirname", "dir", "main"]);
13
- /** `import.meta`, and what follows it, at each use outside a comment. */
14
- const USE = /\bimport\.meta\b(?:\s*\??\.\s*([A-Za-z_$][\w$]*))?/g;
15
- /** The uses of `import.meta` in a module that bytecode cannot express. */
16
- export function unlowerableImportMeta(source) {
17
- const found = [];
18
- const lines = source.split("\n");
19
- for (const [index, raw] of lines.entries()) {
20
- const line = raw.trimStart();
21
- if (line.startsWith("//") || line.startsWith("*") || line.startsWith("/*"))
22
- continue;
23
- for (const match of raw.matchAll(USE)) {
24
- const property = match[1];
25
- if (property && LOWERED.has(property))
26
- continue;
27
- found.push({ line: index + 1, form: property ? `import.meta.${property}` : "import.meta" });
28
- }
29
- }
30
- return found;
31
- }
32
- /** Every server module the binary would compile, with its first unlowerable use. */
33
- export function bytecodeBlockers(serverDir) {
34
- const blockers = [];
35
- const walk = (dir) => {
36
- for (const entry of readdirSync(dir, { withFileTypes: true })) {
37
- const path = join(dir, entry.name);
38
- if (entry.isDirectory()) {
39
- if (entry.name !== "node_modules")
40
- walk(path);
41
- continue;
42
- }
43
- // The stored pages, as one module: their text is data, not code.
44
- if (!/\.m?js$/.test(entry.name) || entry.name.endsWith("-inline.mjs"))
45
- continue;
46
- const [first] = unlowerableImportMeta(readFileSync(path, "utf-8"));
47
- if (first)
48
- blockers.push({ file: relative(serverDir, path), ...first });
49
- }
50
- };
51
- walk(serverDir);
52
- return blockers;
53
- }
54
- /** The note the build prints, or null when the binary can take --bytecode. */
55
- export function bytecodeNote(serverDir) {
56
- const blockers = bytecodeBlockers(serverDir);
57
- if (blockers.length === 0)
58
- return null;
59
- return ("bun build --compile --bytecode will not apply to this server: " +
60
- blockers.map((b) => `${b.file}:${b.line} uses ${b.form}`).join(", ") +
61
- ". Bytecode is CommonJS, where only import.meta.url, .dirname, .dir and .main can be expressed; " +
62
- "Bun reports the failure, names no file, and exits 0, so the binary dies at boot. " +
63
- "--bytecode --format=esm applies regardless.");
64
- }
65
- //# sourceMappingURL=bytecodeCheck.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"bytecodeCheck.js","sourceRoot":"","sources":["../src/bytecodeCheck.ts"],"names":[],"mappings":"AAAA,2EAA2E;AAC3E,EAAE;AACF,4EAA4E;AAC5E,0EAA0E;AAC1E,6E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AC,EAAE,EAAE,CAAC,GAAG,CAAC,CAAC,IAAI,IAAI,CAAC,CAAC,IAAI,SAAS,CAAC,CAAC,IAAI,EAAE,CAAC,CAAC,IAAI,CAAC,IAAI,CAAC;QACpE,iGAAiG;QACjG,mFAAmF;QACnF,6CAA6C,CAC9C,CAAC;AACJ,CAAC","sourcesContent":["// What stops `bun build --compile --bytecode` from applying, said by name.\n//\n// Bun compiles bytecode as CommonJS, and in CommonJS `import.meta` does not\n// exist: `import.meta.url`, `.dirname`, `.dir` and `.main` are lowered to\n// values, and every other form - `.env`, `.filename`, `.resolve`, the object\n// itself - fails the bytecode step. Bun then reports \"Failed to generate\n// bytecode\", names no file, and exits 0, so a CI ships a binary that dies at\n// boot with \"import.meta is only valid inside modules\" and reads green.\n// The build scans its own server output and names the file and line.\n\nimport { readdirSync, readFileSync } from \"node:fs\";\nimport { join, relative } from \"node:path\";\n\nconst LOWERED = new Set([\"url\", \"dirname\", \"dir\", \"main\"]);\n\n/** `import.meta`, and what follows it, at each use outside a comment. */\nconst USE = /\\bimport\\.meta\\b(?:\\s*\\??\\.\\s*([A-Za-z_$][\\w$]*))?/g;\n\nexport interface ImportMetaUse {\n line: number;\n /** `import.meta.env`, or `import.meta` for the bare object. */\n form: string;\n}\n\n/** The uses of `import.meta` in a module that bytecode cannot express. */\nexport function unlowerableImportMeta(source: string): ImportMetaUse[] {\n const found: ImportMetaUse[] = [];\n const lines = source.split(\"\\n\");\n\n for (const [index, raw] of lines.entries()) {\n const line = raw.trimStart();\n\n if (line.startsWith(\"//\") || line.startsWith(\"*\") || line.startsWith(\"/*\")) continue;\n\n for (const match of raw.matchAll(USE)) {\n const property = match[1];\n\n if (property && LOWERED.has(property)) continue;\n\n found.push({ line: index + 1, form: property ? `import.meta.${property}` : \"import.meta\" });\n }\n }\n\n return found;\n}\n\n/** Every server module the binary would compile, with its first unlowerable use. */\nexport function bytecodeBlockers(serverDir: string): { file: string; line: number; form: string }[] {\n const blockers: { file: string; line: number; form: string }[] = [];\n\n const walk = (dir: string): void => {\n for (const entry of readdirSync(dir, { withFileTypes: true })) {\n const path = join(dir, entry.name);\n\n if (entry.isDirectory()) {\n if (entry.name !== \"node_modules\") walk(path);\n\n continue;\n }\n\n // The stored pages, as one module: their text is data, not code.\n if (!/\\.m?js$/.test(entry.name) || entry.name.endsWith(\"-inline.mjs\")) continue;\n\n const [first] = unlowerableImportMeta(readFileSync(path, \"utf-8\"));\n\n if (first) blockers.push({ file: relative(serverDir, path), ...first });\n }\n };\n\n walk(serverDir);\n\n return blockers;\n}\n\n/** The note the build prints, or null when the binary can take --bytecode. */\nexport function bytecodeNote(serverDir: string): string | null {\n const blockers = bytecodeBlockers(serverDir);\n\n if (blockers.length === 0) return null;\n\n return (\n \"bun build --compile --bytecode will not apply to this server: \" +\n blockers.map((b) => `${b.file}:${b.line} uses ${b.form}`).join(\", \") +\n \". Bytecode is CommonJS, where only import.meta.url, .dirname, .dir and .main can be expressed; \" +\n \"Bun reports the failure, names no file, and exits 0, so the binary dies at boot. \" +\n \"--bytecode --format=esm applies regardless.\"\n );\n}\n"]}