Skip to content

Commit 9a8331b

Browse files
committed
refactor: move progress ui to separate package
1 parent db05741 commit 9a8331b

File tree

6 files changed

+18
-95
lines changed

6 files changed

+18
-95
lines changed

package.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -53,6 +53,7 @@
5353
"dependencies": {
5454
"chalk": "^4.1.0",
5555
"imagemin": "^7.0.1",
56+
"@bsmth/loader-progress": "^1.0.0",
5657
"imagemin-gifsicle": "^7.0.0",
5758
"imagemin-mozjpeg": "^9.0.0",
5859
"imagemin-pngquant": "^9.0.1",

src/lib/createBasisFile.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -7,8 +7,8 @@ import {
77
read as cacheRead,
88
getFilename,
99
} from '@bsmth/loader-cache';
10+
import { trackJob } from '@bsmth/loader-progress';
1011
import type BasisOptions from '../types/BasisOptions';
11-
import { trackJob, completeJob } from './jobTracker';
1212

1313
const asyncExec = promisify( exec );
1414

@@ -115,7 +115,7 @@ export default async function createBasisFile({
115115
}
116116
}
117117

118-
const job = trackJob({
118+
const completeJob = trackJob({
119119
reportName,
120120
text: 'compressing .basis',
121121
});
@@ -126,7 +126,7 @@ export default async function createBasisFile({
126126
if ( stderr ) {
127127
throw new Error( `BASIS COMPRESSION FAILED: ${stderr}` );
128128
} else {
129-
completeJob( job );
129+
completeJob();
130130
}
131131

132132

src/lib/createImageFile.ts

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -9,8 +9,8 @@ import {
99
read as cacheRead,
1010
write as cacheWrite,
1111
} from '@bsmth/loader-cache';
12+
import { trackJob } from '@bsmth/loader-progress';
1213
import type { ImgLoaderQualityOptions } from '../types/ImgLoaderOptions';
13-
import { completeJob, trackJob } from './jobTracker';
1414

1515

1616
interface CreateImageFileProps {
@@ -52,7 +52,7 @@ export default async function createImageFile({
5252

5353
if ( cached ) return cached;
5454

55-
const job = trackJob({
55+
const completeJob = trackJob({
5656
reportName,
5757
text: `compressing .${type}`,
5858
});
@@ -84,14 +84,14 @@ export default async function createImageFile({
8484
});
8585
}
8686

87-
const path = await writeFile({
87+
const path = await cacheWrite({
8888
buffer: outBuffer,
8989
options: relevantOptions,
9090
inputHash,
9191
resource,
9292
});
9393

94-
completeJob( job );
94+
completeJob();
9595

9696
return {
9797
buffer: outBuffer,

src/lib/jobTracker.ts

Lines changed: 0 additions & 85 deletions
This file was deleted.

src/lib/resize.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,8 @@ import {
44
read as cacheRead,
55
write as cacheWrite,
66
} from '@bsmth/loader-cache';
7+
import { trackJob } from '@bsmth/loader-progress';
78
import type { ImgLoaderInternalOptions } from '../types/ImgLoaderOptions';
8-
import { completeJob, trackJob } from './jobTracker';
99

1010

1111
interface ResizeProps {
@@ -41,7 +41,7 @@ export default async function resize({
4141

4242
if ( cached ) return cached;
4343

44-
const job = trackJob({
44+
const completeJob = trackJob({
4545
reportName,
4646
text: options.forcePowerOfTwo ? 'resizing to POT' : 'downscaling',
4747
});
@@ -61,7 +61,7 @@ export default async function resize({
6161
...cacheOpts,
6262
});
6363

64-
completeJob( job );
64+
completeJob();
6565

6666
return {
6767
buffer,

yarn.lock

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -894,6 +894,13 @@
894894
version "0.4.0"
895895
resolved "https://registry.yarnpkg.com/@eslint/eslintrc/-/eslintrc-0.4.0.tgz#99cc0a0584d72f1df38b900fb062ba995f395547"
896896
integrity sha512-2ZPCc+uNbjV5ERJr+aKSPRwZgKd2z11x0EgLvb1PURmUrn9QNRXFqje0Ldq454PfAVyaJYyrDvvIKSFP4NnBog==
897+
"@bsmth/loader-progress@^1.0.0":
898+
version "1.0.0"
899+
resolved "https://registry.yarnpkg.com/@bsmth/loader-progress/-/loader-progress-1.0.0.tgz#bba93adc9b3aa9333930b71f1bfe7d29ecc5234e"
900+
integrity sha512-8lmNHLuK/HZdIUjSWzUSKMtRAez+HspqG3CXqlxkFS52ud6XdNbEavUGsEu/SRvITYfnNt8wmkMmuUOYvJPKag==
901+
dependencies:
902+
chalk "^4.1.1"
903+
ora "^5.4.0"
897904
dependencies:
898905
ajv "^6.12.4"
899906
debug "^4.1.1"

0 commit comments

Comments
 (0)