When packaging stuff for Node (CommonJS) and other schemes, there is some indicator of what the environment is (see example code from HighlightJS below).
Is there some way to find the global object from within a Meteor package so I can have essentially the same code base for a npm module (has an extra package.json
relative to a Meteor package), and for a Meteor package (has an extra package.js
relative to a npm package)?
i.e.: I want to be able to do meteor publish; npm publish;
and have things all work out. But what I have below is sketchy.
(function(root, name, factory) {
var thingie = factory();
if (typeof module === "object" && module.exports) {
// Node or CommonJS
module.exports = thingie;
} else if (typeof define === "function" && define.amd) {
// AMD
define([], function() {
return thingie;
});
} else {
// The Else Condition
// Find the global object for export to both the browser and web workers.
var globalObject = (typeof window === 'object') && window ||
(typeof self === 'object') && self;
var thingie = factory(_);
root[name] = thingie;
if (!!globalObject) {
globalObject[name] = thingie;
}
// Poor Meteor
SomeModule = thingie;
}
}(this, 'SomeModule', someFactory));