You need to sign in or sign up before continuing.
Commit fdc273f4 by Иван Кубота

require. get path of file

parent 149574ef
...@@ -11,13 +11,13 @@ module.exports = (function () { ...@@ -11,13 +11,13 @@ module.exports = (function () {
var slice = [].slice; var slice = [].slice;
var waiting = {}; var waiting = {};
var deps = {}; var deps = {};
var Waiter = function(args, fn){ var Waiter = function(args, fn, path){
var argsPos = this.argsPos = {}, i, _i; var argsPos = this.argsPos = {}, i, _i;
this.args = args; this.args = args;
this.deps = args.slice(); this.deps = args.slice();
this.count = args.length; this.count = args.length;
this.fn = fn; this.fn = fn;
this.path = path;
for( i = 0, _i = args.length; i < _i; i++){ for( i = 0, _i = args.length; i < _i; i++){
argsPos[args[i]] = i; argsPos[args[i]] = i;
} }
...@@ -54,13 +54,23 @@ module.exports = (function () { ...@@ -54,13 +54,23 @@ module.exports = (function () {
this.sub(); this.sub();
} }
}; };
var QRequire = function(){ var QRequire = function(){
var args = slice.call(arguments), var args = slice.call(arguments),
fn = args.pop(), fn = args.pop();
waiter = new Waiter(args, fn), /*compiling tool*/
i, _i, arg; 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++){ for( i = 0, _i = args.length; i < _i; i++){
arg = args[i]; arg = args[i];
if(!(arg in waiting)){ if(!(arg in waiting)){
...@@ -72,6 +82,7 @@ module.exports = (function () { ...@@ -72,6 +82,7 @@ module.exports = (function () {
waiting[arg].push(waiter); waiting[arg].push(waiter);
if(arg.indexOf('.')===-1){ if(arg.indexOf('.')===-1){
QRequire.loaded(arg, require(arg)); QRequire.loaded(arg, require(arg));
(waiter.paths || (waiter.paths = [])).push( require.cache[require.resolve(arg)])
} }
} }
} }
...@@ -79,7 +90,7 @@ module.exports = (function () { ...@@ -79,7 +90,7 @@ module.exports = (function () {
//waiter.may(); //waiter.may();
}; };
QRequire.loaded = function(name, obj){ QRequire.loaded = function(name, obj){
console.log(name, typeof obj) //console.log(name, typeof obj)
var waiter = waiting[name]; var waiter = waiting[name];
if(waiter instanceof Array){ if(waiter instanceof Array){
for( var i = 0, _i = waiter.length; i < _i; i++ ){ for( var i = 0, _i = waiter.length; i < _i; i++ ){
...@@ -92,5 +103,8 @@ module.exports = (function () { ...@@ -92,5 +103,8 @@ module.exports = (function () {
QRequire.deps = function(name){ QRequire.deps = function(name){
return (deps[name] || {}).deps; return (deps[name] || {}).deps;
}; };
QRequire.path = function(name){
return (deps[name] || {}).path;
};
return QRequire; return QRequire;
})(); })();
\ No newline at end of file
...@@ -28,6 +28,8 @@ QRequire('quokka-script', 'quokka-core', 'Core.TypeTable', 'fs', function(qs, QC ...@@ -28,6 +28,8 @@ QRequire('quokka-script', 'quokka-core', 'Core.TypeTable', 'fs', function(qs, QC
} }
fullName = getName(main, all); fullName = getName(main, all);
//var cfg = TypeTable.search(fullName); //var cfg = TypeTable.search(fullName);
/*if (cfg.length) { /*if (cfg.length) {
cfg = cfg[0]; cfg = cfg[0];
...@@ -35,11 +37,20 @@ QRequire('quokka-script', 'quokka-core', 'Core.TypeTable', 'fs', function(qs, QC ...@@ -35,11 +37,20 @@ QRequire('quokka-script', 'quokka-core', 'Core.TypeTable', 'fs', function(qs, QC
} else } else
;//throw new Error('No source for '+fullName) ;//throw new Error('No source for '+fullName)
*/ */
var dep = QRequire.deps(fullName); var jsDeps = QRequire.deps(fullName);
if(!(fullName in store.names)) { if(!(fullName in store.names)) {
store.names[fullName] = dep; store.names[fullName] = jsDeps;
store.list.push({name: fullName, deps: dep}); 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] = { /*cache[fullName] = {
require: deps ? Object.keys(deps).map(function (name) { require: deps ? Object.keys(deps).map(function (name) {
...@@ -56,7 +67,11 @@ QRequire('quokka-script', 'quokka-core', 'Core.TypeTable', 'fs', function(qs, QC ...@@ -56,7 +67,11 @@ QRequire('quokka-script', 'quokka-core', 'Core.TypeTable', 'fs', function(qs, QC
newWay: true newWay: true
}, function (result) { }, function (result) {
var mainObj = result.main; 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 cache
}); });
......
...@@ -5,5 +5,6 @@ ...@@ -5,5 +5,6 @@
def Page main def Page main
Slider s1: 10 Slider s1: 10
from:22
div: ee div: ee
td: de 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