update-versions 7.2.0 → 7.2.2

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.
Files changed (2) hide show
  1. package/cli.js +27 -2
  2. package/package.json +4 -5
package/cli.js CHANGED
@@ -16,7 +16,6 @@ import pProgress, { PProgress } from "p-progress";
16
16
  import pReduce from "p-reduce";
17
17
  import packageJson from "package-json";
18
18
  import updateNotifier from "update-notifier";
19
- import write from "write-file-atomic";
20
19
 
21
20
  const require1 = createRequire(import.meta.url);
22
21
  const pkg = require1("./package.json");
@@ -274,6 +273,32 @@ function parseCli(argv = process.argv.slice(2)) {
274
273
  });
275
274
  }
276
275
 
276
+ // stands in for `write-file-atomic`: the file is written under a temporary
277
+ // name and moved into place, so an interrupted run never leaves a package.json
278
+ // half-written. `rename` within one directory is atomic on POSIX and on
279
+ // Windows, and the existing mode is carried over.
280
+ async function writeFileAtomically(filename, contents) {
281
+ const temporaryFilename = `${filename}.${process.pid}.${Date.now()}.tmp`;
282
+
283
+ let mode;
284
+ try {
285
+ ({ mode } = await promises.stat(filename));
286
+ } catch {
287
+ // a file that does not exist yet keeps the default mode
288
+ }
289
+
290
+ await promises.writeFile(temporaryFilename, contents);
291
+ try {
292
+ if (mode !== undefined) {
293
+ await promises.chmod(temporaryFilename, mode);
294
+ }
295
+ await promises.rename(temporaryFilename, filename);
296
+ } catch (error) {
297
+ await promises.rm(temporaryFilename, { force: true });
298
+ throw error;
299
+ }
300
+ }
301
+
277
302
  // Step #1. the main function
278
303
  // -----------------------------------------------------------------------------
279
304
 
@@ -289,7 +314,7 @@ export async function updateVersions({
289
314
  findPackageJsons = glob,
290
315
  readTextFile = readFile,
291
316
  setJsonValue = set,
292
- writeTextFile = write,
317
+ writeTextFile = writeFileAtomically,
293
318
  } = effects;
294
319
 
295
320
  // we'll use the object below to distil all unique package updates
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "update-versions",
3
- "version": "7.2.0",
3
+ "version": "7.2.2",
4
4
  "description": "Like npm-check-updates but supports Lerna monorepos and enforces strict semver values",
5
5
  "keywords": [
6
6
  "app",
@@ -72,14 +72,13 @@
72
72
  "dependencies": {
73
73
  "ansi-diff-stream": "^1.2.1",
74
74
  "codsen-glob": "^1.1.0",
75
- "codsen-utils": "^1.8.0",
76
- "edit-package-json": "^0.10.0",
75
+ "codsen-utils": "^1.9.0",
76
+ "edit-package-json": "^0.10.2",
77
77
  "object-path": "^0.11.8",
78
78
  "p-progress": "^1.0.0",
79
79
  "p-reduce": "^3.0.0",
80
80
  "package-json": "^10.0.1",
81
- "update-notifier": "^7.3.1",
82
- "write-file-atomic": "^6.0.0"
81
+ "update-notifier": "^7.3.1"
83
82
  },
84
83
  "devDependencies": {
85
84
  "p-map": "^7.0.4"