-
Notifications
You must be signed in to change notification settings - Fork 88
/
node.js
50 lines (42 loc) · 1.46 KB
/
node.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
define(["./has"], function(has){
if(!has("host-node")){
throw new Error("node plugin failed to load because environment is not Node.js");
}
return {
// summary:
// This AMD plugin module allows native Node.js modules to be loaded by AMD modules using the Dojo
// loader. Note that this plugin will not work with AMD loaders other than the Dojo loader.
// example:
// | require(["dojo/node!fs"], function(fs){
// | var fileData = fs.readFileSync("foo.txt", "utf-8");
// | });
load: function(/*string*/ id, /*Function*/ require, /*Function*/ load){
// summary:
// Standard AMD plugin interface. See https://github.com/amdjs/amdjs-api/wiki/Loader-Plugins
// for information.
if(!require.nodeRequire){
throw new Error("Cannot find native require function");
}
load((function(id, require){
var oldDefine = define,
result;
// Some modules may attempt to detect an AMD loader via define and define.amd. This can cause issues
// when other CommonJS modules attempt to load them via the standard node require(). If define is
// temporarily moved into another variable, it will prevent modules from detecting AMD in this fashion.
define = undefined;
try {
result = require(id);
} finally {
define = oldDefine;
}
return result;
})(id, require.nodeRequire));
},
normalize: function (/**string*/ id) {
if (id.charAt(0) === '.') {
id = require.baseUrl + id;
}
return id;
}
};
});