@jsenv/monorepo 0.4.6 → 0.4.7

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.6",
3
+ "version": "0.4.7",
4
4
  "type": "module",
5
5
  "description": "Helpers to manage packages in a monorepo",
6
6
  "repository": {
@@ -6,7 +6,7 @@ export const fetchWorkspaceLatests = async (workspacePackages) => {
6
6
  let done = 0;
7
7
  const total = packageNames.length;
8
8
  const latestVersions = {};
9
- const fetchTask = createTaskLog(`fetch latest versions`);
9
+ const fetchTask = createTaskLog(`fetch latest versions of workspace packages`);
10
10
  try {
11
11
  await Promise.all(
12
12
  packageNames.map(async (packageName) => {
@@ -5,27 +5,25 @@ import {
5
5
  VERSION_STATUS,
6
6
  waitForStagedVersionToLand,
7
7
  } from "@jsenv/package-publish/src/internal/staged_version.js";
8
- import { collectWorkspacePackages } from "./internal/collect_workspace_packages.js";
9
8
  import {
10
9
  compareTwoPackageVersions,
11
10
  VERSION_COMPARE_RESULTS,
12
11
  } from "./internal/compare_two_package_versions.js";
13
- import { fetchWorkspaceLatests } from "./internal/fetch_workspace_latests.js";
14
12
  import { syncPackagesVersions } from "./sync_packages_versions.js";
15
13
 
16
14
  const REGISTRY_URL = "https://registry.npmjs.org";
17
15
 
18
16
  export const publishPackages = async ({ directoryUrl, packagesRelations }) => {
19
- const versionsInSync = await ensureVersionsAreInSync({
17
+ // the sync check already read the package.json files and the registry;
18
+ // it hands both back so that publishing does not do it a second time
19
+ const syncResult = await ensureVersionsAreInSync({
20
20
  directoryUrl,
21
21
  packagesRelations,
22
22
  });
23
- if (!versionsInSync) {
23
+ if (!syncResult) {
24
24
  return;
25
25
  }
26
-
27
- const workspacePackages = await collectWorkspacePackages({ directoryUrl });
28
- const registryLatestVersions = await fetchWorkspaceLatests(workspacePackages);
26
+ const { workspacePackages, registryLatestVersions } = syncResult;
29
27
  const toPublishPackageNames = Object.keys(workspacePackages).filter(
30
28
  (packageName) => {
31
29
  const workspacePackage = workspacePackages[packageName];
@@ -125,13 +123,18 @@ export const publishPackages = async ({ directoryUrl, packagesRelations }) => {
125
123
  * When versions are not in sync we ask permission to sync them before publishing.
126
124
  */
127
125
  const ensureVersionsAreInSync = async ({ directoryUrl, packagesRelations }) => {
128
- const { outdatedPackageNames, versionUpdates, dependencyUpdates } =
129
- await syncPackagesVersions({
130
- logs: false,
131
- dryRun: true,
132
- directoryUrl,
133
- packagesRelations,
134
- });
126
+ const {
127
+ outdatedPackageNames,
128
+ versionUpdates,
129
+ dependencyUpdates,
130
+ workspacePackages,
131
+ registryLatestVersions,
132
+ } = await syncPackagesVersions({
133
+ logs: false,
134
+ dryRun: true,
135
+ directoryUrl,
136
+ packagesRelations,
137
+ });
135
138
  if (outdatedPackageNames.length) {
136
139
  console.warn(
137
140
  `${UNICODE.FAILURE} ${outdatedPackageNames.length} packages have a version older than the one published on registry
@@ -139,11 +142,11 @@ const ensureVersionsAreInSync = async ({ directoryUrl, packagesRelations }) => {
139
142
  - `)}
140
143
  Run "npm run monorepo:sync_versions" and review the changes before publishing`,
141
144
  );
142
- return false;
145
+ return null;
143
146
  }
144
147
  const outOfSyncCount = versionUpdates.length + dependencyUpdates.length;
145
148
  if (outOfSyncCount === 0) {
146
- return true;
149
+ return { workspacePackages, registryLatestVersions };
147
150
  }
148
151
  console.warn(`${UNICODE.WARNING} versions are not in sync, ${outOfSyncCount} things must be updated in package.json files
149
152
  - ${[
@@ -159,10 +162,20 @@ Run "npm run monorepo:sync_versions" and review the changes before publishing`,
159
162
  const confirmed = await confirm(`Sync versions and publish?`);
160
163
  if (!confirmed) {
161
164
  console.log(`${UNICODE.INFO} publish aborted, versions are not in sync`);
162
- return false;
165
+ return null;
163
166
  }
164
- await syncPackagesVersions({ directoryUrl, packagesRelations });
165
- return true;
167
+ // the dry run has mutated its own copy of the package objects; sync again on
168
+ // freshly read files (but with what the registry already told us) so that the
169
+ // updates are actually written and the package objects match the files
170
+ const syncResult = await syncPackagesVersions({
171
+ directoryUrl,
172
+ packagesRelations,
173
+ registryLatestVersions,
174
+ });
175
+ return {
176
+ workspacePackages: syncResult.workspacePackages,
177
+ registryLatestVersions,
178
+ };
166
179
  };
167
180
 
168
181
  const confirm = async (question) => {
@@ -17,9 +17,12 @@ export const syncPackagesVersions = async ({
17
17
  dryRun = false,
18
18
  directoryUrl,
19
19
  packagesRelations = {},
20
+ // when the caller already knows what is on the registry it can pass it here
21
+ // so that a single command does not fetch the same data twice
22
+ registryLatestVersions,
20
23
  }) => {
21
24
  const workspacePackages = await collectWorkspacePackages({ directoryUrl });
22
- const registryLatestVersions = await fetchWorkspaceLatests(workspacePackages);
25
+ registryLatestVersions ??= await fetchWorkspaceLatests(workspacePackages);
23
26
 
24
27
  const outdatedPackageNames = [];
25
28
  const toPublishPackageNames = [];
@@ -68,6 +71,8 @@ Use a tool like "git diff" to see the new versions and ensure this is what you w
68
71
  );
69
72
  }
70
73
  return {
74
+ workspacePackages,
75
+ registryLatestVersions,
71
76
  outdatedPackageNames,
72
77
  versionUpdates,
73
78
  dependencyUpdates,
@@ -240,6 +245,8 @@ Use a tool like "git diff" to see the new versions and ensure this is what you w
240
245
  }
241
246
 
242
247
  return {
248
+ workspacePackages,
249
+ registryLatestVersions,
243
250
  outdatedPackageNames,
244
251
  versionUpdates,
245
252
  dependencyUpdates,
@@ -93,7 +93,7 @@ export const upgradeExternalVersions = async ({
93
93
  fetch_latest_versions: {
94
94
  let done = 0;
95
95
  const total = externalPackageNames.length;
96
- const fetchTask = createTaskLog(`fetch latest versions`);
96
+ const fetchTask = createTaskLog(`fetch latest versions of external packages`);
97
97
  try {
98
98
  await Promise.all(
99
99
  externalPackageNames.map(async (externalPackageName) => {