Compare commits

...

3 Commits

Author SHA1 Message Date
calebboyd 1a75bdb058 fix: avoid syncronous errors in compile method 2019-01-23 20:31:11 -06:00
calebboyd 12c77a34fd chore: update resolve-dependencies 2019-01-05 11:25:36 -06:00
calebboyd c76edb7c0b chore: expose build on compiler 2018-12-31 08:51:53 -06:00
8 changed files with 167 additions and 51 deletions
+14 -1
View File
@@ -10,7 +10,20 @@ if (require.main === module) {
process.stderr.write(showHelp ? options.help : options.version + eol)
} else {
const nexe = require('./lib/nexe')
nexe.compile(argv).catch(() => {
nexe.compile(argv).catch((error) => {
const NexeError = require('./lib/compiler').NexeError
const chalk = require('chalk')
const isSilent = Boolean(argv.silent === true || argv.loglevel === 'silent')
if (!isSilent) {
if (error instanceof NexeError) {
process.stderr.write(eol + chalk.red('Error: ') + error.message + eol
+ eol + 'See nexe -h for usage..' + eol + eol
)
} else {
process.stderr.write(error.stack + eol)
}
}
process.exit(1)
})
}
+110 -11
View File
@@ -1,6 +1,6 @@
{
"name": "nexe",
"version": "3.0.0-beta.12",
"version": "3.0.0-beta.15",
"lockfileVersion": 1,
"requires": true,
"dependencies": {
@@ -42,6 +42,37 @@
"integrity": "sha512-2Y8uPt0/jwjhQ6EiluT0XCri1Dbplr0ZxfFXUz+ye13gaqE8u5gL5ppao1JrUYr9cIip5S6MvQzBS7Kke7U9VA==",
"dev": true
},
"@types/decompress": {
"version": "4.2.3",
"resolved": "https://registry.npmjs.org/@types/decompress/-/decompress-4.2.3.tgz",
"integrity": "sha512-W24e3Ycz1UZPgr1ZEDHlK4XnvOr+CpJH3qNsFeqXwwlW/9END9gxn3oJSsp7gYdiQxrXUHwUUd3xuzVz37MrZQ==",
"dev": true,
"requires": {
"@types/node": "*"
}
},
"@types/download": {
"version": "6.2.4",
"resolved": "https://registry.npmjs.org/@types/download/-/download-6.2.4.tgz",
"integrity": "sha512-Lo5dy3ai6LNnbL663sgdzqL1eib11u1yKH6w3v3IXEOO4kRfQpMn1qWUTaumcHLACjFp1RcBx9tUXEvJoR3vcA==",
"dev": true,
"requires": {
"@types/decompress": "*",
"@types/got": "^8",
"@types/node": "*"
},
"dependencies": {
"@types/got": {
"version": "8.3.5",
"resolved": "https://registry.npmjs.org/@types/got/-/got-8.3.5.tgz",
"integrity": "sha512-AaXSrIF99SjjtPVNmCmYb388HML+PKEJb/xmj4SbL2ZO0hHuETZZzyDIKfOqaEoAHZEuX4sC+FRFrHYJoIby6A==",
"dev": true,
"requires": {
"@types/node": "*"
}
}
}
},
"@types/events": {
"version": "1.2.0",
"resolved": "https://registry.npmjs.org/@types/events/-/events-1.2.0.tgz",
@@ -168,9 +199,9 @@
"dev": true
},
"acorn": {
"version": "6.0.4",
"resolved": "https://registry.npmjs.org/acorn/-/acorn-6.0.4.tgz",
"integrity": "sha512-VY4i5EKSKkofY2I+6QLTbTTN/UvEQPCo6eiwzzSaSWfpaDhOmStMCMod6wmuPciNq+XS0faCglFu2lHZpdHUtg=="
"version": "6.0.5",
"resolved": "https://registry.npmjs.org/acorn/-/acorn-6.0.5.tgz",
"integrity": "sha512-i33Zgp3XWtmZBMNvCr4azvOFeWVw1Rk6p3hfi3LUDvIFraOMywb1kAtrbi+med14m4Xfpqm3zRZMT+c0FNE7kg=="
},
"ansi-regex": {
"version": "3.0.0",
@@ -2264,15 +2295,83 @@
}
},
"resolve-dependencies": {
"version": "2.2.0",
"resolved": "https://registry.npmjs.org/resolve-dependencies/-/resolve-dependencies-2.2.0.tgz",
"integrity": "sha512-XIF2ujfs7qBOa4awXgdpQfhCawKiwOeUT/n9YlaipKHqj2iO41t56QDKdO0GGluPs4QduzKtbbM/B+iYPlQVUA==",
"version": "2.2.1",
"resolved": "https://registry.npmjs.org/resolve-dependencies/-/resolve-dependencies-2.2.1.tgz",
"integrity": "sha512-nZkQEcXmJG5C3oDkbILK3fdFyhtwdV+67OD+0sUKLZU+ZJ/ozWsCe7Hyq0bqmhvmtnBgtmOO91OfiqCv6bu+GA==",
"requires": {
"@calebboyd/semaphore": "^1.3.1",
"acorn": "^6.0.4",
"enhanced-resolve": "^4.1.0",
"globby": "^8.0.1",
"globby": "git://github.com/nexe/globby.git#de057b69c2bca74391bfd913ed0145ce4e42563a",
"pify": "^4.0.0"
},
"dependencies": {
"@nodelib/fs.stat": {
"version": "1.1.3",
"resolved": "https://registry.npmjs.org/@nodelib/fs.stat/-/fs.stat-1.1.3.tgz",
"integrity": "sha512-shAmDyaQC4H92APFoIaVDHCx5bStIocgvbwQyxPRrbUY20V1EYTbSDchWbuwlMG3V17cprZhA6+78JfB+3DTPw=="
},
"dir-glob": {
"version": "git://github.com/nexe/dir-glob.git#84f4381fe041b6afd425e8d5c14c33809430d8f1",
"from": "git://github.com/nexe/dir-glob.git#84f4381fe041b6afd425e8d5c14c33809430d8f1",
"requires": {
"path-type": "^3.0.0"
}
},
"fast-glob": {
"version": "2.2.4",
"resolved": "https://registry.npmjs.org/fast-glob/-/fast-glob-2.2.4.tgz",
"integrity": "sha512-FjK2nCGI/McyzgNtTESqaWP3trPvHyRyoyY70hxjc3oKPNmDe8taohLZpoVKoUjW85tbU5txaYUZCNtVzygl1g==",
"requires": {
"@mrmlnc/readdir-enhanced": "^2.2.1",
"@nodelib/fs.stat": "^1.1.2",
"glob-parent": "^3.1.0",
"is-glob": "^4.0.0",
"merge2": "^1.2.3",
"micromatch": "^3.1.10"
}
},
"glob": {
"version": "7.1.3",
"resolved": "https://registry.npmjs.org/glob/-/glob-7.1.3.tgz",
"integrity": "sha512-vcfuiIxogLV4DlGBHIUOwI0IbrJ8HWPc4MU7HzviGeNho/UJDfi6B5p3sHeWIQ0KGIU0Jpxi5ZHxemQfLkkAwQ==",
"requires": {
"fs.realpath": "^1.0.0",
"inflight": "^1.0.4",
"inherits": "2",
"minimatch": "^3.0.4",
"once": "^1.3.0",
"path-is-absolute": "^1.0.0"
}
},
"globby": {
"version": "git://github.com/nexe/globby.git#de057b69c2bca74391bfd913ed0145ce4e42563a",
"from": "git://github.com/nexe/globby.git#de057b69c2bca74391bfd913ed0145ce4e42563a",
"requires": {
"array-union": "^1.0.2",
"dir-glob": "git://github.com/nexe/dir-glob.git#84f4381fe041b6afd425e8d5c14c33809430d8f1",
"fast-glob": "^2.2.3",
"glob": "^7.1.3",
"ignore": "^4.0.3",
"pify": "^4.0.1",
"slash": "^2.0.0"
}
},
"ignore": {
"version": "4.0.6",
"resolved": "https://registry.npmjs.org/ignore/-/ignore-4.0.6.tgz",
"integrity": "sha512-cyFDKrqc/YdcWFniJhzI42+AzS+gNwmUzOSFcRCQYwySuBBBy/KjuxWLZ/FHEH6Moq1NizMOBWyTcv8O4OZIMg=="
},
"merge2": {
"version": "1.2.3",
"resolved": "https://registry.npmjs.org/merge2/-/merge2-1.2.3.tgz",
"integrity": "sha512-gdUU1Fwj5ep4kplwcmftruWofEFt6lfpkkr3h860CXbAB9c3hGb55EOL2ali0Td5oebvW0E1+3Sr+Ur7XfKpRA=="
},
"slash": {
"version": "2.0.0",
"resolved": "https://registry.npmjs.org/slash/-/slash-2.0.0.tgz",
"integrity": "sha512-ZYKh3Wh2z1PpEXWr0MpSBZ0V6mZHAQfYevttO11c51CaWjGTaadiKZ+wVt1PbMlDV5qhMFslpZCemhwOK7C89A=="
}
}
},
"resolve-url": {
@@ -2636,9 +2735,9 @@
}
},
"tapable": {
"version": "1.1.0",
"resolved": "https://registry.npmjs.org/tapable/-/tapable-1.1.0.tgz",
"integrity": "sha512-IlqtmLVaZA2qab8epUXbVWRn3aB1imbDMJtjB3nu4X0NqPkcY/JH9ZtCBWKHWPxs8Svi9tyo8w2dBoi07qZbBA=="
"version": "1.1.1",
"resolved": "https://registry.npmjs.org/tapable/-/tapable-1.1.1.tgz",
"integrity": "sha512-9I2ydhj8Z9veORCw5PRm4u9uebCn0mcCa6scWoNcbZ6dAtoo2618u9UUzxgmsCOreJpqDDuv61LvwofW7hLcBA=="
},
"tar-stream": {
"version": "1.6.1",
+4 -3
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.12",
"version": "3.0.0-beta.15",
"contributors": [
"Craig Condon <craig.j.condon@gmail.com> (http://crcn.io)",
"Jared Allard <jaredallard@outlook.com>",
@@ -37,20 +37,21 @@
"app-builder": "^5.2.0",
"caw": "^2.0.1",
"chalk": "^2.4.1",
"cherow": "1.6.8",
"download": "^7.1.0",
"globby": "^8.0.1",
"cherow": "1.6.8",
"got": "^9.5.0",
"minimist": "^1.2.0",
"mkdirp": "^0.5.1",
"multistream": "^2.1.1",
"ora": "^3.0.0",
"pify": "^4.0.1",
"resolve-dependencies": "^2.2.0",
"resolve-dependencies": "^2.2.1",
"rimraf": "^2.6.2"
},
"devDependencies": {
"@types/chai": "^4.1.7",
"@types/download": "^6.2.4",
"@types/execa": "^0.9.0",
"@types/globby": "^8.0.0",
"@types/got": "^9.2.2",
+18 -12
View File
@@ -1,6 +1,6 @@
import { delimiter, dirname, normalize, join } from 'path'
import { Buffer } from 'buffer'
import { createReadStream } from 'fs'
import { createReadStream, ReadStream } from 'fs'
import { spawn } from 'child_process'
import { Logger, LogStep } from './logger'
import {
@@ -35,22 +35,28 @@ export interface NexeFile {
export { NexeOptions }
export class NexeError extends Error {
constructor(m: string) {
super(m)
Object.setPrototypeOf(this, NexeError.prototype)
}
}
export class NexeCompiler {
/**
* Epoch of when compilation started
*/
private start = Date.now()
private compileStep: LogStep | undefined
public log = new Logger(this.options.loglevel)
/**
* Copy of process.env
*/
private env = { ...process.env }
public env = { ...process.env }
/**
* Virtual FileSystem
*/
private bundle: Bundle
private compileStep: LogStep | undefined
public log = new Logger(this.options.loglevel)
public bundle: Bundle
/**
* Root directory for the source of the current build
*/
@@ -94,7 +100,7 @@ export class NexeCompiler {
/**
* The file path of node binary
*/
private nodeSrcBinPath: string
public nodeSrcBinPath: string
constructor(public options: NexeOptions) {
const { python } = (this.options = options)
@@ -179,7 +185,7 @@ export class NexeCompiler {
assertBuild() {
if (!this.options.build) {
throw new Error('This feature is only available with `--build`')
throw new NexeError('This feature is only available with `--build`')
}
}
@@ -212,7 +218,7 @@ export class NexeCompiler {
}
if (code != 0) {
const error = `${command} ${args.join(' ')} exited with code: ${code}`
reject(new Error(error))
reject(new NexeError(error))
}
resolve()
})
@@ -226,7 +232,7 @@ export class NexeCompiler {
])
}
private async _buildAsync() {
public async build(): Promise<ReadStream> {
this.compileStep!.log(
`Configuring node build${
this.options.configure.length ? ': ' + this.options.configure : '...'
@@ -256,7 +262,7 @@ export class NexeCompiler {
const asset = githubRelease.assets.find(x => x.name === assetName)
if (!asset) {
throw new Error(`${assetName} not available, create it using the --build flag`)
throw new NexeError(`${assetName} not available, create it using the --build flag`)
}
const filename = this.getNodeExecutableLocation(target)
@@ -306,7 +312,7 @@ export class NexeCompiler {
binary = await this._fetchPrebuiltBinaryAsync(target)
}
if (await this._shouldCompileBinaryAsync(binary, location)) {
binary = await this._buildAsync()
binary = await this.build()
step.log('Node binary compiled')
}
return this._assembleDeliverable(binary!)
+16 -19
View File
@@ -1,6 +1,6 @@
import { EOL } from 'os'
import { compose } from 'app-builder'
import { NexeCompiler } from './compiler'
import { NexeCompiler, NexeError } from './compiler'
import { normalizeOptions, NexeOptions, NexePatch } from './options'
import resource from './steps/resource'
import clean from './steps/clean'
@@ -15,31 +15,28 @@ async function compile(
compilerOptions?: Partial<NexeOptions>,
callback?: (err: Error | null) => void
) {
const options = normalizeOptions(compilerOptions)
const compiler = new NexeCompiler(options)
let error = null,
options: NexeOptions | null = null,
compiler: NexeCompiler | null = null
const nexe = compose(
clean,
resource,
cli,
bundle,
shim,
options.build ? [download, artifacts, ...patches, ...(options.patches as NexePatch[])] : [],
options.plugins as NexePatch[]
)
let error = null
try {
await nexe(compiler)
options = normalizeOptions(compilerOptions)
compiler = new NexeCompiler(options)
await compose(
clean,
resource,
cli,
bundle,
shim,
options.build ? [download, artifacts, ...patches, ...(options.patches as NexePatch[])] : [],
options.plugins as NexePatch[]
)(compiler)
} catch (e) {
error = e
}
if (error) {
compiler.quit(error)
if (compiler.options.loglevel !== 'silent' && error) {
process.stderr.write(EOL + error.message + EOL)
}
compiler && compiler.quit(error)
if (callback) return callback(error)
return Promise.reject(error)
}
+2 -2
View File
@@ -1,5 +1,5 @@
import * as parseArgv from 'minimist'
import { NexeCompiler } from './compiler'
import { NexeCompiler, NexeError } from './compiler'
import { isWindows, STDIN_FLAG } from './util'
import { basename, extname, join, isAbsolute, resolve } from 'path'
import { getTarget, NexeTarget } from './target'
@@ -222,7 +222,7 @@ export function resolveEntry(
result = resolveFileNameSync(cwd, '.')
}
if (!result.absPath) {
throw new Error(`Entry file "${input}" not found!`)
throw new NexeError(`Entry file "${input || ''}" not found!`)
}
return result.absPath
}
+2 -2
View File
@@ -1,4 +1,4 @@
import { NexeCompiler } from '../compiler'
import { NexeCompiler, NexeError } from '../compiler'
import { resolve, relative } from 'path'
import { each } from '@calebboyd/semaphore'
import resolveFiles from 'resolve-dependencies'
@@ -48,7 +48,7 @@ export default async function bundle(compiler: NexeCompiler, next: any) {
if (
warnings.filter(x => x.startsWith('Error parsing file') && !x.includes('node_modules')).length
) {
throw new Error('Parsing Error:\n' + warnings.join('\n'))
throw new NexeError('Parsing Error:\n' + warnings.join('\n'))
}
await each(Object.keys(files), (filename: string) => compiler.addResource(filename), {
+1 -1
View File
@@ -3,7 +3,7 @@
"target":"es5",
"skipLibCheck": true,
"experimentalDecorators": true,
"lib": ["es2017"],
"lib": ["es2018"],
"module": "commonjs",
"outDir": "./lib",
"strict": true