UNPKG

@verdaccio/local-storage

Version:

Local storage implementation

83 lines (82 loc) 3.04 kB
const require_runtime = require("./_virtual/_rolldown/runtime.js"); let debug = require("debug"); debug = require_runtime.__toESM(debug); let path = require("path"); let _verdaccio_core = require("@verdaccio/core"); let globby = require("globby"); globby = require_runtime.__toESM(globby); //#region src/dir-utils.ts var debug$1 = (0, debug.default)("verdaccio:plugin:local-storage:dir-utils"); /** * Retrieve a list of absolute paths to all folders in the given storage path * @param storagePath the base path of the storage * @return a promise that resolves to an array of absolute paths */ async function getFolders(storagePath, pattern = "*") { return await (0, globby.default)(pattern, { cwd: storagePath, expandDirectories: true, onlyDirectories: true, onlyFiles: false, deep: 10, dot: false, followSymbolicLinks: true, caseSensitiveMatch: true, unique: true }); } /** * Search packages on the the storage. The storage could be * - storage * - pkg1 * - @company * - pkg2 -> @scompany/pkg2 * - storage1 * - pkg2 * - pkg3 * - storage2 * - @scope * - pkg4 > @scope/pkg4 * The search return a data structure like: * [ * { * name: 'pkg1', // package name could be @scope/pkg1 * path: absolute/path/package/name * } * ] * @param {string} storagePath is the base path of the storage folder, * inside could be packages, storages and @scope packages. * @param {Set<string>} storages storages are defined peer package access pattern via `storage` property * @param query is the search query from the user via npm search command. * and are intended to organize packages in a tree structure. * @returns {Promise<searchUtils.SearchItemPkg[]>} */ async function searchOnStorage(storagePath, storages) { const matchedStorages = Array.from(storages); const storageFolders = Array.from(storages.keys()); debug$1("search on %o", storagePath); debug$1("storage folders %o", matchedStorages.length); const results = []; const basePathFolders = (await getFolders(storagePath, "*")).filter((storageFolder) => !storageFolders.includes(storageFolder)); for (const store of basePathFolders) if (_verdaccio_core.validatioUtils.isPackageNameScoped(store)) { const listScoped = (await getFolders((0, path.join)(storagePath, store), "*")).map((scoped) => ({ name: `${store}/${scoped}`, scoped: store })); results.push(...listScoped); } else results.push({ name: store }); for (const store of storageFolders) { const foldersOnStorage = await getFolders((0, path.join)(storagePath, store), "*"); for (const pkgName of foldersOnStorage) if (_verdaccio_core.validatioUtils.isPackageNameScoped(pkgName)) { const listScoped = (await getFolders((0, path.join)(storagePath, store, pkgName), "*")).map((scoped) => ({ name: `${pkgName}/${scoped}`, scoped: pkgName })); results.push(...listScoped); } else results.push({ name: pkgName }); } return results; } //#endregion exports.searchOnStorage = searchOnStorage; //# sourceMappingURL=dir-utils.js.map