@threadedstack/wmd 0.1.19 → 0.1.21

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.
Files changed (3) hide show
  1. package/index.d.ts +12 -5
  2. package/index.js +37 -9
  3. package/package.json +8 -4
package/index.d.ts CHANGED
@@ -4,11 +4,18 @@ export declare const PROGRAMS: readonly string[]
4
4
  export declare const version: string
5
5
  /** The full commit this release was built from. */
6
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
7
+ /** The guest architecture of this machine's cpu (x64 is amd64). */
8
+ export declare function hostGuestArch(arch?: string): 'arm64' | 'amd64'
9
+ /** The C library of this Linux; null on another os. */
10
+ export declare function hostLibc(
11
+ platform?: string,
12
+ getReport?: () => { header?: { glibcVersionRuntime?: string } } | null,
13
+ ): 'glibc' | 'musl' | null
14
+ /** The platform package's name, e.g. @threadedstack/wmd-darwin-arm64 or @threadedstack/wmd-linux-x64-musl. */
15
+ export declare function platformPackage(platform?: string, arch?: string, libc?: 'glibc' | 'musl' | null): string
16
+ /** The bin folder of this machine's platform package (or of the given platform's). */
17
+ export declare function binDir(platform?: string, arch?: string, libc?: 'glibc' | 'musl' | null): string
11
18
  /** The path of one program (wmd, wmdd, wmd-run, wmd-relay, wmd-exe-stub, wmd-fixtures-gen, bootlock.sh). */
12
19
  export declare function binPath(name?: string): string
13
- /** The guest files folder (vm.wasm, Image, Image-4k, initramfs.cpio.gz, features, config). */
20
+ /** The guest files folder of arch (default: this cpu's): arm64 has Image and Image-4k, amd64 has bzImage. */
14
21
  export declare function guestDir(arch?: string): string
package/index.js CHANGED
@@ -19,18 +19,46 @@ export const PROGRAMS = ['wmd', 'wmdd', 'wmd-run', 'wmd-relay', 'wmd-exe-stub',
19
19
  export const version = self.version
20
20
  export const commit = self.wmd?.commit ?? ''
21
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}`
22
+ /** The guest architecture of a cpu (default: this machine's): arm64, or amd64 for x64; throws for any other. */
23
+ export function hostGuestArch(arch = process.arch) {
24
+ if (arch === 'x64') return 'amd64'
25
+ if (arch === 'arm64') return 'arm64'
26
+ throw new Error(`wmd: no guest for cpu ${arch}; there is one for arm64 and x64`)
27
+ }
28
+
29
+ let report
30
+ /** The process report, read once (it is slow); without the network part. */
31
+ function processReport() {
32
+ if (report === undefined) {
33
+ const was = process.report?.excludeNetwork
34
+ try {
35
+ if (process.report) process.report.excludeNetwork = true
36
+ report = process.report?.getReport?.() ?? null
37
+ } finally {
38
+ if (process.report) process.report.excludeNetwork = was
39
+ }
40
+ }
41
+ return report
42
+ }
43
+
44
+ /** The C library of this Linux: 'glibc' or 'musl'; null on another os. A glibc process reports its version. */
45
+ export function hostLibc(platform = process.platform, getReport = processReport) {
46
+ if (platform !== 'linux') return null
47
+ return getReport()?.header?.glibcVersionRuntime ? 'glibc' : 'musl'
48
+ }
49
+
50
+ /** The platform package's name, e.g. @threadedstack/wmd-darwin-arm64; the Linux musl ones end in -musl. */
51
+ export function platformPackage(platform = process.platform, arch = process.arch, libc = hostLibc()) {
52
+ return `@threadedstack/wmd-${platform}-${arch}${platform === 'linux' && libc === 'musl' ? '-musl' : ''}`
25
53
  }
26
54
 
27
55
  /** 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()
56
+ export function binDir(platform = process.platform, arch = process.arch, libc = hostLibc()) {
57
+ const name = platformPackage(platform, arch, libc)
30
58
  if (!Object.hasOwn(self.optionalDependencies ?? {}, name))
31
59
  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(', '),
60
+ `wmd: no build for ${platform} ${arch}${platform === 'linux' && libc ? ` (${libc})` : ''}; there is one for ` +
61
+ Object.keys(self.optionalDependencies ?? {}).sort().map((n) => n.replace('@threadedstack/wmd-', '')).join(', '),
34
62
  )
35
63
  let pkg
36
64
  try {
@@ -54,8 +82,8 @@ export function binPath(name = 'wmd') {
54
82
  return p
55
83
  }
56
84
 
57
- /** The guest files folder (vm.wasm, Image, Image-4k, initramfs.cpio.gz, features, config) for arch. */
58
- export function guestDir(arch = 'arm64') {
85
+ /** The guest files folder for arch: arm64 has vm.wasm, Image, Image-4k, initramfs.cpio.gz, features, config; amd64 has vm.wasm, bzImage, initramfs.cpio.gz, features, config. */
86
+ export function guestDir(arch = hostGuestArch()) {
59
87
  const d = join(binDir(), 'guest', arch)
60
88
  if (!existsSync(d)) throw new Error(`wmd: this build has no ${arch} guest (${d})`)
61
89
  return d
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@threadedstack/wmd",
3
- "version": "0.1.19",
3
+ "version": "0.1.21",
4
4
  "license": "MIT",
5
5
  "homepage": "https://github.com/threadedstack/wmd-releases",
6
6
  "repository": {
@@ -9,8 +9,8 @@
9
9
  },
10
10
  "description": "wmd: a Docker Engine API compatible daemon and CLI that runs Linux containers in WebAssembly",
11
11
  "wmd": {
12
- "tag": "v0.1.19",
13
- "commit": "89688f12e0caef39ab0a159b39c00f3525e31051"
12
+ "tag": "v0.1.21",
13
+ "commit": "19edd3aa9241c6cc1d2838a9a58a33b559703dc8"
14
14
  },
15
15
  "type": "module",
16
16
  "exports": {
@@ -35,6 +35,10 @@
35
35
  "node": ">=18"
36
36
  },
37
37
  "optionalDependencies": {
38
- "@threadedstack/wmd-darwin-arm64": "0.1.19"
38
+ "@threadedstack/wmd-darwin-arm64": "0.1.21",
39
+ "@threadedstack/wmd-linux-arm64": "0.1.21",
40
+ "@threadedstack/wmd-linux-x64": "0.1.21",
41
+ "@threadedstack/wmd-linux-arm64-musl": "0.1.21",
42
+ "@threadedstack/wmd-linux-x64-musl": "0.1.21"
39
43
  }
40
44
  }