@shaper.org/vite-react-plugin 1.0.14 → 1.0.16

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.mjs CHANGED
@@ -1799,14 +1799,57 @@ function jsxSourcePlugin(options = {}) {
1799
1799
  runtime: "automatic"
1800
1800
  }], "@babel/preset-typescript"],
1801
1801
  plugins: [function injectSourceFile() {
1802
- return { visitor: { JSXOpeningElement(path, state) {
1803
- const root = state.file.opts.root;
1804
- const filename = state.file.opts.filename;
1805
- const relativeFilename = PathUtil.relative(root, filename);
1806
- const { line, column } = path.node.loc.start;
1807
- const attr = t.jsxAttribute(t.jsxIdentifier("data-loc"), t.stringLiteral(`${relativeFilename}:${line}:${column}`));
1808
- path.node.attributes.push(attr);
1809
- } } };
1802
+ return { visitor: {
1803
+ Program(programPath, state) {
1804
+ const root = state.file.opts.root;
1805
+ const filename = state.file.opts.filename;
1806
+ const relativeFilename = PathUtil.relative(root, filename);
1807
+ const injected = /* @__PURE__ */ new Set();
1808
+ function injectAtProgramEnd(name) {
1809
+ if (injected.has(name)) return;
1810
+ injected.add(name);
1811
+ programPath.pushContainer("body", t.expressionStatement(t.assignmentExpression("=", t.memberExpression(t.identifier(name), t.identifier("__file")), t.stringLiteral(relativeFilename))));
1812
+ }
1813
+ programPath.traverse({
1814
+ ExportNamedDeclaration(path) {
1815
+ const decl = path.node.declaration;
1816
+ if (t.isFunctionDeclaration(decl) && decl.id) injectAtProgramEnd(decl.id.name);
1817
+ if (t.isClassDeclaration(decl) && decl.id) injectAtProgramEnd(decl.id.name);
1818
+ if (t.isVariableDeclaration(decl)) {
1819
+ for (const d of decl.declarations) if (t.isIdentifier(d.id) && (t.isArrowFunctionExpression(d.init) || t.isFunctionExpression(d.init))) injectAtProgramEnd(d.id.name);
1820
+ }
1821
+ for (const spec of path.node.specifiers) if (t.isExportSpecifier(spec)) injectAtProgramEnd(spec.local.name);
1822
+ },
1823
+ ExportDefaultDeclaration(path) {
1824
+ const decl = path.node.declaration;
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
+ }
1841
+ }
1842
+ });
1843
+ },
1844
+ JSXOpeningElement(path, state) {
1845
+ const root = state.file.opts.root;
1846
+ const filename = state.file.opts.filename;
1847
+ const relativeFilename = PathUtil.relative(root, filename);
1848
+ const { line, column } = path.node.loc.start;
1849
+ const attr = t.jsxAttribute(t.jsxIdentifier("data-loc"), t.stringLiteral(`${relativeFilename}:${line}:${column}`));
1850
+ path.node.attributes.push(attr);
1851
+ }
1852
+ } };
1810
1853
  }]
1811
1854
  });
1812
1855
  if (!result) return null;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@shaper.org/vite-react-plugin",
3
- "version": "1.0.14",
3
+ "version": "1.0.16",
4
4
  "description": "",
5
5
  "type": "module",
6
6
  "private": false,
package/templates/main.ts CHANGED
@@ -138,12 +138,15 @@ export class ReactRouteMonitor {
138
138
  const validRoutes = event.detail.routes.filter(
139
139
  (route) => route.element !== undefined && route.path !== "*",
140
140
  );
141
+
141
142
  const routes = validRoutes.map((route) => ({
142
143
  name: route.path,
143
144
  path: route.path,
144
- file: route.element.type().props["data-loc"],
145
+ file: route.element.type.__file || "src/",
145
146
  }));
146
147
 
148
+ console.log(routes);
149
+
147
150
  this.iframeClient.sendAllRoutes(routes);
148
151
  }
149
152
 
@@ -181,7 +184,7 @@ export class ReactRouteMonitor {
181
184
  const routeInfo = {
182
185
  name: toPathname,
183
186
  path: toPathname,
184
- file: to.element.type().props["data-loc"],
187
+ file: to.element.type.__file || "src/",
185
188
  };
186
189
 
187
190
  if (toPathname === fromPathname) {
@@ -236,5 +239,7 @@ const monitor = new ReactRouteMonitor({
236
239
  },
237
240
  });
238
241
 
242
+
243
+
239
244
  monitor.start();
240
245
  monitor.triggerRoutes();