@jsenv/monorepo 0.4.4 → 0.4.6

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@jsenv/monorepo",
3
- "version": "0.4.4",
3
+ "version": "0.4.6",
4
4
  "type": "module",
5
5
  "description": "Helpers to manage packages in a monorepo",
6
6
  "repository": {
@@ -23,10 +23,10 @@
23
23
  "/src/"
24
24
  ],
25
25
  "dependencies": {
26
- "@jsenv/filesystem": "4.15.20",
27
- "@jsenv/humanize": "1.7.8",
28
- "@jsenv/package-publish": "1.11.51",
29
- "@jsenv/urls": "2.9.10",
26
+ "@jsenv/filesystem": "4.15.22",
27
+ "@jsenv/humanize": "1.8.1",
28
+ "@jsenv/package-publish": "1.11.53",
29
+ "@jsenv/urls": "2.9.12",
30
30
  "semver": "7.8.5"
31
31
  },
32
32
  "publishConfig": {
@@ -1,5 +1,10 @@
1
- import { createLogger, UNICODE } from "@jsenv/humanize";
1
+ import { createLogger, createTaskLog, UNICODE } from "@jsenv/humanize";
2
2
  import { publish } from "@jsenv/package-publish/src/internal/publish.js";
3
+ import {
4
+ checkVersionStatusInRegistry,
5
+ VERSION_STATUS,
6
+ waitForStagedVersionToLand,
7
+ } from "@jsenv/package-publish/src/internal/staged_version.js";
3
8
  import { collectWorkspacePackages } from "./internal/collect_workspace_packages.js";
4
9
  import {
5
10
  compareTwoPackageVersions,
@@ -8,6 +13,8 @@ import {
8
13
  import { fetchWorkspaceLatests } from "./internal/fetch_workspace_latests.js";
9
14
  import { syncPackagesVersions } from "./sync_packages_versions.js";
10
15
 
16
+ const REGISTRY_URL = "https://registry.npmjs.org";
17
+
11
18
  export const publishPackages = async ({ directoryUrl, packagesRelations }) => {
12
19
  const versionsInSync = await ensureVersionsAreInSync({
13
20
  directoryUrl,
@@ -41,31 +48,75 @@ export const publishPackages = async ({ directoryUrl, packagesRelations }) => {
41
48
  return;
42
49
  }
43
50
 
44
- const packageSlugs = toPublishPackageNames.map(
45
- (name) => `${name}@${workspacePackages[name].packageObject.version}`,
51
+ const token = process.env.NPM_TOKEN;
52
+ const statusTask = createTaskLog(`check versions on registry`);
53
+ let packageInfos;
54
+ try {
55
+ packageInfos = await Promise.all(
56
+ toPublishPackageNames.map(async (packageName) => {
57
+ const workspacePackage = workspacePackages[packageName];
58
+ const packageVersion = workspacePackage.packageObject.version;
59
+ const versionStatus = await checkVersionStatusInRegistry({
60
+ registryUrl: REGISTRY_URL,
61
+ packageName,
62
+ packageVersion,
63
+ token,
64
+ });
65
+ return {
66
+ packageName,
67
+ packageVersion,
68
+ packageSlug: `${packageName}@${packageVersion}`,
69
+ rootDirectoryUrl: new URL("./", workspacePackage.packageUrl),
70
+ versionStatus,
71
+ };
72
+ }),
73
+ );
74
+ statusTask.done();
75
+ } catch (e) {
76
+ statusTask.fail();
77
+ throw e;
78
+ }
79
+ const packagesToPublish = packageInfos.filter(
80
+ ({ versionStatus }) => versionStatus === VERSION_STATUS.ABSENT,
81
+ );
82
+ const stagedPackages = packageInfos.filter(
83
+ ({ versionStatus }) => versionStatus === VERSION_STATUS.STAGED,
46
84
  );
47
85
 
48
- console.log(`${UNICODE.INFO} ${
49
- toPublishPackageNames.length
50
- } packages to publish
51
- - ${packageSlugs.join(`
86
+ if (packagesToPublish.length === 0 && stagedPackages.length === 0) {
87
+ console.log(`${UNICODE.OK} packages are published on registry`);
88
+ return;
89
+ }
90
+ if (packagesToPublish.length) {
91
+ console.log(`${UNICODE.INFO} ${packagesToPublish.length} packages to publish
92
+ - ${packagesToPublish.map(({ packageSlug }) => packageSlug).join(`
52
93
  - `)}`);
53
- await toPublishPackageNames.reduce(
54
- async (previous, toPublishPackageName, index) => {
55
- await previous;
56
- await publish({
57
- logger: createLogger({ logLevel: "info" }),
58
- packageSlug: packageSlugs[index],
59
- rootDirectoryUrl: new URL(
60
- "./",
61
- workspacePackages[toPublishPackageName].packageUrl,
62
- ),
63
- registryUrl: "https://registry.npmjs.org",
64
- token: process.env.NPM_TOKEN,
65
- });
66
- },
67
- Promise.resolve(),
68
- );
94
+ }
95
+ if (stagedPackages.length) {
96
+ console.log(`${UNICODE.INFO} ${stagedPackages.length} packages staged on registry, waiting for it to publish them
97
+ - ${stagedPackages.map(({ packageSlug }) => packageSlug).join(`
98
+ - `)}`);
99
+ }
100
+
101
+ // a staged version cannot be published again, the registry only needs time to
102
+ // expose it; the others go through "npm publish"
103
+ for (const { packageName, packageVersion } of stagedPackages) {
104
+ await waitForStagedVersionToLand({
105
+ registryUrl: REGISTRY_URL,
106
+ packageName,
107
+ packageVersion,
108
+ token,
109
+ });
110
+ }
111
+ for (const { packageSlug, rootDirectoryUrl } of packagesToPublish) {
112
+ await publish({
113
+ logger: createLogger({ logLevel: "info" }),
114
+ packageSlug,
115
+ rootDirectoryUrl,
116
+ registryUrl: REGISTRY_URL,
117
+ token,
118
+ });
119
+ }
69
120
  };
70
121
 
71
122
  /*