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

Update compiler, tests and examples to use Svelte 5 #233

Closed
wants to merge 10 commits into from
Closed
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
4 changes: 2 additions & 2 deletions dist/index.d.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import type { CompileOptions, Warning } from "svelte/types/compiler/interfaces";
import type { PreprocessorGroup } from "svelte/types/compiler/preprocess";
/// <reference types="svelte" />
import type { CompileOptions, Warning, PreprocessorGroup } from "svelte/compiler";
import type { Plugin } from "esbuild";
interface esbuildSvelteOptions {
/**
Expand Down
3 changes: 2 additions & 1 deletion example-js/entry.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import { mount } from "svelte";
import Test from "./index.svelte";

new Test({
mount(Test, {
target: document.body,
});
2 changes: 1 addition & 1 deletion example-js/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
"dependencies": {
"esbuild": "^0.20.1",
"esbuild-svelte": "^0.8.0",
"svelte": "^4.2.11"
"svelte": "^5.0.0-next.136"
},
"private": true
}
6 changes: 5 additions & 1 deletion example-ts/entry.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,9 @@
import Test from "./index.svelte";
import { haha } from "./fun";

new Test({ target: document.body });
import { mount } from "svelte";

mount(Test, {
target: document.body,
});
console.log(haha());
2 changes: 1 addition & 1 deletion example-ts/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
"@tsconfig/svelte": "^5.0.2",
"esbuild": "^0.20.1",
"esbuild-svelte": "^0.8.0",
"svelte": "^4.2.11",
"svelte": "^5.0.0-next.136",
"svelte-check": "^3.6.4",
"svelte-preprocess": "^5.1.3",
"typescript": "^5.3.3"
Expand Down
9 changes: 4 additions & 5 deletions index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,7 @@ import { promisify } from "util";
import { readFile, statSync } from "fs";
import { originalPositionFor, TraceMap } from "@jridgewell/trace-mapping";

import type { CompileOptions, Warning } from "svelte/types/compiler/interfaces";
import type { PreprocessorGroup } from "svelte/types/compiler/preprocess";
import type { CompileOptions, Warning, PreprocessorGroup } from "svelte/compiler";
import type { OnLoadResult, Plugin, PluginBuild, Location, PartialMessage } from "esbuild";

interface esbuildSvelteOptions {
Expand Down Expand Up @@ -202,7 +201,7 @@ export default function sveltePlugin(options?: esbuildSvelteOptions): Plugin {
dependencyModifcationTimes.set(args.path, statSync(args.path).mtime); // add the target file

let compilerOptions = {
css: (svelteVersion < 3 ? false : "external") as boolean | "external",
css: (svelteVersion < 3 ? undefined : "external") as CompileOptions["css"],
Copy link
Owner

@EMH333 EMH333 May 18, 2024

Choose a reason for hiding this comment

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

After looking at this a bit more, I'm fairly sure this logic is broken for everything between Svelte 3.43.0 and 3.53.0 (when support for "external" was added). And actually, false is never returned at all since the version lock requires Svelte >3.43.0. Fun.

Probably not a huge deal, but all the more reason to tear it out soon!

...options?.compilerOptions,
};

Expand Down Expand Up @@ -274,8 +273,8 @@ export default function sveltePlugin(options?: esbuildSvelteOptions): Plugin {

//if svelte emits css seperately, then store it in a map and import it from the js
if (
(compilerOptions.css === false || compilerOptions.css === "external") &&
css.code
(compilerOptions.css === undefined || compilerOptions.css === "external") &&
css?.code
) {
let cssPath = args.path
.replace(".svelte", ".esbuild-svelte-fake-css") //TODO append instead of replace to support different svelte filters
Expand Down
104 changes: 41 additions & 63 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 2 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -33,15 +33,15 @@
"license": "MIT",
"peerDependencies": {
"esbuild": ">=0.9.6",
"svelte": ">=3.43.0 <5"
"svelte": ">=3.43.0 <6"
},
"devDependencies": {
"@types/node": "^16.18.37",
"esbuild": "^0.20.0",
"prettier": "^3.2.5",
"rewrite-imports": "^3.0.0",
"sass": "^1.71.0",
"svelte": "^4.2.11",
"svelte": "^5.0.0-next.136",
"svelte-preprocess-esbuild": "^3.0.0",
"svelte-preprocess-sass": "^2.0.1",
"typescript": "^5.3.3",
Expand Down
4 changes: 2 additions & 2 deletions test/errors.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -33,9 +33,9 @@ test("Errors (with preprocessors) are in the right spot", async () => {
);
assert.equal(error.location.line, 12, "Should have the right line");
assert.equal(error.location.column, 31, "Should have the right column");
assert.equal(
assert.match(
error.text,
"Expected value for the attribute",
/Expected (value for the attribute|attribute value)/,
"Should have the right error message",
);
return;
Expand Down
3 changes: 2 additions & 1 deletion test/fixtures/errors/entry.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import { mount } from "svelte";
import Test from "./error.svelte";

new Test({
mount(Test, {
target: document.body,
});
3 changes: 2 additions & 1 deletion test/fixtures/non-ascii/entry.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import { mount } from "svelte";
import Test from "./non-ascii.svelte";

new Test({
mount(Test, {
target: document.body,
});
3 changes: 2 additions & 1 deletion test/fixtures/preprocessing-sourcemaps/pp-sourcemaps.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import { mount } from "svelte";
import Test from "./pp-sourcemaps.svelte";

new Test({
mount(Test, {
target: document.body,
});
3 changes: 2 additions & 1 deletion test/fixtures/resolveDirectory/entry.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import { mount } from "svelte";
import Test from "./resDir.svelte";

new Test({
mount(Test, {
target: document.body,
});
4 changes: 2 additions & 2 deletions test/fixtures/svelte5/entry.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { mount } from 'svelte';
import Test from './svelte5.svelte';
import { mount } from "svelte";
import Test from "./svelte5.svelte";

const test = mount(Test, { target: document.body });
5 changes: 3 additions & 2 deletions test/fixtures/warnings/entry.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import Test from "./missing-declaration.svelte";
import { mount } from "svelte";
import Test from "./warnings.svelte";

new Test({
mount(Test, {
target: document.body,
});
11 changes: 0 additions & 11 deletions test/fixtures/warnings/missing-declaration.svelte

This file was deleted.

11 changes: 11 additions & 0 deletions test/fixtures/warnings/warnings.svelte
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
<div>
<!-- This will generate a warning about missing alt -->
<img src="foo.jpg" />
</div>

<!-- This will generate a warning about an unused CSS selector -->
<style>
.special-image {
height: 200px;
}
</style>
3 changes: 2 additions & 1 deletion test/fixtures/watch-preprocessing/entry.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import { mount } from "svelte";
import Test from "./external-styles.svelte";

new Test({
mount(Test, {
target: document.body,
});
Loading