rajt 0.0.82 → 0.0.83
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 +4 -3
- package/src/cli/commands/dev.ts +27 -2
- package/src/cli/commands/migrate.ts +4 -4
- package/src/cli/commands/utils.ts +81 -43
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "rajt",
|
|
3
3
|
"description": "A serverless bundler layer, fully typed for AWS Lambda (Node.js and LLRT) and Cloudflare Workers.",
|
|
4
|
-
"version": "0.0.
|
|
4
|
+
"version": "0.0.83",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"main": "./src/index.ts",
|
|
7
7
|
"bin": {
|
|
@@ -39,11 +39,10 @@
|
|
|
39
39
|
},
|
|
40
40
|
"dependencies": {
|
|
41
41
|
"cripta": "^0.1",
|
|
42
|
-
"forj": "^0.0.
|
|
42
|
+
"forj": "^0.0.7",
|
|
43
43
|
"t0n": "^0.1",
|
|
44
44
|
"@hono/node-server": "^1.19.9",
|
|
45
45
|
"@hono/standard-validator": "^0.2.2",
|
|
46
|
-
"@iarna/toml": "^2.2.5",
|
|
47
46
|
"@scalar/hono-api-reference": "^0.9.40",
|
|
48
47
|
"chokidar-cli": "^3.0.0",
|
|
49
48
|
"citty": "^0.1.6",
|
|
@@ -51,6 +50,8 @@
|
|
|
51
50
|
"esbuild": "^0.25.2",
|
|
52
51
|
"hono": "^4.11.7",
|
|
53
52
|
"hono-openapi": "^1.2.0",
|
|
53
|
+
"localflare-api": "^0.4.2",
|
|
54
|
+
"localflare-core": "^0.4.2",
|
|
54
55
|
"miniflare": "^4.20251217.0",
|
|
55
56
|
"quansync": "^0.2.11",
|
|
56
57
|
"tiny-glob": "^0.2",
|
package/src/cli/commands/dev.ts
CHANGED
|
@@ -3,7 +3,11 @@ import { spawn, type ChildProcess } from 'node:child_process'
|
|
|
3
3
|
|
|
4
4
|
import { defineCommand } from 'citty'
|
|
5
5
|
import type { Miniflare } from 'miniflare'
|
|
6
|
-
import {
|
|
6
|
+
import {
|
|
7
|
+
_root, build, wait, watch, normalizePlatform, platformError, getRuntime,
|
|
8
|
+
wranglerConfig, createMiniflare, localflareManifest,
|
|
9
|
+
getDockerHost
|
|
10
|
+
} from './utils'
|
|
7
11
|
import { error, event, log, rn, warn } from '../../utils/log'
|
|
8
12
|
import { withPort } from '../../utils/port'
|
|
9
13
|
import shutdown from '../../utils/shutdown'
|
|
@@ -103,6 +107,8 @@ export default defineCommand({
|
|
|
103
107
|
|
|
104
108
|
const started = (port: number) => {
|
|
105
109
|
log(`Starting API on http://${host}:${port}`)
|
|
110
|
+
if (platform == 'cf')
|
|
111
|
+
log(`Localflare on https://studio.localflare.dev`)
|
|
106
112
|
rn()
|
|
107
113
|
}
|
|
108
114
|
|
|
@@ -156,9 +162,28 @@ export default defineCommand({
|
|
|
156
162
|
return withPort(desiredPort, async (port) => {
|
|
157
163
|
started(port)
|
|
158
164
|
let worker: Miniflare | null = null
|
|
165
|
+
let localflare: Miniflare | null = null
|
|
159
166
|
const startWorker = async () => {
|
|
160
167
|
if (worker) await worker.dispose()
|
|
161
|
-
|
|
168
|
+
if (localflare) await localflare.dispose()
|
|
169
|
+
|
|
170
|
+
const workerConfig = await wranglerConfig()
|
|
171
|
+
workerConfig.host = host
|
|
172
|
+
workerConfig.liveReload = false
|
|
173
|
+
|
|
174
|
+
worker = createMiniflare({ ...workerConfig, port })
|
|
175
|
+
await worker.ready
|
|
176
|
+
localflare = createMiniflare({
|
|
177
|
+
...workerConfig,
|
|
178
|
+
vars: {
|
|
179
|
+
...workerConfig.vars,
|
|
180
|
+
LOCALFLARE_MANIFEST: JSON.stringify(localflareManifest(workerConfig)),
|
|
181
|
+
},
|
|
182
|
+
main: 'node_modules/localflare-api/dist/worker/index.js',
|
|
183
|
+
port: 8788,
|
|
184
|
+
inspectorPort: 9230,
|
|
185
|
+
})
|
|
186
|
+
await localflare.ready
|
|
162
187
|
}
|
|
163
188
|
|
|
164
189
|
await startApp(startWorker)
|
|
@@ -3,7 +3,7 @@ import { spawn } from 'node:child_process'
|
|
|
3
3
|
import { Migrator } from 'forj'
|
|
4
4
|
import { gray } from '../../utils/colors'
|
|
5
5
|
import { _root, getRuntime } from './utils'
|
|
6
|
-
import { wait, info, event, rn, error } from '../../utils/log'
|
|
6
|
+
import { wait, info, event, rn, error, log } from '../../utils/log'
|
|
7
7
|
|
|
8
8
|
export default defineCommand({
|
|
9
9
|
meta: {
|
|
@@ -34,11 +34,11 @@ export default defineCommand({
|
|
|
34
34
|
switch (action) {
|
|
35
35
|
case 'migrate':
|
|
36
36
|
case 'apply':
|
|
37
|
-
wait('Running migrations')
|
|
38
37
|
if (!pending?.length)
|
|
39
|
-
|
|
38
|
+
log('Nothing to compile')
|
|
39
|
+
wait('Running migrations')
|
|
40
40
|
|
|
41
|
-
await Migrator.compile(pending)
|
|
41
|
+
await Migrator.compile([...migrated, ...pending])
|
|
42
42
|
|
|
43
43
|
const child = spawn(
|
|
44
44
|
isBun ? 'bunx' : 'npx',
|
|
@@ -1,16 +1,18 @@
|
|
|
1
1
|
import esbuild from 'esbuild'
|
|
2
|
-
import TOML from '@iarna/toml'
|
|
3
2
|
import { Miniflare } from 'miniflare'
|
|
4
3
|
import { mkdirSync, existsSync, readdirSync, rmSync, copyFileSync, writeFileSync } from 'node:fs'
|
|
5
4
|
import { readFile, stat, writeFile } from 'node:fs/promises'
|
|
6
5
|
import { basename, dirname, join, relative } from 'node:path'
|
|
7
6
|
|
|
7
|
+
import { findWranglerConfig, parseWranglerConfig, WRANGLER_CONFIG_FILES } from 'localflare-core'
|
|
8
|
+
import type { WranglerConfig, LocalflareManifest } from 'localflare-core'
|
|
9
|
+
|
|
8
10
|
import chokidar from 'chokidar'
|
|
9
|
-
import { gray } from '../../utils/colors'
|
|
11
|
+
import { gray, red } from '../../utils/colors'
|
|
10
12
|
import type { ChokidarEventName, Platform } from './types'
|
|
11
13
|
|
|
12
14
|
import { cacheRoutes } from '../../routes'
|
|
13
|
-
import {
|
|
15
|
+
import { substep, event, error, wait as wwait, warn, log } from '../../utils/log'
|
|
14
16
|
import { platforms } from './constants'
|
|
15
17
|
|
|
16
18
|
export const _root = join(dirname(new URL(import.meta.url).pathname), '../../../../../')
|
|
@@ -78,9 +80,7 @@ export const build = async (platform: Platform) => {
|
|
|
78
80
|
: mkdirSync(distDir, { recursive: true })
|
|
79
81
|
|
|
80
82
|
if (isCF) {
|
|
81
|
-
for (let file of
|
|
82
|
-
'wrangler.toml',
|
|
83
|
-
]) {
|
|
83
|
+
for (let file of WRANGLER_CONFIG_FILES) {
|
|
84
84
|
file = join(_root, file)
|
|
85
85
|
if (existsSync(file))
|
|
86
86
|
copyFileSync(file, join(_root, dist, basename(file)))
|
|
@@ -181,48 +181,88 @@ export const build = async (platform: Platform) => {
|
|
|
181
181
|
)
|
|
182
182
|
}
|
|
183
183
|
|
|
184
|
-
|
|
184
|
+
export function wranglerConfig(file?: string) {
|
|
185
|
+
file ??= findWranglerConfig(_root)
|
|
186
|
+
if (!file) {
|
|
187
|
+
console.log(red(` ✗ Could not find wrangler config file`))
|
|
188
|
+
console.log(red(` Looking for: ${WRANGLER_CONFIG_FILES.join(', ')}`))
|
|
189
|
+
process.exit(1)
|
|
190
|
+
}
|
|
191
|
+
|
|
185
192
|
try {
|
|
186
|
-
return
|
|
193
|
+
return parseWranglerConfig(file)
|
|
187
194
|
} catch (e) {
|
|
188
195
|
warn(`Could not parse ${file}, using defaults`)
|
|
189
196
|
return {}
|
|
190
197
|
}
|
|
191
198
|
}
|
|
192
199
|
|
|
193
|
-
export
|
|
194
|
-
|
|
200
|
+
export function localflareManifest(opts: WranglerConfig): LocalflareManifest {
|
|
201
|
+
return {
|
|
202
|
+
name: opts.name || 'worker',
|
|
203
|
+
d1: (opts.d1_databases || []).map((db) => ({
|
|
204
|
+
binding: db.binding,
|
|
205
|
+
database_name: db.database_name,
|
|
206
|
+
})),
|
|
207
|
+
kv: (opts.kv_namespaces || []).map((kv) => ({
|
|
208
|
+
binding: kv.binding,
|
|
209
|
+
})),
|
|
210
|
+
r2: (opts.r2_buckets || []).map((r2) => ({
|
|
211
|
+
binding: r2.binding,
|
|
212
|
+
bucket_name: r2.bucket_name,
|
|
213
|
+
})),
|
|
214
|
+
queues: {
|
|
215
|
+
producers: (opts.queues?.producers || []).map((p) => ({
|
|
216
|
+
binding: p.binding,
|
|
217
|
+
queue: p.queue,
|
|
218
|
+
})),
|
|
219
|
+
consumers: (opts.queues?.consumers || []).map((c) => ({
|
|
220
|
+
queue: c.queue,
|
|
221
|
+
max_batch_size: c.max_batch_size,
|
|
222
|
+
max_batch_timeout: c.max_batch_timeout,
|
|
223
|
+
max_retries: c.max_retries,
|
|
224
|
+
dead_letter_queue: c.dead_letter_queue,
|
|
225
|
+
})),
|
|
226
|
+
},
|
|
227
|
+
do: (opts.durable_objects?.bindings || []).map((d) => ({
|
|
228
|
+
binding: d.name,
|
|
229
|
+
className: d.class_name,
|
|
230
|
+
})),
|
|
231
|
+
vars: Object.entries(opts.vars || {}).map(([key, value]) => ({
|
|
232
|
+
key,
|
|
233
|
+
value,
|
|
234
|
+
isSecret: false,
|
|
235
|
+
// isSecret: looksLikeSecret(key, value),
|
|
236
|
+
})),
|
|
237
|
+
}
|
|
238
|
+
}
|
|
195
239
|
|
|
240
|
+
export function createMiniflare(opts = {}) {
|
|
241
|
+
const entry = join(_root, opts?.main || opts?.script)
|
|
196
242
|
return new Miniflare({
|
|
197
|
-
host:
|
|
198
|
-
port:
|
|
199
|
-
https:
|
|
200
|
-
httpsKey:
|
|
201
|
-
httpsCert:
|
|
202
|
-
liveReload:
|
|
243
|
+
host: opts.host || 'localhost',
|
|
244
|
+
port: opts.port || 8787,
|
|
245
|
+
https: opts.https || false,
|
|
246
|
+
httpsKey: opts.httpsKey,
|
|
247
|
+
httpsCert: opts.httpsCert,
|
|
248
|
+
liveReload: opts.liveReload !== false,
|
|
203
249
|
updateCheck: false,
|
|
204
|
-
|
|
205
|
-
|
|
206
|
-
|
|
207
|
-
|
|
250
|
+
scriptPath: entry,
|
|
251
|
+
modules: [
|
|
252
|
+
{type: 'ESModule', path: entry},
|
|
253
|
+
],
|
|
254
|
+
compatibilityDate: opts.compatibility_date || '2024-11-01',
|
|
255
|
+
compatibilityFlags: opts.compatibility_flags || [
|
|
208
256
|
'nodejs_compat',
|
|
209
257
|
],
|
|
210
|
-
|
|
211
258
|
bindings: {
|
|
212
|
-
|
|
213
|
-
// ENVIRONMENT: 'development',
|
|
214
|
-
...config.vars,
|
|
259
|
+
...opts.vars,
|
|
215
260
|
},
|
|
216
261
|
|
|
217
|
-
d1Databases: Array.isArray(
|
|
218
|
-
|
|
219
|
-
|
|
220
|
-
|
|
221
|
-
],
|
|
222
|
-
// modules: true,
|
|
223
|
-
// modulesRules: [
|
|
224
|
-
// { type: 'ESModule', include: ['**/*.js', '**/*.ts'] },
|
|
225
|
-
// ],
|
|
262
|
+
d1Databases: Array.isArray(opts.d1_databases) ? Object.fromEntries(opts.d1_databases.map(db => [db.binding, db.database_id])) : {},
|
|
263
|
+
kvNamespaces: Object.fromEntries((opts.kv_namespaces || []).map(ns => [ns.binding, ns.id])),
|
|
264
|
+
// r2Buckets: Object.fromEntries((opts.r2_buckets || []).map(r2 => [r2.binding, r2.bucket_name])),
|
|
265
|
+
// durableObjects: Object.fromEntries((opts.durable_objects?.bindings || []).map(do => [do.name, do.class_name])),
|
|
226
266
|
|
|
227
267
|
kvPersist: join(_root, '.wrangler/state/v3/kv'),
|
|
228
268
|
cachePersist: join(_root, '.wrangler/state/v3/cache'),
|
|
@@ -240,23 +280,21 @@ export async function createMiniflare(options = {}, configPath = 'wrangler.toml'
|
|
|
240
280
|
// }),
|
|
241
281
|
|
|
242
282
|
cfFetch: false, // disable cf requests
|
|
243
|
-
upstream:
|
|
283
|
+
upstream: opts.upstream || 'https://example.com',
|
|
244
284
|
|
|
245
|
-
sitePath:
|
|
246
|
-
join(_root,
|
|
247
|
-
siteInclude:
|
|
248
|
-
siteExclude:
|
|
285
|
+
sitePath: opts.site?.bucket ?
|
|
286
|
+
join(_root, opts.site.bucket) : undefined,
|
|
287
|
+
siteInclude: opts.site?.include || ['**/*'],
|
|
288
|
+
siteExclude: opts.site?.exclude || [],
|
|
249
289
|
|
|
250
290
|
globalAsyncIO: true,
|
|
251
291
|
globalTimers: true,
|
|
252
292
|
globalRandom: true,
|
|
253
293
|
|
|
254
|
-
inspectorPort:
|
|
294
|
+
inspectorPort: opts.inspectorPort || 9229,
|
|
255
295
|
|
|
256
296
|
cache: true,
|
|
257
297
|
cacheWarnUsage: true,
|
|
258
|
-
|
|
259
|
-
...options
|
|
260
298
|
})
|
|
261
299
|
}
|
|
262
300
|
|
|
@@ -285,8 +323,8 @@ export async function watch(cb: (e: ChokidarEventName | string, file: string) =>
|
|
|
285
323
|
join(_root, '{actions,features,routes,configs,enums,libs,locales,middlewares,models,utils}/**/*.ts'),
|
|
286
324
|
join(_root, '.env.dev'),
|
|
287
325
|
join(_root, '.env.prod'),
|
|
288
|
-
|
|
289
|
-
|
|
326
|
+
join(_root, 'package.json'),
|
|
327
|
+
...WRANGLER_CONFIG_FILES.map(f => join(_root, f)),
|
|
290
328
|
], {
|
|
291
329
|
ignored: /(^|[/\\])\../, // ignore hidden files
|
|
292
330
|
persistent: true,
|