fix: handle configure script in node 10.11+

This commit is contained in:
calebboyd
2018-10-20 11:23:12 -05:00
parent 129c2f86a0
commit 0db8122f8f
5 changed files with 75 additions and 23 deletions
+1 -1
View File
@@ -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 <craig.j.condon@gmail.com> (http://crcn.io)",
"Jared Allard <jaredallard@outlook.com>",
+52 -3
View File
@@ -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
])
}
+9 -8
View File
@@ -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<void>) {
const snapshotFile = compiler.options.snapshot
const warmupScript = compiler.options.warmup
export default async function(compiler: NexeCompiler, next: () => Promise<void>) {
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()
+1 -11
View File
@@ -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) {
+12
View File
@@ -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,