Skip to content

Commit

Permalink
Use random temp directory for progress estimator (fix concurrent builds)
Browse files Browse the repository at this point in the history
  • Loading branch information
piter2k1 authored and Piotr Grzesiak committed May 12, 2021
1 parent 859c5e3 commit 927aa57
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 11 deletions.
4 changes: 3 additions & 1 deletion src/cli.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ import {
createBundles,
writeBundles,
} from './rollupBuilds';
import { progressEstimator, cleanDist } from './utils';
import { progressEstimatorBuilder, cleanDist } from './utils';
import {
EXIT_ON_ERROR,
errorAsObjectWithMessage,
Expand All @@ -24,6 +24,8 @@ const rollpkg = async () => {
/////////////////////////////////////
// clean dist folder
const cleanDistMessage = 'Cleaning dist folder';
const progressEstimator = await progressEstimatorBuilder();

try {
const clean = cleanDist();
await progressEstimator(clean, cleanDistMessage);
Expand Down
28 changes: 18 additions & 10 deletions src/utils.ts
Original file line number Diff line number Diff line change
@@ -1,15 +1,23 @@
import * as fs from 'fs-extra';
import { resolve } from 'path';
import { resolve, join } from 'path';
import * as os from 'os';
import * as readline from 'readline';
import createProgressEstimator from 'progress-estimator';

export const progressEstimator = createProgressEstimator({
storagePath: resolve(__dirname, '.progress-estimator'),
spinner: {
interval: 180,
frames: ['🌎', '🌏', '🌍'],
},
});
import createProgressEstimator, { ProgressEstimator } from 'progress-estimator';

export const createRandomProgressEstimatorTempDir: () => Promise<string> = () =>
fs.mkdtemp(join(os.tmpdir(), 'progress-estimator-'));

export const progressEstimatorBuilder: () => Promise<ProgressEstimator> = async () => {
const tempDirPath = await createRandomProgressEstimatorTempDir();

return createProgressEstimator({
storagePath: tempDirPath,
spinner: {
interval: 180,
frames: ['🌎', '🌏', '🌍'],
},
});
};

export const cleanDist: () => Promise<void> = () => fs.emptyDir('./dist');

Expand Down

0 comments on commit 927aa57

Please sign in to comment.