mirror of
https://github.com/meteor/meteor.git
synced 2026-05-02 03:01:46 -04:00
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.
26 lines
1.0 KiB
JavaScript
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);
|