Skip to content

Commit

Permalink
fix(api): Generate configs in _proper_ topological order
Browse files Browse the repository at this point in the history
  • Loading branch information
evocateur committed Oct 17, 2019
1 parent b6ee6ea commit 9ea4aa3
Show file tree
Hide file tree
Showing 4 changed files with 14 additions and 38 deletions.
23 changes: 4 additions & 19 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

16 changes: 4 additions & 12 deletions packages/pectin-api/lib/pectin-api.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,8 @@ const path = require('path');
const util = require('util');
const dotProp = require('dot-prop');
const globby = require('globby');
const pMap = require('p-map');
const batchPackages = require('@lerna/batch-packages');
const { getPackages } = require('@lerna/project');
const runTopologically = require('@lerna/run-topologically');
const pectin = require('@pectin/core');

const statAsync = util.promisify(fs.stat);
Expand All @@ -23,10 +22,10 @@ async function findConfigs({
watch = !!process.env.ROLLUP_WATCH,
} = {}) {
const lernaPackages = await getPackages(startDir);
const configs = await pMap(
const configs = await runTopologically(
lernaPackages,
// clones internal JSON, maps synthetic location to cwd property
flatBatched(lernaPackages).map(pkg => [pkg.toJSON(), pkg.location]),
([pkg, cwd]) => generateConfig(pkg, { cwd, watch }),
pkg => generateConfig(pkg.toJSON(), { cwd: pkg.location, watch }),
{ concurrency }
);

Expand Down Expand Up @@ -135,10 +134,3 @@ async function isUpToDate(opts, config) {

return fileStats.every(fileStat => fileStat.mtime.getTime() <= lastBuilt);
}

function flatBatched(pkgList) {
// ensures packages are built in topological order, dependencies before dependents
const batches = batchPackages(pkgList);

return batches.reduce((acc, batch) => acc.concat(batch), []);
}
5 changes: 2 additions & 3 deletions packages/pectin-api/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -33,11 +33,10 @@
"rollup": ">=1.12.0"
},
"dependencies": {
"@lerna/batch-packages": "^3.0.0",
"@lerna/project": "^3.0.0",
"@lerna/run-topologically": "^3.16.0",
"@pectin/core": "file:../pectin-core",
"dot-prop": "^5.1.0",
"globby": "^10.0.1",
"p-map": "^3.0.0"
"globby": "^10.0.1"
}
}
8 changes: 4 additions & 4 deletions packages/pectin-api/test/pectin-api.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -400,10 +400,6 @@ describe('pectin-api', () => {
];

await expect(findConfigs()).resolves.toMatchObject([
{
input: 'modules/app/src/index.js',
output: [{ format: 'cjs', exports: 'auto' }],
},
{
input: 'modules/lib/missing-dist/src/index.js',
output: [{ format: 'cjs', exports: 'auto' }],
Expand All @@ -412,6 +408,10 @@ describe('pectin-api', () => {
input: 'modules/lib/missing-dist/src/index.js',
output: [{ format: 'esm', exports: 'named' }],
},
{
input: 'modules/app/src/index.js',
output: [{ format: 'cjs', exports: 'auto' }],
},
]);
});

Expand Down

0 comments on commit 9ea4aa3

Please sign in to comment.