@vltpkg/vsr 0.0.0-26 → 0.0.0-27
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/LICENSE +10 -114
- package/dist/README.md +1 -0
- package/dist/assets/public/favicon.ico +0 -0
- package/dist/assets/public/fonts/courier-bold-italic.ttf +0 -0
- package/dist/assets/public/fonts/courier-bold.ttf +0 -0
- package/dist/assets/public/fonts/courier-italic.ttf +0 -0
- package/dist/assets/public/fonts/courier-regular.ttf +0 -0
- package/dist/assets/public/fonts/geist-mono.ttf +0 -0
- package/dist/assets/public/fonts/inter.ttf +0 -0
- package/dist/assets/public/index.html +70 -0
- package/dist/assets/public/index.js +1300 -0
- package/dist/assets/public/index.js.map +7 -0
- package/dist/assets/public/main.css +1 -0
- package/dist/bin/vsr.js +771 -0
- package/dist/index.js +28283 -0
- package/dist/index.js.map +8 -0
- package/package.json +6 -49
- package/DEPLOY.md +0 -163
- package/config.ts +0 -221
- package/drizzle.config.js +0 -40
- package/info/COMPARISONS.md +0 -37
- package/info/CONFIGURATION.md +0 -143
- package/info/CONTRIBUTING.md +0 -32
- package/info/DATABASE_SETUP.md +0 -108
- package/info/GRANULAR_ACCESS_TOKENS.md +0 -160
- package/info/PROJECT_STRUCTURE.md +0 -291
- package/info/ROADMAP.md +0 -27
- package/info/SUPPORT.md +0 -39
- package/info/TESTING.md +0 -301
- package/info/USER_SUPPORT.md +0 -31
- package/scripts/build-assets.js +0 -31
- package/scripts/build-bin.js +0 -62
- package/scripts/prepack.js +0 -27
- package/src/bin/vsr.ts +0 -484
- package/src/db/client.ts +0 -590
- package/src/db/migrations/0000_faulty_ricochet.sql +0 -14
- package/src/db/migrations/0000_initial.sql +0 -29
- package/src/db/migrations/0001_uuid_validation.sql +0 -35
- package/src/db/migrations/0001_wealthy_magdalene.sql +0 -7
- package/src/db/migrations/drop.sql +0 -3
- package/src/db/migrations/meta/0000_snapshot.json +0 -104
- package/src/db/migrations/meta/0001_snapshot.json +0 -155
- package/src/db/migrations/meta/_journal.json +0 -20
- package/src/db/schema.ts +0 -43
- package/src/index.ts +0 -434
- package/src/middleware/config.ts +0 -79
- package/src/middleware/telemetry.ts +0 -43
- package/src/queue/index.ts +0 -97
- package/src/routes/access.ts +0 -852
- package/src/routes/docs.ts +0 -63
- package/src/routes/misc.ts +0 -469
- package/src/routes/packages.ts +0 -2823
- package/src/routes/ping.ts +0 -39
- package/src/routes/search.ts +0 -131
- package/src/routes/static.ts +0 -74
- package/src/routes/tokens.ts +0 -259
- package/src/routes/users.ts +0 -68
- package/src/utils/auth.ts +0 -202
- package/src/utils/cache.ts +0 -587
- package/src/utils/config.ts +0 -50
- package/src/utils/database.ts +0 -69
- package/src/utils/docs.ts +0 -146
- package/src/utils/packages.ts +0 -453
- package/src/utils/response.ts +0 -125
- package/src/utils/routes.ts +0 -64
- package/src/utils/spa.ts +0 -52
- package/src/utils/tracing.ts +0 -52
- package/src/utils/upstream.ts +0 -172
- package/test/access.test.ts +0 -705
- package/test/audit.test.ts +0 -828
- package/test/dashboard.test.ts +0 -693
- package/test/dist-tags.test.ts +0 -678
- package/test/manifest.test.ts +0 -436
- package/test/packument.test.ts +0 -530
- package/test/ping.test.ts +0 -41
- package/test/search.test.ts +0 -472
- package/test/setup.ts +0 -130
- package/test/static.test.ts +0 -646
- package/test/tokens.test.ts +0 -389
- package/test/utils/auth.test.ts +0 -214
- package/test/utils/packages.test.ts +0 -235
- package/test/utils/response.test.ts +0 -184
- package/test/whoami.test.ts +0 -119
- package/tsconfig.json +0 -16
- package/tsconfig.worker.json +0 -3
- package/typedoc.mjs +0 -2
- package/types.ts +0 -598
- package/vitest.config.ts +0 -25
- package/vlt.json.example +0 -56
- package/wrangler.json +0 -65
- /package/{src → dist}/assets/public/images/bg.png +0 -0
- /package/{src → dist}/assets/public/images/clients/logo-bun.png +0 -0
- /package/{src → dist}/assets/public/images/clients/logo-deno.png +0 -0
- /package/{src → dist}/assets/public/images/clients/logo-npm.png +0 -0
- /package/{src → dist}/assets/public/images/clients/logo-pnpm.png +0 -0
- /package/{src → dist}/assets/public/images/clients/logo-vlt.png +0 -0
- /package/{src → dist}/assets/public/images/clients/logo-yarn.png +0 -0
- /package/{src → dist}/assets/public/images/favicon/apple-touch-icon.png +0 -0
- /package/{src → dist}/assets/public/images/favicon/favicon-96x96.png +0 -0
- /package/{src → dist}/assets/public/images/favicon/favicon.ico +0 -0
- /package/{src → dist}/assets/public/images/favicon/favicon.svg +0 -0
- /package/{src → dist}/assets/public/images/favicon/site.webmanifest +0 -0
- /package/{src → dist}/assets/public/images/favicon/web-app-manifest-192x192.png +0 -0
- /package/{src → dist}/assets/public/images/favicon/web-app-manifest-512x512.png +0 -0
- /package/{src → dist}/assets/public/styles/styles.css +0 -0
- /package/{src → dist}/bin/demo/package.json +0 -0
- /package/{src → dist}/bin/demo/vlt.json +0 -0
package/src/bin/vsr.ts
DELETED
|
@@ -1,484 +0,0 @@
|
|
|
1
|
-
#!/usr/bin/env NODE_OPTIONS=--no-warnings node
|
|
2
|
-
import type { Args } from '../../types.ts'
|
|
3
|
-
import { fileURLToPath } from 'node:url'
|
|
4
|
-
import path from 'node:path'
|
|
5
|
-
import { spawn } from 'node:child_process'
|
|
6
|
-
import { PathScurry } from 'path-scurry'
|
|
7
|
-
import { PackageJson } from '@vltpkg/package-json'
|
|
8
|
-
import { PackageInfoClient } from '@vltpkg/package-info'
|
|
9
|
-
import { createServer } from '@vltpkg/server'
|
|
10
|
-
import { existsSync, readFileSync } from 'node:fs'
|
|
11
|
-
import type { VltServerOptions } from '@vltpkg/server'
|
|
12
|
-
import {
|
|
13
|
-
DAEMON_PORT,
|
|
14
|
-
DAEMON_URL,
|
|
15
|
-
URL,
|
|
16
|
-
WRANGLER_CONFIG,
|
|
17
|
-
} from '../../config.ts'
|
|
18
|
-
import { minArgs } from 'minargs'
|
|
19
|
-
import { load } from '@vltpkg/vlt-json'
|
|
20
|
-
|
|
21
|
-
const usage = `USAGE:
|
|
22
|
-
|
|
23
|
-
$ vsr [<command>] [<options>]
|
|
24
|
-
|
|
25
|
-
COMMANDS:
|
|
26
|
-
|
|
27
|
-
dev Start development server (default)
|
|
28
|
-
deploy Deploy to Cloudflare Workers
|
|
29
|
-
|
|
30
|
-
OPTIONS: DESCRIPTION:
|
|
31
|
-
|
|
32
|
-
--daemon=<boolean> Run filesystem daemon (default: true)
|
|
33
|
-
--telemetry=<boolean> Run with telemetry reporting (default: true)
|
|
34
|
-
-p, --port=<number> Run on a specific port (default: ${DAEMON_PORT})
|
|
35
|
-
-c, --config=<path> Load configuration from vlt.json file
|
|
36
|
-
-d, --debug Run in debug mode
|
|
37
|
-
-h, --help Print usage information
|
|
38
|
-
|
|
39
|
-
DEPLOY OPTIONS:
|
|
40
|
-
|
|
41
|
-
--env=<string> Environment to deploy to (dev, staging, prod)
|
|
42
|
-
--db-name=<string> Override D1 database name
|
|
43
|
-
--bucket-name=<string> Override R2 bucket name
|
|
44
|
-
--queue-name=<string> Override queue name
|
|
45
|
-
--dry-run Show what would be deployed without deploying
|
|
46
|
-
|
|
47
|
-
EXAMPLES:
|
|
48
|
-
|
|
49
|
-
$ vsr # Run dev server with all defaults
|
|
50
|
-
$ vsr dev --port=3000 --debug # Custom port with debug
|
|
51
|
-
$ vsr deploy # Deploy to default environment
|
|
52
|
-
$ vsr deploy --env=prod # Deploy to production
|
|
53
|
-
$ vsr deploy --dry-run # Preview deployment
|
|
54
|
-
$ vsr --config=/path/to/vlt.json # Use specific config file
|
|
55
|
-
`
|
|
56
|
-
|
|
57
|
-
const defaults: Args = {
|
|
58
|
-
daemon: true,
|
|
59
|
-
telemetry: true,
|
|
60
|
-
debug: false,
|
|
61
|
-
help: false,
|
|
62
|
-
port: WRANGLER_CONFIG.port,
|
|
63
|
-
config: undefined,
|
|
64
|
-
env: undefined,
|
|
65
|
-
'db-name': undefined,
|
|
66
|
-
'bucket-name': undefined,
|
|
67
|
-
'queue-name': undefined,
|
|
68
|
-
'dry-run': false,
|
|
69
|
-
}
|
|
70
|
-
|
|
71
|
-
const opts = {
|
|
72
|
-
alias: {
|
|
73
|
-
p: 'port',
|
|
74
|
-
c: 'config',
|
|
75
|
-
d: 'debug',
|
|
76
|
-
h: 'help',
|
|
77
|
-
},
|
|
78
|
-
boolean: ['debug', 'help', 'daemon', 'telemetry', 'dry-run'],
|
|
79
|
-
string: [
|
|
80
|
-
'port',
|
|
81
|
-
'config',
|
|
82
|
-
'env',
|
|
83
|
-
'db-name',
|
|
84
|
-
'bucket-name',
|
|
85
|
-
'queue-name',
|
|
86
|
-
],
|
|
87
|
-
default: defaults,
|
|
88
|
-
positionalValues: true, // Allow space-separated values like -p 3000
|
|
89
|
-
}
|
|
90
|
-
|
|
91
|
-
// parse args
|
|
92
|
-
const { args, positionals } = minArgs(opts)
|
|
93
|
-
|
|
94
|
-
// Extract command (default to 'dev' if not specified)
|
|
95
|
-
const command = positionals[0] || 'dev'
|
|
96
|
-
|
|
97
|
-
// Helper functions to extract values from minArgs array format
|
|
98
|
-
function getBooleanValue(
|
|
99
|
-
arg: string[] | undefined,
|
|
100
|
-
defaultValue: boolean,
|
|
101
|
-
): boolean {
|
|
102
|
-
if (!arg || arg.length === 0) return defaultValue
|
|
103
|
-
const value = arg[0]
|
|
104
|
-
if (value === '' || value === undefined) return true // flag present without value
|
|
105
|
-
return value !== 'false' && value !== '0'
|
|
106
|
-
}
|
|
107
|
-
|
|
108
|
-
function getStringValue(
|
|
109
|
-
arg: string[] | undefined,
|
|
110
|
-
defaultValue?: string,
|
|
111
|
-
): string | undefined {
|
|
112
|
-
if (!arg || arg.length === 0) return defaultValue
|
|
113
|
-
return arg[0] || defaultValue
|
|
114
|
-
}
|
|
115
|
-
|
|
116
|
-
function getNumberValue(
|
|
117
|
-
arg: string[] | undefined,
|
|
118
|
-
defaultValue: number,
|
|
119
|
-
): number {
|
|
120
|
-
if (!arg || arg.length === 0) return defaultValue
|
|
121
|
-
const value = arg[0]
|
|
122
|
-
return Number(value) || defaultValue
|
|
123
|
-
}
|
|
124
|
-
|
|
125
|
-
// Type definition for VSR config in vlt.json
|
|
126
|
-
interface VsrConfig {
|
|
127
|
-
registry?: {
|
|
128
|
-
daemon?: boolean
|
|
129
|
-
telemetry?: boolean
|
|
130
|
-
debug?: boolean
|
|
131
|
-
port?: number
|
|
132
|
-
deploy?: {
|
|
133
|
-
environments?: {
|
|
134
|
-
[key: string]: DeployEnvironment
|
|
135
|
-
}
|
|
136
|
-
sentry?: {
|
|
137
|
-
dsn?: string
|
|
138
|
-
environment?: string
|
|
139
|
-
sampleRate?: number
|
|
140
|
-
tracesSampleRate?: number
|
|
141
|
-
}
|
|
142
|
-
}
|
|
143
|
-
}
|
|
144
|
-
daemon?: boolean
|
|
145
|
-
telemetry?: boolean
|
|
146
|
-
debug?: boolean
|
|
147
|
-
port?: number
|
|
148
|
-
}
|
|
149
|
-
|
|
150
|
-
interface DeployEnvironment {
|
|
151
|
-
databaseName?: string
|
|
152
|
-
bucketName?: string
|
|
153
|
-
queueName?: string
|
|
154
|
-
vars?: Record<string, any>
|
|
155
|
-
sentry?: {
|
|
156
|
-
dsn?: string
|
|
157
|
-
environment?: string
|
|
158
|
-
sampleRate?: number
|
|
159
|
-
tracesSampleRate?: number
|
|
160
|
-
}
|
|
161
|
-
}
|
|
162
|
-
|
|
163
|
-
// Load configuration from vlt.json
|
|
164
|
-
function loadVltConfig(configPath?: string): VsrConfig {
|
|
165
|
-
try {
|
|
166
|
-
const isVsrConfig = (
|
|
167
|
-
x: unknown,
|
|
168
|
-
_file: string,
|
|
169
|
-
): asserts x is VsrConfig => {
|
|
170
|
-
if (x === null || typeof x !== 'object') {
|
|
171
|
-
throw new Error('Config must be an object')
|
|
172
|
-
}
|
|
173
|
-
}
|
|
174
|
-
|
|
175
|
-
let configData: VsrConfig | undefined
|
|
176
|
-
|
|
177
|
-
if (configPath) {
|
|
178
|
-
// Custom config path specified
|
|
179
|
-
if (!existsSync(configPath)) {
|
|
180
|
-
// eslint-disable-next-line no-console
|
|
181
|
-
console.warn(`Config file not found: ${configPath}`)
|
|
182
|
-
return {}
|
|
183
|
-
}
|
|
184
|
-
|
|
185
|
-
// For custom paths, we need to read the file manually
|
|
186
|
-
const configContent = readFileSync(configPath, 'utf8')
|
|
187
|
-
try {
|
|
188
|
-
configData = JSON.parse(configContent) as VsrConfig
|
|
189
|
-
} catch (_err) {
|
|
190
|
-
// eslint-disable-next-line no-console
|
|
191
|
-
console.warn(`Failed to parse config file ${configPath}`)
|
|
192
|
-
return {}
|
|
193
|
-
}
|
|
194
|
-
} else {
|
|
195
|
-
// Use vlt-json to find and load project config
|
|
196
|
-
try {
|
|
197
|
-
configData = load('config', isVsrConfig)
|
|
198
|
-
} catch (_err) {
|
|
199
|
-
configData = undefined
|
|
200
|
-
}
|
|
201
|
-
}
|
|
202
|
-
|
|
203
|
-
return configData ?? {}
|
|
204
|
-
} catch (_err) {
|
|
205
|
-
// Can't access DEBUG here since it hasn't been defined yet
|
|
206
|
-
return {}
|
|
207
|
-
}
|
|
208
|
-
}
|
|
209
|
-
|
|
210
|
-
// Get the config path from CLI args
|
|
211
|
-
const configPath = getStringValue(args.config)
|
|
212
|
-
|
|
213
|
-
// Load config and merge with CLI args (CLI args take precedence)
|
|
214
|
-
const vltConfig = loadVltConfig(configPath)
|
|
215
|
-
const registryConfig = vltConfig.registry ?? {}
|
|
216
|
-
|
|
217
|
-
// Extract parsed args with config fallbacks, CLI args take precedence
|
|
218
|
-
const PORT = getNumberValue(
|
|
219
|
-
args.port,
|
|
220
|
-
registryConfig.port ?? vltConfig.port ?? defaults.port,
|
|
221
|
-
)
|
|
222
|
-
const TELEMETRY = getBooleanValue(
|
|
223
|
-
args.telemetry,
|
|
224
|
-
registryConfig.telemetry ??
|
|
225
|
-
vltConfig.telemetry ??
|
|
226
|
-
defaults.telemetry,
|
|
227
|
-
)
|
|
228
|
-
const DAEMON = getBooleanValue(
|
|
229
|
-
args.daemon,
|
|
230
|
-
registryConfig.daemon ?? vltConfig.daemon ?? defaults.daemon,
|
|
231
|
-
)
|
|
232
|
-
const DEBUG = getBooleanValue(
|
|
233
|
-
args.debug,
|
|
234
|
-
registryConfig.debug ?? vltConfig.debug ?? defaults.debug,
|
|
235
|
-
)
|
|
236
|
-
|
|
237
|
-
// Deploy-specific configuration
|
|
238
|
-
const ENV = getStringValue(args.env, 'dev')
|
|
239
|
-
const DRY_RUN = getBooleanValue(
|
|
240
|
-
args['dry-run'],
|
|
241
|
-
defaults['dry-run'] ?? false,
|
|
242
|
-
)
|
|
243
|
-
const DB_NAME_OVERRIDE = getStringValue(args['db-name'])
|
|
244
|
-
const BUCKET_NAME_OVERRIDE = getStringValue(args['bucket-name'])
|
|
245
|
-
const QUEUE_NAME_OVERRIDE = getStringValue(args['queue-name'])
|
|
246
|
-
|
|
247
|
-
// Print usage information
|
|
248
|
-
function printUsage(): void {
|
|
249
|
-
// eslint-disable-next-line no-console
|
|
250
|
-
console.log(usage)
|
|
251
|
-
}
|
|
252
|
-
|
|
253
|
-
// Deploy function
|
|
254
|
-
async function deployToCloudflare(): Promise<void> {
|
|
255
|
-
const deployConfig = registryConfig.deploy
|
|
256
|
-
const envConfig = deployConfig?.environments?.[ENV ?? 'dev'] ?? {}
|
|
257
|
-
|
|
258
|
-
// Determine resource names with precedence: CLI args > env config > defaults
|
|
259
|
-
const databaseName =
|
|
260
|
-
DB_NAME_OVERRIDE ?? envConfig.databaseName ?? 'vsr-database'
|
|
261
|
-
const bucketName =
|
|
262
|
-
BUCKET_NAME_OVERRIDE ?? envConfig.bucketName ?? 'vsr-bucket'
|
|
263
|
-
const queueName =
|
|
264
|
-
QUEUE_NAME_OVERRIDE ??
|
|
265
|
-
envConfig.queueName ??
|
|
266
|
-
'cache-refresh-queue'
|
|
267
|
-
|
|
268
|
-
// Build Sentry configuration
|
|
269
|
-
const sentryConfig = envConfig.sentry ?? deployConfig?.sentry ?? {}
|
|
270
|
-
const sentryDsn =
|
|
271
|
-
sentryConfig.dsn ??
|
|
272
|
-
'https://909b085eb764c00250ad312660c2fdf1@o4506397716054016.ingest.us.sentry.io/4509492612300800'
|
|
273
|
-
const sentryEnv = sentryConfig.environment ?? ENV
|
|
274
|
-
|
|
275
|
-
// Build wrangler deploy arguments
|
|
276
|
-
const wranglerArgs = [
|
|
277
|
-
'deploy',
|
|
278
|
-
indexPath,
|
|
279
|
-
'--name',
|
|
280
|
-
`vsr-${ENV}`,
|
|
281
|
-
'--compatibility-date',
|
|
282
|
-
'2024-09-23',
|
|
283
|
-
'--var',
|
|
284
|
-
`SENTRY_DSN:${sentryDsn}`,
|
|
285
|
-
'--var',
|
|
286
|
-
`SENTRY_ENVIRONMENT:${sentryEnv}`,
|
|
287
|
-
'--var',
|
|
288
|
-
`ARG_DEBUG:${DEBUG}`,
|
|
289
|
-
'--var',
|
|
290
|
-
`ARG_TELEMETRY:${TELEMETRY}`,
|
|
291
|
-
'--var',
|
|
292
|
-
`ARG_DAEMON:${DAEMON}`,
|
|
293
|
-
]
|
|
294
|
-
|
|
295
|
-
// Add D1 database binding
|
|
296
|
-
wranglerArgs.push('--d1', `DB=${databaseName}`)
|
|
297
|
-
|
|
298
|
-
// Add R2 bucket binding
|
|
299
|
-
wranglerArgs.push('--r2', `BUCKET=${bucketName}`)
|
|
300
|
-
|
|
301
|
-
// Add queue bindings
|
|
302
|
-
wranglerArgs.push(
|
|
303
|
-
'--queue-producer',
|
|
304
|
-
`CACHE_REFRESH_QUEUE=${queueName}`,
|
|
305
|
-
)
|
|
306
|
-
wranglerArgs.push('--queue-consumer', queueName)
|
|
307
|
-
|
|
308
|
-
// Add custom environment variables from config
|
|
309
|
-
if (envConfig.vars) {
|
|
310
|
-
for (const [key, value] of Object.entries(envConfig.vars)) {
|
|
311
|
-
wranglerArgs.push('--var', `${key}:${value}`)
|
|
312
|
-
}
|
|
313
|
-
}
|
|
314
|
-
|
|
315
|
-
if (DRY_RUN) {
|
|
316
|
-
wranglerArgs.push('--dry-run')
|
|
317
|
-
// eslint-disable-next-line no-console
|
|
318
|
-
console.log(
|
|
319
|
-
'🔍 Dry run - would execute:',
|
|
320
|
-
wranglerBin,
|
|
321
|
-
wranglerArgs.join(' '),
|
|
322
|
-
)
|
|
323
|
-
// eslint-disable-next-line no-console
|
|
324
|
-
console.log('\n📋 Deployment configuration:')
|
|
325
|
-
// eslint-disable-next-line no-console
|
|
326
|
-
console.log(` Environment: ${ENV}`)
|
|
327
|
-
// eslint-disable-next-line no-console
|
|
328
|
-
console.log(` Database: ${databaseName}`)
|
|
329
|
-
// eslint-disable-next-line no-console
|
|
330
|
-
console.log(` Bucket: ${bucketName}`)
|
|
331
|
-
// eslint-disable-next-line no-console
|
|
332
|
-
console.log(` Queue: ${queueName}`)
|
|
333
|
-
// eslint-disable-next-line no-console
|
|
334
|
-
console.log(` Sentry DSN: ${sentryDsn}`)
|
|
335
|
-
// eslint-disable-next-line no-console
|
|
336
|
-
console.log(` Sentry Environment: ${sentryEnv}`)
|
|
337
|
-
return
|
|
338
|
-
}
|
|
339
|
-
|
|
340
|
-
// eslint-disable-next-line no-console
|
|
341
|
-
console.log(`🚀 Deploying VSR to ${ENV} environment...`)
|
|
342
|
-
|
|
343
|
-
return new Promise((resolve, reject) => {
|
|
344
|
-
const deployProcess = spawn(wranglerBin, wranglerArgs, {
|
|
345
|
-
cwd: registryRoot,
|
|
346
|
-
stdio: 'inherit',
|
|
347
|
-
})
|
|
348
|
-
|
|
349
|
-
deployProcess.on('close', code => {
|
|
350
|
-
if (code === 0) {
|
|
351
|
-
// eslint-disable-next-line no-console
|
|
352
|
-
console.log(`✅ Successfully deployed VSR to ${ENV}`)
|
|
353
|
-
resolve()
|
|
354
|
-
} else {
|
|
355
|
-
reject(new Error(`Deployment failed with exit code ${code}`))
|
|
356
|
-
}
|
|
357
|
-
})
|
|
358
|
-
|
|
359
|
-
deployProcess.on('error', error => {
|
|
360
|
-
reject(
|
|
361
|
-
new Error(`Failed to start deployment: ${error.message}`),
|
|
362
|
-
)
|
|
363
|
-
})
|
|
364
|
-
})
|
|
365
|
-
}
|
|
366
|
-
|
|
367
|
-
// Check if the help flag was passed
|
|
368
|
-
if (args.help) {
|
|
369
|
-
printUsage()
|
|
370
|
-
process.exit(0)
|
|
371
|
-
}
|
|
372
|
-
|
|
373
|
-
// Validate command
|
|
374
|
-
if (!['dev', 'deploy'].includes(command)) {
|
|
375
|
-
// eslint-disable-next-line no-console
|
|
376
|
-
console.error(`❌ Unknown command: ${command}`)
|
|
377
|
-
printUsage()
|
|
378
|
-
process.exit(1)
|
|
379
|
-
}
|
|
380
|
-
|
|
381
|
-
// TODO: Remove the demo/dummy project once server doesn't need one
|
|
382
|
-
const __filename = fileURLToPath(import.meta.url)
|
|
383
|
-
const __dirname = path.dirname(__filename)
|
|
384
|
-
const demo = path.resolve(__dirname, './demo')
|
|
385
|
-
|
|
386
|
-
// Resolve paths relative to this script's location
|
|
387
|
-
const registryRoot = path.resolve(__dirname, '../../')
|
|
388
|
-
const indexPath = path.resolve(registryRoot, 'dist/index.js')
|
|
389
|
-
|
|
390
|
-
// Find the wrangler binary from node_modules
|
|
391
|
-
const wranglerBinPath = path.resolve(
|
|
392
|
-
registryRoot,
|
|
393
|
-
'node_modules/.bin/wrangler',
|
|
394
|
-
)
|
|
395
|
-
const wranglerBin =
|
|
396
|
-
existsSync(wranglerBinPath) ? wranglerBinPath : 'wrangler'
|
|
397
|
-
|
|
398
|
-
const serverOptions = {
|
|
399
|
-
scurry: new PathScurry(demo),
|
|
400
|
-
projectRoot: demo,
|
|
401
|
-
packageJson: new PackageJson(),
|
|
402
|
-
catalog: {},
|
|
403
|
-
catalogs: {},
|
|
404
|
-
registry: 'https://registry.npmjs.org/',
|
|
405
|
-
registries: {},
|
|
406
|
-
'scope-registries': {},
|
|
407
|
-
'git-hosts': {},
|
|
408
|
-
'git-host-archives': {},
|
|
409
|
-
} as VltServerOptions
|
|
410
|
-
|
|
411
|
-
void (async () => {
|
|
412
|
-
try {
|
|
413
|
-
if (command === 'deploy') {
|
|
414
|
-
await deployToCloudflare()
|
|
415
|
-
return
|
|
416
|
-
}
|
|
417
|
-
|
|
418
|
-
// Default 'dev' command
|
|
419
|
-
if (DAEMON) {
|
|
420
|
-
// Save original process.argv to restore later
|
|
421
|
-
const originalArgv = process.argv.slice()
|
|
422
|
-
|
|
423
|
-
// Temporarily modify process.argv to remove VSR-specific flags that daemon doesn't understand
|
|
424
|
-
// Keep only the basic node command and script path
|
|
425
|
-
// eslint-disable-next-line @typescript-eslint/no-non-null-assertion
|
|
426
|
-
process.argv = [process.argv[0]!, process.argv[1]!]
|
|
427
|
-
|
|
428
|
-
try {
|
|
429
|
-
const server = createServer({
|
|
430
|
-
...serverOptions,
|
|
431
|
-
// eslint-disable-next-line @typescript-eslint/no-unsafe-assignment
|
|
432
|
-
packageInfo: new PackageInfoClient() as any,
|
|
433
|
-
})
|
|
434
|
-
|
|
435
|
-
await server.start({
|
|
436
|
-
port: DAEMON_PORT,
|
|
437
|
-
})
|
|
438
|
-
|
|
439
|
-
// eslint-disable-next-line no-console
|
|
440
|
-
console.log(`Daemon: ${DAEMON_URL}`)
|
|
441
|
-
} finally {
|
|
442
|
-
// Restore original process.argv
|
|
443
|
-
process.argv = originalArgv
|
|
444
|
-
}
|
|
445
|
-
}
|
|
446
|
-
|
|
447
|
-
// eslint-disable-next-line no-console
|
|
448
|
-
console.log(`VSR: ${URL}`)
|
|
449
|
-
|
|
450
|
-
// spawn the wrangler dev process with resolved paths
|
|
451
|
-
const { stdout, stderr } = spawn(
|
|
452
|
-
wranglerBin,
|
|
453
|
-
[
|
|
454
|
-
'dev',
|
|
455
|
-
indexPath,
|
|
456
|
-
'--local',
|
|
457
|
-
'--persist-to=local-store',
|
|
458
|
-
'--no-remote',
|
|
459
|
-
`--port=${PORT}`,
|
|
460
|
-
`--var=ARG_DEBUG:${DEBUG}`,
|
|
461
|
-
`--var=ARG_TELEMETRY:${TELEMETRY}`,
|
|
462
|
-
`--var=ARG_DAEMON:${DAEMON}`,
|
|
463
|
-
],
|
|
464
|
-
{
|
|
465
|
-
cwd: registryRoot, // Set working directory to registry root
|
|
466
|
-
},
|
|
467
|
-
)
|
|
468
|
-
|
|
469
|
-
if (DEBUG) {
|
|
470
|
-
stdout.on('data', (data: Buffer) => {
|
|
471
|
-
// eslint-disable-next-line no-console
|
|
472
|
-
console.log(data.toString())
|
|
473
|
-
})
|
|
474
|
-
stderr.on('data', (data: Buffer) => {
|
|
475
|
-
// eslint-disable-next-line no-console
|
|
476
|
-
console.error(data.toString())
|
|
477
|
-
})
|
|
478
|
-
}
|
|
479
|
-
} catch (error: unknown) {
|
|
480
|
-
// eslint-disable-next-line no-console
|
|
481
|
-
console.error('Failed to start:', error)
|
|
482
|
-
process.exit(1)
|
|
483
|
-
}
|
|
484
|
-
})()
|