bun-router 0.7.4-experimental.2 → 0.7.4-experimental.3

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.
@@ -2,5 +2,5 @@ import { Router } from '..';
2
2
 
3
3
  const r = Router(3001);
4
4
 
5
- r.static('/', './examples/pages');
5
+ r.static('/', './pages');
6
6
  r.serve();
@@ -31,10 +31,9 @@ const Router: BunRouter = (port?: number | string, options?: RouterOptions<Optio
31
31
  // the root directory is traversed recursively
32
32
  static: async (pattern: string, root: string) => {
33
33
  await readDir(root, async (fp) => {
34
- const pure = path.join('.', fp);
35
- const ext = path.extname(pure);
34
+ const ext = path.extname(fp);
36
35
 
37
- let base = path.basename(pure);
36
+ let base = path.basename(fp);
38
37
 
39
38
  //FIXME: this can be improved
40
39
  if (ext === '.html') base = base.replace(ext, '');
@@ -46,6 +45,8 @@ const Router: BunRouter = (port?: number | string, options?: RouterOptions<Optio
46
45
 
47
46
  if (base === 'index') patternPath = pattern;
48
47
 
48
+ const purePath = path.join(root, patternPath);
49
+
49
50
  const route: Route = {
50
51
  children: new Map(),
51
52
  dynamicPath: '',
@@ -54,10 +55,10 @@ const Router: BunRouter = (port?: number | string, options?: RouterOptions<Optio
54
55
  method: 'GET',
55
56
  handler: async () => {
56
57
  if (ext === '.tsx') {
57
- const component = await loadComponent(path.join(root, patternPath));
58
+ const component = await loadComponent(purePath.split('.')[0]);
58
59
  return await http.render(component());
59
60
  } else {
60
- return await http.file(200, pure);
61
+ return await http.file(200, fp);
61
62
  }
62
63
  },
63
64
  };
package/package.json CHANGED
@@ -14,8 +14,10 @@
14
14
  "peerDependencies": {
15
15
  "typescript": "^5.0.0"
16
16
  },
17
- "version": "0.7.4-experimental.2",
17
+ "version": "0.7.4-experimental.3",
18
18
  "dependencies": {
19
- "eslint-plugin-react-hooks": "^4.6.0"
19
+ "@types/react": "^18.2.22",
20
+ "eslint-plugin-react-hooks": "^4.6.0",
21
+ "react": "^18.2.0"
20
22
  }
21
23
  }
package/tsconfig.json CHANGED
@@ -19,7 +19,7 @@
19
19
  "bun-types" // add Bun global
20
20
  ],
21
21
  "paths": {
22
- "examples/*": ["./examples/*"]
22
+ "examples/*": ["./examples/*"],
23
23
  }
24
24
  }
25
25
  }