├── .gitignore ├── MIT-LICENSE ├── Makefile ├── README.markdown ├── component.json ├── node_modules ├── .bin │ └── uglifyjs ├── node-static │ ├── LICENSE │ ├── README.md │ ├── benchmark │ │ └── node-static-0.3.0.txt │ ├── examples │ │ └── file-server.js │ ├── lib │ │ ├── node-static.js │ │ └── node-static │ │ │ ├── mime.js │ │ │ └── util.js │ └── package.json └── uglify-js │ ├── .gitignore │ ├── README.html │ ├── README.org │ ├── bin │ └── uglifyjs │ ├── docstyle.css │ ├── lib │ ├── object-ast.js │ ├── parse-js.js │ ├── process.js │ └── squeeze-more.js │ ├── package.json │ ├── package.json~ │ ├── test │ ├── beautify.js │ ├── testparser.js │ └── unit │ │ ├── compress │ │ ├── expected │ │ │ ├── array1.js │ │ │ ├── array2.js │ │ │ ├── array3.js │ │ │ ├── array4.js │ │ │ ├── assignment.js │ │ │ ├── concatstring.js │ │ │ ├── const.js │ │ │ ├── empty-blocks.js │ │ │ ├── forstatement.js │ │ │ ├── if.js │ │ │ ├── ifreturn.js │ │ │ ├── ifreturn2.js │ │ │ ├── issue10.js │ │ │ ├── issue11.js │ │ │ ├── issue13.js │ │ │ ├── issue14.js │ │ │ ├── issue16.js │ │ │ ├── issue17.js │ │ │ ├── issue20.js │ │ │ ├── issue21.js │ │ │ ├── issue25.js │ │ │ ├── issue27.js │ │ │ ├── issue28.js │ │ │ ├── issue29.js │ │ │ ├── issue30.js │ │ │ ├── issue34.js │ │ │ ├── issue4.js │ │ │ ├── issue48.js │ │ │ ├── issue50.js │ │ │ ├── issue53.js │ │ │ ├── issue54.1.js │ │ │ ├── issue68.js │ │ │ ├── issue69.js │ │ │ ├── issue9.js │ │ │ ├── mangle.js │ │ │ ├── null_string.js │ │ │ ├── strict-equals.js │ │ │ ├── var.js │ │ │ ├── whitespace.js │ │ │ └── with.js │ │ └── test │ │ │ ├── array1.js │ │ │ ├── array2.js │ │ │ ├── array3.js │ │ │ ├── array4.js │ │ │ ├── assignment.js │ │ │ ├── concatstring.js │ │ │ ├── const.js │ │ │ ├── empty-blocks.js │ │ │ ├── forstatement.js │ │ │ ├── if.js │ │ │ ├── ifreturn.js │ │ │ ├── ifreturn2.js │ │ │ ├── issue10.js │ │ │ ├── issue11.js │ │ │ ├── issue13.js │ │ │ ├── issue14.js │ │ │ ├── issue16.js │ │ │ ├── issue17.js │ │ │ ├── issue20.js │ │ │ ├── issue21.js │ │ │ ├── issue25.js │ │ │ ├── issue27.js │ │ │ ├── issue28.js │ │ │ ├── issue29.js │ │ │ ├── issue30.js │ │ │ ├── issue34.js │ │ │ ├── issue4.js │ │ │ ├── issue48.js │ │ │ ├── issue50.js │ │ │ ├── issue53.js │ │ │ ├── issue54.1.js │ │ │ ├── issue68.js │ │ │ ├── issue69.js │ │ │ ├── issue9.js │ │ │ ├── mangle.js │ │ │ ├── null_string.js │ │ │ ├── strict-equals.js │ │ │ ├── var.js │ │ │ ├── whitespace.js │ │ │ └── with.js │ │ └── scripts.js │ ├── tmp │ ├── hoist.js │ ├── instrument.js │ ├── instrument2.js │ └── test.js │ └── uglify-js.js ├── plugins ├── amd.js ├── commonjs.js ├── defer.js └── json.js ├── src └── loadrunner.js ├── test ├── amd_test.html ├── commonjs_test.html ├── data.json ├── deferred_test.html ├── index.html ├── javascripts │ ├── a.js │ ├── b.js │ ├── c.js │ ├── compiled.js │ ├── d.js │ ├── deferred_bundle.js │ ├── deferred_scripts.js │ ├── e.js │ ├── main.js │ ├── modcompiled.js │ ├── s1.js │ ├── s2.js │ └── s3.js ├── json_test.html ├── modules │ ├── amd │ │ ├── dotdotslash.js │ │ ├── moda.js │ │ ├── modb.js │ │ ├── modlit.js │ │ ├── modnodep.js │ │ └── modrel.js │ ├── app.js │ ├── ded-a.js │ ├── ded-b1.js │ ├── ded-b2.js │ ├── deep.js │ ├── defered.js │ ├── defered2.js │ ├── many.js │ ├── moda.js │ ├── modb.js │ ├── modc.js │ ├── modcompiled.js │ ├── modd.js │ ├── mode.js │ ├── modj.js │ ├── requirejs │ │ ├── moddep.js │ │ └── modtrivial.js │ └── sub │ │ ├── modsubfolder.js │ │ ├── script.js │ │ ├── submoda.js │ │ └── submodb.js ├── server └── test.html └── vendor └── qunit ├── qunit.css └── qunit.js /.gitignore: -------------------------------------------------------------------------------- 1 | .DS_Store -------------------------------------------------------------------------------- /MIT-LICENSE: -------------------------------------------------------------------------------- 1 | Copyright (c) 2010 Dan Webb 2 | 3 | Permission is hereby granted, free of charge, to any person obtaining 4 | a copy of this software and associated documentation files (the 5 | "Software"), to deal in the Software without restriction, including 6 | without limitation the rights to use, copy, modify, merge, publish, 7 | distribute, sublicense, and/or sell copies of the Software, and to 8 | permit persons to whom the Software is furnished to do so, subject to 9 | the following conditions: 10 | 11 | The above copyright notice and this permission notice shall be 12 | included in all copies or substantial portions of the Software. 13 | 14 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, 15 | EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF 16 | MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND 17 | NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE 18 | LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION 19 | OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION 20 | WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. -------------------------------------------------------------------------------- /Makefile: -------------------------------------------------------------------------------- 1 | all: clean main 2 | 3 | dist/plugins/%.js: plugins/%.js 4 | `npm bin`/uglifyjs -o $@ $< 5 | 6 | dist/%.js: src/%.js 7 | `npm bin`/uglifyjs -o $@ $< 8 | 9 | dist: 10 | mkdir -p dist/plugins 11 | 12 | main: dist js plugins 13 | 14 | plugins: dist/plugins/amd.js dist/plugins/defer.js dist/plugins/json.js 15 | 16 | js: dist/loadrunner.js 17 | 18 | clean: 19 | rm -rf dist 20 | 21 | testserver: . 22 | ./test/server 23 | 24 | test: . 25 | open 'http://localhost:8080/test/index.html' -------------------------------------------------------------------------------- /README.markdown: -------------------------------------------------------------------------------- 1 | Loadrunner is a JavaScript dependency manager. 2 | 3 | Loadrunner started off as my science project script loader and module system but its turned into a generic dependency manager that you can build on to manage any type of asynchronous dependency from CSS templates to DOM events to cache loading. It does however include build in support for loading regular JavaScript files, AMD modules and its own, more elegant (IMHO) flavour of modules. 4 | 5 | Run the tests 6 | ------------- 7 | 8 | Open test/test.html. To run against the minified version open test/test.html?dist=true. Also, try reading the tests. They illustrate how it works possibly better than the examples below. 9 | 10 | Build a minified version 11 | ------------------------ 12 | 13 | Just run: 14 | 15 | make 16 | 17 | 18 | The Basics 19 | ---------- 20 | 21 | In its basic form, loadrunner exposes two top level functions: `using` and `provide`. 22 | 23 | __using(dependency[, dependency1, dependency2, ...][, collectResults:boolean][, callback])__ => Combination 24 | 25 | Takes any number of dependencies, which can be any type of dependency object or a string representing a dependency (a path to a javascript file or module identifier works by default), and returns a dependency called a *Combination* which waits for all of the given dependencies to complete in any order. If you specify a callback then it's attached to this dependency as a convenience. 26 | 27 | Dependencies are not loaded until a callback is attached. 28 | 29 | ```javascript 30 | // use some javascript files 31 | using('javascripts/jquery.js', 'javascripts/underscore.js', function() { 32 | $(function() { 33 | _(['foo', 'bar', 'baz']).each(function(i) { 34 | $(document.body).append('

