Skip to content

Commit ff609c9

Browse files
authored
feat(upgrade): add --canary flag to target canary SDK versions (#7866)
1 parent 43e4972 commit ff609c9

3 files changed

Lines changed: 29 additions & 3 deletions

File tree

.changeset/cold-poets-find.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
---
2+
---

packages/upgrade/src/__tests__/integration/cli.test.js

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -73,6 +73,7 @@ describe('CLI Integration', () => {
7373
expect(result.stdout).toContain('--dry-run');
7474
expect(result.stdout).toContain('--skip-upgrade');
7575
expect(result.stdout).toContain('--release');
76+
expect(result.stdout).toContain('--canary');
7677
expect(result.exitCode).toBe(0);
7778
});
7879
});
@@ -267,6 +268,25 @@ describe('CLI Integration', () => {
267268
});
268269
});
269270

271+
describe('--canary flag', () => {
272+
it('shows canary version in dry-run output', async () => {
273+
const dir = getFixturePath('nextjs-v6');
274+
const result = await runCli(['--dir', dir, '--canary', '--dry-run', '--skip-codemods'], { timeout: 15000 });
275+
276+
expect(result.stdout).toContain('canary');
277+
expect(result.stdout).toContain('[dry run]');
278+
});
279+
280+
it('allows upgrade even when already on target major version', async () => {
281+
const dir = getFixturePath('nextjs-v7');
282+
const result = await runCli(['--dir', dir, '--canary', '--dry-run', '--skip-codemods'], { timeout: 15000 });
283+
284+
expect(result.stdout).toContain('canary');
285+
expect(result.stdout).toContain('[dry run]');
286+
expect(result.stdout).not.toContain('already on the latest');
287+
});
288+
});
289+
270290
describe('--release flag', () => {
271291
it('loads specific release configuration', async () => {
272292
const dir = getFixturePath('nextjs-v7');

packages/upgrade/src/cli.js

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -39,12 +39,14 @@ const cli = meow(
3939
--ignore Directories/files to ignore (can be used multiple times)
4040
--skip-upgrade Skip the upgrade step
4141
--release Name of the release you're upgrading to (e.g. core-3)
42+
--canary Upgrade to the latest canary version instead of the stable release
4243
--dry-run Show what would be done without making changes
4344
4445
Examples
4546
$ npx @clerk/upgrade
4647
$ npx @clerk/upgrade --sdk=nextjs
4748
$ npx @clerk/upgrade --dir=./src --ignore=**/test/**
49+
$ npx @clerk/upgrade --canary
4850
$ npx @clerk/upgrade --dry-run
4951
5052
Non-interactive mode:
@@ -59,6 +61,7 @@ const cli = meow(
5961
ignore: { type: 'string', isMultiple: true },
6062
release: { type: 'string' },
6163
sdk: { type: 'string' },
64+
canary: { type: 'boolean', default: false },
6265
skipCodemods: { type: 'boolean', default: false },
6366
skipUpgrade: { type: 'boolean', default: false },
6467
},
@@ -69,6 +72,7 @@ async function main() {
6972
renderHeader();
7073

7174
const options = {
75+
canary: cli.flags.canary,
7276
dir: cli.flags.dir,
7377
dryRun: cli.flags.dryRun,
7478
glob: cli.flags.glob,
@@ -186,9 +190,9 @@ async function main() {
186190
if (options.skipUpgrade) {
187191
renderText('Skipping package upgrade (--skip-upgrade flag)', 'yellow');
188192
renderNewline();
189-
} else if (config.alreadyUpgraded) {
193+
} else if (config.alreadyUpgraded && !options.canary) {
190194
renderSuccess(`You're already on the latest major version of @clerk/${sdk}`);
191-
} else if (config.needsUpgrade) {
195+
} else if (config.needsUpgrade || options.canary) {
192196
await performUpgrade(sdk, packageManager, config, options);
193197
}
194198

@@ -214,7 +218,7 @@ async function main() {
214218
async function performUpgrade(sdk, packageManager, config, options) {
215219
const targetPackage = getTargetPackageName(sdk);
216220
const oldPackage = getOldPackageName(sdk);
217-
const targetVersion = config.sdkVersions?.[sdk]?.to;
221+
const targetVersion = options.canary ? 'canary' : config.sdkVersions?.[sdk]?.to;
218222

219223
if (options.dryRun) {
220224
renderText(`[dry run] Would upgrade ${targetPackage} to version ${targetVersion}`, 'yellow');

0 commit comments

Comments
 (0)