Skip to content

Commit

Permalink
[feat] warn if svelte not found in dependencies or peerDependencies
Browse files Browse the repository at this point in the history
  • Loading branch information
benmccann committed Nov 16, 2022
1 parent 56f2c51 commit ba713f1
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 0 deletions.
5 changes: 5 additions & 0 deletions .changeset/gentle-rocks-run.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
'@sveltejs/package': patch
---

[feat] warn if svelte not found in dependencies or peerDependencies
12 changes: 12 additions & 0 deletions packages/package/src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,10 @@ export async function build(config, cwd = process.cwd()) {

const pkg = generate_pkg(cwd, files);

if (!has_svelte(pkg.dependencies) && !has_svelte(pkg.peerDependencies)) {
console.warn('Svelte libraries should include "svelte" in either "dependencies" or "peerDependencies".');
}

if (!pkg.svelte && files.some((file) => file.is_svelte)) {
// Several heuristics in Kit/vite-plugin-svelte to tell Vite to mark Svelte packages
// rely on the "svelte" property. Vite/Rollup/Webpack plugin can all deal with it.
Expand Down Expand Up @@ -82,6 +86,14 @@ export async function build(config, cwd = process.cwd()) {
console.log(colors.bold().cyan(' npm publish\n'));
}

/** @param {object} field */
function has_svelte(field) {
for (const key of Object.keys(field)) {
if (key === 'svelte') return true;
}
return false;
}

/**
* @param {import('./types').ValidatedConfig} config
*/
Expand Down

0 comments on commit ba713f1

Please sign in to comment.