Skip to content

Commit

Permalink
chore: use reverse dependency tree in oao publish (#102)
Browse files Browse the repository at this point in the history
  • Loading branch information
jeroenptrs committed Jul 20, 2020
1 parent e3b5ef3 commit 693e599
Show file tree
Hide file tree
Showing 5 changed files with 76 additions and 2 deletions.
19 changes: 19 additions & 0 deletions src/__tests__/publish.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -205,6 +205,25 @@ describe('PUBLISH command', () => {
});
});

it('runs `npm publish` following the dependency graph by default', async () => {
const { exec } = require('../utils/shell');
await publish(
Object.assign({}, NOMINAL_OPTIONS, {
src: 'test/fixtures/packages3/*',
})
);
expect(exec).toHaveBeenCalledTimes(
NUM_FIXTURE_SUBPACKAGES - NUM_FIXTURE_PRIVATE_SUBPACKAGES
);
const paths = exec.mock.calls.map(([, { cwd }]) => cwd);
expect(paths).toEqual([
'test/fixtures/packages3/oao-b',
'test/fixtures/packages3/oao',
'test/fixtures/packages3/oao-c',
'test/fixtures/packages3/oao-d',
]);
});

it('runs `npm publish --tag X` on dirty sub-packages', async () => {
const { exec } = require('../utils/shell');
await publish(merge(NOMINAL_OPTIONS, { publishTag: 'next' }));
Expand Down
5 changes: 4 additions & 1 deletion src/publish.js
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ import {
} from './utils/git';
import { addVersionLine } from './utils/changelog';
import { masterOrMainBranch } from './utils/helpers';
import { calcGraphAndReturnAsAllSpecs } from './utils/calcGraph';

const DEBUG_SKIP_CHECKS = false;
const RELEASE_INCREMENTS = ['major', 'minor', 'patch'];
Expand Down Expand Up @@ -70,7 +71,9 @@ const run = async ({
_date,
_masterVersion,
}: Options) => {
const allSpecs = await readAllSpecs(src, ignoreSrc);
const allSpecs = calcGraphAndReturnAsAllSpecs(
await readAllSpecs(src, ignoreSrc)
);

// Confirm that we have run build and run prepublish checks
if (confirm && !(await confirmBuild())) return;
Expand Down
38 changes: 38 additions & 0 deletions src/utils/__tests__/__snapshots__/calcGraph.test.js.snap
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
// Jest Snapshot v1, https://goo.gl/fbAQLP

exports[`buildGraph returns list as an allSpecs object 1`] = `
Object {
"a": Object {
"name": "a",
"specs": Object {
"dependencies": Object {
"b": "*",
"c": "*",
},
},
},
"b": Object {
"name": "b",
"specs": Object {
"dependencies": Object {
"ext": "*",
},
},
},
"c": Object {
"name": "c",
"specs": Object {
"dependencies": Object {
"ext": "*",
},
"devDependencies": Object {
"d": "*",
},
},
},
"d": Object {
"name": "d",
"specs": Object {},
},
}
`;
7 changes: 6 additions & 1 deletion src/utils/__tests__/calcGraph.test.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
/* eslint-env jest */

import calcGraph from '../calcGraph';
import calcGraph, { calcGraphAndReturnAsAllSpecs } from '../calcGraph';

const ALL_SPECS_NO_CYCLE = {
a: {
Expand Down Expand Up @@ -81,4 +81,9 @@ describe('buildGraph', () => {
const dag = calcGraph(ALL_SPECS_CYCLE);
expect(dag).toEqual(['b', 'd', 'e', 'c', 'a']);
});

it('returns list as an allSpecs object', () => {
const allSpecs = calcGraphAndReturnAsAllSpecs(ALL_SPECS_NO_CYCLE);
expect(allSpecs).toMatchSnapshot();
});
});
9 changes: 9 additions & 0 deletions src/utils/calcGraph.js
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,15 @@ const calcGraph = (allSpecs: AllSpecs): Array<string> => {
return out.slice(0, out.length - 1);
};

export const calcGraphAndReturnAsAllSpecs = (allSpecs: AllSpecs): AllSpecs => {
const newAllSpecs = {};
const orderedPackages = calcGraph(allSpecs);
orderedPackages.forEach(pkg => {
newAllSpecs[pkg] = allSpecs[pkg];
});
return newAllSpecs;
};

const buildGraph = (
allSpecs: AllSpecs,
pkg: OaoSpecs,
Expand Down

0 comments on commit 693e599

Please sign in to comment.