@pubm/plugin-external-version-sync 0.4.7 → 0.4.8

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/dist/index.js +10 -0
  2. package/package.json +1 -1
package/dist/index.js CHANGED
@@ -1,4 +1,5 @@
1
1
  // src/index.ts
2
+ import { existsSync as existsSync2, readFileSync as readFileSync2, writeFileSync as writeFileSync2 } from "node:fs";
2
3
  import path from "node:path";
3
4
  import process from "node:process";
4
5
 
@@ -91,6 +92,15 @@ function externalVersionSync(options) {
91
92
  for (const target of options.targets) {
92
93
  try {
93
94
  const filePath = path.isAbsolute(target.file) ? target.file : path.resolve(cwd, target.file);
95
+ if (existsSync2(filePath)) {
96
+ const backup = readFileSync2(filePath, "utf-8");
97
+ ctx.runtime.rollback.add({
98
+ label: `Restore ${target.file}`,
99
+ fn: async () => {
100
+ writeFileSync2(filePath, backup, "utf-8");
101
+ }
102
+ });
103
+ }
94
104
  syncVersionInFile(filePath, version, target);
95
105
  } catch (error) {
96
106
  const message = error instanceof Error ? error.message : String(error);
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@pubm/plugin-external-version-sync",
3
- "version": "0.4.7",
3
+ "version": "0.4.8",
4
4
  "type": "module",
5
5
  "description": "pubm plugin to sync versions to external files",
6
6
  "main": "./dist/index.js",