react-server-frame 0.0.8 → 0.0.9

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.
@@ -5,10 +5,15 @@ declare function reactServerFrame({
5
5
  entry
6
6
  }?: {
7
7
  entry?: string;
8
- }): {
8
+ }): ({
9
9
  name: string;
10
10
  config(this: Vite.ConfigPluginContext, userConfig: Vite.UserConfig): Record<string, any>;
11
- };
11
+ configEnvironment?: undefined;
12
+ } | {
13
+ config?: undefined;
14
+ name: string;
15
+ configEnvironment(this: Vite.ConfigPluginContext, name: string, config: Vite.EnvironmentOptions): Promise<Record<string, any> | undefined>;
16
+ })[];
12
17
  //#endregion
13
18
  export { reactServerFrame };
14
19
  //# sourceMappingURL=plugin.d.mts.map
@@ -1 +1 @@
1
- {"version":3,"file":"plugin.d.mts","names":[],"sources":["../../src/vite/plugin.ts"],"mappings":";;;iBASgB,gBAAA,CAAA;EAAmB;AAAA;EAAiC,KAAA;AAAA"}
1
+ {"version":3,"file":"plugin.d.mts","names":[],"sources":["../../src/vite/plugin.ts"],"mappings":";;;iBAagB,gBAAA,CAAA;EAAmB;AAAA;EAAiC,KAAA;AAAA"}
@@ -1,12 +1,15 @@
1
+ import { execFile } from "node:child_process";
1
2
  import * as path from "node:path";
3
+ import { promisify } from "node:util";
2
4
  import { fileURLToPath } from "node:url";
3
5
  import * as Vite from "vite";
4
6
  //#region src/vite/plugin.ts
7
+ const execFileAsync = promisify(execFile);
5
8
  function getEntry(file) {
6
9
  return Vite.normalizePath(path.join(path.dirname(fileURLToPath(import.meta.url)), file));
7
10
  }
