wowok 2.1.12 → 2.1.13
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 +5 -2
- package/prebuilds/better-sqlite3-v12.9.0-node-v115-darwin-arm64.node +0 -0
- package/prebuilds/better-sqlite3-v12.9.0-node-v115-darwin-x64.node +0 -0
- package/prebuilds/better-sqlite3-v12.9.0-node-v115-linux-arm.node +0 -0
- package/prebuilds/better-sqlite3-v12.9.0-node-v115-linux-arm64.node +0 -0
- package/prebuilds/better-sqlite3-v12.9.0-node-v115-linux-x64.node +0 -0
- package/prebuilds/better-sqlite3-v12.9.0-node-v115-win32-arm64.node +0 -0
- package/prebuilds/better-sqlite3-v12.9.0-node-v115-win32-x64.node +0 -0
- package/prebuilds/better-sqlite3-v12.9.0-node-v127-darwin-arm64.node +0 -0
- package/prebuilds/better-sqlite3-v12.9.0-node-v127-darwin-x64.node +0 -0
- package/prebuilds/better-sqlite3-v12.9.0-node-v127-linux-arm.node +0 -0
- package/prebuilds/better-sqlite3-v12.9.0-node-v127-linux-arm64.node +0 -0
- package/prebuilds/better-sqlite3-v12.9.0-node-v127-linux-x64.node +0 -0
- package/prebuilds/better-sqlite3-v12.9.0-node-v127-win32-arm64.node +0 -0
- package/prebuilds/better-sqlite3-v12.9.0-node-v127-win32-x64.node +0 -0
- package/scripts/download-prebuilds.js +234 -0
- package/scripts/install-better-sqlite3.js +377 -0
package/package.json
CHANGED
|
@@ -3,11 +3,13 @@
|
|
|
3
3
|
"author": "wowok <build@wowok.net>",
|
|
4
4
|
"description": "Wowok Blockchain TypeScript API",
|
|
5
5
|
"homepage": "https://wowok.net",
|
|
6
|
-
"version": "2.1.
|
|
6
|
+
"version": "2.1.13",
|
|
7
7
|
"license": "Apache-2.0",
|
|
8
8
|
"sideEffects": false,
|
|
9
9
|
"files": [
|
|
10
10
|
"dist",
|
|
11
|
+
"prebuilds",
|
|
12
|
+
"scripts",
|
|
11
13
|
"LICENSE",
|
|
12
14
|
"NOTICE"
|
|
13
15
|
],
|
|
@@ -255,7 +257,8 @@
|
|
|
255
257
|
"eslint:fix": "pnpm run eslint:check --fix",
|
|
256
258
|
"lint": "pnpm run eslint:check && pnpm run prettier:check",
|
|
257
259
|
"lint:fix": "pnpm run eslint:fix && pnpm run prettier:fix",
|
|
258
|
-
"postinstall": "node
|
|
260
|
+
"postinstall": "node scripts/install-better-sqlite3.js",
|
|
261
|
+
"prebuilds:download": "node scripts/download-prebuilds.js"
|
|
259
262
|
},
|
|
260
263
|
"devDependencies": {
|
|
261
264
|
"@parcel/watcher": "^2.5.1",
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
@@ -0,0 +1,234 @@
|
|
|
1
|
+
#!/usr/bin/env node
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* Download prebuilt binaries for common platforms
|
|
5
|
+
*
|
|
6
|
+
* Run this script before publishing to include prebuilt binaries for all common platforms
|
|
7
|
+
* Users can then use local prebuilt binaries directly (Option B)
|
|
8
|
+
*/
|
|
9
|
+
|
|
10
|
+
const { execSync } = require('child_process');
|
|
11
|
+
const fs = require('fs');
|
|
12
|
+
const path = require('path');
|
|
13
|
+
|
|
14
|
+
const GREEN = '\x1b[32m';
|
|
15
|
+
const YELLOW = '\x1b[33m';
|
|
16
|
+
const RED = '\x1b[31m';
|
|
17
|
+
const BLUE = '\x1b[34m';
|
|
18
|
+
const NC = '\x1b[0m';
|
|
19
|
+
|
|
20
|
+
function log(message) {
|
|
21
|
+
console.log(message);
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
function logInfo(message) {
|
|
25
|
+
console.log(`${BLUE}${message}${NC}`);
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
function logSuccess(message) {
|
|
29
|
+
console.log(`${GREEN}${message}${NC}`);
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
function logWarning(message) {
|
|
33
|
+
console.log(`${YELLOW}${message}${NC}`);
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
function logError(message) {
|
|
37
|
+
console.log(`${RED}${message}${NC}`);
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
// Platform list to download (extensive coverage)
|
|
41
|
+
// Node ABI versions: 127=Node 22, 120=Node 21, 115=Node 20, 108=Node 18, 93=Node 16
|
|
42
|
+
const TARGET_PLATFORMS = [
|
|
43
|
+
// ==================== Linux ====================
|
|
44
|
+
// Linux x64 (most common)
|
|
45
|
+
{ platform: 'linux', arch: 'x64', nodeAbi: '127' }, // Node 22
|
|
46
|
+
{ platform: 'linux', arch: 'x64', nodeAbi: '120' }, // Node 21
|
|
47
|
+
{ platform: 'linux', arch: 'x64', nodeAbi: '115' }, // Node 20
|
|
48
|
+
{ platform: 'linux', arch: 'x64', nodeAbi: '108' }, // Node 18
|
|
49
|
+
// Linux arm64 (ARM servers/Raspberry Pi)
|
|
50
|
+
{ platform: 'linux', arch: 'arm64', nodeAbi: '127' },
|
|
51
|
+
{ platform: 'linux', arch: 'arm64', nodeAbi: '120' },
|
|
52
|
+
{ platform: 'linux', arch: 'arm64', nodeAbi: '115' },
|
|
53
|
+
// Linux arm (32-bit ARM)
|
|
54
|
+
{ platform: 'linux', arch: 'arm', nodeAbi: '127' },
|
|
55
|
+
{ platform: 'linux', arch: 'arm', nodeAbi: '115' },
|
|
56
|
+
|
|
57
|
+
// ==================== macOS ====================
|
|
58
|
+
// macOS x64 (Intel Mac)
|
|
59
|
+
{ platform: 'darwin', arch: 'x64', nodeAbi: '127' },
|
|
60
|
+
{ platform: 'darwin', arch: 'x64', nodeAbi: '120' },
|
|
61
|
+
{ platform: 'darwin', arch: 'x64', nodeAbi: '115' },
|
|
62
|
+
{ platform: 'darwin', arch: 'x64', nodeAbi: '108' },
|
|
63
|
+
// macOS arm64 (Apple Silicon M1/M2/M3)
|
|
64
|
+
{ platform: 'darwin', arch: 'arm64', nodeAbi: '127' },
|
|
65
|
+
{ platform: 'darwin', arch: 'arm64', nodeAbi: '120' },
|
|
66
|
+
{ platform: 'darwin', arch: 'arm64', nodeAbi: '115' },
|
|
67
|
+
{ platform: 'darwin', arch: 'arm64', nodeAbi: '108' },
|
|
68
|
+
|
|
69
|
+
// ==================== Windows ====================
|
|
70
|
+
// Windows x64 (most common)
|
|
71
|
+
{ platform: 'win32', arch: 'x64', nodeAbi: '127' },
|
|
72
|
+
{ platform: 'win32', arch: 'x64', nodeAbi: '120' },
|
|
73
|
+
{ platform: 'win32', arch: 'x64', nodeAbi: '115' },
|
|
74
|
+
{ platform: 'win32', arch: 'x64', nodeAbi: '108' },
|
|
75
|
+
// Windows ia32 (32-bit Windows)
|
|
76
|
+
{ platform: 'win32', arch: 'ia32', nodeAbi: '127' },
|
|
77
|
+
{ platform: 'win32', arch: 'ia32', nodeAbi: '115' },
|
|
78
|
+
// Windows arm64 (Windows on ARM)
|
|
79
|
+
{ platform: 'win32', arch: 'arm64', nodeAbi: '127' },
|
|
80
|
+
{ platform: 'win32', arch: 'arm64', nodeAbi: '115' },
|
|
81
|
+
|
|
82
|
+
// ==================== FreeBSD ====================
|
|
83
|
+
{ platform: 'freebsd', arch: 'x64', nodeAbi: '127' },
|
|
84
|
+
{ platform: 'freebsd', arch: 'x64', nodeAbi: '115' },
|
|
85
|
+
];
|
|
86
|
+
|
|
87
|
+
function getBetterSqlite3Version() {
|
|
88
|
+
const packageJsonPath = path.join(process.cwd(), 'node_modules', 'better-sqlite3', 'package.json');
|
|
89
|
+
if (!fs.existsSync(packageJsonPath)) {
|
|
90
|
+
throw new Error('better-sqlite3 not installed, please run npm install first');
|
|
91
|
+
}
|
|
92
|
+
const packageJson = JSON.parse(fs.readFileSync(packageJsonPath, 'utf8'));
|
|
93
|
+
return packageJson.version;
|
|
94
|
+
}
|
|
95
|
+
|
|
96
|
+
function downloadPrebuilt(version, platformInfo, prebuildsDir) {
|
|
97
|
+
const fullKey = `node-v${platformInfo.nodeAbi}-${platformInfo.platform}-${platformInfo.arch}`;
|
|
98
|
+
const downloadUrl = `https://github.com/WiseLibs/better-sqlite3/releases/download/v${version}/better-sqlite3-v${version}-${fullKey}.tar.gz`;
|
|
99
|
+
|
|
100
|
+
const tempFile = path.join(prebuildsDir, `.temp-${fullKey}.tar.gz`);
|
|
101
|
+
|
|
102
|
+
try {
|
|
103
|
+
// Download
|
|
104
|
+
if (process.platform === 'win32') {
|
|
105
|
+
execSync(`powershell -Command "Invoke-WebRequest -Uri '${downloadUrl}' -OutFile '${tempFile}'"`, {
|
|
106
|
+
stdio: 'pipe'
|
|
107
|
+
});
|
|
108
|
+
} else {
|
|
109
|
+
execSync(`curl -L -o "${tempFile}" "${downloadUrl}"`, {
|
|
110
|
+
stdio: 'pipe'
|
|
111
|
+
});
|
|
112
|
+
}
|
|
113
|
+
|
|
114
|
+
// Extract
|
|
115
|
+
const extractDir = path.join(prebuildsDir, `.temp-${fullKey}`);
|
|
116
|
+
fs.mkdirSync(extractDir, { recursive: true });
|
|
117
|
+
execSync(`tar -xzf "${tempFile}" -C "${extractDir}"`, {
|
|
118
|
+
stdio: 'pipe'
|
|
119
|
+
});
|
|
120
|
+
|
|
121
|
+
// Find extracted .node file
|
|
122
|
+
const files = fs.readdirSync(extractDir);
|
|
123
|
+
const nodeFile = files.find(f => f.endsWith('.node'));
|
|
124
|
+
|
|
125
|
+
if (!nodeFile) {
|
|
126
|
+
throw new Error('.node file not found');
|
|
127
|
+
}
|
|
128
|
+
|
|
129
|
+
// Rename to standard format
|
|
130
|
+
const sourcePath = path.join(extractDir, nodeFile);
|
|
131
|
+
const targetName = `better-sqlite3-v${version}-${fullKey}.node`;
|
|
132
|
+
const targetPath = path.join(prebuildsDir, targetName);
|
|
133
|
+
|
|
134
|
+
fs.copyFileSync(sourcePath, targetPath);
|
|
135
|
+
|
|
136
|
+
// Cleanup temp files
|
|
137
|
+
fs.rmSync(extractDir, { recursive: true, force: true });
|
|
138
|
+
fs.unlinkSync(tempFile);
|
|
139
|
+
|
|
140
|
+
return targetName;
|
|
141
|
+
} catch (error) {
|
|
142
|
+
// Cleanup temp files
|
|
143
|
+
if (fs.existsSync(tempFile)) {
|
|
144
|
+
fs.unlinkSync(tempFile);
|
|
145
|
+
}
|
|
146
|
+
const tempDir = path.join(prebuildsDir, `.temp-${fullKey}`);
|
|
147
|
+
if (fs.existsSync(tempDir)) {
|
|
148
|
+
fs.rmSync(tempDir, { recursive: true, force: true });
|
|
149
|
+
}
|
|
150
|
+
throw error;
|
|
151
|
+
}
|
|
152
|
+
}
|
|
153
|
+
|
|
154
|
+
function main() {
|
|
155
|
+
log(`${BLUE}=== Download better-sqlite3 Prebuilt Binaries ===${NC}`);
|
|
156
|
+
|
|
157
|
+
// Check if better-sqlite3 is installed
|
|
158
|
+
const betterSqlite3Path = path.join(process.cwd(), 'node_modules', 'better-sqlite3');
|
|
159
|
+
if (!fs.existsSync(betterSqlite3Path)) {
|
|
160
|
+
logError('better-sqlite3 not installed, please run npm install first');
|
|
161
|
+
process.exit(1);
|
|
162
|
+
}
|
|
163
|
+
|
|
164
|
+
// Get better-sqlite3 version
|
|
165
|
+
let version;
|
|
166
|
+
try {
|
|
167
|
+
version = getBetterSqlite3Version();
|
|
168
|
+
logInfo(`better-sqlite3 version: ${version}`);
|
|
169
|
+
} catch (error) {
|
|
170
|
+
logError(error.message);
|
|
171
|
+
process.exit(1);
|
|
172
|
+
}
|
|
173
|
+
|
|
174
|
+
// Create prebuilds directory
|
|
175
|
+
const prebuildsDir = path.join(process.cwd(), 'prebuilds');
|
|
176
|
+
fs.mkdirSync(prebuildsDir, { recursive: true });
|
|
177
|
+
|
|
178
|
+
logInfo(`Prebuilt binaries will be saved to: ${prebuildsDir}`);
|
|
179
|
+
logInfo(`Target platforms: ${TARGET_PLATFORMS.length}`);
|
|
180
|
+
log('');
|
|
181
|
+
|
|
182
|
+
// Download prebuilt binaries for each platform
|
|
183
|
+
let successCount = 0;
|
|
184
|
+
let failCount = 0;
|
|
185
|
+
|
|
186
|
+
for (const platformInfo of TARGET_PLATFORMS) {
|
|
187
|
+
const fullKey = `node-v${platformInfo.nodeAbi}-${platformInfo.platform}-${platformInfo.arch}`;
|
|
188
|
+
const targetName = `better-sqlite3-v${version}-${fullKey}.node`;
|
|
189
|
+
const targetPath = path.join(prebuildsDir, targetName);
|
|
190
|
+
|
|
191
|
+
// Check if already exists
|
|
192
|
+
if (fs.existsSync(targetPath)) {
|
|
193
|
+
logSuccess(`✓ ${fullKey}: already exists`);
|
|
194
|
+
successCount++;
|
|
195
|
+
continue;
|
|
196
|
+
}
|
|
197
|
+
|
|
198
|
+
process.stdout.write(` Downloading ${fullKey}... `);
|
|
199
|
+
|
|
200
|
+
try {
|
|
201
|
+
downloadPrebuilt(version, platformInfo, prebuildsDir);
|
|
202
|
+
logSuccess('success');
|
|
203
|
+
successCount++;
|
|
204
|
+
} catch (error) {
|
|
205
|
+
logWarning('failed');
|
|
206
|
+
failCount++;
|
|
207
|
+
}
|
|
208
|
+
}
|
|
209
|
+
|
|
210
|
+
log('');
|
|
211
|
+
logSuccess(`========================================`);
|
|
212
|
+
logSuccess(`Download complete: ${successCount} success, ${failCount} failed`);
|
|
213
|
+
logSuccess(`========================================`);
|
|
214
|
+
log('');
|
|
215
|
+
|
|
216
|
+
// List downloaded files
|
|
217
|
+
const files = fs.readdirSync(prebuildsDir).filter(f => f.endsWith('.node'));
|
|
218
|
+
logInfo('Downloaded prebuilt binaries:');
|
|
219
|
+
for (const file of files.sort()) {
|
|
220
|
+
const stats = fs.statSync(path.join(prebuildsDir, file));
|
|
221
|
+
const size = (stats.size / 1024 / 1024).toFixed(2);
|
|
222
|
+
log(` - ${file} (${size} MB)`);
|
|
223
|
+
}
|
|
224
|
+
|
|
225
|
+
log('');
|
|
226
|
+
logInfo('Tip: These prebuilt binaries will be included in the npm package');
|
|
227
|
+
logInfo(' Users can install without network or compilation tools');
|
|
228
|
+
}
|
|
229
|
+
|
|
230
|
+
if (require.main === module) {
|
|
231
|
+
main();
|
|
232
|
+
}
|
|
233
|
+
|
|
234
|
+
module.exports = { main };
|
|
@@ -0,0 +1,377 @@
|
|
|
1
|
+
#!/usr/bin/env node
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* better-sqlite3 prebuilt binary installation script
|
|
5
|
+
*
|
|
6
|
+
* Hybrid approach (Option B priority, Option A fallback):
|
|
7
|
+
* 1. First check for local prebuilt binaries (Option B) - priority, no network required
|
|
8
|
+
* 2. If no matching local version, try downloading from GitHub (Option A)
|
|
9
|
+
* 3. If download fails, prompt user for manual installation
|
|
10
|
+
*
|
|
11
|
+
* This script runs in the following scenarios:
|
|
12
|
+
* - During development when running npm install
|
|
13
|
+
* - When users install the wowok package
|
|
14
|
+
* - When other packages depend on wowok
|
|
15
|
+
*/
|
|
16
|
+
|
|
17
|
+
const { execSync } = require("child_process");
|
|
18
|
+
const fs = require("fs");
|
|
19
|
+
const path = require("path");
|
|
20
|
+
|
|
21
|
+
const GREEN = "\x1b[32m";
|
|
22
|
+
const YELLOW = "\x1b[33m";
|
|
23
|
+
const RED = "\x1b[31m";
|
|
24
|
+
const BLUE = "\x1b[34m";
|
|
25
|
+
const NC = "\x1b[0m";
|
|
26
|
+
|
|
27
|
+
function log(message) {
|
|
28
|
+
console.log(message);
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
function logInfo(message) {
|
|
32
|
+
console.log(`${BLUE}${message}${NC}`);
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
function logSuccess(message) {
|
|
36
|
+
console.log(`${GREEN}${message}${NC}`);
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
function logWarning(message) {
|
|
40
|
+
console.log(`${YELLOW}${message}${NC}`);
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
function logError(message) {
|
|
44
|
+
console.log(`${RED}${message}${NC}`);
|
|
45
|
+
}
|
|
46
|
+
|
|
47
|
+
// Detect if currently being installed as a dependency
|
|
48
|
+
function getInstallContext() {
|
|
49
|
+
const cwd = process.cwd();
|
|
50
|
+
const isDependency =
|
|
51
|
+
cwd.includes("node_modules") ||
|
|
52
|
+
!fs.existsSync(path.join(cwd, "package.json"));
|
|
53
|
+
return {
|
|
54
|
+
cwd,
|
|
55
|
+
isDependency,
|
|
56
|
+
isDirectInstall: !isDependency,
|
|
57
|
+
};
|
|
58
|
+
}
|
|
59
|
+
|
|
60
|
+
function getPlatformInfo() {
|
|
61
|
+
const platform = process.platform;
|
|
62
|
+
const arch = process.arch;
|
|
63
|
+
const nodeAbi = process.versions.modules;
|
|
64
|
+
|
|
65
|
+
const platformMap = {
|
|
66
|
+
linux: "linux",
|
|
67
|
+
darwin: "darwin",
|
|
68
|
+
win32: "win32",
|
|
69
|
+
freebsd: "freebsd",
|
|
70
|
+
};
|
|
71
|
+
|
|
72
|
+
return {
|
|
73
|
+
platform: platformMap[platform] || platform,
|
|
74
|
+
arch,
|
|
75
|
+
nodeAbi,
|
|
76
|
+
platformKey: `${platform}-${arch}`,
|
|
77
|
+
fullKey: `node-v${nodeAbi}-${platformMap[platform] || platform}-${arch}`,
|
|
78
|
+
};
|
|
79
|
+
}
|
|
80
|
+
|
|
81
|
+
function findLocalPrebuilt(platformInfo, packageRoot) {
|
|
82
|
+
const prebuildsDir = path.join(packageRoot, "prebuilds");
|
|
83
|
+
|
|
84
|
+
if (fs.existsSync(prebuildsDir)) {
|
|
85
|
+
const files = fs.readdirSync(prebuildsDir);
|
|
86
|
+
|
|
87
|
+
const exactPattern = new RegExp(
|
|
88
|
+
`better-sqlite3-v[\\d.]+-${platformInfo.fullKey}\\.node$`,
|
|
89
|
+
);
|
|
90
|
+
for (const file of files) {
|
|
91
|
+
if (exactPattern.test(file)) {
|
|
92
|
+
return {
|
|
93
|
+
path: path.join(prebuildsDir, file),
|
|
94
|
+
exactMatch: true,
|
|
95
|
+
source: "package",
|
|
96
|
+
};
|
|
97
|
+
}
|
|
98
|
+
}
|
|
99
|
+
|
|
100
|
+
const platformArchPattern = new RegExp(
|
|
101
|
+
`better-sqlite3-v[\\d.]+-node-v[\\d]+-${platformInfo.platform}-${platformInfo.arch}\\.node$`,
|
|
102
|
+
);
|
|
103
|
+
for (const file of files) {
|
|
104
|
+
if (platformArchPattern.test(file)) {
|
|
105
|
+
logWarning(
|
|
106
|
+
`Found similar version: ${file} (Node ABI may not match)`,
|
|
107
|
+
);
|
|
108
|
+
return {
|
|
109
|
+
path: path.join(prebuildsDir, file),
|
|
110
|
+
exactMatch: false,
|
|
111
|
+
source: "package",
|
|
112
|
+
};
|
|
113
|
+
}
|
|
114
|
+
}
|
|
115
|
+
}
|
|
116
|
+
|
|
117
|
+
return null;
|
|
118
|
+
}
|
|
119
|
+
|
|
120
|
+
function copyPrebuiltToBetterSqlite3(
|
|
121
|
+
sourcePath,
|
|
122
|
+
betterSqlite3Path,
|
|
123
|
+
platformInfo,
|
|
124
|
+
) {
|
|
125
|
+
const targetDir = path.join(betterSqlite3Path, "build", "Release");
|
|
126
|
+
const targetPath = path.join(targetDir, "better_sqlite3.node");
|
|
127
|
+
|
|
128
|
+
fs.mkdirSync(targetDir, { recursive: true });
|
|
129
|
+
fs.copyFileSync(sourcePath, targetPath);
|
|
130
|
+
|
|
131
|
+
const bindingDir = path.join(
|
|
132
|
+
betterSqlite3Path,
|
|
133
|
+
"lib",
|
|
134
|
+
"binding",
|
|
135
|
+
platformInfo.fullKey,
|
|
136
|
+
);
|
|
137
|
+
fs.mkdirSync(bindingDir, { recursive: true });
|
|
138
|
+
fs.copyFileSync(sourcePath, path.join(bindingDir, "better_sqlite3.node"));
|
|
139
|
+
|
|
140
|
+
return targetPath;
|
|
141
|
+
}
|
|
142
|
+
|
|
143
|
+
function downloadPrebuilt(platformInfo, betterSqlite3Path) {
|
|
144
|
+
const packageJsonPath = path.join(betterSqlite3Path, "package.json");
|
|
145
|
+
const packageJson = JSON.parse(fs.readFileSync(packageJsonPath, "utf8"));
|
|
146
|
+
const version = packageJson.version;
|
|
147
|
+
|
|
148
|
+
const downloadUrl = `https://github.com/WiseLibs/better-sqlite3/releases/download/v${version}/better-sqlite3-v${version}-${platformInfo.fullKey}.tar.gz`;
|
|
149
|
+
|
|
150
|
+
const tempDir = path.join(betterSqlite3Path, ".download-temp");
|
|
151
|
+
fs.mkdirSync(tempDir, { recursive: true });
|
|
152
|
+
const tempFile = path.join(tempDir, "prebuilt.tar.gz");
|
|
153
|
+
|
|
154
|
+
try {
|
|
155
|
+
if (process.platform === "win32") {
|
|
156
|
+
execSync(
|
|
157
|
+
`powershell -Command "Invoke-WebRequest -Uri '${downloadUrl}' -OutFile '${tempFile}'"`,
|
|
158
|
+
{
|
|
159
|
+
stdio: "pipe",
|
|
160
|
+
},
|
|
161
|
+
);
|
|
162
|
+
} else {
|
|
163
|
+
execSync(`curl -L -o "${tempFile}" "${downloadUrl}"`, {
|
|
164
|
+
stdio: "pipe",
|
|
165
|
+
});
|
|
166
|
+
}
|
|
167
|
+
|
|
168
|
+
const extractDir = path.join(tempDir, "extracted");
|
|
169
|
+
fs.mkdirSync(extractDir, { recursive: true });
|
|
170
|
+
execSync(`tar -xzf "${tempFile}" -C "${extractDir}"`, {
|
|
171
|
+
stdio: "pipe",
|
|
172
|
+
});
|
|
173
|
+
|
|
174
|
+
const files = fs.readdirSync(extractDir);
|
|
175
|
+
const nodeFile = files.find((f) => f.endsWith(".node"));
|
|
176
|
+
|
|
177
|
+
if (!nodeFile) {
|
|
178
|
+
throw new Error(".node file not found");
|
|
179
|
+
}
|
|
180
|
+
|
|
181
|
+
const sourcePath = path.join(extractDir, nodeFile);
|
|
182
|
+
const targetPath = copyPrebuiltToBetterSqlite3(
|
|
183
|
+
sourcePath,
|
|
184
|
+
betterSqlite3Path,
|
|
185
|
+
platformInfo,
|
|
186
|
+
);
|
|
187
|
+
|
|
188
|
+
fs.rmSync(tempDir, { recursive: true, force: true });
|
|
189
|
+
|
|
190
|
+
return targetPath;
|
|
191
|
+
} catch (error) {
|
|
192
|
+
if (fs.existsSync(tempDir)) {
|
|
193
|
+
fs.rmSync(tempDir, { recursive: true, force: true });
|
|
194
|
+
}
|
|
195
|
+
throw error;
|
|
196
|
+
}
|
|
197
|
+
}
|
|
198
|
+
|
|
199
|
+
function tryPrebuildInstall(betterSqlite3Path) {
|
|
200
|
+
try {
|
|
201
|
+
execSync("npx prebuild-install --verbose", {
|
|
202
|
+
cwd: betterSqlite3Path,
|
|
203
|
+
stdio: "pipe",
|
|
204
|
+
});
|
|
205
|
+
return fs.existsSync(
|
|
206
|
+
path.join(
|
|
207
|
+
betterSqlite3Path,
|
|
208
|
+
"build",
|
|
209
|
+
"Release",
|
|
210
|
+
"better_sqlite3.node",
|
|
211
|
+
),
|
|
212
|
+
);
|
|
213
|
+
} catch (error) {
|
|
214
|
+
return false;
|
|
215
|
+
}
|
|
216
|
+
}
|
|
217
|
+
|
|
218
|
+
function main() {
|
|
219
|
+
const context = getInstallContext();
|
|
220
|
+
const platformInfo = getPlatformInfo();
|
|
221
|
+
|
|
222
|
+
const packageRoot = __dirname.includes("node_modules")
|
|
223
|
+
? path.resolve(__dirname, "..")
|
|
224
|
+
: process.cwd();
|
|
225
|
+
|
|
226
|
+
const isSilent = context.isDependency;
|
|
227
|
+
|
|
228
|
+
if (!isSilent) {
|
|
229
|
+
log(`${BLUE}=== better-sqlite3 Prebuilt Binary Installation ===${NC}`);
|
|
230
|
+
logInfo(`Platform: ${platformInfo.platform}-${platformInfo.arch}`);
|
|
231
|
+
logInfo(`Node.js ABI: node-v${platformInfo.nodeAbi}`);
|
|
232
|
+
}
|
|
233
|
+
|
|
234
|
+
const possiblePaths = [
|
|
235
|
+
path.join(packageRoot, "node_modules", "better-sqlite3"),
|
|
236
|
+
path.join(process.cwd(), "node_modules", "better-sqlite3"),
|
|
237
|
+
path.join(packageRoot, "..", "better-sqlite3"),
|
|
238
|
+
];
|
|
239
|
+
|
|
240
|
+
let betterSqlite3Path = null;
|
|
241
|
+
for (const p of possiblePaths) {
|
|
242
|
+
if (fs.existsSync(p)) {
|
|
243
|
+
betterSqlite3Path = p;
|
|
244
|
+
break;
|
|
245
|
+
}
|
|
246
|
+
}
|
|
247
|
+
|
|
248
|
+
if (!betterSqlite3Path) {
|
|
249
|
+
if (!isSilent) {
|
|
250
|
+
logWarning(
|
|
251
|
+
"better-sqlite3 not installed, skipping prebuilt binary installation",
|
|
252
|
+
);
|
|
253
|
+
logInfo(
|
|
254
|
+
"Tip: To use SQLite features, run: npm install better-sqlite3",
|
|
255
|
+
);
|
|
256
|
+
}
|
|
257
|
+
return;
|
|
258
|
+
}
|
|
259
|
+
|
|
260
|
+
const prebuiltPath = path.join(
|
|
261
|
+
betterSqlite3Path,
|
|
262
|
+
"build",
|
|
263
|
+
"Release",
|
|
264
|
+
"better_sqlite3.node",
|
|
265
|
+
);
|
|
266
|
+
if (fs.existsSync(prebuiltPath)) {
|
|
267
|
+
if (!isSilent) {
|
|
268
|
+
logSuccess("better-sqlite3 prebuilt binary already exists");
|
|
269
|
+
}
|
|
270
|
+
return;
|
|
271
|
+
}
|
|
272
|
+
|
|
273
|
+
if (!isSilent) {
|
|
274
|
+
logInfo("");
|
|
275
|
+
logInfo("Step 1: Looking for local prebuilt binaries...");
|
|
276
|
+
}
|
|
277
|
+
|
|
278
|
+
const localPrebuilt = findLocalPrebuilt(platformInfo, packageRoot);
|
|
279
|
+
|
|
280
|
+
if (localPrebuilt) {
|
|
281
|
+
try {
|
|
282
|
+
copyPrebuiltToBetterSqlite3(
|
|
283
|
+
localPrebuilt.path,
|
|
284
|
+
betterSqlite3Path,
|
|
285
|
+
platformInfo,
|
|
286
|
+
);
|
|
287
|
+
if (!isSilent) {
|
|
288
|
+
if (localPrebuilt.exactMatch) {
|
|
289
|
+
logSuccess(
|
|
290
|
+
"Installed successfully using local prebuilt binary!",
|
|
291
|
+
);
|
|
292
|
+
} else {
|
|
293
|
+
logWarning(
|
|
294
|
+
"Installed using similar version, but Node ABI may not match",
|
|
295
|
+
);
|
|
296
|
+
logInfo(
|
|
297
|
+
" If issues occur, consider downloading matching version from GitHub",
|
|
298
|
+
);
|
|
299
|
+
}
|
|
300
|
+
}
|
|
301
|
+
return;
|
|
302
|
+
} catch (error) {
|
|
303
|
+
if (!isSilent) {
|
|
304
|
+
logError(`Failed to use local version: ${error.message}`);
|
|
305
|
+
}
|
|
306
|
+
}
|
|
307
|
+
} else if (!isSilent) {
|
|
308
|
+
logInfo("No local prebuilt binaries found");
|
|
309
|
+
}
|
|
310
|
+
|
|
311
|
+
if (!isSilent) {
|
|
312
|
+
logInfo("");
|
|
313
|
+
logInfo("Step 2: Trying to download prebuilt binary from GitHub...");
|
|
314
|
+
}
|
|
315
|
+
|
|
316
|
+
if (tryPrebuildInstall(betterSqlite3Path)) {
|
|
317
|
+
if (!isSilent) {
|
|
318
|
+
logSuccess("Downloaded successfully via prebuild-install!");
|
|
319
|
+
}
|
|
320
|
+
return;
|
|
321
|
+
}
|
|
322
|
+
|
|
323
|
+
try {
|
|
324
|
+
downloadPrebuilt(platformInfo, betterSqlite3Path);
|
|
325
|
+
if (!isSilent) {
|
|
326
|
+
logSuccess("Downloaded and installed successfully from GitHub!");
|
|
327
|
+
}
|
|
328
|
+
return;
|
|
329
|
+
} catch (error) {
|
|
330
|
+
if (!isSilent) {
|
|
331
|
+
logError(`Download failed: ${error.message}`);
|
|
332
|
+
}
|
|
333
|
+
}
|
|
334
|
+
|
|
335
|
+
if (!isSilent) {
|
|
336
|
+
logInfo("");
|
|
337
|
+
logWarning("========================================");
|
|
338
|
+
logWarning("better-sqlite3 prebuilt binary installation failed");
|
|
339
|
+
logWarning("========================================");
|
|
340
|
+
logInfo("");
|
|
341
|
+
logInfo("You can try the following solutions:");
|
|
342
|
+
logInfo("");
|
|
343
|
+
logInfo("1. Manually download prebuilt binary:");
|
|
344
|
+
logInfo(
|
|
345
|
+
` Visit: https://github.com/WiseLibs/better-sqlite3/releases`,
|
|
346
|
+
);
|
|
347
|
+
logInfo(
|
|
348
|
+
` Download: better-sqlite3-v{version}-${platformInfo.fullKey}.tar.gz`,
|
|
349
|
+
);
|
|
350
|
+
logInfo(` Extract to: ${betterSqlite3Path}/build/Release/`);
|
|
351
|
+
logInfo("");
|
|
352
|
+
logInfo("2. Build from source (requires Python and C++ toolchain):");
|
|
353
|
+
logInfo(" npm install better-sqlite3 --build-from-source");
|
|
354
|
+
logInfo("");
|
|
355
|
+
logInfo("3. Use a compatible Node.js version:");
|
|
356
|
+
logInfo(
|
|
357
|
+
" Check: https://github.com/WiseLibs/better-sqlite3/releases",
|
|
358
|
+
);
|
|
359
|
+
logInfo(" Find matching prebuilt binaries");
|
|
360
|
+
logInfo("");
|
|
361
|
+
logWarning("Note: better-sqlite3 will attempt to compile on first use");
|
|
362
|
+
logWarning(" Runtime errors may occur if build tools are missing");
|
|
363
|
+
} else {
|
|
364
|
+
logWarning(
|
|
365
|
+
`[wowok] better-sqlite3 prebuilt binary installation failed (${platformInfo.fullKey})`,
|
|
366
|
+
);
|
|
367
|
+
logWarning(
|
|
368
|
+
"[wowok] For SQLite features, manually install prebuilt binary or build toolchain",
|
|
369
|
+
);
|
|
370
|
+
}
|
|
371
|
+
}
|
|
372
|
+
|
|
373
|
+
if (require.main === module) {
|
|
374
|
+
main();
|
|
375
|
+
}
|
|
376
|
+
|
|
377
|
+
module.exports = { main };
|