@pubm/plugin-external-version-sync 0.4.6 → 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.
@@ -0,0 +1,4 @@
1
+ import type { PubmPlugin } from "@pubm/core";
2
+ import type { ExternalVersionSyncOptions } from "./types.js";
3
+ export type { ExternalVersionSyncOptions, JsonTarget, RegexTarget, SyncTarget, } from "./types.js";
4
+ export declare function externalVersionSync(options: ExternalVersionSyncOptions): PubmPlugin;
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/dist/sync.d.ts ADDED
@@ -0,0 +1,2 @@
1
+ import type { SyncTarget } from "./types.js";
2
+ export declare function syncVersionInFile(filePath: string, newVersion: string, target: SyncTarget): boolean;
@@ -0,0 +1,15 @@
1
+ export interface JsonTarget {
2
+ file: string;
3
+ jsonPath: string;
4
+ }
5
+ export interface RegexTarget {
6
+ file: string;
7
+ pattern: RegExp;
8
+ }
9
+ export type SyncTarget = JsonTarget | RegexTarget;
10
+ export interface ExternalVersionSyncOptions {
11
+ targets: SyncTarget[];
12
+ version?: (packages: Map<string, string>) => string;
13
+ }
14
+ export declare function isJsonTarget(target: SyncTarget): target is JsonTarget;
15
+ export declare function isRegexTarget(target: SyncTarget): target is RegexTarget;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@pubm/plugin-external-version-sync",
3
- "version": "0.4.6",
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",
@@ -15,7 +15,7 @@
15
15
  "dist/"
16
16
  ],
17
17
  "scripts": {
18
- "build": "bun build src/index.ts --outdir dist --target node --format esm && bunx tsc --project tsconfig.build.json",
18
+ "build": "bun run ./build.ts",
19
19
  "check": "biome check",
20
20
  "typecheck": "tsc --noEmit",
21
21
  "test": "vitest --run",