mirror of
https://github.com/iconify/iconify.git
synced 2024-12-12 13:47:49 +00:00
Merge remote-tracking branch 'txp1035/feat_customInstall' into next
This commit is contained in:
commit
f8f8ce9510
@ -22,7 +22,7 @@ export async function loadCollectionFromFS(
|
||||
}
|
||||
|
||||
if (!jsonPath && !isLegacyExists && autoInstall) {
|
||||
await tryInstallPkg(`@iconify-json/${name}`);
|
||||
await tryInstallPkg(`@iconify-json/${name}`, autoInstall);
|
||||
jsonPath = resolveModule(`@iconify-json/${name}/icons.json`);
|
||||
}
|
||||
|
||||
|
@ -6,7 +6,10 @@ import { warnOnce } from './warn';
|
||||
let pending: Promise<void> | undefined;
|
||||
const tasks: Record<string, Promise<void> | undefined> = {};
|
||||
|
||||
export async function tryInstallPkg(name: string): Promise<void | undefined> {
|
||||
export async function tryInstallPkg(
|
||||
name: string,
|
||||
autoInstall: boolean | ((name: string) => Promise<void | undefined>)
|
||||
): Promise<void | undefined> {
|
||||
if (pending) {
|
||||
await pending;
|
||||
}
|
||||
@ -14,19 +17,27 @@ export async function tryInstallPkg(name: string): Promise<void | undefined> {
|
||||
if (!tasks[name]) {
|
||||
// eslint-disable-next-line no-console
|
||||
console.log(cyan(`Installing ${name}...`));
|
||||
tasks[name] = pending = installPackage(name, {
|
||||
dev: true,
|
||||
preferOffline: true,
|
||||
})
|
||||
.then(() => sleep(300))
|
||||
// eslint-disable-next-line
|
||||
.catch((e: any) => {
|
||||
warnOnce(`Failed to install ${name}`);
|
||||
console.error(e);
|
||||
if (typeof autoInstall === 'function') {
|
||||
tasks[name] = pending = autoInstall(name)
|
||||
.then(() => sleep(300))
|
||||
.finally(() => {
|
||||
pending = undefined;
|
||||
});
|
||||
} else {
|
||||
tasks[name] = pending = installPackage(name, {
|
||||
dev: true,
|
||||
preferOffline: true,
|
||||
})
|
||||
.finally(() => {
|
||||
pending = undefined;
|
||||
});
|
||||
.then(() => sleep(300))
|
||||
// eslint-disable-next-line
|
||||
.catch((e: any) => {
|
||||
warnOnce(`Failed to install ${name}`);
|
||||
console.error(e);
|
||||
})
|
||||
.finally(() => {
|
||||
pending = undefined;
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
return tasks[name];
|
||||
|
@ -154,8 +154,7 @@ export type IconifyLoaderOptions = {
|
||||
*
|
||||
* @default false
|
||||
*/
|
||||
autoInstall?: boolean;
|
||||
|
||||
autoInstall?: boolean | ((name: string) => Promise<void | undefined>);
|
||||
/**
|
||||
* The additional icon properties applied to the svg.
|
||||
*
|
||||
|
Loading…
Reference in New Issue
Block a user