mirror of
https://github.com/mountain-loop/yaak.git
synced 2026-03-19 07:54:23 +01:00
Fix NodeJS vendoring
This commit is contained in:
@@ -1,6 +1,20 @@
|
||||
const path = require('node:path');
|
||||
const {cpSync} = require('node:fs');
|
||||
const destDir = path.join(__dirname, '..', 'src-tauri', 'vendored', 'node');
|
||||
const decompress = require('decompress');
|
||||
const Downloader = require("nodejs-file-downloader");
|
||||
const {rmSync, unlinkSync, cpSync, mkdirSync} = require("node:fs");
|
||||
|
||||
// `${process.platform}_${process.arch}`
|
||||
const MAC_ARM = 'darwin_arm64';
|
||||
const MAC_X64 = 'darwin_x64';
|
||||
const LNX_X64 = 'linux_x64';
|
||||
const WIN_X64 = 'win32_x64';
|
||||
const URL_MAP = {
|
||||
|
||||
[MAC_ARM]: 'https://nodejs.org/download/release/v22.5.1/node-v22.5.1-darwin-arm64.tar.gz',
|
||||
[MAC_X64]: 'https://nodejs.org/download/release/v22.5.1/node-v22.5.1-darwin-x64.tar.gz',
|
||||
[LNX_X64]: 'https://nodejs.org/download/release/v22.5.1/node-v22.5.1-linux-arm64.tar.gz',
|
||||
[WIN_X64]: 'https://nodejs.org/download/release/v22.5.1/node-v22.5.1-win-x64.zip',
|
||||
};
|
||||
|
||||
const DST_BIN_MAP = {
|
||||
darwin_arm64: 'node-aarch64-apple-darwin',
|
||||
@@ -9,14 +23,37 @@ const DST_BIN_MAP = {
|
||||
win32_x64: 'node-x86_64-pc-windows-msvc.exe',
|
||||
};
|
||||
|
||||
// Build the sea
|
||||
console.log('Vendoring NodeJS binary');
|
||||
const SRC_BIN_MAP = {
|
||||
[MAC_ARM]: 'node-v22.5.1-darwin-arm64/bin/node',
|
||||
[MAC_X64]: 'node-v22.5.1-darwin-x64/bin/node',
|
||||
[LNX_X64]: 'node-v22.5.1-linux-arm64/bin/node',
|
||||
[WIN_X64]: 'node-v22.5.1-win-x64/node.exe',
|
||||
};
|
||||
|
||||
// console.log('Changing Node.js binary permissions');
|
||||
// chmodSync(tmpNodePath, 0o755);
|
||||
const dstDir = path.join(__dirname, `..`, 'src-tauri', 'vendored', 'node');
|
||||
rmSync(dstDir, {recursive: true, force: true});
|
||||
mkdirSync(dstDir);
|
||||
|
||||
const key = `${process.platform}_${process.env.NODE_ARCH ?? process.arch}`;
|
||||
const dstPath = path.join(destDir, DST_BIN_MAP[key]);
|
||||
cpSync(process.execPath, dstPath);
|
||||
(async function () {
|
||||
const key = `${process.platform}_${process.env.NODE_ARCH ?? process.arch}`;
|
||||
console.log('Vendoring NodeJS binary for', key);
|
||||
const url = URL_MAP[key];
|
||||
const tmpDir = path.join(__dirname, 'tmp', new Date().toISOString());
|
||||
|
||||
console.log(`Copied NodeJS to ${dstPath}`)
|
||||
// Download GitHub release artifact
|
||||
const {filePath} = await new Downloader({url, directory: tmpDir,}).download();
|
||||
|
||||
// Decompress to the same directory
|
||||
await decompress(filePath, tmpDir, {});
|
||||
|
||||
// Remove the original archive
|
||||
unlinkSync(filePath);
|
||||
|
||||
// Copy binary
|
||||
const binSrc = path.join(tmpDir, SRC_BIN_MAP[key]);
|
||||
const binDst = path.join(dstDir, DST_BIN_MAP[key]);
|
||||
cpSync(binSrc, binDst);
|
||||
rmSync(tmpDir, {recursive: true, force: true});
|
||||
|
||||
console.log("Downloaded NodeJS to", binDst);
|
||||
})().catch(err => console.log('Script failed:', err));
|
||||
|
||||
@@ -2,8 +2,7 @@ const decompress = require('decompress');
|
||||
const Downloader = require("nodejs-file-downloader");
|
||||
const path = require("node:path");
|
||||
const fs = require("node:fs");
|
||||
const rimraf = require('rimraf');
|
||||
const {rmSync} = require("node:fs");
|
||||
const {rmSync, mkdirSync} = require("node:fs");
|
||||
|
||||
// `${process.platform}_${process.arch}`
|
||||
const MAC_ARM = 'darwin_arm64';
|
||||
@@ -26,18 +25,20 @@ const DST_BIN_MAP = {
|
||||
};
|
||||
|
||||
const SRC_BIN_MAP = {
|
||||
[MAC_ARM]: 'protoc',
|
||||
[MAC_X64]: 'protoc',
|
||||
[LNX_X64]: 'protoc',
|
||||
[WIN_X64]: 'protoc.exe',
|
||||
[MAC_ARM]: 'bin/protoc',
|
||||
[MAC_X64]: 'bin/protoc',
|
||||
[LNX_X64]: 'bin/protoc',
|
||||
[WIN_X64]: 'bin/protoc.exe',
|
||||
};
|
||||
|
||||
const dstDir = path.join(__dirname, `..`, 'src-tauri', 'vendored', 'protoc');
|
||||
rmSync(dstDir, {recursive: true, force: true});
|
||||
mkdirSync(dstDir);
|
||||
|
||||
(async function () {
|
||||
const key = `${process.platform}_${process.env.NODE_ARCH ?? process.arch}`;
|
||||
const url = URL_MAP[key];
|
||||
const tmpDir = path.join(__dirname, 'tmp', `${Math.random()}`);
|
||||
const dstDir = path.join(__dirname, `..`, 'src-tauri', 'vendored', 'protoc');
|
||||
rimraf.sync(dstDir);
|
||||
const tmpDir = path.join(__dirname, 'tmp', new Date().toISOString());
|
||||
|
||||
// Download GitHub release artifact
|
||||
const {filePath} = await new Downloader({url, directory: tmpDir,}).download();
|
||||
@@ -49,7 +50,7 @@ const SRC_BIN_MAP = {
|
||||
fs.unlinkSync(filePath);
|
||||
|
||||
// Copy binary
|
||||
const binSrc = path.join(tmpDir, 'bin', SRC_BIN_MAP[key]);
|
||||
const binSrc = path.join(tmpDir, SRC_BIN_MAP[key]);
|
||||
const binDst = path.join(dstDir, DST_BIN_MAP[key]);
|
||||
fs.cpSync(binSrc, binDst);
|
||||
|
||||
|
||||
Reference in New Issue
Block a user