mirror of
https://github.com/mountain-loop/yaak.git
synced 2026-04-21 08:11:24 +02:00
Fix NodeJS vendoring
This commit is contained in:
@@ -1,6 +1,20 @@
|
|||||||
const path = require('node:path');
|
const path = require('node:path');
|
||||||
const {cpSync} = require('node:fs');
|
const decompress = require('decompress');
|
||||||
const destDir = path.join(__dirname, '..', 'src-tauri', 'vendored', 'node');
|
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 = {
|
const DST_BIN_MAP = {
|
||||||
darwin_arm64: 'node-aarch64-apple-darwin',
|
darwin_arm64: 'node-aarch64-apple-darwin',
|
||||||
@@ -9,14 +23,37 @@ const DST_BIN_MAP = {
|
|||||||
win32_x64: 'node-x86_64-pc-windows-msvc.exe',
|
win32_x64: 'node-x86_64-pc-windows-msvc.exe',
|
||||||
};
|
};
|
||||||
|
|
||||||
// Build the sea
|
const SRC_BIN_MAP = {
|
||||||
console.log('Vendoring NodeJS binary');
|
[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');
|
const dstDir = path.join(__dirname, `..`, 'src-tauri', 'vendored', 'node');
|
||||||
// chmodSync(tmpNodePath, 0o755);
|
rmSync(dstDir, {recursive: true, force: true});
|
||||||
|
mkdirSync(dstDir);
|
||||||
|
|
||||||
const key = `${process.platform}_${process.env.NODE_ARCH ?? process.arch}`;
|
(async function () {
|
||||||
const dstPath = path.join(destDir, DST_BIN_MAP[key]);
|
const key = `${process.platform}_${process.env.NODE_ARCH ?? process.arch}`;
|
||||||
cpSync(process.execPath, dstPath);
|
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 Downloader = require("nodejs-file-downloader");
|
||||||
const path = require("node:path");
|
const path = require("node:path");
|
||||||
const fs = require("node:fs");
|
const fs = require("node:fs");
|
||||||
const rimraf = require('rimraf');
|
const {rmSync, mkdirSync} = require("node:fs");
|
||||||
const {rmSync} = require("node:fs");
|
|
||||||
|
|
||||||
// `${process.platform}_${process.arch}`
|
// `${process.platform}_${process.arch}`
|
||||||
const MAC_ARM = 'darwin_arm64';
|
const MAC_ARM = 'darwin_arm64';
|
||||||
@@ -26,18 +25,20 @@ const DST_BIN_MAP = {
|
|||||||
};
|
};
|
||||||
|
|
||||||
const SRC_BIN_MAP = {
|
const SRC_BIN_MAP = {
|
||||||
[MAC_ARM]: 'protoc',
|
[MAC_ARM]: 'bin/protoc',
|
||||||
[MAC_X64]: 'protoc',
|
[MAC_X64]: 'bin/protoc',
|
||||||
[LNX_X64]: 'protoc',
|
[LNX_X64]: 'bin/protoc',
|
||||||
[WIN_X64]: 'protoc.exe',
|
[WIN_X64]: 'bin/protoc.exe',
|
||||||
};
|
};
|
||||||
|
|
||||||
|
const dstDir = path.join(__dirname, `..`, 'src-tauri', 'vendored', 'protoc');
|
||||||
|
rmSync(dstDir, {recursive: true, force: true});
|
||||||
|
mkdirSync(dstDir);
|
||||||
|
|
||||||
(async function () {
|
(async function () {
|
||||||
const key = `${process.platform}_${process.env.NODE_ARCH ?? process.arch}`;
|
const key = `${process.platform}_${process.env.NODE_ARCH ?? process.arch}`;
|
||||||
const url = URL_MAP[key];
|
const url = URL_MAP[key];
|
||||||
const tmpDir = path.join(__dirname, 'tmp', `${Math.random()}`);
|
const tmpDir = path.join(__dirname, 'tmp', new Date().toISOString());
|
||||||
const dstDir = path.join(__dirname, `..`, 'src-tauri', 'vendored', 'protoc');
|
|
||||||
rimraf.sync(dstDir);
|
|
||||||
|
|
||||||
// Download GitHub release artifact
|
// Download GitHub release artifact
|
||||||
const {filePath} = await new Downloader({url, directory: tmpDir,}).download();
|
const {filePath} = await new Downloader({url, directory: tmpDir,}).download();
|
||||||
@@ -49,7 +50,7 @@ const SRC_BIN_MAP = {
|
|||||||
fs.unlinkSync(filePath);
|
fs.unlinkSync(filePath);
|
||||||
|
|
||||||
// Copy binary
|
// 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]);
|
const binDst = path.join(dstDir, DST_BIN_MAP[key]);
|
||||||
fs.cpSync(binSrc, binDst);
|
fs.cpSync(binSrc, binDst);
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user