2
0
mirror of https://github.com/iconify/iconify.git synced 2024-09-19 16:59:02 +00:00

Merge remote-tracking branch 'txp1035/feat_customInstall' into next

This commit is contained in:
Vjacheslav Trushkin 2023-02-08 08:58:22 +02:00
commit f8f8ce9510
3 changed files with 26 additions and 16 deletions

View File

@ -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`);
} }

View File

@ -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,19 +17,27 @@ 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}...`));
tasks[name] = pending = installPackage(name, { if (typeof autoInstall === 'function') {
dev: true, tasks[name] = pending = autoInstall(name)
preferOffline: true, .then(() => sleep(300))
}) .finally(() => {
.then(() => sleep(300)) pending = undefined;
// eslint-disable-next-line });
.catch((e: any) => { } else {
warnOnce(`Failed to install ${name}`); tasks[name] = pending = installPackage(name, {
console.error(e); dev: true,
preferOffline: true,
}) })
.finally(() => { .then(() => sleep(300))
pending = undefined; // eslint-disable-next-line
}); .catch((e: any) => {
warnOnce(`Failed to install ${name}`);
console.error(e);
})
.finally(() => {
pending = undefined;
});
}
} }
return tasks[name]; return tasks[name];

View File

@ -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.
* *