From ba713f173da6dd48b9ef95e6be68053c9e3405ad Mon Sep 17 00:00:00 2001 From: Ben McCann <322311+benmccann@users.noreply.github.com> Date: Wed, 16 Nov 2022 10:46:00 -0800 Subject: [PATCH] [feat] warn if svelte not found in dependencies or peerDependencies --- .changeset/gentle-rocks-run.md | 5 +++++ packages/package/src/index.js | 12 ++++++++++++ 2 files changed, 17 insertions(+) create mode 100644 .changeset/gentle-rocks-run.md diff --git a/.changeset/gentle-rocks-run.md b/.changeset/gentle-rocks-run.md new file mode 100644 index 000000000000..5730b5b8f60d --- /dev/null +++ b/.changeset/gentle-rocks-run.md @@ -0,0 +1,5 @@ +--- +'@sveltejs/package': patch +--- + +[feat] warn if svelte not found in dependencies or peerDependencies diff --git a/packages/package/src/index.js b/packages/package/src/index.js index d751537bf1cf..08a096a4ac04 100644 --- a/packages/package/src/index.js +++ b/packages/package/src/index.js @@ -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. @@ -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 */