diff --git a/packages/modules/.npm/package/.gitignore b/packages/modules/.npm/package/.gitignore new file mode 100644 index 0000000000..3c3629e647 --- /dev/null +++ b/packages/modules/.npm/package/.gitignore @@ -0,0 +1 @@ +node_modules diff --git a/packages/modules/.npm/package/README b/packages/modules/.npm/package/README new file mode 100644 index 0000000000..3d492553a4 --- /dev/null +++ b/packages/modules/.npm/package/README @@ -0,0 +1,7 @@ +This directory and the files immediately inside it are automatically generated +when you change this package's NPM dependencies. Commit the files in this +directory (npm-shrinkwrap.json, .gitignore, and this README) to source control +so that others run the same versions of sub-dependencies. + +You should NOT check in the node_modules directory that Meteor automatically +creates; if you are using git, the .gitignore file tells git to ignore it. diff --git a/packages/modules/.npm/package/npm-shrinkwrap.json b/packages/modules/.npm/package/npm-shrinkwrap.json new file mode 100644 index 0000000000..3d18bb8563 --- /dev/null +++ b/packages/modules/.npm/package/npm-shrinkwrap.json @@ -0,0 +1,7 @@ +{ + "dependencies": { + "install": { + "version": "0.4.0" + } + } +} diff --git a/packages/modules/README.md b/packages/modules/README.md new file mode 100644 index 0000000000..e69de29bb2 diff --git a/packages/modules/modules-tests.js b/packages/modules/modules-tests.js new file mode 100644 index 0000000000..07c400fcaa --- /dev/null +++ b/packages/modules/modules-tests.js @@ -0,0 +1,6 @@ +Tinytest.add('modules', function (test) { + test.equal(typeof meteorInstall, "function"); + var require = meteorInstall(); + test.equal(typeof require, "function"); + test.equal(typeof require.ensure, "function"); +}); diff --git a/packages/modules/modules.js b/packages/modules/modules.js new file mode 100644 index 0000000000..cd1005dca4 --- /dev/null +++ b/packages/modules/modules.js @@ -0,0 +1,25 @@ +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); diff --git a/packages/modules/package.js b/packages/modules/package.js new file mode 100644 index 0000000000..9c45d0700d --- /dev/null +++ b/packages/modules/package.js @@ -0,0 +1,33 @@ +Package.describe({ + name: "modules", + version: "0.4.0", + summary: "CommonJS module system", + git: "https://github.com/benjamn/install", + documentation: "README.md" +}); + +Npm.depends({ + install: "0.4.0" +}); + +Package.onUse(function(api) { + api.use("meteor", { + unordered: true + }); + + api.addFiles(".npm/package/node_modules/install/install.js", [ + "client", + "server" + ], { + bare: true + }); + + api.addFiles("modules.js"); + api.export("meteorInstall"); +}); + +Package.onTest(function(api) { + api.use("tinytest"); + api.use("modules"); + api.addFiles("modules-tests.js"); +});