bpm 0.1.4 → 1.0.0.beta.4
Sign up to get free protection for your applications and to get access to all the features.
- data/CHANGELOG.md +20 -0
- data/README.md +1 -1
- data/TODO.md +90 -2
- data/bpm.gemspec +3 -3
- data/lib/bpm/cli/base.rb +103 -52
- data/lib/bpm/errors.rb +51 -0
- data/lib/bpm/init_generator.rb +1 -8
- data/lib/bpm/libgems_ext/libgems.rb +9 -0
- data/lib/bpm/local.rb +6 -11
- data/lib/bpm/package.rb +272 -178
- data/lib/bpm/pipeline/generated_asset.rb +88 -28
- data/lib/bpm/pipeline/plugin_asset.rb +8 -2
- data/lib/bpm/pipeline/source_url_processor.rb +16 -0
- data/lib/bpm/pipeline/transport_processor.rb +5 -3
- data/lib/bpm/pipeline.rb +33 -23
- data/lib/bpm/project.rb +492 -167
- data/lib/bpm/project_generator.rb +14 -1
- data/lib/bpm/remote.rb +6 -4
- data/lib/bpm/server.rb +4 -15
- data/lib/bpm/version.rb +2 -1
- data/lib/bpm.rb +2 -0
- data/man/bpm-add.1.ronn +22 -0
- data/man/bpm-build.1.ronn +22 -0
- data/man/bpm-compile.1.ronn +23 -0
- data/man/bpm-config.7.ronn +21 -0
- data/man/bpm-fetch.1.ronn +22 -0
- data/man/bpm-fetched.1.ronn +22 -0
- data/man/bpm-init.1.ronn +22 -0
- data/man/bpm-list.1.ronn +22 -0
- data/man/bpm-login.1.ronn +22 -0
- data/man/bpm-new.1.ronn +22 -0
- data/man/bpm-owner.1.ronn +22 -0
- data/man/bpm-preview.1.ronn +22 -0
- data/man/bpm-push.1.ronn +22 -0
- data/man/bpm-remove.1.ronn +22 -0
- data/man/bpm-unpack.1.ronn +22 -0
- data/man/bpm-yank.1.ronn +22 -0
- data/man/bpm.1.ronn +31 -0
- data/spec/cli/add_spec.rb +26 -7
- data/spec/cli/fetch_spec.rb +15 -6
- data/spec/cli/init_spec.rb +165 -25
- data/spec/cli/{build_spec.rb → pack_spec.rb} +9 -10
- data/spec/cli/push_spec.rb +4 -4
- data/spec/cli/rebuild_spec.rb +181 -0
- data/spec/cli/remove_spec.rb +3 -4
- data/spec/cli/unpack_spec.rb +6 -6
- data/spec/fixtures/gems/core-test-0.4.9.bpkg +0 -0
- data/spec/fixtures/{core-test-0.4.9.bpkg → gems/uglify-js-1.0.4.bpkg} +0 -0
- data/spec/fixtures/packages/core-test/extras/extra_file.html +3 -0
- data/spec/fixtures/packages/core-test/index.html +3 -0
- data/spec/fixtures/{core-test → packages/core-test}/package.json +9 -3
- data/spec/fixtures/packages/invalid_json/package.json +3 -0
- data/spec/fixtures/packages/uglify-js/README.html +825 -0
- data/spec/fixtures/packages/uglify-js/README.org +431 -0
- data/spec/fixtures/packages/uglify-js/bin/uglifyjs +305 -0
- data/spec/fixtures/packages/uglify-js/docstyle.css +75 -0
- data/spec/fixtures/packages/uglify-js/lib/parse-js.js +1 -0
- data/spec/fixtures/packages/uglify-js/lib/process.js +1 -0
- data/spec/fixtures/packages/uglify-js/lib/squeeze-more.js +1 -0
- data/spec/fixtures/packages/uglify-js/package.json +27 -0
- data/spec/fixtures/packages/uglify-js/plugins/minifier.js +6 -0
- data/spec/fixtures/packages/uglify-js/uglify-js.js +17 -0
- data/spec/fixtures/projects/hello2/README.md +21 -0
- data/{templates/init → spec/fixtures/projects/hello2}/assets/bpm_packages.js +6 -1
- data/{templates/init → spec/fixtures/projects/hello2}/assets/bpm_styles.css +1 -1
- data/spec/fixtures/projects/hello2/hello2.json +16 -0
- data/spec/fixtures/projects/hello2/index.html +13 -0
- data/spec/fixtures/projects/hello2/packages/a/lib/main.js +2 -0
- data/spec/fixtures/projects/hello2/packages/a/package.json +17 -0
- data/spec/fixtures/projects/hello2/packages/b/lib/main.js +2 -0
- data/spec/fixtures/projects/hello2/packages/b/package.json +17 -0
- data/spec/fixtures/projects/hello2/packages/c/lib/main.js +2 -0
- data/spec/fixtures/projects/hello2/packages/c/package.json +16 -0
- data/spec/fixtures/projects/hello_dev/LICENSE +19 -0
- data/spec/fixtures/projects/hello_dev/README.md +21 -0
- data/spec/fixtures/projects/hello_dev/app/main.js +6 -0
- data/spec/fixtures/projects/hello_dev/assets/bpm_libs.js +5 -0
- data/spec/fixtures/projects/hello_dev/assets/bpm_styles.css +6 -0
- data/spec/fixtures/projects/hello_dev/css/main.css +1 -0
- data/spec/fixtures/projects/hello_dev/hello_dev.json +25 -0
- data/spec/fixtures/projects/hello_dev/index.html +14 -0
- data/spec/fixtures/projects/hello_dev/packages/style_package/css/some_style.css +3 -0
- data/spec/fixtures/{minitest/minitest.json → projects/hello_dev/packages/style_package/package.json} +5 -9
- data/spec/fixtures/projects/hello_world/LICENSE +19 -0
- data/spec/fixtures/projects/hello_world/assets/bpm_packages.js +1 -0
- data/spec/fixtures/projects/hello_world/assets/bpm_styles.css +1 -0
- data/spec/fixtures/projects/hello_world/custom_dir/custom.js +1 -0
- data/spec/fixtures/projects/hello_world/hello_world.json +41 -0
- data/spec/fixtures/projects/hello_world/lib/another.js +1 -0
- data/spec/fixtures/{hello_world → projects/hello_world}/packages/custom_package/package.json +5 -2
- data/spec/fixtures/projects/hello_world/vendor/lib/something.js +1 -0
- data/spec/fixtures/projects/init_app/assets/bpm_libs.js +6 -0
- data/spec/fixtures/projects/init_app/assets/bpm_styles.css +5 -0
- data/spec/fixtures/projects/init_app/assets/new_project/bpm_libs.js +6 -0
- data/spec/fixtures/projects/init_app/assets/new_project/bpm_styles.css +5 -0
- data/spec/fixtures/projects/init_app/new_project.json +27 -0
- data/spec/fixtures/projects/init_default/assets/bpm_libs.js +6 -0
- data/spec/fixtures/projects/init_default/assets/bpm_styles.css +5 -0
- data/spec/fixtures/projects/init_default/new_project.json +15 -0
- data/spec/fixtures/projects/minitest/minitest.json +26 -0
- data/spec/fixtures/{minitest → projects/minitest}/packages/uglyduck/package.json +1 -1
- data/spec/fixtures/projects/needs_rake/needs_rake.json +7 -0
- data/spec/fixtures/{transporter → projects/transporter}/packages/transport/package.json +1 -1
- data/spec/package_spec.rb +343 -315
- data/spec/pipeline_spec.rb +89 -71
- data/spec/plugins/minifier_spec.rb +25 -16
- data/spec/plugins/transport_spec.rb +1 -1
- data/spec/project_spec.rb +97 -34
- data/spec/spec_helper.rb +41 -0
- data/spec/support/fake_gem_server.rb +8 -4
- data/spec/support/path.rb +8 -0
- data/spec/support/project.rb +50 -17
- data/templates/init/project.json +12 -14
- data/templates/project/LICENSE +1 -1
- data/templates/project/app/main.js +6 -0
- data/templates/project/css/main.css +1 -0
- data/templates/project/index.html +4 -3
- data/vendor/sprockets/.travis.yml +3 -2
- data/vendor/sprockets/Gemfile +0 -6
- data/vendor/sprockets/lib/sprockets/asset.rb +7 -12
- data/vendor/sprockets/lib/sprockets/asset_attributes.rb +70 -53
- data/vendor/sprockets/lib/sprockets/base.rb +1 -14
- data/vendor/sprockets/lib/sprockets/bundled_asset.rb +72 -45
- data/vendor/sprockets/lib/sprockets/caching.rb +28 -23
- data/vendor/sprockets/lib/sprockets/context.rb +56 -26
- data/vendor/sprockets/lib/sprockets/directive_processor.rb +21 -4
- data/vendor/sprockets/lib/sprockets/eco_template.rb +3 -4
- data/vendor/sprockets/lib/sprockets/ejs_template.rb +3 -4
- data/vendor/sprockets/lib/sprockets/engines.rb +26 -1
- data/vendor/sprockets/lib/sprockets/environment.rb +2 -1
- data/vendor/sprockets/lib/sprockets/index.rb +1 -0
- data/vendor/sprockets/lib/sprockets/mime.rb +38 -0
- data/vendor/sprockets/lib/sprockets/processing.rb +4 -45
- data/vendor/sprockets/lib/sprockets/static_asset.rb +5 -6
- data/vendor/sprockets/lib/sprockets/static_compilation.rb +4 -12
- data/vendor/sprockets/lib/sprockets/trail.rb +2 -1
- data/vendor/sprockets/test/fixtures/default/blank.gif +0 -0
- data/vendor/sprockets/test/fixtures/default/with_data_uri.css.erb +3 -0
- data/vendor/sprockets/test/test_asset.rb +121 -15
- data/vendor/sprockets/test/test_asset_attributes.rb +85 -21
- data/vendor/sprockets/test/test_environment.rb +13 -36
- metadata +564 -444
- data/spec/cli/new_spec.rb +0 -118
- data/spec/fixtures/hello_world/assets/bpm_packages.js +0 -13
- data/spec/fixtures/hello_world/assets/bpm_styles.css +0 -14
- data/spec/fixtures/hello_world/hello_world.json +0 -20
- /data/spec/fixtures/{badrake-0.8.7.bpkg → gems/badrake-0.8.7.bpkg} +0 -0
- /data/spec/fixtures/{builder-3.0.0.bpkg → gems/builder-3.0.0.bpkg} +0 -0
- /data/spec/fixtures/{bundler-1.1.pre.bpkg → gems/bundler-1.1.pre.bpkg} +0 -0
- /data/spec/fixtures/{coffee-1.0.1.pre.bpkg → gems/coffee-1.0.1.pre.bpkg} +0 -0
- /data/spec/fixtures/{custom_generator-1.0.bpkg → gems/custom_generator-1.0.bpkg} +0 -0
- /data/spec/fixtures/{highline-1.6.1.bpkg → gems/highline-1.6.1.bpkg} +0 -0
- /data/spec/fixtures/{ivory-0.0.1.bpkg → gems/ivory-0.0.1.bpkg} +0 -0
- /data/spec/fixtures/{jquery-1.4.3.bpkg → gems/jquery-1.4.3.bpkg} +0 -0
- /data/spec/fixtures/{optparse-1.0.1.bpkg → gems/optparse-1.0.1.bpkg} +0 -0
- /data/spec/fixtures/{rake-0.8.6.bpkg → gems/rake-0.8.6.bpkg} +0 -0
- /data/spec/fixtures/{rake-0.8.7.bpkg → gems/rake-0.8.7.bpkg} +0 -0
- /data/spec/fixtures/{spade-0.5.0.bpkg → gems/spade-0.5.0.bpkg} +0 -0
- /data/spec/fixtures/{src → packages}/README.txt +0 -0
- /data/spec/fixtures/{src → packages}/bundler-1.1.pre/.gitignore +0 -0
- /data/spec/fixtures/{src → packages}/bundler-1.1.pre/CHANGELOG.md +0 -0
- /data/spec/fixtures/{src → packages}/bundler-1.1.pre/ISSUES.md +0 -0
- /data/spec/fixtures/{src → packages}/bundler-1.1.pre/LICENSE +0 -0
- /data/spec/fixtures/{src → packages}/bundler-1.1.pre/README.md +0 -0
- /data/spec/fixtures/{src → packages}/bundler-1.1.pre/UPGRADING.md +0 -0
- /data/spec/fixtures/{src → packages}/bundler-1.1.pre/bin/bundle +0 -0
- /data/spec/fixtures/{src → packages}/bundler-1.1.pre/lib/bundler/definition.js +0 -0
- /data/spec/fixtures/{src → packages}/bundler-1.1.pre/lib/bundler/dependency.js +0 -0
- /data/spec/fixtures/{src → packages}/bundler-1.1.pre/lib/bundler/dsl.js +0 -0
- /data/spec/fixtures/{src → packages}/bundler-1.1.pre/lib/bundler/ui.js +0 -0
- /data/spec/fixtures/{src → packages}/bundler-1.1.pre/lib/bundler.js +0 -0
- /data/spec/fixtures/{src → packages}/bundler-1.1.pre/man/bundle-config.ronn +0 -0
- /data/spec/fixtures/{src → packages}/bundler-1.1.pre/man/bundle-exec.ronn +0 -0
- /data/spec/fixtures/{src → packages}/bundler-1.1.pre/man/bundle-install.ronn +0 -0
- /data/spec/fixtures/{src → packages}/bundler-1.1.pre/man/bundle-package.ronn +0 -0
- /data/spec/fixtures/{src → packages}/bundler-1.1.pre/man/bundle-update.ronn +0 -0
- /data/spec/fixtures/{src → packages}/bundler-1.1.pre/man/bundle.ronn +0 -0
- /data/spec/fixtures/{src → packages}/bundler-1.1.pre/man/gemfile.5.ronn +0 -0
- /data/spec/fixtures/{src → packages}/bundler-1.1.pre/man/index.txt +0 -0
- /data/spec/fixtures/{src → packages}/bundler-1.1.pre/package.json +0 -0
- /data/spec/fixtures/{src → packages}/coffee-1.0.1.pre/bin/cake +0 -0
- /data/spec/fixtures/{src → packages}/coffee-1.0.1.pre/bin/coffee +0 -0
- /data/spec/fixtures/{src → packages}/coffee-1.0.1.pre/lib/coffee/base.js +0 -0
- /data/spec/fixtures/{src → packages}/coffee-1.0.1.pre/lib/coffee/mocha/chai.js +0 -0
- /data/spec/fixtures/{src → packages}/coffee-1.0.1.pre/lib/coffee.js +0 -0
- /data/spec/fixtures/{src → packages}/coffee-1.0.1.pre/package.json +0 -0
- /data/spec/fixtures/{src → packages}/coffee-1.0.1.pre/qunit/coffee/test.js +0 -0
- /data/spec/fixtures/{src → packages}/coffee-1.0.1.pre/qunit/test.js +0 -0
- /data/spec/fixtures/{core-test → packages/core-test}/bin/cot +0 -0
- /data/spec/fixtures/{core-test → packages/core-test}/lib/main.js +0 -0
- /data/spec/fixtures/{core-test → packages/core-test}/resources/runner.css +0 -0
- /data/spec/fixtures/{core-test → packages/core-test}/tests/test.js +0 -0
- /data/spec/fixtures/{custom_generator → packages/custom_generator}/lib/main.js +0 -0
- /data/spec/fixtures/{custom_generator → packages/custom_generator}/package.json +0 -0
- /data/spec/fixtures/{custom_generator → packages/custom_generator}/templates/init/project.json +0 -0
- /data/spec/fixtures/{custom_generator → packages/custom_generator}/templates/project/app.js +0 -0
- /data/spec/fixtures/{custom_generator → packages/custom_generator}/templates/project/lib/main.js +0 -0
- /data/spec/fixtures/{custom_generator → packages/custom_generator}/templates/project_generator.rb +0 -0
- /data/spec/fixtures/{src → packages}/jquery/lib/main.js +0 -0
- /data/spec/fixtures/{src → packages}/jquery/package.json +0 -0
- /data/spec/fixtures/{src → packages}/rake-0.8.6/CHANGES +0 -0
- /data/spec/fixtures/{src → packages}/rake-0.8.6/MIT-LICENSE +0 -0
- /data/spec/fixtures/{src → packages}/rake-0.8.6/README +0 -0
- /data/spec/fixtures/{src → packages}/rake-0.8.6/Rakefile +0 -0
- /data/spec/fixtures/{src → packages}/rake-0.8.6/TODO +0 -0
- /data/spec/fixtures/{src → packages}/rake-0.8.6/bin/rake +0 -0
- /data/spec/fixtures/{src → packages}/rake-0.8.6/doc/command_line_usage.rdoc +0 -0
- /data/spec/fixtures/{src → packages}/rake-0.8.6/doc/example/Rakefile1 +0 -0
- /data/spec/fixtures/{src → packages}/rake-0.8.6/doc/example/Rakefile2 +0 -0
- /data/spec/fixtures/{src → packages}/rake-0.8.6/doc/example/a.c +0 -0
- /data/spec/fixtures/{src → packages}/rake-0.8.6/doc/example/b.c +0 -0
- /data/spec/fixtures/{src → packages}/rake-0.8.6/doc/example/main.c +0 -0
- /data/spec/fixtures/{src → packages}/rake-0.8.6/doc/glossary.rdoc +0 -0
- /data/spec/fixtures/{src → packages}/rake-0.8.6/doc/jamis.rb +0 -0
- /data/spec/fixtures/{src → packages}/rake-0.8.6/doc/proto_rake.rdoc +0 -0
- /data/spec/fixtures/{src → packages}/rake-0.8.6/doc/rake.1.gz +0 -0
- /data/spec/fixtures/{src → packages}/rake-0.8.6/doc/rakefile.rdoc +0 -0
- /data/spec/fixtures/{src → packages}/rake-0.8.6/doc/rational.rdoc +0 -0
- /data/spec/fixtures/{src → packages}/rake-0.8.6/doc/release_notes/rake-0.4.14.rdoc +0 -0
- /data/spec/fixtures/{src → packages}/rake-0.8.6/doc/release_notes/rake-0.4.15.rdoc +0 -0
- /data/spec/fixtures/{src → packages}/rake-0.8.6/doc/release_notes/rake-0.5.0.rdoc +0 -0
- /data/spec/fixtures/{src → packages}/rake-0.8.6/doc/release_notes/rake-0.5.3.rdoc +0 -0
- /data/spec/fixtures/{src → packages}/rake-0.8.6/doc/release_notes/rake-0.5.4.rdoc +0 -0
- /data/spec/fixtures/{src → packages}/rake-0.8.6/doc/release_notes/rake-0.6.0.rdoc +0 -0
- /data/spec/fixtures/{src → packages}/rake-0.8.6/doc/release_notes/rake-0.7.0.rdoc +0 -0
- /data/spec/fixtures/{src → packages}/rake-0.8.6/doc/release_notes/rake-0.7.1.rdoc +0 -0
- /data/spec/fixtures/{src → packages}/rake-0.8.6/doc/release_notes/rake-0.7.2.rdoc +0 -0
- /data/spec/fixtures/{src → packages}/rake-0.8.6/doc/release_notes/rake-0.7.3.rdoc +0 -0
- /data/spec/fixtures/{src → packages}/rake-0.8.6/doc/release_notes/rake-0.8.0.rdoc +0 -0
- /data/spec/fixtures/{src → packages}/rake-0.8.6/doc/release_notes/rake-0.8.2.rdoc +0 -0
- /data/spec/fixtures/{src → packages}/rake-0.8.6/doc/release_notes/rake-0.8.3.rdoc +0 -0
- /data/spec/fixtures/{src → packages}/rake-0.8.6/doc/release_notes/rake-0.8.4.rdoc +0 -0
- /data/spec/fixtures/{src → packages}/rake-0.8.6/doc/release_notes/rake-0.8.5.rdoc +0 -0
- /data/spec/fixtures/{src → packages}/rake-0.8.6/doc/release_notes/rake-0.8.6.rdoc +0 -0
- /data/spec/fixtures/{src → packages}/rake-0.8.6/install.rb +0 -0
- /data/spec/fixtures/{src → packages}/rake-0.8.6/lib/rake/alt_system.rb +0 -0
- /data/spec/fixtures/{src → packages}/rake-0.8.6/lib/rake/classic_namespace.rb +0 -0
- /data/spec/fixtures/{src → packages}/rake-0.8.6/lib/rake/clean.rb +0 -0
- /data/spec/fixtures/{src → packages}/rake-0.8.6/lib/rake/contrib/compositepublisher.rb +0 -0
- /data/spec/fixtures/{src → packages}/rake-0.8.6/lib/rake/contrib/ftptools.rb +0 -0
- /data/spec/fixtures/{src → packages}/rake-0.8.6/lib/rake/contrib/publisher.rb +0 -0
- /data/spec/fixtures/{src → packages}/rake-0.8.6/lib/rake/contrib/rubyforgepublisher.rb +0 -0
- /data/spec/fixtures/{src → packages}/rake-0.8.6/lib/rake/contrib/sshpublisher.rb +0 -0
- /data/spec/fixtures/{src → packages}/rake-0.8.6/lib/rake/contrib/sys.rb +0 -0
- /data/spec/fixtures/{src → packages}/rake-0.8.6/lib/rake/gempackagetask.rb +0 -0
- /data/spec/fixtures/{src → packages}/rake-0.8.6/lib/rake/loaders/makefile.rb +0 -0
- /data/spec/fixtures/{src → packages}/rake-0.8.6/lib/rake/packagetask.rb +0 -0
- /data/spec/fixtures/{src → packages}/rake-0.8.6/lib/rake/rake_test_loader.rb +0 -0
- /data/spec/fixtures/{src → packages}/rake-0.8.6/lib/rake/rdoctask.rb +0 -0
- /data/spec/fixtures/{src → packages}/rake-0.8.6/lib/rake/ruby182_test_unit_fix.rb +0 -0
- /data/spec/fixtures/{src → packages}/rake-0.8.6/lib/rake/runtest.rb +0 -0
- /data/spec/fixtures/{src → packages}/rake-0.8.6/lib/rake/tasklib.rb +0 -0
- /data/spec/fixtures/{src → packages}/rake-0.8.6/lib/rake/testtask.rb +0 -0
- /data/spec/fixtures/{src → packages}/rake-0.8.6/lib/rake/win32.rb +0 -0
- /data/spec/fixtures/{src → packages}/rake-0.8.6/lib/rake.rb +0 -0
- /data/spec/fixtures/{src → packages}/rake-0.8.6/package.json +0 -0
- /data/spec/fixtures/{src → packages}/rake-0.8.6/test/capture_stdout.rb +0 -0
- /data/spec/fixtures/{src → packages}/rake-0.8.7/CHANGES +0 -0
- /data/spec/fixtures/{src → packages}/rake-0.8.7/MIT-LICENSE +0 -0
- /data/spec/fixtures/{src → packages}/rake-0.8.7/README +0 -0
- /data/spec/fixtures/{src → packages}/rake-0.8.7/Rakefile +0 -0
- /data/spec/fixtures/{src → packages}/rake-0.8.7/TODO +0 -0
- /data/spec/fixtures/{src → packages}/rake-0.8.7/bin/rake +0 -0
- /data/spec/fixtures/{src → packages}/rake-0.8.7/doc/command_line_usage.rdoc +0 -0
- /data/spec/fixtures/{src → packages}/rake-0.8.7/doc/example/Rakefile1 +0 -0
- /data/spec/fixtures/{src → packages}/rake-0.8.7/doc/example/Rakefile2 +0 -0
- /data/spec/fixtures/{src → packages}/rake-0.8.7/doc/example/a.c +0 -0
- /data/spec/fixtures/{src → packages}/rake-0.8.7/doc/example/b.c +0 -0
- /data/spec/fixtures/{src → packages}/rake-0.8.7/doc/example/main.c +0 -0
- /data/spec/fixtures/{src → packages}/rake-0.8.7/doc/glossary.rdoc +0 -0
- /data/spec/fixtures/{src → packages}/rake-0.8.7/doc/jamis.rb +0 -0
- /data/spec/fixtures/{src → packages}/rake-0.8.7/doc/proto_rake.rdoc +0 -0
- /data/spec/fixtures/{src → packages}/rake-0.8.7/doc/rake.1.gz +0 -0
- /data/spec/fixtures/{src → packages}/rake-0.8.7/doc/rakefile.rdoc +0 -0
- /data/spec/fixtures/{src → packages}/rake-0.8.7/doc/rational.rdoc +0 -0
- /data/spec/fixtures/{src → packages}/rake-0.8.7/doc/release_notes/rake-0.4.14.rdoc +0 -0
- /data/spec/fixtures/{src → packages}/rake-0.8.7/doc/release_notes/rake-0.4.15.rdoc +0 -0
- /data/spec/fixtures/{src → packages}/rake-0.8.7/doc/release_notes/rake-0.5.0.rdoc +0 -0
- /data/spec/fixtures/{src → packages}/rake-0.8.7/doc/release_notes/rake-0.5.3.rdoc +0 -0
- /data/spec/fixtures/{src → packages}/rake-0.8.7/doc/release_notes/rake-0.5.4.rdoc +0 -0
- /data/spec/fixtures/{src → packages}/rake-0.8.7/doc/release_notes/rake-0.6.0.rdoc +0 -0
- /data/spec/fixtures/{src → packages}/rake-0.8.7/doc/release_notes/rake-0.7.0.rdoc +0 -0
- /data/spec/fixtures/{src → packages}/rake-0.8.7/doc/release_notes/rake-0.7.1.rdoc +0 -0
- /data/spec/fixtures/{src → packages}/rake-0.8.7/doc/release_notes/rake-0.7.2.rdoc +0 -0
- /data/spec/fixtures/{src → packages}/rake-0.8.7/doc/release_notes/rake-0.7.3.rdoc +0 -0
- /data/spec/fixtures/{src → packages}/rake-0.8.7/doc/release_notes/rake-0.8.0.rdoc +0 -0
- /data/spec/fixtures/{src → packages}/rake-0.8.7/doc/release_notes/rake-0.8.2.rdoc +0 -0
- /data/spec/fixtures/{src → packages}/rake-0.8.7/doc/release_notes/rake-0.8.3.rdoc +0 -0
- /data/spec/fixtures/{src → packages}/rake-0.8.7/doc/release_notes/rake-0.8.4.rdoc +0 -0
- /data/spec/fixtures/{src → packages}/rake-0.8.7/doc/release_notes/rake-0.8.5.rdoc +0 -0
- /data/spec/fixtures/{src → packages}/rake-0.8.7/doc/release_notes/rake-0.8.6.rdoc +0 -0
- /data/spec/fixtures/{src → packages}/rake-0.8.7/doc/release_notes/rake-0.8.7.rdoc +0 -0
- /data/spec/fixtures/{src → packages}/rake-0.8.7/install.rb +0 -0
- /data/spec/fixtures/{src → packages}/rake-0.8.7/lib/rake/alt_system.rb +0 -0
- /data/spec/fixtures/{src → packages}/rake-0.8.7/lib/rake/classic_namespace.rb +0 -0
- /data/spec/fixtures/{src → packages}/rake-0.8.7/lib/rake/clean.rb +0 -0
- /data/spec/fixtures/{src → packages}/rake-0.8.7/lib/rake/contrib/compositepublisher.rb +0 -0
- /data/spec/fixtures/{src → packages}/rake-0.8.7/lib/rake/contrib/ftptools.rb +0 -0
- /data/spec/fixtures/{src → packages}/rake-0.8.7/lib/rake/contrib/publisher.rb +0 -0
- /data/spec/fixtures/{src → packages}/rake-0.8.7/lib/rake/contrib/rubyforgepublisher.rb +0 -0
- /data/spec/fixtures/{src → packages}/rake-0.8.7/lib/rake/contrib/sshpublisher.rb +0 -0
- /data/spec/fixtures/{src → packages}/rake-0.8.7/lib/rake/contrib/sys.rb +0 -0
- /data/spec/fixtures/{src → packages}/rake-0.8.7/lib/rake/gempackagetask.rb +0 -0
- /data/spec/fixtures/{src → packages}/rake-0.8.7/lib/rake/loaders/makefile.rb +0 -0
- /data/spec/fixtures/{src → packages}/rake-0.8.7/lib/rake/packagetask.rb +0 -0
- /data/spec/fixtures/{src → packages}/rake-0.8.7/lib/rake/rake_test_loader.rb +0 -0
- /data/spec/fixtures/{src → packages}/rake-0.8.7/lib/rake/rdoctask.rb +0 -0
- /data/spec/fixtures/{src → packages}/rake-0.8.7/lib/rake/ruby182_test_unit_fix.rb +0 -0
- /data/spec/fixtures/{src → packages}/rake-0.8.7/lib/rake/runtest.rb +0 -0
- /data/spec/fixtures/{src → packages}/rake-0.8.7/lib/rake/tasklib.rb +0 -0
- /data/spec/fixtures/{src → packages}/rake-0.8.7/lib/rake/testtask.rb +0 -0
- /data/spec/fixtures/{src → packages}/rake-0.8.7/lib/rake/win32.rb +0 -0
- /data/spec/fixtures/{src → packages}/rake-0.8.7/lib/rake.rb +0 -0
- /data/spec/fixtures/{src → packages}/rake-0.8.7/package.json +0 -0
- /data/spec/fixtures/{src → packages}/rake-0.8.7/test/capture_stdout.rb +0 -0
- /data/spec/fixtures/{src → packages}/spade/lib/main.js +0 -0
- /data/spec/fixtures/{src → packages}/spade/package.json +0 -0
- /data/spec/fixtures/{custom_name → projects/custom_name}/MyProject.json +0 -0
- /data/spec/fixtures/{hello_world → projects/hello2}/LICENSE +0 -0
- /data/{templates/project → spec/fixtures/projects/hello2}/app.js +0 -0
- /data/spec/fixtures/{hello_world → projects/hello_world}/README.md +0 -0
- /data/spec/fixtures/{hello_world → projects/hello_world}/assets/papa-smurf.jpg +0 -0
- /data/spec/fixtures/{hello_world → projects/hello_world}/css/dummy.css +0 -0
- /data/spec/fixtures/{hello_world → projects/hello_world}/lib/main.js +0 -0
- /data/spec/fixtures/{hello_world → projects/hello_world}/packages/custom_package/assets/dummy.txt +0 -0
- /data/spec/fixtures/{hello_world → projects/hello_world}/packages/custom_package/css/sample_styles.css +0 -0
- /data/spec/fixtures/{hello_world → projects/hello_world}/packages/custom_package/custom_dir/basic-module.js +0 -0
- /data/spec/fixtures/{hello_world → projects/hello_world}/packages/custom_package/lib/main.js +0 -0
- /data/spec/fixtures/{hello_world → projects/hello_world}/tests/main-test.js +0 -0
- /data/spec/fixtures/{minitest → projects/minitest}/assets/bpm_packages.js +0 -0
- /data/spec/fixtures/{minitest → projects/minitest}/assets/bpm_styles.css +0 -0
- /data/spec/fixtures/{minitest → projects/minitest}/assets/minitest/app_package.js +0 -0
- /data/spec/fixtures/{minitest → projects/minitest}/lib/main.js +0 -0
- /data/spec/fixtures/{minitest → projects/minitest}/packages/uglyduck/lib/main.js +0 -0
- /data/spec/fixtures/{minitest → projects/minitest}/packages/uglyduck/minifier/main.js +0 -0
- /data/spec/fixtures/{simple_hello/assets/bpm_packages.js → projects/simple_hello/assets/bpm_libs.js} +0 -0
- /data/spec/fixtures/{simple_hello → projects/simple_hello}/lib/main.js +0 -0
- /data/spec/fixtures/{transporter → projects/transporter}/lib/main.js +0 -0
- /data/spec/fixtures/{transporter → projects/transporter}/packages/transport/lib/main.js +0 -0
- /data/spec/fixtures/{transporter → projects/transporter}/packages/transport/transports/wrapper.js +0 -0
- /data/spec/fixtures/{transporter → projects/transporter}/transporter.json +0 -0
@@ -0,0 +1,431 @@
|
|
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: <link rel="stylesheet" type="text/css" href="docstyle.css" />
|
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
|
+
** <<Unsafe transformations>>
|
74
|
+
|
75
|
+
UglifyJS tries its best to achieve great compression while leaving the
|
76
|
+
semantics of the code intact. In general, if your code logic is broken by
|
77
|
+
UglifyJS then it's a bug in UglifyJS and you should report it and I should
|
78
|
+
fix it. :-)
|
79
|
+
|
80
|
+
However, I opted to include the following potentially unsafe transformations
|
81
|
+
as default behavior. Discussion is welcome, if you have ideas of how to
|
82
|
+
handle this better, or any objections to these optimizations, please let me
|
83
|
+
know.
|
84
|
+
|
85
|
+
*** Calls involving the global Array constructor
|
86
|
+
|
87
|
+
The following transformations occur:
|
88
|
+
|
89
|
+
#+BEGIN_SRC js
|
90
|
+
new Array(1, 2, 3, 4) => [1,2,3,4]
|
91
|
+
Array(a, b, c) => [a,b,c]
|
92
|
+
new Array(5) => Array(5)
|
93
|
+
new Array(a) => Array(a)
|
94
|
+
#+END_SRC
|
95
|
+
|
96
|
+
These are all safe if the Array name isn't redefined. JavaScript does allow
|
97
|
+
one to globally redefine Array (and pretty much everything, in fact) but I
|
98
|
+
personally don't see why would anyone do that.
|
99
|
+
|
100
|
+
UglifyJS does handle the case where Array is redefined locally, or even
|
101
|
+
globally but with a =function= or =var= declaration. Therefore, in the
|
102
|
+
following cases UglifyJS *doesn't touch* calls or instantiations of Array:
|
103
|
+
|
104
|
+
#+BEGIN_SRC js
|
105
|
+
// case 1. globally declared variable
|
106
|
+
var Array;
|
107
|
+
new Array(1, 2, 3);
|
108
|
+
Array(a, b);
|
109
|
+
|
110
|
+
// or (can be declared later)
|
111
|
+
new Array(1, 2, 3);
|
112
|
+
var Array;
|
113
|
+
|
114
|
+
// or (can be a function)
|
115
|
+
new Array(1, 2, 3);
|
116
|
+
function Array() { ... }
|
117
|
+
|
118
|
+
// case 2. declared in a function
|
119
|
+
(function(){
|
120
|
+
a = new Array(1, 2, 3);
|
121
|
+
b = Array(5, 6);
|
122
|
+
var Array;
|
123
|
+
})();
|
124
|
+
|
125
|
+
// or
|
126
|
+
(function(Array){
|
127
|
+
return Array(5, 6, 7);
|
128
|
+
})();
|
129
|
+
|
130
|
+
// or
|
131
|
+
(function(){
|
132
|
+
return new Array(1, 2, 3, 4);
|
133
|
+
function Array() { ... }
|
134
|
+
})();
|
135
|
+
|
136
|
+
// etc.
|
137
|
+
#+END_SRC
|
138
|
+
|
139
|
+
** Install (NPM)
|
140
|
+
|
141
|
+
UglifyJS is now available through NPM --- =npm install uglify-js= should do
|
142
|
+
the job.
|
143
|
+
|
144
|
+
** Install latest code from GitHub
|
145
|
+
|
146
|
+
#+BEGIN_SRC sh
|
147
|
+
## clone the repository
|
148
|
+
mkdir -p /where/you/wanna/put/it
|
149
|
+
cd /where/you/wanna/put/it
|
150
|
+
git clone git://github.com/mishoo/UglifyJS.git
|
151
|
+
|
152
|
+
## make the module available to Node
|
153
|
+
mkdir -p ~/.node_libraries/
|
154
|
+
cd ~/.node_libraries/
|
155
|
+
ln -s /where/you/wanna/put/it/UglifyJS/uglify-js.js
|
156
|
+
|
157
|
+
## and if you want the CLI script too:
|
158
|
+
mkdir -p ~/bin
|
159
|
+
cd ~/bin
|
160
|
+
ln -s /where/you/wanna/put/it/UglifyJS/bin/uglifyjs
|
161
|
+
# (then add ~/bin to your $PATH if it's not there already)
|
162
|
+
#+END_SRC
|
163
|
+
|
164
|
+
** Usage
|
165
|
+
|
166
|
+
There is a command-line tool that exposes the functionality of this library
|
167
|
+
for your shell-scripting needs:
|
168
|
+
|
169
|
+
#+BEGIN_SRC sh
|
170
|
+
uglifyjs [ options... ] [ filename ]
|
171
|
+
#+END_SRC
|
172
|
+
|
173
|
+
=filename= should be the last argument and should name the file from which
|
174
|
+
to read the JavaScript code. If you don't specify it, it will read code
|
175
|
+
from STDIN.
|
176
|
+
|
177
|
+
Supported options:
|
178
|
+
|
179
|
+
- =-b= or =--beautify= --- output indented code; when passed, additional
|
180
|
+
options control the beautifier:
|
181
|
+
|
182
|
+
- =-i N= or =--indent N= --- indentation level (number of spaces)
|
183
|
+
|
184
|
+
- =-q= or =--quote-keys= --- quote keys in literal objects (by default,
|
185
|
+
only keys that cannot be identifier names will be quotes).
|
186
|
+
|
187
|
+
- =--ascii= --- pass this argument to encode non-ASCII characters as
|
188
|
+
=\uXXXX= sequences. By default UglifyJS won't bother to do it and will
|
189
|
+
output Unicode characters instead. (the output is always encoded in UTF8,
|
190
|
+
but if you pass this option you'll only get ASCII).
|
191
|
+
|
192
|
+
- =-nm= or =--no-mangle= --- don't mangle variable names
|
193
|
+
|
194
|
+
- =-ns= or =--no-squeeze= --- don't call =ast_squeeze()= (which does various
|
195
|
+
optimizations that result in smaller, less readable code).
|
196
|
+
|
197
|
+
- =-mt= or =--mangle-toplevel= --- mangle names in the toplevel scope too
|
198
|
+
(by default we don't do this).
|
199
|
+
|
200
|
+
- =--no-seqs= --- when =ast_squeeze()= is called (thus, unless you pass
|
201
|
+
=--no-squeeze=) it will reduce consecutive statements in blocks into a
|
202
|
+
sequence. For example, "a = 10; b = 20; foo();" will be written as
|
203
|
+
"a=10,b=20,foo();". In various occasions, this allows us to discard the
|
204
|
+
block brackets (since the block becomes a single statement). This is ON
|
205
|
+
by default because it seems safe and saves a few hundred bytes on some
|
206
|
+
libs that I tested it on, but pass =--no-seqs= to disable it.
|
207
|
+
|
208
|
+
- =--no-dead-code= --- by default, UglifyJS will remove code that is
|
209
|
+
obviously unreachable (code that follows a =return=, =throw=, =break= or
|
210
|
+
=continue= statement and is not a function/variable declaration). Pass
|
211
|
+
this option to disable this optimization.
|
212
|
+
|
213
|
+
- =-nc= or =--no-copyright= --- by default, =uglifyjs= will keep the initial
|
214
|
+
comment tokens in the generated code (assumed to be copyright information
|
215
|
+
etc.). If you pass this it will discard it.
|
216
|
+
|
217
|
+
- =-o filename= or =--output filename= --- put the result in =filename=. If
|
218
|
+
this isn't given, the result goes to standard output (or see next one).
|
219
|
+
|
220
|
+
- =--overwrite= --- if the code is read from a file (not from STDIN) and you
|
221
|
+
pass =--overwrite= then the output will be written in the same file.
|
222
|
+
|
223
|
+
- =--ast= --- pass this if you want to get the Abstract Syntax Tree instead
|
224
|
+
of JavaScript as output. Useful for debugging or learning more about the
|
225
|
+
internals.
|
226
|
+
|
227
|
+
- =-v= or =--verbose= --- output some notes on STDERR (for now just how long
|
228
|
+
each operation takes).
|
229
|
+
|
230
|
+
- =--extra= --- enable additional optimizations that have not yet been
|
231
|
+
extensively tested. These might, or might not, break your code. If you
|
232
|
+
find a bug using this option, please report a test case.
|
233
|
+
|
234
|
+
- =--unsafe= --- enable other additional optimizations that are known to be
|
235
|
+
unsafe in some contrived situations, but could still be generally useful.
|
236
|
+
For now only this:
|
237
|
+
|
238
|
+
- foo.toString() ==> foo+""
|
239
|
+
|
240
|
+
- =--max-line-len= (default 32K characters) --- add a newline after around
|
241
|
+
32K characters. I've seen both FF and Chrome croak when all the code was
|
242
|
+
on a single line of around 670K. Pass --max-line-len 0 to disable this
|
243
|
+
safety feature.
|
244
|
+
|
245
|
+
- =--reserved-names= --- some libraries rely on certain names to be used, as
|
246
|
+
pointed out in issue #92 and #81, so this option allow you to exclude such
|
247
|
+
names from the mangler. For example, to keep names =require= and =$super=
|
248
|
+
intact you'd specify --reserved-names "require,$super".
|
249
|
+
|
250
|
+
*** API
|
251
|
+
|
252
|
+
To use the library from JavaScript, you'd do the following (example for
|
253
|
+
NodeJS):
|
254
|
+
|
255
|
+
#+BEGIN_SRC js
|
256
|
+
var jsp = require("uglify-js").parser;
|
257
|
+
var pro = require("uglify-js").uglify;
|
258
|
+
|
259
|
+
var orig_code = "... JS code here";
|
260
|
+
var ast = jsp.parse(orig_code); // parse code and get the initial AST
|
261
|
+
ast = pro.ast_mangle(ast); // get a new AST with mangled names
|
262
|
+
ast = pro.ast_squeeze(ast); // get an AST with compression optimizations
|
263
|
+
var final_code = pro.gen_code(ast); // compressed code here
|
264
|
+
#+END_SRC
|
265
|
+
|
266
|
+
The above performs the full compression that is possible right now. As you
|
267
|
+
can see, there are a sequence of steps which you can apply. For example if
|
268
|
+
you want compressed output but for some reason you don't want to mangle
|
269
|
+
variable names, you would simply skip the line that calls
|
270
|
+
=pro.ast_mangle(ast)=.
|
271
|
+
|
272
|
+
Some of these functions take optional arguments. Here's a description:
|
273
|
+
|
274
|
+
- =jsp.parse(code, strict_semicolons)= -- parses JS code and returns an AST.
|
275
|
+
=strict_semicolons= is optional and defaults to =false=. If you pass
|
276
|
+
=true= then the parser will throw an error when it expects a semicolon and
|
277
|
+
it doesn't find it. For most JS code you don't want that, but it's useful
|
278
|
+
if you want to strictly sanitize your code.
|
279
|
+
|
280
|
+
- =pro.ast_mangle(ast, options)= -- generates a new AST containing mangled
|
281
|
+
(compressed) variable and function names. It supports the following
|
282
|
+
options:
|
283
|
+
|
284
|
+
- =toplevel= -- mangle toplevel names (by default we don't touch them).
|
285
|
+
- =except= -- an array of names to exclude from compression.
|
286
|
+
|
287
|
+
- =pro.ast_squeeze(ast, options)= -- employs further optimizations designed
|
288
|
+
to reduce the size of the code that =gen_code= would generate from the
|
289
|
+
AST. Returns a new AST. =options= can be a hash; the supported options
|
290
|
+
are:
|
291
|
+
|
292
|
+
- =make_seqs= (default true) which will cause consecutive statements in a
|
293
|
+
block to be merged using the "sequence" (comma) operator
|
294
|
+
|
295
|
+
- =dead_code= (default true) which will remove unreachable code.
|
296
|
+
|
297
|
+
- =pro.gen_code(ast, options)= -- generates JS code from the AST. By
|
298
|
+
default it's minified, but using the =options= argument you can get nicely
|
299
|
+
formatted output. =options= is, well, optional :-) and if you pass it it
|
300
|
+
must be an object and supports the following properties (below you can see
|
301
|
+
the default values):
|
302
|
+
|
303
|
+
- =beautify: false= -- pass =true= if you want indented output
|
304
|
+
- =indent_start: 0= (only applies when =beautify= is =true=) -- initial
|
305
|
+
indentation in spaces
|
306
|
+
- =indent_level: 4= (only applies when =beautify= is =true=) --
|
307
|
+
indentation level, in spaces (pass an even number)
|
308
|
+
- =quote_keys: false= -- if you pass =true= it will quote all keys in
|
309
|
+
literal objects
|
310
|
+
- =space_colon: false= (only applies when =beautify= is =true=) -- wether
|
311
|
+
to put a space before the colon in object literals
|
312
|
+
- =ascii_only: false= -- pass =true= if you want to encode non-ASCII
|
313
|
+
characters as =\uXXXX=.
|
314
|
+
|
315
|
+
*** Beautifier shortcoming -- no more comments
|
316
|
+
|
317
|
+
The beautifier can be used as a general purpose indentation tool. It's
|
318
|
+
useful when you want to make a minified file readable. One limitation,
|
319
|
+
though, is that it discards all comments, so you don't really want to use it
|
320
|
+
to reformat your code, unless you don't have, or don't care about, comments.
|
321
|
+
|
322
|
+
In fact it's not the beautifier who discards comments --- they are dumped at
|
323
|
+
the parsing stage, when we build the initial AST. Comments don't really
|
324
|
+
make sense in the AST, and while we could add nodes for them, it would be
|
325
|
+
inconvenient because we'd have to add special rules to ignore them at all
|
326
|
+
the processing stages.
|
327
|
+
|
328
|
+
** Compression -- how good is it?
|
329
|
+
|
330
|
+
(XXX: this is somewhat outdated. On the jQuery source code we beat Closure
|
331
|
+
by 168 bytes (560 after gzip) and by many seconds.)
|
332
|
+
|
333
|
+
There are a few popular JS minifiers nowadays -- the two most well known
|
334
|
+
being the GoogleClosure (GCL) compiler and the YUI compressor. For some
|
335
|
+
reason they are both written in Java. I didn't really hope to beat any of
|
336
|
+
them, but finally I did -- UglifyJS compresses better than the YUI
|
337
|
+
compressor, and safer than GoogleClosure.
|
338
|
+
|
339
|
+
I tested it on two big libraries. [[http://www.dynarchlib.com/][DynarchLIB]] is my own, and it's big enough
|
340
|
+
to contain probably all the JavaScript tricks known to mankind. [[http://jquery.com/][jQuery]] is
|
341
|
+
definitely the most popular JavaScript library (to some people, it's a
|
342
|
+
synonym to JavaScript itself).
|
343
|
+
|
344
|
+
I cannot swear that there are no bugs in the generated codes, but they
|
345
|
+
appear to work fine.
|
346
|
+
|
347
|
+
Compression results:
|
348
|
+
|
349
|
+
| Library | Orig. size | UglifyJS | YUI | GCL |
|
350
|
+
|------------+------------+----------+----------------+------------------------|
|
351
|
+
| DynarchLIB | 636896 | 241441 | 246452 (+5011) | 240439 (-1002) (buggy) |
|
352
|
+
| jQuery | 163855 | 72006 | 79702 (+7696) | 71858 (-148) |
|
353
|
+
|
354
|
+
UglifyJS is the fastest to run. On my laptop UglifyJS takes 1.35s for
|
355
|
+
DynarchLIB, while YUI takes 2.7s and GCL takes 6.5s.
|
356
|
+
|
357
|
+
GoogleClosure does a lot of smart ass optimizations. I had to strive really
|
358
|
+
hard to get close to it. It should be possible to even beat it, but then
|
359
|
+
again, GCL has a gazillion lines of code and runs terribly slow, so I'm not
|
360
|
+
sure it worths spending the effort to save a few bytes. Also, GCL doesn't
|
361
|
+
cope with =eval()= or =with{}= -- it just dumps a warning and proceeds to
|
362
|
+
mangle names anyway; my DynarchLIB compiled with it is buggy because of
|
363
|
+
this.
|
364
|
+
|
365
|
+
UglifyJS consists of ~1100 lines of code for the tokenizer/parser, and ~1100
|
366
|
+
lines for the compressor and code generator. That should make it very
|
367
|
+
maintainable and easily extensible, so I would say it has a good place in
|
368
|
+
this field and it's bound to become the de-facto standard JS minifier. And
|
369
|
+
I shall rule the world. :-) Use it, and *spread the word*!
|
370
|
+
|
371
|
+
** Bugs?
|
372
|
+
|
373
|
+
Unfortunately, for the time being there is no automated test suite. But I
|
374
|
+
ran the compressor manually on non-trivial code, and then I tested that the
|
375
|
+
generated code works as expected. A few hundred times.
|
376
|
+
|
377
|
+
DynarchLIB was started in times when there was no good JS minifier.
|
378
|
+
Therefore I was quite religious about trying to write short code manually,
|
379
|
+
and as such DL contains a lot of syntactic hacks[1] such as “foo == bar ? a
|
380
|
+
= 10 : b = 20”, though the more readable version would clearly be to use
|
381
|
+
“if/else”.
|
382
|
+
|
383
|
+
Since the parser/compressor runs fine on DL and jQuery, I'm quite confident
|
384
|
+
that it's solid enough for production use. If you can identify any bugs,
|
385
|
+
I'd love to hear about them ([[http://groups.google.com/group/uglifyjs][use the Google Group]] or email me directly).
|
386
|
+
|
387
|
+
[1] I even reported a few bugs and suggested some fixes in the original
|
388
|
+
[[http://marijn.haverbeke.nl/parse-js/][parse-js]] library, and Marijn pushed fixes literally in minutes.
|
389
|
+
|
390
|
+
** Links
|
391
|
+
|
392
|
+
- Project at GitHub: [[http://github.com/mishoo/UglifyJS][http://github.com/mishoo/UglifyJS]]
|
393
|
+
- Google Group: [[http://groups.google.com/group/uglifyjs][http://groups.google.com/group/uglifyjs]]
|
394
|
+
- Common Lisp JS parser: [[http://marijn.haverbeke.nl/parse-js/][http://marijn.haverbeke.nl/parse-js/]]
|
395
|
+
- JS-to-Lisp compiler: [[http://github.com/marijnh/js][http://github.com/marijnh/js]]
|
396
|
+
- Common Lisp JS uglifier: [[http://github.com/mishoo/cl-uglify-js][http://github.com/mishoo/cl-uglify-js]]
|
397
|
+
|
398
|
+
** License
|
399
|
+
|
400
|
+
UglifyJS is released under the BSD license:
|
401
|
+
|
402
|
+
#+BEGIN_EXAMPLE
|
403
|
+
Copyright 2010 (c) Mihai Bazon <mihai.bazon@gmail.com>
|
404
|
+
Based on parse-js (http://marijn.haverbeke.nl/parse-js/).
|
405
|
+
|
406
|
+
Redistribution and use in source and binary forms, with or without
|
407
|
+
modification, are permitted provided that the following conditions
|
408
|
+
are met:
|
409
|
+
|
410
|
+
* Redistributions of source code must retain the above
|
411
|
+
copyright notice, this list of conditions and the following
|
412
|
+
disclaimer.
|
413
|
+
|
414
|
+
* Redistributions in binary form must reproduce the above
|
415
|
+
copyright notice, this list of conditions and the following
|
416
|
+
disclaimer in the documentation and/or other materials
|
417
|
+
provided with the distribution.
|
418
|
+
|
419
|
+
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDER “AS IS” AND ANY
|
420
|
+
EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
|
421
|
+
IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
|
422
|
+
PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER BE
|
423
|
+
LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY,
|
424
|
+
OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
|
425
|
+
PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
|
426
|
+
PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
|
427
|
+
THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR
|
428
|
+
TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF
|
429
|
+
THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
|
430
|
+
SUCH DAMAGE.
|
431
|
+
#+END_EXAMPLE
|