Skip to content
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
5 changes: 5 additions & 0 deletions .changeset/warm-snails-hope.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"sv": patch
---

fix(addon): Dependencies are allowed in multi-export repos.
4 changes: 2 additions & 2 deletions documentation/docs/30-add-ons/99-community.md
Original file line number Diff line number Diff line change
Expand Up @@ -150,7 +150,7 @@ Community add-ons are bundled with [tsdown](https://tsdown.dev/) into a single f

### `package.json`

Your add-on must have `sv` as a peer dependency and **no** `dependencies` in `package.json`:
Your add-on must have `sv` as a peer dependency. Any `dependencies` declared will **not** be available at runtime, everything must be bundled:

```jsonc
{
Expand All @@ -164,7 +164,7 @@ Your add-on must have `sv` as a peer dependency and **no** `dependencies` in `pa
"publishConfig": {
"access": "public"
},
// cannot have dependencies
// packages declared here will not be available during runtime, it must be bundled
"dependencies": {},
"peerDependencies": {
// minimum version required to run by this add-on
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -45,4 +45,4 @@ npm publish

## Things to be aware of

Community add-ons must have `sv` as a `peerDependency` and should **not** have any `dependencies`. Everything else (including `@sveltejs/sv-utils`) is bundled at build time by tsdown.
Community add-ons must have `sv` as a `peerDependency`. Any `dependencies` declared in `package.json` will not be available at runtime. Everything else (including `@sveltejs/sv-utils`) is bundled at build time by tsdown.
19 changes: 15 additions & 4 deletions packages/sv/src/core/fetch-packages.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { color, coerceVersion, downloadJson } from '@sveltejs/sv-utils';
import { color, coerceVersion, dedent, downloadJson } from '@sveltejs/sv-utils';
import { unpackTar } from 'modern-tar/fs';
import fs from 'node:fs';
import { platform } from 'node:os';
Expand All @@ -13,9 +13,18 @@ import type { AddonDefinition, AddonReference } from './config.ts';
// path to the `node_modules` directory of `sv`
const NODE_MODULES = fileURLToPath(new URL('../../node_modules', import.meta.url));

function isStandalone(addonPkg: Record<string, any>): boolean {
const exports = addonPkg.exports;
if (!exports) return true;
if (typeof exports === 'string') return true;
if (typeof exports === 'object') return Object.keys(exports).length === 1;
return true;
}

function verifyPackage(addonPkg: Record<string, any>, specifier: string): string | undefined {
const peerDeps = { ...addonPkg.peerDependencies };
const deps = { ...addonPkg.dependencies };
const standalone = isStandalone(addonPkg);

// valid addons should always have `sv` as a peerDependency
const addonSvVersion = peerDeps['sv'];
Expand All @@ -25,10 +34,12 @@ function verifyPackage(addonPkg: Record<string, any>, specifier: string): string
);
}

// addons should not have any dependencies (everything should be bundled)
if (Object.keys(deps).length > 0) {
// standalone addons must not have dependencies (everything should be bundled)
if (standalone && Object.keys(deps).length > 0) {
throw new Error(
`Invalid add-on package detected: '${specifier}'\nCommunity add-ons should not have any 'dependencies'. Use 'peerDependencies' for 'sv' and bundle everything else`
dedent`
Invalid add-on package detected: '${specifier}'
Standalone add-ons must not have 'dependencies' in package.json. Everything should be bundled with your add-on.`

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 check long predates the ./sv export condition. Now that add-ons can co-exist with other libraries in the same package, this check is very much out-of-date.

I think it would be best to just remove this check altogether. However, it would also be nice to add it elsewhere. Perhaps our add-on template can have a post-build check built into it to help guide add-on devs in the right direction?

@sacrosanctic sacrosanctic Aug 5, 2026

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.

a post-build check

like a warning? I was thinking we could have an sv validate cmd for this

);
}

Expand Down
2 changes: 1 addition & 1 deletion packages/sv/src/create/shared/+addon/CONTRIBUTING.md
Original file line number Diff line number Diff line change
Expand Up @@ -45,4 +45,4 @@ npm publish

## Things to be aware of

Community add-ons must have `sv` as a `peerDependency` and should **not** have any `dependencies`. Everything else (including `@sveltejs/sv-utils`) is bundled at build time by tsdown.
Community add-ons must have `sv` as a `peerDependency`. Any `dependencies` declared in `package.json` will not be available at runtime. Everything else (including `@sveltejs/sv-utils`) is bundled at build time by tsdown.