From b2a26fbf169478a6d146c74ca7d35d0975ad95e3 Mon Sep 17 00:00:00 2001 From: oxmc <67136658+oxmc@users.noreply.github.com> Date: Sun, 7 Dec 2025 02:55:00 -0800 Subject: [PATCH] Ensure dest directory exists, cleanup and format --- src/compiler.ts | 14 +++++--------- src/fs/SnapshotZipFS.ts | 2 +- src/fs/patch.ts | 6 +++--- src/logger.ts | 4 ++-- src/nexe.ts | 3 +-- src/patches/build-fixes.ts | 2 -- src/patches/gyp.ts | 6 +++--- src/patches/third-party-main.ts | 10 +++++----- src/steps/bundle.ts | 2 +- src/steps/cli.ts | 11 +++++------ src/steps/download.ts | 18 +++++++++++------- src/target.ts | 8 ++++---- src/types.d.ts | 23 ----------------------- tasks/post-build.ts | 2 +- 14 files changed, 42 insertions(+), 69 deletions(-) delete mode 100644 src/types.d.ts diff --git a/src/compiler.ts b/src/compiler.ts index 34a0635..6115eba 100644 --- a/src/compiler.ts +++ b/src/compiler.ts @@ -11,16 +11,14 @@ import { dequote, isWindows, bound, - semverGt, - wrap, + semverGt } from "./util"; import { NexeOptions, version } from "./options"; import { NexeTarget } from "./target"; -import { PassThrough, Readable, Stream, Transform } from "stream"; +import { Readable, Transform } from "stream"; import MultiStream = require("multistream"); import { Bundle, toStream } from "./fs/bundle"; import { File } from "resolve-dependencies"; -import { FactoryStream, LazyStream } from "multistream"; const isBsd = Boolean(~process.platform.indexOf("bsd")); const make = isWindows ? "vcbuild.bat" : isBsd ? "gmake" : "make"; @@ -132,7 +130,7 @@ export class NexeCompiler { this.env = { ...process.env }; this.env.PATH = python ? (this.env.PATH = - dequote(normalize(python)) + delimiter + originalPath) + dequote(normalize(python)) + delimiter + originalPath) : originalPath; process.env.PATH = originalPath; } else { @@ -255,15 +253,13 @@ export class NexeCompiler { public async build(): Promise { this.compileStep!.log( - `Configuring node build${ - this.options.configure.length ? ": " + this.options.configure : "..." + `Configuring node build${this.options.configure.length ? ": " + this.options.configure : "..." }` ); await this._configureAsync(); const buildOptions = this.options.make; this.compileStep!.log( - `Compiling Node${ - buildOptions.length ? " with arguments: " + buildOptions : "..." + `Compiling Node${buildOptions.length ? " with arguments: " + buildOptions : "..." }` ); await this._runBuildCommandAsync(make, buildOptions); diff --git a/src/fs/SnapshotZipFS.ts b/src/fs/SnapshotZipFS.ts index 51206e9..ea28512 100644 --- a/src/fs/SnapshotZipFS.ts +++ b/src/fs/SnapshotZipFS.ts @@ -336,7 +336,7 @@ export class SnapshotZipFS extends BasePortableFakeFS { let fallbackPaths: Array> = []; try { fallbackPaths = fallback(); - } catch (e) {} + } catch (e) { } return fallbackPaths.concat( uniqReaddir(zipFs.readdirSync(subPath, opts as any)) ); diff --git a/src/fs/patch.ts b/src/fs/patch.ts index 70e699a..662856f 100644 --- a/src/fs/patch.ts +++ b/src/fs/patch.ts @@ -1,5 +1,5 @@ import { ZipFS, getLibzipSync } from "@yarnpkg/libzip"; -import { patchFs, npath, PosixFS, NodeFS } from "@yarnpkg/fslib"; +import { patchFs, PosixFS, NodeFS } from "@yarnpkg/fslib"; import { SnapshotZipFS } from "./SnapshotZipFS"; import * as assert from "assert"; import * as constants from "constants"; @@ -16,7 +16,7 @@ export interface NexeHeader { } let originalFsMethods: any = null; -let lazyRestoreFs = () => {}; +let lazyRestoreFs = () => { }; const patches = (process as any).nexe.patches || {}; const originalPatches = { ...patches }; delete (process as any).nexe; @@ -125,7 +125,7 @@ function shimFs(binary: NexeHeader, fs: typeof import("fs") = require("fs")) { lazyRestoreFs = () => { Object.assign(fs, originalFsMethods); Object.assign(patches, originalPatches); - lazyRestoreFs = () => {}; + lazyRestoreFs = () => { }; }; } diff --git a/src/logger.ts b/src/logger.ts index c8418dd..e26fdbe 100644 --- a/src/logger.ts +++ b/src/logger.ts @@ -28,7 +28,7 @@ export class Logger { }); this.ora.stop(); } - const noop = () => {}; + const noop = () => { }; this.modify = this.silent ? noop : this._modify.bind(this); this.write = this.silent ? noop : this._write.bind(this); } @@ -50,7 +50,7 @@ export class Logger { step(text: string, method = "succeed"): LogStep { if (this.silent) { - return { modify() {}, log() {}, pause() {}, resume() {} }; + return { modify() { }, log() { }, pause() { }, resume() { } }; } if (!this.ora.id) { this.ora.start().text = text; diff --git a/src/nexe.ts b/src/nexe.ts index 9f81d62..8a974ac 100644 --- a/src/nexe.ts +++ b/src/nexe.ts @@ -1,6 +1,5 @@ -import { EOL } from "os"; import { compose } from "app-builder"; -import { NexeCompiler, NexeError } from "./compiler"; +import { NexeCompiler } from "./compiler"; import { normalizeOptions, NexeOptions, NexePatch } from "./options"; import resource from "./steps/resource"; import clean from "./steps/clean"; diff --git a/src/patches/build-fixes.ts b/src/patches/build-fixes.ts index b2a72cc..6b3e820 100644 --- a/src/patches/build-fixes.ts +++ b/src/patches/build-fixes.ts @@ -8,8 +8,6 @@ export default async function buildFixes( return next(); } - const file = await compiler.readFileAsync("./tools/msvs/find_python.cmd"); - await compiler.replaceInFileAsync( "./tools/msvs/find_python.cmd", "%p%python.exe -V 2>&1", diff --git a/src/patches/gyp.ts b/src/patches/gyp.ts index fe39950..1a7a3c7 100644 --- a/src/patches/gyp.ts +++ b/src/patches/gyp.ts @@ -13,9 +13,9 @@ export default async function nodeGyp( ` ${nodeGypMarker} ${files - .filter((x) => x.filename.startsWith("lib")) - .map((x) => `'${x.filename}'`) - .toString()}, + .filter((x) => x.filename.startsWith("lib")) + .map((x) => `'${x.filename}'`) + .toString()}, `.trim() ); } diff --git a/src/patches/third-party-main.ts b/src/patches/third-party-main.ts index 2a44ec5..9788045 100644 --- a/src/patches/third-party-main.ts +++ b/src/patches/third-party-main.ts @@ -69,8 +69,8 @@ export default async function main( location.start.line, 0, '{{ file("lib/fs/bootstrap.js") }}' + - "\n" + - (semverGt(version, "11.99") ? "expandArgv1 = false;\n" : "") + "\n" + + (semverGt(version, "11.99") ? "expandArgv1 = false;\n" : "") ); } file.contents = fileLines.join("\n"); @@ -81,7 +81,7 @@ export default async function main( bootFile, "initializeFrozenIntrinsics();", "initializeFrozenIntrinsics();\n" + - wrap('{{ file("lib/patches/boot-nexe.js") }}') + wrap('{{ file("lib/patches/boot-nexe.js") }}') ); } else { await compiler.replaceInFileAsync( @@ -103,14 +103,14 @@ export default async function main( "src/node.cc", "if (env->worker_context() != nullptr) {", "if (env->worker_context() == nullptr) {\n" + - ' return StartExecution(env, "internal/main/run_main_module"); } else {\n' + ' return StartExecution(env, "internal/main/run_main_module"); } else {\n' ); } else { await compiler.replaceInFileAsync( "src/node.cc", "MaybeLocal StartMainThreadExecution(Environment* env) {", "MaybeLocal StartMainThreadExecution(Environment* env) {\n" + - ' return StartExecution(env, "internal/main/run_main_module");\n' + ' return StartExecution(env, "internal/main/run_main_module");\n' ); } } else { diff --git a/src/steps/bundle.ts b/src/steps/bundle.ts index e1685f5..5b1a1b2 100644 --- a/src/steps/bundle.ts +++ b/src/steps/bundle.ts @@ -1,7 +1,7 @@ import { NexeCompiler, NexeError } from "../compiler"; import { resolve, relative } from "path"; import resolveFiles, { resolveSync } from "resolve-dependencies"; -import { dequote, STDIN_FLAG, semverGt, each } from "../util"; +import { dequote, STDIN_FLAG, semverGt } from "../util"; import { Readable } from "stream"; function getStdIn(stdin: Readable): Promise { diff --git a/src/steps/cli.ts b/src/steps/cli.ts index a731ec3..12d95a5 100644 --- a/src/steps/cli.ts +++ b/src/steps/cli.ts @@ -60,12 +60,11 @@ export default async function cli( chmodSync(output, mode.toString(8).slice(-3)); step.log( - `Entry: '${ - compiler.stdinUsed - ? compiler.options.mangle - ? STDIN_FLAG - : "[none]" - : inputFileLogOutput + `Entry: '${compiler.stdinUsed + ? compiler.options.mangle + ? STDIN_FLAG + : "[none]" + : inputFileLogOutput }' written to: ${outputFileLogOutput}` ); compiler.quit(); diff --git a/src/steps/download.ts b/src/steps/download.ts index 61fc769..0e5bf48 100644 --- a/src/steps/download.ts +++ b/src/steps/download.ts @@ -1,13 +1,12 @@ -import axios, { AxiosResponse } from "axios"; +import axios from "axios"; import { pathExistsAsync } from "../util"; import { LogStep } from "../logger"; -import { IncomingMessage } from "http"; import { NexeCompiler, NexeError } from "../compiler"; import { dirname } from "path"; import { createWriteStream } from "fs"; import { pipeline } from "stream/promises"; -import { createBrotliDecompress, createGunzip, createInflate } from "zlib"; -import tar from "tar"; +import { createGunzip } from "zlib"; +import * as tar from 'tar'; import fs from "fs/promises"; async function downloadWithProgress( @@ -16,6 +15,9 @@ async function downloadWithProgress( options: any = {}, step?: LogStep ): Promise { + // Ensure destination directory exists + await fs.mkdir(dirname(dest), { recursive: true }); + const response = await axios({ url, method: "GET", @@ -51,6 +53,9 @@ async function fetchNodeSourceAsync( step: LogStep, options = {} ) { + // Ensure destination directory exists + await fs.mkdir(dest, { recursive: true }); + const setText = (p: number) => step.modify(`Downloading Node: ${p.toFixed()}%...`); @@ -86,7 +91,7 @@ async function fetchNodeSourceAsync( await pipeline( createReadStream(tempFile), createGunzip(), - tar.extract({ + tar.x({ cwd: dest, strip: 1, }) @@ -136,8 +141,7 @@ export default async function downloadNode( sourceUrl || `https://nodejs.org/dist/v${version}/node-v${version}.tar.gz`, step = log.step( - `Downloading ${build ? "" : "pre-built"} Node.js ${ - build ? `source from: ${url}` : "" + `Downloading ${build ? "" : "pre-built"} Node.js ${build ? `source from: ${url}` : "" }` ), exeLocation = compiler.getNodeExecutableLocation( diff --git a/src/target.ts b/src/target.ts index f55b0d2..bb5d067 100644 --- a/src/target.ts +++ b/src/target.ts @@ -58,7 +58,7 @@ class Target implements NexeTarget { public arch: NodeArch, public platform: NodePlatform, public version: string - ) {} + ) { } toJSON() { return this.toString(); } @@ -78,9 +78,9 @@ export function getTarget( ): NexeTarget { const currentArch = process.arch; let arch = - currentArch in prettyArch - ? prettyArch[process.arch] - : (process.arch as NodeArch), + currentArch in prettyArch + ? prettyArch[process.arch] + : (process.arch as NodeArch), platform = prettyPlatform[process.platform], version = process.version.slice(1); diff --git a/src/types.d.ts b/src/types.d.ts deleted file mode 100644 index f705ee6..0000000 --- a/src/types.d.ts +++ /dev/null @@ -1,23 +0,0 @@ -declare module "got" { - interface GotFn { - (url: string, options?: any): Promise<{ body: string }>; - stream(url: string, optoins?: any): any; - } - const got: GotFn; - export = got; -} -declare module "download" { - import { Duplex } from "stream"; - interface DownloadOptions { - extract?: boolean; - strip?: number; - filename?: string; - proxy?: string; - } - function download( - url: string, - destination?: string | DownloadOptions, - options?: DownloadOptions - ): PromiseLike & Duplex; - export = download; -} diff --git a/tasks/post-build.ts b/tasks/post-build.ts index 9bdc147..20e9e8b 100644 --- a/tasks/post-build.ts +++ b/tasks/post-build.ts @@ -15,7 +15,7 @@ inject("lib/options.js", JSON.stringify(require("../package.json").version)); function inject(filename: string, version?: string) { const contents = template(readFileSync(filename, "utf8"), { - interpolate: /'\{\{([\s\S]*?)\}\}'/, + interpolate: /['"]\{\{([\s\S]*?)\}\}['"]/, })({ file: (path: string) => JSON.stringify(readFileSync(path, "utf8")), version,