@opentf/web-compiler 0.16.0 → 0.18.0
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/README.md +3 -4
- package/bin/darwin-arm64/otfwc.br +0 -0
- package/bin/darwin-x64/otfwc.br +0 -0
- package/bin/linux-x64/otfwc.br +0 -0
- package/bin/win32-x64/otfwc.exe.br +0 -0
- package/extract.js +44 -37
- package/package.json +2 -6
- package/scripts/postinstall.js +0 -7
package/README.md
CHANGED
|
@@ -12,10 +12,9 @@ const bin = otfwcPath(); // absolute path to the otfwc executable for this platf
|
|
|
12
12
|
|
|
13
13
|
This single package ships the `otfwc` binary for every supported platform,
|
|
14
14
|
**brotli-compressed**, under `bin/<platform>-<arch>/otfwc[.exe].br` (~0.65 MB each
|
|
15
|
-
vs ~2.3 MB raw).
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
(`process.platform-process.arch`).
|
|
15
|
+
vs ~2.3 MB raw). `otfwcPath()` decompresses **only the host's** binary lazily on
|
|
16
|
+
first use, so installation has no Node lifecycle hook, and returns the path
|
|
17
|
+
matching the host.
|
|
19
18
|
|
|
20
19
|
Shipping all platforms in one package is cheaper to maintain than the per-platform
|
|
21
20
|
optionalDependencies fan-out that rolldown/swc/esbuild use (their binaries are far
|
|
Binary file
|
package/bin/darwin-x64/otfwc.br
CHANGED
|
Binary file
|
package/bin/linux-x64/otfwc.br
CHANGED
|
Binary file
|
|
Binary file
|
package/extract.js
CHANGED
|
@@ -1,70 +1,77 @@
|
|
|
1
1
|
//! Decompress the host's otfwc binary from its shipped brotli archive.
|
|
2
2
|
//
|
|
3
3
|
// The package ships one brotli-compressed binary per platform under
|
|
4
|
-
// `bin/<platform>-<arch>/otfwc[.exe].br` (~0.65MB each vs ~2.3MB raw).
|
|
5
|
-
//
|
|
6
|
-
//
|
|
4
|
+
// `bin/<platform>-<arch>/otfwc[.exe].br` (~0.65MB each vs ~2.3MB raw).
|
|
5
|
+
// `otfwcPath()` decompresses the host's archive lazily on first use.
|
|
6
|
+
//
|
|
7
|
+
// It runs under the ES-Runtime alongside the rest of the toolchain, so package
|
|
8
|
+
// installation needs no Node lifecycle hook.
|
|
9
|
+
|
|
10
|
+
import { chmod, exists, file, write } from "runtime:fs";
|
|
11
|
+
import { dirname, fromFileURL, join } from "runtime:path";
|
|
12
|
+
import { arch, env, platform } from "runtime:process";
|
|
7
13
|
|
|
8
|
-
|
|
9
|
-
import { brotliDecompressSync } from "node:zlib";
|
|
10
|
-
import { dirname, join } from "node:path";
|
|
11
|
-
import { fileURLToPath } from "node:url";
|
|
14
|
+
const here = dirname(fromFileURL(import.meta.url));
|
|
12
15
|
|
|
13
|
-
|
|
16
|
+
// The shipped `bin/` subdirectories are named the way node reports a host, which is
|
|
17
|
+
// not how the runtime does; map onto them rather than renaming what we publish.
|
|
18
|
+
const OS_NAMES = { linux: "linux", macos: "darwin", windows: "win32" };
|
|
19
|
+
const ARCH_NAMES = { x86_64: "x64", aarch64: "arm64" };
|
|
14
20
|
|
|
15
|
-
|
|
16
|
-
const SUPPORTED = new Set([
|
|
17
|
-
"linux-x64",
|
|
18
|
-
"darwin-x64",
|
|
19
|
-
"darwin-arm64",
|
|
20
|
-
"win32-x64",
|
|
21
|
-
]);
|
|
21
|
+
const SUPPORTED = new Set(["linux-x64", "darwin-x64", "darwin-arm64", "win32-x64"]);
|
|
22
22
|
|
|
23
|
-
function
|
|
24
|
-
const
|
|
23
|
+
function hostKey(platformName = platform, architecture = arch) {
|
|
24
|
+
const os = OS_NAMES[platformName];
|
|
25
|
+
const cpu = ARCH_NAMES[architecture];
|
|
26
|
+
return os && cpu ? `${os}-${cpu}` : `${platformName}-${architecture}`;
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
function hostBinPath({ binaryDir = here, os = platform, cpuArch = arch } = {}) {
|
|
30
|
+
const key = hostKey(os, cpuArch);
|
|
25
31
|
if (!SUPPORTED.has(key)) return null;
|
|
26
|
-
|
|
27
|
-
return join(here, "bin", key, bin);
|
|
32
|
+
return join(binaryDir, "bin", key, os === "windows" ? "otfwc.exe" : "otfwc");
|
|
28
33
|
}
|
|
29
34
|
|
|
30
35
|
/** Decompress the host's `.br` archive to a runnable binary; returns its path. */
|
|
31
|
-
function decompress(out) {
|
|
32
|
-
const
|
|
33
|
-
|
|
34
|
-
|
|
36
|
+
async function decompress(out, os = platform) {
|
|
37
|
+
const compressed = await file(`${out}.br`).stream();
|
|
38
|
+
const plain = compressed.pipeThrough(new DecompressionStream("brotli"));
|
|
39
|
+
await write(out, new Uint8Array(await new Response(plain).arrayBuffer()));
|
|
40
|
+
if (os !== "windows") await chmod(out, 0o755);
|
|
35
41
|
return out;
|
|
36
42
|
}
|
|
37
43
|
|
|
38
44
|
/**
|
|
39
45
|
* Best-effort: decompress the host binary if the archive is present. No-op (returns
|
|
40
|
-
* null) on an unsupported platform or a source checkout without the `.br`.
|
|
41
|
-
*
|
|
46
|
+
* null) on an unsupported platform or a source checkout without the `.br`. Never
|
|
47
|
+
* throws — the caller falls back to reporting the missing binary itself.
|
|
42
48
|
*/
|
|
43
|
-
export function extractIfPackaged() {
|
|
49
|
+
export async function extractIfPackaged() {
|
|
44
50
|
const out = hostBinPath();
|
|
45
|
-
if (!out
|
|
51
|
+
if (!out) return null;
|
|
46
52
|
try {
|
|
47
|
-
|
|
53
|
+
if ((await exists(out)) || !(await exists(`${out}.br`))) return null;
|
|
54
|
+
return await decompress(out);
|
|
48
55
|
} catch {
|
|
49
|
-
return null;
|
|
56
|
+
return null;
|
|
50
57
|
}
|
|
51
58
|
}
|
|
52
59
|
|
|
53
60
|
/** Absolute path to the otfwc executable, or throw with a clear message. */
|
|
54
|
-
export function otfwcPath() {
|
|
55
|
-
if (
|
|
56
|
-
if (
|
|
57
|
-
throw new Error(`otfwc: OTFWC_BIN is set but ${
|
|
61
|
+
export async function otfwcPath({ binaryDir = here, environment = env, os = platform, cpuArch = arch } = {}) {
|
|
62
|
+
if (environment.OTFWC_BIN) {
|
|
63
|
+
if (await exists(environment.OTFWC_BIN)) return environment.OTFWC_BIN;
|
|
64
|
+
throw new Error(`otfwc: OTFWC_BIN is set but ${environment.OTFWC_BIN} does not exist`);
|
|
58
65
|
}
|
|
59
|
-
const out = hostBinPath();
|
|
66
|
+
const out = hostBinPath({ binaryDir, os, cpuArch });
|
|
60
67
|
if (!out) {
|
|
61
68
|
throw new Error(
|
|
62
|
-
`otfwc: no prebuilt binary for ${
|
|
69
|
+
`otfwc: no prebuilt binary for ${hostKey(os, cpuArch)}. ` +
|
|
63
70
|
`Supported: ${[...SUPPORTED].join(", ")}. Build from source and set OTFWC_BIN.`,
|
|
64
71
|
);
|
|
65
72
|
}
|
|
66
|
-
if (
|
|
67
|
-
if (
|
|
73
|
+
if (await exists(out)) return out;
|
|
74
|
+
if (await exists(`${out}.br`)) return decompress(out, os);
|
|
68
75
|
throw new Error(
|
|
69
76
|
`otfwc: prebuilt binary missing at ${out}. ` +
|
|
70
77
|
`Reinstall @opentf/web-compiler, or set OTFWC_BIN.`,
|
package/package.json
CHANGED
|
@@ -1,19 +1,15 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@opentf/web-compiler",
|
|
3
|
-
"version": "0.
|
|
4
|
-
"description": "OTF Web
|
|
3
|
+
"version": "0.18.0",
|
|
4
|
+
"description": "OTF Web native toolchain (otfwc) — component compilation and documentation indexing in one platform binary.",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"main": "index.js",
|
|
7
7
|
"exports": {
|
|
8
8
|
".": "./index.js"
|
|
9
9
|
},
|
|
10
|
-
"scripts": {
|
|
11
|
-
"postinstall": "node scripts/postinstall.js"
|
|
12
|
-
},
|
|
13
10
|
"files": [
|
|
14
11
|
"index.js",
|
|
15
12
|
"extract.js",
|
|
16
|
-
"scripts",
|
|
17
13
|
"bin"
|
|
18
14
|
],
|
|
19
15
|
"keywords": [
|
package/scripts/postinstall.js
DELETED
|
@@ -1,7 +0,0 @@
|
|
|
1
|
-
//! Decompress the host's otfwc binary after install. Best-effort: a no-op on a
|
|
2
|
-
//! source checkout (no `.br` present) and never throws, so it can't break install.
|
|
3
|
-
//! `otfwcPath()` decompresses lazily anyway if this is skipped (--ignore-scripts).
|
|
4
|
-
|
|
5
|
-
import { extractIfPackaged } from "../extract.js";
|
|
6
|
-
|
|
7
|
-
extractIfPackaged();
|