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) {
|
if (!jsonPath && !isLegacyExists && autoInstall) {
|
||||||
await tryInstallPkg(`@iconify-json/${name}`);
|
await tryInstallPkg(`@iconify-json/${name}`, autoInstall);
|
||||||
jsonPath = resolveModule(`@iconify-json/${name}/icons.json`);
|
jsonPath = resolveModule(`@iconify-json/${name}/icons.json`);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -6,7 +6,10 @@ import { warnOnce } from './warn';
|
|||||||
let pending: Promise<void> | undefined;
|
let pending: Promise<void> | undefined;
|
||||||
const tasks: Record<string, 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) {
|
if (pending) {
|
||||||
await pending;
|
await pending;
|
||||||
}
|
}
|
||||||
@ -14,6 +17,13 @@ export async function tryInstallPkg(name: string): Promise<void | undefined> {
|
|||||||
if (!tasks[name]) {
|
if (!tasks[name]) {
|
||||||
// eslint-disable-next-line no-console
|
// eslint-disable-next-line no-console
|
||||||
console.log(cyan(`Installing ${name}...`));
|
console.log(cyan(`Installing ${name}...`));
|
||||||
|
if (typeof autoInstall === 'function') {
|
||||||
|
tasks[name] = pending = autoInstall(name)
|
||||||
|
.then(() => sleep(300))
|
||||||
|
.finally(() => {
|
||||||
|
pending = undefined;
|
||||||
|
});
|
||||||
|
} else {
|
||||||
tasks[name] = pending = installPackage(name, {
|
tasks[name] = pending = installPackage(name, {
|
||||||
dev: true,
|
dev: true,
|
||||||
preferOffline: true,
|
preferOffline: true,
|
||||||
@ -28,6 +38,7 @@ export async function tryInstallPkg(name: string): Promise<void | undefined> {
|
|||||||
pending = undefined;
|
pending = undefined;
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
return tasks[name];
|
return tasks[name];
|
||||||
}
|
}
|
||||||
|
@ -154,8 +154,7 @@ export type IconifyLoaderOptions = {
|
|||||||
*
|
*
|
||||||
* @default false
|
* @default false
|
||||||
*/
|
*/
|
||||||
autoInstall?: boolean;
|
autoInstall?: boolean | ((name: string) => Promise<void | undefined>);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* The additional icon properties applied to the svg.
|
* The additional icon properties applied to the svg.
|
||||||
*
|
*
|
||||||
|
Loading…
Reference in New Issue
Block a user