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.
Files changed (341) hide show
  1. data/CHANGELOG.md +20 -0
  2. data/README.md +1 -1
  3. data/TODO.md +90 -2
  4. data/bpm.gemspec +3 -3
  5. data/lib/bpm/cli/base.rb +103 -52
  6. data/lib/bpm/errors.rb +51 -0
  7. data/lib/bpm/init_generator.rb +1 -8
  8. data/lib/bpm/libgems_ext/libgems.rb +9 -0
  9. data/lib/bpm/local.rb +6 -11
  10. data/lib/bpm/package.rb +272 -178
  11. data/lib/bpm/pipeline/generated_asset.rb +88 -28
  12. data/lib/bpm/pipeline/plugin_asset.rb +8 -2
  13. data/lib/bpm/pipeline/source_url_processor.rb +16 -0
  14. data/lib/bpm/pipeline/transport_processor.rb +5 -3
  15. data/lib/bpm/pipeline.rb +33 -23
  16. data/lib/bpm/project.rb +492 -167
  17. data/lib/bpm/project_generator.rb +14 -1
  18. data/lib/bpm/remote.rb +6 -4
  19. data/lib/bpm/server.rb +4 -15
  20. data/lib/bpm/version.rb +2 -1
  21. data/lib/bpm.rb +2 -0
  22. data/man/bpm-add.1.ronn +22 -0
  23. data/man/bpm-build.1.ronn +22 -0
  24. data/man/bpm-compile.1.ronn +23 -0
  25. data/man/bpm-config.7.ronn +21 -0
  26. data/man/bpm-fetch.1.ronn +22 -0
  27. data/man/bpm-fetched.1.ronn +22 -0
  28. data/man/bpm-init.1.ronn +22 -0
  29. data/man/bpm-list.1.ronn +22 -0
  30. data/man/bpm-login.1.ronn +22 -0
  31. data/man/bpm-new.1.ronn +22 -0
  32. data/man/bpm-owner.1.ronn +22 -0
  33. data/man/bpm-preview.1.ronn +22 -0
  34. data/man/bpm-push.1.ronn +22 -0
  35. data/man/bpm-remove.1.ronn +22 -0
  36. data/man/bpm-unpack.1.ronn +22 -0
  37. data/man/bpm-yank.1.ronn +22 -0
  38. data/man/bpm.1.ronn +31 -0
  39. data/spec/cli/add_spec.rb +26 -7
  40. data/spec/cli/fetch_spec.rb +15 -6
  41. data/spec/cli/init_spec.rb +165 -25
  42. data/spec/cli/{build_spec.rb → pack_spec.rb} +9 -10
  43. data/spec/cli/push_spec.rb +4 -4
  44. data/spec/cli/rebuild_spec.rb +181 -0
  45. data/spec/cli/remove_spec.rb +3 -4
  46. data/spec/cli/unpack_spec.rb +6 -6
  47. data/spec/fixtures/gems/core-test-0.4.9.bpkg +0 -0
  48. data/spec/fixtures/{core-test-0.4.9.bpkg → gems/uglify-js-1.0.4.bpkg} +0 -0
  49. data/spec/fixtures/packages/core-test/extras/extra_file.html +3 -0
  50. data/spec/fixtures/packages/core-test/index.html +3 -0
  51. data/spec/fixtures/{core-test → packages/core-test}/package.json +9 -3
  52. data/spec/fixtures/packages/invalid_json/package.json +3 -0
  53. data/spec/fixtures/packages/uglify-js/README.html +825 -0
  54. data/spec/fixtures/packages/uglify-js/README.org +431 -0
  55. data/spec/fixtures/packages/uglify-js/bin/uglifyjs +305 -0
  56. data/spec/fixtures/packages/uglify-js/docstyle.css +75 -0
  57. data/spec/fixtures/packages/uglify-js/lib/parse-js.js +1 -0
  58. data/spec/fixtures/packages/uglify-js/lib/process.js +1 -0
  59. data/spec/fixtures/packages/uglify-js/lib/squeeze-more.js +1 -0
  60. data/spec/fixtures/packages/uglify-js/package.json +27 -0
  61. data/spec/fixtures/packages/uglify-js/plugins/minifier.js +6 -0
  62. data/spec/fixtures/packages/uglify-js/uglify-js.js +17 -0
  63. data/spec/fixtures/projects/hello2/README.md +21 -0
  64. data/{templates/init → spec/fixtures/projects/hello2}/assets/bpm_packages.js +6 -1
  65. data/{templates/init → spec/fixtures/projects/hello2}/assets/bpm_styles.css +1 -1
  66. data/spec/fixtures/projects/hello2/hello2.json +16 -0
  67. data/spec/fixtures/projects/hello2/index.html +13 -0
  68. data/spec/fixtures/projects/hello2/packages/a/lib/main.js +2 -0
  69. data/spec/fixtures/projects/hello2/packages/a/package.json +17 -0
  70. data/spec/fixtures/projects/hello2/packages/b/lib/main.js +2 -0
  71. data/spec/fixtures/projects/hello2/packages/b/package.json +17 -0
  72. data/spec/fixtures/projects/hello2/packages/c/lib/main.js +2 -0
  73. data/spec/fixtures/projects/hello2/packages/c/package.json +16 -0
  74. data/spec/fixtures/projects/hello_dev/LICENSE +19 -0
  75. data/spec/fixtures/projects/hello_dev/README.md +21 -0
  76. data/spec/fixtures/projects/hello_dev/app/main.js +6 -0
  77. data/spec/fixtures/projects/hello_dev/assets/bpm_libs.js +5 -0
  78. data/spec/fixtures/projects/hello_dev/assets/bpm_styles.css +6 -0
  79. data/spec/fixtures/projects/hello_dev/css/main.css +1 -0
  80. data/spec/fixtures/projects/hello_dev/hello_dev.json +25 -0
  81. data/spec/fixtures/projects/hello_dev/index.html +14 -0
  82. data/spec/fixtures/projects/hello_dev/packages/style_package/css/some_style.css +3 -0
  83. data/spec/fixtures/{minitest/minitest.json → projects/hello_dev/packages/style_package/package.json} +5 -9
  84. data/spec/fixtures/projects/hello_world/LICENSE +19 -0
  85. data/spec/fixtures/projects/hello_world/assets/bpm_packages.js +1 -0
  86. data/spec/fixtures/projects/hello_world/assets/bpm_styles.css +1 -0
  87. data/spec/fixtures/projects/hello_world/custom_dir/custom.js +1 -0
  88. data/spec/fixtures/projects/hello_world/hello_world.json +41 -0
  89. data/spec/fixtures/projects/hello_world/lib/another.js +1 -0
  90. data/spec/fixtures/{hello_world → projects/hello_world}/packages/custom_package/package.json +5 -2
  91. data/spec/fixtures/projects/hello_world/vendor/lib/something.js +1 -0
  92. data/spec/fixtures/projects/init_app/assets/bpm_libs.js +6 -0
  93. data/spec/fixtures/projects/init_app/assets/bpm_styles.css +5 -0
  94. data/spec/fixtures/projects/init_app/assets/new_project/bpm_libs.js +6 -0
  95. data/spec/fixtures/projects/init_app/assets/new_project/bpm_styles.css +5 -0
  96. data/spec/fixtures/projects/init_app/new_project.json +27 -0
  97. data/spec/fixtures/projects/init_default/assets/bpm_libs.js +6 -0
  98. data/spec/fixtures/projects/init_default/assets/bpm_styles.css +5 -0
  99. data/spec/fixtures/projects/init_default/new_project.json +15 -0
  100. data/spec/fixtures/projects/minitest/minitest.json +26 -0
  101. data/spec/fixtures/{minitest → projects/minitest}/packages/uglyduck/package.json +1 -1
  102. data/spec/fixtures/projects/needs_rake/needs_rake.json +7 -0
  103. data/spec/fixtures/{transporter → projects/transporter}/packages/transport/package.json +1 -1
  104. data/spec/package_spec.rb +343 -315
  105. data/spec/pipeline_spec.rb +89 -71
  106. data/spec/plugins/minifier_spec.rb +25 -16
  107. data/spec/plugins/transport_spec.rb +1 -1
  108. data/spec/project_spec.rb +97 -34
  109. data/spec/spec_helper.rb +41 -0
  110. data/spec/support/fake_gem_server.rb +8 -4
  111. data/spec/support/path.rb +8 -0
  112. data/spec/support/project.rb +50 -17
  113. data/templates/init/project.json +12 -14
  114. data/templates/project/LICENSE +1 -1
  115. data/templates/project/app/main.js +6 -0
  116. data/templates/project/css/main.css +1 -0
  117. data/templates/project/index.html +4 -3
  118. data/vendor/sprockets/.travis.yml +3 -2
  119. data/vendor/sprockets/Gemfile +0 -6
  120. data/vendor/sprockets/lib/sprockets/asset.rb +7 -12
  121. data/vendor/sprockets/lib/sprockets/asset_attributes.rb +70 -53
  122. data/vendor/sprockets/lib/sprockets/base.rb +1 -14
  123. data/vendor/sprockets/lib/sprockets/bundled_asset.rb +72 -45
  124. data/vendor/sprockets/lib/sprockets/caching.rb +28 -23
  125. data/vendor/sprockets/lib/sprockets/context.rb +56 -26
  126. data/vendor/sprockets/lib/sprockets/directive_processor.rb +21 -4
  127. data/vendor/sprockets/lib/sprockets/eco_template.rb +3 -4
  128. data/vendor/sprockets/lib/sprockets/ejs_template.rb +3 -4
  129. data/vendor/sprockets/lib/sprockets/engines.rb +26 -1
  130. data/vendor/sprockets/lib/sprockets/environment.rb +2 -1
  131. data/vendor/sprockets/lib/sprockets/index.rb +1 -0
  132. data/vendor/sprockets/lib/sprockets/mime.rb +38 -0
  133. data/vendor/sprockets/lib/sprockets/processing.rb +4 -45
  134. data/vendor/sprockets/lib/sprockets/static_asset.rb +5 -6
  135. data/vendor/sprockets/lib/sprockets/static_compilation.rb +4 -12
  136. data/vendor/sprockets/lib/sprockets/trail.rb +2 -1
  137. data/vendor/sprockets/test/fixtures/default/blank.gif +0 -0
  138. data/vendor/sprockets/test/fixtures/default/with_data_uri.css.erb +3 -0
  139. data/vendor/sprockets/test/test_asset.rb +121 -15
  140. data/vendor/sprockets/test/test_asset_attributes.rb +85 -21
  141. data/vendor/sprockets/test/test_environment.rb +13 -36
  142. metadata +564 -444
  143. data/spec/cli/new_spec.rb +0 -118
  144. data/spec/fixtures/hello_world/assets/bpm_packages.js +0 -13
  145. data/spec/fixtures/hello_world/assets/bpm_styles.css +0 -14
  146. data/spec/fixtures/hello_world/hello_world.json +0 -20
  147. /data/spec/fixtures/{badrake-0.8.7.bpkg → gems/badrake-0.8.7.bpkg} +0 -0
  148. /data/spec/fixtures/{builder-3.0.0.bpkg → gems/builder-3.0.0.bpkg} +0 -0
  149. /data/spec/fixtures/{bundler-1.1.pre.bpkg → gems/bundler-1.1.pre.bpkg} +0 -0
  150. /data/spec/fixtures/{coffee-1.0.1.pre.bpkg → gems/coffee-1.0.1.pre.bpkg} +0 -0
  151. /data/spec/fixtures/{custom_generator-1.0.bpkg → gems/custom_generator-1.0.bpkg} +0 -0
  152. /data/spec/fixtures/{highline-1.6.1.bpkg → gems/highline-1.6.1.bpkg} +0 -0
  153. /data/spec/fixtures/{ivory-0.0.1.bpkg → gems/ivory-0.0.1.bpkg} +0 -0
  154. /data/spec/fixtures/{jquery-1.4.3.bpkg → gems/jquery-1.4.3.bpkg} +0 -0
  155. /data/spec/fixtures/{optparse-1.0.1.bpkg → gems/optparse-1.0.1.bpkg} +0 -0
  156. /data/spec/fixtures/{rake-0.8.6.bpkg → gems/rake-0.8.6.bpkg} +0 -0
  157. /data/spec/fixtures/{rake-0.8.7.bpkg → gems/rake-0.8.7.bpkg} +0 -0
  158. /data/spec/fixtures/{spade-0.5.0.bpkg → gems/spade-0.5.0.bpkg} +0 -0
  159. /data/spec/fixtures/{src → packages}/README.txt +0 -0
  160. /data/spec/fixtures/{src → packages}/bundler-1.1.pre/.gitignore +0 -0
  161. /data/spec/fixtures/{src → packages}/bundler-1.1.pre/CHANGELOG.md +0 -0
  162. /data/spec/fixtures/{src → packages}/bundler-1.1.pre/ISSUES.md +0 -0
  163. /data/spec/fixtures/{src → packages}/bundler-1.1.pre/LICENSE +0 -0
  164. /data/spec/fixtures/{src → packages}/bundler-1.1.pre/README.md +0 -0
  165. /data/spec/fixtures/{src → packages}/bundler-1.1.pre/UPGRADING.md +0 -0
  166. /data/spec/fixtures/{src → packages}/bundler-1.1.pre/bin/bundle +0 -0
  167. /data/spec/fixtures/{src → packages}/bundler-1.1.pre/lib/bundler/definition.js +0 -0
  168. /data/spec/fixtures/{src → packages}/bundler-1.1.pre/lib/bundler/dependency.js +0 -0
  169. /data/spec/fixtures/{src → packages}/bundler-1.1.pre/lib/bundler/dsl.js +0 -0
  170. /data/spec/fixtures/{src → packages}/bundler-1.1.pre/lib/bundler/ui.js +0 -0
  171. /data/spec/fixtures/{src → packages}/bundler-1.1.pre/lib/bundler.js +0 -0
  172. /data/spec/fixtures/{src → packages}/bundler-1.1.pre/man/bundle-config.ronn +0 -0
  173. /data/spec/fixtures/{src → packages}/bundler-1.1.pre/man/bundle-exec.ronn +0 -0
  174. /data/spec/fixtures/{src → packages}/bundler-1.1.pre/man/bundle-install.ronn +0 -0
  175. /data/spec/fixtures/{src → packages}/bundler-1.1.pre/man/bundle-package.ronn +0 -0
  176. /data/spec/fixtures/{src → packages}/bundler-1.1.pre/man/bundle-update.ronn +0 -0
  177. /data/spec/fixtures/{src → packages}/bundler-1.1.pre/man/bundle.ronn +0 -0
  178. /data/spec/fixtures/{src → packages}/bundler-1.1.pre/man/gemfile.5.ronn +0 -0
  179. /data/spec/fixtures/{src → packages}/bundler-1.1.pre/man/index.txt +0 -0
  180. /data/spec/fixtures/{src → packages}/bundler-1.1.pre/package.json +0 -0
  181. /data/spec/fixtures/{src → packages}/coffee-1.0.1.pre/bin/cake +0 -0
  182. /data/spec/fixtures/{src → packages}/coffee-1.0.1.pre/bin/coffee +0 -0
  183. /data/spec/fixtures/{src → packages}/coffee-1.0.1.pre/lib/coffee/base.js +0 -0
  184. /data/spec/fixtures/{src → packages}/coffee-1.0.1.pre/lib/coffee/mocha/chai.js +0 -0
  185. /data/spec/fixtures/{src → packages}/coffee-1.0.1.pre/lib/coffee.js +0 -0
  186. /data/spec/fixtures/{src → packages}/coffee-1.0.1.pre/package.json +0 -0
  187. /data/spec/fixtures/{src → packages}/coffee-1.0.1.pre/qunit/coffee/test.js +0 -0
  188. /data/spec/fixtures/{src → packages}/coffee-1.0.1.pre/qunit/test.js +0 -0
  189. /data/spec/fixtures/{core-test → packages/core-test}/bin/cot +0 -0
  190. /data/spec/fixtures/{core-test → packages/core-test}/lib/main.js +0 -0
  191. /data/spec/fixtures/{core-test → packages/core-test}/resources/runner.css +0 -0
  192. /data/spec/fixtures/{core-test → packages/core-test}/tests/test.js +0 -0
  193. /data/spec/fixtures/{custom_generator → packages/custom_generator}/lib/main.js +0 -0
  194. /data/spec/fixtures/{custom_generator → packages/custom_generator}/package.json +0 -0
  195. /data/spec/fixtures/{custom_generator → packages/custom_generator}/templates/init/project.json +0 -0
  196. /data/spec/fixtures/{custom_generator → packages/custom_generator}/templates/project/app.js +0 -0
  197. /data/spec/fixtures/{custom_generator → packages/custom_generator}/templates/project/lib/main.js +0 -0
  198. /data/spec/fixtures/{custom_generator → packages/custom_generator}/templates/project_generator.rb +0 -0
  199. /data/spec/fixtures/{src → packages}/jquery/lib/main.js +0 -0
  200. /data/spec/fixtures/{src → packages}/jquery/package.json +0 -0
  201. /data/spec/fixtures/{src → packages}/rake-0.8.6/CHANGES +0 -0
  202. /data/spec/fixtures/{src → packages}/rake-0.8.6/MIT-LICENSE +0 -0
  203. /data/spec/fixtures/{src → packages}/rake-0.8.6/README +0 -0
  204. /data/spec/fixtures/{src → packages}/rake-0.8.6/Rakefile +0 -0
  205. /data/spec/fixtures/{src → packages}/rake-0.8.6/TODO +0 -0
  206. /data/spec/fixtures/{src → packages}/rake-0.8.6/bin/rake +0 -0
  207. /data/spec/fixtures/{src → packages}/rake-0.8.6/doc/command_line_usage.rdoc +0 -0
  208. /data/spec/fixtures/{src → packages}/rake-0.8.6/doc/example/Rakefile1 +0 -0
  209. /data/spec/fixtures/{src → packages}/rake-0.8.6/doc/example/Rakefile2 +0 -0
  210. /data/spec/fixtures/{src → packages}/rake-0.8.6/doc/example/a.c +0 -0
  211. /data/spec/fixtures/{src → packages}/rake-0.8.6/doc/example/b.c +0 -0
  212. /data/spec/fixtures/{src → packages}/rake-0.8.6/doc/example/main.c +0 -0
  213. /data/spec/fixtures/{src → packages}/rake-0.8.6/doc/glossary.rdoc +0 -0
  214. /data/spec/fixtures/{src → packages}/rake-0.8.6/doc/jamis.rb +0 -0
  215. /data/spec/fixtures/{src → packages}/rake-0.8.6/doc/proto_rake.rdoc +0 -0
  216. /data/spec/fixtures/{src → packages}/rake-0.8.6/doc/rake.1.gz +0 -0
  217. /data/spec/fixtures/{src → packages}/rake-0.8.6/doc/rakefile.rdoc +0 -0
  218. /data/spec/fixtures/{src → packages}/rake-0.8.6/doc/rational.rdoc +0 -0
  219. /data/spec/fixtures/{src → packages}/rake-0.8.6/doc/release_notes/rake-0.4.14.rdoc +0 -0
  220. /data/spec/fixtures/{src → packages}/rake-0.8.6/doc/release_notes/rake-0.4.15.rdoc +0 -0
  221. /data/spec/fixtures/{src → packages}/rake-0.8.6/doc/release_notes/rake-0.5.0.rdoc +0 -0
  222. /data/spec/fixtures/{src → packages}/rake-0.8.6/doc/release_notes/rake-0.5.3.rdoc +0 -0
  223. /data/spec/fixtures/{src → packages}/rake-0.8.6/doc/release_notes/rake-0.5.4.rdoc +0 -0
  224. /data/spec/fixtures/{src → packages}/rake-0.8.6/doc/release_notes/rake-0.6.0.rdoc +0 -0
  225. /data/spec/fixtures/{src → packages}/rake-0.8.6/doc/release_notes/rake-0.7.0.rdoc +0 -0
  226. /data/spec/fixtures/{src → packages}/rake-0.8.6/doc/release_notes/rake-0.7.1.rdoc +0 -0
  227. /data/spec/fixtures/{src → packages}/rake-0.8.6/doc/release_notes/rake-0.7.2.rdoc +0 -0
  228. /data/spec/fixtures/{src → packages}/rake-0.8.6/doc/release_notes/rake-0.7.3.rdoc +0 -0
  229. /data/spec/fixtures/{src → packages}/rake-0.8.6/doc/release_notes/rake-0.8.0.rdoc +0 -0
  230. /data/spec/fixtures/{src → packages}/rake-0.8.6/doc/release_notes/rake-0.8.2.rdoc +0 -0
  231. /data/spec/fixtures/{src → packages}/rake-0.8.6/doc/release_notes/rake-0.8.3.rdoc +0 -0
  232. /data/spec/fixtures/{src → packages}/rake-0.8.6/doc/release_notes/rake-0.8.4.rdoc +0 -0
  233. /data/spec/fixtures/{src → packages}/rake-0.8.6/doc/release_notes/rake-0.8.5.rdoc +0 -0
  234. /data/spec/fixtures/{src → packages}/rake-0.8.6/doc/release_notes/rake-0.8.6.rdoc +0 -0
  235. /data/spec/fixtures/{src → packages}/rake-0.8.6/install.rb +0 -0
  236. /data/spec/fixtures/{src → packages}/rake-0.8.6/lib/rake/alt_system.rb +0 -0
  237. /data/spec/fixtures/{src → packages}/rake-0.8.6/lib/rake/classic_namespace.rb +0 -0
  238. /data/spec/fixtures/{src → packages}/rake-0.8.6/lib/rake/clean.rb +0 -0
  239. /data/spec/fixtures/{src → packages}/rake-0.8.6/lib/rake/contrib/compositepublisher.rb +0 -0
  240. /data/spec/fixtures/{src → packages}/rake-0.8.6/lib/rake/contrib/ftptools.rb +0 -0
  241. /data/spec/fixtures/{src → packages}/rake-0.8.6/lib/rake/contrib/publisher.rb +0 -0
  242. /data/spec/fixtures/{src → packages}/rake-0.8.6/lib/rake/contrib/rubyforgepublisher.rb +0 -0
  243. /data/spec/fixtures/{src → packages}/rake-0.8.6/lib/rake/contrib/sshpublisher.rb +0 -0
  244. /data/spec/fixtures/{src → packages}/rake-0.8.6/lib/rake/contrib/sys.rb +0 -0
  245. /data/spec/fixtures/{src → packages}/rake-0.8.6/lib/rake/gempackagetask.rb +0 -0
  246. /data/spec/fixtures/{src → packages}/rake-0.8.6/lib/rake/loaders/makefile.rb +0 -0
  247. /data/spec/fixtures/{src → packages}/rake-0.8.6/lib/rake/packagetask.rb +0 -0
  248. /data/spec/fixtures/{src → packages}/rake-0.8.6/lib/rake/rake_test_loader.rb +0 -0
  249. /data/spec/fixtures/{src → packages}/rake-0.8.6/lib/rake/rdoctask.rb +0 -0
  250. /data/spec/fixtures/{src → packages}/rake-0.8.6/lib/rake/ruby182_test_unit_fix.rb +0 -0
  251. /data/spec/fixtures/{src → packages}/rake-0.8.6/lib/rake/runtest.rb +0 -0
  252. /data/spec/fixtures/{src → packages}/rake-0.8.6/lib/rake/tasklib.rb +0 -0
  253. /data/spec/fixtures/{src → packages}/rake-0.8.6/lib/rake/testtask.rb +0 -0
  254. /data/spec/fixtures/{src → packages}/rake-0.8.6/lib/rake/win32.rb +0 -0
  255. /data/spec/fixtures/{src → packages}/rake-0.8.6/lib/rake.rb +0 -0
  256. /data/spec/fixtures/{src → packages}/rake-0.8.6/package.json +0 -0
  257. /data/spec/fixtures/{src → packages}/rake-0.8.6/test/capture_stdout.rb +0 -0
  258. /data/spec/fixtures/{src → packages}/rake-0.8.7/CHANGES +0 -0
  259. /data/spec/fixtures/{src → packages}/rake-0.8.7/MIT-LICENSE +0 -0
  260. /data/spec/fixtures/{src → packages}/rake-0.8.7/README +0 -0
  261. /data/spec/fixtures/{src → packages}/rake-0.8.7/Rakefile +0 -0
  262. /data/spec/fixtures/{src → packages}/rake-0.8.7/TODO +0 -0
  263. /data/spec/fixtures/{src → packages}/rake-0.8.7/bin/rake +0 -0
  264. /data/spec/fixtures/{src → packages}/rake-0.8.7/doc/command_line_usage.rdoc +0 -0
  265. /data/spec/fixtures/{src → packages}/rake-0.8.7/doc/example/Rakefile1 +0 -0
  266. /data/spec/fixtures/{src → packages}/rake-0.8.7/doc/example/Rakefile2 +0 -0
  267. /data/spec/fixtures/{src → packages}/rake-0.8.7/doc/example/a.c +0 -0
  268. /data/spec/fixtures/{src → packages}/rake-0.8.7/doc/example/b.c +0 -0
  269. /data/spec/fixtures/{src → packages}/rake-0.8.7/doc/example/main.c +0 -0
  270. /data/spec/fixtures/{src → packages}/rake-0.8.7/doc/glossary.rdoc +0 -0
  271. /data/spec/fixtures/{src → packages}/rake-0.8.7/doc/jamis.rb +0 -0
  272. /data/spec/fixtures/{src → packages}/rake-0.8.7/doc/proto_rake.rdoc +0 -0
  273. /data/spec/fixtures/{src → packages}/rake-0.8.7/doc/rake.1.gz +0 -0
  274. /data/spec/fixtures/{src → packages}/rake-0.8.7/doc/rakefile.rdoc +0 -0
  275. /data/spec/fixtures/{src → packages}/rake-0.8.7/doc/rational.rdoc +0 -0
  276. /data/spec/fixtures/{src → packages}/rake-0.8.7/doc/release_notes/rake-0.4.14.rdoc +0 -0
  277. /data/spec/fixtures/{src → packages}/rake-0.8.7/doc/release_notes/rake-0.4.15.rdoc +0 -0
  278. /data/spec/fixtures/{src → packages}/rake-0.8.7/doc/release_notes/rake-0.5.0.rdoc +0 -0
  279. /data/spec/fixtures/{src → packages}/rake-0.8.7/doc/release_notes/rake-0.5.3.rdoc +0 -0
  280. /data/spec/fixtures/{src → packages}/rake-0.8.7/doc/release_notes/rake-0.5.4.rdoc +0 -0
  281. /data/spec/fixtures/{src → packages}/rake-0.8.7/doc/release_notes/rake-0.6.0.rdoc +0 -0
  282. /data/spec/fixtures/{src → packages}/rake-0.8.7/doc/release_notes/rake-0.7.0.rdoc +0 -0
  283. /data/spec/fixtures/{src → packages}/rake-0.8.7/doc/release_notes/rake-0.7.1.rdoc +0 -0
  284. /data/spec/fixtures/{src → packages}/rake-0.8.7/doc/release_notes/rake-0.7.2.rdoc +0 -0
  285. /data/spec/fixtures/{src → packages}/rake-0.8.7/doc/release_notes/rake-0.7.3.rdoc +0 -0
  286. /data/spec/fixtures/{src → packages}/rake-0.8.7/doc/release_notes/rake-0.8.0.rdoc +0 -0
  287. /data/spec/fixtures/{src → packages}/rake-0.8.7/doc/release_notes/rake-0.8.2.rdoc +0 -0
  288. /data/spec/fixtures/{src → packages}/rake-0.8.7/doc/release_notes/rake-0.8.3.rdoc +0 -0
  289. /data/spec/fixtures/{src → packages}/rake-0.8.7/doc/release_notes/rake-0.8.4.rdoc +0 -0
  290. /data/spec/fixtures/{src → packages}/rake-0.8.7/doc/release_notes/rake-0.8.5.rdoc +0 -0
  291. /data/spec/fixtures/{src → packages}/rake-0.8.7/doc/release_notes/rake-0.8.6.rdoc +0 -0
  292. /data/spec/fixtures/{src → packages}/rake-0.8.7/doc/release_notes/rake-0.8.7.rdoc +0 -0
  293. /data/spec/fixtures/{src → packages}/rake-0.8.7/install.rb +0 -0
  294. /data/spec/fixtures/{src → packages}/rake-0.8.7/lib/rake/alt_system.rb +0 -0
  295. /data/spec/fixtures/{src → packages}/rake-0.8.7/lib/rake/classic_namespace.rb +0 -0
  296. /data/spec/fixtures/{src → packages}/rake-0.8.7/lib/rake/clean.rb +0 -0
  297. /data/spec/fixtures/{src → packages}/rake-0.8.7/lib/rake/contrib/compositepublisher.rb +0 -0
  298. /data/spec/fixtures/{src → packages}/rake-0.8.7/lib/rake/contrib/ftptools.rb +0 -0
  299. /data/spec/fixtures/{src → packages}/rake-0.8.7/lib/rake/contrib/publisher.rb +0 -0
  300. /data/spec/fixtures/{src → packages}/rake-0.8.7/lib/rake/contrib/rubyforgepublisher.rb +0 -0
  301. /data/spec/fixtures/{src → packages}/rake-0.8.7/lib/rake/contrib/sshpublisher.rb +0 -0
  302. /data/spec/fixtures/{src → packages}/rake-0.8.7/lib/rake/contrib/sys.rb +0 -0
  303. /data/spec/fixtures/{src → packages}/rake-0.8.7/lib/rake/gempackagetask.rb +0 -0
  304. /data/spec/fixtures/{src → packages}/rake-0.8.7/lib/rake/loaders/makefile.rb +0 -0
  305. /data/spec/fixtures/{src → packages}/rake-0.8.7/lib/rake/packagetask.rb +0 -0
  306. /data/spec/fixtures/{src → packages}/rake-0.8.7/lib/rake/rake_test_loader.rb +0 -0
  307. /data/spec/fixtures/{src → packages}/rake-0.8.7/lib/rake/rdoctask.rb +0 -0
  308. /data/spec/fixtures/{src → packages}/rake-0.8.7/lib/rake/ruby182_test_unit_fix.rb +0 -0
  309. /data/spec/fixtures/{src → packages}/rake-0.8.7/lib/rake/runtest.rb +0 -0
  310. /data/spec/fixtures/{src → packages}/rake-0.8.7/lib/rake/tasklib.rb +0 -0
  311. /data/spec/fixtures/{src → packages}/rake-0.8.7/lib/rake/testtask.rb +0 -0
  312. /data/spec/fixtures/{src → packages}/rake-0.8.7/lib/rake/win32.rb +0 -0
  313. /data/spec/fixtures/{src → packages}/rake-0.8.7/lib/rake.rb +0 -0
  314. /data/spec/fixtures/{src → packages}/rake-0.8.7/package.json +0 -0
  315. /data/spec/fixtures/{src → packages}/rake-0.8.7/test/capture_stdout.rb +0 -0
  316. /data/spec/fixtures/{src → packages}/spade/lib/main.js +0 -0
  317. /data/spec/fixtures/{src → packages}/spade/package.json +0 -0
  318. /data/spec/fixtures/{custom_name → projects/custom_name}/MyProject.json +0 -0
  319. /data/spec/fixtures/{hello_world → projects/hello2}/LICENSE +0 -0
  320. /data/{templates/project → spec/fixtures/projects/hello2}/app.js +0 -0
  321. /data/spec/fixtures/{hello_world → projects/hello_world}/README.md +0 -0
  322. /data/spec/fixtures/{hello_world → projects/hello_world}/assets/papa-smurf.jpg +0 -0
  323. /data/spec/fixtures/{hello_world → projects/hello_world}/css/dummy.css +0 -0
  324. /data/spec/fixtures/{hello_world → projects/hello_world}/lib/main.js +0 -0
  325. /data/spec/fixtures/{hello_world → projects/hello_world}/packages/custom_package/assets/dummy.txt +0 -0
  326. /data/spec/fixtures/{hello_world → projects/hello_world}/packages/custom_package/css/sample_styles.css +0 -0
  327. /data/spec/fixtures/{hello_world → projects/hello_world}/packages/custom_package/custom_dir/basic-module.js +0 -0
  328. /data/spec/fixtures/{hello_world → projects/hello_world}/packages/custom_package/lib/main.js +0 -0
  329. /data/spec/fixtures/{hello_world → projects/hello_world}/tests/main-test.js +0 -0
  330. /data/spec/fixtures/{minitest → projects/minitest}/assets/bpm_packages.js +0 -0
  331. /data/spec/fixtures/{minitest → projects/minitest}/assets/bpm_styles.css +0 -0
  332. /data/spec/fixtures/{minitest → projects/minitest}/assets/minitest/app_package.js +0 -0
  333. /data/spec/fixtures/{minitest → projects/minitest}/lib/main.js +0 -0
  334. /data/spec/fixtures/{minitest → projects/minitest}/packages/uglyduck/lib/main.js +0 -0
  335. /data/spec/fixtures/{minitest → projects/minitest}/packages/uglyduck/minifier/main.js +0 -0
  336. /data/spec/fixtures/{simple_hello/assets/bpm_packages.js → projects/simple_hello/assets/bpm_libs.js} +0 -0
  337. /data/spec/fixtures/{simple_hello → projects/simple_hello}/lib/main.js +0 -0
  338. /data/spec/fixtures/{transporter → projects/transporter}/lib/main.js +0 -0
  339. /data/spec/fixtures/{transporter → projects/transporter}/packages/transport/lib/main.js +0 -0
  340. /data/spec/fixtures/{transporter → projects/transporter}/packages/transport/transports/wrapper.js +0 -0
  341. /data/spec/fixtures/{transporter → projects/transporter}/transporter.json +0 -0
