From 9c9fb26fec59f5c40a9e7e84edec596cb49577a9 Mon Sep 17 00:00:00 2001 From: Valentin Palkovic Date: Tue, 17 Sep 2024 13:57:07 +0200 Subject: [PATCH 1/3] Merge pull request #29133 from storybookjs/valentin/fix-skip-install-installation CLI: Fix skip-install for stable latest releases (cherry picked from commit 57cdf154a30d35d56629b04ea4640655dd96af3b) --- .circleci/config.yml | 2 + .../JsPackageManager.test.ts | 54 +++++++++++++++++++ .../js-package-manager/JsPackageManager.ts | 12 ++--- 3 files changed, 62 insertions(+), 6 deletions(-) create mode 100644 code/core/src/common/js-package-manager/JsPackageManager.test.ts diff --git a/.circleci/config.yml b/.circleci/config.yml index 3e5c0b499cc6..72f3bf9dc225 100644 --- a/.circleci/config.yml +++ b/.circleci/config.yml @@ -628,6 +628,8 @@ jobs: mkdir empty-<< parameters.template >>-no-install cd empty-<< parameters.template >>-no-install npx storybook init --yes --skip-install + npm install + npm run build-storybook environment: IN_STORYBOOK_SANDBOX: true STORYBOOK_INIT_EMPTY_TYPE: << parameters.template >> diff --git a/code/core/src/common/js-package-manager/JsPackageManager.test.ts b/code/core/src/common/js-package-manager/JsPackageManager.test.ts new file mode 100644 index 000000000000..153edd0be596 --- /dev/null +++ b/code/core/src/common/js-package-manager/JsPackageManager.test.ts @@ -0,0 +1,54 @@ +import { beforeEach, describe, expect, it, vi } from 'vitest'; + +import { JsPackageManager } from './JsPackageManager'; + +vi.mock('../versions', () => ({ + default: { + '@storybook/react': '8.3.0', + }, +})); + +describe('JsPackageManager', () => { + let jsPackageManager: JsPackageManager; + let mockLatestVersion: ReturnType; + let mockStorybookPackagesVersions: Record; + + beforeEach(() => { + mockLatestVersion = vi.fn(); + mockStorybookPackagesVersions = { + '@storybook/react': '8.3.0', + }; + + // @ts-expect-error Ignore abstract class error + jsPackageManager = new JsPackageManager(); + jsPackageManager.latestVersion = mockLatestVersion; + + vi.clearAllMocks(); + }); + + describe('getVersionedPackages method', () => { + it('should return the latest stable release version when current version is the latest stable release', async () => { + mockLatestVersion.mockResolvedValue('8.3.0'); + + const result = await jsPackageManager.getVersionedPackages(['@storybook/react']); + + expect(result).toEqual(['@storybook/react@^8.3.0']); + }); + + it('should return the current version when it is not the latest stable release', async () => { + mockLatestVersion.mockResolvedValue('8.3.1'); + + const result = await jsPackageManager.getVersionedPackages(['@storybook/react']); + + expect(result).toEqual(['@storybook/react@8.3.0']); + }); + + it('should return the latest stable release version when there is no current version', async () => { + mockLatestVersion.mockResolvedValue('2.0.0'); + + const result = await jsPackageManager.getVersionedPackages(['@storybook/new-addon@^8.3.0']); + + expect(result).toEqual(['@storybook/new-addon@^2.0.0']); + }); + }); +}); diff --git a/code/core/src/common/js-package-manager/JsPackageManager.ts b/code/core/src/common/js-package-manager/JsPackageManager.ts index 4b3e00c2f5e7..305ba8d99ed2 100644 --- a/code/core/src/common/js-package-manager/JsPackageManager.ts +++ b/code/core/src/common/js-package-manager/JsPackageManager.ts @@ -337,13 +337,13 @@ export abstract class JsPackageManager { const k = packageName as keyof typeof storybookPackagesVersions; const currentVersion = storybookPackagesVersions[k]; - if (currentVersion === latestInRange) { - return `${packageName}`; - } - if (currentVersion) { - return `${packageName}@${currentVersion}`; + const isLatestStableRelease = currentVersion === latestInRange; + + if (isLatestStableRelease || !currentVersion) { + return `${packageName}@^${latestInRange}`; } - return `${packageName}@^${latestInRange}`; + + return `${packageName}@${currentVersion}`; }) ); } From 499882ae56fccd408f18d4487d5dca2ea60531f0 Mon Sep 17 00:00:00 2001 From: Valentin Palkovic Date: Thu, 19 Sep 2024 11:50:01 +0200 Subject: [PATCH 2/3] Merge pull request #29152 from storybookjs/valentin/fix-package-manager-addition-to-package-json Core: Do not add packageManager field to package.json during `storybook dev` (cherry picked from commit 57ee6e198fd1ffd5227c72e78bd1cd04b19c4d89) --- .../JsPackageManagerFactory.ts | 24 ++++++++++++++++--- 1 file changed, 21 insertions(+), 3 deletions(-) diff --git a/code/core/src/common/js-package-manager/JsPackageManagerFactory.ts b/code/core/src/common/js-package-manager/JsPackageManagerFactory.ts index 7477a1e5f2c0..4b3c6184e59f 100644 --- a/code/core/src/common/js-package-manager/JsPackageManagerFactory.ts +++ b/code/core/src/common/js-package-manager/JsPackageManagerFactory.ts @@ -125,17 +125,35 @@ export class JsPackageManagerFactory { } function hasNPM(cwd?: string) { - const npmVersionCommand = spawnSync('npm', ['--version'], { cwd, shell: true }); + const npmVersionCommand = spawnSync('npm', ['--version'], { + cwd, + shell: true, + env: { + COREPACK_ENABLE_STRICT: '0', + }, + }); return npmVersionCommand.status === 0; } function hasPNPM(cwd?: string) { - const pnpmVersionCommand = spawnSync('pnpm', ['--version'], { cwd, shell: true }); + const pnpmVersionCommand = spawnSync('pnpm', ['--version'], { + cwd, + shell: true, + env: { + COREPACK_ENABLE_STRICT: '0', + }, + }); return pnpmVersionCommand.status === 0; } function getYarnVersion(cwd?: string): 1 | 2 | undefined { - const yarnVersionCommand = spawnSync('yarn', ['--version'], { cwd, shell: true }); + const yarnVersionCommand = spawnSync('yarn', ['--version'], { + cwd, + shell: true, + env: { + COREPACK_ENABLE_STRICT: '0', + }, + }); if (yarnVersionCommand.status !== 0) { return undefined; From 833d58013ae5f09aaecdad2c9c75c7981750605f Mon Sep 17 00:00:00 2001 From: storybook-bot <32066757+storybook-bot@users.noreply.github.com> Date: Thu, 19 Sep 2024 09:52:53 +0000 Subject: [PATCH 3/3] Write changelog for 8.3.2 [skip ci] --- CHANGELOG.md | 5 +++++ code/package.json | 3 ++- docs/versions/latest.json | 2 +- 3 files changed, 8 insertions(+), 2 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 32d3d51cbc00..0bae092457f4 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,3 +1,8 @@ +## 8.3.2 + +- CLI: Fix skip-install for stable latest releases - [#29133](https://github.com/storybookjs/storybook/pull/29133), thanks @valentinpalkovic! +- Core: Do not add packageManager field to package.json during `storybook dev` - [#29152](https://github.com/storybookjs/storybook/pull/29152), thanks @valentinpalkovic! + ## 8.3.1 - Angular: Fix sourceDecorator to apply excludeDecorators flag - [#29069](https://github.com/storybookjs/storybook/pull/29069), thanks @JSMike! diff --git a/code/package.json b/code/package.json index e8eb67fb2f43..56f286fdb8c3 100644 --- a/code/package.json +++ b/code/package.json @@ -295,5 +295,6 @@ "Dependency Upgrades" ] ] - } + }, + "deferredNextVersion": "8.3.2" } diff --git a/docs/versions/latest.json b/docs/versions/latest.json index d83948fbac4c..ef423cd01887 100644 --- a/docs/versions/latest.json +++ b/docs/versions/latest.json @@ -1 +1 @@ -{"version":"8.3.1","info":{"plain":"- Angular: Fix sourceDecorator to apply excludeDecorators flag - [#29069](https://github.com/storybookjs/storybook/pull/29069), thanks @JSMike!\n- Core: Do not prebundle better-opn - [#29137](https://github.com/storybookjs/storybook/pull/29137), thanks @valentinpalkovic!\n- Core: Do not prebundle jsdoc-type-pratt-parser - [#29134](https://github.com/storybookjs/storybook/pull/29134), thanks @valentinpalkovic!\n- Next.js: Upgrade sass-loader from ^12 to ^13 - [#29040](https://github.com/storybookjs/storybook/pull/29040), thanks @HoncharenkoZhenya!"}} +{"version":"8.3.2","info":{"plain":"- CLI: Fix skip-install for stable latest releases - [#29133](https://github.com/storybookjs/storybook/pull/29133), thanks @valentinpalkovic!\n- Core: Do not add packageManager field to package.json during `storybook dev` - [#29152](https://github.com/storybookjs/storybook/pull/29152), thanks @valentinpalkovic!"}}