Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(plugin-swc): should verify the version correctly #3364

Merged
merged 2 commits into from
Sep 3, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 5 additions & 1 deletion packages/compat/plugin-swc/src/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,10 @@ async function findUp({
}
}

export const isVersionBeyond17 = (version: string): boolean => {
return semver.gte(semver.minVersion(version)!, '17.0.0');
};

const isBeyondReact17 = async (cwd: string) => {
const pkgPath = await findUp({ cwd, filename: 'package.json' });

Expand All @@ -67,7 +71,7 @@ const isBeyondReact17 = async (cwd: string) => {
return false;
}

return semver.satisfies(semver.minVersion(deps.react)!, '>=17.0.0');
return isVersionBeyond17(deps.react);
};

/**
Expand Down
19 changes: 19 additions & 0 deletions packages/compat/plugin-swc/tests/utils.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
import { isVersionBeyond17 } from '../src/utils';

describe('isVersionBeyondReact17', () => {
test('should return true for version 17 and above', () => {
expect(isVersionBeyond17('17.0.0')).toBe(true);
expect(isVersionBeyond17('17.0.1')).toBe(true);
expect(isVersionBeyond17('17.0.1-canary')).toBe(true);
expect(isVersionBeyond17('^17.0.0')).toBe(true);
expect(isVersionBeyond17('~18.2.0')).toBe(true);
expect(isVersionBeyond17('18.3.0-canary')).toBe(true);
});

test('should return false for below version 17', () => {
expect(isVersionBeyond17('16.14.0')).toBe(false);
expect(isVersionBeyond17('16.8.0-alpha-1')).toBe(false);
expect(isVersionBeyond17('^16.0.0')).toBe(false);
expect(isVersionBeyond17('~15.0.0')).toBe(false);
});
});
Loading