Skip to content
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
4 changes: 2 additions & 2 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ jobs:
- name: Set up pnpm
uses: pnpm/action-setup@0e279bb959325dab635dd2c09392533439d90093
with:
version: 11.5.2
version: 11.27.1

- name: Set up Node.js
uses: actions/setup-node@48b55a011bda9f5d6aeb4c2d9c7362e8dae4041e
Expand Down Expand Up @@ -66,7 +66,7 @@ jobs:
- name: Set up pnpm
uses: pnpm/action-setup@0e279bb959325dab635dd2c09392533439d90093
with:
version: 11.5.2
version: 11.27.1

- name: Set up Node.js
uses: actions/setup-node@48b55a011bda9f5d6aeb4c2d9c7362e8dae4041e
Expand Down
12 changes: 6 additions & 6 deletions CONTRIBUTING.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,13 +8,13 @@ Some convenient scripts are provided to help develop the add-on.

```sh
## create a new minimal project in the `demo` directory
npm run demo-create
pnpm demo-create

## add your current add-on to the demo project
npm run demo-add
pnpm demo-add

## run the tests
npm run test
pnpm test
```

## Key things to note
Expand All @@ -29,16 +29,16 @@ Your `add-on` should:
Your add-on is bundled with [tsdown](https://tsdown.dev/) into a single file in `dist/`. This bundles everything except `sv` (which is a peer dependency provided at runtime).

```sh
npm run build
pnpm build
```

## Publishing

When you're ready to publish your add-on to npm:

```sh
npm login
npm publish
pnpm login
pnpm publish
```

> `prepublishOnly` will automatically run the build before publishing.
Expand Down
22 changes: 9 additions & 13 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -20,27 +20,23 @@ npx sv add @msw/sveltekit
## What you get

- `msw` added as a dev dependency.
- `src/msw/handlers.ts` or `src/msw/handlers.js` with shared request handlers.
- Optional browser setup in `src/msw/browser` and `src/hooks.client`.
- Optional Node setup in `src/msw/node` and `src/hooks.server`.
- Browser worker configuration in `package.json`.
- `src/mocks/handlers.ts` or `src/mocks/handlers.js` with shared request handlers.
- The `msw()` plugin from `msw/vite` added to your Vite config.
- Optional browser and server setup in the corresponding `src/hooks.client` and `src/hooks.server` `init` hooks.
- Types for `virtual:msw` referenced in `src/app.d.ts`.

The hooks load your handlers and enable the `virtual:msw` network during development only. The Vite plugin selects the browser or Node implementation automatically and serves the browser worker, so there is no need to run `msw init` or copy a worker into `static`.

The add-on installs the latest stable MSW release. The Vite integration requires MSW 3.0.0 or later. You can override the dependency with the `MSW_VERSION` environment variable.

## Options

### `environments`

Choose where MSW should run. This is a multiselect option.
Choose where MSW should run during development: `browser`, `node` (the SvelteKit server), or both. This is a multiselect option.

Default: `browser,node`

```shell
npx sv add @msw/sveltekit="environments:browser,node"
```

## Browser worker

If you enable browser mocking, generate the service worker after installing dependencies:

```shell
npx msw init static --save
```
3 changes: 2 additions & 1 deletion jsconfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -5,5 +5,6 @@
"checkJs": true,
"module": "NodeNext",
"moduleResolution": "NodeNext"
}
},
"include": ["src/**/*.js", "tests/**/*.js", "*.js"]
}
26 changes: 15 additions & 11 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
"version": "0.0.0",
"type": "module",
"license": "MIT",
"packageManager": "pnpm@11.5.2",
"packageManager": "pnpm@11.27.1",
"scripts": {
"demo-create": "sv create demo --types ts --template minimal --no-add-ons --no-install",
"demo-add": "pnpm build && sv add file:../ --cwd demo --no-git-check --no-install",
Expand All @@ -28,7 +28,11 @@
"keywords": [
"sv-add",
"svelte",
"sveltekit"
"sveltekit",
"mock",
"api",
"request",
"msw"
],
"repository": {
"type": "git",
Expand All @@ -39,14 +43,14 @@
"sv": "^0.13.0"
},
"devDependencies": {
"@ossjs/release": "^0.11.0",
"@playwright/test": "^1.59.1",
"@sveltejs/sv-utils": "^0.3.1",
"@types/node": "^25.5.2",
"oxlint": "^1.72.0",
"prettier": "^3.9.4",
"sv": "^0.16.2",
"tsdown": "^0.21.7",
"vitest": "^4.1.3"
"@ossjs/release": "^0.11.2",
"@playwright/test": "^1.63.0",
"@sveltejs/sv-utils": "^0.3.3",
"@types/node": "^26.6.3",
"oxlint": "^1.85.0",
"prettier": "^3.9.9",
"sv": "^0.17.1",
"tsdown": "^0.23.0",
"vitest": "^5.0.2"
}
}
Loading
Loading