kopia lustrzana https://github.com/c9/core
add basic support for vfs! loader, without cache
rodzic
1232261813
commit
e9ac1165af
|
@ -386,6 +386,15 @@ function rewriteDefines(sources, opts){
|
||||||
+ source
|
+ source
|
||||||
+ '");';
|
+ '");';
|
||||||
}
|
}
|
||||||
|
else if (pkg.id.indexOf("vfs!") > -1) {
|
||||||
|
pkg.source = 'define("' + pkg.id + '",[],' + function(require, exports,module) {
|
||||||
|
var path = module.id.slice(4);
|
||||||
|
return {
|
||||||
|
srcUrl: requirejs.MODULE_LOAD_URL + "/~node/" + path,
|
||||||
|
path: path,
|
||||||
|
};
|
||||||
|
} + ');';
|
||||||
|
}
|
||||||
else {
|
else {
|
||||||
var deps = [];
|
var deps = [];
|
||||||
if (keepDeps) {
|
if (keepDeps) {
|
||||||
|
|
|
@ -1,6 +1,6 @@
|
||||||
(function() {
|
(function() {
|
||||||
|
|
||||||
var MODULE_LOAD_URL = "/load/module";
|
var MODULE_LOAD_URL = "/static/build/modules";
|
||||||
|
|
||||||
var global = (function() { return this; })();
|
var global = (function() { return this; })();
|
||||||
if (!global && typeof window != "undefined") global = window; // can happen in strict mode
|
if (!global && typeof window != "undefined") global = window; // can happen in strict mode
|
||||||
|
@ -632,6 +632,17 @@ function definePlugin(plugin, p) {
|
||||||
}
|
}
|
||||||
|
|
||||||
/*** plugins ***/
|
/*** plugins ***/
|
||||||
|
require["vfs!"] = function(module, callback) {
|
||||||
|
var url = require.MODULE_LOAD_URL + "/~node/" + module;
|
||||||
|
if (define.fetchedUrls[url] & 3)
|
||||||
|
return false;
|
||||||
|
define.fetchedUrls[url] |= 3;
|
||||||
|
define("vfs!" + module, [], {
|
||||||
|
srcUrl: url,
|
||||||
|
path: module
|
||||||
|
});
|
||||||
|
callback();
|
||||||
|
};
|
||||||
require["text!"] = function(module, callback) {
|
require["text!"] = function(module, callback) {
|
||||||
var url = require.toUrl(module);
|
var url = require.toUrl(module);
|
||||||
if (define.fetchedUrls[url] & 2)
|
if (define.fetchedUrls[url] & 2)
|
||||||
|
|
|
@ -75,11 +75,15 @@ module.exports = function(mains, opts) {
|
||||||
function idToPathNode(mod) {
|
function idToPathNode(mod) {
|
||||||
var packagePath = mod.id;
|
var packagePath = mod.id;
|
||||||
var filepath = mod.parent && mod.parent.file || root;
|
var filepath = mod.parent && mod.parent.file || root;
|
||||||
return Module._resolveFilename(packagePath, {
|
try {
|
||||||
paths: Module._nodeModulePaths(filepath),
|
return Module._resolveFilename(packagePath, {
|
||||||
filename: filepath,
|
paths: Module._nodeModulePaths(filepath),
|
||||||
id: filepath,
|
filename: filepath,
|
||||||
});
|
id: filepath,
|
||||||
|
});
|
||||||
|
} catch (e) {
|
||||||
|
return packagePath;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
function readModule(mod, cb) {
|
function readModule(mod, cb) {
|
||||||
|
@ -448,7 +452,7 @@ function debugSrc(module) {
|
||||||
|
|
||||||
function quote(str) {
|
function quote(str) {
|
||||||
return "'"
|
return "'"
|
||||||
+ str.replace(/[\\']/g, "\\$&").replace(/\n/g, "\\n")
|
+ str.replace(/[\\']/g, "\\$&").replace(/\n/g, "\\n\\\n")
|
||||||
+ "'";
|
+ "'";
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -45,6 +45,7 @@ return function(_request) {
|
||||||
if ($reqHeaders)
|
if ($reqHeaders)
|
||||||
message += ($reqHeaders == headers) + $reqHeaders["x-request-metadata"];
|
message += ($reqHeaders == headers) + $reqHeaders["x-request-metadata"];
|
||||||
console.error($reqHeaders, headers, message);
|
console.error($reqHeaders, headers, message);
|
||||||
|
// setTimeout(function() { throw new Error(message); });
|
||||||
return callback(err, data.substr(0, ln - ml), res);
|
return callback(err, data.substr(0, ln - ml), res);
|
||||||
}
|
}
|
||||||
callback(err, data.substr(0, ln - ml), ml && data.substr(-1 * ml) || "", res);
|
callback(err, data.substr(0, ln - ml), ml && data.substr(-1 * ml) || "", res);
|
||||||
|
|
|
@ -1,39 +1,67 @@
|
||||||
define(function(require, exports, module) {
|
define(function(require, exports, module) {
|
||||||
var EventEmitter = require("ace/lib/event_emitter").EventEmitter;
|
var debugProxy = require("vfs!./chrome-debug-proxy.js");
|
||||||
|
|
||||||
function extendVFS(vfs, options, register) {
|
var code = "module.exports = " + function(vfs, options, register) {
|
||||||
var extPath = "{EXTPATH}";
|
var extPath = "{EXTPATH}";
|
||||||
var detached = true;
|
var detached = true;
|
||||||
var force = false;
|
var force = false;
|
||||||
var nodeRequire = require;
|
var nodeRequire = require;
|
||||||
var p = nodeRequire("child_process").spawn(process.execPath, [extPath, force], {
|
var fs = nodeRequire("fs");
|
||||||
stdio: detached ? "ignore" : undefined,
|
check();
|
||||||
detached: detached
|
|
||||||
});
|
function check() {
|
||||||
if (detached) {
|
fs.exists(extPath, function(exists) {
|
||||||
p.unref();
|
if (!exists)
|
||||||
} else {
|
return register(null, { launch: launch });
|
||||||
p.stdout.pipe(process.stderr);
|
launch(register);
|
||||||
p.stderr.pipe(process.stderr);
|
});
|
||||||
}
|
}
|
||||||
register(null, {});
|
|
||||||
}
|
function launch(callback) {
|
||||||
|
var p = nodeRequire("child_process").spawn(process.execPath, [extPath, force], {
|
||||||
|
stdio: detached ? "ignore" : undefined,
|
||||||
|
detached: detached
|
||||||
|
});
|
||||||
|
if (detached) {
|
||||||
|
p.unref();
|
||||||
|
} else {
|
||||||
|
p.stdout.pipe(process.stderr);
|
||||||
|
p.stderr.pipe(process.stderr);
|
||||||
|
}
|
||||||
|
callback(null, {});
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
exports.connect = function(imports, options, callback) {
|
exports.connect = function(imports, options, callback) {
|
||||||
|
var util = imports.util;
|
||||||
var vfs = imports.vfs;
|
var vfs = imports.vfs;
|
||||||
var c9 = imports.c9;
|
var c9 = imports.c9;
|
||||||
var exe = c9.sourceDir + "/plugins/c9.ide.run.debug/debuggers/chrome/chrome-debug-proxy.js";
|
var fs = imports.fs;
|
||||||
|
var extPath = c9.standalone && !/packed=1/.test(c9.location)
|
||||||
|
? c9.sourceDir + "/" + debugProxy.path
|
||||||
|
: c9.home + "/.c9/vfs-cache/chrome-debug-proxy.js";
|
||||||
|
|
||||||
var socketPath = c9.home + "/.c9/chrome.sock";
|
var socketPath = c9.home + "/.c9/chrome.sock";
|
||||||
if (c9.platform == "win32")
|
if (c9.platform == "win32")
|
||||||
socketPath = "\\\\.\\pipe\\" + socketPath.replace(/\//g, "\\");
|
socketPath = "\\\\.\\pipe\\" + socketPath.replace(/\//g, "\\");
|
||||||
|
|
||||||
vfs.extend("chromeDebugProxyLauncher", {
|
vfs.extend("chromeDebugProxyLauncher", {
|
||||||
code: "module.exports = " + extendVFS.toString().replace("{EXTPATH}", exe),
|
code: code.replace("{EXTPATH}", extPath),
|
||||||
redefine: true
|
redefine: true
|
||||||
}, function(err, remote) {
|
}, function(err, remote) {
|
||||||
if (err) console.log(err);
|
if (err) console.log(err);
|
||||||
tryConnect(30);
|
if (remote && remote.api && remote.api.launch) {
|
||||||
|
require(["text!" + debugProxy.srcUrl], function(code) {
|
||||||
|
fs.writeFile(util.normalizePath(extPath), code, function() {
|
||||||
|
remote.api.launch(function() {
|
||||||
|
tryConnect(30);
|
||||||
|
});
|
||||||
|
});
|
||||||
|
});
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
tryConnect(30);
|
||||||
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
function tryConnect(retries) {
|
function tryConnect(retries) {
|
||||||
|
@ -106,7 +134,7 @@ define(function(require, exports, module) {
|
||||||
}, socket);
|
}, socket);
|
||||||
c9.on("connect", function() {
|
c9.on("connect", function() {
|
||||||
stream && stream.end();
|
stream && stream.end();
|
||||||
connectPort();
|
connectPort(function() {});
|
||||||
}, socket);
|
}, socket);
|
||||||
|
|
||||||
socket.on("unload", function() {
|
socket.on("unload", function() {
|
||||||
|
|
|
@ -14,7 +14,7 @@ node-process1 node-process2 ... debuggers
|
||||||
|
|
||||||
var fs = require("fs");
|
var fs = require("fs");
|
||||||
var net = require("net");
|
var net = require("net");
|
||||||
var WebSocket = require("ws");
|
var WebSocket = require("ws/index");
|
||||||
var MessageReader = require("./MessageReader");
|
var MessageReader = require("./MessageReader");
|
||||||
|
|
||||||
var startT = Date.now();
|
var startT = Date.now();
|
||||||
|
|
|
@ -134,8 +134,6 @@ define(function(require, exports, module) {
|
||||||
ui.insertSkin({
|
ui.insertSkin({
|
||||||
name: "debugger",
|
name: "debugger",
|
||||||
data: require("text!./skin.xml"),
|
data: require("text!./skin.xml"),
|
||||||
"media-path": options.staticPrefix + "/images/",
|
|
||||||
"icon-path": options.staticPrefix + "/icons/"
|
|
||||||
}, plugin);
|
}, plugin);
|
||||||
|
|
||||||
// Create UI elements
|
// Create UI elements
|
||||||
|
|
|
@ -1,5 +1,5 @@
|
||||||
define(function(require, exports, module) {
|
define(function(require, exports, module) {
|
||||||
main.consumes = ["Plugin", "debugger", "util", "c9", "vfs"];
|
main.consumes = ["Plugin", "debugger", "util", "c9", "vfs", "fs"];
|
||||||
main.provides = ["nodedebugger"];
|
main.provides = ["nodedebugger"];
|
||||||
return main;
|
return main;
|
||||||
|
|
||||||
|
@ -39,17 +39,6 @@ define(function(require, exports, module) {
|
||||||
"sources",
|
"sources",
|
||||||
"sourcesCompile"
|
"sourcesCompile"
|
||||||
];
|
];
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
/***** Helper Functions *****/
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
/***** Event Handler *****/
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
/***** Methods *****/
|
/***** Methods *****/
|
||||||
|
|
||||||
|
@ -113,7 +102,8 @@ define(function(require, exports, module) {
|
||||||
v8DebuggerPlugin.unload();
|
v8DebuggerPlugin.unload();
|
||||||
chromeDebuggerPlugin.unload();
|
chromeDebuggerPlugin.unload();
|
||||||
process = attached = dbg = null;
|
process = attached = dbg = null;
|
||||||
|
eventForwarder.unload();
|
||||||
|
eventForwarder = null;
|
||||||
});
|
});
|
||||||
|
|
||||||
/***** Register and define API *****/
|
/***** Register and define API *****/
|
||||||
|
|
|
@ -203,7 +203,14 @@ function main(options, imports, register) {
|
||||||
if (/^(ace\/|plugins\/c9.ide.ace)/.test(module))
|
if (/^(ace\/|plugins\/c9.ide.ace)/.test(module))
|
||||||
return buildAce(module, pathConfig, callback);
|
return buildAce(module, pathConfig, callback);
|
||||||
|
|
||||||
build([], {
|
var compileForNode = false;
|
||||||
|
if (/^~node\//.test(module)) {
|
||||||
|
module = module.substring(6);
|
||||||
|
compileForNode = true;
|
||||||
|
}
|
||||||
|
|
||||||
|
build(compileForNode ? [module] : [], {
|
||||||
|
node: compileForNode,
|
||||||
cache: cache,
|
cache: cache,
|
||||||
pathConfig: pathConfig,
|
pathConfig: pathConfig,
|
||||||
enableBrowser: true,
|
enableBrowser: true,
|
||||||
|
@ -212,11 +219,11 @@ function main(options, imports, register) {
|
||||||
compress: compress,
|
compress: compress,
|
||||||
filter: [],
|
filter: [],
|
||||||
ignore: [],
|
ignore: [],
|
||||||
additional: [{
|
additional: compileForNode && [{
|
||||||
id: module,
|
id: module,
|
||||||
noDeps: true
|
noDeps: true
|
||||||
}],
|
}],
|
||||||
withRequire: false,
|
withRequire: compileForNode,
|
||||||
basepath: pathConfig.root
|
basepath: pathConfig.root
|
||||||
}, callback);
|
}, callback);
|
||||||
}
|
}
|
||||||
|
|
Ładowanie…
Reference in New Issue