|
| 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. |
0 commit comments