|
1 | 1 | import { describe, expect, test } from '@voidzero-dev/vite-plus-test'; |
2 | 2 | import * as semver from 'semver'; |
3 | 3 |
|
4 | | -import { mergePnpmWorkspaces } from '../sync-remote-deps.ts'; |
| 4 | +import { mergePnpmWorkspaces, syncCargoOxcVersions } from '../sync-remote-deps.ts'; |
5 | 5 |
|
6 | 6 | describe('mergePnpmWorkspaces() minimumReleaseAgeExclude', () => { |
7 | 7 | test('drops versioned upstream entries already covered by a glob or bare pattern', () => { |
@@ -80,3 +80,107 @@ describe('mergePnpmWorkspaces() minimumReleaseAgeExclude', () => { |
80 | 80 | expect(result.minimumReleaseAgeExclude).toEqual(['@oxc-parser/*', 'oxc-parser']); |
81 | 81 | }); |
82 | 82 | }); |
| 83 | + |
| 84 | +// Reproduces the upstream-upgrade build break: when the bumped rolldown hash |
| 85 | +// pins a newer oxc release (e.g. 0.135.0 / oxc_index 5), the vendored rolldown |
| 86 | +// crates fail to compile against vp's stale `Cargo.toml` oxc pin (0.134.0). The |
| 87 | +// root `Cargo.toml` oxc versions must follow rolldown's `Cargo.toml`. |
| 88 | +describe('syncCargoOxcVersions()', () => { |
| 89 | + const mainCargo = `[workspace] |
| 90 | +members = ["crates/*"] |
| 91 | +
|
| 92 | +[workspace.dependencies] |
| 93 | +serde = "1" |
| 94 | +
|
| 95 | +# oxc crates with the same version |
| 96 | +oxc = { version = "0.134.0", features = [ |
| 97 | + "ast_visit", |
| 98 | + "transformer", |
| 99 | +] } |
| 100 | +oxc_allocator = { version = "0.134.0", features = ["pool"] } |
| 101 | +oxc_ast = "0.134.0" |
| 102 | +oxc_parser = "0.134.0" |
| 103 | +oxc_span = "0.134.0" |
| 104 | +oxc_traverse = "0.134.0" |
| 105 | +
|
| 106 | +# oxc crates in their own repos |
| 107 | +oxc_index = { version = "4", features = ["rayon", "serde"] } |
| 108 | +oxc_resolver = { version = "11.21.0", features = ["yarn_pnp"] } |
| 109 | +oxc_sourcemap = "7" |
| 110 | +
|
| 111 | +[profile.release] |
| 112 | +lto = true |
| 113 | +`; |
| 114 | + |
| 115 | + const rolldownCargo = `[workspace] |
| 116 | +members = ["crates/*"] |
| 117 | +
|
| 118 | +[workspace.dependencies] |
| 119 | +# oxc crates with the same version |
| 120 | +oxc = { version = "0.135.0", features = [ |
| 121 | + "ast_visit", |
| 122 | + "transformer", |
| 123 | +] } |
| 124 | +oxc_allocator = { version = "0.135.0", features = ["pool"] } |
| 125 | +oxc_traverse = { version = "0.135.0" } |
| 126 | +
|
| 127 | +# oxc crates in their own repos |
| 128 | +oxc_index = { version = "5", features = ["rayon", "serde"] } |
| 129 | +oxc_resolver = { version = "11.21.0", features = ["yarn_pnp"] } |
| 130 | +oxc_sourcemap = { version = "7" } |
| 131 | +`; |
| 132 | + |
| 133 | + test('bumps the oxc same-version family and oxc_index to match rolldown', () => { |
| 134 | + const { content, changes } = syncCargoOxcVersions(mainCargo, rolldownCargo); |
| 135 | + |
| 136 | + // Same-version family follows rolldown's umbrella `oxc` version, including |
| 137 | + // crates rolldown does not declare explicitly (oxc_ast/oxc_parser/oxc_span). |
| 138 | + expect(content).toContain('oxc = { version = "0.135.0"'); |
| 139 | + expect(content).toContain('oxc_allocator = { version = "0.135.0"'); |
| 140 | + expect(content).toContain('oxc_ast = "0.135.0"'); |
| 141 | + expect(content).toContain('oxc_parser = "0.135.0"'); |
| 142 | + expect(content).toContain('oxc_span = "0.135.0"'); |
| 143 | + expect(content).toContain('oxc_traverse = "0.135.0"'); |
| 144 | + // Independently-versioned crate follows rolldown's own pin. |
| 145 | + expect(content).toContain('oxc_index = { version = "5"'); |
| 146 | + // Unchanged crates stay put. |
| 147 | + expect(content).toContain('oxc_resolver = { version = "11.21.0"'); |
| 148 | + expect(content).toContain('oxc_sourcemap = "7"'); |
| 149 | + // Features and unrelated entries are preserved. |
| 150 | + expect(content).toContain('"ast_visit",'); |
| 151 | + expect(content).toContain('serde = "1"'); |
| 152 | + |
| 153 | + const changed = Object.fromEntries(changes.map((c) => [c.key, c.to])); |
| 154 | + expect(changed).toMatchObject({ |
| 155 | + oxc: '0.135.0', |
| 156 | + oxc_allocator: '0.135.0', |
| 157 | + oxc_ast: '0.135.0', |
| 158 | + oxc_parser: '0.135.0', |
| 159 | + oxc_span: '0.135.0', |
| 160 | + oxc_traverse: '0.135.0', |
| 161 | + oxc_index: '5', |
| 162 | + }); |
| 163 | + // No spurious changes for already-matching crates. |
| 164 | + expect(changes.find((c) => c.key === 'oxc_resolver')).toBeUndefined(); |
| 165 | + expect(changes.find((c) => c.key === 'oxc_sourcemap')).toBeUndefined(); |
| 166 | + }); |
| 167 | + |
| 168 | + test('is a no-op when versions already match', () => { |
| 169 | + const { content, changes } = syncCargoOxcVersions(mainCargo, mainCargo); |
| 170 | + expect(content).toBe(mainCargo); |
| 171 | + expect(changes).toEqual([]); |
| 172 | + }); |
| 173 | + |
| 174 | + test('only rewrites entries inside [workspace.dependencies]', () => { |
| 175 | + const withPatch = `${mainCargo} |
| 176 | +[patch.crates-io] |
| 177 | +# pinned override, must not be touched by the oxc sync |
| 178 | +oxc_ast = { git = "https://example.com/oxc", rev = "abc" } |
| 179 | +`; |
| 180 | + const { content } = syncCargoOxcVersions(withPatch, rolldownCargo); |
| 181 | + // The dependency entry is bumped... |
| 182 | + expect(content).toContain('oxc_ast = "0.135.0"'); |
| 183 | + // ...but the [patch] git override is left intact. |
| 184 | + expect(content).toContain('oxc_ast = { git = "https://example.com/oxc", rev = "abc" }'); |
| 185 | + }); |
| 186 | +}); |
0 commit comments