From de94041f6f131a726bc59d56224049d13c7494b5 Mon Sep 17 00:00:00 2001 From: Alexey Yaroshevich Date: Sat, 22 Oct 2016 04:28:30 +0300 Subject: [PATCH 1/4] chore: ignore npm-debug.log --- .gitignore | 1 + 1 file changed, 1 insertion(+) diff --git a/.gitignore b/.gitignore index 2a7be39..9c9ccc5 100644 --- a/.gitignore +++ b/.gitignore @@ -1,3 +1,4 @@ node_modules coverage benchmark/fixtures/libs +npm-debug.log From 342ec27135bca3ee5dfa1161fc03207a06b62f64 Mon Sep 17 00:00:00 2001 From: Alexey Yaroshevich Date: Sat, 22 Oct 2016 04:28:53 +0300 Subject: [PATCH 2/4] tests: require mockfs before the rest --- test/mocha.opts | 1 + 1 file changed, 1 insertion(+) diff --git a/test/mocha.opts b/test/mocha.opts index 957db65..ba9a551 100644 --- a/test/mocha.opts +++ b/test/mocha.opts @@ -1,3 +1,4 @@ --ui bdd --reporter dot --require must +--require mock-fs From 82c9fc1610d604fbd734ffdabbad856b0c978a22 Mon Sep 17 00:00:00 2001 From: Alexey Yaroshevich Date: Sat, 22 Oct 2016 04:29:32 +0300 Subject: [PATCH 3/4] tests(deps-resolver): add case for modifier, #203 --- test/unit/deps-resolver.test.js | 66 +++++++++++++++++++++++++++++++++ 1 file changed, 66 insertions(+) create mode 100644 test/unit/deps-resolver.test.js diff --git a/test/unit/deps-resolver.test.js b/test/unit/deps-resolver.test.js new file mode 100644 index 0000000..098a1ee --- /dev/null +++ b/test/unit/deps-resolver.test.js @@ -0,0 +1,66 @@ +var DepsResolver = require('../../lib/deps/deps-resolver'), + mock = require('mock-fs'); + +describe('libs: deps-resolver', function () { + after(function () { + mock.restore(); + }); + + it('must resolve mod required ordered block. issue#203', function () { + return createGraph({ + x: { + mustDeps: { mod: 'must-mod' }, + shouldDeps: { mod: 'should-mod' } + } + }) + .dependenciesOf({ block: 'x' }) + .must.eventually.equal([ + { block: 'x', mod: 'must-mod' }, + { block: 'x' }, + { block: 'x', mod: 'should-mod' } + ]); + }); + + it('must resolve elem that required ordered block', function () { + return createGraph({ + x: { + mustDeps: { elem: 'must-elem' }, + shouldDeps: { elem: 'should-elem' } + } + }) + .dependenciesOf({ block: 'x' }) + .must.eventually.equal([ + { block: 'x', elem: 'must-elem' }, + { block: 'x' }, + { block: 'x', elem: 'should-elem' } + ]); + }); +}); + +function createGraph(entitiesData) { + var files = Object.keys(entitiesData).reduce(function (res, k) { + res[k + '.deps.js'] = '(' + JSON.stringify(entitiesData[k]) + ')'; + return res; + }, {}); + mock(files); + + var resolver = new DepsResolver({ + getBlockFiles: function (b, m, v) { + var name = b + (m ? '_' + m : '') + (v ? '_' + v : '') + '.deps.js'; + return files[name] ? [{ name: name, fullname: name, suffix: 'deps.js' }] : []; + }, + getElemFiles: function (b, e, m, v) { + var name = b + '__' + e + (m ? '_' + m : '') + (v ? '_' + v : '') + '.deps.js'; + return files[name] ? [{ name: name, fullname: name, suffix: 'deps.js' }] : []; + } + }); + + return { + dependenciesOf: function (decl) { + decl = resolver.normalizeDeps(decl); + return resolver.addDecls(decl).then(function () { + return resolver.resolve(); + }); + } + }; +} From b4ff60b6073e7d51a6603037aaaeeb3f962c0c28 Mon Sep 17 00:00:00 2001 From: Alexey Yaroshevich Date: Sat, 22 Oct 2016 06:31:44 +0300 Subject: [PATCH 4/4] wip --- lib/deps/deps-resolver.js | 34 +++++++++++++++++++++++++++++++--- 1 file changed, 31 insertions(+), 3 deletions(-) diff --git a/lib/deps/deps-resolver.js b/lib/deps/deps-resolver.js index 3ff69c2..08175be 100644 --- a/lib/deps/deps-resolver.js +++ b/lib/deps/deps-resolver.js @@ -236,6 +236,7 @@ module.exports = inherit(/** @lends DepsResolver.prototype */{ nd.key = key; mustDeps.push(nd); } + console.log(key, {mustDeps: mustDeps.map(v => v.key), shouldDeps: shouldDeps.map(v => v.key)}); }); } if (dep.shouldDeps) { @@ -246,6 +247,7 @@ module.exports = inherit(/** @lends DepsResolver.prototype */{ nd.key = key; shouldDeps.push(nd); } + console.log(key, {mustDeps: mustDeps.map(v => v.key), shouldDeps: shouldDeps.map(v => v.key)}); }); } if (dep.noDeps) { @@ -386,11 +388,33 @@ module.exports = inherit(/** @lends DepsResolver.prototype */{ decl.key = key; decl.deps = {}; decl.depCount = 0; + + // naturalization + if (decl.elem && !decl.deps[decl.name]) { + decl.deps[decl.name] = 'fake'; + decl.depCount++; + } + if (decl.modName) { + if (decl.elem) { + if (!decl.deps[decl.name + '_' + decl.elem]) { + decl.deps[decl.name + '_' + decl.elem] = 'fake'; + decl.depCount++; + } + } else if (!decl.deps[decl.name]) { + decl.deps[decl.name] = 'fake'; + decl.depCount++; + } + } + return _this.addDecls(deps.mustDeps, function (dep) { decl.deps[dep.key] = dep.fake ? 'fake' : true; + console.log(key + ' => ' + dep.key, dep.fake ? 'fake' : 'real'); decl.depCount++; }).then(function () { - return _this.addDecls(deps.shouldDeps); + return _this.addDecls(deps.shouldDeps, function (dep) { +// if (decl.deps[dep.key]) return; + console.log('KK', key + ' -> ' + dep.key, dep.deps); + }); }); }); }, @@ -426,7 +450,9 @@ module.exports = inherit(/** @lends DepsResolver.prototype */{ result = [], hasChanges = true, newItems; - while (hasChanges) { + + while (hasChanges && items.length) { + console.log('!', items.map(v => v.key), result); var i, j, l; newItems = []; @@ -439,7 +465,7 @@ module.exports = inherit(/** @lends DepsResolver.prototype */{ for (j = 0; j < l; j++) { var subDecl = items[j], subDeclKey = decl.key; - +console.log('aaa', subDecl.key, subDecl.deps); if (subDecl.deps[subDeclKey]) { delete subDecl.deps[subDeclKey]; subDecl.depCount--; @@ -457,8 +483,10 @@ module.exports = inherit(/** @lends DepsResolver.prototype */{ item.val = decl.modVal; } } + console.log('+', item); result.push(item); } else { + console.log('®', decl.key); newItems.push(decl); } }