wllama-service 2.0.0 → 2.0.1
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 +54 -17
package/package.json
CHANGED
package/scripts/postinstall.js
CHANGED
|
@@ -1,26 +1,63 @@
|
|
|
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 fixed relative path. This is the part that breaks in
|
|
10
|
+
* yarn workspaces monorepos: @wllama/wllama gets hoisted to the
|
|
11
|
+
* monorepo ROOT node_modules, not nested under wllama-service's own
|
|
12
|
+
* node_modules, so `__dirname + '../node_modules/@wllama/wllama/...'`
|
|
13
|
+
* never finds it. require.resolve walks up node_modules the same way
|
|
14
|
+
* Node itself would, so it finds the package wherever it actually is.
|
|
15
|
+
*/
|
|
16
|
+
function resolveWasmSrc() {
|
|
17
|
+
const pkgJsonPath = require.resolve('@wllama/wllama/package.json');
|
|
18
|
+
const pkgRoot = path.dirname(pkgJsonPath);
|
|
19
|
+
return path.join(pkgRoot, 'esm', 'wasm', 'wllama.wasm');
|
|
20
|
+
}
|
|
15
21
|
|
|
16
|
-
|
|
17
|
-
|
|
22
|
+
/**
|
|
23
|
+
* Find the consuming app's public directory. Tries common monorepo
|
|
24
|
+
* layouts, then falls back to walking up from cwd looking for a
|
|
25
|
+
* package.json + public/ pair.
|
|
26
|
+
*/
|
|
27
|
+
function findPublicDir() {
|
|
28
|
+
const candidates = [
|
|
29
|
+
path.resolve(process.cwd(), 'public'),
|
|
30
|
+
path.resolve(process.cwd(), '../../public'),
|
|
31
|
+
path.resolve(process.cwd(), '../../../public'),
|
|
32
|
+
path.resolve(process.cwd(), '../../../../public'),
|
|
33
|
+
];
|
|
34
|
+
return candidates.find((p) => fs.existsSync(p));
|
|
35
|
+
}
|
|
18
36
|
|
|
19
|
-
|
|
37
|
+
let wasmSrc;
|
|
38
|
+
try {
|
|
39
|
+
wasmSrc = resolveWasmSrc();
|
|
40
|
+
} catch (err) {
|
|
41
|
+
console.warn('[wllama-service] Could not resolve @wllama/wllama:', err.message);
|
|
42
|
+
process.exit(0);
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
if (!fs.existsSync(wasmSrc)) {
|
|
46
|
+
console.warn('[wllama-service] wllama.wasm not found at', wasmSrc);
|
|
47
|
+
process.exit(0);
|
|
48
|
+
}
|
|
20
49
|
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
50
|
+
const publicDir = findPublicDir();
|
|
51
|
+
if (!publicDir) {
|
|
52
|
+
console.warn(
|
|
53
|
+
'[wllama-service] Could not find a public/ directory near',
|
|
54
|
+
process.cwd(),
|
|
55
|
+
'\n Set WLLAMA_PUBLIC_DIR env var to specify it explicitly.',
|
|
56
|
+
);
|
|
25
57
|
process.exit(0);
|
|
26
|
-
}
|
|
58
|
+
}
|
|
59
|
+
|
|
60
|
+
const dest = path.join(publicDir, 'wllama', 'wllama.wasm');
|
|
61
|
+
fs.mkdirSync(path.dirname(dest), { recursive: true });
|
|
62
|
+
fs.copyFileSync(wasmSrc, dest);
|
|
63
|
+
console.log(`[wllama-service] ✓ Copied wllama.wasm to ${dest}`);
|