@qvac/audiogen-ggml 0.6.0 → 0.7.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/CHANGELOG.md CHANGED
@@ -5,7 +5,48 @@ All notable changes to this project will be documented in this file.
5
5
  The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),
6
6
  and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).
7
7
 
8
- ## [Unreleased]
8
+ ## [0.7.0] - 2026-10-14
9
+
10
+ ### Breaking
11
+
12
+ - `binding.js` is now `module.exports = require('#host-addon')`, a specifier
13
+ the Bare module lexer can follow, so `bare-pack` bundles an app that
14
+ requires `@qvac/audiogen-ggml`. `#host-addon` maps each host to its platform
15
+ package alone, with no fallback.
16
+ - The meta package is no longer an addon. Each platform package is an ordinary
17
+ one: its module is built as `qvac__audiogen-ggml-<suffix>` (every iOS host
18
+ shares `ios`) and sits at `prebuilds/<host>/qvac__audiogen-ggml-<suffix>.bare`,
19
+ with its ggml backends in `prebuilds/<host>/qvac__audiogen-ggml-<suffix>/`.
20
+ - The addon finds its ggml backends itself, next to the loaded module. An
21
+ explicit `backendsDir` is now scanned as given rather than as a prebuilds
22
+ root under which `<host>/<module>` is appended. `resolveBackendsDir()` and
23
+ `lib/backends.js` are removed.
24
+ - A source build is loadable once `npm run link:platform` (part of
25
+ `build:native`) stages it as the host's platform package in `node_modules/`.
26
+
27
+ ## [0.6.1] - 2026-10-13
28
+
29
+ ### Added
30
+
31
+ - `package.json` records the `ggml-speech` build the prebuilds ship as
32
+ `qvac["ggml-speech"]`. The speech addons ship their ggml backends under the
33
+ same file names, so an app that bundles several of them needs releases that
34
+ record the same build.
35
+
36
+ ### Changed
37
+
38
+ - `qvac-lib-inference-addon-cpp` dependency floor raised `1.4.0` -> `1.5.0`
39
+ ([#5030](https://github.com/tetherto/qvac/pull/5030)). The new library adds
40
+ `JsAsyncTask::run(env, work, marshal)`, which resolves a Promise with a value
41
+ marshalled on the JavaScript loop, and includes `<uv.h>` from headers that
42
+ use libuv types now that libjs no longer includes it from `<js.h>`.
43
+ Compile-time only; no API or runtime behaviour change for this package.
44
+ - Update `speech-cpp` to `2026-10-12` to keep the native speech source pin aligned across all speech addons.
45
+
46
+ - Pin `ggml-speech` to `2026-10-07#1` and `speech-cpp` to `2026-10-09`, the
47
+ same versions as the other speech addons. `speech-cpp` moves from
48
+ `2026-10-07#2`; its changes are in engines this package does not build, so
49
+ published behavior is unchanged.
9
50
 
10
51
  ## [0.6.0] - 2026-10-09
11
52
 
package/README.md CHANGED
@@ -11,7 +11,8 @@ on desktop CPUs and GPUs and returns stereo 44.1 kHz audio.
11
11
  The C++ CI carve-out builds the native addon on the Ubuntu 22.04 CPU runner,
12
12
  reusing vcpkg and compiler caches with two build workers. Addon-level C++ tests
13
13
  remain a stub. Only trusted default-branch builds save shared caches; pushes
14
- affecting AudioGen or its cache configuration and manual dispatches warm them.
14
+ affecting AudioGen or its cache configuration, a schedule every 2 days, and
15
+ manual dispatches warm them.
15
16
  Non-PR runs build the triggering commit and reject inputs selecting another
16
17
  repository or revision. PR events retain caller-selected PR-head checkouts.
17
18
  See [C++ CI configuration](../../docs/ci/nx-ci-consolidation.md#optionsci-cheat-sheet).
@@ -65,11 +66,12 @@ platform package selected at install time through `os`/`cpu` filtered
65
66
 
66
67
  Do not depend on desktop platform packages directly. Supported installers are
67
68
  npm 7+, pnpm, bun, and Yarn Berry. Yarn v1 and `--omit=optional` installs skip
68
- the platform package and fail at require time with an error naming the missing
69
- package; a locally built `prebuilds/` directory in the package root always
70
- takes precedence. Use `require('@qvac/audiogen-ggml').resolveBackendsDir()`
71
- to locate the directory holding the host's prebuilt binaries and dynamically
72
- loaded ggml backends.
69
+ the platform package and fail at require time, and at `bare-pack` time, naming
70
+ the missing package. Each platform package is an ordinary Bare addon whose
71
+ `prebuilds/<host>/` holds the native module and, next to it, the dynamically
72
+ loaded ggml backends the module finds on its own. A source build becomes
73
+ loadable once `npm run link:platform` (run by `npm run build:native`) stages it
74
+ as the host's platform package in `node_modules/`.
73
75
 
74
76
  Mobile targets are cross-built, so no install host ever matches their `os`,
75
77
  and `optionalDependencies` filtering can never select them. Mobile
@@ -621,7 +623,7 @@ runnable end-to-end script (`npm run example`).
621
623
  | `cfgScale` | Default MiniMax flow guidance scale; `0` uses the model default. |
622
624
  | `nGpuLayers` | GPU layers to offload when `useGPU` is set (99 = all). |
623
625
  | `threads` | CPU thread count (0 / unset = hardware default). |
624
- | `backendsDir` | Advanced; override the prebuilds root scanned for dlopen'd ggml backend modules. Defaults to `resolveBackendsDir()`: the package's own `prebuilds/` when present, otherwise the installed platform package. Needed on arm64, where the CPU backend is a set of per-microarch module `.so`s. |
626
+ | `backendsDir` | Advanced; directory scanned, as given, for dlopen'd ggml backend modules. Unset scans the addon's own, next to its native module, which is where the platform package and `bare-link` put them. |
625
627
 
626
628
  `logger` — an optional object implementing `error`/`warn`/`info`/`debug`,
627
629
  wrapped by a level-gated `QvacLogger`.
@@ -823,6 +825,13 @@ dispatches to the corresponding `audiogen-cpp` engine.
823
825
  - `addon/src/model-interface/minimax/` — desktop-only `MinimaxModel`.
824
826
  - Built with `cmake-bare` + `cmake-vcpkg`; `vcpkg.json` depends on the
825
827
  `speech-cpp[audiogen]` port.
828
+ - `ggml-speech` and `speech-cpp` are pinned with vcpkg `overrides` to the same
829
+ versions in every speech addon (`@qvac/asr-ggml`, `@qvac/audiogen-ggml`,
830
+ `@qvac/bci-whispercpp`, `@qvac/tts-ggml`), and `package.json` records the
831
+ `ggml-speech` build as `qvac["ggml-speech"]`. The speech addons ship their
832
+ ggml backends under the same file names, so an app that bundles several of
833
+ them keeps one copy of each: use releases that record the same
834
+ `ggml-speech`.
826
835
 
827
836
  ## Benchmarking
828
837
 
@@ -1,31 +1,15 @@
1
- const { hostPlatformPackage, PREBUILT_HOSTS } = require('./lib/backends.js')
1
+ 'use strict'
2
2
 
3
- const META_PACKAGE = '@qvac/audiogen-ggml'
4
- const UNKNOWN_HOST = 'unknown'
3
+ // "#host-addon" target for hosts with no platform package. Hosts that have one
4
+ // map straight to it with no fallback, so a missing install fails bare-pack (and
5
+ // fails at run time naming the package) instead of producing a bundle that only
6
+ // throws once launched.
7
+ const host = require.addon ? require.addon.host : 'unknown'
5
8
 
6
- throw new Error(buildMessage(currentHost()))
7
-
8
- function currentHost() {
9
- return require.addon ? require.addon.host : null
10
- }
11
-
12
- function buildMessage(host) {
13
- if (!host || !PREBUILT_HOSTS.includes(host)) {
14
- return (
15
- META_PACKAGE +
16
- ' has no prebuilt binaries for host ' +
17
- (host || UNKNOWN_HOST) +
18
- '. Prebuilt hosts: ' +
19
- PREBUILT_HOSTS.join(', ') +
20
- '. Build from source with bare-make.'
21
- )
22
- }
23
- return (
24
- META_PACKAGE +
25
- ' found no native prebuild for ' +
9
+ throw new Error(
10
+ '@qvac/audiogen-ggml has no prebuilt binaries for host ' +
26
11
  host +
27
- ': the platform package ' +
28
- hostPlatformPackage(host) +
29
- ' is not installed. It ships as an os/cpu filtered optional dependency, which Yarn v1 and installs using --omit=optional drop. Reinstall with npm 7+, pnpm, bun, or Yarn Berry, or build from source with bare-make.'
30
- )
31
- }
12
+ '. Platform packages exist for linux-x64, linux-arm64, darwin-arm64, ' +
13
+ 'darwin-x64, win32-x64, android-arm64 and ios (ios-arm64, ' +
14
+ 'ios-arm64-simulator, ios-x64-simulator). Build from source with bare-make.'
15
+ )
package/audiogen.d.ts CHANGED
@@ -14,9 +14,8 @@ export interface AudioGenConfigurationParams {
14
14
  nGpuLayers?: number;
15
15
  threads?: number;
16
16
  /**
17
- * Prebuilds root the native side scans (after appending the per-target
18
- * BACKENDS_SUBDIR) for dlopen'd ggml backend modules. Required on arm64, where
19
- * the CPU backend ships as per-microarch MODULE .so files.
17
+ * Directory the native side scans, as given, for dlopen'd ggml backend
18
+ * modules. Unset scans the addon's own, next to its native module.
20
19
  */
21
20
  backendsDir?: string;
22
21
  }
package/binding.js CHANGED
@@ -1,49 +1 @@
1
- module.exports = loadAddon()
2
-
3
- // The split meta package has no local prebuild. Some runtimes return this
4
- // package's Javascript entry from require.addon() instead of throwing, so
5
- // validate the result before accepting it as the native binding.
6
-
7
- function loadAddon() {
8
- let cause = null
9
-
10
- try {
11
- const addon = require.addon()
12
- if (isNativeBinding(addon)) return addon
13
- cause = new Error(
14
- '@qvac/audiogen-ggml: require.addon() answered with a module that is not the native binding ' +
15
- '(no createInstance function), so the prebuild in this package was treated as absent.'
16
- )
17
- } catch (err) {
18
- cause = err
19
- }
20
-
21
- return loadPlatformPackageAddon(cause)
22
- }
23
-
24
- function loadPlatformPackageAddon(cause) {
25
- let addon
26
-
27
- try {
28
- addon = require('#host-addon')
29
- } catch (err) {
30
- if (err.cause === undefined) err.cause = cause
31
- throw err
32
- }
33
-
34
- if (!isNativeBinding(addon)) {
35
- const err = new Error(
36
- '@qvac/audiogen-ggml resolved #host-addon to a module that is not the native binding: ' +
37
- 'it has no createInstance function. Check that the platform package for this host ' +
38
- 'is installed and is not shadowed by another module of the same name.'
39
- )
40
- err.cause = cause
41
- throw err
42
- }
43
-
44
- return addon
45
- }
46
-
47
- function isNativeBinding(addon) {
48
- return addon !== null && typeof addon === 'object' && typeof addon.createInstance === 'function'
49
- }
1
+ module.exports = require('#host-addon')
package/index.d.ts CHANGED
@@ -52,12 +52,9 @@ export interface AudioGenRuntimeConfig {
52
52
  /** 0 = engine auto-picks. */
53
53
  threads?: number;
54
54
  /**
55
- * Override the prebuilds root the native engine scans for dlopen'd ggml
56
- * backend modules. Defaults to `resolveBackendsDir()`: the package's own
57
- * `prebuilds/` when present, otherwise the installed platform package
58
- * (`@qvac/audiogen-ggml-<platform>-<arch>`). Only set this for a
59
- * non-standard prebuilds layout. Needed on arm64, where the CPU backend is
60
- * a set of per-microarch MODULE .so files.
55
+ * Directory the native engine scans, as given, for dlopen'd ggml backend
56
+ * modules. Unset scans the addon's own, next to its native module, which is
57
+ * where the platform package and bare-link put them.
61
58
  */
62
59
  backendsDir?: string;
63
60
  }
@@ -556,7 +553,6 @@ export { REGISTRY_SOURCE, REGISTRY_PREFIX, FIXED_MODELS, DIT_VARIANTS, DEFAULT_D
556
553
  export type { DitVariant, ModelManifest, ModelSources, ResolveDitModelPathOptions } from './models';
557
554
  export { encodePcm, pcmToWav, SUPPORTED_FORMATS as OUTPUT_FORMATS } from './lib/audio-format';
558
555
  export type { OutputFormat, EncodeOptions, EncodedAudio } from './lib/audio-format';
559
- export { resolveBackendsDir } from './lib/backends';
560
556
  export { assessFit } from './lib/fit';
561
557
  export type { AudiogenFitRequest, AudiogenFitResult, AudiogenFitStatus } from './lib/fit';
562
558
  export { ERR_CODE_RANGE, ERR_CODES, QvacErrorAudioGen } from './error';
package/index.js CHANGED
@@ -11,7 +11,7 @@
11
11
  // streams the engine's output (progress ticks + one interleaved-Int16 PCM
12
12
  // chunk) and resolves with the run stats.
13
13
  Object.defineProperty(exports, "__esModule", { value: true });
14
- exports.RepaintMode = exports.AudioEditOperationType = exports.QvacErrorAudioGen = exports.ERR_CODES = exports.ERR_CODE_RANGE = exports.assessFit = exports.resolveBackendsDir = exports.OUTPUT_FORMATS = exports.pcmToWav = exports.encodePcm = exports.allRegistryPaths = exports.resolveDitModelPath = exports.modelSources = exports.modelManifest = exports.modelFilenames = exports.registryPath = exports.ditFilename = exports.ditVariants = exports.DEFAULT_DIT_VARIANT = exports.DIT_VARIANTS = exports.FIXED_MODELS = exports.REGISTRY_PREFIX = exports.REGISTRY_SOURCE = exports.AudioGen = exports.AudioEditSession = exports.AUDIOGEN_GPU_FALLBACK_REASONS = exports.AUDIOGEN_BACKEND_NAMES = exports.MINIMAX_DEFAULT_MAX_FRAMES = exports.MINIMAX_FRAMES_PER_SECOND = exports.ENGINE_MINIMAX = exports.ENGINE_ACESTEP = void 0;
14
+ exports.RepaintMode = exports.AudioEditOperationType = exports.QvacErrorAudioGen = exports.ERR_CODES = exports.ERR_CODE_RANGE = exports.assessFit = exports.OUTPUT_FORMATS = exports.pcmToWav = exports.encodePcm = exports.allRegistryPaths = exports.resolveDitModelPath = exports.modelSources = exports.modelManifest = exports.modelFilenames = exports.registryPath = exports.ditFilename = exports.ditVariants = exports.DEFAULT_DIT_VARIANT = exports.DIT_VARIANTS = exports.FIXED_MODELS = exports.REGISTRY_PREFIX = exports.REGISTRY_SOURCE = exports.AudioGen = exports.AudioEditSession = exports.AUDIOGEN_GPU_FALLBACK_REASONS = exports.AUDIOGEN_BACKEND_NAMES = exports.MINIMAX_DEFAULT_MAX_FRAMES = exports.MINIMAX_FRAMES_PER_SECOND = exports.ENGINE_MINIMAX = exports.ENGINE_ACESTEP = void 0;
15
15
  exports.audiogenBackendName = audiogenBackendName;
16
16
  exports.audiogenGpuFallbackReason = audiogenGpuFallbackReason;
17
17
  exports.detectEngineType = detectEngineType;
@@ -23,7 +23,6 @@ const os = require("bare-os");
23
23
  const audiogen_1 = require("./audiogen");
24
24
  const models_1 = require("./models");
25
25
  const audio_format_1 = require("./lib/audio-format");
26
- const backends_1 = require("./lib/backends");
27
26
  const error_1 = require("./error");
28
27
  exports.ENGINE_ACESTEP = 'acestep';
29
28
  exports.ENGINE_MINIMAX = 'minimax';
@@ -568,7 +567,7 @@ class AudioGen {
568
567
  const files = options.files ?? {};
569
568
  const config = options.config ?? {};
570
569
  this._engineType = detectEngineType(files, options.engine);
571
- const backendsDir = config.backendsDir ?? (0, backends_1.resolveBackendsDir)();
570
+ const backendsDir = config.backendsDir;
572
571
  const threads = requireNonNegativeInt32(config.threads ?? 0, 'threads');
573
572
  this._ditVariant = files.ditVariant;
574
573
  if (this._engineType === exports.ENGINE_MINIMAX) {
@@ -1163,8 +1162,6 @@ var audio_format_2 = require("./lib/audio-format");
1163
1162
  Object.defineProperty(exports, "encodePcm", { enumerable: true, get: function () { return audio_format_2.encodePcm; } });
1164
1163
  Object.defineProperty(exports, "pcmToWav", { enumerable: true, get: function () { return audio_format_2.pcmToWav; } });
1165
1164
  Object.defineProperty(exports, "OUTPUT_FORMATS", { enumerable: true, get: function () { return audio_format_2.SUPPORTED_FORMATS; } });
1166
- var backends_2 = require("./lib/backends");
1167
- Object.defineProperty(exports, "resolveBackendsDir", { enumerable: true, get: function () { return backends_2.resolveBackendsDir; } });
1168
1165
  var fit_1 = require("./lib/fit");
1169
1166
  Object.defineProperty(exports, "assessFit", { enumerable: true, get: function () { return fit_1.assessFit; } });
1170
1167
  var error_2 = require("./error");
package/lib/fit.js CHANGED
@@ -1,7 +1,5 @@
1
1
  'use strict'
2
2
 
3
- const { resolveBackendsDir } = require('./backends')
4
-
5
3
  /**
6
4
  * Projects one model set against the memory free right now, reading GGUF
7
5
  * metadata and never weight data. The registry's weightless copy of each stage
@@ -18,13 +16,7 @@ const { resolveBackendsDir } = require('./backends')
18
16
  function assessFit(request) {
19
17
  const binding = require('../binding.js')
20
18
 
21
- return binding.assessFit({
22
- ...request,
23
- backendsDir:
24
- typeof request.backendsDir === 'string' && request.backendsDir.length > 0
25
- ? request.backendsDir
26
- : resolveBackendsDir()
27
- })
19
+ return binding.assessFit(request)
28
20
  }
29
21
 
30
22
  module.exports = { assessFit }
package/package.json CHANGED
@@ -1,60 +1,42 @@
1
1
  {
2
2
  "name": "@qvac/audiogen-ggml",
3
- "version": "0.6.0",
3
+ "version": "0.7.0",
4
4
  "description": "Audio generation (music) addon for qvac",
5
- "addon": true,
5
+ "qvac": {
6
+ "ggml-speech": "2026-10-07#1"
7
+ },
6
8
  "engines": {
7
9
  "bare": ">=1.19.0"
8
10
  },
9
11
  "imports": {
10
12
  "#host-addon": {
11
13
  "linux": {
12
- "x64": [
13
- "@qvac/audiogen-ggml-linux-x64",
14
- "./addon-unavailable.js"
15
- ],
16
- "arm64": [
17
- "@qvac/audiogen-ggml-linux-arm64",
18
- "./addon-unavailable.js"
19
- ],
14
+ "x64": "@qvac/audiogen-ggml-linux-x64",
15
+ "arm64": "@qvac/audiogen-ggml-linux-arm64",
20
16
  "default": "./addon-unavailable.js"
21
17
  },
22
18
  "darwin": {
23
- "arm64": [
24
- "@qvac/audiogen-ggml-darwin-arm64",
25
- "./addon-unavailable.js"
26
- ],
27
- "x64": [
28
- "@qvac/audiogen-ggml-darwin-x64",
29
- "./addon-unavailable.js"
30
- ],
19
+ "arm64": "@qvac/audiogen-ggml-darwin-arm64",
20
+ "x64": "@qvac/audiogen-ggml-darwin-x64",
31
21
  "default": "./addon-unavailable.js"
32
22
  },
33
23
  "win32": {
34
- "x64": [
35
- "@qvac/audiogen-ggml-win32-x64",
36
- "./addon-unavailable.js"
37
- ],
24
+ "x64": "@qvac/audiogen-ggml-win32-x64",
38
25
  "default": "./addon-unavailable.js"
39
26
  },
40
27
  "android": {
41
- "arm64": [
42
- "@qvac/audiogen-ggml-android-arm64",
43
- "./addon-unavailable.js"
44
- ],
28
+ "arm64": "@qvac/audiogen-ggml-android-arm64",
45
29
  "default": "./addon-unavailable.js"
46
30
  },
47
- "ios": [
48
- "@qvac/audiogen-ggml-ios",
49
- "./addon-unavailable.js"
50
- ],
31
+ "ios": "@qvac/audiogen-ggml-ios",
51
32
  "default": "./addon-unavailable.js"
52
33
  }
53
34
  },
54
35
  "scripts": {
55
36
  "build": "npm run build:ts && npm run build:native",
56
- "build:native": "bare-make generate && bare-make build && bare-make install",
57
- "build:native:cuda": "bare-make generate -D ENABLE_CUDA=ON && bare-make build && bare-make install",
37
+ "build:native": "bare-make generate && bare-make build && bare-make install && npm run link:platform",
38
+ "build:native:cuda": "bare-make generate -D ENABLE_CUDA=ON && bare-make build && bare-make install && npm run link:platform",
39
+ "link:platform": "node ../../scripts/ci/slice-platform-packages.mjs --link-local --workdir .",
58
40
  "build:cuda": "npm run build:ts && npm run build:native:cuda",
59
41
  "build:ts": "tsc -p tsconfig.build.json",
60
42
  "build:pack": "npm run build:ts && mkdir -p dist && npm pack --pack-destination dist",
@@ -168,15 +150,27 @@
168
150
  "bare-path": "^3.0.0",
169
151
  "bare-process": "^4.2.2"
170
152
  },
153
+ "optionalDependencies": {
154
+ "@qvac/audiogen-ggml-linux-x64": "0.7.0",
155
+ "@qvac/audiogen-ggml-linux-arm64": "0.7.0",
156
+ "@qvac/audiogen-ggml-darwin-arm64": "0.7.0",
157
+ "@qvac/audiogen-ggml-darwin-x64": "0.7.0",
158
+ "@qvac/audiogen-ggml-win32-x64": "0.7.0"
159
+ },
171
160
  "overrides": {
172
161
  "bare-module-lexer": "1.6.3"
173
162
  },
174
163
  "types": "index.d.ts",
175
- "optionalDependencies": {
176
- "@qvac/audiogen-ggml-linux-x64": "0.6.0",
177
- "@qvac/audiogen-ggml-linux-arm64": "0.6.0",
178
- "@qvac/audiogen-ggml-darwin-arm64": "0.6.0",
179
- "@qvac/audiogen-ggml-darwin-x64": "0.6.0",
180
- "@qvac/audiogen-ggml-win32-x64": "0.6.0"
164
+ "peerDependencies": {
165
+ "@qvac/audiogen-ggml-android-arm64": "0.7.0",
166
+ "@qvac/audiogen-ggml-ios": "0.7.0"
167
+ },
168
+ "peerDependenciesMeta": {
169
+ "@qvac/audiogen-ggml-android-arm64": {
170
+ "optional": true
171
+ },
172
+ "@qvac/audiogen-ggml-ios": {
173
+ "optional": true
174
+ }
181
175
  }
182
176
  }
package/lib/backends.d.ts DELETED
@@ -1,11 +0,0 @@
1
- export interface BackendsDirSources {
2
- localPrebuildsDir: string
3
- host: string | null
4
- directoryExists: (dir: string) => boolean
5
- resolveManifest: (specifier: string) => string | null
6
- }
7
-
8
- export const PREBUILT_HOSTS: string[]
9
- export function hostPlatformPackage(host: string): string
10
- export function resolveBackendsDirFrom(sources: BackendsDirSources): string
11
- export function resolveBackendsDir(): string
package/lib/backends.js DELETED
@@ -1,86 +0,0 @@
1
- 'use strict'
2
-
3
- const fs = require('bare-fs')
4
- const path = require('bare-path')
5
-
6
- const PACKAGE_ROOT = path.join(__dirname, '..')
7
- const PREBUILDS_DIR_NAME = 'prebuilds'
8
- const PLATFORM_ADDON_DIR_NAME = 'addon'
9
- const PLATFORM_PACKAGE_PREFIX = '@qvac/audiogen-ggml-'
10
- const PLATFORM_MANIFEST_SUBPATH = '/package'
11
- const IOS_PLATFORM = 'ios'
12
- const HOST_SEPARATOR = '-'
13
-
14
- const PREBUILT_HOSTS = [
15
- 'linux-x64',
16
- 'linux-arm64',
17
- 'darwin-arm64',
18
- 'darwin-x64',
19
- 'win32-x64',
20
- 'android-arm64',
21
- 'ios-arm64',
22
- 'ios-arm64-simulator',
23
- 'ios-x64-simulator'
24
- ]
25
-
26
- function hostPlatformPackage(host) {
27
- const platform = host.split(HOST_SEPARATOR)[0]
28
- const suffix = platform === IOS_PLATFORM ? IOS_PLATFORM : host
29
- return PLATFORM_PACKAGE_PREFIX + suffix
30
- }
31
-
32
- function resolveBackendsDirFrom(sources) {
33
- if (sources.directoryExists(sources.localPrebuildsDir)) {
34
- return sources.localPrebuildsDir
35
- }
36
- return platformPackagePrebuildsDir(sources) ?? sources.localPrebuildsDir
37
- }
38
-
39
- function platformPackagePrebuildsDir(sources) {
40
- if (!sources.host) {
41
- return null
42
- }
43
- const manifestPath = sources.resolveManifest(
44
- hostPlatformPackage(sources.host) + PLATFORM_MANIFEST_SUBPATH
45
- )
46
- if (!manifestPath) {
47
- return null
48
- }
49
- return path.join(path.dirname(manifestPath), PLATFORM_ADDON_DIR_NAME, PREBUILDS_DIR_NAME)
50
- }
51
-
52
- function resolveBackendsDir() {
53
- return resolveBackendsDirFrom({
54
- localPrebuildsDir: path.join(PACKAGE_ROOT, PREBUILDS_DIR_NAME),
55
- host: currentHost(),
56
- directoryExists: safeDirectoryExists,
57
- resolveManifest: safeResolveManifest
58
- })
59
- }
60
-
61
- function currentHost() {
62
- return require.addon ? require.addon.host : null
63
- }
64
-
65
- function safeDirectoryExists(dir) {
66
- try {
67
- return fs.existsSync(dir)
68
- } catch {
69
- return false
70
- }
71
- }
72
-
73
- function safeResolveManifest(specifier) {
74
- try {
75
- return require.resolve(specifier)
76
- } catch {
77
- return null
78
- }
79
- }
80
-
81
- module.exports = {
82
- PREBUILT_HOSTS,
83
- hostPlatformPackage,
84
- resolveBackendsDirFrom,
85
- resolveBackendsDir
86
- }