@@ -0,0 +1,825 @@
1
+ <?xml version="1.0" encoding="utf-8"?>
2
+ <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN"
3
+ "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
4
+ <html xmlns="http://www.w3.org/1999/xhtml"
5
+ lang="en" xml:lang="en">
6
+ <head>
7
+ <title>UglifyJS -- a JavaScript parser/compressor/beautifier</title>
8
+ <meta http-equiv="Content-Type" content="text/html;charset=utf-8"/>
9
+ <meta name="generator" content="Org-mode"/>
10
+ <meta name="generated" content="2011-04-04 00:07:13 EEST"/>
11
+ <meta name="author" content="Mihai Bazon"/>
12
+ <meta name="description" content="a JavaScript parser/compressor/beautifier in JavaScript"/>
13
+ <meta name="keywords" content="javascript, js, parser, compiler, compressor, mangle, minify, minifier"/>
14
+ <style type="text/css">
15
+ <!--/*--><![CDATA[/*><!--*/
16
+ html { font-family: Times, serif; font-size: 12pt; }
17
+ .title { text-align: center; }
18
+ .todo { color: red; }
19
+ .done { color: green; }
20
+ .tag { background-color: #add8e6; font-weight:normal }
21
+ .target { }
22
+ .timestamp { color: #bebebe; }
23
+ .timestamp-kwd { color: #5f9ea0; }
24
+ p.verse { margin-left: 3% }
25
+ pre {
26
+ border: 1pt solid #AEBDCC;
27
+ background-color: #F3F5F7;
28
+ padding: 5pt;
29
+ font-family: courier, monospace;
30
+ font-size: 90%;
31
+ overflow:auto;
32
+ }
33
+ table { border-collapse: collapse; }
34
+ td, th { vertical-align: top; }
35
+ dt { font-weight: bold; }
36
+ div.figure { padding: 0.5em; }
37
+ div.figure p { text-align: center; }
38
+ textarea { overflow-x: auto; }
39
+ .linenr { font-size:smaller }
40
+ .code-highlighted {background-color:#ffff00;}
41
+ .org-info-js_info-navigation { border-style:none; }
42
+ #org-info-js_console-label { font-size:10px; font-weight:bold;
43
+ white-space:nowrap; }
44
+ .org-info-js_search-highlight {background-color:#ffff00; color:#000000;
45
+ font-weight:bold; }
46
+ /*]]>*/-->
47
+ </style>
48
+ <link rel="stylesheet" type="text/css" href="docstyle.css" />
49
+ <script type="text/javascript">
50
+ <!--/*--><![CDATA[/*><!--*/
51
+ function CodeHighlightOn(elem, id)
52
+ {
53
+ var target = document.getElementById(id);
54
+ if(null != target) {
55
+ elem.cacheClassElem = elem.className;
56
+ elem.cacheClassTarget = target.className;
57
+ target.className = "code-highlighted";
58
+ elem.className = "code-highlighted";
59
+ }
60
+ }
61
+ function CodeHighlightOff(elem, id)
62
+ {
63
+ var target = document.getElementById(id);
64
+ if(elem.cacheClassElem)
65
+ elem.className = elem.cacheClassElem;
66
+ if(elem.cacheClassTarget)
67
+ target.className = elem.cacheClassTarget;
68
+ }
69
+ /*]]>*///-->
70
+ </script>
71
+
72
+ </head>
73
+ <body>
74
+ <div id="content">
75
+
76
+ <h1 class="title">UglifyJS &ndash; a JavaScript parser/compressor/beautifier</h1>
77
+
78
+
79
+ <div id="table-of-contents">
80
+ <h2>Table of Contents</h2>
81
+ <div id="text-table-of-contents">
82
+ <ul>
83
+ <li><a href="#sec-1">1 UglifyJS &mdash; a JavaScript parser/compressor/beautifier </a>
84
+ <ul>
85
+ <li><a href="#sec-1_1">1.1 Unsafe transformations </a>
86
+ <ul>
87
+ <li><a href="#sec-1_1_1">1.1.1 Calls involving the global Array constructor </a></li>
88
+ </ul>
89
+ </li>
90
+ <li><a href="#sec-1_2">1.2 Install (NPM) </a></li>
91
+ <li><a href="#sec-1_3">1.3 Install latest code from GitHub </a></li>
92
+ <li><a href="#sec-1_4">1.4 Usage </a>
93
+ <ul>
94
+ <li><a href="#sec-1_4_1">1.4.1 API </a></li>
95
+ <li><a href="#sec-1_4_2">1.4.2 Beautifier shortcoming &ndash; no more comments </a></li>
96
+ </ul>
97
+ </li>
98
+ <li><a href="#sec-1_5">1.5 Compression &ndash; how good is it? </a></li>
99
+ <li><a href="#sec-1_6">1.6 Bugs? </a></li>
100
+ <li><a href="#sec-1_7">1.7 Links </a></li>
101
+ <li><a href="#sec-1_8">1.8 License </a></li>
102
+ </ul>
103
+ </li>
104
+ </ul>
105
+ </div>
106
+ </div>
107
+
108
+ <div id="outline-container-1" class="outline-2">
109
+ <h2 id="sec-1"><span class="section-number-2">1</span> UglifyJS &mdash; a JavaScript parser/compressor/beautifier </h2>
110
+ <div class="outline-text-2" id="text-1">
111
+
112
+
113
+ <p>
114
+ This package implements a general-purpose JavaScript
115
+ parser/compressor/beautifier toolkit. It is developed on <a href="http://nodejs.org/">NodeJS</a>, but it
116
+ should work on any JavaScript platform supporting the CommonJS module system
117
+ (and if your platform of choice doesn't support CommonJS, you can easily
118
+ implement it, or discard the <code>exports.*</code> lines from UglifyJS sources).
119
+ </p>
120
+ <p>
121
+ The tokenizer/parser generates an abstract syntax tree from JS code. You
122
+ can then traverse the AST to learn more about the code, or do various
123
+ manipulations on it. This part is implemented in <a href="../lib/parse-js.js">parse-js.js</a> and it's a
124
+ port to JavaScript of the excellent <a href="http://marijn.haverbeke.nl/parse-js/">parse-js</a> Common Lisp library from <a href="http://marijn.haverbeke.nl/">Marijn Haverbeke</a>.
125
+ </p>
126
+ <p>
127
+ ( See <a href="http://github.com/mishoo/cl-uglify-js">cl-uglify-js</a> if you're looking for the Common Lisp version of
128
+ UglifyJS. )
129
+ </p>
130
+ <p>
131
+ The second part of this package, implemented in <a href="../lib/process.js">process.js</a>, inspects and
132
+ manipulates the AST generated by the parser to provide the following:
133
+ </p>
134
+ <ul>
135
+ <li>
136
+ ability to re-generate JavaScript code from the AST. Optionally
137
+ indented&mdash;you can use this if you want to “beautify” a program that has
138
+ been compressed, so that you can inspect the source. But you can also run
139
+ our code generator to print out an AST without any whitespace, so you
140
+ achieve compression as well.
141
+
142
+ </li>
143
+ <li>
144
+ shorten variable names (usually to single characters). Our mangler will
145
+ analyze the code and generate proper variable names, depending on scope
146
+ and usage, and is smart enough to deal with globals defined elsewhere, or
147
+ with <code>eval()</code> calls or <code>with{}</code> statements. In short, if <code>eval()</code> or
148
+ <code>with{}</code> are used in some scope, then all variables in that scope and any
149
+ variables in the parent scopes will remain unmangled, and any references
150
+ to such variables remain unmangled as well.
151
+
152
+ </li>
153
+ <li>
154
+ various small optimizations that may lead to faster code but certainly
155
+ lead to smaller code. Where possible, we do the following:
156
+
157
+ <ul>
158
+ <li>
159
+ foo["bar"] ==&gt; foo.bar
160
+
161
+ </li>
162
+ <li>
163
+ remove block brackets <code>{}</code>
164
+
165
+ </li>
166
+ <li>
167
+ join consecutive var declarations:
168
+ var a = 10; var b = 20; ==&gt; var a=10,b=20;
169
+
170
+ </li>
171
+ <li>
172
+ resolve simple constant expressions: 1 +2 * 3 ==&gt; 7. We only do the
173
+ replacement if the result occupies less bytes; for example 1/3 would
174
+ translate to 0.333333333333, so in this case we don't replace it.
175
+
176
+ </li>
177
+ <li>
178
+ consecutive statements in blocks are merged into a sequence; in many
179
+ cases, this leaves blocks with a single statement, so then we can remove
180
+ the block brackets.
181
+
182
+ </li>
183
+ <li>
184
+ various optimizations for IF statements:
185
+
186
+ <ul>
187
+ <li>
188
+ if (foo) bar(); else baz(); ==&gt; foo?bar():baz();
189
+ </li>
190
+ <li>
191
+ if (!foo) bar(); else baz(); ==&gt; foo?baz():bar();
192
+ </li>
193
+ <li>
194
+ if (foo) bar(); ==&gt; foo&amp;&amp;bar();
195
+ </li>
196
+ <li>
197
+ if (!foo) bar(); ==&gt; foo||bar();
198
+ </li>
199
+ <li>
200
+ if (foo) return bar(); else return baz(); ==&gt; return foo?bar():baz();
201
+ </li>
202
+ <li>
203
+ if (foo) return bar(); else something(); ==&gt; {if(foo)return bar();something()}
204
+
205
+ </li>
206
+ </ul>
207
+ </li>
208
+ <li>
209
+ remove some unreachable code and warn about it (code that follows a
210
+ <code>return</code>, <code>throw</code>, <code>break</code> or <code>continue</code> statement, except
211
+ function/variable declarations).
212
+ </li>
213
+ </ul>
214
+ </li>
215
+ </ul>
216
+
217
+
218
+
219
+ </div>
220
+
221
+ <div id="outline-container-1_1" class="outline-3">
222
+ <h3 id="sec-1_1"><span class="section-number-3">1.1</span> <span class="target">Unsafe transformations</span> </h3>
223
+ <div class="outline-text-3" id="text-1_1">
224
+
225
+
226
+ <p>
227
+ UglifyJS tries its best to achieve great compression while leaving the
228
+ semantics of the code intact. In general, if your code logic is broken by
229
+ UglifyJS then it's a bug in UglifyJS and you should report it and I should
230
+ fix it. :-)
231
+ </p>
232
+ <p>
233
+ However, I opted to include the following potentially unsafe transformations
234
+ as default behavior. Discussion is welcome, if you have ideas of how to
235
+ handle this better, or any objections to these optimizations, please let me
236
+ know.
237
+ </p>
238
+
239
+ </div>
240
+
241
+ <div id="outline-container-1_1_1" class="outline-4">
242
+ <h4 id="sec-1_1_1"><span class="section-number-4">1.1.1</span> Calls involving the global Array constructor </h4>
243
+ <div class="outline-text-4" id="text-1_1_1">
244
+
245
+
246
+ <p>
247
+ The following transformations occur:
248
+ </p>
249
+
250
+
251
+
252
+ <pre class="src src-js"><span style="color: #a020f0;">new</span> <span style="color: #228b22;">Array</span>(1, 2, 3, 4) =&gt; [1,2,3,4]
253
+ Array(a, b, c) =&gt; [a,b,c]
254
+ <span style="color: #a020f0;">new</span> <span style="color: #228b22;">Array</span>(5) =&gt; Array(5)
255
+ <span style="color: #a020f0;">new</span> <span style="color: #228b22;">Array</span>(a) =&gt; Array(a)
256
+ </pre>
257
+
258
+
259
+
260
+ <p>
261
+ These are all safe if the Array name isn't redefined. JavaScript does allow
262
+ one to globally redefine Array (and pretty much everything, in fact) but I
263
+ personally don't see why would anyone do that.
264
+ </p>
265
+ <p>
266
+ UglifyJS does handle the case where Array is redefined locally, or even
267
+ globally but with a <code>function</code> or <code>var</code> declaration. Therefore, in the
268
+ following cases UglifyJS <b>doesn't touch</b> calls or instantiations of Array:
269
+ </p>
270
+
271
+
272
+
273
+ <pre class="src src-js"><span style="color: #b22222;">// </span><span style="color: #b22222;">case 1. globally declared variable
274
+ </span> <span style="color: #a020f0;">var</span> <span style="color: #b8860b;">Array</span>;
275
+ <span style="color: #a020f0;">new</span> <span style="color: #228b22;">Array</span>(1, 2, 3);
276
+ Array(a, b);
277
+
278
+ <span style="color: #b22222;">// </span><span style="color: #b22222;">or (can be declared later)
279
+ </span> <span style="color: #a020f0;">new</span> <span style="color: #228b22;">Array</span>(1, 2, 3);
280
+ <span style="color: #a020f0;">var</span> <span style="color: #b8860b;">Array</span>;
281
+
282
+ <span style="color: #b22222;">// </span><span style="color: #b22222;">or (can be a function)
283
+ </span> <span style="color: #a020f0;">new</span> <span style="color: #228b22;">Array</span>(1, 2, 3);
284
+ <span style="color: #a020f0;">function</span> <span style="color: #0000ff;">Array</span>() { ... }
285
+
286
+ <span style="color: #b22222;">// </span><span style="color: #b22222;">case 2. declared in a function
287
+ </span> (<span style="color: #a020f0;">function</span>(){
288
+ a = <span style="color: #a020f0;">new</span> <span style="color: #228b22;">Array</span>(1, 2, 3);
289
+ b = Array(5, 6);
290
+ <span style="color: #a020f0;">var</span> <span style="color: #b8860b;">Array</span>;
291
+ })();
292
+
293
+ <span style="color: #b22222;">// </span><span style="color: #b22222;">or
294
+ </span> (<span style="color: #a020f0;">function</span>(<span style="color: #b8860b;">Array</span>){
295
+ <span style="color: #a020f0;">return</span> Array(5, 6, 7);
296
+ })();
297
+
298
+ <span style="color: #b22222;">// </span><span style="color: #b22222;">or
299
+ </span> (<span style="color: #a020f0;">function</span>(){
300
+ <span style="color: #a020f0;">return</span> <span style="color: #a020f0;">new</span> <span style="color: #228b22;">Array</span>(1, 2, 3, 4);
301
+ <span style="color: #a020f0;">function</span> <span style="color: #0000ff;">Array</span>() { ... }
302
+ })();
303
+
304
+ <span style="color: #b22222;">// </span><span style="color: #b22222;">etc.
305
+ </span></pre>
306
+
307
+
308
+
309
+ </div>
310
+ </div>
311
+
312
+ </div>
313
+
314
+ <div id="outline-container-1_2" class="outline-3">
315
+ <h3 id="sec-1_2"><span class="section-number-3">1.2</span> Install (NPM) </h3>
316
+ <div class="outline-text-3" id="text-1_2">
317
+
318
+
319
+ <p>
320
+ UglifyJS is now available through NPM &mdash; <code>npm install uglify-js</code> should do
321
+ the job.
322
+ </p>
323
+ </div>
324
+
325
+ </div>
326
+
327
+ <div id="outline-container-1_3" class="outline-3">
328
+ <h3 id="sec-1_3"><span class="section-number-3">1.3</span> Install latest code from GitHub </h3>
329
+ <div class="outline-text-3" id="text-1_3">
330
+
331
+
332
+
333
+
334
+
335
+ <pre class="src src-sh"><span style="color: #b22222;">## </span><span style="color: #b22222;">clone the repository
336
+ </span>mkdir -p /where/you/wanna/put/it
337
+ <span style="color: #da70d6;">cd</span> /where/you/wanna/put/it
338
+ git clone git://github.com/mishoo/UglifyJS.git
339
+
340
+ <span style="color: #b22222;">## </span><span style="color: #b22222;">make the module available to Node
341
+ </span>mkdir -p ~/.node_libraries/
342
+ <span style="color: #da70d6;">cd</span> ~/.node_libraries/
343
+ ln -s /where/you/wanna/put/it/UglifyJS/uglify-js.js
344
+
345
+ <span style="color: #b22222;">## </span><span style="color: #b22222;">and if you want the CLI script too:
346
+ </span>mkdir -p ~/bin
347
+ <span style="color: #da70d6;">cd</span> ~/bin
348
+ ln -s /where/you/wanna/put/it/UglifyJS/bin/uglifyjs
349
+ <span style="color: #b22222;"># </span><span style="color: #b22222;">(then add ~/bin to your $PATH if it's not there already)
350
+ </span></pre>
351
+
352
+
353
+
354
+ </div>
355
+
356
+ </div>
357
+
358
+ <div id="outline-container-1_4" class="outline-3">
359
+ <h3 id="sec-1_4"><span class="section-number-3">1.4</span> Usage </h3>
360
+ <div class="outline-text-3" id="text-1_4">
361
+
362
+
363
+ <p>
364
+ There is a command-line tool that exposes the functionality of this library
365
+ for your shell-scripting needs:
366
+ </p>
367
+
368
+
369
+
370
+ <pre class="src src-sh">uglifyjs [ options... ] [ filename ]
371
+ </pre>
372
+
373
+
374
+
375
+ <p>
376
+ <code>filename</code> should be the last argument and should name the file from which
377
+ to read the JavaScript code. If you don't specify it, it will read code
378
+ from STDIN.
379
+ </p>
380
+ <p>
381
+ Supported options:
382
+ </p>
383
+ <ul>
384
+ <li>
385
+ <code>-b</code> or <code>--beautify</code> &mdash; output indented code; when passed, additional
386
+ options control the beautifier:
387
+
388
+ <ul>
389
+ <li>
390
+ <code>-i N</code> or <code>--indent N</code> &mdash; indentation level (number of spaces)
391
+
392
+ </li>
393
+ <li>
394
+ <code>-q</code> or <code>--quote-keys</code> &mdash; quote keys in literal objects (by default,
395
+ only keys that cannot be identifier names will be quotes).
396
+
397
+ </li>
398
+ </ul>
399
+ </li>
400
+ <li>
401
+ <code>--ascii</code> &mdash; pass this argument to encode non-ASCII characters as
402
+ <code>\uXXXX</code> sequences. By default UglifyJS won't bother to do it and will
403
+ output Unicode characters instead. (the output is always encoded in UTF8,
404
+ but if you pass this option you'll only get ASCII).
405
+
406
+ </li>
407
+ <li>
408
+ <code>-nm</code> or <code>--no-mangle</code> &mdash; don't mangle variable names
409
+
410
+ </li>
411
+ <li>
412
+ <code>-ns</code> or <code>--no-squeeze</code> &mdash; don't call <code>ast_squeeze()</code> (which does various
413
+ optimizations that result in smaller, less readable code).
414
+
415
+ </li>
416
+ <li>
417
+ <code>-mt</code> or <code>--mangle-toplevel</code> &mdash; mangle names in the toplevel scope too
418
+ (by default we don't do this).
419
+
420
+ </li>
421
+ <li>
422
+ <code>--no-seqs</code> &mdash; when <code>ast_squeeze()</code> is called (thus, unless you pass
423
+ <code>--no-squeeze</code>) it will reduce consecutive statements in blocks into a
424
+ sequence. For example, "a = 10; b = 20; foo();" will be written as
425
+ "a=10,b=20,foo();". In various occasions, this allows us to discard the
426
+ block brackets (since the block becomes a single statement). This is ON
427
+ by default because it seems safe and saves a few hundred bytes on some
428
+ libs that I tested it on, but pass <code>--no-seqs</code> to disable it.
429
+
430
+ </li>
431
+ <li>
432
+ <code>--no-dead-code</code> &mdash; by default, UglifyJS will remove code that is
433
+ obviously unreachable (code that follows a <code>return</code>, <code>throw</code>, <code>break</code> or
434
+ <code>continue</code> statement and is not a function/variable declaration). Pass
435
+ this option to disable this optimization.
436
+
437
+ </li>
438
+ <li>
439
+ <code>-nc</code> or <code>--no-copyright</code> &mdash; by default, <code>uglifyjs</code> will keep the initial
440
+ comment tokens in the generated code (assumed to be copyright information
441
+ etc.). If you pass this it will discard it.
442
+
443
+ </li>
444
+ <li>
445
+ <code>-o filename</code> or <code>--output filename</code> &mdash; put the result in <code>filename</code>. If
446
+ this isn't given, the result goes to standard output (or see next one).
447
+
448
+ </li>
449
+ <li>
450
+ <code>--overwrite</code> &mdash; if the code is read from a file (not from STDIN) and you
451
+ pass <code>--overwrite</code> then the output will be written in the same file.
452
+
453
+ </li>
454
+ <li>
455
+ <code>--ast</code> &mdash; pass this if you want to get the Abstract Syntax Tree instead
456
+ of JavaScript as output. Useful for debugging or learning more about the
457
+ internals.
458
+
459
+ </li>
460
+ <li>
461
+ <code>-v</code> or <code>--verbose</code> &mdash; output some notes on STDERR (for now just how long
462
+ each operation takes).
463
+
464
+ </li>
465
+ <li>
466
+ <code>--extra</code> &mdash; enable additional optimizations that have not yet been
467
+ extensively tested. These might, or might not, break your code. If you
468
+ find a bug using this option, please report a test case.
469
+
470
+ </li>
471
+ <li>
472
+ <code>--unsafe</code> &mdash; enable other additional optimizations that are known to be
473
+ unsafe in some contrived situations, but could still be generally useful.
474
+ For now only this:
475
+
476
+ <ul>
477
+ <li>
478
+ foo.toString() ==&gt; foo+""
479
+
480
+ </li>
481
+ </ul>
482
+ </li>
483
+ <li>
484
+ <code>--max-line-len</code> (default 32K characters) &mdash; add a newline after around
485
+ 32K characters. I've seen both FF and Chrome croak when all the code was
486
+ on a single line of around 670K. Pass &ndash;max-line-len 0 to disable this
487
+ safety feature.
488
+
489
+ </li>
490
+ <li>
491
+ <code>--reserved-names</code> &mdash; some libraries rely on certain names to be used, as
492
+ pointed out in issue #92 and #81, so this option allow you to exclude such
493
+ names from the mangler. For example, to keep names <code>require</code> and <code>$super</code>
494
+ intact you'd specify &ndash;reserved-names "require,$super".
495
+ </li>
496
+ </ul>
497
+
498
+
499
+
500
+ </div>
501
+
502
+ <div id="outline-container-1_4_1" class="outline-4">
503
+ <h4 id="sec-1_4_1"><span class="section-number-4">1.4.1</span> API </h4>
504
+ <div class="outline-text-4" id="text-1_4_1">
505
+
506
+
507
+ <p>
508
+ To use the library from JavaScript, you'd do the following (example for
509
+ NodeJS):
510
+ </p>
511
+
512
+
513
+
514
+ <pre class="src src-js"><span style="color: #a020f0;">var</span> <span style="color: #b8860b;">jsp</span> = require(<span style="color: #bc8f8f;">"uglify-js"</span>).parser;
515
+ <span style="color: #a020f0;">var</span> <span style="color: #b8860b;">pro</span> = require(<span style="color: #bc8f8f;">"uglify-js"</span>).uglify;
516
+
517
+ <span style="color: #a020f0;">var</span> <span style="color: #b8860b;">orig_code</span> = <span style="color: #bc8f8f;">"... JS code here"</span>;
518
+ <span style="color: #a020f0;">var</span> <span style="color: #b8860b;">ast</span> = jsp.parse(orig_code); <span style="color: #b22222;">// </span><span style="color: #b22222;">parse code and get the initial AST
519
+ </span>ast = pro.ast_mangle(ast); <span style="color: #b22222;">// </span><span style="color: #b22222;">get a new AST with mangled names
520
+ </span>ast = pro.ast_squeeze(ast); <span style="color: #b22222;">// </span><span style="color: #b22222;">get an AST with compression optimizations
521
+ </span><span style="color: #a020f0;">var</span> <span style="color: #b8860b;">final_code</span> = pro.gen_code(ast); <span style="color: #b22222;">// </span><span style="color: #b22222;">compressed code here
522
+ </span></pre>
523
+
524
+
525
+
526
+ <p>
527
+ The above performs the full compression that is possible right now. As you
528
+ can see, there are a sequence of steps which you can apply. For example if
529
+ you want compressed output but for some reason you don't want to mangle
530
+ variable names, you would simply skip the line that calls
531
+ <code>pro.ast_mangle(ast)</code>.
532
+ </p>
533
+ <p>
534
+ Some of these functions take optional arguments. Here's a description:
535
+ </p>
536
+ <ul>
537
+ <li>
538
+ <code>jsp.parse(code, strict_semicolons)</code> &ndash; parses JS code and returns an AST.
539
+ <code>strict_semicolons</code> is optional and defaults to <code>false</code>. If you pass
540
+ <code>true</code> then the parser will throw an error when it expects a semicolon and
541
+ it doesn't find it. For most JS code you don't want that, but it's useful
542
+ if you want to strictly sanitize your code.
543
+
544
+ </li>
545
+ <li>
546
+ <code>pro.ast_mangle(ast, options)</code> &ndash; generates a new AST containing mangled
547
+ (compressed) variable and function names. It supports the following
548
+ options:
549
+
550
+ <ul>
551
+ <li>
552
+ <code>toplevel</code> &ndash; mangle toplevel names (by default we don't touch them).
553
+ </li>
554
+ <li>
555
+ <code>except</code> &ndash; an array of names to exclude from compression.
556
+
557
+ </li>
558
+ </ul>
559
+ </li>
560
+ <li>
561
+ <code>pro.ast_squeeze(ast, options)</code> &ndash; employs further optimizations designed
562
+ to reduce the size of the code that <code>gen_code</code> would generate from the
563
+ AST. Returns a new AST. <code>options</code> can be a hash; the supported options
564
+ are:
565
+
566
+ <ul>
567
+ <li>
568
+ <code>make_seqs</code> (default true) which will cause consecutive statements in a
569
+ block to be merged using the "sequence" (comma) operator
570
+
571
+ </li>
572
+ <li>
573
+ <code>dead_code</code> (default true) which will remove unreachable code.
574
+
575
+ </li>
576
+ </ul>
577
+ </li>
578
+ <li>
579
+ <code>pro.gen_code(ast, options)</code> &ndash; generates JS code from the AST. By
580
+ default it's minified, but using the <code>options</code> argument you can get nicely
581
+ formatted output. <code>options</code> is, well, optional :-) and if you pass it it
582
+ must be an object and supports the following properties (below you can see
583
+ the default values):
584
+
585
+ <ul>
586
+ <li>
587
+ <code>beautify: false</code> &ndash; pass <code>true</code> if you want indented output
588
+ </li>
589
+ <li>
590
+ <code>indent_start: 0</code> (only applies when <code>beautify</code> is <code>true</code>) &ndash; initial
591
+ indentation in spaces
592
+ </li>
593
+ <li>
594
+ <code>indent_level: 4</code> (only applies when <code>beautify</code> is <code>true</code>) --
595
+ indentation level, in spaces (pass an even number)
596
+ </li>
597
+ <li>
598
+ <code>quote_keys: false</code> &ndash; if you pass <code>true</code> it will quote all keys in
599
+ literal objects
600
+ </li>
601
+ <li>
602
+ <code>space_colon: false</code> (only applies when <code>beautify</code> is <code>true</code>) &ndash; wether
603
+ to put a space before the colon in object literals
604
+ </li>
605
+ <li>
606
+ <code>ascii_only: false</code> &ndash; pass <code>true</code> if you want to encode non-ASCII
607
+ characters as <code>\uXXXX</code>.
608
+ </li>
609
+ </ul>
610
+ </li>
611
+ </ul>
612
+
613
+
614
+ </div>
615
+
616
+ </div>
617
+
618
+ <div id="outline-container-1_4_2" class="outline-4">
619
+ <h4 id="sec-1_4_2"><span class="section-number-4">1.4.2</span> Beautifier shortcoming &ndash; no more comments </h4>
620
+ <div class="outline-text-4" id="text-1_4_2">
621
+
622
+
623
+ <p>
624
+ The beautifier can be used as a general purpose indentation tool. It's
625
+ useful when you want to make a minified file readable. One limitation,
626
+ though, is that it discards all comments, so you don't really want to use it
627
+ to reformat your code, unless you don't have, or don't care about, comments.
628
+ </p>
629
+ <p>
630
+ In fact it's not the beautifier who discards comments &mdash; they are dumped at
631
+ the parsing stage, when we build the initial AST. Comments don't really
632
+ make sense in the AST, and while we could add nodes for them, it would be
633
+ inconvenient because we'd have to add special rules to ignore them at all
634
+ the processing stages.
635
+ </p>
636
+ </div>
637
+ </div>
638
+
639
+ </div>
640
+
641
+ <div id="outline-container-1_5" class="outline-3">
642
+ <h3 id="sec-1_5"><span class="section-number-3">1.5</span> Compression &ndash; how good is it? </h3>
643
+ <div class="outline-text-3" id="text-1_5">
644
+
645
+
646
+ <p>
647
+ (XXX: this is somewhat outdated. On the jQuery source code we beat Closure
648
+ by 168 bytes (560 after gzip) and by many seconds.)
649
+ </p>
650
+ <p>
651
+ There are a few popular JS minifiers nowadays &ndash; the two most well known
652
+ being the GoogleClosure (GCL) compiler and the YUI compressor. For some
653
+ reason they are both written in Java. I didn't really hope to beat any of
654
+ them, but finally I did &ndash; UglifyJS compresses better than the YUI
655
+ compressor, and safer than GoogleClosure.
656
+ </p>
657
+ <p>
658
+ I tested it on two big libraries. <a href="http://www.dynarchlib.com/">DynarchLIB</a> is my own, and it's big enough
659
+ to contain probably all the JavaScript tricks known to mankind. <a href="http://jquery.com/">jQuery</a> is
660
+ definitely the most popular JavaScript library (to some people, it's a
661
+ synonym to JavaScript itself).
662
+ </p>
663
+ <p>
664
+ I cannot swear that there are no bugs in the generated codes, but they
665
+ appear to work fine.
666
+ </p>
667
+ <p>
668
+ Compression results:
669
+ </p>
670
+ <table border="2" cellspacing="0" cellpadding="6" rules="groups" frame="hsides">
671
+ <caption></caption>
672
+ <colgroup><col align="left" /><col align="right" /><col align="right" /><col align="left" /><col align="left" />
673
+ </colgroup>
674
+ <thead>
675
+ <tr><th scope="col">Library</th><th scope="col">Orig. size</th><th scope="col">UglifyJS</th><th scope="col">YUI</th><th scope="col">GCL</th></tr>
676
+ </thead>
677
+ <tbody>
678
+ <tr><td>DynarchLIB</td><td>636896</td><td>241441</td><td>246452 (+5011)</td><td>240439 (-1002) (buggy)</td></tr>
679
+ <tr><td>jQuery</td><td>163855</td><td>72006</td><td>79702 (+7696)</td><td>71858 (-148)</td></tr>
680
+ </tbody>
681
+ </table>
682
+
683
+
684
+ <p>
685
+ UglifyJS is the fastest to run. On my laptop UglifyJS takes 1.35s for
686
+ DynarchLIB, while YUI takes 2.7s and GCL takes 6.5s.
687
+ </p>
688
+ <p>
689
+ GoogleClosure does a lot of smart ass optimizations. I had to strive really
690
+ hard to get close to it. It should be possible to even beat it, but then
691
+ again, GCL has a gazillion lines of code and runs terribly slow, so I'm not
692
+ sure it worths spending the effort to save a few bytes. Also, GCL doesn't
693
+ cope with <code>eval()</code> or <code>with{}</code> &ndash; it just dumps a warning and proceeds to
694
+ mangle names anyway; my DynarchLIB compiled with it is buggy because of
695
+ this.
696
+ </p>
697
+ <p>
698
+ UglifyJS consists of ~1100 lines of code for the tokenizer/parser, and ~1100
699
+ lines for the compressor and code generator. That should make it very
700
+ maintainable and easily extensible, so I would say it has a good place in
701
+ this field and it's bound to become the de-facto standard JS minifier. And
702
+ I shall rule the world. :-) Use it, and <b>spread the word</b>!
703
+ </p>
704
+ </div>
705
+
706
+ </div>
707
+
708
+ <div id="outline-container-1_6" class="outline-3">
709
+ <h3 id="sec-1_6"><span class="section-number-3">1.6</span> Bugs? </h3>
710
+ <div class="outline-text-3" id="text-1_6">
711
+
712
+
713
+ <p>
714
+ Unfortunately, for the time being there is no automated test suite. But I
715
+ ran the compressor manually on non-trivial code, and then I tested that the
716
+ generated code works as expected. A few hundred times.
717
+ </p>
718
+ <p>
719
+ DynarchLIB was started in times when there was no good JS minifier.
720
+ Therefore I was quite religious about trying to write short code manually,
721
+ and as such DL contains a lot of syntactic hacks<sup><a class="footref" name="fnr.1" href="#fn.1">1</a></sup> such as “foo == bar ? a
722
+ = 10 : b = 20”, though the more readable version would clearly be to use
723
+ “if/else”.
724
+ </p>
725
+ <p>
726
+ Since the parser/compressor runs fine on DL and jQuery, I'm quite confident
727
+ that it's solid enough for production use. If you can identify any bugs,
728
+ I'd love to hear about them (<a href="http://groups.google.com/group/uglifyjs">use the Google Group</a> or email me directly).
729
+ </p>
730
+ </div>
731
+
732
+ </div>
733
+
734
+ <div id="outline-container-1_7" class="outline-3">
735
+ <h3 id="sec-1_7"><span class="section-number-3">1.7</span> Links </h3>
736
+ <div class="outline-text-3" id="text-1_7">
737
+
738
+
739
+ <ul>
740
+ <li>
741
+ Project at GitHub: <a href="http://github.com/mishoo/UglifyJS">http://github.com/mishoo/UglifyJS</a>
742
+ </li>
743
+ <li>
744
+ Google Group: <a href="http://groups.google.com/group/uglifyjs">http://groups.google.com/group/uglifyjs</a>
745
+ </li>
746
+ <li>
747
+ Common Lisp JS parser: <a href="http://marijn.haverbeke.nl/parse-js/">http://marijn.haverbeke.nl/parse-js/</a>
748
+ </li>
749
+ <li>
750
+ JS-to-Lisp compiler: <a href="http://github.com/marijnh/js">http://github.com/marijnh/js</a>
751
+ </li>
752
+ <li>
753
+ Common Lisp JS uglifier: <a href="http://github.com/mishoo/cl-uglify-js">http://github.com/mishoo/cl-uglify-js</a>
754
+ </li>
755
+ </ul>
756
+
757
+
758
+ </div>
759
+
760
+ </div>
761
+
762
+ <div id="outline-container-1_8" class="outline-3">
763
+ <h3 id="sec-1_8"><span class="section-number-3">1.8</span> License </h3>
764
+ <div class="outline-text-3" id="text-1_8">
765
+
766
+
767
+ <p>
768
+ UglifyJS is released under the BSD license:
769
+ </p>
770
+
771
+
772
+
773
+ <pre class="example">Copyright 2010 (c) Mihai Bazon &lt;mihai.bazon@gmail.com&gt;
774
+ Based on parse-js (http://marijn.haverbeke.nl/parse-js/).
775
+
776
+ Redistribution and use in source and binary forms, with or without
777
+ modification, are permitted provided that the following conditions
778
+ are met:
779
+
780
+ * Redistributions of source code must retain the above
781
+ copyright notice, this list of conditions and the following
782
+ disclaimer.
783
+
784
+ * Redistributions in binary form must reproduce the above
785
+ copyright notice, this list of conditions and the following
786
+ disclaimer in the documentation and/or other materials
787
+ provided with the distribution.
788
+
789
+ THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDER “AS IS” AND ANY
790
+ EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
791
+ IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
792
+ PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER BE
793
+ LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY,
794
+ OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
795
+ PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
796
+ PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
797
+ THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR
798
+ TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF
799
+ THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
800
+ SUCH DAMAGE.
801
+ </pre>
802
+
803
+
804
+
805
+
806
+ </div>
807
+ </div>
808
+ </div>
809
+ <div id="footnotes">
810
+ <h2 class="footnotes">Footnotes: </h2>
811
+ <div id="text-footnotes">
812
+ <p class="footnote"><sup><a class="footnum" name="fn.1" href="#fnr.1">1</a></sup> I even reported a few bugs and suggested some fixes in the original
813
+ <a href="http://marijn.haverbeke.nl/parse-js/">parse-js</a> library, and Marijn pushed fixes literally in minutes.
814
+ </p>
815
+ </div>
816
+ </div>
817
+ <div id="postamble">
818
+ <p class="author"> Author: Mihai Bazon
819
+ </p>
820
+ <p class="date"> Date: 2011-04-04 00:07:13 EEST</p>
821
+ <p class="creator">HTML generated by org-mode 7.01trans in emacs 23</p>
822
+ </div>
823
+ </div>
824
+ </body>
825
+ </html>