Skip to content

Commit

Permalink
feat: don't include from arrays in tree
Browse files Browse the repository at this point in the history
as the backend doesn't it need anymore,
and it reduces the result json size by 3
  • Loading branch information
michael-go committed Apr 24, 2018
1 parent a3e6d4f commit 66f2b83
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 81 deletions.
13 changes: 4 additions & 9 deletions lib/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,8 @@ module.exports = {
inspect: inspect,
};

var VIRTUAL_ROOT_NODE_ID = '.'

function inspect(root, targetFile, options) {
return Promise.all([
getMetaData(root, targetFile),
Expand Down Expand Up @@ -84,7 +86,7 @@ function getDependencies(root, targetFile) {
var projectRootPath = getProjectRootFromTargetFile(targetFile);

var pkgsTree = recursivelyBuildPkgTree(
graph, root, config.lockedVersions, projectRootPath, [], {});
graph, root, config.lockedVersions, projectRootPath, {});
delete pkgsTree._counts;

pkgsTree.packageFormatVersion = 'golang:0.0.1';
Expand Down Expand Up @@ -149,11 +151,10 @@ function recursivelyBuildPkgTree(
node,
lockedVersions,
projectRootPath,
fromPath,
counts
) {

var isRoot = (fromPath.length == 0);
var isRoot = (node.Name === VIRTUAL_ROOT_NODE_ID);

var isProjSubpkg = isProjSubpackage(node.Dir, projectRootPath);

Expand All @@ -174,11 +175,6 @@ function recursivelyBuildPkgTree(
pkg.version = lockedVersions[pkg.name].version;
}

pkg.from = fromPath;
if (isRoot || !isProjSubpkg) {
pkg.from = pkg.from.concat(pkg.name + '@' + pkg.version)
}

pkg._counts = {};

var children = graph.successors(node.Name).sort();
Expand All @@ -197,7 +193,6 @@ function recursivelyBuildPkgTree(
dep,
lockedVersions,
projectRootPath,
pkg.from,
sumCounts(counts, pkg._counts)
);

Expand Down
72 changes: 0 additions & 72 deletions test/inspect.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,6 @@ test('happy inspect', function (t) {
t.match(pkg, {
name: 'path/to/pkg',
version: '',
from: ['path/to/pkg@'],
packageFormatVersion: 'golang:0.0.1',
}, 'root pkg')
t.end();
Expand All @@ -44,7 +43,6 @@ test('happy inspect', function (t) {
version: '#b6ffb7d62206806b573348160795ea16a00940a6',
},
},
from: ['path/to/pkg@', 'gitpub.com/food/salad@v1.3.7'],
}, 'salad depends on tomato and cucamba');

t.match(deps['gitpub.com/meal/dinner'], {
Expand All @@ -55,12 +53,6 @@ test('happy inspect', function (t) {
dependencies: {
'gitpub.com/nature/vegetables/tomato': {
version: '#b6ffb7d62206806b573348160795ea16a00940a6',
from: [
'path/to/pkg@',
'gitpub.com/meal/dinner@v0.0.7',
'gitpub.com/food/salad@v1.3.7',
'gitpub.com/nature/vegetables/tomato@#b6ffb7d62206806b573348160795ea16a00940a6', // jscs:ignore maximumLineLength
],
},
},
},
Expand Down Expand Up @@ -99,12 +91,6 @@ test('pkg with local import', function (t) {
dependencies: {
'gitpub.com/nature/vegetables/tomato': {
version: '#b6ffb7d62206806b573348160795ea16a00940a6',
from: [
'path/to/pkg-with-local-import@',
'gitpub.com/meal/dinner@v0.0.7',
'gitpub.com/food/salad@v1.3.7',
'gitpub.com/nature/vegetables/tomato@#b6ffb7d62206806b573348160795ea16a00940a6', // jscs:ignore maximumLineLength
],
},
},
},
Expand Down Expand Up @@ -145,12 +131,6 @@ test('pkg with internal subpkg', function (t) {
dependencies: {
'gitpub.com/nature/vegetables/tomato': {
version: '#b6ffb7d62206806b573348160795ea16a00940a6',
from: [
'path/to/pkg-with-internal-subpkg@',
'gitpub.com/meal/dinner@v0.0.7',
'gitpub.com/food/salad@v1.3.7',
'gitpub.com/nature/vegetables/tomato@#b6ffb7d62206806b573348160795ea16a00940a6', // jscs:ignore maximumLineLength
],
},
},
},
Expand Down Expand Up @@ -184,7 +164,6 @@ test('multi-root project', function (t) {
t.match(pkg, {
name: 'path/to/multiroot-pkg',
version: '',
from: ['path/to/multiroot-pkg@'],
packageFormatVersion: 'golang:0.0.1',
}, 'root pkg')
t.end();
Expand All @@ -204,7 +183,6 @@ test('multi-root project', function (t) {
version: '#b6ffb7d62206806b573348160795ea16a00940a6',
},
},
from: ['path/to/multiroot-pkg@', 'gitpub.com/food/salad@v1.3.7'],
}, 'salad depends on tomato and cucamba');

t.match(deps['gitpub.com/meal/dinner'], {
Expand All @@ -215,12 +193,6 @@ test('multi-root project', function (t) {
dependencies: {
'gitpub.com/nature/vegetables/tomato': {
version: '#b6ffb7d62206806b573348160795ea16a00940a6',
from: [
'path/to/multiroot-pkg@',
'gitpub.com/meal/dinner@v0.0.7',
'gitpub.com/food/salad@v1.3.7',
'gitpub.com/nature/vegetables/tomato@#b6ffb7d62206806b573348160795ea16a00940a6', // jscs:ignore maximumLineLength
],
},
},
},
Expand Down Expand Up @@ -277,7 +249,6 @@ test('multi-root project without code at root', function (t) {
t.match(pkg, {
name: 'path/to/multiroot-pkg-without-root',
version: '',
from: ['path/to/multiroot-pkg-without-root@'],
packageFormatVersion: 'golang:0.0.1',
}, 'root pkg')
t.end();
Expand All @@ -297,10 +268,6 @@ test('multi-root project without code at root', function (t) {
version: '#b6ffb7d62206806b573348160795ea16a00940a6',
},
},
from: [
'path/to/multiroot-pkg-without-root@',
'gitpub.com/food/salad@v1.3.7',
],
}, 'salad depends on tomato and cucamba');

t.match(deps['gitpub.com/meal/dinner'], {
Expand All @@ -311,12 +278,6 @@ test('multi-root project without code at root', function (t) {
dependencies: {
'gitpub.com/nature/vegetables/tomato': {
version: '#b6ffb7d62206806b573348160795ea16a00940a6',
from: [
'path/to/multiroot-pkg-without-root@',
'gitpub.com/meal/dinner@v0.0.7',
'gitpub.com/food/salad@v1.3.7',
'gitpub.com/nature/vegetables/tomato@#b6ffb7d62206806b573348160795ea16a00940a6', // jscs:ignore maximumLineLength
],
},
},
},
Expand All @@ -326,10 +287,6 @@ test('multi-root project without code at root', function (t) {
t.match(deps['gitpub.com/meal/dinner/desert'], {
version: 'v0.0.7',
dependencies: {},
from: [
'path/to/multiroot-pkg-without-root@',
'gitpub.com/meal/dinner/desert@v0.0.7',
],
}, 'dinner/desert is a direct dependency');

t.end();
Expand Down Expand Up @@ -382,7 +339,6 @@ test('no Go code', function (t) {
name: 'path/to/empty',
dependencies: {},
version: '',
from: ['path/to/empty@'],
packageFormatVersion: 'golang:0.0.1',
}, 'root pkg')
t.end();
Expand Down Expand Up @@ -411,7 +367,6 @@ test('with external ignores', function (t) {
t.match(pkg, {
name: 'path/to/pkg-with-ignores',
version: '',
from: ['path/to/pkg-with-ignores@'],
packageFormatVersion: 'golang:0.0.1',
}, 'root pkg')
t.end();
Expand All @@ -431,7 +386,6 @@ test('with external ignores', function (t) {
version: '#b6ffb7d62206806b573348160795ea16a00940a6',
},
},
from: ['path/to/pkg-with-ignores@', 'gitpub.com/food/salad@v1.3.7'],
}, 'salad depends on tomato and cucamba, even though vegetables are ignored'); // jscs:ignore maximumLineLength


Expand All @@ -447,12 +401,6 @@ test('with external ignores', function (t) {
dependencies: {
'gitpub.com/nature/vegetables/tomato': {
version: '#b6ffb7d62206806b573348160795ea16a00940a6',
from: [
'path/to/pkg-with-ignores@',
'gitpub.com/meal/dinner@v0.0.7',
'gitpub.com/food/salad@v1.3.7',
'gitpub.com/nature/vegetables/tomato@#b6ffb7d62206806b573348160795ea16a00940a6', // jscs:ignore maximumLineLength
],
},
},
},
Expand Down Expand Up @@ -484,7 +432,6 @@ test('with external ignores (govendor)', function (t) {
t.match(pkg, {
name: 'path/to/pkg-with-ignores-govendor',
version: '',
from: ['path/to/pkg-with-ignores-govendor@'],
packageFormatVersion: 'golang:0.0.1',
}, 'root pkg')
t.end();
Expand Down Expand Up @@ -648,7 +595,6 @@ test('pkg without external deps', function (t) {
t.same(pkg, {
name: 'path/to/pkg-without-deps',
version: '',
from: ['path/to/pkg-without-deps@'],
packageFormatVersion: 'golang:0.0.1',
dependencies: {},
});
Expand Down Expand Up @@ -677,7 +623,6 @@ test('happy inspect govendor', function (t) {
t.match(pkg, {
name: 'path/to/pkg',
version: '',
from: ['path/to/pkg@'],
packageFormatVersion: 'golang:0.0.1',
}, 'root pkg');
t.end();
Expand All @@ -697,7 +642,6 @@ test('happy inspect govendor', function (t) {
version: '#b6ffb7d62206806b573348160795ea16a00940a6',
},
},
from: ['path/to/pkg@', 'gitpub.com/food/salad@v1.3.7'],
}, 'salad depends on tomato and cucamba');

t.match(deps['gitpub.com/meal/dinner'], {
Expand All @@ -708,12 +652,6 @@ test('happy inspect govendor', function (t) {
dependencies: {
'gitpub.com/nature/vegetables/tomato': {
version: '#b6ffb7d62206806b573348160795ea16a00940a6',
from: [
'path/to/pkg@',
'gitpub.com/meal/dinner@v0.0.7',
'gitpub.com/food/salad@v1.3.7',
'gitpub.com/nature/vegetables/tomato@#b6ffb7d62206806b573348160795ea16a00940a6', // jscs:ignore maximumLineLength
],
},
},
},
Expand Down Expand Up @@ -745,7 +683,6 @@ test('inspect govendor with alternate case', function (t) {
t.match(pkg, {
name: 'path/to/pkg-with-alternate-govendor',
version: '',
from: ['path/to/pkg-with-alternate-govendor@'],
packageFormatVersion: 'golang:0.0.1',
dependencies: {
'gitpub.com/drink/juice': {
Expand All @@ -770,9 +707,6 @@ test('inspect govendor with alternate case', function (t) {
version: '#b6ffb7d62206806b573348160795ea16a00940a6',
},
},
from: [
'path/to/pkg-with-alternate-govendor@',
'gitpub.com/food/salad@v1.3.7',],
}, 'salad depends on tomato and cucamba');

t.match(deps['gitpub.com/meal/dinner'], {
Expand All @@ -783,12 +717,6 @@ test('inspect govendor with alternate case', function (t) {
dependencies: {
'gitpub.com/nature/vegetables/tomato': {
version: '#b6ffb7d62206806b573348160795ea16a00940a6',
from: [
'path/to/pkg-with-alternate-govendor@',
'gitpub.com/meal/dinner@v0.0.7',
'gitpub.com/food/salad@v1.3.7',
'gitpub.com/nature/vegetables/tomato@#b6ffb7d62206806b573348160795ea16a00940a6', // jscs:ignore maximumLineLength
],
},
},
},
Expand Down

0 comments on commit 66f2b83

Please sign in to comment.