From 0db8122f8fbebfdb7efe6d0fa218fc41e2dfd26c Mon Sep 17 00:00:00 2001 From: calebboyd Date: Sat, 20 Oct 2018 11:23:12 -0500 Subject: [PATCH] fix: handle configure script in node 10.11+ --- package.json | 2 +- src/compiler.ts | 55 +++++++++++++++++++++++++++++++-- src/patches/snapshot.ts | 17 +++++----- src/patches/third-party-main.ts | 12 +------ src/util.ts | 12 +++++++ 5 files changed, 75 insertions(+), 23 deletions(-) diff --git a/package.json b/package.json index 1018ffb..88e26f7 100644 --- a/package.json +++ b/package.json @@ -2,7 +2,7 @@ "name": "nexe", "description": "Create a single executable out of your Node.js application", "license": "MIT", - "version": "3.0.0-beta.3", + "version": "3.0.0-beta.4", "contributors": [ "Craig Condon (http://crcn.io)", "Jared Allard ", diff --git a/src/compiler.ts b/src/compiler.ts index add43c7..a4a1237 100644 --- a/src/compiler.ts +++ b/src/compiler.ts @@ -4,7 +4,15 @@ import { createReadStream } from 'fs' import { Readable, Stream } from 'stream' import { spawn } from 'child_process' import { Logger, LogStep } from './logger' -import { readFileAsync, writeFileAsync, pathExistsAsync, dequote, isWindows, bound } from './util' +import { + readFileAsync, + writeFileAsync, + pathExistsAsync, + dequote, + isWindows, + bound, + semverGt +} from './util' import { NexeOptions, version } from './options' import { NexeTarget } from './target' import download = require('download') @@ -26,20 +34,60 @@ export interface NexeFile { export { NexeOptions } export class NexeCompiler { + /** + * Epoch of when compilation started + */ private start = Date.now() + /** + * Copy of process.env + */ private env = { ...process.env } + /** + * Virtual FileSystem + */ private bundle: Bundle + private compileStep: LogStep | undefined public log = new Logger(this.options.loglevel) + /** + * Root directory for the source of the current build + */ public src: string + /** + * In memory files that are being manipulated by the compiler + */ public files: NexeFile[] = [] + /** + * Standalone pieces of code run before the application entrypoint + */ public shims: string[] = [] + /** + * The last shim (defaults to "require('module').runMain()") + */ public startup: string = '' + /** + * The main entrypoint filename for your application - eg. node mainFile.js + */ public entrypoint: string | undefined - public bundledInput?: string + /** + * Not used + */ public targets: NexeTarget[] + /** + * Current target of the compiler + */ public target: NexeTarget + /** + * Output filename (-o myapp.exe) + */ public output = this.options.output + /** + * Path to the configure script + */ + public configureScript: string + /** + * The file path of node binary + */ private nodeSrcBinPath: string constructor(public options: NexeOptions) { @@ -47,6 +95,7 @@ export class NexeCompiler { this.targets = options.targets as NexeTarget[] this.target = this.targets[0] this.src = join(this.options.temp, this.target.version) + this.configureScript = configure + (semverGt(this.target.version, '10.10.0') ? '.py' : '') this.nodeSrcBinPath = isWindows ? join(this.src, 'Release', 'node.exe') : join(this.src, 'out', 'Release', 'node') @@ -166,7 +215,7 @@ export class NexeCompiler { private _configureAsync() { return this._runBuildCommandAsync(this.env.PYTHON || 'python', [ - configure, + this.configureScript, ...this.options.configure ]) } diff --git a/src/patches/snapshot.ts b/src/patches/snapshot.ts index f3f1c7d..4618b76 100644 --- a/src/patches/snapshot.ts +++ b/src/patches/snapshot.ts @@ -1,19 +1,20 @@ -import * as path from 'path' +import { resolve } from 'path' import { NexeCompiler } from '../compiler' -export default async function snapshot(compiler: NexeCompiler, next: () => Promise) { - const snapshotFile = compiler.options.snapshot - const warmupScript = compiler.options.warmup +export default async function(compiler: NexeCompiler, next: () => Promise) { + const { snapshot, warmup, cwd } = compiler.options - if (!snapshotFile) { + if (!snapshot) { return next() } await compiler.replaceInFileAsync( - 'configure', + compiler.configureScript, 'def configure_v8(o):', - `def configure_v8(o):\n o['variables']['embed_script'] = r'${path.resolve(snapshotFile)}'\n o['variables']['warmup_script'] = r'${path.resolve(warmupScript || - snapshotFile)}'` + `def configure_v8(o):\n o['variables']['embed_script'] = r'${resolve( + cwd, + snapshot + )}'\n o['variables']['warmup_script'] = r'${resolve(warmup || snapshot)}'` ) return next() diff --git a/src/patches/third-party-main.ts b/src/patches/third-party-main.ts index 55d80b3..36bb927 100644 --- a/src/patches/third-party-main.ts +++ b/src/patches/third-party-main.ts @@ -1,16 +1,6 @@ import { NexeCompiler } from '../compiler' import { parse } from 'cherow' - -function semverGt(version: string, operand: string) { - const [cMajor, cMinor, cPatch] = version.split('.').map(Number) - const [major, minor, patch] = operand.split('.').map(Number) - - return ( - cMajor > major || - (cMajor === major && cMinor > minor) || - (cMajor === major && cMinor === minor && cPatch > patch) - ) -} +import { semverGt } from '../util' function walkSome(node: any, visit: Function) { if (!node || typeof node.type !== 'string' || node._visited) { diff --git a/src/util.ts b/src/util.ts index 5ec22c6..705d5d5 100644 --- a/src/util.ts +++ b/src/util.ts @@ -81,9 +81,21 @@ function isDirectoryAsync(path: string) { .catch(falseOnEnoent) } +function semverGt(version: string, operand: string) { + const [cMajor, cMinor, cPatch] = version.split('.').map(Number) + const [major, minor, patch] = operand.split('.').map(Number) + + return ( + cMajor > major || + (cMajor === major && cMinor > minor) || + (cMajor === major && cMinor === minor && cPatch > patch) + ) +} + export { dequote, padRight, + semverGt, bound, isWindows, rimrafAsync,