Skip to content

Commit 852122c

Browse files
committed
NPM changes
1 parent 175b4cb commit 852122c

File tree

6 files changed

+166
-84
lines changed

6 files changed

+166
-84
lines changed

README.html

+109-66
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
<title>UglifyJS -- a JavaScript parser/compressor/beautifier</title>
88
<meta http-equiv="Content-Type" content="text/html;charset=utf-8"/>
99
<meta name="generator" content="Org-mode"/>
10-
<meta name="generated" content="2011-02-28 22:35:00 EET"/>
10+
<meta name="generated" content="2011-04-04 00:07:13 EEST"/>
1111
<meta name="author" content="Mihai Bazon"/>
1212
<meta name="description" content="a JavaScript parser/compressor/beautifier in JavaScript"/>
1313
<meta name="keywords" content="javascript, js, parser, compiler, compressor, mangle, minify, minifier"/>
@@ -87,16 +87,18 @@ <h2>Table of Contents</h2>
8787
<li><a href="#sec-1_1_1">1.1.1 Calls involving the global Array constructor </a></li>
8888
</ul>
8989
</li>
90-
<li><a href="#sec-1_2">1.2 Usage </a>
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>
9193
<ul>
92-
<li><a href="#sec-1_2_1">1.2.1 API </a></li>
93-
<li><a href="#sec-1_2_2">1.2.2 Beautifier shortcoming &ndash; no more comments </a></li>
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>
9496
</ul>
9597
</li>
96-
<li><a href="#sec-1_3">1.3 Compression &ndash; how good is it? </a></li>
97-
<li><a href="#sec-1_4">1.4 Bugs? </a></li>
98-
<li><a href="#sec-1_5">1.5 Links </a></li>
99-
<li><a href="#sec-1_6">1.6 License </a></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>
100102
</ul>
101103
</li>
102104
</ul>
@@ -108,9 +110,6 @@ <h2 id="sec-1"><span class="section-number-2">1</span> UglifyJS &mdash; a JavaSc
108110
<div class="outline-text-2" id="text-1">
109111

110112

111-
<p>
112-
<b>Update</b>: please read the section on <a href="#sec-1_1">unsafe transformations</a>.
113-
</p>
114113
<p>
115114
This package implements a general-purpose JavaScript
116115
parser/compressor/beautifier toolkit. It is developed on <a href="http://nodejs.org/">NodeJS</a>, but it
@@ -250,10 +249,10 @@ <h4 id="sec-1_1_1"><span class="section-number-4">1.1.1</span> Calls involving t
250249

251250

252251

253-
<pre class="src src-espresso"><span style="color: #afeeee; font-weight: bold;">new</span> <span style="color: #87ceeb; font-weight: bold;">Array</span>(1, 2, 3, 4) =&gt; [1,2,3,4]
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]
254253
Array(a, b, c) =&gt; [a,b,c]
255-
<span style="color: #afeeee; font-weight: bold;">new</span> <span style="color: #87ceeb; font-weight: bold;">Array</span>(5) =&gt; Array(5)
256-
<span style="color: #afeeee; font-weight: bold;">new</span> <span style="color: #87ceeb; font-weight: bold;">Array</span>(a) =&gt; Array(a)
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)
257256
</pre>
258257

259258

@@ -271,38 +270,38 @@ <h4 id="sec-1_1_1"><span class="section-number-4">1.1.1</span> Calls involving t
271270

272271

273272

274-
<pre class="src src-espresso"><span style="color: #add8e6;">// </span><span style="color: #add8e6;">case 1. globally declared variable
275-
</span> <span style="color: #afeeee; font-weight: bold;">var</span> <span style="color: #40e0d0; font-weight: bold;">Array</span>;
276-
<span style="color: #afeeee; font-weight: bold;">new</span> <span style="color: #87ceeb; font-weight: bold;">Array</span>(1, 2, 3);
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);
277276
Array(a, b);
278277

