Skip to content

Commit 7d1594e

Browse files
committed
RELEASING: Releasing 2 package(s)
Releases: [email protected] @repo/[email protected]
1 parent e8d0e8e commit 7d1594e

File tree

10 files changed

+366
-121
lines changed

10 files changed

+366
-121
lines changed

COMMIT_MESSAGE.txt

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
feat!: refactor plugin architecture to factory pattern
2+
3+
BREAKING CHANGE: Default export is now createSemverPlugin() factory function
4+
5+
- Refactor: Changed from single plugin object to factory function pattern
6+
- Improve: Enhanced semver validation with validateStrict support
7+
- Fix: Better handling of version prefixes (e.g., ^1.2.3)
8+
- Add: Immutable configuration scoped per plugin instance
9+
- Update: Improved TypeScript support and type safety
10+
11+
Migration: Use createSemverPlugin() or individual strategy exports.
12+
See MIGRATION.md for detailed upgrade instructions.

MIGRATION.md

Lines changed: 125 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,125 @@
1+
# Migration Guide
2+
3+
## v0.0.2 → v1.0.0
4+
5+
This release introduces a **breaking change** in the plugin architecture. The plugin now uses a factory pattern for better configuration management and TypeScript support.
6+
7+
### What Changed
8+
9+
- Default export changed from plugin object to `createSemverPlugin()` factory function
10+
- Improved semver validation with `validateStrict` support
11+
- Better handling of version prefixes (e.g., `^1.2.3`)
12+
- Configuration is now immutable and scoped per plugin instance
13+
14+
### Migration Steps
15+
16+
#### 1. Dynamic Plugin Loading (Recommended - No Changes Required)
17+
18+
If you're using dynamic plugin loading, **no changes are needed**:
19+
20+
```json
21+
{
22+
"plugins": ["git-json-resolver-semver"],
23+
"rules": {
24+
"dependencies.react": ["semver-max"]
25+
}
26+
}
27+
```
28+
29+
#### 2. Direct Import Usage
30+
31+
**Before (v0.0.2):**
32+
```ts
33+
import plugin, { semverMax } from "git-json-resolver-semver";
34+
import { resolveConflicts } from "git-json-resolver";
35+
36+
// Plugin configuration (old way)
37+
await plugin.init?.({
38+
strict: false,
39+
fallback: "ours"
40+
});
41+
42+
await resolveConflicts({
43+
customStrategies: {
44+
"semver-max": semverMax,
45+
},
46+
rules: {
47+
"dependencies.react": ["semver-max"],
48+
},
49+
});
50+
```
51+
52+
**After (v1.0.0):**
53+
```ts
54+
import createSemverPlugin, { semverMax, init } from "git-json-resolver-semver";
55+
import { resolveConflicts } from "git-json-resolver";
56+
57+
// Option 1: Use factory function with config
58+
const plugin = createSemverPlugin({
59+
strict: false,
60+
fallback: "ours"
61+
});
62+
63+
await resolveConflicts({
64+
customStrategies: plugin.strategies,
65+
rules: {
66+
"dependencies.react": ["semver-max"],
67+
},
68+
});
69+
70+
// Option 2: Use global init (for backward compatibility)
71+
init({
72+
strict: false,
73+
fallback: "ours"
74+
});
75+
76+
await resolveConflicts({
77+
customStrategies: {
78+
"semver-max": semverMax,
79+
},
80+
rules: {
81+
"dependencies.react": ["semver-max"],
82+
},
83+
});
84+
```
85+
86+
### New Features
87+
88+
#### Enhanced Semver Validation
89+
90+
The plugin now uses `validateStrict` from compare-versions and properly handles version prefixes:
91+
92+
```ts
93+
// Now properly handles these cases:
94+
"^1.2.3" // Strips ^ prefix before validation
95+
"1.2.3-beta.1" // Handled based on strict mode setting
96+
```
97+
98+
#### Factory Pattern Benefits
99+
100+
```ts
101+
// Create multiple plugin instances with different configs
102+
const strictPlugin = createSemverPlugin({ strict: true });
103+
const flexiblePlugin = createSemverPlugin({ strict: false, fallback: "ours" });
104+
```
105+
106+
### Configuration Options
107+
108+
All configuration options remain the same:
109+
110+
- `strict` (boolean, default: `true`) - Use strict semver validation
111+
- `fallback` (string, default: `"continue"`) - Behavior when both sides invalid
112+
- `preferValid` (boolean, default: `true`) - Prefer valid semver when only one side is valid
113+
- `preferRange` (boolean, default: `false`) - Future feature for range merging
114+
- `workspacePattern` (string, default: `""`) - Pattern for workspace rules
115+
116+
### Troubleshooting
117+
118+
**Error: "Cannot read property 'strategies' of undefined"**
119+
- You're likely importing the old way. Use `createSemverPlugin()` or individual strategy exports.
120+
121+
**Error: "plugin.init is not a function"**
122+
- Use the new `init` named export instead of `plugin.init`.
123+
124+
**Semver validation behaving differently**
125+
- The new validation is more accurate. Check if your versions need the `strict: false` option.

