Skip to content

Upgrade Svelte to v5. Replace Jest with Vitest. Upgrade other packages - #34

Merged
internettrans merged 7 commits into
single-spa:mainfrom
dualinventive:upgrade-svelte
Jul 23, 2025
Merged

Upgrade Svelte to v5. Replace Jest with Vitest. Upgrade other packages#34
internettrans merged 7 commits into
single-spa:mainfrom
dualinventive:upgrade-svelte

Conversation

@mac89

@mac89 mac89 commented Jul 7, 2025

Copy link
Copy Markdown
Contributor

Upgrade outdated versions of Svelte and other packages. Simplify test setup by using Vitest instead of Jest.

Developed in conjunction with single-spa/create-single-spa#460

@internettrans internettrans left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

What version(s) of svelte does this code work with? All versions of svelte 5? Does it work with svelte 4?

The github workflow should be updated to latest versions, too

Comment thread setupTests.js
// JSDom + Vitest don't play well with each other. Long story short - default
// TextEncoder produces Uint8Array objects that are _different_ from the global
// Uint8Array objects, so some functions that compare their types explode.
// https://github.com/vitest-dev/vitest/issues/4043#issuecomment-1905172846

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Does the following comment also fix the issue? It is a simpler workaround

vitest-dev/vitest#4043 (comment)

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

I could not get it to work with that solution.

Comment thread package.json
@@ -5,7 +5,7 @@
"main": "lib/single-spa-svelte.js",
"scripts": {
"build": "rimraf lib && babel src/single-spa-svelte.js --out-file lib/single-spa-svelte.js --source-maps",

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Babel is still being used here - why was the .babelrc removed?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

My mistake, reverting

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

babel is still missing from devDependencies after the latest commits. I'd like to also change the package.json to use exports rather than main, with type: "module", but can do that in a follow-up pull request if you do not have the time to do so in this one. The module format of the code in the lib folder should be ESM

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

I don't have time to do so at the moment, so have to add it a later point.

Comment thread .husky/pre-commit Outdated
. "$(dirname "$0")/_/husky.sh"

pnpx pretty-quick --staged && pnpx lint
pnpm pretty-quick --staged && pnpm run lint

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Suggested change
pnpm pretty-quick --staged && pnpm run lint
pnpm exec pretty-quick --staged && pnpm run lint

@mac89

mac89 commented Jul 14, 2025

Copy link
Copy Markdown
Contributor Author

What version(s) of svelte does this code work with? All versions of svelte 5? Does it work with svelte 4?

The github workflow should be updated to latest versions, too

Only svelte 5. If you want it to continue working with the older versions I'll take another go at it.

Can you point me to the github workflow?

@internettrans internettrans left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

github workflow: The node-version and pnpm/action-setup should be updated to latest versions. The version of pnpm to use should be specified in the packageManager field of package.json, which pnpm/action-setup uses automatically. Should use latest version.

Since this is a breaking change to single-spa-svelte, I'd like to also migrate it to typescript in the process. If you don't have the time to do so in this pull request, I will do so in a follow-up.

Comment thread setupTests.js
@@ -0,0 +1,21 @@
// JSDom + Vitest don't play well with each other. Long story short - default

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

This file should be moved to src folder.

Comment thread src/single-spa-svelte.js Outdated
@@ -1,3 +1,5 @@
import { mount as originalMount, unmount as originalUnmount } from "svelte";

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

svelte is in devDependencies, which means that this import would fail in a library that installs single-spa-svelte. Traditionally, single-spa adapter libraries for frameworks use dependency injection of the framework (pass in React/Angular/Vue libs via opts) rather than imports, due to the complexities of bundling the adapter libraries and/or using them as runtime shared dependencies in import maps.

Please switch to the mount and unmount functions being passed in as opts

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Added mount and unmount options

Comment thread package.json
@@ -5,7 +5,7 @@
"main": "lib/single-spa-svelte.js",
"scripts": {
"build": "rimraf lib && babel src/single-spa-svelte.js --out-file lib/single-spa-svelte.js --source-maps",

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

babel is still missing from devDependencies after the latest commits. I'd like to also change the package.json to use exports rather than main, with type: "module", but can do that in a follow-up pull request if you do not have the time to do so in this one. The module format of the code in the lib folder should be ESM

@internettrans

Copy link
Copy Markdown
Member

Build failed because of pnpm lockfile being out of date. Github used to let me push to pull request branches but doesn't anymore. I am going to merge this as-is and then complete the rewrite.

@internettrans
internettrans merged commit 1668ca6 into single-spa:main Jul 23, 2025
1 check failed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants