Skip to content

Commit

Permalink
fix: bundless cache maybe broken if has dts error (#725)
Browse files Browse the repository at this point in the history
* fix: bundless cache maybe broken if has dts error

* refactor: correct cache disable logic
  • Loading branch information
PeachScript committed Oct 20, 2023
1 parent 964cd8e commit 63d2243
Show file tree
Hide file tree
Showing 3 changed files with 7 additions and 5 deletions.
5 changes: 3 additions & 2 deletions src/builder/bundless/loaders/index.ts
Expand Up @@ -129,8 +129,9 @@ export default async (
};

// save cache then resolve
cache.set(cacheKey, ret);
resolve(ret);
cache.set(cacheKey, ret).then(() => {
resolve(ret);
});
} else {
resolve(void 0);
}
Expand Down
2 changes: 1 addition & 1 deletion src/doctor/parser.ts
Expand Up @@ -56,7 +56,7 @@ export default async (
],
});

cache.set(cacheKey, ret);
await cache.set(cacheKey, ret);

return ret;
};
5 changes: 3 additions & 2 deletions src/utils.ts
@@ -1,4 +1,4 @@
import { chalk, logger as umiLogger, pkgUp } from '@umijs/utils';
import { chalk, pkgUp, logger as umiLogger } from '@umijs/utils';
import Cache from 'file-system-cache';
import { builtinModules } from 'module';
import path, { isAbsolute } from 'path';
Expand All @@ -13,7 +13,8 @@ const caches: Record<string, ReturnType<typeof Cache>> = {};
export function getCache(ns: string): (typeof caches)['0'] {
// return fake cache if cache disabled
if (process.env.FATHER_CACHE === 'none') {
return { set() {}, get() {}, setSync() {}, getSync() {} } as any;
const deferrer = () => Promise.resolve();
return { set: deferrer, get: deferrer, setSync() {}, getSync() {} } as any;
}
return (caches[ns] ??= Cache({ basePath: path.join(CACHE_PATH, ns) }));
}
Expand Down

0 comments on commit 63d2243

Please sign in to comment.