Skip to content

Commit

Permalink
add peer dependency check
Browse files Browse the repository at this point in the history
  • Loading branch information
JReinhold committed Nov 8, 2023
1 parent 45a52d6 commit 630b5c4
Showing 1 changed file with 28 additions and 0 deletions.
28 changes: 28 additions & 0 deletions scripts/prepublish-checks.mjs
Expand Up @@ -3,6 +3,8 @@
import boxen from "boxen";
import dedent from "dedent";
import { readFile } from 'fs/promises';
import { globalPackages as globalManagerPackages } from "@storybook/manager/globals";
import { globalPackages as globalPreviewPackages } from "@storybook/preview/globals";

const packageJson = await readFile('./package.json', 'utf8').then(JSON.parse);

Expand Down Expand Up @@ -55,4 +57,30 @@ if ((await $`cat README.md | grep -E ${readmeTestStrings}`.exitCode) == 0) {
exitCode = 1;
}

/**
* Check that globalized packages are not incorrectly listed as peer dependencies
*/
const peerDependencies = Object.keys(packageJson.peerDependencies || {});
const globalPackages = [...globalManagerPackages, ...globalPreviewPackages];
peerDependencies.forEach((dependency) => {
if(globalPackages.includes(dependency)) {
console.error(
boxen(
dedent`
${chalk.red.bold("Unnecessary peer dependency")}
${chalk.red(dedent`You have a peer dependency on ${chalk.bold(dependency)} which is most likely unnecessary
as that is provided by Storybook directly.
Check the "bundling" section in README.md for more information.
If you are absolutely sure you are doing it correct, you should remove this check from scripts/prepublish-checks.mjs.`)}
`,
{ padding: 1, borderColor: "red" }
)
);

exitCode = 1;

}
})

process.exit(exitCode);

0 comments on commit 630b5c4

Please sign in to comment.