Ensure dest directory exists, cleanup and format
This commit is contained in:
+5
-9
@@ -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<ReadStream> {
|
||||
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);
|
||||
|
||||
@@ -336,7 +336,7 @@ export class SnapshotZipFS extends BasePortableFakeFS {
|
||||
let fallbackPaths: Array<string | Dirent<PortablePath>> = [];
|
||||
try {
|
||||
fallbackPaths = fallback();
|
||||
} catch (e) {}
|
||||
} catch (e) { }
|
||||
return fallbackPaths.concat(
|
||||
uniqReaddir(zipFs.readdirSync(subPath, opts as any))
|
||||
);
|
||||
|
||||
+3
-3
@@ -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 = () => { };
|
||||
};
|
||||
}
|
||||
|
||||
|
||||
+2
-2
@@ -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;
|
||||
|
||||
+1
-2
@@ -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";
|
||||
|
||||
@@ -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",
|
||||
|
||||
+3
-3
@@ -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()
|
||||
);
|
||||
}
|
||||
|
||||
@@ -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<Value> StartMainThreadExecution(Environment* env) {",
|
||||
"MaybeLocal<Value> StartMainThreadExecution(Environment* env) {\n" +
|
||||
' return StartExecution(env, "internal/main/run_main_module");\n'
|
||||
' return StartExecution(env, "internal/main/run_main_module");\n'
|
||||
);
|
||||
}
|
||||
} else {
|
||||
|
||||
+1
-1
@@ -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<string> {
|
||||
|
||||
+5
-6
@@ -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();
|
||||
|
||||
+11
-7
@@ -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<void> {
|
||||
// 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(
|
||||
|
||||
+4
-4
@@ -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);
|
||||
|
||||
|
||||
Vendored
-23
@@ -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<Buffer> & Duplex;
|
||||
export = download;
|
||||
}
|
||||
+1
-1
@@ -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,
|
||||
|
||||
Reference in New Issue
Block a user