diff --git a/app.js b/app.js index f326fb89..e7c2c92b 100644 --- a/app.js +++ b/app.js @@ -47,12 +47,12 @@ function init(mod) { let depcache = {}; - function find_deps(path, seen = []) { + function find_deps(path) { let cached = depcache[path]; if (cached) { return cached; } - let deps = []; + let deps = [ "main/gapp" ]; let lines = fs.readFileSync(`${dir}/src/${path}.js`) .toString() .split('\n'); @@ -60,21 +60,17 @@ function init(mod) { let dpos = line.indexOf('// dep:'); if (dpos >= 0) { let dep = line.substring(dpos+7).trim().replace('.','/'); - if (seen.indexOf(dep) >= 0) { - dbug.warn(`circular ${dep} from ${path}`); - continue; - } if (deps.indexOf(dep) < 0) { deps.push(dep); } - let deep = find_deps(dep, seen); - if (deep) { - // deeper dependencies go first - deps = [...deep, ...deps]; - } + let deep = find_deps(dep); + deps = deps.filter(p => deep.indexOf(p) < 0); + // deeper dependencies go first + deps = [...deep, ...deps]; } } - return deps.length ? deps : undefined; + depcache[path] = deps; + return deps; } // process script dependencies, expand paths @@ -94,7 +90,6 @@ function init(mod) { let deps = find_deps(path); if (deps) { // remove deps already in list - // todo: promote filtered deps order in path array deps = deps.filter(p => nval.indexOf(p) < 0); let ppos = nval.indexOf(path); if (ppos < 0) { @@ -479,18 +474,12 @@ const script = { "main/meta", ], mesh : [ - "main/gapp", - "moto/license", "&main/mesh" ], mesh_work : [ - "main/gapp", - "moto/license", "&mesh/work" ], mesh_pool : [ - "main/gapp", - "moto/license", "&mesh/pool" ] }; diff --git a/src/add/three.js b/src/add/three.js index d2f82b08..26c51f4e 100644 --- a/src/add/three.js +++ b/src/add/three.js @@ -4,6 +4,7 @@ (function() { + // dep: ext.three gapp.register('add.three'); var MP = THREE.Mesh.prototype, diff --git a/src/main/gapp.js b/src/main/gapp.js index 79072531..3962a46e 100644 --- a/src/main/gapp.js +++ b/src/main/gapp.js @@ -10,6 +10,10 @@ if (typeof(self) === 'undefined') { (function () { +/** satisfy earcut, tween, etc **/ + +if (!self.module) self.module = { exports: {} }; + /** debug and logging **/ let mark = Date.now(); diff --git a/src/main/mesh.js b/src/main/mesh.js index b5e90a91..e3fde86c 100644 --- a/src/main/mesh.js +++ b/src/main/mesh.js @@ -99,10 +99,11 @@ document.onreadystatechange = function() { // finalize modules gapp.finalize("main.mesh", [ + "moto.license", // dep: moto.license "moto.webui", // dep: moto.webui "moto.client", // dep: moto.client "moto.broker", // dep: moto.broker - "moto.space" // dep: moto.space + "moto.space", // dep: moto.space ]); })(); diff --git a/src/mesh/pool.js b/src/mesh/pool.js index 7810fd69..ff0328cb 100644 --- a/src/mesh/pool.js +++ b/src/mesh/pool.js @@ -5,6 +5,7 @@ (function() { gapp.finalize("mesh.pool", [ + "moto.license", // dep: moto.license "moto.worker" // dep: moto.worker ]); diff --git a/src/mesh/work.js b/src/mesh/work.js index 7275e10d..47c8acd4 100644 --- a/src/mesh/work.js +++ b/src/mesh/work.js @@ -10,6 +10,7 @@ // dep: ext.three // dep: ext.three-bgu gapp.finalize("mesh.work", [ + "moto.license", // dep: moto.license "moto.client" // dep: moto.client ]); diff --git a/src/moto/license.js b/src/moto/license.js index cb90ad44..6fc8ba49 100644 --- a/src/moto/license.js +++ b/src/moto/license.js @@ -16,8 +16,10 @@ app.license = terms.LICENSE; app.version = terms.VERSION; app.copyright = terms.COPYRIGHT; + // satisfy resolver + gapp.register('moto.license'); // for earcut and other modules - self.module = { exports: terms }; + (self.module = self.module || {}).exports = terms; } })();