Skip to content

Commit 4f596b6

Browse files
authored
Merge pull request #6 from dfreeman/gzipped-maps
Handle gzipped source maps
2 parents 4fc261c + 135cd9a commit 4f596b6

File tree

2 files changed

+23
-1
lines changed

2 files changed

+23
-1
lines changed

README.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -79,6 +79,7 @@ Set by other Ember CLI Deploy plugins:
7979
| ---------- | ------------- | -------- | ----------- | ------ |
8080
| `distDir` | string | `tmp/deploy-dist` | The path to your app's distribution directory. | [`ember-cli-build`](https://github.com/zapnito/ember-cli-deploy-build) |
8181
| `revisionKey` | string | `<none>` | The unique identifier of a build based on its git tag. | [`ember-cli-deploy-revision-data`](https://github.com/zapnito/ember-cli-deploy-revision-data) |
82+
| `gzippedFiles` | array | `<none>` | A list of files that have been gzipped in the build. | [`ember-cli-deploy-gzip`](https://github.com/ember-cli-deploy/ember-cli-deploy-gzip) |
8283
8384
### Deploying to Heroku
8485

index.js

Lines changed: 22 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,9 @@
44

55
var RSVP = require('rsvp');
66
var fs = require('fs');
7+
var path = require('path');
78
var request = require('request-promise');
9+
var zlib = require('zlib');
810

911
var BasePlugin = require('ember-cli-deploy-plugin');
1012

@@ -22,6 +24,9 @@ module.exports = {
2224
distFiles: function(context) {
2325
return context.distFiles;
2426
},
27+
gzippedFiles: function(context) {
28+
return context.gzippedFiles || [];
29+
},
2530
revisionKey: function(context) {
2631
if (context.revisionData) {
2732
return context.revisionData.revisionKey;
@@ -57,7 +62,7 @@ module.exports = {
5762
apiKey: apiKey,
5863
overwrite: overwrite,
5964
minifiedUrl: jsFilePath,
60-
sourceMap: fs.createReadStream(mapFilePath)
65+
sourceMap: this._readSourceMap(mapFilePath)
6166
};
6267
if (revisionKey && includeAppVersion) {
6368
formData.appVersion = revisionKey;
@@ -97,6 +102,22 @@ module.exports = {
97102
return RSVP.all(promises);
98103
}
99104
},
105+
106+
_readSourceMap(mapFilePath) {
107+
var relativeMapFilePath = mapFilePath.replace(this.readConfig('distDir') + '/', '');
108+
if (this.readConfig('gzippedFiles').indexOf(relativeMapFilePath) !== -1) {
109+
// When the source map is gzipped, we need to eagerly load it into a buffer
110+
// so that the actual content length is known.
111+
return {
112+
value: zlib.unzipSync(fs.readFileSync(mapFilePath)),
113+
options: {
114+
filename: path.basename(mapFilePath),
115+
}
116+
};
117+
} else {
118+
return fs.createReadStream(mapFilePath);
119+
}
120+
}
100121
});
101122

102123
return new DeployPlugin();

0 commit comments

Comments
 (0)