279-
<span style="color: #add8e6;">// </span><span style="color: #add8e6;">or (can be declared later)
280-
</span> <span style="color: #afeeee; font-weight: bold;">new</span> <span style="color: #87ceeb; font-weight: bold;">Array</span>(1, 2, 3);
281-
<span style="color: #afeeee; font-weight: bold;">var</span> <span style="color: #40e0d0; font-weight: bold;">Array</span>;
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>;
282281

283-
<span style="color: #add8e6;">// </span><span style="color: #add8e6;">or (can be a function)
284-
</span> <span style="color: #afeeee; font-weight: bold;">new</span> <span style="color: #87ceeb; font-weight: bold;">Array</span>(1, 2, 3);
285-
<span style="color: #afeeee; font-weight: bold;">function</span> <span style="color: #7fffd4; font-weight: bold;">Array</span>() { ... }
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>() { ... }
286285

287-
<span style="color: #add8e6;">// </span><span style="color: #add8e6;">case 2. declared in a function
288-
</span> (<span style="color: #afeeee; font-weight: bold;">function</span>(){
289-
a = <span style="color: #afeeee; font-weight: bold;">new</span> <span style="color: #87ceeb; font-weight: bold;">Array</span>(1, 2, 3);
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);
290289
b = Array(5, 6);
291-
<span style="color: #afeeee; font-weight: bold;">var</span> <span style="color: #40e0d0; font-weight: bold;">Array</span>;
290+
<span style="color: #a020f0;">var</span> <span style="color: #b8860b;">Array</span>;
292291
})();
293292

294-
<span style="color: #add8e6;">// </span><span style="color: #add8e6;">or
295-
</span> (<span style="color: #afeeee; font-weight: bold;">function</span>(<span style="color: #40e0d0; font-weight: bold;">Array</span>){
296-
<span style="color: #afeeee; font-weight: bold;">return</span> Array(5, 6, 7);
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);
297296
})();
298297

299-
<span style="color: #add8e6;">// </span><span style="color: #add8e6;">or
300-
</span> (<span style="color: #afeeee; font-weight: bold;">function</span>(){
301-
<span style="color: #afeeee; font-weight: bold;">return</span> <span style="color: #afeeee; font-weight: bold;">new</span> <span style="color: #87ceeb; font-weight: bold;">Array</span>(1, 2, 3, 4);
302-
<span style="color: #afeeee; font-weight: bold;">function</span> <span style="color: #7fffd4; font-weight: bold;">Array</span>() { ... }
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>() { ... }
303302
})();
304303

305-
<span style="color: #add8e6;">// </span><span style="color: #add8e6;">etc.
304+
<span style="color: #b22222;">// </span><span style="color: #b22222;">etc.
306305
</span></pre>
307306

308307

@@ -313,13 +312,57 @@ <h4 id="sec-1_1_1"><span class="section-number-4">1.1.1</span> Calls involving t
313312
</div>
314313

315314
<div id="outline-container-1_2" class="outline-3">
316-
<h3 id="sec-1_2"><span class="section-number-3">1.2</span> Usage </h3>
315+
<h3 id="sec-1_2"><span class="section-number-3">1.2</span> Install (NPM) </h3>
317316
<div class="outline-text-3" id="text-1_2">
318317

319318

320319
<p>
321-
There is a helper script now &mdash; <code>bin/uglifyjs</code> &mdash; that uses the library to
322-
compress a script using the maximum compression settings. Synopsis:
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:
323366
</p>
324367

325368

@@ -456,26 +499,26 @@ <h3 id="sec-1_2"><span class="section-number-3">1.2</span> Usage </h3>
456499

457500
</div>
458501

459-
<div id="outline-container-1_2_1" class="outline-4">
460-
<h4 id="sec-1_2_1"><span class="section-number-4">1.2.1</span> API </h4>
461-
<div class="outline-text-4" id="text-1_2_1">
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">
462505

463506

