quilltap 3.1.0-dev.26 → 3.1.0-dev.29
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/bin/quilltap.js +57 -1
- package/package.json +1 -1
package/bin/quilltap.js
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
#!/usr/bin/env node
|
|
2
2
|
'use strict';
|
|
3
3
|
|
|
4
|
-
const { fork, exec } = require('child_process');
|
|
4
|
+
const { fork, exec, execSync } = require('child_process');
|
|
5
5
|
const path = require('path');
|
|
6
6
|
const fs = require('fs');
|
|
7
7
|
const { getCacheDir, isCacheValid, ensureStandalone } = require('../lib/download-manager');
|
|
@@ -114,6 +114,59 @@ function openBrowser(url) {
|
|
|
114
114
|
});
|
|
115
115
|
}
|
|
116
116
|
|
|
117
|
+
// Check if native modules are compiled for the current Node.js version.
|
|
118
|
+
// This handles the case where npx caches the package but the user upgrades
|
|
119
|
+
// Node.js — the cached native modules will have a stale NODE_MODULE_VERSION.
|
|
120
|
+
function ensureNativeModules() {
|
|
121
|
+
const needsRebuild = [];
|
|
122
|
+
|
|
123
|
+
// Check better-sqlite3: it lazy-loads the native .node binary only when you
|
|
124
|
+
// create a Database, so a bare require('better-sqlite3') always succeeds.
|
|
125
|
+
// We must load the native binding directly to detect NODE_MODULE_VERSION mismatches.
|
|
126
|
+
try {
|
|
127
|
+
const bindingsPath = path.join(
|
|
128
|
+
PACKAGE_DIR, 'node_modules', 'better-sqlite3', 'build', 'Release', 'better_sqlite3.node'
|
|
129
|
+
);
|
|
130
|
+
require(bindingsPath);
|
|
131
|
+
} catch (err) {
|
|
132
|
+
if (err.message && err.message.includes('NODE_MODULE_VERSION')) {
|
|
133
|
+
needsRebuild.push('better-sqlite3');
|
|
134
|
+
} else if (err.code === 'MODULE_NOT_FOUND') {
|
|
135
|
+
needsRebuild.push('better-sqlite3');
|
|
136
|
+
}
|
|
137
|
+
}
|
|
138
|
+
|
|
139
|
+
// Check sharp: loads its native binding eagerly on require, but we use
|
|
140
|
+
// the same explicit-path approach for consistency and reliability.
|
|
141
|
+
try {
|
|
142
|
+
require('sharp');
|
|
143
|
+
} catch (err) {
|
|
144
|
+
if (err.message && err.message.includes('NODE_MODULE_VERSION')) {
|
|
145
|
+
needsRebuild.push('sharp');
|
|
146
|
+
} else if (err.code === 'MODULE_NOT_FOUND') {
|
|
147
|
+
needsRebuild.push('sharp');
|
|
148
|
+
}
|
|
149
|
+
}
|
|
150
|
+
|
|
151
|
+
if (needsRebuild.length === 0) return;
|
|
152
|
+
|
|
153
|
+
console.log(` Rebuilding native modules for Node.js ${process.version}...`);
|
|
154
|
+
|
|
155
|
+
try {
|
|
156
|
+
execSync(`npm rebuild ${needsRebuild.join(' ')}`, {
|
|
157
|
+
cwd: PACKAGE_DIR,
|
|
158
|
+
stdio: 'inherit',
|
|
159
|
+
});
|
|
160
|
+
console.log(' Done.');
|
|
161
|
+
console.log('');
|
|
162
|
+
} catch (err) {
|
|
163
|
+
console.error('');
|
|
164
|
+
console.error(` Warning: Failed to rebuild native modules: ${err.message}`);
|
|
165
|
+
console.error(' Try running: npm rebuild --prefix ' + PACKAGE_DIR);
|
|
166
|
+
console.error('');
|
|
167
|
+
}
|
|
168
|
+
}
|
|
169
|
+
|
|
117
170
|
// Main
|
|
118
171
|
async function main() {
|
|
119
172
|
const opts = parseArgs(process.argv);
|
|
@@ -150,6 +203,9 @@ async function main() {
|
|
|
150
203
|
process.exit(1);
|
|
151
204
|
}
|
|
152
205
|
|
|
206
|
+
// Ensure native modules are compiled for the current Node.js version
|
|
207
|
+
ensureNativeModules();
|
|
208
|
+
|
|
153
209
|
// Set up environment
|
|
154
210
|
const env = {
|
|
155
211
|
...process.env,
|