Files
meteor/packages/modules/modules.js
Ben Newman f727bb3c56 New package implementing the runtime API for a CommonJS module system.
When used, the 'modules' package provides a CommonJS require/exports
module system via the exported meteorInstall function. Once that
underlying system is available, ECMAScript 2015 import/export syntax can
be easily compiled into require/exports.
2015-12-09 14:29:53 -05:00

26 lines
1.0 KiB
JavaScript

var options = {};
// RegExp matching strings that don't start with a `.` or a `/`.
var topLevelIdPattern = /^[^./]/;
// This function will be called whenever a module identifier that hasn't
// been installed is required. For backwards compatibility, and so that we
// can require binary dependencies on the server, we implement the
// fallback in terms of Npm.require.
options.fallback = function (id, dir, error) {
// For simplicity, we honor only top-level module identifiers here.
// We could try to honor relative and absolute module identifiers by
// somehow combining `id` with `dir`, but we'd have to be really careful
// that the resulting modules were located in a known directory (not
// some arbitrary location on the file system), and we only really need
// the fallback for dependencies installed in node_modules directories.
if (topLevelIdPattern.test(id) &&
typeof Npm === "object" &&
typeof Npm.require === "function") {
return Npm.require(id);
}
throw error;
};
meteorInstall = makeInstaller(options);