' + i + '

'); 35 | }); 36 | }) 37 | }); 38 | ``` 39 | 40 | Depending on the type of dependencies specified in the `using` block some arguments may be passed to the callback function. For instance, in the case of using a module, the module's exports are passed as a function argument. 41 | 42 | ```javascript 43 | // use some modules 44 | using('dom', 'events', function(dom, events) { 45 | var el = dom.get('#thing'); 46 | 47 | events.on(el, function() { 48 | alert('kersplang'); 49 | }); 50 | }); 51 | 52 | // get reference to a dependency 53 | var mods = using('dom', 'events'); 54 | 55 | // use that dependency with others 56 | using(mods, 'javascripts/jquery.js', function(dom, events) { 57 | 58 | }); 59 | ``` 60 | 61 | Using can provide all exports in a single object if required. Just use the 'as' method. 62 | 63 | ```javascript 64 | // use some modules in one object 65 | using('dom', 'events').as(function(imports) { 66 | var el = imports.dom.get('#thing'); 67 | imports.events.on(el, function() { 68 | alert('kersplang'); 69 | }); 70 | }); 71 | ``` 72 | 73 | In this case, the exports are still available individually. 74 | 75 | ```javascript 76 | // use some modules in one object, and also have them immediately available 77 | using('dom', 'events').as(function(imports, dom, events) { 78 | var el = dom.get('#thing'); 79 | imports.events.on(el, function() { 80 | alert('kersplang'); 81 | }); 82 | }); 83 | ``` 84 | 85 | Using can load scripts synchronously (in order) by being provided arguments in an array. 86 | 87 | ```javascript 88 | // load 'dom' first, then load 'events', then execute the callback 89 | using(['dom', 'events'], true, function(imports) { 90 | 91 | }); 92 | ``` 93 | 94 | 95 | __provide([id,] factory)__ => Module 96 | 97 | `provide` defines a module with the given id. If you don't provide an id then the module's id will be inferred from the location of the javascript file that contains it (dom/events.js => dom/events). Provide returns a type of definition, *Module*. The second argument can be either a function that is run to define the module, or any kind of other type. In the case of this being a function, then when the module is evaluated the function is called with a single argument, normally called *exports*, which is a function that you call to specify which public values the module exports. Note that you can call this at any point after the module has been evaluated. _Exporting module values is asynchronous._ Among other things, this allows seamless operation with the `using` function to allow your modules to depend on other items. 98 | 99 | ```javascript 100 | // define a module, "config", that exports some static values 101 | provide('config', { 102 | env: 'staging', 103 | admin: true 104 | }); 105 | 106 | // define then use a module, test 107 | provide('test', function(exports) { 108 | var thing = 47; 109 | 110 | exports(thing); 111 | }); 112 | 113 | using('test', function(thing) { 114 | alert(thing); // => 47 115 | }); 116 | 117 | // define and use a module that depends on other modules (app/main.js) 118 | provide(function(exports) { 119 | using('test', function(thing) { 120 | exports(thing + 10); 121 | }); 122 | }); 123 | 124 | using('app/main', function(main) { 125 | alert(main); //=> 57 126 | }); 127 | ``` 128 | 129 | Debugging 130 | -------- 131 | 132 | Loadrunner provides a debug command to run in the console. Enter `loadrunner.debug()`, and you'll see a set of met, inProgress and paused dependencies. 133 | 134 | Another great debugging method is to inspect `loadrunner.Module.exports`. 135 | 136 | 137 | Bundling 138 | -------- 139 | 140 | Modules can be joined together in single files, provided they have names explicitly defined. Tools such as [Loadbuilder](https://github.com/danwrong/loadbuilder) can help with automatically inserting the module names. 141 | 142 | If a module is requested in a `using` before it has been provided, loadrunner will make a call to load the module individually. To prevent this, loadrunner provides some options: 143 | 144 | * `loadrunner.autoFetch = false` Assumes modules will be provided in later-loading bundles, so loadrunner will not fetch scripts. To explicitly fetch scripts, you must run `forceStart` on the dependency, eg: `using('bundle').forceStart();` 145 | * `using.bundles.push({'bundle': ['moda', 'modb'])` Declare the location of modules in bundles. When a module is requested, loadrunner will wait first on the evaluation of the bundle, fetching it if required. 146 | 147 | If your wish to bundle scripts, then they must first be wrapped with `deferred` syntax, like so: 148 | 149 | ```javascript 150 | deferred('jquery.js', function() { /* jquery source */ }); 151 | ``` 152 | 153 | Loadrunner supports the `deferred` syntax through the `defer` plugin. 154 | 155 | AMD Modules 156 | ----------- 157 | 158 | Loadrunner will have support for [AMD Modules](http://wiki.commonjs.org/wiki/Modules/AsynchronousDefinition) with the use of a plugin. However, this support is not be complete at this time. 159 | 160 | 161 | More documentation forthcoming... 162 | 163 | -------------------------------------------------------------------------------- /component.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "loadrunner", 3 | "version": "0.1.2", 4 | "description": "Simple, flexible and sane JavaScript loader and build tool for browsers.", 5 | "contributors": [{ "name": "Dan Webb", "email": "dan@danwebb.net" }], 6 | "homepage": "https://github.com/danwrong/loadrunner", 7 | "main" : "./src/loadrunner.js" 8 | } -------------------------------------------------------------------------------- /node_modules/.bin/uglifyjs: -------------------------------------------------------------------------------- 1 | ../uglify-js/bin/uglifyjs -------------------------------------------------------------------------------- /node_modules/node-static/LICENSE: -------------------------------------------------------------------------------- 1 | Copyright (c) 2010 Alexis Sellier 2 | 3 | Permission is hereby granted, free of charge, to any person obtaining 4 | a copy of this software and associated documentation files (the 5 | "Software"), to deal in the Software without restriction, including 6 | without limitation the rights to use, copy, modify, merge, publish, 7 | distribute, sublicense, and/or sell copies of the Software, and to 8 | permit persons to whom the Software is furnished to do so, subject to 9 | the following conditions: 10 | 11 | The above copyright notice and this permission notice shall be 12 | included in all copies or substantial portions of the Software. 13 | 14 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, 15 | EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF 16 | MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND 17 | NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE 18 | LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION 19 | OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION 20 | WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. 21 | -------------------------------------------------------------------------------- /node_modules/node-static/README.md: -------------------------------------------------------------------------------- 1 | node-static 2 | =========== 3 | 4 | > a simple, *rfc 2616 compliant* file streaming module for [node](http://nodejs.org) 5 | 6 | node-static has an in-memory file cache, making it highly efficient. 7 | node-static understands and supports *conditional GET* and *HEAD* requests. 8 | node-static was inspired by some of the other static-file serving modules out there, 9 | such as node-paperboy and antinode. 10 | 11 | synopsis 12 | -------- 13 | 14 | var static = require('node-static'); 15 | 16 | // 17 | // Create a node-static server instance to serve the './public' folder 18 | // 19 | var file = new(static.Server)('./public'); 20 | 21 | require('http').createServer(function (request, response) { 22 | request.addListener('end', function () { 23 | // 24 | // Serve files! 25 | // 26 | file.serve(request, response); 27 | }); 28 | }).listen(8080); 29 | 30 | API 31 | --- 32 | 33 | ### Creating a node-static Server # 34 | 35 | Creating a file server instance is as simple as: 36 | 37 | new static.Server(); 38 | 39 | This will serve files in the current directory. If you want to serve files in a specific 40 | directory, pass it as the first argument: 41 | 42 | new static.Server('./public'); 43 | 44 | You can also specify how long the client is supposed to cache the files node-static serves: 45 | 46 | new static.Server('./public', { cache: 3600 }); 47 | 48 | This will set the `Cache-Control` header, telling clients to cache the file for an hour. 49 | This is the default setting. 50 | 51 | ### Serving files under a directory # 52 | 53 | To serve files under a directory, simply call the `serve` method on a `Server` instance, passing it 54 | the HTTP request and response object: 55 | 56 | var fileServer = new static.Server('./public'); 57 | 58 | require('http').createServer(function (request, response) { 59 | request.addListener('end', function () { 60 | fileServer.serve(request, response); 61 | }); 62 | }).listen(8080); 63 | 64 | ### Serving specific files # 65 | 66 | If you want to serve a specific file, like an error page for example, use the `serveFile` method: 67 | 68 | fileServer.serveFile('/error.html', 500, {}, request, response); 69 | 70 | This will serve the `error.html` file, from under the file root directory, with a `500` status code. 71 | For example, you could serve an error page, when the initial request wasn't found: 72 | 73 | require('http').createServer(function (request, response) { 74 | request.addListener('end', function () { 75 | fileServer.serve(request, response, function (e, res) { 76 | if (e && (e.status === 404)) { // If the file wasn't found 77 | fileServer.serveFile('/not-found.html', request, response); 78 | } 79 | }); 80 | }); 81 | }).listen(8080); 82 | 83 | More on intercepting errors bellow. 84 | 85 | ### Intercepting errors & Listening # 86 | 87 | An optional callback can be passed as last argument, it will be called every time a file 88 | has been served successfully, or if there was an error serving the file: 89 | 90 | var fileServer = new static.Server('./public'); 91 | 92 | require('http').createServer(function (request, response) { 93 | request.addListener('end', function () { 94 | fileServer.serve(request, response, function (err, result) { 95 | if (err) { // There was an error serving the file 96 | sys.error("Error serving " + request.url + " - " + err.message); 97 | 98 | // Respond to the client 99 | response.writeHead(err.status, err.headers); 100 | response.end(); 101 | } 102 | }); 103 | }); 104 | }).listen(8080); 105 | 106 | Note that if you pass a callback, and there is an error serving the file, node-static 107 | *will not* respond to the client. This gives you the opportunity to re-route the request, 108 | or handle it differently. 109 | 110 | For example, you may want to interpret a request as a static request, but if the file isn't found, 111 | send it to an application. 112 | 113 | If you only want to *listen* for errors, you can use *event listeners*: 114 | 115 | fileServer.serve(request, response).addListener('error', function (err) { 116 | sys.error("Error serving " + request.url + " - " + err.message); 117 | }); 118 | 119 | With this method, you don't have to explicitly send the response back, in case of an error. 120 | 121 | ### Options when creating an instance of `Server` # 122 | 123 | #### `cache` # 124 | 125 | Sets the `Cache-Control` header. 126 | 127 | example: `{ cache: 7200 }` 128 | 129 | Passing a number will set the cache duration to that number of seconds. 130 | Passing `false` will disable the `Cache-Control` header. 131 | 132 | > Defaults to `3600` 133 | 134 | #### `headers` # 135 | 136 | Sets response headers. 137 | 138 | example: `{ 'X-Hello': 'World!' }` 139 | 140 | > defaults to `{}` 141 | 142 | -------------------------------------------------------------------------------- /node_modules/node-static/benchmark/node-static-0.3.0.txt: -------------------------------------------------------------------------------- 1 | This is ApacheBench, Version 2.3 <$Revision: 655654 $> 2 | Copyright 1996 Adam Twiss, Zeus Technology Ltd, http://www.zeustech.net/ 3 | Licensed to The Apache Software Foundation, http://www.apache.org/ 4 | 5 | Benchmarking 127.0.0.1 (be patient) 6 | 7 | 8 | Server Software: node-static/0.3.0 9 | Server Hostname: 127.0.0.1 10 | Server Port: 8080 11 | 12 | Document Path: /lib/node-static.js 13 | Document Length: 6038 bytes 14 | 15 | Concurrency Level: 20 16 | Time taken for tests: 2.323 seconds 17 | Complete requests: 10000 18 | Failed requests: 0 19 | Write errors: 0 20 | Total transferred: 63190000 bytes 21 | HTML transferred: 60380000 bytes 22 | Requests per second: 4304.67 [#/sec] (mean) 23 | Time per request: 4.646 [ms] (mean) 24 | Time per request: 0.232 [ms] (mean, across all concurrent requests) 25 | Transfer rate: 26563.66 [Kbytes/sec] received 26 | 27 | Connection Times (ms) 28 | min mean[+/-sd] median max 29 | Connect: 0 0 0.2 0 3 30 | Processing: 1 4 1.4 4 28 31 | Waiting: 1 4 1.3 4 18 32 | Total: 2 5 1.5 4 28 33 | 34 | Percentage of the requests served within a certain time (ms) 35 | 50% 4 36 | 66% 5 37 | 75% 5 38 | 80% 5 39 | 90% 5 40 | 95% 6 41 | 98% 8 42 | 99% 9 43 | 100% 28 (longest request) 44 | -------------------------------------------------------------------------------- /node_modules/node-static/examples/file-server.js: -------------------------------------------------------------------------------- 1 | var sys = require('sys'); 2 | var static = require('../lib/node-static'); 3 | 4 | // 5 | // Create a node-static server to serve the current directory 6 | // 7 | var file = new(static.Server)('.', { cache: 7200, headers: {'X-Hello':'World!'} }); 8 | 9 | require('http').createServer(function (request, response) { 10 | request.addListener('end', function () { 11 | // 12 | // Serve files! 13 | // 14 | file.serve(request, response, function (err, res) { 15 | if (err) { // An error as occured 16 | sys.error("> Error serving " + request.url + " - " + err.message); 17 | response.writeHead(err.status, err.headers); 18 | response.end(); 19 | } else { // The file was served successfully 20 | sys.puts("> " + request.url + " - " + res.message); 21 | } 22 | }); 23 | }); 24 | }).listen(8080); 25 | 26 | sys.puts("> node-static is listening on http://127.0.0.1:8080"); 27 | -------------------------------------------------------------------------------- /node_modules/node-static/lib/node-static.js: -------------------------------------------------------------------------------- 1 | var fs = require('fs'), 2 | sys = require('sys'), 3 | events = require('events'), 4 | buffer = require('buffer'), 5 | http = require('http'), 6 | url = require('url'), 7 | path = require('path'); 8 | 9 | this.version = [0, 5, 9]; 10 | 11 | var mime = require('./node-static/mime'); 12 | var util = require('./node-static/util'); 13 | 14 | var serverInfo = 'node-static/' + this.version.join('.'); 15 | 16 | // In-memory file store 17 | this.store = {}; 18 | this.indexStore = {}; 19 | 20 | this.Server = function (root, options) { 21 | if (root && (typeof(root) === 'object')) { options = root, root = null } 22 | 23 | this.root = path.resolve(root || '.'); 24 | this.options = options || {}; 25 | this.cache = 3600; 26 | 27 | this.defaultHeaders = {}; 28 | this.options.headers = this.options.headers || {}; 29 | 30 | if ('cache' in this.options) { 31 | if (typeof(this.options.cache) === 'number') { 32 | this.cache = this.options.cache; 33 | } else if (! this.options.cache) { 34 | this.cache = false; 35 | } 36 | } 37 | 38 | if (this.cache !== false) { 39 | this.defaultHeaders['Cache-Control'] = 'max-age=' + this.cache; 40 | } 41 | this.defaultHeaders['Server'] = serverInfo; 42 | 43 | for (var k in this.defaultHeaders) { 44 | this.options.headers[k] = this.options.headers[k] || 45 | this.defaultHeaders[k]; 46 | } 47 | }; 48 | 49 | this.Server.prototype.serveDir = function (pathname, req, res, finish) { 50 | var htmlIndex = path.join(pathname, 'index.html'), 51 | that = this; 52 | 53 | fs.stat(htmlIndex, function (e, stat) { 54 | if (!e) { 55 | that.respond(null, 200, {}, [htmlIndex], stat, req, res, finish); 56 | } else { 57 | if (pathname in exports.store) { 58 | streamFiles(exports.indexStore[pathname].files); 59 | } else { 60 | // Stream a directory of files as a single file. 61 | fs.readFile(path.join(pathname, 'index.json'), function (e, contents) { 62 | if (e) { return finish(404, {}) } 63 | var index = JSON.parse(contents); 64 | exports.indexStore[pathname] = index; 65 | streamFiles(index.files); 66 | }); 67 | } 68 | } 69 | }); 70 | function streamFiles(files) { 71 | util.mstat(pathname, files, function (e, stat) { 72 | that.respond(pathname, 200, {}, files, stat, req, res, finish); 73 | }); 74 | } 75 | }; 76 | this.Server.prototype.serveFile = function (pathname, status, headers, req, res) { 77 | var that = this; 78 | var promise = new(events.EventEmitter); 79 | 80 | pathname = this.resolve(pathname); 81 | 82 | fs.stat(pathname, function (e, stat) { 83 | if (e) { 84 | return promise.emit('error', e); 85 | } 86 | that.respond(null, status, headers, [pathname], stat, req, res, function (status, headers) { 87 | that.finish(status, headers, req, res, promise); 88 | }); 89 | }); 90 | return promise; 91 | }; 92 | this.Server.prototype.finish = function (status, headers, req, res, promise, callback) { 93 | var result = { 94 | status: status, 95 | headers: headers, 96 | message: http.STATUS_CODES[status] 97 | }; 98 | 99 | headers['Server'] = serverInfo; 100 | 101 | if (!status || status >= 400) { 102 | if (callback) { 103 | callback(result); 104 | } else { 105 | if (promise.listeners('error').length > 0) { 106 | promise.emit('error', result); 107 | } 108 | res.writeHead(status, headers); 109 | res.end(); 110 | } 111 | } else { 112 | // Don't end the request here, if we're streaming; 113 | // it's taken care of in `prototype.stream`. 114 | if (status !== 200 || req.method !== 'GET') { 115 | res.writeHead(status, headers); 116 | res.end(); 117 | } 118 | callback && callback(null, result); 119 | promise.emit('success', result); 120 | } 121 | }; 122 | 123 | this.Server.prototype.servePath = function (pathname, status, headers, req, res, finish) { 124 | var that = this, 125 | promise = new(events.EventEmitter); 126 | 127 | pathname = this.resolve(pathname); 128 | 129 | // Only allow GET and HEAD requests 130 | if (req.method !== 'GET' && req.method !== 'HEAD') { 131 | finish(405, { 'Allow': 'GET, HEAD' }); 132 | return promise; 133 | } 134 | 135 | // Make sure we're not trying to access a 136 | // file outside of the root. 137 | if (pathname.indexOf(that.root) === 0) { 138 | fs.stat(pathname, function (e, stat) { 139 | if (e) { 140 | finish(404, {}); 141 | } else if (stat.isFile()) { // Stream a single file. 142 | that.respond(null, status, headers, [pathname], stat, req, res, finish); 143 | } else if (stat.isDirectory()) { // Stream a directory of files. 144 | that.serveDir(pathname, req, res, finish); 145 | } else { 146 | finish(400, {}); 147 | } 148 | }); 149 | } else { 150 | // Forbidden 151 | finish(403, {}); 152 | } 153 | return promise; 154 | }; 155 | this.Server.prototype.resolve = function (pathname) { 156 | return path.resolve(path.join(this.root, pathname)); 157 | }; 158 | this.Server.prototype.serve = function (req, res, callback) { 159 | var that = this, 160 | promise = new(events.EventEmitter); 161 | 162 | var pathname = decodeURI(url.parse(req.url).pathname); 163 | 164 | var finish = function (status, headers) { 165 | that.finish(status, headers, req, res, promise, callback); 166 | }; 167 | 168 | process.nextTick(function () { 169 | that.servePath(pathname, 200, {}, req, res, finish).on('success', function (result) { 170 | promise.emit('success', result); 171 | }).on('error', function (err) { 172 | promise.emit('error'); 173 | }); 174 | }); 175 | if (! callback) { return promise } 176 | }; 177 | 178 | this.Server.prototype.respond = function (pathname, status, _headers, files, stat, req, res, finish) { 179 | var mtime = Date.parse(stat.mtime), 180 | key = pathname || files[0], 181 | headers = {}; 182 | 183 | // Copy default headers 184 | for (var k in this.options.headers) { headers[k] = this.options.headers[k] } 185 | 186 | headers['Etag'] = JSON.stringify([stat.ino, stat.size, mtime].join('-')); 187 | headers['Date'] = new(Date)().toUTCString(); 188 | headers['Last-Modified'] = new(Date)(stat.mtime).toUTCString(); 189 | 190 | // Conditional GET 191 | // If the "If-Modified-Since" or "If-None-Match" headers 192 | // match the conditions, send a 304 Not Modified. 193 | if (req.headers['if-none-match'] === headers['Etag'] || 194 | Date.parse(req.headers['if-modified-since']) >= mtime) { 195 | finish(304, headers); 196 | } else if (req.method === 'HEAD') { 197 | finish(200, headers); 198 | } else { 199 | headers['Content-Length'] = stat.size; 200 | headers['Content-Type'] = mime.contentTypes[path.extname(files[0]).slice(1)] || 201 | 'application/octet-stream'; 202 | 203 | for (var k in _headers) { headers[k] = _headers[k] } 204 | 205 | res.writeHead(status, headers); 206 | 207 | // If the file was cached and it's not older 208 | // than what's on disk, serve the cached version. 209 | if (this.cache && (key in exports.store) && 210 | exports.store[key].stat.mtime >= stat.mtime) { 211 | res.end(exports.store[key].buffer); 212 | finish(status, headers); 213 | } else { 214 | this.stream(pathname, files, new(buffer.Buffer)(stat.size), res, function (e, buffer) { 215 | if (e) { return finish(500, {}) } 216 | exports.store[key] = { 217 | stat: stat, 218 | buffer: buffer, 219 | timestamp: Date.now() 220 | }; 221 | finish(status, headers); 222 | }); 223 | } 224 | } 225 | }; 226 | 227 | this.Server.prototype.stream = function (pathname, files, buffer, res, callback) { 228 | (function streamFile(files, offset) { 229 | var file = files.shift(); 230 | 231 | if (file) { 232 | file = file[0] === '/' ? file : path.join(pathname || '.', file); 233 | 234 | // Stream the file to the client 235 | fs.createReadStream(file, { 236 | flags: 'r', 237 | mode: 0666 238 | }).on('data', function (chunk) { 239 | chunk.copy(buffer, offset); 240 | offset += chunk.length; 241 | }).on('close', function () { 242 | streamFile(files, offset); 243 | }).on('error', function (err) { 244 | callback(err); 245 | console.error(err); 246 | }).pipe(res, { end: false }); 247 | } else { 248 | res.end(); 249 | callback(null, buffer, offset); 250 | } 251 | })(files.slice(0), 0); 252 | }; 253 | -------------------------------------------------------------------------------- /node_modules/node-static/lib/node-static/mime.js: -------------------------------------------------------------------------------- 1 | this.contentTypes = { 2 | "aiff": "audio/x-aiff", 3 | "arj": "application/x-arj-compressed", 4 | "asf": "video/x-ms-asf", 5 | "asx": "video/x-ms-asx", 6 | "au": "audio/ulaw", 7 | "avi": "video/x-msvideo", 8 | "bcpio": "application/x-bcpio", 9 | "ccad": "application/clariscad", 10 | "cod": "application/vnd.rim.cod", 11 | "com": "application/x-msdos-program", 12 | "cpio": "application/x-cpio", 13 | "cpt": "application/mac-compactpro", 14 | "csh": "application/x-csh", 15 | "css": "text/css", 16 | "deb": "application/x-debian-package", 17 | "dl": "video/dl", 18 | "doc": "application/msword", 19 | "drw": "application/drafting", 20 | "dvi": "application/x-dvi", 21 | "dwg": "application/acad", 22 | "dxf": "application/dxf", 23 | "dxr": "application/x-director", 24 | "etx": "text/x-setext", 25 | "ez": "application/andrew-inset", 26 | "fli": "video/x-fli", 27 | "flv": "video/x-flv", 28 | "gif": "image/gif", 29 | "gl": "video/gl", 30 | "gtar": "application/x-gtar", 31 | "gz": "application/x-gzip", 32 | "hdf": "application/x-hdf", 33 | "hqx": "application/mac-binhex40", 34 | "html": "text/html", 35 | "ice": "x-conference/x-cooltalk", 36 | "ico": "image/x-icon", 37 | "ief": "image/ief", 38 | "igs": "model/iges", 39 | "ips": "application/x-ipscript", 40 | "ipx": "application/x-ipix", 41 | "jad": "text/vnd.sun.j2me.app-descriptor", 42 | "jar": "application/java-archive", 43 | "jpeg": "image/jpeg", 44 | "jpg": "image/jpeg", 45 | "js": "text/javascript", 46 | "json": "application/json", 47 | "latex": "application/x-latex", 48 | "less": "text/css", 49 | "lsp": "application/x-lisp", 50 | "lzh": "application/octet-stream", 51 | "m": "text/plain", 52 | "m3u": "audio/x-mpegurl", 53 | "man": "application/x-troff-man", 54 | "manifest": "text/cache-manifest", 55 | "me": "application/x-troff-me", 56 | "midi": "audio/midi", 57 | "mif": "application/x-mif", 58 | "mime": "www/mime", 59 | "movie": "video/x-sgi-movie", 60 | "mp4": "video/mp4", 61 | "mpg": "video/mpeg", 62 | "mpga": "audio/mpeg", 63 | "ms": "application/x-troff-ms", 64 | "nc": "application/x-netcdf", 65 | "oda": "application/oda", 66 | "ogm": "application/ogg", 67 | "pbm": "image/x-portable-bitmap", 68 | "pdf": "application/pdf", 69 | "pgm": "image/x-portable-graymap", 70 | "pgn": "application/x-chess-pgn", 71 | "pgp": "application/pgp", 72 | "pm": "application/x-perl", 73 | "png": "image/png", 74 | "pnm": "image/x-portable-anymap", 75 | "ppm": "image/x-portable-pixmap", 76 | "ppz": "application/vnd.ms-powerpoint", 77 | "pre": "application/x-freelance", 78 | "prt": "application/pro_eng", 79 | "ps": "application/postscript", 80 | "qt": "video/quicktime", 81 | "ra": "audio/x-realaudio", 82 | "rar": "application/x-rar-compressed", 83 | "ras": "image/x-cmu-raster", 84 | "rgb": "image/x-rgb", 85 | "rm": "audio/x-pn-realaudio", 86 | "rpm": "audio/x-pn-realaudio-plugin", 87 | "rtf": "text/rtf", 88 | "rtx": "text/richtext", 89 | "scm": "application/x-lotusscreencam", 90 | "set": "application/set", 91 | "sgml": "text/sgml", 92 | "sh": "application/x-sh", 93 | "shar": "application/x-shar", 94 | "silo": "model/mesh", 95 | "sit": "application/x-stuffit", 96 | "skt": "application/x-koan", 97 | "smil": "application/smil", 98 | "snd": "audio/basic", 99 | "sol": "application/solids", 100 | "spl": "application/x-futuresplash", 101 | "src": "application/x-wais-source", 102 | "stl": "application/SLA", 103 | "stp": "application/STEP", 104 | "sv4cpio": "application/x-sv4cpio", 105 | "sv4crc": "application/x-sv4crc", 106 | "svg": "image/svg+xml", 107 | "swf": "application/x-shockwave-flash", 108 | "tar": "application/x-tar", 109 | "tcl": "application/x-tcl", 110 | "tex": "application/x-tex", 111 | "texinfo": "application/x-texinfo", 112 | "tgz": "application/x-tar-gz", 113 | "tiff": "image/tiff", 114 | "tr": "application/x-troff", 115 | "tsi": "audio/TSP-audio", 116 | "tsp": "application/dsptype", 117 | "tsv": "text/tab-separated-values", 118 | "txt": "text/plain", 119 | "unv": "application/i-deas", 120 | "ustar": "application/x-ustar", 121 | "vcd": "application/x-cdlink", 122 | "vda": "application/vda", 123 | "vivo": "video/vnd.vivo", 124 | "vrm": "x-world/x-vrml", 125 | "wav": "audio/x-wav", 126 | "wax": "audio/x-ms-wax", 127 | "wma": "audio/x-ms-wma", 128 | "wmv": "video/x-ms-wmv", 129 | "wmx": "video/x-ms-wmx", 130 | "wrl": "model/vrml", 131 | "wvx": "video/x-ms-wvx", 132 | "xbm": "image/x-xbitmap", 133 | "xlw": "application/vnd.ms-excel", 134 | "xml": "text/xml", 135 | "xpm": "image/x-xpixmap", 136 | "xwd": "image/x-xwindowdump", 137 | "xyz": "chemical/x-pdb", 138 | "zip": "application/zip" 139 | }; 140 | -------------------------------------------------------------------------------- /node_modules/node-static/lib/node-static/util.js: -------------------------------------------------------------------------------- 1 | var fs = require('fs'), 2 | path = require('path'); 3 | 4 | this.mstat = function (dir, files, callback) { 5 | (function mstat(files, stats) { 6 | var file = files.shift(); 7 | 8 | if (file) { 9 | fs.stat(path.join(dir, file), function (e, stat) { 10 | if (e) { 11 | callback(e); 12 | } else { 13 | mstat(files, stats.concat([stat])); 14 | } 15 | }); 16 | } else { 17 | callback(null, { 18 | size: stats.reduce(function (total, stat) { 19 | return total + stat.size; 20 | }, 0), 21 | mtime: stats.reduce(function (latest, stat) { 22 | return latest > stat.mtime ? latest : stat.mtime; 23 | }, 0), 24 | ino: stats.reduce(function (total, stat) { 25 | return total + stat.ino; 26 | }, 0) 27 | }); 28 | } 29 | })(files.slice(0), []); 30 | }; 31 | -------------------------------------------------------------------------------- /node_modules/node-static/package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name" : "node-static", 3 | "description" : "simple, compliant file streaming module for node", 4 | "url" : "http://github.com/cloudhead/node-static", 5 | "keywords" : ["http", "static", "file", "server"], 6 | "author" : "Alexis Sellier ", 7 | "contributors" : [], 8 | "licenses" : ["MIT"], 9 | "dependencies" : [], 10 | "lib" : "lib", 11 | "main" : "./lib/node-static", 12 | "version" : "0.5.9", 13 | "directories" : { "test": "./test" }, 14 | "engines" : { "node": ">= 0.4.1" } 15 | } 16 | -------------------------------------------------------------------------------- /node_modules/uglify-js/.gitignore: -------------------------------------------------------------------------------- 1 | .DS_Store 2 | .tmp*~ 3 | *.local.* 4 | .pinf-* -------------------------------------------------------------------------------- /node_modules/uglify-js/README.org: -------------------------------------------------------------------------------- 1 | #+TITLE: UglifyJS -- a JavaScript parser/compressor/beautifier 2 | #+KEYWORDS: javascript, js, parser, compiler, compressor, mangle, minify, minifier 3 | #+DESCRIPTION: a JavaScript parser/compressor/beautifier in JavaScript 4 | #+STYLE: 5 | #+AUTHOR: Mihai Bazon 6 | #+EMAIL: mihai.bazon@gmail.com 7 | 8 | * UglifyJS --- a JavaScript parser/compressor/beautifier 9 | 10 | This package implements a general-purpose JavaScript 11 | parser/compressor/beautifier toolkit. It is developed on [[http://nodejs.org/][NodeJS]], but it 12 | should work on any JavaScript platform supporting the CommonJS module system 13 | (and if your platform of choice doesn't support CommonJS, you can easily 14 | implement it, or discard the =exports.*= lines from UglifyJS sources). 15 | 16 | The tokenizer/parser generates an abstract syntax tree from JS code. You 17 | can then traverse the AST to learn more about the code, or do various 18 | manipulations on it. This part is implemented in [[../lib/parse-js.js][parse-js.js]] and it's a 19 | port to JavaScript of the excellent [[http://marijn.haverbeke.nl/parse-js/][parse-js]] Common Lisp library from [[http://marijn.haverbeke.nl/][Marijn 20 | Haverbeke]]. 21 | 22 | ( See [[http://github.com/mishoo/cl-uglify-js][cl-uglify-js]] if you're looking for the Common Lisp version of 23 | UglifyJS. ) 24 | 25 | The second part of this package, implemented in [[../lib/process.js][process.js]], inspects and 26 | manipulates the AST generated by the parser to provide the following: 27 | 28 | - ability to re-generate JavaScript code from the AST. Optionally 29 | indented---you can use this if you want to “beautify” a program that has 30 | been compressed, so that you can inspect the source. But you can also run 31 | our code generator to print out an AST without any whitespace, so you 32 | achieve compression as well. 33 | 34 | - shorten variable names (usually to single characters). Our mangler will 35 | analyze the code and generate proper variable names, depending on scope 36 | and usage, and is smart enough to deal with globals defined elsewhere, or 37 | with =eval()= calls or =with{}= statements. In short, if =eval()= or 38 | =with{}= are used in some scope, then all variables in that scope and any 39 | variables in the parent scopes will remain unmangled, and any references 40 | to such variables remain unmangled as well. 41 | 42 | - various small optimizations that may lead to faster code but certainly 43 | lead to smaller code. Where possible, we do the following: 44 | 45 | - foo["bar"] ==> foo.bar 46 | 47 | - remove block brackets ={}= 48 | 49 | - join consecutive var declarations: 50 | var a = 10; var b = 20; ==> var a=10,b=20; 51 | 52 | - resolve simple constant expressions: 1 +2 * 3 ==> 7. We only do the 53 | replacement if the result occupies less bytes; for example 1/3 would 54 | translate to 0.333333333333, so in this case we don't replace it. 55 | 56 | - consecutive statements in blocks are merged into a sequence; in many 57 | cases, this leaves blocks with a single statement, so then we can remove 58 | the block brackets. 59 | 60 | - various optimizations for IF statements: 61 | 62 | - if (foo) bar(); else baz(); ==> foo?bar():baz(); 63 | - if (!foo) bar(); else baz(); ==> foo?baz():bar(); 64 | - if (foo) bar(); ==> foo&&bar(); 65 | - if (!foo) bar(); ==> foo||bar(); 66 | - if (foo) return bar(); else return baz(); ==> return foo?bar():baz(); 67 | - if (foo) return bar(); else something(); ==> {if(foo)return bar();something()} 68 | 69 | - remove some unreachable code and warn about it (code that follows a 70 | =return=, =throw=, =break= or =continue= statement, except 71 | function/variable declarations). 72 | 73 | - act a limited version of a pre-processor (c.f. the pre-processor of 74 | C/C++) to allow you to safely replace selected global symbols with 75 | specified values. When combined with the optimisations above this can 76 | make UglifyJS operate slightly more like a compilation process, in 77 | that when certain symbols are replaced by constant values, entire code 78 | blocks may be optimised away as unreachable. 79 | 80 | ** <> 81 | 82 | The following transformations can in theory break code, although they're 83 | probably safe in most practical cases. To enable them you need to pass the 84 | =--unsafe= flag. 85 | 86 | *** Calls involving the global Array constructor 87 | 88 | The following transformations occur: 89 | 90 | #+BEGIN_SRC js 91 | new Array(1, 2, 3, 4) => [1,2,3,4] 92 | Array(a, b, c) => [a,b,c] 93 | new Array(5) => Array(5) 94 | new Array(a) => Array(a) 95 | #+END_SRC 96 | 97 | These are all safe if the Array name isn't redefined. JavaScript does allow 98 | one to globally redefine Array (and pretty much everything, in fact) but I 99 | personally don't see why would anyone do that. 100 | 101 | UglifyJS does handle the case where Array is redefined locally, or even 102 | globally but with a =function= or =var= declaration. Therefore, in the 103 | following cases UglifyJS *doesn't touch* calls or instantiations of Array: 104 | 105 | #+BEGIN_SRC js 106 | // case 1. globally declared variable 107 | var Array; 108 | new Array(1, 2, 3); 109 | Array(a, b); 110 | 111 | // or (can be declared later) 112 | new Array(1, 2, 3); 113 | var Array; 114 | 115 | // or (can be a function) 116 | new Array(1, 2, 3); 117 | function Array() { ... } 118 | 119 | // case 2. declared in a function 120 | (function(){ 121 | a = new Array(1, 2, 3); 122 | b = Array(5, 6); 123 | var Array; 124 | })(); 125 | 126 | // or 127 | (function(Array){ 128 | return Array(5, 6, 7); 129 | })(); 130 | 131 | // or 132 | (function(){ 133 | return new Array(1, 2, 3, 4); 134 | function Array() { ... } 135 | })(); 136 | 137 | // etc. 138 | #+END_SRC 139 | 140 | *** =obj.toString()= ==> =obj+“”= 141 | 142 | ** Install (NPM) 143 | 144 | UglifyJS is now available through NPM --- =npm install uglify-js= should do 145 | the job. 146 | 147 | ** Install latest code from GitHub 148 | 149 | #+BEGIN_SRC sh 150 | ## clone the repository 151 | mkdir -p /where/you/wanna/put/it 152 | cd /where/you/wanna/put/it 153 | git clone git://github.com/mishoo/UglifyJS.git 154 | 155 | ## make the module available to Node 156 | mkdir -p ~/.node_libraries/ 157 | cd ~/.node_libraries/ 158 | ln -s /where/you/wanna/put/it/UglifyJS/uglify-js.js 159 | 160 | ## and if you want the CLI script too: 161 | mkdir -p ~/bin 162 | cd ~/bin 163 | ln -s /where/you/wanna/put/it/UglifyJS/bin/uglifyjs 164 | # (then add ~/bin to your $PATH if it's not there already) 165 | #+END_SRC 166 | 167 | ** Usage 168 | 169 | There is a command-line tool that exposes the functionality of this library 170 | for your shell-scripting needs: 171 | 172 | #+BEGIN_SRC sh 173 | uglifyjs [ options... ] [ filename ] 174 | #+END_SRC 175 | 176 | =filename= should be the last argument and should name the file from which 177 | to read the JavaScript code. If you don't specify it, it will read code 178 | from STDIN. 179 | 180 | Supported options: 181 | 182 | - =-b= or =--beautify= --- output indented code; when passed, additional 183 | options control the beautifier: 184 | 185 | - =-i N= or =--indent N= --- indentation level (number of spaces) 186 | 187 | - =-q= or =--quote-keys= --- quote keys in literal objects (by default, 188 | only keys that cannot be identifier names will be quotes). 189 | 190 | - =--ascii= --- pass this argument to encode non-ASCII characters as 191 | =\uXXXX= sequences. By default UglifyJS won't bother to do it and will 192 | output Unicode characters instead. (the output is always encoded in UTF8, 193 | but if you pass this option you'll only get ASCII). 194 | 195 | - =-nm= or =--no-mangle= --- don't mangle variable names 196 | 197 | - =-ns= or =--no-squeeze= --- don't call =ast_squeeze()= (which does various 198 | optimizations that result in smaller, less readable code). 199 | 200 | - =-mt= or =--mangle-toplevel= --- mangle names in the toplevel scope too 201 | (by default we don't do this). 202 | 203 | - =--no-seqs= --- when =ast_squeeze()= is called (thus, unless you pass 204 | =--no-squeeze=) it will reduce consecutive statements in blocks into a 205 | sequence. For example, "a = 10; b = 20; foo();" will be written as 206 | "a=10,b=20,foo();". In various occasions, this allows us to discard the 207 | block brackets (since the block becomes a single statement). This is ON 208 | by default because it seems safe and saves a few hundred bytes on some 209 | libs that I tested it on, but pass =--no-seqs= to disable it. 210 | 211 | - =--no-dead-code= --- by default, UglifyJS will remove code that is 212 | obviously unreachable (code that follows a =return=, =throw=, =break= or 213 | =continue= statement and is not a function/variable declaration). Pass 214 | this option to disable this optimization. 215 | 216 | - =-nc= or =--no-copyright= --- by default, =uglifyjs= will keep the initial 217 | comment tokens in the generated code (assumed to be copyright information 218 | etc.). If you pass this it will discard it. 219 | 220 | - =-o filename= or =--output filename= --- put the result in =filename=. If 221 | this isn't given, the result goes to standard output (or see next one). 222 | 223 | - =--overwrite= --- if the code is read from a file (not from STDIN) and you 224 | pass =--overwrite= then the output will be written in the same file. 225 | 226 | - =--ast= --- pass this if you want to get the Abstract Syntax Tree instead 227 | of JavaScript as output. Useful for debugging or learning more about the 228 | internals. 229 | 230 | - =-v= or =--verbose= --- output some notes on STDERR (for now just how long 231 | each operation takes). 232 | 233 | - =-d SYMBOL[=VALUE]= or =--define SYMBOL[=VALUE]= --- will replace 234 | all instances of the specified symbol where used as an identifier 235 | (except where symbol has properly declared by a var declaration or 236 | use as function parameter or similar) with the specified value. This 237 | argument may be specified multiple times to define multiple 238 | symbols - if no value is specified the symbol will be replaced with 239 | the value =true=, or you can specify a numeric value (such as 240 | =1024=), a quoted string value (such as ="object"= or 241 | ='https://github.com'=), or the name of another symbol or keyword 242 | (such as =null= or =document=). 243 | This allows you, for example, to assign meaningful names to key 244 | constant values but discard the symbolic names in the uglified 245 | version for brevity/efficiency, or when used wth care, allows 246 | UglifyJS to operate as a form of *conditional compilation* 247 | whereby defining appropriate values may, by dint of the constant 248 | folding and dead code removal features above, remove entire 249 | superfluous code blocks (e.g. completely remove instrumentation or 250 | trace code for production use). 251 | Where string values are being defined, the handling of quotes are 252 | likely to be subject to the specifics of your command shell 253 | environment, so you may need to experiment with quoting styles 254 | depending on your platform, or you may find the option 255 | =--define-from-module= more suitable for use. 256 | 257 | - =-define-from-module SOMEMODULE= --- will load the named module (as 258 | per the NodeJS =require()= function) and iterate all the exported 259 | properties of the module defining them as symbol names to be defined 260 | (as if by the =--define= option) per the name of each property 261 | (i.e. without the module name prefix) and given the value of the 262 | property. This is a much easier way to handle and document groups of 263 | symbols to be defined rather than a large number of =--define= 264 | options. 265 | 266 | - =--unsafe= --- enable other additional optimizations that are known to be 267 | unsafe in some contrived situations, but could still be generally useful. 268 | For now only these: 269 | 270 | - foo.toString() ==> foo+"" 271 | - new Array(x,...) ==> [x,...] 272 | - new Array(x) ==> Array(x) 273 | 274 | - =--max-line-len= (default 32K characters) --- add a newline after around 275 | 32K characters. I've seen both FF and Chrome croak when all the code was 276 | on a single line of around 670K. Pass --max-line-len 0 to disable this 277 | safety feature. 278 | 279 | - =--reserved-names= --- some libraries rely on certain names to be used, as 280 | pointed out in issue #92 and #81, so this option allow you to exclude such 281 | names from the mangler. For example, to keep names =require= and =$super= 282 | intact you'd specify --reserved-names "require,$super". 283 | 284 | - =--inline-script= -- when you want to include the output literally in an 285 | HTML = 8 | 9 | 10 | 11 | 12 |

module.js deferred() test

13 |

14 |

15 |
    16 | 17 | 101 | 102 | -------------------------------------------------------------------------------- /test/commonjs_test.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | requirejs plugin test 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 |

    requirejs plugin test

    14 |

    15 |

    16 |
      17 | 18 | 60 | 61 | -------------------------------------------------------------------------------- /test/data.json: -------------------------------------------------------------------------------- 1 | { "success": true } -------------------------------------------------------------------------------- /test/deferred_test.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | deferred plugin test 6 | 7 | 8 | 9 | 10 | 11 | 12 |

      module.js deferred() test

      13 |

      14 |

      15 |
        16 | 17 | 75 | 76 | -------------------------------------------------------------------------------- /test/index.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | Loadrunner and plugin tests 6 | 22 | 23 | 24 |

        Loadrunner core tests

        25 | 26 | 27 |

        AMD plugin tests

        28 | 29 | 30 |

        JSON plugin tests

        31 | 32 | 33 |

        Deferred plugin tests

        34 | 35 | 36 |

        CommonJS plugin tests

        37 | 38 | 39 | -------------------------------------------------------------------------------- /test/javascripts/a.js: -------------------------------------------------------------------------------- 1 | loadedA = true; -------------------------------------------------------------------------------- /test/javascripts/b.js: -------------------------------------------------------------------------------- 1 | bLoadCount++; -------------------------------------------------------------------------------- /test/javascripts/c.js: -------------------------------------------------------------------------------- 1 | loadedC = true; -------------------------------------------------------------------------------- /test/javascripts/compiled.js: -------------------------------------------------------------------------------- 1 | provide("moda",{test:"success"});using.loaded.push("moda");provide("modc",function(a){using("moda",function(b){a({test:function(){return b.test+" from mod a"}})})});using.loaded.push("modc");provide("modcompiled",function(a){using("modc",function(b){a({test:function(){return b.test()+" via modcompiled"}})})});using.loaded.push("modcompiled");provide("modcompiled",function(a){using("modc",function(b){a({test:function(){return b.test()+" via modcompiled"}})})});using.loaded.push("modules/modcompiled.js"); -------------------------------------------------------------------------------- /test/javascripts/d.js: -------------------------------------------------------------------------------- 1 | loadedD = true; -------------------------------------------------------------------------------- /test/javascripts/deferred_bundle.js: -------------------------------------------------------------------------------- 1 | deferred('bundled_thing.js', function() { 2 | window.bundleLoadedThing = true; 3 | }); 4 | 5 | deferred('bundled_another.js', function() { 6 | window.bundleLoadedAnother = true; 7 | }); 8 | 9 | deferred('$bundled_with_modpath.js', function() { 10 | window.bundleLoadedModpath = true; 11 | }); -------------------------------------------------------------------------------- /test/javascripts/deferred_scripts.js: -------------------------------------------------------------------------------- 1 | deferred('thing.js', function() { 2 | window.loadedThing = true; 3 | }); 4 | 5 | deferred('another.js', function() { 6 | window.loadedAnother = true; 7 | }) -------------------------------------------------------------------------------- /test/javascripts/e.js: -------------------------------------------------------------------------------- 1 | loadedE = true; -------------------------------------------------------------------------------- /test/javascripts/main.js: -------------------------------------------------------------------------------- 1 | mainLoaded = true; -------------------------------------------------------------------------------- /test/javascripts/modcompiled.js: -------------------------------------------------------------------------------- 1 | provide('modcompiled', function(exports) { 2 | using('modc', function(modc) { 3 | exports({ 4 | test: function() { 5 | return modc.test() + ' via modcompiled'; 6 | } 7 | }); 8 | }); 9 | }); -------------------------------------------------------------------------------- /test/javascripts/s1.js: -------------------------------------------------------------------------------- 1 | window.testSeq.push(1); -------------------------------------------------------------------------------- /test/javascripts/s2.js: -------------------------------------------------------------------------------- 1 | window.testSeq.push(2); -------------------------------------------------------------------------------- /test/javascripts/s3.js: -------------------------------------------------------------------------------- 1 | window.testSeq.push(3); -------------------------------------------------------------------------------- /test/json_test.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | json plugin test 6 | 7 | 8 | 9 | 10 | 11 | 12 |

        json test

        13 |

        14 |

        15 |
          16 | 17 | 33 | 34 | -------------------------------------------------------------------------------- /test/modules/amd/dotdotslash.js: -------------------------------------------------------------------------------- 1 | define(['../sub/submodb'], function(modb) { 2 | return { 3 | modb: modb.test() 4 | }; 5 | }); -------------------------------------------------------------------------------- /test/modules/amd/moda.js: -------------------------------------------------------------------------------- 1 | define(['moda'], function(moda) { 2 | return { 3 | moda: moda.test 4 | }; 5 | }); -------------------------------------------------------------------------------- /test/modules/amd/modb.js: -------------------------------------------------------------------------------- 1 | define(function() { 2 | return { 3 | test: function() { 4 | return 'AMD success'; 5 | } 6 | }; 7 | }); -------------------------------------------------------------------------------- /test/modules/amd/modlit.js: -------------------------------------------------------------------------------- 1 | define({ 2 | test: 'success' 3 | }); -------------------------------------------------------------------------------- /test/modules/amd/modnodep.js: -------------------------------------------------------------------------------- 1 | define(function() { 2 | return { 3 | test: 'success' 4 | }; 5 | }); -------------------------------------------------------------------------------- /test/modules/amd/modrel.js: -------------------------------------------------------------------------------- 1 | define(['./modb'], function(modb) { 2 | return { 3 | modb: modb.test() 4 | }; 5 | }); -------------------------------------------------------------------------------- /test/modules/app.js: -------------------------------------------------------------------------------- 1 | provide('app', function(exports) { 2 | using('modd', function(d) { 3 | console.log(d.test()); 4 | }); 5 | 6 | exports(); 7 | }) -------------------------------------------------------------------------------- /test/modules/ded-a.js: -------------------------------------------------------------------------------- 1 | provide('ded-a', function (exports) { 2 | using('ded-b1', 'ded-b2', 3 | function (b1, b2) { 4 | exports(b1 == b2); 5 | }); 6 | 7 | }); 8 | -------------------------------------------------------------------------------- /test/modules/ded-b1.js: -------------------------------------------------------------------------------- 1 | provide('ded-b1', function (exports) { 2 | using('javascripts/a.js', function () { 3 | exports(loadedA); 4 | }); 5 | }); -------------------------------------------------------------------------------- /test/modules/ded-b2.js: -------------------------------------------------------------------------------- 1 | provide('ded-b2', function (exports) { 2 | using('ded-b1', function (b1) { 3 | exports(b1); 4 | }); 5 | }); -------------------------------------------------------------------------------- /test/modules/deep.js: -------------------------------------------------------------------------------- 1 | provide(function(exports) { 2 | var limit = 2000; 3 | var dep = 'moda'; 4 | for (var i=0;i 2 | 3 | 4 | 5 | loadrunner test 6 | 7 | 8 | 9 | 10 |

          module.js test

          11 |

          12 |

          13 |
            14 | 15 | 437 | 438 | 473 | 474 | -------------------------------------------------------------------------------- /vendor/qunit/qunit.css: -------------------------------------------------------------------------------- 1 | /** Font Family and Sizes */ 2 | 3 | #qunit-tests, #qunit-header, #qunit-banner, #qunit-testrunner-toolbar, #qunit-userAgent, #qunit-testresult { 4 | font-family: "Helvetica Neue Light", "HelveticaNeue-Light", "Helvetica Neue", Calibri, Helvetica, Arial; 5 | } 6 | 7 | #qunit-testrunner-toolbar, #qunit-userAgent, #qunit-testresult, #qunit-tests li { font-size: small; } 8 | #qunit-tests { font-size: smaller; } 9 | 10 | 11 | /** Resets */ 12 | 13 | #qunit-tests, #qunit-tests ol, #qunit-header, #qunit-banner, #qunit-userAgent, #qunit-testresult { 14 | margin: 0; 15 | padding: 0; 16 | } 17 | 18 | 19 | /** Header */ 20 | 21 | #qunit-header { 22 | padding: 0.5em 0 0.5em 1em; 23 | 24 | color: #8699a4; 25 | background-color: #0d3349; 26 | 27 | font-size: 1.5em; 28 | line-height: 1em; 29 | font-weight: normal; 30 | 31 | border-radius: 15px 15px 0 0; 32 | -moz-border-radius: 15px 15px 0 0; 33 | -webkit-border-top-right-radius: 15px; 34 | -webkit-border-top-left-radius: 15px; 35 | } 36 | 37 | #qunit-header a { 38 | text-decoration: none; 39 | color: #c2ccd1; 40 | } 41 | 42 | #qunit-header a:hover, 43 | #qunit-header a:focus { 44 | color: #fff; 45 | } 46 | 47 | #qunit-banner { 48 | height: 5px; 49 | } 50 | 51 | #qunit-testrunner-toolbar { 52 | padding: 0.5em 0 0.5em 2em; 53 | color: #5E740B; 54 | background-color: #eee; 55 | } 56 | 57 | #qunit-userAgent { 58 | padding: 0.5em 0 0.5em 2.5em; 59 | background-color: #2b81af; 60 | color: #fff; 61 | text-shadow: rgba(0, 0, 0, 0.5) 2px 2px 1px; 62 | } 63 | 64 | 65 | /** Tests: Pass/Fail */ 66 | 67 | #qunit-tests { 68 | list-style-position: inside; 69 | } 70 | 71 | #qunit-tests li { 72 | padding: 0.4em 0.5em 0.4em 2.5em; 73 | border-bottom: 1px solid #fff; 74 | list-style-position: inside; 75 | } 76 | 77 | #qunit-tests.hidepass li.pass, #qunit-tests.hidepass li.running { 78 | display: none; 79 | } 80 | 81 | #qunit-tests li strong { 82 | cursor: pointer; 83 | } 84 | 85 | #qunit-tests li a { 86 | padding: 0.5em; 87 | color: #c2ccd1; 88 | text-decoration: none; 89 | } 90 | #qunit-tests li a:hover, 91 | #qunit-tests li a:focus { 92 | color: #000; 93 | } 94 | 95 | #qunit-tests ol { 96 | margin-top: 0.5em; 97 | padding: 0.5em; 98 | 99 | background-color: #fff; 100 | 101 | border-radius: 15px; 102 | -moz-border-radius: 15px; 103 | -webkit-border-radius: 15px; 104 | 105 | box-shadow: inset 0px 2px 13px #999; 106 | -moz-box-shadow: inset 0px 2px 13px #999; 107 | -webkit-box-shadow: inset 0px 2px 13px #999; 108 | } 109 | 110 | #qunit-tests table { 111 | border-collapse: collapse; 112 | margin-top: .2em; 113 | } 114 | 115 | #qunit-tests th { 116 | text-align: right; 117 | vertical-align: top; 118 | padding: 0 .5em 0 0; 119 | } 120 | 121 | #qunit-tests td { 122 | vertical-align: top; 123 | } 124 | 125 | #qunit-tests pre { 126 | margin: 0; 127 | white-space: pre-wrap; 128 | word-wrap: break-word; 129 | } 130 | 131 | #qunit-tests del { 132 | background-color: #e0f2be; 133 | color: #374e0c; 134 | text-decoration: none; 135 | } 136 | 137 | #qunit-tests ins { 138 | background-color: #ffcaca; 139 | color: #500; 140 | text-decoration: none; 141 | } 142 | 143 | /*** Test Counts */ 144 | 145 | #qunit-tests b.counts { color: black; } 146 | #qunit-tests b.passed { color: #5E740B; } 147 | #qunit-tests b.failed { color: #710909; } 148 | 149 | #qunit-tests li li { 150 | margin: 0.5em; 151 | padding: 0.4em 0.5em 0.4em 0.5em; 152 | background-color: #fff; 153 | border-bottom: none; 154 | list-style-position: inside; 155 | } 156 | 157 | /*** Passing Styles */ 158 | 159 | #qunit-tests li li.pass { 160 | color: #5E740B; 161 | background-color: #fff; 162 | border-left: 26px solid #C6E746; 163 | } 164 | 165 | #qunit-tests .pass { color: #528CE0; background-color: #D2E0E6; } 166 | #qunit-tests .pass .test-name { color: #366097; } 167 | 168 | #qunit-tests .pass .test-actual, 169 | #qunit-tests .pass .test-expected { color: #999999; } 170 | 171 | #qunit-banner.qunit-pass { background-color: #C6E746; } 172 | 173 | /*** Failing Styles */ 174 | 175 | #qunit-tests li li.fail { 176 | color: #710909; 177 | background-color: #fff; 178 | border-left: 26px solid #EE5757; 179 | } 180 | 181 | #qunit-tests > li:last-child { 182 | border-radius: 0 0 15px 15px; 183 | -moz-border-radius: 0 0 15px 15px; 184 | -webkit-border-bottom-right-radius: 15px; 185 | -webkit-border-bottom-left-radius: 15px; 186 | } 187 | 188 | #qunit-tests .fail { color: #000000; background-color: #EE5757; } 189 | #qunit-tests .fail .test-name, 190 | #qunit-tests .fail .module-name { color: #000000; } 191 | 192 | #qunit-tests .fail .test-actual { color: #EE5757; } 193 | #qunit-tests .fail .test-expected { color: green; } 194 | 195 | #qunit-banner.qunit-fail { background-color: #EE5757; } 196 | 197 | 198 | /** Result */ 199 | 200 | #qunit-testresult { 201 | padding: 0.5em 0.5em 0.5em 2.5em; 202 | 203 | color: #2b81af; 204 | background-color: #D2E0E6; 205 | 206 | border-bottom: 1px solid white; 207 | } 208 | 209 | /** Fixture */ 210 | 211 | #qunit-fixture { 212 | position: absolute; 213 | top: -10000px; 214 | left: -10000px; 215 | } 216 | --------------------------------------------------------------------------------