@threadedstack/wmd 0.0.0-stage → 0.1.12

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/bin/run.js ADDED
@@ -0,0 +1,28 @@
1
+ // The wmd, wmdd and wmd-relay commands of @threadedstack/wmd (bin/<name>.js): runs the program of that name from the
2
+ // platform package with the same arguments, stdin, stdout and stderr, and ends with its exit code (or its signal).
3
+ import { spawn } from 'node:child_process'
4
+ import { binPath } from '../index.js'
5
+
6
+ export function run(name) {
7
+ let file
8
+ try {
9
+ file = binPath(name)
10
+ } catch (e) {
11
+ console.error(e.message)
12
+ process.exit(1)
13
+ }
14
+ const child = spawn(file, process.argv.slice(2), { stdio: 'inherit' })
15
+ // the terminal sends ^C to the whole process group; other signals are passed on
16
+ for (const sig of ['SIGTERM', 'SIGHUP', 'SIGQUIT', 'SIGUSR1', 'SIGUSR2']) process.on(sig, () => child.kill(sig))
17
+ process.on('SIGINT', () => {})
18
+ child.on('error', (e) => {
19
+ console.error(`wmd: ${file}: ${e.message}`)
20
+ process.exit(1)
21
+ })
22
+ child.on('exit', (code, signal) => {
23
+ if (signal) {
24
+ process.removeAllListeners(signal)
25
+ process.kill(process.pid, signal)
26
+ } else process.exit(code ?? 1)
27
+ })
28
+ }
@@ -0,0 +1,4 @@
1
+ #!/usr/bin/env node
2
+ import { run } from './run.js'
3
+
4
+ run('wmd-relay')
package/bin/wmd.js ADDED
@@ -0,0 +1,4 @@
1
+ #!/usr/bin/env node
2
+ import { run } from './run.js'
3
+
4
+ run('wmd')
package/bin/wmdd.js ADDED
@@ -0,0 +1,4 @@
1
+ #!/usr/bin/env node
2
+ import { run } from './run.js'
3
+
4
+ run('wmdd')
package/index.d.ts ADDED
@@ -0,0 +1,14 @@
1
+ /** The programs a platform package carries. */
2
+ export declare const PROGRAMS: readonly string[]
3
+ /** wmd's version (the release tag without the v). */
4
+ export declare const version: string
5
+ /** The full commit this release was built from. */
6
+ export declare const commit: string
7
+ /** The platform package's name, e.g. @threadedstack/wmd-darwin-arm64. */
8
+ export declare function platformPackage(platform?: string, arch?: string): string
9
+ /** The bin folder of this machine's platform package. */
10
+ export declare function binDir(): string
11
+ /** The path of one program (wmd, wmdd, wmd-run, wmd-relay, wmd-exe-stub, wmd-fixtures-gen, bootlock.sh). */
12
+ export declare function binPath(name?: string): string
13
+ /** The guest files folder (vm.wasm, Image, Image-4k, initramfs.cpio.gz, features, config). */
14
+ export declare function guestDir(arch?: string): string
package/index.js ADDED
@@ -0,0 +1,62 @@
1
+ // @threadedstack/wmd: where the wmd programs and guest files of this machine's platform package are.
2
+ //
3
+ // import { binPath, guestDir } from '@threadedstack/wmd'
4
+ // binPath('wmd') // .../node_modules/@threadedstack/wmd-darwin-arm64/bin/wmd
5
+ // guestDir('arm64') // .../node_modules/@threadedstack/wmd-darwin-arm64/bin/guest/arm64
6
+ //
7
+ // The programs and the guest live in one platform package (an optional dependency, so npm installs only the one
8
+ // for this os and cpu). wmd finds wmdd, wmd-run and guest/<arch> next to its own file, so they stay together in bin/.
9
+ import { chmodSync, existsSync, readFileSync, statSync } from 'node:fs'
10
+ import { createRequire } from 'node:module'
11
+ import { dirname, join } from 'node:path'
12
+
13
+ const require = createRequire(import.meta.url)
14
+ const self = JSON.parse(readFileSync(new URL('./package.json', import.meta.url), 'utf8'))
15
+
16
+ /** The programs a platform package carries. */
17
+ export const PROGRAMS = ['wmd', 'wmdd', 'wmd-run', 'wmd-relay', 'wmd-exe-stub', 'wmd-fixtures-gen', 'bootlock.sh']
18
+ /** wmd's version (the release tag without the v) and the commit it was built from. */
19
+ export const version = self.version
20
+ export const commit = self.wmd?.commit ?? ''
21
+
22
+ /** The platform package's name for this machine, e.g. @threadedstack/wmd-darwin-arm64. */
23
+ export function platformPackage(platform = process.platform, arch = process.arch) {
24
+ return `@threadedstack/wmd-${platform}-${arch}`
25
+ }
26
+
27
+ /** The bin folder of this machine's platform package; throws, naming what to install, when there is none. */
28
+ export function binDir() {
29
+ const name = platformPackage()
30
+ if (!Object.hasOwn(self.optionalDependencies ?? {}, name))
31
+ throw new Error(
32
+ `wmd: no build for ${process.platform} ${process.arch}; there is one for ` +
33
+ Object.keys(self.optionalDependencies ?? {}).map((n) => n.replace('@threadedstack/wmd-', '')).join(', '),
34
+ )
35
+ let pkg
36
+ try {
37
+ pkg = require.resolve(`${name}/package.json`)
38
+ } catch {
39
+ throw new Error(
40
+ `wmd: ${name} is not installed. It is an optional dependency of @threadedstack/wmd; ` +
41
+ `install without --no-optional / --omit=optional, or add ${name}@${version} yourself`,
42
+ )
43
+ }
44
+ return join(dirname(pkg), 'bin')
45
+ }
46
+
47
+ /** The path of one program (see PROGRAMS), executable. */
48
+ export function binPath(name = 'wmd') {
49
+ if (!PROGRAMS.includes(name)) throw new Error(`wmd: ${name} is not one of ${PROGRAMS.join(', ')}`)
50
+ const p = join(binDir(), name)
51
+ if (!existsSync(p)) throw new Error(`wmd: ${p} is missing`)
52
+ // an install that dropped the mode bits (some package managers do) would leave it unrunnable
53
+ if ((statSync(p).mode & 0o111) === 0) chmodSync(p, 0o755)
54
+ return p
55
+ }
56
+
57
+ /** The guest files folder (vm.wasm, Image, Image-4k, initramfs.cpio.gz, features, config) for arch. */
58
+ export function guestDir(arch = 'arm64') {
59
+ const d = join(binDir(), 'guest', arch)
60
+ if (!existsSync(d)) throw new Error(`wmd: this build has no ${arch} guest (${d})`)
61
+ return d
62
+ }
package/package.json CHANGED
@@ -1,6 +1,40 @@
1
1
  {
2
2
  "name": "@threadedstack/wmd",
3
- "version": "0.0.0-stage",
4
- "stub": true,
5
- "description": "Temporary package placeholder for staged publishing"
6
- }
3
+ "version": "0.1.12",
4
+ "license": "MIT",
5
+ "homepage": "https://github.com/threadedstack/wmd-releases",
6
+ "repository": {
7
+ "type": "git",
8
+ "url": "git+https://github.com/threadedstack/wmd-releases.git"
9
+ },
10
+ "description": "wmd: a Docker Engine API compatible daemon and CLI that runs Linux containers in WebAssembly",
11
+ "wmd": {
12
+ "tag": "v0.1.12",
13
+ "commit": "7ee6237bcee18c5d8a28e8a172838c85802d4602"
14
+ },
15
+ "type": "module",
16
+ "exports": {
17
+ ".": {
18
+ "types": "./index.d.ts",
19
+ "default": "./index.js"
20
+ },
21
+ "./package.json": "./package.json"
22
+ },
23
+ "types": "./index.d.ts",
24
+ "bin": {
25
+ "wmd": "bin/wmd.js",
26
+ "wmdd": "bin/wmdd.js",
27
+ "wmd-relay": "bin/wmd-relay.js"
28
+ },
29
+ "files": [
30
+ "index.js",
31
+ "index.d.ts",
32
+ "bin"
33
+ ],
34
+ "engines": {
35
+ "node": ">=18"
36
+ },
37
+ "optionalDependencies": {
38
+ "@threadedstack/wmd-darwin-arm64": "0.1.12"
39
+ }
40
+ }
package/README.md DELETED
@@ -1,3 +0,0 @@
1
- # Temporary Holding Version
2
-
3
- This version is a temporary placeholder for this package. An operational version to replace this has been submitted for review and is awaiting a staged release.