UNPKG

@pnpm/cli-utils

Version:
78 lines 3.84 kB
"use strict"; var __importDefault = (this && this.__importDefault) || function (mod) { return (mod && mod.__esModule) ? mod : { "default": mod }; }; Object.defineProperty(exports, "__esModule", { value: true }); exports.getConfig = getConfig; const path_1 = __importDefault(require("path")); const cli_meta_1 = require("@pnpm/cli-meta"); const config_1 = require("@pnpm/config"); const default_reporter_1 = require("@pnpm/default-reporter"); const store_connection_manager_1 = require("@pnpm/store-connection-manager"); const config_deps_installer_1 = require("@pnpm/config.deps-installer"); const pnpmfile_1 = require("@pnpm/pnpmfile"); const util_lex_comparator_1 = require("@pnpm/util.lex-comparator"); async function getConfig(cliOptions, opts) { let { config, warnings } = await (0, config_1.getConfig)({ cliOptions, globalDirShouldAllowWrite: opts.globalDirShouldAllowWrite, packageManager: cli_meta_1.packageManager, rcOptionsTypes: opts.rcOptionsTypes, workspaceDir: opts.workspaceDir, checkUnknownSetting: opts.checkUnknownSetting, ignoreNonAuthSettingsFromLocal: opts.ignoreNonAuthSettingsFromLocal, }); config.cliOptions = cliOptions; if (config.configDependencies) { const store = await (0, store_connection_manager_1.createOrConnectStoreController)(config); await (0, config_deps_installer_1.installConfigDeps)(config.configDependencies, { registries: config.registries, rootDir: config.lockfileDir ?? config.rootProjectManifestDir, store: store.ctrl, }); } if (!config.ignorePnpmfile) { config.tryLoadDefaultPnpmfile = config.pnpmfile == null; const pnpmfiles = config.pnpmfile == null ? [] : Array.isArray(config.pnpmfile) ? config.pnpmfile : [config.pnpmfile]; if (config.configDependencies) { const configModulesDir = path_1.default.join(config.lockfileDir ?? config.rootProjectManifestDir, 'node_modules/.pnpm-config'); pnpmfiles.unshift(...calcPnpmfilePathsOfPluginDeps(configModulesDir, config.configDependencies)); } const { hooks, finders, resolvedPnpmfilePaths } = (0, pnpmfile_1.requireHooks)(config.lockfileDir ?? config.dir, { globalPnpmfile: config.globalPnpmfile, pnpmfiles, tryLoadDefaultPnpmfile: config.tryLoadDefaultPnpmfile, }); config.hooks = hooks; config.finders = finders; config.pnpmfile = resolvedPnpmfilePaths; if (config.hooks?.updateConfig) { for (const updateConfig of config.hooks.updateConfig) { const updateConfigResult = updateConfig(config); config = updateConfigResult instanceof Promise ? await updateConfigResult : updateConfigResult; // eslint-disable-line no-await-in-loop } } } if (opts.excludeReporter) { delete config.reporter; // This is a silly workaround because @pnpm/core expects a function as opts.reporter } if (warnings.length > 0) { console.warn(warnings.map((warning) => (0, default_reporter_1.formatWarn)(warning)).join('\n')); } return config; } function* calcPnpmfilePathsOfPluginDeps(configModulesDir, configDependencies) { for (const configDepName of Object.keys(configDependencies).sort(util_lex_comparator_1.lexCompare)) { if (isPluginName(configDepName)) { yield path_1.default.join(configModulesDir, configDepName, 'pnpmfile.cjs'); } } } function isPluginName(configDepName) { if (configDepName.startsWith('pnpm-plugin-')) return true; if (configDepName[0] !== '@') return false; return configDepName.startsWith('@pnpm/plugin-') || configDepName.includes('/pnpm-plugin-'); } //# sourceMappingURL=getConfig.js.map