Compare commits

..

3 Commits

Author SHA1 Message Date
calebboyd ff612d610e feat(fs): add option to restore all but internal filesystem methods 2019-04-08 22:14:27 -05:00
calebboyd 448f4270ea fix: set entrypoint correctly when outside a tty 2019-04-08 16:23:21 -05:00
calebboyd c9c9b5a0a3 fix: mount vfs relative to execPath instead of cwd 2019-04-08 11:10:33 -05:00
7 changed files with 42 additions and 29 deletions
+1 -1
View File
@@ -1,6 +1,6 @@
{
"name": "nexe",
"version": "3.0.3",
"version": "3.1.0",
"lockfileVersion": 1,
"requires": true,
"dependencies": {
+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.3",
"version": "3.1.0",
"contributors": [
"Craig Condon <craig.j.condon@gmail.com> (http://crcn.io)",
"Jared Allard <jaredallard@outlook.com>",
+19 -18
View File
@@ -13,34 +13,24 @@ export interface NexeBinary {
}
let originalFsMethods: any = null
let nexeBinary: NexeBinary | null = null
function restoreFs(fs: any = require('fs')): NexeBinary | false {
if (!nexeBinary) {
return false
}
const source = nexeBinary
Object.assign(fs, originalFsMethods)
nexeBinary = originalFsMethods = null
return source
}
let lazyRestoreFs = () => {}
function shimFs(binary: NexeBinary, fs: any = require('fs')) {
if (originalFsMethods !== null) {
return
}
originalFsMethods = Object.assign({}, fs)
nexeBinary = binary
const { blobPath, resources: manifest } = binary
const { resourceStart, stat } = binary.layout
const directories: { [key: string]: { [key: string]: boolean } } = {},
const { blobPath, resources: manifest } = binary,
{ resourceStart, stat } = binary.layout,
directories: { [key: string]: { [key: string]: boolean } } = {},
notAFile = '!@#$%^&*',
isWin = process.platform.startsWith('win'),
isString = (x: any): x is string => typeof x === 'string' || x instanceof String,
noop = () => {},
path = require('path')
path = require('path'),
baseDir = path.dirname(process.execPath)
let log = (text: string) => true
let log = (_: string) => true
if ((process.env.DEBUG || '').toLowerCase().includes('nexe:require')) {
log = (text: string) => process.stderr.write('[nexe] - ' + text + '\n')
}
@@ -52,7 +42,7 @@ function shimFs(binary: NexeBinary, fs: any = require('fs')) {
if (!isString(filepath)) {
return notAFile
}
let key = path.resolve(filepath)
let key = path.resolve(baseDir, filepath)
if (isWin && key.substr(1, 2) === ':\\') {
key = key[0].toUpperCase() + key.substr(1)
@@ -329,7 +319,18 @@ function shimFs(binary: NexeBinary, fs: any = require('fs')) {
}
}
Object.assign(fs, nfs)
lazyRestoreFs = () => {
Object.keys(nfs).forEach(key => {
fs[key] = originalFsMethods[key]
})
lazyRestoreFs = () => {}
}
return true
}
function restoreFs() {
lazyRestoreFs()
}
export { shimFs, restoreFs }
+2
View File
@@ -23,6 +23,7 @@ export interface NexeOptions {
name: string
asset: string
cwd: string
fs: boolean | string[]
flags: string[]
configure: string[]
vcBuild: string[]
@@ -59,6 +60,7 @@ export interface NexeOptions {
const defaults = {
flags: [],
cwd: process.cwd(),
fs: true,
configure: [],
mangle: true,
make: [],
+2 -1
View File
@@ -45,10 +45,11 @@ export default async function bundle(compiler: NexeCompiler, next: any) {
if (input === STDIN_FLAG) {
const maybeInput = resolveFileNameSync(cwd, '.')
if (!maybeInput) {
if (!maybeInput || !maybeInput.absPath) {
throw new NexeError('No valid input detected')
}
input = maybeInput.absPath
compiler.entrypoint = './' + relative(cwd, input)
}
const { files, warnings } = await resolveFiles(
+9 -6
View File
@@ -1,4 +1,4 @@
import { dirname, normalize, relative } from 'path'
import { dirname, normalize, relative, resolve } from 'path'
import { createWriteStream, chmodSync, statSync } from 'fs'
import { NexeCompiler } from '../compiler'
import { NexeTarget } from '../target'
@@ -24,18 +24,21 @@ export default async function cli(compiler: NexeCompiler, next: () => Promise<vo
mkdirp.sync(dirname(output))
return new Promise((resolve, reject) => {
return new Promise((res, rej) => {
const step = log.step('Writing result to file')
deliverable
.pipe(createWriteStream(output))
.on('error', reject)
.on('error', rej)
.once('close', (e: Error) => {
if (e) {
reject(e)
rej(e)
} else if (compiler.output) {
const output = compiler.output,
mode = statSync(output).mode | 0o111,
inputFileLogOutput = relative(process.cwd(), compiler.options.input),
inputFileLogOutput = relative(
process.cwd(),
resolve(compiler.options.cwd, compiler.entrypoint || compiler.options.input)
),
outputFileLogOutput = relative(process.cwd(), output)
chmodSync(output, mode.toString(8).slice(-3))
@@ -48,7 +51,7 @@ export default async function cli(compiler: NexeCompiler, next: () => Promise<vo
: inputFileLogOutput
}' written to: ${outputFileLogOutput}`
)
resolve(compiler.quit())
res(compiler.quit())
}
})
})
+8 -2
View File
@@ -6,7 +6,9 @@ export default function(compiler: NexeCompiler, next: () => Promise<void>) {
wrap(
`process.__nexe = ${JSON.stringify(compiler.binaryConfiguration)};\n` +
'{{replace:lib/fs/patch.js}}' +
'\nshimFs(process.__nexe)'
'\nshimFs(process.__nexe)' +
`\n${compiler.options.fs ? '' : 'restoreFs()'}`
//TODO support only restoring specific methods
)
)
compiler.shims.push(
@@ -22,7 +24,11 @@ export default function(compiler: NexeCompiler, next: () => Promise<void>) {
compiler.shims.push(
wrap(`
if (!process.send) {
process.argv.splice(1,0, require.resolve(${JSON.stringify(compiler.entrypoint)}))
const path = require('path')
const entry = path.resolve(path.dirname(process.execPath),${JSON.stringify(
compiler.entrypoint
)})
process.argv.splice(1,0, entry)
}
`)
)