Skip to content

Commit 2004283

Browse files
Add gulp build process
1 parent d415c78 commit 2004283

File tree

9 files changed

+183
-78
lines changed

9 files changed

+183
-78
lines changed

.jshintrc

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@
1919
"predef": {
2020
"ActiveXObject": false,
2121
"XDomainRequest": false,
22+
"Promise": false,
2223
"StackFrame": false,
2324
"StackTraceGPS": false,
2425
"afterEach": false,

dist/stacktrace-gps.js

Lines changed: 39 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -2,16 +2,14 @@
22
'use strict';
33
// Universal Module Definition (UMD) to support AMD, CommonJS/Node.js, Rhino, and browsers.
44
if (typeof define === 'function' && define.amd) {
5-
define('stacktrace-gps', ['source-map', 'es6-promise', 'stackframe'], factory);
5+
define('stacktrace-gps', ['source-map', 'stackframe'], factory);
66
} else if (typeof exports === 'object') {
7-
module.exports = factory(require('source-map/lib/source-map/source-map-consumer'), require('es6-promise'), require('stackframe'));
7+
module.exports = factory(require('source-map/lib/source-map/source-map-consumer'), require('stackframe'));
88
} else {
9-
root.StackTraceGPS = factory(root.SourceMap, root.ES6Promise, root.StackFrame);
9+
root.StackTraceGPS = factory(root.SourceMap, root.StackFrame);
1010
}
11-
}(this, function (SourceMap, ES6Promise, StackFrame) {
11+
}(this, function (SourceMap, StackFrame) {
1212
'use strict';
13-
ES6Promise.polyfill();
14-
var Promise = ES6Promise.Promise;
1513

1614
/**
1715
* Create XHR or equivalent object for this environment.
@@ -150,17 +148,40 @@
150148

151149
this.ajax = _xdr;
152150

151+
this._atob = function (input) {
152+
if (window && window.atob) {
153+
return window.atob(input);
154+
} else if (typeof Buffer !== 'undefined') {
155+
return new Buffer(input, 'base64').toString('utf-8');
156+
}
157+
throw new Error('No base64 decoder available');
158+
};
159+
153160
this._get = function _get(location) {
154161
return new Promise(function (resolve, reject) {
162+
var isDataUrl = location.substr(0, 5) === "data:";
155163
if (this.sourceCache[location]) {
156164
resolve(this.sourceCache[location]);
157-
} else if (opts.offline) {
165+
} else if (opts.offline && !isDataUrl) {
158166
reject(new Error('Cannot make network requests in offline mode'));
159167
} else {
160-
this.ajax(location, function (source) {
161-
this.sourceCache[location] = source;
162-
resolve(source);
163-
}.bind(this), reject);
168+
if (isDataUrl) {
169+
var supportedEncoding = 'application/json;base64';
170+
if (location.substr(5, supportedEncoding.length) !== supportedEncoding) {
171+
reject(new Error('The encoding of the inline sourcemap is not supported'));
172+
} else {
173+
var sourceMapStart = 'data:'.length + supportedEncoding.length + ','.length;
174+
var encodedSource = location.substr(sourceMapStart);
175+
var source = this._atob(encodedSource);
176+
this.sourceCache[location] = source;
177+
resolve(source);
178+
}
179+
} else {
180+
this.ajax(location, function (source) {
181+
this.sourceCache[location] = source;
182+
resolve(source);
183+
}.bind(this), reject);
184+
}
164185
}
165186
}.bind(this));
166187
};
@@ -216,8 +237,13 @@
216237
_ensureSupportedEnvironment();
217238
_ensureStackFrameIsLegit(stackframe);
218239

219-
this._get(stackframe.fileName).then(function (source) {
220-
this._get(_findSourceMappingURL(source)).then(function (map) {
240+
var fileName = stackframe.fileName;
241+
this._get(fileName).then(function (source) {
242+
var sourceMappingURL = _findSourceMappingURL(source);
243+
if (sourceMappingURL[0] !== '/') {
244+
sourceMappingURL = fileName.substring(0, fileName.lastIndexOf('/') + 1) + sourceMappingURL;
245+
}
246+
this._get(sourceMappingURL).then(function (map) {
221247
var lineNumber = stackframe.lineNumber;
222248
var columnNumber = stackframe.columnNumber;
223249
resolve(_newLocationInfoFromSourceMap(map, stackframe.args, lineNumber, columnNumber));

dist/stacktrace-gps.js.map

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

dist/stacktrace-gps.min.js

Lines changed: 2 additions & 2 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

gulpfile.js

Lines changed: 70 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,70 @@
1+
var del = require('del');
2+
var gulp = require('gulp');
3+
var jshint = require('gulp-jshint');
4+
var karma = require('karma').server;
5+
var concat = require('gulp-concat');
6+
var path = require("path");
7+
var runSequence = require('run-sequence');
8+
var sourcemaps = require('gulp-sourcemaps');
9+
var uglify = require('gulp-uglify');
10+
var webpack = require('webpack');
11+
12+
var dependencies = [
13+
'./node_modules/stackframe/dist/stackframe.js',
14+
'./build/source-map-consumer.js'
15+
];
16+
var sources = 'stacktrace-gps.js';
17+
var minified = sources.replace('.js', '.min.js');
18+
19+
gulp.task('lint', function () {
20+
return gulp.src(sources)
21+
.pipe(jshint())
22+
.pipe(jshint.reporter('checkstyle'));
23+
});
24+
25+
gulp.task('test', function (done) {
26+
karma.start({
27+
configFile: __dirname + '/karma.conf.js',
28+
singleRun: true
29+
}, done);
30+
});
31+
32+
gulp.task('test-ci', function (done) {
33+
karma.start({
34+
configFile: __dirname + '/karma.conf.ci.js',
35+
singleRun: true
36+
}, done);
37+
});
38+
39+
gulp.task('copy', function () {
40+
var app = gulp.src(sources)
41+
.pipe(gulp.dest('dist'));
42+
});
43+
44+
gulp.task('webpack-source-consumer', function () {
45+
return webpack({
46+
entry: './node_modules/source-map/lib/source-map/source-map-consumer.js',
47+
output: {
48+
library: 'SourceMap',
49+
path: path.join(__dirname, 'build'),
50+
name: 'source-map-consumer.js'
51+
}
52+
}, function (err) {
53+
if (err) throw new Error('webpack', err);
54+
});
55+
});
56+
57+
gulp.task('compress', ['webpack-source-consumer'], function () {
58+
return gulp.src(dependencies.concat(sources))
59+
.pipe(sourcemaps.init())
60+
.pipe(concat(minified))
61+
.pipe(uglify())
62+
.pipe(sourcemaps.write('./'))
63+
.pipe(gulp.dest('dist'));
64+
});
65+
66+
gulp.task('clean', del.bind(null, ['dist']));
67+
68+
gulp.task('default', ['clean'], function (cb) {
69+
runSequence('lint', ['copy', 'compress'], cb);
70+
});

karma.conf.ci.js

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -56,24 +56,24 @@ module.exports = function (config) {
5656
base: 'SauceLabs',
5757
browserName: 'opera'
5858
},
59-
slIE11: {
60-
base: 'SauceLabs',
61-
browserName: 'internet explorer',
62-
platform: 'Windows 8.1',
63-
version: '11'
64-
},
65-
//slIE10: {
59+
//slIE11: {
6660
// base: 'SauceLabs',
6761
// browserName: 'internet explorer',
68-
// platform: 'Windows 8',
69-
// version: '10'
62+
// platform: 'Windows 8.1',
63+
// version: '11'
7064
//},
71-
slIE9: {
65+
slIE10: {
7266
base: 'SauceLabs',
7367
browserName: 'internet explorer',
74-
platform: 'Windows 7',
75-
version: '9'
68+
platform: 'Windows 8',
69+
version: '10'
7670
}
71+
//slIE9: {
72+
// base: 'SauceLabs',
73+
// browserName: 'internet explorer',
74+
// platform: 'Windows 7',
75+
// version: '9'
76+
//}
7777
};
7878

7979
config.set({

package.json

Lines changed: 10 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
"Eric Wendelin <[email protected]> (http://www.eriwen.com)",
66
"Victor Homyakov <[email protected]> (https://github.com/victor-homyakov)"
77
],
8-
"version": "2.1.2",
8+
"version": "2.1.3",
99
"keywords": [
1010
"stacktrace",
1111
"error",
@@ -17,13 +17,18 @@
1717
"url": "git://github.com/stacktracejs/stacktrace-gps.git"
1818
},
1919
"dependencies": {
20-
"es6-promise": "^2.0.1",
2120
"source-map": "^0.1.43",
2221
"stackframe": "~0.2.2"
2322
},
2423
"devDependencies": {
2524
"colors": "~1.0.3",
2625
"coveralls": "^2.11.2",
26+
"del": "^1.2.0",
27+
"gulp": "^3.9.0",
28+
"gulp-concat": "^2.6.0",
29+
"gulp-jshint": "^1.11.2",
30+
"gulp-sourcemaps": "^1.5.2",
31+
"gulp-uglify": "^1.2.0",
2732
"jasmine-node": "~1.14",
2833
"jasmine-sinon": "^0.4.0",
2934
"jshint": "^2.5.6",
@@ -38,9 +43,10 @@
3843
"karma-safari-launcher": "^0.1.1",
3944
"karma-sauce-launcher": "^0.2.10",
4045
"karma-sinon": "^1.0.3",
46+
"run-sequence": "^1.1.1",
4147
"sinon": "^1.2.22",
4248
"uglify-js": "^2.2.0",
43-
"webpack": "^1.4.12"
49+
"webpack": "^1.10.5"
4450
},
4551
"bugs": {
4652
"url": "https://github.com/stacktracejs/stacktrace-gps/issues"
@@ -58,10 +64,9 @@
5864
"stacktrace-gps.js",
5965
"dist/",
6066
"node_modules/stackframe/",
61-
"node_modules/es6-promise/",
6267
"node_modules/source-map/"
6368
],
6469
"scripts": {
65-
"test": "make test"
70+
"test": "gulp test"
6671
}
6772
}

spec/stacktrace-gps-spec.js

Lines changed: 33 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -317,11 +317,11 @@ describe('StackTraceGPS', function () {
317317
var sourceMin = 'var foo=function(){};function bar(){}var baz=eval("XXX");\n//@ sourceMappingURL=test.js.map';
318318
var sourceMap = '{"version":3,"sources":["./test.js"],"names":["foo","bar","baz","eval"],"mappings":"AAAA,GAAIA,KAAM,YACV,SAASC,QACT,GAAIC,KAAMC,KAAK","file":"test.min.js"}';
319319
var source = 'var foo = function() {};\nfunction bar() {}\nvar baz = eval("XXX")';
320-
server.respondWith('GET', 'http://localhost:9999/test.min.js', [200, { 'Content-Type': 'application/x-javascript' }, sourceMin]);
320+
server.respondWith('GET', 'test.min.js', [200, { 'Content-Type': 'application/x-javascript' }, sourceMin]);
321321
server.respondWith('GET', 'test.js.map', [200, { 'Content-Type': 'application/x-javascript' }, sourceMap]);
322322
server.respondWith('GET', 'test.js', [200, { 'Content-Type': 'application/x-javascript' }, source]);
323323

324-
var stackframe = new StackFrame(undefined, [], 'http://localhost:9999/test.min.js', 1, 47);
324+
var stackframe = new StackFrame(undefined, [], 'test.min.js', 1, 47);
325325
new StackTraceGPS().pinpoint(stackframe).then(callback, errback)['catch'](debugErrback);
326326
});
327327
waits(100);
@@ -343,42 +343,42 @@ describe('StackTraceGPS', function () {
343343
});
344344
});
345345

346-
it('resolves with mapped location even if find function name fails', function() {
347-
runs(function() {
348-
var sourceMin = 'var foo=function(){};function bar(){}var baz=eval("XXX");\n//@ sourceMappingURL=test.js.map';
349-
var sourceMap = '{"version":3,"sources":["./test.js"],"names":["foo","bar","baz","eval"],"mappings":"AAAA,GAAIA,KAAM,YACV,SAASC,QACT,GAAIC,KAAMC,KAAK","file":"test.min.js"}';
350-
server.respondWith('GET', 'http://localhost:9999/test.min.js', [200, { 'Content-Type': 'application/x-javascript' }, sourceMin]);
351-
server.respondWith('GET', 'test.js.map', [200, { 'Content-Type': 'application/x-javascript' }, sourceMap]);
352-
server.respondWith('GET', 'test.js', [404, { 'Content-Type': 'application/x-javascript' }, '']);
346+
it('resolves with mapped location even if find function name fails', function() {
347+
runs(function() {
348+
var sourceMin = 'var foo=function(){};function bar(){}var baz=eval("XXX");\n//@ sourceMappingURL=test.js.map';
349+
var sourceMap = '{"version":3,"sources":["./test.js"],"names":["foo","bar","baz","eval"],"mappings":"AAAA,GAAIA,KAAM,YACV,SAASC,QACT,GAAIC,KAAMC,KAAK","file":"test.min.js"}';
350+
server.respondWith('GET', 'test.min.js', [200, { 'Content-Type': 'application/x-javascript' }, sourceMin]);
351+
server.respondWith('GET', 'test.js.map', [200, { 'Content-Type': 'application/x-javascript' }, sourceMap]);
352+
server.respondWith('GET', 'test.js', [404, { 'Content-Type': 'application/x-javascript' }, '']);
353353

354-
var stackframe = new StackFrame(undefined, [], 'http://localhost:9999/test.min.js', 1, 47);
355-
new StackTraceGPS().pinpoint(stackframe).then(callback, errback)['catch'](debugErrback);
356-
});
357-
waits(100);
358-
runs(function() {
359-
server.respond();
360-
});
361-
waits(100);
362-
runs(function() {
363-
server.respond();
364-
});
365-
waits(100);
366-
runs(function() {
367-
server.respond();
368-
});
369-
waits(100);
370-
runs(function() {
371-
expect(callback).toHaveBeenCalledWith(new StackFrame('eval', [], 'test.js', 3, 10));
372-
expect(errback).not.toHaveBeenCalled();
373-
});
374-
});
354+
var stackframe = new StackFrame(undefined, [], 'test.min.js', 1, 47);
355+
new StackTraceGPS().pinpoint(stackframe).then(callback, errback)['catch'](debugErrback);
356+
});
357+
waits(100);
358+
runs(function() {
359+
server.respond();
360+
});
361+
waits(100);
362+
runs(function() {
363+
server.respond();
364+
});
365+
waits(100);
366+
runs(function() {
367+
server.respond();
368+
});
369+
waits(100);
370+
runs(function() {
371+
expect(callback).toHaveBeenCalledWith(new StackFrame('eval', [], 'test.js', 3, 10));
372+
expect(errback).not.toHaveBeenCalled();
373+
});
374+
});
375375

376376
it('supports inline source maps', function() {
377377
runs(function() {
378378
var sourceMin = 'var foo=function(){};function bar(){}var baz=eval("XXX");//# sourceMappingURL=data:application/json;base64,eyJ2ZXJzaW9uIjozLCJzb3VyY2VzIjpbInRlc3QuanMiXSwibmFtZXMiOlsiZm9vIiwiYmFyIiwiYmF6IiwiZXZhbCJdLCJtYXBwaW5ncyI6IkFBQUEsR0FBSUEsS0FBTSxZQUdWLFNBQVNDLFFBRVQsR0FBSUMsS0FBTUMsS0FBTSJ9';
379-
server.respondWith('GET', 'http://localhost:9999/test.min.js', [200, { 'Content-Type': 'application/x-javascript' }, sourceMin]);
379+
server.respondWith('GET', 'test.min.js', [200, { 'Content-Type': 'application/x-javascript' }, sourceMin]);
380380

381-
var stackframe = new StackFrame(undefined, [], 'http://localhost:9999/test.min.js', 1, 47);
381+
var stackframe = new StackFrame(undefined, [], 'test.min.js', 1, 47);
382382
new StackTraceGPS().pinpoint(stackframe).then(callback, errback)['catch'](debugErrback);
383383
});
384384
waits(100);
@@ -395,7 +395,7 @@ describe('StackTraceGPS', function () {
395395
});
396396
waits(100);
397397
runs(function() {
398-
expect(callback).toHaveBeenCalledWith(new StackFrame('eval', [], 'test.js', 3, 10));
398+
expect(callback).toHaveBeenCalledWith(new StackFrame('eval', [], 'test.js', 6, 10));
399399
expect(errback).not.toHaveBeenCalled();
400400
});
401401
});

0 commit comments

Comments
 (0)