@shaper.org/vite-react-plugin 1.0.15 → 1.0.17

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/dist/index.d.mts CHANGED
@@ -3,25 +3,6 @@ import { UserConfig } from "vite";
3
3
 
4
4
  //#region src/index.d.ts
5
5
  declare const reactPlugin: (config: UserConfig) => ({
6
- name: string;
7
- enforce: string;
8
- resolveId(id: string): "virtual:hmr-events-plugin" | undefined;
9
- load(id: string): string | undefined;
10
- transformIndexHtml(html: string): {
11
- html: string;
12
- tags: {
13
- tag: string;
14
- injectTo: string;
15
- type: string;
16
- attrs: {
17
- src: string;
18
- type: string;
19
- };
20
- }[];
21
- };
22
- configureServer(server: vite0.ViteDevServer): void;
23
- handleHotUpdate(ctx: vite0.HmrContext): vite0.ModuleNode[];
24
- } | {
25
6
  name: string;
26
7
  enforce: string;
27
8
  transform(code: any, id: any): Promise<{
@@ -34,6 +15,9 @@ declare const reactPlugin: (config: UserConfig) => ({
34
15
  apply: string;
35
16
  configResolved(resolvedConfig: vite0.ResolvedConfig): void;
36
17
  transform(code: string, id: string, options: Record<string, any>): Promise<string | undefined>;
18
+ } | {
19
+ name: string;
20
+ configureServer(server: any): void;
37
21
  })[];
38
22
  //#endregion
39
23
  export { reactPlugin };
package/dist/index.mjs CHANGED
@@ -1814,13 +1814,30 @@ function jsxSourcePlugin(options = {}) {
1814
1814
  ExportNamedDeclaration(path) {
1815
1815
  const decl = path.node.declaration;
1816
1816
  if (t.isFunctionDeclaration(decl) && decl.id) injectAtProgramEnd(decl.id.name);
1817
+ if (t.isClassDeclaration(decl) && decl.id) injectAtProgramEnd(decl.id.name);
1817
1818
  if (t.isVariableDeclaration(decl)) {
1818
1819
  for (const d of decl.declarations) if (t.isIdentifier(d.id) && (t.isArrowFunctionExpression(d.init) || t.isFunctionExpression(d.init))) injectAtProgramEnd(d.id.name);
1819
1820
  }
1821
+ for (const spec of path.node.specifiers) if (t.isExportSpecifier(spec)) injectAtProgramEnd(spec.local.name);
1820
1822
  },
1821
1823
  ExportDefaultDeclaration(path) {
1822
1824
  const decl = path.node.declaration;
1823
- if (t.isIdentifier(decl)) injectAtProgramEnd(decl.name);
1825
+ if (t.isFunctionDeclaration(decl) && decl.id) {
1826
+ injectAtProgramEnd(decl.id.name);
1827
+ return;
1828
+ }
1829
+ if (t.isClassDeclaration(decl) && decl.id) {
1830
+ injectAtProgramEnd(decl.id.name);
1831
+ return;
1832
+ }
1833
+ if (t.isIdentifier(decl)) {
1834
+ injectAtProgramEnd(decl.name);
1835
+ return;
1836
+ }
1837
+ if (t.isExportSpecifier?.(decl)) {
1838
+ injectAtProgramEnd(decl.local.name);
1839
+ return;
1840
+ }
1824
1841
  }
1825
1842
  });
1826
1843
  },
@@ -1844,13 +1861,47 @@ function jsxSourcePlugin(options = {}) {
1844
1861
  };
1845
1862
  }
1846
1863
 
1864
+ //#endregion
1865
+ //#region src/analyze-deps-plugin.ts
1866
+ function analyzeDepsPlugin() {
1867
+ return {
1868
+ name: "analyze-deps",
1869
+ configureServer(server) {
1870
+ server.middlewares.use("/__analyze", async (req, res) => {
1871
+ console.log(req.url);
1872
+ try {
1873
+ const entry = new URL(req.url, "http://localhost").searchParams.get("entry");
1874
+ await server.transformRequest(entry);
1875
+ const mod = await server.moduleGraph.getModuleByUrl(entry);
1876
+ const result = [];
1877
+ for (const nodeModule of mod._clientModule.importedModules) result.push({
1878
+ id: nodeModule.id,
1879
+ file: nodeModule.file
1880
+ });
1881
+ res.setHeader("Content-Type", "application/json");
1882
+ res.statusCode = 200;
1883
+ res.end(JSON.stringify({
1884
+ modules: result,
1885
+ file: mod._clientModule.file
1886
+ }));
1887
+ } catch (err) {
1888
+ res.setHeader("Content-Type", "application/json");
1889
+ res.statusCode = 500;
1890
+ res.end(JSON.stringify({ msg: err.message ?? "Unexpected error." }));
1891
+ }
1892
+ });
1893
+ }
1894
+ };
1895
+ }
1896
+
1847
1897
  //#endregion
1848
1898
  //#region src/index.ts
1849
1899
  const reactPlugin = (config) => {
1850
1900
  return [
1851
1901
  HMREventsPlugin(),
1852
1902
  jsxSourcePlugin(config),
1853
- reactRoutesPlugin()
1903
+ reactRoutesPlugin(),
1904
+ analyzeDepsPlugin()
1854
1905
  ];
1855
1906
  };
1856
1907
 
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@shaper.org/vite-react-plugin",
3
- "version": "1.0.15",
3
+ "version": "1.0.17",
4
4
  "description": "",
5
5
  "type": "module",
6
6
  "private": false,
package/templates/main.ts CHANGED
@@ -142,9 +142,11 @@ export class ReactRouteMonitor {
142
142
  const routes = validRoutes.map((route) => ({
143
143
  name: route.path,
144
144
  path: route.path,
145
- file: route.element.type.__file,
145
+ file: route.element.type.__file || "src/",
146
146
  }));
147
147
 
148
+ console.log(routes);
149
+
148
150
  this.iframeClient.sendAllRoutes(routes);
149
151
  }
150
152
 
@@ -182,7 +184,7 @@ export class ReactRouteMonitor {
182
184
  const routeInfo = {
183
185
  name: toPathname,
184
186
  path: toPathname,
185
- file: to.element.type().props["data-loc"],
187
+ file: to.element.type.__file || "src/",
186
188
  };
187
189
 
188
190
  if (toPathname === fromPathname) {
@@ -237,5 +239,7 @@ const monitor = new ReactRouteMonitor({
237
239
  },
238
240
  });
239
241
 
242
+
243
+
240
244
  monitor.start();
241
245
  monitor.triggerRoutes();