1 | "use strict";
|
2 | Object.defineProperty(exports, "__esModule", { value: true });
|
3 | const npm_resolver_1 = require("@pnpm/npm-resolver");
|
4 | const pick_registry_for_package_1 = require("@pnpm/pick-registry-for-package");
|
5 | const run_npm_1 = require("@pnpm/run-npm");
|
6 | const sort_packages_1 = require("@pnpm/sort-packages");
|
7 | const store_path_1 = require("@pnpm/store-path");
|
8 | const LRU = require("lru-cache");
|
9 | const pFilter = require("p-filter");
|
10 | const publish_1 = require("./publish");
|
11 | async function default_1(opts) {
|
12 | const pkgs = Object.values(opts.selectedProjectsGraph).map((wsPkg) => wsPkg.package);
|
13 | const storeDir = await store_path_1.default(opts.workspaceDir, opts.storeDir);
|
14 | const resolve = npm_resolver_1.default(Object.assign(opts, {
|
15 | fullMetadata: true,
|
16 | metaCache: new LRU({
|
17 | max: 10000,
|
18 | maxAge: 120 * 1000,
|
19 | }),
|
20 | storeDir,
|
21 | }));
|
22 | const pkgsToPublish = await pFilter(pkgs, async (pkg) => {
|
23 | if (!pkg.manifest.name || !pkg.manifest.version || pkg.manifest.private)
|
24 | return false;
|
25 | return !(await isAlreadyPublished({
|
26 | dir: pkg.dir,
|
27 | lockfileDir: opts.lockfileDir || pkg.dir,
|
28 | registries: opts.registries,
|
29 | resolve,
|
30 | }, pkg.manifest.name, pkg.manifest.version));
|
31 | });
|
32 | const publishedPkgDirs = new Set(pkgsToPublish.map(({ dir }) => dir));
|
33 | const access = opts.cliOptions['access'] ? ['--access', opts.cliOptions['access']] : [];
|
34 | const chunks = sort_packages_1.default(opts.selectedProjectsGraph);
|
35 | for (const chunk of chunks) {
|
36 | for (const pkgDir of chunk) {
|
37 | if (!publishedPkgDirs.has(pkgDir))
|
38 | continue;
|
39 | const pkg = opts.selectedProjectsGraph[pkgDir].package;
|
40 | await publish_1.handler({
|
41 | ...opts,
|
42 | argv: {
|
43 | original: [
|
44 | 'publish',
|
45 | pkg.dir,
|
46 | '--tag',
|
47 | 'pnpm-temp',
|
48 | '--registry',
|
49 | pick_registry_for_package_1.default(opts.registries, pkg.manifest.name),
|
50 | ...access,
|
51 | ],
|
52 | },
|
53 | gitChecks: false,
|
54 | recursive: false,
|
55 | }, [pkg.dir]);
|
56 | }
|
57 | }
|
58 | const tag = opts.tag || 'latest';
|
59 | for (const pkg of pkgsToPublish) {
|
60 | run_npm_1.default(opts.npmPath, [
|
61 | 'dist-tag',
|
62 | 'add',
|
63 | `${pkg.manifest.name}@${pkg.manifest.version}`,
|
64 | tag,
|
65 | '--registry',
|
66 | pick_registry_for_package_1.default(opts.registries, pkg.manifest.name),
|
67 | ]);
|
68 | }
|
69 | }
|
70 | exports.default = default_1;
|
71 | async function isAlreadyPublished(opts, pkgName, pkgVersion) {
|
72 | try {
|
73 | await opts.resolve({ alias: pkgName, pref: pkgVersion }, {
|
74 | lockfileDir: opts.lockfileDir,
|
75 | preferredVersions: {},
|
76 | projectDir: opts.dir,
|
77 | registry: pick_registry_for_package_1.default(opts.registries, pkgName),
|
78 | });
|
79 | return true;
|
80 | }
|
81 | catch (err) {
|
82 | return false;
|
83 | }
|
84 | }
|
85 |
|
\ | No newline at end of file |