u
This commit is contained in:
@@ -18,7 +18,55 @@ if (!fs.existsSync(distDir)) {
|
||||
fs.mkdirSync(distDir, { recursive: true });
|
||||
}
|
||||
|
||||
console.log('Packaging application, siblings, and dependencies into SEA payload...');
|
||||
console.log('Packaging application, siblings, and JavaScript dependencies into SEA payload (excluding native binaries)...');
|
||||
|
||||
const nativeNodes = {};
|
||||
|
||||
function findNearestPackageJson(startDir) {
|
||||
let dir = startDir;
|
||||
while (dir && dir !== path.dirname(dir)) {
|
||||
const pkgFile = path.join(dir, 'package.json');
|
||||
if (fs.existsSync(pkgFile)) {
|
||||
try {
|
||||
return JSON.parse(fs.readFileSync(pkgFile, 'utf8'));
|
||||
} catch {}
|
||||
}
|
||||
dir = path.dirname(dir);
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
function getVersionedNodeFilename(fullPath) {
|
||||
const base = path.basename(fullPath, '.node');
|
||||
const pkg = findNearestPackageJson(path.dirname(fullPath));
|
||||
if (!pkg || !pkg.name || !pkg.version) {
|
||||
return `${base}.node`;
|
||||
}
|
||||
const shortName = pkg.name.replace(/^@[^/]+\//, '');
|
||||
if (base.includes(pkg.version)) {
|
||||
return `${base}.node`;
|
||||
}
|
||||
if (base === shortName) {
|
||||
return `${shortName}-${process.platform}-${process.arch}-${pkg.version}.node`;
|
||||
}
|
||||
return `${shortName}-${base}-${pkg.version}.node`;
|
||||
}
|
||||
|
||||
function isNativeBinary(name) {
|
||||
return (
|
||||
name.endsWith('.node') ||
|
||||
name.endsWith('.so') ||
|
||||
name.includes('.so.') ||
|
||||
name.endsWith('.dylib') ||
|
||||
name.endsWith('.dll') ||
|
||||
name.endsWith('.a') ||
|
||||
name.endsWith('.o') ||
|
||||
name.endsWith('.cc') ||
|
||||
name.endsWith('.cpp') ||
|
||||
name.endsWith('.c') ||
|
||||
name.endsWith('.h')
|
||||
);
|
||||
}
|
||||
|
||||
function packDirectory(dir, prefix, result) {
|
||||
if (!fs.existsSync(dir)) return;
|
||||
@@ -30,7 +78,11 @@ function packDirectory(dir, prefix, result) {
|
||||
if (entry.name === 'test' || entry.name === 'tests' || entry.name === 'docs' || entry.name === '.github' || entry.name === '.git' || entry.name === 'obj.target') continue;
|
||||
packDirectory(full, rel, result);
|
||||
} else if (entry.isFile()) {
|
||||
if (entry.name.endsWith('.a') || entry.name.endsWith('.o') || entry.name.endsWith('.cc') || entry.name.endsWith('.cpp') || entry.name.endsWith('.c') || entry.name.endsWith('.h')) continue;
|
||||
if (entry.name.endsWith('.node')) {
|
||||
nativeNodes[rel] = getVersionedNodeFilename(full);
|
||||
continue;
|
||||
}
|
||||
if (isNativeBinary(entry.name)) continue;
|
||||
result[rel] = fs.readFileSync(full).toString('base64');
|
||||
}
|
||||
}
|
||||
@@ -82,6 +134,8 @@ function packNodeModules(nmPath) {
|
||||
packNodeModules(path.join(rootDir, 'node_modules'));
|
||||
packNodeModules(path.join(dbschemaDir, 'node_modules'));
|
||||
|
||||
payload['.native-nodes.json'] = Buffer.from(JSON.stringify(nativeNodes)).toString('base64');
|
||||
|
||||
const compressedPayload = zlib.deflateSync(Buffer.from(JSON.stringify(payload)));
|
||||
fs.writeFileSync(payloadPath, compressedPayload);
|
||||
|
||||
|
||||
Reference in New Issue
Block a user