8
11
  function reactServerFrame({ entry = "/src/entry.server" } = {}) {
9
- return {
12
+ return [{
10
13
  name: "framework",
11
14
  config(userConfig) {
12
15
  return Vite.mergeConfig({ environments: {
@@ -15,7 +18,37 @@ function reactServerFrame({ entry = "/src/entry.server" } = {}) {
15
18
  ssr: { build: { rolldownOptions: { input: { index: getEntry("entry.ssr.tsx") } } } }
16
19
  } }, userConfig, true);
17
20
  }
18
- };
21
+ }, {
22
+ name: "framework:optimize-deps",
23
+ async configEnvironment(name, config) {
24
+ if (name !== "client") return;
25
+ const entries = new Set([getEntry("entry.client.tsx")]);
26
+ try {
27
+ const { stdout } = await execFileAsync("ast-grep", [
28
+ "scan",
29
+ "--json",
30
+ "--inline-rules",
31
+ `id: find-use-client-directives
32
+ language: TSX
33
+ rule:
34
+ all:
35
+ - kind: expression_statement
36
+ - has:
37
+ kind: string
38
+ regex: '^[''"]use client[''"]$'
39
+ - inside:
40
+ kind: program
41
+ stopBy: neighbor`
42
+ ]);
43
+ const results = JSON.parse(stdout);
44
+ for (const result of results) entries.add(result.file);
45
+ console.log(`Optimizing dependencies for ${entries.size} client modules`);
46
+ } catch {
47
+ console.warn("Install https://ast-grep.github.io/ to enable dependencies optimization discovery");
48
+ }
49
+ return Vite.mergeConfig(config, { optimizeDeps: { entries: [...entries] } }, true);
50
+ }
51
+ }];
19
52
  }
20
53
  //#endregion
21
54
  export { reactServerFrame };
@@ -1 +1 @@
1
- {"version":3,"file":"plugin.mjs","names":[],"sources":["../../src/vite/plugin.ts"],"sourcesContent":["import * as path from \"node:path\";\nimport { fileURLToPath } from \"node:url\";\n\nimport * as Vite from \"vite\";\n\nfunction getEntry(file: string) {\n return Vite.normalizePath(path.join(path.dirname(fileURLToPath(import.meta.url)), file));\n}\n\nexport function reactServerFrame({ entry = \"/src/entry.server\" }: { entry?: string } = {}) {\n return {\n name: \"framework\",\n config(userConfig) {\n return Vite.mergeConfig(\n {\n environments: {\n client: {\n build: {\n rolldownOptions: {\n input: {\n index: getEntry(\"entry.client.tsx\"),\n },\n },\n },\n },\n rsc: {\n build: {\n rolldownOptions: {\n input: {\n index: entry,\n },\n },\n },\n },\n ssr: {\n build: {\n rolldownOptions: {\n input: {\n index: getEntry(\"entry.ssr.tsx\"),\n },\n },\n },\n },\n },\n } satisfies Vite.UserConfig,\n userConfig,\n true,\n );\n },\n } satisfies Vite.Plugin;\n}\n"],"mappings":";;;;AAKA,SAAS,SAAS,MAAc;AAC9B,QAAO,KAAK,cAAc,KAAK,KAAK,KAAK,QAAQ,cAAc,OAAO,KAAK,IAAI,CAAC,EAAE,KAAK,CAAC;;AAG1F,SAAgB,iBAAiB,EAAE,QAAQ,wBAA4C,EAAE,EAAE;AACzF,QAAO;EACL,MAAM;EACN,OAAO,YAAY;AACjB,UAAO,KAAK,YACV,EACE,cAAc;IACZ,QAAQ,EACN,OAAO,EACL,iBAAiB,EACf,OAAO,EACL,OAAO,SAAS,mBAAmB,EACpC,EACF,EACF,EACF;IACD,KAAK,EACH,OAAO,EACL,iBAAiB,EACf,OAAO,EACL,OAAO,OACR,EACF,EACF,EACF;IACD,KAAK,EACH,OAAO,EACL,iBAAiB,EACf,OAAO,EACL,OAAO,SAAS,gBAAgB,EACjC,EACF,EACF,EACF;IACF,EACF,EACD,YACA,KACD;;EAEJ"}
1
+ {"version":3,"file":"plugin.mjs","names":[],"sources":["../../src/vite/plugin.ts"],"sourcesContent":["import { execFile } from \"node:child_process\";\nimport * as path from \"node:path\";\nimport { promisify } from \"node:util\";\nimport { fileURLToPath } from \"node:url\";\n\nimport * as Vite from \"vite\";\n\nconst execFileAsync = promisify(execFile);\n\nfunction getEntry(file: string) {\n return Vite.normalizePath(path.join(path.dirname(fileURLToPath(import.meta.url)), file));\n}\n\nexport function reactServerFrame({ entry = \"/src/entry.server\" }: { entry?: string } = {}) {\n return [\n {\n name: \"framework\",\n config(userConfig) {\n return Vite.mergeConfig(\n {\n environments: {\n client: {\n build: {\n rolldownOptions: {\n input: {\n index: getEntry(\"entry.client.tsx\"),\n },\n },\n },\n },\n rsc: {\n build: {\n rolldownOptions: {\n input: {\n index: entry,\n },\n },\n },\n },\n ssr: {\n build: {\n rolldownOptions: {\n input: {\n index: getEntry(\"entry.ssr.tsx\"),\n },\n },\n },\n },\n },\n } satisfies Vite.UserConfig,\n userConfig,\n true,\n );\n },\n },\n {\n name: \"framework:optimize-deps\",\n async configEnvironment(name, config) {\n if (name !== \"client\") return;\n\n const entries = new Set<string>([getEntry(\"entry.client.tsx\")]);\n\n try {\n const ruleYaml = `id: find-use-client-directives\nlanguage: TSX\nrule:\n all:\n - kind: expression_statement\n - has:\n kind: string\n regex: '^[''\"]use client[''\"]$'\n - inside:\n kind: program\n stopBy: neighbor`;\n\n const { stdout } = await execFileAsync(\"ast-grep\", [\n \"scan\",\n \"--json\",\n \"--inline-rules\",\n ruleYaml,\n ]);\n const results: Array<{ file: string }> = JSON.parse(stdout);\n for (const result of results) {\n entries.add(result.file);\n }\n console.log(`Optimizing dependencies for ${entries.size} client modules`);\n } catch {\n console.warn(\n \"Install https://ast-grep.github.io/ to enable dependencies optimization discovery\",\n );\n }\n\n return Vite.mergeConfig(\n config,\n {\n optimizeDeps: {\n entries: [...entries],\n },\n } as Vite.EnvironmentOptions,\n true,\n );\n },\n },\n ] satisfies Vite.Plugin[];\n}\n"],"mappings":";;;;;;AAOA,MAAM,gBAAgB,UAAU,SAAS;AAEzC,SAAS,SAAS,MAAc;AAC9B,QAAO,KAAK,cAAc,KAAK,KAAK,KAAK,QAAQ,cAAc,OAAO,KAAK,IAAI,CAAC,EAAE,KAAK,CAAC;;AAG1F,SAAgB,iBAAiB,EAAE,QAAQ,wBAA4C,EAAE,EAAE;AACzF,QAAO,CACL;EACE,MAAM;EACN,OAAO,YAAY;AACjB,UAAO,KAAK,YACV,EACE,cAAc;IACZ,QAAQ,EACN,OAAO,EACL,iBAAiB,EACf,OAAO,EACL,OAAO,SAAS,mBAAmB,EACpC,EACF,EACF,EACF;IACD,KAAK,EACH,OAAO,EACL,iBAAiB,EACf,OAAO,EACL,OAAO,OACR,EACF,EACF,EACF;IACD,KAAK,EACH,OAAO,EACL,iBAAiB,EACf,OAAO,EACL,OAAO,SAAS,gBAAgB,EACjC,EACF,EACF,EACF;IACF,EACF,EACD,YACA,KACD;;EAEJ,EACD;EACE,MAAM;EACN,MAAM,kBAAkB,MAAM,QAAQ;AACpC,OAAI,SAAS,SAAU;GAEvB,MAAM,UAAU,IAAI,IAAY,CAAC,SAAS,mBAAmB,CAAC,CAAC;AAE/D,OAAI;IAaF,MAAM,EAAE,WAAW,MAAM,cAAc,YAAY;KACjD;KACA;KACA;KAfe;;;;;;;;;;;KAiBhB,CAAC;IACF,MAAM,UAAmC,KAAK,MAAM,OAAO;AAC3D,SAAK,MAAM,UAAU,QACnB,SAAQ,IAAI,OAAO,KAAK;AAE1B,YAAQ,IAAI,+BAA+B,QAAQ,KAAK,iBAAiB;WACnE;AACN,YAAQ,KACN,oFACD;;AAGH,UAAO,KAAK,YACV,QACA,EACE,cAAc,EACZ,SAAS,CAAC,GAAG,QAAQ,EACtB,EACF,EACD,KACD;;EAEJ,CACF"}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "react-server-frame",
3
- "version": "0.0.8",
3
+ "version": "0.0.9",
4
4
  "description": "A new type of RSC routing.",
5
5
  "homepage": "https://github.com/jacob-ebey/react-server-frame#readme",
6
6
  "bugs": {
@@ -50,7 +50,7 @@
50
50
  },
51
51
  "peerDependencies": {
52
52
  "@vitejs/plugin-rsc": "*",
53
- "react": "*:",
53
+ "react": "*",
54
54
  "react-dom": "*",
55
55
  "remix": "*",
56
56
  "vite": "*"