Merge lp:~deryck/launchpad/minify-app-specific-js-592795 into lp:launchpad

Proposed by Deryck Hodge
Status: Merged
Approved by: Deryck Hodge
Approved revision: no longer in the source branch.
Merged at revision: 11009
Proposed branch: lp:~deryck/launchpad/minify-app-specific-js-592795
Merge into: lp:launchpad
Diff against target: 55 lines (+19/-4)
2 files modified
Makefile (+1/-1)
utilities/lp-deps.py (+18/-3)
To merge this branch: bzr merge lp:~deryck/launchpad/minify-app-specific-js-592795
Reviewer Review Type Date Requested Status
Māris Fogels (community) Approve
Review via email: mp+27395@code.launchpad.net

Commit message

Ensure JavaScript included from app-specific modules is minified.

Description of the change

This gets js files that live in app-specific javascript directories
minified. They are not currently minified, and while moving bugs js
code to lp.bugs.javascript, I got the build error about launchpad.js
being over 500k.

I've run the fix by rockstar who wrote the original lp-dep script,
and mars since he maintains the front-end build infrastructure. Both
seemed generally fine with the approach here, after some small
discussion on IRC.

= Launchpad lint =

Checking for conflicts. and issues in doctests and templates.
Running jslint, xmllint, pyflakes, and pylint.
Using normal rules.

Linting changed files:
  Makefile
  utilities/lp-deps.py

To post a comment you must log in.
Revision history for this message
Māris Fogels (mars) wrote :

Hi Deryck,

I assume the log_none() monkey patch is because this script's output to STDOUT is a programmatic input to another script? It would be nice to put a comment before if that is the case.

I assume you ran this through 'xvfb-run make jscheck'?

And thanks for the Makefile fix.

With the added comment, r=mars.

Maris

review: Approve
Revision history for this message
Deryck Hodge (deryck) wrote :

Hi, Maris.

I'm adding a comment for the monkey patch, and yes, I have run this through make jscheck. Passes fine.

Thanks for the review and comments!

Cheers,
deryck

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1=== modified file 'Makefile'
2--- Makefile 2010-06-09 14:49:31 +0000
3+++ Makefile 2010-06-14 13:36:38 +0000
4@@ -153,7 +153,7 @@
5 -s lib/canonical/launchpad/javascript \
6 -b $(LP_BUILT_JS_ROOT) \
7 $(shell $(HERE)/utilities/yui-deps.py) \
8- $(shell $(HERE)/utilities/lp-deps.py) \
9+ $(shell $(PY) $(HERE)/utilities/lp-deps.py) \
10 lib/canonical/launchpad/icing/lazr/build/lazr.js
11 ${SHHH} bin/jssize
12
13
14=== modified file 'utilities/lp-deps.py'
15--- utilities/lp-deps.py 2010-05-18 18:04:00 +0000
16+++ utilities/lp-deps.py 2010-06-14 13:36:38 +0000
17@@ -13,6 +13,7 @@
18
19 import os
20
21+from lazr.js.build import Builder
22
23 TOP = os.path.abspath(
24 os.path.join(os.path.dirname(__file__), '..'))
25@@ -26,13 +27,27 @@
26 ICING_ROOT = os.path.join(TOP, 'lib', 'canonical', 'launchpad', 'icing')
27 ICING_BUILD = os.path.join(ICING_ROOT, 'build')
28
29+# Builder has lots of logging, which might not
30+# play well with printing filenames. Monkey patch
31+# to disable it.
32+def log_none(msg):
33+ return
34+
35 for DIRSET in JS_DIRSET:
36 full_dir = os.path.join(TOP, DIRSET[0])
37+ module_name = DIRSET[1]
38+ BUILD_DIR = os.path.join(ICING_BUILD, module_name)
39+ if not os.path.exists(BUILD_DIR):
40+ os.mkdir(BUILD_DIR)
41+ builder = Builder(
42+ name=module_name, src_dir=full_dir, build_dir=ICING_BUILD)
43+ builder.log = log_none
44 # We don't want the tests to be included. If we want to nest the files in
45 # more folders though, this is where we change it.
46 for filename in os.listdir(full_dir):
47 if filename.endswith('.js'):
48+ basename, nothing = filename.split('.js')
49+ min_filename = basename + '-min.js'
50 absolute_filename = os.path.join(full_dir, filename)
51- print absolute_filename
52-
53- os.symlink(full_dir, os.path.join(ICING_BUILD, DIRSET[1]))
54+ builder.link_and_minify(builder.name, absolute_filename)
55+ print os.path.join(BUILD_DIR, min_filename)