README.md

Lines changed: 48 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -58,9 +58,24 @@ pnpm install git-json-resolver
5858
### 1. Direct Import
5959

6060
```ts
61-
import { semverMax } from "git-json-resolver-semver";
61+
import createSemverPlugin, { semverMax } from "git-json-resolver-semver";
6262
import { resolveConflicts } from "git-json-resolver";
6363

64+
// Option 1: Use factory function with custom config
65+
const plugin = createSemverPlugin({
66+
strict: false,
67+
fallback: "ours",
68+
});
69+
70+
await resolveConflicts({
71+
customStrategies: plugin.strategies,
72+
rules: {
73+
"dependencies.react": ["semver-max"],
74+
"devDependencies.vitest": ["semver-min"],
75+
},
76+
});
77+
78+
// Option 2: Use individual strategy exports - not scoped @see migration guide for more details
6479
await resolveConflicts({
6580
customStrategies: {
6681
"semver-max": semverMax,
@@ -103,11 +118,39 @@ export default config;
103118

104119
---
105120

106-
## ⚙️ Behavior notes
121+
## ⚙️ Configuration
122+
123+
### Factory Pattern (Recommended)
124+
125+
```ts
126+
import createSemverPlugin from "git-json-resolver-semver";
127+
128+
const plugin = createSemverPlugin({
129+
strict: true, // Use validateStrict for exact semver only
130+
preferValid: true, // Prefer valid semver when only one side is valid
131+
fallback: "continue", // Behavior when both sides invalid
132+
preferRange: false, // Future: merge into semver ranges
133+
workspacePattern: "", // Pattern for workspace rules
134+
});
135+
```
136+
137+
### Global Configuration
138+
139+
```ts
140+
import { init } from "git-json-resolver-semver";
141+
142+
init({
143+
strict: false, // Allow prereleases and ranges
144+
fallback: "ours",
145+
});
146+
```
147+
148+
### Behavior Notes
107149

108-
- **strict** mode (default) accepts only `x.y.z`. Set non-strict to allow prereleases/ranges.
109-
- **preferValid** (default) returns the valid side when the other is invalid.
110-
- **fallback** controls behavior when neither side is valid (`ours` | `theirs` | `continue` | `error`).
150+
- **strict** mode uses `validateStrict` - only accepts `x.y.z` format
151+
- **preferValid** returns the valid side when the other is invalid
152+
- **fallback** controls behavior when neither side is valid
153+
- Version prefixes like `^1.2.3` are automatically handled
111154

112155
## ⚙️ Strategies
113156

lib/CHANGELOG.md

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,17 @@
11
# git-json-resolver-semver
22

3+
## 1.0.0
4+
5+
### Major Changes
6+
7+
- **BREAKING CHANGE**: Refactor plugin architecture to factory pattern
8+
- **Changed**: Default export is now `createSemverPlugin()` factory function instead of plugin object
9+
- **Improved**: Semver validation now uses `validateStrict` and handles version prefixes (e.g., `^1.2.3`)
10+
- **Added**: Better TypeScript support with immutable configuration
11+
- **Fixed**: Configuration is now properly scoped per plugin instance
12+
13+
**Migration required**: See MIGRATION.md for upgrade instructions.
14+
315
## 0.0.2
416

517
### Patch Changes

lib/README.md

Lines changed: 48 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -58,9 +58,24 @@ pnpm install git-json-resolver
5858
### 1. Direct Import
5959

6060
```ts
61-
import { semverMax } from "git-json-resolver-semver";
61+
import createSemverPlugin, { semverMax } from "git-json-resolver-semver";
6262
import { resolveConflicts } from "git-json-resolver";
6363

