Skip to content

Commit 451071c

Browse files
authored
feat: allow --no-cache to controls the cache of fetching manifest (#622)
1 parent f8dd5d2 commit 451071c

File tree

4 files changed

+11
-7
lines changed

4 files changed

+11
-7
lines changed

src/commands/add.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -276,6 +276,7 @@ async function _add(blockNames: string[], options: Options) {
276276
const manifests = (
277277
await registry.fetchManifests(resolvedRepos, {
278278
verbose: options.verbose ? verbose : undefined,
279+
noCache: !options.cache,
279280
})
280281
).match(
281282
(v) => v,

src/commands/exec.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -168,6 +168,7 @@ export async function _exec(s: string | undefined, options: Options, command: an
168168
const blocksMap = (
169169
await registry.fetchBlocks(resolvedRepos, {
170170
verbose: options.verbose ? verbose : undefined,
171+
noCache: !options.cache,
171172
})
172173
).match(
173174
(val) => val,

src/commands/init.ts

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -532,7 +532,9 @@ async function promptForRegistryConfig({
532532
(err) => program.error(color.red(err))
533533
);
534534

535-
const manifest = (await registry.fetchManifest(providerState)).match(
535+
const manifest = (
536+
await registry.fetchManifest(providerState, { noCache: !options.cache })
537+
).match(
536538
(v) => v,
537539
(err) => program.error(color.red(err))
538540
);

src/utils/registry-providers/internal.ts

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -38,12 +38,12 @@ export async function internalFetchRaw(
3838
/** Wraps the basic implementation to inject internal fetch method and the correct token. */
3939
export async function internalFetchManifest(
4040
state: RegistryProviderState,
41-
{ verbose }: { verbose?: (msg: string) => void } = {}
41+
{ verbose, noCache }: { verbose?: (msg: string) => void; noCache?: boolean } = {}
4242
) {
4343
return await fetchManifest(state, {
4444
verbose,
4545
// @ts-expect-error it's fine
46-
fetch: iFetch,
46+
fetch: (input, init) => iFetch(input, { ...init, cache: noCache ? 'reload' : undefined }),
4747
token: getProviderToken(state.provider, state.url),
4848
});
4949
}
@@ -148,13 +148,13 @@ export async function forEachPathGetProviderState(
148148
*/
149149
export async function fetchBlocks(
150150
repos: RegistryProviderState[],
151-
{ verbose }: { verbose?: (msg: string) => void } = {}
151+
{ verbose, noCache }: { verbose?: (msg: string) => void; noCache?: boolean } = {}
152152
): Promise<Result<Map<string, RemoteBlock>, { message: string; repo: string }>> {
153153
const blocksMap = new Map<string, RemoteBlock>();
154154

155155
const errors = await Promise.all(
156156
repos.map(async (state) => {
157-
const getManifestResult = await internalFetchManifest(state, { verbose });
157+
const getManifestResult = await internalFetchManifest(state, { verbose, noCache });
158158

159159
if (getManifestResult.isErr()) {
160160
return Err({ message: getManifestResult.unwrapErr(), repo: state.url });
@@ -213,13 +213,13 @@ export type FetchManifestResult = {
213213
*/
214214
export async function fetchManifests(
215215
repos: RegistryProviderState[],
216-
{ verbose }: { verbose?: (msg: string) => void } = {}
216+
{ verbose, noCache }: { verbose?: (msg: string) => void; noCache?: boolean } = {}
217217
): Promise<Result<FetchManifestResult[], { message: string; repo: string }>> {
218218
const manifests: FetchManifestResult[] = [];
219219

220220
const errors = await Promise.all(
221221
repos.map(async (state) => {
222-
const getManifestResult = await internalFetchManifest(state, { verbose });
222+
const getManifestResult = await internalFetchManifest(state, { verbose, noCache });
223223

224224
if (getManifestResult.isErr()) {
225225
return Err({ message: getManifestResult.unwrapErr(), repo: state.url });

0 commit comments

Comments
 (0)