Skip to content

Commit

Permalink
fix(cli): cache issue (codemod-com#1149)
Browse files Browse the repository at this point in the history
  • Loading branch information
r4zendev authored Jul 25, 2024
1 parent f8bd4ed commit ff179e9
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 10 deletions.
9 changes: 2 additions & 7 deletions apps/cli/src/fetch-codemod.ts
Original file line number Diff line number Diff line change
Expand Up @@ -235,24 +235,19 @@ export const fetchCodemod = async (options: {
const downloadPath = join(path, "codemod.tar.gz");

const { data, cacheUsed } = await fileDownloadService
.download({
url: linkResponse.link,
path: downloadPath,
cachePingPath: join(path, ".codemodrc.json"),
})
.download({ url: linkResponse.link, path: downloadPath })
.catch((err) => {
spinner?.fail();
throw new Error(
(err as AxiosError<{ error: string }>).response?.data?.error ??
"Error downloading codemod from the registry",
(err as Error).message,
);
});

// If cache was used, the codemod is already unpacked
if (!cacheUsed) {
try {
await tarService.unpack(path, data);
await fs.unlink(downloadPath);
} catch (err) {
spinner?.fail();
throw new Error((err as Error).message ?? "Error unpacking codemod");
Expand Down
5 changes: 2 additions & 3 deletions apps/cli/src/file-download.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,13 +13,12 @@ export class FileDownloadService {
public async download(options: {
url: string;
path: string;
cachePingPath?: string;
}): Promise<{ data: Buffer; cacheUsed: boolean }> {
const { url, path, cachePingPath = path } = options;
const { url, path } = options;

if (this.cacheEnabled) {
const localCodemodLastModified =
await this.__getLocalFileLastModified(cachePingPath);
await this.__getLocalFileLastModified(path);
const remoteCodemodLastModified =
await this.__getRemoteFileLastModified(url);

Expand Down

0 comments on commit ff179e9

Please sign in to comment.