rajt 0.0.2 → 0.0.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.
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "rajt",
3
- "version": "0.0.2",
3
+ "version": "0.0.3",
4
4
  "type": "module",
5
5
  "main": "dist/index.js",
6
6
  "exports": {
@@ -16,17 +16,17 @@
16
16
  "dev": "tsx watch src/dev.ts",
17
17
  "prod": "bun run build && bun run sam",
18
18
  "build": "bun run cache:routes && bun run export && bun run clean:temp",
19
- "build:watch": "chokidar \"{actions,src,models,utils,configs}/**/*.ts\" -c \"bun run build\" --initial",
20
- "export": "esbuild --bundle --minify --outfile=dist/index.js --platform=node --target=node20 --format=esm --tree-shaking=true --legal-comments=none src/prod.ts",
19
+ "build:watch": "chokidar \"../../{actions,configs,models,utils}/**/*.ts\" -c \"bun run build\" --initial",
20
+ "export": "esbuild --bundle --minify --outfile=../../dist/index.js --platform=node --target=node20 --format=esm --tree-shaking=true --legal-comments=none src/prod.ts",
21
21
  "cache:routes": "tsx src/scripts/cache-routes.ts",
22
- "ensure-dirs": "rm -rf dist tmp && mkdir -p ./tmp && chmod 755 ./tmp && mkdir -p ./dist && chmod 755 ./dist",
23
- "clean": "rm -rf dist tmp",
24
- "clean:build": "rm -rf dist",
25
- "clean:temp": "rm -rf tmp",
26
- "zip": "zip -j lambda.zip dist/index.js",
27
- "update": "aws lambda update-function-code --zip-file fileb://lambda.zip --function-name hello",
22
+ "ensure-dirs": "rm -rf ../../dist ../../tmp && mkdir -p ../../tmp && chmod 755 ../../tmp && mkdir -p ../../dist && chmod 755 ../../dist",
23
+ "clean": "rm -rf ../../dist ../../tmp",
24
+ "clean:build": "rm -rf ../../dist",
25
+ "clean:temp": "rm -rf ../../tmp",
26
+ "zip": "zip -j lambda.zip ../../dist/index.js",
27
+ "update": "aws lambda update-function-code --zip-file fileb://../../lambda.zip --function-name hello",
28
28
  "deploy": "run-s build zip update",
29
- "start": "node dist/index.js"
29
+ "start": "node ../../dist/index.js"
30
30
  },
31
31
  "dependencies": {
32
32
  "@hono/node-server": "^1.14.1",
package/src/create-app.ts CHANGED
@@ -116,6 +116,7 @@ export const createApp = <E extends Env>(options?: ServerOptions<E>) => {
116
116
 
117
117
  function mw(...objs: string[]): Function[] {
118
118
  return objs.flatMap(obj => {
119
+ if (typeof obj !== 'string') return null
119
120
  // @ts-ignore
120
121
  return getHandler(obj)?.mw || null
121
122
  }).flat().filter(Boolean)
package/src/prod.ts CHANGED
@@ -5,10 +5,10 @@ import createApp from './create-app'
5
5
  config({ path: '.env.prod' })
6
6
 
7
7
  // @ts-ignore
8
- await import('../tmp/import-routes.mjs')
8
+ await import('../../../tmp/import-routes.mjs')
9
9
 
10
10
  // @ts-ignore
11
- const routes = (await import('../tmp/routes.json')).default
11
+ const routes = (await import('../../../tmp/routes.json')).default
12
12
  // @ts-ignore
13
13
  const app = createApp({ routes })
14
14
 
package/src/routes.ts CHANGED
@@ -49,7 +49,7 @@ export default async function getRoutes(all: boolean = false, baseDir: string =
49
49
  method: handle.m.toLowerCase(),
50
50
  path: handle.p,
51
51
  name: handle.name.replace(/\.ts$/, ''),
52
- file: relative(process.cwd(), fullPath),
52
+ file: baseDir + fullPath.split(baseDir)[1],
53
53
  middlewares,
54
54
  handle,
55
55
  })
@@ -58,6 +58,6 @@ export default async function getRoutes(all: boolean = false, baseDir: string =
58
58
  }
59
59
  }
60
60
 
61
- await walk(path.resolve(__dirname, '..', baseDir))
61
+ await walk(path.resolve(__dirname, '../../..', baseDir))
62
62
  return routes
63
63
  }
@@ -5,10 +5,10 @@ import ensureDir from '../utils/ensuredir'
5
5
  async function cacheRoutes() {
6
6
  const routes = await getRoutes(true)
7
7
 
8
- const iPath = './tmp/import-routes.mjs'
8
+ const iPath = '../../tmp/import-routes.mjs'
9
9
  ensureDir(iPath)
10
10
  writeFileSync(iPath, `// AUTO-GENERATED FILE - DO NOT EDIT
11
- import { registerHandler } from '../src/register'
11
+ import { registerHandler } from '../node_modules/rajt/src/register'
12
12
 
13
13
  ${routes.map(r => `import ${r.name} from '../${normalizePath(r.file)}'`).join('\n')}
14
14
 
@@ -20,12 +20,12 @@ try {
20
20
  registerHandler(name, handler)
21
21
  }
22
22
  }
23
- } catch (error) {
24
- console.error('Failed to register handlers:', error)
23
+ } catch (e) {
24
+ console.error('Failed to register handlers:', e)
25
25
  }
26
26
  `)
27
27
 
28
- const rPath = './tmp/routes.json'
28
+ const rPath = '../../tmp/routes.json'
29
29
  ensureDir(rPath)
30
30
  writeFileSync(rPath, JSON.stringify(routes.filter(r => r.method && r.path).map(route => [
31
31
  route.method,