UNPKG

1.19 kBJavaScriptView Raw
1var fs = require("fs");
2var path = require("path");
3var depsDir = path.join(__dirname, "..", "deps");
4var map = require("../map.json");
5
6// Each file in the `deps` directory expresses the dependencies of a stub.
7// For example, `deps/http.js` calls `require("http-browserify")` to
8// indicate that the `http` stub depends on the `http-browserify` package.
9// This makes it easy for a bundling tool like Browserify, Webpack, or
10// Meteor to include the appropriate package dependencies by depending on
11// `meteor-node-stubs/deps/http` rather than having to know how the `http`
12// stub is implemented. Some modules in the `deps` directory are empty,
13// such as `deps/fs.js`, which indicates that no dependencies need to be
14// bundled. Note that these modules should not be `require`d at runtime,
15// but merely scanned at bundling time.
16
17fs.mkdir(depsDir, function () {
18 require("rimraf")("deps/*.js", function (error) {
19 if (error) throw error;
20 Object.keys(map).forEach(function (id) {
21 fs.writeFileSync(
22 path.join(depsDir, id + ".js"),
23 typeof map[id] === "string"
24 ? "require(" + JSON.stringify(map[id]) + ");\n"
25 : ""
26 );
27 });
28 });
29});