Commit fdc273f4 by Иван Кубота

require. get path of file

parent 149574ef
......@@ -11,13 +11,13 @@ module.exports = (function () {
var slice = [].slice;
var waiting = {};
var deps = {};
var Waiter = function(args, fn){
var Waiter = function(args, fn, path){
var argsPos = this.argsPos = {}, i, _i;
this.args = args;
this.deps = args.slice();
this.count = args.length;
this.fn = fn;
this.path = path;
for( i = 0, _i = args.length; i < _i; i++){
argsPos[args[i]] = i;
}
......@@ -54,13 +54,23 @@ module.exports = (function () {
this.sub();
}
};
var QRequire = function(){
var args = slice.call(arguments),
fn = args.pop(),
fn = args.pop();
waiter = new Waiter(args, fn),
i, _i, arg;
/*compiling tool*/
var tmp = Error.prepareStackTrace;
Error.prepareStackTrace = function (err, stack) { return stack; };
var err = new Error(),
errFile = err.stack[1].getFileName();
Error.prepareStackTrace = tmp;
/* end compiling*/
var waiter = new Waiter(args, fn, errFile),
i, _i, arg;
for( i = 0, _i = args.length; i < _i; i++){
arg = args[i];
if(!(arg in waiting)){
......@@ -72,6 +82,7 @@ module.exports = (function () {
waiting[arg].push(waiter);
if(arg.indexOf('.')===-1){
QRequire.loaded(arg, require(arg));
(waiter.paths || (waiter.paths = [])).push( require.cache[require.resolve(arg)])
}
}
}
......@@ -79,7 +90,7 @@ module.exports = (function () {
//waiter.may();
};
QRequire.loaded = function(name, obj){
console.log(name, typeof obj)
//console.log(name, typeof obj)
var waiter = waiting[name];
if(waiter instanceof Array){
for( var i = 0, _i = waiter.length; i < _i; i++ ){
......@@ -92,5 +103,8 @@ module.exports = (function () {
QRequire.deps = function(name){
return (deps[name] || {}).deps;
};
QRequire.path = function(name){
return (deps[name] || {}).path;
};
return QRequire;
})();
\ No newline at end of file
......@@ -28,6 +28,8 @@ QRequire('quokka-script', 'quokka-core', 'Core.TypeTable', 'fs', function(qs, QC
}
fullName = getName(main, all);
//var cfg = TypeTable.search(fullName);
/*if (cfg.length) {
cfg = cfg[0];
......@@ -35,11 +37,20 @@ QRequire('quokka-script', 'quokka-core', 'Core.TypeTable', 'fs', function(qs, QC
} else
;//throw new Error('No source for '+fullName)
*/
var dep = QRequire.deps(fullName);
var jsDeps = QRequire.deps(fullName);
if(!(fullName in store.names)) {
store.names[fullName] = dep;
store.list.push({name: fullName, deps: dep});
store.names[fullName] = jsDeps;
store.list.push({name: fullName, deps: jsDeps, path: QRequire.path(fullName)});
}
jsDeps && jsDeps.forEach(function (dep) {
if(!(dep in store.names)) {
store.names[dep] = true;
store.list.push({name: dep, path: QRequire.path(dep)});
}
});
/*cache[fullName] = {
require: deps ? Object.keys(deps).map(function (name) {
......@@ -56,7 +67,11 @@ QRequire('quokka-script', 'quokka-core', 'Core.TypeTable', 'fs', function(qs, QC
newWay: true
}, function (result) {
var mainObj = result.main;
var deps = startDepsResolve(mainObj, result.world);
var deps = startDepsResolve(mainObj, result.world).list.filter(function (dep) {
return dep.path
});
console.log(deps)
require
cache
});
......
......@@ -5,5 +5,6 @@
def Page main
Slider s1: 10
from:22
div: ee
td: de
\ No newline at end of file
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment