wllama-service 2.0.0 → 2.0.2
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/package.json +1 -1
- package/scripts/postinstall.js +44 -17
package/package.json
CHANGED
package/scripts/postinstall.js
CHANGED
|
@@ -1,26 +1,53 @@
|
|
|
1
1
|
#!/usr/bin/env node
|
|
2
2
|
'use strict';
|
|
3
3
|
|
|
4
|
+
const fs = require('fs');
|
|
4
5
|
const path = require('path');
|
|
5
|
-
const { copyWasm } = require('./copyWllamaWasm');
|
|
6
6
|
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
7
|
+
/**
|
|
8
|
+
* Resolve @wllama/wllama's wasm file using Node's real module resolution
|
|
9
|
+
* instead of a guessed relative path. This works correctly regardless of
|
|
10
|
+
* where in the yarn workspaces hoisting tree @wllama/wllama actually
|
|
11
|
+
* landed (monorepo root, nested under wllama-service, etc) — Node's own
|
|
12
|
+
* require.resolve algorithm finds it the same way `require()` would.
|
|
13
|
+
*/
|
|
14
|
+
function resolveWasmSrc() {
|
|
15
|
+
const pkgJsonPath = require.resolve('@wllama/wllama/package.json', {
|
|
16
|
+
paths: [process.cwd()],
|
|
17
|
+
});
|
|
18
|
+
const pkgRoot = path.dirname(pkgJsonPath);
|
|
15
19
|
|
|
16
|
-
|
|
17
|
-
|
|
20
|
+
// Different @wllama/wllama versions ship different layouts:
|
|
21
|
+
// older: esm/wasm/wllama.wasm
|
|
22
|
+
// newer: esm/single-thread/wllama.wasm (+ esm/multi-thread/wllama.wasm)
|
|
23
|
+
const candidates = [
|
|
24
|
+
path.join(pkgRoot, 'esm', 'wasm', 'wllama.wasm'),
|
|
25
|
+
path.join(pkgRoot, 'esm', 'single-thread', 'wllama.wasm'),
|
|
26
|
+
];
|
|
27
|
+
const found = candidates.find((p) => fs.existsSync(p));
|
|
28
|
+
if (!found) {
|
|
29
|
+
throw new Error(
|
|
30
|
+
`wllama.wasm not found in any known location under ${pkgRoot}\n` +
|
|
31
|
+
`Checked: ${candidates.join(', ')}`,
|
|
32
|
+
);
|
|
33
|
+
}
|
|
34
|
+
return found;
|
|
35
|
+
}
|
|
18
36
|
|
|
19
|
-
|
|
37
|
+
// Destination: this app's own public folder. Adjust this path if your
|
|
38
|
+
// app's public folder lives somewhere other than apps/<this-app>/public
|
|
39
|
+
// relative to where this script sits.
|
|
40
|
+
const destDir = path.resolve(__dirname, '..', 'public', 'wllama');
|
|
20
41
|
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
42
|
+
let wasmSrc;
|
|
43
|
+
try {
|
|
44
|
+
wasmSrc = resolveWasmSrc();
|
|
45
|
+
} catch (err) {
|
|
46
|
+
console.warn('[copy-wllama-wasm] ' + err.message);
|
|
25
47
|
process.exit(0);
|
|
26
|
-
}
|
|
48
|
+
}
|
|
49
|
+
|
|
50
|
+
fs.mkdirSync(destDir, { recursive: true });
|
|
51
|
+
const dest = path.join(destDir, 'wllama.wasm');
|
|
52
|
+
fs.copyFileSync(wasmSrc, dest);
|
|
53
|
+
console.log(`[copy-wllama-wasm] ✓ Copied ${wasmSrc} -> ${dest}`);
|