Skip to content

Commit 78b49c9

Browse files
bz2steren
authored andcommitted
Expose as module and use browserify (#53)
Expose as module Switch base library to commonjs format Use require() rather than implicit global for StackTrace dependency. Dedent library source, losing blame unfortunately. Link test.html to built source that adds UMD wrapper. Update eslint config to expect commonjs source everywhere. Drop special handling for StackTrace object being undefined. Fixes: #2 Bundle dist script with browserify Change gulp dist task from concatting prebuilt source to building from components and bundling using browserify. Supply polyfills from core-js via browserify require, based on the upstream polyfills in stacktrace-js. This may be overly conservative as browsers back to IE 9 have good enough ES5 support, just filling Promise is probably be reasonable. * Update dependencies and drop to nise from sinon The fake-xhr part of sinon has been split to its own package, so can just use that drop a few unused packages.
1 parent 8864fb4 commit 78b49c9

8 files changed

Lines changed: 1943 additions & 863 deletions

File tree

.eslintrc.json

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
{
22
"env": {
3-
"browser": true
3+
"browser": true,
4+
"commonjs": true
45
},
56
"extends": [
67
"eslint:recommended"
@@ -58,7 +59,7 @@
5859
},
5960
"globals": {
6061
"chai": false,
61-
"sinon": false,
62+
"nise": false,
6263
"StackdriverErrorReporter": false
6364
},
6465
"plugins": [

gulpfile.js

Lines changed: 23 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -13,25 +13,39 @@
1313
* See the License for the specific language governing permissions and
1414
* limitations under the License.
1515
*/
16-
/* global require */
16+
var browserify = require('browserify');
1717
var gulp = require('gulp');
1818
var rename = require('gulp-rename');
1919
var replace = require('gulp-replace');
2020
var uglify = require('gulp-uglify');
2121
var sourcemaps = require('gulp-sourcemaps');
22-
var concat = require('gulp-concat');
22+
var buffer = require('vinyl-buffer');
23+
var source = require('vinyl-source-stream');
2324

2425
var SRC_FILE = 'stackdriver-errors.js';
2526
var DEST = 'dist/';
2627

27-
var dependencies = [
28-
'./node_modules/stacktrace-js/dist/stacktrace-with-promises-and-json-polyfills.js',
28+
var polyfills = [
29+
'core-js/fn/array/filter',
30+
'core-js/fn/array/for-each',
31+
'core-js/fn/array/map',
32+
'core-js/fn/function/bind',
33+
'core-js/fn/promise',
2934
];
3035

31-
gulp.task('dist', function() {
32-
return gulp.src(dependencies.concat(SRC_FILE))
36+
gulp.task('lib-concat', function() {
37+
return browserify({
38+
debug: true,
39+
entries: SRC_FILE,
40+
standalone: 'StackdriverErrorReporter',
41+
})
42+
.require(polyfills)
43+
.plugin('browser-pack-flat/plugin')
44+
.bundle()
45+
.pipe(source(SRC_FILE))
46+
.pipe(rename({suffix: '-concat'}))
47+
.pipe(buffer())
3348
.pipe(sourcemaps.init({loadMaps: true}))
34-
.pipe(concat(SRC_FILE.replace('.js', '-concat.js')))
3549
// This will output the non-minified version
3650
.pipe(gulp.dest(DEST))
3751
// This will minify and rename to stackdriver-errors.min.js
@@ -58,5 +72,5 @@ gulp.task('demo-js', function() {
5872
.pipe(gulp.dest('dist'));
5973
});
6074

61-
gulp.task('default', ['dist']);
62-
gulp.task('demo', ['dist', 'demo-html', 'demo-js']);
75+
gulp.task('default', ['lib-concat']);
76+
gulp.task('demo', ['lib-concat', 'demo-html', 'demo-js']);

0 commit comments

Comments
 (0)