Skip to content

Commit 5b3364b

Browse files
committed
style(server-rust): prettier-format imported npm tooling files
The TS formatting check (`prettier --check .`) failed on 3 imported npm files I hadn't edited (so lint-staged never reformatted them) — they kept the durable-streams style: npm/assemble.mjs, npm/bin/launcher.cjs, npm/test/launcher.test.mjs. Formatting only; npm tooling tests still pass (4/4).
1 parent 9d08fbf commit 5b3364b

3 files changed

Lines changed: 60 additions & 60 deletions

File tree

packages/server-rust/npm/assemble.mjs

Lines changed: 22 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -6,58 +6,58 @@ import {
66
existsSync,
77
chmodSync,
88
rmSync,
9-
} from "node:fs"
10-
import { join, dirname } from "node:path"
11-
import { fileURLToPath } from "node:url"
9+
} from 'node:fs'
10+
import { join, dirname } from 'node:path'
11+
import { fileURLToPath } from 'node:url'
1212

1313
const here = dirname(fileURLToPath(import.meta.url))
1414

1515
function readJson(p) {
16-
return JSON.parse(readFileSync(p, "utf8"))
16+
return JSON.parse(readFileSync(p, 'utf8'))
1717
}
1818

1919
export function assemble({ version, binsDir, outDir }) {
20-
if (!version) throw new Error("assemble: version is required")
21-
const targets = readJson(join(here, "targets.json"))
22-
const mainTpl = readJson(join(here, "templates", "main.package.json"))
23-
const platTpl = readJson(join(here, "templates", "platform.package.json"))
20+
if (!version) throw new Error('assemble: version is required')
21+
const targets = readJson(join(here, 'targets.json'))
22+
const mainTpl = readJson(join(here, 'templates', 'main.package.json'))
23+
const platTpl = readJson(join(here, 'templates', 'platform.package.json'))
2424

2525
// Platform packages.
2626
const optionalDependencies = {}
2727
for (const t of targets) {
28-
const src = join(binsDir, t.rustTarget, "durable-streams-server")
28+
const src = join(binsDir, t.rustTarget, 'durable-streams-server')
2929
if (!existsSync(src))
3030
throw new Error(`assemble: missing binary for ${t.rustTarget} at ${src}`)
3131
const pkgDir = join(outDir, t.rustTarget)
3232
rmSync(pkgDir, { recursive: true, force: true })
33-
mkdirSync(join(pkgDir, "bin"), { recursive: true })
34-
const dest = join(pkgDir, "bin", "durable-streams-server")
33+
mkdirSync(join(pkgDir, 'bin'), { recursive: true })
34+
const dest = join(pkgDir, 'bin', 'durable-streams-server')
3535
copyFileSync(src, dest)
3636
chmodSync(dest, 0o755)
3737

3838
const pj = { ...platTpl, name: t.pkg, version, os: [t.os], cpu: [t.cpu] }
3939
if (t.libc) pj.libc = [t.libc]
4040
writeFileSync(
41-
join(pkgDir, "package.json"),
42-
JSON.stringify(pj, null, 2) + "\n"
41+
join(pkgDir, 'package.json'),
42+
JSON.stringify(pj, null, 2) + '\n'
4343
)
4444
optionalDependencies[t.pkg] = version
4545
}
4646

4747
// Main package.
48-
const mainDir = join(outDir, "main")
48+
const mainDir = join(outDir, 'main')
4949
rmSync(mainDir, { recursive: true, force: true })
50-
mkdirSync(join(mainDir, "bin"), { recursive: true })
50+
mkdirSync(join(mainDir, 'bin'), { recursive: true })
5151
copyFileSync(
52-
join(here, "bin", "launcher.cjs"),
53-
join(mainDir, "bin", "launcher.cjs")
52+
join(here, 'bin', 'launcher.cjs'),
53+
join(mainDir, 'bin', 'launcher.cjs')
5454
)
55-
copyFileSync(join(here, "targets.json"), join(mainDir, "targets.json"))
56-
copyFileSync(join(here, "README.md"), join(mainDir, "README.md"))
55+
copyFileSync(join(here, 'targets.json'), join(mainDir, 'targets.json'))
56+
copyFileSync(join(here, 'README.md'), join(mainDir, 'README.md'))
5757
const mainPj = { ...mainTpl, version, optionalDependencies }
5858
writeFileSync(
59-
join(mainDir, "package.json"),
60-
JSON.stringify(mainPj, null, 2) + "\n"
59+
join(mainDir, 'package.json'),
60+
JSON.stringify(mainPj, null, 2) + '\n'
6161
)
6262

6363
return {
@@ -73,7 +73,7 @@ export function assemble({ version, binsDir, outDir }) {
7373
function parseArgs(argv) {
7474
const out = {}
7575
for (let i = 0; i < argv.length; i += 2) {
76-
const k = argv[i].replace(/^--/, "")
76+
const k = argv[i].replace(/^--/, '')
7777
out[k] = argv[i + 1]
7878
}
7979
return out
Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,14 @@
11
#!/usr/bin/env node
2-
"use strict"
3-
const path = require("node:path")
4-
const { execFileSync } = require("node:child_process")
2+
'use strict'
3+
const path = require('node:path')
4+
const { execFileSync } = require('node:child_process')
55

6-
const targets = require("../targets.json")
6+
const targets = require('../targets.json')
77
const key = `${process.platform}-${process.arch}`
88
const target = targets.find((t) => t.node === key)
99

1010
if (!target) {
11-
const supported = targets.map((t) => t.node).join(", ")
11+
const supported = targets.map((t) => t.node).join(', ')
1212
console.error(
1313
`durable-streams-server: unsupported platform "${key}". Supported: ${supported}.`
1414
)
@@ -19,7 +19,7 @@ let binary
1919
try {
2020
// Resolve via package.json (always resolvable) then join the known binary path.
2121
const pkgJson = require.resolve(`${target.pkg}/package.json`)
22-
binary = path.join(path.dirname(pkgJson), "bin", "durable-streams-server")
22+
binary = path.join(path.dirname(pkgJson), 'bin', 'durable-streams-server')
2323
} catch {
2424
console.error(
2525
`durable-streams-server: the platform package "${target.pkg}" is not installed.\n` +
@@ -30,8 +30,8 @@ try {
3030
}
3131

3232
try {
33-
execFileSync(binary, process.argv.slice(2), { stdio: "inherit" })
33+
execFileSync(binary, process.argv.slice(2), { stdio: 'inherit' })
3434
} catch (err) {
3535
// execFileSync throws on non-zero exit; mirror the child's exit code.
36-
process.exit(typeof err.status === "number" ? err.status : 1)
36+
process.exit(typeof err.status === 'number' ? err.status : 1)
3737
}

packages/server-rust/npm/test/launcher.test.mjs

Lines changed: 30 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -1,71 +1,71 @@
1-
import { test } from "node:test"
2-
import assert from "node:assert/strict"
3-
import { execFileSync } from "node:child_process"
1+
import { test } from 'node:test'
2+
import assert from 'node:assert/strict'
3+
import { execFileSync } from 'node:child_process'
44
import {
55
mkdtempSync,
66
mkdirSync,
77
writeFileSync,
88
chmodSync,
99
readFileSync,
10-
} from "node:fs"
11-
import { tmpdir } from "node:os"
12-
import { join, dirname } from "node:path"
13-
import { fileURLToPath } from "node:url"
10+
} from 'node:fs'
11+
import { tmpdir } from 'node:os'
12+
import { join, dirname } from 'node:path'
13+
import { fileURLToPath } from 'node:url'
1414

1515
const here = dirname(fileURLToPath(import.meta.url))
16-
const launcher = join(here, "..", "bin", "launcher.cjs")
16+
const launcher = join(here, '..', 'bin', 'launcher.cjs')
1717
const targets = JSON.parse(
18-
readFileSync(join(here, "..", "targets.json"), "utf8")
18+
readFileSync(join(here, '..', 'targets.json'), 'utf8')
1919
)
2020

2121
function fakePlatformPackageRoot() {
2222
// Build node_modules/<pkg>/{package.json,bin/durable-streams-server} for THIS host.
2323
const hostKey = `${process.platform}-${process.arch}`
2424
const t = targets.find((t) => t.node === hostKey)
2525
assert.ok(t, `test host ${hostKey} not in targets.json`)
26-
const root = mkdtempSync(join(tmpdir(), "ds-npm-"))
27-
const pkgDir = join(root, "node_modules", t.pkg)
28-
mkdirSync(join(pkgDir, "bin"), { recursive: true })
26+
const root = mkdtempSync(join(tmpdir(), 'ds-npm-'))
27+
const pkgDir = join(root, 'node_modules', t.pkg)
28+
mkdirSync(join(pkgDir, 'bin'), { recursive: true })
2929
writeFileSync(
30-
join(pkgDir, "package.json"),
31-
JSON.stringify({ name: t.pkg, version: "0.0.0" })
30+
join(pkgDir, 'package.json'),
31+
JSON.stringify({ name: t.pkg, version: '0.0.0' })
3232
)
3333
// A fake "binary" that is really a shell script: echoes args, exits 7.
34-
const bin = join(pkgDir, "bin", "durable-streams-server")
34+
const bin = join(pkgDir, 'bin', 'durable-streams-server')
3535
writeFileSync(bin, `#!/bin/sh\necho "ARGS:$*"\nexit 7\n`)
3636
chmodSync(bin, 0o755)
3737
return root
3838
}
3939

40-
test("launcher execs the platform binary, forwards args, propagates exit code", () => {
40+
test('launcher execs the platform binary, forwards args, propagates exit code', () => {
4141
const root = fakePlatformPackageRoot()
42-
let out = "",
42+
let out = '',
4343
code = 0
4444
try {
45-
out = execFileSync("node", [launcher, "--port", "4438"], {
46-
env: { ...process.env, NODE_PATH: join(root, "node_modules") },
47-
encoding: "utf8",
45+
out = execFileSync('node', [launcher, '--port', '4438'], {
46+
env: { ...process.env, NODE_PATH: join(root, 'node_modules') },
47+
encoding: 'utf8',
4848
})
4949
} catch (e) {
5050
code = e.status
51-
out = e.stdout?.toString() ?? ""
51+
out = e.stdout?.toString() ?? ''
5252
}
53-
assert.equal(code, 7, "exit code propagated")
54-
assert.match(out, /ARGS:--port 4438/, "args forwarded")
53+
assert.equal(code, 7, 'exit code propagated')
54+
assert.match(out, /ARGS:--port 4438/, 'args forwarded')
5555
})
5656

57-
test("launcher errors clearly when no platform package is installed", () => {
58-
const empty = mkdtempSync(join(tmpdir(), "ds-npm-empty-"))
59-
let stderr = "",
57+
test('launcher errors clearly when no platform package is installed', () => {
58+
const empty = mkdtempSync(join(tmpdir(), 'ds-npm-empty-'))
59+
let stderr = '',
6060
code = 0
6161
try {
62-
execFileSync("node", [launcher], {
63-
env: { ...process.env, NODE_PATH: join(empty, "node_modules") },
64-
encoding: "utf8",
62+
execFileSync('node', [launcher], {
63+
env: { ...process.env, NODE_PATH: join(empty, 'node_modules') },
64+
encoding: 'utf8',
6565
})
6666
} catch (e) {
6767
code = e.status
68-
stderr = e.stderr?.toString() ?? ""
68+
stderr = e.stderr?.toString() ?? ''
6969
}
7070
assert.notEqual(code, 0)
7171
assert.match(stderr, /platform package/i)

0 commit comments

Comments
 (0)