@qvac/sdk 0.22.0 ā 0.24.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/NOTICE +194 -97
- package/README.md +29 -470
- package/dist/examples/asr/parakeet-sortformer.js +24 -14
- package/dist/examples/asr/parakeet-transcribepsy-filesystem.d.ts +2 -0
- package/dist/examples/asr/parakeet-transcribepsy-filesystem.js +105 -0
- package/dist/examples/asr/parakeet-unified-coreml.js +14 -9
- package/dist/examples/asr/whispercpp-prompt.js +9 -5
- package/dist/examples/assess-model-fit.d.ts +7 -9
- package/dist/examples/assess-model-fit.js +22 -43
- package/dist/examples/calc-tokens.d.ts +2 -0
- package/dist/examples/calc-tokens.js +21 -0
- package/dist/examples/classification/classify-image.js +11 -5
- package/dist/examples/completion-stop-reason.d.ts +3 -3
- package/dist/examples/completion-stop-reason.js +4 -4
- package/dist/examples/diffusion-flux3-klein.d.ts +2 -0
- package/dist/examples/diffusion-flux3-klein.js +102 -0
- package/dist/examples/diffusion-img2vid-ltx.js +7 -14
- package/dist/examples/diffusion-moss-image.d.ts +2 -0
- package/dist/examples/diffusion-moss-image.js +126 -0
- package/dist/examples/diffusion-qwen-image-21.d.ts +2 -0
- package/dist/examples/diffusion-qwen-image-21.js +115 -0
- package/dist/examples/diffusion-txt2vid-ltx.js +7 -14
- package/dist/examples/embed-multimodal.d.ts +2 -0
- package/dist/examples/embed-multimodal.js +80 -0
- package/dist/examples/embed-p2p.js +2 -2
- package/dist/examples/finetune/llamacpp-finetune.js +9 -4
- package/dist/examples/image/megaloc.d.ts +2 -0
- package/dist/examples/image/megaloc.js +37 -0
- package/dist/examples/llamacpp-multimodal.js +21 -1
- package/dist/examples/mcp-websearch.js +1 -1
- package/dist/examples/plugins.js +1 -1
- package/dist/examples/rag/rag-hyperdb/pipeline.js +2 -2
- package/dist/examples/rag/rag-turbovec.js +2 -2
- package/dist/examples/rerank.d.ts +2 -0
- package/dist/examples/rerank.js +33 -0
- package/dist/examples/sessions.d.ts +17 -0
- package/dist/examples/sessions.js +63 -0
- package/dist/examples/tools/llamacpp-deferred-tools.js +12 -8
- package/dist/examples/tools/llamacpp-tools-auto-dialect.js +4 -3
- package/dist/examples/tools/llamacpp-tools-gemma4.js +3 -3
- package/dist/examples/tools/llamacpp-tools-qwen35.js +4 -3
- package/dist/scripts/check-resource-collectors-packaging.js +7 -6
- package/dist/scripts/contract/build-contract.d.ts +2 -1
- package/dist/scripts/contract/build-contract.js +13 -1
- package/dist/scripts/contract/constants-registry.d.ts +19 -0
- package/dist/scripts/contract/constants-registry.js +9 -2
- package/dist/scripts/contract/method-shapes.d.ts +5 -0
- package/dist/scripts/contract/method-shapes.js +5 -0
- package/dist/scripts/enforce-inference-versions.d.ts +1 -1
- package/dist/scripts/enforce-inference-versions.js +28 -18
- package/dist/scripts/generate-bare-kit-runtimes.js +101 -69
- package/dist/src/client/api/assess-model-fit.d.ts +17 -17
- package/dist/src/client/api/assess-model-fit.js +19 -32
- package/dist/src/client/api/audio-edit.d.ts +5 -3
- package/dist/src/client/api/audio-edit.js +7 -5
- package/dist/src/client/api/audio-gen-result.js +136 -47
- package/dist/src/client/api/audio-gen.d.ts +40 -3
- package/dist/src/client/api/audio-gen.js +42 -5
- package/dist/src/client/api/audio-understand.d.ts +2 -2
- package/dist/src/client/api/audio-understand.js +4 -4
- package/dist/src/client/api/batch-completion.js +4 -3
- package/dist/src/client/api/bci-transcribe.js +3 -3
- package/dist/src/client/api/calc-tokens.d.ts +33 -0
- package/dist/src/client/api/calc-tokens.js +44 -0
- package/dist/src/client/api/cancel.d.ts +2 -2
- package/dist/src/client/api/cancel.js +3 -3
- package/dist/src/client/api/classify.d.ts +12 -5
- package/dist/src/client/api/classify.js +18 -6
- package/dist/src/client/api/client-request-id.d.ts +0 -15
- package/dist/src/client/api/client-request-id.js +15 -12
- package/dist/src/client/api/completion-stream.d.ts +9 -1
- package/dist/src/client/api/completion-stream.js +14 -3
- package/dist/src/client/api/decide.d.ts +1 -1
- package/dist/src/client/api/decide.js +3 -3
- package/dist/src/client/api/delete-cache.d.ts +9 -2
- package/dist/src/client/api/delete-cache.js +14 -4
- package/dist/src/client/api/diffusion.d.ts +38 -5
- package/dist/src/client/api/diffusion.js +42 -7
- package/dist/src/client/api/download-asset.js +3 -3
- package/dist/src/client/api/embed.d.ts +82 -29
- package/dist/src/client/api/embed.js +66 -21
- package/dist/src/client/api/finetune.js +3 -3
- package/dist/src/client/api/get-loaded-model-info.js +1 -1
- package/dist/src/client/api/get-model-info.d.ts +2 -2
- package/dist/src/client/api/get-model-info.js +3 -3
- package/dist/src/client/api/get-system-resources.d.ts +2 -2
- package/dist/src/client/api/get-system-resources.js +3 -3
- package/dist/src/client/api/heartbeat.d.ts +3 -2
- package/dist/src/client/api/heartbeat.js +4 -3
- package/dist/src/client/api/index.d.ts +8 -6
- package/dist/src/client/api/index.js +6 -4
- package/dist/src/client/api/invoke-plugin.d.ts +8 -2
- package/dist/src/client/api/invoke-plugin.js +18 -3
- package/dist/src/client/api/load-model.js +9 -6
- package/dist/src/client/api/logging-stream.d.ts +11 -2
- package/dist/src/client/api/logging-stream.js +12 -3
- package/dist/src/client/api/ocr.d.ts +5 -3
- package/dist/src/client/api/ocr.js +45 -22
- package/dist/src/client/api/rag.d.ts +1 -1
- package/dist/src/client/api/rag.js +3 -3
- package/dist/src/client/api/registry.d.ts +19 -8
- package/dist/src/client/api/registry.js +43 -17
- package/dist/src/client/api/rerank.d.ts +22 -0
- package/dist/src/client/api/rerank.js +39 -0
- package/dist/src/client/api/resume.d.ts +2 -1
- package/dist/src/client/api/resume.js +3 -3
- package/dist/src/client/api/rpc-server.d.ts +4 -4
- package/dist/src/client/api/rpc-server.js +12 -12
- package/dist/src/client/api/state.d.ts +2 -2
- package/dist/src/client/api/state.js +3 -3
- package/dist/src/client/api/subscribe-logs.d.ts +2 -2
- package/dist/src/client/api/subscribe-logs.js +4 -3
- package/dist/src/client/api/suspend.d.ts +4 -2
- package/dist/src/client/api/suspend.js +5 -4
- package/dist/src/client/api/text-to-speech.d.ts +14 -5
- package/dist/src/client/api/text-to-speech.js +86 -32
- package/dist/src/client/api/transcribe.d.ts +7 -3
- package/dist/src/client/api/transcribe.js +9 -3
- package/dist/src/client/api/translate.js +2 -2
- package/dist/src/client/api/unload-model.d.ts +19 -7
- package/dist/src/client/api/unload-model.js +31 -13
- package/dist/src/client/api/upscale.d.ts +6 -3
- package/dist/src/client/api/upscale.js +10 -5
- package/dist/src/client/api/vector-index.d.ts +51 -17
- package/dist/src/client/api/vector-index.js +101 -49
- package/dist/src/client/api/video-request.d.ts +5 -5
- package/dist/src/client/api/video.d.ts +3 -2
- package/dist/src/client/api/video.js +6 -5
- package/dist/src/client/api/vla.d.ts +9 -5
- package/dist/src/client/api/vla.js +17 -8
- package/dist/src/client/api/world-result.js +2 -2
- package/dist/src/client/api/world.d.ts +6 -6
- package/dist/src/client/api/world.js +6 -6
- package/dist/src/client/init-hooks.d.ts +6 -4
- package/dist/src/client/init-hooks.js +12 -15
- package/dist/src/client/logging-stream-registry.d.ts +6 -3
- package/dist/src/client/logging-stream-registry.js +36 -14
- package/dist/src/client/plugins-factory.d.ts +1 -1
- package/dist/src/client/plugins-factory.js +1 -1
- package/dist/src/client/rpc/bundle-stamp.d.ts +29 -0
- package/dist/src/client/rpc/bundle-stamp.js +75 -0
- package/dist/src/client/rpc/expo-home-dir.d.ts +2 -0
- package/dist/src/client/rpc/expo-home-dir.js +4 -0
- package/dist/src/client/rpc/expo-rpc-client.js +192 -138
- package/dist/src/client/rpc/node-rpc-client.js +324 -426
- package/dist/src/client/rpc/pear-runtime.d.ts +12 -0
- package/dist/src/client/rpc/pear-runtime.js +12 -0
- package/dist/src/client/rpc/rpc-client.d.ts +6 -4
- package/dist/src/client/rpc/rpc-client.js +168 -31
- package/dist/src/client/rpc/rpc-error.js +24 -2
- package/dist/src/client/rpc/unbundled-harness.d.ts +16 -0
- package/dist/src/client/rpc/unbundled-harness.js +27 -0
- package/dist/src/client/rpc/worker-failure.d.ts +27 -0
- package/dist/src/client/rpc/worker-failure.js +61 -0
- package/dist/src/client/session-registry.d.ts +75 -0
- package/dist/src/client/session-registry.js +149 -0
- package/dist/src/client/session.d.ts +125 -0
- package/dist/src/client/session.js +148 -0
- package/dist/src/commands/bundle/addons.d.ts +14 -0
- package/dist/src/commands/bundle/addons.js +65 -0
- package/dist/src/commands/bundle/constants.js +2 -0
- package/dist/src/commands/bundle/entry-gen.d.ts +1 -5
- package/dist/src/commands/bundle/entry-gen.js +18 -51
- package/dist/src/commands/bundle/index.d.ts +60 -14
- package/dist/src/commands/bundle/index.js +350 -126
- package/dist/src/commands/bundle/link.d.ts +58 -0
- package/dist/src/commands/bundle/link.js +135 -0
- package/dist/src/commands/bundle/node-support.d.ts +13 -0
- package/dist/src/commands/bundle/node-support.js +23 -0
- package/dist/src/commands/bundle/plugins.js +1 -1
- package/dist/src/commands/bundle/read-bundle.d.ts +9 -0
- package/dist/src/commands/bundle/read-bundle.js +27 -0
- package/dist/src/commands/bundle/resolve-sdk-import.d.ts +6 -0
- package/dist/src/commands/bundle/resolve-sdk-import.js +24 -28
- package/dist/src/commands/bundle/scratch.d.ts +35 -0
- package/dist/src/commands/bundle/scratch.js +178 -0
- package/dist/src/commands/bundle/targets.d.ts +14 -0
- package/dist/src/commands/bundle/targets.js +37 -0
- package/dist/src/commands/host-prebuilds/index.d.ts +8 -7
- package/dist/src/commands/host-prebuilds/index.js +13 -11
- package/dist/src/commands/index.d.ts +13 -12
- package/dist/src/commands/index.js +7 -7
- package/dist/src/commands/verify/abi.d.ts +21 -15
- package/dist/src/commands/verify/abi.js +12 -80
- package/dist/src/commands/verify/bare-kit-runtime.d.ts +20 -22
- package/dist/src/commands/verify/bare-kit-runtime.js +102 -150
- package/dist/src/commands/verify/bare-kit-runtimes.d.ts +10 -9
- package/dist/src/commands/verify/bare-kit-runtimes.js +21 -21
- package/dist/src/commands/verify/bundle-source.d.ts +1 -1
- package/dist/src/commands/verify/bundle-source.js +27 -23
- package/dist/src/commands/verify/engines-advice.d.ts +6 -12
- package/dist/src/commands/verify/engines-advice.js +9 -56
- package/dist/src/commands/verify/index.d.ts +34 -33
- package/dist/src/commands/verify/index.js +96 -204
- package/dist/src/commands/verify/node-modules-source.d.ts +1 -1
- package/dist/src/commands/verify/node-modules-source.js +1 -1
- package/dist/src/commands/verify/prebuilds.d.ts +4 -6
- package/dist/src/commands/verify/prebuilds.js +3 -4
- package/dist/src/commands/verify/resource-collectors.d.ts +0 -6
- package/dist/src/commands/verify/resource-collectors.js +3 -52
- package/dist/src/commands/verify/sidecar-runtime.d.ts +6 -0
- package/dist/src/commands/verify/sidecar-runtime.js +51 -0
- package/dist/src/expo/plugins/get-project-root.d.ts +1 -1
- package/dist/src/expo/plugins/withAndroidArchitecture.d.ts +1 -1
- package/dist/src/expo/plugins/withAndroidNdkVersion.d.ts +1 -1
- package/dist/src/expo/plugins/withAndroidNdkVersion.js +16 -10
- package/dist/src/expo/plugins/withBareKit.d.ts +59 -0
- package/dist/src/expo/plugins/withBareKit.js +204 -0
- package/dist/src/expo/plugins/withDeviceInfo.d.ts +1 -1
- package/dist/src/expo/plugins/withDeviceInfo.js +19 -5
- package/dist/src/expo/plugins/withMobileBundle.d.ts +5 -12
- package/dist/src/expo/plugins/withMobileBundle.js +38 -59
- package/dist/src/expo/plugins/withOpenCL.d.ts +1 -1
- package/dist/src/expo/plugins/withQvacSDK.d.ts +2 -1
- package/dist/src/expo/plugins/withQvacSDK.js +3 -0
- package/dist/src/index.d.ts +6 -5
- package/dist/src/index.js +10 -14
- package/dist/src/logging/addon.d.ts +1 -1
- package/dist/src/logging/base-logger.js +1 -1
- package/dist/src/logging/utils.js +11 -3
- package/dist/src/plugin-ids.d.ts +3 -1
- package/dist/src/plugin-ids.js +4 -0
- package/dist/src/schemas/public.d.ts +1 -1
- package/dist/src/schemas/public.js +1 -1
- package/dist/src/schemas/sdk-errors-client.d.ts +5 -6
- package/dist/src/schemas/sdk-errors-client.js +30 -36
- package/dist/src/schemas/sdk-errors-server.d.ts +12 -1
- package/dist/src/schemas/sdk-errors-server.js +65 -2
- package/dist/src/server/rpc/rpc-utils.d.ts +26 -0
- package/dist/src/server/rpc/rpc-utils.js +41 -0
- package/dist/src/utils/aggregate-events.d.ts +1 -1
- package/dist/src/utils/aggregate-events.js +2 -2
- package/dist/src/utils/errors-client.d.ts +37 -29
- package/dist/src/utils/errors-client.js +50 -41
- package/dist/src/utils/errors-server.d.ts +65 -1
- package/dist/src/utils/errors-server.js +122 -1
- package/dist/src/utils/mcp-adapter.d.ts +1 -1
- package/dist/src/utils/mcp-adapter.js +1 -1
- package/dist/src/utils/tool-helpers.js +1 -1
- package/dist/src/utils/withTimeout.js +34 -17
- package/dist/src/worker/handle-request.js +26 -21
- package/dist/src/worker/handler-utils.d.ts +2 -6
- package/dist/src/worker/handler-utils.js +2 -20
- package/dist/src/worker/index.d.ts +2 -4
- package/dist/src/worker/index.js +24 -34
- package/dist/src/worker/plugins/ggml-image-embedding.d.ts +2 -0
- package/dist/src/worker/plugins/ggml-image-embedding.js +1 -0
- package/dist/src/worker/plugins/llamacpp-rerank.d.ts +2 -0
- package/dist/src/worker/plugins/llamacpp-rerank.js +1 -0
- package/dist/src/worker/shim.d.ts +4 -0
- package/dist/src/worker/shim.js +7 -0
- package/dist/src/worker/start.d.ts +9 -0
- package/dist/src/worker/start.js +16 -0
- package/dist/src/worker/unbundled-shim.d.ts +2 -0
- package/dist/src/worker/unbundled-shim.js +4 -0
- package/docs/system-resources-support-matrix.md +27 -19
- package/package.json +91 -74
- package/src/electron-forge/index.cjs +65 -91
- package/dist/examples/model-fit-ui/server.d.ts +0 -24
- package/dist/examples/model-fit-ui/server.js +0 -221
- package/dist/src/client/rpc/ensure-worker-ready.d.ts +0 -9
- package/dist/src/client/rpc/ensure-worker-ready.js +0 -17
- package/dist/src/client/rpc/init-timeout.d.ts +0 -26
- package/dist/src/client/rpc/init-timeout.js +0 -25
- package/dist/src/client/rpc/worker-startup-error.d.ts +0 -12
- package/dist/src/client/rpc/worker-startup-error.js +0 -13
- package/dist/src/commands/bundle/bare-pack.d.ts +0 -21
- package/dist/src/commands/bundle/bare-pack.js +0 -77
- package/dist/src/commands/bundle/manifest.d.ts +0 -25
- package/dist/src/commands/bundle/manifest.js +0 -192
- package/dist/src/expo/plugins/link-addons.d.ts +0 -18
- package/dist/src/expo/plugins/link-addons.js +0 -65
- package/dist/src/pear/pre.d.ts +0 -21
- package/dist/src/pear/pre.js +0 -448
- package/dist/src/server/env.d.ts +0 -22
- package/dist/src/server/env.js +0 -59
- package/dist/src/server/utils/qvac-paths.d.ts +0 -2
- package/dist/src/server/utils/qvac-paths.js +0 -5
- package/dist/src/server/utils/worker-lock.d.ts +0 -3
- package/dist/src/server/utils/worker-lock.js +0 -67
- package/dist/src/worker/create-server.d.ts +0 -8
- package/dist/src/worker/create-server.js +0 -51
- package/dist/src/worker/lifecycle.d.ts +0 -23
- package/dist/src/worker/lifecycle.js +0 -149
|
@@ -1,34 +1,43 @@
|
|
|
1
1
|
import fs, { promises as fsp } from 'node:fs';
|
|
2
2
|
import path from 'node:path';
|
|
3
3
|
import { createRequire } from 'node:module';
|
|
4
|
-
import {
|
|
4
|
+
import { fileURLToPath, pathToFileURL } from 'node:url';
|
|
5
|
+
import stow from 'bare-stow';
|
|
6
|
+
import { DEFAULT_HOSTS, DEFAULT_SDK_NAME } from '../../commands/bundle/constants.js';
|
|
5
7
|
import { CONFIG_CANDIDATES, resolveConfigForProject } from '../../client/config-loader/resolve-config.node.js';
|
|
6
|
-
import { createCommandLogger } from '
|
|
7
|
-
import { BareImportsMapNotFoundError, HostPrebuildsMissingError } from '../../utils/errors-client.js';
|
|
8
|
-
import { resolvePluginSpecifiers, parseBuiltinSpecifier } from '
|
|
9
|
-
import {
|
|
10
|
-
import {
|
|
11
|
-
import { AUDIO_DECODER_ADDON,
|
|
12
|
-
import {
|
|
13
|
-
import {
|
|
14
|
-
import {
|
|
15
|
-
import {
|
|
16
|
-
import {
|
|
17
|
-
|
|
8
|
+
import { createCommandLogger } from '../../commands/command-logger.js';
|
|
9
|
+
import { BareImportsMapNotFoundError, BundleFailedError, BundleVerificationFailedError, HostPrebuildsMissingError } from '../../utils/errors-client.js';
|
|
10
|
+
import { resolvePluginSpecifiers, parseBuiltinSpecifier } from '../../commands/bundle/plugins.js';
|
|
11
|
+
import { generateWorkerEntry } from '../../commands/bundle/entry-gen.js';
|
|
12
|
+
import { createSdkImportResolver, sdkImportsMap } from '../../commands/bundle/resolve-sdk-import.js';
|
|
13
|
+
import { AUDIO_DECODER_ADDON, listBundledAddonModules, listBundledAddons } from '../../commands/bundle/addons.js';
|
|
14
|
+
import { assertReactNativeBareKitSupported, stageAddons } from '../../commands/bundle/link.js';
|
|
15
|
+
import { assertNodeCanBundle } from '../../commands/bundle/node-support.js';
|
|
16
|
+
import { readBundle } from '../../commands/bundle/read-bundle.js';
|
|
17
|
+
import { discardScratch, discardStaged, removeStaleScratch, replaceAll, scratchFolderFor } from '../../commands/bundle/scratch.js';
|
|
18
|
+
import { HARNESS_FILE, TARGETS } from '../../commands/bundle/targets.js';
|
|
19
|
+
import { findMissingPlatformPackages, installMissingHostPrebuilds, resolveAddons } from '../../commands/host-prebuilds/index.js';
|
|
20
|
+
import { findInAncestorNodeModules } from '../../expo/plugins/find-in-ancestor-node-modules.js';
|
|
21
|
+
import { isMobileHost } from '../../commands/verify/prebuilds.js';
|
|
22
|
+
import { DESKTOP_RUNTIMES, formatVerifyBundleResult, hasErrors, verifyBundle } from '../../commands/verify/index.js';
|
|
23
|
+
import { formatRuntimeSource } from '../../commands/verify/abi.js';
|
|
24
|
+
import { formatEnginesAdvice } from '../../commands/verify/engines-advice.js';
|
|
25
|
+
import { BUNDLE_RECORD_FILE, BUNDLED_SDK_VERSION_FIELD, BUNDLED_TARGET_FIELD } from '../../client/rpc/bundle-stamp.js';
|
|
18
26
|
function resolveSdkPath(projectRoot, explicitSdkPath) {
|
|
19
27
|
if (explicitSdkPath) {
|
|
20
28
|
return path.isAbsolute(explicitSdkPath)
|
|
21
29
|
? explicitSdkPath
|
|
22
30
|
: path.join(projectRoot, explicitSdkPath);
|
|
23
31
|
}
|
|
32
|
+
return (findInAncestorNodeModules(projectRoot, DEFAULT_SDK_NAME) ??
|
|
33
|
+
path.join(projectRoot, 'node_modules', DEFAULT_SDK_NAME));
|
|
34
|
+
}
|
|
35
|
+
function realpath(dir) {
|
|
24
36
|
try {
|
|
25
|
-
|
|
26
|
-
paths: [projectRoot]
|
|
27
|
-
});
|
|
28
|
-
return path.dirname(pkgJsonPath);
|
|
37
|
+
return fs.realpathSync(dir);
|
|
29
38
|
}
|
|
30
39
|
catch {
|
|
31
|
-
return
|
|
40
|
+
return dir;
|
|
32
41
|
}
|
|
33
42
|
}
|
|
34
43
|
async function resolveSdkName(sdkPath) {
|
|
@@ -53,7 +62,6 @@ function resolveImportsMapPath(sdkPath, sdkName) {
|
|
|
53
62
|
}
|
|
54
63
|
throw new BareImportsMapNotFoundError(sdkName, importsMapPath);
|
|
55
64
|
}
|
|
56
|
-
const ENGINES_ISSUE_CODES = new Set(['abi-mismatch', 'engines-mismatch']);
|
|
57
65
|
const AUDIO_PLUGINS = new Set([
|
|
58
66
|
'whispercpp-transcription',
|
|
59
67
|
'bci-whispercpp-transcription',
|
|
@@ -67,50 +75,204 @@ function audioPluginsIn(pluginSpecifiers, sdkName) {
|
|
|
67
75
|
return builtin !== null && AUDIO_PLUGINS.has(builtin.suffix);
|
|
68
76
|
});
|
|
69
77
|
}
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
78
|
+
/**
|
|
79
|
+
* The bare-stow this command bundles and links with, whose Bare Kit pins are
|
|
80
|
+
* the phone runtimes, even when the project installs another SDK.
|
|
81
|
+
*/
|
|
82
|
+
function bundlerBareStowDir() {
|
|
83
|
+
return path.dirname(createRequire(import.meta.url).resolve('bare-stow/package'));
|
|
84
|
+
}
|
|
85
|
+
async function verifyOutput(options) {
|
|
86
|
+
const { projectRoot, bundlePath, hosts, target, network, logger } = options;
|
|
87
|
+
logger.info('\nš Verifying the bundle...');
|
|
73
88
|
const result = await verifyBundle({
|
|
74
89
|
projectRoot,
|
|
75
90
|
addonsSource: bundlePath,
|
|
76
91
|
hosts,
|
|
77
|
-
|
|
92
|
+
bareStowDir: bundlerBareStowDir(),
|
|
93
|
+
desktopRuntime: DESKTOP_RUNTIMES[target],
|
|
78
94
|
...(network !== undefined ? { network } : {}),
|
|
79
95
|
onProgress: (message) => logger.info(` ${message}`)
|
|
80
96
|
});
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
97
|
+
if (hasErrors(result)) {
|
|
98
|
+
throw new BundleVerificationFailedError(bundlePath, new Error(formatVerifyBundleResult(result)));
|
|
99
|
+
}
|
|
100
|
+
const checked = [];
|
|
101
|
+
for (const { hosts: platformHosts, resolution } of result.runtimes) {
|
|
102
|
+
const label = platformHosts.join(', ');
|
|
103
|
+
if (!resolution.resolved) {
|
|
104
|
+
logger.warn(`engines.bare not checked for ${label}: ${resolution.error.reason}`);
|
|
105
|
+
continue;
|
|
90
106
|
}
|
|
107
|
+
logger.info(` ${label}: Bare ${resolution.runtime.version} (from ${formatRuntimeSource(resolution.runtime)})`);
|
|
108
|
+
checked.push(...platformHosts);
|
|
91
109
|
}
|
|
92
|
-
|
|
110
|
+
if (checked.length === 0)
|
|
111
|
+
return result;
|
|
112
|
+
const mismatches = result.issues.filter((issue) => issue.code === 'engines-mismatch');
|
|
93
113
|
if (mismatches.length === 0) {
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
}
|
|
97
|
-
return;
|
|
114
|
+
logger.info(` No engines.bare mismatches for ${checked.join(', ')}`);
|
|
115
|
+
return result;
|
|
98
116
|
}
|
|
99
|
-
const lines = ['The bundle contains packages that
|
|
117
|
+
const lines = ['The bundle contains packages that declare a newer Bare runtime:'];
|
|
100
118
|
for (const issue of mismatches)
|
|
101
119
|
lines.push(` - ${issue.message}`);
|
|
102
120
|
lines.push('');
|
|
103
|
-
for (const advice of result.advice
|
|
121
|
+
for (const advice of result.advice)
|
|
104
122
|
lines.push(...formatEnginesAdvice(advice));
|
|
105
123
|
logger.warn(lines.join('\n').trimEnd());
|
|
124
|
+
return result;
|
|
125
|
+
}
|
|
126
|
+
function defaultHosts(target) {
|
|
127
|
+
if (target === 'react-native')
|
|
128
|
+
return DEFAULT_HOSTS.filter(isMobileHost);
|
|
129
|
+
if (target === 'bare-kit')
|
|
130
|
+
return DEFAULT_HOSTS.filter((host) => host.startsWith('android-'));
|
|
131
|
+
return [`${process.platform}-${process.arch}`];
|
|
132
|
+
}
|
|
133
|
+
/** Writes bare-stow's harness package for the target to `outputDir`, and returns the bundle's path. */
|
|
134
|
+
async function stowBundle(options) {
|
|
135
|
+
const { projectRoot, entryPath, target, language, outputDir, hosts, imports, deferModules } = options;
|
|
136
|
+
const stowTarget = await TARGETS[target].load(projectRoot);
|
|
137
|
+
assertNodeCanBundle();
|
|
138
|
+
// With no base, bare-stow keys the bundle from the closest folder holding
|
|
139
|
+
// every module.
|
|
140
|
+
const stowOptions = {
|
|
141
|
+
imports,
|
|
142
|
+
defer: deferModules,
|
|
143
|
+
hosts,
|
|
144
|
+
language,
|
|
145
|
+
languageOptions: options.languageOptions
|
|
146
|
+
};
|
|
147
|
+
let bundlePath;
|
|
148
|
+
try {
|
|
149
|
+
for await (const artifact of stow(pathToFileURL(entryPath).href, stowTarget, pathToFileURL(outputDir).href, stowOptions)) {
|
|
150
|
+
if (artifact.base !== undefined)
|
|
151
|
+
bundlePath = fileURLToPath(artifact.url.href);
|
|
152
|
+
}
|
|
153
|
+
}
|
|
154
|
+
catch (error) {
|
|
155
|
+
throw new BundleFailedError(entryPath, describeMissingAddonBuild(error, hosts) ?? error);
|
|
156
|
+
}
|
|
157
|
+
if (bundlePath === undefined) {
|
|
158
|
+
throw new BundleFailedError(entryPath, new Error(`bare-stow wrote no bundle to ${outputDir}`));
|
|
159
|
+
}
|
|
160
|
+
if (language === 'javascript')
|
|
161
|
+
await assertHarnessDependenciesResolve(entryPath, outputDir);
|
|
162
|
+
return bundlePath;
|
|
163
|
+
}
|
|
164
|
+
const PACKAGE_IN_PATH = /\/node_modules\/((?:@[^/]+\/)?[^/]+)(?=\/)/g;
|
|
165
|
+
const MISSING_FOR_HOSTS = /for hosts? ((?:'[^']+'(?:, )?)+)/;
|
|
166
|
+
/**
|
|
167
|
+
* The addon package and hosts an `ADDON_NOT_FOUND` from the bundler names, in
|
|
168
|
+
* place of its list of candidate paths, or null for any other error. The error
|
|
169
|
+
* names the hosts only when some of `hosts` have a build.
|
|
170
|
+
*/
|
|
171
|
+
export function describeMissingAddonBuild(error, hosts) {
|
|
172
|
+
const { code, referrer, message } = (error ?? {});
|
|
173
|
+
if (code !== 'ADDON_NOT_FOUND' || !referrer)
|
|
174
|
+
return null;
|
|
175
|
+
const owner = [...referrer.href.matchAll(PACKAGE_IN_PATH)].at(-1)?.[1];
|
|
176
|
+
if (owner === undefined)
|
|
177
|
+
return null;
|
|
178
|
+
const named = typeof message === 'string' ? MISSING_FOR_HOSTS.exec(message)?.[1] : undefined;
|
|
179
|
+
const missing = named === undefined ? hosts : [...named.matchAll(/'([^']+)'/g)].map((m) => m[1]);
|
|
180
|
+
return new Error(`${owner} has no native build for ${missing.join(', ')}. Bundle for the hosts it ships ` +
|
|
181
|
+
'builds for, or leave it out of the bundle with `defer`.', { cause: error });
|
|
182
|
+
}
|
|
183
|
+
/**
|
|
184
|
+
* Packages every importer gets from the SDK's own dependencies. Their newer
|
|
185
|
+
* releases need a newer Bare than the Bare Kit this SDK links, and a project
|
|
186
|
+
* may install one through another package's range.
|
|
187
|
+
*/
|
|
188
|
+
const SDK_PINNED_MODULES = ['bare-type'];
|
|
189
|
+
function pinSdkModules(imports, sdkPath, logger) {
|
|
190
|
+
const sdkRequire = createRequire(path.join(sdkPath, 'package.json'));
|
|
191
|
+
for (const name of SDK_PINNED_MODULES) {
|
|
192
|
+
try {
|
|
193
|
+
imports[name] = pathToFileURL(sdkRequire.resolve(name)).href;
|
|
194
|
+
}
|
|
195
|
+
catch {
|
|
196
|
+
logger.debug(` ${name} is not among the SDK's dependencies; bundling the project's`);
|
|
197
|
+
}
|
|
198
|
+
}
|
|
199
|
+
}
|
|
200
|
+
/** Files an older `@qvac/sdk` wrote into `qvac/`, which nothing reads now. */
|
|
201
|
+
const STALE_QVAC_FILES = ['worker.bundle.js', 'addons.manifest.json'];
|
|
202
|
+
/**
|
|
203
|
+
* Records the SDK version and the target in the harness package.json, for the
|
|
204
|
+
* client and `verifyBundle` to check. A Kotlin or Python harness has no
|
|
205
|
+
* package.json, so they go in a record file at its root.
|
|
206
|
+
*/
|
|
207
|
+
async function stampBundle(harnessDir, sdkPath, target, language) {
|
|
208
|
+
const sdk = JSON.parse(await fsp.readFile(path.join(sdkPath, 'package.json'), 'utf8'));
|
|
209
|
+
const stampPath = path.join(harnessDir, language === 'javascript' ? 'package.json' : BUNDLE_RECORD_FILE);
|
|
210
|
+
const stamp = language === 'javascript'
|
|
211
|
+
? JSON.parse(await fsp.readFile(stampPath, 'utf8'))
|
|
212
|
+
: {};
|
|
213
|
+
if (typeof sdk.version === 'string')
|
|
214
|
+
stamp[BUNDLED_SDK_VERSION_FIELD] = sdk.version;
|
|
215
|
+
stamp[BUNDLED_TARGET_FIELD] = target;
|
|
216
|
+
await fsp.writeFile(stampPath, `${JSON.stringify(stamp, null, 2)}\n`);
|
|
217
|
+
}
|
|
218
|
+
/**
|
|
219
|
+
* A `javascript` harness imports the dependencies bare-stow lists in its
|
|
220
|
+
* `package.json` by name, from the project that holds the package.
|
|
221
|
+
*/
|
|
222
|
+
async function assertHarnessDependenciesResolve(entryPath, outputDir) {
|
|
223
|
+
const manifest = JSON.parse(await fsp.readFile(path.join(outputDir, 'package.json'), 'utf8'));
|
|
224
|
+
for (const name of Object.keys(manifest.dependencies ?? {})) {
|
|
225
|
+
if (findInAncestorNodeModules(outputDir, name) !== null)
|
|
226
|
+
continue;
|
|
227
|
+
throw new BundleFailedError(entryPath, new Error(`${HARNESS_FILE} imports '${name}', which the project cannot resolve`));
|
|
228
|
+
}
|
|
229
|
+
}
|
|
230
|
+
async function readFileIfExists(filePath) {
|
|
231
|
+
try {
|
|
232
|
+
return await fsp.readFile(filePath);
|
|
233
|
+
}
|
|
234
|
+
catch (error) {
|
|
235
|
+
if (error.code === 'ENOENT')
|
|
236
|
+
return null;
|
|
237
|
+
throw error;
|
|
238
|
+
}
|
|
239
|
+
}
|
|
240
|
+
/** Puts back `filePath`'s earlier content, or removes it when it had none. */
|
|
241
|
+
async function restoreFile(filePath, content) {
|
|
242
|
+
if (content === null)
|
|
243
|
+
await fsp.rm(filePath, { force: true });
|
|
244
|
+
else
|
|
245
|
+
await fsp.writeFile(filePath, content);
|
|
246
|
+
}
|
|
247
|
+
async function assertOutputDirEmpty(outputDir, entryPath) {
|
|
248
|
+
let entries;
|
|
249
|
+
try {
|
|
250
|
+
entries = await fsp.readdir(outputDir);
|
|
251
|
+
}
|
|
252
|
+
catch (error) {
|
|
253
|
+
if (error.code === 'ENOENT')
|
|
254
|
+
return;
|
|
255
|
+
throw new BundleFailedError(entryPath, error);
|
|
256
|
+
}
|
|
257
|
+
if (entries.length > 0) {
|
|
258
|
+
throw new BundleFailedError(entryPath, new Error(`outputDir ${outputDir} must be empty or not exist yet`));
|
|
259
|
+
}
|
|
106
260
|
}
|
|
107
261
|
export async function bundleSdk(options = {}) {
|
|
108
262
|
const startTime = Date.now();
|
|
109
|
-
const projectRoot = options.projectRoot ?? process.cwd();
|
|
110
|
-
const
|
|
111
|
-
const
|
|
112
|
-
const
|
|
113
|
-
|
|
263
|
+
const projectRoot = path.resolve(options.projectRoot ?? process.cwd());
|
|
264
|
+
const qvacDir = path.join(projectRoot, 'qvac');
|
|
265
|
+
const outputDir = path.resolve(projectRoot, options.outputDir ?? path.join(qvacDir, 'worker'));
|
|
266
|
+
const entryPath = path.join(qvacDir, 'worker.entry.mjs');
|
|
267
|
+
if (options.outputDir !== undefined)
|
|
268
|
+
await assertOutputDirEmpty(outputDir, entryPath);
|
|
269
|
+
const entryFromOutput = path.relative(outputDir, entryPath);
|
|
270
|
+
if (!entryFromOutput.startsWith('..') && !path.isAbsolute(entryFromOutput)) {
|
|
271
|
+
throw new BundleFailedError(entryPath, new Error(`outputDir ${outputDir} must not contain the worker entry`));
|
|
272
|
+
}
|
|
273
|
+
const target = options.target ?? 'bare-sidecar';
|
|
274
|
+
const language = options.language ?? (target === 'bare-kit' ? 'kotlin' : 'javascript');
|
|
275
|
+
const languageOptions = options.languageOptions ?? {};
|
|
114
276
|
const logger = createCommandLogger(options);
|
|
115
277
|
logger.info('š§ QVAC SDK Worker Bundler\n');
|
|
116
278
|
const { configPath, config } = await resolveConfigForProject(projectRoot, options.configPath);
|
|
@@ -124,18 +286,33 @@ export async function bundleSdk(options = {}) {
|
|
|
124
286
|
CONFIG_CANDIDATES.map((c) => ` - ${c}`).join('\n') +
|
|
125
287
|
'\n');
|
|
126
288
|
}
|
|
127
|
-
const sdkPath = resolveSdkPath(projectRoot, options.sdkPath);
|
|
289
|
+
const sdkPath = realpath(resolveSdkPath(projectRoot, options.sdkPath));
|
|
128
290
|
const sdkName = await resolveSdkName(sdkPath);
|
|
129
291
|
logger.info(`š¦ SDK: ${sdkName}`);
|
|
130
292
|
logger.debug(` Path: ${sdkPath}`);
|
|
131
293
|
const importsMapPath = resolveImportsMapPath(sdkPath, sdkName);
|
|
294
|
+
const imports = JSON.parse(await fsp.readFile(importsMapPath, 'utf8'));
|
|
295
|
+
// An SDK the project installs is imported by name. One outside the project is
|
|
296
|
+
// imported by its real path, and so is its bare-stow runtime, which the
|
|
297
|
+
// generated shim imports.
|
|
298
|
+
const installedSdk = findInAncestorNodeModules(projectRoot, sdkName);
|
|
299
|
+
const sdkByName = installedSdk !== null && realpath(installedSdk) === sdkPath;
|
|
300
|
+
const resolveImport = sdkByName ? undefined : createSdkImportResolver(sdkPath, sdkName);
|
|
301
|
+
if (!sdkByName) {
|
|
302
|
+
const sdkRequire = createRequire(path.join(sdkPath, 'package.json'));
|
|
303
|
+
Object.assign(imports, sdkImportsMap(sdkPath, sdkName));
|
|
304
|
+
for (const runtime of ['bare-stow-runtime', 'bare-stow-runtime/process']) {
|
|
305
|
+
imports[runtime] = pathToFileURL(sdkRequire.resolve(runtime)).href;
|
|
306
|
+
}
|
|
307
|
+
}
|
|
308
|
+
pinSdkModules(imports, sdkPath, logger);
|
|
132
309
|
const pluginSpecifiers = resolvePluginSpecifiers(config, sdkName, logger);
|
|
133
310
|
logger.info(`\nš¦ Plugins to include (${pluginSpecifiers.length}):`);
|
|
134
311
|
for (const spec of pluginSpecifiers) {
|
|
135
312
|
const label = parseBuiltinSpecifier(spec, sdkName) ? 'ā built-in' : 'ā custom';
|
|
136
313
|
logger.info(` ${label}: ${spec}`);
|
|
137
314
|
}
|
|
138
|
-
const hosts = options.hosts && options.hosts.length > 0 ? options.hosts :
|
|
315
|
+
const hosts = options.hosts && options.hosts.length > 0 ? options.hosts : defaultHosts(target);
|
|
139
316
|
const explicitDefer = options.defer ?? [];
|
|
140
317
|
const includeAudioDecoder = config.includeAudioDecoder !== false && !explicitDefer.includes(AUDIO_DECODER_ADDON);
|
|
141
318
|
const deferModules = includeAudioDecoder
|
|
@@ -147,119 +324,170 @@ export async function bundleSdk(options = {}) {
|
|
|
147
324
|
logger.warn(`${AUDIO_DECODER_ADDON} is not bundled: ${affected.join(', ')} cannot decode compressed audio files; compressed audiogen output formats also require FFmpeg.`);
|
|
148
325
|
}
|
|
149
326
|
}
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
const
|
|
154
|
-
await
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
let installedPrebuilds = [];
|
|
164
|
-
const barePackOptions = {
|
|
165
|
-
entryPath: bundleEntryPath,
|
|
327
|
+
if (target === 'react-native')
|
|
328
|
+
await assertReactNativeBareKitSupported(projectRoot, sdkPath);
|
|
329
|
+
await fsp.mkdir(qvacDir, { recursive: true });
|
|
330
|
+
const scanOutputDir = path.join(qvacDir, 'worker-scan');
|
|
331
|
+
await removeStaleScratch(outputDir);
|
|
332
|
+
await removeStaleScratch(scanOutputDir);
|
|
333
|
+
const stowOptions = {
|
|
334
|
+
projectRoot,
|
|
335
|
+
entryPath,
|
|
336
|
+
target,
|
|
337
|
+
language,
|
|
338
|
+
languageOptions,
|
|
339
|
+
outputDir,
|
|
166
340
|
hosts,
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
logger
|
|
341
|
+
imports,
|
|
342
|
+
deferModules
|
|
170
343
|
};
|
|
171
344
|
const addonsMissingPlatformPackages = () => reachedAddonsMissingPlatformPackages({
|
|
172
345
|
addons: async () => (await resolveAddons(projectRoot, undefined, logger)).filter((addon) => !deferModules.includes(addon.name)),
|
|
173
346
|
hosts,
|
|
174
|
-
scan: (extraDefer
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
|
|
347
|
+
scan: async (extraDefer) => {
|
|
348
|
+
const scanDir = await scratchFolderFor(scanOutputDir);
|
|
349
|
+
try {
|
|
350
|
+
const bundlePath = await stowBundle({
|
|
351
|
+
...stowOptions,
|
|
352
|
+
outputDir: scanDir,
|
|
353
|
+
deferModules: [...deferModules, ...extraDefer]
|
|
354
|
+
});
|
|
355
|
+
return (await readBundle(bundlePath)).resolutions;
|
|
356
|
+
}
|
|
357
|
+
finally {
|
|
358
|
+
await discardScratch(scanDir);
|
|
359
|
+
}
|
|
360
|
+
},
|
|
181
361
|
logger
|
|
182
362
|
});
|
|
363
|
+
// The bundle and the app's native modules are built in scratch folders and
|
|
364
|
+
// replace the old ones together, so a failure leaves the working ones in place.
|
|
365
|
+
// bare-stow names the bundle's main after the entry's folder, so the entry is
|
|
366
|
+
// bundled from its own path and its previous content is restored on failure.
|
|
367
|
+
const previousEntry = await readFileIfExists(entryPath);
|
|
368
|
+
const scratch = await scratchFolderFor(outputDir);
|
|
369
|
+
const staged = [{ dir: outputDir, next: scratch }];
|
|
370
|
+
let installedPrebuilds = [];
|
|
371
|
+
let addons;
|
|
372
|
+
let addonModules;
|
|
373
|
+
let linked = [];
|
|
374
|
+
let verification = null;
|
|
375
|
+
let bundlePath;
|
|
376
|
+
let replaced = false;
|
|
183
377
|
try {
|
|
184
|
-
|
|
185
|
-
|
|
378
|
+
logger.info('\nš Generating worker entry...');
|
|
379
|
+
await fsp.writeFile(entryPath, generateWorkerEntry(pluginSpecifiers, sdkName, config.rpcServerProvider, resolveImport), 'utf8');
|
|
380
|
+
logger.info(` Created: ${path.relative(projectRoot, entryPath)}`);
|
|
381
|
+
logger.info(`\nšØ Bundling for ${target}...`);
|
|
382
|
+
logger.debug(` Hosts: ${hosts.join(', ')}`);
|
|
383
|
+
if (deferModules.length > 0) {
|
|
384
|
+
logger.debug(` Deferred: ${deferModules.join(', ')}`);
|
|
385
|
+
}
|
|
386
|
+
const missingPlatformAddons = await addonsMissingPlatformPackages();
|
|
186
387
|
if (options.installMissingPrebuilds === true) {
|
|
388
|
+
// Desktop packages are never installed, so a missing one is reported
|
|
389
|
+
// before package.json changes.
|
|
390
|
+
await throwIfPlatformPackagesMissing(missingPlatformAddons, hosts.filter((host) => !isMobileHost(host)));
|
|
187
391
|
const { installed } = await installMissingHostPrebuilds({
|
|
188
392
|
projectRoot,
|
|
189
393
|
hosts,
|
|
190
|
-
addons,
|
|
394
|
+
addons: missingPlatformAddons,
|
|
191
395
|
quiet: options.quiet === true,
|
|
192
396
|
logger
|
|
193
397
|
});
|
|
194
398
|
installedPrebuilds = installed;
|
|
195
399
|
}
|
|
196
400
|
else {
|
|
197
|
-
await throwIfPlatformPackagesMissing(
|
|
401
|
+
await throwIfPlatformPackagesMissing(missingPlatformAddons, hosts);
|
|
198
402
|
}
|
|
199
|
-
await
|
|
403
|
+
const scratchBundlePath = await stowBundle({ ...stowOptions, outputDir: scratch });
|
|
404
|
+
await stampBundle(scratch, sdkPath, target, language);
|
|
405
|
+
bundlePath = path.join(outputDir, path.relative(scratch, scratchBundlePath));
|
|
406
|
+
const stats = await fsp.stat(scratchBundlePath);
|
|
407
|
+
const sizeKB = (stats.size / 1024).toFixed(1);
|
|
408
|
+
logger.info(`\nā
Bundle created: ${path.relative(projectRoot, bundlePath)}`);
|
|
409
|
+
logger.info(` Size: ${sizeKB} KB`);
|
|
410
|
+
const listOptions = { bundlePath: scratchBundlePath, projectRoot, logger, includeAudioDecoder };
|
|
411
|
+
addons = await listBundledAddons(listOptions);
|
|
412
|
+
addonModules = await listBundledAddonModules(listOptions);
|
|
413
|
+
logger.info(` Native addons (${addons.length}): ${addons.join(', ') || '(none)'}`);
|
|
414
|
+
if (options.verify !== false) {
|
|
415
|
+
verification = await verifyOutput({
|
|
416
|
+
projectRoot,
|
|
417
|
+
bundlePath: scratchBundlePath,
|
|
418
|
+
hosts,
|
|
419
|
+
target,
|
|
420
|
+
network: options.network,
|
|
421
|
+
logger
|
|
422
|
+
});
|
|
423
|
+
}
|
|
424
|
+
if (target === 'react-native' && options.link !== false) {
|
|
425
|
+
const linkHosts = Array.isArray(options.link) ? options.link : hosts;
|
|
426
|
+
logger.info('\nš Writing Bare Kit and the native addons into the app...');
|
|
427
|
+
const nativeModules = await stageAddons({
|
|
428
|
+
projectRoot,
|
|
429
|
+
entryPath,
|
|
430
|
+
hosts: linkHosts,
|
|
431
|
+
imports,
|
|
432
|
+
defer: deferModules,
|
|
433
|
+
logger
|
|
434
|
+
});
|
|
435
|
+
staged.push(...nativeModules.staged);
|
|
436
|
+
linked = nativeModules.written;
|
|
437
|
+
logger.info(` Wrote ${linked.length} files`);
|
|
438
|
+
}
|
|
439
|
+
await replaceAll(staged);
|
|
440
|
+
replaced = true;
|
|
441
|
+
for (const stale of STALE_QVAC_FILES)
|
|
442
|
+
await fsp.rm(path.join(qvacDir, stale), { force: true });
|
|
200
443
|
}
|
|
201
|
-
|
|
202
|
-
|
|
444
|
+
catch (error) {
|
|
445
|
+
if (!replaced)
|
|
446
|
+
await restoreFile(entryPath, previousEntry);
|
|
447
|
+
throw error;
|
|
203
448
|
}
|
|
204
|
-
|
|
205
|
-
|
|
206
|
-
logger.info(`\nā
Bundle created: ${path.relative(projectRoot, bundlePath)}`);
|
|
207
|
-
logger.info(` Size: ${sizeKB} KB`);
|
|
208
|
-
const manifestResult = await generateAddonsManifest({
|
|
209
|
-
bundlePath,
|
|
210
|
-
outputDir,
|
|
211
|
-
projectRoot,
|
|
212
|
-
logger,
|
|
213
|
-
includeAudioDecoder
|
|
214
|
-
});
|
|
215
|
-
if (options.checkEngines !== false) {
|
|
216
|
-
await checkBundleEngines({
|
|
217
|
-
projectRoot,
|
|
218
|
-
bundlePath,
|
|
219
|
-
hosts,
|
|
220
|
-
configPath: configPath ?? undefined,
|
|
221
|
-
network: options.network,
|
|
222
|
-
logger
|
|
223
|
-
});
|
|
449
|
+
finally {
|
|
450
|
+
await discardStaged(staged);
|
|
224
451
|
}
|
|
225
452
|
const elapsed = ((Date.now() - startTime) / 1000).toFixed(2);
|
|
226
453
|
logger.info(`\nš Done in ${elapsed}s!\n`);
|
|
227
454
|
logger.info('Generated files:');
|
|
228
|
-
logger.info(
|
|
229
|
-
logger.info(
|
|
230
|
-
logger.info(
|
|
231
|
-
logger.info('Mobile: Expo plugin auto-configures worker.bundle.js');
|
|
232
|
-
logger.info('Standalone: Import qvac/worker.entry.mjs for full worker with RPC\n');
|
|
455
|
+
logger.info(` - ${path.relative(projectRoot, entryPath)} (worker entry)`);
|
|
456
|
+
logger.info(` - ${path.relative(projectRoot, outputDir)} (starts the bundled worker)`);
|
|
457
|
+
logger.info(` - ${path.relative(projectRoot, bundlePath)}\n`);
|
|
233
458
|
return {
|
|
459
|
+
target,
|
|
460
|
+
language,
|
|
461
|
+
hosts,
|
|
462
|
+
entryPath,
|
|
463
|
+
outputDir,
|
|
234
464
|
bundlePath,
|
|
235
465
|
plugins: pluginSpecifiers,
|
|
236
|
-
addons
|
|
237
|
-
|
|
238
|
-
|
|
239
|
-
|
|
240
|
-
|
|
241
|
-
installedPrebuilds
|
|
466
|
+
addons,
|
|
467
|
+
addonModules,
|
|
468
|
+
installedPrebuilds,
|
|
469
|
+
linked,
|
|
470
|
+
verification
|
|
242
471
|
};
|
|
243
472
|
}
|
|
244
473
|
/**
|
|
245
474
|
* The installed split addons that the bundle reaches and that are missing a
|
|
246
|
-
*
|
|
247
|
-
* depends on all of them), so a first
|
|
248
|
-
* platform package:
|
|
475
|
+
* platform package for one of the hosts. Every installed addon is a candidate (`@qvac/sdk`
|
|
476
|
+
* depends on all of them), so a first bundling pass defers each missing
|
|
477
|
+
* platform package: the bundle then records the reached ones as
|
|
249
478
|
* `deferred:<package>` and never visits the rest. Empty when nothing is
|
|
250
479
|
* missing, or when that pass fails, which leaves the real bundle to report
|
|
251
480
|
* the failure.
|
|
252
481
|
*/
|
|
253
482
|
async function reachedAddonsMissingPlatformPackages(options) {
|
|
254
|
-
const { hosts, scan,
|
|
483
|
+
const { hosts, scan, logger } = options;
|
|
255
484
|
const addons = await options.addons();
|
|
256
|
-
const missing = await
|
|
485
|
+
const missing = await findMissingPlatformPackages(addons, hosts);
|
|
257
486
|
if (missing.length === 0)
|
|
258
487
|
return [];
|
|
259
488
|
logger.debug(`\nš Checking which of ${missing.length} missing platform packages the bundle reaches...`);
|
|
260
489
|
try {
|
|
261
|
-
await scan(missing.map((pkg) => pkg.name)
|
|
262
|
-
const reached = deferredSpecifiers(await fsp.readFile(scanPath, 'utf8'));
|
|
490
|
+
const reached = deferredSpecifiers(await scan(missing.map((pkg) => pkg.name)));
|
|
263
491
|
const owners = new Set(missing.filter((pkg) => reached.has(pkg.name)).map((pkg) => pkg.addon));
|
|
264
492
|
return addons.filter((addon) => owners.has(addon.name));
|
|
265
493
|
}
|
|
@@ -267,14 +495,10 @@ async function reachedAddonsMissingPlatformPackages(options) {
|
|
|
267
495
|
logger.debug(` Scan failed: ${error instanceof Error ? error.message : String(error)}`);
|
|
268
496
|
return [];
|
|
269
497
|
}
|
|
270
|
-
finally {
|
|
271
|
-
await fsp.rm(scanPath, { force: true });
|
|
272
|
-
}
|
|
273
498
|
}
|
|
274
499
|
const DEFERRED_PROTOCOL = 'deferred:';
|
|
275
|
-
/** Every specifier a
|
|
276
|
-
function deferredSpecifiers(
|
|
277
|
-
const { resolutions = {} } = extractBarePackHeader(extractPackedString(bundleText));
|
|
500
|
+
/** Every specifier a bundle leaves as `deferred:<specifier>`. */
|
|
501
|
+
function deferredSpecifiers(resolutions) {
|
|
278
502
|
const found = new Set();
|
|
279
503
|
const visit = (value) => {
|
|
280
504
|
if (typeof value === 'string') {
|
|
@@ -290,13 +514,13 @@ function deferredSpecifiers(bundleText) {
|
|
|
290
514
|
return found;
|
|
291
515
|
}
|
|
292
516
|
/**
|
|
293
|
-
* Throws `HostPrebuildsMissingError` when split addons are missing
|
|
294
|
-
*
|
|
517
|
+
* Throws `HostPrebuildsMissingError` when split addons are missing platform
|
|
518
|
+
* packages for `hosts`, naming the exact pins.
|
|
295
519
|
*/
|
|
296
520
|
async function throwIfPlatformPackagesMissing(addons, hosts) {
|
|
297
521
|
let missing;
|
|
298
522
|
try {
|
|
299
|
-
missing = await
|
|
523
|
+
missing = await findMissingPlatformPackages(addons, hosts);
|
|
300
524
|
}
|
|
301
525
|
catch {
|
|
302
526
|
return;
|