Skip to content

Commit caea59b

Browse files
committed
Merge pull request #1588 from rtfd/vendor-bundle-fix
Repair vendor bundles and clean up js library usage
2 parents 3b770f5 + 26f27dd commit caea59b

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

39 files changed

+192
-282
lines changed

bower.json

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,8 @@
1818
"underscore": "~1.7.0",
1919
"readthedocs-client": "https://github.com/agjohnson/readthedocs-client-js.git",
2020
"knockout": "~3.3.0",
21-
"jquery.payment": "~1.2.3"
21+
"jquery.payment": "~1.2.3",
22+
"jquery-migrate": "~1.2.1",
23+
"jquery-ui": "1.8.23"
2224
}
2325
}

gulpfile.js

Lines changed: 107 additions & 50 deletions
Original file line numberDiff line numberDiff line change
@@ -17,74 +17,105 @@ var gulp = require('gulp'),
1717
// picking up dependencies of the primary entry points and putting any
1818
// limitations on directory structure for entry points.
1919
var sources = {
20-
builds: ['js/detail.js'],
21-
core: [
22-
'js/readthedocs-doc-embed.js',
23-
'js/autocomplete.js',
24-
'js/projectimport.js',
25-
],
26-
projects: ['js/tools.js'],
27-
gold: ['js/gold.js'],
28-
donate: ['js/donate.js']
20+
builds: {'js/detail.js': {}},
21+
core: {
22+
'js/readthedocs-doc-embed.js': {expose: false},
23+
'js/autocomplete.js': {},
24+
'js/projectimport.js': {},
25+
},
26+
projects: {'js/tools.js': {}},
27+
gold: {'js/gold.js': {}},
28+
donate: {'js/donate.js': {}}
2929
};
3030

3131
// Standalone application to create vendor bundles for. These can be imported
3232
// with require in the browser or with Node during testing.
33-
var standalone = ['jquery', 'knockout'];
33+
var standalone = {
34+
'jquery': {standalone: 'jquery'},
35+
'knockout': {},
36+
'jquery-migrate': {standalone: 'jquery-migrate'},
37+
'jquery-ui': {standalone: 'jquery-ui'},
38+
'underscore': {standalone: '_'}
39+
};
3440

