Skip to content

Commit b950339

Browse files
authored
Switch deno scripts to plain node (#3409)
Might as well now that Deno is effectively dead and Node can do all these things. The changes are pretty mechanical, though there are a lot of them. I tested a few of the scripts manually, but some can't be fully tested except by using them. They're all manually run scripts, so if there are remaining issues we'll find them when we try to use them. Multiple LLMs agreed it looks fine. There are a couple of small behavior changes, but they're improvements.
1 parent 5147e77 commit b950339

12 files changed

Lines changed: 188 additions & 115 deletions

‎.gitignore‎

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
/dist
22
/node_modules
3-
deno.lock
43

54
# IDEs and editors
65
/.idea

‎.vscode/settings.json‎

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,5 @@
1717
},
1818
"vite.browserType": "system",
1919
"vite.buildCommand": "npm run build",
20-
"vite.devCommand": "npm run start:msw",
21-
"deno.enablePaths": ["./tools/deno"]
20+
"vite.devCommand": "npm run start:msw"
2221
}

‎package-lock.json‎

Lines changed: 75 additions & 5 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

‎package.json‎

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -97,6 +97,7 @@
9797
"zustand": "^5.0.3"
9898
},
9999
"devDependencies": {
100+
"@commander-js/extra-typings": "^15.0.0",
100101
"@mswjs/http-middleware": "^0.10.3",
101102
"@oxide/openapi-gen-ts": "~0.16.0",
102103
"@playwright/test": "^1.61.0",
@@ -111,6 +112,8 @@
111112
"@vitejs/plugin-basic-ssl": "^2.3.0",
112113
"@vitejs/plugin-react": "^6.0.2",
113114
"@vitest/browser-playwright": "^5.0.3",
115+
"commander": "^15.0.0",
116+
"dax": "^0.50.1",
114117
"eslint-plugin-playwright": "^2.10.4",
115118
"eslint-plugin-react-hook-form": "^0.3.1",
116119
"husky": "^9.1.7",
Lines changed: 31 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
#! /usr/bin/env -S deno run --allow-run --allow-net --allow-read --allow-write=/tmp --allow-env
1+
#! /usr/bin/env node
22

33
/*
44
* This Source Code Form is subject to the terms of the Mozilla Public
@@ -7,9 +7,11 @@
77
*
88
* Copyright Oxide Computer Company
99
*/
10-
import { Command, ValidationError } from 'jsr:@cliffy/[email protected]'
11-
import { $ } from 'jsr:@david/[email protected]'
12-
import { exists } from 'jsr:@std/[email protected]'
10+
import { existsSync } from 'node:fs'
11+
import { mkdir, writeFile } from 'node:fs/promises'
12+
13+
import { Command, Option } from '@commander-js/extra-typings'
14+
import $ from 'dax'
1315

1416
import { isJjRepository, pickPr, resolveLocalCommit } from './common.ts'
1517

@@ -122,7 +124,7 @@ const remoteSource: Source = {
122124
/** Read schemas from the git repo in the current directory (run from an omicron checkout) */
123125
async function createLocalSource(): Promise<Source> {
124126
if (!$.commandExistsSync('git')) throw new Error('--local requires git')
125-
const repoRoot = Deno.cwd()
127+
const repoRoot = process.cwd()
126128
// jj's working copy is always a commit, so in a jj repo @ is the natural
127129
// default and reflects in-progress (even uncommitted) work. Plain git uses HEAD.
128130
const isJj = await isJjRepository(repoRoot)
@@ -243,8 +245,6 @@ async function resolveTarget(
243245

244246
// Two refs: compare latest schema on each
245247
if (ref2 !== undefined) {
246-
if (ref1 === undefined)
247-
throw new ValidationError('Provide a base ref when passing two refs')
248248
const [baseRef, headRef] = await Promise.all([
249249
source.resolveCommit(norm(ref1)),
250250
source.resolveCommit(norm(ref2)),
@@ -297,11 +297,11 @@ async function ensureSchema(
297297
) {
298298
const dir = `/tmp/api-diff/${commit}/${specFilename}`
299299
const schemaPath = `${dir}/spec.json`
300-
if (force || !(await exists(schemaPath))) {
301-
await $`mkdir -p ${dir}`
300+
if (force || !existsSync(schemaPath)) {
301+
await mkdir(dir, { recursive: true })
302302
console.error(`Loading ${specFilename}...`)
303303
const content = await source.readSpec(commit, specFilename)
304-
await Deno.writeTextFile(schemaPath, content)
304+
await writeFile(schemaPath, content)
305305
}
306306
return schemaPath
307307
}
@@ -315,15 +315,15 @@ const OXFMT_CONFIG = '/tmp/api-diff/oxfmt.json'
315315
*/
316316
async function ensureClientTools() {
317317
await $`npx --yes --package @oxide/openapi-gen-ts@latest --package oxfmt true`
318-
await $`mkdir -p /tmp/api-diff`
318+
await mkdir('/tmp/api-diff', { recursive: true })
319319
// an explicit (empty) config silences oxfmt's "No config found" warning
320-
await Deno.writeTextFile(OXFMT_CONFIG, '{}\n')
320+
await writeFile(OXFMT_CONFIG, '{}\n')
321321
}
322322

323323
async function ensureClient(schemaPath: string, force: boolean) {
324324
const dir = schemaPath.replace(/\/spec\.json$/, '')
325325
const clientPath = `${dir}/Api.ts`
326-
if (force || !(await exists(clientPath))) {
326+
if (force || !existsSync(clientPath)) {
327327
console.error(`Generating client...`)
328328
await $`npx --yes @oxide/openapi-gen-ts@latest ${schemaPath} ${dir}`
329329
await $`npx --yes oxfmt -c ${OXFMT_CONFIG} ${dir}`
@@ -345,7 +345,7 @@ async function runDiff(
345345
const filename = base.endsWith('spec.json') ? 'spec.json' : 'Api.ts'
346346
// prefer delta if it exists and output is a terminal, otherwise use diff
347347
// https://dandavison.github.io/delta/
348-
const useDelta = $.commandExistsSync('delta') && Deno.stdout.isTerminal()
348+
const useDelta = $.commandExistsSync('delta') && process.stdout.isTTY
349349

350350
// use -L to set labels, extracting version from spec filename (e.g., nexus-2026010300.0.0-7599dd.json)
351351
const getVersion = (spec: string) =>
@@ -359,9 +359,10 @@ async function runDiff(
359359

360360
await new Command()
361361
.name('api-diff')
362-
.description(
363-
`Display changes to API client or schema caused by a given Omicron PR.
364-
362+
.description('Display changes to API client or schema caused by a given Omicron PR.')
363+
.addHelpText(
364+
'after',
365+
`
365366
Arguments:
366367
No args Interactive PR picker (or, with --local, the default ref)
367368
<ref> PR number, commit SHA, branch, or tag
@@ -376,32 +377,29 @@ the current schema (nexus-latest) at each commit:
376377
Refs are git revisions (jj revsets in a jj repo). PR numbers are not available.
377378
378379
Dependencies:
379-
- Deno
380+
- Node.js
380381
- GitHub CLI (gh), or git in the current directory with --local
381382
- Optional: delta diff pager https://dandavison.github.io/delta/
382383
- Optional: fzf for PR picker https://github.com/junegunn/fzf`
383384
)
384-
.helpOption('-h, --help', 'Show help')
385385
.option('--local', 'Read schemas from the repo in the current directory')
386386
.option('--force', 'Redo everything even if cached')
387-
.type('format', ({ value }) => {
388-
if (value !== 'ts' && value !== 'schema') {
389-
throw new ValidationError(`Invalid format: '${value}'. Must be 'ts' or 'schema'`)
390-
}
391-
return value
392-
})
393-
.option('-f, --format <format:format>', "Output format: 'ts' or 'schema'", {
394-
default: 'ts' as const,
395-
})
396-
.arguments('[ref1:string] [ref2:string]')
397-
.action(async (options, ref?: string, ref2?: string) => {
387+
.addOption(
388+
new Option('-f, --format <format>', 'Output format')
389+
.choices(['ts', 'schema'] as const)
390+
.default('ts' as const)
391+
)
392+
.argument('[ref1]')
393+
.argument('[ref2]')
394+
.showHelpAfterError()
395+
.action(async (ref, ref2, options) => {
398396
try {
399397
const local = options.local ?? false
398+
const force = options.force ?? false
400399
if (!local && !$.commandExistsSync('gh')) throw new Error('Need gh (GitHub CLI)')
401400
const source = local ? await createLocalSource() : remoteSource
402401

403402
const target = await resolveTarget(source, local, ref, ref2)
404-
const force = options.force ?? false
405403

406404
const [baseSchema, headSchema] = await Promise.all([
407405
ensureSchema(source, target.baseCommit, target.baseSchema, force),
@@ -420,7 +418,7 @@ Dependencies:
420418
}
421419
} catch (e) {
422420
console.error(`error: ${e instanceof Error ? e.message : String(e)}`)
423-
Deno.exit(1)
421+
process.exit(1)
424422
}
425423
})
426-
.parse(Deno.args)
424+
.parseAsync()

0 commit comments

Comments
 (0)