464507
<p>
465-
Symlink the <b>lib</b> directory as <b>~/.node_libraries/uglifyjs</b>, so that the
466-
<b>require</b> calls in the following sample will work:
508+
To use the library from JavaScript, you'd do the following (example for
509+
NodeJS):
467510
</p>
468511

469512

470513

471-
<pre class="src src-espresso"><span style="color: #afeeee; font-weight: bold;">var</span> <span style="color: #40e0d0; font-weight: bold;">jsp</span> = require(<span style="color: #87cefa;">"uglifyjs/parse-js"</span>);
472-
<span style="color: #afeeee; font-weight: bold;">var</span> <span style="color: #40e0d0; font-weight: bold;">pro</span> = require(<span style="color: #87cefa;">"uglifyjs/process"</span>);
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;
473516

474-
<span style="color: #afeeee; font-weight: bold;">var</span> <span style="color: #40e0d0; font-weight: bold;">orig_code</span> = <span style="color: #87cefa;">"... JS code here"</span>;
475-
<span style="color: #afeeee; font-weight: bold;">var</span> <span style="color: #40e0d0; font-weight: bold;">ast</span> = jsp.parse(orig_code); <span style="color: #add8e6;">// </span><span style="color: #add8e6;">parse code and get the initial AST
476-
</span>ast = pro.ast_mangle(ast); <span style="color: #add8e6;">// </span><span style="color: #add8e6;">get a new AST with mangled names
477-
</span>ast = pro.ast_squeeze(ast); <span style="color: #add8e6;">// </span><span style="color: #add8e6;">get an AST with compression optimizations
478-
</span><span style="color: #afeeee; font-weight: bold;">var</span> <span style="color: #40e0d0; font-weight: bold;">final_code</span> = pro.gen_code(ast); <span style="color: #add8e6;">// </span><span style="color: #add8e6;">compressed code here
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
479522
</span></pre>
480523

481524

@@ -572,9 +615,9 @@ <h4 id="sec-1_2_1"><span class="section-number-4">1.2.1</span> API </h4>
572615

573616
</div>
574617

575-
<div id="outline-container-1_2_2" class="outline-4">
576-
<h4 id="sec-1_2_2"><span class="section-number-4">1.2.2</span> Beautifier shortcoming &ndash; no more comments </h4>
577-
<div class="outline-text-4" id="text-1_2_2">
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">
578621

579622

580623
<p>
@@ -595,9 +638,9 @@ <h4 id="sec-1_2_2"><span class="section-number-4">1.2.2</span> Beautifier shortc
595638

596639
</div>
597640

598-
<div id="outline-container-1_3" class="outline-3">
599-
<h3 id="sec-1_3"><span class="section-number-3">1.3</span> Compression &ndash; how good is it? </h3>
600-
<div class="outline-text-3" id="text-1_3">
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">
601644

602645

603646
<p>
@@ -662,9 +705,9 @@ <h3 id="sec-1_3"><span class="section-number-3">1.3</span> Compression &ndash; h
662705

663706
</div>
664707

665-
<div id="outline-container-1_4" class="outline-3">
666-
<h3 id="sec-1_4"><span class="section-number-3">1.4</span> Bugs? </h3>
667-
<div class="outline-text-3" id="text-1_4">
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">
668711

669712

670713
<p>
@@ -688,9 +731,9 @@ <h3 id="sec-1_4"><span class="section-number-3">1.4</span> Bugs? </h3>
688731

689732
</div>
690733

691-
<div id="outline-container-1_5" class="outline-3">
692-
<h3 id="sec-1_5"><span class="section-number-3">1.5</span> Links </h3>
693-
<div class="outline-text-3" id="text-1_5">
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">
694737

695738

696739
<ul>
@@ -716,9 +759,9 @@ <h3 id="sec-1_5"><span class="section-number-3">1.5</span> Links </h3>
716759

717760
</div>
718761

