Skip to content

Commit db05741

Browse files
committed
refactor: move cache to separate package
1 parent 8fd6762 commit db05741

File tree

8 files changed

+29
-225
lines changed

8 files changed

+29
-225
lines changed

package.json

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -63,7 +63,9 @@
6363
"sharp": "^0.27.2",
6464
"svgo": "2"
6565
},
66-
"peerDependencies": {},
66+
"peerDependencies": {
67+
"@bsmth/loader-cache": "^1.0.1"
68+
},
6769
"husky": {
6870
"hooks": {
6971
"pre-commit": "lint-staged"

src/index.ts

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,12 @@
1+
import { deprecate } from 'util';
2+
import { CachePlugin as _CachePlugin } from '@bsmth/loader-cache';
3+
14
export { default } from './loader';
2-
export { default as CachePlugin } from './plugin';
5+
6+
export const CachePlugin = deprecate(
7+
_CachePlugin,
8+
'[@bsmth/img-loader]: CachePlugin has moved to `@bsmth/loader-cache`, '
9+
+ 'please import it from there instead.',
10+
);
311

412
export const raw = true;

src/lib/cache.ts

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

src/lib/createBasisFile.ts

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,11 @@ import { promises as fs } from 'fs';
33
import { promisify } from 'util';
44
import { exec } from 'child_process';
55

6+
import {
7+
read as cacheRead,
8+
getFilename,
9+
} from '@bsmth/loader-cache';
610
import type BasisOptions from '../types/BasisOptions';
7-
import { getFile, getFilename } from './cache';
811
import { trackJob, completeJob } from './jobTracker';
912

1013
const asyncExec = promisify( exec );
@@ -41,7 +44,7 @@ export default async function createBasisFile({
4144
buffer: Buffer;
4245
path: string;
4346
}> {
44-
const cached = await getFile({ inputHash, options, resource });
47+
const cached = await cacheRead({ inputHash, options, resource });
4548

4649
if ( cached ) {
4750
return cached;

src/lib/createImageFile.ts

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,8 +5,11 @@ import imageminSvgo from 'imagemin-svgo';
55
import imageminGifsicle from 'imagemin-gifsicle';
66

77
import sharp from 'sharp';
8+
import {
9+
read as cacheRead,
10+
write as cacheWrite,
11+
} from '@bsmth/loader-cache';
812
import type { ImgLoaderQualityOptions } from '../types/ImgLoaderOptions';
9-
import { getFile, writeFile } from './cache';
1013
import { completeJob, trackJob } from './jobTracker';
1114

1215

@@ -41,7 +44,7 @@ export default async function createImageFile({
4144
}> {
4245
const relevantOptions = options[compressorForType[type]];
4346

44-
const cached = await getFile({
47+
const cached = await cacheRead({
4548
options: relevantOptions,
4649
inputHash,
4750
resource,

src/lib/resize.ts

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,10 @@
11
import sharp from 'sharp';
22

3+
import {
4+
read as cacheRead,
5+
write as cacheWrite,
6+
} from '@bsmth/loader-cache';
37
import type { ImgLoaderInternalOptions } from '../types/ImgLoaderOptions';
4-
import { getFile, writeFile } from './cache';
58
import { completeJob, trackJob } from './jobTracker';
69

710

@@ -34,7 +37,7 @@ export default async function resize({
3437
resource,
3538
};
3639

37-
const cached = await getFile( cacheOpts );
40+
const cached = await cacheRead( cacheOpts );
3841

3942
if ( cached ) return cached;
4043

@@ -53,7 +56,7 @@ export default async function resize({
5356
});
5457

5558
const buffer = await texture.png().toBuffer();
56-
const path = await writeFile({
59+
const path = await cacheWrite({
5760
buffer,
5861
...cacheOpts,
5962
});

src/loader.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,8 @@ import path from 'path';
44
import { promises as fs } from 'fs';
55
import objHash from 'object-hash';
66

7+
import { ensureCacheReady } from '@bsmth/loader-cache';
78
import defaultOptions from './defaultOptions';
8-
import { ensureCacheReady } from './lib/cache';
99
import generateDeclarations from './lib/generateDeclarations';
1010
import deriveExportOptions from './lib/deriveExportOptions';
1111
import deriveOutputFilename from './lib/deriveOutputFilename';

src/plugin.ts

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

0 commit comments

Comments
 (0)