From 54675f0e235684c1af3725841807e7f426a1f2e2 Mon Sep 17 00:00:00 2001 From: Jared Allard Date: Thu, 28 Jan 2016 15:32:33 -0800 Subject: [PATCH] bundle: search top-level directories for browserify as well. Fixes #170. Implement support for js-flags in 0.12.x --- .gitignore | 2 ++ .npmignore | 4 ---- lib/bundle.js | 27 ++++++++++++++++++++++++--- lib/exe.js | 8 ++++++-- package.json | 2 +- test/flags-test/package.json | 2 +- test/gulp-test-170/gulpfile.js | 23 +++++++++++++++++++++++ test/gulp-test-170/index.js | 1 + test/gulp-test-170/package.json | 15 +++++++++++++++ 9 files changed, 73 insertions(+), 11 deletions(-) delete mode 100644 .npmignore create mode 100644 test/gulp-test-170/gulpfile.js create mode 100644 test/gulp-test-170/index.js create mode 100644 test/gulp-test-170/package.json diff --git a/.gitignore b/.gitignore index a60bd28..ac747ae 100644 --- a/.gitignore +++ b/.gitignore @@ -8,3 +8,5 @@ npm-debug.log test/**/src test/**/out.nex test/**/test.nex +test/**/tmp +test/**/node_modules diff --git a/.npmignore b/.npmignore deleted file mode 100644 index e846e54..0000000 --- a/.npmignore +++ /dev/null @@ -1,4 +0,0 @@ -node_modules -test/**/src -test/**/*-test -test/**/*.nex diff --git a/lib/bundle.js b/lib/bundle.js index 25a40d6..3134eb7 100644 --- a/lib/bundle.js +++ b/lib/bundle.js @@ -23,14 +23,14 @@ * **/ -var mdeps = require("module-deps"), +var mdeps = require("module-deps"), path = require("path"), spawn = require('child_process').spawn, fs = require("fs"), async = require("async"), browserify = require('browserify'), builtins = require("builtins"), - _log = require("./log"); + _log = require("./log"); /** * User browserify to create a "packed" file. @@ -42,7 +42,25 @@ var mdeps = require("module-deps"), function bundle (input, nc, complete) { var bundlePath = path.join(nc, "lib", "nexe.js"); var ws = fs.createWriteStream(bundlePath); - var proc = spawn('node', [path.join(__dirname, '../', 'node_modules/browserify/bin/cmd.js'), '--node', input ]); + var browserifyExec; + + var browserifyLocations = [ // TODO: Do this programattically. + 'This is to ignore the 0 location.', + path.join(__dirname, '../', 'node_modules/browserify/bin/cmd.js'), + path.join(__dirname, '../../', 'node_modules/browserify/bin/cmd.js'), + path.join(__dirname, '../../../', 'node_modules/browserify/bin/cmd.js'), + path.join(__dirname, '../../../../', 'node_modules/browserify/bin/cmd.js') + ] + + for(var i = 0; i !== (browserifyLocations.length-1); i++) { + if(fs.existsSync(browserifyLocations[i])) { + browserifyExec = browserifyLocations[i]; + _log('found browserify in', browserifyExec); + break; + } + } + + var proc = spawn('node', [browserifyExec, '--node', input ]); proc.stdout.pipe(ws); @@ -54,6 +72,9 @@ function bundle (input, nc, complete) { proc.stderr.on('data', function(data) { console.error(data.toString('ascii')); + if(!fs.existsSync(input)) { + _log('error', 'Your input file doesn\'t exist!'); + } _log('error', 'Browserify failed to launch'); process.exit(1); }); diff --git a/lib/exe.js b/lib/exe.js index 8063002..54d2f63 100644 --- a/lib/exe.js +++ b/lib/exe.js @@ -707,6 +707,12 @@ SetFlagsFromString(nexevargs, nexevargslen);\n\ var lineInjectDifference = contentsLength - lineToInjectAfter; + // support for 0.12.x + if(lineToInjectAfter===-1) { + _log('warn', 'Using an expiramental support patch for 0.12.x'); + lineToInjectAfter = contentsSplit.indexOf('#undef FLAG_MODE_DEFINE_IMPLICATIONS'); + } + // this is debug, comment out. // _log('v8 injection is', injectionLength, 'newlines long'); // _log('v8 flags source is', contentsLength, 'newlines long'); @@ -731,8 +737,6 @@ SetFlagsFromString(nexevargs, nexevargslen);\n\ injectionSplit[0] = injectionSplit[0].replace('{{args}}', options.jsFlags); - console.log(startShiftLine, endShiftLine); - for (var i = startShiftLine; i !== endShiftLine; i--) { contentsSplit[i+injectRoom] = contentsSplit[i]; contentsSplit[i] = ''; diff --git a/package.json b/package.json index e177d08..583c9bd 100644 --- a/package.json +++ b/package.json @@ -3,7 +3,7 @@ "name": "nexe", "description": "create single executables out of your [node/io].js applications", "license": "MIT", - "version": "1.0.5", + "version": "1.0.6", "contributors": [ { "name": "Criag Condon", diff --git a/test/flags-test/package.json b/test/flags-test/package.json index 0706630..31bb264 100644 --- a/test/flags-test/package.json +++ b/test/flags-test/package.json @@ -6,7 +6,7 @@ "temp": "src", "runtime": { "framework": "node", - "version": "0.12.1", + "version": "0.10.0", "ignoreFlags": false, "js-flags": "--use_strict", "node-args": "" diff --git a/test/gulp-test-170/gulpfile.js b/test/gulp-test-170/gulpfile.js new file mode 100644 index 0000000..7819837 --- /dev/null +++ b/test/gulp-test-170/gulpfile.js @@ -0,0 +1,23 @@ +"use strict"; + +var gulp = require('gulp'); +var nexe = require('nexe'); + +gulp.task( "compile", ( callback ) => { + let options = { + input: "index.js", + output: "test.nex", + python: "python", + nodeTempDir: "./tmp", + nodeVersion: "latest", + flags: false, + framework: "nodejs" + }; + + nexe.compile( options, ( err ) => { + console.log( err ); + callback( err ); + } ); +} ); + +gulp.task('default', ['compile']); diff --git a/test/gulp-test-170/index.js b/test/gulp-test-170/index.js new file mode 100644 index 0000000..e9fe009 --- /dev/null +++ b/test/gulp-test-170/index.js @@ -0,0 +1 @@ +console.log('Hello, world!'); diff --git a/test/gulp-test-170/package.json b/test/gulp-test-170/package.json new file mode 100644 index 0000000..44048a0 --- /dev/null +++ b/test/gulp-test-170/package.json @@ -0,0 +1,15 @@ +{ + "name": "gulp-test-170", + "version": "0.0.1", + "description": "gulpfile.js issue #170", + "main": "index.js", + "scripts": { + "test": "echo \"Error: no test specified\" && exit 1" + }, + "author": "Jared Allard ", + "license": "MIT", + "dependencies": { + "gulp": "^3.9.0", + "nexe": "^1.0.5" + } +}