719-
<div id="outline-container-1_6" class="outline-3">
720-
<h3 id="sec-1_6"><span class="section-number-3">1.6</span> License </h3>
721-
<div class="outline-text-3" id="text-1_6">
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">
722765

723766

724767
<p>
@@ -774,7 +817,7 @@ <h2 class="footnotes">Footnotes: </h2>
774817
<div id="postamble">
775818
<p class="author"> Author: Mihai Bazon
776819
</p>
777-
<p class="date"> Date: 2011-02-28 22:35:00 EET</p>
820+
<p class="date"> Date: 2011-04-04 00:07:13 EEST</p>
778821
<p class="creator">HTML generated by org-mode 7.01trans in emacs 23</p>
779822
</div>
780823
</div>

README.org

+34-11
Original file line numberDiff line numberDiff line change
@@ -7,8 +7,6 @@
77

88
* UglifyJS --- a JavaScript parser/compressor/beautifier
99

10-
*Update*: please read the section on [[unsafe transformations]].
11-
1210
This package implements a general-purpose JavaScript
1311
parser/compressor/beautifier toolkit. It is developed on [[http://nodejs.org/][NodeJS]], but it
1412
should work on any JavaScript platform supporting the CommonJS module system
@@ -88,7 +86,7 @@ know.
8886

8987
The following transformations occur:
9088

91-
#+BEGIN_SRC espresso
89+
#+BEGIN_SRC js
9290
new Array(1, 2, 3, 4) => [1,2,3,4]
9391
Array(a, b, c) => [a,b,c]
9492
new Array(5) => Array(5)
@@ -103,7 +101,7 @@ UglifyJS does handle the case where Array is redefined locally, or even
103101
globally but with a =function= or =var= declaration. Therefore, in the
104102
following cases UglifyJS *doesn't touch* calls or instantiations of Array:
105103

106-
#+BEGIN_SRC espresso
104+
#+BEGIN_SRC js
107105
// case 1. globally declared variable
108106
var Array;
109107
new Array(1, 2, 3);
@@ -138,10 +136,35 @@ following cases UglifyJS *doesn't touch* calls or instantiations of Array:
138136
// etc.
139137
#+END_SRC
140138

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+
141164
** Usage
142165

143-
There is a helper script now --- =bin/uglifyjs= --- that uses the library to
144-
compress a script using the maximum compression settings. Synopsis:
166+
There is a command-line tool that exposes the functionality of this library
167+
for your shell-scripting needs:
145168

146169
#+BEGIN_SRC sh
147170
uglifyjs [ options... ] [ filename ]
@@ -226,12 +249,12 @@ Supported options:
226249

227250
*** API
228251

229-
Symlink the *lib* directory as *~/.node\_libraries/uglifyjs*, so that the
230-
*require* calls in the following sample will work:
252+
To use the library from JavaScript, you'd do the following (example for
253+
NodeJS):
231254

232-
#+BEGIN_SRC espresso
233-
var jsp = require("uglifyjs/parse-js");
234-
var pro = require("uglifyjs/process");
255+
#+BEGIN_SRC js
256+
var jsp = require("uglify-js").parser;
257+
var pro = require("uglify-js").uglify;
235258

236259
var orig_code = "... JS code here";
237260
var ast = jsp.parse(orig_code); // parse code and get the initial AST

bin/uglifyjs

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
#! /usr/bin/env node
2-
// -*- js2 -*-
2+
// -*- js -*-
33

44
global.sys = require(/^v0\.[012]/.test(process.version) ? "sys" : "util");
55
var fs = require("fs");

docstyle.css

+1-1
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ pre {
1717
overflow:auto;
1818
}
1919
pre.src {
20-
background-color: #333; color: #ffd; border: 1px solid #000;
20+
background-color: #eee; color: #112; border: 1px solid #000;
2121
}
2222
table { border-collapse: collapse; }
2323
td, th { vertical-align: top; }

0 commit comments

Comments
 (0)