Skip to content
Merged
Show file tree
Hide file tree
Changes from 3 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
20 changes: 8 additions & 12 deletions code/addons/themes/src/postinstall.ts
Original file line number Diff line number Diff line change
@@ -1,26 +1,22 @@
import { spawn } from 'child_process';

const PACKAGE_MANAGER_TO_COMMAND = {
npm: ['npx'],
pnpm: ['pnpm', 'dlx'],
yarn1: ['npx'],
yarn2: ['yarn', 'dlx'],
bun: ['bunx'],
npm: 'npx',
pnpm: 'pnpm dlx',
yarn1: 'npx',
yarn2: 'yarn dlx',
bun: 'bunx',
};

const selectPackageManagerCommand = (packageManager: string) =>
PACKAGE_MANAGER_TO_COMMAND[packageManager as keyof typeof PACKAGE_MANAGER_TO_COMMAND];

const spawnPackageManagerScript = async (packageManager: string, args: string[]) => {
const [command, ...baseArgs] = selectPackageManagerCommand(packageManager);
export default async function postinstall({ packageManager = 'npm' }) {
const command = selectPackageManagerCommand(packageManager);

await spawn(command, [...baseArgs, ...args], {
await spawn(`${command} @storybook/auto-config themes`, {
stdio: 'inherit',
cwd: process.cwd(),
shell: true,
});
};

export default async function postinstall({ packageManager = 'npm' }) {
await spawnPackageManagerScript(packageManager, ['@storybook/auto-config', 'themes']);
}
Original file line number Diff line number Diff line change
Expand Up @@ -119,7 +119,7 @@
return 'npm';
}

throw new Error('Unable to find a usable package manager within NPM, PNPM, Yarn and Yarn 2');

Check failure on line 122 in code/core/src/common/js-package-manager/JsPackageManagerFactory.ts

View workflow job for this annotation

GitHub Actions / Core Unit Tests, windows-latest

src/common/js-package-manager/JsPackageManagerFactory.test.ts > CLASS: JsPackageManagerFactory > METHOD: getPackageManager > Yarn 2 proxy > when Yarn command is ok, Yarn version is >=2, NPM and PNPM are ok, there is a `yarn.lock` file

Error: Unable to find a usable package manager within NPM, PNPM, Yarn and Yarn 2 ❯ Function.getPackageManagerType src/common/js-package-manager/JsPackageManagerFactory.ts:122:11 ❯ Function.getPackageManager src/common/js-package-manager/JsPackageManagerFactory.ts:154:37 ❯ src/common/js-package-manager/JsPackageManagerFactory.test.ts:365:40

Check failure on line 122 in code/core/src/common/js-package-manager/JsPackageManagerFactory.ts

View workflow job for this annotation

GitHub Actions / Core Unit Tests, windows-latest

src/common/js-package-manager/JsPackageManagerFactory.test.ts > CLASS: JsPackageManagerFactory > METHOD: getPackageManager > Yarn 2 proxy > ONLY YARN 2: when Yarn command is ok, Yarn version is >=2, NPM is ko, PNPM is ko, and a yarn.lock file is found

Error: Unable to find a usable package manager within NPM, PNPM, Yarn and Yarn 2 ❯ Function.getPackageManagerType src/common/js-package-manager/JsPackageManagerFactory.ts:122:11 ❯ Function.getPackageManager src/common/js-package-manager/JsPackageManagerFactory.ts:154:37 ❯ src/common/js-package-manager/JsPackageManagerFactory.test.ts:323:40

Check failure on line 122 in code/core/src/common/js-package-manager/JsPackageManagerFactory.ts

View workflow job for this annotation

GitHub Actions / Core Unit Tests, windows-latest

src/common/js-package-manager/JsPackageManagerFactory.test.ts > CLASS: JsPackageManagerFactory > METHOD: getPackageManager > Yarn 1 proxy > when multiple lockfiles are in a project, prefers yarn

Error: Unable to find a usable package manager within NPM, PNPM, Yarn and Yarn 2 ❯ Function.getPackageManagerType src/common/js-package-manager/JsPackageManagerFactory.ts:122:11 ❯ Function.getPackageManager src/common/js-package-manager/JsPackageManagerFactory.ts:154:37 ❯ src/common/js-package-manager/JsPackageManagerFactory.test.ts:278:40

Check failure on line 122 in code/core/src/common/js-package-manager/JsPackageManagerFactory.ts

View workflow job for this annotation

GitHub Actions / Core Unit Tests, windows-latest

src/common/js-package-manager/JsPackageManagerFactory.test.ts > CLASS: JsPackageManagerFactory > METHOD: getPackageManager > Yarn 1 proxy > when Yarn command is ok, Yarn version is <2, NPM and PNPM are ok, there is a `yarn.lock` file

Error: Unable to find a usable package manager within NPM, PNPM, Yarn and Yarn 2 ❯ Function.getPackageManagerType src/common/js-package-manager/JsPackageManagerFactory.ts:122:11 ❯ Function.getPackageManager src/common/js-package-manager/JsPackageManagerFactory.ts:154:37 ❯ src/common/js-package-manager/JsPackageManagerFactory.test.ts:241:40

Check failure on line 122 in code/core/src/common/js-package-manager/JsPackageManagerFactory.ts

View workflow job for this annotation

GitHub Actions / Core Unit Tests, windows-latest

src/common/js-package-manager/JsPackageManagerFactory.test.ts > CLASS: JsPackageManagerFactory > METHOD: getPackageManager > Yarn 1 proxy > when Yarn command is ok and a yarn.lock file is found

Error: Unable to find a usable package manager within NPM, PNPM, Yarn and Yarn 2 ❯ Function.getPackageManagerType src/common/js-package-manager/JsPackageManagerFactory.ts:122:11 ❯ Function.getPackageManager src/common/js-package-manager/JsPackageManagerFactory.ts:154:37 ❯ src/common/js-package-manager/JsPackageManagerFactory.test.ts:206:40

Check failure on line 122 in code/core/src/common/js-package-manager/JsPackageManagerFactory.ts

View workflow job for this annotation

GitHub Actions / Core Unit Tests, windows-latest

src/common/js-package-manager/JsPackageManagerFactory.test.ts > CLASS: JsPackageManagerFactory > METHOD: getPackageManager > PNPM proxy > PNPM LOCK IF CLOSER: when a pnpm-lock.yaml file is closer than a yarn.lock

Error: Unable to find a usable package manager within NPM, PNPM, Yarn and Yarn 2 ❯ Function.getPackageManagerType src/common/js-package-manager/JsPackageManagerFactory.ts:122:11 ❯ Function.getPackageManager src/common/js-package-manager/JsPackageManagerFactory.ts:154:37 ❯ src/common/js-package-manager/JsPackageManagerFactory.test.ts:160:40

Check failure on line 122 in code/core/src/common/js-package-manager/JsPackageManagerFactory.ts

View workflow job for this annotation

GitHub Actions / Core Unit Tests, windows-latest

src/common/js-package-manager/JsPackageManagerFactory.test.ts > CLASS: JsPackageManagerFactory > METHOD: getPackageManager > PNPM proxy > ALL EXIST: when all package managers are ok, but only a `pnpm-lock.yaml` file is found

Error: Unable to find a usable package manager within NPM, PNPM, Yarn and Yarn 2 ❯ Function.getPackageManagerType src/common/js-package-manager/JsPackageManagerFactory.ts:122:11 ❯ Function.getPackageManager src/common/js-package-manager/JsPackageManagerFactory.ts:154:37 ❯ src/common/js-package-manager/JsPackageManagerFactory.test.ts:123:40

Check failure on line 122 in code/core/src/common/js-package-manager/JsPackageManagerFactory.ts

View workflow job for this annotation

GitHub Actions / Core Unit Tests, windows-latest

src/common/js-package-manager/JsPackageManagerFactory.test.ts > CLASS: JsPackageManagerFactory > METHOD: getPackageManager > NPM proxy > ALL EXIST: when all package managers are ok, but only a `package-lock.json` file is found

Error: Unable to find a usable package manager within NPM, PNPM, Yarn and Yarn 2 ❯ Function.getPackageManagerType src/common/js-package-manager/JsPackageManagerFactory.ts:122:11 ❯ Function.getPackageManager src/common/js-package-manager/JsPackageManagerFactory.ts:154:37 ❯ src/common/js-package-manager/JsPackageManagerFactory.test.ts:75:40
}

public static getPackageManager(
Expand Down Expand Up @@ -195,7 +195,7 @@
}

function hasNPM(cwd?: string) {
const npmVersionCommand = spawnSync('npm', ['--version'], {
const npmVersionCommand = spawnSync('npm --version', {
cwd,
shell: true,
env: {
Expand All @@ -207,7 +207,7 @@
}

function hasBun(cwd?: string) {
const pnpmVersionCommand = spawnSync('bun', ['--version'], {
const pnpmVersionCommand = spawnSync('bun --version', {
cwd,
shell: true,
env: {
Expand All @@ -219,7 +219,7 @@
}

function hasPNPM(cwd?: string) {
const pnpmVersionCommand = spawnSync('pnpm', ['--version'], {
const pnpmVersionCommand = spawnSync('pnpm --version', {
cwd,
shell: true,
env: {
Expand All @@ -231,7 +231,7 @@
}

function getYarnVersion(cwd?: string): 1 | 2 | undefined {
const yarnVersionCommand = spawnSync('yarn', ['--version'], {
const yarnVersionCommand = spawnSync('yarn --version', {
cwd,
shell: true,
env: {
Expand Down
4 changes: 1 addition & 3 deletions code/lib/cli-storybook/src/upgrade.ts
Original file line number Diff line number Diff line change
Expand Up @@ -76,9 +76,7 @@ const formatPackage = (pkg: Package) => `${pkg.package}@${pkg.version}`;
const warnPackages = (pkgs: Package[]) => pkgs.map((pkg) => `- ${formatPackage(pkg)}`).join('\n');

export const checkVersionConsistency = () => {
const lines = spawnSync('npm', ['ls'], { stdio: 'pipe', shell: true })
.output.toString()
.split('\n');
const lines = spawnSync('npm ls', { stdio: 'pipe', shell: true }).output.toString().split('\n');
const storybookPackages = lines
.map(getStorybookVersion)
.filter((item): item is NonNullable<typeof item> => !!item)
Expand Down
2 changes: 1 addition & 1 deletion code/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@
"lint:prettier": "prettier --write",
"local-registry": "yarn --cwd ../scripts local-registry",
"publish-sandboxes": "yarn --cwd ../scripts publish",
"storybook:ui": "NODE_OPTIONS=\"--max_old_space_size=4096\" core/dist/bin/dispatcher.js dev --port 6006 --config-dir ./.storybook",
"storybook:ui": "NODE_OPTIONS=\"--max_old_space_size=4096 --trace-deprecation\" core/dist/bin/dispatcher.js dev --port 6006 --config-dir ./.storybook",
"storybook:ui:build": "NODE_OPTIONS=\"--max_old_space_size=4096\" core/dist/bin/dispatcher.js build --config-dir ./.storybook --webpack-stats-json",
"storybook:ui:chromatic": "../scripts/node_modules/.bin/chromatic --build-script-name storybook:ui:build --storybook-base-dir ./ --exit-zero-on-changes --exit-once-uploaded",
"storybook:vitest": "yarn test:watch --project storybook-ui",
Expand Down
Loading