browserify-lite
Advanced tools
Comparing version 0.2.5 to 0.3.0
35
cli.js
@@ -6,21 +6,25 @@ #!/usr/bin/env node | ||
var entrySourcePath = process.argv[2]; | ||
var outputFileParam = process.argv[3]; | ||
var outBundlePath = process.argv[4]; | ||
if (entrySourcePath === '--help') { | ||
usage(); | ||
var options = {}; | ||
for (var i = 2; i < process.argv.length; i += 1) { | ||
var arg = process.argv[i]; | ||
if (arg === '--help') { | ||
usage(); | ||
} else if (arg === '--outfile') { | ||
if (++i >= process.argv.length) usage(); | ||
options.outBundlePath = process.argv[i]; | ||
} else if (arg === '--standalone') { | ||
if (++i >= process.argv.length) usage(); | ||
options.standalone = process.argv[i]; | ||
} else if (!options.entrySourcePath) { | ||
options.entrySourcePath = arg; | ||
} else { | ||
usage(); | ||
} | ||
} | ||
if (outputFileParam !== '--outfile') { | ||
console.error("Expected second param to be --outfile\n"); | ||
if (!options.outBundlePath || !options.entrySourcePath) { | ||
usage(); | ||
} | ||
if (!outBundlePath || !entrySourcePath) { | ||
console.error("Expected first arg to be source path and third arg to be out bundle path.\n"); | ||
usage(); | ||
} | ||
browserifyLite.createBundle(entrySourcePath, outBundlePath, function(err) { | ||
browserifyLite.createBundle(options, function(err) { | ||
if (err) throw err; | ||
@@ -36,4 +40,5 @@ }); | ||
"\n" + | ||
" --outfile Write the browserify bundle to this file."); | ||
" --outfile Write the browserify bundle to this file\n" + | ||
" --standalone xyz Export as window.xyz"); | ||
process.exit(1); | ||
} |
27
index.js
@@ -8,3 +8,7 @@ var fs = require('fs'); | ||
function createBundle(entrySourcePath, outBundlePath, cb) { | ||
function createBundle(options, cb) { | ||
var entrySourcePath = options.entrySourcePath; | ||
var outBundlePath = options.outBundlePath; | ||
var standalone = options.standalone; | ||
// data structure that is filled up with canonical source path as the key, | ||
@@ -82,9 +86,13 @@ // source code as the value. | ||
var standaloneLine = standalone ? | ||
" window." + standalone + " = req(entry);\n" : | ||
" req(entry);\n"; | ||
var out = | ||
"(function(modules, cache, entry) {\n" + | ||
" req(entry);\n" + | ||
standaloneLine + | ||
" function req(name) {\n" + | ||
" if (cache[name]) return cache[name].exports;\n" + | ||
" var m = cache[name] = {exports: {}};\n" + | ||
" modules[name][0].call(m.exports, modRequire, m, m.exports);\n" + | ||
" modules[name][0].call(m.exports, modRequire, m, m.exports, window);\n" + | ||
" return m.exports;\n" + | ||
@@ -100,3 +108,3 @@ " function modRequire(alias) {\n" + | ||
modules.forEach(function(canonicalSourcePath) { | ||
out += aliases[canonicalSourcePath] + ": [function(require,module,exports){\n"; | ||
out += aliases[canonicalSourcePath] + ": [function(require,module,exports,global){\n"; | ||
if (canonicalSourcePath.match(/\.json$/)) { | ||
@@ -119,3 +127,2 @@ out += "module.exports = "; | ||
var inQuote = false; | ||
var braceCount = 0; | ||
var quoteType; | ||
@@ -138,5 +145,3 @@ var qEscape = false; | ||
inQuote = false; | ||
if (braceCount === 0) { | ||
tokens.push(token); | ||
} | ||
tokens.push(token); | ||
token = ""; | ||
@@ -172,6 +177,4 @@ } else { | ||
token = ""; | ||
braceCount += 1; | ||
} else if (c === '}') { | ||
startComment = false; | ||
braceCount -= 1; | ||
} else if (c === '/') { | ||
@@ -191,3 +194,3 @@ if (startComment) { | ||
startComment = false; | ||
} else if (braceCount === 0) { | ||
} else { | ||
if (/\W/.test(c)) { | ||
@@ -200,4 +203,2 @@ if (token) tokens.push(token); | ||
} | ||
} else { | ||
startComment = false; | ||
} | ||
@@ -204,0 +205,0 @@ } |
{ | ||
"name": "browserify-lite", | ||
"version": "0.2.5", | ||
"version": "0.3.0", | ||
"description": "browserify, minus some of the advanced features and heavy dependencies.", | ||
@@ -5,0 +5,0 @@ "main": "index.js", |
@@ -7,4 +7,4 @@ # browserify-lite | ||
* Naive AST tokenization for require instead of true AST parsing. | ||
- Require statements must be outside all braces. This includes functions, | ||
control statements, and objects. | ||
- All require statements are found regardless of if they are in an `if` | ||
statement or a function body that is never called. | ||
* Only supports a single entry file and the `--outfile` parameter, | ||
@@ -18,3 +18,8 @@ nothing else. | ||
``` | ||
browserify-lite ./src/app.js --outfile public/app.js | ||
browserify-lite ./entry-file.js --outfile bundle.js | ||
Standard Options: | ||
--outfile Write the browserify bundle to this file. | ||
--standalone xyz Export as a window global. | ||
``` | ||
@@ -21,0 +26,0 @@ |
@@ -55,5 +55,6 @@ var assert = require('assert'); | ||
name: "ignore braces", | ||
source: "var foo = require('derp'); { require('ignore-this'); } require('this-ok')\n", | ||
source: "var foo = require('derp'); { require('dont-ignore-this'); } require('this-ok')\n", | ||
output: [ | ||
"derp", | ||
"dont-ignore-this", | ||
"this-ok", | ||
@@ -64,8 +65,9 @@ ], | ||
name: "ignore comments", | ||
source: "/* var foo = require('derp');*/ { require('ignore-this'); } require('this-ok') // require('also-ignore-this'); \n require('this-also-ok')", | ||
source: "/* var foo = require('derp');*/ { require('dont-ignore-this'); } require('this-ok') // require('also-ignore-this'); \n require('this-also-ok')", | ||
output: [ | ||
"dont-ignore-this", | ||
"this-ok", | ||
"this-also-ok", | ||
], | ||
}, | ||
} | ||
]; | ||
@@ -72,0 +74,0 @@ |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
15313
406
28