Skip to content

fix: svelte version detection was broken #495

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

Merged
merged 1 commit into from
Nov 14, 2022
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
Original file line number Diff line number Diff line change
Expand Up @@ -61,42 +61,42 @@ describe('svelte-version', () => {
expect(atLeastSvelte(VERSION)).toBe(true);
});

it('should return true for patch bump', async () => {
it('should return false for higher patch', async () => {
const patch = svelteVersion.concat();
patch[2] += 1;
const patchBump = patch.join('.');
expect(atLeastSvelte(patchBump)).toBe(true);
expect(atLeastSvelte(patchBump)).toBe(false);
});
it('should return true for minor bump', async () => {
it('should return false for higher minor', async () => {
const minor = svelteVersion.concat();
minor[1] += 1;
const minorBump = minor.join('.');
expect(atLeastSvelte(minorBump)).toBe(true);
expect(atLeastSvelte(minorBump)).toBe(false);
});
it('should return true for major bump', async () => {
it('should return false for higher major', async () => {
const major = svelteVersion.concat();
major[0] += 1;
const majorBump = major.join('.');
expect(atLeastSvelte(majorBump)).toBe(true);
expect(atLeastSvelte(majorBump)).toBe(false);
});

it('should return false for lower patch', async () => {
it('should return true for lower patch', async () => {
const patch = svelteVersion.concat();
patch[2] -= 1;
const lowerPatch = patch.join('.');
expect(atLeastSvelte(lowerPatch)).toBe(false);
expect(atLeastSvelte(lowerPatch)).toBe(true);
});
it('should return false for lower minor', async () => {
it('should return true for lower minor', async () => {
const minor = svelteVersion.concat();
minor[1] -= 1;
const lowerMinor = minor.join('.');
expect(atLeastSvelte(lowerMinor)).toBe(false);
expect(atLeastSvelte(lowerMinor)).toBe(true);
});
it('should return false for lower major', async () => {
it('should return true for lower major', async () => {
const major = svelteVersion.concat();
major[0] -= 1;
const lowerMajor = major.join('.');
expect(atLeastSvelte(lowerMajor)).toBe(false);
expect(atLeastSvelte(lowerMajor)).toBe(true);
});
});
});
2 changes: 1 addition & 1 deletion packages/vite-plugin-svelte/src/utils/esbuild.ts
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ async function compileSvelte(
): Promise<string> {
let css = options.compilerOptions.css;
if (css !== 'none') {
css = isCssString ? 'inject' : true;
css = isCssString ? 'injected' : true;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I missed this too 😅 Didn't expect it to be past-tense.

}
const compileOptions: CompileOptions = {
...options.compilerOptions,
Expand Down
3 changes: 2 additions & 1 deletion packages/vite-plugin-svelte/src/utils/svelte-version.ts
Original file line number Diff line number Diff line change
Expand Up @@ -32,5 +32,6 @@ export function compareToSvelte(version: string): 1 | 0 | -1 {
}

export function atLeastSvelte(version: string) {
return compareToSvelte(version) >= 0;
const result = compareToSvelte(version) <= 0;
return result;
Comment on lines -35 to +36
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

took me a while to grasp why but makes sense now. nice catch

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

still mad at myself for this one

}