mirror of
https://github.com/meteor/meteor.git
synced 2026-05-02 03:01:46 -04:00
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.
This commit is contained in:
1
packages/modules/.npm/package/.gitignore
vendored
Normal file
1
packages/modules/.npm/package/.gitignore
vendored
Normal file
@@ -0,0 +1 @@
|
||||
node_modules
|
||||
7
packages/modules/.npm/package/README
Normal file
7
packages/modules/.npm/package/README
Normal file
@@ -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.
|
||||
7
packages/modules/.npm/package/npm-shrinkwrap.json
generated
Normal file
7
packages/modules/.npm/package/npm-shrinkwrap.json
generated
Normal file
@@ -0,0 +1,7 @@
|
||||
{
|
||||
"dependencies": {
|
||||
"install": {
|
||||
"version": "0.4.0"
|
||||
}
|
||||
}
|
||||
}
|
||||
0
packages/modules/README.md
Normal file
0
packages/modules/README.md
Normal file
6
packages/modules/modules-tests.js
Normal file
6
packages/modules/modules-tests.js
Normal file
@@ -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");
|
||||
});
|
||||
25
packages/modules/modules.js
Normal file
25
packages/modules/modules.js
Normal file
@@ -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);
|
||||
33
packages/modules/package.js
Normal file
33
packages/modules/package.js
Normal file
@@ -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");
|
||||
});
|
||||
Reference in New Issue
Block a user