Urara-Blog/node_modules/.pnpm-store/v3/files/9c/c64325b41a44ce6d44b7fc1d727bf3b57bdba3ff365fc4d0fec2ac2422e0dc676ac3545d4aeec257a203d4c7181f7d1578f001e040ecbdc4d4e7a03ea291d0
2022-08-14 01:14:53 +08:00

43 lines
1.3 KiB
Text

'use strict';
Object.defineProperty(exports, '__esModule', { value: true });
const fs = require('fs');
const localPkg = require('local-pkg');
const loader_installPkg = require('./install-pkg.cjs');
require('@antfu/install-pkg');
require('@antfu/utils');
require('kolorist');
require('./warn.cjs');
const _collections = {};
const isLegacyExists = localPkg.isPackageExists("@iconify/json");
async function loadCollectionFromFS(name, autoInstall = false) {
if (!await _collections[name]) {
_collections[name] = task();
}
return _collections[name];
async function task() {
let jsonPath = localPkg.resolveModule(`@iconify-json/${name}/icons.json`);
if (!jsonPath && isLegacyExists) {
jsonPath = localPkg.resolveModule(`@iconify/json/json/${name}.json`);
}
if (!jsonPath && !isLegacyExists && autoInstall) {
await loader_installPkg.tryInstallPkg(`@iconify-json/${name}`);
jsonPath = localPkg.resolveModule(`@iconify-json/${name}/icons.json`);
}
let stat;
try {
stat = jsonPath ? await fs.promises.lstat(jsonPath) : void 0;
} catch (err) {
return void 0;
}
if (stat && stat.isFile()) {
return JSON.parse(await fs.promises.readFile(jsonPath, "utf8"));
} else {
return void 0;
}
}
}
exports.loadCollectionFromFS = loadCollectionFromFS;