Skip to content

Commit

Permalink
Store runner.js in test-in-console as an asset; extract via env var.
Browse files Browse the repository at this point in the history
Allow packages to specify that files are assets, overriding any handler defined
for them. (May be useful for web workers!)

Let Assets.getBinary work before global-imports.js is executed.
  • Loading branch information
glasser committed Jul 19, 2013
1 parent d0b7b41 commit 237f6da
Show file tree
Hide file tree
Showing 4 changed files with 19 additions and 4 deletions.
3 changes: 3 additions & 0 deletions packages/test-in-console/package.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,4 14,7 @@ Package.on_use(function (api) {
api.add_files([
'reporter.js'
], "server");

// This is to be run by phantomjs, not as part of normal package code.
api.add_files('runner.js', 'server', {isAsset: true});
});
6 changes: 6 additions & 0 deletions packages/test-in-console/reporter.js
Original file line number Diff line number Diff line change
@@ -1,3 1,9 @@
// A hacky way to extract the phantom runner script from the package.
if (process.env.WRITE_RUNNER_JS) {
Npm.require('fs').writeFileSync(
process.env.WRITE_RUNNER_JS, new Buffer(Assets.getBinary('runner.js')));
}

var url = null;
if (Meteor.settings &&
Meteor.settings.public &&
Expand Down
6 changes: 4 additions & 2 deletions tools/packages.js
Original file line number Diff line number Diff line change
Expand Up @@ -265,7 265,7 @@ _.extend(Slice.prototype, {
var fileOptions = _.clone(source.fileOptions) || {};
var absPath = path.resolve(self.pkg.sourceRoot, relPath);
var ext = path.extname(relPath).substr(1);
var handler = !source.isAsset && self._getSourceHandler(ext);
var handler = !fileOptions.isAsset && self._getSourceHandler(ext);
var contents = fs.readFileSync(absPath);
self.dependencyInfo.files[absPath] = Builder.sha1(contents);

Expand Down Expand Up @@ -1857,7 1857,9 @@ _.extend(Package.prototype, {

sources.push({
relPath: assetRelPath,
isAsset: true
fileOptions: {
isAsset: true
}
});
});
};
Expand Down
8 changes: 6 additions & 2 deletions tools/server/boot.js
Original file line number Diff line number Diff line change
Expand Up @@ -114,13 114,17 @@ Fiber(function () {
fut = new Future();
callback = fut.resolver();
}
var _callback = Meteor.bindEnvironment(function (err, result) {
// This assumes that we've already loaded the meteor package, so meteor
// itself (and weird special cases like js-analyze) can't call
// Assets.get*. (We could change this function so that it doesn't call
// bindEnvironment if you don't pass a callback if we need to.)
var _callback = Package.meteor.Meteor.bindEnvironment(function (err, result) {
if (result && ! encoding)
// Sadly, this copies in Node 0.10.
result = new Uint8Array(result);
callback(err, result);
}, function (e) {
Meteor._debug("Exception in callback of getAsset", e.stack);
console.log("Exception in callback of getAsset", e.stack);
});

if (!fileInfo.assets || !_.has(fileInfo.assets, assetPath)) {
Expand Down

0 comments on commit 237f6da

Please sign in to comment.