3541
// Build application call, wraps building entry point files for a single
3642
// application. This is called by build and dev tasks.
3743
function build_app_sources (application, minify) {
3844
// Normalize file glob lists
39-
var app_sources = sources[application].map(function (n) {
40-
return path.join(pkg_config.name, application, 'static-src', '**', n)
41-
});
42-
var app_js_sources = app_sources.filter(function (elem, n, arr) {
43-
return /\.js$/.test(elem);
44-
});
45-
var app_css_sources = app_sources.filter(function (elem, n, arr) {
46-
return /\.less$/.test(elem);
45+
var bundles = Object.keys(sources[application]).map(function (n) {
46+
var bundle_path = path.join(
47+
pkg_config.name, application, 'static-src', '**', n),
48+
bundle_config = sources[application][n] || {},
49+
bundle;
50+
51+
if (/\.js$/.test(bundle_path)) {
52+
// Javascript sources
53+
bundle = gulp
54+
.src(bundle_path)
55+
.pipe(es.map(function (file, cb) {
56+
if (typeof(bundle_config.expose) == 'undefined') {
57+
var parts = [
58+
application,
59+
path.basename(file.path, '.js')
60+
];
61+
bundle_config.expose = parts.join('/');
62+
}
63+
else if (bundle_config.expose === false) {
64+
bundle_config.expose = undefined;
65+
}
66+
return browserify_stream(
67+
file, bundle_config, cb
68+
);
69+
}));
70+
71+
if (minify) {
72+
bundle = bundle
73+
.pipe(vinyl_buffer())
74+
.pipe(uglify())
75+
.on('error', function (ev) {
76+
gulp_util.beep();
77+
gulp_util.log('Uglify error:', ev.message);
78+
});
79+
}
80+
}
81+
else if (/\.less$/.test(bundle_path)) {
82+
// CSS sources
83+
bundle = gulp.src(bundle_path)
84+
.pipe(less({}))
85+
.on('error', function (ev) {
86+
gulp_util.beep();
87+
gulp_util.log('LESS error:', ev.message);
88+
});
89+
}
90+
91+
return bundle;
4792
});
4893

49-
// Javascript sources
50-
var app_js = gulp
51-
.src(app_js_sources)
52-
.pipe(es.map(browserify_stream));
53-
54-
if (minify) {
55-
app_js = app_js
56-
.pipe(vinyl_buffer())
57-
.pipe(uglify())
58-
.on('error', function (ev) {
59-
gulp_util.beep();
60-
gulp_util.log('Uglify error:', ev.message);
61-
});
62-
}
63-
64-
// CSS sources
65-
var app_css = gulp.src(app_css_sources)
66-
.pipe(less({}))
67-
.on('error', function (ev) {
68-
gulp_util.beep();
69-
gulp_util.log('LESS error:', ev.message);
70-
});
71-
72-
return es.merge(app_js, app_css)
94+
return es.merge(bundles)
7395
.pipe(gulp.dest(path.join(pkg_config.name, application, 'static')));
7496
}
7597

7698
// Browserify build
77-
function browserify_stream (file, cb_output) {
99+
function browserify_stream (file, config, cb_output) {
78100
bower_resolve.offline = true;
79101
bower_resolve.init(function () {
80-
var bundle_stream = browserify(file.path)
102+
var bundle_stream = browserify();
81103

82-
standalone.map(function (module) {
104+
Object.keys(standalone).map(function (module) {
83105
bundle_stream = bundle_stream.external(module);
84106
});
85107

108+
if (typeof(config.expose) == 'undefined') {
109+
bundle_stream.add(file.path);
110+
}
111+
else {
112+
bundle_stream = bundle_stream.require(
113+
file.path, {expose: config.expose}
114+
);
115+
}
116+
86117
bundle_stream
87-
.transform('debowerify', {ignoreModules: standalone})
118+
.transform('debowerify', {ignoreModules: Object.keys(standalone)})
88119
.bundle()
89120
.on('error', function (ev) {
90121
gulp_util.beep();
@@ -101,14 +132,40 @@ function browserify_stream (file, cb_output) {
101132
function build_vendor_sources(data, cb_output) {
102133
bower_resolve.offline = true;
103134
bower_resolve.init(function () {
104-
var standalone_modules = standalone.map(function (module) {
105-
return browserify({standalone: module})
135+
var standalone_modules = Object.keys(standalone).map(function (module) {
136+
var vendor_options = standalone[module] || {},
137+
vendor_bundles = [];
138+
139+
// Bundle vendor libs for import via require()
140+
vendor_bundles.push(
141+
browserify()
106142
.require(bower_resolve(module), {expose: module})
107143
.bundle()
108144
.pipe(vinyl_source(module + '.js'))
109145
.pipe(vinyl_buffer())
110146
.pipe(uglify())
111-
.pipe(gulp.dest(path.join(pkg_config.name, 'static', 'vendor')));
147+
.pipe(gulp.dest(
148+
path.join(pkg_config.name, 'static', 'vendor')
149+
))
150+
);
151+
152+
// Bundle standalone for legacy use. These should only be used on
153+
// old documentation that does not yet use the new bundles
154+
if (typeof(vendor_options.standalone) != 'undefined') {
155+
vendor_bundles.push(
156+
browserify({standalone: vendor_options.standalone})
157+
.require(bower_resolve(module))
158+
.bundle()
159+
.pipe(vinyl_source(module + '-standalone.js'))
160+
.pipe(vinyl_buffer())
161+
.pipe(uglify())
162+
.pipe(gulp.dest(
163+
path.join(pkg_config.name, 'static', 'vendor')
164+
))
165+
);
166+
}
167+
168+
return es.merge(vendor_bundles);
112169
});
113170

114171
es
@@ -145,7 +202,7 @@ gulp.task('dev', function (done) {
145202
.merge(Object.keys(sources).map(function (application) {
146203
var files = [
147204
path.join(pkg_config.name, application, 'static-src', '**', '*.js'),
148-
path.join(pkg_config.name, application, 'static-src', '**', '*.css')
205+
path.join(pkg_config.name, application, 'static-src', '**', '*.less')
149206
];
150207
return watch(files, {verbose: true, name: 'dev'}, function () {
151208
build_app_sources(application, false)

media/javascript/jquery/jquery-2.0.3.min.js

Lines changed: 0 additions & 6 deletions
This file was deleted.
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
../../static/vendor/jquery-standalone.js

media/javascript/jquery/jquery-2.0.3.min.map

Lines changed: 0 additions & 1 deletion
This file was deleted.

media/javascript/jquery/jquery-migrate-1.2.1.min.js

Lines changed: 0 additions & 2 deletions
This file was deleted.
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
../../static/vendor/jquery-migrate-standalone.js

0 commit comments

Comments
 (0)