Files
meteor/packages/modules/modules.js
Ben Newman d885a9a796 Stop generating stub modules for imported Meteor packages.
Instead, we rely on the fallback function defined in
meteor/packages/modules/modules.js to resolve meteor/package identifiers
at runtime. The ImportScanner also now warns if no such Meteor package
seems to be available.

Package stubs were a clever hack, but eliminating them means every module
installed by meteorInstall now corresponds to some actual module file.
2016-01-08 19:10:32 -05:00

36 lines
1.3 KiB
JavaScript

var options = {};
var hasOwn = options.hasOwnProperty;
// 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)) {
var parts = id.split("/");
if (parts.length === 2 &&
parts[0] === "meteor" &&
hasOwn.call(Package, parts[1])) {
return Package[parts[1]];
}
if (typeof Npm === "object" &&
typeof Npm.require === "function") {
return Npm.require(id);
}
}
throw error;
};
meteorInstall = makeInstaller(options);