From 927aa572bbfd330a85f4dbe8459806d68f243111 Mon Sep 17 00:00:00 2001 From: Piotr Grzesiak Date: Wed, 12 May 2021 13:11:31 +0200 Subject: [PATCH 1/3] Use random temp directory for progress estimator (fix concurrent builds) --- src/cli.ts | 4 +++- src/utils.ts | 28 ++++++++++++++++++---------- 2 files changed, 21 insertions(+), 11 deletions(-) diff --git a/src/cli.ts b/src/cli.ts index 5bbc64f..f94940d 100755 --- a/src/cli.ts +++ b/src/cli.ts @@ -11,7 +11,7 @@ import { createBundles, writeBundles, } from './rollupBuilds'; -import { progressEstimator, cleanDist } from './utils'; +import { progressEstimatorBuilder, cleanDist } from './utils'; import { EXIT_ON_ERROR, errorAsObjectWithMessage, @@ -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); diff --git a/src/utils.ts b/src/utils.ts index d149299..512aefa 100644 --- a/src/utils.ts +++ b/src/utils.ts @@ -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 = () => + fs.mkdtemp(join(os.tmpdir(), 'progress-estimator-')); + +export const progressEstimatorBuilder: () => Promise = async () => { + const tempDirPath = await createRandomProgressEstimatorTempDir(); + + return createProgressEstimator({ + storagePath: tempDirPath, + spinner: { + interval: 180, + frames: ['🌎', '🌏', '🌍'], + }, + }); +}; export const cleanDist: () => Promise = () => fs.emptyDir('./dist'); From 2ae0a176e21931f65dc1639903ccef970c652619 Mon Sep 17 00:00:00 2001 From: Piotr Grzesiak Date: Fri, 14 May 2021 21:08:24 +0200 Subject: [PATCH 2/3] Revert "Use random temp directory for progress estimator (fix concurrent builds)" This reverts commit 927aa572 --- src/cli.ts | 4 +--- src/utils.ts | 28 ++++++++++------------------ 2 files changed, 11 insertions(+), 21 deletions(-) diff --git a/src/cli.ts b/src/cli.ts index f94940d..5bbc64f 100755 --- a/src/cli.ts +++ b/src/cli.ts @@ -11,7 +11,7 @@ import { createBundles, writeBundles, } from './rollupBuilds'; -import { progressEstimatorBuilder, cleanDist } from './utils'; +import { progressEstimator, cleanDist } from './utils'; import { EXIT_ON_ERROR, errorAsObjectWithMessage, @@ -24,8 +24,6 @@ const rollpkg = async () => { ///////////////////////////////////// // clean dist folder const cleanDistMessage = 'Cleaning dist folder'; - const progressEstimator = await progressEstimatorBuilder(); - try { const clean = cleanDist(); await progressEstimator(clean, cleanDistMessage); diff --git a/src/utils.ts b/src/utils.ts index 512aefa..d149299 100644 --- a/src/utils.ts +++ b/src/utils.ts @@ -1,23 +1,15 @@ import * as fs from 'fs-extra'; -import { resolve, join } from 'path'; -import * as os from 'os'; +import { resolve } from 'path'; import * as readline from 'readline'; -import createProgressEstimator, { ProgressEstimator } from 'progress-estimator'; - -export const createRandomProgressEstimatorTempDir: () => Promise = () => - fs.mkdtemp(join(os.tmpdir(), 'progress-estimator-')); - -export const progressEstimatorBuilder: () => Promise = async () => { - const tempDirPath = await createRandomProgressEstimatorTempDir(); - - return createProgressEstimator({ - storagePath: tempDirPath, - spinner: { - interval: 180, - frames: ['🌎', '🌏', '🌍'], - }, - }); -}; +import createProgressEstimator from 'progress-estimator'; + +export const progressEstimator = createProgressEstimator({ + storagePath: resolve(__dirname, '.progress-estimator'), + spinner: { + interval: 180, + frames: ['🌎', '🌏', '🌍'], + }, +}); export const cleanDist: () => Promise = () => fs.emptyDir('./dist'); From fa914d7e3cc5826b3a6e361bba3724aa68322c0c Mon Sep 17 00:00:00 2001 From: Piotr Grzesiak Date: Fri, 14 May 2021 21:10:34 +0200 Subject: [PATCH 3/3] Use package node_modules/.cache or os dir temp to store cache files --- package-lock.json | 16 +++++++++++++++- package.json | 2 ++ src/utils.ts | 10 +++++++++- 3 files changed, 26 insertions(+), 2 deletions(-) diff --git a/package-lock.json b/package-lock.json index fa75672..b9f1ffe 100644 --- a/package-lock.json +++ b/package-lock.json @@ -5,7 +5,7 @@ "requires": true, "packages": { "": { - "version": "0.5.5", + "version": "0.5.6", "license": "MIT", "dependencies": { "@rollup/plugin-commonjs": "^18.0.0", @@ -25,6 +25,7 @@ "eslint-plugin-jsx-a11y": "^6.4.1", "eslint-plugin-react": "^7.23.1", "eslint-plugin-react-hooks": "^4.2.0", + "find-cache-dir": "^3.3.1", "fs-extra": "^9.1.0", "jest": "^26.6.3", "jest-watch-typeahead": "^0.6.2", @@ -43,6 +44,7 @@ "rollpkg": "dist/cli.js" }, "devDependencies": { + "@types/find-cache-dir": "^3.2.0", "@types/fs-extra": "^9.0.10", "@types/mock-fs": "^4.13.0", "@types/node": "^14.14.37", @@ -1185,6 +1187,12 @@ "resolved": "https://registry.npmjs.org/@types/estree/-/estree-0.0.39.tgz", "integrity": "sha512-EYNwp3bU+98cpU4lAWYYL7Zz+2gryWH1qbdDTidVd6hkiR6weksdbMadyXKXNPEkQFhXM+hVO9ZygomHXp+AIw==" }, + "node_modules/@types/find-cache-dir": { + "version": "3.2.0", + "resolved": "https://registry.npmjs.org/@types/find-cache-dir/-/find-cache-dir-3.2.0.tgz", + "integrity": "sha512-+JeT9qb2Jwzw72WdjU+TSvD5O1QRPWCeRpDJV+guiIq+2hwR0DFGw+nZNbTFjMIVe6Bf4GgAKeB/6Ytx6+MbeQ==", + "dev": true + }, "node_modules/@types/fs-extra": { "version": "9.0.10", "resolved": "https://registry.npmjs.org/@types/fs-extra/-/fs-extra-9.0.10.tgz", @@ -20370,6 +20378,12 @@ "resolved": "https://registry.npmjs.org/@types/estree/-/estree-0.0.39.tgz", "integrity": "sha512-EYNwp3bU+98cpU4lAWYYL7Zz+2gryWH1qbdDTidVd6hkiR6weksdbMadyXKXNPEkQFhXM+hVO9ZygomHXp+AIw==" }, + "@types/find-cache-dir": { + "version": "3.2.0", + "resolved": "https://registry.npmjs.org/@types/find-cache-dir/-/find-cache-dir-3.2.0.tgz", + "integrity": "sha512-+JeT9qb2Jwzw72WdjU+TSvD5O1QRPWCeRpDJV+guiIq+2hwR0DFGw+nZNbTFjMIVe6Bf4GgAKeB/6Ytx6+MbeQ==", + "dev": true + }, "@types/fs-extra": { "version": "9.0.10", "resolved": "https://registry.npmjs.org/@types/fs-extra/-/fs-extra-9.0.10.tgz", diff --git a/package.json b/package.json index e061bf2..d268cf5 100644 --- a/package.json +++ b/package.json @@ -55,6 +55,7 @@ "eslint-plugin-jsx-a11y": "^6.4.1", "eslint-plugin-react": "^7.23.1", "eslint-plugin-react-hooks": "^4.2.0", + "find-cache-dir": "^3.3.1", "fs-extra": "^9.1.0", "jest": "^26.6.3", "jest-watch-typeahead": "^0.6.2", @@ -70,6 +71,7 @@ "validate-npm-package-name": "^3.0.0" }, "devDependencies": { + "@types/find-cache-dir": "^3.2.0", "@types/fs-extra": "^9.0.10", "@types/mock-fs": "^4.13.0", "@types/node": "^14.14.37", diff --git a/src/utils.ts b/src/utils.ts index d149299..9ec7416 100644 --- a/src/utils.ts +++ b/src/utils.ts @@ -1,10 +1,18 @@ +import * as os from 'os'; import * as fs from 'fs-extra'; import { resolve } from 'path'; import * as readline from 'readline'; +import findCacheDir from 'find-cache-dir'; import createProgressEstimator from 'progress-estimator'; +export const getCacheDir = (...pathParts: string[]): string => { + const thunk = findCacheDir({ name: 'rollpkg', create: true, thunk: true }); + + return thunk ? thunk(...pathParts) : resolve(os.tmpdir(), ...pathParts); +} + export const progressEstimator = createProgressEstimator({ - storagePath: resolve(__dirname, '.progress-estimator'), + storagePath: getCacheDir('progress-estimator'), spinner: { interval: 180, frames: ['🌎', '🌏', '🌍'],