macgyver 0.0.8
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +7 -0
- data/.gitignore +5 -0
- data/Gemfile +4 -0
- data/LICENSE +20 -0
- data/README.md +45 -0
- data/Rakefile +1 -0
- data/assets/MacGap.app/Contents/Frameworks/Growl.framework/Growl +0 -0
- data/assets/MacGap.app/Contents/Frameworks/Growl.framework/Versions/A/Growl +0 -0
- data/assets/MacGap.app/Contents/Frameworks/Growl.framework/Versions/A/Headers/Growl.h +5 -0
- data/assets/MacGap.app/Contents/Frameworks/Growl.framework/Versions/A/Headers/GrowlApplicationBridge.h +551 -0
- data/assets/MacGap.app/Contents/Frameworks/Growl.framework/Versions/A/Headers/GrowlDefines.h +341 -0
- data/assets/MacGap.app/Contents/Frameworks/Growl.framework/Versions/A/Resources/Info.plist +40 -0
- data/assets/MacGap.app/Contents/Frameworks/Growl.framework/Versions/A/_CodeSignature/CodeResources +34 -0
- data/assets/MacGap.app/Contents/Info.plist +48 -0
- data/assets/MacGap.app/Contents/MacOS/MacGap +0 -0
- data/assets/MacGap.app/Contents/PkgInfo +1 -0
- data/assets/MacGap.app/Contents/Resources/_debugger.js +1718 -0
- data/assets/MacGap.app/Contents/Resources/_http_agent.js +310 -0
- data/assets/MacGap.app/Contents/Resources/_http_client.js +533 -0
- data/assets/MacGap.app/Contents/Resources/_http_common.js +222 -0
- data/assets/MacGap.app/Contents/Resources/_http_incoming.js +194 -0
- data/assets/MacGap.app/Contents/Resources/_http_outgoing.js +597 -0
- data/assets/MacGap.app/Contents/Resources/_http_server.js +510 -0
- data/assets/MacGap.app/Contents/Resources/_linklist.js +76 -0
- data/assets/MacGap.app/Contents/Resources/_stream_duplex.js +69 -0
- data/assets/MacGap.app/Contents/Resources/_stream_passthrough.js +41 -0
- data/assets/MacGap.app/Contents/Resources/_stream_readable.js +900 -0
- data/assets/MacGap.app/Contents/Resources/_stream_transform.js +204 -0
- data/assets/MacGap.app/Contents/Resources/_stream_writable.js +456 -0
- data/assets/MacGap.app/Contents/Resources/_tls_legacy.js +887 -0
- data/assets/MacGap.app/Contents/Resources/_tls_wrap.js +831 -0
- data/assets/MacGap.app/Contents/Resources/application.icns +0 -0
- data/assets/MacGap.app/Contents/Resources/assert.js +326 -0
- data/assets/MacGap.app/Contents/Resources/buffer.js +724 -0
- data/assets/MacGap.app/Contents/Resources/child_process.js +1107 -0
- data/assets/MacGap.app/Contents/Resources/cluster.js +613 -0
- data/assets/MacGap.app/Contents/Resources/console.js +108 -0
- data/assets/MacGap.app/Contents/Resources/constants.js +22 -0
- data/assets/MacGap.app/Contents/Resources/crypto.js +691 -0
- data/assets/MacGap.app/Contents/Resources/dgram.js +459 -0
- data/assets/MacGap.app/Contents/Resources/dns.js +274 -0
- data/assets/MacGap.app/Contents/Resources/domain.js +292 -0
- data/assets/MacGap.app/Contents/Resources/en.lproj/Credits.rtf +29 -0
- data/assets/MacGap.app/Contents/Resources/en.lproj/InfoPlist.strings +0 -0
- data/assets/MacGap.app/Contents/Resources/en.lproj/MainMenu.nib +0 -0
- data/assets/MacGap.app/Contents/Resources/en.lproj/Window.nib +0 -0
- data/assets/MacGap.app/Contents/Resources/events.js +312 -0
- data/assets/MacGap.app/Contents/Resources/freelist.js +43 -0
- data/assets/MacGap.app/Contents/Resources/fs.js +1732 -0
- data/assets/MacGap.app/Contents/Resources/http.js +119 -0
- data/assets/MacGap.app/Contents/Resources/https.js +134 -0
- data/assets/MacGap.app/Contents/Resources/module.js +529 -0
- data/assets/MacGap.app/Contents/Resources/net.js +1378 -0
- data/assets/MacGap.app/Contents/Resources/nodelike.js +195 -0
- data/assets/MacGap.app/Contents/Resources/os.js +64 -0
- data/assets/MacGap.app/Contents/Resources/path.js +517 -0
- data/assets/MacGap.app/Contents/Resources/public/index.html +38 -0
- data/assets/MacGap.app/Contents/Resources/punycode.js +507 -0
- data/assets/MacGap.app/Contents/Resources/querystring.js +206 -0
- data/assets/MacGap.app/Contents/Resources/readline.js +1311 -0
- data/assets/MacGap.app/Contents/Resources/repl.js +945 -0
- data/assets/MacGap.app/Contents/Resources/smalloc.js +90 -0
- data/assets/MacGap.app/Contents/Resources/stream.js +127 -0
- data/assets/MacGap.app/Contents/Resources/string_decoder.js +189 -0
- data/assets/MacGap.app/Contents/Resources/sys.js +24 -0
- data/assets/MacGap.app/Contents/Resources/timers.js +568 -0
- data/assets/MacGap.app/Contents/Resources/tls.js +220 -0
- data/assets/MacGap.app/Contents/Resources/tty.js +129 -0
- data/assets/MacGap.app/Contents/Resources/url.js +693 -0
- data/assets/MacGap.app/Contents/Resources/util.js +688 -0
- data/assets/MacGap.app/Contents/Resources/vm.js +73 -0
- data/assets/MacGap.app/Contents/Resources/zlib.js +524 -0
- data/assets/index.html +38 -0
- data/bin/macgyver +104 -0
- data/macgyver.gemspec +19 -0
- data/test/public/index.html +27 -0
- metadata +121 -0
@@ -0,0 +1,119 @@
|
|
1
|
+
// Copyright Joyent, Inc. and other Node contributors.
|
2
|
+
//
|
3
|
+
// Permission is hereby granted, free of charge, to any person obtaining a
|
4
|
+
// copy of this software and associated documentation files (the
|
5
|
+
// "Software"), to deal in the Software without restriction, including
|
6
|
+
// without limitation the rights to use, copy, modify, merge, publish,
|
7
|
+
// distribute, sublicense, and/or sell copies of the Software, and to permit
|
8
|
+
// persons to whom the Software is furnished to do so, subject to the
|
9
|
+
// following conditions:
|
10
|
+
//
|
11
|
+
// The above copyright notice and this permission notice shall be included
|
12
|
+
// in all copies or substantial portions of the Software.
|
13
|
+
//
|
14
|
+
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
|
15
|
+
// OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
16
|
+
// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN
|
17
|
+
// NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM,
|
18
|
+
// DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR
|
19
|
+
// OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE
|
20
|
+
// USE OR OTHER DEALINGS IN THE SOFTWARE.
|
21
|
+
|
22
|
+
var util = require('util');
|
23
|
+
var EventEmitter = require('events').EventEmitter;
|
24
|
+
|
25
|
+
|
26
|
+
var incoming = require('_http_incoming');
|
27
|
+
var IncomingMessage = exports.IncomingMessage = incoming.IncomingMessage;
|
28
|
+
|
29
|
+
|
30
|
+
var common = require('_http_common');
|
31
|
+
exports.METHODS = util._extend([], common.methods).sort();
|
32
|
+
exports.parsers = common.parsers;
|
33
|
+
|
34
|
+
|
35
|
+
var outgoing = require('_http_outgoing');
|
36
|
+
var OutgoingMessage = exports.OutgoingMessage = outgoing.OutgoingMessage;
|
37
|
+
|
38
|
+
|
39
|
+
var server = require('_http_server');
|
40
|
+
exports.ServerResponse = server.ServerResponse;
|
41
|
+
exports.STATUS_CODES = server.STATUS_CODES;
|
42
|
+
|
43
|
+
|
44
|
+
var agent = require('_http_agent');
|
45
|
+
var Agent = exports.Agent = agent.Agent;
|
46
|
+
var globalAgent = exports.globalAgent = agent.globalAgent;
|
47
|
+
|
48
|
+
var client = require('_http_client');
|
49
|
+
var ClientRequest = exports.ClientRequest = client.ClientRequest;
|
50
|
+
|
51
|
+
exports.request = function(options, cb) {
|
52
|
+
return globalAgent.request(options, cb);
|
53
|
+
};
|
54
|
+
|
55
|
+
exports.get = function(options, cb) {
|
56
|
+
return globalAgent.get(options, cb);
|
57
|
+
};
|
58
|
+
|
59
|
+
exports._connectionListener = server._connectionListener;
|
60
|
+
var Server = exports.Server = server.Server;
|
61
|
+
|
62
|
+
exports.createServer = function(requestListener) {
|
63
|
+
return new Server(requestListener);
|
64
|
+
};
|
65
|
+
|
66
|
+
|
67
|
+
// Legacy Interface
|
68
|
+
|
69
|
+
function Client(port, host) {
|
70
|
+
if (!(this instanceof Client)) return new Client(port, host);
|
71
|
+
EventEmitter.call(this);
|
72
|
+
|
73
|
+
host = host || 'localhost';
|
74
|
+
port = port || 80;
|
75
|
+
this.host = host;
|
76
|
+
this.port = port;
|
77
|
+
this.agent = new Agent({ host: host, port: port, maxSockets: 1 });
|
78
|
+
}
|
79
|
+
util.inherits(Client, EventEmitter);
|
80
|
+
Client.prototype.request = function(method, path, headers) {
|
81
|
+
var self = this;
|
82
|
+
var options = {};
|
83
|
+
options.host = self.host;
|
84
|
+
options.port = self.port;
|
85
|
+
if (method[0] === '/') {
|
86
|
+
headers = path;
|
87
|
+
path = method;
|
88
|
+
method = 'GET';
|
89
|
+
}
|
90
|
+
options.method = method;
|
91
|
+
options.path = path;
|
92
|
+
options.headers = headers;
|
93
|
+
options.agent = self.agent;
|
94
|
+
var c = new ClientRequest(options);
|
95
|
+
c.on('error', function(e) {
|
96
|
+
self.emit('error', e);
|
97
|
+
});
|
98
|
+
// The old Client interface emitted 'end' on socket end.
|
99
|
+
// This doesn't map to how we want things to operate in the future
|
100
|
+
// but it will get removed when we remove this legacy interface.
|
101
|
+
c.on('socket', function(s) {
|
102
|
+
s.on('end', function() {
|
103
|
+
if (self._decoder) {
|
104
|
+
var ret = self._decoder.end();
|
105
|
+
if (ret)
|
106
|
+
self.emit('data', ret);
|
107
|
+
}
|
108
|
+
self.emit('end');
|
109
|
+
});
|
110
|
+
});
|
111
|
+
return c;
|
112
|
+
};
|
113
|
+
|
114
|
+
exports.Client = util.deprecate(Client,
|
115
|
+
'http.Client will be removed soon. Do not use it.');
|
116
|
+
|
117
|
+
exports.createClient = util.deprecate(function(port, host) {
|
118
|
+
return new Client(port, host);
|
119
|
+
}, 'http.createClient is deprecated. Use `http.request` instead.');
|
@@ -0,0 +1,134 @@
|
|
1
|
+
// Copyright Joyent, Inc. and other Node contributors.
|
2
|
+
//
|
3
|
+
// Permission is hereby granted, free of charge, to any person obtaining a
|
4
|
+
// copy of this software and associated documentation files (the
|
5
|
+
// "Software"), to deal in the Software without restriction, including
|
6
|
+
// without limitation the rights to use, copy, modify, merge, publish,
|
7
|
+
// distribute, sublicense, and/or sell copies of the Software, and to permit
|
8
|
+
// persons to whom the Software is furnished to do so, subject to the
|
9
|
+
// following conditions:
|
10
|
+
//
|
11
|
+
// The above copyright notice and this permission notice shall be included
|
12
|
+
// in all copies or substantial portions of the Software.
|
13
|
+
//
|
14
|
+
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
|
15
|
+
// OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
16
|
+
// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN
|
17
|
+
// NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM,
|
18
|
+
// DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR
|
19
|
+
// OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE
|
20
|
+
// USE OR OTHER DEALINGS IN THE SOFTWARE.
|
21
|
+
|
22
|
+
var tls = require('tls');
|
23
|
+
var http = require('http');
|
24
|
+
var util = require('util');
|
25
|
+
var inherits = require('util').inherits;
|
26
|
+
var debug = util.debuglog('https');
|
27
|
+
|
28
|
+
function Server(opts, requestListener) {
|
29
|
+
if (!(this instanceof Server)) return new Server(opts, requestListener);
|
30
|
+
|
31
|
+
if (process.features.tls_npn && !opts.NPNProtocols) {
|
32
|
+
opts.NPNProtocols = ['http/1.1', 'http/1.0'];
|
33
|
+
}
|
34
|
+
|
35
|
+
tls.Server.call(this, opts, http._connectionListener);
|
36
|
+
|
37
|
+
this.httpAllowHalfOpen = false;
|
38
|
+
|
39
|
+
if (requestListener) {
|
40
|
+
this.addListener('request', requestListener);
|
41
|
+
}
|
42
|
+
|
43
|
+
this.addListener('clientError', function(err, conn) {
|
44
|
+
conn.destroy();
|
45
|
+
});
|
46
|
+
|
47
|
+
this.timeout = 2 * 60 * 1000;
|
48
|
+
}
|
49
|
+
inherits(Server, tls.Server);
|
50
|
+
exports.Server = Server;
|
51
|
+
|
52
|
+
Server.prototype.setTimeout = http.Server.prototype.setTimeout;
|
53
|
+
|
54
|
+
exports.createServer = function(opts, requestListener) {
|
55
|
+
return new Server(opts, requestListener);
|
56
|
+
};
|
57
|
+
|
58
|
+
|
59
|
+
// HTTPS agents.
|
60
|
+
|
61
|
+
function createConnection(port, host, options) {
|
62
|
+
if (util.isObject(port)) {
|
63
|
+
options = port;
|
64
|
+
} else if (util.isObject(host)) {
|
65
|
+
options = host;
|
66
|
+
} else if (util.isObject(options)) {
|
67
|
+
options = options;
|
68
|
+
} else {
|
69
|
+
options = {};
|
70
|
+
}
|
71
|
+
|
72
|
+
if (util.isNumber(port)) {
|
73
|
+
options.port = port;
|
74
|
+
}
|
75
|
+
|
76
|
+
if (util.isString(host)) {
|
77
|
+
options.host = host;
|
78
|
+
}
|
79
|
+
|
80
|
+
debug('createConnection', options);
|
81
|
+
return tls.connect(options);
|
82
|
+
}
|
83
|
+
|
84
|
+
|
85
|
+
function Agent(options) {
|
86
|
+
http.Agent.call(this, options);
|
87
|
+
this.defaultPort = 443;
|
88
|
+
this.protocol = 'https:';
|
89
|
+
}
|
90
|
+
inherits(Agent, http.Agent);
|
91
|
+
Agent.prototype.createConnection = createConnection;
|
92
|
+
|
93
|
+
Agent.prototype.getName = function(options) {
|
94
|
+
var name = http.Agent.prototype.getName.call(this, options);
|
95
|
+
|
96
|
+
name += ':';
|
97
|
+
if (options.ca)
|
98
|
+
name += options.ca;
|
99
|
+
|
100
|
+
name += ':';
|
101
|
+
if (options.cert)
|
102
|
+
name += options.cert;
|
103
|
+
|
104
|
+
name += ':';
|
105
|
+
if (options.ciphers)
|
106
|
+
name += options.ciphers;
|
107
|
+
|
108
|
+
name += ':';
|
109
|
+
if (options.key)
|
110
|
+
name += options.key;
|
111
|
+
|
112
|
+
name += ':';
|
113
|
+
if (options.pfx)
|
114
|
+
name += options.pfx;
|
115
|
+
|
116
|
+
name += ':';
|
117
|
+
if (!util.isUndefined(options.rejectUnauthorized))
|
118
|
+
name += options.rejectUnauthorized;
|
119
|
+
|
120
|
+
return name;
|
121
|
+
};
|
122
|
+
|
123
|
+
var globalAgent = new Agent();
|
124
|
+
|
125
|
+
exports.globalAgent = globalAgent;
|
126
|
+
exports.Agent = Agent;
|
127
|
+
|
128
|
+
exports.request = function(options, cb) {
|
129
|
+
return globalAgent.request(options, cb);
|
130
|
+
};
|
131
|
+
|
132
|
+
exports.get = function(options, cb) {
|
133
|
+
return globalAgent.get(options, cb);
|
134
|
+
};
|
@@ -0,0 +1,529 @@
|
|
1
|
+
// Copyright Joyent, Inc. and other Node contributors.
|
2
|
+
//
|
3
|
+
// Permission is hereby granted, free of charge, to any person obtaining a
|
4
|
+
// copy of this software and associated documentation files (the
|
5
|
+
// "Software"), to deal in the Software without restriction, including
|
6
|
+
// without limitation the rights to use, copy, modify, merge, publish,
|
7
|
+
// distribute, sublicense, and/or sell copies of the Software, and to permit
|
8
|
+
// persons to whom the Software is furnished to do so, subject to the
|
9
|
+
// following conditions:
|
10
|
+
//
|
11
|
+
// The above copyright notice and this permission notice shall be included
|
12
|
+
// in all copies or substantial portions of the Software.
|
13
|
+
//
|
14
|
+
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
|
15
|
+
// OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
16
|
+
// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN
|
17
|
+
// NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM,
|
18
|
+
// DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR
|
19
|
+
// OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE
|
20
|
+
// USE OR OTHER DEALINGS IN THE SOFTWARE.
|
21
|
+
|
22
|
+
var NativeModule = require('native_module');
|
23
|
+
var util = NativeModule.require('util');
|
24
|
+
var runInThisContext = require('vm').runInThisContext;
|
25
|
+
var runInNewContext = require('vm').runInNewContext;
|
26
|
+
var assert = require('assert').ok;
|
27
|
+
|
28
|
+
|
29
|
+
// If obj.hasOwnProperty has been overridden, then calling
|
30
|
+
// obj.hasOwnProperty(prop) will break.
|
31
|
+
// See: https://github.com/joyent/node/issues/1707
|
32
|
+
function hasOwnProperty(obj, prop) {
|
33
|
+
return Object.prototype.hasOwnProperty.call(obj, prop);
|
34
|
+
}
|
35
|
+
|
36
|
+
|
37
|
+
function Module(id, parent) {
|
38
|
+
this.id = id;
|
39
|
+
this.exports = {};
|
40
|
+
this.parent = parent;
|
41
|
+
if (parent && parent.children) {
|
42
|
+
parent.children.push(this);
|
43
|
+
}
|
44
|
+
|
45
|
+
this.filename = null;
|
46
|
+
this.loaded = false;
|
47
|
+
this.children = [];
|
48
|
+
}
|
49
|
+
module.exports = Module;
|
50
|
+
|
51
|
+
// Set the environ variable NODE_MODULE_CONTEXTS=1 to make node load all
|
52
|
+
// modules in their own context.
|
53
|
+
Module._contextLoad = (+process.env['NODE_MODULE_CONTEXTS'] > 0);
|
54
|
+
Module._cache = {};
|
55
|
+
Module._pathCache = {};
|
56
|
+
Module._extensions = {};
|
57
|
+
var modulePaths = [];
|
58
|
+
Module.globalPaths = [];
|
59
|
+
|
60
|
+
Module.wrapper = NativeModule.wrapper;
|
61
|
+
Module.wrap = NativeModule.wrap;
|
62
|
+
|
63
|
+
var path = NativeModule.require('path');
|
64
|
+
|
65
|
+
Module._debug = util.debuglog('module');
|
66
|
+
|
67
|
+
|
68
|
+
// We use this alias for the preprocessor that filters it out
|
69
|
+
var debug = Module._debug;
|
70
|
+
|
71
|
+
|
72
|
+
// given a module name, and a list of paths to test, returns the first
|
73
|
+
// matching file in the following precedence.
|
74
|
+
//
|
75
|
+
// require("a.<ext>")
|
76
|
+
// -> a.<ext>
|
77
|
+
//
|
78
|
+
// require("a")
|
79
|
+
// -> a
|
80
|
+
// -> a.<ext>
|
81
|
+
// -> a/index.<ext>
|
82
|
+
|
83
|
+
function statPath(path) {
|
84
|
+
var fs = NativeModule.require('fs');
|
85
|
+
try {
|
86
|
+
return fs.statSync(path);
|
87
|
+
} catch (ex) {}
|
88
|
+
return false;
|
89
|
+
}
|
90
|
+
|
91
|
+
// check if the directory is a package.json dir
|
92
|
+
var packageMainCache = {};
|
93
|
+
|
94
|
+
function readPackage(requestPath) {
|
95
|
+
if (hasOwnProperty(packageMainCache, requestPath)) {
|
96
|
+
return packageMainCache[requestPath];
|
97
|
+
}
|
98
|
+
|
99
|
+
var fs = NativeModule.require('fs');
|
100
|
+
try {
|
101
|
+
var jsonPath = path.resolve(requestPath, 'package.json');
|
102
|
+
var json = fs.readFileSync(jsonPath, 'utf8');
|
103
|
+
} catch (e) {
|
104
|
+
return false;
|
105
|
+
}
|
106
|
+
|
107
|
+
try {
|
108
|
+
var pkg = packageMainCache[requestPath] = JSON.parse(json).main;
|
109
|
+
} catch (e) {
|
110
|
+
e.path = jsonPath;
|
111
|
+
e.message = 'Error parsing ' + jsonPath + ': ' + e.message;
|
112
|
+
throw e;
|
113
|
+
}
|
114
|
+
return pkg;
|
115
|
+
}
|
116
|
+
|
117
|
+
function tryPackage(requestPath, exts) {
|
118
|
+
var pkg = readPackage(requestPath);
|
119
|
+
|
120
|
+
if (!pkg) return false;
|
121
|
+
|
122
|
+
var filename = path.resolve(requestPath, pkg);
|
123
|
+
return tryFile(filename) || tryExtensions(filename, exts) ||
|
124
|
+
tryExtensions(path.resolve(filename, 'index'), exts);
|
125
|
+
}
|
126
|
+
|
127
|
+
// In order to minimize unnecessary lstat() calls,
|
128
|
+
// this cache is a list of known-real paths.
|
129
|
+
// Set to an empty object to reset.
|
130
|
+
Module._realpathCache = {};
|
131
|
+
|
132
|
+
// check if the file exists and is not a directory
|
133
|
+
function tryFile(requestPath) {
|
134
|
+
var fs = NativeModule.require('fs');
|
135
|
+
var stats = statPath(requestPath);
|
136
|
+
if (stats && !stats.isDirectory()) {
|
137
|
+
return fs.realpathSync(requestPath, Module._realpathCache);
|
138
|
+
}
|
139
|
+
return false;
|
140
|
+
}
|
141
|
+
|
142
|
+
// given a path check a the file exists with any of the set extensions
|
143
|
+
function tryExtensions(p, exts) {
|
144
|
+
for (var i = 0, EL = exts.length; i < EL; i++) {
|
145
|
+
var filename = tryFile(p + exts[i]);
|
146
|
+
|
147
|
+
if (filename) {
|
148
|
+
return filename;
|
149
|
+
}
|
150
|
+
}
|
151
|
+
return false;
|
152
|
+
}
|
153
|
+
|
154
|
+
|
155
|
+
Module._findPath = function(request, paths) {
|
156
|
+
var exts = Object.keys(Module._extensions);
|
157
|
+
|
158
|
+
if (request.charAt(0) === '/') {
|
159
|
+
paths = [''];
|
160
|
+
}
|
161
|
+
|
162
|
+
var trailingSlash = (request.slice(-1) === '/');
|
163
|
+
|
164
|
+
var cacheKey = JSON.stringify({request: request, paths: paths});
|
165
|
+
if (Module._pathCache[cacheKey]) {
|
166
|
+
return Module._pathCache[cacheKey];
|
167
|
+
}
|
168
|
+
|
169
|
+
// For each path
|
170
|
+
for (var i = 0, PL = paths.length; i < PL; i++) {
|
171
|
+
var basePath = path.resolve(paths[i], request);
|
172
|
+
var filename;
|
173
|
+
|
174
|
+
if (!trailingSlash) {
|
175
|
+
// try to join the request to the path
|
176
|
+
filename = tryFile(basePath);
|
177
|
+
|
178
|
+
if (!filename && !trailingSlash) {
|
179
|
+
// try it with each of the extensions
|
180
|
+
filename = tryExtensions(basePath, exts);
|
181
|
+
}
|
182
|
+
}
|
183
|
+
|
184
|
+
if (!filename) {
|
185
|
+
filename = tryPackage(basePath, exts);
|
186
|
+
}
|
187
|
+
|
188
|
+
if (!filename) {
|
189
|
+
// try it with each of the extensions at "index"
|
190
|
+
filename = tryExtensions(path.resolve(basePath, 'index'), exts);
|
191
|
+
}
|
192
|
+
|
193
|
+
if (filename) {
|
194
|
+
Module._pathCache[cacheKey] = filename;
|
195
|
+
return filename;
|
196
|
+
}
|
197
|
+
}
|
198
|
+
return false;
|
199
|
+
};
|
200
|
+
|
201
|
+
// 'from' is the __dirname of the module.
|
202
|
+
Module._nodeModulePaths = function(from) {
|
203
|
+
// guarantee that 'from' is absolute.
|
204
|
+
from = path.resolve(from);
|
205
|
+
|
206
|
+
// note: this approach *only* works when the path is guaranteed
|
207
|
+
// to be absolute. Doing a fully-edge-case-correct path.split
|
208
|
+
// that works on both Windows and Posix is non-trivial.
|
209
|
+
var splitRe = process.platform === 'win32' ? /[\/\\]/ : /\//;
|
210
|
+
var paths = [];
|
211
|
+
var parts = from.split(splitRe);
|
212
|
+
|
213
|
+
for (var tip = parts.length - 1; tip >= 0; tip--) {
|
214
|
+
// don't search in .../node_modules/node_modules
|
215
|
+
if (parts[tip] === 'node_modules') continue;
|
216
|
+
var dir = parts.slice(0, tip + 1).concat('node_modules').join(path.sep);
|
217
|
+
paths.push(dir);
|
218
|
+
}
|
219
|
+
|
220
|
+
return paths;
|
221
|
+
};
|
222
|
+
|
223
|
+
|
224
|
+
Module._resolveLookupPaths = function(request, parent) {
|
225
|
+
if (NativeModule.exists(request)) {
|
226
|
+
return [request, []];
|
227
|
+
}
|
228
|
+
|
229
|
+
var start = request.substring(0, 2);
|
230
|
+
if (start !== './' && start !== '..') {
|
231
|
+
var paths = modulePaths;
|
232
|
+
if (parent) {
|
233
|
+
if (!parent.paths) parent.paths = [];
|
234
|
+
paths = parent.paths.concat(paths);
|
235
|
+
}
|
236
|
+
return [request, paths];
|
237
|
+
}
|
238
|
+
|
239
|
+
// with --eval, parent.id is not set and parent.filename is null
|
240
|
+
if (!parent || !parent.id || !parent.filename) {
|
241
|
+
// make require('./path/to/foo') work - normally the path is taken
|
242
|
+
// from realpath(__filename) but with eval there is no filename
|
243
|
+
var mainPaths = ['.'].concat(modulePaths);
|
244
|
+
mainPaths = Module._nodeModulePaths('.').concat(mainPaths);
|
245
|
+
return [request, mainPaths];
|
246
|
+
}
|
247
|
+
|
248
|
+
// Is the parent an index module?
|
249
|
+
// We can assume the parent has a valid extension,
|
250
|
+
// as it already has been accepted as a module.
|
251
|
+
var isIndex = /^index\.\w+?$/.test(path.basename(parent.filename));
|
252
|
+
var parentIdPath = isIndex ? parent.id : path.dirname(parent.id);
|
253
|
+
var id = path.resolve(parentIdPath, request);
|
254
|
+
|
255
|
+
// make sure require('./path') and require('path') get distinct ids, even
|
256
|
+
// when called from the toplevel js file
|
257
|
+
if (parentIdPath === '.' && id.indexOf('/') === -1) {
|
258
|
+
id = './' + id;
|
259
|
+
}
|
260
|
+
|
261
|
+
debug('RELATIVE: requested:' + request +
|
262
|
+
' set ID to: ' + id + ' from ' + parent.id);
|
263
|
+
|
264
|
+
return [id, [path.dirname(parent.filename)]];
|
265
|
+
};
|
266
|
+
|
267
|
+
|
268
|
+
Module._load = function(request, parent, isMain) {
|
269
|
+
if (parent) {
|
270
|
+
debug('Module._load REQUEST ' + (request) + ' parent: ' + parent.id);
|
271
|
+
}
|
272
|
+
|
273
|
+
var filename = Module._resolveFilename(request, parent);
|
274
|
+
|
275
|
+
var cachedModule = Module._cache[filename];
|
276
|
+
if (cachedModule) {
|
277
|
+
return cachedModule.exports;
|
278
|
+
}
|
279
|
+
|
280
|
+
if (NativeModule.exists(filename)) {
|
281
|
+
// REPL is a special case, because it needs the real require.
|
282
|
+
if (filename == 'repl') {
|
283
|
+
var replModule = new Module('repl');
|
284
|
+
replModule._compile(NativeModule.getSource('repl'), 'repl.js');
|
285
|
+
NativeModule._cache.repl = replModule;
|
286
|
+
return replModule.exports;
|
287
|
+
}
|
288
|
+
|
289
|
+
debug('load native module ' + request);
|
290
|
+
return NativeModule.require(filename);
|
291
|
+
}
|
292
|
+
|
293
|
+
var module = new Module(filename, parent);
|
294
|
+
|
295
|
+
if (isMain) {
|
296
|
+
process.mainModule = module;
|
297
|
+
module.id = '.';
|
298
|
+
}
|
299
|
+
|
300
|
+
Module._cache[filename] = module;
|
301
|
+
|
302
|
+
var hadException = true;
|
303
|
+
|
304
|
+
try {
|
305
|
+
module.load(filename);
|
306
|
+
hadException = false;
|
307
|
+
} finally {
|
308
|
+
if (hadException) {
|
309
|
+
delete Module._cache[filename];
|
310
|
+
}
|
311
|
+
}
|
312
|
+
|
313
|
+
return module.exports;
|
314
|
+
};
|
315
|
+
|
316
|
+
Module._resolveFilename = function(request, parent) {
|
317
|
+
if (NativeModule.exists(request)) {
|
318
|
+
return request;
|
319
|
+
}
|
320
|
+
|
321
|
+
var resolvedModule = Module._resolveLookupPaths(request, parent);
|
322
|
+
var id = resolvedModule[0];
|
323
|
+
var paths = resolvedModule[1];
|
324
|
+
|
325
|
+
// look up the filename first, since that's the cache key.
|
326
|
+
debug('looking for ' + JSON.stringify(id) +
|
327
|
+
' in ' + JSON.stringify(paths));
|
328
|
+
|
329
|
+
var filename = Module._findPath(request, paths);
|
330
|
+
if (!filename) {
|
331
|
+
var err = new Error("Cannot find module '" + request + "'");
|
332
|
+
err.code = 'MODULE_NOT_FOUND';
|
333
|
+
throw err;
|
334
|
+
}
|
335
|
+
return filename;
|
336
|
+
};
|
337
|
+
|
338
|
+
|
339
|
+
Module.prototype.load = function(filename) {
|
340
|
+
debug('load ' + JSON.stringify(filename) +
|
341
|
+
' for module ' + JSON.stringify(this.id));
|
342
|
+
|
343
|
+
assert(!this.loaded);
|
344
|
+
this.filename = filename;
|
345
|
+
this.paths = Module._nodeModulePaths(path.dirname(filename));
|
346
|
+
|
347
|
+
var extension = path.extname(filename) || '.js';
|
348
|
+
if (!Module._extensions[extension]) extension = '.js';
|
349
|
+
Module._extensions[extension](this, filename);
|
350
|
+
this.loaded = true;
|
351
|
+
};
|
352
|
+
|
353
|
+
|
354
|
+
Module.prototype.require = function(path) {
|
355
|
+
assert(util.isString(path), 'path must be a string');
|
356
|
+
assert(path, 'missing path');
|
357
|
+
return Module._load(path, this);
|
358
|
+
};
|
359
|
+
|
360
|
+
|
361
|
+
// Resolved path to process.argv[1] will be lazily placed here
|
362
|
+
// (needed for setting breakpoint when called with --debug-brk)
|
363
|
+
var resolvedArgv;
|
364
|
+
|
365
|
+
|
366
|
+
// Returns exception if any
|
367
|
+
Module.prototype._compile = function(content, filename) {
|
368
|
+
var self = this;
|
369
|
+
// remove shebang
|
370
|
+
content = content.replace(/^\#\!.*/, '');
|
371
|
+
|
372
|
+
function require(path) {
|
373
|
+
return self.require(path);
|
374
|
+
}
|
375
|
+
|
376
|
+
require.resolve = function(request) {
|
377
|
+
return Module._resolveFilename(request, self);
|
378
|
+
};
|
379
|
+
|
380
|
+
Object.defineProperty(require, 'paths', { get: function() {
|
381
|
+
throw new Error('require.paths is removed. Use ' +
|
382
|
+
'node_modules folders, or the NODE_PATH ' +
|
383
|
+
'environment variable instead.');
|
384
|
+
}});
|
385
|
+
|
386
|
+
require.main = process.mainModule;
|
387
|
+
|
388
|
+
// Enable support to add extra extension types
|
389
|
+
require.extensions = Module._extensions;
|
390
|
+
require.registerExtension = function() {
|
391
|
+
throw new Error('require.registerExtension() removed. Use ' +
|
392
|
+
'require.extensions instead.');
|
393
|
+
};
|
394
|
+
|
395
|
+
require.cache = Module._cache;
|
396
|
+
|
397
|
+
var dirname = path.dirname(filename);
|
398
|
+
|
399
|
+
if (Module._contextLoad) {
|
400
|
+
if (self.id !== '.') {
|
401
|
+
debug('load submodule');
|
402
|
+
// not root module
|
403
|
+
var sandbox = {};
|
404
|
+
for (var k in global) {
|
405
|
+
sandbox[k] = global[k];
|
406
|
+
}
|
407
|
+
sandbox.require = require;
|
408
|
+
sandbox.exports = self.exports;
|
409
|
+
sandbox.__filename = filename;
|
410
|
+
sandbox.__dirname = dirname;
|
411
|
+
sandbox.module = self;
|
412
|
+
sandbox.global = sandbox;
|
413
|
+
sandbox.root = root;
|
414
|
+
|
415
|
+
return runInNewContext(content, sandbox, { filename: filename });
|
416
|
+
}
|
417
|
+
|
418
|
+
debug('load root module');
|
419
|
+
// root module
|
420
|
+
global.require = require;
|
421
|
+
global.exports = self.exports;
|
422
|
+
global.__filename = filename;
|
423
|
+
global.__dirname = dirname;
|
424
|
+
global.module = self;
|
425
|
+
|
426
|
+
return runInThisContext(content, { filename: filename });
|
427
|
+
}
|
428
|
+
|
429
|
+
// create wrapper function
|
430
|
+
var wrapper = Module.wrap(content);
|
431
|
+
|
432
|
+
var compiledWrapper = runInThisContext(wrapper, { filename: filename });
|
433
|
+
if (global.v8debug) {
|
434
|
+
if (!resolvedArgv) {
|
435
|
+
// we enter the repl if we're not given a filename argument.
|
436
|
+
if (process.argv[1]) {
|
437
|
+
resolvedArgv = Module._resolveFilename(process.argv[1], null);
|
438
|
+
} else {
|
439
|
+
resolvedArgv = 'repl';
|
440
|
+
}
|
441
|
+
}
|
442
|
+
|
443
|
+
// Set breakpoint on module start
|
444
|
+
if (filename === resolvedArgv) {
|
445
|
+
global.v8debug.Debug.setBreakPoint(compiledWrapper, 0, 0);
|
446
|
+
}
|
447
|
+
}
|
448
|
+
var args = [self.exports, require, self, filename, dirname];
|
449
|
+
return compiledWrapper.apply(self.exports, args);
|
450
|
+
};
|
451
|
+
|
452
|
+
|
453
|
+
function stripBOM(content) {
|
454
|
+
// Remove byte order marker. This catches EF BB BF (the UTF-8 BOM)
|
455
|
+
// because the buffer-to-string conversion in `fs.readFileSync()`
|
456
|
+
// translates it to FEFF, the UTF-16 BOM.
|
457
|
+
if (content.charCodeAt(0) === 0xFEFF) {
|
458
|
+
content = content.slice(1);
|
459
|
+
}
|
460
|
+
return content;
|
461
|
+
}
|
462
|
+
|
463
|
+
|
464
|
+
// Native extension for .js
|
465
|
+
Module._extensions['.js'] = function(module, filename) {
|
466
|
+
var content = NativeModule.require('fs').readFileSync(filename, 'utf8');
|
467
|
+
module._compile(stripBOM(content), filename);
|
468
|
+
};
|
469
|
+
|
470
|
+
|
471
|
+
// Native extension for .json
|
472
|
+
Module._extensions['.json'] = function(module, filename) {
|
473
|
+
var content = NativeModule.require('fs').readFileSync(filename, 'utf8');
|
474
|
+
try {
|
475
|
+
module.exports = JSON.parse(stripBOM(content));
|
476
|
+
} catch (err) {
|
477
|
+
err.message = filename + ': ' + err.message;
|
478
|
+
throw err;
|
479
|
+
}
|
480
|
+
};
|
481
|
+
|
482
|
+
|
483
|
+
//Native extension for .node
|
484
|
+
Module._extensions['.node'] = process.dlopen;
|
485
|
+
|
486
|
+
|
487
|
+
// bootstrap main module.
|
488
|
+
Module.runMain = function() {
|
489
|
+
// Load the main module--the command line argument.
|
490
|
+
Module._load(process.argv[1], null, true);
|
491
|
+
// Handle any nextTicks added in the first tick of the program
|
492
|
+
process._tickCallback();
|
493
|
+
};
|
494
|
+
|
495
|
+
Module._initPaths = function() {
|
496
|
+
var isWindows = process.platform === 'win32';
|
497
|
+
|
498
|
+
if (isWindows) {
|
499
|
+
var homeDir = process.env.USERPROFILE;
|
500
|
+
} else {
|
501
|
+
var homeDir = process.env.HOME;
|
502
|
+
}
|
503
|
+
|
504
|
+
var paths = [path.resolve(process.execPath, '..', '..', 'lib', 'node')];
|
505
|
+
|
506
|
+
if (homeDir) {
|
507
|
+
paths.unshift(path.resolve(homeDir, '.node_libraries'));
|
508
|
+
paths.unshift(path.resolve(homeDir, '.node_modules'));
|
509
|
+
}
|
510
|
+
|
511
|
+
if (process.env['NODE_PATH']) {
|
512
|
+
paths = process.env['NODE_PATH'].split(path.delimiter).concat(paths);
|
513
|
+
}
|
514
|
+
|
515
|
+
modulePaths = paths;
|
516
|
+
|
517
|
+
// clone as a read-only copy, for introspection.
|
518
|
+
Module.globalPaths = modulePaths.slice(0);
|
519
|
+
};
|
520
|
+
|
521
|
+
// bootstrap repl
|
522
|
+
Module.requireRepl = function() {
|
523
|
+
return Module._load('repl', '.');
|
524
|
+
};
|
525
|
+
|
526
|
+
Module._initPaths();
|
527
|
+
|
528
|
+
// backwards compatibility
|
529
|
+
Module.Module = Module;
|