64+
// Option 1: Use factory function with custom config
65+
const plugin = createSemverPlugin({
66+
strict: false,
67+
fallback: "ours"
68+
});
69+
70+
await resolveConflicts({
71+
customStrategies: plugin.strategies,
72+
rules: {
73+
"dependencies.react": ["semver-max"],
74+
"devDependencies.vitest": ["semver-min"],
75+
},
76+
});
77+
78+
// Option 2: Use individual strategy exports
6479
await resolveConflicts({
6580
customStrategies: {
6681
"semver-max": semverMax,
@@ -103,11 +118,39 @@ export default config;
103118

104119
---
105120

106-
## ⚙️ Behavior notes
121+
## ⚙️ Configuration
122+
123+
### Factory Pattern (Recommended)
124+
125+
```ts
126+
import createSemverPlugin from "git-json-resolver-semver";
127+
128+
const plugin = createSemverPlugin({
129+
strict: true, // Use validateStrict for exact semver only
130+
preferValid: true, // Prefer valid semver when only one side is valid
131+
fallback: "continue", // Behavior when both sides invalid
132+
preferRange: false, // Future: merge into semver ranges
133+
workspacePattern: "" // Pattern for workspace rules
134+
});
135+
```
136+
137+
### Global Configuration
138+
139+
```ts
140+
import { init } from "git-json-resolver-semver";
141+
142+
init({
143+
strict: false, // Allow prereleases and ranges
144+
fallback: "ours"
145+
});
146+
```
147+
148+
### Behavior Notes
107149

108-
- **strict** mode (default) accepts only `x.y.z`. Set non-strict to allow prereleases/ranges.
109-
- **preferValid** (default) returns the valid side when the other is invalid.
110-
- **fallback** controls behavior when neither side is valid (`ours` | `theirs` | `continue` | `error`).
150+
- **strict** mode uses `validateStrict` - only accepts `x.y.z` format
151+
- **preferValid** returns the valid side when the other is invalid
152+
- **fallback** controls behavior when neither side is valid
153+
- Version prefixes like `^1.2.3` are automatically handled
111154

112155
## ⚙️ Strategies
113156

lib/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
"name": "git-json-resolver-semver",
33
"author": "Mayank Kumar Chaudhari (https://mayank-chaudhari.vercel.app)",
44
"private": false,
5-
"version": "0.0.2",
5+
"version": "1.0.0",
66
"description": "Plugin for git-json-resolver that applies semver-based merge strategies (max, min, secure, override) to resolve version conflicts in package.json and similar files.",
77
"license": "MPL-2.0",
88
"main": "./dist/index.js",

lib/src/index.test.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import { describe, it, expect, beforeEach, vi } from "vitest";
2-
import plugin, { semverMax, semverMin, semverOurs, semverTheirs } from "./index";
2+
import { init, semverMax, semverMin, semverOurs, semverTheirs } from "./index";
33
import {
44
StrategyStatus_OK,
55
StrategyStatus_CONTINUE,
@@ -19,7 +19,7 @@ const run = (fn: any, ours: any, theirs: any) =>
1919
fn({ ours, theirs, base: undefined, path: [], logger: mockLogger });
2020

2121
const reset = (overrides: any = {}) => {
22-
plugin.init?.({
22+
init?.({
2323
strict: true,
2424
normalize: true,
2525
fallback: "continue",

0 commit comments

Comments
 (0)