({ outfile, target })
| 25 | const repoRoot = resolve(computerdRoot, "../.."); |
| 26 | |
| 27 | export async function bundleComputerd({ outfile, target }) { |
| 28 | const nodeGypBuildShim = ` |
| 29 | const { writeFileSync, chmodSync, existsSync, mkdirSync } = require("node:fs"); |
| 30 | const { tmpdir } = require("node:os"); |
| 31 | const { join } = require("node:path"); |
| 32 | const { createHash } = require("node:crypto"); |
| 33 | const sea = require("node:sea"); |
| 34 | |
| 35 | const LIBFUSE_NAME = ${JSON.stringify(target.libfuseName)}; |
| 36 | const ENV_VAR = ${JSON.stringify(target.envVar)}; |
| 37 | |
| 38 | let cached; |
| 39 | function loadNative() { |
| 40 | if (cached) return cached; |
| 41 | const addonBuf = Buffer.from(sea.getAsset("fuse-native.node")); |
| 42 | const libBuf = Buffer.from(sea.getAsset(LIBFUSE_NAME)); |
| 43 | const hash = createHash("sha256").update(addonBuf).update(libBuf).digest("hex").slice(0, 16); |
| 44 | const dir = join(tmpdir(), "computerd-sea-" + hash); |
| 45 | try { mkdirSync(dir, { recursive: true }); } catch {} |
| 46 | const libPath = join(dir, LIBFUSE_NAME); |
| 47 | const addonPath = join(dir, "fuse-native.node"); |
| 48 | if (!existsSync(libPath)) writeFileSync(libPath, libBuf); |
| 49 | if (!existsSync(addonPath)) { writeFileSync(addonPath, addonBuf); chmodSync(addonPath, 0o755); } |
| 50 | process.env[ENV_VAR] = dir + (process.env[ENV_VAR] ? ":" + process.env[ENV_VAR] : ""); |
| 51 | const m = { exports: {} }; |
| 52 | process.dlopen(m, addonPath); |
| 53 | cached = m.exports; |
| 54 | return cached; |
| 55 | } |
| 56 | |
| 57 | module.exports = function nodeGypBuild(_dir) { return loadNative(); }; |
| 58 | `; |
| 59 | |
| 60 | const fuseSharedLibraryShim = ` |
| 61 | function noop(cb) { if (typeof cb === "function") process.nextTick(cb); } |
| 62 | function isConfigured(cb) { process.nextTick(() => cb(null, true)); } |
| 63 | module.exports = { beforeMount: noop, beforeUnmount: noop, configure: noop, unconfigure: noop, isConfigured }; |
| 64 | `; |
| 65 | |
| 66 | const nativeShimPlugin = { |
| 67 | name: "fuse-native-shim", |
| 68 | setup(b) { |
| 69 | b.onResolve({ filter: /^node-gyp-build$/ }, () => ({ |
| 70 | path: "node-gyp-build", |
| 71 | namespace: "computerd-shim", |
| 72 | })); |
| 73 | b.onResolve({ filter: /^fuse-shared-library$/ }, () => ({ |
| 74 | path: "fuse-shared-library", |
| 75 | namespace: "computerd-shim", |
| 76 | })); |
| 77 | b.onLoad({ filter: /.*/, namespace: "computerd-shim" }, (args) => { |
| 78 | if (args.path === "node-gyp-build") { |
| 79 | return { contents: nodeGypBuildShim, loader: "js", resolveDir: repoRoot }; |
| 80 | } |
| 81 | if (args.path === "fuse-shared-library") { |
| 82 | return { contents: fuseSharedLibraryShim, loader: "js" }; |
| 83 | } |
| 84 | return null; |
no outgoing calls
no test coverage detected