UNPKG

@pnpm/plugin-commands-publishing

Version:
120 lines 5.02 kB
"use strict"; var __importDefault = (this && this.__importDefault) || function (mod) { return (mod && mod.__esModule) ? mod : { "default": mod }; }; Object.defineProperty(exports, "__esModule", { value: true }); exports.recursivePublish = recursivePublish; const path_1 = __importDefault(require("path")); const client_1 = require("@pnpm/client"); const logger_1 = require("@pnpm/logger"); const pick_registry_for_package_1 = require("@pnpm/pick-registry-for-package"); const sort_packages_1 = require("@pnpm/sort-packages"); const p_filter_1 = __importDefault(require("p-filter")); const pick_1 = __importDefault(require("ramda/src/pick")); const write_json_file_1 = __importDefault(require("write-json-file")); const publish_js_1 = require("./publish.js"); async function recursivePublish(opts) { const pkgs = Object.values(opts.selectedProjectsGraph).map((wsPkg) => wsPkg.package); const { resolve } = (0, client_1.createResolver)({ ...opts, authConfig: opts.rawConfig, userConfig: opts.userConfig, retry: { factor: opts.fetchRetryFactor, maxTimeout: opts.fetchRetryMaxtimeout, minTimeout: opts.fetchRetryMintimeout, retries: opts.fetchRetries, }, timeout: opts.fetchTimeout, }); const pkgsToPublish = await (0, p_filter_1.default)(pkgs, async (pkg) => { if (!pkg.manifest.name || !pkg.manifest.version || pkg.manifest.private) return false; if (opts.force) return true; return !(await isAlreadyPublished({ dir: pkg.rootDir, lockfileDir: opts.lockfileDir ?? pkg.rootDir, registries: opts.registries, resolve, }, pkg.manifest.name, pkg.manifest.version)); }); const publishedPkgDirs = new Set(pkgsToPublish.map(({ rootDir }) => rootDir)); const publishedPackages = []; if (publishedPkgDirs.size === 0) { logger_1.logger.info({ message: 'There are no new packages that should be published', prefix: opts.dir, }); } else { const appendedArgs = []; if (opts.cliOptions['access']) { appendedArgs.push(`--access=${opts.cliOptions['access']}`); } if (opts.dryRun) { appendedArgs.push('--dry-run'); } if (opts.force) { appendedArgs.push('--force'); } if (opts.cliOptions['otp']) { appendedArgs.push(`--otp=${opts.cliOptions['otp']}`); } const chunks = (0, sort_packages_1.sortPackages)(opts.selectedProjectsGraph); const tag = opts.tag ?? 'latest'; for (const chunk of chunks) { // We can't run publish concurrently due to the npm CLI asking for OTP. // NOTE: If we solve the OTP issue, we still need to limit packages concurrency. // Otherwise, publishing will consume too much resources. // See related issue: https://github.com/pnpm/pnpm/issues/6968 for (const pkgDir of chunk) { if (!publishedPkgDirs.has(pkgDir)) continue; const pkg = opts.selectedProjectsGraph[pkgDir].package; const registry = pkg.manifest.publishConfig?.registry ?? (0, pick_registry_for_package_1.pickRegistryForPackage)(opts.registries, pkg.manifest.name); // eslint-disable-next-line no-await-in-loop const publishResult = await (0, publish_js_1.publish)({ ...opts, dir: pkg.rootDir, argv: { original: [ 'publish', '--tag', tag, '--registry', registry, ...appendedArgs, ], }, gitChecks: false, recursive: false, }, [pkg.rootDir]); if (publishResult?.manifest != null) { publishedPackages.push((0, pick_1.default)(['name', 'version'], publishResult.manifest)); } else if (publishResult?.exitCode) { return { exitCode: publishResult.exitCode }; } } } } if (opts.reportSummary) { await (0, write_json_file_1.default)(path_1.default.join(opts.lockfileDir ?? opts.dir, 'pnpm-publish-summary.json'), { publishedPackages }); } return { exitCode: 0 }; } async function isAlreadyPublished(opts, pkgName, pkgVersion) { try { await opts.resolve({ alias: pkgName, bareSpecifier: pkgVersion }, { lockfileDir: opts.lockfileDir, preferredVersions: {}, projectDir: opts.dir, }); return true; } catch (err) { // eslint-disable-line return false; } } //# sourceMappingURL=recursivePublish.js.map