add basic support for vfs! loader, without cache

pull/483/head
nightwing 2018-02-06 02:11:42 +04:00
rodzic 1232261813
commit e9ac1165af
9 zmienionych plików z 91 dodań i 43 usunięć

9
node_modules/architect-build/build.js wygenerowano vendored
Wyświetl plik

@ -386,6 +386,15 @@ function rewriteDefines(sources, opts){
+ 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 {
var deps = [];
if (keepDeps) {

Wyświetl plik

@ -1,6 +1,6 @@
(function() {
var MODULE_LOAD_URL = "/load/module";
var MODULE_LOAD_URL = "/static/build/modules";
var global = (function() { return this; })();
if (!global && typeof window != "undefined") global = window; // can happen in strict mode
@ -632,6 +632,17 @@ function definePlugin(plugin, p) {
}
/*** 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) {
var url = require.toUrl(module);
if (define.fetchedUrls[url] & 2)

Wyświetl plik

@ -75,11 +75,15 @@ module.exports = function(mains, opts) {
function idToPathNode(mod) {
var packagePath = mod.id;
var filepath = mod.parent && mod.parent.file || root;
return Module._resolveFilename(packagePath, {
paths: Module._nodeModulePaths(filepath),
filename: filepath,
id: filepath,
});
try {
return Module._resolveFilename(packagePath, {
paths: Module._nodeModulePaths(filepath),
filename: filepath,
id: filepath,
});
} catch (e) {
return packagePath;
}
}
function readModule(mod, cb) {
@ -448,7 +452,7 @@ function debugSrc(module) {
function quote(str) {
return "'"
+ str.replace(/[\\']/g, "\\$&").replace(/\n/g, "\\n")
+ str.replace(/[\\']/g, "\\$&").replace(/\n/g, "\\n\\\n")
+ "'";
}

Wyświetl plik

@ -45,6 +45,7 @@ return function(_request) {
if ($reqHeaders)
message += ($reqHeaders == headers) + $reqHeaders["x-request-metadata"];
console.error($reqHeaders, headers, message);
// setTimeout(function() { throw new Error(message); });
return callback(err, data.substr(0, ln - ml), res);
}
callback(err, data.substr(0, ln - ml), ml && data.substr(-1 * ml) || "", res);

Wyświetl plik

@ -1,39 +1,67 @@
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 detached = true;
var force = false;
var nodeRequire = require;
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);
var fs = nodeRequire("fs");
check();
function check() {
fs.exists(extPath, function(exists) {
if (!exists)
return register(null, { launch: launch });
launch(register);
});
}
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) {
var util = imports.util;
var vfs = imports.vfs;
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";
if (c9.platform == "win32")
socketPath = "\\\\.\\pipe\\" + socketPath.replace(/\//g, "\\");
vfs.extend("chromeDebugProxyLauncher", {
code: "module.exports = " + extendVFS.toString().replace("{EXTPATH}", exe),
code: code.replace("{EXTPATH}", extPath),
redefine: true
}, function(err, remote) {
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) {
@ -106,7 +134,7 @@ define(function(require, exports, module) {
}, socket);
c9.on("connect", function() {
stream && stream.end();
connectPort();
connectPort(function() {});
}, socket);
socket.on("unload", function() {

Wyświetl plik

@ -14,7 +14,7 @@ node-process1 node-process2 ... debuggers
var fs = require("fs");
var net = require("net");
var WebSocket = require("ws");
var WebSocket = require("ws/index");
var MessageReader = require("./MessageReader");
var startT = Date.now();

Wyświetl plik

@ -134,8 +134,6 @@ define(function(require, exports, module) {
ui.insertSkin({
name: "debugger",
data: require("text!./skin.xml"),
"media-path": options.staticPrefix + "/images/",
"icon-path": options.staticPrefix + "/icons/"
}, plugin);
// Create UI elements

Wyświetl plik

@ -1,5 +1,5 @@
define(function(require, exports, module) {
main.consumes = ["Plugin", "debugger", "util", "c9", "vfs"];
main.consumes = ["Plugin", "debugger", "util", "c9", "vfs", "fs"];
main.provides = ["nodedebugger"];
return main;
@ -39,17 +39,6 @@ define(function(require, exports, module) {
"sources",
"sourcesCompile"
];
/***** Helper Functions *****/
/***** Event Handler *****/
/***** Methods *****/
@ -113,7 +102,8 @@ define(function(require, exports, module) {
v8DebuggerPlugin.unload();
chromeDebuggerPlugin.unload();
process = attached = dbg = null;
eventForwarder.unload();
eventForwarder = null;
});
/***** Register and define API *****/

Wyświetl plik

@ -203,7 +203,14 @@ function main(options, imports, register) {
if (/^(ace\/|plugins\/c9.ide.ace)/.test(module))
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,
pathConfig: pathConfig,
enableBrowser: true,
@ -212,11 +219,11 @@ function main(options, imports, register) {
compress: compress,
filter: [],
ignore: [],
additional: [{
additional: compileForNode && [{
id: module,
noDeps: true
}],
withRequire: false,
withRequire: compileForNode,
basepath: pathConfig.root
}, callback);
}