diff --git a/.changeset/poor-otters-doubt.md b/.changeset/poor-otters-doubt.md new file mode 100644 index 000000000000..55be4b145386 --- /dev/null +++ b/.changeset/poor-otters-doubt.md @@ -0,0 +1,5 @@ +--- +'@astrojs/upgrade': patch +--- + +Improves dependency handling by ignoring packages that don't use a semver version diff --git a/packages/upgrade/src/actions/verify.ts b/packages/upgrade/src/actions/verify.ts index 82daa9a06b14..8233a5caf157 100644 --- a/packages/upgrade/src/actions/verify.ts +++ b/packages/upgrade/src/actions/verify.ts @@ -66,17 +66,32 @@ async function verifyAstroProject(ctx: Pick, - dependencies: Record, - devDependencies: Record + dependencies: Record = {}, + devDependencies: Record = {} ) { for (const [name, currentVersion] of Object.entries(dependencies)) { - if (!isAstroPackage(name)) continue; + if (!isSupportedPackage(name, currentVersion)) continue; ctx.packages.push({ name, currentVersion, @@ -84,7 +99,7 @@ function collectPackageInfo( }); } for (const [name, currentVersion] of Object.entries(devDependencies)) { - if (!isAstroPackage(name)) continue; + if (!isSupportedPackage(name, currentVersion)) continue; ctx.packages.push({ name, currentVersion, diff --git a/packages/upgrade/src/index.ts b/packages/upgrade/src/index.ts index 8131e6eb3d8d..8dac82c1c854 100644 --- a/packages/upgrade/src/index.ts +++ b/packages/upgrade/src/index.ts @@ -2,7 +2,7 @@ import { getContext } from './actions/context.js'; import { help } from './actions/help.js'; import { install } from './actions/install.js'; -import { verify } from './actions/verify.js'; +import { verify, collectPackageInfo } from './actions/verify.js'; import { setStdout } from './messages.js'; const exit = () => process.exit(0); @@ -29,4 +29,4 @@ export async function main() { process.exit(0); } -export { getContext, install, setStdout, verify }; +export { getContext, install, setStdout, verify, collectPackageInfo }; diff --git a/packages/upgrade/test/verify.test.js b/packages/upgrade/test/verify.test.js new file mode 100644 index 000000000000..ec9d2de58a36 --- /dev/null +++ b/packages/upgrade/test/verify.test.js @@ -0,0 +1,66 @@ +import { expect } from 'chai'; +import { collectPackageInfo } from '../dist/index.js'; + +describe('collectPackageInfo', () => { + const context = { + cwd: '', + version: 'latest', + packageManager: 'npm', + dryRun: true, + packages: [] + }; + + beforeEach(() => { + context.packages = []; + }) + + it('detects astro', async () => { + collectPackageInfo(context, { "astro": "1.0.0" }, {}); + expect(context.packages).deep.equal([{ name: 'astro', currentVersion: '1.0.0', targetVersion: 'latest' }]); + }); + + it('detects @astrojs', async () => { + collectPackageInfo(context, { "@astrojs/preact": "1.0.0" }, {}); + expect(context.packages).deep.equal([{ name: '@astrojs/preact', currentVersion: '1.0.0', targetVersion: 'latest' }]); + }); + + it('supports ^ prefixes', async () => { + collectPackageInfo(context, { "astro": "^1.0.0" }, {}); + expect(context.packages).deep.equal([{ name: 'astro', currentVersion: '^1.0.0', targetVersion: 'latest' }]); + }); + + it('supports ~ prefixes', async () => { + collectPackageInfo(context, { "astro": "~1.0.0" }, {}); + expect(context.packages).deep.equal([{ name: 'astro', currentVersion: '~1.0.0', targetVersion: 'latest' }]); + }); + + it('supports prereleases', async () => { + collectPackageInfo(context, { "astro": "1.0.0-beta.0" }, {}); + expect(context.packages).deep.equal([{ name: 'astro', currentVersion: '1.0.0-beta.0', targetVersion: 'latest' }]); + }); + + it('ignores self', async () => { + collectPackageInfo(context, { "@astrojs/upgrade": "0.0.1" }, {}); + expect(context.packages).deep.equal([]); + }); + + it('ignores linked packages', async () => { + collectPackageInfo(context, { "@astrojs/preact": "link:../packages/preact" }, {}); + expect(context.packages).deep.equal([]); + }); + + it('ignores workspace packages', async () => { + collectPackageInfo(context, { "@astrojs/preact": "workspace:*" }, {}); + expect(context.packages).deep.equal([]); + }); + + it('ignores github packages', async () => { + collectPackageInfo(context, { "@astrojs/preact": "github:withastro/astro" }, {}); + expect(context.packages).deep.equal([]); + }); + + it('ignores tag', async () => { + collectPackageInfo(context, { "@astrojs/preact": "beta" }, {}); + expect(context.packages).deep.equal([]); + }); +});