diff --git a/.circleci/config.yml b/.circleci/config.yml index bd2d13b2af33..6ff1fb7ed744 100644 --- a/.circleci/config.yml +++ b/.circleci/config.yml @@ -16,7 +16,7 @@ parameters: default: "next" executors: - sb_node_18_classic: + sb_node_22_classic: parameters: class: description: The Resource class @@ -25,7 +25,7 @@ executors: default: "small" working_directory: /tmp/storybook docker: - - image: cimg/node:18.19.1 + - image: cimg/node:22.6.0 environment: NODE_OPTIONS: --max_old_space_size=6144 resource_class: <> @@ -38,7 +38,20 @@ executors: default: "small" working_directory: /tmp/storybook docker: - - image: cimg/node:18.19.1-browsers + - image: cimg/node:18.20.3-browsers + environment: + NODE_OPTIONS: --max_old_space_size=6144 + resource_class: <> + sb_node_22_browsers: + parameters: + class: + description: The Resource class + type: enum + enum: ["small", "medium", "medium+", "large", "xlarge"] + default: "small" + working_directory: /tmp/storybook + docker: + - image: cimg/node:22.6.0-browsers environment: NODE_OPTIONS: --max_old_space_size=6144 resource_class: <> @@ -74,7 +87,6 @@ orbs: browser-tools: circleci/browser-tools@1.4.1 discord: antonioned/discord@0.1.0 codecov: codecov/codecov@3.2.4 - bun-orb: cmgriffing/bun-orb@0.0.29 node: circleci/node@5.2.0 nx: nrwl/nx@1.6.2 @@ -109,7 +121,7 @@ jobs: pretty-docs: executor: class: medium - name: sb_node_18_classic + name: sb_node_22_classic steps: - git-shallow-clone/checkout_advanced: clone_options: "--depth 1 --verbose" @@ -135,12 +147,10 @@ jobs: build: executor: class: xlarge - name: sb_node_18_classic + name: sb_node_22_classic steps: - git-shallow-clone/checkout_advanced: clone_options: "--depth 1 --verbose" - - bun-orb/setup: - version: 1.1.1 - restore_cache: name: Restore Yarn cache keys: @@ -182,7 +192,7 @@ jobs: lint: executor: class: large - name: sb_node_18_classic + name: sb_node_22_classic steps: - git-shallow-clone/checkout_advanced: clone_options: "--depth 1 --verbose" @@ -198,12 +208,10 @@ jobs: check: executor: class: xlarge - name: sb_node_18_classic + name: sb_node_22_classic steps: - git-shallow-clone/checkout_advanced: clone_options: "--depth 1 --verbose" - - bun-orb/setup: - version: 1.1.1 - attach_workspace: at: . - nx/set-shas: @@ -218,7 +226,7 @@ jobs: - report-workflow-on-failure - cancel-workflow-on-failure script-checks: - executor: sb_node_18_browsers + executor: sb_node_22_browsers steps: - git-shallow-clone/checkout_advanced: clone_options: "--depth 1 --verbose" @@ -238,7 +246,7 @@ jobs: name: Run tests command: | cd scripts - yarn test --coverage + yarn test --coverage --coverage.all=false - store_test_results: path: scripts/junit.xml - report-workflow-on-failure @@ -246,7 +254,7 @@ jobs: unit-tests: executor: class: xlarge - name: sb_node_18_browsers + name: sb_node_22_browsers steps: - git-shallow-clone/checkout_advanced: clone_options: "--depth 1 --verbose" @@ -256,7 +264,7 @@ jobs: name: Test command: | cd code - yarn test --coverage + yarn test --coverage --coverage.all=false - store_test_results: path: code/junit.xml - persist_to_workspace: @@ -268,7 +276,7 @@ jobs: coverage: executor: class: small - name: sb_node_18_browsers + name: sb_node_22_browsers steps: - git-shallow-clone/checkout_advanced: clone_options: "--depth 1 --verbose" @@ -279,7 +287,7 @@ jobs: chromatic-internal-storybook: executor: class: medium+ - name: sb_node_18_browsers + name: sb_node_22_browsers environment: NODE_OPTIONS: --max_old_space_size=6144 steps: @@ -301,7 +309,7 @@ jobs: type: integer executor: class: medium - name: sb_node_18_browsers + name: sb_node_22_browsers parallelism: << parameters.parallelism >> steps: - git-shallow-clone/checkout_advanced: @@ -348,18 +356,16 @@ jobs: type: integer executor: class: large - name: sb_node_18_browsers + name: sb_node_22_browsers parallelism: << parameters.parallelism >> steps: - git-shallow-clone/checkout_advanced: clone_options: "--depth 1 --verbose" - - bun-orb/setup: - version: 1.1.1 - attach_workspace: at: . - run: name: Starting Event Collector - command: node --loader esbuild-register/loader -r esbuild-register ./event-log-collector.ts + command: yarn jiti ./event-log-collector.ts working_directory: scripts background: true - run: @@ -373,7 +379,7 @@ jobs: TEMPLATE=$(yarn get-template --cadence << pipeline.parameters.workflow >> --task build) if [[ $TEMPLATE != bench/* ]] then - node --loader esbuild-register/loader -r esbuild-register ./event-log-checker.ts build $TEMPLATE + yarn jiti ./event-log-checker.ts build $TEMPLATE fi working_directory: scripts - report-workflow-on-failure: @@ -431,7 +437,7 @@ jobs: type: integer executor: class: medium - name: sb_node_18_browsers + name: sb_node_22_browsers parallelism: << parameters.parallelism >> steps: - checkout @@ -514,7 +520,7 @@ jobs: test-empty-init: executor: class: medium - name: sb_node_18_browsers + name: sb_node_22_browsers parameters: packageManager: type: string @@ -602,6 +608,23 @@ jobs: IN_STORYBOOK_SANDBOX: true STORYBOOK_INIT_EMPTY_TYPE: << parameters.template >> STORYBOOK_DISABLE_TELEMETRY: true + - when: + condition: + equal: ["react-vite-ts", << parameters.template >>] + steps: + - run: + name: Storybook init from empty directory (--skip-install) + command: | + cd code + yarn local-registry --open & + cd ../../ + mkdir empty-<< parameters.template >>-no-install + cd empty-<< parameters.template >>-no-install + npx storybook init --yes --skip-install + environment: + IN_STORYBOOK_SANDBOX: true + STORYBOOK_INIT_EMPTY_TYPE: << parameters.template >> + STORYBOOK_DISABLE_TELEMETRY: true - report-workflow-on-failure test-portable-stories: parameters: diff --git a/.git-blame-ignore-revs b/.git-blame-ignore-revs index a57524a04ebb..4d2cf93d7d43 100644 --- a/.git-blame-ignore-revs +++ b/.git-blame-ignore-revs @@ -2,4 +2,6 @@ c0896915fb7fb9a8dd416b9aebca17abd909d1c1 a41c227037e7e7249b8b376f838f4f8bcc3e3e59 13c46e6c0b7f3dd8cf4ba42d1cfd6714f4777d54 -0a4522a3f84773f39daec4820c49b8a92e9f9d11 \ No newline at end of file +0a4522a3f84773f39daec4820c49b8a92e9f9d11 +e12039c0593ba021ce27cb7245b6067677f27625 +513bb66bb9729ece57581b6eb50e5b338c47c0b9 \ No newline at end of file diff --git a/.github/workflows/canary-release-pr.yml b/.github/workflows/canary-release-pr.yml index 2859f3072c6d..dde7b4eb3606 100644 --- a/.github/workflows/canary-release-pr.yml +++ b/.github/workflows/canary-release-pr.yml @@ -60,10 +60,6 @@ jobs: with: node-version-file: ".nvmrc" - - uses: oven-sh/setup-bun@v1 - with: - bun-version: 1.1.1 - - name: Cache dependencies uses: actions/cache@v4 with: diff --git a/.github/workflows/generate-sandboxes.yml b/.github/workflows/generate-sandboxes.yml index 3782aba5d8a8..09ab43d53601 100644 --- a/.github/workflows/generate-sandboxes.yml +++ b/.github/workflows/generate-sandboxes.yml @@ -29,10 +29,6 @@ jobs: - uses: actions/checkout@v4 with: ref: next - - - uses: oven-sh/setup-bun@v1 - with: - bun-version: 1.1.1 - uses: actions/setup-node@v4 with: @@ -86,10 +82,6 @@ jobs: with: ref: main - - uses: oven-sh/setup-bun@v1 - with: - bun-version: 1.1.1 - - uses: actions/setup-node@v4 with: node-version-file: ".nvmrc" diff --git a/.github/workflows/prepare-non-patch-release.yml b/.github/workflows/prepare-non-patch-release.yml index 54cff041315d..c495114d461e 100644 --- a/.github/workflows/prepare-non-patch-release.yml +++ b/.github/workflows/prepare-non-patch-release.yml @@ -56,10 +56,6 @@ jobs: with: node-version-file: ".nvmrc" - - uses: oven-sh/setup-bun@v1 - with: - bun-version: 1.1.1 - - name: Cache dependencies uses: actions/cache@v4 with: diff --git a/.github/workflows/prepare-patch-release.yml b/.github/workflows/prepare-patch-release.yml index 1a92fd0f8f6a..f66258c0d836 100644 --- a/.github/workflows/prepare-patch-release.yml +++ b/.github/workflows/prepare-patch-release.yml @@ -35,10 +35,6 @@ jobs: with: node-version-file: ".nvmrc" - - uses: oven-sh/setup-bun@v1 - with: - bun-version: 1.1.1 - - name: Cache dependencies uses: actions/cache@v4 with: diff --git a/.github/workflows/publish.yml b/.github/workflows/publish.yml index c48b3a2df59d..61566b49d5bb 100644 --- a/.github/workflows/publish.yml +++ b/.github/workflows/publish.yml @@ -47,10 +47,6 @@ jobs: with: node-version-file: ".nvmrc" - - uses: oven-sh/setup-bun@v1 - with: - bun-version: 1.1.1 - - name: Cache dependencies uses: actions/cache@v4 with: diff --git a/.github/workflows/tests-unit.yml b/.github/workflows/tests-unit.yml index 8cd873592d1b..462f30daf183 100644 --- a/.github/workflows/tests-unit.yml +++ b/.github/workflows/tests-unit.yml @@ -17,9 +17,6 @@ jobs: runs-on: ${{ matrix.os }} steps: - uses: actions/checkout@v4 - - uses: oven-sh/setup-bun@v1 - with: - bun-version: 1.1.1 - name: Set node version uses: actions/setup-node@v4 with: diff --git a/.nvmrc b/.nvmrc index 3c5535cf60a0..dc5f6a52b13e 100644 --- a/.nvmrc +++ b/.nvmrc @@ -1 +1 @@ -18.19.1 +22.6.0 diff --git a/.vscode/settings.json b/.vscode/settings.json index 64101684328f..7f078764150f 100644 --- a/.vscode/settings.json +++ b/.vscode/settings.json @@ -24,14 +24,7 @@ "eslint.options": { "cache": true, "cacheLocation": ".cache/eslint", - "extensions": [ - ".js", - ".jsx", - ".mjs", - ".json", - ".ts", - ".tsx" - ] + "extensions": [".js", ".jsx", ".mjs", ".json", ".ts", ".tsx"] }, "eslint.useESLintClass": true, "eslint.validate": [ @@ -42,10 +35,7 @@ "typescript", "typescriptreact" ], - "eslint.workingDirectories": [ - "./code", - "./scripts" - ], + "eslint.workingDirectories": ["./code", "./scripts"], "files.associations": { "*.js": "javascriptreact" }, @@ -59,5 +49,6 @@ "typescript.preferences.preferTypeOnlyAutoImports": true, "typescript.preferences.quoteStyle": "single", "typescript.preferGoToSourceDefinition": true, - "typescript.tsdk": "./code/node_modules/typescript/lib" -} \ No newline at end of file + "typescript.tsdk": "./code/node_modules/typescript/lib", + "vitest.workspaceConfig": "./code/vitest.workspace.ts" +} diff --git a/CHANGELOG.md b/CHANGELOG.md index bdf5324fe23d..8e8a800ac62f 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,3 +1,8 @@ +## 8.2.8 + +- CLI: Parse more Yarn Berry errors - [#28816](https://github.com/storybookjs/storybook/pull/28816), thanks @yannbf! +- Fix: Invariant failed: Expected package.json#version to be defined in the "undefined" package - [#28752](https://github.com/storybookjs/storybook/pull/28752), thanks @abcdmku! + ## 8.2.7 - CPC: Fix type usage in renderers - [#28745](https://github.com/storybookjs/storybook/pull/28745), thanks @ndelangen! diff --git a/CHANGELOG.prerelease.md b/CHANGELOG.prerelease.md index 6180d4046fb2..03c9c8f635b1 100644 --- a/CHANGELOG.prerelease.md +++ b/CHANGELOG.prerelease.md @@ -1,3 +1,17 @@ +## 8.3.0-alpha.5 + +- Builder-Vite: Add null character prefix to virtual file IDs - [#28863](https://github.com/storybookjs/storybook/pull/28863), thanks @valentinpalkovic! +- CLI: Fix `init --skip-install` - [#28853](https://github.com/storybookjs/storybook/pull/28853), thanks @ndelangen! +- CLI: Parse more Yarn Berry errors - [#28816](https://github.com/storybookjs/storybook/pull/28816), thanks @yannbf! +- Core: Make sure CJS build always has lowest prio - [#28829](https://github.com/storybookjs/storybook/pull/28829), thanks @kasperpeulen! +- Maintenance: Add `node:`-prefix to node core-modules - [#28860](https://github.com/storybookjs/storybook/pull/28860), thanks @ndelangen! +- Next.js: Add @storybook/nextjs-vite package - [#28800](https://github.com/storybookjs/storybook/pull/28800), thanks @valentinpalkovic! +- React: Bundle in `lodash` - [#28609](https://github.com/storybookjs/storybook/pull/28609), thanks @ndelangen! +- Telemetry: Add globals stats - [#28822](https://github.com/storybookjs/storybook/pull/28822), thanks @shilman! +- Telemetry: Add portable stories - [#26764](https://github.com/storybookjs/storybook/pull/26764), thanks @shilman! +- Telemetry: Disable save-from-controls logs for example stories - [#28870](https://github.com/storybookjs/storybook/pull/28870), thanks @shilman! +- Test: Upgrade Vitest to v2 - [#28788](https://github.com/storybookjs/storybook/pull/28788), thanks @yannbf! + ## 8.3.0-alpha.4 - CSF: Allow overridding globals at the story level - [#26654](https://github.com/storybookjs/storybook/pull/26654), thanks @tmeasday! diff --git a/CONTRIBUTING.md b/CONTRIBUTING.md index 4029a3ed691d..4f65401dd4a8 100644 --- a/CONTRIBUTING.md +++ b/CONTRIBUTING.md @@ -8,7 +8,6 @@ You will need to have the following installed: - git - node - yarn -- [bun](https://bun.sh/) ## Using fnm as a Node version manager diff --git a/MIGRATION.md b/MIGRATION.md index dcb75d359224..7235c43b2319 100644 --- a/MIGRATION.md +++ b/MIGRATION.md @@ -1,5 +1,8 @@

Migration

+- [From version 8.2.x to 8.3.x](#from-version-82x-to-83x) + - [New parameters format for addon backgrounds](#new-parameters-format-for-addon-backgrounds) + - [New parameters format for addon viewport](#new-parameters-format-for-addon-viewport) - [From version 8.1.x to 8.2.x](#from-version-81x-to-82x) - [Failed to resolve import "@storybook/X" error](#failed-to-resolve-import-storybookx-error) - [Preview.js globals renamed to initialGlobals](#previewjs-globals-renamed-to-initialglobals) @@ -414,6 +417,90 @@ - [Packages renaming](#packages-renaming) - [Deprecated embedded addons](#deprecated-embedded-addons) +## From version 8.2.x to 8.3.x + +### New parameters format for addon backgrounds + +The `addon-backgrounds` addon now uses a new format for parameters. The `backgrounds` parameter is now an object with a `values` key that contains the background values. + +> ! You need to set the feature flag `backgroundsStoryGlobals` to `true` in your `.storybook/main.ts` to use the new format. + +```diff +// .storybook/preview.js +export const parameters = { + backgrounds: { +- values: [ +- { name: 'twitter', value: '#00aced' }, +- { name: 'facebook', value: '#3b5998' }, +- ], ++ options: { ++ twitter: { name: 'twitter', value: '#00aced' }, ++ facebook: { name: 'facebook', value: '#3b5998' }, ++ }, + }, +}; +``` + +Setting an override value should now be done via a `globals` property on your component/meta or story itself: + +```ts +// Button.stories.ts +export default { + component: Button, + globals: { + backgrounds: { value: 'twitter' }, + }, +}; +``` + +This locks that story to the `twitter` background, it cannot be changed by the addon UI. + +### New parameters format for addon viewport + +> ! You need to set the feature flag `viewportStoryGlobals` to `true` in your `.storybook/main.ts` to use the new format. + +The `addon-viewport` addon now uses a new format for parameters. The `viewport` parameter is now an object with a `viewports` key that contains the viewport values. + +```diff +// .storybook/preview.js +export const parameters = { + viewport: { +- viewports: { +- iphone5: { +- name: 'phone', +- styles: { +- width: '320px', +- height: '568px', +- }, +- }, +- }, ++ options: { ++ iphone5: { ++ name: 'phone', ++ styles: { ++ width: '320px', ++ height: '568px', ++ }, ++ }, ++ }, + }, +}; +``` + +Setting an override value should now be done via a `globals` property on your component/meta or story itself: + +```ts +// Button.stories.ts +export default { + component: Button, + globals: { + viewport: { value: 'phone' }, + }, +}; +``` + +This locks that story to the `phone` viewport, it cannot be changed by the addon UI. + ## From version 8.1.x to 8.2.x ### Failed to resolve import "@storybook/X" error @@ -444,7 +531,7 @@ Starting in 8.2 `preview.js` `globals` are deprecated and have been renamed to ` // .storybook/preview.js export default { - globals: [ a: 1, b: 2 ], -+ initiaGlobals: [ a: 1, b: 2 ], ++ initialGlobals: [ a: 1, b: 2 ], } ``` @@ -2419,7 +2506,7 @@ const meta: Meta = { // Extract all providers (and nested ones) from a ModuleWithProviders importProvidersFrom(SomeOtherModule.forRoot()), ], - } + }), ], }; diff --git a/code/.eslintrc.js b/code/.eslintrc.js index efb47a4e193f..baac3337d8d6 100644 --- a/code/.eslintrc.js +++ b/code/.eslintrc.js @@ -19,6 +19,10 @@ module.exports = { }, plugins: ['local-rules'], rules: { + 'import/no-extraneous-dependencies': [ + 'error', + { devDependencies: true, peerDependencies: true }, + ], 'import/no-unresolved': 'off', // covered by typescript 'eslint-comments/disable-enable-pair': ['error', { allowWholeFile: true }], 'eslint-comments/no-unused-disable': 'error', @@ -55,7 +59,13 @@ module.exports = { }, }, { - files: ['**/template/**/*', '**/vitest.config.ts', '**/addons/docs/**/*'], + files: [ + '*.test.*', + '*.spec.*', + '**/template/**/*', + '**/vitest.config.ts', + '**/addons/docs/**/*', + ], rules: { 'import/no-extraneous-dependencies': 'off', }, diff --git a/code/.storybook/main.ts b/code/.storybook/main.ts index 6a1f51f62f7c..52e8a12175b4 100644 --- a/code/.storybook/main.ts +++ b/code/.storybook/main.ts @@ -1,10 +1,12 @@ -import path from 'path'; +import { join } from 'node:path'; + // eslint-disable-next-line @typescript-eslint/no-restricted-imports import { mergeConfig } from 'vite'; + import type { StorybookConfig } from '../frameworks/react-vite'; -const componentsPath = path.join(__dirname, '../core/src/components'); -const managerApiPath = path.join(__dirname, '../core/src/manager-api'); +const componentsPath = join(__dirname, '../core/src/components'); +const managerApiPath = join(__dirname, '../core/src/manager-api'); const config: StorybookConfig = { stories: [ diff --git a/code/.storybook/manager.tsx b/code/.storybook/manager.tsx index 0bf39f832e2e..b6c5ed75c345 100644 --- a/code/.storybook/manager.tsx +++ b/code/.storybook/manager.tsx @@ -1,4 +1,5 @@ import { addons } from 'storybook/internal/manager-api'; + import startCase from 'lodash/startCase.js'; addons.setConfig({ diff --git a/code/.storybook/preview-head.html b/code/.storybook/preview-head.html deleted file mode 100644 index 4037d732ffec..000000000000 --- a/code/.storybook/preview-head.html +++ /dev/null @@ -1,3 +0,0 @@ - diff --git a/code/.storybook/preview.tsx b/code/.storybook/preview.tsx index 548f29473efc..07d79f194746 100644 --- a/code/.storybook/preview.tsx +++ b/code/.storybook/preview.tsx @@ -1,24 +1,26 @@ -import { global } from '@storybook/global'; import React, { Fragment, useEffect } from 'react'; -import { isChromatic } from './isChromatic'; + +import type { Channel } from 'storybook/internal/channels'; +import { DocsContext as DocsContextProps, useArgs } from 'storybook/internal/preview-api'; +import type { PreviewWeb } from 'storybook/internal/preview-api'; import { Global, ThemeProvider, - themes, - createReset, convert, + createReset, styled, + themes, useTheme, } from 'storybook/internal/theming'; -import { useArgs, DocsContext as DocsContextProps } from 'storybook/internal/preview-api'; -import type { PreviewWeb } from 'storybook/internal/preview-api'; -import type { ReactRenderer, Decorator } from '@storybook/react'; -import type { Channel } from 'storybook/internal/channels'; import { DocsContext } from '@storybook/blocks'; +import { global } from '@storybook/global'; +import type { Decorator, ReactRenderer } from '@storybook/react'; + import { MINIMAL_VIEWPORTS } from '@storybook/addon-viewport'; import { DocsPageWrapper } from '../lib/blocks/src/components'; +import { isChromatic } from './isChromatic'; const { document } = global; diff --git a/code/.yarn/patches/@vitest-expect-npm-1.6.0-0e382f8212.patch b/code/.yarn/patches/@vitest-expect-npm-2.0.5-8933466cce.patch similarity index 82% rename from code/.yarn/patches/@vitest-expect-npm-1.6.0-0e382f8212.patch rename to code/.yarn/patches/@vitest-expect-npm-2.0.5-8933466cce.patch index 04c3bd5cfd7a..ffb0cd3ba2c4 100644 --- a/code/.yarn/patches/@vitest-expect-npm-1.6.0-0e382f8212.patch +++ b/code/.yarn/patches/@vitest-expect-npm-2.0.5-8933466cce.patch @@ -1,18 +1,20 @@ diff --git a/dist/index.js b/dist/index.js -index 13af149aa3c44f52dd5c5a80db3bf5689dfe15ea..1d111032c3fdc104723e19dea49db62be8b79b94 100644 +index ea14a7a52838ff2fb3010996a47f82507315019f..d5248b4daac4333ecdf250952cec3fbd39b89c19 100644 --- a/dist/index.js +++ b/dist/index.js -@@ -6,26 +6,32 @@ import { processError } from '@vitest/utils/error'; - import { util } from 'chai'; - +@@ -6,7 +6,9 @@ import { processError } from '@vitest/utils/error'; + import { use, util } from 'chai'; + const MATCHERS_OBJECT = Symbol.for("matchers-object"); -const JEST_MATCHERS_OBJECT = Symbol.for("$$jest-matchers-object"); +// Patched this symbol for storybook, so that @storybook/test can be used in a jest environment as well. +// Otherwise, vitest will override global jest matchers, and crash. +const JEST_MATCHERS_OBJECT = Symbol.for("$$jest-matchers-object-storybook"); const GLOBAL_EXPECT = Symbol.for("expect-global"); - const ASYMMETRIC_MATCHERS_OBJECT = Symbol.for("asymmetric-matchers-object"); - + const ASYMMETRIC_MATCHERS_OBJECT = Symbol.for( + "asymmetric-matchers-object" +@@ -14,20 +16,24 @@ const ASYMMETRIC_MATCHERS_OBJECT = Symbol.for( + if (!Object.prototype.hasOwnProperty.call(globalThis, MATCHERS_OBJECT)) { const globalState = /* @__PURE__ */ new WeakMap(); - const matchers = /* @__PURE__ */ Object.create(null); diff --git a/code/addons/a11y/README.md b/code/addons/a11y/README.md index 64730ef61033..a6c984d21f65 100755 --- a/code/addons/a11y/README.md +++ b/code/addons/a11y/README.md @@ -168,7 +168,7 @@ You can override these options [at story level too](https://storybook.js.org/doc ```js import React from 'react'; -import { storiesOf, addDecorator, addParameters } from '@storybook/react'; +import { addDecorator, addParameters, storiesOf } from '@storybook/react'; export default { title: 'button', diff --git a/code/addons/a11y/package.json b/code/addons/a11y/package.json index 09276984fff3..e6d8533f9798 100644 --- a/code/addons/a11y/package.json +++ b/code/addons/a11y/package.json @@ -28,9 +28,9 @@ "exports": { ".": { "types": "./dist/index.d.ts", - "node": "./dist/index.js", "import": "./dist/index.mjs", - "require": "./dist/index.js" + "require": "./dist/index.js", + "node": "./dist/index.js" }, "./preview": { "types": "./dist/preview.d.ts", @@ -52,8 +52,8 @@ "!src/**/*" ], "scripts": { - "check": "node --loader ../../../scripts/node_modules/esbuild-register/loader.js -r ../../../scripts/node_modules/esbuild-register/register.js ../../../scripts/prepare/check.ts", - "prep": "node --loader ../../../scripts/node_modules/esbuild-register/loader.js -r ../../../scripts/node_modules/esbuild-register/register.js ../../../scripts/prepare/addon-bundle.ts" + "check": "jiti ../../../scripts/prepare/check.ts", + "prep": "jiti ../../../scripts/prepare/addon-bundle.ts" }, "dependencies": { "@storybook/addon-highlight": "workspace:*", diff --git a/code/addons/a11y/src/a11yRunner.test.ts b/code/addons/a11y/src/a11yRunner.test.ts index 15d99c41002d..402ff24f6cb9 100644 --- a/code/addons/a11y/src/a11yRunner.test.ts +++ b/code/addons/a11y/src/a11yRunner.test.ts @@ -1,6 +1,8 @@ import type { Mock } from 'vitest'; -import { describe, beforeEach, it, expect, vi } from 'vitest'; +import { beforeEach, describe, expect, it, vi } from 'vitest'; + import { addons } from 'storybook/internal/preview-api'; + import { EVENTS } from './constants'; vi.mock('storybook/internal/preview-api'); diff --git a/code/addons/a11y/src/a11yRunner.ts b/code/addons/a11y/src/a11yRunner.ts index 44bac1ee093d..e1cae2ec96b2 100644 --- a/code/addons/a11y/src/a11yRunner.ts +++ b/code/addons/a11y/src/a11yRunner.ts @@ -1,5 +1,7 @@ -import { global } from '@storybook/global'; import { addons } from 'storybook/internal/preview-api'; + +import { global } from '@storybook/global'; + import { EVENTS } from './constants'; import type { A11yParameters } from './params'; diff --git a/code/addons/a11y/src/components/A11YPanel.test.tsx b/code/addons/a11y/src/components/A11YPanel.test.tsx index 7c621b6a377d..a88e3b678288 100644 --- a/code/addons/a11y/src/components/A11YPanel.test.tsx +++ b/code/addons/a11y/src/components/A11YPanel.test.tsx @@ -1,14 +1,14 @@ // @vitest-environment happy-dom +import { act, cleanup, fireEvent, render, waitFor } from '@testing-library/react'; +import { afterEach, beforeEach, describe, expect, it, vi } from 'vitest'; -import { describe, beforeEach, afterEach, it, expect, vi } from 'vitest'; import React from 'react'; -import { render, waitFor, fireEvent, act, cleanup } from '@testing-library/react'; -import { ThemeProvider, themes, convert } from 'storybook/internal/theming'; import * as api from 'storybook/internal/manager-api'; +import { ThemeProvider, convert, themes } from 'storybook/internal/theming'; -import { A11YPanel } from './A11YPanel'; import { EVENTS } from '../constants'; +import { A11YPanel } from './A11YPanel'; vi.mock('storybook/internal/manager-api'); diff --git a/code/addons/a11y/src/components/A11YPanel.tsx b/code/addons/a11y/src/components/A11YPanel.tsx index 0931bb5cc65d..4e259c4c155a 100644 --- a/code/addons/a11y/src/components/A11YPanel.tsx +++ b/code/addons/a11y/src/components/A11YPanel.tsx @@ -1,25 +1,23 @@ import React, { useCallback, useMemo, useState } from 'react'; -import { styled } from 'storybook/internal/theming'; - import { ActionBar, ScrollArea } from 'storybook/internal/components'; -import { SyncIcon, CheckIcon } from '@storybook/icons'; - -import type { AxeResults } from 'axe-core'; import { useChannel, useParameter, useStorybookApi, useStorybookState, } from 'storybook/internal/manager-api'; +import { styled } from 'storybook/internal/theming'; -import { Report } from './Report'; +import { CheckIcon, SyncIcon } from '@storybook/icons'; -import { Tabs } from './Tabs'; +import type { AxeResults } from 'axe-core'; -import { useA11yContext } from './A11yContext'; import { EVENTS } from '../constants'; import type { A11yParameters } from '../params'; +import { useA11yContext } from './A11yContext'; +import { Report } from './Report'; +import { Tabs } from './Tabs'; export enum RuleType { VIOLATION, diff --git a/code/addons/a11y/src/components/A11yContext.test.tsx b/code/addons/a11y/src/components/A11yContext.test.tsx index c65143106789..1a1aab3412b2 100644 --- a/code/addons/a11y/src/components/A11yContext.test.tsx +++ b/code/addons/a11y/src/components/A11yContext.test.tsx @@ -1,15 +1,18 @@ // @vitest-environment happy-dom +import { act, cleanup, render } from '@testing-library/react'; +import { afterEach, beforeEach, describe, expect, it, vi } from 'vitest'; -import { describe, beforeEach, afterEach, it, expect, vi } from 'vitest'; import * as React from 'react'; -import type { AxeResults } from 'axe-core'; -import { render, act, cleanup } from '@testing-library/react'; -import * as api from 'storybook/internal/manager-api'; + import { STORY_CHANGED } from 'storybook/internal/core-events'; +import * as api from 'storybook/internal/manager-api'; + import { HIGHLIGHT } from '@storybook/addon-highlight'; -import { A11yContextProvider, useA11yContext } from './A11yContext'; +import type { AxeResults } from 'axe-core'; + import { EVENTS } from '../constants'; +import { A11yContextProvider, useA11yContext } from './A11yContext'; vi.mock('storybook/internal/manager-api'); const mockedApi = vi.mocked(api); diff --git a/code/addons/a11y/src/components/A11yContext.tsx b/code/addons/a11y/src/components/A11yContext.tsx index 80c74518bc1a..35bc476328b1 100644 --- a/code/addons/a11y/src/components/A11yContext.tsx +++ b/code/addons/a11y/src/components/A11yContext.tsx @@ -1,9 +1,13 @@ import * as React from 'react'; -import { themes, convert } from 'storybook/internal/theming'; -import type { Result } from 'axe-core'; -import { useChannel, useAddonState, useStorybookApi } from 'storybook/internal/manager-api'; + import { STORY_CHANGED, STORY_RENDERED } from 'storybook/internal/core-events'; +import { useAddonState, useChannel, useStorybookApi } from 'storybook/internal/manager-api'; +import { convert, themes } from 'storybook/internal/theming'; + import { HIGHLIGHT } from '@storybook/addon-highlight'; + +import type { Result } from 'axe-core'; + import { ADDON_ID, EVENTS } from '../constants'; export interface Results { diff --git a/code/addons/a11y/src/components/Report/Elements.tsx b/code/addons/a11y/src/components/Report/Elements.tsx index d17697f66f88..6f1bf8f203b1 100644 --- a/code/addons/a11y/src/components/Report/Elements.tsx +++ b/code/addons/a11y/src/components/Report/Elements.tsx @@ -4,10 +4,10 @@ import React from 'react'; import { styled } from 'storybook/internal/theming'; import type { NodeResult } from 'axe-core'; -import { Rules } from './Rules'; import type { RuleType } from '../A11YPanel'; import HighlightToggle from './HighlightToggle'; +import { Rules } from './Rules'; const Item = styled.li({ fontWeight: 600, diff --git a/code/addons/a11y/src/components/Report/HighlightToggle.test.tsx b/code/addons/a11y/src/components/Report/HighlightToggle.test.tsx index b01b1d731202..4bfc197395a9 100644 --- a/code/addons/a11y/src/components/Report/HighlightToggle.test.tsx +++ b/code/addons/a11y/src/components/Report/HighlightToggle.test.tsx @@ -1,11 +1,13 @@ // @vitest-environment happy-dom +import { cleanup, fireEvent, render } from '@testing-library/react'; +import { afterEach, describe, expect, it, vi } from 'vitest'; -import { describe, it, expect, afterEach, vi } from 'vitest'; import React from 'react'; -import { render, fireEvent, cleanup } from '@testing-library/react'; + import type { NodeResult } from 'axe-core'; -import HighlightToggle from './HighlightToggle'; + import { A11yContext } from '../A11yContext'; +import HighlightToggle from './HighlightToggle'; const nodeResult = (target: string): NodeResult => ({ html: '', diff --git a/code/addons/a11y/src/components/Report/HighlightToggle.tsx b/code/addons/a11y/src/components/Report/HighlightToggle.tsx index 40f08966add8..acbd1159945d 100644 --- a/code/addons/a11y/src/components/Report/HighlightToggle.tsx +++ b/code/addons/a11y/src/components/Report/HighlightToggle.tsx @@ -1,7 +1,9 @@ import React from 'react'; + import { styled } from 'storybook/internal/theming'; import type { NodeResult } from 'axe-core'; + import { useA11yContext } from '../A11yContext'; interface ToggleProps { diff --git a/code/addons/a11y/src/components/Report/Info.tsx b/code/addons/a11y/src/components/Report/Info.tsx index 052cfb8de6b7..e85bac76ff6b 100644 --- a/code/addons/a11y/src/components/Report/Info.tsx +++ b/code/addons/a11y/src/components/Report/Info.tsx @@ -2,6 +2,7 @@ import type { FC } from 'react'; import React from 'react'; import { styled } from 'storybook/internal/theming'; + import type { Result } from 'axe-core'; const Wrapper = styled.div({ diff --git a/code/addons/a11y/src/components/Report/Item.tsx b/code/addons/a11y/src/components/Report/Item.tsx index 2089da0f63a3..54f564d1ed34 100644 --- a/code/addons/a11y/src/components/Report/Item.tsx +++ b/code/addons/a11y/src/components/Report/Item.tsx @@ -2,15 +2,15 @@ import React, { Fragment, useState } from 'react'; import { styled } from 'storybook/internal/theming'; -import type { Result } from 'axe-core'; -import { Info } from './Info'; +import { ChevronSmallDownIcon } from '@storybook/icons'; -import { Elements } from './Elements'; -import { Tags } from './Tags'; +import type { Result } from 'axe-core'; import type { RuleType } from '../A11YPanel'; +import { Elements } from './Elements'; import HighlightToggle from './HighlightToggle'; -import { ChevronSmallDownIcon } from '@storybook/icons'; +import { Info } from './Info'; +import { Tags } from './Tags'; const Wrapper = styled.div(({ theme }) => ({ display: 'flex', diff --git a/code/addons/a11y/src/components/Report/Rules.tsx b/code/addons/a11y/src/components/Report/Rules.tsx index a24ded693da7..4c4a9ed037cd 100644 --- a/code/addons/a11y/src/components/Report/Rules.tsx +++ b/code/addons/a11y/src/components/Report/Rules.tsx @@ -1,7 +1,9 @@ import type { FC } from 'react'; import React from 'react'; -import { styled } from 'storybook/internal/theming'; + import { Badge } from 'storybook/internal/components'; +import { styled } from 'storybook/internal/theming'; + import type { CheckResult } from 'axe-core'; import { useResizeDetector } from 'react-resize-detector'; diff --git a/code/addons/a11y/src/components/Report/Tags.tsx b/code/addons/a11y/src/components/Report/Tags.tsx index 4d8c2e81a386..e16c4d52f51f 100644 --- a/code/addons/a11y/src/components/Report/Tags.tsx +++ b/code/addons/a11y/src/components/Report/Tags.tsx @@ -2,6 +2,7 @@ import type { FC } from 'react'; import React from 'react'; import { styled } from 'storybook/internal/theming'; + import type { TagValue } from 'axe-core'; const Wrapper = styled.div({ diff --git a/code/addons/a11y/src/components/Report/index.tsx b/code/addons/a11y/src/components/Report/index.tsx index 0644488614f1..0de6a7d8f582 100644 --- a/code/addons/a11y/src/components/Report/index.tsx +++ b/code/addons/a11y/src/components/Report/index.tsx @@ -1,11 +1,12 @@ import type { FC } from 'react'; import React, { Fragment } from 'react'; + import { EmptyTabContent } from 'storybook/internal/components'; -import type { Result } from 'axe-core'; -import { Item } from './Item'; +import type { Result } from 'axe-core'; import type { RuleType } from '../A11YPanel'; +import { Item } from './Item'; export interface ReportProps { items: Result[]; diff --git a/code/addons/a11y/src/components/Tabs.tsx b/code/addons/a11y/src/components/Tabs.tsx index 6a3fbecbd46a..08ae46714dbd 100644 --- a/code/addons/a11y/src/components/Tabs.tsx +++ b/code/addons/a11y/src/components/Tabs.tsx @@ -1,12 +1,13 @@ import * as React from 'react'; import { styled } from 'storybook/internal/theming'; + import type { NodeResult, Result } from 'axe-core'; import { useResizeDetector } from 'react-resize-detector'; -import HighlightToggle from './Report/HighlightToggle'; import type { RuleType } from './A11YPanel'; import { useA11yContext } from './A11yContext'; +import HighlightToggle from './Report/HighlightToggle'; // TODO: reuse the Tabs component from @storybook/theming instead of re-building identical functionality diff --git a/code/addons/a11y/src/components/VisionSimulator.test.tsx b/code/addons/a11y/src/components/VisionSimulator.test.tsx index 4fb2e127e0b0..5db1d38e7973 100644 --- a/code/addons/a11y/src/components/VisionSimulator.test.tsx +++ b/code/addons/a11y/src/components/VisionSimulator.test.tsx @@ -1,11 +1,13 @@ // @vitest-environment happy-dom - /// ; -import { describe, it, expect } from 'vitest'; -import React from 'react'; -import { render, fireEvent, screen, waitFor } from '@testing-library/react'; +import { fireEvent, render, screen, waitFor } from '@testing-library/react'; import userEvent from '@testing-library/user-event'; -import { ThemeProvider, themes, convert } from 'storybook/internal/theming'; +import { describe, expect, it } from 'vitest'; + +import React from 'react'; + +import { ThemeProvider, convert, themes } from 'storybook/internal/theming'; + import { VisionSimulator, baseList } from './VisionSimulator'; const getOptionByNameAndPercentage = (option: string, percentage?: number) => diff --git a/code/addons/a11y/src/components/VisionSimulator.tsx b/code/addons/a11y/src/components/VisionSimulator.tsx index 419da70240a6..2acc66b21c71 100644 --- a/code/addons/a11y/src/components/VisionSimulator.tsx +++ b/code/addons/a11y/src/components/VisionSimulator.tsx @@ -1,9 +1,11 @@ import type { ReactNode } from 'react'; import React, { useState } from 'react'; + +import { IconButton, TooltipLinkList, WithTooltip } from 'storybook/internal/components'; import { Global, styled } from 'storybook/internal/theming'; -import { IconButton, WithTooltip, TooltipLinkList } from 'storybook/internal/components'; import { AccessibilityIcon } from '@storybook/icons'; + import { Filters } from './ColorFilters'; const iframeId = 'storybook-preview-iframe'; diff --git a/code/addons/a11y/src/manager.test.tsx b/code/addons/a11y/src/manager.test.tsx index ccd232e44543..c95bdf629d0f 100644 --- a/code/addons/a11y/src/manager.test.tsx +++ b/code/addons/a11y/src/manager.test.tsx @@ -1,8 +1,9 @@ // @vitest-environment happy-dom +import { describe, expect, it, vi } from 'vitest'; -import { describe, it, expect, vi } from 'vitest'; import * as api from 'storybook/internal/manager-api'; import type { Addon_BaseType } from 'storybook/internal/types'; + import { PANEL_ID } from './constants'; import './manager'; @@ -56,7 +57,6 @@ describe('A11yManager', () => { > Accessibility - `); diff --git a/code/addons/a11y/src/manager.tsx b/code/addons/a11y/src/manager.tsx index b423e029b310..41e79b3061df 100644 --- a/code/addons/a11y/src/manager.tsx +++ b/code/addons/a11y/src/manager.tsx @@ -1,11 +1,13 @@ import React from 'react'; -import { addons, types, useAddonState } from 'storybook/internal/manager-api'; + import { Badge, Spaced } from 'storybook/internal/components'; -import { ADDON_ID, PANEL_ID, PARAM_KEY } from './constants'; -import { VisionSimulator } from './components/VisionSimulator'; +import { addons, types, useAddonState } from 'storybook/internal/manager-api'; + import { A11YPanel } from './components/A11YPanel'; import type { Results } from './components/A11yContext'; import { A11yContextProvider } from './components/A11yContext'; +import { VisionSimulator } from './components/VisionSimulator'; +import { ADDON_ID, PANEL_ID, PARAM_KEY } from './constants'; const Title = () => { const [addonState] = useAddonState(ADDON_ID); diff --git a/code/addons/a11y/src/params.ts b/code/addons/a11y/src/params.ts index 4d529eac8503..2428b38add45 100644 --- a/code/addons/a11y/src/params.ts +++ b/code/addons/a11y/src/params.ts @@ -1,4 +1,4 @@ -import type { ElementContext, Spec, RunOptions } from 'axe-core'; +import type { ElementContext, RunOptions, Spec } from 'axe-core'; export interface Setup { element?: ElementContext; diff --git a/code/addons/a11y/vitest.config.ts b/code/addons/a11y/vitest.config.ts index 03172200442f..7420176b2e46 100644 --- a/code/addons/a11y/vitest.config.ts +++ b/code/addons/a11y/vitest.config.ts @@ -1,4 +1,5 @@ import { defineConfig, mergeConfig } from 'vitest/config'; + import { vitestCommonConfig } from '../../vitest.workspace'; export default mergeConfig( diff --git a/code/addons/actions/package.json b/code/addons/actions/package.json index 898ef0754f2d..96275b93501d 100644 --- a/code/addons/actions/package.json +++ b/code/addons/actions/package.json @@ -24,9 +24,9 @@ "exports": { ".": { "types": "./dist/index.d.ts", - "node": "./dist/index.js", "import": "./dist/index.mjs", - "require": "./dist/index.js" + "require": "./dist/index.js", + "node": "./dist/index.js" }, "./decorator": { "types": "./dist/decorator.d.ts", @@ -64,8 +64,8 @@ "!src/**/*" ], "scripts": { - "check": "node --loader ../../../scripts/node_modules/esbuild-register/loader.js -r ../../../scripts/node_modules/esbuild-register/register.js ../../../scripts/prepare/check.ts", - "prep": "node --loader ../../../scripts/node_modules/esbuild-register/loader.js -r ../../../scripts/node_modules/esbuild-register/register.js ../../../scripts/prepare/addon-bundle.ts" + "check": "jiti ../../../scripts/prepare/check.ts", + "prep": "jiti ../../../scripts/prepare/addon-bundle.ts" }, "dependencies": { "@storybook/global": "^5.0.0", diff --git a/code/addons/actions/src/addArgs.ts b/code/addons/actions/src/addArgs.ts index 1a114fa22222..f0ee718ed28a 100644 --- a/code/addons/actions/src/addArgs.ts +++ b/code/addons/actions/src/addArgs.ts @@ -1,4 +1,5 @@ import type { ArgsEnhancer } from 'storybook/internal/types'; + import { addActionsFromArgTypes, inferActionsFromArgTypesRegex } from './addArgsHelpers'; export const argsEnhancers: ArgsEnhancer[] = [ diff --git a/code/addons/actions/src/addArgsHelpers.test.ts b/code/addons/actions/src/addArgsHelpers.test.ts index 4ad092c93b9c..99b8da579089 100644 --- a/code/addons/actions/src/addArgsHelpers.test.ts +++ b/code/addons/actions/src/addArgsHelpers.test.ts @@ -1,6 +1,8 @@ -import { describe, it, expect } from 'vitest'; +import { describe, expect, it } from 'vitest'; + import type { StoryContext } from 'storybook/internal/types'; -import { inferActionsFromArgTypesRegex, addActionsFromArgTypes } from './addArgsHelpers'; + +import { addActionsFromArgTypes, inferActionsFromArgTypesRegex } from './addArgsHelpers'; describe('actions parameter enhancers', () => { describe('actions.argTypesRegex parameter', () => { diff --git a/code/addons/actions/src/addArgsHelpers.ts b/code/addons/actions/src/addArgsHelpers.ts index f86400fdaab0..f13b98274df4 100644 --- a/code/addons/actions/src/addArgsHelpers.ts +++ b/code/addons/actions/src/addArgsHelpers.ts @@ -1,4 +1,5 @@ -import type { Args, Renderer, ArgsEnhancer } from 'storybook/internal/types'; +import type { Args, ArgsEnhancer, Renderer } from 'storybook/internal/types'; + import { action } from './runtime/action'; // interface ActionsParameter { diff --git a/code/addons/actions/src/components/ActionLogger/index.tsx b/code/addons/actions/src/components/ActionLogger/index.tsx index afff6535f047..25ab0da611ac 100644 --- a/code/addons/actions/src/components/ActionLogger/index.tsx +++ b/code/addons/actions/src/components/ActionLogger/index.tsx @@ -1,13 +1,14 @@ import type { ElementRef, ReactNode } from 'react'; -import React, { forwardRef, Fragment, useEffect, useRef } from 'react'; +import React, { Fragment, forwardRef, useEffect, useRef } from 'react'; + +import { ActionBar, ScrollArea } from 'storybook/internal/components'; import type { Theme } from 'storybook/internal/theming'; import { styled, withTheme } from 'storybook/internal/theming'; import { Inspector } from 'react-inspector'; -import { ActionBar, ScrollArea } from 'storybook/internal/components'; -import { Action, Counter, InspectorContainer } from './style'; import type { ActionDisplay } from '../../models'; +import { Action, Counter, InspectorContainer } from './style'; const UnstyledWrapped = forwardRef( ({ children, className }, ref) => ( diff --git a/code/addons/actions/src/components/ActionLogger/style.tsx b/code/addons/actions/src/components/ActionLogger/style.tsx index 351cda9a95a2..77e5e30e910e 100644 --- a/code/addons/actions/src/components/ActionLogger/style.tsx +++ b/code/addons/actions/src/components/ActionLogger/style.tsx @@ -1,4 +1,5 @@ import { styled } from 'storybook/internal/theming'; + import { opacify } from 'polished'; export const Action = styled.div({ diff --git a/code/addons/actions/src/containers/ActionLogger/index.tsx b/code/addons/actions/src/containers/ActionLogger/index.tsx index ff9e50302633..075ba94af565 100644 --- a/code/addons/actions/src/containers/ActionLogger/index.tsx +++ b/code/addons/actions/src/containers/ActionLogger/index.tsx @@ -1,12 +1,13 @@ import React, { Component } from 'react'; -import { dequal as deepEqual } from 'dequal'; -import type { API } from 'storybook/internal/manager-api'; import { STORY_CHANGED } from 'storybook/internal/core-events'; +import type { API } from 'storybook/internal/manager-api'; + +import { dequal as deepEqual } from 'dequal'; import { ActionLogger as ActionLoggerComponent } from '../../components/ActionLogger'; -import type { ActionDisplay } from '../../models'; import { CLEAR_ID, EVENT_ID } from '../../constants'; +import type { ActionDisplay } from '../../models'; interface ActionLoggerProps { active: boolean; diff --git a/code/addons/actions/src/decorator.ts b/code/addons/actions/src/decorator.ts index 6e8319680cd3..e0eb6148f216 100644 --- a/code/addons/actions/src/decorator.ts +++ b/code/addons/actions/src/decorator.ts @@ -1,9 +1,10 @@ -import { global } from '@storybook/global'; -import { useEffect, makeDecorator } from 'storybook/internal/preview-api'; +import { makeDecorator, useEffect } from 'storybook/internal/preview-api'; import type { PartialStoryFn, Renderer } from 'storybook/internal/types'; -import { actions } from './runtime/actions'; + +import { global } from '@storybook/global'; import { PARAM_KEY } from './constants'; +import { actions } from './runtime/actions'; const { document, Element } = global; diff --git a/code/addons/actions/src/loaders.ts b/code/addons/actions/src/loaders.ts index 93bc938cb652..585d8e3815b7 100644 --- a/code/addons/actions/src/loaders.ts +++ b/code/addons/actions/src/loaders.ts @@ -1,7 +1,9 @@ /* eslint-disable no-underscore-dangle */ import type { LoaderFunction } from 'storybook/internal/types'; + import { global } from '@storybook/global'; import type { onMockCall as onMockCallType } from '@storybook/test'; + import { action } from './runtime'; let subscribed = false; diff --git a/code/addons/actions/src/manager.tsx b/code/addons/actions/src/manager.tsx index 944f5e4e5971..341d9c1f423f 100644 --- a/code/addons/actions/src/manager.tsx +++ b/code/addons/actions/src/manager.tsx @@ -1,9 +1,11 @@ import React from 'react'; -import { addons, types, useAddonState, useChannel } from 'storybook/internal/manager-api'; -import { STORY_CHANGED } from 'storybook/internal/core-events'; + import { Badge, Spaced } from 'storybook/internal/components'; -import ActionLogger from './containers/ActionLogger'; +import { STORY_CHANGED } from 'storybook/internal/core-events'; +import { addons, types, useAddonState, useChannel } from 'storybook/internal/manager-api'; + import { ADDON_ID, CLEAR_ID, EVENT_ID, PANEL_ID, PARAM_KEY } from './constants'; +import ActionLogger from './containers/ActionLogger'; function Title() { const [{ count }, setCount] = useAddonState(ADDON_ID, { count: 0 }); diff --git a/code/addons/actions/src/runtime/__tests__/action.test.js b/code/addons/actions/src/runtime/__tests__/action.test.js index 5276d7a75e51..cd6e695304f5 100644 --- a/code/addons/actions/src/runtime/__tests__/action.test.js +++ b/code/addons/actions/src/runtime/__tests__/action.test.js @@ -1,5 +1,7 @@ -import { describe, it, expect, vi } from 'vitest'; +import { describe, expect, it, vi } from 'vitest'; + import { addons } from 'storybook/internal/preview-api'; + import { action, configureActions } from '../..'; vi.mock('storybook/internal/preview-api'); diff --git a/code/addons/actions/src/runtime/__tests__/actions.test.js b/code/addons/actions/src/runtime/__tests__/actions.test.js index 04cf68b9e79b..3e524d827a08 100644 --- a/code/addons/actions/src/runtime/__tests__/actions.test.js +++ b/code/addons/actions/src/runtime/__tests__/actions.test.js @@ -1,5 +1,7 @@ -import { describe, it, expect, vi } from 'vitest'; +import { describe, expect, it, vi } from 'vitest'; + import { addons } from 'storybook/internal/preview-api'; + import { actions } from '../..'; vi.mock('storybook/internal/preview-api'); diff --git a/code/addons/actions/src/runtime/__tests__/configureActions.test.js b/code/addons/actions/src/runtime/__tests__/configureActions.test.js index 7034904a2a5c..acd29ac33166 100644 --- a/code/addons/actions/src/runtime/__tests__/configureActions.test.js +++ b/code/addons/actions/src/runtime/__tests__/configureActions.test.js @@ -1,6 +1,7 @@ -import { describe, it, expect } from 'vitest'; -import { config } from '../configureActions'; +import { describe, expect, it } from 'vitest'; + import { configureActions } from '../..'; +import { config } from '../configureActions'; describe('Configure Actions', () => { it('can configure actions', () => { diff --git a/code/addons/actions/src/runtime/action.ts b/code/addons/actions/src/runtime/action.ts index a5b39c3e340a..00295c007e8d 100644 --- a/code/addons/actions/src/runtime/action.ts +++ b/code/addons/actions/src/runtime/action.ts @@ -1,9 +1,12 @@ -import { v4 as uuidv4 } from 'uuid'; import type { PreviewWeb } from 'storybook/internal/preview-api'; import { addons } from 'storybook/internal/preview-api'; +import { ImplicitActionsDuringRendering } from 'storybook/internal/preview-errors'; import type { Renderer } from 'storybook/internal/types'; + import { global } from '@storybook/global'; -import { ImplicitActionsDuringRendering } from 'storybook/internal/preview-errors'; + +import { v4 as uuidv4 } from 'uuid'; + import { EVENT_ID } from '../constants'; import type { ActionDisplay, ActionOptions, HandlerFunction } from '../models'; import { config } from './configureActions'; diff --git a/code/addons/actions/src/runtime/actions.ts b/code/addons/actions/src/runtime/actions.ts index 3deeb185e641..9cbb57c4198b 100644 --- a/code/addons/actions/src/runtime/actions.ts +++ b/code/addons/actions/src/runtime/actions.ts @@ -1,5 +1,5 @@ +import type { ActionOptions, ActionsFunction, ActionsMap } from '../models'; import { action } from './action'; -import type { ActionsFunction, ActionOptions, ActionsMap } from '../models'; import { config } from './configureActions'; export const actions: ActionsFunction = (...args: any[]) => { diff --git a/code/addons/actions/template/stories/parameters.stories.ts b/code/addons/actions/template/stories/parameters.stories.ts index e4a5bf0ef9dd..f184f89a1538 100644 --- a/code/addons/actions/template/stories/parameters.stories.ts +++ b/code/addons/actions/template/stories/parameters.stories.ts @@ -1,4 +1,5 @@ import { global as globalThis } from '@storybook/global'; + import { withActions } from '@storybook/addon-actions/decorator'; export default { diff --git a/code/addons/actions/vitest.config.ts b/code/addons/actions/vitest.config.ts index 03172200442f..7420176b2e46 100644 --- a/code/addons/actions/vitest.config.ts +++ b/code/addons/actions/vitest.config.ts @@ -1,4 +1,5 @@ import { defineConfig, mergeConfig } from 'vitest/config'; + import { vitestCommonConfig } from '../../vitest.workspace'; export default mergeConfig( diff --git a/code/addons/backgrounds/package.json b/code/addons/backgrounds/package.json index 9c6cbac80053..474a82f29c04 100644 --- a/code/addons/backgrounds/package.json +++ b/code/addons/backgrounds/package.json @@ -28,9 +28,9 @@ "exports": { ".": { "types": "./dist/index.d.ts", - "node": "./dist/index.js", "import": "./dist/index.mjs", - "require": "./dist/index.js" + "require": "./dist/index.js", + "node": "./dist/index.js" }, "./preview": { "types": "./dist/preview.d.ts", @@ -52,8 +52,8 @@ "!src/**/*" ], "scripts": { - "check": "node --loader ../../../scripts/node_modules/esbuild-register/loader.js -r ../../../scripts/node_modules/esbuild-register/register.js ../../../scripts/prepare/check.ts", - "prep": "node --loader ../../../scripts/node_modules/esbuild-register/loader.js -r ../../../scripts/node_modules/esbuild-register/register.js ../../../scripts/prepare/addon-bundle.ts" + "check": "jiti ../../../scripts/prepare/check.ts", + "prep": "jiti ../../../scripts/prepare/addon-bundle.ts" }, "dependencies": { "@storybook/global": "^5.0.0", diff --git a/code/addons/backgrounds/src/components/Tool.tsx b/code/addons/backgrounds/src/components/Tool.tsx index e214780714e4..5f94606d0614 100644 --- a/code/addons/backgrounds/src/components/Tool.tsx +++ b/code/addons/backgrounds/src/components/Tool.tsx @@ -1,9 +1,10 @@ -import React, { useState, memo, Fragment, useCallback } from 'react'; +import React, { Fragment, memo, useCallback, useState } from 'react'; +import { IconButton, TooltipLinkList, WithTooltip } from 'storybook/internal/components'; import { useGlobals, useParameter } from 'storybook/internal/manager-api'; -import { IconButton, WithTooltip, TooltipLinkList } from 'storybook/internal/components'; import { CircleIcon, GridIcon, PhotoIcon, RefreshIcon } from '@storybook/icons'; + import { PARAM_KEY as KEY } from '../constants'; import type { Background, BackgroundMap, Config, GlobalStateUpdate } from '../types'; diff --git a/code/addons/backgrounds/src/decorator.ts b/code/addons/backgrounds/src/decorator.ts index bdee2f2ea19b..ecaccb44c99d 100644 --- a/code/addons/backgrounds/src/decorator.ts +++ b/code/addons/backgrounds/src/decorator.ts @@ -1,13 +1,13 @@ import { useEffect } from 'storybook/internal/preview-api'; import type { Renderer, - PartialStoryFn as StoryFunction, StoryContext, + PartialStoryFn as StoryFunction, } from 'storybook/internal/types'; import { PARAM_KEY as KEY } from './constants'; -import { clearStyles, addBackgroundStyle, isReduceMotionEnabled, addGridStyle } from './utils'; import type { Config, GridConfig } from './types'; +import { addBackgroundStyle, addGridStyle, clearStyles, isReduceMotionEnabled } from './utils'; const defaultGrid: GridConfig = { cellSize: 100, diff --git a/code/addons/backgrounds/src/legacy/BackgroundSelectorLegacy.tsx b/code/addons/backgrounds/src/legacy/BackgroundSelectorLegacy.tsx index dcc8ffb8e658..cc5bc3d00b7b 100644 --- a/code/addons/backgrounds/src/legacy/BackgroundSelectorLegacy.tsx +++ b/code/addons/backgrounds/src/legacy/BackgroundSelectorLegacy.tsx @@ -1,15 +1,17 @@ import type { FC, ReactElement } from 'react'; -import React, { useState, useCallback, useMemo, memo } from 'react'; -import memoize from 'memoizerific'; +import React, { memo, useCallback, useMemo, useState } from 'react'; -import { useParameter, useGlobals } from 'storybook/internal/manager-api'; import { logger } from 'storybook/internal/client-logger'; -import { IconButton, WithTooltip, TooltipLinkList } from 'storybook/internal/components'; +import { IconButton, TooltipLinkList, WithTooltip } from 'storybook/internal/components'; +import { useGlobals, useParameter } from 'storybook/internal/manager-api'; import { PhotoIcon } from '@storybook/icons'; + +import memoize from 'memoizerific'; + import { PARAM_KEY as BACKGROUNDS_PARAM_KEY } from '../constants'; -import { ColorIcon } from './ColorIcon'; import type { Background } from '../types'; +import { ColorIcon } from './ColorIcon'; import { getBackgroundColorByName } from './getBackgroundColorByName'; export interface DeprecatedGlobalState { diff --git a/code/addons/backgrounds/src/legacy/GridSelectorLegacy.tsx b/code/addons/backgrounds/src/legacy/GridSelectorLegacy.tsx index e061fd4f2311..2cb6e192574c 100644 --- a/code/addons/backgrounds/src/legacy/GridSelectorLegacy.tsx +++ b/code/addons/backgrounds/src/legacy/GridSelectorLegacy.tsx @@ -1,10 +1,11 @@ import type { FC } from 'react'; import React, { memo } from 'react'; -import { useGlobals, useParameter } from 'storybook/internal/manager-api'; import { IconButton } from 'storybook/internal/components'; +import { useGlobals, useParameter } from 'storybook/internal/manager-api'; import { GridIcon } from '@storybook/icons'; + import { PARAM_KEY as BACKGROUNDS_PARAM_KEY } from '../constants'; export const GridToolLegacy: FC = memo(function GridSelector() { diff --git a/code/addons/backgrounds/src/legacy/getBackgroundColorByName.ts b/code/addons/backgrounds/src/legacy/getBackgroundColorByName.ts index 95b5296752c1..e5fea7ee637d 100644 --- a/code/addons/backgrounds/src/legacy/getBackgroundColorByName.ts +++ b/code/addons/backgrounds/src/legacy/getBackgroundColorByName.ts @@ -1,5 +1,7 @@ -import { dedent } from 'ts-dedent'; import { logger } from 'storybook/internal/client-logger'; + +import { dedent } from 'ts-dedent'; + import type { Background } from '../types'; export const getBackgroundColorByName = ( diff --git a/code/addons/backgrounds/src/legacy/withBackgroundLegacy.ts b/code/addons/backgrounds/src/legacy/withBackgroundLegacy.ts index ba649a0a1d36..a7d42e9d46b0 100644 --- a/code/addons/backgrounds/src/legacy/withBackgroundLegacy.ts +++ b/code/addons/backgrounds/src/legacy/withBackgroundLegacy.ts @@ -1,12 +1,12 @@ -import { useMemo, useEffect } from 'storybook/internal/preview-api'; +import { useEffect, useMemo } from 'storybook/internal/preview-api'; import type { Renderer, - PartialStoryFn as StoryFunction, StoryContext, + PartialStoryFn as StoryFunction, } from 'storybook/internal/types'; import { PARAM_KEY as BACKGROUNDS_PARAM_KEY } from '../constants'; -import { clearStyles, addBackgroundStyle, isReduceMotionEnabled } from '../utils'; +import { addBackgroundStyle, clearStyles, isReduceMotionEnabled } from '../utils'; import { getBackgroundColorByName } from './getBackgroundColorByName'; export const withBackground = ( diff --git a/code/addons/backgrounds/src/legacy/withGridLegacy.ts b/code/addons/backgrounds/src/legacy/withGridLegacy.ts index 801a1962d926..3fb711c772e2 100644 --- a/code/addons/backgrounds/src/legacy/withGridLegacy.ts +++ b/code/addons/backgrounds/src/legacy/withGridLegacy.ts @@ -1,12 +1,12 @@ -import { useMemo, useEffect } from 'storybook/internal/preview-api'; +import { useEffect, useMemo } from 'storybook/internal/preview-api'; import type { Renderer, - PartialStoryFn as StoryFunction, StoryContext, + PartialStoryFn as StoryFunction, } from 'storybook/internal/types'; -import { clearStyles, addGridStyle } from '../utils'; import { PARAM_KEY as BACKGROUNDS_PARAM_KEY } from '../constants'; +import { addGridStyle, clearStyles } from '../utils'; export const withGrid = (StoryFn: StoryFunction, context: StoryContext) => { const { globals, parameters } = context; diff --git a/code/addons/backgrounds/src/manager.tsx b/code/addons/backgrounds/src/manager.tsx index 3f8ab23da58d..a1cc71c46ea4 100644 --- a/code/addons/backgrounds/src/manager.tsx +++ b/code/addons/backgrounds/src/manager.tsx @@ -1,10 +1,11 @@ import React, { Fragment } from 'react'; + import { addons, types } from 'storybook/internal/manager-api'; +import { BackgroundTool } from './components/Tool'; import { ADDON_ID } from './constants'; import { BackgroundToolLegacy } from './legacy/BackgroundSelectorLegacy'; import { GridToolLegacy } from './legacy/GridSelectorLegacy'; -import { BackgroundTool } from './components/Tool'; addons.register(ADDON_ID, () => { addons.add(ADDON_ID, { diff --git a/code/addons/backgrounds/src/preview.ts b/code/addons/backgrounds/src/preview.ts index dad8dad077bb..9d773da2d48e 100644 --- a/code/addons/backgrounds/src/preview.ts +++ b/code/addons/backgrounds/src/preview.ts @@ -1,8 +1,9 @@ import type { Addon_DecoratorFunction } from 'storybook/internal/types'; -import { withBackground } from './legacy/withBackgroundLegacy'; -import { withGrid } from './legacy/withGridLegacy'; + import { PARAM_KEY as KEY } from './constants'; import { withBackgroundAndGrid } from './decorator'; +import { withBackground } from './legacy/withBackgroundLegacy'; +import { withGrid } from './legacy/withGridLegacy'; import type { Config, GlobalState } from './types'; export const decorators: Addon_DecoratorFunction[] = FEATURES?.backgroundsStoryGlobals diff --git a/code/addons/backgrounds/vitest.config.ts b/code/addons/backgrounds/vitest.config.ts index 03172200442f..7420176b2e46 100644 --- a/code/addons/backgrounds/vitest.config.ts +++ b/code/addons/backgrounds/vitest.config.ts @@ -1,4 +1,5 @@ import { defineConfig, mergeConfig } from 'vitest/config'; + import { vitestCommonConfig } from '../../vitest.workspace'; export default mergeConfig( diff --git a/code/addons/controls/package.json b/code/addons/controls/package.json index 8d5fe84da8ec..9f109664fdcb 100644 --- a/code/addons/controls/package.json +++ b/code/addons/controls/package.json @@ -28,9 +28,9 @@ "exports": { ".": { "types": "./dist/index.d.ts", - "node": "./dist/index.js", "import": "./dist/index.mjs", - "require": "./dist/index.js" + "require": "./dist/index.js", + "node": "./dist/index.js" }, "./manager": "./dist/manager.js", "./register": "./dist/manager.js", @@ -47,8 +47,8 @@ "!src/**/*" ], "scripts": { - "check": "node --loader ../../../scripts/node_modules/esbuild-register/loader.js -r ../../../scripts/node_modules/esbuild-register/register.js ../../../scripts/prepare/check.ts", - "prep": "node --loader ../../../scripts/node_modules/esbuild-register/loader.js -r ../../../scripts/node_modules/esbuild-register/register.js ../../../scripts/prepare/addon-bundle.ts" + "check": "jiti ../../../scripts/prepare/check.ts", + "prep": "jiti ../../../scripts/prepare/addon-bundle.ts" }, "dependencies": { "dequal": "^2.0.2", diff --git a/code/addons/controls/src/ControlsPanel.tsx b/code/addons/controls/src/ControlsPanel.tsx index 20d3e695c2bd..a84591aefb41 100644 --- a/code/addons/controls/src/ControlsPanel.tsx +++ b/code/addons/controls/src/ControlsPanel.tsx @@ -1,19 +1,22 @@ -import { dequal as deepEqual } from 'dequal'; import React, { useEffect, useMemo, useState } from 'react'; -import { global } from '@storybook/global'; + import { + useArgTypes, useArgs, useGlobals, - useArgTypes, useParameter, useStorybookState, } from 'storybook/internal/manager-api'; -import { PureArgsTable as ArgsTable, type PresetColor, type SortType } from '@storybook/blocks'; import { styled } from 'storybook/internal/theming'; import type { ArgTypes } from 'storybook/internal/types'; -import { PARAM_KEY } from './constants'; +import { PureArgsTable as ArgsTable, type PresetColor, type SortType } from '@storybook/blocks'; +import { global } from '@storybook/global'; + +import { dequal as deepEqual } from 'dequal'; + import { SaveStory } from './SaveStory'; +import { PARAM_KEY } from './constants'; // Remove undefined values (top-level only) const clean = (obj: { [key: string]: any }) => diff --git a/code/addons/controls/src/SaveStory.stories.tsx b/code/addons/controls/src/SaveStory.stories.tsx index 9dbe620da7fb..9c39f6746e04 100644 --- a/code/addons/controls/src/SaveStory.stories.tsx +++ b/code/addons/controls/src/SaveStory.stories.tsx @@ -1,9 +1,11 @@ import React from 'react'; -import { action } from '@storybook/addon-actions'; + import type { Meta, StoryObj } from '@storybook/react'; +import { expect, fireEvent, fn, userEvent, within } from '@storybook/test'; + +import { action } from '@storybook/addon-actions'; import { SaveStory } from './SaveStory'; -import { expect, fireEvent, fn, userEvent, within } from '@storybook/test'; const meta = { component: SaveStory, diff --git a/code/addons/controls/src/SaveStory.tsx b/code/addons/controls/src/SaveStory.tsx index 8cb9bf716a3f..56e50a0f0326 100644 --- a/code/addons/controls/src/SaveStory.tsx +++ b/code/addons/controls/src/SaveStory.tsx @@ -1,3 +1,5 @@ +import React from 'react'; + import { Bar as BaseBar, Button, @@ -7,9 +9,9 @@ import { TooltipNote, WithTooltip, } from 'storybook/internal/components'; -import { AddIcon, CheckIcon, UndoIcon } from '@storybook/icons'; import { keyframes, styled } from 'storybook/internal/theming'; -import React from 'react'; + +import { AddIcon, CheckIcon, UndoIcon } from '@storybook/icons'; const slideIn = keyframes({ from: { transform: 'translateY(40px)' }, diff --git a/code/addons/controls/src/manager.tsx b/code/addons/controls/src/manager.tsx index 31640963a522..b745bad9eb16 100644 --- a/code/addons/controls/src/manager.tsx +++ b/code/addons/controls/src/manager.tsx @@ -1,5 +1,5 @@ import React from 'react'; -import { dequal as deepEqual } from 'dequal'; + import { AddonPanel, Badge, Spaced } from 'storybook/internal/components'; import type { ResponseData, @@ -14,9 +14,13 @@ import { useArgTypes, } from 'storybook/internal/manager-api'; import { color } from 'storybook/internal/theming'; + +import type { Args } from '@storybook/csf'; + +import { dequal as deepEqual } from 'dequal'; + import { ControlsPanel } from './ControlsPanel'; import { ADDON_ID, PARAM_KEY } from './constants'; -import type { Args } from '@storybook/csf'; function Title() { const rows = useArgTypes(); diff --git a/code/addons/controls/src/preset/checkDocsLoaded.ts b/code/addons/controls/src/preset/checkDocsLoaded.ts index bd801324a1ee..7f97c3267c5d 100644 --- a/code/addons/controls/src/preset/checkDocsLoaded.ts +++ b/code/addons/controls/src/preset/checkDocsLoaded.ts @@ -1,5 +1,6 @@ +import { isAbsolute, join } from 'node:path'; + import { checkAddonOrder, serverRequire } from 'storybook/internal/common'; -import path from 'path'; export const checkDocsLoaded = (configDir: string) => { checkAddonOrder({ @@ -11,9 +12,9 @@ export const checkDocsLoaded = (configDir: string) => { name: '@storybook/addon-controls', inEssentials: true, }, - configFile: path.isAbsolute(configDir) - ? path.join(configDir, 'main') - : path.join(process.cwd(), configDir, 'main'), + configFile: isAbsolute(configDir) + ? join(configDir, 'main') + : join(process.cwd(), configDir, 'main'), getConfig: (configFile) => serverRequire(configFile), }); }; diff --git a/code/addons/controls/template/stories/basics.stories.ts b/code/addons/controls/template/stories/basics.stories.ts index a75abbf2fb4d..bcd5cd147aae 100644 --- a/code/addons/controls/template/stories/basics.stories.ts +++ b/code/addons/controls/template/stories/basics.stories.ts @@ -1,6 +1,7 @@ -import { global as globalThis } from '@storybook/global'; import type { PartialStoryFn, StoryContext } from 'storybook/internal/types'; +import { global as globalThis } from '@storybook/global'; + export default { component: globalThis.Components.Pre, decorators: [ diff --git a/code/addons/controls/template/stories/conditional.stories.ts b/code/addons/controls/template/stories/conditional.stories.ts index ed3c51d8ba8e..56d43aa7366f 100644 --- a/code/addons/controls/template/stories/conditional.stories.ts +++ b/code/addons/controls/template/stories/conditional.stories.ts @@ -1,6 +1,7 @@ -import { global as globalThis } from '@storybook/global'; import type { PartialStoryFn, StoryContext } from 'storybook/internal/types'; +import { global as globalThis } from '@storybook/global'; + export default { component: globalThis.Components.Pre, decorators: [ diff --git a/code/addons/controls/template/stories/disable.stories.ts b/code/addons/controls/template/stories/disable.stories.ts index 653840df5de8..2402d982e451 100644 --- a/code/addons/controls/template/stories/disable.stories.ts +++ b/code/addons/controls/template/stories/disable.stories.ts @@ -1,6 +1,7 @@ -import { global as globalThis } from '@storybook/global'; import type { PartialStoryFn, StoryContext } from 'storybook/internal/types'; +import { global as globalThis } from '@storybook/global'; + export default { component: globalThis.Components.Pre, decorators: [ diff --git a/code/addons/controls/template/stories/filters.stories.ts b/code/addons/controls/template/stories/filters.stories.ts index 983e58905243..e2378d6d0cad 100644 --- a/code/addons/controls/template/stories/filters.stories.ts +++ b/code/addons/controls/template/stories/filters.stories.ts @@ -1,6 +1,7 @@ -import { global as globalThis } from '@storybook/global'; import type { PartialStoryFn, StoryContext } from 'storybook/internal/types'; +import { global as globalThis } from '@storybook/global'; + export default { component: globalThis.Components.Pre, decorators: [ diff --git a/code/addons/controls/template/stories/issues.stories.ts b/code/addons/controls/template/stories/issues.stories.ts index b320f54b1eba..636baf38d531 100644 --- a/code/addons/controls/template/stories/issues.stories.ts +++ b/code/addons/controls/template/stories/issues.stories.ts @@ -1,6 +1,7 @@ -import { global as globalThis } from '@storybook/global'; import type { PartialStoryFn, StoryContext } from 'storybook/internal/types'; +import { global as globalThis } from '@storybook/global'; + export default { component: globalThis.Components.Pre, decorators: [ diff --git a/code/addons/controls/template/stories/matchers.stories.ts b/code/addons/controls/template/stories/matchers.stories.ts index bc5a896d4f6e..b54703120f72 100644 --- a/code/addons/controls/template/stories/matchers.stories.ts +++ b/code/addons/controls/template/stories/matchers.stories.ts @@ -1,6 +1,7 @@ -import { global as globalThis } from '@storybook/global'; import type { PartialStoryFn, StoryContext } from 'storybook/internal/types'; +import { global as globalThis } from '@storybook/global'; + export default { component: globalThis.Components.Pre, decorators: [ diff --git a/code/addons/controls/template/stories/sorting.stories.ts b/code/addons/controls/template/stories/sorting.stories.ts index dc6a66acdc31..c3b7b831dec6 100644 --- a/code/addons/controls/template/stories/sorting.stories.ts +++ b/code/addons/controls/template/stories/sorting.stories.ts @@ -1,6 +1,7 @@ -import { global as globalThis } from '@storybook/global'; import type { PartialStoryFn, StoryContext } from 'storybook/internal/types'; +import { global as globalThis } from '@storybook/global'; + export default { component: globalThis.Components.Pre, decorators: [ diff --git a/code/addons/controls/vitest.config.ts b/code/addons/controls/vitest.config.ts index 03172200442f..7420176b2e46 100644 --- a/code/addons/controls/vitest.config.ts +++ b/code/addons/controls/vitest.config.ts @@ -1,4 +1,5 @@ import { defineConfig, mergeConfig } from 'vitest/config'; + import { vitestCommonConfig } from '../../vitest.workspace'; export default mergeConfig( diff --git a/code/addons/docs/docs/docspage.md b/code/addons/docs/docs/docspage.md index ea50050f6b94..26f75811de5b 100644 --- a/code/addons/docs/docs/docspage.md +++ b/code/addons/docs/docs/docspage.md @@ -70,6 +70,7 @@ You can replace DocsPage at any level by overriding the `docs.page` parameter: ```js import { addParameters } from '@storybook/react'; + addParameters({ docs: { page: null } }); ``` @@ -77,6 +78,7 @@ addParameters({ docs: { page: null } }); ```js import { Button } from './Button'; + export default { title: 'Demo/Button', component: Button, @@ -101,7 +103,7 @@ Here's an example of rebuilding `DocsPage` out of doc blocks: ```js import React from 'react'; -import { Title, Subtitle, Description, Primary, ArgsTable, Stories } from '@storybook/addon-docs'; +import { ArgsTable, Description, Primary, Stories, Subtitle, Title } from '@storybook/addon-docs'; import { DocgenButton } from '../../components/DocgenButton'; export default { @@ -141,8 +143,8 @@ That being said, there is a system in place to remove the necessity of this trad ```js import React from 'react'; import { render } from 'react-dom'; -import toReact from '@egoist/vue-to-react'; import { addParameters } from '@storybook/vue'; +import toReact from '@egoist/vue-to-react'; addParameters({ docs: { diff --git a/code/addons/docs/docs/multiframework.md b/code/addons/docs/docs/multiframework.md index 070d94089b00..c68201aabdc3 100644 --- a/code/addons/docs/docs/multiframework.md +++ b/code/addons/docs/docs/multiframework.md @@ -113,7 +113,7 @@ This dynamic rendering is framework-specific, meaning it needs a custom implemen Let's take a look at the React framework implementation of `dynamic` snippets as a reference for implementing this feature in other frameworks: ```tsx -import { addons, StoryContext } from '@storybook/preview-api'; +import { StoryContext, addons } from '@storybook/preview-api'; import { SNIPPET_RENDERED } from '../../shared'; export const jsxDecorator = (storyFn: any, context: StoryContext) => { @@ -150,6 +150,7 @@ Now we need a way to configure how it's displayed in the UI: ```tsx import { jsxDecorator } from './jsxDecorator'; + export const decorators = [jsxDecorator]; ``` diff --git a/code/addons/docs/docs/props-tables.md b/code/addons/docs/docs/props-tables.md index 8dd5e8f7a285..7a44a6c653ae 100644 --- a/code/addons/docs/docs/props-tables.md +++ b/code/addons/docs/docs/props-tables.md @@ -104,6 +104,7 @@ Consider the following input: // Button.js import React from 'react'; import PropTypes from 'prop-types'; + export const Button = ({ label }) => ; Button.propTypes = { /** demo description */ diff --git a/code/addons/docs/docs/recipes.md b/code/addons/docs/docs/recipes.md index 0a982974f390..e760a61e08f4 100644 --- a/code/addons/docs/docs/recipes.md +++ b/code/addons/docs/docs/recipes.md @@ -106,6 +106,7 @@ And I can also embed arbitrary markdown & JSX in this file. import React from 'react'; import { Button } from './Button'; import mdx from './Button.mdx'; + export default { title: 'Demo/Button', parameters: { diff --git a/code/addons/docs/docs/theming.md b/code/addons/docs/docs/theming.md index 6f66a2d37267..6c4c8ac13082 100644 --- a/code/addons/docs/docs/theming.md +++ b/code/addons/docs/docs/theming.md @@ -14,9 +14,9 @@ Storybook theming is the **recommended way** to theme your docs. Docs uses the s Supposing you have a Storybook theme defined for the main UI in `.storybook/manager.js`: ```js -import { addons } from '@storybook/manager-api'; // or a custom theme import { themes } from '@storybook/theming'; +import { addons } from '@storybook/manager-api'; addons.setConfig({ theme: themes.dark, diff --git a/code/addons/docs/ember/README.md b/code/addons/docs/ember/README.md index 7491de442845..9418707e31b1 100644 --- a/code/addons/docs/ember/README.md +++ b/code/addons/docs/ember/README.md @@ -52,6 +52,7 @@ Next, add the following to your `.storybook/preview.js` to load the generated js ```js import { setJSONDoc } from '@storybook/addon-docs/ember'; import docJson from '../dist/storybook-docgen/index.json'; + setJSONDoc(docJson); ``` diff --git a/code/addons/docs/package.json b/code/addons/docs/package.json index a1302ed0a8c4..5e3d735bfef6 100644 --- a/code/addons/docs/package.json +++ b/code/addons/docs/package.json @@ -27,9 +27,9 @@ "exports": { ".": { "types": "./dist/index.d.ts", - "node": "./dist/index.js", "import": "./dist/index.mjs", - "require": "./dist/index.js" + "require": "./dist/index.js", + "node": "./dist/index.js" }, "./preview": { "types": "./dist/preview.d.ts", @@ -94,8 +94,8 @@ "!src/**/*" ], "scripts": { - "check": "node --loader ../../../scripts/node_modules/esbuild-register/loader.js -r ../../../scripts/node_modules/esbuild-register/register.js ../../../scripts/prepare/check.ts", - "prep": "node --loader ../../../scripts/node_modules/esbuild-register/loader.js -r ../../../scripts/node_modules/esbuild-register/register.js ../../../scripts/prepare/bundle.ts" + "check": "jiti ../../../scripts/prepare/check.ts", + "prep": "jiti ../../../scripts/prepare/bundle.ts" }, "dependencies": { "@babel/core": "^7.24.4", diff --git a/code/addons/docs/src/DocsRenderer.tsx b/code/addons/docs/src/DocsRenderer.tsx index 0124bf4dabe6..afb3c1e1402c 100644 --- a/code/addons/docs/src/DocsRenderer.tsx +++ b/code/addons/docs/src/DocsRenderer.tsx @@ -1,13 +1,16 @@ import type { PropsWithChildren } from 'react'; import React, { Component } from 'react'; -import { renderElement, unmountElement } from '@storybook/react-dom-shim'; + import type { - Renderer, - Parameters, DocsContextProps, DocsRenderFunction, + Parameters, + Renderer, } from 'storybook/internal/types'; -import { Docs, CodeOrSourceMdx, AnchorMdx, HeadersMdx } from '@storybook/blocks'; + +import { AnchorMdx, CodeOrSourceMdx, Docs, HeadersMdx } from '@storybook/blocks'; + +import { renderElement, unmountElement } from '@storybook/react-dom-shim'; // TS doesn't like that we export a component with types that it doesn't know about (TS4203) export const defaultComponents: Record = { diff --git a/code/addons/docs/src/compiler/index.test.ts b/code/addons/docs/src/compiler/index.test.ts index 54ea2c2d2911..6f4ec7b4bd8b 100644 --- a/code/addons/docs/src/compiler/index.test.ts +++ b/code/addons/docs/src/compiler/index.test.ts @@ -1,6 +1,8 @@ -import { expect, describe, it } from 'vitest'; +import { describe, expect, it } from 'vitest'; + import { dedent } from 'ts-dedent'; -import { compileSync, compile } from './index'; + +import { compile, compileSync } from './index'; expect.addSnapshotSerializer({ serialize: (val: any) => (typeof val === 'string' ? val : val.toString()), diff --git a/code/addons/docs/src/mdx-loader.ts b/code/addons/docs/src/mdx-loader.ts index 639fb0c70f0d..3f8603457e01 100644 --- a/code/addons/docs/src/mdx-loader.ts +++ b/code/addons/docs/src/mdx-loader.ts @@ -1,5 +1,6 @@ import type { transformAsync } from '@babel/core'; import type { compile as mdxCompile } from '@mdx-js/mdx'; + import { compile } from './compiler'; export type MdxCompileOptions = Parameters[1]; diff --git a/code/addons/docs/src/plugins/mdx-plugin.ts b/code/addons/docs/src/plugins/mdx-plugin.ts index 84ce92afeacc..2e2112a91a88 100644 --- a/code/addons/docs/src/plugins/mdx-plugin.ts +++ b/code/addons/docs/src/plugins/mdx-plugin.ts @@ -1,9 +1,12 @@ +import { dirname, join } from 'node:path'; + import type { Options } from 'storybook/internal/types'; -import type { Plugin } from 'vite'; -import rehypeSlug from 'rehype-slug'; -import rehypeExternalLinks from 'rehype-external-links'; + import { createFilter } from '@rollup/pluginutils'; -import { dirname, join } from 'path'; +import rehypeExternalLinks from 'rehype-external-links'; +import rehypeSlug from 'rehype-slug'; +import type { Plugin } from 'vite'; + import type { CompileOptions } from '../compiler'; import { compile } from '../compiler'; diff --git a/code/addons/docs/src/preset.ts b/code/addons/docs/src/preset.ts index 8d359204c227..90933f7d8a9c 100644 --- a/code/addons/docs/src/preset.ts +++ b/code/addons/docs/src/preset.ts @@ -1,10 +1,13 @@ -import { dirname, join, isAbsolute } from 'path'; -import rehypeSlug from 'rehype-slug'; -import rehypeExternalLinks from 'rehype-external-links'; +import { dirname, isAbsolute, join } from 'node:path'; +import { logger } from 'storybook/internal/node-logger'; import type { DocsOptions, Options, PresetProperty } from 'storybook/internal/types'; + import type { CsfPluginOptions } from '@storybook/csf-plugin'; -import { logger } from 'storybook/internal/node-logger'; + +import rehypeExternalLinks from 'rehype-external-links'; +import rehypeSlug from 'rehype-slug'; + import type { CompileOptions } from './compiler'; /** diff --git a/code/addons/docs/src/preview.ts b/code/addons/docs/src/preview.ts index bf3c02329580..735de9f72234 100644 --- a/code/addons/docs/src/preview.ts +++ b/code/addons/docs/src/preview.ts @@ -1,4 +1,5 @@ import type { PreparedStory } from 'storybook/internal/types'; + import { global } from '@storybook/global'; const excludeTags = Object.entries(global.TAGS_OPTIONS ?? {}).reduce( diff --git a/code/addons/docs/template/stories/docs2/resolved-react.stories.ts b/code/addons/docs/template/stories/docs2/resolved-react.stories.ts index 20095ec6164b..331b7e1dfd89 100644 --- a/code/addons/docs/template/stories/docs2/resolved-react.stories.ts +++ b/code/addons/docs/template/stories/docs2/resolved-react.stories.ts @@ -1,8 +1,9 @@ -import { within, expect } from '@storybook/test'; import * as ReactExport from 'react'; import * as ReactDom from 'react-dom'; import * as ReactDomServer from 'react-dom/server'; +import { expect, within } from '@storybook/test'; + /** * This component is used to display the resolved version of React and its related packages. * As long as `@storybook/addon-docs` is installed, `react` and `react-dom` should be available to import from and should resolve to the same version. diff --git a/code/addons/docs/template/stories/docspage/source.stories.ts b/code/addons/docs/template/stories/docspage/source.stories.ts index 2c92512198dd..faa8517dc54d 100644 --- a/code/addons/docs/template/stories/docspage/source.stories.ts +++ b/code/addons/docs/template/stories/docspage/source.stories.ts @@ -1,5 +1,7 @@ -import { global as globalThis } from '@storybook/global'; import type { StoryContext } from 'storybook/internal/types'; + +import { global as globalThis } from '@storybook/global'; + import { dedent } from 'ts-dedent'; export default { diff --git a/code/addons/docs/template/stories/toc/basic.stories.ts b/code/addons/docs/template/stories/toc/basic.stories.ts index 63938a400e8f..2a81297d25be 100644 --- a/code/addons/docs/template/stories/toc/basic.stories.ts +++ b/code/addons/docs/template/stories/toc/basic.stories.ts @@ -1,4 +1,5 @@ import { global as globalThis } from '@storybook/global'; +import { fn } from '@storybook/test'; export default { component: globalThis.Components.Button, diff --git a/code/addons/docs/vitest.config.ts b/code/addons/docs/vitest.config.ts index 03172200442f..7420176b2e46 100644 --- a/code/addons/docs/vitest.config.ts +++ b/code/addons/docs/vitest.config.ts @@ -1,4 +1,5 @@ import { defineConfig, mergeConfig } from 'vitest/config'; + import { vitestCommonConfig } from '../../vitest.workspace'; export default mergeConfig( diff --git a/code/addons/essentials/package.json b/code/addons/essentials/package.json index beb8eb4b8517..63e90588853a 100644 --- a/code/addons/essentials/package.json +++ b/code/addons/essentials/package.json @@ -24,9 +24,9 @@ "exports": { ".": { "types": "./dist/index.d.ts", - "node": "./dist/index.js", "import": "./dist/index.mjs", - "require": "./dist/index.js" + "require": "./dist/index.js", + "node": "./dist/index.js" }, "./actions/preview": { "types": "./dist/actions/preview.d.ts", @@ -85,8 +85,8 @@ "!src/**/*" ], "scripts": { - "check": "node --loader ../../../scripts/node_modules/esbuild-register/loader.js -r ../../../scripts/node_modules/esbuild-register/register.js ../../../scripts/prepare/check.ts", - "prep": "node --loader ../../../scripts/node_modules/esbuild-register/loader.js -r ../../../scripts/node_modules/esbuild-register/register.js ../../../scripts/prepare/addon-bundle.ts" + "check": "jiti ../../../scripts/prepare/check.ts", + "prep": "jiti ../../../scripts/prepare/addon-bundle.ts" }, "dependencies": { "@storybook/addon-actions": "workspace:*", diff --git a/code/addons/essentials/src/docs/preset.ts b/code/addons/essentials/src/docs/preset.ts index 5c7409f65b14..1d6ed6fbbc54 100644 --- a/code/addons/essentials/src/docs/preset.ts +++ b/code/addons/essentials/src/docs/preset.ts @@ -1,4 +1,4 @@ -import { dirname, join } from 'path'; +import { dirname, join } from 'node:path'; export * from '@storybook/addon-docs/dist/preset'; diff --git a/code/addons/essentials/src/index.ts b/code/addons/essentials/src/index.ts index d2b1ca20785c..ce80fc37634e 100644 --- a/code/addons/essentials/src/index.ts +++ b/code/addons/essentials/src/index.ts @@ -1,6 +1,7 @@ -import path from 'path'; -import { logger } from 'storybook/internal/node-logger'; +import { isAbsolute, join } from 'node:path'; + import { serverRequire } from 'storybook/internal/common'; +import { logger } from 'storybook/internal/node-logger'; interface PresetOptions { /** @@ -56,10 +57,8 @@ interface PresetOptions { } const requireMain = (configDir: string) => { - const absoluteConfigDir = path.isAbsolute(configDir) - ? configDir - : path.join(process.cwd(), configDir); - const mainFile = path.join(absoluteConfigDir, 'main'); + const absoluteConfigDir = isAbsolute(configDir) ? configDir : join(process.cwd(), configDir); + const mainFile = join(absoluteConfigDir, 'main'); return serverRequire(mainFile) ?? {}; }; diff --git a/code/addons/essentials/vitest.config.ts b/code/addons/essentials/vitest.config.ts index 03172200442f..7420176b2e46 100644 --- a/code/addons/essentials/vitest.config.ts +++ b/code/addons/essentials/vitest.config.ts @@ -1,4 +1,5 @@ import { defineConfig, mergeConfig } from 'vitest/config'; + import { vitestCommonConfig } from '../../vitest.workspace'; export default mergeConfig( diff --git a/code/addons/gfm/package.json b/code/addons/gfm/package.json index 58fe31499140..e5602723dd6e 100644 --- a/code/addons/gfm/package.json +++ b/code/addons/gfm/package.json @@ -40,8 +40,8 @@ "!src/**/*" ], "scripts": { - "check": "node --loader ../../../scripts/node_modules/esbuild-register/loader.js -r ../../../scripts/node_modules/esbuild-register/register.js ../../../scripts/prepare/check.ts", - "prep": "node --loader ../../../scripts/node_modules/esbuild-register/loader.js -r ../../../scripts/node_modules/esbuild-register/register.js ../../../scripts/prepare/addon-bundle.ts" + "check": "jiti ../../../scripts/prepare/check.ts", + "prep": "jiti ../../../scripts/prepare/addon-bundle.ts" }, "dependencies": { "remark-gfm": "^4.0.0", diff --git a/code/addons/gfm/src/index.ts b/code/addons/gfm/src/index.ts index 2ae1e565529a..08b13e81842f 100644 --- a/code/addons/gfm/src/index.ts +++ b/code/addons/gfm/src/index.ts @@ -1,7 +1,7 @@ -import { dedent } from 'ts-dedent'; import { deprecate } from 'storybook/internal/node-logger'; import remarkGfm from 'remark-gfm'; +import { dedent } from 'ts-dedent'; export const mdxLoaderOptions = async (config: any) => { config.mdxCompileOptions.remarkPlugins = config.mdxCompileOptions.remarkPlugins || []; diff --git a/code/addons/gfm/vitest.config.ts b/code/addons/gfm/vitest.config.ts index 03172200442f..7420176b2e46 100644 --- a/code/addons/gfm/vitest.config.ts +++ b/code/addons/gfm/vitest.config.ts @@ -1,4 +1,5 @@ import { defineConfig, mergeConfig } from 'vitest/config'; + import { vitestCommonConfig } from '../../vitest.workspace'; export default mergeConfig( diff --git a/code/addons/highlight/README.md b/code/addons/highlight/README.md index 5f7ffbe0c3a9..6f27d1fda606 100644 --- a/code/addons/highlight/README.md +++ b/code/addons/highlight/README.md @@ -32,7 +32,6 @@ Add `"@storybook/addon-highlight"` to the addons array in your `.storybook/main. ```ts // .storybook/main.ts - // Replace your-framework with the framework you are using (e.g., react-webpack5, vue3-vite) import type { StorybookConfig } from '@storybook/your-framework'; @@ -49,11 +48,9 @@ Highlight DOM nodes by emitting the `HIGHLIGHT` event from within a story or an ```ts // MyComponent.stories.ts - import type { Meta, StoryObj } from '@storybook/react'; import { useChannel } from '@storybook/preview-api'; import { HIGHLIGHT } from '@storybook/addon-highlight'; - import { MyComponent } from './MyComponent'; const meta: Meta = { @@ -82,11 +79,9 @@ Highlights are automatically cleared when the story changes. You can also manual ```ts // MyComponent.stories.ts|tsx - import type { Meta, StoryObj } from '@storybook/react'; import { useChannel } from '@storybook/preview-api'; import { HIGHLIGHT, RESET_HIGHLIGHT } from '@storybook/addon-highlight'; - import { MyComponent } from './MyComponent'; const meta: Meta = { @@ -116,11 +111,9 @@ The addon applies a standard style to the highlighted elements you've enabled fo ```ts // MyComponent.stories.ts - import type { Meta, StoryObj } from '@storybook/react'; import { useChannel } from '@storybook/preview-api'; import { HIGHLIGHT } from '@storybook/addon-highlight'; - import { MyComponent } from './MyComponent'; const meta: Meta = { diff --git a/code/addons/highlight/package.json b/code/addons/highlight/package.json index 1a3ebc1535fc..29e1f0352416 100644 --- a/code/addons/highlight/package.json +++ b/code/addons/highlight/package.json @@ -26,9 +26,9 @@ "exports": { ".": { "types": "./dist/index.d.ts", - "node": "./dist/index.js", "import": "./dist/index.mjs", - "require": "./dist/index.js" + "require": "./dist/index.js", + "node": "./dist/index.js" }, "./preview": { "types": "./dist/preview.d.ts", @@ -48,8 +48,8 @@ "!src/**/*" ], "scripts": { - "check": "node --loader ../../../scripts/node_modules/esbuild-register/loader.js -r ../../../scripts/node_modules/esbuild-register/register.js ../../../scripts/prepare/check.ts", - "prep": "node --loader ../../../scripts/node_modules/esbuild-register/loader.js -r ../../../scripts/node_modules/esbuild-register/register.js ../../../scripts/prepare/addon-bundle.ts" + "check": "jiti ../../../scripts/prepare/check.ts", + "prep": "jiti ../../../scripts/prepare/addon-bundle.ts" }, "dependencies": { "@storybook/global": "^5.0.0" diff --git a/code/addons/highlight/src/preview.ts b/code/addons/highlight/src/preview.ts index 5d38b0aa87b9..7d7d43bd14d4 100644 --- a/code/addons/highlight/src/preview.ts +++ b/code/addons/highlight/src/preview.ts @@ -1,8 +1,10 @@ /* eslint-env browser */ -import { global } from '@storybook/global'; -import { addons } from 'storybook/internal/preview-api'; import { STORY_CHANGED } from 'storybook/internal/core-events'; -import { HIGHLIGHT, RESET_HIGHLIGHT, HIGHLIGHT_STYLE_ID } from './constants'; +import { addons } from 'storybook/internal/preview-api'; + +import { global } from '@storybook/global'; + +import { HIGHLIGHT, HIGHLIGHT_STYLE_ID, RESET_HIGHLIGHT } from './constants'; const { document } = global; diff --git a/code/addons/highlight/vitest.config.ts b/code/addons/highlight/vitest.config.ts index 03172200442f..7420176b2e46 100644 --- a/code/addons/highlight/vitest.config.ts +++ b/code/addons/highlight/vitest.config.ts @@ -1,4 +1,5 @@ import { defineConfig, mergeConfig } from 'vitest/config'; + import { vitestCommonConfig } from '../../vitest.workspace'; export default mergeConfig( diff --git a/code/addons/interactions/README.md b/code/addons/interactions/README.md index 815a83b1804d..8e97267a65d3 100644 --- a/code/addons/interactions/README.md +++ b/code/addons/interactions/README.md @@ -27,8 +27,8 @@ Note that `@storybook/addon-interactions` must be listed **after** `@storybook/a Interactions relies on "instrumented" versions of Vitest and Testing Library, that you import from `@storybook/test` instead of their original package. You can then use these libraries in your `play` function. ```js +import { expect, fn, userEvent, within } from '@storybook/test'; import { Button } from './Button'; -import { within, userEvent, expect, fn } from '@storybook/test'; export default { title: 'Button', diff --git a/code/addons/interactions/package.json b/code/addons/interactions/package.json index 264ccbf8068d..43123c029ce2 100644 --- a/code/addons/interactions/package.json +++ b/code/addons/interactions/package.json @@ -24,9 +24,9 @@ "exports": { ".": { "types": "./dist/index.d.ts", - "node": "./dist/index.js", "import": "./dist/index.mjs", - "require": "./dist/index.js" + "require": "./dist/index.js", + "node": "./dist/index.js" }, "./preview": { "types": "./dist/preview.d.ts", @@ -49,8 +49,8 @@ "!src/**/*" ], "scripts": { - "check": "node --loader ../../../scripts/node_modules/esbuild-register/loader.js -r ../../../scripts/node_modules/esbuild-register/register.js ../../../scripts/prepare/check.ts", - "prep": "node --loader ../../../scripts/node_modules/esbuild-register/loader.js -r ../../../scripts/node_modules/esbuild-register/register.js ../../../scripts/prepare/addon-bundle.ts" + "check": "jiti ../../../scripts/prepare/check.ts", + "prep": "jiti ../../../scripts/prepare/addon-bundle.ts" }, "dependencies": { "@storybook/global": "^5.0.0", @@ -62,7 +62,7 @@ "devDependencies": { "@devtools-ds/object-inspector": "^1.1.2", "@storybook/icons": "^1.2.5", - "@types/node": "^18.0.0", + "@types/node": "^22.0.0", "formik": "^2.2.9", "react": "^18.2.0", "react-dom": "^18.2.0", diff --git a/code/addons/interactions/src/Panel.test.ts b/code/addons/interactions/src/Panel.test.ts index bb05a875e29d..1d25d154dadc 100644 --- a/code/addons/interactions/src/Panel.test.ts +++ b/code/addons/interactions/src/Panel.test.ts @@ -1,7 +1,8 @@ // @vitest-environment happy-dom +import { describe, expect, it } from 'vitest'; -import { describe, it, expect } from 'vitest'; import { type Call, CallStates, type LogItem } from '@storybook/instrumenter'; + import { getInteractions } from './Panel'; describe('Panel', () => { diff --git a/code/addons/interactions/src/Panel.tsx b/code/addons/interactions/src/Panel.tsx index f6e1b06b8619..eec7d8a80e96 100644 --- a/code/addons/interactions/src/Panel.tsx +++ b/code/addons/interactions/src/Panel.tsx @@ -1,15 +1,17 @@ -import { global } from '@storybook/global'; import type { Dispatch, SetStateAction } from 'react'; import React, { Fragment, memo, useEffect, useMemo, useRef, useState } from 'react'; -import { useAddonState, useChannel, useParameter } from 'storybook/internal/manager-api'; + import { FORCE_REMOUNT, + PLAY_FUNCTION_THREW_EXCEPTION, STORY_RENDER_PHASE_CHANGED, STORY_THREW_EXCEPTION, - PLAY_FUNCTION_THREW_EXCEPTION, UNHANDLED_ERRORS_WHILE_PLAYING, } from 'storybook/internal/core-events'; -import { EVENTS, type Call, CallStates, type LogItem } from '@storybook/instrumenter'; +import { useAddonState, useChannel, useParameter } from 'storybook/internal/manager-api'; + +import { global } from '@storybook/global'; +import { type Call, CallStates, EVENTS, type LogItem } from '@storybook/instrumenter'; import { InteractionsPanel } from './components/InteractionsPanel'; import { ADDON_ID } from './constants'; diff --git a/code/addons/interactions/src/components/EmptyState.tsx b/code/addons/interactions/src/components/EmptyState.tsx index effaabee839e..5c0ee95a1bc7 100644 --- a/code/addons/interactions/src/components/EmptyState.tsx +++ b/code/addons/interactions/src/components/EmptyState.tsx @@ -1,9 +1,11 @@ import React, { useEffect, useState } from 'react'; -import { Link, EmptyTabContent } from 'storybook/internal/components'; -import { DocumentIcon, VideoIcon } from '@storybook/icons'; + +import { EmptyTabContent, Link } from 'storybook/internal/components'; import { useStorybookApi } from 'storybook/internal/manager-api'; import { styled } from 'storybook/internal/theming'; +import { DocumentIcon, VideoIcon } from '@storybook/icons'; + import { DOCUMENTATION_LINK, TUTORIAL_VIDEO_LINK } from '../constants'; const Links = styled.div(({ theme }) => ({ diff --git a/code/addons/interactions/src/components/Interaction.stories.tsx b/code/addons/interactions/src/components/Interaction.stories.tsx index 98f579090986..784c5251bf34 100644 --- a/code/addons/interactions/src/components/Interaction.stories.tsx +++ b/code/addons/interactions/src/components/Interaction.stories.tsx @@ -1,8 +1,8 @@ -import type { StoryObj, Meta } from '@storybook/react'; import { CallStates } from '@storybook/instrumenter'; -import { userEvent, within, expect } from '@storybook/test'; -import { getCalls } from '../mocks'; +import type { Meta, StoryObj } from '@storybook/react'; +import { expect, userEvent, within } from '@storybook/test'; +import { getCalls } from '../mocks'; import { Interaction } from './Interaction'; import SubnavStories from './Subnav.stories'; diff --git a/code/addons/interactions/src/components/Interaction.tsx b/code/addons/interactions/src/components/Interaction.tsx index 6b4682f61bea..3e613391e856 100644 --- a/code/addons/interactions/src/components/Interaction.tsx +++ b/code/addons/interactions/src/components/Interaction.tsx @@ -1,17 +1,19 @@ import * as React from 'react'; + import { IconButton, TooltipNote, WithTooltip } from 'storybook/internal/components'; -import { type Call, CallStates, type ControlStates } from '@storybook/instrumenter'; import { styled, typography } from 'storybook/internal/theming'; -import { transparentize } from 'polished'; import { ListUnorderedIcon } from '@storybook/icons'; +import { type Call, CallStates, type ControlStates } from '@storybook/instrumenter'; + +import { transparentize } from 'polished'; + +import { isChaiError, isJestError } from '../utils'; +import type { Controls } from './InteractionsPanel'; import { MatcherResult } from './MatcherResult'; import { MethodCall } from './MethodCall'; import { StatusIcon } from './StatusIcon'; -import type { Controls } from './InteractionsPanel'; -import { isChaiError, isJestError } from '../utils'; - const MethodCallWrapper = styled.div(() => ({ fontFamily: typography.fonts.mono, fontSize: typography.size.s1, diff --git a/code/addons/interactions/src/components/InteractionsPanel.stories.tsx b/code/addons/interactions/src/components/InteractionsPanel.stories.tsx index 9105ea7f2a3a..c2fb2b9af2ac 100644 --- a/code/addons/interactions/src/components/InteractionsPanel.stories.tsx +++ b/code/addons/interactions/src/components/InteractionsPanel.stories.tsx @@ -1,10 +1,12 @@ import React from 'react'; -import type { StoryObj, Meta } from '@storybook/react'; -import { CallStates } from '@storybook/instrumenter'; + import { styled } from 'storybook/internal/theming'; -import { userEvent, within, waitFor, expect } from '@storybook/test'; -import { isChromatic } from '../../../../.storybook/isChromatic'; +import { CallStates } from '@storybook/instrumenter'; +import type { Meta, StoryObj } from '@storybook/react'; +import { expect, userEvent, waitFor, within } from '@storybook/test'; + +import { isChromatic } from '../../../../.storybook/isChromatic'; import { getCalls, getInteractions } from '../mocks'; import { InteractionsPanel } from './InteractionsPanel'; import SubnavStories from './Subnav.stories'; diff --git a/code/addons/interactions/src/components/InteractionsPanel.tsx b/code/addons/interactions/src/components/InteractionsPanel.tsx index 56165d5e3769..c86a1df8ffde 100644 --- a/code/addons/interactions/src/components/InteractionsPanel.tsx +++ b/code/addons/interactions/src/components/InteractionsPanel.tsx @@ -1,13 +1,15 @@ import * as React from 'react'; -import { type Call, CallStates, type ControlStates } from '@storybook/instrumenter'; + import { styled } from 'storybook/internal/theming'; -import { transparentize } from 'polished'; -import { Subnav } from './Subnav'; +import { type Call, CallStates, type ControlStates } from '@storybook/instrumenter'; + +import { transparentize } from 'polished'; -import { Interaction } from './Interaction'; import { isTestAssertionError } from '../utils'; import { Empty } from './EmptyState'; +import { Interaction } from './Interaction'; +import { Subnav } from './Subnav'; export interface Controls { start: (args: any) => void; diff --git a/code/addons/interactions/src/components/List.tsx b/code/addons/interactions/src/components/List.tsx index e3a435ffa535..dece58b465ea 100644 --- a/code/addons/interactions/src/components/List.tsx +++ b/code/addons/interactions/src/components/List.tsx @@ -1,5 +1,7 @@ import React, { Fragment, useState } from 'react'; -import { styled, themes, convert } from 'storybook/internal/theming'; + +import { convert, styled, themes } from 'storybook/internal/theming'; + import { ChevronSmallDownIcon } from '@storybook/icons'; const ListWrapper = styled.ul({ diff --git a/code/addons/interactions/src/components/MatcherResult.stories.tsx b/code/addons/interactions/src/components/MatcherResult.stories.tsx index 9e812673f6b6..516aaed5cd63 100644 --- a/code/addons/interactions/src/components/MatcherResult.stories.tsx +++ b/code/addons/interactions/src/components/MatcherResult.stories.tsx @@ -1,6 +1,9 @@ import React from 'react'; -import { dedent } from 'ts-dedent'; + import { styled } from 'storybook/internal/theming'; + +import { dedent } from 'ts-dedent'; + import { MatcherResult } from './MatcherResult'; const StyledWrapper = styled.div(({ theme }) => ({ diff --git a/code/addons/interactions/src/components/MatcherResult.tsx b/code/addons/interactions/src/components/MatcherResult.tsx index f1bc83d56ec1..a56f96abf627 100644 --- a/code/addons/interactions/src/components/MatcherResult.tsx +++ b/code/addons/interactions/src/components/MatcherResult.tsx @@ -1,5 +1,7 @@ import React from 'react'; + import { styled, typography } from 'storybook/internal/theming'; + import { Node } from './MethodCall'; const getParams = (line: string, fromIndex = 0): string => { diff --git a/code/addons/interactions/src/components/MethodCall.stories.tsx b/code/addons/interactions/src/components/MethodCall.stories.tsx index 3c9354d44c8e..1ab027dd5dec 100644 --- a/code/addons/interactions/src/components/MethodCall.stories.tsx +++ b/code/addons/interactions/src/components/MethodCall.stories.tsx @@ -1,7 +1,10 @@ -import type { Call } from '@storybook/instrumenter'; import React from 'react'; + import { styled, typography } from 'storybook/internal/theming'; -import { Node, MethodCall } from './MethodCall'; + +import type { Call } from '@storybook/instrumenter'; + +import { MethodCall, Node } from './MethodCall'; const StyledWrapper = styled.div(({ theme }) => ({ backgroundColor: theme.background.content, diff --git a/code/addons/interactions/src/components/MethodCall.tsx b/code/addons/interactions/src/components/MethodCall.tsx index 4b6896eb4bf5..8e19ea9e6549 100644 --- a/code/addons/interactions/src/components/MethodCall.tsx +++ b/code/addons/interactions/src/components/MethodCall.tsx @@ -1,9 +1,12 @@ -import { ObjectInspector } from '@devtools-ds/object-inspector'; -import type { Call, CallRef, ElementRef } from '@storybook/instrumenter'; -import { useTheme } from 'storybook/internal/theming'; import type { ReactElement } from 'react'; import React, { Fragment } from 'react'; +import { useTheme } from 'storybook/internal/theming'; + +import type { Call, CallRef, ElementRef } from '@storybook/instrumenter'; + +import { ObjectInspector } from '@devtools-ds/object-inspector'; + const colorsLight = { base: '#444', nullish: '#7D99AA', diff --git a/code/addons/interactions/src/components/StatusBadge.stories.tsx b/code/addons/interactions/src/components/StatusBadge.stories.tsx index 8fa3f91ae3a3..afac03be0a11 100644 --- a/code/addons/interactions/src/components/StatusBadge.stories.tsx +++ b/code/addons/interactions/src/components/StatusBadge.stories.tsx @@ -1,4 +1,5 @@ import { CallStates } from '@storybook/instrumenter'; + import { StatusBadge } from './StatusBadge'; export default { diff --git a/code/addons/interactions/src/components/StatusBadge.tsx b/code/addons/interactions/src/components/StatusBadge.tsx index 3a989492f1b3..d730b8ef985c 100644 --- a/code/addons/interactions/src/components/StatusBadge.tsx +++ b/code/addons/interactions/src/components/StatusBadge.tsx @@ -1,7 +1,9 @@ import React from 'react'; -import { type Call, CallStates } from '@storybook/instrumenter'; + import { styled, typography } from 'storybook/internal/theming'; +import { type Call, CallStates } from '@storybook/instrumenter'; + export interface StatusBadgeProps { status: Call['status']; } diff --git a/code/addons/interactions/src/components/StatusIcon.stories.tsx b/code/addons/interactions/src/components/StatusIcon.stories.tsx index 4e8ea4217489..7d465dc64001 100644 --- a/code/addons/interactions/src/components/StatusIcon.stories.tsx +++ b/code/addons/interactions/src/components/StatusIcon.stories.tsx @@ -1,4 +1,5 @@ import { CallStates } from '@storybook/instrumenter'; + import { StatusIcon } from './StatusIcon'; export default { diff --git a/code/addons/interactions/src/components/StatusIcon.tsx b/code/addons/interactions/src/components/StatusIcon.tsx index c09a9e3c9c8f..1e9ec4c9aa99 100644 --- a/code/addons/interactions/src/components/StatusIcon.tsx +++ b/code/addons/interactions/src/components/StatusIcon.tsx @@ -1,9 +1,11 @@ import React from 'react'; -import { type Call, CallStates } from '@storybook/instrumenter'; + import { styled, useTheme } from 'storybook/internal/theming'; -import { transparentize } from 'polished'; import { CheckIcon, CircleIcon, PlayIcon, StopAltIcon } from '@storybook/icons'; +import { type Call, CallStates } from '@storybook/instrumenter'; + +import { transparentize } from 'polished'; export interface StatusIconProps { status: Call['status']; diff --git a/code/addons/interactions/src/components/Subnav.stories.tsx b/code/addons/interactions/src/components/Subnav.stories.tsx index bdaa5fae2831..e19f86fc9847 100644 --- a/code/addons/interactions/src/components/Subnav.stories.tsx +++ b/code/addons/interactions/src/components/Subnav.stories.tsx @@ -1,7 +1,9 @@ -import { action } from '@storybook/addon-actions'; import { CallStates } from '@storybook/instrumenter'; -import { Subnav } from './Subnav'; + +import { action } from '@storybook/addon-actions'; + import { parameters } from '../preview'; +import { Subnav } from './Subnav'; export default { title: 'Subnav', diff --git a/code/addons/interactions/src/components/Subnav.tsx b/code/addons/interactions/src/components/Subnav.tsx index 8818248e2b5b..59564dab2b67 100644 --- a/code/addons/interactions/src/components/Subnav.tsx +++ b/code/addons/interactions/src/components/Subnav.tsx @@ -1,16 +1,15 @@ import type { ComponentProps } from 'react'; import React from 'react'; + import { + Bar, Button, IconButton, - Separator, P, + Separator, TooltipNote, WithTooltip, - Bar, } from 'storybook/internal/components'; -import type { Call, ControlStates } from '@storybook/instrumenter'; -import { CallStates } from '@storybook/instrumenter'; import { styled } from 'storybook/internal/theming'; import { @@ -20,9 +19,11 @@ import { RewindIcon, SyncIcon, } from '@storybook/icons'; -import { StatusBadge } from './StatusBadge'; +import type { Call, ControlStates } from '@storybook/instrumenter'; +import { CallStates } from '@storybook/instrumenter'; import type { Controls } from './InteractionsPanel'; +import { StatusBadge } from './StatusBadge'; const SubnavWrapper = styled.div(({ theme }) => ({ background: theme.background.app, diff --git a/code/addons/interactions/src/manager.tsx b/code/addons/interactions/src/manager.tsx index 2de5d48d8fa6..e2d9c50f8758 100644 --- a/code/addons/interactions/src/manager.tsx +++ b/code/addons/interactions/src/manager.tsx @@ -1,9 +1,11 @@ import React, { useCallback } from 'react'; -import type { Combo } from 'storybook/internal/manager-api'; -import { addons, Consumer, types, useAddonState } from 'storybook/internal/manager-api'; + import { AddonPanel, Badge, Spaced } from 'storybook/internal/components'; -import { ADDON_ID, PANEL_ID } from './constants'; +import type { Combo } from 'storybook/internal/manager-api'; +import { Consumer, addons, types, useAddonState } from 'storybook/internal/manager-api'; + import { Panel } from './Panel'; +import { ADDON_ID, PANEL_ID } from './constants'; function Title() { const [addonState = {}] = useAddonState(ADDON_ID); diff --git a/code/addons/interactions/src/mocks/index.ts b/code/addons/interactions/src/mocks/index.ts index cffabc3352bc..02760bce429d 100644 --- a/code/addons/interactions/src/mocks/index.ts +++ b/code/addons/interactions/src/mocks/index.ts @@ -1,4 +1,4 @@ -import { CallStates, type Call } from '@storybook/instrumenter'; +import { type Call, CallStates } from '@storybook/instrumenter'; export const getCalls = (finalStatus: CallStates) => { const calls: Call[] = [ diff --git a/code/addons/interactions/src/preset.ts b/code/addons/interactions/src/preset.ts index fa827d0e86d0..b58832d5e36e 100644 --- a/code/addons/interactions/src/preset.ts +++ b/code/addons/interactions/src/preset.ts @@ -1,5 +1,6 @@ +import { isAbsolute, join } from 'node:path'; + import { checkAddonOrder, serverRequire } from 'storybook/internal/common'; -import path from 'path'; export const checkActionsLoaded = (configDir: string) => { checkAddonOrder({ @@ -11,9 +12,9 @@ export const checkActionsLoaded = (configDir: string) => { name: '@storybook/addon-interactions', inEssentials: false, }, - configFile: path.isAbsolute(configDir) - ? path.join(configDir, 'main') - : path.join(process.cwd(), configDir, 'main'), + configFile: isAbsolute(configDir) + ? join(configDir, 'main') + : join(process.cwd(), configDir, 'main'), getConfig: (configFile) => serverRequire(configFile), }); }; diff --git a/code/addons/interactions/src/preview.ts b/code/addons/interactions/src/preview.ts index c74a3aa742d6..6abc30f63b93 100644 --- a/code/addons/interactions/src/preview.ts +++ b/code/addons/interactions/src/preview.ts @@ -1,4 +1,5 @@ import type { PlayFunction, StepLabel, StoryContext } from 'storybook/internal/types'; + import { instrument } from '@storybook/instrumenter'; export const { step: runStep } = instrument( diff --git a/code/addons/interactions/template/stories/basics.stories.ts b/code/addons/interactions/template/stories/basics.stories.ts index 459471817711..e208654602ea 100644 --- a/code/addons/interactions/template/stories/basics.stories.ts +++ b/code/addons/interactions/template/stories/basics.stories.ts @@ -1,8 +1,8 @@ import { global as globalThis } from '@storybook/global'; import { expect, - fn, fireEvent, + fn, userEvent, waitFor, waitForElementToBeRemoved, diff --git a/code/addons/interactions/vitest.config.ts b/code/addons/interactions/vitest.config.ts index 03172200442f..7420176b2e46 100644 --- a/code/addons/interactions/vitest.config.ts +++ b/code/addons/interactions/vitest.config.ts @@ -1,4 +1,5 @@ import { defineConfig, mergeConfig } from 'vitest/config'; + import { vitestCommonConfig } from '../../vitest.workspace'; export default mergeConfig( diff --git a/code/addons/jest/README.md b/code/addons/jest/README.md index ec2cc8a34c6c..73b37e6dc21c 100644 --- a/code/addons/jest/README.md +++ b/code/addons/jest/README.md @@ -88,12 +88,9 @@ In your story file, add a [decorator](https://storybook.js.org/docs/react/writin ```js // MyComponent.stories.js|jsx - -import MyComponent from './MyComponent'; - -import results from '../.jest-test-results.json'; - import { withTests } from '@storybook/addon-jest'; +import results from '../.jest-test-results.json'; +import MyComponent from './MyComponent'; export default { component: MyComponent, @@ -137,9 +134,7 @@ your [`.storybook/preview.js`](https://storybook.js.org/docs/react/configure/#co ```js // .storybook/preview.js - import { withTests } from '@storybook/addon-jest'; - import results from '../.jest-test-results.json'; export const decorators = [ @@ -181,7 +176,6 @@ You can disable the addon for a single story by setting the `jest` parameter to ```js // MyComponent.stories.js|jsx - import MyComponent from './MyComponent'; export default { @@ -209,9 +203,7 @@ Then, in your `.storybook/preview.js`, you'll need to add a decorator with the f ```js // .storybook/preview.js - import { withTests } from '@storybook/addon-jest'; - import results from '../.jest-test-results.json'; export const decorators = [ @@ -226,9 +218,7 @@ Finally, in your story, you'll need to include the following: ```ts // MyComponent.stories.ts - import type { Meta, StoryFn } from '@storybook/angular'; - import MyComponent from './MyComponent.component'; export default { diff --git a/code/addons/jest/package.json b/code/addons/jest/package.json index d0a2ec7b1609..84e35aeb94d4 100644 --- a/code/addons/jest/package.json +++ b/code/addons/jest/package.json @@ -30,9 +30,9 @@ "exports": { ".": { "types": "./dist/index.d.ts", - "node": "./dist/index.js", "import": "./dist/index.mjs", - "require": "./dist/index.js" + "require": "./dist/index.js", + "node": "./dist/index.js" }, "./manager": "./dist/manager.js", "./register": "./dist/manager.js", @@ -49,8 +49,8 @@ "!src/**/*" ], "scripts": { - "check": "node --loader ../../../scripts/node_modules/esbuild-register/loader.js -r ../../../scripts/node_modules/esbuild-register/register.js ../../../scripts/prepare/check.ts", - "prep": "node --loader ../../../scripts/node_modules/esbuild-register/loader.js -r ../../../scripts/node_modules/esbuild-register/register.js ../../../scripts/prepare/addon-bundle.ts" + "check": "jiti ../../../scripts/prepare/check.ts", + "prep": "jiti ../../../scripts/prepare/addon-bundle.ts" }, "dependencies": { "@storybook/global": "^5.0.0", diff --git a/code/addons/jest/src/components/Message.tsx b/code/addons/jest/src/components/Message.tsx index 13c38a1d5074..2fdfcd41e46a 100644 --- a/code/addons/jest/src/components/Message.tsx +++ b/code/addons/jest/src/components/Message.tsx @@ -1,5 +1,6 @@ import type { FC, ReactElement } from 'react'; import React, { Fragment } from 'react'; + import { styled } from 'storybook/internal/theming'; const positiveConsoleRegex = /\[32m(.*?)\[39m/; diff --git a/code/addons/jest/src/components/Panel.tsx b/code/addons/jest/src/components/Panel.tsx index 5b2024ca4258..27be5cbf7a5c 100644 --- a/code/addons/jest/src/components/Panel.tsx +++ b/code/addons/jest/src/components/Panel.tsx @@ -1,11 +1,14 @@ import type { FC } from 'react'; import React, { Fragment } from 'react'; -import { styled, themes, convert } from 'storybook/internal/theming'; -import { ScrollArea, TabsState, Link, Placeholder } from 'storybook/internal/components'; + +import { Link, Placeholder, ScrollArea, TabsState } from 'storybook/internal/components'; +import { convert, styled, themes } from 'storybook/internal/theming'; + import { useResizeDetector } from 'react-resize-detector'; -import { Result } from './Result'; + import type { Test } from '../hoc/provideJestResult'; import { provideTests as provideJestResult } from '../hoc/provideJestResult'; +import { Result } from './Result'; const StatusTypes = { PASSED_TYPE: 'passed', diff --git a/code/addons/jest/src/components/Result.tsx b/code/addons/jest/src/components/Result.tsx index 832bc3b988f9..332178a32bed 100644 --- a/code/addons/jest/src/components/Result.tsx +++ b/code/addons/jest/src/components/Result.tsx @@ -1,8 +1,11 @@ import React, { Fragment, useState } from 'react'; -import { styled, themes, convert } from 'storybook/internal/theming'; + +import { convert, styled, themes } from 'storybook/internal/theming'; + +import { ChevronSmallDownIcon } from '@storybook/icons'; + // eslint-disable-next-line import/no-named-as-default import Message from './Message'; -import { ChevronSmallDownIcon } from '@storybook/icons'; const Wrapper = styled.div<{ status: string }>(({ theme, status }) => ({ display: 'flex', diff --git a/code/addons/jest/src/hoc/provideJestResult.tsx b/code/addons/jest/src/hoc/provideJestResult.tsx index c1af585d2709..f2c891c647b6 100644 --- a/code/addons/jest/src/hoc/provideJestResult.tsx +++ b/code/addons/jest/src/hoc/provideJestResult.tsx @@ -1,7 +1,9 @@ import type { ComponentType } from 'react'; import React, { Component as ReactComponent } from 'react'; + import { STORY_CHANGED } from 'storybook/internal/core-events'; import type { API } from 'storybook/internal/manager-api'; + import { ADD_TESTS } from '../shared'; // TODO: import type from @types/jest diff --git a/code/addons/jest/src/index.ts b/code/addons/jest/src/index.ts index ca96f5bf9148..0ec5000c1b48 100644 --- a/code/addons/jest/src/index.ts +++ b/code/addons/jest/src/index.ts @@ -1,5 +1,7 @@ import { addons } from 'storybook/internal/preview-api'; + import { normalize, sep } from 'upath'; + import { ADD_TESTS, defineJestParameter } from './shared'; const findTestResults = ( diff --git a/code/addons/jest/src/manager.tsx b/code/addons/jest/src/manager.tsx index 60b3c9fb0f0b..ca1b84bb60ee 100644 --- a/code/addons/jest/src/manager.tsx +++ b/code/addons/jest/src/manager.tsx @@ -1,8 +1,9 @@ import * as React from 'react'; + import { addons, types } from 'storybook/internal/manager-api'; -import { ADDON_ID, PANEL_ID, PARAM_KEY } from './shared'; import Panel from './components/Panel'; +import { ADDON_ID, PANEL_ID, PARAM_KEY } from './shared'; addons.register(ADDON_ID, (api) => { addons.add(PANEL_ID, { diff --git a/code/addons/jest/src/shared.test.ts b/code/addons/jest/src/shared.test.ts index 599276a12355..6ef232fe5a32 100644 --- a/code/addons/jest/src/shared.test.ts +++ b/code/addons/jest/src/shared.test.ts @@ -1,4 +1,5 @@ import { describe, expect, it } from 'vitest'; + import { defineJestParameter } from './shared'; describe('defineJestParameter', () => { diff --git a/code/addons/jest/src/shared.ts b/code/addons/jest/src/shared.ts index 69c7930102b7..32107bdf23ef 100644 --- a/code/addons/jest/src/shared.ts +++ b/code/addons/jest/src/shared.ts @@ -1,6 +1,7 @@ -import invariant from 'tiny-invariant'; import type { StorybookInternalParameters } from 'storybook/internal/types'; +import invariant from 'tiny-invariant'; + // addons, panels and events get unique names using a prefix export const PARAM_KEY = 'test'; export const ADDON_ID = 'storybookjs/test'; diff --git a/code/addons/jest/vitest.config.ts b/code/addons/jest/vitest.config.ts index 03172200442f..7420176b2e46 100644 --- a/code/addons/jest/vitest.config.ts +++ b/code/addons/jest/vitest.config.ts @@ -1,4 +1,5 @@ import { defineConfig, mergeConfig } from 'vitest/config'; + import { vitestCommonConfig } from '../../vitest.workspace'; export default mergeConfig( diff --git a/code/addons/links/README.md b/code/addons/links/README.md index 8b8d94afff28..cc50832328fa 100644 --- a/code/addons/links/README.md +++ b/code/addons/links/README.md @@ -80,8 +80,8 @@ export const third = () => Go back; If you want to get an URL for a particular story, you may use `hrefTo` function. It returns a promise, which resolves to string containing a relative URL: ```js -import { hrefTo } from '@storybook/addon-links'; import { action } from '@storybook/addon-actions'; +import { hrefTo } from '@storybook/addon-links'; export default { title: 'Href', diff --git a/code/addons/links/package.json b/code/addons/links/package.json index c1259e50cb19..e6d1175a502c 100644 --- a/code/addons/links/package.json +++ b/code/addons/links/package.json @@ -24,9 +24,9 @@ "exports": { ".": { "types": "./dist/index.d.ts", - "node": "./dist/index.js", "import": "./dist/index.mjs", - "require": "./dist/index.js" + "require": "./dist/index.js", + "node": "./dist/index.js" }, "./react": { "types": "./dist/react/index.d.ts", @@ -63,8 +63,8 @@ "!src/**/*" ], "scripts": { - "check": "node --loader ../../../scripts/node_modules/esbuild-register/loader.js -r ../../../scripts/node_modules/esbuild-register/register.js ../../../scripts/prepare/check.ts", - "prep": "node --loader ../../../scripts/node_modules/esbuild-register/loader.js -r ../../../scripts/node_modules/esbuild-register/register.js ../../../scripts/prepare/addon-bundle.ts" + "check": "jiti ../../../scripts/prepare/check.ts", + "prep": "jiti ../../../scripts/prepare/addon-bundle.ts" }, "dependencies": { "@storybook/csf": "^0.1.11", diff --git a/code/addons/links/src/preview.ts b/code/addons/links/src/preview.ts index c0da77c598b7..6270d133ab77 100644 --- a/code/addons/links/src/preview.ts +++ b/code/addons/links/src/preview.ts @@ -1,4 +1,5 @@ import type { Addon_DecoratorFunction } from 'storybook/internal/types'; + import { withLinks } from './index'; export const decorators: Addon_DecoratorFunction[] = [withLinks]; diff --git a/code/addons/links/src/react/components/link.test.tsx b/code/addons/links/src/react/components/link.test.tsx index 78b8bb3876a4..e0b87be09dca 100644 --- a/code/addons/links/src/react/components/link.test.tsx +++ b/code/addons/links/src/react/components/link.test.tsx @@ -1,12 +1,14 @@ // @vitest-environment happy-dom - /// ; -import { describe, it, expect, afterEach, vi } from 'vitest'; -import React from 'react'; -import { addons } from 'storybook/internal/preview-api'; -import { render, screen, waitFor, cleanup, act } from '@testing-library/react'; +import { act, cleanup, render, screen, waitFor } from '@testing-library/react'; import userEvent from '@testing-library/user-event'; +import { afterEach, describe, expect, it, vi } from 'vitest'; + +import React from 'react'; + import { SELECT_STORY } from 'storybook/internal/core-events'; +import { addons } from 'storybook/internal/preview-api'; + import LinkTo from './link'; vi.mock('storybook/internal/preview-api'); diff --git a/code/addons/links/src/react/components/link.tsx b/code/addons/links/src/react/components/link.tsx index 12437029ba67..0f1f5d34718f 100644 --- a/code/addons/links/src/react/components/link.tsx +++ b/code/addons/links/src/react/components/link.tsx @@ -1,8 +1,9 @@ -import type { ComponentTitle, StoryKind, StoryName } from 'storybook/internal/types'; import type { MouseEvent, ReactNode } from 'react'; import React, { PureComponent } from 'react'; -import { navigate, hrefTo } from '../../utils'; +import type { ComponentTitle, StoryKind, StoryName } from 'storybook/internal/types'; + +import { hrefTo, navigate } from '../../utils'; // FIXME: copied from Typography.Link. Code is duplicated to // avoid emotion dependency which breaks React 15.x back-compat diff --git a/code/addons/links/src/utils.test.ts b/code/addons/links/src/utils.test.ts index 3ca7c0c4631a..44a6601d36e2 100644 --- a/code/addons/links/src/utils.test.ts +++ b/code/addons/links/src/utils.test.ts @@ -1,10 +1,10 @@ // @vitest-environment happy-dom +import { beforeAll, beforeEach, describe, expect, it, vi } from 'vitest'; -import { describe, beforeAll, beforeEach, it, expect, vi } from 'vitest'; -import { addons } from 'storybook/internal/preview-api'; import { SELECT_STORY } from 'storybook/internal/core-events'; +import { addons } from 'storybook/internal/preview-api'; -import { linkTo, hrefTo } from './utils'; +import { hrefTo, linkTo } from './utils'; vi.mock('storybook/internal/preview-api'); vi.mock('@storybook/global', () => ({ diff --git a/code/addons/links/src/utils.ts b/code/addons/links/src/utils.ts index 93eb4dc19b94..86aa75c4fc4a 100644 --- a/code/addons/links/src/utils.ts +++ b/code/addons/links/src/utils.ts @@ -1,8 +1,10 @@ -import { global } from '@storybook/global'; +import { SELECT_STORY, STORY_CHANGED } from 'storybook/internal/core-events'; import { addons, makeDecorator } from 'storybook/internal/preview-api'; -import { STORY_CHANGED, SELECT_STORY } from 'storybook/internal/core-events'; -import type { StoryId, StoryName, ComponentTitle, StoryKind } from 'storybook/internal/types'; +import type { ComponentTitle, StoryId, StoryKind, StoryName } from 'storybook/internal/types'; + import { toId } from '@storybook/csf'; +import { global } from '@storybook/global'; + import { PARAM_KEY } from './constants'; const { document, HTMLElement } = global; diff --git a/code/addons/links/template/stories/decorator.stories.ts b/code/addons/links/template/stories/decorator.stories.ts index 53a05f380e74..afe2cd34a6a1 100644 --- a/code/addons/links/template/stories/decorator.stories.ts +++ b/code/addons/links/template/stories/decorator.stories.ts @@ -1,4 +1,5 @@ import { global as globalThis } from '@storybook/global'; + import { withLinks } from '@storybook/addon-links'; export default { diff --git a/code/addons/links/template/stories/linkto.stories.ts b/code/addons/links/template/stories/linkto.stories.ts index 502509a8d5aa..07df223f009e 100644 --- a/code/addons/links/template/stories/linkto.stories.ts +++ b/code/addons/links/template/stories/linkto.stories.ts @@ -1,4 +1,5 @@ import { global as globalThis } from '@storybook/global'; + import { linkTo } from '@storybook/addon-links'; export default { diff --git a/code/addons/links/vitest.config.ts b/code/addons/links/vitest.config.ts index 03172200442f..7420176b2e46 100644 --- a/code/addons/links/vitest.config.ts +++ b/code/addons/links/vitest.config.ts @@ -1,4 +1,5 @@ import { defineConfig, mergeConfig } from 'vitest/config'; + import { vitestCommonConfig } from '../../vitest.workspace'; export default mergeConfig( diff --git a/code/addons/measure/package.json b/code/addons/measure/package.json index b3dafc43f25f..d28e60d56672 100644 --- a/code/addons/measure/package.json +++ b/code/addons/measure/package.json @@ -27,9 +27,9 @@ "exports": { ".": { "types": "./dist/index.d.ts", - "node": "./dist/index.js", "import": "./dist/index.mjs", - "require": "./dist/index.js" + "require": "./dist/index.js", + "node": "./dist/index.js" }, "./preview": { "types": "./dist/preview.d.ts", @@ -64,8 +64,8 @@ "!src/**/*" ], "scripts": { - "check": "node --loader ../../../scripts/node_modules/esbuild-register/loader.js -r ../../../scripts/node_modules/esbuild-register/register.js ../../../scripts/prepare/check.ts", - "prep": "node --loader ../../../scripts/node_modules/esbuild-register/loader.js -r ../../../scripts/node_modules/esbuild-register/register.js ../../../scripts/prepare/addon-bundle.ts" + "check": "jiti ../../../scripts/prepare/check.ts", + "prep": "jiti ../../../scripts/prepare/addon-bundle.ts" }, "dependencies": { "@storybook/global": "^5.0.0", diff --git a/code/addons/measure/src/Tool.tsx b/code/addons/measure/src/Tool.tsx index 8662a32beec4..b6e9cbf21caa 100644 --- a/code/addons/measure/src/Tool.tsx +++ b/code/addons/measure/src/Tool.tsx @@ -1,8 +1,11 @@ import React, { useCallback, useEffect } from 'react'; -import { useGlobals, useStorybookApi } from 'storybook/internal/manager-api'; + import { IconButton } from 'storybook/internal/components'; +import { useGlobals, useStorybookApi } from 'storybook/internal/manager-api'; + import { RulerIcon } from '@storybook/icons'; -import { TOOL_ID, ADDON_ID } from './constants'; + +import { ADDON_ID, TOOL_ID } from './constants'; export const Tool = () => { const [globals, updateGlobals] = useGlobals(); diff --git a/code/addons/measure/src/box-model/canvas.ts b/code/addons/measure/src/box-model/canvas.ts index 09c769c6d244..80d0f1d3b10a 100644 --- a/code/addons/measure/src/box-model/canvas.ts +++ b/code/addons/measure/src/box-model/canvas.ts @@ -1,4 +1,5 @@ import { global } from '@storybook/global'; + import invariant from 'tiny-invariant'; interface Size { diff --git a/code/addons/measure/src/box-model/visualizer.ts b/code/addons/measure/src/box-model/visualizer.ts index 5d07189cedbd..00b1425f7f13 100644 --- a/code/addons/measure/src/box-model/visualizer.ts +++ b/code/addons/measure/src/box-model/visualizer.ts @@ -2,6 +2,7 @@ * Based on https://gist.github.com/awestbro/e668c12662ad354f02a413205b65fce7 */ import { global } from '@storybook/global'; + import { draw } from './canvas'; import type { Label, LabelStack } from './labels'; import { labelStacks } from './labels'; diff --git a/code/addons/measure/src/manager.tsx b/code/addons/measure/src/manager.tsx index 0b6aa66a74cc..df36d8211718 100644 --- a/code/addons/measure/src/manager.tsx +++ b/code/addons/measure/src/manager.tsx @@ -1,8 +1,9 @@ import React from 'react'; + import { addons, types } from 'storybook/internal/manager-api'; -import { ADDON_ID, TOOL_ID } from './constants'; import { Tool } from './Tool'; +import { ADDON_ID, TOOL_ID } from './constants'; addons.register(ADDON_ID, () => { addons.add(TOOL_ID, { diff --git a/code/addons/measure/src/preview.tsx b/code/addons/measure/src/preview.tsx index 596823c3b905..8898eb58dd6b 100644 --- a/code/addons/measure/src/preview.tsx +++ b/code/addons/measure/src/preview.tsx @@ -1,6 +1,7 @@ import type { Addon_DecoratorFunction } from 'storybook/internal/types'; -import { withMeasure } from './withMeasure'; + import { PARAM_KEY } from './constants'; +import { withMeasure } from './withMeasure'; export const decorators: Addon_DecoratorFunction[] = [withMeasure]; diff --git a/code/addons/measure/src/withMeasure.ts b/code/addons/measure/src/withMeasure.ts index c9c9a8c57a2c..8524a7f71fce 100644 --- a/code/addons/measure/src/withMeasure.ts +++ b/code/addons/measure/src/withMeasure.ts @@ -2,11 +2,12 @@ import { useEffect } from 'storybook/internal/preview-api'; import type { Renderer, - PartialStoryFn as StoryFunction, StoryContext, + PartialStoryFn as StoryFunction, } from 'storybook/internal/types'; + +import { destroy, init, rescale } from './box-model/canvas'; import { drawSelectedElement } from './box-model/visualizer'; -import { init, rescale, destroy } from './box-model/canvas'; import { deepElementFromPoint } from './util'; let nodeAtPointerRef; diff --git a/code/addons/measure/vitest.config.ts b/code/addons/measure/vitest.config.ts index 03172200442f..7420176b2e46 100644 --- a/code/addons/measure/vitest.config.ts +++ b/code/addons/measure/vitest.config.ts @@ -1,4 +1,5 @@ import { defineConfig, mergeConfig } from 'vitest/config'; + import { vitestCommonConfig } from '../../vitest.workspace'; export default mergeConfig( diff --git a/code/addons/onboarding/package.json b/code/addons/onboarding/package.json index ad9b4fdec033..8d7c2ddb6189 100644 --- a/code/addons/onboarding/package.json +++ b/code/addons/onboarding/package.json @@ -23,9 +23,9 @@ "exports": { ".": { "types": "./dist/index.d.ts", - "node": "./dist/index.js", "import": "./dist/index.mjs", - "require": "./dist/index.js" + "require": "./dist/index.js", + "node": "./dist/index.js" }, "./manager": "./dist/manager.js", "./preset": "./dist/preset.js", @@ -42,8 +42,8 @@ "!src/**/*" ], "scripts": { - "check": "node --loader ../../../scripts/node_modules/esbuild-register/loader.js -r ../../../scripts/node_modules/esbuild-register/register.js ../../../scripts/prepare/check.ts", - "prep": "node --loader ../../../scripts/node_modules/esbuild-register/loader.js -r ../../../scripts/node_modules/esbuild-register/register.js ../../../scripts/prepare/addon-bundle.ts" + "check": "jiti ../../../scripts/prepare/check.ts", + "prep": "jiti ../../../scripts/prepare/addon-bundle.ts" }, "dependencies": { "react-confetti": "^6.1.0" diff --git a/code/addons/onboarding/src/Onboarding.tsx b/code/addons/onboarding/src/Onboarding.tsx index fde1526aa483..2fe360db7e93 100644 --- a/code/addons/onboarding/src/Onboarding.tsx +++ b/code/addons/onboarding/src/Onboarding.tsx @@ -1,16 +1,17 @@ +import React, { useCallback, useEffect, useState } from 'react'; + import { SyntaxHighlighter } from 'storybook/internal/components'; import { SAVE_STORY_RESPONSE } from 'storybook/internal/core-events'; import { type API } from 'storybook/internal/manager-api'; import { ThemeProvider, convert, styled, themes } from 'storybook/internal/theming'; -import React, { useCallback, useEffect, useState } from 'react'; + import type { Step } from 'react-joyride'; -import { GuidedTour } from './features/GuidedTour/GuidedTour'; import { Confetti } from './components/Confetti/Confetti'; +import { HighlightElement } from './components/HighlightElement/HighlightElement'; import type { STORYBOOK_ADDON_ONBOARDING_STEPS } from './constants'; import { STORYBOOK_ADDON_ONBOARDING_CHANNEL } from './constants'; - -import { HighlightElement } from './components/HighlightElement/HighlightElement'; +import { GuidedTour } from './features/GuidedTour/GuidedTour'; import { SplashScreen } from './features/SplashScreen/SplashScreen'; const SpanHighlight = styled.span(({ theme }) => ({ diff --git a/code/addons/onboarding/src/components/Button/Button.stories.tsx b/code/addons/onboarding/src/components/Button/Button.stories.tsx index cf8a824713fb..1d4396a29c63 100644 --- a/code/addons/onboarding/src/components/Button/Button.stories.tsx +++ b/code/addons/onboarding/src/components/Button/Button.stories.tsx @@ -1,4 +1,5 @@ import type { Meta, StoryObj } from '@storybook/react'; + import { Button } from './Button'; const meta: Meta = { diff --git a/code/addons/onboarding/src/components/Button/Button.tsx b/code/addons/onboarding/src/components/Button/Button.tsx index b4836f8bd93b..e8cc30d4cbd6 100644 --- a/code/addons/onboarding/src/components/Button/Button.tsx +++ b/code/addons/onboarding/src/components/Button/Button.tsx @@ -1,5 +1,6 @@ import type { ComponentProps } from 'react'; import React, { forwardRef } from 'react'; + import { styled } from 'storybook/internal/theming'; export interface ButtonProps extends ComponentProps<'button'> { diff --git a/code/addons/onboarding/src/components/Confetti/Confetti.stories.tsx b/code/addons/onboarding/src/components/Confetti/Confetti.stories.tsx index 80b01c7e31d8..b55fdf783b34 100644 --- a/code/addons/onboarding/src/components/Confetti/Confetti.stories.tsx +++ b/code/addons/onboarding/src/components/Confetti/Confetti.stories.tsx @@ -1,6 +1,8 @@ +import React from 'react'; + import type { Meta, StoryObj } from '@storybook/react'; + import { Confetti } from './Confetti'; -import React from 'react'; const meta: Meta = { component: Confetti, diff --git a/code/addons/onboarding/src/components/Confetti/Confetti.tsx b/code/addons/onboarding/src/components/Confetti/Confetti.tsx index e913712c170a..b9b816d3e051 100644 --- a/code/addons/onboarding/src/components/Confetti/Confetti.tsx +++ b/code/addons/onboarding/src/components/Confetti/Confetti.tsx @@ -1,8 +1,10 @@ -import ReactConfetti from 'react-confetti'; import React, { useEffect } from 'react'; -import { styled } from 'storybook/internal/theming'; -import { createPortal } from 'react-dom'; import { useState } from 'react'; +import { createPortal } from 'react-dom'; + +import { styled } from 'storybook/internal/theming'; + +import ReactConfetti from 'react-confetti'; interface ConfettiProps extends Omit, 'drawShape'> { top?: number; diff --git a/code/addons/onboarding/src/components/HighlightElement/HighlightElement.stories.tsx b/code/addons/onboarding/src/components/HighlightElement/HighlightElement.stories.tsx index 44d894260a20..0a6cb70831b9 100644 --- a/code/addons/onboarding/src/components/HighlightElement/HighlightElement.stories.tsx +++ b/code/addons/onboarding/src/components/HighlightElement/HighlightElement.stories.tsx @@ -1,7 +1,9 @@ +import React from 'react'; + import type { Meta, StoryObj } from '@storybook/react'; +import { expect, within } from '@storybook/test'; + import { HighlightElement } from './HighlightElement'; -import React from 'react'; -import { within, expect } from '@storybook/test'; const meta: Meta = { component: HighlightElement, diff --git a/code/addons/onboarding/src/components/List/List.stories.tsx b/code/addons/onboarding/src/components/List/List.stories.tsx index 9ff667586fc3..8e7667d8a12e 100644 --- a/code/addons/onboarding/src/components/List/List.stories.tsx +++ b/code/addons/onboarding/src/components/List/List.stories.tsx @@ -1,6 +1,7 @@ import React, { useState } from 'react'; + import type { Meta, StoryObj } from '@storybook/react'; -import { userEvent, waitFor, within, expect } from '@storybook/test'; +import { expect, userEvent, waitFor, within } from '@storybook/test'; import { List } from './List'; import { ListItem } from './ListItem/ListItem'; diff --git a/code/addons/onboarding/src/components/List/List.tsx b/code/addons/onboarding/src/components/List/List.tsx index 0b9640f7d909..69467f1101ce 100644 --- a/code/addons/onboarding/src/components/List/List.tsx +++ b/code/addons/onboarding/src/components/List/List.tsx @@ -1,4 +1,5 @@ import React from 'react'; + import { ListWrapper } from './List.styled'; interface ListProps { diff --git a/code/addons/onboarding/src/components/List/ListItem/ListItem.tsx b/code/addons/onboarding/src/components/List/ListItem/ListItem.tsx index e8a9945c0bbe..2b493b456157 100644 --- a/code/addons/onboarding/src/components/List/ListItem/ListItem.tsx +++ b/code/addons/onboarding/src/components/List/ListItem/ListItem.tsx @@ -1,7 +1,9 @@ import React from 'react'; -import { ListItemContentWrapper, ListItemIndexWrapper, ListItemWrapper } from './ListItem.styled'; + import { CheckIcon } from '@storybook/icons'; +import { ListItemContentWrapper, ListItemIndexWrapper, ListItemWrapper } from './ListItem.styled'; + interface ListItemProps { children: React.ReactNode; index: number; diff --git a/code/addons/onboarding/src/features/GuidedTour/GuidedTour.tsx b/code/addons/onboarding/src/features/GuidedTour/GuidedTour.tsx index 38fd595bdc25..a61e44a420a9 100644 --- a/code/addons/onboarding/src/features/GuidedTour/GuidedTour.tsx +++ b/code/addons/onboarding/src/features/GuidedTour/GuidedTour.tsx @@ -1,10 +1,12 @@ import React, { useEffect, useState } from 'react'; + +import { useTheme } from 'storybook/internal/theming'; + import type { CallBackProps } from 'react-joyride'; import Joyride, { ACTIONS } from 'react-joyride'; -import { useTheme } from 'storybook/internal/theming'; -import { Tooltip } from './Tooltip'; import type { StepDefinition, StepKey } from '../../Onboarding'; +import { Tooltip } from './Tooltip'; export function GuidedTour({ step, diff --git a/code/addons/onboarding/src/features/GuidedTour/Tooltip.tsx b/code/addons/onboarding/src/features/GuidedTour/Tooltip.tsx index a20554757654..34ba2593b560 100644 --- a/code/addons/onboarding/src/features/GuidedTour/Tooltip.tsx +++ b/code/addons/onboarding/src/features/GuidedTour/Tooltip.tsx @@ -1,9 +1,12 @@ import type { FC } from 'react'; import React, { useEffect } from 'react'; -import type { Step, TooltipRenderProps } from 'react-joyride'; + import { IconButton } from 'storybook/internal/components'; +import { color, styled } from 'storybook/internal/theming'; + import { CloseAltIcon } from '@storybook/icons'; -import { styled, color } from 'storybook/internal/theming'; + +import type { Step, TooltipRenderProps } from 'react-joyride'; import { Button } from '../../components/Button/Button'; diff --git a/code/addons/onboarding/src/features/SplashScreen/SplashScreen.stories.tsx b/code/addons/onboarding/src/features/SplashScreen/SplashScreen.stories.tsx index fffa7ce4d3a9..7e83cd3e6558 100644 --- a/code/addons/onboarding/src/features/SplashScreen/SplashScreen.stories.tsx +++ b/code/addons/onboarding/src/features/SplashScreen/SplashScreen.stories.tsx @@ -1,4 +1,5 @@ import type { Meta, StoryObj } from '@storybook/react'; + import { SplashScreen } from './SplashScreen'; const meta = { diff --git a/code/addons/onboarding/src/features/SplashScreen/SplashScreen.tsx b/code/addons/onboarding/src/features/SplashScreen/SplashScreen.tsx index 683bca455289..0e373f63e16e 100644 --- a/code/addons/onboarding/src/features/SplashScreen/SplashScreen.tsx +++ b/code/addons/onboarding/src/features/SplashScreen/SplashScreen.tsx @@ -1,7 +1,9 @@ -import { ArrowRightIcon } from '@storybook/icons'; -import { styled, keyframes } from 'storybook/internal/theming'; import React, { useCallback, useEffect, useState } from 'react'; +import { keyframes, styled } from 'storybook/internal/theming'; + +import { ArrowRightIcon } from '@storybook/icons'; + const fadeIn = keyframes({ from: { opacity: 0, diff --git a/code/addons/onboarding/src/manager.tsx b/code/addons/onboarding/src/manager.tsx index 07c543be8bc2..b4e2edebedeb 100644 --- a/code/addons/onboarding/src/manager.tsx +++ b/code/addons/onboarding/src/manager.tsx @@ -1,7 +1,8 @@ +import React, { Suspense, lazy } from 'react'; import ReactDOM from 'react-dom'; -import React, { lazy, Suspense } from 'react'; -import { addons } from 'storybook/internal/manager-api'; + import { STORY_SPECIFIED } from 'storybook/internal/core-events'; +import { addons } from 'storybook/internal/manager-api'; const Onboarding = lazy(() => import('./Onboarding')); diff --git a/code/addons/onboarding/src/preset.ts b/code/addons/onboarding/src/preset.ts index c88501d0a3e2..f93b16235bfd 100644 --- a/code/addons/onboarding/src/preset.ts +++ b/code/addons/onboarding/src/preset.ts @@ -1,8 +1,10 @@ -import type { CoreConfig, Options } from 'storybook/internal/types'; +import { readFileSync } from 'node:fs'; + import type { Channel } from 'storybook/internal/channels'; -import { STORYBOOK_ADDON_ONBOARDING_CHANNEL } from './constants'; import { telemetry } from 'storybook/internal/telemetry'; -import fs from 'fs'; +import type { CoreConfig, Options } from 'storybook/internal/types'; + +import { STORYBOOK_ADDON_ONBOARDING_CHANNEL } from './constants'; type Event = { type: 'telemetry'; @@ -18,7 +20,7 @@ export const experimental_serverChannel = async (channel: Channel, options: Opti const packageJsonPath = require.resolve('@storybook/addon-onboarding/package.json'); const { version: addonVersion } = JSON.parse( - fs.readFileSync(packageJsonPath, { encoding: 'utf-8' }) + readFileSync(packageJsonPath, { encoding: 'utf-8' }) ); channel.on(STORYBOOK_ADDON_ONBOARDING_CHANNEL, ({ type, ...event }: Event) => { diff --git a/code/addons/onboarding/vitest.config.ts b/code/addons/onboarding/vitest.config.ts index 03172200442f..7420176b2e46 100644 --- a/code/addons/onboarding/vitest.config.ts +++ b/code/addons/onboarding/vitest.config.ts @@ -1,4 +1,5 @@ import { defineConfig, mergeConfig } from 'vitest/config'; + import { vitestCommonConfig } from '../../vitest.workspace'; export default mergeConfig( diff --git a/code/addons/outline/package.json b/code/addons/outline/package.json index 2a1eb92d7607..b46927903cee 100644 --- a/code/addons/outline/package.json +++ b/code/addons/outline/package.json @@ -30,9 +30,9 @@ "exports": { ".": { "types": "./dist/index.d.ts", - "node": "./dist/index.js", "import": "./dist/index.mjs", - "require": "./dist/index.js" + "require": "./dist/index.js", + "node": "./dist/index.js" }, "./preview": { "types": "./dist/preview.d.ts", @@ -54,8 +54,8 @@ "!src/**/*" ], "scripts": { - "check": "node --loader ../../../scripts/node_modules/esbuild-register/loader.js -r ../../../scripts/node_modules/esbuild-register/register.js ../../../scripts/prepare/check.ts", - "prep": "node --loader ../../../scripts/node_modules/esbuild-register/loader.js -r ../../../scripts/node_modules/esbuild-register/register.js ../../../scripts/prepare/addon-bundle.ts" + "check": "jiti ../../../scripts/prepare/check.ts", + "prep": "jiti ../../../scripts/prepare/addon-bundle.ts" }, "dependencies": { "@storybook/global": "^5.0.0", diff --git a/code/addons/outline/src/OutlineSelector.tsx b/code/addons/outline/src/OutlineSelector.tsx index 54fb87eda53e..a8fb501ca851 100644 --- a/code/addons/outline/src/OutlineSelector.tsx +++ b/code/addons/outline/src/OutlineSelector.tsx @@ -1,7 +1,10 @@ import React, { memo, useCallback, useEffect } from 'react'; -import { useGlobals, useStorybookApi } from 'storybook/internal/manager-api'; + import { IconButton } from 'storybook/internal/components'; +import { useGlobals, useStorybookApi } from 'storybook/internal/manager-api'; + import { OutlineIcon } from '@storybook/icons'; + import { ADDON_ID, PARAM_KEY } from './constants'; export const OutlineSelector = memo(function OutlineSelector() { diff --git a/code/addons/outline/src/manager.tsx b/code/addons/outline/src/manager.tsx index 708ee358a61c..61084e2c6abd 100644 --- a/code/addons/outline/src/manager.tsx +++ b/code/addons/outline/src/manager.tsx @@ -1,8 +1,9 @@ import React from 'react'; + import { addons, types } from 'storybook/internal/manager-api'; -import { ADDON_ID } from './constants'; import { OutlineSelector } from './OutlineSelector'; +import { ADDON_ID } from './constants'; addons.register(ADDON_ID, () => { addons.add(ADDON_ID, { diff --git a/code/addons/outline/src/preview.tsx b/code/addons/outline/src/preview.tsx index 394a6fbabe60..19deb3a9afe0 100644 --- a/code/addons/outline/src/preview.tsx +++ b/code/addons/outline/src/preview.tsx @@ -1,6 +1,7 @@ import type { Addon_DecoratorFunction } from 'storybook/internal/types'; -import { withOutline } from './withOutline'; + import { PARAM_KEY } from './constants'; +import { withOutline } from './withOutline'; export const decorators: Addon_DecoratorFunction[] = [withOutline]; diff --git a/code/addons/outline/src/withOutline.ts b/code/addons/outline/src/withOutline.ts index 5a9185e7ea02..219b93a3acd2 100644 --- a/code/addons/outline/src/withOutline.ts +++ b/code/addons/outline/src/withOutline.ts @@ -1,12 +1,12 @@ -import { useMemo, useEffect } from 'storybook/internal/preview-api'; +import { useEffect, useMemo } from 'storybook/internal/preview-api'; import type { Renderer, - PartialStoryFn as StoryFunction, StoryContext, + PartialStoryFn as StoryFunction, } from 'storybook/internal/types'; -import { clearStyles, addOutlineStyles } from './helpers'; import { PARAM_KEY } from './constants'; +import { addOutlineStyles, clearStyles } from './helpers'; import outlineCSS from './outlineCSS'; export const withOutline = (StoryFn: StoryFunction, context: StoryContext) => { diff --git a/code/addons/outline/vitest.config.ts b/code/addons/outline/vitest.config.ts index 03172200442f..7420176b2e46 100644 --- a/code/addons/outline/vitest.config.ts +++ b/code/addons/outline/vitest.config.ts @@ -1,4 +1,5 @@ import { defineConfig, mergeConfig } from 'vitest/config'; + import { vitestCommonConfig } from '../../vitest.workspace'; export default mergeConfig( diff --git a/code/addons/storysource/package.json b/code/addons/storysource/package.json index 5e19655dbb88..ec7ba777613c 100644 --- a/code/addons/storysource/package.json +++ b/code/addons/storysource/package.json @@ -24,9 +24,9 @@ "exports": { ".": { "types": "./dist/index.d.ts", - "node": "./dist/index.js", "import": "./dist/index.mjs", - "require": "./dist/index.js" + "require": "./dist/index.js", + "node": "./dist/index.js" }, "./preset": "./dist/preset.js", "./manager": "./dist/manager.js", @@ -43,8 +43,8 @@ "!src/**/*" ], "scripts": { - "check": "node --loader ../../../scripts/node_modules/esbuild-register/loader.js -r ../../../scripts/node_modules/esbuild-register/register.js ../../../scripts/prepare/check.ts", - "prep": "node --loader ../../../scripts/node_modules/esbuild-register/loader.js -r ../../../scripts/node_modules/esbuild-register/register.js ../../../scripts/prepare/addon-bundle.ts" + "check": "jiti ../../../scripts/prepare/check.ts", + "prep": "jiti ../../../scripts/prepare/addon-bundle.ts" }, "dependencies": { "@storybook/source-loader": "workspace:*", diff --git a/code/addons/storysource/src/StoryPanel.tsx b/code/addons/storysource/src/StoryPanel.tsx index 3800837778d9..aada383782ea 100644 --- a/code/addons/storysource/src/StoryPanel.tsx +++ b/code/addons/storysource/src/StoryPanel.tsx @@ -1,18 +1,19 @@ import React from 'react'; -import { type API, useParameter } from 'storybook/internal/manager-api'; -import { styled } from 'storybook/internal/theming'; -import { Link } from 'storybook/internal/router'; + import { SyntaxHighlighter, type SyntaxHighlighterProps, type SyntaxHighlighterRendererProps, } from 'storybook/internal/components'; -import invariant from 'tiny-invariant'; +import { type API, useParameter } from 'storybook/internal/manager-api'; +import { Link } from 'storybook/internal/router'; +import { styled } from 'storybook/internal/theming'; + +import type { LocationsMap, SourceBlock } from '@storybook/source-loader'; // @ts-expect-error Typedefs don't currently expose `createElement` even though it exists import { createElement as createSyntaxHighlighterElement } from 'react-syntax-highlighter'; - -import type { SourceBlock, LocationsMap } from '@storybook/source-loader'; +import invariant from 'tiny-invariant'; const StyledStoryLink = styled(Link)<{ to: string; key: string }>(({ theme }) => ({ display: 'block', diff --git a/code/addons/storysource/src/manager.tsx b/code/addons/storysource/src/manager.tsx index d08e2480fcac..7e07f90b595e 100644 --- a/code/addons/storysource/src/manager.tsx +++ b/code/addons/storysource/src/manager.tsx @@ -1,4 +1,5 @@ import React from 'react'; + import { addons, types } from 'storybook/internal/manager-api'; import { StoryPanel } from './StoryPanel'; diff --git a/code/addons/storysource/vitest.config.ts b/code/addons/storysource/vitest.config.ts index 03172200442f..7420176b2e46 100644 --- a/code/addons/storysource/vitest.config.ts +++ b/code/addons/storysource/vitest.config.ts @@ -1,4 +1,5 @@ import { defineConfig, mergeConfig } from 'vitest/config'; + import { vitestCommonConfig } from '../../vitest.workspace'; export default mergeConfig( diff --git a/code/addons/themes/docs/api.md b/code/addons/themes/docs/api.md index 0c8fc32996dd..143178b00047 100644 --- a/code/addons/themes/docs/api.md +++ b/code/addons/themes/docs/api.md @@ -95,6 +95,7 @@ Pulls the selected theme from storybook's global state. ```js import { DecoratorHelpers } from '@storybook/addon-themes'; + const { pluckThemeFromContext } = DecoratorHelpers; export const myCustomDecorator = @@ -112,6 +113,7 @@ Returns the theme parameters for this addon. ```js import { DecoratorHelpers } from '@storybook/addon-themes'; + const { useThemeParameters } = DecoratorHelpers; export const myCustomDecorator = @@ -129,6 +131,7 @@ Used to register the themes and defaultTheme with the addon state. ```js import { DecoratorHelpers } from '@storybook/addon-themes'; + const { initializeThemeState } = DecoratorHelpers; export const myCustomDecorator = ({ themes, defaultState, ...rest }) => { @@ -146,7 +149,6 @@ Let's use Vuetify as an example. Vuetify uses it's own global state to know whic ```js // .storybook/withVeutifyTheme.decorator.js - import { DecoratorHelpers } from '@storybook/addon-themes'; import { useTheme } from 'vuetify'; @@ -182,7 +184,6 @@ This can then be provided to Storybook in `.storybook/preview.js`: ```js // .storybook/preview.js - import { setup } from '@storybook/vue3'; import { registerPlugins } from '../src/plugins'; import { withVuetifyTheme } from './withVuetifyTheme.decorator'; diff --git a/code/addons/themes/package.json b/code/addons/themes/package.json index ff0ed5d26f77..dd45712d437e 100644 --- a/code/addons/themes/package.json +++ b/code/addons/themes/package.json @@ -29,9 +29,9 @@ "exports": { ".": { "types": "./dist/index.d.ts", - "node": "./dist/index.js", "import": "./dist/index.mjs", - "require": "./dist/index.js" + "require": "./dist/index.js", + "node": "./dist/index.js" }, "./preview": { "types": "./dist/preview.d.ts", @@ -53,8 +53,8 @@ "!src/**/*" ], "scripts": { - "check": "node --loader ../../../scripts/node_modules/esbuild-register/loader.js -r ../../../scripts/node_modules/esbuild-register/register.js ../../../scripts/prepare/check.ts", - "prep": "node --loader ../../../scripts/node_modules/esbuild-register/loader.js -r ../../../scripts/node_modules/esbuild-register/register.js ../../../scripts/prepare/addon-bundle.ts" + "check": "jiti ../../../scripts/prepare/check.ts", + "prep": "jiti ../../../scripts/prepare/addon-bundle.ts" }, "dependencies": { "ts-dedent": "^2.0.0" diff --git a/code/addons/themes/src/decorators/data-attribute.decorator.tsx b/code/addons/themes/src/decorators/data-attribute.decorator.tsx index 05ad62792e7c..6d4b1cfe26f9 100644 --- a/code/addons/themes/src/decorators/data-attribute.decorator.tsx +++ b/code/addons/themes/src/decorators/data-attribute.decorator.tsx @@ -1,5 +1,6 @@ import { useEffect } from 'storybook/internal/preview-api'; import type { DecoratorFunction, Renderer } from 'storybook/internal/types'; + import { initializeThemeState, pluckThemeFromContext, useThemeParameters } from './helpers'; export interface DataAttributeStrategyConfiguration { diff --git a/code/addons/themes/src/decorators/helpers.ts b/code/addons/themes/src/decorators/helpers.ts index d26ce0410320..396f0d257f24 100644 --- a/code/addons/themes/src/decorators/helpers.ts +++ b/code/addons/themes/src/decorators/helpers.ts @@ -1,7 +1,8 @@ import { addons, useParameter } from 'storybook/internal/preview-api'; import type { StoryContext } from 'storybook/internal/types'; + import type { ThemeParameters } from '../constants'; -import { GLOBAL_KEY, PARAM_KEY, THEMING_EVENTS, DEFAULT_THEME_PARAMETERS } from '../constants'; +import { DEFAULT_THEME_PARAMETERS, GLOBAL_KEY, PARAM_KEY, THEMING_EVENTS } from '../constants'; /** * diff --git a/code/addons/themes/src/decorators/provider.decorator.tsx b/code/addons/themes/src/decorators/provider.decorator.tsx index f8b477810035..3cc1bce2fdb3 100644 --- a/code/addons/themes/src/decorators/provider.decorator.tsx +++ b/code/addons/themes/src/decorators/provider.decorator.tsx @@ -1,4 +1,5 @@ import React from 'react'; + import { useMemo } from 'storybook/internal/preview-api'; import type { DecoratorFunction, Renderer } from 'storybook/internal/types'; diff --git a/code/addons/themes/src/preview.tsx b/code/addons/themes/src/preview.tsx index 6f4a444e7f7c..5d33f51b94f7 100644 --- a/code/addons/themes/src/preview.tsx +++ b/code/addons/themes/src/preview.tsx @@ -1,4 +1,5 @@ -import type { Renderer, ProjectAnnotations } from 'storybook/internal/types'; +import type { ProjectAnnotations, Renderer } from 'storybook/internal/types'; + import { GLOBAL_KEY as KEY } from './constants'; export const initialGlobals: ProjectAnnotations['initialGlobals'] = { diff --git a/code/addons/themes/src/theme-switcher.tsx b/code/addons/themes/src/theme-switcher.tsx index d57b9ce1e5e8..2af5530a0a86 100644 --- a/code/addons/themes/src/theme-switcher.tsx +++ b/code/addons/themes/src/theme-switcher.tsx @@ -1,23 +1,25 @@ import React from 'react'; + +import { IconButton, TooltipLinkList, WithTooltip } from 'storybook/internal/components'; import { + addons, useAddonState, useChannel, useGlobals, useParameter, - addons, } from 'storybook/internal/manager-api'; import { styled } from 'storybook/internal/theming'; -import { IconButton, WithTooltip, TooltipLinkList } from 'storybook/internal/components'; import { PaintBrushIcon } from '@storybook/icons'; + import type { ThemeAddonState, ThemeParameters } from './constants'; import { - PARAM_KEY, - THEME_SWITCHER_ID, - THEMING_EVENTS, DEFAULT_ADDON_STATE, DEFAULT_THEME_PARAMETERS, GLOBAL_KEY as KEY, + PARAM_KEY, + THEME_SWITCHER_ID, + THEMING_EVENTS, } from './constants'; const IconButtonLabel = styled.div(({ theme }) => ({ diff --git a/code/addons/themes/template/stories/decorators.stories.ts b/code/addons/themes/template/stories/decorators.stories.ts index aba8f17d0e79..f4308ba9e02b 100644 --- a/code/addons/themes/template/stories/decorators.stories.ts +++ b/code/addons/themes/template/stories/decorators.stories.ts @@ -1,10 +1,12 @@ +import { useEffect } from 'storybook/internal/preview-api'; + import { global as globalThis } from '@storybook/global'; + import { withThemeByClassName, withThemeByDataAttribute, withThemeFromJSXProvider, } from '@storybook/addon-themes'; -import { useEffect } from 'storybook/internal/preview-api'; const cleanup = () => { const existing = globalThis.document.querySelector('style[data-theme-css]'); diff --git a/code/addons/themes/template/stories/globals.stories.ts b/code/addons/themes/template/stories/globals.stories.ts index 3d193d1fa71a..e2d5aed08aec 100644 --- a/code/addons/themes/template/stories/globals.stories.ts +++ b/code/addons/themes/template/stories/globals.stories.ts @@ -1,6 +1,8 @@ +import { useEffect } from 'storybook/internal/preview-api'; + import { global as globalThis } from '@storybook/global'; + import { withThemeByClassName } from '@storybook/addon-themes'; -import { useEffect } from 'storybook/internal/preview-api'; const cleanup = () => { const existing = globalThis.document.querySelector('style[data-theme-css]'); diff --git a/code/addons/themes/template/stories/parameters.stories.ts b/code/addons/themes/template/stories/parameters.stories.ts index f2906696859f..2c243e085e62 100644 --- a/code/addons/themes/template/stories/parameters.stories.ts +++ b/code/addons/themes/template/stories/parameters.stories.ts @@ -1,6 +1,8 @@ +import { useEffect } from 'storybook/internal/preview-api'; + import { global as globalThis } from '@storybook/global'; + import { withThemeByClassName } from '@storybook/addon-themes'; -import { useEffect } from 'storybook/internal/preview-api'; const cleanup = () => { const existing = globalThis.document.querySelector('style[data-theme-css]'); diff --git a/code/addons/themes/vitest.config.ts b/code/addons/themes/vitest.config.ts index 03172200442f..7420176b2e46 100644 --- a/code/addons/themes/vitest.config.ts +++ b/code/addons/themes/vitest.config.ts @@ -1,4 +1,5 @@ import { defineConfig, mergeConfig } from 'vitest/config'; + import { vitestCommonConfig } from '../../vitest.workspace'; export default mergeConfig( diff --git a/code/addons/toolbars/package.json b/code/addons/toolbars/package.json index da507489ca9d..1a59a4f7b0b4 100644 --- a/code/addons/toolbars/package.json +++ b/code/addons/toolbars/package.json @@ -28,9 +28,9 @@ "exports": { ".": { "types": "./dist/index.d.ts", - "node": "./dist/index.js", "import": "./dist/index.mjs", - "require": "./dist/index.js" + "require": "./dist/index.js", + "node": "./dist/index.js" }, "./manager": "./dist/manager.js", "./register": "./dist/manager.js", @@ -47,8 +47,8 @@ "!src/**/*" ], "scripts": { - "check": "node --loader ../../../scripts/node_modules/esbuild-register/loader.js -r ../../../scripts/node_modules/esbuild-register/register.js ../../../scripts/prepare/check.ts", - "prep": "node --loader ../../../scripts/node_modules/esbuild-register/loader.js -r ../../../scripts/node_modules/esbuild-register/register.js ../../../scripts/prepare/addon-bundle.ts" + "check": "jiti ../../../scripts/prepare/check.ts", + "prep": "jiti ../../../scripts/prepare/addon-bundle.ts" }, "devDependencies": { "react": "^18.2.0", diff --git a/code/addons/toolbars/src/components/ToolbarManager.tsx b/code/addons/toolbars/src/components/ToolbarManager.tsx index 1570b72883f6..79ce101cb027 100644 --- a/code/addons/toolbars/src/components/ToolbarManager.tsx +++ b/code/addons/toolbars/src/components/ToolbarManager.tsx @@ -1,10 +1,12 @@ import type { FC } from 'react'; import React from 'react'; -import { useGlobalTypes } from 'storybook/internal/manager-api'; + import { Separator } from 'storybook/internal/components'; -import { ToolbarMenuList } from './ToolbarMenuList'; -import { normalizeArgType } from '../utils/normalize-toolbar-arg-type'; +import { useGlobalTypes } from 'storybook/internal/manager-api'; + import type { ToolbarArgType } from '../types'; +import { normalizeArgType } from '../utils/normalize-toolbar-arg-type'; +import { ToolbarMenuList } from './ToolbarMenuList'; /** * A smart component for handling manager-preview interactions. diff --git a/code/addons/toolbars/src/components/ToolbarMenuButton.tsx b/code/addons/toolbars/src/components/ToolbarMenuButton.tsx index bc093fabfade..30e4aa5365a8 100644 --- a/code/addons/toolbars/src/components/ToolbarMenuButton.tsx +++ b/code/addons/toolbars/src/components/ToolbarMenuButton.tsx @@ -1,6 +1,7 @@ import type { FC } from 'react'; import React from 'react'; -import { Icons, IconButton, type IconsProps } from 'storybook/internal/components'; + +import { IconButton, Icons, type IconsProps } from 'storybook/internal/components'; interface ToolbarMenuButtonProps { active: boolean; diff --git a/code/addons/toolbars/src/components/ToolbarMenuList.tsx b/code/addons/toolbars/src/components/ToolbarMenuList.tsx index b54f0df44e59..032cccdca4f5 100644 --- a/code/addons/toolbars/src/components/ToolbarMenuList.tsx +++ b/code/addons/toolbars/src/components/ToolbarMenuList.tsx @@ -1,12 +1,14 @@ import type { FC } from 'react'; -import React, { useState, useCallback } from 'react'; +import React, { useCallback, useState } from 'react'; + +import { TooltipLinkList, WithTooltip } from 'storybook/internal/components'; import { useGlobals } from 'storybook/internal/manager-api'; -import { WithTooltip, TooltipLinkList } from 'storybook/internal/components'; -import { ToolbarMenuButton } from './ToolbarMenuButton'; + import type { WithKeyboardCycleProps } from '../hoc/withKeyboardCycle'; import { withKeyboardCycle } from '../hoc/withKeyboardCycle'; -import { getSelectedIcon, getSelectedTitle } from '../utils/get-selected'; import type { ToolbarMenuProps } from '../types'; +import { getSelectedIcon, getSelectedTitle } from '../utils/get-selected'; +import { ToolbarMenuButton } from './ToolbarMenuButton'; import { ToolbarMenuListItem } from './ToolbarMenuListItem'; type ToolbarMenuListProps = ToolbarMenuProps & WithKeyboardCycleProps; diff --git a/code/addons/toolbars/src/components/ToolbarMenuListItem.tsx b/code/addons/toolbars/src/components/ToolbarMenuListItem.tsx index 39fa7df5dace..829829de4b25 100644 --- a/code/addons/toolbars/src/components/ToolbarMenuListItem.tsx +++ b/code/addons/toolbars/src/components/ToolbarMenuListItem.tsx @@ -1,6 +1,8 @@ import React from 'react'; + import type { TooltipLinkListLink } from 'storybook/internal/components'; import { Icons } from 'storybook/internal/components'; + import type { ToolbarItem } from '../types'; export type ToolbarMenuListItemProps = { diff --git a/code/addons/toolbars/src/hoc/withKeyboardCycle.tsx b/code/addons/toolbars/src/hoc/withKeyboardCycle.tsx index 9bdcc8e8b6a5..15b2e75eb60c 100644 --- a/code/addons/toolbars/src/hoc/withKeyboardCycle.tsx +++ b/code/addons/toolbars/src/hoc/withKeyboardCycle.tsx @@ -1,8 +1,10 @@ -import React, { useRef, useEffect, useCallback } from 'react'; +import React, { useCallback, useEffect, useRef } from 'react'; + import { useGlobals, useStorybookApi } from 'storybook/internal/manager-api'; + +import type { ToolbarMenuProps } from '../types'; import { createCycleValueArray } from '../utils/create-cycle-value-array'; import { registerShortcuts } from '../utils/register-shortcuts'; -import type { ToolbarMenuProps } from '../types'; export type WithKeyboardCycleProps = { cycleValues?: string[]; diff --git a/code/addons/toolbars/src/manager.tsx b/code/addons/toolbars/src/manager.tsx index 306e857544b0..7b63e9e7b52e 100644 --- a/code/addons/toolbars/src/manager.tsx +++ b/code/addons/toolbars/src/manager.tsx @@ -1,5 +1,7 @@ import React from 'react'; + import { addons, types } from 'storybook/internal/manager-api'; + import { ToolbarManager } from './components/ToolbarManager'; import { ADDON_ID } from './constants'; diff --git a/code/addons/toolbars/src/utils/register-shortcuts.ts b/code/addons/toolbars/src/utils/register-shortcuts.ts index 98ef5cc03f5b..423543db6944 100644 --- a/code/addons/toolbars/src/utils/register-shortcuts.ts +++ b/code/addons/toolbars/src/utils/register-shortcuts.ts @@ -1,4 +1,5 @@ import type { API } from 'storybook/internal/manager-api'; + import { ADDON_ID } from '../constants'; import type { ToolbarShortcutConfig } from '../types'; diff --git a/code/addons/toolbars/template/stories/globals.stories.ts b/code/addons/toolbars/template/stories/globals.stories.ts index dd5b52ddece0..8c8ec6a5f0f5 100644 --- a/code/addons/toolbars/template/stories/globals.stories.ts +++ b/code/addons/toolbars/template/stories/globals.stories.ts @@ -1,6 +1,7 @@ -import { global as globalThis } from '@storybook/global'; import type { DecoratorFunction } from 'storybook/internal/types'; +import { global as globalThis } from '@storybook/global'; + const greetingForLocale = (locale: string) => { switch (locale) { case 'es': diff --git a/code/addons/toolbars/vitest.config.ts b/code/addons/toolbars/vitest.config.ts index 03172200442f..7420176b2e46 100644 --- a/code/addons/toolbars/vitest.config.ts +++ b/code/addons/toolbars/vitest.config.ts @@ -1,4 +1,5 @@ import { defineConfig, mergeConfig } from 'vitest/config'; + import { vitestCommonConfig } from '../../vitest.workspace'; export default mergeConfig( diff --git a/code/addons/viewport/package.json b/code/addons/viewport/package.json index e06d56ff12be..42fab30abd92 100644 --- a/code/addons/viewport/package.json +++ b/code/addons/viewport/package.json @@ -25,9 +25,9 @@ "exports": { ".": { "types": "./dist/index.d.ts", - "node": "./dist/index.js", "import": "./dist/index.mjs", - "require": "./dist/index.js" + "require": "./dist/index.js", + "node": "./dist/index.js" }, "./preview": { "types": "./dist/preview.d.ts", @@ -48,8 +48,8 @@ "!src/**/*" ], "scripts": { - "check": "node --loader ../../../scripts/node_modules/esbuild-register/loader.js -r ../../../scripts/node_modules/esbuild-register/register.js ../../../scripts/prepare/check.ts", - "prep": "node --loader ../../../scripts/node_modules/esbuild-register/loader.js -r ../../../scripts/node_modules/esbuild-register/register.js ../../../scripts/prepare/addon-bundle.ts" + "check": "jiti ../../../scripts/prepare/check.ts", + "prep": "jiti ../../../scripts/prepare/addon-bundle.ts" }, "dependencies": { "memoizerific": "^1.11.3" diff --git a/code/addons/viewport/src/components/Tool.tsx b/code/addons/viewport/src/components/Tool.tsx index 8ee3c3bfb966..3564ecad2c08 100644 --- a/code/addons/viewport/src/components/Tool.tsx +++ b/code/addons/viewport/src/components/Tool.tsx @@ -1,22 +1,23 @@ -import React, { useState, Fragment, useEffect, type FC, useCallback } from 'react'; +import React, { type FC, Fragment, useCallback, useEffect, useState } from 'react'; +import { IconButton, TooltipLinkList, WithTooltip } from 'storybook/internal/components'; +import { type API, useGlobals, useParameter } from 'storybook/internal/manager-api'; import { Global } from 'storybook/internal/theming'; -import { IconButton, WithTooltip, TooltipLinkList } from 'storybook/internal/components'; -import { useGlobals, type API, useParameter } from 'storybook/internal/manager-api'; import { GrowIcon, RefreshIcon, TransferIcon } from '@storybook/icons'; + import { PARAM_KEY as KEY } from '../constants'; +import { responsiveViewport } from '../responsiveViewport'; import { registerShortcuts } from '../shortcuts'; +import type { Config, GlobalState, GlobalStateUpdate, Viewport, ViewportMap } from '../types'; import { - IconButtonWithLabel, - IconButtonLabel, - ActiveViewportSize, ActiveViewportLabel, - iconsMap, + ActiveViewportSize, + IconButtonLabel, + IconButtonWithLabel, emptyViewportMap, + iconsMap, } from '../utils'; -import { responsiveViewport } from '../responsiveViewport'; -import type { Config, Viewport, ViewportMap, GlobalState, GlobalStateUpdate } from '../types'; interface PureProps { item: Viewport; diff --git a/code/addons/viewport/src/legacy/ToolLegacy.tsx b/code/addons/viewport/src/legacy/ToolLegacy.tsx index c3eb3f59f7ae..7035bd79789d 100644 --- a/code/addons/viewport/src/legacy/ToolLegacy.tsx +++ b/code/addons/viewport/src/legacy/ToolLegacy.tsx @@ -1,17 +1,18 @@ -import type { ReactNode, FC } from 'react'; -import React, { useState, Fragment, useEffect, useRef, memo } from 'react'; -import memoize from 'memoizerific'; - -import { styled, Global } from 'storybook/internal/theming'; +import type { FC, ReactNode } from 'react'; +import React, { Fragment, memo, useEffect, useRef, useState } from 'react'; -import { IconButton, WithTooltip, TooltipLinkList } from 'storybook/internal/components'; +import { IconButton, TooltipLinkList, WithTooltip } from 'storybook/internal/components'; +import { useGlobals, useParameter, useStorybookApi } from 'storybook/internal/manager-api'; +import { Global, styled } from 'storybook/internal/theming'; -import { useStorybookApi, useParameter, useGlobals } from 'storybook/internal/manager-api'; import { GrowIcon, TransferIcon } from '@storybook/icons'; -import { registerShortcuts } from '../shortcuts'; + +import memoize from 'memoizerific'; + import { PARAM_KEY } from '../constants'; import { MINIMAL_VIEWPORTS } from '../defaults'; -import type { ViewportMap, ViewportStyles, Styles } from '../types'; +import { registerShortcuts } from '../shortcuts'; +import type { Styles, ViewportMap, ViewportStyles } from '../types'; import type { ViewportAddonParameter } from './ViewportAddonParameter'; interface ViewportItem { diff --git a/code/addons/viewport/src/manager.tsx b/code/addons/viewport/src/manager.tsx index e7425aff76d3..df05367498f8 100644 --- a/code/addons/viewport/src/manager.tsx +++ b/code/addons/viewport/src/manager.tsx @@ -1,10 +1,10 @@ import * as React from 'react'; + import { addons, types } from 'storybook/internal/manager-api'; +import { ViewportTool } from './components/Tool'; import { ADDON_ID } from './constants'; - import { ViewportToolLegacy } from './legacy/ToolLegacy'; -import { ViewportTool } from './components/Tool'; addons.register(ADDON_ID, (api) => { addons.add(ADDON_ID, { diff --git a/code/addons/viewport/src/shortcuts.ts b/code/addons/viewport/src/shortcuts.ts index f53d460b81bd..59ef7787e208 100644 --- a/code/addons/viewport/src/shortcuts.ts +++ b/code/addons/viewport/src/shortcuts.ts @@ -1,4 +1,5 @@ import { type API } from 'storybook/internal/manager-api'; + import { ADDON_ID } from './constants'; import { initialGlobals as defaultGlobals } from './preview'; diff --git a/code/addons/viewport/src/utils.tsx b/code/addons/viewport/src/utils.tsx index be4f3cb16096..e83572e89628 100644 --- a/code/addons/viewport/src/utils.tsx +++ b/code/addons/viewport/src/utils.tsx @@ -1,9 +1,10 @@ import React, { Fragment } from 'react'; -import { styled } from 'storybook/internal/theming'; import { IconButton } from 'storybook/internal/components'; +import { styled } from 'storybook/internal/theming'; import { BrowserIcon, MobileIcon, TabletIcon } from '@storybook/icons'; + import type { Viewport, ViewportMap } from './types'; export const ActiveViewportSize = styled.div(() => ({ diff --git a/code/addons/viewport/template/stories/globals.stories.ts b/code/addons/viewport/template/stories/globals.stories.ts index 621bf0b02c62..ebfcc11f9b6b 100644 --- a/code/addons/viewport/template/stories/globals.stories.ts +++ b/code/addons/viewport/template/stories/globals.stories.ts @@ -1,4 +1,5 @@ import { global as globalThis } from '@storybook/global'; + import { MINIMAL_VIEWPORTS } from '@storybook/addon-viewport'; const first = Object.keys(MINIMAL_VIEWPORTS)[0]; diff --git a/code/addons/viewport/template/stories/parameters.stories.ts b/code/addons/viewport/template/stories/parameters.stories.ts index f98de1eda0c4..b715564e1753 100644 --- a/code/addons/viewport/template/stories/parameters.stories.ts +++ b/code/addons/viewport/template/stories/parameters.stories.ts @@ -1,4 +1,5 @@ import { global as globalThis } from '@storybook/global'; + import { MINIMAL_VIEWPORTS } from '@storybook/addon-viewport'; // these stories only work with `viewportStoryGlobals` set to false diff --git a/code/addons/viewport/vitest.config.ts b/code/addons/viewport/vitest.config.ts index 03172200442f..7420176b2e46 100644 --- a/code/addons/viewport/vitest.config.ts +++ b/code/addons/viewport/vitest.config.ts @@ -1,4 +1,5 @@ import { defineConfig, mergeConfig } from 'vitest/config'; + import { vitestCommonConfig } from '../../vitest.workspace'; export default mergeConfig( diff --git a/code/builders/builder-vite/README.md b/code/builders/builder-vite/README.md index 18a2e0ec6df3..d6116b3c30fe 100644 --- a/code/builders/builder-vite/README.md +++ b/code/builders/builder-vite/README.md @@ -117,7 +117,9 @@ The function should return the updated Vite configuration. Configure your `.storybook/main.ts` to use TypeScript: ```typescript -import type { StorybookConfig } from '@storybook/react-vite'; // (or whatever framework you are using) +import type { StorybookConfig } from '@storybook/react-vite'; + +// (or whatever framework you are using) const config: StorybookConfig = { // other storybook options..., diff --git a/code/builders/builder-vite/package.json b/code/builders/builder-vite/package.json index a5df7a0333a5..0b191cd58d97 100644 --- a/code/builders/builder-vite/package.json +++ b/code/builders/builder-vite/package.json @@ -39,8 +39,8 @@ "!src/**/*" ], "scripts": { - "check": "node --loader ../../../scripts/node_modules/esbuild-register/loader.js -r ../../../scripts/node_modules/esbuild-register/register.js ../../../scripts/prepare/check.ts", - "prep": "node --loader ../../../scripts/node_modules/esbuild-register/loader.js -r ../../../scripts/node_modules/esbuild-register/register.js ../../../scripts/prepare/bundle.ts" + "check": "jiti ../../../scripts/prepare/check.ts", + "prep": "jiti ../../../scripts/prepare/bundle.ts" }, "dependencies": { "@storybook/csf-plugin": "workspace:*", @@ -55,7 +55,7 @@ }, "devDependencies": { "@types/express": "^4.17.21", - "@types/node": "^18.0.0", + "@types/node": "^22.0.0", "glob": "^10.0.0", "slash": "^5.0.0", "typescript": "^5.3.2", diff --git a/code/builders/builder-vite/src/build.ts b/code/builders/builder-vite/src/build.ts index f55423e0e979..581ce74a7569 100644 --- a/code/builders/builder-vite/src/build.ts +++ b/code/builders/builder-vite/src/build.ts @@ -1,13 +1,14 @@ -import type { Options } from 'storybook/internal/types'; import { logger } from 'storybook/internal/node-logger'; +import type { Options } from 'storybook/internal/types'; + import { dedent } from 'ts-dedent'; +import type { InlineConfig } from 'vite'; -import { commonConfig } from './vite-config'; import { sanitizeEnvVars } from './envs'; import type { WebpackStatsPlugin } from './plugins'; -import type { InlineConfig } from 'vite'; import { hasVitePlugins } from './utils/has-vite-plugins'; import { withoutVitePlugins } from './utils/without-vite-plugins'; +import { commonConfig } from './vite-config'; function findPlugin(config: InlineConfig, name: string) { return config.plugins?.find((p) => p && 'name' in p && p.name === name); diff --git a/code/builders/builder-vite/src/codegen-importfn-script.ts b/code/builders/builder-vite/src/codegen-importfn-script.ts index 48ce451b74f8..abf89ce09a73 100644 --- a/code/builders/builder-vite/src/codegen-importfn-script.ts +++ b/code/builders/builder-vite/src/codegen-importfn-script.ts @@ -1,4 +1,4 @@ -import * as path from 'path'; +import { relative } from 'node:path'; import type { Options } from 'storybook/internal/types'; @@ -27,7 +27,7 @@ function toImportPath(relativePath: string) { async function toImportFn(stories: string[]) { const { normalizePath } = await import('vite'); const objectEntries = stories.map((file) => { - const relativePath = normalizePath(path.relative(process.cwd(), file)); + const relativePath = normalizePath(relative(process.cwd(), file)); return ` '${toImportPath(relativePath)}': async () => import('/@fs/${file}')`; }); diff --git a/code/builders/builder-vite/src/codegen-modern-iframe-script.ts b/code/builders/builder-vite/src/codegen-modern-iframe-script.ts index bcafede02125..86a39776ddeb 100644 --- a/code/builders/builder-vite/src/codegen-modern-iframe-script.ts +++ b/code/builders/builder-vite/src/codegen-modern-iframe-script.ts @@ -1,7 +1,8 @@ -import { loadPreviewOrConfigFile, getFrameworkName } from 'storybook/internal/common'; +import { getFrameworkName, loadPreviewOrConfigFile } from 'storybook/internal/common'; import type { Options, PreviewAnnotation } from 'storybook/internal/types'; -import { virtualStoriesFile, virtualAddonSetupFile } from './virtual-file-names'; + import { processPreviewAnnotation } from './utils/process-preview-annotation'; +import { virtualAddonSetupFile, virtualStoriesFile } from './virtual-file-names'; export async function generateModernIframeScriptCode(options: Options, projectRoot: string) { const { presets, configDir } = options; diff --git a/code/builders/builder-vite/src/envs.ts b/code/builders/builder-vite/src/envs.ts index 1b9495d78828..422ce3ae28bf 100644 --- a/code/builders/builder-vite/src/envs.ts +++ b/code/builders/builder-vite/src/envs.ts @@ -1,7 +1,8 @@ import { stringifyEnvs } from 'storybook/internal/common'; -import type { UserConfig as ViteConfig } from 'vite'; import type { Builder_EnvsRaw, Options } from 'storybook/internal/types'; +import type { UserConfig as ViteConfig } from 'vite'; + // Allowed env variables on the client const allowedEnvVariables = [ 'STORYBOOK', diff --git a/code/builders/builder-vite/src/index.ts b/code/builders/builder-vite/src/index.ts index d62d230b676c..a8a775a13344 100644 --- a/code/builders/builder-vite/src/index.ts +++ b/code/builders/builder-vite/src/index.ts @@ -1,17 +1,19 @@ // noinspection JSUnusedGlobalSymbols +import { join, parse } from 'node:path'; -import * as fs from 'fs-extra'; -import type { RequestHandler } from 'express'; -import type { ViteDevServer } from 'vite'; -import express from 'express'; -import { join, parse } from 'path'; import { NoStatsForViteDevError } from 'storybook/internal/server-errors'; import type { Options } from 'storybook/internal/types'; + +import type { RequestHandler } from 'express'; +import express from 'express'; +import * as fs from 'fs-extra'; import { corePath } from 'storybook/core-path'; -import { transformIframeHtml } from './transform-iframe-html'; -import { createViteServer } from './vite-server'; +import type { ViteDevServer } from 'vite'; + import { build as viteBuild } from './build'; +import { transformIframeHtml } from './transform-iframe-html'; import type { ViteBuilder } from './types'; +import { createViteServer } from './vite-server'; export { withoutVitePlugins } from './utils/without-vite-plugins'; export { hasVitePlugins } from './utils/has-vite-plugins'; diff --git a/code/builders/builder-vite/src/list-stories.ts b/code/builders/builder-vite/src/list-stories.ts index e484ba6cc0c4..5eefb9b8fb74 100644 --- a/code/builders/builder-vite/src/list-stories.ts +++ b/code/builders/builder-vite/src/list-stories.ts @@ -1,10 +1,11 @@ -import * as path from 'path'; -import slash from 'slash'; -import { glob } from 'glob'; -import { normalizeStories, commonGlobOptions } from 'storybook/internal/common'; +import { isAbsolute, join } from 'node:path'; +import { commonGlobOptions, normalizeStories } from 'storybook/internal/common'; import type { Options } from 'storybook/internal/types'; +import { glob } from 'glob'; +import slash from 'slash'; + export async function listStories(options: Options) { const { normalizePath } = await import('vite'); @@ -15,10 +16,8 @@ export async function listStories(options: Options) { configDir: options.configDir, workingDir: options.configDir, }).map(({ directory, files }) => { - const pattern = path.join(directory, files); - const absolutePattern = path.isAbsolute(pattern) - ? pattern - : path.join(options.configDir, pattern); + const pattern = join(directory, files); + const absolutePattern = isAbsolute(pattern) ? pattern : join(options.configDir, pattern); return glob(slash(absolutePattern), { ...commonGlobOptions(absolutePattern), diff --git a/code/builders/builder-vite/src/optimizeDeps.ts b/code/builders/builder-vite/src/optimizeDeps.ts index 2b0cb4ad9049..5937c4497720 100644 --- a/code/builders/builder-vite/src/optimizeDeps.ts +++ b/code/builders/builder-vite/src/optimizeDeps.ts @@ -1,6 +1,9 @@ -import * as path from 'path'; -import type { InlineConfig as ViteInlineConfig, UserConfig } from 'vite'; +import { relative } from 'node:path'; + import type { Options } from 'storybook/internal/types'; + +import type { UserConfig, InlineConfig as ViteInlineConfig } from 'vite'; + import { listStories } from './list-stories'; // It ensures that vite converts cjs deps into esm without vite having to find them during startup and then having to log a message about them and restart @@ -119,7 +122,7 @@ export async function getOptimizeDeps(config: ViteInlineConfig, options: Options const { root = process.cwd() } = config; const { normalizePath, resolveConfig } = await import('vite'); const absoluteStories = await listStories(options); - const stories = absoluteStories.map((storyPath) => normalizePath(path.relative(root, storyPath))); + const stories = absoluteStories.map((storyPath) => normalizePath(relative(root, storyPath))); // TODO: check if resolveConfig takes a lot of time, possible optimizations here const resolvedConfig = await resolveConfig(config, 'serve', 'development'); diff --git a/code/builders/builder-vite/src/plugins/code-generator-plugin.ts b/code/builders/builder-vite/src/plugins/code-generator-plugin.ts index 65015129cb3f..ac0fe2a3b970 100644 --- a/code/builders/builder-vite/src/plugins/code-generator-plugin.ts +++ b/code/builders/builder-vite/src/plugins/code-generator-plugin.ts @@ -1,11 +1,13 @@ -import * as fs from 'fs'; -import type { Plugin } from 'vite'; +import { readFileSync } from 'node:fs'; + import type { Options } from 'storybook/internal/types'; -import { transformIframeHtml } from '../transform-iframe-html'; -import { generateModernIframeScriptCode } from '../codegen-modern-iframe-script'; + +import type { Plugin } from 'vite'; + import { generateImportFnScriptCode } from '../codegen-importfn-script'; +import { generateModernIframeScriptCode } from '../codegen-modern-iframe-script'; import { generateAddonSetupCode } from '../codegen-set-addon-channel'; - +import { transformIframeHtml } from '../transform-iframe-html'; import { virtualAddonSetupFile, virtualFileId, @@ -68,41 +70,38 @@ export function codeGeneratorPlugin(options: Options): Plugin { }, resolveId(source) { if (source === virtualFileId) { - return virtualFileId; + return `\0${virtualFileId}`; } if (source === iframePath) { return iframeId; } if (source === virtualStoriesFile) { - return virtualStoriesFile; + return `\0${virtualStoriesFile}`; } if (source === virtualPreviewFile) { return virtualPreviewFile; } if (source === virtualAddonSetupFile) { - return virtualAddonSetupFile; + return `\0${virtualAddonSetupFile}`; } return undefined; }, async load(id, config) { - if (id === virtualStoriesFile) { + if (id === `\0${virtualStoriesFile}`) { return generateImportFnScriptCode(options); } - if (id === virtualAddonSetupFile) { + if (id === `\0${virtualAddonSetupFile}`) { return generateAddonSetupCode(); } - if (id === virtualFileId) { + if (id === `\0${virtualFileId}`) { return generateModernIframeScriptCode(options, projectRoot); } if (id === iframeId) { - return fs.readFileSync( - require.resolve('@storybook/builder-vite/input/iframe.html'), - 'utf-8' - ); + return readFileSync(require.resolve('@storybook/builder-vite/input/iframe.html'), 'utf-8'); } return undefined; diff --git a/code/builders/builder-vite/src/plugins/csf-plugin.ts b/code/builders/builder-vite/src/plugins/csf-plugin.ts index cb549f165b89..2541f7b74758 100644 --- a/code/builders/builder-vite/src/plugins/csf-plugin.ts +++ b/code/builders/builder-vite/src/plugins/csf-plugin.ts @@ -1,7 +1,9 @@ -import type { Plugin } from 'vite'; -import { vite } from '@storybook/csf-plugin'; import type { Options } from 'storybook/internal/types'; +import { vite } from '@storybook/csf-plugin'; + +import type { Plugin } from 'vite'; + export async function csfPlugin(config: Options): Promise { const { presets } = config; diff --git a/code/builders/builder-vite/src/plugins/external-globals-plugin.test.ts b/code/builders/builder-vite/src/plugins/external-globals-plugin.test.ts index fc9ec9e47abc..9555a4dd6b86 100644 --- a/code/builders/builder-vite/src/plugins/external-globals-plugin.test.ts +++ b/code/builders/builder-vite/src/plugins/external-globals-plugin.test.ts @@ -1,4 +1,5 @@ -import { it, expect } from 'vitest'; +import { expect, it } from 'vitest'; + import { rewriteImport } from './external-globals-plugin'; const packageName = '@storybook/package'; diff --git a/code/builders/builder-vite/src/plugins/external-globals-plugin.ts b/code/builders/builder-vite/src/plugins/external-globals-plugin.ts index 94af1a74999c..8fbe95669f1d 100644 --- a/code/builders/builder-vite/src/plugins/external-globals-plugin.ts +++ b/code/builders/builder-vite/src/plugins/external-globals-plugin.ts @@ -1,8 +1,9 @@ import { join } from 'node:path'; -import findCacheDirectory from 'find-cache-dir'; + import { init, parse } from 'es-module-lexer'; -import MagicString from 'magic-string'; +import findCacheDirectory from 'find-cache-dir'; import { ensureFile, writeFile } from 'fs-extra'; +import MagicString from 'magic-string'; import type { Alias, Plugin } from 'vite'; const escapeKeys = (key: string) => key.replace(/[-[\]{}()*+?.,\\^$|#\s]/g, '\\$&'); diff --git a/code/builders/builder-vite/src/plugins/strip-story-hmr-boundaries.ts b/code/builders/builder-vite/src/plugins/strip-story-hmr-boundaries.ts index c249fc523d1a..d393d41476b1 100644 --- a/code/builders/builder-vite/src/plugins/strip-story-hmr-boundaries.ts +++ b/code/builders/builder-vite/src/plugins/strip-story-hmr-boundaries.ts @@ -1,5 +1,5 @@ -import type { Plugin } from 'vite'; import MagicString from 'magic-string'; +import type { Plugin } from 'vite'; /** * This plugin removes HMR `accept` calls in story files. Stories should not be treated diff --git a/code/builders/builder-vite/src/plugins/webpack-stats-plugin.ts b/code/builders/builder-vite/src/plugins/webpack-stats-plugin.ts index 672ff4531a6d..3669bfd4a745 100644 --- a/code/builders/builder-vite/src/plugins/webpack-stats-plugin.ts +++ b/code/builders/builder-vite/src/plugins/webpack-stats-plugin.ts @@ -1,7 +1,8 @@ // This plugin is a direct port of https://github.com/IanVS/vite-plugin-turbosnap +import { relative } from 'node:path'; import type { BuilderStats } from 'storybook/internal/types'; -import path from 'path'; + import slash from 'slash'; import type { Plugin } from 'vite'; @@ -57,7 +58,7 @@ export function pluginWebpackStats({ workingDir }: WebpackStatsPluginOptions): W } // Otherwise, we need them in the format `./path/to/file.js`. else { - const relativePath = path.relative(workingDir, stripQueryParams(filename)); + const relativePath = relative(workingDir, stripQueryParams(filename)); // This seems hacky, got to be a better way to add a `./` to the start of a path. return `./${slash(relativePath)}`; } diff --git a/code/builders/builder-vite/src/transform-iframe-html.ts b/code/builders/builder-vite/src/transform-iframe-html.ts index 0cf17c2cd8d7..6f864b5e4189 100644 --- a/code/builders/builder-vite/src/transform-iframe-html.ts +++ b/code/builders/builder-vite/src/transform-iframe-html.ts @@ -1,5 +1,5 @@ import { normalizeStories } from 'storybook/internal/common'; -import type { DocsOptions, TagsOptions, Options } from 'storybook/internal/types'; +import type { DocsOptions, Options, TagsOptions } from 'storybook/internal/types'; export type PreviewHtml = string | undefined; diff --git a/code/builders/builder-vite/src/types.ts b/code/builders/builder-vite/src/types.ts index a6579ed938cf..404a259243a5 100644 --- a/code/builders/builder-vite/src/types.ts +++ b/code/builders/builder-vite/src/types.ts @@ -1,6 +1,7 @@ -import type { InlineConfig, UserConfig } from 'vite'; import type { Builder, Options } from 'storybook/internal/types'; +import type { InlineConfig, UserConfig } from 'vite'; + // Storybook's Stats are optional Webpack related property type ViteStats = { toJson: () => any; diff --git a/code/builders/builder-vite/src/utils/has-vite-plugins.test.ts b/code/builders/builder-vite/src/utils/has-vite-plugins.test.ts index 8070b69220be..b8d5a3e44617 100644 --- a/code/builders/builder-vite/src/utils/has-vite-plugins.test.ts +++ b/code/builders/builder-vite/src/utils/has-vite-plugins.test.ts @@ -1,4 +1,5 @@ -import { describe, it, expect } from 'vitest'; +import { describe, expect, it } from 'vitest'; + import { hasVitePlugins } from './has-vite-plugins'; describe('hasVitePlugins', () => { diff --git a/code/builders/builder-vite/src/utils/process-preview-annotation.test.ts b/code/builders/builder-vite/src/utils/process-preview-annotation.test.ts index 4d211fd5fafb..3a01623919d5 100644 --- a/code/builders/builder-vite/src/utils/process-preview-annotation.test.ts +++ b/code/builders/builder-vite/src/utils/process-preview-annotation.test.ts @@ -1,6 +1,7 @@ -import { describe, it, expect } from 'vitest'; -import { processPreviewAnnotation } from './process-preview-annotation'; +import { describe, expect, it } from 'vitest'; + import { onlyWindows, skipWindows } from '../../../../vitest.helpers'; +import { processPreviewAnnotation } from './process-preview-annotation'; describe('processPreviewAnnotation()', () => { it('should pull the `bare` value from an object', () => { diff --git a/code/builders/builder-vite/src/utils/process-preview-annotation.ts b/code/builders/builder-vite/src/utils/process-preview-annotation.ts index e87259d00941..d63dc9d375d1 100644 --- a/code/builders/builder-vite/src/utils/process-preview-annotation.ts +++ b/code/builders/builder-vite/src/utils/process-preview-annotation.ts @@ -1,7 +1,9 @@ +import { isAbsolute, relative, resolve } from 'node:path'; + +import { stripAbsNodeModulesPath } from 'storybook/internal/common'; import type { PreviewAnnotation } from 'storybook/internal/types'; -import { resolve, isAbsolute, relative } from 'path'; + import slash from 'slash'; -import { stripAbsNodeModulesPath } from 'storybook/internal/common'; /** * Preview annotations can take several forms, and vite needs them to be diff --git a/code/builders/builder-vite/src/utils/without-vite-plugins.test.ts b/code/builders/builder-vite/src/utils/without-vite-plugins.test.ts index dea82e6af9cb..e0efee13036b 100644 --- a/code/builders/builder-vite/src/utils/without-vite-plugins.test.ts +++ b/code/builders/builder-vite/src/utils/without-vite-plugins.test.ts @@ -1,4 +1,5 @@ -import { describe, it, expect } from 'vitest'; +import { describe, expect, it } from 'vitest'; + import { withoutVitePlugins } from './without-vite-plugins'; describe('withoutVitePlugins', () => { diff --git a/code/builders/builder-vite/src/vite-config.test.ts b/code/builders/builder-vite/src/vite-config.test.ts index 6f83d67b5479..d88da0305397 100644 --- a/code/builders/builder-vite/src/vite-config.test.ts +++ b/code/builders/builder-vite/src/vite-config.test.ts @@ -1,7 +1,10 @@ -import { describe, it, expect, vi } from 'vitest'; +import { describe, expect, it, vi } from 'vitest'; + import type { Options, Presets } from 'storybook/internal/types'; + // eslint-disable-next-line @typescript-eslint/no-restricted-imports import { loadConfigFromFile } from 'vite'; + import { commonConfig } from './vite-config'; vi.mock('vite', async (importOriginal) => ({ diff --git a/code/builders/builder-vite/src/vite-config.ts b/code/builders/builder-vite/src/vite-config.ts index 2a965dbacffc..e3eff12d038e 100644 --- a/code/builders/builder-vite/src/vite-config.ts +++ b/code/builders/builder-vite/src/vite-config.ts @@ -1,28 +1,30 @@ -import * as path from 'path'; -import type { - ConfigEnv, - InlineConfig as ViteInlineConfig, - PluginOption, - UserConfig as ViteConfig, - InlineConfig, -} from 'vite'; +import { resolve } from 'node:path'; + import { - isPreservingSymlinks, - getFrameworkName, getBuilderOptions, + getFrameworkName, + isPreservingSymlinks, resolvePathInStorybookCache, } from 'storybook/internal/common'; import { globalsNameReferenceMap } from 'storybook/internal/preview/globals'; import type { Options } from 'storybook/internal/types'; + +import type { + ConfigEnv, + InlineConfig, + PluginOption, + UserConfig as ViteConfig, + InlineConfig as ViteInlineConfig, +} from 'vite'; + import { codeGeneratorPlugin, csfPlugin, - injectExportOrderPlugin, - stripStoryHMRBoundary, externalGlobalsPlugin, + injectExportOrderPlugin, pluginWebpackStats, + stripStoryHMRBoundary, } from './plugins'; - import type { BuilderOptions } from './types'; export type PluginConfigType = 'build' | 'development'; @@ -49,7 +51,7 @@ export async function commonConfig( const { viteConfigPath } = await getBuilderOptions(options); - const projectRoot = path.resolve(options.configDir, '..'); + const projectRoot = resolve(options.configDir, '..'); // I destructure away the `build` property from the user's config object // I do this because I can contain config that breaks storybook, such as we had in a lit project. diff --git a/code/builders/builder-vite/src/vite-server.ts b/code/builders/builder-vite/src/vite-server.ts index 41cc40ed9470..ff235aa93833 100644 --- a/code/builders/builder-vite/src/vite-server.ts +++ b/code/builders/builder-vite/src/vite-server.ts @@ -1,9 +1,11 @@ -import type { Server } from 'http'; import type { Options } from 'storybook/internal/types'; -import { commonConfig } from './vite-config'; -import { getOptimizeDeps } from './optimizeDeps'; -import { sanitizeEnvVars } from './envs'; + +import type { Server } from 'http'; + import { getAssetsInclude } from './assetsInclude'; +import { sanitizeEnvVars } from './envs'; +import { getOptimizeDeps } from './optimizeDeps'; +import { commonConfig } from './vite-config'; export async function createViteServer(options: Options, devServer: Server) { const { presets } = options; diff --git a/code/builders/builder-vite/vitest.config.ts b/code/builders/builder-vite/vitest.config.ts index ea8b4ef14350..edf3cc3ea035 100644 --- a/code/builders/builder-vite/vitest.config.ts +++ b/code/builders/builder-vite/vitest.config.ts @@ -1,5 +1,6 @@ // eslint-disable-next-line import/no-extraneous-dependencies import { defineConfig, mergeConfig } from 'vitest/config'; + import { vitestCommonConfig } from '../../vitest.workspace'; export default mergeConfig( diff --git a/code/builders/builder-webpack5/package.json b/code/builders/builder-webpack5/package.json index b66000089f29..430d7b0b94d3 100644 --- a/code/builders/builder-webpack5/package.json +++ b/code/builders/builder-webpack5/package.json @@ -59,12 +59,12 @@ "!src/**/*" ], "scripts": { - "check": "node --loader ../../../scripts/node_modules/esbuild-register/loader.js -r ../../../scripts/node_modules/esbuild-register/register.js ../../../scripts/prepare/check.ts", - "prep": "node --loader ../../../scripts/node_modules/esbuild-register/loader.js -r ../../../scripts/node_modules/esbuild-register/register.js ../../../scripts/prepare/bundle.ts" + "check": "jiti ../../../scripts/prepare/check.ts", + "prep": "jiti ../../../scripts/prepare/bundle.ts" }, "dependencies": { "@storybook/core-webpack": "workspace:*", - "@types/node": "^18.0.0", + "@types/node": "^22.0.0", "@types/semver": "^7.3.4", "browser-assert": "^1.2.1", "case-sensitive-paths-webpack-plugin": "^2.4.0", diff --git a/code/builders/builder-webpack5/src/index.ts b/code/builders/builder-webpack5/src/index.ts index 635643626e62..12b38b0709ee 100644 --- a/code/builders/builder-webpack5/src/index.ts +++ b/code/builders/builder-webpack5/src/index.ts @@ -1,22 +1,24 @@ -import type { Stats, Configuration, StatsOptions } from 'webpack'; -import webpack, { ProgressPlugin } from 'webpack'; -import webpackDevMiddleware from 'webpack-dev-middleware'; -import webpackHotMiddleware from 'webpack-hot-middleware'; -import { logger } from 'storybook/internal/node-logger'; -import type { Builder, Options } from 'storybook/internal/types'; -import { corePath } from 'storybook/core-path'; -import { checkWebpackVersion } from '@storybook/core-webpack'; -import { join, parse } from 'path'; -import express from 'express'; -import fs from 'fs-extra'; +import { join, parse } from 'node:path'; + import { PREVIEW_BUILDER_PROGRESS } from 'storybook/internal/core-events'; +import { logger } from 'storybook/internal/node-logger'; import { WebpackCompilationError, WebpackInvocationError, WebpackMissingStatsError, } from 'storybook/internal/server-errors'; +import type { Builder, Options } from 'storybook/internal/types'; +import { checkWebpackVersion } from '@storybook/core-webpack'; + +import express from 'express'; +import fs from 'fs-extra'; import prettyTime from 'pretty-hrtime'; +import { corePath } from 'storybook/core-path'; +import type { Configuration, Stats, StatsOptions } from 'webpack'; +import webpack, { ProgressPlugin } from 'webpack'; +import webpackDevMiddleware from 'webpack-dev-middleware'; +import webpackHotMiddleware from 'webpack-hot-middleware'; export * from './types'; export * from './preview/virtual-module-mapping'; diff --git a/code/builders/builder-webpack5/src/loaders/export-order-loader.ts b/code/builders/builder-webpack5/src/loaders/export-order-loader.ts index ef3149a424c1..43f5fd00db42 100644 --- a/code/builders/builder-webpack5/src/loaders/export-order-loader.ts +++ b/code/builders/builder-webpack5/src/loaders/export-order-loader.ts @@ -1,5 +1,6 @@ import assert from 'node:assert'; -import { parse as parseCjs, init as initCjsParser } from 'cjs-module-lexer'; + +import { init as initCjsParser, parse as parseCjs } from 'cjs-module-lexer'; import { parse as parseEs } from 'es-module-lexer'; import MagicString from 'magic-string'; import type { LoaderContext } from 'webpack'; diff --git a/code/builders/builder-webpack5/src/presets/custom-webpack-preset.ts b/code/builders/builder-webpack5/src/presets/custom-webpack-preset.ts index f8978d512973..31a90cf794f9 100644 --- a/code/builders/builder-webpack5/src/presets/custom-webpack-preset.ts +++ b/code/builders/builder-webpack5/src/presets/custom-webpack-preset.ts @@ -1,8 +1,11 @@ -import * as webpackReal from 'webpack'; import { logger } from 'storybook/internal/node-logger'; import type { Options, PresetProperty } from 'storybook/internal/types'; -import type { Configuration } from 'webpack'; + import { loadCustomWebpackConfig } from '@storybook/core-webpack'; + +import * as webpackReal from 'webpack'; +import type { Configuration } from 'webpack'; + import { createDefaultWebpackConfig } from '../preview/base-webpack.config'; export const swc: PresetProperty<'swc'> = (config: Record): Record => { diff --git a/code/builders/builder-webpack5/src/preview/base-webpack.config.ts b/code/builders/builder-webpack5/src/preview/base-webpack.config.ts index e99fab6b769f..d53b437989ee 100644 --- a/code/builders/builder-webpack5/src/preview/base-webpack.config.ts +++ b/code/builders/builder-webpack5/src/preview/base-webpack.config.ts @@ -1,5 +1,6 @@ import { logger } from 'storybook/internal/node-logger'; import type { Options } from 'storybook/internal/types'; + import type { Configuration } from 'webpack'; export async function createDefaultWebpackConfig( diff --git a/code/builders/builder-webpack5/src/preview/iframe-webpack.config.ts b/code/builders/builder-webpack5/src/preview/iframe-webpack.config.ts index c594b12978de..461a36aec648 100644 --- a/code/builders/builder-webpack5/src/preview/iframe-webpack.config.ts +++ b/code/builders/builder-webpack5/src/preview/iframe-webpack.config.ts @@ -1,23 +1,27 @@ -import { dirname, join, resolve } from 'path'; -import { DefinePlugin, HotModuleReplacementPlugin, ProgressPlugin, ProvidePlugin } from 'webpack'; -import type { Configuration } from 'webpack'; -import HtmlWebpackPlugin from 'html-webpack-plugin'; -// @ts-expect-error (I removed this on purpose, because it's incorrect) -import CaseSensitivePathsPlugin from 'case-sensitive-paths-webpack-plugin'; -import TerserWebpackPlugin from 'terser-webpack-plugin'; -import VirtualModulePlugin from 'webpack-virtual-modules'; -import ForkTsCheckerWebpackPlugin from 'fork-ts-checker-webpack-plugin'; -import type { TransformOptions as EsbuildOptions } from 'esbuild'; -import type { Options } from 'storybook/internal/types'; -import { globalsNameReferenceMap } from 'storybook/internal/preview/globals'; +import { dirname, join, resolve } from 'node:path'; + import { getBuilderOptions, - stringifyProcessEnvs, - normalizeStories, isPreservingSymlinks, + normalizeStories, + stringifyProcessEnvs, } from 'storybook/internal/common'; +import { globalsNameReferenceMap } from 'storybook/internal/preview/globals'; +import type { Options } from 'storybook/internal/types'; + import { type BuilderOptions } from '@storybook/core-webpack'; + +// @ts-expect-error (I removed this on purpose, because it's incorrect) +import CaseSensitivePathsPlugin from 'case-sensitive-paths-webpack-plugin'; +import type { TransformOptions as EsbuildOptions } from 'esbuild'; +import ForkTsCheckerWebpackPlugin from 'fork-ts-checker-webpack-plugin'; +import HtmlWebpackPlugin from 'html-webpack-plugin'; +import TerserWebpackPlugin from 'terser-webpack-plugin'; import { dedent } from 'ts-dedent'; +import { DefinePlugin, HotModuleReplacementPlugin, ProgressPlugin, ProvidePlugin } from 'webpack'; +import type { Configuration } from 'webpack'; +import VirtualModulePlugin from 'webpack-virtual-modules'; + import type { TypescriptOptions } from '../types'; import { getVirtualModules } from './virtual-module-mapping'; diff --git a/code/builders/builder-webpack5/src/preview/virtual-module-mapping.ts b/code/builders/builder-webpack5/src/preview/virtual-module-mapping.ts index 69f64ad41921..2b78d926f12e 100644 --- a/code/builders/builder-webpack5/src/preview/virtual-module-mapping.ts +++ b/code/builders/builder-webpack5/src/preview/virtual-module-mapping.ts @@ -1,5 +1,5 @@ -import type { Options, PreviewAnnotation } from 'storybook/internal/types'; -import { join, resolve } from 'path'; +import { join, resolve } from 'node:path'; + import { getBuilderOptions, handlebars, @@ -7,8 +7,12 @@ import { normalizeStories, readTemplate, } from 'storybook/internal/common'; -import slash from 'slash'; +import type { Options, PreviewAnnotation } from 'storybook/internal/types'; + import { toImportFn } from '@storybook/core-webpack'; + +import slash from 'slash'; + import type { BuilderOptions } from '../types'; export const getVirtualModules = async (options: Options) => { diff --git a/code/builders/builder-webpack5/src/types.ts b/code/builders/builder-webpack5/src/types.ts index 38621af56274..1064cdb485f6 100644 --- a/code/builders/builder-webpack5/src/types.ts +++ b/code/builders/builder-webpack5/src/types.ts @@ -1,12 +1,12 @@ -import type { Configuration, Stats } from 'webpack'; import type { - Options, BuilderResult as BuilderResultBase, + Options, StorybookConfig, TypescriptOptions as WebpackTypescriptOptions, } from '@storybook/core-webpack'; import type ForkTsCheckerWebpackPlugin from 'fork-ts-checker-webpack-plugin'; +import type { Configuration, Stats } from 'webpack'; type TypeScriptOptionsBase = Partial; diff --git a/code/builders/builder-webpack5/vitest.config.ts b/code/builders/builder-webpack5/vitest.config.ts index ea8b4ef14350..edf3cc3ea035 100644 --- a/code/builders/builder-webpack5/vitest.config.ts +++ b/code/builders/builder-webpack5/vitest.config.ts @@ -1,5 +1,6 @@ // eslint-disable-next-line import/no-extraneous-dependencies import { defineConfig, mergeConfig } from 'vitest/config'; + import { vitestCommonConfig } from '../../vitest.workspace'; export default mergeConfig( diff --git a/code/core/package.json b/code/core/package.json index bb87c60bcfd7..400c9c392e52 100644 --- a/code/core/package.json +++ b/code/core/package.json @@ -265,13 +265,12 @@ "!src/**/*" ], "scripts": { - "check": "bun ./scripts/check.ts", - "prep": "bun ./scripts/prep.ts" + "check": "jiti ./scripts/check.ts", + "prep": "jiti ./scripts/prep.ts" }, "dependencies": { "@storybook/csf": "^0.1.11", "@types/express": "^4.17.21", - "@types/node": "^18.0.0", "browser-assert": "^1.2.1", "esbuild": "^0.18.0 || ^0.19.0 || ^0.20.0 || ^0.21.0 || ^0.22.0 || ^0.23.0", "esbuild-register": "^3.5.0", @@ -314,8 +313,7 @@ "@types/fs-extra": "^11.0.1", "@types/js-yaml": "^4.0.5", "@types/lodash": "^4.14.167", - "@types/mock-fs": "^4.13.1", - "@types/node": "^18.0.0", + "@types/node": "^22.0.0", "@types/npmlog": "^7.0.0", "@types/picomatch": "^2.3.0", "@types/prettier": "^3.0.0", @@ -326,7 +324,6 @@ "@types/react-transition-group": "^4", "@types/semver": "^7.5.8", "@types/ws": "^8", - "@vitest/utils": "^1.3.1", "@yarnpkg/esbuild-plugin-pnp": "^3.0.0-rc.10", "@yarnpkg/fslib": "2.10.3", "@yarnpkg/libzip": "2.3.0", @@ -376,8 +373,8 @@ "leven": "^4.0.0", "lodash": "^4.17.21", "markdown-to-jsx": "^7.4.5", + "memfs": "^4.11.1", "memoizerific": "^1.11.3", - "mock-fs": "^5.2.0", "nanoid": "^4.0.2", "npmlog": "^7.0.0", "open": "^8.4.0", diff --git a/code/core/scripts/check.ts b/code/core/scripts/check.ts index ca51bcf847f5..945fe125c138 100644 --- a/code/core/scripts/check.ts +++ b/code/core/scripts/check.ts @@ -1,4 +1,4 @@ -import { getTSFilesAndConfig, getTSProgramAndHost, getTSDiagnostics } from './helpers/typescript'; +import { getTSDiagnostics, getTSFilesAndConfig, getTSProgramAndHost } from './helpers/typescript'; const tsconfigPath = 'tsconfig.json'; diff --git a/code/core/scripts/dts.ts b/code/core/scripts/dts.ts index 932a2ae228e5..93458c07dfac 100644 --- a/code/core/scripts/dts.ts +++ b/code/core/scripts/dts.ts @@ -1,49 +1,55 @@ import { join } from 'node:path'; -import { process, dts, nodeInternals } from '../../../scripts/prepare/tools'; -import { getEntries } from './entries'; + +import { dts, nodeInternals, process } from '../../../scripts/prepare/tools'; import pkg from '../package.json'; +import { getEntries } from './entries'; + +async function run() { + const cwd = process.cwd(); + + const flags = process.argv.slice(2); + + const selection = flags[0] || 'all'; + + const entries = getEntries(cwd); + const external = [ + ...Object.keys((pkg as any).dependencies || {}), + ...Object.keys((pkg as any).peerDependencies || {}), + ...nodeInternals, + 'typescript', + '@storybook/core', + + '@storybook/core/builder-manager', + '@storybook/core/channels', + '@storybook/core/client-logger', + '@storybook/core/common', + '@storybook/core/components', + '@storybook/core/core-events', + '@storybook/core/core-server', + '@storybook/core/csf-tools', + '@storybook/core/docs-tools', + '@storybook/core/manager-api', + '@storybook/core/node-logger', + '@storybook/core/preview-api', + '@storybook/core/router', + '@storybook/core/telemetry', + '@storybook/core/theming', + '@storybook/core/types', + ]; + + const all = entries.filter((e) => e.dts); + const list = selection === 'all' ? all : [all[Number(selection)]]; + + console.log('Generating d.ts files for', list.map((i) => i.file).join(', ')); + + await Promise.all( + list.map(async (i) => { + await dts(i.file, [...external, ...i.externals], join(__dirname, '..', 'tsconfig.json')); + }) + ); +} -const cwd = process.cwd(); - -const flags = process.argv.slice(2); - -const selection = flags[0] || 'all'; - -const entries = getEntries(cwd); -const external = [ - ...Object.keys((pkg as any).dependencies || {}), - ...Object.keys((pkg as any).peerDependencies || {}), - ...nodeInternals, - 'typescript', - '@storybook/core', - - '@storybook/core/builder-manager', - '@storybook/core/channels', - '@storybook/core/client-logger', - '@storybook/core/common', - '@storybook/core/components', - '@storybook/core/core-events', - '@storybook/core/core-server', - '@storybook/core/csf-tools', - '@storybook/core/docs-tools', - '@storybook/core/manager-api', - '@storybook/core/node-logger', - '@storybook/core/preview-api', - '@storybook/core/router', - '@storybook/core/telemetry', - '@storybook/core/theming', - '@storybook/core/types', -]; - -const all = entries.filter((e) => e.dts); -const list = selection === 'all' ? all : [all[Number(selection)]]; - -await Promise.all( - list.map(async (i) => { - await dts( - i.file, - [...external, ...i.externals], - join(import.meta.dirname, '..', 'tsconfig.json') - ); - }) -); +run().catch((e) => { + process.stderr.write(e.toString()); + process.exit(1); +}); diff --git a/code/core/scripts/helpers/dependencies.ts b/code/core/scripts/helpers/dependencies.ts index b94144854034..82b22a022ad4 100644 --- a/code/core/scripts/helpers/dependencies.ts +++ b/code/core/scripts/helpers/dependencies.ts @@ -1,5 +1,7 @@ import { join } from 'node:path'; +import { readJson } from 'fs-extra'; + export async function flattenDependencies( list: string[], output: string[] = [], @@ -16,7 +18,7 @@ export async function flattenDependencies( console.log(dep + ' not found'); return; } - const { dependencies = {}, peerDependencies = {} } = await Bun.file(path).json(); + const { dependencies = {}, peerDependencies = {} } = await readJson(path); const all: string[] = [ ...new Set([...Object.keys(dependencies), ...Object.keys(peerDependencies)]), ] diff --git a/code/core/scripts/helpers/generatePackageJsonFile.ts b/code/core/scripts/helpers/generatePackageJsonFile.ts index 7d87d25ae9e2..08a7975e3d9b 100644 --- a/code/core/scripts/helpers/generatePackageJsonFile.ts +++ b/code/core/scripts/helpers/generatePackageJsonFile.ts @@ -1,13 +1,17 @@ +import { writeFile } from 'node:fs/promises'; import { join, relative } from 'node:path'; + +import { readJSON } from 'fs-extra'; import slash from 'slash'; -import { sortPackageJson, Bun } from '../../../../scripts/prepare/tools'; + +import { sortPackageJson } from '../../../../scripts/prepare/tools'; import type { getEntries } from '../entries'; const cwd = process.cwd(); export async function generatePackageJsonFile(entries: ReturnType) { const location = join(cwd, 'package.json'); - const pkgJson = await Bun.file(location).json(); + const pkgJson = await readJSON(location); /** Re-create the `exports` field in `code/core/package.json` * This way we only need to update the `./scripts/entries.ts` file to ensure all things we create actually exist and are mapped to the correct path. @@ -67,5 +71,5 @@ export async function generatePackageJsonFile(entries: ReturnType[] = []; + const limited = limit(10); + let processes: ReturnType[] = []; await Promise.all( dtsEntries.map(async (fileName, index) => { return limited(async () => { const getDtsProcess = () => - Bun.spawn(['bun', './scripts/dts.ts', index.toString()], { - cwd, - stdio: ['ignore', 'pipe', 'inherit'], - }); + spawn( + join(__dirname, '../../../../scripts/node_modules/.bin/jiti'), + ['./scripts/dts.ts', index.toString()], + { + cwd, + stdio: ['ignore', 'pipe', 'inherit'], + } + ); let timer: ReturnType | undefined; - let dtsProcess = getDtsProcess(); + const dtsProcess = getDtsProcess(); processes.push(dtsProcess); + await Promise.race([ - dtsProcess.exited.catch(async () => { - await dtsProcess.kill(); - dtsProcess = getDtsProcess(); - return dtsProcess.exited; + new Promise((resolve) => { + dtsProcess.on('exit', () => { + resolve(void 0); + }); + dtsProcess.on('error', () => { + resolve(void 0); + }); + dtsProcess.on('close', () => { + resolve(void 0); + }); }), - new Promise((_, reject) => { + new Promise((resolve) => { timer = setTimeout(() => { console.log(index, fileName); - reject(new Error('timed out')); + dtsProcess.kill(408); // timed out + resolve(void 0); }, 60000); }), ]); + if (timer) { clearTimeout(timer); } + if (dtsProcess.exitCode !== 0) { + console.log(dtsProcess.exitCode); // If any fail, kill all the other processes and exit (bail) processes.forEach((p) => p.kill()); processes = []; diff --git a/code/core/scripts/helpers/generateTypesMapperFiles.ts b/code/core/scripts/helpers/generateTypesMapperFiles.ts index f50f9b4fb07d..11423eaa0b58 100644 --- a/code/core/scripts/helpers/generateTypesMapperFiles.ts +++ b/code/core/scripts/helpers/generateTypesMapperFiles.ts @@ -1,7 +1,10 @@ -import { Bun } from '../../../../scripts/prepare/tools'; -import type { getEntries } from '../entries'; +import { writeFile } from 'node:fs/promises'; import { join, relative } from 'node:path'; + +import { ensureFile } from 'fs-extra'; + import { dedent } from '../../../../scripts/prepare/tools'; +import type { getEntries } from '../entries'; const cwd = process.cwd(); @@ -10,7 +13,7 @@ async function generateTypesMapperContent(filePath: string) { const downwards = relative(cwd, filePath); return dedent` - // auto generated file from ${import.meta.filename}, do not edit + // auto generated file from ${__filename}, do not edit export * from '${join(upwards, downwards)}'; export type * from '${join(upwards, downwards)}'; `; @@ -27,11 +30,10 @@ export async function generateTypesMapperFiles(entries: ReturnType e.dts).map((e) => e.file); await Promise.all( - all.map(async (filePath) => - Bun.write( - filePath.replace('src', 'dist').replace(/\.tsx?/, '.d.ts'), - await generateTypesMapperContent(filePath) - ) - ) + all.map(async (filePath) => { + const location = filePath.replace('src', 'dist').replace(/\.tsx?/, '.d.ts'); + await ensureFile(location); + await writeFile(location, await generateTypesMapperContent(filePath)); + }) ); } diff --git a/code/core/scripts/helpers/modifyThemeTypes.ts b/code/core/scripts/helpers/modifyThemeTypes.ts index 3faf5c37af63..5e586f4763bc 100644 --- a/code/core/scripts/helpers/modifyThemeTypes.ts +++ b/code/core/scripts/helpers/modifyThemeTypes.ts @@ -1,5 +1,7 @@ +import { readFile, writeFile } from 'node:fs/promises'; import { join } from 'node:path'; -import { dedent, Bun } from '../../../../scripts/prepare/tools'; + +import { dedent } from '../../../../scripts/prepare/tools'; export async function modifyThemeTypes() { /** @@ -7,8 +9,8 @@ export async function modifyThemeTypes() { * This is not an option for us, because we pre-bundle emotion in. * The little hack work to ensure the `Theme` export is overloaded with our `StorybookTheme` interface. (in both development and production builds) */ - const target = join(import.meta.dirname, '..', '..', 'dist', 'theming', 'index.d.ts'); - const contents = await Bun.file(target).text(); + const target = join(__dirname, '..', '..', 'dist', 'theming', 'index.d.ts'); + const contents = await readFile(target, 'utf-8'); const footer = contents.includes('// auto generated file') ? `export { StorybookTheme as Theme } from '../src/index';` @@ -22,5 +24,5 @@ export async function modifyThemeTypes() { ${footer} `; - await Bun.write(target, newContents); + await writeFile(target, newContents); } diff --git a/code/core/scripts/helpers/sourcefiles.ts b/code/core/scripts/helpers/sourcefiles.ts index 867f401ad15b..7b38a00e025e 100644 --- a/code/core/scripts/helpers/sourcefiles.ts +++ b/code/core/scripts/helpers/sourcefiles.ts @@ -1,17 +1,18 @@ +import { readdir, writeFile } from 'node:fs/promises'; import { join } from 'node:path'; -import { readdir } from 'node:fs/promises'; -import { dedent, prettier, getWorkspace, esbuild } from '../../../../scripts/prepare/tools'; -import { temporaryFile } from '../../src/common/utils/cli'; import { GlobalRegistrator } from '@happy-dom/global-registrator'; +import { dedent, esbuild, getWorkspace, prettier } from '../../../../scripts/prepare/tools'; +import { temporaryFile } from '../../src/common/utils/cli'; + GlobalRegistrator.register({ url: 'http://localhost:3000', width: 1920, height: 1080 }); // read code/frameworks subfolders and generate a list of available frameworks // save this list into ./code/core/src/types/frameworks.ts and export it as a union type. // The name of the type is `SupportedFrameworks`. Add additionally 'qwik' and `solid` to that list. export const generateSourceFiles = async () => { - const location = join(import.meta.dirname, '..', '..', 'src'); + const location = join(__dirname, '..', '..', 'src'); const prettierConfig = await prettier.resolveConfig(location); await Promise.all([ @@ -23,7 +24,7 @@ export const generateSourceFiles = async () => { }; async function generateVersionsFile(prettierConfig: prettier.Options | null): Promise { - const location = join(import.meta.dirname, '..', '..', 'src', 'common', 'versions.ts'); + const location = join(__dirname, '..', '..', 'src', 'common', 'versions.ts'); const workspace = await getWorkspace(); @@ -38,7 +39,7 @@ async function generateVersionsFile(prettierConfig: prettier.Options | null): Pr }, {}) ); - await Bun.write( + await writeFile( location, await prettier.format( dedent` @@ -55,23 +56,15 @@ async function generateVersionsFile(prettierConfig: prettier.Options | null): Pr async function generateFrameworksFile(prettierConfig: prettier.Options | null): Promise { const thirdPartyFrameworks = ['qwik', 'solid']; - const location = join( - import.meta.dirname, - '..', - '..', - 'src', - 'types', - 'modules', - 'frameworks.ts' - ); - const frameworksDirectory = join(import.meta.dirname, '..', '..', '..', 'frameworks'); + const location = join(__dirname, '..', '..', 'src', 'types', 'modules', 'frameworks.ts'); + const frameworksDirectory = join(__dirname, '..', '..', '..', 'frameworks'); const readFrameworks = await readdir(frameworksDirectory); const frameworks = [...readFrameworks.sort(), ...thirdPartyFrameworks] .map((framework) => `'${framework}'`) .join(' | '); - await Bun.write( + await writeFile( location, await prettier.format( dedent` @@ -87,25 +80,17 @@ async function generateFrameworksFile(prettierConfig: prettier.Options | null): } const localAlias = { - '@storybook/core': join(import.meta.dirname, '..', '..', 'src'), - storybook: join(import.meta.dirname, '..', '..', 'src'), + '@storybook/core': join(__dirname, '..', '..', 'src'), + storybook: join(__dirname, '..', '..', 'src'), }; async function generateExportsFile(prettierConfig: prettier.Options | null): Promise { function removeDefault(input: string) { return input !== 'default'; } - const location = join(import.meta.dirname, '..', '..', 'src', 'manager', 'globals', 'exports.ts'); + const location = join(__dirname, '..', '..', 'src', 'manager', 'globals', 'exports.ts'); - const entryFile = join( - import.meta.dirname, - '..', - '..', - 'src', - 'manager', - 'globals', - 'runtime.ts' - ); + const entryFile = join(__dirname, '..', '..', 'src', 'manager', 'globals', 'runtime.ts'); const outFile = await temporaryFile({ extension: 'js' }); await esbuild.build({ @@ -133,7 +118,7 @@ async function generateExportsFile(prettierConfig: prettier.Options | null): Pro } } - await Bun.write( + await writeFile( location, await prettier.format( dedent` diff --git a/code/core/scripts/helpers/typescript.ts b/code/core/scripts/helpers/typescript.ts index 474a64e8bc7e..13d26b9be642 100644 --- a/code/core/scripts/helpers/typescript.ts +++ b/code/core/scripts/helpers/typescript.ts @@ -1,4 +1,5 @@ import { join } from 'node:path'; + import { typescript } from '../../../../scripts/prepare/tools'; export function getTSDiagnostics( diff --git a/code/core/scripts/prep.ts b/code/core/scripts/prep.ts index 4bd99e8837a3..a24980b296f5 100644 --- a/code/core/scripts/prep.ts +++ b/code/core/scripts/prep.ts @@ -1,161 +1,163 @@ /* eslint-disable local-rules/no-uncategorized-errors */ - import { watch } from 'node:fs'; -import { rmdir } from 'node:fs/promises'; -import { join, dirname } from 'node:path'; +import { mkdir, rm } from 'node:fs/promises'; +import { dirname, join } from 'node:path'; + import { - esbuild, - process, - merge, - measure, chalk, - prettyTime, - nodeInternals, dedent, + esbuild, globalExternals, + measure, + merge, + nodeInternals, + prettyTime, + process, } from '../../../scripts/prepare/tools'; -import { getBundles, getEntries, getFinals } from './entries'; - -import { globalsModuleInfoMap } from '../src/manager/globals-module-info'; - import pkg from '../package.json'; -import { generateSourceFiles } from './helpers/sourcefiles'; -import { modifyThemeTypes } from './helpers/modifyThemeTypes'; +import { globalsModuleInfoMap } from '../src/manager/globals-module-info'; +import { getBundles, getEntries, getFinals } from './entries'; import { generatePackageJsonFile } from './helpers/generatePackageJsonFile'; -import { generateTypesMapperFiles } from './helpers/generateTypesMapperFiles'; import { generateTypesFiles } from './helpers/generateTypesFiles'; -import { isNode, noExternals, isBrowser } from './helpers/isEntryType'; +import { generateTypesMapperFiles } from './helpers/generateTypesMapperFiles'; +import { isBrowser, isNode, noExternals } from './helpers/isEntryType'; +import { modifyThemeTypes } from './helpers/modifyThemeTypes'; +import { generateSourceFiles } from './helpers/sourcefiles'; -const flags = process.argv.slice(2); -const cwd = process.cwd(); +async function run() { + const flags = process.argv.slice(2); + const cwd = process.cwd(); -const isOptimized = flags.includes('--optimized'); -const isWatch = flags.includes('--watch'); -const isReset = flags.includes('--reset'); + const isOptimized = flags.includes('--optimized'); + const isWatch = flags.includes('--watch'); + const isReset = flags.includes('--reset'); -const external = [ - ...new Set([ - ...Object.keys(pkg.dependencies), - ...Object.keys((pkg as any).peerDependencies || {}), - ]), -]; + const external = [ + ...new Set([ + ...Object.keys(pkg.dependencies), + ...Object.keys((pkg as any).peerDependencies || {}), + ]), + ]; -if (isOptimized && isWatch) { - throw new Error('Cannot watch and optimize at the same time'); -} + if (isOptimized && isWatch) { + throw new Error('Cannot watch and optimize at the same time'); + } -if (isReset) { - await rmdir(join(cwd, 'dist'), { recursive: true }); -} + if (isReset) { + await rm(join(cwd, 'dist'), { recursive: true }).catch(() => {}); + await mkdir(join(cwd, 'dist')); + } -const entries = getEntries(cwd); -const bundles = getBundles(cwd); -const finals = getFinals(cwd); + const entries = getEntries(cwd); + const bundles = getBundles(cwd); + const finals = getFinals(cwd); -type EsbuildContextOptions = Parameters<(typeof esbuild)['context']>[0]; + type EsbuildContextOptions = Parameters<(typeof esbuild)['context']>[0]; -console.log(isWatch ? 'Watching...' : 'Bundling...'); + console.log(isWatch ? 'Watching...' : 'Bundling...'); -const files = measure(generateSourceFiles); -const packageJson = measure(() => generatePackageJsonFile(entries)); -const dist = files.then(() => measure(generateDistFiles)); -const types = measure(async () => { - await generateTypesMapperFiles(entries); - await modifyThemeTypes(); - await generateTypesFiles(entries, isOptimized, cwd); - await modifyThemeTypes(); -}); + const files = measure(generateSourceFiles); + const packageJson = measure(() => generatePackageJsonFile(entries)); + const dist = files.then(() => measure(generateDistFiles)); + const types = files.then(() => + measure(async () => { + await generateTypesMapperFiles(entries); + await modifyThemeTypes(); + await generateTypesFiles(entries, isOptimized, cwd); + await modifyThemeTypes(); + }) + ); -const [filesTime, packageJsonTime, distTime, typesTime] = await Promise.all([ - files, - packageJson, - dist, - types, -]); + const [filesTime, packageJsonTime, distTime, typesTime] = await Promise.all([ + files, + packageJson, + dist, + types, + ]); -console.log('Files generated in', chalk.yellow(prettyTime(filesTime))); -console.log('Package.json generated in', chalk.yellow(prettyTime(packageJsonTime))); -console.log(isWatch ? 'Watcher started in' : 'Bundled in', chalk.yellow(prettyTime(distTime))); -console.log( - isOptimized ? 'Generated types in' : 'Generated type mappers in', - chalk.yellow(prettyTime(typesTime)) -); + console.log('Files generated in', chalk.yellow(prettyTime(filesTime))); + console.log('Package.json generated in', chalk.yellow(prettyTime(packageJsonTime))); + console.log(isWatch ? 'Watcher started in' : 'Bundled in', chalk.yellow(prettyTime(distTime))); + console.log( + isOptimized ? 'Generated types in' : 'Generated type mappers in', + chalk.yellow(prettyTime(typesTime)) + ); -async function generateDistFiles() { - const esbuildDefaultOptions = { - absWorkingDir: cwd, - allowOverwrite: false, - assetNames: 'assets/[name]-[hash]', - bundle: true, - chunkNames: 'chunks/[name]-[hash]', - external: ['@storybook/core', ...external], - keepNames: true, - legalComments: 'none', - lineLimit: 140, - metafile: true, - minifyIdentifiers: isOptimized, - minifySyntax: isOptimized, - minifyWhitespace: false, - outdir: 'dist', - sourcemap: false, - treeShaking: true, - } satisfies EsbuildContextOptions; + async function generateDistFiles() { + const esbuildDefaultOptions = { + absWorkingDir: cwd, + allowOverwrite: false, + assetNames: 'assets/[name]-[hash]', + bundle: true, + chunkNames: 'chunks/[name]-[hash]', + external: ['@storybook/core', ...external], + keepNames: true, + legalComments: 'none', + lineLimit: 140, + metafile: true, + minifyIdentifiers: isOptimized, + minifySyntax: isOptimized, + minifyWhitespace: false, + outdir: 'dist', + sourcemap: false, + treeShaking: true, + } satisfies EsbuildContextOptions; - const browserEsbuildOptions = { - ...esbuildDefaultOptions, - format: 'esm', - target: ['chrome100', 'safari15', 'firefox91'], - splitting: false, - platform: 'browser', + const browserEsbuildOptions = { + ...esbuildDefaultOptions, + format: 'esm', + target: ['chrome100', 'safari15', 'firefox91'], + splitting: false, + platform: 'browser', - conditions: ['browser', 'module', 'import', 'default'], - } satisfies EsbuildContextOptions; + conditions: ['browser', 'module', 'import', 'default'], + } satisfies EsbuildContextOptions; - const nodeEsbuildOptions = { - ...esbuildDefaultOptions, - target: 'node18', - splitting: false, - platform: 'neutral', - mainFields: ['main', 'module', 'node'], - conditions: ['node', 'module', 'import', 'require'], - } satisfies EsbuildContextOptions; + const nodeEsbuildOptions = { + ...esbuildDefaultOptions, + target: 'node18', + splitting: false, + platform: 'neutral', + mainFields: ['main', 'module', 'node'], + conditions: ['node', 'module', 'import', 'require'], + } satisfies EsbuildContextOptions; - const browserAliases = { - assert: require.resolve('browser-assert'), - process: require.resolve('process/browser.js'), - util: require.resolve('util/util.js'), - }; + const browserAliases = { + assert: require.resolve('browser-assert'), + process: require.resolve('process/browser.js'), + util: require.resolve('util/util.js'), + }; - const compile = await Promise.all([ - esbuild.context( - merge(nodeEsbuildOptions, { - entryPoints: entries - .filter(isNode) - .filter(noExternals) - .map((e) => e.file), - external: [...nodeInternals, ...esbuildDefaultOptions.external], - format: 'cjs', - outExtension: { - '.js': '.cjs', - }, - }) - ), - esbuild.context( - merge(browserEsbuildOptions, { - alias: browserAliases, - entryPoints: entries - .filter(isBrowser) - .filter(noExternals) - .map((entry) => entry.file), - outExtension: { - '.js': '.js', - }, - }) - ), - esbuild.context( - merge(nodeEsbuildOptions, { - banner: { - js: dedent` + const compile = await Promise.all([ + esbuild.context( + merge(nodeEsbuildOptions, { + entryPoints: entries + .filter(isNode) + .filter(noExternals) + .map((e) => e.file), + external: [...nodeInternals, ...esbuildDefaultOptions.external], + format: 'cjs', + outExtension: { + '.js': '.cjs', + }, + }) + ), + esbuild.context( + merge(browserEsbuildOptions, { + alias: browserAliases, + entryPoints: entries + .filter(isBrowser) + .filter(noExternals) + .map((entry) => entry.file), + outExtension: { + '.js': '.js', + }, + }) + ), + esbuild.context( + merge(nodeEsbuildOptions, { + banner: { + js: dedent` import ESM_COMPAT_Module from "node:module"; import { fileURLToPath as ESM_COMPAT_fileURLToPath } from 'node:url'; import { dirname as ESM_COMPAT_dirname } from 'node:path'; @@ -163,167 +165,173 @@ async function generateDistFiles() { const __dirname = ESM_COMPAT_dirname(__filename); const require = ESM_COMPAT_Module.createRequire(import.meta.url); `, - }, - entryPoints: entries - .filter(isNode) - .filter(noExternals) - .filter((i) => !isBrowser(i)) - .map((entry) => entry.file), - external: [...nodeInternals, ...esbuildDefaultOptions.external], - format: 'esm', - outExtension: { - '.js': '.js', - }, - }) - ), - ...bundles.flatMap((entry) => { - const results = []; - results.push( - esbuild.context( - merge(browserEsbuildOptions, { - outdir: dirname(entry.file).replace('src', 'dist'), - entryPoints: [entry.file], - outExtension: { '.js': '.js' }, - alias: { - ...browserAliases, - '@storybook/core': join(cwd, 'src'), - react: dirname(require.resolve('react/package.json')), - 'react-dom': dirname(require.resolve('react-dom/package.json')), - }, - external: [], - }) - ) - ); - - return results; - }), - ...finals.flatMap((entry) => { - const results = []; - results.push( - esbuild.context( - merge(browserEsbuildOptions, { - alias: { - '@storybook/core': join(cwd, 'src'), - react: dirname(require.resolve('react/package.json')), - 'react-dom': dirname(require.resolve('react-dom/package.json')), - 'react-dom/client': join( - dirname(require.resolve('react-dom/package.json')), - 'client' - ), - }, - define: { - // This should set react in prod mode for the manager - 'process.env.NODE_ENV': JSON.stringify('production'), - }, - entryPoints: [entry.file], - external: [], - outdir: dirname(entry.file).replace('src', 'dist'), - outExtension: { - '.js': '.js', - }, - plugins: [globalExternals(globalsModuleInfoMap)], - }) - ) - ); + }, + entryPoints: entries + .filter(isNode) + .filter(noExternals) + .filter((i) => !isBrowser(i)) + .map((entry) => entry.file), + external: [...nodeInternals, ...esbuildDefaultOptions.external], + format: 'esm', + outExtension: { + '.js': '.js', + }, + }) + ), + ...bundles.flatMap((entry) => { + const results = []; + results.push( + esbuild.context( + merge(browserEsbuildOptions, { + outdir: dirname(entry.file).replace('src', 'dist'), + entryPoints: [entry.file], + outExtension: { '.js': '.js' }, + alias: { + ...browserAliases, + '@storybook/core': join(cwd, 'src'), + react: dirname(require.resolve('react/package.json')), + 'react-dom': dirname(require.resolve('react-dom/package.json')), + }, + external: [], + }) + ) + ); - return results; - }), - ...entries - .filter((entry) => !noExternals(entry)) - .flatMap((entry) => { + return results; + }), + ...finals.flatMap((entry) => { const results = []; - if (entry.node) { - results.push( - esbuild.context( - merge(nodeEsbuildOptions, { - entryPoints: [entry.file], - external: [ - ...nodeInternals, - ...esbuildDefaultOptions.external, - ...entry.externals, - ].filter((e) => !entry.internals.includes(e)), - format: 'cjs', - outdir: dirname(entry.file).replace('src', 'dist'), - outExtension: { - '.js': '.cjs', - }, - }) - ) - ); - } - if (entry.browser) { - results.push( - esbuild.context( - merge(browserEsbuildOptions, { - entryPoints: [entry.file], - external: [ - ...nodeInternals, - ...esbuildDefaultOptions.external, - ...entry.externals, - ].filter((e) => !entry.internals.includes(e)), - outdir: dirname(entry.file).replace('src', 'dist'), - outExtension: { - '.js': '.js', - }, - }) - ) - ); - } else if (entry.node) { - results.push( - esbuild.context( - merge(nodeEsbuildOptions, { - entryPoints: [entry.file], - external: [ - ...nodeInternals, - ...esbuildDefaultOptions.external, - ...entry.externals, - ].filter((e) => !entry.internals.includes(e)), - format: 'esm', - outdir: dirname(entry.file).replace('src', 'dist'), - outExtension: { - '.js': '.js', - }, - }) - ) - ); - } + results.push( + esbuild.context( + merge(browserEsbuildOptions, { + alias: { + '@storybook/core': join(cwd, 'src'), + react: dirname(require.resolve('react/package.json')), + 'react-dom': dirname(require.resolve('react-dom/package.json')), + 'react-dom/client': join( + dirname(require.resolve('react-dom/package.json')), + 'client' + ), + }, + define: { + // This should set react in prod mode for the manager + 'process.env.NODE_ENV': JSON.stringify('production'), + }, + entryPoints: [entry.file], + external: [], + outdir: dirname(entry.file).replace('src', 'dist'), + outExtension: { + '.js': '.js', + }, + plugins: [globalExternals(globalsModuleInfoMap)], + }) + ) + ); return results; }), - ]); + ...entries + .filter((entry) => !noExternals(entry)) + .flatMap((entry) => { + const results = []; + if (entry.node) { + results.push( + esbuild.context( + merge(nodeEsbuildOptions, { + entryPoints: [entry.file], + external: [ + ...nodeInternals, + ...esbuildDefaultOptions.external, + ...entry.externals, + ].filter((e) => !entry.internals.includes(e)), + format: 'cjs', + outdir: dirname(entry.file).replace('src', 'dist'), + outExtension: { + '.js': '.cjs', + }, + }) + ) + ); + } + if (entry.browser) { + results.push( + esbuild.context( + merge(browserEsbuildOptions, { + entryPoints: [entry.file], + external: [ + ...nodeInternals, + ...esbuildDefaultOptions.external, + ...entry.externals, + ].filter((e) => !entry.internals.includes(e)), + outdir: dirname(entry.file).replace('src', 'dist'), + outExtension: { + '.js': '.js', + }, + }) + ) + ); + } else if (entry.node) { + results.push( + esbuild.context( + merge(nodeEsbuildOptions, { + entryPoints: [entry.file], + external: [ + ...nodeInternals, + ...esbuildDefaultOptions.external, + ...entry.externals, + ].filter((e) => !entry.internals.includes(e)), + format: 'esm', + outdir: dirname(entry.file).replace('src', 'dist'), + outExtension: { + '.js': '.js', + }, + }) + ) + ); + } - if (isWatch) { - await Promise.all( - compile.map(async (context) => { - await context.watch(); - }) - ); + return results; + }), + ]); - // show a log message when a file is compiled - watch(join(cwd, 'dist'), { recursive: true }, (event, filename) => { - console.log(`compiled ${chalk.cyan(filename)}`); - }); - } else { - await Promise.all( - compile.map(async (context) => { - const out = await context.rebuild(); - await context.dispose(); + if (isWatch) { + await Promise.all( + compile.map(async (context) => { + await context.watch(); + }) + ); + + // show a log message when a file is compiled + watch(join(cwd, 'dist'), { recursive: true }, (event, filename) => { + console.log(`compiled ${chalk.cyan(filename)}`); + }); + } else { + await Promise.all( + compile.map(async (context) => { + const out = await context.rebuild(); + await context.dispose(); - /** - * I'm leaving this in place, because I want to start utilizing it in the future. - * I'm imagining a github action that shows the bundle analysis in the PR. - * I didn't have the project-scope to make that happen now, but I want expose this very rich useful data accessible, for the next person investigating bundle size issues. - */ + /** + * I'm leaving this in place, because I want to start utilizing it in the future. + * I'm imagining a github action that shows the bundle analysis in the PR. + * I didn't have the project-scope to make that happen now, but I want expose this very rich useful data accessible, for the next person investigating bundle size issues. + */ - // if (out.metafile) { - // await Bun.write('report/meta.json', JSON.stringify(out.metafile, null, 2)); - // await Bun.write( - // 'report/meta.txt', - // await esbuild.analyzeMetafile(out.metafile, { color: false, verbose: false }) - // ); - // console.log(await esbuild.analyzeMetafile(out.metafile, { color: true })); - // } - }) - ); + // if (out.metafile) { + // await writeFile('report/meta.json', JSON.stringify(out.metafile, null, 2)); + // await writeFile( + // 'report/meta.txt', + // await esbuild.analyzeMetafile(out.metafile, { color: false, verbose: false }) + // ); + // console.log(await esbuild.analyzeMetafile(out.metafile, { color: true })); + // } + }) + ); + } } } + +run().catch((err) => { + console.error(err); + process.exit(1); +}); diff --git a/code/core/src/ERRORS.md b/code/core/src/ERRORS.md index 3638cb7e4780..bba4fbbc6a9b 100644 --- a/code/core/src/ERRORS.md +++ b/code/core/src/ERRORS.md @@ -26,6 +26,7 @@ Second use the `StorybookError` class to define custom errors with specific code ```typescript import { StorybookError } from './storybook-error'; + export class YourCustomError extends StorybookError { constructor() { super({ diff --git a/code/core/src/__mocks__/composeStories.txt b/code/core/src/__mocks__/composeStories.txt new file mode 100644 index 000000000000..9337671400bb --- /dev/null +++ b/code/core/src/__mocks__/composeStories.txt @@ -0,0 +1,2 @@ +// THIS IS A MOCK FILE, DO NOT TOUCH +const Primary = composeStory(stories.Primary, stories.default) \ No newline at end of file diff --git a/code/core/src/__mocks__/composeStory.txt b/code/core/src/__mocks__/composeStory.txt new file mode 100644 index 000000000000..8f400a3b0a52 --- /dev/null +++ b/code/core/src/__mocks__/composeStory.txt @@ -0,0 +1,2 @@ +// THIS IS A MOCK FILE, DO NOT TOUCH +const { Primary } = composeStories(stories) \ No newline at end of file diff --git a/code/core/src/__tests/preview-errors.test.ts b/code/core/src/__tests/preview-errors.test.ts index ae573d0f4eaf..6c780167947f 100644 --- a/code/core/src/__tests/preview-errors.test.ts +++ b/code/core/src/__tests/preview-errors.test.ts @@ -1,4 +1,5 @@ -import { describe, it, expect } from 'vitest'; +import { describe, expect, it } from 'vitest'; + import { UnknownArgTypesError } from '../preview-errors'; describe('UnknownFlowArgTypesError', () => { diff --git a/code/core/src/__tests/server-errors.test.ts b/code/core/src/__tests/server-errors.test.ts index e5a23d7054c5..e268a8b43e55 100644 --- a/code/core/src/__tests/server-errors.test.ts +++ b/code/core/src/__tests/server-errors.test.ts @@ -1,4 +1,5 @@ -import { describe, it, expect } from 'vitest'; +import { describe, expect, it } from 'vitest'; + import { WebpackCompilationError } from '../server-errors'; describe('WebpackCompilationError', () => { diff --git a/code/core/src/__tests/storybook-error.test.ts b/code/core/src/__tests/storybook-error.test.ts index dfbec1546375..770997b00fe9 100644 --- a/code/core/src/__tests/storybook-error.test.ts +++ b/code/core/src/__tests/storybook-error.test.ts @@ -1,4 +1,5 @@ -import { describe, it, expect } from 'vitest'; +import { describe, expect, it } from 'vitest'; + import { StorybookError } from '../storybook-error'; describe('StorybookError', () => { diff --git a/code/core/src/builder-manager/index.ts b/code/core/src/builder-manager/index.ts index 01755fbdef2c..e23d3bb89ac0 100644 --- a/code/core/src/builder-manager/index.ts +++ b/code/core/src/builder-manager/index.ts @@ -1,17 +1,16 @@ import { dirname, join, parse } from 'node:path'; -import fs from 'fs-extra'; -import express from 'express'; +import { stringifyProcessEnvs } from '@storybook/core/common'; + +import { globalsModuleInfoMap } from '@storybook/core/manager/globals-module-info'; import { logger } from '@storybook/core/node-logger'; import { globalExternals } from '@fal-works/esbuild-plugin-global-externals'; import { pnpPlugin } from '@yarnpkg/esbuild-plugin-pnp'; import aliasPlugin from 'esbuild-plugin-alias'; +import express from 'express'; +import fs from 'fs-extra'; -import { stringifyProcessEnvs } from '@storybook/core/common'; -import { globalsModuleInfoMap } from '@storybook/core/manager/globals-module-info'; -import { getTemplatePath, renderHTML } from './utils/template'; -import { wrapManagerEntries } from './utils/managerEntries'; import type { BuilderBuildResult, BuilderFunction, @@ -20,11 +19,12 @@ import type { ManagerBuilder, StarterFunction, } from './types'; - import { getData } from './utils/data'; -import { safeResolve } from './utils/safeResolve'; import { readOrderedFiles } from './utils/files'; import { buildFrameworkGlobalsFromOptions } from './utils/framework'; +import { wrapManagerEntries } from './utils/managerEntries'; +import { safeResolve } from './utils/safeResolve'; +import { getTemplatePath, renderHTML } from './utils/template'; let compilation: Compilation; let asyncIterator: ReturnType | ReturnType; diff --git a/code/core/src/builder-manager/types.ts b/code/core/src/builder-manager/types.ts index a56481f2c5e8..e7541dced4bc 100644 --- a/code/core/src/builder-manager/types.ts +++ b/code/core/src/builder-manager/types.ts @@ -1,8 +1,8 @@ import type { Builder, - Builder_WithRequiredProperty, BuilderStats, Builder_Unpromise, + Builder_WithRequiredProperty, } from '@storybook/core/types'; import type { BuildOptions, BuildResult } from 'esbuild'; diff --git a/code/core/src/builder-manager/utils/data.ts b/code/core/src/builder-manager/utils/data.ts index fc21a933c499..233d3186c38e 100644 --- a/code/core/src/builder-manager/utils/data.ts +++ b/code/core/src/builder-manager/utils/data.ts @@ -1,10 +1,10 @@ import { basename } from 'node:path'; -import type { Options } from '@storybook/core/types'; -import { getRefs } from '@storybook/core/common'; -import { readTemplate } from './template'; +import { getRefs } from '@storybook/core/common'; +import type { Options } from '@storybook/core/types'; import { executor, getConfig } from '../index'; +import { readTemplate } from './template'; export const getData = async (options: Options) => { const refs = getRefs(options); diff --git a/code/core/src/builder-manager/utils/files.test.ts b/code/core/src/builder-manager/utils/files.test.ts index ed902f1d391f..4d37bbd3af6c 100644 --- a/code/core/src/builder-manager/utils/files.test.ts +++ b/code/core/src/builder-manager/utils/files.test.ts @@ -1,6 +1,8 @@ -import { it, expect } from 'vitest'; +import { expect, it } from 'vitest'; + import type { OutputFile } from 'esbuild'; import { platform } from 'os'; + import { sanitizePath } from './files'; const os = platform(); diff --git a/code/core/src/builder-manager/utils/files.ts b/code/core/src/builder-manager/utils/files.ts index 15e7d1838e27..94ec31677c4a 100644 --- a/code/core/src/builder-manager/utils/files.ts +++ b/code/core/src/builder-manager/utils/files.ts @@ -1,7 +1,9 @@ +import { join, normalize } from 'node:path'; + import type { OutputFile } from 'esbuild'; import fs from 'fs-extra'; -import { join, normalize } from 'node:path'; import slash from 'slash'; + import type { Compilation } from '../types'; export async function readOrderedFiles( diff --git a/code/core/src/builder-manager/utils/framework.test.ts b/code/core/src/builder-manager/utils/framework.test.ts index ecdcb42ead50..cea3453294e2 100644 --- a/code/core/src/builder-manager/utils/framework.test.ts +++ b/code/core/src/builder-manager/utils/framework.test.ts @@ -1,5 +1,6 @@ -import path from 'node:path'; -import { describe, it, expect } from 'vitest'; +import { join } from 'node:path'; + +import { describe, expect, it } from 'vitest'; import { pluckNameFromConfigProperty, @@ -24,24 +25,24 @@ describe('UTILITIES: Framework information', () => { describe('UTILITY: pluckStorybookPackageFromPath', () => { it('should return the package name if the path is a storybook package', () => { - const packagePath = path.join(process.cwd(), 'node_modules', '@storybook', 'foo'); + const packagePath = join(process.cwd(), 'node_modules', '@storybook', 'foo'); expect(pluckStorybookPackageFromPath(packagePath)).toBe('@storybook/foo'); }); it('should return undefined if the path is not a storybook package', () => { - const packagePath = path.join(process.cwd(), 'foo'); + const packagePath = join(process.cwd(), 'foo'); expect(pluckStorybookPackageFromPath(packagePath)).toBe(undefined); }); }); describe('UTILITY: pluckThirdPartyPackageFromPath', () => { it('should return the package name if the path is a third party package', () => { - const packagePath = path.join(process.cwd(), 'node_modules', 'bar'); + const packagePath = join(process.cwd(), 'node_modules', 'bar'); expect(pluckThirdPartyPackageFromPath(packagePath)).toBe('bar'); }); it('should return the given path if the path is not a third party package', () => { - const packagePath = path.join(process.cwd(), 'foo', 'bar', 'baz'); + const packagePath = join(process.cwd(), 'foo', 'bar', 'baz'); expect(pluckThirdPartyPackageFromPath(packagePath)).toBe(packagePath); }); }); diff --git a/code/core/src/builder-manager/utils/framework.ts b/code/core/src/builder-manager/utils/framework.ts index a40c72ae9042..d399494c049c 100644 --- a/code/core/src/builder-manager/utils/framework.ts +++ b/code/core/src/builder-manager/utils/framework.ts @@ -1,6 +1,7 @@ -import path from 'node:path'; -import type { Options } from '@storybook/core/types'; +import { sep } from 'node:path'; + import { extractProperRendererNameFromFramework, getFrameworkName } from '@storybook/core/common'; +import type { Options } from '@storybook/core/types'; interface PropertyObject { name: string; @@ -18,7 +19,7 @@ export const pluckNameFromConfigProperty = (property: Property) => { }; // For replacing Windows backslashes with forward slashes -const normalizePath = (packagePath: string) => packagePath.replaceAll(path.sep, '/'); +const normalizePath = (packagePath: string) => packagePath.replaceAll(sep, '/'); export const pluckStorybookPackageFromPath = (packagePath: string) => normalizePath(packagePath).match(/(@storybook\/.*)$/)?.[1]; diff --git a/code/core/src/builder-manager/utils/managerEntries.ts b/code/core/src/builder-manager/utils/managerEntries.ts index 8d60a077759d..a30fbab4a4bd 100644 --- a/code/core/src/builder-manager/utils/managerEntries.ts +++ b/code/core/src/builder-manager/utils/managerEntries.ts @@ -1,6 +1,8 @@ -import fs from 'fs-extra'; -import { resolvePathInStorybookCache } from '@storybook/core/common'; import { join, parse, relative, sep } from 'node:path'; + +import { resolvePathInStorybookCache } from '@storybook/core/common'; + +import fs from 'fs-extra'; import slash from 'slash'; const sanitizeBase = (path: string) => { diff --git a/code/core/src/builder-manager/utils/template.ts b/code/core/src/builder-manager/utils/template.ts index 222bb80a0a64..b264a3d5e02e 100644 --- a/code/core/src/builder-manager/utils/template.ts +++ b/code/core/src/builder-manager/utils/template.ts @@ -1,9 +1,9 @@ import { dirname, join } from 'node:path'; -import fs from 'fs-extra'; -import { render } from 'ejs'; +import type { DocsOptions, Options, Ref, TagsOptions } from '@storybook/core/types'; -import type { DocsOptions, TagsOptions, Options, Ref } from '@storybook/core/types'; +import { render } from 'ejs'; +import fs from 'fs-extra'; export const getTemplatePath = async (template: string) => { return join(dirname(require.resolve('@storybook/core/package.json')), 'assets/server', template); diff --git a/code/core/src/channels/index.test.ts b/code/core/src/channels/index.test.ts index f99e04f6099c..44a9aba61090 100644 --- a/code/core/src/channels/index.test.ts +++ b/code/core/src/channels/index.test.ts @@ -1,4 +1,5 @@ -import { describe, beforeEach, it, expect, vi } from 'vitest'; +import { beforeEach, describe, expect, it, vi } from 'vitest'; + import type { ChannelTransport, Listener } from '.'; import { Channel, WebsocketTransport } from '.'; diff --git a/code/core/src/channels/index.ts b/code/core/src/channels/index.ts index 1823011d8b8f..ab2d311b097f 100644 --- a/code/core/src/channels/index.ts +++ b/code/core/src/channels/index.ts @@ -1,6 +1,6 @@ /// - import { global } from '@storybook/global'; + import { Channel } from './main'; import { PostMessageTransport } from './postmessage'; import type { ChannelTransport, Config } from './types'; diff --git a/code/core/src/channels/main.ts b/code/core/src/channels/main.ts index 795e9eaa2f60..62bebb4dd54b 100644 --- a/code/core/src/channels/main.ts +++ b/code/core/src/channels/main.ts @@ -1,11 +1,11 @@ import type { ChannelArgs, ChannelArgsMulti, - EventsKeyValue, - ChannelTransport, ChannelArgsSingle, - Listener, ChannelEvent, + ChannelTransport, + EventsKeyValue, + Listener, } from './types'; const isMulti = (args: ChannelArgs): args is ChannelArgsMulti => { diff --git a/code/core/src/channels/postmessage/index.ts b/code/core/src/channels/postmessage/index.ts index 7d2bb67baf7b..a60ba16a47b4 100644 --- a/code/core/src/channels/postmessage/index.ts +++ b/code/core/src/channels/postmessage/index.ts @@ -1,16 +1,18 @@ /// - import { global } from '@storybook/global'; -import * as EVENTS from '@storybook/core/core-events'; + import { logger, pretty } from '@storybook/core/client-logger'; +import * as EVENTS from '@storybook/core/core-events'; + import { isJSON, parse, stringify } from 'telejson'; import invariant from 'tiny-invariant'; + import type { - ChannelTransport, BufferedEvent, + ChannelEvent, ChannelHandler, + ChannelTransport, Config, - ChannelEvent, } from '../types'; import { getEventSourceUrl } from './getEventSourceUrl'; diff --git a/code/core/src/channels/websocket/index.ts b/code/core/src/channels/websocket/index.ts index 989b53862683..15033296512b 100644 --- a/code/core/src/channels/websocket/index.ts +++ b/code/core/src/channels/websocket/index.ts @@ -1,11 +1,12 @@ /// - import { global } from '@storybook/global'; + +import * as EVENTS from '@storybook/core/core-events'; + import { isJSON, parse, stringify } from 'telejson'; import invariant from 'tiny-invariant'; -import * as EVENTS from '@storybook/core/core-events'; -import type { ChannelTransport, ChannelHandler, Config } from '../types'; +import type { ChannelHandler, ChannelTransport, Config } from '../types'; const { WebSocket } = global; diff --git a/code/core/src/cli/angular/helpers.ts b/code/core/src/cli/angular/helpers.ts index 9d651fa60cae..78ef8836996f 100644 --- a/code/core/src/cli/angular/helpers.ts +++ b/code/core/src/cli/angular/helpers.ts @@ -1,10 +1,12 @@ -import fs from 'fs'; -import { join } from 'path'; -import prompts from 'prompts'; -import { dedent } from 'ts-dedent'; +import { existsSync, readFileSync, writeFileSync } from 'node:fs'; +import { join } from 'node:path'; + +import { logger } from '@storybook/core/node-logger'; import { MissingAngularJsonError } from '@storybook/core/server-errors'; + import boxen from 'boxen'; -import { logger } from '@storybook/core/node-logger'; +import prompts from 'prompts'; +import { dedent } from 'ts-dedent'; export const ANGULAR_JSON_PATH = 'angular.json'; @@ -42,11 +44,11 @@ export class AngularJSON { }; constructor() { - if (!fs.existsSync(ANGULAR_JSON_PATH)) { + if (!existsSync(ANGULAR_JSON_PATH)) { throw new MissingAngularJsonError({ path: join(process.cwd(), ANGULAR_JSON_PATH) }); } - const jsonContent = fs.readFileSync(ANGULAR_JSON_PATH, 'utf8'); + const jsonContent = readFileSync(ANGULAR_JSON_PATH, 'utf8'); this.json = JSON.parse(jsonContent); } @@ -148,6 +150,6 @@ export class AngularJSON { } write() { - fs.writeFileSync(ANGULAR_JSON_PATH, JSON.stringify(this.json, null, 2)); + writeFileSync(ANGULAR_JSON_PATH, JSON.stringify(this.json, null, 2)); } } diff --git a/code/core/src/cli/bin/index.ts b/code/core/src/cli/bin/index.ts index 512dc963924b..38cbce23efb1 100644 --- a/code/core/src/cli/bin/index.ts +++ b/code/core/src/cli/bin/index.ts @@ -1,15 +1,16 @@ -import program from 'commander'; +import { getEnvConfig, parseList, versions } from '@storybook/core/common'; +import { addToGlobalContext } from '@storybook/core/telemetry'; + +import { logger } from '@storybook/core/node-logger'; + import chalk from 'chalk'; -import leven from 'leven'; +import program from 'commander'; import { findPackageSync } from 'fd-package-json'; +import leven from 'leven'; import invariant from 'tiny-invariant'; -import { logger } from '@storybook/core/node-logger'; -import { addToGlobalContext } from '@storybook/core/telemetry'; -import { parseList, getEnvConfig, versions } from '@storybook/core/common'; - -import { dev } from '../dev'; import { build } from '../build'; +import { dev } from '../dev'; addToGlobalContext('cliVersion', versions.storybook); diff --git a/code/core/src/cli/build.ts b/code/core/src/cli/build.ts index a596eb6278d1..2a8594cf76ed 100644 --- a/code/core/src/cli/build.ts +++ b/code/core/src/cli/build.ts @@ -1,6 +1,8 @@ -import { findPackage } from 'fd-package-json'; -import { buildStaticStandalone, withTelemetry } from '@storybook/core/core-server'; import { cache } from '@storybook/core/common'; + +import { buildStaticStandalone, withTelemetry } from '@storybook/core/core-server'; + +import { findPackage } from 'fd-package-json'; import invariant from 'tiny-invariant'; export const build = async (cliOptions: any) => { diff --git a/code/core/src/cli/detect.test.ts b/code/core/src/cli/detect.test.ts index cf21f8bc423c..f12ece4314fa 100644 --- a/code/core/src/cli/detect.test.ts +++ b/code/core/src/cli/detect.test.ts @@ -1,9 +1,13 @@ -import { describe, afterEach, it, expect, vi } from 'vitest'; -import * as fs from 'fs'; +import { existsSync } from 'node:fs'; + +import { afterEach, describe, expect, it, vi } from 'vitest'; + +import type { JsPackageManager, PackageJsonWithMaybeDeps } from '@storybook/core/common'; + import { logger } from '@storybook/core/node-logger'; + import { detect, detectFrameworkPreset, detectLanguage } from './detect'; import { ProjectType, SupportedLanguage } from './project_types'; -import type { JsPackageManager, PackageJsonWithMaybeDeps } from '@storybook/core/common'; vi.mock('./helpers', () => ({ isNxProject: vi.fn(), @@ -417,7 +421,7 @@ describe('Detect', () => { MOCK_FRAMEWORK_FILES.forEach((structure) => { it(`${structure.name}`, () => { - vi.mocked(fs.existsSync).mockImplementation((filePath) => { + vi.mocked(existsSync).mockImplementation((filePath) => { return typeof filePath === 'string' && Object.keys(structure.files).includes(filePath); }); @@ -450,7 +454,7 @@ describe('Detect', () => { '/node_modules/.bin/react-scripts': 'file content', }; - vi.mocked(fs.existsSync).mockImplementation((filePath) => { + vi.mocked(existsSync).mockImplementation((filePath) => { return ( typeof filePath === 'string' && Object.keys(forkedReactScriptsConfig).includes(filePath) ); diff --git a/code/core/src/cli/detect.ts b/code/core/src/cli/detect.ts index 83b90237aa9b..96ab4c785cee 100644 --- a/code/core/src/cli/detect.ts +++ b/code/core/src/cli/detect.ts @@ -1,21 +1,24 @@ -import * as fs from 'fs'; -import { findUpSync } from 'find-up'; -import semver from 'semver'; +import { existsSync } from 'node:fs'; +import { resolve } from 'node:path'; + +import type { JsPackageManager, PackageJsonWithMaybeDeps } from '@storybook/core/common'; +import { HandledError, commandLog } from '@storybook/core/common'; + import { logger } from '@storybook/core/node-logger'; -import { resolve } from 'node:path'; +import { findUpSync } from 'find-up'; import prompts from 'prompts'; +import semver from 'semver'; + +import { isNxProject } from './helpers'; import type { TemplateConfiguration, TemplateMatcher } from './project_types'; import { + CoreBuilder, ProjectType, - supportedTemplates, SupportedLanguage, + supportedTemplates, unsupportedTemplate, - CoreBuilder, } from './project_types'; -import { isNxProject } from './helpers'; -import type { JsPackageManager, PackageJsonWithMaybeDeps } from '@storybook/core/common'; -import { commandLog, HandledError } from '@storybook/core/common'; const viteConfigFiles = ['vite.config.ts', 'vite.config.js', 'vite.config.mjs']; const webpackConfigFiles = ['webpack.config.js']; @@ -87,7 +90,7 @@ const getFrameworkPreset = ( } if (Array.isArray(files) && files.length > 0) { - matcher.files = files.map((name) => fs.existsSync(name)); + matcher.files = files.map((name) => existsSync(name)); } return matcherFunction(matcher) ? preset : null; @@ -157,7 +160,7 @@ export async function detectBuilder(packageManager: JsPackageManager, projectTyp } export function isStorybookInstantiated(configDir = resolve(process.cwd(), '.storybook')) { - return fs.existsSync(configDir); + return existsSync(configDir); } export async function detectPnp() { @@ -167,7 +170,7 @@ export async function detectPnp() { export async function detectLanguage(packageManager: JsPackageManager) { let language = SupportedLanguage.JAVASCRIPT; - if (fs.existsSync('jsconfig.json')) { + if (existsSync('jsconfig.json')) { return language; } diff --git a/code/core/src/cli/dev.ts b/code/core/src/cli/dev.ts index f8c7ecbcd112..6d05f140fa38 100644 --- a/code/core/src/cli/dev.ts +++ b/code/core/src/cli/dev.ts @@ -1,10 +1,12 @@ -import { dedent } from 'ts-dedent'; -import { findPackage } from 'fd-package-json'; -import { logger, instance as npmLog } from '@storybook/core/node-logger'; -import { buildDevStandalone, withTelemetry } from '@storybook/core/core-server'; import { cache } from '@storybook/core/common'; import type { CLIOptions } from '@storybook/core/types'; + +import { buildDevStandalone, withTelemetry } from '@storybook/core/core-server'; +import { logger, instance as npmLog } from '@storybook/core/node-logger'; + +import { findPackage } from 'fd-package-json'; import invariant from 'tiny-invariant'; +import { dedent } from 'ts-dedent'; function printError(error: any) { // this is a weird bugfix, somehow 'node-pre-gyp' is polluting the npmLog header diff --git a/code/core/src/cli/dirs.ts b/code/core/src/cli/dirs.ts index 88515e6b6683..11ca9cb67441 100644 --- a/code/core/src/cli/dirs.ts +++ b/code/core/src/cli/dirs.ts @@ -1,14 +1,15 @@ -import { dirname, join } from 'path'; +import { dirname, join } from 'node:path'; -import downloadTarball from '@ndelangen/get-tarball'; -import getNpmTarballUrl from 'get-npm-tarball-url'; +import type { JsPackageManager } from '@storybook/core/common'; +import { temporaryDirectory, versions } from '@storybook/core/common'; +import type { SupportedFrameworks } from '@storybook/core/types'; +import downloadTarballDefault from '@ndelangen/get-tarball'; +import getNpmTarballUrlDefault from 'get-npm-tarball-url'; import invariant from 'tiny-invariant'; + import { externalFrameworks } from './project_types'; import type { SupportedRenderers } from './project_types'; -import type { JsPackageManager } from '@storybook/core/common'; -import { temporaryDirectory, versions } from '@storybook/core/common'; -import type { SupportedFrameworks } from '@storybook/core/types'; const resolveUsingBranchInstall = async (packageManager: JsPackageManager, request: string) => { const tempDirectory = await temporaryDirectory(); @@ -17,6 +18,12 @@ const resolveUsingBranchInstall = async (packageManager: JsPackageManager, reque // FIXME: this might not be the right version for community packages const version = versions[name] || (await packageManager.latestVersion(request)); + // an artifact of esbuild + type=commonjs + exportmap + // @ts-expect-error (default export) + const getNpmTarballUrl = getNpmTarballUrlDefault.default || getNpmTarballUrlDefault; + // @ts-expect-error (default export) + const downloadTarball = downloadTarballDefault.default || downloadTarballDefault; + const url = getNpmTarballUrl(request, version, { registry: await packageManager.getRegistryURL(), }); diff --git a/code/core/src/cli/eslintPlugin.test.ts b/code/core/src/cli/eslintPlugin.test.ts index cb428df7d27b..4752f8734ebf 100644 --- a/code/core/src/cli/eslintPlugin.test.ts +++ b/code/core/src/cli/eslintPlugin.test.ts @@ -1,4 +1,5 @@ -import { describe, it, expect } from 'vitest'; +import { describe, expect, it } from 'vitest'; + import { normalizeExtends } from './eslintPlugin'; describe('normalizeExtends', () => { diff --git a/code/core/src/cli/eslintPlugin.ts b/code/core/src/cli/eslintPlugin.ts index 75fcaa96bb4c..53371725f84a 100644 --- a/code/core/src/cli/eslintPlugin.ts +++ b/code/core/src/cli/eslintPlugin.ts @@ -1,13 +1,15 @@ -import fse, { readFile, readJson, writeJson } from 'fs-extra'; -import { dedent } from 'ts-dedent'; -import detectIndent from 'detect-indent'; -import prompts from 'prompts'; -import chalk from 'chalk'; +import { existsSync } from 'node:fs'; -import { readConfig, writeConfig } from '@storybook/core/csf-tools'; import type { JsPackageManager } from '@storybook/core/common'; import { paddedLog } from '@storybook/core/common'; -import fs from 'node:fs'; + +import { readConfig, writeConfig } from '@storybook/core/csf-tools'; + +import chalk from 'chalk'; +import detectIndent from 'detect-indent'; +import { readFile, readJson, writeJson } from 'fs-extra'; +import prompts from 'prompts'; +import { dedent } from 'ts-dedent'; export const SUPPORTED_ESLINT_EXTENSIONS = ['js', 'cjs', 'json']; const UNSUPPORTED_ESLINT_EXTENSIONS = ['yaml', 'yml']; @@ -15,7 +17,7 @@ const UNSUPPORTED_ESLINT_EXTENSIONS = ['yaml', 'yml']; export const findEslintFile = () => { const filePrefix = '.eslintrc'; const unsupportedExtension = UNSUPPORTED_ESLINT_EXTENSIONS.find((ext: string) => - fs.existsSync(`${filePrefix}.${ext}`) + existsSync(`${filePrefix}.${ext}`) ); if (unsupportedExtension) { @@ -23,7 +25,7 @@ export const findEslintFile = () => { } const extension = SUPPORTED_ESLINT_EXTENSIONS.find((ext: string) => - fs.existsSync(`${filePrefix}.${ext}`) + existsSync(`${filePrefix}.${ext}`) ); return extension ? `${filePrefix}.${extension}` : null; }; diff --git a/code/core/src/cli/helpers.test.ts b/code/core/src/cli/helpers.test.ts index 9464c8551a9f..cff797a8f505 100644 --- a/code/core/src/cli/helpers.test.ts +++ b/code/core/src/cli/helpers.test.ts @@ -1,10 +1,12 @@ -import { describe, beforeEach, it, expect, vi } from 'vitest'; -import fse from 'fs-extra'; +import { beforeEach, describe, expect, it, vi } from 'vitest'; + +import type { JsPackageManager } from '@storybook/core/common'; +import fse from 'fs-extra'; import { sep } from 'path'; -import * as helpers from './helpers'; + import { IS_WINDOWS } from '../../../vitest.helpers'; -import type { JsPackageManager } from '@storybook/core/common'; +import * as helpers from './helpers'; import type { SupportedRenderers } from './project_types'; import { SupportedLanguage } from './project_types'; @@ -76,7 +78,7 @@ describe('Helpers', () => { describe('copyTemplate', () => { it(`should copy template files when directory is present`, () => { - const csfDirectory = /template-csf$/; + const csfDirectory = /template-csf\/$/; fsMocks.existsSync.mockReturnValue(true); helpers.copyTemplate(''); diff --git a/code/core/src/cli/helpers.ts b/code/core/src/cli/helpers.ts index e0af5f76af9f..5970a1276237 100644 --- a/code/core/src/cli/helpers.ts +++ b/code/core/src/cli/helpers.ts @@ -1,32 +1,34 @@ -import chalk from 'chalk'; -import fs from 'fs'; -import fse from 'fs-extra'; -import path, { join } from 'path'; -import { coerce, satisfies } from 'semver'; -import stripJsonComments from 'strip-json-comments'; +import { existsSync, readFileSync, writeFileSync } from 'node:fs'; +import { join, resolve } from 'node:path'; -import { findUpSync } from 'find-up'; -import invariant from 'tiny-invariant'; -import { getRendererDir } from './dirs'; import { + frameworkToRenderer as CoreFrameworkToRenderer, type JsPackageManager, type PackageJson, type PackageJsonWithDepsAndDevDeps, - frameworkToRenderer as CoreFrameworkToRenderer, } from '@storybook/core/common'; +import { versions as storybookMonorepoPackages } from '@storybook/core/common'; import type { SupportedFrameworks, SupportedRenderers } from '@storybook/core/types'; + +import chalk from 'chalk'; +import { findUpSync } from 'find-up'; +import { copy, copySync, pathExists, readFile, writeFile } from 'fs-extra'; +import { coerce, satisfies } from 'semver'; +import stripJsonComments from 'strip-json-comments'; +import invariant from 'tiny-invariant'; + +import { getRendererDir } from './dirs'; import { CoreBuilder, SupportedLanguage } from './project_types'; -import { versions as storybookMonorepoPackages } from '@storybook/core/common'; const logger = console; export function readFileAsJson(jsonPath: string, allowComments?: boolean) { - const filePath = path.resolve(jsonPath); - if (!fs.existsSync(filePath)) { + const filePath = resolve(jsonPath); + if (!existsSync(filePath)) { return false; } - const fileContent = fs.readFileSync(filePath, 'utf8'); + const fileContent = readFileSync(filePath, 'utf8'); const jsonContent = allowComments ? stripJsonComments(fileContent) : fileContent; try { @@ -38,12 +40,12 @@ export function readFileAsJson(jsonPath: string, allowComments?: boolean) { } export const writeFileAsJson = (jsonPath: string, content: unknown) => { - const filePath = path.resolve(jsonPath); - if (!fs.existsSync(filePath)) { + const filePath = resolve(jsonPath); + if (!existsSync(filePath)) { return false; } - fs.writeFileSync(filePath, `${JSON.stringify(content, null, 2)}\n`); + writeFileSync(filePath, `${JSON.stringify(content, null, 2)}\n`); return true; }; @@ -114,13 +116,13 @@ export function addToDevDependenciesIfNotPresent( } export function copyTemplate(templateRoot: string, destination = '.') { - const templateDir = path.resolve(templateRoot, `template-csf/`); + const templateDir = resolve(templateRoot, `template-csf/`); - if (!fs.existsSync(templateDir)) { + if (!existsSync(templateDir)) { throw new Error(`Couldn't find template dir`); } - fse.copySync(templateDir, destination, { overwrite: true }); + copySync(templateDir, destination, { overwrite: true }); } type CopyTemplateFilesOptions = { @@ -142,6 +144,7 @@ export const frameworkToDefaultBuilder: Record 'html-vite': CoreBuilder.Vite, 'html-webpack5': CoreBuilder.Webpack5, nextjs: CoreBuilder.Webpack5, + 'experimental-nextjs-vite': CoreBuilder.Vite, 'preact-vite': CoreBuilder.Vite, 'preact-webpack5': CoreBuilder.Webpack5, qwik: CoreBuilder.Vite, @@ -182,30 +185,30 @@ export async function copyTemplateFiles({ const assetsTS38 = join(assetsDir, languageFolderMapping[SupportedLanguage.TYPESCRIPT_3_8]); // Ideally use the assets that match the language & version. - if (await fse.pathExists(assetsLanguage)) { + if (await pathExists(assetsLanguage)) { return assetsLanguage; } // Use fallback typescript 3.8 assets if new ones aren't available - if (language === SupportedLanguage.TYPESCRIPT_4_9 && (await fse.pathExists(assetsTS38))) { + if (language === SupportedLanguage.TYPESCRIPT_4_9 && (await pathExists(assetsTS38))) { return assetsTS38; } // Fallback further to TS (for backwards compatibility purposes) - if (await fse.pathExists(assetsTS)) { + if (await pathExists(assetsTS)) { return assetsTS; } // Fallback further to JS - if (await fse.pathExists(assetsJS)) { + if (await pathExists(assetsJS)) { return assetsJS; } // As a last resort, look for the root of the asset directory - if (await fse.pathExists(assetsDir)) { + if (await pathExists(assetsDir)) { return assetsDir; } throw new Error(`Unsupported renderer: ${renderer} (${baseDir})`); }; const targetPath = async () => { - if (await fse.pathExists('./src')) { + if (await pathExists('./src')) { return './src/stories'; } return './stories'; @@ -213,11 +216,11 @@ export async function copyTemplateFiles({ const destinationPath = destination ?? (await targetPath()); if (commonAssetsDir) { - await fse.copy(commonAssetsDir, destinationPath, { + await copy(commonAssetsDir, destinationPath, { overwrite: true, }); } - await fse.copy(await templatePath(), destinationPath, { overwrite: true }); + await copy(await templatePath(), destinationPath, { overwrite: true }); if (commonAssetsDir) { let rendererType = frameworkToRenderer[renderer] || 'react'; @@ -230,13 +233,13 @@ export async function copyTemplateFiles({ export async function adjustTemplate(templatePath: string, templateData: Record) { // for now, we're just doing a simple string replace // in the future we might replace this with a proper templating engine - let template = await fse.readFile(templatePath, 'utf8'); + let template = await readFile(templatePath, 'utf8'); Object.keys(templateData).forEach((key) => { template = template.replaceAll(`{{${key}}}`, `${templateData[key]}`); }); - await fse.writeFile(templatePath, template); + await writeFile(templatePath, template); } // Given a package.json, finds any official storybook package within it diff --git a/code/core/src/cli/project_types.test.ts b/code/core/src/cli/project_types.test.ts index 95bca595dfc7..c5b6e4adc82f 100644 --- a/code/core/src/cli/project_types.test.ts +++ b/code/core/src/cli/project_types.test.ts @@ -1,5 +1,6 @@ -import { describe, it, expect } from 'vitest'; -import { installableProjectTypes, SUPPORTED_RENDERERS } from './project_types'; +import { describe, expect, it } from 'vitest'; + +import { SUPPORTED_RENDERERS, installableProjectTypes } from './project_types'; describe('installableProjectTypes should have an entry for the supported framework', () => { SUPPORTED_RENDERERS.forEach((framework) => { diff --git a/code/core/src/cli/project_types.ts b/code/core/src/cli/project_types.ts index b0f6c889c7c5..1efeba6cc52f 100644 --- a/code/core/src/cli/project_types.ts +++ b/code/core/src/cli/project_types.ts @@ -1,9 +1,10 @@ -import { minVersion, validRange } from 'semver'; import type { - SupportedFrameworks, SupportedRenderers as CoreSupportedFrameworks, + SupportedFrameworks, } from '@storybook/core/types'; +import { minVersion, validRange } from 'semver'; + function eqMajor(versionRange: string, major: number) { // Uses validRange to avoid a throw from minVersion if an invalid range gets passed if (validRange(versionRange)) { diff --git a/code/core/src/client-logger/index.test.ts b/code/core/src/client-logger/index.test.ts index 8574cef5066d..c46f70f2fd00 100644 --- a/code/core/src/client-logger/index.test.ts +++ b/code/core/src/client-logger/index.test.ts @@ -1,4 +1,5 @@ -import { describe, beforeEach, afterAll, it, expect, vi } from 'vitest'; +import { afterAll, beforeEach, describe, expect, it, vi } from 'vitest'; + import { logger } from '.'; vi.mock('@storybook/global', () => ({ global: { ...global, LOGLEVEL: 'debug' } })); diff --git a/code/core/src/common/config.test.ts b/code/core/src/common/config.test.ts index 3e75aeb0396f..de70dd7fe9a4 100644 --- a/code/core/src/common/config.test.ts +++ b/code/core/src/common/config.test.ts @@ -1,4 +1,5 @@ -import { describe, it, expect } from 'vitest'; +import { describe, expect, it } from 'vitest'; + import { filterPresetsConfig } from './presets'; describe('filterPresetsConfig', () => { diff --git a/code/core/src/common/index.ts b/code/core/src/common/index.ts index d16c9118ae8b..107ce9b6d98f 100644 --- a/code/core/src/common/index.ts +++ b/code/core/src/common/index.ts @@ -1,3 +1,5 @@ +import versions from './versions'; + /// export * from './presets'; @@ -40,7 +42,6 @@ export * from './utils/strip-abs-node-modules-path'; export * from './utils/formatter'; export * from './js-package-manager'; -import versions from './versions'; export { versions }; export { createFileSystemCache } from './utils/file-cache'; diff --git a/code/core/src/common/js-package-manager/JsPackageManager.ts b/code/core/src/common/js-package-manager/JsPackageManager.ts index 5a18b572f248..d126db20aa8a 100644 --- a/code/core/src/common/js-package-manager/JsPackageManager.ts +++ b/code/core/src/common/js-package-manager/JsPackageManager.ts @@ -1,17 +1,18 @@ +import { existsSync, readFileSync } from 'node:fs'; +import { readFile, writeFile } from 'node:fs/promises'; +import { dirname, resolve } from 'node:path'; + import chalk from 'chalk'; -import { gt, satisfies } from 'semver'; import type { CommonOptions } from 'execa'; import { execaCommand, execaCommandSync } from 'execa'; -import path from 'node:path'; - -import { dedent } from 'ts-dedent'; -import { existsSync, readFileSync } from 'node:fs'; -import { readFile, writeFile } from 'node:fs/promises'; +import { gt, satisfies } from 'semver'; import invariant from 'tiny-invariant'; -import type { PackageJson, PackageJsonWithDepsAndDevDeps } from './PackageJson'; +import { dedent } from 'ts-dedent'; + +import { HandledError } from '../utils/HandledError'; import storybookPackagesVersions from '../versions'; +import type { PackageJson, PackageJsonWithDepsAndDevDeps } from './PackageJson'; import type { InstallationMetadata } from './types'; -import { HandledError } from '../utils/HandledError'; const logger = console; @@ -98,7 +99,7 @@ export abstract class JsPackageManager { } // Move up to the parent directory - const parentDir = path.dirname(cwd); + const parentDir = dirname(cwd); // Check if we have reached the root of the filesystem if (parentDir === cwd) { @@ -131,7 +132,7 @@ export abstract class JsPackageManager { if (!this.cwd) { throw new Error('Missing cwd'); } - return path.resolve(this.cwd, 'package.json'); + return resolve(this.cwd, 'package.json'); } async readPackageJson(): Promise { diff --git a/code/core/src/common/js-package-manager/JsPackageManagerFactory.test.ts b/code/core/src/common/js-package-manager/JsPackageManagerFactory.test.ts index 0a5e6e626731..9f703d7c5ba3 100644 --- a/code/core/src/common/js-package-manager/JsPackageManagerFactory.test.ts +++ b/code/core/src/common/js-package-manager/JsPackageManagerFactory.test.ts @@ -1,7 +1,10 @@ -import { describe, beforeEach, it, expect, vi } from 'vitest'; +import { join } from 'node:path'; + +import { beforeEach, describe, expect, it, vi } from 'vitest'; + import { sync as spawnSync } from 'cross-spawn'; import { findUpSync } from 'find-up'; -import path from 'node:path'; + import { JsPackageManagerFactory } from './JsPackageManagerFactory'; import { NPMProxy } from './NPMProxy'; import { PNPMProxy } from './PNPMProxy'; @@ -150,7 +153,7 @@ describe('CLASS: JsPackageManagerFactory', () => { status: 1, } as any; }); - const fixture = path.join(__dirname, 'fixtures', 'pnpm-workspace', 'package'); + const fixture = join(__dirname, 'fixtures', 'pnpm-workspace', 'package'); expect(JsPackageManagerFactory.getPackageManager({}, fixture)).toBeInstanceOf(PNPMProxy); }); }); @@ -268,7 +271,7 @@ describe('CLASS: JsPackageManagerFactory', () => { status: 1, } as any; }); - const fixture = path.join(__dirname, 'fixtures', 'multiple-lockfiles'); + const fixture = join(__dirname, 'fixtures', 'multiple-lockfiles'); expect(JsPackageManagerFactory.getPackageManager({}, fixture)).toBeInstanceOf(Yarn1Proxy); }); }); diff --git a/code/core/src/common/js-package-manager/JsPackageManagerFactory.ts b/code/core/src/common/js-package-manager/JsPackageManagerFactory.ts index badd60ea6cf7..0b09f57bac52 100644 --- a/code/core/src/common/js-package-manager/JsPackageManagerFactory.ts +++ b/code/core/src/common/js-package-manager/JsPackageManagerFactory.ts @@ -1,14 +1,13 @@ -import path, { parse, relative } from 'node:path'; +import { basename, parse, relative } from 'node:path'; + import { sync as spawnSync } from 'cross-spawn'; import { findUpSync } from 'find-up'; +import type { JsPackageManager, PackageManagerName } from './JsPackageManager'; import { NPMProxy } from './NPMProxy'; import { PNPMProxy } from './PNPMProxy'; - -import type { JsPackageManager, PackageManagerName } from './JsPackageManager'; - -import { Yarn2Proxy } from './Yarn2Proxy'; import { Yarn1Proxy } from './Yarn1Proxy'; +import { Yarn2Proxy } from './Yarn2Proxy'; const NPM_LOCKFILE = 'package-lock.json'; const PNPM_LOCKFILE = 'pnpm-lock.yaml'; @@ -56,7 +55,7 @@ export class JsPackageManagerFactory { // Option 2: We try to infer the package manager from the closest lockfile const closestLockfilePath = lockFiles[0]; - const closestLockfile = closestLockfilePath && path.basename(closestLockfilePath); + const closestLockfile = closestLockfilePath && basename(closestLockfilePath); const hasNPMCommand = hasNPM(cwd); const hasPNPMCommand = hasPNPM(cwd); diff --git a/code/core/src/common/js-package-manager/NPMProxy.test.ts b/code/core/src/common/js-package-manager/NPMProxy.test.ts index 9c88ea60af45..4a783017d917 100644 --- a/code/core/src/common/js-package-manager/NPMProxy.test.ts +++ b/code/core/src/common/js-package-manager/NPMProxy.test.ts @@ -1,4 +1,5 @@ -import { describe, beforeEach, it, expect, vi } from 'vitest'; +import { beforeEach, describe, expect, it, vi } from 'vitest'; + import { NPMProxy } from './NPMProxy'; // mock createLogStream diff --git a/code/core/src/common/js-package-manager/NPMProxy.ts b/code/core/src/common/js-package-manager/NPMProxy.ts index 3cdadeb17ff3..69a89a741d53 100644 --- a/code/core/src/common/js-package-manager/NPMProxy.ts +++ b/code/core/src/common/js-package-manager/NPMProxy.ts @@ -1,16 +1,18 @@ -import sort from 'semver/functions/sort.js'; -import { platform } from 'os'; -import dedent from 'ts-dedent'; -import { findUpSync } from 'find-up'; import { existsSync, readFileSync } from 'node:fs'; -import path from 'node:path'; +import { join } from 'node:path'; + import { logger } from '@storybook/core/node-logger'; import { FindPackageVersionsError } from '@storybook/core/server-errors'; +import { findUp } from 'find-up'; +import { platform } from 'os'; +import sort from 'semver/functions/sort.js'; +import dedent from 'ts-dedent'; + +import { createLogStream } from '../utils/cli'; import { JsPackageManager } from './JsPackageManager'; import type { PackageJson } from './PackageJson'; import type { InstallationMetadata, PackageMetadata } from './types'; -import { createLogStream } from '../utils/cli'; type NpmDependency = { version: string; @@ -87,9 +89,9 @@ export class NPMProxy extends JsPackageManager { packageName: string, basePath = this.cwd ): Promise { - const packageJsonPath = await findUpSync( + const packageJsonPath = await findUp( (dir) => { - const possiblePath = path.join(dir, 'node_modules', packageName, 'package.json'); + const possiblePath = join(dir, 'node_modules', packageName, 'package.json'); return existsSync(possiblePath) ? possiblePath : undefined; }, { cwd: basePath } diff --git a/code/core/src/common/js-package-manager/PNPMProxy.test.ts b/code/core/src/common/js-package-manager/PNPMProxy.test.ts index cca2ca4ea364..f869dcb8181d 100644 --- a/code/core/src/common/js-package-manager/PNPMProxy.test.ts +++ b/code/core/src/common/js-package-manager/PNPMProxy.test.ts @@ -1,4 +1,5 @@ -import { describe, beforeEach, it, expect, vi } from 'vitest'; +import { beforeEach, describe, expect, it, vi } from 'vitest'; + import { PNPMProxy } from './PNPMProxy'; describe('PNPM Proxy', () => { diff --git a/code/core/src/common/js-package-manager/PNPMProxy.ts b/code/core/src/common/js-package-manager/PNPMProxy.ts index 652310bf87b3..8256926e35b6 100644 --- a/code/core/src/common/js-package-manager/PNPMProxy.ts +++ b/code/core/src/common/js-package-manager/PNPMProxy.ts @@ -1,14 +1,16 @@ -import { pathExistsSync } from 'fs-extra'; -import dedent from 'ts-dedent'; import { existsSync, readFileSync } from 'node:fs'; -import { findUpSync } from 'find-up'; -import path from 'node:path'; +import { join } from 'node:path'; + import { FindPackageVersionsError } from '@storybook/core/server-errors'; +import { findUpSync } from 'find-up'; +import { pathExistsSync } from 'fs-extra'; +import dedent from 'ts-dedent'; + +import { createLogStream } from '../utils/cli'; import { JsPackageManager } from './JsPackageManager'; import type { PackageJson } from './PackageJson'; import type { InstallationMetadata, PackageMetadata } from './types'; -import { createLogStream } from '../utils/cli'; type PnpmDependency = { from: string; @@ -142,7 +144,7 @@ export class PNPMProxy extends JsPackageManager { const pkg = pnpApi.getPackageInformation(pkgLocator); const packageJSON = JSON.parse( - readFileSync(path.join(pkg.packageLocation, 'package.json'), 'utf-8') + readFileSync(join(pkg.packageLocation, 'package.json'), 'utf-8') ); return packageJSON; @@ -156,7 +158,7 @@ export class PNPMProxy extends JsPackageManager { const packageJsonPath = await findUpSync( (dir) => { - const possiblePath = path.join(dir, 'node_modules', packageName, 'package.json'); + const possiblePath = join(dir, 'node_modules', packageName, 'package.json'); return existsSync(possiblePath) ? possiblePath : undefined; }, { cwd: basePath } diff --git a/code/core/src/common/js-package-manager/Yarn1Proxy.test.ts b/code/core/src/common/js-package-manager/Yarn1Proxy.test.ts index c20f496fed80..69bbc046aaf0 100644 --- a/code/core/src/common/js-package-manager/Yarn1Proxy.test.ts +++ b/code/core/src/common/js-package-manager/Yarn1Proxy.test.ts @@ -1,5 +1,7 @@ -import { describe, beforeEach, it, expect, vi } from 'vitest'; +import { beforeEach, describe, expect, it, vi } from 'vitest'; + import { dedent } from 'ts-dedent'; + import { Yarn1Proxy } from './Yarn1Proxy'; describe('Yarn 1 Proxy', () => { diff --git a/code/core/src/common/js-package-manager/Yarn1Proxy.ts b/code/core/src/common/js-package-manager/Yarn1Proxy.ts index a6387bc34176..8922a581ce55 100644 --- a/code/core/src/common/js-package-manager/Yarn1Proxy.ts +++ b/code/core/src/common/js-package-manager/Yarn1Proxy.ts @@ -1,9 +1,11 @@ import { existsSync, readFileSync } from 'node:fs'; -import dedent from 'ts-dedent'; -import { findUpSync } from 'find-up'; -import path from 'node:path'; +import { join } from 'node:path'; + import { FindPackageVersionsError } from '@storybook/core/server-errors'; +import { findUp } from 'find-up'; +import dedent from 'ts-dedent'; + import { createLogStream } from '../utils/cli'; import { JsPackageManager } from './JsPackageManager'; import type { PackageJson } from './PackageJson'; @@ -68,9 +70,9 @@ export class Yarn1Proxy extends JsPackageManager { packageName: string, basePath = this.cwd ): Promise { - const packageJsonPath = await findUpSync( + const packageJsonPath = await findUp( (dir) => { - const possiblePath = path.join(dir, 'node_modules', packageName, 'package.json'); + const possiblePath = join(dir, 'node_modules', packageName, 'package.json'); return existsSync(possiblePath) ? possiblePath : undefined; }, { cwd: basePath } diff --git a/code/core/src/common/js-package-manager/Yarn2Proxy.test.ts b/code/core/src/common/js-package-manager/Yarn2Proxy.test.ts index 4e4441aedb4d..fad7e829d180 100644 --- a/code/core/src/common/js-package-manager/Yarn2Proxy.test.ts +++ b/code/core/src/common/js-package-manager/Yarn2Proxy.test.ts @@ -1,4 +1,5 @@ -import { describe, beforeEach, it, expect, vi } from 'vitest'; +import { beforeEach, describe, expect, it, vi } from 'vitest'; + import { Yarn2Proxy } from './Yarn2Proxy'; describe('Yarn 2 Proxy', () => { @@ -309,6 +310,15 @@ describe('Yarn 2 Proxy', () => { expect(yarn2Proxy.parseErrorFromLogs(YARN2_ERROR_SAMPLE)).toMatchInlineSnapshot( ` "YARN2 error + YN0002: MISSING_PEER_DEPENDENCY + -> before-storybook@workspace:. doesn't provide @testing-library/dom (p1ac37), requested by @testing-library/user-event. + + YN0002: MISSING_PEER_DEPENDENCY + -> before-storybook@workspace:. doesn't provide eslint (p1f657), requested by eslint-plugin-storybook. + + YN0086: EXPLAIN_PEER_DEPENDENCIES_CTA + -> Some peer dependencies are incorrectly met; run yarn explain peer-requirements for details, where is the six-letter p-prefixed code. + YN0014: YARN_IMPORT_FAILED -> Failed to import certain dependencies diff --git a/code/core/src/common/js-package-manager/Yarn2Proxy.ts b/code/core/src/common/js-package-manager/Yarn2Proxy.ts index 05156d146130..711d34240292 100644 --- a/code/core/src/common/js-package-manager/Yarn2Proxy.ts +++ b/code/core/src/common/js-package-manager/Yarn2Proxy.ts @@ -1,10 +1,12 @@ -import { dedent } from 'ts-dedent'; -import { findUpSync } from 'find-up'; import { existsSync, readFileSync } from 'node:fs'; -import path from 'node:path'; +import { join } from 'node:path'; + +import { FindPackageVersionsError } from '@storybook/core/server-errors'; + import { PosixFS, VirtualFS, ZipOpenFS } from '@yarnpkg/fslib'; import { getLibzipSync } from '@yarnpkg/libzip'; -import { FindPackageVersionsError } from '@storybook/core/server-errors'; +import { findUp, findUpSync } from 'find-up'; +import { dedent } from 'ts-dedent'; import { createLogStream } from '../utils/cli'; import { JsPackageManager } from './JsPackageManager'; @@ -12,36 +14,9 @@ import type { PackageJson } from './PackageJson'; import type { InstallationMetadata, PackageMetadata } from './types'; import { parsePackageData } from './util'; +// more info at https://yarnpkg.com/advanced/error-codes const CRITICAL_YARN2_ERROR_CODES = { YN0001: 'EXCEPTION', - YN0009: 'BUILD_FAILED', - YN0010: 'RESOLVER_NOT_FOUND', - YN0011: 'FETCHER_NOT_FOUND', - YN0012: 'LINKER_NOT_FOUND', - YN0014: 'YARN_IMPORT_FAILED', - YN0015: 'REMOTE_INVALID', - YN0016: 'REMOTE_NOT_FOUND', - YN0020: 'MISSING_LOCKFILE_ENTRY', - YN0021: 'WORKSPACE_NOT_FOUND', - YN0028: 'FROZEN_LOCKFILE_EXCEPTION', - YN0030: 'FETCH_FAILED', - YN0046: 'AUTOMERGE_FAILED_TO_PARSE', - YN0062: 'INCOMPATIBLE_OS', - YN0063: 'INCOMPATIBLE_CPU', - YN0071: 'NM_CANT_INSTALL_EXTERNAL_SOFT_LINK', - YN0072: 'NM_PRESERVE_SYMLINKS_REQUIRED', - YN0075: 'PROLOG_INSTANTIATION_ERROR', - YN0076: 'INCOMPATIBLE_ARCHITECTURE', - YN0078: 'RESOLUTION_MISMATCH', - YN0081: 'NETWORK_UNSAFE_HTTP', - YN0082: 'RESOLUTION_FAILED', - YN0083: 'AUTOMERGE_GIT_ERROR', -}; - -// Keep the codes here, they might be helpful in the future -const YARN2_ERROR_CODES = { - ...CRITICAL_YARN2_ERROR_CODES, - YN0000: 'UNNAMED', YN0002: 'MISSING_PEER_DEPENDENCY', YN0003: 'CYCLIC_DEPENDENCIES', YN0004: 'DISABLED_BUILD_SCRIPTS', @@ -49,36 +24,50 @@ const YARN2_ERROR_CODES = { YN0006: 'SOFT_LINK_BUILD', YN0007: 'MUST_BUILD', YN0008: 'MUST_REBUILD', + YN0009: 'BUILD_FAILED', + YN0010: 'RESOLVER_NOT_FOUND', + YN0011: 'FETCHER_NOT_FOUND', + YN0012: 'LINKER_NOT_FOUND', YN0013: 'FETCH_NOT_CACHED', - YN0017: 'RESOLUTION_PACK', + YN0014: 'YARN_IMPORT_FAILED', + YN0015: 'REMOTE_INVALID', + YN0016: 'REMOTE_NOT_FOUND', YN0018: 'CACHE_CHECKSUM_MISMATCH', YN0019: 'UNUSED_CACHE_ENTRY', + YN0020: 'MISSING_LOCKFILE_ENTRY', YN0022: 'TOO_MANY_MATCHING_WORKSPACES', YN0023: 'CONSTRAINTS_MISSING_DEPENDENCY', YN0024: 'CONSTRAINTS_INCOMPATIBLE_DEPENDENCY', YN0025: 'CONSTRAINTS_EXTRANEOUS_DEPENDENCY', YN0026: 'CONSTRAINTS_INVALID_DEPENDENCY', YN0027: 'CANT_SUGGEST_RESOLUTIONS', + YN0028: 'FROZEN_LOCKFILE_EXCEPTION', YN0029: 'CROSS_DRIVE_VIRTUAL_LOCAL', + YN0030: 'FETCH_FAILED', YN0031: 'DANGEROUS_NODE_MODULES', - YN0032: 'NODE_GYP_INJECTED', + YN0035: 'NETWORK_ERROR', + YN0046: 'AUTOMERGE_FAILED_TO_PARSE', YN0047: 'AUTOMERGE_IMMUTABLE', YN0048: 'AUTOMERGE_SUCCESS', YN0049: 'AUTOMERGE_REQUIRED', YN0050: 'DEPRECATED_CLI_SETTINGS', YN0059: 'INVALID_RANGE_PEER_DEPENDENCY', YN0060: 'INCOMPATIBLE_PEER_DEPENDENCY', - YN0061: 'DEPRECATED_PACKAGE', - YN0068: 'UNUSED_PACKAGE_EXTENSION', + YN0062: 'INCOMPATIBLE_OS', + YN0063: 'INCOMPATIBLE_CPU', YN0069: 'REDUNDANT_PACKAGE_EXTENSION', + YN0071: 'NM_CANT_INSTALL_EXTERNAL_SOFT_LINK', + YN0072: 'NM_PRESERVE_SYMLINKS_REQUIRED', YN0074: 'NM_HARDLINKS_MODE_DOWNGRADED', + YN0075: 'PROLOG_INSTANTIATION_ERROR', + YN0076: 'INCOMPATIBLE_ARCHITECTURE', YN0077: 'GHOST_ARCHITECTURE', + YN0078: 'RESOLUTION_MISMATCH', YN0080: 'NETWORK_DISABLED', - YN0085: 'UPDATED_RESOLUTION_RECORD', + YN0081: 'NETWORK_UNSAFE_HTTP', + YN0082: 'RESOLUTION_FAILED', + YN0083: 'AUTOMERGE_GIT_ERROR', YN0086: 'EXPLAIN_PEER_DEPENDENCIES_CTA', - YN0087: 'MIGRATION_SUCCESS', - YN0088: 'VERSION_NOTICE', - YN0089: 'TIPS_NOTICE', YN0090: 'OFFLINE_MODE_ENABLED', }; @@ -163,7 +152,7 @@ export class Yarn2Proxy extends JsPackageManager { const virtualFs = new VirtualFS({ baseFs: zipOpenFs }); const crossFs = new PosixFS(virtualFs); - const virtualPath = path.join(pkg.packageLocation, 'package.json'); + const virtualPath = join(pkg.packageLocation, 'package.json'); return crossFs.readJsonSync(virtualPath); } catch (error: any) { @@ -174,9 +163,9 @@ export class Yarn2Proxy extends JsPackageManager { } } - const packageJsonPath = await findUpSync( + const packageJsonPath = await findUp( (dir) => { - const possiblePath = path.join(dir, 'node_modules', packageName, 'package.json'); + const possiblePath = join(dir, 'node_modules', packageName, 'package.json'); return existsSync(possiblePath) ? possiblePath : undefined; }, { cwd: basePath } diff --git a/code/core/src/common/presets.test.ts b/code/core/src/common/presets.test.ts index d7a847949f5c..565abe4521f4 100644 --- a/code/core/src/common/presets.test.ts +++ b/code/core/src/common/presets.test.ts @@ -1,8 +1,12 @@ -import mockRequire from 'mock-require'; -import { describe, beforeEach, afterEach, it, expect, vi } from 'vitest'; -import path from 'node:path'; +import { normalize } from 'node:path'; + +import { afterEach, beforeEach, describe, expect, it, vi } from 'vitest'; + import { logger } from '@storybook/core/node-logger'; -import { getPresets, resolveAddonName, loadPreset } from './presets'; + +import mockRequire from 'mock-require'; + +import { getPresets, loadPreset, resolveAddonName } from './presets'; function wrapPreset(basePresets: any): { babel: Function; webpack: Function } { return { @@ -410,7 +414,7 @@ describe('resolveAddonName', () => { it('should resolve managerEntries', () => { expect(resolveAddonName({} as any, '@storybook/addon-actions/register.js', {})).toEqual({ name: '@storybook/addon-actions/register.js', - managerEntries: [path.normalize('@storybook/addon-actions/register')], + managerEntries: [normalize('@storybook/addon-actions/register')], type: 'virtual', }); }); @@ -418,7 +422,7 @@ describe('resolveAddonName', () => { it('should resolve managerEntries from new /manager path', () => { expect(resolveAddonName({} as any, '@storybook/addon-actions/manager', {})).toEqual({ name: '@storybook/addon-actions/manager', - managerEntries: [path.normalize('@storybook/addon-actions/manager')], + managerEntries: [normalize('@storybook/addon-actions/manager')], type: 'virtual', }); }); @@ -545,14 +549,14 @@ describe('loadPreset', () => { name: '@storybook/addon-actions/register.js', options: {}, preset: { - managerEntries: [path.normalize('@storybook/addon-actions/register')], + managerEntries: [normalize('@storybook/addon-actions/register')], }, }, { name: 'addon-foo/register.js', options: {}, preset: { - managerEntries: [path.normalize('addon-foo/register')], + managerEntries: [normalize('addon-foo/register')], }, }, { @@ -574,14 +578,14 @@ describe('loadPreset', () => { name: 'addon-baz/register.js', options: {}, preset: { - managerEntries: [path.normalize('addon-baz/register')], + managerEntries: [normalize('addon-baz/register')], }, }, { name: '@storybook/addon-notes/register-panel', options: {}, preset: { - managerEntries: [path.normalize('@storybook/addon-notes/register-panel')], + managerEntries: [normalize('@storybook/addon-notes/register-panel')], }, }, { diff --git a/code/core/src/common/presets.ts b/code/core/src/common/presets.ts index 593d60051192..5651aa3e6a1f 100644 --- a/code/core/src/common/presets.ts +++ b/code/core/src/common/presets.ts @@ -1,11 +1,5 @@ -import { dedent } from 'ts-dedent'; -import { logger } from '@storybook/core/node-logger'; import { join, parse } from 'node:path'; -import { CriticalPresetLoadError } from '@storybook/core/server-errors'; -import { loadCustomPresets } from './utils/load-custom-presets'; -import { safeResolve, safeResolveFrom } from './utils/safeResolve'; -import { interopRequireDefault } from './utils/interpret-require'; -import { stripAbsNodeModulesPath } from './utils/strip-abs-node-modules-path'; + import type { BuilderOptions, CLIOptions, @@ -18,6 +12,16 @@ import type { StorybookConfigRaw, } from '@storybook/core/types'; +import { logger } from '@storybook/core/node-logger'; +import { CriticalPresetLoadError } from '@storybook/core/server-errors'; + +import { dedent } from 'ts-dedent'; + +import { interopRequireDefault } from './utils/interpret-require'; +import { loadCustomPresets } from './utils/load-custom-presets'; +import { safeResolve, safeResolveFrom } from './utils/safeResolve'; +import { stripAbsNodeModulesPath } from './utils/strip-abs-node-modules-path'; + type InterPresetOptions = Omit< CLIOptions & LoadOptions & diff --git a/code/core/src/common/utils/__tests__/check-addon-order.test.ts b/code/core/src/common/utils/__tests__/check-addon-order.test.ts index 9b22f83b98f2..c9f67ffd3631 100644 --- a/code/core/src/common/utils/__tests__/check-addon-order.test.ts +++ b/code/core/src/common/utils/__tests__/check-addon-order.test.ts @@ -1,10 +1,13 @@ -import { afterEach, it, expect, vi, describe } from 'vitest'; -import { logger } from '@storybook/core/node-logger'; +import { afterEach, describe, expect, it, vi } from 'vitest'; + import type { CoreCommon_AddonEntry, CoreCommon_AddonInfo, CoreCommon_OptionsEntry, } from '@storybook/core/types'; + +import { logger } from '@storybook/core/node-logger'; + import { checkAddonOrder } from '../check-addon-order'; const configFile = './main.js'; diff --git a/code/core/src/common/utils/__tests__/interpret-files.test.ts b/code/core/src/common/utils/__tests__/interpret-files.test.ts index fff12806dfb1..7d898af3ab04 100644 --- a/code/core/src/common/utils/__tests__/interpret-files.test.ts +++ b/code/core/src/common/utils/__tests__/interpret-files.test.ts @@ -1,10 +1,18 @@ -import { describe, afterEach, it, expect } from 'vitest'; -import mock from 'mock-fs'; +import { afterEach, describe, expect, it, vi } from 'vitest'; + +import { vol } from 'memfs'; + import { getInterpretedFile } from '../interpret-files'; +vi.mock('fs', async () => { + const memfs = await vi.importActual('memfs'); + + return { default: memfs.fs, ...(memfs as any).fs }; +}); + describe('interpret-files', () => { it('will interpret file as file.ts when it exists in fs', () => { - mock({ + vol.fromNestedJSON({ 'path/to/file.ts': 'ts file contents', }); @@ -14,7 +22,7 @@ describe('interpret-files', () => { }); it('will interpret file as file.js when both are in fs', () => { - mock({ + vol.fromNestedJSON({ 'path/to/file.js': 'js file contents', 'path/to/file.ts': 'ts file contents', }); @@ -25,7 +33,7 @@ describe('interpret-files', () => { }); it('will interpret file even if extension is already present', () => { - mock({ + vol.fromNestedJSON({ 'path/to/file.js': 'js file contents', 'path/to/file.ts': 'ts file contents', }); @@ -36,7 +44,7 @@ describe('interpret-files', () => { }); it('will return undefined if there is no candidate of a file in fs', () => { - mock({ + vol.fromNestedJSON({ 'path/to/file.js': 'js file contents', }); @@ -46,7 +54,7 @@ describe('interpret-files', () => { }); it('will interpret file as file.mts when it exists in fs', () => { - mock({ + vol.fromNestedJSON({ 'path/to/file.mts': 'ts file contents', }); @@ -56,7 +64,7 @@ describe('interpret-files', () => { }); it('will interpret file as file.cts when it exists in fs', () => { - mock({ + vol.fromNestedJSON({ 'path/to/file.cts': 'ts file contents', }); @@ -65,5 +73,5 @@ describe('interpret-files', () => { expect(file).toEqual('path/to/file.cts'); }); - afterEach(mock.restore); + afterEach(() => vol.reset()); }); diff --git a/code/core/src/common/utils/__tests__/normalize-stories.test.ts b/code/core/src/common/utils/__tests__/normalize-stories.test.ts index d16479ee6e73..26e5f1bcc3c8 100644 --- a/code/core/src/common/utils/__tests__/normalize-stories.test.ts +++ b/code/core/src/common/utils/__tests__/normalize-stories.test.ts @@ -1,8 +1,10 @@ /// ; -import { describe, it, expect, vi } from 'vitest'; import { sep } from 'node:path'; +import { describe, expect, it, vi } from 'vitest'; + import { InvalidStoriesEntryError } from '@storybook/core/server-errors'; + import { getDirectoryFromWorkingDir, normalizeStories, diff --git a/code/core/src/common/utils/__tests__/paths.test.ts b/code/core/src/common/utils/__tests__/paths.test.ts index 71b6b2a1efa0..e353aed6f36e 100644 --- a/code/core/src/common/utils/__tests__/paths.test.ts +++ b/code/core/src/common/utils/__tests__/paths.test.ts @@ -1,19 +1,22 @@ -import { describe, it, expect, vi } from 'vitest'; -import path from 'node:path'; +import { join, sep } from 'node:path'; + +import { describe, expect, it, vi } from 'vitest'; + import { findUpSync } from 'find-up'; import slash from 'slash'; -import { normalizeStoryPath, getProjectRoot } from '../paths'; + +import { getProjectRoot, normalizeStoryPath } from '../paths'; vi.mock('find-up'); describe('paths - normalizeStoryPath()', () => { it('returns a path starting with "./" unchanged', () => { - const filename = `.${path.sep}${path.join('src', 'Comp.story.js')}`; + const filename = `.${sep}${join('src', 'Comp.story.js')}`; expect(normalizeStoryPath(filename)).toEqual(filename); }); it('returns a path starting with "../" unchanged', () => { - const filename = path.join('..', 'src', 'Comp.story.js'); + const filename = join('..', 'src', 'Comp.story.js'); expect(normalizeStoryPath(filename)).toEqual(filename); }); @@ -28,18 +31,18 @@ describe('paths - normalizeStoryPath()', () => { }); it('adds "./" to a normalized relative path', () => { - const filename = path.join('src', 'Comp.story.js'); - expect(normalizeStoryPath(filename)).toEqual(`.${path.sep}${filename}`); + const filename = join('src', 'Comp.story.js'); + expect(normalizeStoryPath(filename)).toEqual(`.${sep}${filename}`); }); it('adds "./" to a hidden folder', () => { - const filename = path.join('.storybook', 'Comp.story.js'); - expect(normalizeStoryPath(filename)).toEqual(`.${path.sep}${filename}`); + const filename = join('.storybook', 'Comp.story.js'); + expect(normalizeStoryPath(filename)).toEqual(`.${sep}${filename}`); }); it('adds "./" to a hidden file', () => { const filename = `.Comp.story.js`; - expect(normalizeStoryPath(filename)).toEqual(`.${path.sep}${filename}`); + expect(normalizeStoryPath(filename)).toEqual(`.${sep}${filename}`); }); }); diff --git a/code/core/src/common/utils/__tests__/template.test.ts b/code/core/src/common/utils/__tests__/template.test.ts index 53a43e84909e..93fdf7a8ed87 100644 --- a/code/core/src/common/utils/__tests__/template.test.ts +++ b/code/core/src/common/utils/__tests__/template.test.ts @@ -1,8 +1,17 @@ -import { describe, beforeEach, afterEach, it, expect } from 'vitest'; -import mock from 'mock-fs'; -import { getPreviewHeadTemplate, getPreviewBodyTemplate } from '../template'; import { dirname } from 'node:path'; +import { afterEach, beforeEach, describe, expect, it, vi } from 'vitest'; + +import { vol } from 'memfs'; + +import { getPreviewBodyTemplate, getPreviewHeadTemplate } from '../template'; + +vi.mock('fs', async () => { + const memfs = await vi.importActual('memfs'); + + return { default: memfs.fs, ...(memfs as any).fs }; +}); + const HEAD_HTML_CONTENTS = ''; const BASE_HTML_CONTENTS = ''; @@ -12,18 +21,17 @@ const BODY_HTML_CONTENTS = '
custom body contents
'; const base = dirname(require.resolve('@storybook/core/package.json')); describe('server.getPreviewHeadHtml', () => { + afterEach(() => { + vol.reset(); + }); describe('when .storybook/preview-head.html does not exist', () => { beforeEach(() => { - mock({ + vol.fromNestedJSON({ [`${base}/assets/server/base-preview-head.html`]: BASE_HTML_CONTENTS, config: {}, }); }); - afterEach(() => { - mock.restore(); - }); - it('return an empty string', () => { const result = getPreviewHeadTemplate('./config'); expect(result).toEqual(BASE_HTML_CONTENTS); @@ -32,7 +40,7 @@ describe('server.getPreviewHeadHtml', () => { describe('when .storybook/preview-head.html exists', () => { beforeEach(() => { - mock({ + vol.fromNestedJSON({ [`${base}/assets/server/base-preview-head.html`]: BASE_HTML_CONTENTS, config: { 'preview-head.html': HEAD_HTML_CONTENTS, @@ -40,10 +48,6 @@ describe('server.getPreviewHeadHtml', () => { }); }); - afterEach(() => { - mock.restore(); - }); - it('return the contents of the file', () => { const result = getPreviewHeadTemplate('./config'); expect(result).toEqual(BASE_HTML_CONTENTS + HEAD_HTML_CONTENTS); @@ -54,16 +58,12 @@ describe('server.getPreviewHeadHtml', () => { describe('server.getPreviewBodyHtml', () => { describe('when .storybook/preview-body.html does not exist', () => { beforeEach(() => { - mock({ + vol.fromNestedJSON({ [`${base}/assets/server/base-preview-body.html`]: BASE_BODY_HTML_CONTENTS, config: {}, }); }); - afterEach(() => { - mock.restore(); - }); - it('return an empty string', () => { const result = getPreviewBodyTemplate('./config'); expect(result).toEqual(BASE_BODY_HTML_CONTENTS); @@ -72,7 +72,7 @@ describe('server.getPreviewBodyHtml', () => { describe('when .storybook/preview-body.html exists', () => { beforeEach(() => { - mock({ + vol.fromNestedJSON({ [`${base}/assets/server/base-preview-body.html`]: BASE_BODY_HTML_CONTENTS, config: { 'preview-body.html': BODY_HTML_CONTENTS, @@ -80,10 +80,6 @@ describe('server.getPreviewBodyHtml', () => { }); }); - afterEach(() => { - mock.restore(); - }); - it('return the contents of the file', () => { const result = getPreviewBodyTemplate('./config'); expect(result).toEqual(BODY_HTML_CONTENTS + BASE_BODY_HTML_CONTENTS); diff --git a/code/core/src/common/utils/check-addon-order.ts b/code/core/src/common/utils/check-addon-order.ts index 0669e0f67234..0922a8cce447 100644 --- a/code/core/src/common/utils/check-addon-order.ts +++ b/code/core/src/common/utils/check-addon-order.ts @@ -1,10 +1,11 @@ -import { logger } from '@storybook/core/node-logger'; import type { CoreCommon_AddonEntry, CoreCommon_AddonInfo, CoreCommon_OptionsEntry, } from '@storybook/core/types'; +import { logger } from '@storybook/core/node-logger'; + interface Options { before: CoreCommon_AddonInfo; after: CoreCommon_AddonInfo; diff --git a/code/core/src/common/utils/cli.test.ts b/code/core/src/common/utils/cli.test.ts index 47bcf7d19b3b..eecfcc648889 100644 --- a/code/core/src/common/utils/cli.test.ts +++ b/code/core/src/common/utils/cli.test.ts @@ -1,4 +1,5 @@ -import { describe, it, expect } from 'vitest'; +import { describe, expect, it } from 'vitest'; + import { isCorePackage } from './cli'; describe('UTILS', () => { diff --git a/code/core/src/common/utils/cli.ts b/code/core/src/common/utils/cli.ts index 40a686df486f..5061d81905c3 100644 --- a/code/core/src/common/utils/cli.ts +++ b/code/core/src/common/utils/cli.ts @@ -1,12 +1,15 @@ -import type { WriteStream } from 'fs-extra'; -import { move, remove, writeFile, readFile, createWriteStream, mkdirSync } from 'fs-extra'; +import { realpath } from 'node:fs/promises'; +import os from 'node:os'; import { join } from 'node:path'; -import { rendererPackages } from './get-storybook-info'; + +import type { WriteStream } from 'fs-extra'; +import { createWriteStream, mkdirSync, move, readFile, remove, writeFile } from 'fs-extra'; +import { type MergeExclusive } from 'type-fest'; +import uniqueString from 'unique-string'; + import type { JsPackageManager } from '../js-package-manager'; import versions from '../versions'; -import uniqueString from 'unique-string'; -import os from 'node:os'; -import { realpath } from 'node:fs/promises'; +import { rendererPackages } from './get-storybook-info'; const tempDir = () => realpath(os.tmpdir()); @@ -18,8 +21,6 @@ export async function temporaryDirectory({ prefix = '' } = {}) { return directory; } -import { type MergeExclusive } from 'type-fest'; - export type FileOptions = MergeExclusive< { /** diff --git a/code/core/src/common/utils/envs.ts b/code/core/src/common/utils/envs.ts index 46401309cea5..adf1297f686f 100644 --- a/code/core/src/common/utils/envs.ts +++ b/code/core/src/common/utils/envs.ts @@ -1,6 +1,7 @@ // eslint-disable-next-line @typescript-eslint/ban-ts-comment // @ts-ignore - Needed for Angular sandbox running without --no-link option. Do NOT convert to @ts-expect-error! import { getEnvironment } from 'lazy-universal-dotenv'; + import { nodePathsToArray } from './paths'; // Load environment variables starts with STORYBOOK_ to the client side. diff --git a/code/core/src/common/utils/formatter.test.ts b/code/core/src/common/utils/formatter.test.ts index 53dfbfb51483..c60ecb09b84f 100644 --- a/code/core/src/common/utils/formatter.test.ts +++ b/code/core/src/common/utils/formatter.test.ts @@ -1,6 +1,8 @@ +import { resolve } from 'node:path'; + +import { describe, expect, it, vi } from 'vitest'; + import { formatFileContent } from './formatter'; -import { describe, it, expect, vi } from 'vitest'; -import path from 'node:path'; const mockPrettier = vi.hoisted(() => ({ resolveConfig: vi.fn(), @@ -32,7 +34,7 @@ type Story = StoryObj; describe('formatter', () => { describe('withPrettierConfig', () => { - const testPath = path.resolve(__dirname, '__tests-formatter__', 'withPrettierConfig'); + const testPath = resolve(__dirname, '__tests-formatter__', 'withPrettierConfig'); describe('prettier', async () => { const prettierV3 = await import('prettier'); @@ -42,7 +44,7 @@ describe('formatter', () => { mockPrettier.version.mockReturnValue(prettierV3.version); mockPrettier.resolveConfig.mockImplementation(prettierV3.resolveConfig); - const filePath = path.resolve(testPath, 'testFile.ts'); + const filePath = resolve(testPath, 'testFile.ts'); const result = await formatFileContent(filePath, dummyContent); @@ -52,7 +54,7 @@ describe('formatter', () => { }); describe('withoutPrettierConfigAndWithEditorConfig', () => { - const testPath = path.resolve(__dirname, '__tests-formatter__', 'withoutPrettierConfig'); + const testPath = resolve(__dirname, '__tests-formatter__', 'withoutPrettierConfig'); describe('prettier-v3', async () => { const prettierV3 = await import('prettier'); @@ -62,7 +64,7 @@ describe('formatter', () => { mockPrettier.version.mockReturnValue(prettierV3.version); mockPrettier.resolveConfig.mockImplementation(prettierV3.resolveConfig); - const filePath = path.resolve(testPath, 'testFile.ts'); + const filePath = resolve(testPath, 'testFile.ts'); const result = await formatFileContent(filePath, dummyContent); @@ -72,7 +74,7 @@ describe('formatter', () => { }); describe('withoutPrettierConfigAndWithEditorConfig', () => { - const testPath = path.resolve(__dirname, '__tests-formatter__', 'withoutEditorConfig'); + const testPath = resolve(__dirname, '__tests-formatter__', 'withoutEditorConfig'); describe('prettier-v3', async () => { const prettierV3 = await import('prettier'); @@ -82,7 +84,7 @@ describe('formatter', () => { mockPrettier.version.mockReturnValue(prettierV3.version); mockPrettier.resolveConfig.mockResolvedValue(null); - const filePath = path.resolve(testPath, 'testFile.ts'); + const filePath = resolve(testPath, 'testFile.ts'); const result = await formatFileContent(filePath, dummyContent); diff --git a/code/core/src/common/utils/framework-to-renderer.ts b/code/core/src/common/utils/framework-to-renderer.ts index a34ac765c2c7..63107ad8313b 100644 --- a/code/core/src/common/utils/framework-to-renderer.ts +++ b/code/core/src/common/utils/framework-to-renderer.ts @@ -11,6 +11,7 @@ export const frameworkToRenderer: Record< 'html-vite': 'html', 'html-webpack5': 'html', nextjs: 'react', + 'experimental-nextjs-vite': 'react', 'preact-vite': 'preact', 'preact-webpack5': 'preact', qwik: 'qwik', diff --git a/code/core/src/common/utils/get-framework-name.test.ts b/code/core/src/common/utils/get-framework-name.test.ts index 9f6a95ba19e7..b0dba5027e01 100644 --- a/code/core/src/common/utils/get-framework-name.test.ts +++ b/code/core/src/common/utils/get-framework-name.test.ts @@ -1,4 +1,5 @@ import { describe, expect, it } from 'vitest'; + import { extractProperFrameworkName } from './get-framework-name'; describe('get-framework-name', () => { diff --git a/code/core/src/common/utils/get-framework-name.ts b/code/core/src/common/utils/get-framework-name.ts index 984de13b7d07..b4fcc57ee344 100644 --- a/code/core/src/common/utils/get-framework-name.ts +++ b/code/core/src/common/utils/get-framework-name.ts @@ -1,7 +1,9 @@ +import type { Options } from '@storybook/core/types'; + import { dedent } from 'ts-dedent'; + import { frameworkPackages } from './get-storybook-info'; import { normalizePath } from './normalize-path'; -import type { Options } from '@storybook/core/types'; /** * Framework can be a string or an object. This utility always returns the string name. diff --git a/code/core/src/common/utils/get-renderer-name.test.ts b/code/core/src/common/utils/get-renderer-name.test.ts index 09c31f36b4f1..5ae7fef96f35 100644 --- a/code/core/src/common/utils/get-renderer-name.test.ts +++ b/code/core/src/common/utils/get-renderer-name.test.ts @@ -1,4 +1,5 @@ import { describe, expect, test } from 'vitest'; + import { extractProperRendererNameFromFramework } from './get-renderer-name'; describe('get-renderer-name', () => { diff --git a/code/core/src/common/utils/get-renderer-name.ts b/code/core/src/common/utils/get-renderer-name.ts index df1380632360..867fa94f3775 100644 --- a/code/core/src/common/utils/get-renderer-name.ts +++ b/code/core/src/common/utils/get-renderer-name.ts @@ -1,7 +1,8 @@ +import type { Options } from '@storybook/core/types'; + +import { frameworkToRenderer } from './framework-to-renderer'; import { extractProperFrameworkName, getFrameworkName } from './get-framework-name'; import { frameworkPackages } from './get-storybook-info'; -import { frameworkToRenderer } from './framework-to-renderer'; -import type { Options } from '@storybook/core/types'; /** * Render is set as a string on core. It must be set by the framework diff --git a/code/core/src/common/utils/get-storybook-configuration.test.ts b/code/core/src/common/utils/get-storybook-configuration.test.ts index aa821e38e594..1bb377f79d94 100644 --- a/code/core/src/common/utils/get-storybook-configuration.test.ts +++ b/code/core/src/common/utils/get-storybook-configuration.test.ts @@ -1,4 +1,5 @@ -import { describe, it, expect } from 'vitest'; +import { describe, expect, it } from 'vitest'; + import { getStorybookConfiguration } from './get-storybook-configuration'; describe('getStorybookConfiguration', () => { diff --git a/code/core/src/common/utils/get-storybook-info.ts b/code/core/src/common/utils/get-storybook-info.ts index b61f1fd4914a..e86281caad8e 100644 --- a/code/core/src/common/utils/get-storybook-info.ts +++ b/code/core/src/common/utils/get-storybook-info.ts @@ -1,9 +1,12 @@ -import path from 'node:path'; -import { pathExistsSync } from 'fs-extra'; -import { getStorybookConfiguration } from './get-storybook-configuration'; +import { join } from 'node:path'; + import type { SupportedFrameworks } from '@storybook/core/types'; import type { CoreCommon_StorybookInfo, PackageJson } from '@storybook/core/types'; +import { pathExistsSync } from 'fs-extra'; + +import { getStorybookConfiguration } from './get-storybook-configuration'; + export const rendererPackages: Record = { '@storybook/react': 'react', '@storybook/vue3': 'vue3', @@ -88,7 +91,7 @@ const getRendererInfo = (packageJson: PackageJson) => { const validConfigExtensions = ['ts', 'js', 'tsx', 'jsx', 'mjs', 'cjs']; export const findConfigFile = (prefix: string, configDir: string) => { - const filePrefix = path.join(configDir, prefix); + const filePrefix = join(configDir, prefix); const extension = validConfigExtensions.find((ext: string) => pathExistsSync(`${filePrefix}.${ext}`) ); diff --git a/code/core/src/common/utils/get-storybook-refs.ts b/code/core/src/common/utils/get-storybook-refs.ts index b24fde29dea5..053ae17abc93 100644 --- a/code/core/src/common/utils/get-storybook-refs.ts +++ b/code/core/src/common/utils/get-storybook-refs.ts @@ -1,11 +1,13 @@ -import { readJSON } from 'fs-extra'; import { dirname, join } from 'node:path'; -import { findUp } from 'find-up'; -import resolveFrom from 'resolve-from'; -import { logger } from '@storybook/core/node-logger'; import type { Options, Ref } from '@storybook/core/types'; +import { logger } from '@storybook/core/node-logger'; + +import { findUp } from 'find-up'; +import { readJSON } from 'fs-extra'; +import resolveFrom from 'resolve-from'; + export const getAutoRefs = async (options: Options): Promise> => { const location = await findUp('package.json', { cwd: options.configDir }); if (!location) { diff --git a/code/core/src/common/utils/load-custom-presets.ts b/code/core/src/common/utils/load-custom-presets.ts index 16923ec1a6f0..dcb104351703 100644 --- a/code/core/src/common/utils/load-custom-presets.ts +++ b/code/core/src/common/utils/load-custom-presets.ts @@ -1,16 +1,18 @@ -import path from 'node:path'; +import { resolve } from 'node:path'; + +import type { PresetConfig } from '@storybook/core/types'; + import { serverRequire, serverResolve } from './interpret-require'; import { validateConfigurationFiles } from './validate-configuration-files'; -import type { PresetConfig } from '@storybook/core/types'; export function loadCustomPresets({ configDir }: { configDir: string }): PresetConfig[] { validateConfigurationFiles(configDir); - const presets = serverRequire(path.resolve(configDir, 'presets')); - const main = serverRequire(path.resolve(configDir, 'main')); + const presets = serverRequire(resolve(configDir, 'presets')); + const main = serverRequire(resolve(configDir, 'main')); if (main) { - const resolved = serverResolve(path.resolve(configDir, 'main')); + const resolved = serverResolve(resolve(configDir, 'main')); if (resolved) { return [resolved]; } diff --git a/code/core/src/common/utils/load-main-config.ts b/code/core/src/common/utils/load-main-config.ts index 37d9789afcfb..e594a380d6f8 100644 --- a/code/core/src/common/utils/load-main-config.ts +++ b/code/core/src/common/utils/load-main-config.ts @@ -1,9 +1,12 @@ -import path, { relative } from 'node:path'; +import { readFile } from 'node:fs/promises'; +import { relative, resolve } from 'node:path'; + +import type { StorybookConfig } from '@storybook/core/types'; + +import { MainFileESMOnlyImportError, MainFileEvaluationError } from '@storybook/core/server-errors'; + import { serverRequire, serverResolve } from './interpret-require'; import { validateConfigurationFiles } from './validate-configuration-files'; -import { readFile } from 'fs/promises'; -import { MainFileESMOnlyImportError, MainFileEvaluationError } from '@storybook/core/server-errors'; -import type { StorybookConfig } from '@storybook/core/types'; export async function loadMainConfig({ configDir = '.storybook', @@ -14,7 +17,7 @@ export async function loadMainConfig({ }): Promise { await validateConfigurationFiles(configDir); - const mainJsPath = serverResolve(path.resolve(configDir, 'main')) as string; + const mainJsPath = serverResolve(resolve(configDir, 'main')) as string; if (noCache && mainJsPath && require.cache[mainJsPath]) { delete require.cache[mainJsPath]; diff --git a/code/core/src/common/utils/load-manager-or-addons-file.ts b/code/core/src/common/utils/load-manager-or-addons-file.ts index 78c10958269c..a60fd6daf9ec 100644 --- a/code/core/src/common/utils/load-manager-or-addons-file.ts +++ b/code/core/src/common/utils/load-manager-or-addons-file.ts @@ -1,12 +1,14 @@ -import path from 'node:path'; +import { resolve } from 'node:path'; + import { logger } from '@storybook/core/node-logger'; + import { dedent } from 'ts-dedent'; import { getInterpretedFile } from './interpret-files'; export function loadManagerOrAddonsFile({ configDir }: { configDir: string }) { - const storybookCustomAddonsPath = getInterpretedFile(path.resolve(configDir, 'addons')); - const storybookCustomManagerPath = getInterpretedFile(path.resolve(configDir, 'manager')); + const storybookCustomAddonsPath = getInterpretedFile(resolve(configDir, 'addons')); + const storybookCustomManagerPath = getInterpretedFile(resolve(configDir, 'manager')); if (storybookCustomAddonsPath || storybookCustomManagerPath) { logger.info('=> Loading custom manager config'); @@ -14,7 +16,7 @@ export function loadManagerOrAddonsFile({ configDir }: { configDir: string }) { if (storybookCustomAddonsPath && storybookCustomManagerPath) { throw new Error(dedent` - You have both a "addons.js" and a "manager.js", remove the "addons.js" file from your configDir (${path.resolve( + You have both a "addons.js" and a "manager.js", remove the "addons.js" file from your configDir (${resolve( configDir, 'addons' )})`); diff --git a/code/core/src/common/utils/load-preview-or-config-file.ts b/code/core/src/common/utils/load-preview-or-config-file.ts index a6af14cfae16..bc6cadcfbb30 100644 --- a/code/core/src/common/utils/load-preview-or-config-file.ts +++ b/code/core/src/common/utils/load-preview-or-config-file.ts @@ -1,15 +1,16 @@ -import path from 'node:path'; +import { resolve } from 'node:path'; + import { dedent } from 'ts-dedent'; import { getInterpretedFile } from './interpret-files'; export function loadPreviewOrConfigFile({ configDir }: { configDir: string }) { - const storybookConfigPath = getInterpretedFile(path.resolve(configDir, 'config')); - const storybookPreviewPath = getInterpretedFile(path.resolve(configDir, 'preview')); + const storybookConfigPath = getInterpretedFile(resolve(configDir, 'config')); + const storybookPreviewPath = getInterpretedFile(resolve(configDir, 'preview')); if (storybookConfigPath && storybookPreviewPath) { throw new Error(dedent` - You have both a "config.js" and a "preview.js", remove the "config.js" file from your configDir (${path.resolve( + You have both a "config.js" and a "preview.js", remove the "config.js" file from your configDir (${resolve( configDir, 'config' )})`); diff --git a/code/core/src/common/utils/normalize-path.test.ts b/code/core/src/common/utils/normalize-path.test.ts index b2688660b6ef..41c5b1dbbf34 100644 --- a/code/core/src/common/utils/normalize-path.test.ts +++ b/code/core/src/common/utils/normalize-path.test.ts @@ -1,6 +1,7 @@ -import { normalizePath } from './normalize-path'; import { describe, expect, it } from 'vitest'; +import { normalizePath } from './normalize-path'; + describe('normalize-path', () => { it('should normalize paths', () => { expect(normalizePath('path/to/../file')).toBe('path/file'); diff --git a/code/core/src/common/utils/normalize-path.ts b/code/core/src/common/utils/normalize-path.ts index 098d8a7a0c58..18c6c00dd157 100644 --- a/code/core/src/common/utils/normalize-path.ts +++ b/code/core/src/common/utils/normalize-path.ts @@ -1,4 +1,4 @@ -import path from 'node:path'; +import { posix } from 'node:path'; /** * Normalize a path to use forward slashes and remove .. and . @@ -10,5 +10,5 @@ import path from 'node:path'; * normalizePath('path\\to\\file') // => 'path/to/file' */ export function normalizePath(p: string) { - return path.posix.normalize(p.replace(/\\/g, '/')); + return posix.normalize(p.replace(/\\/g, '/')); } diff --git a/code/core/src/common/utils/normalize-stories.ts b/code/core/src/common/utils/normalize-stories.ts index 44e2bb38f64a..a001209f401b 100644 --- a/code/core/src/common/utils/normalize-stories.ts +++ b/code/core/src/common/utils/normalize-stories.ts @@ -1,19 +1,22 @@ import { lstatSync } from 'node:fs'; -import path from 'node:path'; +import { basename, dirname, relative, resolve } from 'node:path'; + +import type { NormalizedStoriesSpecifier, StoriesEntry } from '@storybook/core/types'; + +import { InvalidStoriesEntryError } from '@storybook/core/server-errors'; + import * as pico from 'picomatch'; import slash from 'slash'; -import { InvalidStoriesEntryError } from '@storybook/core/server-errors'; -import { normalizeStoryPath } from './paths'; import { globToRegexp } from './glob-to-regexp'; -import type { NormalizedStoriesSpecifier, StoriesEntry } from '@storybook/core/types'; +import { normalizeStoryPath } from './paths'; const DEFAULT_TITLE_PREFIX = ''; const DEFAULT_FILES_PATTERN = '**/*.@(mdx|stories.@(js|jsx|mjs|ts|tsx))'; const isDirectory = (configDir: string, entry: string) => { try { - return lstatSync(path.resolve(configDir, entry)).isDirectory(); + return lstatSync(resolve(configDir, entry)).isDirectory(); } catch (err) { return false; } @@ -24,8 +27,8 @@ export const getDirectoryFromWorkingDir = ({ workingDir, directory, }: NormalizeOptions & { directory: string }) => { - const directoryFromConfig = path.resolve(configDir, directory); - const directoryFromWorking = path.relative(workingDir, directoryFromConfig); + const directoryFromConfig = resolve(configDir, directory); + const directoryFromWorking = relative(workingDir, directoryFromConfig); // relative('/foo', '/foo/src') => 'src' // but we want `./src` to match importPaths @@ -58,8 +61,8 @@ export const normalizeStoriesEntry = ( } else { specifierWithoutMatcher = { titlePrefix: DEFAULT_TITLE_PREFIX, - directory: path.dirname(entry), - files: path.basename(entry), + directory: dirname(entry), + files: basename(entry), }; } } else { diff --git a/code/core/src/common/utils/notify-telemetry.ts b/code/core/src/common/utils/notify-telemetry.ts index 53b291b4b6a8..bb39028dedeb 100644 --- a/code/core/src/common/utils/notify-telemetry.ts +++ b/code/core/src/common/utils/notify-telemetry.ts @@ -1,4 +1,5 @@ import chalk from 'chalk'; + import { cache } from './cache'; const TELEMETRY_KEY_NOTIFY_DATE = 'telemetry-notification-date'; diff --git a/code/core/src/common/utils/paths.ts b/code/core/src/common/utils/paths.ts index b2260be135f4..9600f3028e1a 100644 --- a/code/core/src/common/utils/paths.ts +++ b/code/core/src/common/utils/paths.ts @@ -1,4 +1,5 @@ -import path from 'node:path'; +import { join, resolve, sep } from 'node:path'; + import { findUpSync } from 'find-up'; export const getProjectRoot = () => { @@ -11,7 +12,7 @@ export const getProjectRoot = () => { try { const found = findUpSync('.git', { type: 'directory' }); if (found) { - result = path.join(found, '..'); + result = join(found, '..'); } } catch (e) { // @@ -19,7 +20,7 @@ export const getProjectRoot = () => { try { const found = findUpSync('.svn', { type: 'directory' }); if (found) { - result = result || path.join(found, '..'); + result = result || join(found, '..'); } } catch (e) { // @@ -27,7 +28,7 @@ export const getProjectRoot = () => { try { const found = findUpSync('.hg', { type: 'directory' }); if (found) { - result = result || path.join(found, '..'); + result = result || join(found, '..'); } } catch (e) { // @@ -43,7 +44,7 @@ export const getProjectRoot = () => { try { const found = findUpSync('.yarn', { type: 'directory' }); if (found) { - result = result || path.join(found, '..'); + result = result || join(found, '..'); } } catch (e) { // @@ -56,7 +57,7 @@ export const nodePathsToArray = (nodePath: string) => nodePath .split(process.platform === 'win32' ? ';' : ':') .filter(Boolean) - .map((p) => path.resolve('./', p)); + .map((p) => resolve('./', p)); const relativePattern = /^\.{1,2}([/\\]|$)/; /** @@ -65,5 +66,5 @@ const relativePattern = /^\.{1,2}([/\\]|$)/; export function normalizeStoryPath(filename: string) { if (relativePattern.test(filename)) return filename; - return `.${path.sep}${filename}`; + return `.${sep}${filename}`; } diff --git a/code/core/src/common/utils/remove.ts b/code/core/src/common/utils/remove.ts index f20a9d9f66af..a1be0176cca2 100644 --- a/code/core/src/common/utils/remove.ts +++ b/code/core/src/common/utils/remove.ts @@ -1,5 +1,7 @@ -import { dedent } from 'ts-dedent'; import { readConfig, writeConfig } from '@storybook/core/csf-tools'; + +import { dedent } from 'ts-dedent'; + import type { PackageManagerName } from '../js-package-manager'; import { JsPackageManagerFactory } from '../js-package-manager'; import { getStorybookInfo } from './get-storybook-info'; diff --git a/code/core/src/common/utils/resolve-path-in-sb-cache.ts b/code/core/src/common/utils/resolve-path-in-sb-cache.ts index 4ba6e762ba1b..3bd12c365c2f 100644 --- a/code/core/src/common/utils/resolve-path-in-sb-cache.ts +++ b/code/core/src/common/utils/resolve-path-in-sb-cache.ts @@ -1,4 +1,5 @@ -import path from 'node:path'; +import { join } from 'node:path'; + import findCacheDirectory from 'find-cache-dir'; /** @@ -11,7 +12,7 @@ import findCacheDirectory from 'find-cache-dir'; */ export function resolvePathInStorybookCache(fileOrDirectoryName: string, sub = 'default'): string { let cacheDirectory = findCacheDirectory({ name: 'storybook' }); - cacheDirectory ||= path.join(process.cwd(), '.cache', 'storybook'); + cacheDirectory ||= join(process.cwd(), '.cache', 'storybook'); - return path.join(cacheDirectory, sub, fileOrDirectoryName); + return join(cacheDirectory, sub, fileOrDirectoryName); } diff --git a/code/core/src/common/utils/strip-abs-node-modules-path.ts b/code/core/src/common/utils/strip-abs-node-modules-path.ts index b3d83198f1e7..abbb55608a64 100644 --- a/code/core/src/common/utils/strip-abs-node-modules-path.ts +++ b/code/core/src/common/utils/strip-abs-node-modules-path.ts @@ -1,15 +1,16 @@ -import path from 'node:path'; +import { posix, sep } from 'node:path'; + import slash from 'slash'; function normalizePath(id: string) { - return path.posix.normalize(slash(id)); + return posix.normalize(slash(id)); } // We need to convert from an absolute path, to a traditional node module import path, // so that vite can correctly pre-bundle/optimize export function stripAbsNodeModulesPath(absPath: string) { // TODO: Evaluate if searching for node_modules in a yarn pnp environment is correct - const splits = absPath.split(`node_modules${path.sep}`); + const splits = absPath.split(`node_modules${sep}`); // Return everything after the final "node_modules/" const module = normalizePath(splits[splits.length - 1]); return module; diff --git a/code/core/src/common/utils/template.ts b/code/core/src/common/utils/template.ts index 367ea32afe71..eb32545b7ea2 100644 --- a/code/core/src/common/utils/template.ts +++ b/code/core/src/common/utils/template.ts @@ -1,5 +1,5 @@ -import { dirname, resolve } from 'node:path'; import { existsSync, readFileSync } from 'node:fs'; +import { dirname, resolve } from 'node:path'; const interpolate = (string: string, data: Record = {}) => Object.entries(data).reduce((acc, [k, v]) => acc.replace(new RegExp(`%${k}%`, 'g'), v), string); diff --git a/code/core/src/common/utils/validate-config.test.ts b/code/core/src/common/utils/validate-config.test.ts index d945f374002f..891b5daa63fb 100644 --- a/code/core/src/common/utils/validate-config.test.ts +++ b/code/core/src/common/utils/validate-config.test.ts @@ -1,4 +1,5 @@ -import { describe, afterEach, it, expect, vi } from 'vitest'; +import { afterEach, describe, expect, it, vi } from 'vitest'; + import { validateFrameworkName } from './validate-config'; describe('validateFrameworkName', () => { diff --git a/code/core/src/common/utils/validate-config.ts b/code/core/src/common/utils/validate-config.ts index 4ca2856d02b9..221ea9235522 100644 --- a/code/core/src/common/utils/validate-config.ts +++ b/code/core/src/common/utils/validate-config.ts @@ -1,9 +1,11 @@ import { join } from 'node:path'; + import { CouldNotEvaluateFrameworkError, - MissingFrameworkFieldError, InvalidFrameworkNameError, + MissingFrameworkFieldError, } from '@storybook/core/server-errors'; + import { frameworkPackages } from './get-storybook-info'; const renderers = ['html', 'preact', 'react', 'server', 'svelte', 'vue', 'vue3', 'web-components']; diff --git a/code/core/src/common/utils/validate-configuration-files.ts b/code/core/src/common/utils/validate-configuration-files.ts index f177bc84901b..3e35a6f2bafb 100644 --- a/code/core/src/common/utils/validate-configuration-files.ts +++ b/code/core/src/common/utils/validate-configuration-files.ts @@ -1,21 +1,23 @@ -import { dedent } from 'ts-dedent'; +import { resolve } from 'node:path'; + +import { once } from '@storybook/core/node-logger'; +import { MainFileMissingError } from '@storybook/core/server-errors'; + import { glob } from 'glob'; -import path from 'node:path'; import slash from 'slash'; -import { once } from '@storybook/core/node-logger'; +import { dedent } from 'ts-dedent'; import { boost } from './interpret-files'; -import { MainFileMissingError } from '@storybook/core/server-errors'; export async function validateConfigurationFiles(configDir: string) { const extensionsPattern = `{${Array.from(boost).join(',')}}`; - const mainConfigMatches = await glob(slash(path.resolve(configDir, `main${extensionsPattern}`))); + const mainConfigMatches = await glob(slash(resolve(configDir, `main${extensionsPattern}`))); const [mainConfigPath] = mainConfigMatches; if (mainConfigMatches.length > 1) { once.warn(dedent` - Multiple main files found in your configDir (${path.resolve(configDir)}). + Multiple main files found in your configDir (${resolve(configDir)}). Storybook will use the first one found and ignore the others. Please remove the extra files. `); } diff --git a/code/core/src/common/versions.ts b/code/core/src/common/versions.ts index aa838eab79cc..051878614fe9 100644 --- a/code/core/src/common/versions.ts +++ b/code/core/src/common/versions.ts @@ -41,6 +41,7 @@ export default { '@storybook/types': '8.3.0-alpha.4', '@storybook/angular': '8.3.0-alpha.4', '@storybook/ember': '8.3.0-alpha.4', + '@storybook/experimental-nextjs-vite': '8.3.0-alpha.4', '@storybook/html-vite': '8.3.0-alpha.4', '@storybook/html-webpack5': '8.3.0-alpha.4', '@storybook/nextjs': '8.3.0-alpha.4', diff --git a/code/core/src/components/components/ActionBar/ActionBar.stories.tsx b/code/core/src/components/components/ActionBar/ActionBar.stories.tsx index 48fa2d56f47a..d5598a36ec1f 100644 --- a/code/core/src/components/components/ActionBar/ActionBar.stories.tsx +++ b/code/core/src/components/components/ActionBar/ActionBar.stories.tsx @@ -1,5 +1,6 @@ import type { ReactNode } from 'react'; import React from 'react'; + import { action } from '@storybook/addon-actions'; import { ActionBar } from './ActionBar'; diff --git a/code/core/src/components/components/Badge/Badge.stories.tsx b/code/core/src/components/components/Badge/Badge.stories.tsx index 974dc64f8be1..4f51422c0f0e 100644 --- a/code/core/src/components/components/Badge/Badge.stories.tsx +++ b/code/core/src/components/components/Badge/Badge.stories.tsx @@ -1,4 +1,5 @@ import type { Meta, StoryObj } from '@storybook/react'; + import { Badge } from './Badge'; const meta = { diff --git a/code/core/src/components/components/Badge/Badge.tsx b/code/core/src/components/components/Badge/Badge.tsx index f5e111cd4c69..a76cbd1121cc 100644 --- a/code/core/src/components/components/Badge/Badge.tsx +++ b/code/core/src/components/components/Badge/Badge.tsx @@ -1,5 +1,7 @@ import React from 'react'; + import { styled } from '@storybook/core/theming'; + import { transparentize } from 'polished'; const BadgeWrapper = styled.div( diff --git a/code/core/src/components/components/Button/Button.deprecated.stories.tsx b/code/core/src/components/components/Button/Button.deprecated.stories.tsx index 009ea9627ab5..ee10af77e39b 100644 --- a/code/core/src/components/components/Button/Button.deprecated.stories.tsx +++ b/code/core/src/components/components/Button/Button.deprecated.stories.tsx @@ -1,8 +1,10 @@ -import type { Meta, StoryObj } from '@storybook/react'; import React from 'react'; + import { LinkIcon } from '@storybook/icons'; -import { Button } from './Button'; +import type { Meta, StoryObj } from '@storybook/react'; + import { Form } from '../form'; +import { Button } from './Button'; const meta: Meta = { title: 'Button (Deprecated)', diff --git a/code/core/src/components/components/Button/Button.stories.tsx b/code/core/src/components/components/Button/Button.stories.tsx index a74ce9e308a6..93407ce8cc8d 100644 --- a/code/core/src/components/components/Button/Button.stories.tsx +++ b/code/core/src/components/components/Button/Button.stories.tsx @@ -1,7 +1,9 @@ -import type { Meta, StoryObj } from '@storybook/react'; import type { ReactNode } from 'react'; import React from 'react'; + import { FaceHappyIcon } from '@storybook/icons'; +import type { Meta, StoryObj } from '@storybook/react'; + import { Button } from './Button'; const meta = { diff --git a/code/core/src/components/components/Button/Button.tsx b/code/core/src/components/components/Button/Button.tsx index 5c9eb88b693f..4e91549a9874 100644 --- a/code/core/src/components/components/Button/Button.tsx +++ b/code/core/src/components/components/Button/Button.tsx @@ -1,10 +1,13 @@ import type { ButtonHTMLAttributes, SyntheticEvent } from 'react'; import React, { forwardRef, useEffect, useState } from 'react'; + import { isPropValid, styled } from '@storybook/core/theming'; -import { darken, lighten, rgba, transparentize } from 'polished'; -import { Slot } from '@radix-ui/react-slot'; + import { deprecate } from '@storybook/core/client-logger'; +import { Slot } from '@radix-ui/react-slot'; +import { darken, lighten, rgba, transparentize } from 'polished'; + export interface ButtonProps extends ButtonHTMLAttributes { asChild?: boolean; size?: 'small' | 'medium'; diff --git a/code/core/src/components/components/ErrorFormatter/ErrorFormatter.stories.tsx b/code/core/src/components/components/ErrorFormatter/ErrorFormatter.stories.tsx index 9038928d27a2..3ffc4e68381d 100644 --- a/code/core/src/components/components/ErrorFormatter/ErrorFormatter.stories.tsx +++ b/code/core/src/components/components/ErrorFormatter/ErrorFormatter.stories.tsx @@ -1,5 +1,7 @@ import React from 'react'; -import type { StoryObj, Meta } from '@storybook/react'; + +import type { Meta, StoryObj } from '@storybook/react'; + import { dedent } from 'ts-dedent'; import { ErrorFormatter } from './ErrorFormatter'; diff --git a/code/core/src/components/components/ErrorFormatter/ErrorFormatter.tsx b/code/core/src/components/components/ErrorFormatter/ErrorFormatter.tsx index 422d0a0ff5ad..b33a4c2f4040 100644 --- a/code/core/src/components/components/ErrorFormatter/ErrorFormatter.tsx +++ b/code/core/src/components/components/ErrorFormatter/ErrorFormatter.tsx @@ -1,7 +1,7 @@ -import { global } from '@storybook/global'; - import React, { Fragment } from 'react'; + import { styled } from '@storybook/core/theming'; +import { global } from '@storybook/global'; const { document } = global; diff --git a/code/core/src/components/components/IconButton/IconButton.stories.tsx b/code/core/src/components/components/IconButton/IconButton.stories.tsx index c3341ac44c92..b7c8584cc150 100644 --- a/code/core/src/components/components/IconButton/IconButton.stories.tsx +++ b/code/core/src/components/components/IconButton/IconButton.stories.tsx @@ -1,6 +1,8 @@ -import type { Meta, StoryObj } from '@storybook/react'; import React from 'react'; + import { FaceHappyIcon } from '@storybook/icons'; +import type { Meta, StoryObj } from '@storybook/react'; + import { IconButton } from './IconButton'; const meta = { diff --git a/code/core/src/components/components/IconButton/IconButton.tsx b/code/core/src/components/components/IconButton/IconButton.tsx index 87088d342b52..31bf06902b36 100644 --- a/code/core/src/components/components/IconButton/IconButton.tsx +++ b/code/core/src/components/components/IconButton/IconButton.tsx @@ -1,4 +1,5 @@ import React, { forwardRef } from 'react'; + import type { ButtonProps } from '../Button/Button'; import { Button } from '../Button/Button'; diff --git a/code/core/src/components/components/Loader/Loader.stories.tsx b/code/core/src/components/components/Loader/Loader.stories.tsx index c4d7b5eb0019..35b3f4cc14a3 100644 --- a/code/core/src/components/components/Loader/Loader.stories.tsx +++ b/code/core/src/components/components/Loader/Loader.stories.tsx @@ -1,4 +1,5 @@ import React from 'react'; + import { Loader } from './Loader'; const withBackground = (storyFn: any) => ( diff --git a/code/core/src/components/components/Loader/Loader.tsx b/code/core/src/components/components/Loader/Loader.tsx index c29130e86b5e..e30812e27286 100644 --- a/code/core/src/components/components/Loader/Loader.tsx +++ b/code/core/src/components/components/Loader/Loader.tsx @@ -1,9 +1,12 @@ -import { transparentize } from 'polished'; import React from 'react'; -import { styled, keyframes } from '@storybook/core/theming'; -import { rotate360 } from '../shared/animation'; + +import { keyframes, styled } from '@storybook/core/theming'; import { LightningOffIcon } from '@storybook/icons'; +import { transparentize } from 'polished'; + +import { rotate360 } from '../shared/animation'; + const LoaderWrapper = styled.div<{ size?: number }>(({ size = 32 }) => ({ borderRadius: '50%', cursor: 'progress', diff --git a/code/core/src/components/components/Modal/Modal.stories.tsx b/code/core/src/components/components/Modal/Modal.stories.tsx index 658683e6368b..0793d24c8db5 100644 --- a/code/core/src/components/components/Modal/Modal.stories.tsx +++ b/code/core/src/components/components/Modal/Modal.stories.tsx @@ -1,9 +1,10 @@ import React, { useState } from 'react'; + import type { Meta, StoryObj } from '@storybook/react'; -import { userEvent, within, expect } from '@storybook/test'; +import { expect, userEvent, within } from '@storybook/test'; -import { Modal } from './Modal'; import { Button } from '../Button/Button'; +import { Modal } from './Modal'; type Story = StoryObj; diff --git a/code/core/src/components/components/Modal/Modal.styled.tsx b/code/core/src/components/components/Modal/Modal.styled.tsx index 4636eea89d80..ca56fb05627e 100644 --- a/code/core/src/components/components/Modal/Modal.styled.tsx +++ b/code/core/src/components/components/Modal/Modal.styled.tsx @@ -1,11 +1,13 @@ -import { keyframes, styled } from '@storybook/core/theming'; -import * as Dialog from '@radix-ui/react-dialog'; import type { ComponentProps } from 'react'; import React from 'react'; -import { IconButton } from '../IconButton/IconButton'; +import { keyframes, styled } from '@storybook/core/theming'; import { CrossIcon } from '@storybook/icons'; +import * as Dialog from '@radix-ui/react-dialog'; + +import { IconButton } from '../IconButton/IconButton'; + const fadeIn = keyframes({ from: { opacity: 0 }, to: { opacity: 1 }, diff --git a/code/core/src/components/components/Modal/Modal.tsx b/code/core/src/components/components/Modal/Modal.tsx index ad5ddaa85b4e..a31f5aa838b6 100644 --- a/code/core/src/components/components/Modal/Modal.tsx +++ b/code/core/src/components/components/Modal/Modal.tsx @@ -1,5 +1,7 @@ import React from 'react'; + import * as Dialog from '@radix-ui/react-dialog'; + import * as Components from './Modal.styled'; type ContentProps = React.ComponentProps; diff --git a/code/core/src/components/components/ScrollArea/ScrollArea.stories.tsx b/code/core/src/components/components/ScrollArea/ScrollArea.stories.tsx index b353f644cec7..134088a66eda 100644 --- a/code/core/src/components/components/ScrollArea/ScrollArea.stories.tsx +++ b/code/core/src/components/components/ScrollArea/ScrollArea.stories.tsx @@ -1,6 +1,8 @@ import type { ReactElement } from 'react'; import React, { Fragment } from 'react'; + import { styled } from '@storybook/core/theming'; + import { ScrollArea } from './ScrollArea'; const Block = styled.span({ diff --git a/code/core/src/components/components/ScrollArea/ScrollArea.tsx b/code/core/src/components/components/ScrollArea/ScrollArea.tsx index 836294b51f3e..aa1dff7b5c24 100644 --- a/code/core/src/components/components/ScrollArea/ScrollArea.tsx +++ b/code/core/src/components/components/ScrollArea/ScrollArea.tsx @@ -1,5 +1,7 @@ import React, { forwardRef } from 'react'; + import { styled } from '@storybook/core/theming'; + import * as ScrollAreaPrimitive from '@radix-ui/react-scroll-area'; export interface ScrollAreaProps { diff --git a/code/core/src/components/components/Zoom/Zoom.stories.tsx b/code/core/src/components/components/Zoom/Zoom.stories.tsx index f4632ece0e4e..b480b78b1925 100644 --- a/code/core/src/components/components/Zoom/Zoom.stories.tsx +++ b/code/core/src/components/components/Zoom/Zoom.stories.tsx @@ -1,5 +1,6 @@ import type { CSSProperties } from 'react'; import React, { useEffect, useState } from 'react'; + import { Zoom } from './Zoom'; export default { diff --git a/code/core/src/components/components/Zoom/ZoomElement.tsx b/code/core/src/components/components/Zoom/ZoomElement.tsx index e67a5f821817..7fb8068a3d60 100644 --- a/code/core/src/components/components/Zoom/ZoomElement.tsx +++ b/code/core/src/components/components/Zoom/ZoomElement.tsx @@ -1,8 +1,10 @@ import type { ReactElement } from 'react'; -import React, { useEffect, useRef, useState, useCallback } from 'react'; +import React, { useCallback, useEffect, useRef, useState } from 'react'; + +import { styled } from '@storybook/core/theming'; + import type { ResizeHandler } from 'use-resize-observer'; import useResizeObserver from 'use-resize-observer'; -import { styled } from '@storybook/core/theming'; const ZoomElementWrapper = styled.div<{ scale: number; elementHeight: number }>( ({ scale = 1, elementHeight }) => ({ diff --git a/code/core/src/components/components/Zoom/ZoomIFrame.tsx b/code/core/src/components/components/Zoom/ZoomIFrame.tsx index 370b2c4e22de..d166d3b96c28 100644 --- a/code/core/src/components/components/Zoom/ZoomIFrame.tsx +++ b/code/core/src/components/components/Zoom/ZoomIFrame.tsx @@ -1,4 +1,4 @@ -import type { RefObject, ReactElement } from 'react'; +import type { ReactElement, RefObject } from 'react'; import React, { Component } from 'react'; export type IZoomIFrameProps = { diff --git a/code/core/src/components/components/addon-panel/addon-panel.tsx b/code/core/src/components/components/addon-panel/addon-panel.tsx index 89e32c0b8592..a34ac48e9efb 100644 --- a/code/core/src/components/components/addon-panel/addon-panel.tsx +++ b/code/core/src/components/components/addon-panel/addon-panel.tsx @@ -1,5 +1,5 @@ import type { ReactNode } from 'react'; -import React, { useRef, useEffect } from 'react'; +import React, { useEffect, useRef } from 'react'; const usePrevious = (value: any) => { const ref = useRef(); diff --git a/code/core/src/components/components/bar/bar.tsx b/code/core/src/components/components/bar/bar.tsx index 933cd65cb524..571d84016620 100644 --- a/code/core/src/components/components/bar/bar.tsx +++ b/code/core/src/components/components/bar/bar.tsx @@ -1,5 +1,6 @@ import type { ComponentProps } from 'react'; import React, { Children } from 'react'; + import { styled } from '@storybook/core/theming'; import type { ScrollAreaProps } from '../ScrollArea/ScrollArea'; diff --git a/code/core/src/components/components/bar/button.tsx b/code/core/src/components/components/bar/button.tsx index 2561f19fa2ae..ef64b7e60647 100644 --- a/code/core/src/components/components/bar/button.tsx +++ b/code/core/src/components/components/bar/button.tsx @@ -2,13 +2,14 @@ import type { AnchorHTMLAttributes, ButtonHTMLAttributes, DetailedHTMLProps, - ForwardedRef, ForwardRefExoticComponent, + ForwardedRef, ReactElement, RefAttributes, } from 'react'; import React, { forwardRef } from 'react'; -import { styled, isPropValid } from '@storybook/core/theming'; + +import { isPropValid, styled } from '@storybook/core/theming'; interface ButtonProps extends DetailedHTMLProps, HTMLButtonElement> { diff --git a/code/core/src/components/components/bar/separator.tsx b/code/core/src/components/components/bar/separator.tsx index 039c4257ad65..dd06697e9af0 100644 --- a/code/core/src/components/components/bar/separator.tsx +++ b/code/core/src/components/components/bar/separator.tsx @@ -1,4 +1,5 @@ import React, { Fragment } from 'react'; + import { styled } from '@storybook/core/theming'; export interface SeparatorProps { diff --git a/code/core/src/components/components/clipboard/ClipboardCode.tsx b/code/core/src/components/components/clipboard/ClipboardCode.tsx index 5954e466f62d..bb9ffd1bf736 100644 --- a/code/core/src/components/components/clipboard/ClipboardCode.tsx +++ b/code/core/src/components/components/clipboard/ClipboardCode.tsx @@ -1,4 +1,5 @@ import React from 'react'; + import { color, styled, typography } from '@storybook/core/theming'; const Code = styled.pre` diff --git a/code/core/src/components/components/form/field/field.tsx b/code/core/src/components/components/form/field/field.tsx index 6ff17740691a..ad43a1388781 100644 --- a/code/core/src/components/components/form/field/field.tsx +++ b/code/core/src/components/components/form/field/field.tsx @@ -1,5 +1,6 @@ import type { ReactNode } from 'react'; import React from 'react'; + import { styled } from '@storybook/core/theming'; const Wrapper = styled.label(({ theme }) => ({ diff --git a/code/core/src/components/components/form/form.stories.tsx b/code/core/src/components/components/form/form.stories.tsx index 45470d60c848..a081368f6db9 100644 --- a/code/core/src/components/components/form/form.stories.tsx +++ b/code/core/src/components/components/form/form.stories.tsx @@ -1,9 +1,11 @@ import React from 'react'; + import { styled } from '@storybook/core/theming'; + import { action } from '@storybook/addon-actions'; -import * as InputComponents from './input/input'; import { Field as FieldComponent } from './field/field'; +import * as InputComponents from './input/input'; const Flexed = styled(FieldComponent)({ display: 'flex' }); diff --git a/code/core/src/components/components/form/index.tsx b/code/core/src/components/components/form/index.tsx index 3407f342a862..4eba4e779f11 100644 --- a/code/core/src/components/components/form/index.tsx +++ b/code/core/src/components/components/form/index.tsx @@ -1,7 +1,8 @@ import { styled } from '@storybook/core/theming'; + +import { Button } from '../Button/Button'; import { Field } from './field/field'; import { Input, Select, Textarea } from './input/input'; -import { Button } from '../Button/Button'; export const Form = Object.assign( styled.form({ diff --git a/code/core/src/components/components/form/input/input.tsx b/code/core/src/components/components/form/input/input.tsx index 423da39326a0..5e037b38fb4f 100644 --- a/code/core/src/components/components/form/input/input.tsx +++ b/code/core/src/components/components/form/input/input.tsx @@ -1,5 +1,6 @@ import type { HTMLProps, SelectHTMLAttributes } from 'react'; import React, { forwardRef } from 'react'; + import type { CSSObject, StorybookTheme } from '@storybook/core/theming'; import { styled } from '@storybook/core/theming'; diff --git a/code/core/src/components/components/icon/icon.stories.tsx b/code/core/src/components/components/icon/icon.stories.tsx index 929319b346a7..acafe6af4425 100644 --- a/code/core/src/components/components/icon/icon.stories.tsx +++ b/code/core/src/components/components/icon/icon.stories.tsx @@ -1,6 +1,7 @@ import type { ComponentProps } from 'react'; import React from 'react'; -import { styled, css } from '@storybook/core/theming'; + +import { css, styled } from '@storybook/core/theming'; import type { IconType } from './icon'; import { Icons, icons } from './icon'; diff --git a/code/core/src/components/components/icon/icon.tsx b/code/core/src/components/components/icon/icon.tsx index ca80a0700954..9e2a52405cd5 100644 --- a/code/core/src/components/components/icon/icon.tsx +++ b/code/core/src/components/components/icon/icon.tsx @@ -1,8 +1,9 @@ import type { ComponentProps } from 'react'; import React, { memo } from 'react'; -import * as StorybookIcons from '@storybook/icons'; import { styled } from '@storybook/core/theming'; +import * as StorybookIcons from '@storybook/icons'; + import { deprecate, logger } from '@storybook/core/client-logger'; export type IconType = keyof typeof icons; diff --git a/code/core/src/components/components/placeholder/placeholder.stories.tsx b/code/core/src/components/components/placeholder/placeholder.stories.tsx index 4e7c53172449..071610125b7f 100644 --- a/code/core/src/components/components/placeholder/placeholder.stories.tsx +++ b/code/core/src/components/components/placeholder/placeholder.stories.tsx @@ -1,7 +1,7 @@ import React, { Fragment } from 'react'; -import { Placeholder } from './placeholder'; import { Link } from '../typography/link/link'; +import { Placeholder } from './placeholder'; export default { component: Placeholder, diff --git a/code/core/src/components/components/placeholder/placeholder.tsx b/code/core/src/components/components/placeholder/placeholder.tsx index 68f1c026d4d2..faa7d1df78b7 100644 --- a/code/core/src/components/components/placeholder/placeholder.tsx +++ b/code/core/src/components/components/placeholder/placeholder.tsx @@ -1,4 +1,5 @@ import React, { Children } from 'react'; + import { styled } from '@storybook/core/theming'; const Title = styled.div(({ theme }) => ({ diff --git a/code/core/src/components/components/spaced/Spaced.stories.tsx b/code/core/src/components/components/spaced/Spaced.stories.tsx index 4c84f6811661..3f342022e3b5 100644 --- a/code/core/src/components/components/spaced/Spaced.stories.tsx +++ b/code/core/src/components/components/spaced/Spaced.stories.tsx @@ -1,5 +1,6 @@ import type { ComponentProps } from 'react'; import React from 'react'; + import { styled } from '@storybook/core/theming'; import { Spaced } from './Spaced'; diff --git a/code/core/src/components/components/spaced/Spaced.tsx b/code/core/src/components/components/spaced/Spaced.tsx index b4a79a919203..4c0afcfb9bfd 100644 --- a/code/core/src/components/components/spaced/Spaced.tsx +++ b/code/core/src/components/components/spaced/Spaced.tsx @@ -1,5 +1,6 @@ import React from 'react'; -import { styled, ignoreSsrWarning } from '@storybook/core/theming'; + +import { ignoreSsrWarning, styled } from '@storybook/core/theming'; const toNumber = (input: any) => (typeof input === 'number' ? input : Number(input)); diff --git a/code/core/src/components/components/syntaxhighlighter/formatter.test.ts b/code/core/src/components/components/syntaxhighlighter/formatter.test.ts index 041cf2148ee1..4c215c977154 100644 --- a/code/core/src/components/components/syntaxhighlighter/formatter.test.ts +++ b/code/core/src/components/components/syntaxhighlighter/formatter.test.ts @@ -1,4 +1,5 @@ -import { describe, it, expect } from 'vitest'; +import { describe, expect, it } from 'vitest'; + import { dedent } from 'ts-dedent'; import { formatter } from './formatter'; diff --git a/code/core/src/components/components/syntaxhighlighter/formatter.ts b/code/core/src/components/components/syntaxhighlighter/formatter.ts index c0ec2d7ad183..7ff96626bc0e 100644 --- a/code/core/src/components/components/syntaxhighlighter/formatter.ts +++ b/code/core/src/components/components/syntaxhighlighter/formatter.ts @@ -1,8 +1,8 @@ import memoize from 'memoizerific'; - import prettierHtml from 'prettier/plugins/html'; import prettier from 'prettier/standalone'; import { dedent } from 'ts-dedent'; + import type { SyntaxHighlighterFormatTypes } from './syntaxhighlighter-types'; export const formatter = memoize(2)(async (type: SyntaxHighlighterFormatTypes, source: string) => { diff --git a/code/core/src/components/components/syntaxhighlighter/lazy-syntaxhighlighter.tsx b/code/core/src/components/components/syntaxhighlighter/lazy-syntaxhighlighter.tsx index 822034aca219..25aacedaafb5 100644 --- a/code/core/src/components/components/syntaxhighlighter/lazy-syntaxhighlighter.tsx +++ b/code/core/src/components/components/syntaxhighlighter/lazy-syntaxhighlighter.tsx @@ -1,6 +1,6 @@ import React, { Suspense, lazy } from 'react'; - import type { ComponentProps } from 'react'; + import type ReactSyntaxHighlighter from './syntaxhighlighter'; let languages: Parameters[] = []; diff --git a/code/core/src/components/components/syntaxhighlighter/syntaxhighlighter-types.ts b/code/core/src/components/components/syntaxhighlighter/syntaxhighlighter-types.ts index d7ec7832df8a..389f966e4968 100644 --- a/code/core/src/components/components/syntaxhighlighter/syntaxhighlighter-types.ts +++ b/code/core/src/components/components/syntaxhighlighter/syntaxhighlighter-types.ts @@ -1,5 +1,7 @@ -import type { BuiltInParserName } from 'prettier'; import type { ReactNode } from 'react'; + +import type { BuiltInParserName } from 'prettier'; + import type { supportedLanguages } from './syntaxhighlighter'; export interface SyntaxHighlighterRendererProps { diff --git a/code/core/src/components/components/syntaxhighlighter/syntaxhighlighter.stories.tsx b/code/core/src/components/components/syntaxhighlighter/syntaxhighlighter.stories.tsx index 4b817b756c79..cd1fbe7af16b 100644 --- a/code/core/src/components/components/syntaxhighlighter/syntaxhighlighter.stories.tsx +++ b/code/core/src/components/components/syntaxhighlighter/syntaxhighlighter.stories.tsx @@ -1,7 +1,8 @@ -import { ThemeProvider, ensure, themes } from '@storybook/core/theming'; - import type { ComponentProps } from 'react'; import React from 'react'; + +import { ThemeProvider, ensure, themes } from '@storybook/core/theming'; + import { SyntaxHighlighter } from './lazy-syntaxhighlighter'; export default { diff --git a/code/core/src/components/components/syntaxhighlighter/syntaxhighlighter.tsx b/code/core/src/components/components/syntaxhighlighter/syntaxhighlighter.tsx index 08a424fe31a0..1c6db28aca22 100644 --- a/code/core/src/components/components/syntaxhighlighter/syntaxhighlighter.tsx +++ b/code/core/src/components/components/syntaxhighlighter/syntaxhighlighter.tsx @@ -1,31 +1,31 @@ import type { MouseEvent } from 'react'; import React, { useCallback, useEffect, useState } from 'react'; -import { logger } from '@storybook/core/client-logger'; + import { styled } from '@storybook/core/theming'; import { global } from '@storybook/global'; -import memoize from 'memoizerific'; -import jsx from 'react-syntax-highlighter/dist/esm/languages/prism/jsx'; +import { logger } from '@storybook/core/client-logger'; + +import memoize from 'memoizerific'; +// @ts-expect-error (Converted from ts-ignore) +import { createElement } from 'react-syntax-highlighter/dist/esm/index'; import bash from 'react-syntax-highlighter/dist/esm/languages/prism/bash'; import css from 'react-syntax-highlighter/dist/esm/languages/prism/css'; +import graphql from 'react-syntax-highlighter/dist/esm/languages/prism/graphql'; // @ts-expect-error (Converted from ts-ignore) import jsExtras from 'react-syntax-highlighter/dist/esm/languages/prism/js-extras'; import json from 'react-syntax-highlighter/dist/esm/languages/prism/json'; -import graphql from 'react-syntax-highlighter/dist/esm/languages/prism/graphql'; -import html from 'react-syntax-highlighter/dist/esm/languages/prism/markup'; +import jsx from 'react-syntax-highlighter/dist/esm/languages/prism/jsx'; import md from 'react-syntax-highlighter/dist/esm/languages/prism/markdown'; -import yml from 'react-syntax-highlighter/dist/esm/languages/prism/yaml'; +import html from 'react-syntax-highlighter/dist/esm/languages/prism/markup'; import tsx from 'react-syntax-highlighter/dist/esm/languages/prism/tsx'; import typescript from 'react-syntax-highlighter/dist/esm/languages/prism/typescript'; - +import yml from 'react-syntax-highlighter/dist/esm/languages/prism/yaml'; import ReactSyntaxHighlighter from 'react-syntax-highlighter/dist/esm/prism-light'; -// @ts-expect-error (Converted from ts-ignore) -import { createElement } from 'react-syntax-highlighter/dist/esm/index'; import { ActionBar } from '../ActionBar/ActionBar'; import type { ScrollAreaProps } from '../ScrollArea/ScrollArea'; import { ScrollArea } from '../ScrollArea/ScrollArea'; - import type { SyntaxHighlighterProps, SyntaxHighlighterRenderer, diff --git a/code/core/src/components/components/tabs/EmptyTabContent.stories.tsx b/code/core/src/components/components/tabs/EmptyTabContent.stories.tsx index e03fa329532b..9c291b9e6299 100644 --- a/code/core/src/components/components/tabs/EmptyTabContent.stories.tsx +++ b/code/core/src/components/components/tabs/EmptyTabContent.stories.tsx @@ -1,9 +1,11 @@ import React from 'react'; -import { EmptyTabContent } from './EmptyTabContent'; -import { DocumentIcon } from '@storybook/icons'; + import { Link } from '@storybook/core/components'; +import { DocumentIcon } from '@storybook/icons'; import type { Meta, StoryObj } from '@storybook/react'; +import { EmptyTabContent } from './EmptyTabContent'; + export default { title: 'TabContentEmpty', component: EmptyTabContent, diff --git a/code/core/src/components/components/tabs/EmptyTabContent.tsx b/code/core/src/components/components/tabs/EmptyTabContent.tsx index 1ce8d5e5a9f8..cdb191e59716 100644 --- a/code/core/src/components/components/tabs/EmptyTabContent.tsx +++ b/code/core/src/components/components/tabs/EmptyTabContent.tsx @@ -1,4 +1,5 @@ import React from 'react'; + import { styled } from '@storybook/core/theming'; const Wrapper = styled.div(({ theme }) => ({ diff --git a/code/core/src/components/components/tabs/tabs.helpers.tsx b/code/core/src/components/components/tabs/tabs.helpers.tsx index 2a26b6651139..90ae4c2c10ab 100644 --- a/code/core/src/components/components/tabs/tabs.helpers.tsx +++ b/code/core/src/components/components/tabs/tabs.helpers.tsx @@ -1,7 +1,9 @@ -import { styled } from '@storybook/core/theming'; import type { FC, PropsWithChildren, ReactChild, ReactElement, ReactNode } from 'react'; import React, { Children } from 'react'; + +import { styled } from '@storybook/core/theming'; import type { Addon_RenderOptions } from '@storybook/core/types'; + import type { TabsProps } from './tabs'; export interface VisuallyHiddenProps { diff --git a/code/core/src/components/components/tabs/tabs.hooks.tsx b/code/core/src/components/components/tabs/tabs.hooks.tsx index d2606644d5a4..be3a8f2060a7 100644 --- a/code/core/src/components/components/tabs/tabs.hooks.tsx +++ b/code/core/src/components/components/tabs/tabs.hooks.tsx @@ -1,12 +1,15 @@ import React, { useCallback, useLayoutEffect, useRef, useState } from 'react'; -import { sanitize } from '@storybook/csf'; + import { styled } from '@storybook/core/theming'; +import { sanitize } from '@storybook/csf'; + import useResizeObserver from 'use-resize-observer'; + import { TabButton } from '../bar/button'; import { TooltipLinkList } from '../tooltip/TooltipLinkList'; +import type { Link } from '../tooltip/TooltipLinkList'; import { WithTooltip } from '../tooltip/WithTooltip'; import type { ChildrenListComplete } from './tabs.helpers'; -import type { Link } from '../tooltip/TooltipLinkList'; const CollapseIcon = styled.span<{ isActive: boolean }>(({ theme, isActive }) => ({ display: 'inline-block', diff --git a/code/core/src/components/components/tabs/tabs.stories.tsx b/code/core/src/components/components/tabs/tabs.stories.tsx index 1958c3e18555..5e23fd7ecb7b 100644 --- a/code/core/src/components/components/tabs/tabs.stories.tsx +++ b/code/core/src/components/components/tabs/tabs.stories.tsx @@ -1,12 +1,15 @@ -import { expect } from '@storybook/test'; import React from 'react'; -import { action } from '@storybook/addon-actions'; -import type { Meta, StoryObj } from '@storybook/react'; -import { within, fireEvent, waitFor, screen, userEvent, findByText } from '@storybook/test'; + import { BottomBarIcon, CloseIcon } from '@storybook/icons'; -import { Tabs, TabsState, TabWrapper } from './tabs'; -import type { ChildrenList } from './tabs.helpers'; +import type { Meta, StoryObj } from '@storybook/react'; +import { expect } from '@storybook/test'; +import { findByText, fireEvent, screen, userEvent, waitFor, within } from '@storybook/test'; + +import { action } from '@storybook/addon-actions'; + import { IconButton } from '../IconButton/IconButton'; +import { TabWrapper, Tabs, TabsState } from './tabs'; +import type { ChildrenList } from './tabs.helpers'; const colours = Array.from(new Array(15), (val, index) => index).map((i) => Math.floor((1 / 15) * i * 16777215) diff --git a/code/core/src/components/components/tabs/tabs.tsx b/code/core/src/components/components/tabs/tabs.tsx index 318fc31c033a..3c8c46c45c1b 100644 --- a/code/core/src/components/components/tabs/tabs.tsx +++ b/code/core/src/components/components/tabs/tabs.tsx @@ -1,14 +1,15 @@ import type { FC, PropsWithChildren, ReactElement, ReactNode, SyntheticEvent } from 'react'; -import React, { useMemo, Component, memo } from 'react'; +import React, { Component, memo, useMemo } from 'react'; + import { styled } from '@storybook/core/theming'; +import type { Addon_RenderOptions } from '@storybook/core/types'; import { sanitize } from '@storybook/csf'; -import type { Addon_RenderOptions } from '@storybook/core/types'; -import { TabButton } from '../bar/button'; import { FlexBar } from '../bar/bar'; -import { childrenToList, VisuallyHidden } from './tabs.helpers'; -import { useList } from './tabs.hooks'; +import { TabButton } from '../bar/button'; import { EmptyTabContent } from './EmptyTabContent'; +import { VisuallyHidden, childrenToList } from './tabs.helpers'; +import { useList } from './tabs.hooks'; const ignoreSsrWarning = '/* emotion-disable-server-rendering-unsafe-selector-warning-please-do-not-use-this-the-warning-exists-for-a-reason */'; diff --git a/code/core/src/components/components/tooltip/ListItem.stories.tsx b/code/core/src/components/components/tooltip/ListItem.stories.tsx index ab68b8444ba8..b85d3ba4c1ab 100644 --- a/code/core/src/components/components/tooltip/ListItem.stories.tsx +++ b/code/core/src/components/components/tooltip/ListItem.stories.tsx @@ -1,5 +1,7 @@ import React, { Fragment } from 'react'; + import { EyeIcon } from '@storybook/icons'; + import ListItem from './ListItem'; export default { diff --git a/code/core/src/components/components/tooltip/ListItem.tsx b/code/core/src/components/components/tooltip/ListItem.tsx index 58528169f165..9e4dc9d75f9b 100644 --- a/code/core/src/components/components/tooltip/ListItem.tsx +++ b/code/core/src/components/components/tooltip/ListItem.tsx @@ -1,6 +1,8 @@ -import type { ReactNode, ComponentProps } from 'react'; +import type { ComponentProps, ReactNode } from 'react'; import React from 'react'; + import { styled } from '@storybook/core/theming'; + import memoize from 'memoizerific'; import { transparentize } from 'polished'; diff --git a/code/core/src/components/components/tooltip/Tooltip.stories.tsx b/code/core/src/components/components/tooltip/Tooltip.stories.tsx index 3ca9e21cfc11..35385c1b447f 100644 --- a/code/core/src/components/components/tooltip/Tooltip.stories.tsx +++ b/code/core/src/components/components/tooltip/Tooltip.stories.tsx @@ -1,6 +1,8 @@ import type { ComponentProps } from 'react'; import React from 'react'; + import { styled } from '@storybook/core/theming'; + import { Tooltip } from './Tooltip'; // Popper would position the tooltip absolutely. We just need to make sure we are pos:rel diff --git a/code/core/src/components/components/tooltip/Tooltip.tsx b/code/core/src/components/components/tooltip/Tooltip.tsx index 83fbebfd1c9c..77a6d4fc9c25 100644 --- a/code/core/src/components/components/tooltip/Tooltip.tsx +++ b/code/core/src/components/components/tooltip/Tooltip.tsx @@ -1,7 +1,8 @@ import React from 'react'; -import memoize from 'memoizerific'; -import { styled, type Color, lighten } from '@storybook/core/theming'; +import { type Color, lighten, styled } from '@storybook/core/theming'; + +import memoize from 'memoizerific'; const match = memoize(1000)((requests, actual, value, fallback = 0) => actual.split('-')[0] === requests ? value : fallback diff --git a/code/core/src/components/components/tooltip/TooltipLinkList.stories.tsx b/code/core/src/components/components/tooltip/TooltipLinkList.stories.tsx index 84186de35444..07f870cc1f24 100644 --- a/code/core/src/components/components/tooltip/TooltipLinkList.stories.tsx +++ b/code/core/src/components/components/tooltip/TooltipLinkList.stories.tsx @@ -1,10 +1,13 @@ import type { FunctionComponent, MouseEvent, PropsWithChildren, ReactElement } from 'react'; import React, { Children, cloneElement } from 'react'; -import { action } from '@storybook/addon-actions'; -import type { Meta, StoryObj } from '@storybook/react'; + import { LinkIcon, LinuxIcon } from '@storybook/icons'; -import { WithTooltip } from './WithTooltip'; +import type { Meta, StoryObj } from '@storybook/react'; + +import { action } from '@storybook/addon-actions'; + import { TooltipLinkList } from './TooltipLinkList'; +import { WithTooltip } from './WithTooltip'; import ellipseUrl from './assets/ellipse.png'; const onLinkClick = action('onLinkClick'); diff --git a/code/core/src/components/components/tooltip/TooltipLinkList.tsx b/code/core/src/components/components/tooltip/TooltipLinkList.tsx index 6f05bf2ec90d..7ab5fabf1961 100644 --- a/code/core/src/components/components/tooltip/TooltipLinkList.tsx +++ b/code/core/src/components/components/tooltip/TooltipLinkList.tsx @@ -1,5 +1,6 @@ import type { SyntheticEvent } from 'react'; import React, { useCallback } from 'react'; + import { styled } from '@storybook/core/theming'; import type { LinkWrapperType, ListItemProps } from './ListItem'; diff --git a/code/core/src/components/components/tooltip/TooltipMessage.stories.tsx b/code/core/src/components/components/tooltip/TooltipMessage.stories.tsx index 9c210eb90bab..c84eb4dcc401 100644 --- a/code/core/src/components/components/tooltip/TooltipMessage.stories.tsx +++ b/code/core/src/components/components/tooltip/TooltipMessage.stories.tsx @@ -1,7 +1,9 @@ import React from 'react'; + import type { Meta } from '@storybook/react'; -import { WithTooltip } from './WithTooltip'; + import { TooltipMessage } from './TooltipMessage'; +import { WithTooltip } from './WithTooltip'; export default { component: TooltipMessage, diff --git a/code/core/src/components/components/tooltip/TooltipMessage.tsx b/code/core/src/components/components/tooltip/TooltipMessage.tsx index 8af15a915013..3882e428fab7 100644 --- a/code/core/src/components/components/tooltip/TooltipMessage.tsx +++ b/code/core/src/components/components/tooltip/TooltipMessage.tsx @@ -1,5 +1,6 @@ import type { ReactNode } from 'react'; import React from 'react'; + import { styled } from '@storybook/core/theming'; import { Link } from '../typography/link/link'; diff --git a/code/core/src/components/components/tooltip/TooltipNote.stories.tsx b/code/core/src/components/components/tooltip/TooltipNote.stories.tsx index 6c1e533edc77..fac7e72347eb 100644 --- a/code/core/src/components/components/tooltip/TooltipNote.stories.tsx +++ b/code/core/src/components/components/tooltip/TooltipNote.stories.tsx @@ -1,6 +1,7 @@ import React from 'react'; -import { WithTooltip } from './WithTooltip'; + import { TooltipNote } from './TooltipNote'; +import { WithTooltip } from './WithTooltip'; export default { component: TooltipNote, diff --git a/code/core/src/components/components/tooltip/TooltipNote.tsx b/code/core/src/components/components/tooltip/TooltipNote.tsx index 2366525b0a5a..6bfde56693d6 100644 --- a/code/core/src/components/components/tooltip/TooltipNote.tsx +++ b/code/core/src/components/components/tooltip/TooltipNote.tsx @@ -1,4 +1,5 @@ import React from 'react'; + import { styled } from '@storybook/core/theming'; const Note = styled.div(({ theme }) => ({ diff --git a/code/core/src/components/components/tooltip/WithTooltip.stories.tsx b/code/core/src/components/components/tooltip/WithTooltip.stories.tsx index 4bfae3be6aad..e5651c50bf7e 100644 --- a/code/core/src/components/components/tooltip/WithTooltip.stories.tsx +++ b/code/core/src/components/components/tooltip/WithTooltip.stories.tsx @@ -1,8 +1,10 @@ -import type { FunctionComponent, ComponentProps } from 'react'; +import type { ComponentProps, FunctionComponent } from 'react'; import React from 'react'; + +import { styled } from '@storybook/core/theming'; import type { StoryObj } from '@storybook/react'; import { expect, screen } from '@storybook/test'; -import { styled } from '@storybook/core/theming'; + import { TooltipMessage } from './TooltipMessage'; import { WithToolTipState as WithTooltip } from './WithTooltip'; diff --git a/code/core/src/components/components/tooltip/WithTooltip.tsx b/code/core/src/components/components/tooltip/WithTooltip.tsx index 63cb4e5d5d74..17628604438b 100644 --- a/code/core/src/components/components/tooltip/WithTooltip.tsx +++ b/code/core/src/components/components/tooltip/WithTooltip.tsx @@ -1,11 +1,13 @@ import type { ComponentProps, ReactNode } from 'react'; -import React, { useCallback, useState, useEffect } from 'react'; +import React, { useCallback, useEffect, useState } from 'react'; import ReactDOM from 'react-dom'; + import { styled } from '@storybook/core/theming'; import { global } from '@storybook/global'; -import type { Config as ReactPopperTooltipConfig, PopperOptions } from 'react-popper-tooltip'; +import type { PopperOptions, Config as ReactPopperTooltipConfig } from 'react-popper-tooltip'; import { usePopperTooltip } from 'react-popper-tooltip'; + import { Tooltip } from './Tooltip'; const { document } = global; diff --git a/code/core/src/components/components/tooltip/lazy-WithTooltip.tsx b/code/core/src/components/components/tooltip/lazy-WithTooltip.tsx index 4bf90edb5f13..336ffdfacf49 100644 --- a/code/core/src/components/components/tooltip/lazy-WithTooltip.tsx +++ b/code/core/src/components/components/tooltip/lazy-WithTooltip.tsx @@ -1,5 +1,5 @@ import type { ComponentProps } from 'react'; -import React, { lazy, Suspense } from 'react'; +import React, { Suspense, lazy } from 'react'; const LazyWithTooltip = lazy(() => import('./WithTooltip').then((mod) => ({ default: mod.WithTooltip })) diff --git a/code/core/src/components/components/typography/ResetWrapper.tsx b/code/core/src/components/components/typography/ResetWrapper.tsx index 5f639a3fa093..09791ce4c325 100644 --- a/code/core/src/components/components/typography/ResetWrapper.tsx +++ b/code/core/src/components/components/typography/ResetWrapper.tsx @@ -1,4 +1,5 @@ import { styled } from '@storybook/core/theming'; + import { withReset } from './lib/common'; /** diff --git a/code/core/src/components/components/typography/components.tsx b/code/core/src/components/components/typography/components.tsx index 4f324b3f7a5c..790a8c025013 100644 --- a/code/core/src/components/components/typography/components.tsx +++ b/code/core/src/components/components/typography/components.tsx @@ -1,20 +1,22 @@ import type { - HTMLAttributes, - DetailedHTMLProps, AnchorHTMLAttributes, BlockquoteHTMLAttributes, + DetailedHTMLProps, + HTMLAttributes, ImgHTMLAttributes, - TableHTMLAttributes, LiHTMLAttributes, OlHTMLAttributes, + TableHTMLAttributes, } from 'react'; import React from 'react'; + import { nameSpaceClassNames } from './DocumentFormatting'; +import { ResetWrapper } from './ResetWrapper'; import { A } from './elements/A'; import { Blockquote } from './elements/Blockquote'; import { Code } from './elements/Code'; -import { Div } from './elements/Div'; import { DL } from './elements/DL'; +import { Div } from './elements/Div'; import { H1 } from './elements/H1'; import { H2 } from './elements/H2'; import { H3 } from './elements/H3'; @@ -28,10 +30,9 @@ import { OL } from './elements/OL'; import { P } from './elements/P'; import { Pre } from './elements/Pre'; import { Span } from './elements/Span'; -import { Table } from './elements/Table'; import { TT } from './elements/TT'; +import { Table } from './elements/Table'; import { UL } from './elements/UL'; -import { ResetWrapper } from './ResetWrapper'; export const components = { h1: (props: DetailedHTMLProps, HTMLHeadingElement>) => ( diff --git a/code/core/src/components/components/typography/elements/A.tsx b/code/core/src/components/components/typography/elements/A.tsx index 28e8ccc082d6..2eb9cdb4d87a 100644 --- a/code/core/src/components/components/typography/elements/A.tsx +++ b/code/core/src/components/components/typography/elements/A.tsx @@ -1,4 +1,5 @@ import { styled } from '@storybook/core/theming'; + import { withReset } from '../lib/common'; import { Link } from './Link'; diff --git a/code/core/src/components/components/typography/elements/Blockquote.tsx b/code/core/src/components/components/typography/elements/Blockquote.tsx index 5692a72aa9f0..b4e06b210ed0 100644 --- a/code/core/src/components/components/typography/elements/Blockquote.tsx +++ b/code/core/src/components/components/typography/elements/Blockquote.tsx @@ -1,5 +1,6 @@ import { styled } from '@storybook/core/theming'; -import { withReset, withMargin } from '../lib/common'; + +import { withMargin, withReset } from '../lib/common'; export const Blockquote = styled.blockquote(withReset, withMargin, ({ theme }) => ({ borderLeft: `4px solid ${theme.color.medium}`, diff --git a/code/core/src/components/components/typography/elements/Code.tsx b/code/core/src/components/components/typography/elements/Code.tsx index 7f67c12e645b..e22b3cca9134 100644 --- a/code/core/src/components/components/typography/elements/Code.tsx +++ b/code/core/src/components/components/typography/elements/Code.tsx @@ -1,10 +1,12 @@ -import { styled } from '@storybook/core/theming'; import type { ComponentProps } from 'react'; import React, { Children } from 'react'; + +import { styled } from '@storybook/core/theming'; + import { SyntaxHighlighter } from '../../syntaxhighlighter/syntaxhighlighter'; -import { isReactChildString } from '../lib/isReactChildString'; -import { codeCommon } from '../lib/common'; import type { SupportedLanguage } from '../../syntaxhighlighter/syntaxhighlighter-types'; +import { codeCommon } from '../lib/common'; +import { isReactChildString } from '../lib/isReactChildString'; const isInlineCodeRegex = /[\n\r]/g; diff --git a/code/core/src/components/components/typography/elements/DL.tsx b/code/core/src/components/components/typography/elements/DL.tsx index 792df46878c3..840dbc0bbede 100644 --- a/code/core/src/components/components/typography/elements/DL.tsx +++ b/code/core/src/components/components/typography/elements/DL.tsx @@ -1,5 +1,6 @@ import { styled } from '@storybook/core/theming'; -import { withReset, withMargin } from '../lib/common'; + +import { withMargin, withReset } from '../lib/common'; export const DL = styled.dl(withReset, withMargin, { padding: 0, diff --git a/code/core/src/components/components/typography/elements/Div.tsx b/code/core/src/components/components/typography/elements/Div.tsx index bf70948dfa1d..7e8b9b6765d4 100644 --- a/code/core/src/components/components/typography/elements/Div.tsx +++ b/code/core/src/components/components/typography/elements/Div.tsx @@ -1,4 +1,5 @@ import { styled } from '@storybook/core/theming'; + import { withReset } from '../lib/common'; export const Div = styled.div(withReset); diff --git a/code/core/src/components/components/typography/elements/H1.tsx b/code/core/src/components/components/typography/elements/H1.tsx index 9b306ab1343b..6ede5882351d 100644 --- a/code/core/src/components/components/typography/elements/H1.tsx +++ b/code/core/src/components/components/typography/elements/H1.tsx @@ -1,5 +1,6 @@ import { styled } from '@storybook/core/theming'; -import { withReset, headerCommon } from '../lib/common'; + +import { headerCommon, withReset } from '../lib/common'; export const H1 = styled.h1(withReset, headerCommon, ({ theme }) => ({ fontSize: `${theme.typography.size.l1}px`, diff --git a/code/core/src/components/components/typography/elements/H2.tsx b/code/core/src/components/components/typography/elements/H2.tsx index 9d17758aefbe..f2c070827ede 100644 --- a/code/core/src/components/components/typography/elements/H2.tsx +++ b/code/core/src/components/components/typography/elements/H2.tsx @@ -1,5 +1,6 @@ import { styled } from '@storybook/core/theming'; -import { withReset, headerCommon } from '../lib/common'; + +import { headerCommon, withReset } from '../lib/common'; export const H2 = styled.h2(withReset, headerCommon, ({ theme }) => ({ fontSize: `${theme.typography.size.m2}px`, diff --git a/code/core/src/components/components/typography/elements/H3.tsx b/code/core/src/components/components/typography/elements/H3.tsx index 6eea8bd27af1..150474aa427e 100644 --- a/code/core/src/components/components/typography/elements/H3.tsx +++ b/code/core/src/components/components/typography/elements/H3.tsx @@ -1,5 +1,6 @@ import { styled } from '@storybook/core/theming'; -import { withReset, headerCommon } from '../lib/common'; + +import { headerCommon, withReset } from '../lib/common'; export const H3 = styled.h3(withReset, headerCommon, ({ theme }) => ({ fontSize: `${theme.typography.size.m1}px`, diff --git a/code/core/src/components/components/typography/elements/H4.tsx b/code/core/src/components/components/typography/elements/H4.tsx index edd0b2639224..f0933727d8ca 100644 --- a/code/core/src/components/components/typography/elements/H4.tsx +++ b/code/core/src/components/components/typography/elements/H4.tsx @@ -1,5 +1,6 @@ import { styled } from '@storybook/core/theming'; -import { withReset, headerCommon } from '../lib/common'; + +import { headerCommon, withReset } from '../lib/common'; export const H4 = styled.h4(withReset, headerCommon, ({ theme }) => ({ fontSize: `${theme.typography.size.s3}px`, diff --git a/code/core/src/components/components/typography/elements/H5.tsx b/code/core/src/components/components/typography/elements/H5.tsx index e06405f19092..637b64cad8f2 100644 --- a/code/core/src/components/components/typography/elements/H5.tsx +++ b/code/core/src/components/components/typography/elements/H5.tsx @@ -1,5 +1,6 @@ import { styled } from '@storybook/core/theming'; -import { withReset, headerCommon } from '../lib/common'; + +import { headerCommon, withReset } from '../lib/common'; export const H5 = styled.h5(withReset, headerCommon, ({ theme }) => ({ fontSize: `${theme.typography.size.s2}px`, diff --git a/code/core/src/components/components/typography/elements/H6.tsx b/code/core/src/components/components/typography/elements/H6.tsx index bbf7b7cbb435..b862026ede75 100644 --- a/code/core/src/components/components/typography/elements/H6.tsx +++ b/code/core/src/components/components/typography/elements/H6.tsx @@ -1,5 +1,6 @@ import { styled } from '@storybook/core/theming'; -import { withReset, headerCommon } from '../lib/common'; + +import { headerCommon, withReset } from '../lib/common'; export const H6 = styled.h6(withReset, headerCommon, ({ theme }) => ({ fontSize: `${theme.typography.size.s2}px`, diff --git a/code/core/src/components/components/typography/elements/LI.tsx b/code/core/src/components/components/typography/elements/LI.tsx index 4b18e602272d..9361defda4e3 100644 --- a/code/core/src/components/components/typography/elements/LI.tsx +++ b/code/core/src/components/components/typography/elements/LI.tsx @@ -1,6 +1,7 @@ import type { CSSObject } from '@storybook/core/theming'; import { styled } from '@storybook/core/theming'; -import { withReset, codeCommon } from '../lib/common'; + +import { codeCommon, withReset } from '../lib/common'; export const LI = styled.li(withReset, ({ theme }) => ({ fontSize: theme.typography.size.s2, diff --git a/code/core/src/components/components/typography/elements/OL.tsx b/code/core/src/components/components/typography/elements/OL.tsx index 50d171003582..dd6c328c72ba 100644 --- a/code/core/src/components/components/typography/elements/OL.tsx +++ b/code/core/src/components/components/typography/elements/OL.tsx @@ -1,6 +1,7 @@ import { styled } from '@storybook/core/theming'; import type { Interpolation } from '@storybook/core/theming'; -import { withReset, withMargin } from '../lib/common'; + +import { withMargin, withReset } from '../lib/common'; const listCommon: Interpolation = { paddingLeft: 30, diff --git a/code/core/src/components/components/typography/elements/P.tsx b/code/core/src/components/components/typography/elements/P.tsx index c24405d69a5c..3039d8592270 100644 --- a/code/core/src/components/components/typography/elements/P.tsx +++ b/code/core/src/components/components/typography/elements/P.tsx @@ -1,6 +1,7 @@ import type { CSSObject } from '@storybook/core/theming'; import { styled } from '@storybook/core/theming'; -import { withReset, withMargin, codeCommon } from '../lib/common'; + +import { codeCommon, withMargin, withReset } from '../lib/common'; export const P = styled.p(withReset, withMargin, ({ theme }) => ({ fontSize: theme.typography.size.s2, diff --git a/code/core/src/components/components/typography/elements/Pre.tsx b/code/core/src/components/components/typography/elements/Pre.tsx index 4792fe8b387b..d2c3a1258cc4 100644 --- a/code/core/src/components/components/typography/elements/Pre.tsx +++ b/code/core/src/components/components/typography/elements/Pre.tsx @@ -1,5 +1,6 @@ import { styled } from '@storybook/core/theming'; -import { withReset, withMargin } from '../lib/common'; + +import { withMargin, withReset } from '../lib/common'; export const Pre = styled.pre(withReset, withMargin, ({ theme }) => ({ // reset diff --git a/code/core/src/components/components/typography/elements/Span.tsx b/code/core/src/components/components/typography/elements/Span.tsx index 3c3a8a119576..35d9e45bd609 100644 --- a/code/core/src/components/components/typography/elements/Span.tsx +++ b/code/core/src/components/components/typography/elements/Span.tsx @@ -1,4 +1,5 @@ import { styled } from '@storybook/core/theming'; + import { withReset } from '../lib/common'; export const Span = styled.span(withReset, ({ theme }) => ({ diff --git a/code/core/src/components/components/typography/elements/TT.tsx b/code/core/src/components/components/typography/elements/TT.tsx index af32c5954423..4544a0b6ded1 100644 --- a/code/core/src/components/components/typography/elements/TT.tsx +++ b/code/core/src/components/components/typography/elements/TT.tsx @@ -1,4 +1,5 @@ import { styled } from '@storybook/core/theming'; + import { codeCommon } from '../lib/common'; export const TT = styled.title(codeCommon); diff --git a/code/core/src/components/components/typography/elements/Table.tsx b/code/core/src/components/components/typography/elements/Table.tsx index d09639884f64..262adddd3f36 100644 --- a/code/core/src/components/components/typography/elements/Table.tsx +++ b/code/core/src/components/components/typography/elements/Table.tsx @@ -1,5 +1,6 @@ import { styled } from '@storybook/core/theming'; -import { withReset, withMargin } from '../lib/common'; + +import { withMargin, withReset } from '../lib/common'; export const Table = styled.table(withReset, withMargin, ({ theme }) => ({ fontSize: theme.typography.size.s2, diff --git a/code/core/src/components/components/typography/elements/UL.tsx b/code/core/src/components/components/typography/elements/UL.tsx index 75bb7d5c9dab..1aeb5b10bb66 100644 --- a/code/core/src/components/components/typography/elements/UL.tsx +++ b/code/core/src/components/components/typography/elements/UL.tsx @@ -1,6 +1,7 @@ import { styled } from '@storybook/core/theming'; import type { Interpolation } from '@storybook/core/theming'; -import { withReset, withMargin } from '../lib/common'; + +import { withMargin, withReset } from '../lib/common'; const listCommon: Interpolation = { paddingLeft: 30, diff --git a/code/core/src/components/components/typography/lib/common.tsx b/code/core/src/components/components/typography/lib/common.tsx index 1cf1ccd9e93c..fc0d32f128b1 100644 --- a/code/core/src/components/components/typography/lib/common.tsx +++ b/code/core/src/components/components/typography/lib/common.tsx @@ -1,6 +1,7 @@ -import { transparentize } from 'polished'; import type { CSSObject, FunctionInterpolation } from '@storybook/core/theming'; +import { transparentize } from 'polished'; + export const headerCommon: FunctionInterpolation = ({ theme }) => ({ margin: '20px 0 8px', padding: 0, diff --git a/code/core/src/components/components/typography/link/link.stories.tsx b/code/core/src/components/components/typography/link/link.stories.tsx index 0ee21b793143..9ac42ec35816 100644 --- a/code/core/src/components/components/typography/link/link.stories.tsx +++ b/code/core/src/components/components/typography/link/link.stories.tsx @@ -1,7 +1,10 @@ import type { ComponentProps } from 'react'; import React from 'react'; -import { action } from '@storybook/addon-actions'; + import { DiscordIcon, SidebarIcon } from '@storybook/icons'; + +import { action } from '@storybook/addon-actions'; + import { Link } from './link'; const onClick = action('onClick'); diff --git a/code/core/src/components/components/typography/link/link.test.tsx b/code/core/src/components/components/typography/link/link.test.tsx index ccf004e87657..5e0af1da2096 100644 --- a/code/core/src/components/components/typography/link/link.test.tsx +++ b/code/core/src/components/components/typography/link/link.test.tsx @@ -1,11 +1,13 @@ // @vitest-environment happy-dom +import { cleanup, render, screen } from '@testing-library/react'; +import userEvent from '@testing-library/user-event'; +import { afterEach, describe, expect, it, vi } from 'vitest'; -import { vi, describe, afterEach, it, expect } from 'vitest'; import type { AnchorHTMLAttributes } from 'react'; import React from 'react'; -import { cleanup, render, screen } from '@testing-library/react'; -import userEvent from '@testing-library/user-event'; -import { ThemeProvider, themes, convert } from '@storybook/core/theming'; + +import { ThemeProvider, convert, themes } from '@storybook/core/theming'; + import type { LinkProps } from './link'; import { Link } from './link'; diff --git a/code/core/src/components/components/typography/link/link.tsx b/code/core/src/components/components/typography/link/link.tsx index adb92701af28..2ce80ec9612e 100644 --- a/code/core/src/components/components/typography/link/link.tsx +++ b/code/core/src/components/components/typography/link/link.tsx @@ -1,9 +1,11 @@ import type { AnchorHTMLAttributes, MouseEvent } from 'react'; import React from 'react'; + import { styled } from '@storybook/core/theming'; -import { darken } from 'polished'; import { ChevronRightIcon } from '@storybook/icons'; +import { darken } from 'polished'; + // Cmd/Ctrl/Shift/Alt + Click should trigger default browser behavior. Same applies to non-left clicks const LEFT_BUTTON = 0; diff --git a/code/core/src/components/index.ts b/code/core/src/components/index.ts index ad14eb46e728..eaf6fef4f609 100644 --- a/code/core/src/components/index.ts +++ b/code/core/src/components/index.ts @@ -1,7 +1,7 @@ /// - import type { ElementType } from 'react'; import { createElement, forwardRef } from 'react'; + import * as typography from './components/typography/components'; export { A } from './components/typography/elements/A'; diff --git a/code/core/src/core-events/index.test.ts b/code/core/src/core-events/index.test.ts index 9ee5d1b0669d..bc3401a71861 100644 --- a/code/core/src/core-events/index.test.ts +++ b/code/core/src/core-events/index.test.ts @@ -1,4 +1,5 @@ -import { describe, it, expect } from 'vitest'; +import { describe, expect, it } from 'vitest'; + import * as EventsPackageExport from './index'; import EventsDefaultExport, { CHANNEL_CREATED } from './index'; diff --git a/code/core/src/core-server/build-dev.ts b/code/core/src/core-server/build-dev.ts index f1c8cd8468c1..fc07aa11ab95 100644 --- a/code/core/src/core-server/build-dev.ts +++ b/code/core/src/core-server/build-dev.ts @@ -1,4 +1,5 @@ -import type { BuilderOptions, CLIOptions, LoadOptions, Options } from '@storybook/core/types'; +import { join, relative, resolve } from 'node:path'; + import { getProjectRoot, loadAllPresets, @@ -8,25 +9,27 @@ import { serverResolve, validateFrameworkName, } from '@storybook/core/common'; -import prompts from 'prompts'; -import invariant from 'tiny-invariant'; -import { global } from '@storybook/global'; import { oneWayHash, telemetry } from '@storybook/core/telemetry'; +import type { BuilderOptions, CLIOptions, LoadOptions, Options } from '@storybook/core/types'; +import { global } from '@storybook/global'; -import { join, relative, resolve } from 'node:path'; import { deprecate } from '@storybook/core/node-logger'; -import { dedent } from 'ts-dedent'; -import { readFile } from 'fs-extra'; import { MissingBuilderError, NoStatsForViteDevError } from '@storybook/core/server-errors'; + +import { readFile } from 'fs-extra'; +import prompts from 'prompts'; +import invariant from 'tiny-invariant'; +import { dedent } from 'ts-dedent'; + import { storybookDevServer } from './dev-server'; -import { outputStats } from './utils/output-stats'; +import { buildOrThrow } from './utils/build-or-throw'; +import { getManagerBuilder, getPreviewBuilder } from './utils/get-builders'; import { outputStartupInformation } from './utils/output-startup-information'; -import { updateCheck } from './utils/update-check'; +import { outputStats } from './utils/output-stats'; import { getServerChannelUrl, getServerPort } from './utils/server-address'; -import { getManagerBuilder, getPreviewBuilder } from './utils/get-builders'; +import { updateCheck } from './utils/update-check'; import { warnOnIncompatibleAddons } from './utils/warnOnIncompatibleAddons'; import { warnWhenUsingArgTypesRegex } from './utils/warnWhenUsingArgTypesRegex'; -import { buildOrThrow } from './utils/build-or-throw'; export async function buildDevStandalone( options: CLIOptions & LoadOptions & BuilderOptions diff --git a/code/core/src/core-server/build-static.ts b/code/core/src/core-server/build-static.ts index 16d7de1036bf..248b2746ea8c 100644 --- a/code/core/src/core-server/build-static.ts +++ b/code/core/src/core-server/build-static.ts @@ -1,10 +1,5 @@ -import chalk from 'chalk'; -import { copy, emptyDir, ensureDir } from 'fs-extra'; import { dirname, join, relative, resolve } from 'node:path'; -import { global } from '@storybook/global'; -import { logger } from '@storybook/core/node-logger'; -import { getPrecedingUpgrade, telemetry } from '@storybook/core/telemetry'; -import type { BuilderOptions, CLIOptions, LoadOptions, Options } from '@storybook/core/types'; + import { loadAllPresets, loadMainConfig, @@ -12,15 +7,23 @@ import { normalizeStories, resolveAddonName, } from '@storybook/core/common'; +import { getPrecedingUpgrade, telemetry } from '@storybook/core/telemetry'; +import type { BuilderOptions, CLIOptions, LoadOptions, Options } from '@storybook/core/types'; +import { global } from '@storybook/global'; -import { outputStats } from './utils/output-stats'; +import { logger } from '@storybook/core/node-logger'; + +import chalk from 'chalk'; +import { copy, emptyDir, ensureDir } from 'fs-extra'; + +import { StoryIndexGenerator } from './utils/StoryIndexGenerator'; +import { buildOrThrow } from './utils/build-or-throw'; import { copyAllStaticFilesRelativeToMain } from './utils/copy-all-static-files'; import { getBuilders } from './utils/get-builders'; -import { extractStoriesJson } from './utils/stories-json'; import { extractStorybookMetadata } from './utils/metadata'; -import { StoryIndexGenerator } from './utils/StoryIndexGenerator'; +import { outputStats } from './utils/output-stats'; +import { extractStoriesJson } from './utils/stories-json'; import { summarizeIndex } from './utils/summarizeIndex'; -import { buildOrThrow } from './utils/build-or-throw'; export type BuildStaticStandaloneOptions = CLIOptions & LoadOptions & diff --git a/code/core/src/core-server/dev-server.ts b/code/core/src/core-server/dev-server.ts index 1639e754fe04..cdf1027d1872 100644 --- a/code/core/src/core-server/dev-server.ts +++ b/code/core/src/core-server/dev-server.ts @@ -1,27 +1,26 @@ -import express from 'express'; -import compression from 'compression'; -import invariant from 'tiny-invariant'; - +import { logConfig } from '@storybook/core/common'; import type { Options } from '@storybook/core/types'; -import { logConfig } from '@storybook/core/common'; import { logger } from '@storybook/core/node-logger'; - import { MissingBuilderError } from '@storybook/core/server-errors'; -import { getMiddleware } from './utils/middleware'; -import { getServerAddresses } from './utils/server-address'; -import { getServer } from './utils/server-init'; -import { useStatics } from './utils/server-statics'; -import { getServerChannel } from './utils/get-server-channel'; -import { openInBrowser } from './utils/open-in-browser'; -import { getManagerBuilder, getPreviewBuilder } from './utils/get-builders'; +import compression from 'compression'; +import express from 'express'; +import invariant from 'tiny-invariant'; + import type { StoryIndexGenerator } from './utils/StoryIndexGenerator'; -import { getStoryIndexGenerator } from './utils/getStoryIndexGenerator'; import { doTelemetry } from './utils/doTelemetry'; -import { router } from './utils/router'; -import { getAccessControlMiddleware } from './utils/getAccessControlMiddleware'; +import { getManagerBuilder, getPreviewBuilder } from './utils/get-builders'; import { getCachingMiddleware } from './utils/get-caching-middleware'; +import { getServerChannel } from './utils/get-server-channel'; +import { getAccessControlMiddleware } from './utils/getAccessControlMiddleware'; +import { getStoryIndexGenerator } from './utils/getStoryIndexGenerator'; +import { getMiddleware } from './utils/middleware'; +import { openInBrowser } from './utils/open-in-browser'; +import { router } from './utils/router'; +import { getServerAddresses } from './utils/server-address'; +import { getServer } from './utils/server-init'; +import { useStatics } from './utils/server-statics'; export async function storybookDevServer(options: Options) { const app = express(); diff --git a/code/core/src/core-server/presets/common-manager.ts b/code/core/src/core-server/presets/common-manager.ts index f12d1d662751..07b11bbaa501 100644 --- a/code/core/src/core-server/presets/common-manager.ts +++ b/code/core/src/core-server/presets/common-manager.ts @@ -1,6 +1,7 @@ -import { addons } from '@storybook/core/manager-api'; import { global } from '@storybook/global'; +import { addons } from '@storybook/core/manager-api'; + const STATIC_FILTER = 'static-filter'; addons.register(STATIC_FILTER, (api) => { diff --git a/code/core/src/core-server/presets/common-override-preset.ts b/code/core/src/core-server/presets/common-override-preset.ts index 83e6ed022ce6..2566bee53593 100644 --- a/code/core/src/core-server/presets/common-override-preset.ts +++ b/code/core/src/core-server/presets/common-override-preset.ts @@ -1,4 +1,5 @@ import type { PresetProperty, TestBuildFlags } from '@storybook/core/types'; + import { removeMDXEntries } from '../utils/remove-mdx-entries'; export const framework: PresetProperty<'framework'> = async (config) => { diff --git a/code/core/src/core-server/presets/common-preset.ts b/code/core/src/core-server/presets/common-preset.ts index 177944e34534..c1b8ca68f88a 100644 --- a/code/core/src/core-server/presets/common-preset.ts +++ b/code/core/src/core-server/presets/common-preset.ts @@ -1,6 +1,6 @@ -import { pathExists, readFile } from 'fs-extra'; -import { logger } from '@storybook/core/node-logger'; -import { telemetry } from '@storybook/core/telemetry'; +import { dirname, isAbsolute, join } from 'node:path'; + +import type { Channel } from '@storybook/core/channels'; import { getDirectoryFromWorkingDir, getPreviewBodyTemplate, @@ -8,24 +8,28 @@ import { loadEnvs, removeAddon as removeAddonBase, } from '@storybook/core/common'; +import { telemetry } from '@storybook/core/telemetry'; import type { CLIOptions, CoreConfig, Indexer, Options, - PresetPropertyFn, PresetProperty, + PresetPropertyFn, } from '@storybook/core/types'; + import { readCsf } from '@storybook/core/csf-tools'; -import { join, dirname, isAbsolute } from 'node:path'; +import { logger } from '@storybook/core/node-logger'; + +import { pathExists, readFile } from 'fs-extra'; import { dedent } from 'ts-dedent'; -import type { Channel } from '@storybook/core/channels'; -import { parseStaticDir } from '../utils/server-statics'; + +import { initCreateNewStoryChannel } from '../server-channel/create-new-story-channel'; +import { initFileSearchChannel } from '../server-channel/file-search-channel'; import { defaultStaticDirs } from '../utils/constants'; -import { initializeWhatsNew, type OptionsWithRequiredCache } from '../utils/whats-new'; import { initializeSaveStory } from '../utils/save-story/save-story'; -import { initFileSearchChannel } from '../server-channel/file-search-channel'; -import { initCreateNewStoryChannel } from '../server-channel/create-new-story-channel'; +import { parseStaticDir } from '../utils/server-statics'; +import { type OptionsWithRequiredCache, initializeWhatsNew } from '../utils/whats-new'; const interpolate = (string: string, data: Record = {}) => Object.entries(data).reduce((acc, [k, v]) => acc.replace(new RegExp(`%${k}%`, 'g'), v), string); diff --git a/code/core/src/core-server/presets/favicon.test.ts b/code/core/src/core-server/presets/favicon.test.ts index 2ba8666cc6a6..7af2bfbfb34d 100644 --- a/code/core/src/core-server/presets/favicon.test.ts +++ b/code/core/src/core-server/presets/favicon.test.ts @@ -1,8 +1,11 @@ -import { expect, vi, it } from 'vitest'; - import { dirname, join } from 'node:path'; -import * as fs from 'fs-extra'; + +import { expect, it, vi } from 'vitest'; + import { logger } from '@storybook/core/node-logger'; + +import * as fs from 'fs-extra'; + import * as m from './common-preset'; const defaultFavicon = join( diff --git a/code/core/src/core-server/server-channel/create-new-story-channel.test.ts b/code/core/src/core-server/server-channel/create-new-story-channel.test.ts index 81b9d74fce93..23fa28dbc870 100644 --- a/code/core/src/core-server/server-channel/create-new-story-channel.test.ts +++ b/code/core/src/core-server/server-channel/create-new-story-channel.test.ts @@ -1,14 +1,18 @@ -import { describe, it, expect, vi, beforeEach } from 'vitest'; -import { initCreateNewStoryChannel } from './create-new-story-channel'; -import path from 'node:path'; +import { join } from 'node:path'; + +import { beforeEach, describe, expect, it, vi } from 'vitest'; + import type { ChannelTransport } from '@storybook/core/channels'; import { Channel } from '@storybook/core/channels'; + import type { CreateNewStoryRequestPayload, RequestData } from '@storybook/core/core-events'; import { CREATE_NEW_STORYFILE_REQUEST, CREATE_NEW_STORYFILE_RESPONSE, } from '@storybook/core/core-events'; +import { initCreateNewStoryChannel } from './create-new-story-channel'; + vi.mock('@storybook/core/common', async (importOriginal) => { const actual = await importOriginal(); return { @@ -52,7 +56,7 @@ describe( initCreateNewStoryChannel( mockChannel, { - configDir: path.join(cwd, '.storybook'), + configDir: join(cwd, '.storybook'), presets: { apply: (val: string) => { if (val === 'framework') { @@ -85,7 +89,7 @@ describe( id: 'components-page--default', payload: { storyId: 'components-page--default', - storyFilePath: path.join('src', 'components', 'Page.stories.jsx'), + storyFilePath: join('src', 'components', 'Page.stories.jsx'), exportedStoryName: 'Default', }, success: true, @@ -103,7 +107,7 @@ describe( initCreateNewStoryChannel( mockChannel, { - configDir: path.join(cwd, '.storybook'), + configDir: join(cwd, '.storybook'), presets: { apply: (val: string) => { if (val === 'framework') { diff --git a/code/core/src/core-server/server-channel/create-new-story-channel.ts b/code/core/src/core-server/server-channel/create-new-story-channel.ts index f30fdf2d57a3..a24dda123806 100644 --- a/code/core/src/core-server/server-channel/create-new-story-channel.ts +++ b/code/core/src/core-server/server-channel/create-new-story-channel.ts @@ -1,6 +1,11 @@ -import type { CoreConfig, Options } from '@storybook/core/types'; +import { existsSync } from 'node:fs'; +import { writeFile } from 'node:fs/promises'; +import { relative } from 'node:path'; + import type { Channel } from '@storybook/core/channels'; import { telemetry } from '@storybook/core/telemetry'; +import type { CoreConfig, Options } from '@storybook/core/types'; + import type { CreateNewStoryErrorPayload, CreateNewStoryRequestPayload, @@ -12,11 +17,9 @@ import { CREATE_NEW_STORYFILE_REQUEST, CREATE_NEW_STORYFILE_RESPONSE, } from '@storybook/core/core-events'; -import { writeFile } from 'node:fs/promises'; -import { existsSync } from 'node:fs'; + import { getNewStoryFile } from '../utils/get-new-story-file'; import { getStoryId } from '../utils/get-story-id'; -import path from 'node:path'; export function initCreateNewStoryChannel( channel: Channel, @@ -35,7 +38,7 @@ export function initCreateNewStoryChannel( options ); - const relativeStoryFilePath = path.relative(process.cwd(), storyFilePath); + const relativeStoryFilePath = relative(process.cwd(), storyFilePath); const { storyId, kind } = await getStoryId({ storyFilePath, exportedStoryName }, options); @@ -67,7 +70,7 @@ export function initCreateNewStoryChannel( id: data.id, payload: { storyId, - storyFilePath: path.relative(process.cwd(), storyFilePath), + storyFilePath: relative(process.cwd(), storyFilePath), exportedStoryName, }, error: null, diff --git a/code/core/src/core-server/server-channel/file-search-channel.test.ts b/code/core/src/core-server/server-channel/file-search-channel.test.ts index bb27cfcb1e0d..5594b8a844b4 100644 --- a/code/core/src/core-server/server-channel/file-search-channel.test.ts +++ b/code/core/src/core-server/server-channel/file-search-channel.test.ts @@ -1,13 +1,14 @@ // @vitest-environment happy-dom +import { beforeEach, describe, expect, it, vi } from 'vitest'; import type { ChannelTransport } from '@storybook/core/channels'; import { Channel } from '@storybook/core/channels'; -import type { RequestData, FileComponentSearchRequestPayload } from '@storybook/core/core-events'; + +import type { FileComponentSearchRequestPayload, RequestData } from '@storybook/core/core-events'; import { - FILE_COMPONENT_SEARCH_RESPONSE, FILE_COMPONENT_SEARCH_REQUEST, + FILE_COMPONENT_SEARCH_RESPONSE, } from '@storybook/core/core-events'; -import { beforeEach, describe, expect, vi, it } from 'vitest'; import { initFileSearchChannel } from './file-search-channel'; diff --git a/code/core/src/core-server/server-channel/file-search-channel.ts b/code/core/src/core-server/server-channel/file-search-channel.ts index aaf6af62af35..31f62a909e18 100644 --- a/code/core/src/core-server/server-channel/file-search-channel.ts +++ b/code/core/src/core-server/server-channel/file-search-channel.ts @@ -1,15 +1,15 @@ -import type { CoreConfig, Options, SupportedRenderers } from '@storybook/core/types'; +import { readFile } from 'node:fs/promises'; +import { dirname, join } from 'node:path'; + import type { Channel } from '@storybook/core/channels'; import { extractProperRendererNameFromFramework, getFrameworkName, getProjectRoot, } from '@storybook/core/common'; -import path from 'node:path'; -import fs from 'fs/promises'; +import { telemetry } from '@storybook/core/telemetry'; +import type { CoreConfig, Options, SupportedRenderers } from '@storybook/core/types'; -import { getParser } from '../utils/parser'; -import { searchFiles } from '../utils/search-files'; import type { FileComponentSearchRequestPayload, FileComponentSearchResponsePayload, @@ -20,8 +20,10 @@ import { FILE_COMPONENT_SEARCH_REQUEST, FILE_COMPONENT_SEARCH_RESPONSE, } from '@storybook/core/core-events'; + import { doesStoryFileExist, getStoryMetadata } from '../utils/get-new-story-file'; -import { telemetry } from '@storybook/core/telemetry'; +import { getParser } from '../utils/parser'; +import { searchFiles } from '../utils/search-files'; export async function initFileSearchChannel( channel: Channel, @@ -57,14 +59,11 @@ export async function initFileSearchChannel( const parser = getParser(rendererName); try { - const content = await fs.readFile(path.join(projectRoot, file), 'utf-8'); - const { storyFileName } = getStoryMetadata(path.join(projectRoot, file)); - const dirname = path.dirname(file); - - const storyFileExists = doesStoryFileExist( - path.join(projectRoot, dirname), - storyFileName - ); + const content = await readFile(join(projectRoot, file), 'utf-8'); + const { storyFileName } = getStoryMetadata(join(projectRoot, file)); + const dir = dirname(file); + + const storyFileExists = doesStoryFileExist(join(projectRoot, dir), storyFileName); const info = await parser.parse(content); diff --git a/code/core/src/core-server/standalone.ts b/code/core/src/core-server/standalone.ts index 72a98d617112..d79463578146 100644 --- a/code/core/src/core-server/standalone.ts +++ b/code/core/src/core-server/standalone.ts @@ -1,7 +1,8 @@ -import { buildStaticStandalone } from './build-static'; -import { buildDevStandalone } from './build-dev'; import { dirname } from 'node:path'; +import { buildDevStandalone } from './build-dev'; +import { buildStaticStandalone } from './build-static'; + async function build(options: any = {}, frameworkOptions: any = {}) { const { mode = 'dev' } = options; const packageJsonDir = dirname(require.resolve('@storybook/core/package.json')); diff --git a/code/core/src/core-server/utils/StoryIndexGenerator.test.ts b/code/core/src/core-server/utils/StoryIndexGenerator.test.ts index e07b46ba83af..f199c05cfe7f 100644 --- a/code/core/src/core-server/utils/StoryIndexGenerator.test.ts +++ b/code/core/src/core-server/utils/StoryIndexGenerator.test.ts @@ -1,17 +1,18 @@ /* eslint-disable @typescript-eslint/no-shadow */ +import { join } from 'node:path'; -import { describe, beforeEach, it, expect, vi } from 'vitest'; +import { beforeEach, describe, expect, it, vi } from 'vitest'; -import path from 'node:path'; import { normalizeStoriesEntry } from '@storybook/core/common'; import type { NormalizedStoriesSpecifier, StoryIndexEntry } from '@storybook/core/types'; -import { readCsf, getStorySortParameter } from '@storybook/core/csf-tools'; import { toId } from '@storybook/csf'; + +import { getStorySortParameter, readCsf } from '@storybook/core/csf-tools'; import { logger, once } from '@storybook/core/node-logger'; +import { csfIndexer } from '../presets/common-preset'; import type { StoryIndexGeneratorOptions } from './StoryIndexGenerator'; import { StoryIndexGenerator } from './StoryIndexGenerator'; -import { csfIndexer } from '../presets/common-preset'; vi.mock('@storybook/csf', async (importOriginal) => { const csf = await importOriginal(); @@ -37,8 +38,8 @@ const readCsfMock = vi.mocked(readCsf); const getStorySortParameterMock = vi.mocked(getStorySortParameter); const options: StoryIndexGeneratorOptions = { - configDir: path.join(__dirname, '__mockdata__'), - workingDir: path.join(__dirname, '__mockdata__'), + configDir: join(__dirname, '__mockdata__'), + workingDir: join(__dirname, '__mockdata__'), indexers: [csfIndexer], docs: { defaultName: 'docs', autodocs: false }, }; @@ -94,6 +95,7 @@ describe('StoryIndexGenerator', () => { expect(stats).toMatchInlineSnapshot(` { "beforeEach": 0, + "globals": 0, "loaders": 0, "moduleMock": 0, "mount": 0, @@ -461,6 +463,7 @@ describe('StoryIndexGenerator', () => { expect(stats).toMatchInlineSnapshot(` { "beforeEach": 1, + "globals": 0, "loaders": 1, "moduleMock": 0, "mount": 1, @@ -725,6 +728,7 @@ describe('StoryIndexGenerator', () => { expect(stats).toMatchInlineSnapshot(` { "beforeEach": 1, + "globals": 0, "loaders": 1, "moduleMock": 0, "mount": 1, diff --git a/code/core/src/core-server/utils/StoryIndexGenerator.ts b/code/core/src/core-server/utils/StoryIndexGenerator.ts index 64aa9744e00e..1a86ac9e3ba7 100644 --- a/code/core/src/core-server/utils/StoryIndexGenerator.ts +++ b/code/core/src/core-server/utils/StoryIndexGenerator.ts @@ -1,34 +1,37 @@ /* eslint-disable no-underscore-dangle */ -import path from 'node:path'; -import chalk from 'chalk'; -import fs from 'fs-extra'; -import slash from 'slash'; -import invariant from 'tiny-invariant'; -import * as TsconfigPaths from 'tsconfig-paths'; -import { findUp } from 'find-up'; +import { dirname, extname, join, normalize, relative, resolve, sep } from 'node:path'; +import { commonGlobOptions, normalizeStoryPath } from '@storybook/core/common'; import type { - IndexEntry, - StoryIndexEntry, DocsIndexEntry, - NormalizedStoriesSpecifier, DocsOptions, + IndexEntry, + IndexInputStats, + Indexer, + NormalizedStoriesSpecifier, Path, - Tag, StoryIndex, - Indexer, + StoryIndexEntry, StorybookConfigRaw, - IndexInputStats, + Tag, } from '@storybook/core/types'; -import { userOrAutoTitleFromSpecifier, sortStoriesV7 } from '@storybook/core/preview-api'; -import { commonGlobOptions, normalizeStoryPath } from '@storybook/core/common'; -import { logger, once } from '@storybook/core/node-logger'; +import { combineTags, storyNameFromExport, toId } from '@storybook/csf'; + import { getStorySortParameter, loadConfig } from '@storybook/core/csf-tools'; -import { storyNameFromExport, toId, combineTags } from '@storybook/csf'; +import { logger, once } from '@storybook/core/node-logger'; +import { sortStoriesV7, userOrAutoTitleFromSpecifier } from '@storybook/core/preview-api'; + +import chalk from 'chalk'; +import { findUp } from 'find-up'; +import fs from 'fs-extra'; +import slash from 'slash'; +import invariant from 'tiny-invariant'; import { dedent } from 'ts-dedent'; -import { autoName } from './autoName'; +import * as TsconfigPaths from 'tsconfig-paths'; + import { IndexingError, MultipleIndexingError } from './IndexingError'; -import { addStats, type IndexStatsSummary } from './summarizeStats'; +import { autoName } from './autoName'; +import { type IndexStatsSummary, addStats } from './summarizeStats'; // Extended type to keep track of the csf meta id so we know the component id when referencing docs in `extractDocs` type StoryIndexEntryWithExtra = StoryIndexEntry & { @@ -69,12 +72,7 @@ export function isMdxEntry({ tags }: DocsIndexEntry) { const makeAbsolute = (otherImport: Path, normalizedPath: Path, workingDir: Path) => otherImport.startsWith('.') - ? slash( - path.resolve( - workingDir, - normalizeStoryPath(path.join(path.dirname(normalizedPath), otherImport)) - ) - ) + ? slash(resolve(workingDir, normalizeStoryPath(join(dirname(normalizedPath), otherImport)))) : otherImport; /** @@ -127,7 +125,7 @@ export class StoryIndexGenerator { this.specifiers.map(async (specifier) => { const pathToSubIndex = {} as SpecifierStoriesCache; - const fullGlob = slash(path.join(specifier.directory, specifier.files)); + const fullGlob = slash(join(specifier.directory, specifier.files)); // Dynamically import globby because it is a pure ESM module const { globby } = await import('globby'); @@ -141,15 +139,15 @@ export class StoryIndexGenerator { if (files.length === 0) { once.warn( `No story files found for the specified pattern: ${chalk.blue( - path.join(specifier.directory, specifier.files) + join(specifier.directory, specifier.files) )}` ); } files.sort().forEach((absolutePath: Path) => { - const ext = path.extname(absolutePath); + const ext = extname(absolutePath); if (ext === '.storyshot') { - const relativePath = path.relative(this.options.workingDir, absolutePath); + const relativePath = relative(this.options.workingDir, absolutePath); logger.info(`Skipping ${ext} file ${relativePath}`); return; } @@ -201,10 +199,7 @@ export class StoryIndexGenerator { try { entry[absolutePath] = await updater(specifier, absolutePath, entry[absolutePath]); } catch (err) { - const relativePath = `.${path.sep}${path.relative( - this.options.workingDir, - absolutePath - )}`; + const relativePath = `.${sep}${relative(this.options.workingDir, absolutePath)}`; entry[absolutePath] = { type: 'error', @@ -298,7 +293,7 @@ export class StoryIndexGenerator { * the same format as `importPath`. Respect tsconfig paths if available. * * If no such file exists, assume that the import is from a package and - * return the raw path. + * return the raw */ resolveComponentPath( rawComponentPath: Path, @@ -310,12 +305,12 @@ export class StoryIndexGenerator { rawPath = matchPath(rawPath) ?? rawPath; } - const absoluteComponentPath = path.resolve(path.dirname(absolutePath), rawPath); + const absoluteComponentPath = resolve(dirname(absolutePath), rawPath); const existing = ['', '.js', '.ts', '.jsx', '.tsx', '.mjs', '.mts'] .map((ext) => `${absoluteComponentPath}${ext}`) .find((candidate) => fs.existsSync(candidate)); if (existing) { - const relativePath = path.relative(this.options.workingDir, existing); + const relativePath = relative(this.options.workingDir, existing); return slash(normalizeStoryPath(relativePath)); } @@ -327,7 +322,7 @@ export class StoryIndexGenerator { absolutePath: Path, projectTags: Tag[] = [] ): Promise { - const relativePath = path.relative(this.options.workingDir, absolutePath); + const relativePath = relative(this.options.workingDir, absolutePath); const importPath = slash(normalizeStoryPath(relativePath)); const defaultMakeTitle = (userTitle?: string) => { const title = userOrAutoTitleFromSpecifier(importPath, specifier, userTitle); @@ -416,7 +411,7 @@ export class StoryIndexGenerator { absolutePath: Path, projectTags: Tag[] = [] ) { - const relativePath = path.relative(this.options.workingDir, absolutePath); + const relativePath = relative(this.options.workingDir, absolutePath); try { const normalizedPath = normalizeStoryPath(relativePath); const importPath = slash(normalizedPath); @@ -452,9 +447,9 @@ export class StoryIndexGenerator { const first = dep.entries.find((e) => e.type !== 'docs') as StoryIndexEntryWithExtra; if ( - path - .normalize(path.resolve(this.options.workingDir, first.importPath)) - .startsWith(path.normalize(absoluteOf)) + normalize(resolve(this.options.workingDir, first.importPath)).startsWith( + normalize(absoluteOf) + ) ) { csfEntry = first; } @@ -682,7 +677,7 @@ export class StoryIndexGenerator { } invalidate(specifier: NormalizedStoriesSpecifier, importPath: Path, removed: boolean) { - const absolutePath = slash(path.resolve(this.options.workingDir, importPath)); + const absolutePath = slash(resolve(this.options.workingDir, importPath)); const cache = this.specifierToCache.get(specifier); invariant( cache, @@ -710,7 +705,7 @@ export class StoryIndexGenerator { if (removed) { if (cacheEntry && cacheEntry.type === 'docs') { const absoluteImports = cacheEntry.storiesImports.map((p) => - path.resolve(this.options.workingDir, p) + resolve(this.options.workingDir, p) ); const dependencies = this.findDependencies(absoluteImports); dependencies.forEach((dep) => @@ -727,7 +722,7 @@ export class StoryIndexGenerator { async getPreviewCode() { const previewFile = ['js', 'jsx', 'ts', 'tsx', 'mjs', 'cjs', 'mts'] - .map((ext) => path.join(this.options.configDir, `preview.${ext}`)) + .map((ext) => join(this.options.configDir, `preview.${ext}`)) .find((fname) => fs.existsSync(fname)); return previewFile && (await fs.readFile(previewFile, 'utf-8')).toString(); diff --git a/code/core/src/core-server/utils/__tests__/IndexingError.test.ts b/code/core/src/core-server/utils/__tests__/IndexingError.test.ts index 20154aa4250b..ad228d2dbb22 100644 --- a/code/core/src/core-server/utils/__tests__/IndexingError.test.ts +++ b/code/core/src/core-server/utils/__tests__/IndexingError.test.ts @@ -1,4 +1,5 @@ -import { describe, it, expect } from 'vitest'; +import { describe, expect, it } from 'vitest'; + import { IndexingError, MultipleIndexingError } from '../IndexingError'; it('formats single file errors', () => { diff --git a/code/core/src/core-server/utils/__tests__/autoName.test.ts b/code/core/src/core-server/utils/__tests__/autoName.test.ts index 64954fc55d17..273178340f2a 100644 --- a/code/core/src/core-server/utils/__tests__/autoName.test.ts +++ b/code/core/src/core-server/utils/__tests__/autoName.test.ts @@ -1,4 +1,5 @@ -import { it, expect } from 'vitest'; +import { expect, it } from 'vitest'; + import { autoName } from '../autoName'; it('pulls name from named MDX files', () => { diff --git a/code/core/src/core-server/utils/__tests__/index-extraction.test.ts b/code/core/src/core-server/utils/__tests__/index-extraction.test.ts index 6fbbdeb41c6c..8377cdb18e2d 100644 --- a/code/core/src/core-server/utils/__tests__/index-extraction.test.ts +++ b/code/core/src/core-server/utils/__tests__/index-extraction.test.ts @@ -1,6 +1,7 @@ -import { describe, it, expect, vi } from 'vitest'; +import { join } from 'node:path'; + +import { describe, expect, it, vi } from 'vitest'; -import path from 'node:path'; import { normalizeStoriesEntry } from '@storybook/core/common'; import type { NormalizedStoriesSpecifier } from '@storybook/core/types'; @@ -10,8 +11,8 @@ import { AUTODOCS_TAG, StoryIndexGenerator } from '../StoryIndexGenerator'; vi.mock('@storybook/core/node-logger'); const options: StoryIndexGeneratorOptions = { - configDir: path.join(__dirname, '..', '__mockdata__'), - workingDir: path.join(__dirname, '..', '__mockdata__'), + configDir: join(__dirname, '..', '__mockdata__'), + workingDir: join(__dirname, '..', '__mockdata__'), indexers: [], docs: { defaultName: 'docs', autodocs: false }, }; @@ -19,7 +20,7 @@ const options: StoryIndexGeneratorOptions = { describe('story extraction', () => { it('extracts stories from full indexer inputs', async () => { const relativePath = './src/A.stories.js'; - const absolutePath = path.join(options.workingDir, relativePath); + const absolutePath = join(options.workingDir, relativePath); const specifier: NormalizedStoriesSpecifier = normalizeStoriesEntry(relativePath, options); const generator = new StoryIndexGenerator([specifier], { @@ -98,7 +99,7 @@ describe('story extraction', () => { it('extracts stories from minimal indexer inputs', async () => { const relativePath = './src/first-nested/deeply/F.stories.js'; - const absolutePath = path.join(options.workingDir, relativePath); + const absolutePath = join(options.workingDir, relativePath); const specifier: NormalizedStoriesSpecifier = normalizeStoriesEntry(relativePath, options); const generator = new StoryIndexGenerator([specifier], { @@ -143,7 +144,7 @@ describe('story extraction', () => { it('auto-generates title from indexer inputs without title', async () => { const relativePath = './src/first-nested/deeply/F.stories.js'; - const absolutePath = path.join(options.workingDir, relativePath); + const absolutePath = join(options.workingDir, relativePath); const specifier: NormalizedStoriesSpecifier = normalizeStoriesEntry(relativePath, options); const generator = new StoryIndexGenerator([specifier], { @@ -194,7 +195,7 @@ describe('story extraction', () => { it('auto-generates name from indexer inputs without name', async () => { const relativePath = './src/A.stories.js'; - const absolutePath = path.join(options.workingDir, relativePath); + const absolutePath = join(options.workingDir, relativePath); const specifier: NormalizedStoriesSpecifier = normalizeStoriesEntry(relativePath, options); const generator = new StoryIndexGenerator([specifier], { @@ -245,7 +246,7 @@ describe('story extraction', () => { it('auto-generates id', async () => { const relativePath = './src/A.stories.js'; - const absolutePath = path.join(options.workingDir, relativePath); + const absolutePath = join(options.workingDir, relativePath); const specifier: NormalizedStoriesSpecifier = normalizeStoriesEntry(relativePath, options); const generator = new StoryIndexGenerator([specifier], { @@ -344,7 +345,7 @@ describe('story extraction', () => { it('auto-generates id, title and name from exportName input', async () => { const relativePath = './src/A.stories.js'; - const absolutePath = path.join(options.workingDir, relativePath); + const absolutePath = join(options.workingDir, relativePath); const specifier: NormalizedStoriesSpecifier = normalizeStoriesEntry(relativePath, options); const generator = new StoryIndexGenerator([specifier], { @@ -393,7 +394,7 @@ describe('story extraction', () => { describe('docs entries from story extraction', () => { it('adds docs entry when autodocs is globally enabled', async () => { const relativePath = './src/A.stories.js'; - const absolutePath = path.join(options.workingDir, relativePath); + const absolutePath = join(options.workingDir, relativePath); const specifier: NormalizedStoriesSpecifier = normalizeStoriesEntry(relativePath, options); const generator = new StoryIndexGenerator([specifier], { @@ -444,7 +445,7 @@ describe('docs entries from story extraction', () => { }); it(`adds docs entry when autodocs is "tag" and an entry has the "${AUTODOCS_TAG}" tag`, async () => { const relativePath = './src/A.stories.js'; - const absolutePath = path.join(options.workingDir, relativePath); + const absolutePath = join(options.workingDir, relativePath); const specifier: NormalizedStoriesSpecifier = normalizeStoriesEntry(relativePath, options); const generator = new StoryIndexGenerator([specifier], { @@ -508,7 +509,7 @@ describe('docs entries from story extraction', () => { }); it(`DOES NOT adds docs entry when autodocs is false and an entry has the "${AUTODOCS_TAG}" tag`, async () => { const relativePath = './src/A.stories.js'; - const absolutePath = path.join(options.workingDir, relativePath); + const absolutePath = join(options.workingDir, relativePath); const specifier: NormalizedStoriesSpecifier = normalizeStoriesEntry(relativePath, options); const generator = new StoryIndexGenerator([specifier], { diff --git a/code/core/src/core-server/utils/__tests__/remove-mdx-stories.test.ts b/code/core/src/core-server/utils/__tests__/remove-mdx-stories.test.ts index 2dff9f7810e4..f1342ad48a9a 100644 --- a/code/core/src/core-server/utils/__tests__/remove-mdx-stories.test.ts +++ b/code/core/src/core-server/utils/__tests__/remove-mdx-stories.test.ts @@ -1,9 +1,13 @@ -import { glob as globOriginal } from 'glob'; -import { type StoriesEntry } from '@storybook/core/types'; -import { normalizeStoriesEntry } from '@storybook/core/common'; import { join } from 'node:path'; + +import { describe, expect, it, vi } from 'vitest'; + +import { normalizeStoriesEntry } from '@storybook/core/common'; +import { type StoriesEntry } from '@storybook/core/types'; + +import { glob as globOriginal } from 'glob'; import slash from 'slash'; -import { vi, it, describe, expect } from 'vitest'; + import { removeMDXEntries } from '../remove-mdx-entries'; const configDir = '/configDir/'; diff --git a/code/core/src/core-server/utils/__tests__/server-address.test.ts b/code/core/src/core-server/utils/__tests__/server-address.test.ts index 4b3636ee9e84..cc9b3dfa6f53 100644 --- a/code/core/src/core-server/utils/__tests__/server-address.test.ts +++ b/code/core/src/core-server/utils/__tests__/server-address.test.ts @@ -1,5 +1,7 @@ -import { describe, beforeEach, it, expect, vi } from 'vitest'; +import { beforeEach, describe, expect, it, vi } from 'vitest'; + import os, { type NetworkInterfaceInfoIPv4 } from 'os'; + import { getServerAddresses } from '../server-address'; vi.mock('os'); diff --git a/code/core/src/core-server/utils/__tests__/server-channel.test.ts b/code/core/src/core-server/utils/__tests__/server-channel.test.ts index 0078b6d78cfa..c43955bd5886 100644 --- a/code/core/src/core-server/utils/__tests__/server-channel.test.ts +++ b/code/core/src/core-server/utils/__tests__/server-channel.test.ts @@ -1,10 +1,12 @@ -import { describe, expect, vi, it } from 'vitest'; -import type { Server } from 'http'; +import { describe, expect, it, vi } from 'vitest'; + import { Channel } from '@storybook/core/channels'; import { EventEmitter } from 'events'; +import type { Server } from 'http'; import { stringify } from 'telejson'; -import { getServerChannel, ServerChannelTransport } from '../get-server-channel'; + +import { ServerChannelTransport, getServerChannel } from '../get-server-channel'; describe('getServerChannel', () => { it('should return a channel', () => { diff --git a/code/core/src/core-server/utils/__tests__/server-statics.test.ts b/code/core/src/core-server/utils/__tests__/server-statics.test.ts index 7033bec57704..ca532a8b04f9 100644 --- a/code/core/src/core-server/utils/__tests__/server-statics.test.ts +++ b/code/core/src/core-server/utils/__tests__/server-statics.test.ts @@ -1,6 +1,9 @@ -import { describe, it, expect, vi, beforeEach } from 'vitest'; +import { resolve } from 'node:path'; + +import { beforeEach, describe, expect, it, vi } from 'vitest'; + import fs from 'fs-extra'; -import path from 'node:path'; + import { onlyWindows, skipWindows } from '../../../../../vitest.helpers'; import { parseStaticDir } from '../server-statics'; @@ -16,14 +19,14 @@ describe('parseStaticDir', () => { it('returns the static dir/path and default target', async () => { await expect(parseStaticDir('public')).resolves.toEqual({ staticDir: './public', - staticPath: path.resolve('public'), + staticPath: resolve('public'), targetDir: './', targetEndpoint: '/', }); await expect(parseStaticDir('foo/bar')).resolves.toEqual({ staticDir: './foo/bar', - staticPath: path.resolve('foo/bar'), + staticPath: resolve('foo/bar'), targetDir: './', targetEndpoint: '/', }); @@ -32,14 +35,14 @@ describe('parseStaticDir', () => { it('returns the static dir/path and custom target', async () => { await expect(parseStaticDir('public:/custom-endpoint')).resolves.toEqual({ staticDir: './public', - staticPath: path.resolve('public'), + staticPath: resolve('public'), targetDir: './custom-endpoint', targetEndpoint: '/custom-endpoint', }); await expect(parseStaticDir('foo/bar:/custom-endpoint')).resolves.toEqual({ staticDir: './foo/bar', - staticPath: path.resolve('foo/bar'), + staticPath: resolve('foo/bar'), targetDir: './custom-endpoint', targetEndpoint: '/custom-endpoint', }); @@ -56,7 +59,7 @@ describe('parseStaticDir', () => { it('checks that the path exists', async () => { // @ts-expect-error for some reason vitest does not match the return type with one of the overloads from pathExists pathExistsMock.mockResolvedValue(false); - await expect(parseStaticDir('nonexistent')).rejects.toThrow(path.resolve('nonexistent')); + await expect(parseStaticDir('nonexistent')).rejects.toThrow(resolve('nonexistent')); }); skipWindows(() => { @@ -82,8 +85,8 @@ describe('parseStaticDir', () => { onlyWindows(() => { it('supports absolute file paths - windows', async () => { await expect(parseStaticDir('C:\\foo\\bar')).resolves.toEqual({ - staticDir: path.resolve('C:\\foo\\bar'), - staticPath: path.resolve('C:\\foo\\bar'), + staticDir: resolve('C:\\foo\\bar'), + staticPath: resolve('C:\\foo\\bar'), targetDir: './', targetEndpoint: '/', }); @@ -92,14 +95,14 @@ describe('parseStaticDir', () => { it('supports absolute file paths with custom endpoint - windows', async () => { await expect(parseStaticDir('C:\\foo\\bar:/custom-endpoint')).resolves.toEqual({ staticDir: expect.any(String), // can't test this properly on unix - staticPath: path.resolve('C:\\foo\\bar'), + staticPath: resolve('C:\\foo\\bar'), targetDir: './custom-endpoint', targetEndpoint: '/custom-endpoint', }); await expect(parseStaticDir('C:\\foo\\bar:\\custom-endpoint')).resolves.toEqual({ staticDir: expect.any(String), // can't test this properly on unix - staticPath: path.resolve('C:\\foo\\bar'), + staticPath: resolve('C:\\foo\\bar'), targetDir: './custom-endpoint', targetEndpoint: '/custom-endpoint', }); diff --git a/code/core/src/core-server/utils/autoName.ts b/code/core/src/core-server/utils/autoName.ts index aa916c865664..953124f7db0f 100644 --- a/code/core/src/core-server/utils/autoName.ts +++ b/code/core/src/core-server/utils/autoName.ts @@ -1,6 +1,7 @@ -import type { Path } from '@storybook/core/types'; import { basename } from 'node:path'; +import type { Path } from '@storybook/core/types'; + /** * Calculate a name to use for a docs entry if not specified. The rule is: * diff --git a/code/core/src/core-server/utils/copy-all-static-files.ts b/code/core/src/core-server/utils/copy-all-static-files.ts index 344bc12eeb72..b17ceaa1f8dd 100644 --- a/code/core/src/core-server/utils/copy-all-static-files.ts +++ b/code/core/src/core-server/utils/copy-all-static-files.ts @@ -1,8 +1,12 @@ -import chalk from 'chalk'; -import fs from 'fs-extra'; import { join, relative } from 'node:path'; -import { logger } from '@storybook/core/node-logger'; + import { getDirectoryFromWorkingDir } from '@storybook/core/common'; + +import { logger } from '@storybook/core/node-logger'; + +import chalk from 'chalk'; +import fs from 'fs-extra'; + import { parseStaticDir } from './server-statics'; export async function copyAllStaticFiles(staticDirs: any[] | undefined, outputDir: string) { diff --git a/code/core/src/core-server/utils/doTelemetry.ts b/code/core/src/core-server/utils/doTelemetry.ts index be9479cf3348..511616d02f24 100644 --- a/code/core/src/core-server/utils/doTelemetry.ts +++ b/code/core/src/core-server/utils/doTelemetry.ts @@ -1,12 +1,14 @@ +import { getPrecedingUpgrade, telemetry } from '@storybook/core/telemetry'; +import type { CoreConfig, Options } from '@storybook/core/types'; + import invariant from 'tiny-invariant'; -import type { CoreConfig, Options, StoryIndex } from '@storybook/core/types'; -import { telemetry, getPrecedingUpgrade } from '@storybook/core/telemetry'; -import { useStorybookMetadata } from './metadata'; + +import { sendTelemetryError } from '../withTelemetry'; import type { StoryIndexGenerator } from './StoryIndexGenerator'; -import { summarizeIndex } from './summarizeIndex'; +import { useStorybookMetadata } from './metadata'; import { router } from './router'; +import { summarizeIndex } from './summarizeIndex'; import { versionStatus } from './versionStatus'; -import { sendTelemetryError } from '../withTelemetry'; export async function doTelemetry( core: CoreConfig, diff --git a/code/core/src/core-server/utils/get-builders.ts b/code/core/src/core-server/utils/get-builders.ts index 13a5365c91e2..5b654a14c955 100644 --- a/code/core/src/core-server/utils/get-builders.ts +++ b/code/core/src/core-server/utils/get-builders.ts @@ -1,6 +1,8 @@ +import { pathToFileURL } from 'node:url'; + import type { Builder, Options } from '@storybook/core/types'; + import { MissingBuilderError } from '@storybook/core/server-errors'; -import { pathToFileURL } from 'node:url'; export async function getManagerBuilder(): Promise> { return import('@storybook/core/builder-manager'); diff --git a/code/core/src/core-server/utils/get-component-variable-name.test.ts b/code/core/src/core-server/utils/get-component-variable-name.test.ts index 07b2fb5599aa..222f97226d5d 100644 --- a/code/core/src/core-server/utils/get-component-variable-name.test.ts +++ b/code/core/src/core-server/utils/get-component-variable-name.test.ts @@ -1,4 +1,5 @@ import { describe, expect, it } from 'vitest'; + import { getComponentVariableName } from './get-component-variable-name'; describe('get-variable-name', () => { diff --git a/code/core/src/core-server/utils/get-new-story-file.test.ts b/code/core/src/core-server/utils/get-new-story-file.test.ts index c1a4e5e083de..6144927e478e 100644 --- a/code/core/src/core-server/utils/get-new-story-file.test.ts +++ b/code/core/src/core-server/utils/get-new-story-file.test.ts @@ -1,6 +1,8 @@ +import { join } from 'node:path'; + import { describe, expect, it, vi } from 'vitest'; + import { getNewStoryFile } from './get-new-story-file'; -import path from 'node:path'; vi.mock('@storybook/core/common', async (importOriginal) => { const actual = await importOriginal(); @@ -46,7 +48,7 @@ describe('get-new-story-file', () => { export const Default: Story = {};" `); - expect(storyFilePath).toBe(path.join(__dirname, 'src', 'components', 'Page.stories.tsx')); + expect(storyFilePath).toBe(join(__dirname, 'src', 'components', 'Page.stories.tsx')); }); it('should create a new story file (JavaScript)', async () => { @@ -80,6 +82,6 @@ describe('get-new-story-file', () => { export const Default = {};" `); - expect(storyFilePath).toBe(path.join(__dirname, 'src', 'components', 'Page.stories.jsx')); + expect(storyFilePath).toBe(join(__dirname, 'src', 'components', 'Page.stories.jsx')); }); }); diff --git a/code/core/src/core-server/utils/get-new-story-file.ts b/code/core/src/core-server/utils/get-new-story-file.ts index 61de20234995..570ab8aecf7e 100644 --- a/code/core/src/core-server/utils/get-new-story-file.ts +++ b/code/core/src/core-server/utils/get-new-story-file.ts @@ -1,16 +1,19 @@ -import type { Options } from '@storybook/core/types'; +import { existsSync } from 'node:fs'; +import { basename, dirname, extname, join } from 'node:path'; + import { extractProperRendererNameFromFramework, getFrameworkName, getProjectRoot, rendererPackages, } from '@storybook/core/common'; -import path from 'node:path'; -import fs from 'node:fs'; -import { getTypeScriptTemplateForNewStoryFile } from './new-story-templates/typescript'; -import { getJavaScriptTemplateForNewStoryFile } from './new-story-templates/javascript'; +import type { Options } from '@storybook/core/types'; + import type { CreateNewStoryRequestPayload } from '@storybook/core/core-events'; +import { getJavaScriptTemplateForNewStoryFile } from './new-story-templates/javascript'; +import { getTypeScriptTemplateForNewStoryFile } from './new-story-templates/typescript'; + export async function getNewStoryFile( { componentFilePath, @@ -28,10 +31,10 @@ export async function getNewStoryFile( ([, value]) => value === rendererName )?.[0]; - const basename = path.basename(componentFilePath); - const extension = path.extname(componentFilePath); - const basenameWithoutExtension = basename.replace(extension, ''); - const dirname = path.dirname(componentFilePath); + const base = basename(componentFilePath); + const extension = extname(componentFilePath); + const basenameWithoutExtension = base.replace(extension, ''); + const dir = dirname(componentFilePath); const { storyFileName, isTypescript, storyFileExtension } = getStoryMetadata(componentFilePath); const storyFileNameWithExtension = `${storyFileName}.${storyFileExtension}`; @@ -56,18 +59,18 @@ export async function getNewStoryFile( }); const storyFilePath = - doesStoryFileExist(path.join(cwd, dirname), storyFileName) && componentExportCount > 1 - ? path.join(cwd, dirname, alternativeStoryFileNameWithExtension) - : path.join(cwd, dirname, storyFileNameWithExtension); + doesStoryFileExist(join(cwd, dir), storyFileName) && componentExportCount > 1 + ? join(cwd, dir, alternativeStoryFileNameWithExtension) + : join(cwd, dir, storyFileNameWithExtension); return { storyFilePath, exportedStoryName, storyFileContent, dirname }; } export const getStoryMetadata = (componentFilePath: string) => { const isTypescript = /\.(ts|tsx|mts|cts)$/.test(componentFilePath); - const basename = path.basename(componentFilePath); - const extension = path.extname(componentFilePath); - const basenameWithoutExtension = basename.replace(extension, ''); + const base = basename(componentFilePath); + const extension = extname(componentFilePath); + const basenameWithoutExtension = base.replace(extension, ''); const storyFileExtension = isTypescript ? 'tsx' : 'jsx'; return { storyFileName: `${basenameWithoutExtension}.stories`, @@ -78,9 +81,9 @@ export const getStoryMetadata = (componentFilePath: string) => { export const doesStoryFileExist = (parentFolder: string, storyFileName: string) => { return ( - fs.existsSync(path.join(parentFolder, `${storyFileName}.ts`)) || - fs.existsSync(path.join(parentFolder, `${storyFileName}.tsx`)) || - fs.existsSync(path.join(parentFolder, `${storyFileName}.js`)) || - fs.existsSync(path.join(parentFolder, `${storyFileName}.jsx`)) + existsSync(join(parentFolder, `${storyFileName}.ts`)) || + existsSync(join(parentFolder, `${storyFileName}.tsx`)) || + existsSync(join(parentFolder, `${storyFileName}.js`)) || + existsSync(join(parentFolder, `${storyFileName}.jsx`)) ); }; diff --git a/code/core/src/core-server/utils/get-server-channel.ts b/code/core/src/core-server/utils/get-server-channel.ts index d7f8c4721de7..ce5844e6235d 100644 --- a/code/core/src/core-server/utils/get-server-channel.ts +++ b/code/core/src/core-server/utils/get-server-channel.ts @@ -1,8 +1,9 @@ -import WebSocket, { WebSocketServer } from 'ws'; -import { isJSON, parse, stringify } from 'telejson'; import type { ChannelHandler } from '@storybook/core/channels'; import { Channel } from '@storybook/core/channels'; +import { isJSON, parse, stringify } from 'telejson'; +import WebSocket, { WebSocketServer } from 'ws'; + type Server = NonNullable[0]>['server']>; /** diff --git a/code/core/src/core-server/utils/get-story-id.test.ts b/code/core/src/core-server/utils/get-story-id.test.ts index 26fedcbe03e9..e2056119f155 100644 --- a/code/core/src/core-server/utils/get-story-id.test.ts +++ b/code/core/src/core-server/utils/get-story-id.test.ts @@ -1,12 +1,14 @@ -import path from 'node:path'; +import { join } from 'node:path'; + import { describe, expect, it } from 'vitest'; + import { getStoryId } from './get-story-id'; describe('getStoryId', () => { it('should return the storyId', async () => { const cwd = process.cwd(); const options = { - configDir: path.join(cwd, '.storybook'), + configDir: join(cwd, '.storybook'), presets: { apply: (val: string) => { if (val === 'stories') { @@ -15,7 +17,7 @@ describe('getStoryId', () => { }, }, } as any; - const storyFilePath = path.join(cwd, 'src', 'components', 'stories', 'Page1.stories.ts'); + const storyFilePath = join(cwd, 'src', 'components', 'stories', 'Page1.stories.ts'); const exportedStoryName = 'Default'; const { storyId, kind } = await getStoryId({ storyFilePath, exportedStoryName }, options); @@ -27,7 +29,7 @@ describe('getStoryId', () => { it('should throw an error if the storyId cannot be calculated', async () => { const cwd = process.cwd(); const options = { - configDir: path.join(cwd, '.storybook'), + configDir: join(cwd, '.storybook'), presets: { apply: (val: string) => { if (val === 'stories') { @@ -36,7 +38,7 @@ describe('getStoryId', () => { }, }, } as any; - const storyFilePath = path.join(cwd, 'not-covered-path', 'stories', 'Page1.stories.ts'); + const storyFilePath = join(cwd, 'not-covered-path', 'stories', 'Page1.stories.ts'); const exportedStoryName = 'Default'; await expect(() => diff --git a/code/core/src/core-server/utils/get-story-id.ts b/code/core/src/core-server/utils/get-story-id.ts index ef44c263f094..7dad86006b97 100644 --- a/code/core/src/core-server/utils/get-story-id.ts +++ b/code/core/src/core-server/utils/get-story-id.ts @@ -1,9 +1,13 @@ -import type { Options } from '@storybook/core/types'; -import { dedent } from 'ts-dedent'; +import { relative } from 'node:path'; + import { normalizeStories, normalizeStoryPath } from '@storybook/core/common'; -import path from 'node:path'; +import type { Options } from '@storybook/core/types'; import { sanitize, storyNameFromExport, toId } from '@storybook/csf'; + import { userOrAutoTitleFromSpecifier } from '@storybook/core/preview-api'; + +import { dedent } from 'ts-dedent'; + import { posix } from './posix'; interface StoryIdData { @@ -21,7 +25,7 @@ export async function getStoryId(data: StoryIdData, options: Options) { workingDir, }); - const relativePath = path.relative(workingDir, data.storyFilePath); + const relativePath = relative(workingDir, data.storyFilePath); const importPath = posix(normalizeStoryPath(relativePath)); const autoTitle = normalizedStories diff --git a/code/core/src/core-server/utils/getStoryIndexGenerator.ts b/code/core/src/core-server/utils/getStoryIndexGenerator.ts index b61a5490c3b4..6e5e4960b132 100644 --- a/code/core/src/core-server/utils/getStoryIndexGenerator.ts +++ b/code/core/src/core-server/utils/getStoryIndexGenerator.ts @@ -1,9 +1,10 @@ -import type { DocsOptions, Options } from '@storybook/core/types'; import { normalizeStories } from '@storybook/core/common'; -import { useStoriesJson } from './stories-json'; -import type { ServerChannel } from './get-server-channel'; +import type { DocsOptions, Options } from '@storybook/core/types'; + import { StoryIndexGenerator } from './StoryIndexGenerator'; +import type { ServerChannel } from './get-server-channel'; import { router } from './router'; +import { useStoriesJson } from './stories-json'; export async function getStoryIndexGenerator( features: { diff --git a/code/core/src/core-server/utils/metadata.ts b/code/core/src/core-server/utils/metadata.ts index a3a2c755b33b..cc047d841768 100644 --- a/code/core/src/core-server/utils/metadata.ts +++ b/code/core/src/core-server/utils/metadata.ts @@ -1,7 +1,8 @@ -import { writeJSON } from 'fs-extra'; -import type { Request, Response, Router } from 'express'; import { getStorybookMetadata } from '@storybook/core/telemetry'; +import type { Request, Response, Router } from 'express'; +import { writeJSON } from 'fs-extra'; + export async function extractStorybookMetadata(outputFile: string, configDir: string) { const storybookMetadata = await getStorybookMetadata(configDir); diff --git a/code/core/src/core-server/utils/middleware.ts b/code/core/src/core-server/utils/middleware.ts index 33ad1e641771..366f3f096c6c 100644 --- a/code/core/src/core-server/utils/middleware.ts +++ b/code/core/src/core-server/utils/middleware.ts @@ -1,14 +1,14 @@ -import path from 'node:path'; -import fs from 'node:fs'; +import { existsSync } from 'node:fs'; +import { resolve } from 'node:path'; const fileExists = (basename: string) => ['.js', '.cjs'].reduce((found: string, ext: string) => { const filename = `${basename}${ext}`; - return !found && fs.existsSync(filename) ? filename : found; + return !found && existsSync(filename) ? filename : found; }, ''); export function getMiddleware(configDir: string) { - const middlewarePath = fileExists(path.resolve(configDir, 'middleware')); + const middlewarePath = fileExists(resolve(configDir, 'middleware')); if (middlewarePath) { let middlewareModule = require(middlewarePath); // eslint-disable-next-line no-underscore-dangle diff --git a/code/core/src/core-server/utils/new-story-templates/javascript.test.ts b/code/core/src/core-server/utils/new-story-templates/javascript.test.ts index 525c0fe25f4c..31d7f7686030 100644 --- a/code/core/src/core-server/utils/new-story-templates/javascript.test.ts +++ b/code/core/src/core-server/utils/new-story-templates/javascript.test.ts @@ -1,4 +1,5 @@ import { describe, expect, it } from 'vitest'; + import { getJavaScriptTemplateForNewStoryFile } from './javascript'; describe('javascript', () => { diff --git a/code/core/src/core-server/utils/new-story-templates/javascript.ts b/code/core/src/core-server/utils/new-story-templates/javascript.ts index cc59e78cf34c..12742502b413 100644 --- a/code/core/src/core-server/utils/new-story-templates/javascript.ts +++ b/code/core/src/core-server/utils/new-story-templates/javascript.ts @@ -1,4 +1,5 @@ import { dedent } from 'ts-dedent'; + import { getComponentVariableName } from '../get-component-variable-name'; interface JavaScriptTemplateData { diff --git a/code/core/src/core-server/utils/new-story-templates/typescript.test.ts b/code/core/src/core-server/utils/new-story-templates/typescript.test.ts index 338b3209ce95..b470cf0699b1 100644 --- a/code/core/src/core-server/utils/new-story-templates/typescript.test.ts +++ b/code/core/src/core-server/utils/new-story-templates/typescript.test.ts @@ -1,4 +1,5 @@ import { describe, expect, it } from 'vitest'; + import { getTypeScriptTemplateForNewStoryFile } from './typescript'; describe('typescript', () => { diff --git a/code/core/src/core-server/utils/new-story-templates/typescript.ts b/code/core/src/core-server/utils/new-story-templates/typescript.ts index d9e0acaa12cc..892772f06f2d 100644 --- a/code/core/src/core-server/utils/new-story-templates/typescript.ts +++ b/code/core/src/core-server/utils/new-story-templates/typescript.ts @@ -1,4 +1,5 @@ import { dedent } from 'ts-dedent'; + import { getComponentVariableName } from '../get-component-variable-name'; interface TypeScriptTemplateData { diff --git a/code/core/src/core-server/utils/open-in-browser.ts b/code/core/src/core-server/utils/open-in-browser.ts index b4fe5d77d961..aa5f745b8ce6 100644 --- a/code/core/src/core-server/utils/open-in-browser.ts +++ b/code/core/src/core-server/utils/open-in-browser.ts @@ -1,7 +1,9 @@ import { logger } from '@storybook/core/node-logger'; -import betterOpn from 'better-opn'; // betterOpn alias used because also loading open -import open from 'open'; + import getDefaultBrowser from '@aw-web-design/x-default-browser'; +import betterOpn from 'better-opn'; +// betterOpn alias used because also loading open +import open from 'open'; import { dedent } from 'ts-dedent'; export function openInBrowser(address: string) { diff --git a/code/core/src/core-server/utils/output-startup-information.ts b/code/core/src/core-server/utils/output-startup-information.ts index 092a29671aa4..cfe60bef6cc9 100644 --- a/code/core/src/core-server/utils/output-startup-information.ts +++ b/code/core/src/core-server/utils/output-startup-information.ts @@ -1,10 +1,13 @@ -import chalk from 'chalk'; +import type { VersionCheck } from '@storybook/core/types'; + import { colors } from '@storybook/core/node-logger'; + import boxen from 'boxen'; -import { dedent } from 'ts-dedent'; +import chalk from 'chalk'; import Table from 'cli-table3'; import prettyTime from 'pretty-hrtime'; -import type { VersionCheck } from '@storybook/core/types'; +import { dedent } from 'ts-dedent'; + import { createUpdateMessage } from './update-check'; export function outputStartupInformation(options: { diff --git a/code/core/src/core-server/utils/output-stats.ts b/code/core/src/core-server/utils/output-stats.ts index 0b99ef1f4eb3..c3a5b9f8aad9 100644 --- a/code/core/src/core-server/utils/output-stats.ts +++ b/code/core/src/core-server/utils/output-stats.ts @@ -1,9 +1,12 @@ -import { stringifyStream } from '@discoveryjs/json-ext'; -import { logger } from '@storybook/core/node-logger'; +import { join } from 'node:path'; + import type { Stats } from '@storybook/core/types'; + +import { logger } from '@storybook/core/node-logger'; + +import { stringifyStream } from '@discoveryjs/json-ext'; import chalk from 'chalk'; import fs from 'fs-extra'; -import path from 'node:path'; export async function outputStats(directory: string, previewStats?: any, managerStats?: any) { if (previewStats) { @@ -17,7 +20,7 @@ export async function outputStats(directory: string, previewStats?: any, manager } export const writeStats = async (directory: string, name: string, stats: Stats) => { - const filePath = path.join(directory, `${name}-stats.json`); + const filePath = join(directory, `${name}-stats.json`); const { chunks, ...data } = stats.toJson(); // omit chunks, which is about half of the total data await new Promise((resolve, reject) => { stringifyStream(data, null, 2) diff --git a/code/core/src/core-server/utils/parser/generic-parser.test.ts b/code/core/src/core-server/utils/parser/generic-parser.test.ts index 17995e7ec0f0..e461a9cdbf50 100644 --- a/code/core/src/core-server/utils/parser/generic-parser.test.ts +++ b/code/core/src/core-server/utils/parser/generic-parser.test.ts @@ -1,15 +1,17 @@ +import { readFileSync } from 'node:fs'; +import { join } from 'node:path'; + import { describe, expect, it } from 'vitest'; -import path from 'node:path'; + import { GenericParser } from './generic-parser'; -import fs from 'node:fs'; const genericParser = new GenericParser(); -const TEST_DIR = path.join(__dirname, '..', '__search-files-tests__'); +const TEST_DIR = join(__dirname, '..', '__search-files-tests__'); describe('generic-parser', () => { it('should correctly return exports from ES modules', async () => { - const content = fs.readFileSync(path.join(TEST_DIR, 'src', 'es-module.js'), 'utf-8'); + const content = readFileSync(join(TEST_DIR, 'src', 'es-module.js'), 'utf-8'); const { exports } = await genericParser.parse(content); expect(exports).toEqual([ diff --git a/code/core/src/core-server/utils/parser/generic-parser.ts b/code/core/src/core-server/utils/parser/generic-parser.ts index e3c4754fab44..cbce263ac9ec 100644 --- a/code/core/src/core-server/utils/parser/generic-parser.ts +++ b/code/core/src/core-server/utils/parser/generic-parser.ts @@ -1,5 +1,5 @@ -import * as babelParser from '@babel/parser'; import { types } from '@babel/core'; +import * as babelParser from '@babel/parser'; import type { Parser, ParserResult } from './types'; diff --git a/code/core/src/core-server/utils/parser/index.ts b/code/core/src/core-server/utils/parser/index.ts index 5e3aa13fd866..753e2c1d8afd 100644 --- a/code/core/src/core-server/utils/parser/index.ts +++ b/code/core/src/core-server/utils/parser/index.ts @@ -1,4 +1,5 @@ import type { SupportedRenderers } from '@storybook/core/types'; + import { GenericParser } from './generic-parser'; import type { Parser } from './types'; diff --git a/code/core/src/core-server/utils/posix.test.ts b/code/core/src/core-server/utils/posix.test.ts index 23c8d2ca3bec..960d799e30b1 100644 --- a/code/core/src/core-server/utils/posix.test.ts +++ b/code/core/src/core-server/utils/posix.test.ts @@ -1,4 +1,5 @@ import { describe, expect, it } from 'vitest'; + import { posix } from './posix'; describe('posix', () => { diff --git a/code/core/src/core-server/utils/posix.ts b/code/core/src/core-server/utils/posix.ts index d9b8224cdde5..d4fbcc98b3cf 100644 --- a/code/core/src/core-server/utils/posix.ts +++ b/code/core/src/core-server/utils/posix.ts @@ -1,7 +1,7 @@ -import path from 'node:path'; +import { posix as posixPath, sep } from 'node:path'; /** * Replaces the path separator with forward slashes */ -export const posix = (localPath: string, sep: string = path.sep) => - localPath.split(sep).filter(Boolean).join(path.posix.sep); +export const posix = (localPath: string, seperator: string = sep) => + localPath.split(seperator).filter(Boolean).join(posixPath.sep); diff --git a/code/core/src/core-server/utils/remove-mdx-entries.ts b/code/core/src/core-server/utils/remove-mdx-entries.ts index d9d5a285dcc6..f71488712a49 100644 --- a/code/core/src/core-server/utils/remove-mdx-entries.ts +++ b/code/core/src/core-server/utils/remove-mdx-entries.ts @@ -1,8 +1,10 @@ -import type { Options, StoriesEntry } from '@storybook/core/types'; -import { normalizeStories, commonGlobOptions } from '@storybook/core/common'; import { isAbsolute, join, relative } from 'node:path'; -import slash from 'slash'; + +import { commonGlobOptions, normalizeStories } from '@storybook/core/common'; +import type { Options, StoriesEntry } from '@storybook/core/types'; + import { glob } from 'glob'; +import slash from 'slash'; export async function removeMDXEntries( entries: StoriesEntry[], diff --git a/code/core/src/core-server/utils/save-story/duplicate-story-with-new-name.test.ts b/code/core/src/core-server/utils/save-story/duplicate-story-with-new-name.test.ts index da4b26eabb25..549c74337ca9 100644 --- a/code/core/src/core-server/utils/save-story/duplicate-story-with-new-name.test.ts +++ b/code/core/src/core-server/utils/save-story/duplicate-story-with-new-name.test.ts @@ -1,11 +1,14 @@ /* eslint-disable no-underscore-dangle */ -import { describe, test, expect } from 'vitest'; -import { readCsf, printCsf } from '@storybook/core/csf-tools'; - -import { duplicateStoryWithNewName } from './duplicate-story-with-new-name'; -import { readFile } from 'fs/promises'; +import { readFile } from 'node:fs/promises'; import { join } from 'node:path'; + +import { describe, expect, test } from 'vitest'; + +import { printCsf, readCsf } from '@storybook/core/csf-tools'; + import { format } from 'prettier'; + +import { duplicateStoryWithNewName } from './duplicate-story-with-new-name'; import { getDiff } from './getDiff'; const makeTitle = (userTitle: string) => userTitle; diff --git a/code/core/src/core-server/utils/save-story/duplicate-story-with-new-name.ts b/code/core/src/core-server/utils/save-story/duplicate-story-with-new-name.ts index f93c02d12afe..25e634a0faf4 100644 --- a/code/core/src/core-server/utils/save-story/duplicate-story-with-new-name.ts +++ b/code/core/src/core-server/utils/save-story/duplicate-story-with-new-name.ts @@ -1,7 +1,9 @@ /* eslint-disable no-underscore-dangle */ import type { CsfFile } from '@storybook/core/csf-tools'; -import * as t from '@babel/types'; + import bt from '@babel/traverse'; +import * as t from '@babel/types'; + import { SaveStoryError } from './utils'; // @ts-expect-error (needed due to it's use of `exports.default`) diff --git a/code/core/src/core-server/utils/save-story/mocks/csf-variances.stories.tsx b/code/core/src/core-server/utils/save-story/mocks/csf-variances.stories.tsx index 9fcbc4bd4df3..35081f422ae3 100644 --- a/code/core/src/core-server/utils/save-story/mocks/csf-variances.stories.tsx +++ b/code/core/src/core-server/utils/save-story/mocks/csf-variances.stories.tsx @@ -1,5 +1,6 @@ import React from 'react'; import type { FC } from 'react'; + import type { Meta, StoryObj } from '@storybook/react'; export default { diff --git a/code/core/src/core-server/utils/save-story/mocks/data-variances.stories.tsx b/code/core/src/core-server/utils/save-story/mocks/data-variances.stories.tsx index ea2f79bdcc3b..e049efd5339f 100644 --- a/code/core/src/core-server/utils/save-story/mocks/data-variances.stories.tsx +++ b/code/core/src/core-server/utils/save-story/mocks/data-variances.stories.tsx @@ -1,5 +1,6 @@ import React from 'react'; import type { FC } from 'react'; + import type { Meta, StoryObj } from '@storybook/react'; export default { diff --git a/code/core/src/core-server/utils/save-story/mocks/export-variances.stories.tsx b/code/core/src/core-server/utils/save-story/mocks/export-variances.stories.tsx index 7c853f484468..3fc94bcceaab 100644 --- a/code/core/src/core-server/utils/save-story/mocks/export-variances.stories.tsx +++ b/code/core/src/core-server/utils/save-story/mocks/export-variances.stories.tsx @@ -1,5 +1,6 @@ import React from 'react'; import type { FC } from 'react'; + import type { Meta, StoryObj } from '@storybook/react'; export default { diff --git a/code/core/src/core-server/utils/save-story/mocks/typescript-constructs.stories.tsx b/code/core/src/core-server/utils/save-story/mocks/typescript-constructs.stories.tsx index d44c95c446be..0d4aa951ad89 100644 --- a/code/core/src/core-server/utils/save-story/mocks/typescript-constructs.stories.tsx +++ b/code/core/src/core-server/utils/save-story/mocks/typescript-constructs.stories.tsx @@ -1,5 +1,6 @@ import React from 'react'; import type { FC } from 'react'; + import type { Meta, StoryObj } from '@storybook/react'; export default { diff --git a/code/core/src/core-server/utils/save-story/mocks/unsupported-csf-variances.stories.tsx b/code/core/src/core-server/utils/save-story/mocks/unsupported-csf-variances.stories.tsx index b86095381faa..7a300959e0a8 100644 --- a/code/core/src/core-server/utils/save-story/mocks/unsupported-csf-variances.stories.tsx +++ b/code/core/src/core-server/utils/save-story/mocks/unsupported-csf-variances.stories.tsx @@ -1,5 +1,6 @@ import React from 'react'; import type { FC } from 'react'; + import type { Meta } from '@storybook/react'; export default { diff --git a/code/core/src/core-server/utils/save-story/save-story.ts b/code/core/src/core-server/utils/save-story/save-story.ts index 5369d99a4cba..9131107fdc0c 100644 --- a/code/core/src/core-server/utils/save-story/save-story.ts +++ b/code/core/src/core-server/utils/save-story/save-story.ts @@ -1,6 +1,13 @@ /* eslint-disable no-underscore-dangle */ -import fs from 'node:fs/promises'; +import { writeFile } from 'node:fs/promises'; +import { basename, join } from 'node:path'; + import type { Channel } from '@storybook/core/channels'; +import { formatFileContent } from '@storybook/core/common'; +import { isExampleStoryId, telemetry } from '@storybook/core/telemetry'; +import type { CoreConfig, Options } from '@storybook/core/types'; +import { storyNameFromExport, toId } from '@storybook/csf'; + import type { RequestData, ResponseData, @@ -12,16 +19,11 @@ import { SAVE_STORY_RESPONSE, STORY_RENDERED, } from '@storybook/core/core-events'; -import { storyNameFromExport, toId } from '@storybook/csf'; import { printCsf, readCsf } from '@storybook/core/csf-tools'; import { logger } from '@storybook/core/node-logger'; -import type { CoreConfig, Options } from '@storybook/core/types'; -import { telemetry } from '@storybook/core/telemetry'; -import { basename, join } from 'node:path'; -import { updateArgsInCsfFile } from './update-args-in-csf-file'; import { duplicateStoryWithNewName } from './duplicate-story-with-new-name'; -import { formatFileContent } from '@storybook/core/common'; +import { updateArgsInCsfFile } from './update-args-in-csf-file'; import { SaveStoryError } from './utils'; const parseArgs = (args: string): Record => @@ -101,7 +103,7 @@ export function initializeSaveStory(channel: Channel, options: Options, coreConf channel.on(STORY_RENDERED, resolve); setTimeout(() => resolve(channel.off(STORY_RENDERED, resolve)), 3000); }), - fs.writeFile(sourceFilePath, code), + writeFile(sourceFilePath, code), ]); channel.emit(SAVE_STORY_RESPONSE, { @@ -120,7 +122,9 @@ export function initializeSaveStory(channel: Channel, options: Options, coreConf error: null, } satisfies ResponseData); - if (!coreConfig.disableTelemetry) { + // don't take credit for save-from-controls actions against CLI example stories + const isCLIExample = isExampleStoryId(newStoryId ?? csfId); + if (!coreConfig.disableTelemetry && !isCLIExample) { await telemetry('save-story', { action: name ? 'createStory' : 'updateStory', success: true, diff --git a/code/core/src/core-server/utils/save-story/update-args-in-csf-file.test.ts b/code/core/src/core-server/utils/save-story/update-args-in-csf-file.test.ts index c06f71de482f..43bc049fc58b 100644 --- a/code/core/src/core-server/utils/save-story/update-args-in-csf-file.test.ts +++ b/code/core/src/core-server/utils/save-story/update-args-in-csf-file.test.ts @@ -1,12 +1,15 @@ /* eslint-disable no-underscore-dangle */ -import { describe, test, expect } from 'vitest'; -import { readCsf, printCsf } from '@storybook/core/csf-tools'; - -import { updateArgsInCsfFile } from './update-args-in-csf-file'; -import { readFile } from 'fs/promises'; +import { readFile } from 'node:fs/promises'; import { join } from 'node:path'; + +import { describe, expect, test } from 'vitest'; + +import { printCsf, readCsf } from '@storybook/core/csf-tools'; + import { format } from 'prettier'; + import { getDiff } from './getDiff'; +import { updateArgsInCsfFile } from './update-args-in-csf-file'; const makeTitle = (userTitle: string) => userTitle; diff --git a/code/core/src/core-server/utils/save-story/update-args-in-csf-file.ts b/code/core/src/core-server/utils/save-story/update-args-in-csf-file.ts index 8446594f1c71..9f7466ccfc07 100644 --- a/code/core/src/core-server/utils/save-story/update-args-in-csf-file.ts +++ b/code/core/src/core-server/utils/save-story/update-args-in-csf-file.ts @@ -1,7 +1,8 @@ -import * as t from '@babel/types'; import bt from '@babel/traverse'; -import { valueToAST } from './valueToAST'; +import * as t from '@babel/types'; + import { SaveStoryError } from './utils'; +import { valueToAST } from './valueToAST'; // @ts-expect-error (needed due to it's use of `exports.default`) const traverse = (bt.default || bt) as typeof bt; diff --git a/code/core/src/core-server/utils/save-story/valueToAST.ts b/code/core/src/core-server/utils/save-story/valueToAST.ts index f09dd7b65a64..b1227d8619ae 100644 --- a/code/core/src/core-server/utils/save-story/valueToAST.ts +++ b/code/core/src/core-server/utils/save-story/valueToAST.ts @@ -1,5 +1,5 @@ -import * as t from '@babel/types'; import * as babylon from '@babel/parser'; +import * as t from '@babel/types'; export function valueToAST(literal: T): any { if (literal === null) { diff --git a/code/core/src/core-server/utils/search-files.test.ts b/code/core/src/core-server/utils/search-files.test.ts index 58899c35d35f..c86afac79ac9 100644 --- a/code/core/src/core-server/utils/search-files.test.ts +++ b/code/core/src/core-server/utils/search-files.test.ts @@ -1,12 +1,14 @@ +import { join } from 'node:path'; + import { describe, expect, it } from 'vitest'; -import path from 'node:path'; + import { searchFiles } from './search-files'; describe('search-files', () => { it('should automatically convert static search to a dynamic glob search', async (t) => { const files = await searchFiles({ searchQuery: 'ommonjs', - cwd: path.join(__dirname, '__search-files-tests__'), + cwd: join(__dirname, '__search-files-tests__'), }); expect(files).toEqual(['src/commonjs-module-default.js', 'src/commonjs-module.js']); @@ -15,7 +17,7 @@ describe('search-files', () => { it('should automatically convert static search to a dynamic glob search (with file extension)', async (t) => { const files = await searchFiles({ searchQuery: 'module.js', - cwd: path.join(__dirname, '__search-files-tests__'), + cwd: join(__dirname, '__search-files-tests__'), }); expect(files).toEqual(['src/commonjs-module.js', 'src/es-module.js']); @@ -24,7 +26,7 @@ describe('search-files', () => { it('should return all files if the search query matches the parent folder', async (t) => { const files = await searchFiles({ searchQuery: 'file-extensions', - cwd: path.join(__dirname, '__search-files-tests__'), + cwd: join(__dirname, '__search-files-tests__'), }); expect(files).toEqual([ @@ -42,7 +44,7 @@ describe('search-files', () => { it('should ignore files that do not have the allowed extensions', async (t) => { const files = await searchFiles({ searchQuery: 'asset', - cwd: path.join(__dirname, '__search-files-tests__'), + cwd: join(__dirname, '__search-files-tests__'), }); expect(files).toEqual([]); @@ -51,7 +53,7 @@ describe('search-files', () => { it('should ignore test files (*.spec.*, *.test.*)', async (t) => { const files = await searchFiles({ searchQuery: 'tests', - cwd: path.join(__dirname, '__search-files-tests__'), + cwd: join(__dirname, '__search-files-tests__'), }); expect(files).toEqual([]); @@ -60,7 +62,7 @@ describe('search-files', () => { it('should work with glob search patterns', async (t) => { const files = await searchFiles({ searchQuery: '**/commonjs-module.js', - cwd: path.join(__dirname, '__search-files-tests__'), + cwd: join(__dirname, '__search-files-tests__'), }); expect(files).toEqual(['src/commonjs-module.js']); @@ -69,7 +71,7 @@ describe('search-files', () => { it('should respect glob but also the allowed file extensions', async (t) => { const files = await searchFiles({ searchQuery: '**/*', - cwd: path.join(__dirname, '__search-files-tests__'), + cwd: join(__dirname, '__search-files-tests__'), }); expect(files).toEqual([ @@ -91,7 +93,7 @@ describe('search-files', () => { it('should ignore node_modules', async (t) => { const files = await searchFiles({ searchQuery: 'file-in-common.js', - cwd: path.join(__dirname, '__search-files-tests__'), + cwd: join(__dirname, '__search-files-tests__'), }); expect(files).toEqual([]); @@ -100,7 +102,7 @@ describe('search-files', () => { it('should ignore story files', async (t) => { const files = await searchFiles({ searchQuery: 'es-module.stories.js', - cwd: path.join(__dirname, '__search-files-tests__'), + cwd: join(__dirname, '__search-files-tests__'), }); expect(files).toEqual([]); @@ -110,7 +112,7 @@ describe('search-files', () => { await expect(() => searchFiles({ searchQuery: '../**/*', - cwd: path.join(__dirname, '__search-files-tests__'), + cwd: join(__dirname, '__search-files-tests__'), }) ).rejects.toThrowError(); }); diff --git a/code/core/src/core-server/utils/server-address.test.ts b/code/core/src/core-server/utils/server-address.test.ts index 81f228c9abdf..114fbfd9608a 100644 --- a/code/core/src/core-server/utils/server-address.test.ts +++ b/code/core/src/core-server/utils/server-address.test.ts @@ -1,6 +1,8 @@ -import { describe, it, expect, vi } from 'vitest'; +import { describe, expect, it, vi } from 'vitest'; + import detectPort from 'detect-port'; -import { getServerAddresses, getServerPort, getServerChannelUrl } from './server-address'; + +import { getServerAddresses, getServerChannelUrl, getServerPort } from './server-address'; vi.mock('os', () => ({ default: { release: () => '' }, diff --git a/code/core/src/core-server/utils/server-address.ts b/code/core/src/core-server/utils/server-address.ts index a7c8f9f2d28a..7fc59312a084 100644 --- a/code/core/src/core-server/utils/server-address.ts +++ b/code/core/src/core-server/utils/server-address.ts @@ -1,7 +1,7 @@ -import os from 'os'; - import { logger } from '@storybook/core/node-logger'; + import detectFreePort from 'detect-port'; +import os from 'os'; export function getServerAddresses( port: number, diff --git a/code/core/src/core-server/utils/server-init.ts b/code/core/src/core-server/utils/server-init.ts index 0888c37fde4a..b63d663e6857 100644 --- a/code/core/src/core-server/utils/server-init.ts +++ b/code/core/src/core-server/utils/server-init.ts @@ -1,4 +1,5 @@ import { logger } from '@storybook/core/node-logger'; + import type { Express } from 'express'; import { readFile } from 'fs-extra'; import http from 'http'; diff --git a/code/core/src/core-server/utils/server-statics.ts b/code/core/src/core-server/utils/server-statics.ts index a2fd5cc8a25f..926fcdb34842 100644 --- a/code/core/src/core-server/utils/server-statics.ts +++ b/code/core/src/core-server/utils/server-statics.ts @@ -1,12 +1,14 @@ -import { logger } from '@storybook/core/node-logger'; -import type { Options } from '@storybook/core/types'; +import { basename, isAbsolute, posix, resolve, sep, win32 } from 'node:path'; + import { getDirectoryFromWorkingDir } from '@storybook/core/common'; +import type { Options } from '@storybook/core/types'; + +import { logger } from '@storybook/core/node-logger'; + import chalk from 'chalk'; import type { Router } from 'express'; import express from 'express'; import { pathExists } from 'fs-extra'; -import path, { basename, isAbsolute } from 'node:path'; - import { dedent } from 'ts-dedent'; export async function useStatics(router: Router, options: Options) { @@ -52,16 +54,16 @@ export async function useStatics(router: Router, options: Options) { export const parseStaticDir = async (arg: string) => { // Split on last index of ':', for Windows compatibility (e.g. 'C:\some\dir:\foo') const lastColonIndex = arg.lastIndexOf(':'); - const isWindowsAbsolute = path.win32.isAbsolute(arg); + const isWindowsAbsolute = win32.isAbsolute(arg); const isWindowsRawDirOnly = isWindowsAbsolute && lastColonIndex === 1; // e.g. 'C:\some\dir' const splitIndex = lastColonIndex !== -1 && !isWindowsRawDirOnly ? lastColonIndex : arg.length; const targetRaw = arg.substring(splitIndex + 1) || '/'; - const target = targetRaw.split(path.sep).join(path.posix.sep); // Ensure target has forward-slash path + const target = targetRaw.split(sep).join(posix.sep); // Ensure target has forward-slash path const rawDir = arg.substring(0, splitIndex); - const staticDir = path.isAbsolute(rawDir) ? rawDir : `./${rawDir}`; - const staticPath = path.resolve(staticDir); + const staticDir = isAbsolute(rawDir) ? rawDir : `./${rawDir}`; + const staticPath = resolve(staticDir); const targetDir = target.replace(/^\/?/, './'); const targetEndpoint = targetDir.substring(1); diff --git a/code/core/src/core-server/utils/stories-json.test.ts b/code/core/src/core-server/utils/stories-json.test.ts index a4ad0fa780b7..e9f5e73a7378 100644 --- a/code/core/src/core-server/utils/stories-json.test.ts +++ b/code/core/src/core-server/utils/stories-json.test.ts @@ -1,23 +1,26 @@ -import { describe, beforeEach, it, expect, vi } from 'vitest'; +import { join } from 'node:path'; + +import { beforeEach, describe, expect, it, vi } from 'vitest'; -import type { Router, Request, Response } from 'express'; -import Watchpack from 'watchpack'; -import path from 'node:path'; -import debounce from 'lodash/debounce.js'; -import { STORY_INDEX_INVALIDATED } from '@storybook/core/core-events'; import { normalizeStoriesEntry } from '@storybook/core/common'; -import { useStoriesJson, DEBOUNCE } from './stories-json'; -import type { ServerChannel } from './get-server-channel'; +import { STORY_INDEX_INVALIDATED } from '@storybook/core/core-events'; + +import type { Request, Response, Router } from 'express'; +import debounce from 'lodash/debounce.js'; +import Watchpack from 'watchpack'; + +import { csfIndexer } from '../presets/common-preset'; import type { StoryIndexGeneratorOptions } from './StoryIndexGenerator'; import { StoryIndexGenerator } from './StoryIndexGenerator'; -import { csfIndexer } from '../presets/common-preset'; +import type { ServerChannel } from './get-server-channel'; +import { DEBOUNCE, useStoriesJson } from './stories-json'; vi.mock('watchpack'); vi.mock('lodash/debounce'); vi.mock('@storybook/core/node-logger'); -const workingDir = path.join(__dirname, '__mockdata__'); +const workingDir = join(__dirname, '__mockdata__'); const normalizedStories = [ normalizeStoriesEntry( { diff --git a/code/core/src/core-server/utils/stories-json.ts b/code/core/src/core-server/utils/stories-json.ts index a85791dd6a9b..8956a4ed7ab1 100644 --- a/code/core/src/core-server/utils/stories-json.ts +++ b/code/core/src/core-server/utils/stories-json.ts @@ -1,15 +1,17 @@ import { basename } from 'node:path'; -import type { Router, Request, Response } from 'express'; -import { writeJSON } from 'fs-extra'; import type { NormalizedStoriesSpecifier, StoryIndex } from '@storybook/core/types'; -import debounce from 'lodash/debounce.js'; import { STORY_INDEX_INVALIDATED } from '@storybook/core/core-events'; + +import type { Request, Response, Router } from 'express'; +import { writeJSON } from 'fs-extra'; +import debounce from 'lodash/debounce.js'; + import type { StoryIndexGenerator } from './StoryIndexGenerator'; +import type { ServerChannel } from './get-server-channel'; import { watchStorySpecifiers } from './watch-story-specifiers'; import { watchConfig } from './watchConfig'; -import type { ServerChannel } from './get-server-channel'; export const DEBOUNCE = 100; diff --git a/code/core/src/core-server/utils/summarizeIndex.test.ts b/code/core/src/core-server/utils/summarizeIndex.test.ts index e1be61027c22..5307f05252df 100644 --- a/code/core/src/core-server/utils/summarizeIndex.test.ts +++ b/code/core/src/core-server/utils/summarizeIndex.test.ts @@ -1,4 +1,5 @@ -import { describe, it, expect } from 'vitest'; +import { describe, expect, it } from 'vitest'; + import { isPageStory, summarizeIndex } from './summarizeIndex'; describe('isPageStory', () => { diff --git a/code/core/src/core-server/utils/summarizeIndex.ts b/code/core/src/core-server/utils/summarizeIndex.ts index 56b4b27ad929..75a5b09696ee 100644 --- a/code/core/src/core-server/utils/summarizeIndex.ts +++ b/code/core/src/core-server/utils/summarizeIndex.ts @@ -1,6 +1,7 @@ +import { isExampleStoryId } from '@storybook/core/telemetry'; import type { IndexEntry, StoryIndex } from '@storybook/core/types'; -import { isMdxEntry, AUTODOCS_TAG, PLAY_FN_TAG } from './StoryIndexGenerator'; +import { AUTODOCS_TAG, PLAY_FN_TAG, isMdxEntry } from './StoryIndexGenerator'; const PAGE_REGEX = /(page|screen)/i; @@ -25,15 +26,6 @@ const isCLIExampleEntry = (entry: IndexEntry) => 'example-page--logged-out', ].includes(entry.id); -/** - * Is this story part of the CLI generated examples, - * including user-created stories in those files - */ -const isAnyExampleEntry = (entry: IndexEntry) => - entry.id.startsWith('example-button--') || - entry.id.startsWith('example-header--') || - entry.id.startsWith('example-page--'); - export function summarizeIndex(storyIndex: StoryIndex) { let storyCount = 0; const componentTitles = new Set(); @@ -49,7 +41,7 @@ export function summarizeIndex(storyIndex: StoryIndex) { if (isCLIExampleEntry(entry)) { if (entry.type === 'story') exampleStoryCount += 1; if (entry.type === 'docs') exampleDocsCount += 1; - } else if (isAnyExampleEntry(entry)) { + } else if (isExampleStoryId(entry.id)) { if (entry.type === 'story') onboardingStoryCount += 1; if (entry.type === 'docs') onboardingDocsCount += 1; } else if (entry.type === 'story') { diff --git a/code/core/src/core-server/utils/summarizeStats.test.ts b/code/core/src/core-server/utils/summarizeStats.test.ts index e1e342e94260..735671fb3c58 100644 --- a/code/core/src/core-server/utils/summarizeStats.test.ts +++ b/code/core/src/core-server/utils/summarizeStats.test.ts @@ -1,4 +1,5 @@ -import { it, expect } from 'vitest'; +import { expect, it } from 'vitest'; + import { summarizeStats } from './summarizeStats'; it('should summarize stats', () => { diff --git a/code/core/src/core-server/utils/update-check.ts b/code/core/src/core-server/utils/update-check.ts index 93bf3ac96688..4d1fe03c685c 100644 --- a/code/core/src/core-server/utils/update-check.ts +++ b/code/core/src/core-server/utils/update-check.ts @@ -1,9 +1,11 @@ -import chalk from 'chalk'; +import { cache } from '@storybook/core/common'; +import type { VersionCheck } from '@storybook/core/types'; + import { colors } from '@storybook/core/node-logger'; + +import chalk from 'chalk'; import semver from 'semver'; import { dedent } from 'ts-dedent'; -import { cache } from '@storybook/core/common'; -import type { VersionCheck } from '@storybook/core/types'; const { STORYBOOK_VERSION_BASE = 'https://storybook.js.org', CI } = process.env; diff --git a/code/core/src/core-server/utils/warnOnIncompatibleAddons.ts b/code/core/src/core-server/utils/warnOnIncompatibleAddons.ts index a921f4ba3645..aaf64313fd61 100644 --- a/code/core/src/core-server/utils/warnOnIncompatibleAddons.ts +++ b/code/core/src/core-server/utils/warnOnIncompatibleAddons.ts @@ -1,7 +1,8 @@ import { logger } from '@storybook/core/node-logger'; + import { - getIncompatibleStorybookPackages, getIncompatiblePackagesSummary, + getIncompatibleStorybookPackages, } from '../../../../lib/cli-storybook/src/doctor/getIncompatibleStorybookPackages'; export const warnOnIncompatibleAddons = async (currentStorybookVersion: string) => { diff --git a/code/core/src/core-server/utils/warnWhenUsingArgTypesRegex.ts b/code/core/src/core-server/utils/warnWhenUsingArgTypesRegex.ts index c4ab825e51a0..b36755fcd6ab 100644 --- a/code/core/src/core-server/utils/warnWhenUsingArgTypesRegex.ts +++ b/code/core/src/core-server/utils/warnWhenUsingArgTypesRegex.ts @@ -1,11 +1,13 @@ -import type { PackageJson, StorybookConfig } from '@storybook/core/types'; import { getConfigInfo } from '@storybook/core/common'; -import { readFile } from 'fs-extra'; +import type { PackageJson, StorybookConfig } from '@storybook/core/types'; + +import { babelParse } from '@storybook/core/csf-tools'; + import * as babel from '@babel/core'; import type { BabelFile } from '@babel/core'; -import { babelParse } from '@storybook/core/csf-tools'; -import { dedent } from 'ts-dedent'; import chalk from 'chalk'; +import { readFile } from 'fs-extra'; +import { dedent } from 'ts-dedent'; export async function warnWhenUsingArgTypesRegex( packageJson: PackageJson, diff --git a/code/core/src/core-server/utils/watch-story-specifiers.test.ts b/code/core/src/core-server/utils/watch-story-specifiers.test.ts index 7d93002ab37f..9142af5aeb22 100644 --- a/code/core/src/core-server/utils/watch-story-specifiers.test.ts +++ b/code/core/src/core-server/utils/watch-story-specifiers.test.ts @@ -1,6 +1,9 @@ -import { describe, afterEach, it, expect, vi } from 'vitest'; +import { join } from 'node:path'; + +import { afterEach, describe, expect, it, vi } from 'vitest'; + import { normalizeStoriesEntry } from '@storybook/core/common'; -import path from 'node:path'; + import Watchpack from 'watchpack'; import { watchStorySpecifiers } from './watch-story-specifiers'; @@ -8,12 +11,12 @@ import { watchStorySpecifiers } from './watch-story-specifiers'; vi.mock('watchpack'); describe('watchStorySpecifiers', () => { - const workingDir = path.join(__dirname, '__mockdata__'); + const workingDir = join(__dirname, '__mockdata__'); const options = { - configDir: path.join(workingDir, '.storybook'), + configDir: join(workingDir, '.storybook'), workingDir, }; - const abspath = (filename: string) => path.join(workingDir, filename); + const abspath = (filename: string) => join(workingDir, filename); let close: () => void; afterEach(() => close?.()); diff --git a/code/core/src/core-server/utils/watch-story-specifiers.ts b/code/core/src/core-server/utils/watch-story-specifiers.ts index 068d626d8ad8..b320520dc9a4 100644 --- a/code/core/src/core-server/utils/watch-story-specifiers.ts +++ b/code/core/src/core-server/utils/watch-story-specifiers.ts @@ -1,14 +1,15 @@ -import Watchpack from 'watchpack'; -import slash from 'slash'; -import fs from 'node:fs'; -import path from 'node:path'; +import { type Dirent, lstatSync, readdirSync } from 'node:fs'; +import { basename, join, relative, resolve } from 'node:path'; -import type { NormalizedStoriesSpecifier, Path } from '@storybook/core/types'; import { commonGlobOptions } from '@storybook/core/common'; +import type { NormalizedStoriesSpecifier, Path } from '@storybook/core/types'; + +import slash from 'slash'; +import Watchpack from 'watchpack'; const isDirectory = (directory: Path) => { try { - return fs.lstatSync(directory).isDirectory(); + return lstatSync(directory).isDirectory(); } catch (err) { return false; } @@ -24,11 +25,11 @@ function getNestedFilesAndDirectories(directories: Path[]) { if (traversedDirectories.has(directory)) { return; } - fs.readdirSync(directory, { withFileTypes: true }).forEach((ent: fs.Dirent) => { + readdirSync(directory, { withFileTypes: true }).forEach((ent: Dirent) => { if (ent.isDirectory()) { - traverse(path.join(directory, ent.name)); + traverse(join(directory, ent.name)); } else if (ent.isFile()) { - files.add(path.join(directory, ent.name)); + files.add(join(directory, ent.name)); } }); traversedDirectories.add(directory); @@ -45,7 +46,7 @@ export function watchStorySpecifiers( // Watch all nested files and directories up front to avoid this issue: // https://github.com/webpack/watchpack/issues/222 const { files, directories } = getNestedFilesAndDirectories( - specifiers.map((ns) => path.resolve(options.workingDir, ns.directory)) + specifiers.map((ns) => resolve(options.workingDir, ns.directory)) ); // See https://www.npmjs.com/package/watchpack for full options. @@ -58,7 +59,7 @@ export function watchStorySpecifiers( wp.watch({ files, directories }); const toImportPath = (absolutePath: Path) => { - const relativePath = path.relative(options.workingDir, absolutePath); + const relativePath = relative(options.workingDir, absolutePath); return slash(relativePath.startsWith('.') ? relativePath : `./${relativePath}`); }; @@ -87,12 +88,12 @@ export function watchStorySpecifiers( .map(async (specifier) => { // If `./path/to/dir` was added, check all files matching `./path/to/dir/**/*.stories.*` // (where the last bit depends on `files`). - const dirGlob = path.join( + const dirGlob = join( absolutePath, '**', // files can be e.g. '**/foo/*/*.js' so we just want the last bit, // because the directory could already be within the files part (e.g. './x/foo/bar') - path.basename(specifier.files) + basename(specifier.files) ); // Dynamically import globby because it is a pure ESM module diff --git a/code/core/src/core-server/utils/watchConfig.ts b/code/core/src/core-server/utils/watchConfig.ts index 614504a1b958..bf8e055c8ced 100644 --- a/code/core/src/core-server/utils/watchConfig.ts +++ b/code/core/src/core-server/utils/watchConfig.ts @@ -1,6 +1,7 @@ -import Watchpack from 'watchpack'; import type { Path } from '@storybook/core/types'; +import Watchpack from 'watchpack'; + // copied from './watch-story-specifiers.ts' /** Watch the .storybook dir for changes */ export function watchConfig( diff --git a/code/core/src/core-server/utils/whats-new.ts b/code/core/src/core-server/utils/whats-new.ts index 024889025d00..324680c8e0c4 100644 --- a/code/core/src/core-server/utils/whats-new.ts +++ b/code/core/src/core-server/utils/whats-new.ts @@ -1,19 +1,22 @@ -import fs from 'fs-extra'; -import { logger } from '@storybook/core/node-logger'; -import { telemetry } from '@storybook/core/telemetry'; +import type { Channel } from '@storybook/core/channels'; import { findConfigFile } from '@storybook/core/common'; +import { telemetry } from '@storybook/core/telemetry'; import type { CoreConfig, Options } from '@storybook/core/types'; -import { printConfig, readConfig } from '@storybook/core/csf-tools'; -import type { Channel } from '@storybook/core/channels'; + import type { WhatsNewCache, WhatsNewData } from '@storybook/core/core-events'; import { REQUEST_WHATS_NEW_DATA, RESULT_WHATS_NEW_DATA, - TELEMETRY_ERROR, SET_WHATS_NEW_CACHE, + TELEMETRY_ERROR, TOGGLE_WHATS_NEW_NOTIFICATIONS, } from '@storybook/core/core-events'; +import { printConfig, readConfig } from '@storybook/core/csf-tools'; +import { logger } from '@storybook/core/node-logger'; + +import fs from 'fs-extra'; import invariant from 'tiny-invariant'; + import { sendTelemetryError } from '../withTelemetry'; export type OptionsWithRequiredCache = Exclude & Required>; diff --git a/code/core/src/core-server/withTelemetry.test.ts b/code/core/src/core-server/withTelemetry.test.ts index 6c085b6dc9e9..6c0628ec4e1e 100644 --- a/code/core/src/core-server/withTelemetry.test.ts +++ b/code/core/src/core-server/withTelemetry.test.ts @@ -1,7 +1,9 @@ +import { beforeEach, describe, expect, it, vi } from 'vitest'; + +import { cache, loadAllPresets } from '@storybook/core/common'; +import { oneWayHash, telemetry } from '@storybook/core/telemetry'; + import prompts from 'prompts'; -import { describe, beforeEach, it, expect, vi } from 'vitest'; -import { loadAllPresets, cache } from '@storybook/core/common'; -import { telemetry, oneWayHash } from '@storybook/core/telemetry'; import { getErrorLevel, sendTelemetryError, withTelemetry } from './withTelemetry'; diff --git a/code/core/src/core-server/withTelemetry.ts b/code/core/src/core-server/withTelemetry.ts index 7be18cbe15fd..af38bed50a23 100644 --- a/code/core/src/core-server/withTelemetry.ts +++ b/code/core/src/core-server/withTelemetry.ts @@ -1,10 +1,12 @@ -import prompts from 'prompts'; -import type { CLIOptions } from '@storybook/core/types'; -import { loadAllPresets, cache } from '@storybook/core/common'; -import { telemetry, getPrecedingUpgrade, oneWayHash } from '@storybook/core/telemetry'; +import { cache, loadAllPresets } from '@storybook/core/common'; +import { getPrecedingUpgrade, oneWayHash, telemetry } from '@storybook/core/telemetry'; import type { EventType } from '@storybook/core/telemetry'; +import type { CLIOptions } from '@storybook/core/types'; + import { logger } from '@storybook/core/node-logger'; +import prompts from 'prompts'; + type TelemetryOptions = { cliOptions: CLIOptions; presetOptions?: Parameters[0]; diff --git a/code/core/src/csf-tools/ConfigFile.test.ts b/code/core/src/csf-tools/ConfigFile.test.ts index b43e98c93d53..9846837cac44 100644 --- a/code/core/src/csf-tools/ConfigFile.test.ts +++ b/code/core/src/csf-tools/ConfigFile.test.ts @@ -1,5 +1,7 @@ +import { describe, expect, it } from 'vitest'; + import { dedent } from 'ts-dedent'; -import { describe, it, expect } from 'vitest'; + import { loadConfig, printConfig } from './ConfigFile'; import { babelPrint } from './babelParse'; diff --git a/code/core/src/csf-tools/ConfigFile.ts b/code/core/src/csf-tools/ConfigFile.ts index b13e42175a45..a56e3ecf098e 100644 --- a/code/core/src/csf-tools/ConfigFile.ts +++ b/code/core/src/csf-tools/ConfigFile.ts @@ -1,16 +1,15 @@ /* eslint-disable no-underscore-dangle */ import { readFile, writeFile } from 'node:fs/promises'; -import { dedent } from 'ts-dedent'; -import * as t from '@babel/types'; import bg from '@babel/generator'; import bt from '@babel/traverse'; - +import * as t from '@babel/types'; import type { Options } from 'recast'; import * as recast from 'recast'; +import { dedent } from 'ts-dedent'; -import { babelParse } from './babelParse'; import type { PrintResultType } from './PrintResultType'; +import { babelParse } from './babelParse'; // @ts-expect-error (needed due to it's use of `exports.default`) const traverse = (bt.default || bt) as typeof bt; diff --git a/code/core/src/csf-tools/CsfFile.test.ts b/code/core/src/csf-tools/CsfFile.test.ts index 0988e938a51b..f90f25d209f2 100644 --- a/code/core/src/csf-tools/CsfFile.test.ts +++ b/code/core/src/csf-tools/CsfFile.test.ts @@ -1,8 +1,10 @@ /* eslint-disable no-underscore-dangle */ -import { dedent } from 'ts-dedent'; -import { describe, it, expect, vi } from 'vitest'; +import { describe, expect, it, vi } from 'vitest'; + import yaml from 'js-yaml'; -import { loadCsf, isModuleMock } from './CsfFile'; +import { dedent } from 'ts-dedent'; + +import { isModuleMock, loadCsf } from './CsfFile'; expect.addSnapshotSerializer({ print: (val: any) => yaml.dump(val).trimEnd(), @@ -47,6 +49,7 @@ describe('CsfFile', () => { render: false loaders: false beforeEach: false + globals: false storyFn: true mount: false moduleMock: false @@ -60,6 +63,7 @@ describe('CsfFile', () => { render: false loaders: false beforeEach: false + globals: false storyFn: true mount: false moduleMock: false @@ -90,6 +94,7 @@ describe('CsfFile', () => { render: false loaders: false beforeEach: false + globals: false storyFn: false mount: false moduleMock: false @@ -102,6 +107,7 @@ describe('CsfFile', () => { render: false loaders: false beforeEach: false + globals: false storyFn: false mount: false moduleMock: false @@ -131,6 +137,7 @@ describe('CsfFile', () => { render: false loaders: false beforeEach: false + globals: false storyFn: true mount: false moduleMock: false @@ -161,6 +168,7 @@ describe('CsfFile', () => { render: false loaders: false beforeEach: false + globals: false storyFn: true mount: false moduleMock: false @@ -189,6 +197,7 @@ describe('CsfFile', () => { render: false loaders: false beforeEach: false + globals: false storyFn: true mount: false moduleMock: false @@ -215,6 +224,7 @@ describe('CsfFile', () => { render: false loaders: false beforeEach: false + globals: false storyFn: true mount: false moduleMock: false @@ -242,6 +252,7 @@ describe('CsfFile', () => { render: false loaders: false beforeEach: false + globals: false storyFn: true mount: false moduleMock: false @@ -252,6 +263,7 @@ describe('CsfFile', () => { render: false loaders: false beforeEach: false + globals: false storyFn: true mount: false moduleMock: false @@ -279,6 +291,7 @@ describe('CsfFile', () => { render: false loaders: false beforeEach: false + globals: false storyFn: true mount: false moduleMock: false @@ -289,6 +302,7 @@ describe('CsfFile', () => { render: false loaders: false beforeEach: false + globals: false storyFn: true mount: false moduleMock: false @@ -316,6 +330,7 @@ describe('CsfFile', () => { render: false loaders: false beforeEach: false + globals: false storyFn: false mount: false moduleMock: false @@ -326,6 +341,7 @@ describe('CsfFile', () => { render: false loaders: false beforeEach: false + globals: false storyFn: false mount: false moduleMock: false @@ -354,6 +370,7 @@ describe('CsfFile', () => { render: false loaders: false beforeEach: false + globals: false storyFn: true mount: false moduleMock: false @@ -364,6 +381,7 @@ describe('CsfFile', () => { render: false loaders: false beforeEach: false + globals: false storyFn: true mount: false moduleMock: false @@ -396,6 +414,7 @@ describe('CsfFile', () => { render: false loaders: false beforeEach: false + globals: false storyFn: false mount: false moduleMock: false @@ -409,6 +428,7 @@ describe('CsfFile', () => { render: false loaders: false beforeEach: false + globals: false storyFn: false mount: false moduleMock: false @@ -441,6 +461,7 @@ describe('CsfFile', () => { render: false loaders: false beforeEach: false + globals: false storyFn: false mount: false moduleMock: false @@ -454,6 +475,7 @@ describe('CsfFile', () => { render: false loaders: false beforeEach: false + globals: false storyFn: false mount: false moduleMock: false @@ -483,6 +505,7 @@ describe('CsfFile', () => { render: false loaders: false beforeEach: false + globals: false storyFn: true mount: false moduleMock: false @@ -493,6 +516,7 @@ describe('CsfFile', () => { render: false loaders: false beforeEach: false + globals: false storyFn: true mount: false moduleMock: false @@ -522,6 +546,7 @@ describe('CsfFile', () => { render: false loaders: false beforeEach: false + globals: false storyFn: true mount: false moduleMock: false @@ -532,6 +557,7 @@ describe('CsfFile', () => { render: false loaders: false beforeEach: false + globals: false storyFn: true mount: false moduleMock: false @@ -559,6 +585,7 @@ describe('CsfFile', () => { render: false loaders: false beforeEach: false + globals: false storyFn: true mount: false moduleMock: false @@ -569,6 +596,7 @@ describe('CsfFile', () => { render: false loaders: false beforeEach: false + globals: false storyFn: true mount: false moduleMock: false @@ -600,6 +628,7 @@ describe('CsfFile', () => { render: false loaders: false beforeEach: false + globals: false storyFn: true mount: false moduleMock: false @@ -630,6 +659,7 @@ describe('CsfFile', () => { render: false loaders: false beforeEach: false + globals: false storyFn: true mount: false moduleMock: false @@ -661,6 +691,7 @@ describe('CsfFile', () => { render: false loaders: false beforeEach: false + globals: false storyFn: true mount: false moduleMock: false @@ -697,6 +728,7 @@ describe('CsfFile', () => { render: false loaders: false beforeEach: false + globals: false storyFn: true mount: false moduleMock: false @@ -728,6 +760,7 @@ describe('CsfFile', () => { render: false loaders: false beforeEach: false + globals: false storyFn: true mount: false moduleMock: false @@ -741,6 +774,7 @@ describe('CsfFile', () => { render: false loaders: false beforeEach: false + globals: false storyFn: true mount: false moduleMock: false @@ -767,6 +801,7 @@ describe('CsfFile', () => { render: false loaders: false beforeEach: false + globals: false storyFn: false mount: false moduleMock: false @@ -777,6 +812,7 @@ describe('CsfFile', () => { render: false loaders: false beforeEach: false + globals: false storyFn: false mount: false moduleMock: false @@ -808,6 +844,7 @@ describe('CsfFile', () => { render: false loaders: false beforeEach: false + globals: false storyFn: true mount: false moduleMock: false @@ -821,6 +858,7 @@ describe('CsfFile', () => { render: false loaders: false beforeEach: false + globals: false storyFn: true mount: false moduleMock: false @@ -853,6 +891,7 @@ describe('CsfFile', () => { render: false loaders: false beforeEach: false + globals: false storyFn: true mount: false moduleMock: false @@ -932,6 +971,7 @@ describe('CsfFile', () => { render: false loaders: false beforeEach: false + globals: false storyFn: true mount: false moduleMock: false @@ -942,6 +982,7 @@ describe('CsfFile', () => { render: false loaders: false beforeEach: false + globals: false storyFn: true mount: false moduleMock: false @@ -994,6 +1035,7 @@ describe('CsfFile', () => { render: false loaders: false beforeEach: false + globals: false storyFn: true mount: false moduleMock: false @@ -1004,6 +1046,7 @@ describe('CsfFile', () => { render: false loaders: false beforeEach: false + globals: false storyFn: true mount: false moduleMock: false @@ -1080,6 +1123,7 @@ describe('CsfFile', () => { render: true loaders: false beforeEach: false + globals: false storyFn: false mount: false moduleMock: false @@ -1111,6 +1155,7 @@ describe('CsfFile', () => { render: true loaders: false beforeEach: false + globals: false storyFn: false mount: false moduleMock: false @@ -1140,6 +1185,7 @@ describe('CsfFile', () => { render: false loaders: false beforeEach: false + globals: false storyFn: false mount: false moduleMock: false @@ -1171,6 +1217,7 @@ describe('CsfFile', () => { render: false loaders: false beforeEach: false + globals: false storyFn: false mount: false moduleMock: false @@ -1251,6 +1298,7 @@ describe('CsfFile', () => { render: false loaders: false beforeEach: false + globals: false storyFn: true mount: false moduleMock: false @@ -1283,6 +1331,7 @@ describe('CsfFile', () => { render: true loaders: false beforeEach: false + globals: false storyFn: false mount: false moduleMock: false @@ -1317,6 +1366,7 @@ describe('CsfFile', () => { render: true loaders: false beforeEach: false + globals: false storyFn: false mount: false moduleMock: false @@ -1376,6 +1426,7 @@ describe('CsfFile', () => { render: false loaders: false beforeEach: false + globals: false storyFn: true mount: false moduleMock: false @@ -1410,6 +1461,7 @@ describe('CsfFile', () => { render: true loaders: false beforeEach: false + globals: false storyFn: false mount: false moduleMock: false @@ -1440,6 +1492,7 @@ describe('CsfFile', () => { render: false loaders: false beforeEach: false + globals: false storyFn: false mount: true moduleMock: false @@ -1469,6 +1522,7 @@ describe('CsfFile', () => { render: false loaders: false beforeEach: false + globals: false storyFn: false mount: true moduleMock: false @@ -1501,6 +1555,7 @@ describe('CsfFile', () => { render: false loaders: false beforeEach: false + globals: false storyFn: false mount: true moduleMock: false @@ -1533,6 +1588,7 @@ describe('CsfFile', () => { render: true loaders: true beforeEach: false + globals: false storyFn: false mount: false moduleMock: false @@ -1564,6 +1620,7 @@ describe('CsfFile', () => { render: false loaders: false beforeEach: false + globals: false storyFn: true mount: false moduleMock: false @@ -1613,6 +1670,7 @@ describe('CsfFile', () => { render: false loaders: false beforeEach: false + globals: false storyFn: false mount: false moduleMock: false @@ -1632,6 +1690,7 @@ describe('CsfFile', () => { render: false loaders: false beforeEach: false + globals: false storyFn: false mount: false moduleMock: false @@ -1669,6 +1728,7 @@ describe('CsfFile', () => { render: false loaders: false beforeEach: false + globals: false storyFn: false mount: false moduleMock: false @@ -1711,6 +1771,7 @@ describe('CsfFile', () => { render: false loaders: false beforeEach: false + globals: false storyFn: false mount: false moduleMock: false @@ -1768,6 +1829,7 @@ describe('CsfFile', () => { render: true loaders: false beforeEach: false + globals: false storyFn: false mount: false moduleMock: false @@ -1804,6 +1866,7 @@ describe('CsfFile', () => { render: true loaders: false beforeEach: false + globals: false storyFn: false mount: false moduleMock: false @@ -1840,6 +1903,7 @@ describe('CsfFile', () => { render: true loaders: false beforeEach: false + globals: false storyFn: false mount: false moduleMock: false @@ -1876,6 +1940,7 @@ describe('CsfFile', () => { render: true loaders: false beforeEach: false + globals: false storyFn: false mount: false moduleMock: false @@ -1905,6 +1970,37 @@ describe('CsfFile', () => { render: false loaders: false beforeEach: true + globals: false + storyFn: false + mount: false + moduleMock: false + `); + }); + }); + + describe('globals', () => { + it('basic', () => { + expect( + parse( + dedent` + export default { title: 'foo/bar' }; + export const A = { + globals: { foo: 'bar' } + }; + ` + ) + ).toMatchInlineSnapshot(` + meta: + title: foo/bar + stories: + - id: foo-bar--a + name: A + __stats: + play: false + render: false + loaders: false + beforeEach: false + globals: true storyFn: false mount: false moduleMock: false @@ -1933,6 +2029,7 @@ describe('CsfFile', () => { render: false loaders: false beforeEach: false + globals: false storyFn: false mount: false moduleMock: true @@ -1958,6 +2055,7 @@ describe('CsfFile', () => { render: false loaders: false beforeEach: false + globals: false storyFn: false mount: false moduleMock: true diff --git a/code/core/src/csf-tools/CsfFile.ts b/code/core/src/csf-tools/CsfFile.ts index 149a182bcf7d..de422f321333 100644 --- a/code/core/src/csf-tools/CsfFile.ts +++ b/code/core/src/csf-tools/CsfFile.ts @@ -1,26 +1,26 @@ /* eslint-disable no-underscore-dangle */ import { readFile, writeFile } from 'node:fs/promises'; -import { dedent } from 'ts-dedent'; - -import * as t from '@babel/types'; -import bg, { type GeneratorOptions } from '@babel/generator'; -import bt from '@babel/traverse'; -import * as recast from 'recast'; - -import { toId, isExportStory, storyNameFromExport } from '@storybook/csf'; import type { - Tag, - StoryAnnotations, ComponentAnnotations, - IndexedCSFFile, IndexInput, IndexInputStats, + IndexedCSFFile, + StoryAnnotations, + Tag, } from '@storybook/core/types'; +import { isExportStory, storyNameFromExport, toId } from '@storybook/csf'; + +import bg, { type GeneratorOptions } from '@babel/generator'; +import bt from '@babel/traverse'; +import * as t from '@babel/types'; +import * as recast from 'recast'; import type { Options } from 'recast'; +import { dedent } from 'ts-dedent'; + +import type { PrintResultType } from './PrintResultType'; import { babelParse } from './babelParse'; import { findVarInitialization } from './findVarInitialization'; -import type { PrintResultType } from './PrintResultType'; // @ts-expect-error (needed due to it's use of `exports.default`) const traverse = (bt.default || bt) as typeof bt; @@ -566,7 +566,7 @@ export class CsfFile { acc[key].tags = [...(acc[key].tags || []), 'play-fn']; } const stats = acc[key].__stats; - ['play', 'render', 'loaders', 'beforeEach'].forEach((annotation) => { + ['play', 'render', 'loaders', 'beforeEach', 'globals'].forEach((annotation) => { stats[annotation as keyof IndexInputStats] = !!storyAnnotations[annotation] || !!self._metaAnnotations[annotation]; }); diff --git a/code/core/src/csf-tools/babelParse.ts b/code/core/src/csf-tools/babelParse.ts index 9e3aaf8b53de..c802734ef675 100644 --- a/code/core/src/csf-tools/babelParse.ts +++ b/code/core/src/csf-tools/babelParse.ts @@ -1,7 +1,7 @@ -import type * as t from '@babel/types'; import * as babelParser from '@babel/parser'; -import * as recast from 'recast'; import type { ParserOptions } from '@babel/parser'; +import type * as t from '@babel/types'; +import * as recast from 'recast'; function parseWithFlowOrTypescript(source: string, parserOptions: babelParser.ParserOptions) { const flowCommentPattern = /^\s*\/\/\s*@flow/; diff --git a/code/core/src/csf-tools/enrichCsf.test.ts b/code/core/src/csf-tools/enrichCsf.test.ts index 562cacd8c04b..e8c0ce6250eb 100644 --- a/code/core/src/csf-tools/enrichCsf.test.ts +++ b/code/core/src/csf-tools/enrichCsf.test.ts @@ -1,6 +1,8 @@ /* eslint-disable no-underscore-dangle */ +import { describe, expect, it } from 'vitest'; + import { dedent } from 'ts-dedent'; -import { describe, it, expect } from 'vitest'; + import { formatCsf, loadCsf } from './CsfFile'; import type { EnrichCsfOptions } from './enrichCsf'; import { enrichCsf, extractSource } from './enrichCsf'; diff --git a/code/core/src/csf-tools/enrichCsf.ts b/code/core/src/csf-tools/enrichCsf.ts index dc267458854d..b14e146b1d31 100644 --- a/code/core/src/csf-tools/enrichCsf.ts +++ b/code/core/src/csf-tools/enrichCsf.ts @@ -1,7 +1,7 @@ /* eslint-disable no-underscore-dangle */ +import bg from '@babel/generator'; import * as t from '@babel/types'; -import bg from '@babel/generator'; import type { CsfFile } from './CsfFile'; // @ts-expect-error (needed due to it's use of `exports.default`) diff --git a/code/core/src/csf-tools/getStorySortParameter.test.ts b/code/core/src/csf-tools/getStorySortParameter.test.ts index b2672bb0198c..565e0e10fdf2 100644 --- a/code/core/src/csf-tools/getStorySortParameter.test.ts +++ b/code/core/src/csf-tools/getStorySortParameter.test.ts @@ -1,5 +1,7 @@ -import { describe, it, expect } from 'vitest'; +import { describe, expect, it } from 'vitest'; + import { dedent } from 'ts-dedent'; + import { getStorySortParameter } from './getStorySortParameter'; describe('getStorySortParameter', () => { diff --git a/code/core/src/csf-tools/getStorySortParameter.ts b/code/core/src/csf-tools/getStorySortParameter.ts index 07202029aba7..7766b114935f 100644 --- a/code/core/src/csf-tools/getStorySortParameter.ts +++ b/code/core/src/csf-tools/getStorySortParameter.ts @@ -1,8 +1,8 @@ -import * as t from '@babel/types'; -import bt from '@babel/traverse'; import bg from '@babel/generator'; - +import bt from '@babel/traverse'; +import * as t from '@babel/types'; import { dedent } from 'ts-dedent'; + import { babelParse } from './babelParse'; import { findVarInitialization } from './findVarInitialization'; diff --git a/code/core/src/docs-tools/argTypes/convert/__testfixtures__/proptypes/arrays.js b/code/core/src/docs-tools/argTypes/convert/__testfixtures__/proptypes/arrays.js index 0f1ebcdae092..b3cb9649b70c 100644 --- a/code/core/src/docs-tools/argTypes/convert/__testfixtures__/proptypes/arrays.js +++ b/code/core/src/docs-tools/argTypes/convert/__testfixtures__/proptypes/arrays.js @@ -1,4 +1,5 @@ import React from 'react'; + import PropTypes from 'prop-types'; export const Component = (props) => <>JSON.stringify(props); diff --git a/code/core/src/docs-tools/argTypes/convert/__testfixtures__/proptypes/enums.js b/code/core/src/docs-tools/argTypes/convert/__testfixtures__/proptypes/enums.js index d8baae693125..2bfa6a5e7417 100644 --- a/code/core/src/docs-tools/argTypes/convert/__testfixtures__/proptypes/enums.js +++ b/code/core/src/docs-tools/argTypes/convert/__testfixtures__/proptypes/enums.js @@ -1,4 +1,5 @@ import React from 'react'; + import PropTypes from 'prop-types'; export const Component = (props) => <>JSON.stringify(props); diff --git a/code/core/src/docs-tools/argTypes/convert/__testfixtures__/proptypes/misc.js b/code/core/src/docs-tools/argTypes/convert/__testfixtures__/proptypes/misc.js index e662474d1ab1..a5e0d60dcf70 100644 --- a/code/core/src/docs-tools/argTypes/convert/__testfixtures__/proptypes/misc.js +++ b/code/core/src/docs-tools/argTypes/convert/__testfixtures__/proptypes/misc.js @@ -1,4 +1,5 @@ import React from 'react'; + import PropTypes from 'prop-types'; export const Component = (props) => <>JSON.stringify(props); diff --git a/code/core/src/docs-tools/argTypes/convert/__testfixtures__/proptypes/objects.js b/code/core/src/docs-tools/argTypes/convert/__testfixtures__/proptypes/objects.js index 09036cf88088..12d81862672a 100644 --- a/code/core/src/docs-tools/argTypes/convert/__testfixtures__/proptypes/objects.js +++ b/code/core/src/docs-tools/argTypes/convert/__testfixtures__/proptypes/objects.js @@ -1,4 +1,5 @@ import React from 'react'; + import PropTypes from 'prop-types'; export const Component = (props) => <>JSON.stringify(props); diff --git a/code/core/src/docs-tools/argTypes/convert/__testfixtures__/proptypes/react.js b/code/core/src/docs-tools/argTypes/convert/__testfixtures__/proptypes/react.js index fd54e9307663..0b772151166a 100644 --- a/code/core/src/docs-tools/argTypes/convert/__testfixtures__/proptypes/react.js +++ b/code/core/src/docs-tools/argTypes/convert/__testfixtures__/proptypes/react.js @@ -1,4 +1,5 @@ import React from 'react'; + import PropTypes from 'prop-types'; export const Component = (props) => <>JSON.stringify(props); diff --git a/code/core/src/docs-tools/argTypes/convert/__testfixtures__/proptypes/scalars.js b/code/core/src/docs-tools/argTypes/convert/__testfixtures__/proptypes/scalars.js index 7e74151596b0..c28a4e4bb991 100644 --- a/code/core/src/docs-tools/argTypes/convert/__testfixtures__/proptypes/scalars.js +++ b/code/core/src/docs-tools/argTypes/convert/__testfixtures__/proptypes/scalars.js @@ -1,4 +1,5 @@ import React from 'react'; + import PropTypes from 'prop-types'; export const Component = (props) => <>JSON.stringify(props); diff --git a/code/core/src/docs-tools/argTypes/convert/convert.test.ts b/code/core/src/docs-tools/argTypes/convert/convert.test.ts index 3d33efd5ea73..e88f8d00a226 100644 --- a/code/core/src/docs-tools/argTypes/convert/convert.test.ts +++ b/code/core/src/docs-tools/argTypes/convert/convert.test.ts @@ -1,11 +1,13 @@ -import { describe, it, expect } from 'vitest'; -import mapValues from 'lodash/mapValues.js'; +import { readFileSync } from 'node:fs'; + +import { describe, expect, it } from 'vitest'; + import { transformSync } from '@babel/core'; +import mapValues from 'lodash/mapValues.js'; import requireFromString from 'require-from-string'; -import fs from 'node:fs'; -import { convert } from './index'; import { normalizeNewlines } from '../utils'; +import { convert } from './index'; expect.addSnapshotSerializer({ print: (val: any) => JSON.stringify(val, null, 2), @@ -508,6 +510,7 @@ describe('storybook type system', () => { const input = readFixture('proptypes/scalars.js'); expect(input).toMatchInlineSnapshot(` "import React from 'react'; + import PropTypes from 'prop-types'; export const Component = (props) => <>JSON.stringify(props); @@ -544,6 +547,7 @@ describe('storybook type system', () => { const input = readFixture('proptypes/arrays.js'); expect(input).toMatchInlineSnapshot(` "import React from 'react'; + import PropTypes from 'prop-types'; export const Component = (props) => <>JSON.stringify(props); @@ -587,6 +591,7 @@ describe('storybook type system', () => { const input = readFixture('proptypes/enums.js'); expect(input).toMatchInlineSnapshot(` "import React from 'react'; + import PropTypes from 'prop-types'; export const Component = (props) => <>JSON.stringify(props); @@ -638,6 +643,7 @@ describe('storybook type system', () => { const input = readFixture('proptypes/misc.js'); expect(input).toMatchInlineSnapshot(` "import React from 'react'; + import PropTypes from 'prop-types'; export const Component = (props) => <>JSON.stringify(props); @@ -686,6 +692,7 @@ describe('storybook type system', () => { const input = readFixture('proptypes/objects.js'); expect(input).toMatchInlineSnapshot(` "import React from 'react'; + import PropTypes from 'prop-types'; export const Component = (props) => <>JSON.stringify(props); @@ -743,6 +750,7 @@ describe('storybook type system', () => { const input = readFixture('proptypes/react.js'); expect(input).toMatchInlineSnapshot(` "import React from 'react'; + import PropTypes from 'prop-types'; export const Component = (props) => <>JSON.stringify(props); @@ -778,7 +786,7 @@ describe('storybook type system', () => { }); const readFixture = (fixture: string) => - fs.readFileSync(`${__dirname}/__testfixtures__/${fixture}`).toString(); + readFileSync(`${__dirname}/__testfixtures__/${fixture}`).toString(); const transformToModule = (inputCode: string) => { const options = { diff --git a/code/core/src/docs-tools/argTypes/convert/flow/convert.ts b/code/core/src/docs-tools/argTypes/convert/flow/convert.ts index 0166ccfb86da..fe5ecc6a8b7c 100644 --- a/code/core/src/docs-tools/argTypes/convert/flow/convert.ts +++ b/code/core/src/docs-tools/argTypes/convert/flow/convert.ts @@ -1,6 +1,8 @@ -import { UnknownArgTypesError } from '@storybook/core/preview-errors'; import type { SBType } from '@storybook/core/types'; -import type { FlowType, FlowSigType, FlowLiteralType } from './types'; + +import { UnknownArgTypesError } from '@storybook/core/preview-errors'; + +import type { FlowLiteralType, FlowSigType, FlowType } from './types'; const isLiteral = (type: FlowType): type is FlowLiteralType => type.name === 'literal'; const toEnumOption = (element: FlowLiteralType) => element.value.replace(/['|"]/g, ''); diff --git a/code/core/src/docs-tools/argTypes/convert/index.ts b/code/core/src/docs-tools/argTypes/convert/index.ts index 812fcf517896..1076e9950e97 100644 --- a/code/core/src/docs-tools/argTypes/convert/index.ts +++ b/code/core/src/docs-tools/argTypes/convert/index.ts @@ -1,9 +1,9 @@ import type { DocgenInfo } from '../docgen/types'; -import type { TSType } from './typescript'; -import { convert as tsConvert } from './typescript'; import type { FlowType } from './flow'; import { convert as flowConvert } from './flow'; import { convert as propTypesConvert } from './proptypes'; +import type { TSType } from './typescript'; +import { convert as tsConvert } from './typescript'; export const convert = (docgenInfo: DocgenInfo) => { const { type, tsType, flowType } = docgenInfo; diff --git a/code/core/src/docs-tools/argTypes/convert/proptypes/convert.ts b/code/core/src/docs-tools/argTypes/convert/proptypes/convert.ts index 895b275e244c..4934af202b49 100644 --- a/code/core/src/docs-tools/argTypes/convert/proptypes/convert.ts +++ b/code/core/src/docs-tools/argTypes/convert/proptypes/convert.ts @@ -1,7 +1,9 @@ -import mapValues from 'lodash/mapValues.js'; import type { SBType } from '@storybook/core/types'; -import type { PTType } from './types'; + +import mapValues from 'lodash/mapValues.js'; + import { parseLiteral } from '../utils'; +import type { PTType } from './types'; const SIGNATURE_REGEXP = /^\(.*\) => /; diff --git a/code/core/src/docs-tools/argTypes/convert/typescript/convert.ts b/code/core/src/docs-tools/argTypes/convert/typescript/convert.ts index 248dfba4f2b2..bfb8312d2043 100644 --- a/code/core/src/docs-tools/argTypes/convert/typescript/convert.ts +++ b/code/core/src/docs-tools/argTypes/convert/typescript/convert.ts @@ -1,7 +1,9 @@ -import { UnknownArgTypesError } from '@storybook/core/preview-errors'; import type { SBType } from '@storybook/core/types'; -import type { TSType, TSSigType } from './types'; + +import { UnknownArgTypesError } from '@storybook/core/preview-errors'; + import { parseLiteral } from '../utils'; +import type { TSSigType, TSType } from './types'; const convertSig = (type: TSSigType) => { switch (type.type) { diff --git a/code/core/src/docs-tools/argTypes/docgen/createPropDef.ts b/code/core/src/docs-tools/argTypes/docgen/createPropDef.ts index 4fd5b7f48b04..ea903a9378df 100644 --- a/code/core/src/docs-tools/argTypes/docgen/createPropDef.ts +++ b/code/core/src/docs-tools/argTypes/docgen/createPropDef.ts @@ -1,15 +1,12 @@ -import type { JsDocParam, PropDefaultValue } from './PropDef'; -import type { PropDef, DocgenInfo, DocgenType, DocgenPropDefaultValue } from './types'; -import { TypeSystem } from './types'; +import { convert } from '../convert'; import type { JsDocParsingResult } from '../jsdocParser'; - import { createSummaryValue } from '../utils'; - +import type { JsDocParam, PropDefaultValue } from './PropDef'; import { createFlowPropDef } from './flow/createPropDef'; -import { isDefaultValueBlacklisted } from './utils/defaultValue'; - import { createTsPropDef } from './typeScript/createPropDef'; -import { convert } from '../convert'; +import type { DocgenInfo, DocgenPropDefaultValue, DocgenType, PropDef } from './types'; +import { TypeSystem } from './types'; +import { isDefaultValueBlacklisted } from './utils/defaultValue'; export type PropDefFactory = ( propName: string, diff --git a/code/core/src/docs-tools/argTypes/docgen/extractDocgenProps.test.ts b/code/core/src/docs-tools/argTypes/docgen/extractDocgenProps.test.ts index 3a8cdc650bf1..83e8f09b8675 100644 --- a/code/core/src/docs-tools/argTypes/docgen/extractDocgenProps.test.ts +++ b/code/core/src/docs-tools/argTypes/docgen/extractDocgenProps.test.ts @@ -1,5 +1,5 @@ /* eslint-disable no-underscore-dangle */ -import { describe, it, expect } from 'vitest'; +import { describe, expect, it } from 'vitest'; import type { Component } from '../types'; import { extractComponentProps } from './extractDocgenProps'; diff --git a/code/core/src/docs-tools/argTypes/docgen/extractDocgenProps.ts b/code/core/src/docs-tools/argTypes/docgen/extractDocgenProps.ts index 3ed22e31d224..1a4d595ad844 100644 --- a/code/core/src/docs-tools/argTypes/docgen/extractDocgenProps.ts +++ b/code/core/src/docs-tools/argTypes/docgen/extractDocgenProps.ts @@ -1,12 +1,11 @@ -import type { Component } from '../types'; import type { ExtractedJsDoc } from '../jsdocParser'; import { parseJsDoc } from '../jsdocParser'; -import type { PropDef, DocgenInfo } from './types'; -import { TypeSystem } from './types'; -import { getDocgenSection, isValidDocgenSection, getDocgenDescription } from './utils'; - +import type { Component } from '../types'; import type { PropDefFactory } from './createPropDef'; import { getPropDefFactory } from './createPropDef'; +import type { DocgenInfo, PropDef } from './types'; +import { TypeSystem } from './types'; +import { getDocgenDescription, getDocgenSection, isValidDocgenSection } from './utils'; export interface ExtractedProp { propDef: PropDef; diff --git a/code/core/src/docs-tools/argTypes/docgen/flow/createDefaultValue.ts b/code/core/src/docs-tools/argTypes/docgen/flow/createDefaultValue.ts index 3bb55aec2c6c..00645488910a 100644 --- a/code/core/src/docs-tools/argTypes/docgen/flow/createDefaultValue.ts +++ b/code/core/src/docs-tools/argTypes/docgen/flow/createDefaultValue.ts @@ -1,7 +1,6 @@ +import { createSummaryValue, isTooLongForDefaultValueSummary } from '../../utils'; import type { PropDefaultValue } from '../PropDef'; import type { DocgenPropDefaultValue, DocgenPropType } from '../types'; - -import { createSummaryValue, isTooLongForDefaultValueSummary } from '../../utils'; import { isDefaultValueBlacklisted } from '../utils/defaultValue'; export function createDefaultValue( diff --git a/code/core/src/docs-tools/argTypes/docgen/flow/createPropDef.test.ts b/code/core/src/docs-tools/argTypes/docgen/flow/createPropDef.test.ts index 50cc5d8e95ee..95959caec2f1 100644 --- a/code/core/src/docs-tools/argTypes/docgen/flow/createPropDef.test.ts +++ b/code/core/src/docs-tools/argTypes/docgen/flow/createPropDef.test.ts @@ -1,6 +1,7 @@ -import { describe, it, expect } from 'vitest'; -import { createFlowPropDef } from './createPropDef'; +import { describe, expect, it } from 'vitest'; + import type { DocgenInfo } from '../types'; +import { createFlowPropDef } from './createPropDef'; const PROP_NAME = 'propName'; diff --git a/code/core/src/docs-tools/argTypes/docgen/flow/createPropDef.ts b/code/core/src/docs-tools/argTypes/docgen/flow/createPropDef.ts index edbad170e702..53c07e365513 100644 --- a/code/core/src/docs-tools/argTypes/docgen/flow/createPropDef.ts +++ b/code/core/src/docs-tools/argTypes/docgen/flow/createPropDef.ts @@ -1,8 +1,6 @@ import type { PropDefFactory } from '../createPropDef'; - -import { createType } from './createType'; - import { createDefaultValue } from './createDefaultValue'; +import { createType } from './createType'; export const createFlowPropDef: PropDefFactory = (propName, docgenInfo) => { const { flowType, description, required, defaultValue } = docgenInfo; diff --git a/code/core/src/docs-tools/argTypes/docgen/flow/createType.ts b/code/core/src/docs-tools/argTypes/docgen/flow/createType.ts index d4c4bb358f29..03a4dc7885f2 100644 --- a/code/core/src/docs-tools/argTypes/docgen/flow/createType.ts +++ b/code/core/src/docs-tools/argTypes/docgen/flow/createType.ts @@ -1,8 +1,7 @@ +import { createSummaryValue, isTooLongForTypeSummary } from '../../utils'; import type { PropType } from '../PropDef'; import type { DocgenFlowType } from '../types'; -import { createSummaryValue, isTooLongForTypeSummary } from '../../utils'; - enum FlowTypesType { UNION = 'union', SIGNATURE = 'signature', diff --git a/code/core/src/docs-tools/argTypes/docgen/typeScript/createDefaultValue.ts b/code/core/src/docs-tools/argTypes/docgen/typeScript/createDefaultValue.ts index 79dc5bcc1c55..de1d5335063e 100644 --- a/code/core/src/docs-tools/argTypes/docgen/typeScript/createDefaultValue.ts +++ b/code/core/src/docs-tools/argTypes/docgen/typeScript/createDefaultValue.ts @@ -1,7 +1,6 @@ +import { createSummaryValue } from '../../utils'; import type { PropDefaultValue } from '../PropDef'; import type { DocgenInfo } from '../types'; - -import { createSummaryValue } from '../../utils'; import { isDefaultValueBlacklisted } from '../utils/defaultValue'; export function createDefaultValue({ defaultValue }: DocgenInfo): PropDefaultValue | null { diff --git a/code/core/src/docs-tools/argTypes/docgen/typeScript/createPropDef.test.ts b/code/core/src/docs-tools/argTypes/docgen/typeScript/createPropDef.test.ts index 12fe6c24b514..e816d87ecc1e 100644 --- a/code/core/src/docs-tools/argTypes/docgen/typeScript/createPropDef.test.ts +++ b/code/core/src/docs-tools/argTypes/docgen/typeScript/createPropDef.test.ts @@ -1,6 +1,7 @@ -import { describe, it, expect } from 'vitest'; -import { createTsPropDef } from './createPropDef'; +import { describe, expect, it } from 'vitest'; + import type { DocgenInfo } from '../types'; +import { createTsPropDef } from './createPropDef'; const PROP_NAME = 'propName'; diff --git a/code/core/src/docs-tools/argTypes/docgen/typeScript/createPropDef.ts b/code/core/src/docs-tools/argTypes/docgen/typeScript/createPropDef.ts index c6a7f904e3b0..fd81a7a6ed69 100644 --- a/code/core/src/docs-tools/argTypes/docgen/typeScript/createPropDef.ts +++ b/code/core/src/docs-tools/argTypes/docgen/typeScript/createPropDef.ts @@ -1,8 +1,6 @@ import type { PropDefFactory } from '../createPropDef'; - -import { createType } from './createType'; - import { createDefaultValue } from './createDefaultValue'; +import { createType } from './createType'; export const createTsPropDef: PropDefFactory = (propName, docgenInfo) => { const { description, required } = docgenInfo; diff --git a/code/core/src/docs-tools/argTypes/docgen/typeScript/createType.ts b/code/core/src/docs-tools/argTypes/docgen/typeScript/createType.ts index af37d97e1dc0..c7408df13b39 100644 --- a/code/core/src/docs-tools/argTypes/docgen/typeScript/createType.ts +++ b/code/core/src/docs-tools/argTypes/docgen/typeScript/createType.ts @@ -1,8 +1,7 @@ +import { createSummaryValue } from '../../utils'; import type { PropType } from '../PropDef'; import type { DocgenInfo } from '../types'; -import { createSummaryValue } from '../../utils'; - export function createType({ tsType, required }: DocgenInfo): PropType | null { // A type could be null if a defaultProp has been provided without a type definition. if (tsType == null) { diff --git a/code/core/src/docs-tools/argTypes/docgen/types.ts b/code/core/src/docs-tools/argTypes/docgen/types.ts index dc059af40ed5..9639be964e00 100644 --- a/code/core/src/docs-tools/argTypes/docgen/types.ts +++ b/code/core/src/docs-tools/argTypes/docgen/types.ts @@ -1,6 +1,7 @@ import type { StrictArgTypes } from '@storybook/core/types'; -import type { PropDef } from './PropDef'; + import type { Component } from '../types'; +import type { PropDef } from './PropDef'; export type PropsExtractor = (component: Component) => { rows?: PropDef[] } | null; diff --git a/code/core/src/docs-tools/argTypes/docgen/utils/docgenInfo.ts b/code/core/src/docs-tools/argTypes/docgen/utils/docgenInfo.ts index 6d1a7005ca0c..03cd442cf805 100644 --- a/code/core/src/docs-tools/argTypes/docgen/utils/docgenInfo.ts +++ b/code/core/src/docs-tools/argTypes/docgen/utils/docgenInfo.ts @@ -1,5 +1,4 @@ /* eslint-disable no-underscore-dangle */ - import type { Component } from '../../types'; import { str } from './string'; diff --git a/code/core/src/docs-tools/argTypes/enhanceArgTypes.test.ts b/code/core/src/docs-tools/argTypes/enhanceArgTypes.test.ts index a3a83ab2c93c..55b70ef2ea52 100644 --- a/code/core/src/docs-tools/argTypes/enhanceArgTypes.test.ts +++ b/code/core/src/docs-tools/argTypes/enhanceArgTypes.test.ts @@ -1,5 +1,7 @@ -import { describe, it, expect } from 'vitest'; +import { describe, expect, it } from 'vitest'; + import type { ArgTypes, StrictInputType } from '@storybook/core/types'; + import { enhanceArgTypes } from './enhanceArgTypes'; expect.addSnapshotSerializer({ diff --git a/code/core/src/docs-tools/argTypes/enhanceArgTypes.ts b/code/core/src/docs-tools/argTypes/enhanceArgTypes.ts index 09736e160ce1..96cc2ce44d67 100644 --- a/code/core/src/docs-tools/argTypes/enhanceArgTypes.ts +++ b/code/core/src/docs-tools/argTypes/enhanceArgTypes.ts @@ -1,4 +1,5 @@ import type { Renderer, StoryContextForEnhancers } from '@storybook/core/types'; + import { combineParameters } from '@storybook/core/preview-api'; export const enhanceArgTypes = ( diff --git a/code/core/src/docs-tools/argTypes/jsdocParser.test.ts b/code/core/src/docs-tools/argTypes/jsdocParser.test.ts index e0f83617605d..899736513476 100644 --- a/code/core/src/docs-tools/argTypes/jsdocParser.test.ts +++ b/code/core/src/docs-tools/argTypes/jsdocParser.test.ts @@ -1,4 +1,5 @@ -import { describe, it, expect } from 'vitest'; +import { describe, expect, it } from 'vitest'; + import { parseJsDoc } from './jsdocParser'; describe('parseJsDoc', () => { diff --git a/code/core/src/docs-tools/argTypes/jsdocParser.ts b/code/core/src/docs-tools/argTypes/jsdocParser.ts index 0990865a14c4..887bab58c719 100644 --- a/code/core/src/docs-tools/argTypes/jsdocParser.ts +++ b/code/core/src/docs-tools/argTypes/jsdocParser.ts @@ -1,11 +1,12 @@ import type { Block, Spec } from 'comment-parser'; -import type { RootResult as JSDocType } from 'jsdoc-type-pratt-parser'; import { parse as parseJSDoc } from 'comment-parser'; +import type { RootResult as JSDocType } from 'jsdoc-type-pratt-parser'; import { parse as parseJSDocType, - transform as transformJSDocType, stringifyRules, + transform as transformJSDocType, } from 'jsdoc-type-pratt-parser'; + import type { JsDocParam, JsDocReturns } from './docgen'; export interface ExtractedJsDocParam extends JsDocParam { diff --git a/code/core/src/docs-tools/argTypes/utils.test.ts b/code/core/src/docs-tools/argTypes/utils.test.ts index fc0a204a531c..4ebfba015844 100644 --- a/code/core/src/docs-tools/argTypes/utils.test.ts +++ b/code/core/src/docs-tools/argTypes/utils.test.ts @@ -1,4 +1,5 @@ -import { describe, it, expect } from 'vitest'; +import { describe, expect, it } from 'vitest'; + import { createSummaryValue } from './utils'; describe('createSummaryValue', () => { diff --git a/code/core/src/manager-api/context.ts b/code/core/src/manager-api/context.ts index c0e2053c4ff0..2344d8361ac6 100644 --- a/code/core/src/manager-api/context.ts +++ b/code/core/src/manager-api/context.ts @@ -1,4 +1,5 @@ import { createContext as ReactCreateContext } from 'react'; + import type { Combo } from './root'; export const createContext = ({ api, state }: Combo) => ReactCreateContext({ api, state }); diff --git a/code/core/src/manager-api/initial-state.ts b/code/core/src/manager-api/initial-state.ts index fa862a9b5892..583944b81be8 100644 --- a/code/core/src/manager-api/initial-state.ts +++ b/code/core/src/manager-api/initial-state.ts @@ -1,5 +1,4 @@ import merge from './lib/merge'; - import type { State } from './root'; interface Addition { diff --git a/code/core/src/manager-api/lib/addons.ts b/code/core/src/manager-api/lib/addons.ts index c463a9ca4744..f782e80713ed 100644 --- a/code/core/src/manager-api/lib/addons.ts +++ b/code/core/src/manager-api/lib/addons.ts @@ -1,23 +1,24 @@ -import { global } from '@storybook/global'; - import type { Channel } from '@storybook/core/channels'; -import { SET_CONFIG } from '@storybook/core/core-events'; import type { + Addon_BaseType, Addon_Collection, Addon_Config, Addon_Elements, Addon_Loaders, - Addon_Type, - Addon_BaseType, Addon_PageType, + Addon_SidebarBottomType, + Addon_SidebarTopType, + Addon_Type, Addon_Types, Addon_TypesMapping, Addon_WrapperType, - Addon_SidebarBottomType, - Addon_SidebarTopType, } from '@storybook/core/types'; import { Addon_TypesEnum } from '@storybook/core/types'; +import { global } from '@storybook/global'; + import { logger } from '@storybook/core/client-logger'; +import { SET_CONFIG } from '@storybook/core/core-events'; + import type { API } from '../root'; import { mockChannel } from './storybook-channel-mock'; diff --git a/code/core/src/manager-api/lib/events.ts b/code/core/src/manager-api/lib/events.ts index b896961187c3..f964626ac8ef 100644 --- a/code/core/src/manager-api/lib/events.ts +++ b/code/core/src/manager-api/lib/events.ts @@ -1,7 +1,7 @@ -import { logger } from '@storybook/core/client-logger'; - import type { API_ComposedRef } from '@storybook/core/types'; +import { logger } from '@storybook/core/client-logger'; + import { getSourceType } from '../modules/refs'; import type { API } from '../root'; diff --git a/code/core/src/manager-api/lib/merge.ts b/code/core/src/manager-api/lib/merge.ts index e6b7eabf8e9e..ec4c474942b0 100644 --- a/code/core/src/manager-api/lib/merge.ts +++ b/code/core/src/manager-api/lib/merge.ts @@ -1,8 +1,8 @@ -import mergeWith from 'lodash/mergeWith.js'; -import isEqual from 'lodash/isEqual.js'; - import { logger } from '@storybook/core/client-logger'; +import isEqual from 'lodash/isEqual.js'; +import mergeWith from 'lodash/mergeWith.js'; + export default (a: TObj, b: Partial) => mergeWith({}, a, b, (objValue: TObj, srcValue: Partial) => { if (Array.isArray(srcValue) && Array.isArray(objValue)) { diff --git a/code/core/src/manager-api/lib/request-response.ts b/code/core/src/manager-api/lib/request-response.ts index d76e1aca5659..da7413f55b1a 100644 --- a/code/core/src/manager-api/lib/request-response.ts +++ b/code/core/src/manager-api/lib/request-response.ts @@ -1,4 +1,5 @@ import type { Channel } from '@storybook/core/channels'; + import type { RequestData, ResponseData } from '@storybook/core/core-events'; export class RequestResponseError | void> extends Error { diff --git a/code/core/src/manager-api/lib/shortcut.ts b/code/core/src/manager-api/lib/shortcut.ts index 9ca5b2d7afe5..0db5c65f6596 100644 --- a/code/core/src/manager-api/lib/shortcut.ts +++ b/code/core/src/manager-api/lib/shortcut.ts @@ -1,4 +1,5 @@ import { global } from '@storybook/global'; + import type { API_KeyCollection } from '../modules/shortcuts'; const { navigator } = global; diff --git a/code/core/src/manager-api/lib/store-setup.ts b/code/core/src/manager-api/lib/store-setup.ts index 805b3237ab0e..291898bede0a 100644 --- a/code/core/src/manager-api/lib/store-setup.ts +++ b/code/core/src/manager-api/lib/store-setup.ts @@ -1,5 +1,4 @@ /* eslint-disable no-underscore-dangle */ - import { parse, stringify } from 'telejson'; // setting up the store, overriding set and get to use telejson diff --git a/code/core/src/manager-api/lib/stories.test.ts b/code/core/src/manager-api/lib/stories.test.ts index 5f005eef9e26..76aaadd7f99d 100644 --- a/code/core/src/manager-api/lib/stories.test.ts +++ b/code/core/src/manager-api/lib/stories.test.ts @@ -1,11 +1,13 @@ -import { describe, it, expect } from 'vitest'; -import type { StoryIndexV2, StoryIndexV3, API_PreparedStoryIndex } from '@storybook/core/types'; +import { describe, expect, it } from 'vitest'; + +import type { API_PreparedStoryIndex, StoryIndexV2, StoryIndexV3 } from '@storybook/core/types'; + +import { mockEntries } from '../tests/mockStoriesEntries'; import { transformStoryIndexV2toV3, transformStoryIndexV3toV4, transformStoryIndexV4toV5, } from './stories'; -import { mockEntries } from '../tests/mockStoriesEntries'; const baseV2: StoryIndexV2['stories'][0] = { id: '1', diff --git a/code/core/src/manager-api/lib/stories.ts b/code/core/src/manager-api/lib/stories.ts index 52366345ca08..139b6acaf851 100644 --- a/code/core/src/manager-api/lib/stories.ts +++ b/code/core/src/manager-api/lib/stories.ts @@ -1,29 +1,30 @@ -import memoize from 'memoizerific'; -import { dedent } from 'ts-dedent'; -import countBy from 'lodash/countBy.js'; -import mapValues from 'lodash/mapValues.js'; -import { sanitize } from '@storybook/csf'; import type { - StoryId, - Parameters, - DocsOptions, - API_Provider, - SetStoriesStoryData, - API_PreparedStoryIndex, - StoryIndexV3, - IndexEntry, - API_RootEntry, - API_GroupEntry, API_ComponentEntry, - API_IndexHash, API_DocsEntry, - API_StoryEntry, + API_GroupEntry, API_HashEntry, + API_IndexHash, + API_PreparedStoryIndex, + API_Provider, + API_RootEntry, + API_StoryEntry, + DocsOptions, + IndexEntry, + Parameters, SetStoriesPayload, + SetStoriesStoryData, + StoryId, StoryIndexV2, + StoryIndexV3, } from '@storybook/core/types'; +import { sanitize } from '@storybook/csf'; + +import countBy from 'lodash/countBy.js'; +import mapValues from 'lodash/mapValues.js'; +import memoize from 'memoizerific'; +import { dedent } from 'ts-dedent'; -import { type API, combineParameters, type State } from '../root'; +import { type API, type State, combineParameters } from '../root'; import merge from './merge'; const TITLE_PATH_SEPARATOR = /\s*\/\s*/; diff --git a/code/core/src/manager-api/lib/types.tsx b/code/core/src/manager-api/lib/types.tsx index 2b7a31e2498c..1579954f7e17 100644 --- a/code/core/src/manager-api/lib/types.tsx +++ b/code/core/src/manager-api/lib/types.tsx @@ -1,5 +1,5 @@ -import type { API_ProviderData } from '@storybook/core/types'; import type { RouterData } from '@storybook/core/router'; +import type { API_ProviderData } from '@storybook/core/types'; import type { API, State } from '../root'; import type Store from '../store'; diff --git a/code/core/src/manager-api/modules/addons.ts b/code/core/src/manager-api/modules/addons.ts index 2cefd4d9b39c..61e65084f955 100644 --- a/code/core/src/manager-api/modules/addons.ts +++ b/code/core/src/manager-api/modules/addons.ts @@ -1,11 +1,12 @@ import type { + API_StateMerger, Addon_BaseType, Addon_Collection, Addon_Types, Addon_TypesMapping, - API_StateMerger, } from '@storybook/core/types'; import { Addon_TypesEnum } from '@storybook/core/types'; + import type { ModuleFn } from '../lib/types'; import type { Options } from '../store'; diff --git a/code/core/src/manager-api/modules/channel.ts b/code/core/src/manager-api/modules/channel.ts index 8fdc688cf81b..6621aafa2ea4 100644 --- a/code/core/src/manager-api/modules/channel.ts +++ b/code/core/src/manager-api/modules/channel.ts @@ -1,8 +1,8 @@ import type { Listener } from '@storybook/core/channels'; - import type { API_Provider } from '@storybook/core/types'; -import type { API } from '../root'; + import type { ModuleFn } from '../lib/types'; +import type { API } from '../root'; export interface SubAPI { /** diff --git a/code/core/src/manager-api/modules/globals.ts b/code/core/src/manager-api/modules/globals.ts index cd990975ad10..0d3c790cf411 100644 --- a/code/core/src/manager-api/modules/globals.ts +++ b/code/core/src/manager-api/modules/globals.ts @@ -1,16 +1,17 @@ -import { SET_GLOBALS, UPDATE_GLOBALS, GLOBALS_UPDATED } from '@storybook/core/core-events'; -import { logger } from '@storybook/core/client-logger'; -import { dequal as deepEqual } from 'dequal'; import type { - SetGlobalsPayload, - Globals, GlobalTypes, + Globals, GlobalsUpdatedPayload, + SetGlobalsPayload, } from '@storybook/core/types'; -import type { ModuleFn } from '../lib/types'; +import { logger } from '@storybook/core/client-logger'; +import { GLOBALS_UPDATED, SET_GLOBALS, UPDATE_GLOBALS } from '@storybook/core/core-events'; + +import { dequal as deepEqual } from 'dequal'; import { getEventMetadata } from '../lib/events'; +import type { ModuleFn } from '../lib/types'; export interface SubState { globals?: Globals; diff --git a/code/core/src/manager-api/modules/layout.ts b/code/core/src/manager-api/modules/layout.ts index 89bd0ab19afd..de5ea65e1f56 100644 --- a/code/core/src/manager-api/modules/layout.ts +++ b/code/core/src/manager-api/modules/layout.ts @@ -1,14 +1,16 @@ -import { global } from '@storybook/global'; -import pick from 'lodash/pick.js'; -import { dequal as deepEqual } from 'dequal'; +import type { ThemeVars } from '@storybook/core/theming'; import { create } from '@storybook/core/theming/create'; +import type { API_Layout, API_PanelPositions, API_UI } from '@storybook/core/types'; +import { global } from '@storybook/global'; + import { SET_CONFIG } from '@storybook/core/core-events'; -import type { ThemeVars } from '@storybook/core/theming'; -import type { API_Layout, API_PanelPositions, API_UI } from '@storybook/core/types'; +import { dequal as deepEqual } from 'dequal'; +import pick from 'lodash/pick.js'; + import merge from '../lib/merge'; -import type { State } from '../root'; import type { ModuleFn } from '../lib/types'; +import type { State } from '../root'; const { document } = global; diff --git a/code/core/src/manager-api/modules/notifications.ts b/code/core/src/manager-api/modules/notifications.ts index dcabddd628ec..c234191d0148 100644 --- a/code/core/src/manager-api/modules/notifications.ts +++ b/code/core/src/manager-api/modules/notifications.ts @@ -1,5 +1,7 @@ import type { API_Notification } from '@storybook/core/types'; + import partition from 'lodash/partition.js'; + import type { ModuleFn } from '../lib/types'; export interface SubState { diff --git a/code/core/src/manager-api/modules/provider.ts b/code/core/src/manager-api/modules/provider.ts index 730195392fcf..0e22115369e1 100644 --- a/code/core/src/manager-api/modules/provider.ts +++ b/code/core/src/manager-api/modules/provider.ts @@ -1,4 +1,5 @@ import type { API_IframeRenderer } from '@storybook/core/types'; + import type { ModuleFn } from '../lib/types'; export interface SubAPI { diff --git a/code/core/src/manager-api/modules/refs.ts b/code/core/src/manager-api/modules/refs.ts index 50901f281901..29b03eadf11c 100644 --- a/code/core/src/manager-api/modules/refs.ts +++ b/code/core/src/manager-api/modules/refs.ts @@ -1,21 +1,21 @@ -import { global } from '@storybook/global'; -import { dedent } from 'ts-dedent'; import type { API_ComposedRef, API_ComposedRefUpdate, + API_IndexHash, API_Refs, API_SetRefData, - SetStoriesStoryData, - API_IndexHash, API_StoryMapper, + SetStoriesStoryData, StoryIndex, } from '@storybook/core/types'; +import { global } from '@storybook/global'; + +import { dedent } from 'ts-dedent'; import { transformSetStoriesStoryDataToPreparedStoryIndex, transformStoryIndexToStoriesHash, } from '../lib/stories'; - import type { ModuleFn } from '../lib/types'; const { location, fetch } = global; diff --git a/code/core/src/manager-api/modules/settings.ts b/code/core/src/manager-api/modules/settings.ts index 24bd16c327d8..59fdab207063 100644 --- a/code/core/src/manager-api/modules/settings.ts +++ b/code/core/src/manager-api/modules/settings.ts @@ -1,4 +1,5 @@ import type { API_Settings, StoryId } from '@storybook/core/types'; + import type { ModuleFn } from '../lib/types'; export interface SubAPI { diff --git a/code/core/src/manager-api/modules/shortcuts.ts b/code/core/src/manager-api/modules/shortcuts.ts index e65a7767faa9..58d2c2d642d6 100644 --- a/code/core/src/manager-api/modules/shortcuts.ts +++ b/code/core/src/manager-api/modules/shortcuts.ts @@ -1,5 +1,6 @@ /* eslint-disable @typescript-eslint/naming-convention */ import { global } from '@storybook/global'; + import { FORCE_REMOUNT, PREVIEW_KEYDOWN, @@ -7,10 +8,9 @@ import { STORIES_EXPAND_ALL, } from '@storybook/core/core-events'; -import type { ModuleFn } from '../lib/types'; - import type { KeyboardEventLike } from '../lib/shortcut'; -import { shortcutMatchesShortcut, eventToShortcut } from '../lib/shortcut'; +import { eventToShortcut, shortcutMatchesShortcut } from '../lib/shortcut'; +import type { ModuleFn } from '../lib/types'; import { focusableUIElements } from './layout'; const { navigator, document } = global; diff --git a/code/core/src/manager-api/modules/stories.ts b/code/core/src/manager-api/modules/stories.ts index 23edae60ad95..20bfdee92db0 100644 --- a/code/core/src/manager-api/modules/stories.ts +++ b/code/core/src/manager-api/modules/stories.ts @@ -1,61 +1,60 @@ -import { global } from '@storybook/global'; -import { toId, sanitize } from '@storybook/csf'; import type { - StoryKind, - ComponentTitle, - StoryName, - StoryId, - Args, API_ComposedRef, + API_DocsEntry, + API_FilterFunction, API_HashEntry, + API_IndexHash, API_LeafEntry, + API_LoadedRefData, API_PreparedStoryIndex, - SetStoriesPayload, + API_StatusState, + API_StatusUpdate, API_StoryEntry, + API_ViewMode, + Args, + ComponentTitle, + DocsPreparedPayload, + SetStoriesPayload, + StoryId, StoryIndex, - API_LoadedRefData, - API_IndexHash, + StoryKind, + StoryName, StoryPreparedPayload, - DocsPreparedPayload, - API_DocsEntry, - API_ViewMode, - API_StatusState, - API_StatusUpdate, - API_FilterFunction, } from '@storybook/core/types'; +import { sanitize, toId } from '@storybook/csf'; +import { global } from '@storybook/global'; + +import { logger } from '@storybook/core/client-logger'; import { + CONFIG_ERROR, + CURRENT_STORY_WAS_SET, + DOCS_PREPARED, PRELOAD_ENTRIES, - STORY_PREPARED, - UPDATE_STORY_ARGS, RESET_STORY_ARGS, - STORY_ARGS_UPDATED, - STORY_CHANGED, SELECT_STORY, - SET_STORIES, + SET_CONFIG, + SET_CURRENT_STORY, SET_INDEX, - STORY_SPECIFIED, + SET_STORIES, + STORY_ARGS_UPDATED, + STORY_CHANGED, STORY_INDEX_INVALIDATED, - CONFIG_ERROR, - CURRENT_STORY_WAS_SET, STORY_MISSING, - DOCS_PREPARED, - SET_CURRENT_STORY, - SET_CONFIG, + STORY_PREPARED, + STORY_SPECIFIED, + UPDATE_STORY_ARGS, } from '@storybook/core/core-events'; -import { logger } from '@storybook/core/client-logger'; import { getEventMetadata } from '../lib/events'; - import { + addPreparedStories, denormalizeStoryParameters, - transformStoryIndexToStoriesHash, getComponentLookupList, getStoriesLookupList, - addPreparedStories, + transformStoryIndexToStoriesHash, } from '../lib/stories'; - -import type { ComposedRef } from '../root'; import type { ModuleFn } from '../lib/types'; +import type { ComposedRef } from '../root'; const { fetch } = global; const STORY_INDEX_PATH = './index.json'; diff --git a/code/core/src/manager-api/modules/url.ts b/code/core/src/manager-api/modules/url.ts index d69e194a6947..c5a23e57a4fc 100644 --- a/code/core/src/manager-api/modules/url.ts +++ b/code/core/src/manager-api/modules/url.ts @@ -1,16 +1,18 @@ +import type { NavigateOptions } from '@storybook/core/router'; +import { buildArgsParam, queryFromLocation } from '@storybook/core/router'; +import type { API_Layout, API_UI, Args } from '@storybook/core/types'; +import { global } from '@storybook/global'; + import { + GLOBALS_UPDATED, NAVIGATE_URL, - STORY_ARGS_UPDATED, SET_CURRENT_STORY, - GLOBALS_UPDATED, + STORY_ARGS_UPDATED, UPDATE_QUERY_PARAMS, } from '@storybook/core/core-events'; -import type { NavigateOptions } from '@storybook/core/router'; -import { queryFromLocation, buildArgsParam } from '@storybook/core/router'; + import { dequal as deepEqual } from 'dequal'; -import { global } from '@storybook/global'; -import type { API_Layout, API_UI, Args } from '@storybook/core/types'; import type { ModuleArgs, ModuleFn } from '../lib/types'; import { defaultLayoutState } from './layout'; diff --git a/code/core/src/manager-api/modules/versions.ts b/code/core/src/manager-api/modules/versions.ts index 16015cde837d..734ba0442838 100644 --- a/code/core/src/manager-api/modules/versions.ts +++ b/code/core/src/manager-api/modules/versions.ts @@ -1,11 +1,11 @@ +import type { API_UnknownEntries, API_Version, API_Versions } from '@storybook/core/types'; import { global } from '@storybook/global'; -import semver from 'semver'; -import memoize from 'memoizerific'; -import type { API_UnknownEntries, API_Version, API_Versions } from '@storybook/core/types'; -import { version as currentVersion } from '../version'; +import memoize from 'memoizerific'; +import semver from 'semver'; import type { ModuleFn } from '../lib/types'; +import { version as currentVersion } from '../version'; const { VERSIONCHECK } = global; diff --git a/code/core/src/manager-api/modules/whatsnew.tsx b/code/core/src/manager-api/modules/whatsnew.tsx index 71e6b9e03d85..7878f5920066 100644 --- a/code/core/src/manager-api/modules/whatsnew.tsx +++ b/code/core/src/manager-api/modules/whatsnew.tsx @@ -1,5 +1,8 @@ import React from 'react'; + import { global } from '@storybook/global'; +import { StorybookIcon } from '@storybook/icons'; + import type { WhatsNewCache, WhatsNewData } from '@storybook/core/core-events'; import { REQUEST_WHATS_NEW_DATA, @@ -7,8 +10,8 @@ import { SET_WHATS_NEW_CACHE, TOGGLE_WHATS_NEW_NOTIFICATIONS, } from '@storybook/core/core-events'; + import type { ModuleFn } from '../lib/types'; -import { StorybookIcon } from '@storybook/icons'; export type SubState = { whatsNewData?: WhatsNewData; diff --git a/code/core/src/manager-api/root.tsx b/code/core/src/manager-api/root.tsx index 8d23d1d8fcd2..0a1fad42c3e1 100644 --- a/code/core/src/manager-api/root.tsx +++ b/code/core/src/manager-api/root.tsx @@ -9,10 +9,10 @@ import React, { useMemo, useRef, } from 'react'; -import mergeWith from 'lodash/mergeWith.js'; + +import type { Listener } from '@storybook/core/channels'; +import type { RouterData } from '@storybook/core/router'; import type { - Args, - ArgTypes, API_ComponentEntry, API_ComposedRef, API_DocsEntry, @@ -26,49 +26,42 @@ import type { API_RootEntry, API_StateMerger, API_StoryEntry, + ArgTypes, + Args, + Globals, Parameters, StoryId, - Globals, } from '@storybook/core/types'; +import { deprecate } from '@storybook/core/client-logger'; import { - STORY_CHANGED, + SET_STORIES, SHARED_STATE_CHANGED, SHARED_STATE_SET, - SET_STORIES, + STORY_CHANGED, } from '@storybook/core/core-events'; -import type { RouterData } from '@storybook/core/router'; -import type { Listener } from '@storybook/core/channels'; -import { deprecate } from '@storybook/core/client-logger'; + +import mergeWith from 'lodash/mergeWith.js'; import { createContext } from './context'; -import type { Options } from './store'; -import Store from './store'; import getInitialState from './initial-state'; - -import * as provider from './modules/provider'; - +import { types } from './lib/addons'; +import type { ModuleFn } from './lib/types'; import * as addons from './modules/addons'; - import * as channel from './modules/channel'; - +import * as globals from './modules/globals'; +import * as layout from './modules/layout'; import * as notifications from './modules/notifications'; -import * as settings from './modules/settings'; - -import * as stories from './modules/stories'; - +import * as provider from './modules/provider'; import * as refs from './modules/refs'; -import * as layout from './modules/layout'; +import * as settings from './modules/settings'; import * as shortcuts from './modules/shortcuts'; - +import * as stories from './modules/stories'; import * as url from './modules/url'; import * as version from './modules/versions'; import * as whatsnew from './modules/whatsnew'; - -import * as globals from './modules/globals'; -import type { ModuleFn } from './lib/types'; - -import { types } from './lib/addons'; +import type { Options } from './store'; +import Store from './store'; export * from './lib/request-response'; export * from './lib/shortcut'; diff --git a/code/core/src/manager-api/store.ts b/code/core/src/manager-api/store.ts index ffb3b43dbc83..ca19eb4f4293 100644 --- a/code/core/src/manager-api/store.ts +++ b/code/core/src/manager-api/store.ts @@ -1,7 +1,7 @@ import type { StoreAPI } from 'store2'; import store from 'store2'; -import storeSetup from './lib/store-setup'; +import storeSetup from './lib/store-setup'; import type { State } from './root'; // setting up the store, overriding set and get to use telejson diff --git a/code/core/src/manager-api/tests/addons.test.js b/code/core/src/manager-api/tests/addons.test.js index 8d0928d9f82d..4d64ecc95224 100644 --- a/code/core/src/manager-api/tests/addons.test.js +++ b/code/core/src/manager-api/tests/addons.test.js @@ -1,5 +1,7 @@ -import { describe, it, expect, vi } from 'vitest'; +import { describe, expect, it, vi } from 'vitest'; + import { Addon_TypesEnum as types } from '@storybook/core/types'; + import { init as initAddons } from '../modules/addons'; const PANELS = { diff --git a/code/core/src/manager-api/tests/events.test.ts b/code/core/src/manager-api/tests/events.test.ts index ac0c4ed7887f..9adc7a06eb1a 100644 --- a/code/core/src/manager-api/tests/events.test.ts +++ b/code/core/src/manager-api/tests/events.test.ts @@ -1,4 +1,5 @@ -import { describe, it, expect, vi } from 'vitest'; +import { describe, expect, it, vi } from 'vitest'; + import { getEventMetadata } from '../lib/events'; import type { API } from '../root'; diff --git a/code/core/src/manager-api/tests/globals.test.ts b/code/core/src/manager-api/tests/globals.test.ts index 52f3fa379472..96da32051f2b 100644 --- a/code/core/src/manager-api/tests/globals.test.ts +++ b/code/core/src/manager-api/tests/globals.test.ts @@ -1,20 +1,22 @@ -import { describe, beforeEach, it, expect, vi } from 'vitest'; -import { EventEmitter } from 'events'; +import { beforeEach, describe, expect, it, vi } from 'vitest'; + +import type { GlobalsUpdatedPayload, SetGlobalsPayload } from '@storybook/core/types'; + +import { logger as _logger } from '@storybook/core/client-logger'; import { - SET_STORIES, + GLOBALS_UPDATED, SET_GLOBALS, + SET_STORIES, UPDATE_GLOBALS, - GLOBALS_UPDATED, } from '@storybook/core/core-events'; -import { logger as _logger } from '@storybook/core/client-logger'; -import type { API } from '../root'; -import type { SubAPI } from '../modules/globals'; -import { init as initModule } from '../modules/globals'; -import type { ModuleArgs } from '../lib/types'; +import { EventEmitter } from 'events'; import { getEventMetadata as _getEventData } from '../lib/events'; -import type { GlobalsUpdatedPayload, SetGlobalsPayload } from '@storybook/core/types'; +import type { ModuleArgs } from '../lib/types'; +import type { SubAPI } from '../modules/globals'; +import { init as initModule } from '../modules/globals'; +import type { API } from '../root'; const getEventMetadata = vi.mocked(_getEventData, true); const logger = vi.mocked(_logger, true); diff --git a/code/core/src/manager-api/tests/layout.test.ts b/code/core/src/manager-api/tests/layout.test.ts index a9ced49e1ac3..7b1c7361f254 100644 --- a/code/core/src/manager-api/tests/layout.test.ts +++ b/code/core/src/manager-api/tests/layout.test.ts @@ -1,15 +1,17 @@ import type { Mock } from 'vitest'; -import { expect, describe, beforeEach, it, vi } from 'vitest'; +import { beforeEach, describe, expect, it, vi } from 'vitest'; import { themes } from '@storybook/core/theming'; import type { API_Provider } from '@storybook/core/types'; + import EventEmitter from 'events'; -import type { SubAPI, SubState } from '../modules/layout'; + +import type { ModuleArgs } from '../lib/types'; import type { SubState as AddonsSubState } from '../modules/addons'; +import type { SubAPI, SubState } from '../modules/layout'; import { defaultLayoutState, init as initLayout } from '../modules/layout'; -import type Store from '../store'; import type { API, State } from '../root'; -import type { ModuleArgs } from '../lib/types'; +import type Store from '../store'; describe('layout API', () => { let layoutApi: SubAPI; diff --git a/code/core/src/manager-api/tests/mockStoriesEntries.ts b/code/core/src/manager-api/tests/mockStoriesEntries.ts index 0bb2df381aa6..2bccab057186 100644 --- a/code/core/src/manager-api/tests/mockStoriesEntries.ts +++ b/code/core/src/manager-api/tests/mockStoriesEntries.ts @@ -1,4 +1,4 @@ -import type { StoryIndex, API_PreparedStoryIndex } from '@storybook/core/types'; +import type { API_PreparedStoryIndex, StoryIndex } from '@storybook/core/types'; export const mockEntries: StoryIndex['entries'] = { 'component-a--docs': { diff --git a/code/core/src/manager-api/tests/notifications.test.js b/code/core/src/manager-api/tests/notifications.test.js index 8d2005db6837..95ccbe1f1187 100644 --- a/code/core/src/manager-api/tests/notifications.test.js +++ b/code/core/src/manager-api/tests/notifications.test.js @@ -1,4 +1,5 @@ -import { describe, it, expect, vi } from 'vitest'; +import { describe, expect, it, vi } from 'vitest'; + import { init as initNotifications } from '../modules/notifications'; describe('notifications API', () => { diff --git a/code/core/src/manager-api/tests/refs.test.ts b/code/core/src/manager-api/tests/refs.test.ts index 96d2b3b8d84f..c8d65baafc57 100644 --- a/code/core/src/manager-api/tests/refs.test.ts +++ b/code/core/src/manager-api/tests/refs.test.ts @@ -1,9 +1,11 @@ -import { describe, it, expect, vi } from 'vitest'; -import { global } from '@storybook/global'; +import { describe, expect, it, vi } from 'vitest'; + import type { StoryIndex } from '@storybook/core/types'; -import type { State } from '../root'; +import { global } from '@storybook/global'; + import { transformStoryIndexToStoriesHash } from '../lib/stories'; import { getSourceType, init as initRefs } from '../modules/refs'; +import type { State } from '../root'; import type Store from '../store'; const { fetch } = global; diff --git a/code/core/src/manager-api/tests/shortcut.test.js b/code/core/src/manager-api/tests/shortcut.test.js index 5b0db8e39672..d45d50afb182 100644 --- a/code/core/src/manager-api/tests/shortcut.test.js +++ b/code/core/src/manager-api/tests/shortcut.test.js @@ -2,6 +2,7 @@ import { describe, expect, it } from 'vitest'; import { global } from '@storybook/global'; + import { eventToShortcut, keyToSymbol } from '../lib/shortcut'; const { KeyboardEvent } = global; diff --git a/code/core/src/manager-api/tests/shortcuts.test.js b/code/core/src/manager-api/tests/shortcuts.test.js index 9aba57c756f7..be1efd4063d9 100644 --- a/code/core/src/manager-api/tests/shortcuts.test.js +++ b/code/core/src/manager-api/tests/shortcuts.test.js @@ -1,4 +1,5 @@ -import { describe, it, expect, vi } from 'vitest'; +import { describe, expect, it, vi } from 'vitest'; + import { init as initShortcuts } from '../modules/shortcuts'; function createMockStore() { diff --git a/code/core/src/manager-api/tests/store.test.js b/code/core/src/manager-api/tests/store.test.js index c0f88f586409..e77bc1cd289e 100644 --- a/code/core/src/manager-api/tests/store.test.js +++ b/code/core/src/manager-api/tests/store.test.js @@ -1,6 +1,8 @@ -import { describe, it, expect, vi } from 'vitest'; -import store2 from 'store2'; +import { describe, expect, it, vi } from 'vitest'; + import flushPromises from 'flush-promises'; +import store2 from 'store2'; + import Store, { STORAGE_KEY } from '../store'; vi.mock('store2', () => ({ diff --git a/code/core/src/manager-api/tests/stories.test.ts b/code/core/src/manager-api/tests/stories.test.ts index ea02cdfd464b..16b5c926c9c2 100644 --- a/code/core/src/manager-api/tests/stories.test.ts +++ b/code/core/src/manager-api/tests/stories.test.ts @@ -1,30 +1,32 @@ import type { Mocked } from 'vitest'; -import { describe, it, expect, vi } from 'vitest'; +import { describe, expect, it, vi } from 'vitest'; + +import type { API_StoryEntry } from '@storybook/core/types'; +import { global } from '@storybook/global'; + import { - STORY_ARGS_UPDATED, - UPDATE_STORY_ARGS, + CONFIG_ERROR, + CURRENT_STORY_WAS_SET, + DOCS_PREPARED, RESET_STORY_ARGS, + SET_INDEX, SET_STORIES, - STORY_SPECIFIED, - STORY_PREPARED, + STORY_ARGS_UPDATED, STORY_INDEX_INVALIDATED, - CONFIG_ERROR, - SET_INDEX, - CURRENT_STORY_WAS_SET, STORY_MISSING, - DOCS_PREPARED, + STORY_PREPARED, + STORY_SPECIFIED, + UPDATE_STORY_ARGS, } from '@storybook/core/core-events'; + import { EventEmitter } from 'events'; -import { global } from '@storybook/global'; -import type { API_StoryEntry } from '@storybook/core/types'; import { getEventMetadata as getEventMetadataOriginal } from '../lib/events'; - +import type { ModuleArgs } from '../lib/types'; import { init as initStories } from '../modules/stories'; -import type Store from '../store'; import type { API, State } from '../root'; -import { mockEntries, docsEntries, preparedEntries, navigationEntries } from './mockStoriesEntries'; -import type { ModuleArgs } from '../lib/types'; +import type Store from '../store'; +import { docsEntries, mockEntries, navigationEntries, preparedEntries } from './mockStoriesEntries'; const mockGetEntries = vi.fn(); const fetch = vi.mocked(global.fetch); diff --git a/code/core/src/manager-api/tests/url.test.js b/code/core/src/manager-api/tests/url.test.js index a4a9de83ba75..a3612650530c 100644 --- a/code/core/src/manager-api/tests/url.test.js +++ b/code/core/src/manager-api/tests/url.test.js @@ -1,12 +1,13 @@ -import { describe, beforeEach, it, expect, vi } from 'vitest'; +import { beforeEach, describe, expect, it, vi } from 'vitest'; import { - SET_CURRENT_STORY, GLOBALS_UPDATED, + SET_CURRENT_STORY, UPDATE_QUERY_PARAMS, } from '@storybook/core/core-events'; import EventEmitter from 'events'; + import { init as initURL } from '../modules/url'; vi.mock('@storybook/core/client-logger'); diff --git a/code/core/src/manager-api/tests/versions.test.js b/code/core/src/manager-api/tests/versions.test.js index 4ed44dc50595..280deaeed2ae 100644 --- a/code/core/src/manager-api/tests/versions.test.js +++ b/code/core/src/manager-api/tests/versions.test.js @@ -1,4 +1,5 @@ -import { describe, it, expect, vi, beforeEach } from 'vitest'; +import { beforeEach, describe, expect, it, vi } from 'vitest'; + import { global } from '@storybook/global'; import { init as initVersions } from '../modules/versions'; diff --git a/code/core/src/manager/App.tsx b/code/core/src/manager/App.tsx index c4679ffe43ca..287f9736cc71 100644 --- a/code/core/src/manager/App.tsx +++ b/code/core/src/manager/App.tsx @@ -1,13 +1,14 @@ import type { ComponentProps } from 'react'; import React from 'react'; + import { Global, createGlobal } from '@storybook/core/theming'; import type { Addon_PageType } from '@storybook/core/types'; -import Sidebar from './container/Sidebar'; -import Preview from './container/Preview'; -import Panel from './container/Panel'; import { Layout } from './components/layout/Layout'; import { useLayout } from './components/layout/LayoutProvider'; +import Panel from './container/Panel'; +import Preview from './container/Preview'; +import Sidebar from './container/Sidebar'; type Props = { managerLayoutState: ComponentProps['managerLayoutState']; diff --git a/code/core/src/manager/FakeProvider.tsx b/code/core/src/manager/FakeProvider.tsx index 397a91b86a62..dc66dedf0f6f 100644 --- a/code/core/src/manager/FakeProvider.tsx +++ b/code/core/src/manager/FakeProvider.tsx @@ -1,6 +1,9 @@ import React from 'react'; + import { styled } from '@storybook/core/theming'; + import { addons } from '@storybook/core/manager-api'; + import Provider from './provider'; export class FakeProvider extends Provider { diff --git a/code/core/src/manager/README.md b/code/core/src/manager/README.md index c91e4b2cb06a..ff55e2830fdf 100644 --- a/code/core/src/manager/README.md +++ b/code/core/src/manager/README.md @@ -55,8 +55,8 @@ export default class MyProvider extends Provider { Then you need to initialize the UI like this: ```js -import global from 'global'; import { renderStorybookUI } from '@storybook/manager'; +import global from 'global'; import Provider from './provider'; const { document } = global; diff --git a/code/core/src/manager/__tests__/index.test.ts b/code/core/src/manager/__tests__/index.test.ts index ce85a45e293b..792484347ad1 100644 --- a/code/core/src/manager/__tests__/index.test.ts +++ b/code/core/src/manager/__tests__/index.test.ts @@ -1,6 +1,6 @@ // @vitest-environment happy-dom +import { describe, expect, it } from 'vitest'; -import { describe, it, expect } from 'vitest'; import { renderStorybookUI } from '..'; describe('Main API', () => { diff --git a/code/core/src/manager/components/layout/Layout.stories.tsx b/code/core/src/manager/components/layout/Layout.stories.tsx index 8282d8434587..6a133d6c492f 100644 --- a/code/core/src/manager/components/layout/Layout.stories.tsx +++ b/code/core/src/manager/components/layout/Layout.stories.tsx @@ -1,14 +1,16 @@ -import { action } from '@storybook/addon-actions'; import type { FC, PropsWithChildren } from 'react'; import React, { useState } from 'react'; +import { LocationProvider } from '@storybook/core/router'; import { styled } from '@storybook/core/theming'; import type { Meta, StoryObj } from '@storybook/react'; import { fn } from '@storybook/test'; + +import { action } from '@storybook/addon-actions'; + +import MobileNavigationStoriesMeta from '../mobile/navigation/MobileNavigation.stories'; import { Layout } from './Layout'; import { LayoutProvider } from './LayoutProvider'; -import { LocationProvider } from '@storybook/core/router'; -import MobileNavigationStoriesMeta from '../mobile/navigation/MobileNavigation.stories'; const PlaceholderBlock = styled.div({ width: '100%', diff --git a/code/core/src/manager/components/layout/Layout.tsx b/code/core/src/manager/components/layout/Layout.tsx index 82e6b532c9ae..a984a5a266d5 100644 --- a/code/core/src/manager/components/layout/Layout.tsx +++ b/code/core/src/manager/components/layout/Layout.tsx @@ -1,12 +1,14 @@ import React, { useEffect, useLayoutEffect, useState } from 'react'; + +import { Match } from '@storybook/core/router'; import { styled } from '@storybook/core/theming'; import type { API_Layout, API_ViewMode } from '@storybook/core/types'; -import { useDragging } from './useDragging'; -import { MobileNavigation } from '../mobile/navigation/MobileNavigation'; + import { MEDIA_DESKTOP_BREAKPOINT } from '../../constants'; -import { useLayout } from './LayoutProvider'; import { Notifications } from '../../container/Notifications'; -import { Match } from '@storybook/core/router'; +import { MobileNavigation } from '../mobile/navigation/MobileNavigation'; +import { useLayout } from './LayoutProvider'; +import { useDragging } from './useDragging'; interface InternalLayoutState { isDragging: boolean; diff --git a/code/core/src/manager/components/layout/LayoutProvider.tsx b/code/core/src/manager/components/layout/LayoutProvider.tsx index 81c342e0546c..88f3b7a781f6 100644 --- a/code/core/src/manager/components/layout/LayoutProvider.tsx +++ b/code/core/src/manager/components/layout/LayoutProvider.tsx @@ -1,7 +1,8 @@ import type { FC, PropsWithChildren } from 'react'; import React, { createContext, useContext, useMemo, useState } from 'react'; -import { useMediaQuery } from '../hooks/useMedia'; + import { BREAKPOINT } from '../../constants'; +import { useMediaQuery } from '../hooks/useMedia'; type LayoutContextType = { isMobileMenuOpen: boolean; diff --git a/code/core/src/manager/components/layout/useDragging.ts b/code/core/src/manager/components/layout/useDragging.ts index 1c00f516c234..a62f6c29e4ac 100644 --- a/code/core/src/manager/components/layout/useDragging.ts +++ b/code/core/src/manager/components/layout/useDragging.ts @@ -1,5 +1,6 @@ import type { Dispatch, SetStateAction } from 'react'; import { useEffect, useRef } from 'react'; + import type { LayoutState } from './Layout'; // the distance from the edge of the screen at which the panel/sidebar will snap to the edge diff --git a/code/core/src/manager/components/mobile/about/MobileAbout.stories.tsx b/code/core/src/manager/components/mobile/about/MobileAbout.stories.tsx index e552171cca4b..ee13d985f3cc 100644 --- a/code/core/src/manager/components/mobile/about/MobileAbout.stories.tsx +++ b/code/core/src/manager/components/mobile/about/MobileAbout.stories.tsx @@ -1,9 +1,12 @@ -import type { Meta, StoryObj } from '@storybook/react'; -import { ManagerContext } from '@storybook/core/manager-api'; import React, { useEffect } from 'react'; + +import type { Meta, StoryObj } from '@storybook/react'; import { within } from '@storybook/test'; -import { MobileAbout } from './MobileAbout'; + +import { ManagerContext } from '@storybook/core/manager-api'; + import { LayoutProvider, useLayout } from '../../layout/LayoutProvider'; +import { MobileAbout } from './MobileAbout'; /** * A helper component to open the about page via the MobileLayoutContext diff --git a/code/core/src/manager/components/mobile/about/MobileAbout.tsx b/code/core/src/manager/components/mobile/about/MobileAbout.tsx index 2b65bf59c5a0..a794ba00ea9f 100644 --- a/code/core/src/manager/components/mobile/about/MobileAbout.tsx +++ b/code/core/src/manager/components/mobile/about/MobileAbout.tsx @@ -1,12 +1,15 @@ import type { FC } from 'react'; import React, { useRef } from 'react'; -import { Transition, type TransitionStatus } from 'react-transition-group'; -import { styled } from '@storybook/core/theming'; + import { Link } from '@storybook/core/components'; +import { styled } from '@storybook/core/theming'; import { ArrowLeftIcon, GithubIcon, ShareAltIcon, StorybookIcon } from '@storybook/icons'; -import { UpgradeBlock } from '../../upgrade/UpgradeBlock'; + +import { Transition, type TransitionStatus } from 'react-transition-group'; + import { MOBILE_TRANSITION_DURATION } from '../../../constants'; import { useLayout } from '../../layout/LayoutProvider'; +import { UpgradeBlock } from '../../upgrade/UpgradeBlock'; export const MobileAbout: FC = () => { const { isMobileAboutOpen, setMobileAboutOpen } = useLayout(); diff --git a/code/core/src/manager/components/mobile/navigation/MobileAddonsDrawer.tsx b/code/core/src/manager/components/mobile/navigation/MobileAddonsDrawer.tsx index b17ec5e55c5e..def0c9e2bdf8 100644 --- a/code/core/src/manager/components/mobile/navigation/MobileAddonsDrawer.tsx +++ b/code/core/src/manager/components/mobile/navigation/MobileAddonsDrawer.tsx @@ -1,5 +1,6 @@ import type { FC, ReactNode } from 'react'; import React from 'react'; + import { styled } from '@storybook/core/theming'; interface MobileAddonsDrawerProps { diff --git a/code/core/src/manager/components/mobile/navigation/MobileMenuDrawer.tsx b/code/core/src/manager/components/mobile/navigation/MobileMenuDrawer.tsx index 8c3ac21152b6..8e3de4b51581 100644 --- a/code/core/src/manager/components/mobile/navigation/MobileMenuDrawer.tsx +++ b/code/core/src/manager/components/mobile/navigation/MobileMenuDrawer.tsx @@ -1,11 +1,14 @@ import type { FC } from 'react'; import React, { useRef } from 'react'; + import { styled } from '@storybook/core/theming'; + import { Transition } from 'react-transition-group'; import type { TransitionStatus } from 'react-transition-group/Transition'; -import { MobileAbout } from '../about/MobileAbout'; + import { MOBILE_TRANSITION_DURATION } from '../../../constants'; import { useLayout } from '../../layout/LayoutProvider'; +import { MobileAbout } from '../about/MobileAbout'; interface MobileMenuDrawerProps { children?: React.ReactNode; diff --git a/code/core/src/manager/components/mobile/navigation/MobileNavigation.stories.tsx b/code/core/src/manager/components/mobile/navigation/MobileNavigation.stories.tsx index 552556add58c..e445d73dea23 100644 --- a/code/core/src/manager/components/mobile/navigation/MobileNavigation.stories.tsx +++ b/code/core/src/manager/components/mobile/navigation/MobileNavigation.stories.tsx @@ -1,10 +1,14 @@ -import type { Meta, StoryObj } from '@storybook/react'; import React from 'react'; -import { ManagerContext } from '@storybook/core/manager-api'; + +import type { Meta, StoryObj } from '@storybook/react'; import { within } from '@storybook/test'; + +import { ManagerContext } from '@storybook/core/manager-api'; + import { startCase } from 'lodash'; -import { MobileNavigation } from './MobileNavigation'; + import { LayoutProvider, useLayout } from '../../layout/LayoutProvider'; +import { MobileNavigation } from './MobileNavigation'; const MockPanel = () => { const { setMobilePanelOpen } = useLayout(); diff --git a/code/core/src/manager/components/mobile/navigation/MobileNavigation.tsx b/code/core/src/manager/components/mobile/navigation/MobileNavigation.tsx index 963c56360f19..cef5b139b625 100644 --- a/code/core/src/manager/components/mobile/navigation/MobileNavigation.tsx +++ b/code/core/src/manager/components/mobile/navigation/MobileNavigation.tsx @@ -1,12 +1,15 @@ import type { FC } from 'react'; import React from 'react'; -import { styled } from '@storybook/core/theming'; + import { IconButton } from '@storybook/core/components'; -import { useStorybookApi, useStorybookState } from '@storybook/core/manager-api'; +import { styled } from '@storybook/core/theming'; import { BottomBarToggleIcon, MenuIcon } from '@storybook/icons'; -import { MobileMenuDrawer } from './MobileMenuDrawer'; -import { MobileAddonsDrawer } from './MobileAddonsDrawer'; + +import { useStorybookApi, useStorybookState } from '@storybook/core/manager-api'; + import { useLayout } from '../../layout/LayoutProvider'; +import { MobileAddonsDrawer } from './MobileAddonsDrawer'; +import { MobileMenuDrawer } from './MobileMenuDrawer'; interface MobileNavigationProps { menu?: React.ReactNode; diff --git a/code/core/src/manager/components/notifications/NotificationItem.stories.tsx b/code/core/src/manager/components/notifications/NotificationItem.stories.tsx index 93588e4a5353..1914a0fe7987 100644 --- a/code/core/src/manager/components/notifications/NotificationItem.stories.tsx +++ b/code/core/src/manager/components/notifications/NotificationItem.stories.tsx @@ -1,15 +1,18 @@ import React from 'react'; -import { action } from '@storybook/addon-actions'; + import { LocationProvider } from '@storybook/core/router'; -import type { Meta, StoryObj } from '@storybook/react'; -import NotificationItem from './NotificationItem'; import { AccessibilityIcon as AccessibilityIconIcon, BookIcon as BookIconIcon, FaceHappyIcon, } from '@storybook/icons'; +import type { Meta, StoryObj } from '@storybook/react'; import { expect, fn, userEvent, waitFor, within } from '@storybook/test'; +import { action } from '@storybook/addon-actions'; + +import NotificationItem from './NotificationItem'; + const meta = { component: NotificationItem, title: 'Notifications/NotificationItem', diff --git a/code/core/src/manager/components/notifications/NotificationItem.tsx b/code/core/src/manager/components/notifications/NotificationItem.tsx index f912828783a2..66a8cef66bf3 100644 --- a/code/core/src/manager/components/notifications/NotificationItem.tsx +++ b/code/core/src/manager/components/notifications/NotificationItem.tsx @@ -1,13 +1,16 @@ import type { FC, SyntheticEvent } from 'react'; import React, { useCallback, useEffect, useRef } from 'react'; -import { type State } from '@storybook/core/manager-api'; -import { Link } from '@storybook/core/router'; -import { keyframes, styled, useTheme } from '@storybook/core/theming'; + import type { IconsProps } from '@storybook/core/components'; import { IconButton, Icons } from '@storybook/core/components'; -import { transparentize } from 'polished'; +import { Link } from '@storybook/core/router'; +import { keyframes, styled, useTheme } from '@storybook/core/theming'; import { CloseAltIcon } from '@storybook/icons'; +import { type State } from '@storybook/core/manager-api'; + +import { transparentize } from 'polished'; + const slideIn = keyframes({ '0%': { opacity: 0, diff --git a/code/core/src/manager/components/notifications/NotificationList.stories.tsx b/code/core/src/manager/components/notifications/NotificationList.stories.tsx index d2842e5eb872..60554232747c 100644 --- a/code/core/src/manager/components/notifications/NotificationList.stories.tsx +++ b/code/core/src/manager/components/notifications/NotificationList.stories.tsx @@ -1,9 +1,10 @@ import React from 'react'; + import { LocationProvider } from '@storybook/core/router'; import type { Meta, StoryObj } from '@storybook/react'; -import { NotificationList } from './NotificationList'; import * as itemStories from './NotificationItem.stories'; +import { NotificationList } from './NotificationList'; const meta = { component: NotificationList, diff --git a/code/core/src/manager/components/notifications/NotificationList.tsx b/code/core/src/manager/components/notifications/NotificationList.tsx index 604ed50c5101..a0c8fabd13c6 100644 --- a/code/core/src/manager/components/notifications/NotificationList.tsx +++ b/code/core/src/manager/components/notifications/NotificationList.tsx @@ -1,10 +1,13 @@ import type { FC } from 'react'; import React from 'react'; -import type { State } from '@storybook/core/manager-api'; + import { styled } from '@storybook/core/theming'; import type { CSSObject } from '@storybook/core/theming'; -import NotificationItem from './NotificationItem'; + +import type { State } from '@storybook/core/manager-api'; + import { MEDIA_DESKTOP_BREAKPOINT } from '../../constants'; +import NotificationItem from './NotificationItem'; interface NotificationListProps { notifications: State['notifications']; diff --git a/code/core/src/manager/components/panel/Panel.stories.tsx b/code/core/src/manager/components/panel/Panel.stories.tsx index 7b6691c314cd..3caa6a3c0fb1 100644 --- a/code/core/src/manager/components/panel/Panel.stories.tsx +++ b/code/core/src/manager/components/panel/Panel.stories.tsx @@ -1,12 +1,15 @@ import type { EventHandler, FocusEvent, MouseEvent } from 'react'; import React, { useCallback, useRef, useState } from 'react'; -import { action } from '@storybook/addon-actions'; + import { Badge, Spaced } from '@storybook/core/components'; import type { Addon_BaseType, Addon_Collection } from '@storybook/core/types'; import { Addon_TypesEnum } from '@storybook/core/types'; import { BellIcon } from '@storybook/icons'; -import { AddonPanel } from './Panel'; + +import { action } from '@storybook/addon-actions'; + import { defaultShortcuts } from '../../settings/defaultShortcuts'; +import { AddonPanel } from './Panel'; const onSelect = action('onSelect'); const toggleVisibility = action('toggleVisibility'); diff --git a/code/core/src/manager/components/panel/Panel.tsx b/code/core/src/manager/components/panel/Panel.tsx index dad5d7f9b85d..701cd94925e3 100644 --- a/code/core/src/manager/components/panel/Panel.tsx +++ b/code/core/src/manager/components/panel/Panel.tsx @@ -1,10 +1,13 @@ import React, { Component } from 'react'; -import { Tabs, IconButton, Link, EmptyTabContent } from '@storybook/core/components'; -import type { State } from '@storybook/core/manager-api'; -import { shortcutToHumanString } from '@storybook/core/manager-api'; -import type { Addon_BaseType } from '@storybook/core/types'; + +import { EmptyTabContent, IconButton, Link, Tabs } from '@storybook/core/components'; import { styled } from '@storybook/core/theming'; +import type { Addon_BaseType } from '@storybook/core/types'; import { BottomBarIcon, CloseIcon, DocumentIcon, SidebarAltIcon } from '@storybook/icons'; + +import type { State } from '@storybook/core/manager-api'; +import { shortcutToHumanString } from '@storybook/core/manager-api'; + import { useLayout } from '../layout/LayoutProvider'; export interface SafeTabProps { diff --git a/code/core/src/manager/components/preview/FramesRenderer.tsx b/code/core/src/manager/components/preview/FramesRenderer.tsx index ecf627be9df9..40a42c3fbe98 100644 --- a/code/core/src/manager/components/preview/FramesRenderer.tsx +++ b/code/core/src/manager/components/preview/FramesRenderer.tsx @@ -1,13 +1,16 @@ import type { FC } from 'react'; -import React, { useRef, Fragment } from 'react'; -import type { Combo } from '@storybook/core/manager-api'; -import { Consumer } from '@storybook/core/manager-api'; +import React, { Fragment, useRef } from 'react'; + import { Button, getStoryHref } from '@storybook/core/components'; import { Global, styled } from '@storybook/core/theming'; import type { CSSObject } from '@storybook/core/theming'; + +import type { Combo } from '@storybook/core/manager-api'; +import { Consumer } from '@storybook/core/manager-api'; + import { IFrame } from './Iframe'; -import type { FramesRendererProps } from './utils/types'; import { stringifyQueryParams } from './utils/stringifyQueryParams'; +import type { FramesRendererProps } from './utils/types'; const getActive = (refId: FramesRendererProps['refId'], refs: FramesRendererProps['refs']) => { if (refId && refs[refId]) { diff --git a/code/core/src/manager/components/preview/Iframe.tsx b/code/core/src/manager/components/preview/Iframe.tsx index e7f0df251147..13fd65261ec2 100644 --- a/code/core/src/manager/components/preview/Iframe.tsx +++ b/code/core/src/manager/components/preview/Iframe.tsx @@ -1,7 +1,8 @@ import type { IframeHTMLAttributes } from 'react'; import React from 'react'; -import { styled } from '@storybook/core/theming'; + import { Zoom } from '@storybook/core/components'; +import { styled } from '@storybook/core/theming'; const StyledIframe = styled.iframe(({ theme }) => ({ backgroundColor: theme.background.preview, diff --git a/code/core/src/manager/components/preview/Preview.tsx b/code/core/src/manager/components/preview/Preview.tsx index 2350b58f1b3f..8a459276f0e7 100644 --- a/code/core/src/manager/components/preview/Preview.tsx +++ b/code/core/src/manager/components/preview/Preview.tsx @@ -1,20 +1,20 @@ import type { FC } from 'react'; import React, { Fragment, useEffect, useRef, useState } from 'react'; -import { Helmet } from 'react-helmet-async'; -import { global } from '@storybook/global'; -import { Consumer, type Combo, merge, addons, types } from '@storybook/core/manager-api'; +import { Loader } from '@storybook/core/components'; import type { Addon_BaseType, Addon_WrapperType } from '@storybook/core/types'; +import { global } from '@storybook/global'; + import { PREVIEW_BUILDER_PROGRESS, SET_CURRENT_STORY } from '@storybook/core/core-events'; +import { type Combo, Consumer, addons, merge, types } from '@storybook/core/manager-api'; -import { Loader } from '@storybook/core/components'; +import { Helmet } from 'react-helmet-async'; -import * as S from './utils/components'; -import { ZoomProvider, ZoomConsumer } from './tools/zoom'; -import { ApplyWrappers } from './Wrappers'; -import { ToolbarComp } from './Toolbar'; import { FramesRenderer } from './FramesRenderer'; - +import { ToolbarComp } from './Toolbar'; +import { ApplyWrappers } from './Wrappers'; +import { ZoomConsumer, ZoomProvider } from './tools/zoom'; +import * as S from './utils/components'; import type { PreviewProps } from './utils/types'; const canvasMapper = ({ state, api }: Combo) => ({ diff --git a/code/core/src/manager/components/preview/Toolbar.tsx b/code/core/src/manager/components/preview/Toolbar.tsx index 297764e3983f..de8c1aab066f 100644 --- a/code/core/src/manager/components/preview/Toolbar.tsx +++ b/code/core/src/manager/components/preview/Toolbar.tsx @@ -1,30 +1,29 @@ import React, { Fragment } from 'react'; +import { IconButton, Separator, TabBar, TabButton } from '@storybook/core/components'; import { styled } from '@storybook/core/theming'; +import { type Addon_BaseType, Addon_TypesEnum } from '@storybook/core/types'; +import { CloseIcon, ExpandIcon } from '@storybook/icons'; -import { IconButton, Separator, TabButton, TabBar } from '@storybook/core/components'; import { - shortcutToHumanString, - Consumer, - type Combo, type API, - type State, - merge, + type Combo, + Consumer, type LeafEntry, + type State, addons, + merge, + shortcutToHumanString, types, } from '@storybook/core/manager-api'; -import { Addon_TypesEnum, type Addon_BaseType } from '@storybook/core/types'; -import { CloseIcon, ExpandIcon } from '@storybook/icons'; -import { zoomTool } from './tools/zoom'; - -import type { PreviewProps } from './utils/types'; +import { useLayout } from '../layout/LayoutProvider'; +import { addonsTool } from './tools/addons'; import { copyTool } from './tools/copy'; import { ejectTool } from './tools/eject'; -import { addonsTool } from './tools/addons'; import { remountTool } from './tools/remount'; -import { useLayout } from '../layout/LayoutProvider'; +import { zoomTool } from './tools/zoom'; +import type { PreviewProps } from './utils/types'; export const getTools = (getFn: API['getElements']) => Object.values(getFn(types.TOOL)); export const getToolsExtra = (getFn: API['getElements']) => Object.values(getFn(types.TOOLEXTRA)); diff --git a/code/core/src/manager/components/preview/Wrappers.tsx b/code/core/src/manager/components/preview/Wrappers.tsx index a6ecc04a4afa..299db428b1d9 100644 --- a/code/core/src/manager/components/preview/Wrappers.tsx +++ b/code/core/src/manager/components/preview/Wrappers.tsx @@ -1,9 +1,11 @@ import type { FC, PropsWithChildren } from 'react'; import React, { Fragment } from 'react'; + import type { Addon_WrapperType } from '@storybook/core/types'; import { Addon_TypesEnum } from '@storybook/core/types'; -import type { ApplyWrappersProps } from './utils/types'; + import { IframeWrapper } from './utils/components'; +import type { ApplyWrappersProps } from './utils/types'; export const ApplyWrappers: FC> = ({ wrappers, diff --git a/code/core/src/manager/components/preview/tools/addons.tsx b/code/core/src/manager/components/preview/tools/addons.tsx index a0beb24f768a..46d45f6eac07 100644 --- a/code/core/src/manager/components/preview/tools/addons.tsx +++ b/code/core/src/manager/components/preview/tools/addons.tsx @@ -1,10 +1,12 @@ import React from 'react'; + import { IconButton } from '@storybook/core/components'; -import { Consumer, types } from '@storybook/core/manager-api'; -import type { Combo } from '@storybook/core/manager-api'; import type { Addon_BaseType } from '@storybook/core/types'; import { BottomBarIcon, SidebarAltIcon } from '@storybook/icons'; +import { Consumer, types } from '@storybook/core/manager-api'; +import type { Combo } from '@storybook/core/manager-api'; + const menuMapper = ({ api, state }: Combo) => ({ isVisible: api.getIsPanelShown(), singleStory: state.singleStory, diff --git a/code/core/src/manager/components/preview/tools/copy.tsx b/code/core/src/manager/components/preview/tools/copy.tsx index 2fdc098cffe4..adf9b54efd24 100644 --- a/code/core/src/manager/components/preview/tools/copy.tsx +++ b/code/core/src/manager/components/preview/tools/copy.tsx @@ -1,12 +1,15 @@ -import { global } from '@storybook/global'; import React from 'react'; -import copy from 'copy-to-clipboard'; -import { getStoryHref, IconButton } from '@storybook/core/components'; -import { Consumer, types } from '@storybook/core/manager-api'; -import type { Combo } from '@storybook/core/manager-api'; + +import { IconButton, getStoryHref } from '@storybook/core/components'; import type { Addon_BaseType } from '@storybook/core/types'; +import { global } from '@storybook/global'; import { LinkIcon } from '@storybook/icons'; +import { Consumer, types } from '@storybook/core/manager-api'; +import type { Combo } from '@storybook/core/manager-api'; + +import copy from 'copy-to-clipboard'; + const { PREVIEW_URL, document } = global; const copyMapper = ({ state }: Combo) => { diff --git a/code/core/src/manager/components/preview/tools/eject.tsx b/code/core/src/manager/components/preview/tools/eject.tsx index 25bf9676c8d7..dda18c7db1f9 100644 --- a/code/core/src/manager/components/preview/tools/eject.tsx +++ b/code/core/src/manager/components/preview/tools/eject.tsx @@ -1,11 +1,13 @@ -import { global } from '@storybook/global'; import React from 'react'; -import { getStoryHref, IconButton } from '@storybook/core/components'; -import { Consumer, types } from '@storybook/core/manager-api'; -import type { Combo } from '@storybook/core/manager-api'; + +import { IconButton, getStoryHref } from '@storybook/core/components'; import type { Addon_BaseType } from '@storybook/core/types'; +import { global } from '@storybook/global'; import { ShareAltIcon } from '@storybook/icons'; +import { Consumer, types } from '@storybook/core/manager-api'; +import type { Combo } from '@storybook/core/manager-api'; + const { PREVIEW_URL } = global; const ejectMapper = ({ state }: Combo) => { diff --git a/code/core/src/manager/components/preview/tools/menu.tsx b/code/core/src/manager/components/preview/tools/menu.tsx index 9cf7a3a1ea64..f61f8955c541 100644 --- a/code/core/src/manager/components/preview/tools/menu.tsx +++ b/code/core/src/manager/components/preview/tools/menu.tsx @@ -1,10 +1,12 @@ import React from 'react'; + import { IconButton, Separator } from '@storybook/core/components'; -import { Consumer, types } from '@storybook/core/manager-api'; -import type { Combo } from '@storybook/core/manager-api'; import type { Addon_BaseType } from '@storybook/core/types'; import { MenuIcon } from '@storybook/icons'; +import { Consumer, types } from '@storybook/core/manager-api'; +import type { Combo } from '@storybook/core/manager-api'; + const menuMapper = ({ api, state }: Combo) => ({ isVisible: api.getIsNavShown(), singleStory: state.singleStory, diff --git a/code/core/src/manager/components/preview/tools/remount.tsx b/code/core/src/manager/components/preview/tools/remount.tsx index 1d8735b7dec3..2facd7a8465e 100644 --- a/code/core/src/manager/components/preview/tools/remount.tsx +++ b/code/core/src/manager/components/preview/tools/remount.tsx @@ -1,13 +1,15 @@ import type { ComponentProps } from 'react'; import React, { useState } from 'react'; + import { IconButton } from '@storybook/core/components'; -import { Consumer, types } from '@storybook/core/manager-api'; -import type { Combo } from '@storybook/core/manager-api'; import { styled } from '@storybook/core/theming'; -import { FORCE_REMOUNT } from '@storybook/core/core-events'; import type { Addon_BaseType } from '@storybook/core/types'; import { SyncIcon } from '@storybook/icons'; +import { FORCE_REMOUNT } from '@storybook/core/core-events'; +import { Consumer, types } from '@storybook/core/manager-api'; +import type { Combo } from '@storybook/core/manager-api'; + interface AnimatedButtonProps { animating?: boolean; } diff --git a/code/core/src/manager/components/preview/tools/zoom.tsx b/code/core/src/manager/components/preview/tools/zoom.tsx index 9af3c17d9c39..aba59a2da272 100644 --- a/code/core/src/manager/components/preview/tools/zoom.tsx +++ b/code/core/src/manager/components/preview/tools/zoom.tsx @@ -1,11 +1,12 @@ -import type { SyntheticEvent, MouseEventHandler, PropsWithChildren } from 'react'; +import type { MouseEventHandler, PropsWithChildren, SyntheticEvent } from 'react'; import React, { Component, createContext, memo, useCallback } from 'react'; import { IconButton, Separator } from '@storybook/core/components'; import type { Addon_BaseType } from '@storybook/core/types'; -import { types } from '@storybook/core/manager-api'; import { ZoomIcon, ZoomOutIcon, ZoomResetIcon } from '@storybook/icons'; +import { types } from '@storybook/core/manager-api'; + const initialZoom = 1 as const; const Context = createContext({ value: initialZoom, set: (v: number) => {} }); diff --git a/code/core/src/manager/components/preview/utils/components.ts b/code/core/src/manager/components/preview/utils/components.ts index b9cd39b097a0..e38f44164e51 100644 --- a/code/core/src/manager/components/preview/utils/components.ts +++ b/code/core/src/manager/components/preview/utils/components.ts @@ -1,5 +1,5 @@ -import { styled } from '@storybook/core/theming'; import { Link } from '@storybook/core/router'; +import { styled } from '@storybook/core/theming'; export const PreviewContainer = styled.main({ display: 'flex', diff --git a/code/core/src/manager/components/preview/utils/types.tsx b/code/core/src/manager/components/preview/utils/types.tsx index 2a1fd83c2e6d..6c18cb6bdddc 100644 --- a/code/core/src/manager/components/preview/utils/types.tsx +++ b/code/core/src/manager/components/preview/utils/types.tsx @@ -1,12 +1,14 @@ import type { ReactElement } from 'react'; -import type { State, API, LeafEntry } from '@storybook/core/manager-api'; + import type { + API_ViewMode, Addon_BaseType, Addon_WrapperType, - API_ViewMode, StoryId, } from '@storybook/core/types'; +import type { API, LeafEntry, State } from '@storybook/core/manager-api'; + export interface PreviewProps { api: API; viewMode: API_ViewMode; diff --git a/code/core/src/manager/components/sidebar/Brand.tsx b/code/core/src/manager/components/sidebar/Brand.tsx index f3c0a89c046a..05ff72a23c0a 100644 --- a/code/core/src/manager/components/sidebar/Brand.tsx +++ b/code/core/src/manager/components/sidebar/Brand.tsx @@ -1,7 +1,7 @@ import React from 'react'; -import { styled, withTheme } from '@storybook/core/theming'; import { StorybookLogo } from '@storybook/core/components'; +import { styled, withTheme } from '@storybook/core/theming'; export const StorybookLogoStyled = styled(StorybookLogo)(({ theme }) => ({ width: 'auto', diff --git a/code/core/src/manager/components/sidebar/CreateNewStoryFileModal.tsx b/code/core/src/manager/components/sidebar/CreateNewStoryFileModal.tsx index 4c45bcc51645..70ad346fbdbb 100644 --- a/code/core/src/manager/components/sidebar/CreateNewStoryFileModal.tsx +++ b/code/core/src/manager/components/sidebar/CreateNewStoryFileModal.tsx @@ -1,5 +1,7 @@ import React, { useCallback, useDeferredValue, useEffect, useRef, useState } from 'react'; + import { CheckIcon } from '@storybook/icons'; + import type { ArgTypesRequestPayload, ArgTypesResponsePayload, @@ -28,8 +30,8 @@ import { addons, experimental_requestResponse, useStorybookApi } from '@storyboo import { useDebounce } from '../../hooks/useDebounce'; import type { NewStoryPayload, SearchResult } from './FileSearchList'; -import { extractSeededRequiredArgs, trySelectNewStory } from './FileSearchModal.utils'; import { FileSearchModal } from './FileSearchModal'; +import { extractSeededRequiredArgs, trySelectNewStory } from './FileSearchModal.utils'; interface CreateNewStoryFileModalProps { open: boolean; diff --git a/code/core/src/manager/components/sidebar/Explorer.stories.tsx b/code/core/src/manager/components/sidebar/Explorer.stories.tsx index 9cf8c887397f..908ead2be9f3 100644 --- a/code/core/src/manager/components/sidebar/Explorer.stories.tsx +++ b/code/core/src/manager/components/sidebar/Explorer.stories.tsx @@ -1,10 +1,10 @@ import React from 'react'; import { Explorer } from './Explorer'; +import { IconSymbols } from './IconSymbols'; +import * as RefStories from './Refs.stories'; import { mockDataset } from './mockdata'; import type { RefType } from './types'; -import * as RefStories from './Refs.stories'; -import { IconSymbols } from './IconSymbols'; export default { component: Explorer, diff --git a/code/core/src/manager/components/sidebar/Explorer.tsx b/code/core/src/manager/components/sidebar/Explorer.tsx index dae74f34e21c..1c4a93825ebe 100644 --- a/code/core/src/manager/components/sidebar/Explorer.tsx +++ b/code/core/src/manager/components/sidebar/Explorer.tsx @@ -1,11 +1,10 @@ import type { FC } from 'react'; import React, { useRef } from 'react'; +import { HighlightStyles } from './HighlightStyles'; import { Ref } from './Refs'; import type { CombinedDataset, Selection } from './types'; - import { useHighlighted } from './useHighlighted'; -import { HighlightStyles } from './HighlightStyles'; export interface ExplorerProps { isLoading: boolean; diff --git a/code/core/src/manager/components/sidebar/FIleSearchList.utils.tsx b/code/core/src/manager/components/sidebar/FIleSearchList.utils.tsx index 87c2297a44f5..5ee7b3313a82 100644 --- a/code/core/src/manager/components/sidebar/FIleSearchList.utils.tsx +++ b/code/core/src/manager/components/sidebar/FIleSearchList.utils.tsx @@ -1,7 +1,8 @@ -import type { Virtualizer } from '@tanstack/react-virtual'; import { useEffect } from 'react'; import { flushSync } from 'react-dom'; +import type { Virtualizer } from '@tanstack/react-virtual'; + interface UseArrowKeyNavigationProps { rowVirtualizer: Virtualizer; parentRef: React.MutableRefObject; diff --git a/code/core/src/manager/components/sidebar/FileList.tsx b/code/core/src/manager/components/sidebar/FileList.tsx index 9f7cc75c290a..bc2d46eee829 100644 --- a/code/core/src/manager/components/sidebar/FileList.tsx +++ b/code/core/src/manager/components/sidebar/FileList.tsx @@ -1,4 +1,5 @@ import { styled } from '@storybook/core/theming'; + import { rgba } from 'polished'; export const FileListWrapper = styled('div')(({ theme }) => ({ diff --git a/code/core/src/manager/components/sidebar/FileSearchList.stories.tsx b/code/core/src/manager/components/sidebar/FileSearchList.stories.tsx index a1f9ca9d9df6..2c5ec140ee86 100644 --- a/code/core/src/manager/components/sidebar/FileSearchList.stories.tsx +++ b/code/core/src/manager/components/sidebar/FileSearchList.stories.tsx @@ -1,5 +1,5 @@ import type { Meta, StoryObj } from '@storybook/react'; -import { fn, fireEvent, findByText, expect } from '@storybook/test'; +import { expect, findByText, fireEvent, fn } from '@storybook/test'; import { FileSearchList } from './FileSearchList'; diff --git a/code/core/src/manager/components/sidebar/FileSearchList.tsx b/code/core/src/manager/components/sidebar/FileSearchList.tsx index 9ba2fd205c47..3a4eacbbf03c 100644 --- a/code/core/src/manager/components/sidebar/FileSearchList.tsx +++ b/code/core/src/manager/components/sidebar/FileSearchList.tsx @@ -1,7 +1,18 @@ import React, { memo, useCallback, useMemo, useState } from 'react'; -import { ChevronDownIcon, ChevronRightIcon, ComponentIcon } from '@storybook/icons'; + +import { TooltipNote, WithTooltip } from '@storybook/core/components'; import { styled } from '@storybook/core/theming'; -import { FileSearchListLoadingSkeleton } from './FileSearchListSkeleton'; +import { ChevronDownIcon, ChevronRightIcon, ComponentIcon } from '@storybook/icons'; + +import type { + CreateNewStoryRequestPayload, + FileComponentSearchResponsePayload, +} from '@storybook/core/core-events'; + +import type { VirtualItem } from '@tanstack/react-virtual'; +import { useVirtualizer } from '@tanstack/react-virtual'; + +import { useArrowKeyNavigation } from './FIleSearchList.utils'; import { DefaultExport, FileList, @@ -21,14 +32,7 @@ import { NoResults, NoResultsDescription, } from './FileList'; -import type { VirtualItem } from '@tanstack/react-virtual'; -import { useVirtualizer } from '@tanstack/react-virtual'; -import type { - CreateNewStoryRequestPayload, - FileComponentSearchResponsePayload, -} from '@storybook/core/core-events'; -import { WithTooltip, TooltipNote } from '@storybook/core/components'; -import { useArrowKeyNavigation } from './FIleSearchList.utils'; +import { FileSearchListLoadingSkeleton } from './FileSearchListSkeleton'; export type SearchResult = NonNullable[0]; diff --git a/code/core/src/manager/components/sidebar/FileSearchListSkeleton.tsx b/code/core/src/manager/components/sidebar/FileSearchListSkeleton.tsx index ddbb757e1fee..33e6e0dd890b 100644 --- a/code/core/src/manager/components/sidebar/FileSearchListSkeleton.tsx +++ b/code/core/src/manager/components/sidebar/FileSearchListSkeleton.tsx @@ -1,5 +1,7 @@ import React from 'react'; + import { styled } from '@storybook/core/theming'; + import { FileList, FileListItem } from './FileList'; const FileListItemContentWrapperSkeleton = styled('div')(({ theme }) => ({ diff --git a/code/core/src/manager/components/sidebar/FileSearchModal.stories.tsx b/code/core/src/manager/components/sidebar/FileSearchModal.stories.tsx index 8d6d2b7e9c3a..a2a10005b887 100644 --- a/code/core/src/manager/components/sidebar/FileSearchModal.stories.tsx +++ b/code/core/src/manager/components/sidebar/FileSearchModal.stories.tsx @@ -1,8 +1,9 @@ -import type { Meta, StoryObj } from '@storybook/react'; -import { findByText, fireEvent, fn, expect } from '@storybook/test'; -import { WithResults } from './FileSearchList.stories'; import React, { useState } from 'react'; +import type { Meta, StoryObj } from '@storybook/react'; +import { expect, findByText, fireEvent, fn } from '@storybook/test'; + +import { WithResults } from './FileSearchList.stories'; import { FileSearchModal } from './FileSearchModal'; const meta = { diff --git a/code/core/src/manager/components/sidebar/FileSearchModal.tsx b/code/core/src/manager/components/sidebar/FileSearchModal.tsx index 9762c8222633..469493744d43 100644 --- a/code/core/src/manager/components/sidebar/FileSearchModal.tsx +++ b/code/core/src/manager/components/sidebar/FileSearchModal.tsx @@ -1,11 +1,12 @@ import React, { useEffect, useState, useTransition } from 'react'; -import { Modal, Form } from '@storybook/core/components'; + +import { Form, Modal } from '@storybook/core/components'; import { styled } from '@storybook/core/theming'; import { CloseAltIcon, SearchIcon, SyncIcon } from '@storybook/icons'; +import { useMeasure } from '../../hooks/useMeasure'; import type { NewStoryPayload, SearchResult } from './FileSearchList'; import { FileSearchList } from './FileSearchList'; -import { useMeasure } from '../../hooks/useMeasure'; const MODAL_HEIGHT = 418; diff --git a/code/core/src/manager/components/sidebar/FileSearchModal.utils.test.tsx b/code/core/src/manager/components/sidebar/FileSearchModal.utils.test.tsx index d86a9c208d68..34f1f4ec8a68 100644 --- a/code/core/src/manager/components/sidebar/FileSearchModal.utils.test.tsx +++ b/code/core/src/manager/components/sidebar/FileSearchModal.utils.test.tsx @@ -1,7 +1,9 @@ import { describe, expect, it } from 'vitest'; -import { extractSeededRequiredArgs } from './FileSearchModal.utils'; + import type { ArgTypes } from '@storybook/csf'; +import { extractSeededRequiredArgs } from './FileSearchModal.utils'; + describe('FileSearchModal.utils', () => { describe('extractSeededRequiredArgs', () => { it('should extract seeded required args', () => { diff --git a/code/core/src/manager/components/sidebar/Heading.stories.tsx b/code/core/src/manager/components/sidebar/Heading.stories.tsx index 0308cae7dd50..678a6c8e2ae5 100644 --- a/code/core/src/manager/components/sidebar/Heading.stories.tsx +++ b/code/core/src/manager/components/sidebar/Heading.stories.tsx @@ -1,11 +1,13 @@ // @TODO: use addon-interactions and remove the rule disable above import React from 'react'; -import type { Meta, StoryObj, StoryFn } from '@storybook/react'; + import { ThemeProvider, useTheme } from '@storybook/core/theming'; import type { Theme } from '@storybook/core/theming'; -import { action } from '@storybook/addon-actions'; +import type { Meta, StoryFn, StoryObj } from '@storybook/react'; import { screen } from '@storybook/test'; +import { action } from '@storybook/addon-actions'; + import { Heading } from './Heading'; type Story = StoryFn; diff --git a/code/core/src/manager/components/sidebar/Heading.tsx b/code/core/src/manager/components/sidebar/Heading.tsx index 962e91bbc8a5..905ae1f61081 100644 --- a/code/core/src/manager/components/sidebar/Heading.tsx +++ b/code/core/src/manager/components/sidebar/Heading.tsx @@ -1,9 +1,10 @@ -import type { FC, ComponentProps } from 'react'; +import type { ComponentProps, FC } from 'react'; import React from 'react'; -import { styled } from '@storybook/core/theming'; -import { Button } from '@storybook/core/components'; +import { Button } from '@storybook/core/components'; +import { styled } from '@storybook/core/theming'; import type { Addon_SidebarTopType } from '@storybook/core/types'; + import { Brand } from './Brand'; import type { MenuList, SidebarMenuProps } from './Menu'; import { SidebarMenu } from './Menu'; diff --git a/code/core/src/manager/components/sidebar/HighlightStyles.tsx b/code/core/src/manager/components/sidebar/HighlightStyles.tsx index 0683a04c9550..71f853666865 100644 --- a/code/core/src/manager/components/sidebar/HighlightStyles.tsx +++ b/code/core/src/manager/components/sidebar/HighlightStyles.tsx @@ -1,7 +1,10 @@ -import { transparentize } from 'polished'; import type { FC } from 'react'; import React from 'react'; + import { Global } from '@storybook/core/theming'; + +import { transparentize } from 'polished'; + import type { Highlight } from './types'; // @ts-expect-error (non strict) diff --git a/code/core/src/manager/components/sidebar/IconSymbols.tsx b/code/core/src/manager/components/sidebar/IconSymbols.tsx index 8dec99d6e248..20101343e7b2 100644 --- a/code/core/src/manager/components/sidebar/IconSymbols.tsx +++ b/code/core/src/manager/components/sidebar/IconSymbols.tsx @@ -1,7 +1,8 @@ -import { styled } from '@storybook/core/theming'; import type { FC } from 'react'; import React from 'react'; +import { styled } from '@storybook/core/theming'; + const Svg = styled.svg` position: absolute; width: 0; diff --git a/code/core/src/manager/components/sidebar/Loader.tsx b/code/core/src/manager/components/sidebar/Loader.tsx index 254626aa0b79..96499c4b2ad8 100644 --- a/code/core/src/manager/components/sidebar/Loader.tsx +++ b/code/core/src/manager/components/sidebar/Loader.tsx @@ -1,5 +1,6 @@ import type { FC } from 'react'; import React, { Fragment } from 'react'; + import { styled } from '@storybook/core/theming'; const LOADER_SEQUENCE = [0, 0, 1, 1, 2, 3, 3, 3, 1, 1, 1, 2, 2, 2, 3]; diff --git a/code/core/src/manager/components/sidebar/Menu.stories.tsx b/code/core/src/manager/components/sidebar/Menu.stories.tsx index e4873e751b05..663bd4caa3b4 100644 --- a/code/core/src/manager/components/sidebar/Menu.stories.tsx +++ b/code/core/src/manager/components/sidebar/Menu.stories.tsx @@ -1,15 +1,17 @@ import type { ComponentProps } from 'react'; import React from 'react'; -import type { Meta, StoryObj } from '@storybook/react'; import { TooltipLinkList } from '@storybook/core/components'; import { styled } from '@storybook/core/theming'; -import { screen, userEvent, within, expect } from '@storybook/test'; -import type { State } from '@storybook/core/manager-api'; import { LinkIcon } from '@storybook/icons'; -import { SidebarMenu } from './Menu'; +import type { Meta, StoryObj } from '@storybook/react'; +import { expect, screen, userEvent, within } from '@storybook/test'; + +import type { State } from '@storybook/core/manager-api'; + import { useMenu } from '../../container/Menu'; import { LayoutProvider } from '../layout/LayoutProvider'; +import { SidebarMenu } from './Menu'; const fakemenu: ComponentProps['links'] = [ { title: 'has icon', icon: , id: 'icon' }, diff --git a/code/core/src/manager/components/sidebar/Menu.tsx b/code/core/src/manager/components/sidebar/Menu.tsx index 960fa8b58844..d24656aa7079 100644 --- a/code/core/src/manager/components/sidebar/Menu.tsx +++ b/code/core/src/manager/components/sidebar/Menu.tsx @@ -1,11 +1,13 @@ import type { ComponentProps, FC } from 'react'; import React, { useMemo, useState } from 'react'; -import { styled } from '@storybook/core/theming'; -import { transparentize } from 'polished'; import type { Button, TooltipLinkListLink } from '@storybook/core/components'; -import { WithTooltip, TooltipLinkList, IconButton } from '@storybook/core/components'; +import { IconButton, TooltipLinkList, WithTooltip } from '@storybook/core/components'; +import { styled } from '@storybook/core/theming'; import { CloseIcon, CogIcon } from '@storybook/icons'; + +import { transparentize } from 'polished'; + import { useLayout } from '../layout/LayoutProvider'; export type MenuList = ComponentProps['links']; diff --git a/code/core/src/manager/components/sidebar/RefBlocks.tsx b/code/core/src/manager/components/sidebar/RefBlocks.tsx index d4fd979129ba..16af958a8a02 100644 --- a/code/core/src/manager/components/sidebar/RefBlocks.tsx +++ b/code/core/src/manager/components/sidebar/RefBlocks.tsx @@ -1,13 +1,14 @@ -import { global } from '@storybook/global'; import type { FC } from 'react'; -import React, { useState, useCallback, Fragment } from 'react'; +import React, { Fragment, useCallback, useState } from 'react'; -import { WithTooltip, Spaced, Button, Link, ErrorFormatter } from '@storybook/core/components'; -import { logger } from '@storybook/core/client-logger'; +import { Button, ErrorFormatter, Link, Spaced, WithTooltip } from '@storybook/core/components'; import { styled } from '@storybook/core/theming'; - +import { global } from '@storybook/global'; import { ChevronDownIcon, LockIcon, SyncIcon } from '@storybook/icons'; -import { Loader, Contained } from './Loader'; + +import { logger } from '@storybook/core/client-logger'; + +import { Contained, Loader } from './Loader'; const { window: globalWindow } = global; diff --git a/code/core/src/manager/components/sidebar/RefIndicator.tsx b/code/core/src/manager/components/sidebar/RefIndicator.tsx index 6fca6687effe..7c49c95105cd 100644 --- a/code/core/src/manager/components/sidebar/RefIndicator.tsx +++ b/code/core/src/manager/components/sidebar/RefIndicator.tsx @@ -1,13 +1,10 @@ -import { global } from '@storybook/global'; import type { FC, MouseEventHandler } from 'react'; -import React, { useMemo, useCallback, forwardRef } from 'react'; +import React, { forwardRef, useCallback, useMemo } from 'react'; import type { TooltipLinkListLink } from '@storybook/core/components'; -import { WithTooltip, Spaced, TooltipLinkList } from '@storybook/core/components'; +import { Spaced, TooltipLinkList, WithTooltip } from '@storybook/core/components'; import { styled, useTheme } from '@storybook/core/theming'; -import { transparentize } from 'polished'; -import { useStorybookApi } from '@storybook/core/manager-api'; - +import { global } from '@storybook/global'; import { AlertIcon, ChevronDownIcon, @@ -18,9 +15,13 @@ import { MarkupIcon, TimeIcon, } from '@storybook/icons'; -import type { RefType } from './types'; + +import { useStorybookApi } from '@storybook/core/manager-api'; + +import { transparentize } from 'polished'; import type { getStateType } from '../../utils/tree'; +import type { RefType } from './types'; const { document, window: globalWindow } = global; diff --git a/code/core/src/manager/components/sidebar/Refs.stories.tsx b/code/core/src/manager/components/sidebar/Refs.stories.tsx index 6b89f1b13a57..a26cad976dcb 100644 --- a/code/core/src/manager/components/sidebar/Refs.stories.tsx +++ b/code/core/src/manager/components/sidebar/Refs.stories.tsx @@ -1,11 +1,12 @@ import React from 'react'; + import { ManagerContext } from '@storybook/core/manager-api'; -import { Ref } from './Refs'; import { standardData as standardHeaderData } from './Heading.stories'; +import { IconSymbols } from './IconSymbols'; +import { Ref } from './Refs'; import { mockDataset } from './mockdata'; import type { RefType } from './types'; -import { IconSymbols } from './IconSymbols'; export default { component: Ref, diff --git a/code/core/src/manager/components/sidebar/Refs.tsx b/code/core/src/manager/components/sidebar/Refs.tsx index 756080d63ec2..7412a627e889 100644 --- a/code/core/src/manager/components/sidebar/Refs.tsx +++ b/code/core/src/manager/components/sidebar/Refs.tsx @@ -1,21 +1,20 @@ import type { FC, MutableRefObject } from 'react'; -import React, { useEffect, useMemo, useState, useRef, useCallback } from 'react'; +import React, { useCallback, useEffect, useMemo, useRef, useState } from 'react'; + +import { styled } from '@storybook/core/theming'; + import type { State } from '@storybook/core/manager-api'; import { useStorybookApi, useStorybookState } from '@storybook/core/manager-api'; -import { styled } from '@storybook/core/theming'; -import { transparentize } from 'polished'; -import { AuthBlock, ErrorBlock, LoaderBlock, EmptyBlock } from './RefBlocks'; +import { transparentize } from 'polished'; +import { getStateType } from '../../utils/tree'; +import { AuthBlock, EmptyBlock, ErrorBlock, LoaderBlock } from './RefBlocks'; import { RefIndicator } from './RefIndicator'; - -import { Tree } from './Tree'; - import { DEFAULT_REF_ID } from './Sidebar'; -import type { Highlight, RefType } from './types'; - -import { getStateType } from '../../utils/tree'; +import { Tree } from './Tree'; import { CollapseIcon } from './components/CollapseIcon'; +import type { Highlight, RefType } from './types'; export interface RefProps { isLoading: boolean; diff --git a/code/core/src/manager/components/sidebar/Search.stories.tsx b/code/core/src/manager/components/sidebar/Search.stories.tsx index 8de58e633373..5c70863735e0 100644 --- a/code/core/src/manager/components/sidebar/Search.stories.tsx +++ b/code/core/src/manager/components/sidebar/Search.stories.tsx @@ -1,16 +1,19 @@ import React from 'react'; -import type { StoryFn, Meta } from '@storybook/react'; + +import type { Meta, StoryFn } from '@storybook/react'; + import type { API } from '@storybook/core/manager-api'; import { ManagerContext } from '@storybook/core/manager-api'; + import { action } from '@storybook/addon-actions'; -import { index } from './mockdata.large'; +import { IconSymbols } from './IconSymbols'; import { Search } from './Search'; import { SearchResults } from './SearchResults'; import { noResults } from './SearchResults.stories'; import { DEFAULT_REF_ID } from './Sidebar'; +import { index } from './mockdata.large'; import type { Selection } from './types'; -import { IconSymbols } from './IconSymbols'; const refId = DEFAULT_REF_ID; const data = { [refId]: { id: refId, url: '/', index, previewInitialized: true } }; diff --git a/code/core/src/manager/components/sidebar/Search.tsx b/code/core/src/manager/components/sidebar/Search.tsx index 48abe7637de1..470002f85ef3 100644 --- a/code/core/src/manager/components/sidebar/Search.tsx +++ b/code/core/src/manager/components/sidebar/Search.tsx @@ -1,28 +1,31 @@ -import { useStorybookApi, shortcutToHumanString } from '@storybook/core/manager-api'; +import React, { useCallback, useRef, useState } from 'react'; + +import { IconButton, TooltipNote, WithTooltip } from '@storybook/core/components'; import { styled } from '@storybook/core/theming'; +import { global } from '@storybook/global'; +import { CloseIcon, PlusIcon, SearchIcon } from '@storybook/icons'; + +import { shortcutToHumanString, useStorybookApi } from '@storybook/core/manager-api'; + import type { DownshiftState, StateChangeOptions } from 'downshift'; import Downshift from 'downshift'; import type { FuseOptions } from 'fuse.js'; import Fuse from 'fuse.js'; -import { global } from '@storybook/global'; -import React, { useRef, useState, useCallback } from 'react'; -import { CloseIcon, PlusIcon, SearchIcon } from '@storybook/icons'; -import { IconButton, TooltipNote, WithTooltip } from '@storybook/core/components'; + +import { getGroupStatus, getHighestStatus } from '../../utils/status'; +import { scrollIntoView, searchItem } from '../../utils/tree'; +import { useLayout } from '../layout/LayoutProvider'; +import { CreateNewStoryFileModal } from './CreateNewStoryFileModal'; import { DEFAULT_REF_ID } from './Sidebar'; import type { CombinedDataset, - SearchItem, - SearchResult, DownshiftItem, SearchChildrenFn, + SearchItem, + SearchResult, Selection, } from './types'; -import { isSearchResult, isExpandType } from './types'; - -import { scrollIntoView, searchItem } from '../../utils/tree'; -import { getGroupStatus, getHighestStatus } from '../../utils/status'; -import { useLayout } from '../layout/LayoutProvider'; -import { CreateNewStoryFileModal } from './CreateNewStoryFileModal'; +import { isExpandType, isSearchResult } from './types'; const { document } = global; diff --git a/code/core/src/manager/components/sidebar/SearchResults.stories.tsx b/code/core/src/manager/components/sidebar/SearchResults.stories.tsx index c45473a9c3d3..114f529bcd85 100644 --- a/code/core/src/manager/components/sidebar/SearchResults.stories.tsx +++ b/code/core/src/manager/components/sidebar/SearchResults.stories.tsx @@ -1,11 +1,12 @@ import React from 'react'; + import type { StoriesHash } from '@storybook/core/manager-api'; -import { mockDataset } from './mockdata'; -import { SearchResults } from './SearchResults'; -import type { CombinedDataset, Refs, SearchItem } from './types'; import { searchItem } from '../../utils/tree'; import { IconSymbols } from './IconSymbols'; +import { SearchResults } from './SearchResults'; +import { mockDataset } from './mockdata'; +import type { CombinedDataset, Refs, SearchItem } from './types'; export default { component: SearchResults, diff --git a/code/core/src/manager/components/sidebar/SearchResults.tsx b/code/core/src/manager/components/sidebar/SearchResults.tsx index 0259bd2a92e9..4c7793ef9b8d 100644 --- a/code/core/src/manager/components/sidebar/SearchResults.tsx +++ b/code/core/src/manager/components/sidebar/SearchResults.tsx @@ -1,21 +1,23 @@ -import { styled } from '@storybook/core/theming'; -import { Button, IconButton } from '@storybook/core/components'; -import { global } from '@storybook/global'; import type { FC, MouseEventHandler, PropsWithChildren, ReactNode } from 'react'; import React, { useCallback, useEffect } from 'react'; -import type { ControllerStateAndHelpers } from 'downshift'; -import { useStorybookApi } from '@storybook/core/manager-api'; +import { Button, IconButton } from '@storybook/core/components'; +import { styled } from '@storybook/core/theming'; +import { global } from '@storybook/global'; +import { TrashIcon } from '@storybook/icons'; + import { PRELOAD_ENTRIES } from '@storybook/core/core-events'; +import { useStorybookApi } from '@storybook/core/manager-api'; + +import type { ControllerStateAndHelpers } from 'downshift'; import { transparentize } from 'polished'; -import { TrashIcon } from '@storybook/icons'; -import { TypeIcon } from './TreeNode'; -import type { Match, DownshiftItem, SearchResult } from './types'; -import { isExpandType } from './types'; -import { matchesKeyCode, matchesModifiers } from '../../keybinding'; +import { matchesKeyCode, matchesModifiers } from '../../keybinding'; import { statusMapping } from '../../utils/status'; import { UseSymbol } from './IconSymbols'; +import { TypeIcon } from './TreeNode'; +import type { DownshiftItem, Match, SearchResult } from './types'; +import { isExpandType } from './types'; const { document } = global; diff --git a/code/core/src/manager/components/sidebar/Sidebar.stories.tsx b/code/core/src/manager/components/sidebar/Sidebar.stories.tsx index 3179587c2123..230e68ee203f 100644 --- a/code/core/src/manager/components/sidebar/Sidebar.stories.tsx +++ b/code/core/src/manager/components/sidebar/Sidebar.stories.tsx @@ -1,18 +1,20 @@ import React from 'react'; -import type { IndexHash, State } from '@storybook/core/manager-api'; -import { ManagerContext, types } from '@storybook/core/manager-api'; -import type { StoryObj, Meta } from '@storybook/react'; -import { within, userEvent, expect, fn } from '@storybook/test'; -import type { Addon_SidebarTopType } from '@storybook/core/types'; import { Button, IconButton } from '@storybook/core/components'; +import type { Addon_SidebarTopType } from '@storybook/core/types'; import { FaceHappyIcon } from '@storybook/icons'; -import { Sidebar, DEFAULT_REF_ID } from './Sidebar'; +import type { Meta, StoryObj } from '@storybook/react'; +import { expect, fn, userEvent, within } from '@storybook/test'; + +import type { IndexHash, State } from '@storybook/core/manager-api'; +import { ManagerContext, types } from '@storybook/core/manager-api'; + +import { LayoutProvider } from '../layout/LayoutProvider'; import { standardData as standardHeaderData } from './Heading.stories'; +import { IconSymbols } from './IconSymbols'; +import { DEFAULT_REF_ID, Sidebar } from './Sidebar'; import { mockDataset } from './mockdata'; import type { RefType } from './types'; -import { LayoutProvider } from '../layout/LayoutProvider'; -import { IconSymbols } from './IconSymbols'; const wait = (ms: number) => new Promise((resolve) => { diff --git a/code/core/src/manager/components/sidebar/Sidebar.tsx b/code/core/src/manager/components/sidebar/Sidebar.tsx index 583c11518fc9..5cc306d796fb 100644 --- a/code/core/src/manager/components/sidebar/Sidebar.tsx +++ b/code/core/src/manager/components/sidebar/Sidebar.tsx @@ -1,25 +1,23 @@ import React, { useMemo } from 'react'; -import { styled } from '@storybook/core/theming'; import { ScrollArea, Spaced } from '@storybook/core/components'; -import type { State } from '@storybook/core/manager-api'; - +import { styled } from '@storybook/core/theming'; import type { + API_LoadedRefData, Addon_SidebarBottomType, Addon_SidebarTopType, - API_LoadedRefData, } from '@storybook/core/types'; -import type { HeadingProps } from './Heading'; -import { Heading } from './Heading'; -import { Explorer } from './Explorer'; +import type { State } from '@storybook/core/manager-api'; +import { MEDIA_DESKTOP_BREAKPOINT } from '../../constants'; +import { Explorer } from './Explorer'; +import type { HeadingProps } from './Heading'; +import { Heading } from './Heading'; import { Search } from './Search'; - import { SearchResults } from './SearchResults'; import type { CombinedDataset, Selection } from './types'; import { useLastViewed } from './useLastViewed'; -import { MEDIA_DESKTOP_BREAKPOINT } from '../../constants'; export const DEFAULT_REF_ID = 'storybook_internal'; diff --git a/code/core/src/manager/components/sidebar/Tree.stories.tsx b/code/core/src/manager/components/sidebar/Tree.stories.tsx index ab965dfb7d51..aed8dbd4648c 100644 --- a/code/core/src/manager/components/sidebar/Tree.stories.tsx +++ b/code/core/src/manager/components/sidebar/Tree.stories.tsx @@ -1,13 +1,16 @@ // @TODO: use addon-interactions and remove the rule disable above import React, { useState } from 'react'; + +import type { Meta, StoryObj } from '@storybook/react'; +import { expect, within } from '@storybook/test'; + import type { ComponentEntry, IndexHash } from '@storybook/core/manager-api'; + import { action } from '@storybook/addon-actions'; -import type { StoryObj, Meta } from '@storybook/react'; -import { within, expect } from '@storybook/test'; +import { DEFAULT_REF_ID } from './Sidebar'; import { Tree } from './Tree'; import { index } from './mockdata.large'; -import { DEFAULT_REF_ID } from './Sidebar'; const meta = { component: Tree, diff --git a/code/core/src/manager/components/sidebar/Tree.tsx b/code/core/src/manager/components/sidebar/Tree.tsx index f9adf1e16334..41699290cacc 100644 --- a/code/core/src/manager/components/sidebar/Tree.tsx +++ b/code/core/src/manager/components/sidebar/Tree.tsx @@ -1,38 +1,38 @@ +import type { MutableRefObject } from 'react'; +import React, { useCallback, useMemo, useRef } from 'react'; + +import { Button, IconButton, TooltipLinkList, WithTooltip } from '@storybook/core/components'; +import { styled } from '@storybook/core/theming'; +import { CollapseIcon as CollapseIconSvg, ExpandAltIcon } from '@storybook/icons'; + +import { PRELOAD_ENTRIES } from '@storybook/core/core-events'; import { useStorybookApi } from '@storybook/core/manager-api'; import type { - StoriesHash, - GroupEntry, + API, ComponentEntry, - StoryEntry, + GroupEntry, State, - API, + StoriesHash, + StoryEntry, } from '@storybook/core/manager-api'; -import { styled } from '@storybook/core/theming'; -import { Button, IconButton, TooltipLinkList, WithTooltip } from '@storybook/core/components'; -import { transparentize } from 'polished'; -import type { MutableRefObject } from 'react'; -import React, { useCallback, useMemo, useRef } from 'react'; -import { PRELOAD_ENTRIES } from '@storybook/core/core-events'; -import { ExpandAltIcon, CollapseIcon as CollapseIconSvg } from '@storybook/icons'; -import { ComponentNode, DocumentNode, GroupNode, RootNode, StoryNode } from './TreeNode'; - -import type { ExpandAction, ExpandedState } from './useExpanded'; - -import { useExpanded } from './useExpanded'; -import type { Highlight, Item } from './types'; +import { transparentize } from 'polished'; +import { getGroupStatus, getHighestStatus, statusMapping } from '../../utils/status'; import { - isStoryHoistable, createId, getAncestorIds, getDescendantIds, getLink, + isStoryHoistable, } from '../../utils/tree'; -import { statusMapping, getHighestStatus, getGroupStatus } from '../../utils/status'; import { useLayout } from '../layout/LayoutProvider'; import { IconSymbols } from './IconSymbols'; +import { ComponentNode, DocumentNode, GroupNode, RootNode, StoryNode } from './TreeNode'; import { CollapseIcon } from './components/CollapseIcon'; +import type { Highlight, Item } from './types'; +import type { ExpandAction, ExpandedState } from './useExpanded'; +import { useExpanded } from './useExpanded'; const Container = styled.div<{ hasOrphans: boolean }>((props) => ({ marginTop: props.hasOrphans ? 20 : 0, diff --git a/code/core/src/manager/components/sidebar/TreeNode.stories.tsx b/code/core/src/manager/components/sidebar/TreeNode.stories.tsx index b78a9b704773..d35daf9060f6 100644 --- a/code/core/src/manager/components/sidebar/TreeNode.stories.tsx +++ b/code/core/src/manager/components/sidebar/TreeNode.stories.tsx @@ -1,9 +1,9 @@ import React from 'react'; + import { HighlightStyles } from './HighlightStyles'; +import { IconSymbols } from './IconSymbols'; import { LeafNodeStyleWrapper } from './Tree'; - import { ComponentNode, DocumentNode, GroupNode, StoryNode } from './TreeNode'; -import { IconSymbols } from './IconSymbols'; export default { title: 'Sidebar/TreeNode', diff --git a/code/core/src/manager/components/sidebar/TreeNode.tsx b/code/core/src/manager/components/sidebar/TreeNode.tsx index 7c42a42a8f3d..59dd02f04b10 100644 --- a/code/core/src/manager/components/sidebar/TreeNode.tsx +++ b/code/core/src/manager/components/sidebar/TreeNode.tsx @@ -1,7 +1,10 @@ +import type { ComponentProps, FC } from 'react'; +import React from 'react'; + import { styled } from '@storybook/core/theming'; + import { transparentize } from 'polished'; -import type { FC, ComponentProps } from 'react'; -import React from 'react'; + import { UseSymbol } from './IconSymbols'; import { CollapseIcon } from './components/CollapseIcon'; diff --git a/code/core/src/manager/components/sidebar/__tests__/Sidebar.test.tsx b/code/core/src/manager/components/sidebar/__tests__/Sidebar.test.tsx index a24f59333ef5..adc05cb07a55 100644 --- a/code/core/src/manager/components/sidebar/__tests__/Sidebar.test.tsx +++ b/code/core/src/manager/components/sidebar/__tests__/Sidebar.test.tsx @@ -1,14 +1,16 @@ // @vitest-environment happy-dom +import { cleanup, fireEvent, render, screen } from '@testing-library/react'; +import type { RenderResult } from '@testing-library/react'; +import { afterEach, describe, expect, test } from 'vitest'; -import { afterEach, describe, test, expect } from 'vitest'; import React from 'react'; -import { render, screen, fireEvent, cleanup } from '@testing-library/react'; -import { ThemeProvider, ensure, themes } from '@storybook/core/theming'; -import type { HashEntry, Refs } from '@storybook/core/manager-api'; +import { ThemeProvider, ensure, themes } from '@storybook/core/theming'; import type { Theme } from '@storybook/core/theming'; -import type { RenderResult } from '@testing-library/react'; import type { API_IndexHash } from '@storybook/core/types'; + +import type { HashEntry, Refs } from '@storybook/core/manager-api'; + import { Sidebar } from '../Sidebar'; import type { SidebarProps } from '../Sidebar'; diff --git a/code/core/src/manager/components/sidebar/components/CollapseIcon.tsx b/code/core/src/manager/components/sidebar/components/CollapseIcon.tsx index fd3bd67752a4..f4de9e9cd46b 100644 --- a/code/core/src/manager/components/sidebar/components/CollapseIcon.tsx +++ b/code/core/src/manager/components/sidebar/components/CollapseIcon.tsx @@ -1,6 +1,8 @@ -import { styled } from '@storybook/core/theming'; import type { FC } from 'react'; import React from 'react'; + +import { styled } from '@storybook/core/theming'; + import { transparentize } from 'polished'; interface CollapseIconProps { diff --git a/code/core/src/manager/components/sidebar/mockdata.large.ts b/code/core/src/manager/components/sidebar/mockdata.large.ts index b4c2a0b99399..6fb9d233379e 100644 --- a/code/core/src/manager/components/sidebar/mockdata.large.ts +++ b/code/core/src/manager/components/sidebar/mockdata.large.ts @@ -10,7 +10,6 @@ * return acc; * }, {}), null, 2) */ - import type { Dataset } from './types'; // @ts-expect-error (TODO) diff --git a/code/core/src/manager/components/sidebar/types.ts b/code/core/src/manager/components/sidebar/types.ts index b9eac9bf8062..abf0c686b374 100644 --- a/code/core/src/manager/components/sidebar/types.ts +++ b/code/core/src/manager/components/sidebar/types.ts @@ -1,7 +1,9 @@ -import type { StoriesHash, State } from '@storybook/core/manager-api'; -import type { ControllerStateAndHelpers } from 'downshift'; import type { API_StatusState, API_StatusValue } from '@storybook/core/types'; +import type { State, StoriesHash } from '@storybook/core/manager-api'; + +import type { ControllerStateAndHelpers } from 'downshift'; + export type Refs = State['refs']; export type RefType = Refs[keyof Refs] & { status?: API_StatusState }; export type Item = StoriesHash[keyof StoriesHash]; diff --git a/code/core/src/manager/components/sidebar/useExpanded.ts b/code/core/src/manager/components/sidebar/useExpanded.ts index 3af0ed908b8d..dcf49137c968 100644 --- a/code/core/src/manager/components/sidebar/useExpanded.ts +++ b/code/core/src/manager/components/sidebar/useExpanded.ts @@ -1,15 +1,18 @@ +import type { Dispatch, MutableRefObject, Reducer } from 'react'; +import { useCallback, useEffect, useReducer } from 'react'; + +import { global } from '@storybook/global'; + +import { STORIES_COLLAPSE_ALL, STORIES_EXPAND_ALL } from '@storybook/core/core-events'; import type { StoriesHash } from '@storybook/core/manager-api'; import { useStorybookApi } from '@storybook/core/manager-api'; -import { STORIES_COLLAPSE_ALL, STORIES_EXPAND_ALL } from '@storybook/core/core-events'; -import { global } from '@storybook/global'; + import throttle from 'lodash/throttle.js'; -import type { Dispatch, MutableRefObject, Reducer } from 'react'; -import { useCallback, useEffect, useReducer } from 'react'; + import { matchesKeyCode, matchesModifiers } from '../../keybinding'; +import { getAncestorIds, getDescendantIds, isAncestor, scrollIntoView } from '../../utils/tree'; import type { Highlight } from './types'; -import { isAncestor, getAncestorIds, getDescendantIds, scrollIntoView } from '../../utils/tree'; - const { document } = global; export type ExpandedState = Record; diff --git a/code/core/src/manager/components/sidebar/useHighlighted.ts b/code/core/src/manager/components/sidebar/useHighlighted.ts index 5f9df6c2297b..1ca9ed1f6b3c 100644 --- a/code/core/src/manager/components/sidebar/useHighlighted.ts +++ b/code/core/src/manager/components/sidebar/useHighlighted.ts @@ -1,13 +1,14 @@ -import { global } from '@storybook/global'; import type { Dispatch, MutableRefObject, SetStateAction } from 'react'; import { useCallback, useEffect, useRef, useState } from 'react'; -import { useStorybookApi } from '@storybook/core/manager-api'; -import { PRELOAD_ENTRIES } from '@storybook/core/core-events'; -import { matchesKeyCode, matchesModifiers } from '../../keybinding'; -import type { CombinedDataset, Highlight, Selection } from './types'; +import { global } from '@storybook/global'; +import { PRELOAD_ENTRIES } from '@storybook/core/core-events'; +import { useStorybookApi } from '@storybook/core/manager-api'; + +import { matchesKeyCode, matchesModifiers } from '../../keybinding'; import { cycle, isAncestor, scrollIntoView } from '../../utils/tree'; +import type { CombinedDataset, Highlight, Selection } from './types'; const { document, window: globalWindow } = global; diff --git a/code/core/src/manager/components/sidebar/useLastViewed.ts b/code/core/src/manager/components/sidebar/useLastViewed.ts index 1bc8d679883a..0b2f6eddc760 100644 --- a/code/core/src/manager/components/sidebar/useLastViewed.ts +++ b/code/core/src/manager/components/sidebar/useLastViewed.ts @@ -1,5 +1,6 @@ -import debounce from 'lodash/debounce.js'; import { useCallback, useEffect, useMemo, useRef } from 'react'; + +import debounce from 'lodash/debounce.js'; import store from 'store2'; import type { Selection, StoryRef } from './types'; diff --git a/code/core/src/manager/components/upgrade/UpgradeBlock.stories.tsx b/code/core/src/manager/components/upgrade/UpgradeBlock.stories.tsx index 35c180911b2b..1ed8698aad0c 100644 --- a/code/core/src/manager/components/upgrade/UpgradeBlock.stories.tsx +++ b/code/core/src/manager/components/upgrade/UpgradeBlock.stories.tsx @@ -1,8 +1,11 @@ +import React from 'react'; + import type { Meta, StoryObj } from '@storybook/react'; +import { fn } from '@storybook/test'; + import { ManagerContext } from '@storybook/core/manager-api'; -import React from 'react'; + import { UpgradeBlock } from './UpgradeBlock'; -import { fn } from '@storybook/test'; const meta = { component: UpgradeBlock, diff --git a/code/core/src/manager/components/upgrade/UpgradeBlock.tsx b/code/core/src/manager/components/upgrade/UpgradeBlock.tsx index 023dc81ced08..207b9fcef6b1 100644 --- a/code/core/src/manager/components/upgrade/UpgradeBlock.tsx +++ b/code/core/src/manager/components/upgrade/UpgradeBlock.tsx @@ -1,8 +1,11 @@ import type { FC } from 'react'; import React, { useState } from 'react'; + +import { Link } from '@storybook/core/components'; import { styled } from '@storybook/core/theming'; + import { useStorybookApi } from '@storybook/core/manager-api'; -import { Link } from '@storybook/core/components'; + import { MEDIA_DESKTOP_BREAKPOINT } from '../../constants'; interface UpgradeBlockProps { diff --git a/code/core/src/manager/container/Menu.stories.tsx b/code/core/src/manager/container/Menu.stories.tsx index 401a39e7e545..0a2fd0c6b4d8 100644 --- a/code/core/src/manager/container/Menu.stories.tsx +++ b/code/core/src/manager/container/Menu.stories.tsx @@ -1,8 +1,11 @@ import type { FC, MouseEvent, PropsWithChildren, ReactElement } from 'react'; import React, { Children, cloneElement } from 'react'; -import { action } from '@storybook/addon-actions'; -import type { Meta, StoryObj } from '@storybook/react'; + import { TooltipLinkList, WithTooltip } from '@storybook/core/components'; +import type { Meta, StoryObj } from '@storybook/react'; + +import { action } from '@storybook/addon-actions'; + import { Shortcut } from './Menu'; const onLinkClick = action('onLinkClick'); diff --git a/code/core/src/manager/container/Menu.tsx b/code/core/src/manager/container/Menu.tsx index ce1cce434226..b2b92ef17ad1 100644 --- a/code/core/src/manager/container/Menu.tsx +++ b/code/core/src/manager/container/Menu.tsx @@ -2,11 +2,12 @@ import type { FC } from 'react'; import React, { useCallback, useMemo } from 'react'; import { Badge } from '@storybook/core/components'; -import type { API, State } from '@storybook/core/manager-api'; -import { shortcutToHumanString } from '@storybook/core/manager-api'; import { styled, useTheme } from '@storybook/core/theming'; import { CheckIcon, InfoIcon, ShareAltIcon, WandIcon } from '@storybook/icons'; + import { STORIES_COLLAPSE_ALL } from '@storybook/core/core-events'; +import type { API, State } from '@storybook/core/manager-api'; +import { shortcutToHumanString } from '@storybook/core/manager-api'; const focusableUIElements = { storySearchField: 'storybook-explorer-searchfield', diff --git a/code/core/src/manager/container/Panel.tsx b/code/core/src/manager/container/Panel.tsx index c8accbb6c4e2..c81e489d8f68 100644 --- a/code/core/src/manager/container/Panel.tsx +++ b/code/core/src/manager/container/Panel.tsx @@ -1,9 +1,12 @@ import type { FC } from 'react'; import React from 'react'; -import memoize from 'memoizerific'; + +import { Addon_TypesEnum } from '@storybook/core/types'; + import { Consumer } from '@storybook/core/manager-api'; import type { API, Combo } from '@storybook/core/manager-api'; -import { Addon_TypesEnum } from '@storybook/core/types'; + +import memoize from 'memoizerific'; import { AddonPanel } from '../components/panel/Panel'; diff --git a/code/core/src/manager/container/Preview.tsx b/code/core/src/manager/container/Preview.tsx index 9d824b408cc9..fabda783bf64 100644 --- a/code/core/src/manager/container/Preview.tsx +++ b/code/core/src/manager/container/Preview.tsx @@ -1,24 +1,25 @@ -import { global } from '@storybook/global'; -import type { Addon_BaseType, Addon_Collection, Addon_WrapperType } from '@storybook/core/types'; -import { Addon_TypesEnum } from '@storybook/core/types'; import type { ComponentProps } from 'react'; import React from 'react'; -import memoizerific from 'memoizerific'; +import type { Addon_BaseType, Addon_Collection, Addon_WrapperType } from '@storybook/core/types'; +import { Addon_TypesEnum } from '@storybook/core/types'; +import { global } from '@storybook/global'; import type { State, StoriesHash } from '@storybook/core/manager-api'; import { Consumer } from '@storybook/core/manager-api'; +import memoizerific from 'memoizerific'; + import { Preview, createCanvasTab, filterTabs } from '../components/preview/Preview'; -import { defaultWrappers } from '../components/preview/Wrappers'; import { filterToolsSide, fullScreenTool } from '../components/preview/Toolbar'; +import { defaultWrappers } from '../components/preview/Wrappers'; +import { addonsTool } from '../components/preview/tools/addons'; +import { copyTool } from '../components/preview/tools/copy'; +import { ejectTool } from '../components/preview/tools/eject'; import { menuTool } from '../components/preview/tools/menu'; import { remountTool } from '../components/preview/tools/remount'; import { zoomTool } from '../components/preview/tools/zoom'; import type { PreviewProps } from '../components/preview/utils/types'; -import { addonsTool } from '../components/preview/tools/addons'; -import { copyTool } from '../components/preview/tools/copy'; -import { ejectTool } from '../components/preview/tools/eject'; const defaultTabs = [createCanvasTab()]; const defaultTools = [menuTool, remountTool, zoomTool]; diff --git a/code/core/src/manager/container/Sidebar.tsx b/code/core/src/manager/container/Sidebar.tsx index 058361de9afb..61f0ff57c76d 100755 --- a/code/core/src/manager/container/Sidebar.tsx +++ b/code/core/src/manager/container/Sidebar.tsx @@ -1,8 +1,9 @@ import React, { useMemo } from 'react'; +import { Addon_TypesEnum } from '@storybook/core/types'; + import type { Combo, StoriesHash } from '@storybook/core/manager-api'; import { Consumer } from '@storybook/core/manager-api'; -import { Addon_TypesEnum } from '@storybook/core/types'; import type { SidebarProps as SidebarComponentProps } from '../components/sidebar/Sidebar'; import { Sidebar as SidebarComponent } from '../components/sidebar/Sidebar'; diff --git a/code/core/src/manager/globals-runtime.ts b/code/core/src/manager/globals-runtime.ts index 011cb0f60fdf..7e4c07eccb28 100644 --- a/code/core/src/manager/globals-runtime.ts +++ b/code/core/src/manager/globals-runtime.ts @@ -2,8 +2,8 @@ import { global } from '@storybook/global'; import { TELEMETRY_ERROR } from '@storybook/core/core-events'; -import { globalsNameValueMap } from './globals/runtime'; import { globalPackages, globalsNameReferenceMap } from './globals/globals'; +import { globalsNameValueMap } from './globals/runtime'; import { prepareForTelemetry, shouldSkipError } from './utils/prepareForTelemetry'; // Apply all the globals @@ -20,12 +20,10 @@ global.sendTelemetryError = (error) => { // handle all uncaught errors at the root of the application and log to telemetry global.addEventListener('error', (args) => { - // @ts-expect-error (not Event) const error = args.error || args; global.sendTelemetryError(error); }); -// @ts-expect-error (not Event) global.addEventListener('unhandledrejection', ({ reason }) => { global.sendTelemetryError(reason); }); diff --git a/code/core/src/manager/globals/globals-module-info.ts b/code/core/src/manager/globals/globals-module-info.ts index 193ee13d615f..ff5e8f0b9ecb 100644 --- a/code/core/src/manager/globals/globals-module-info.ts +++ b/code/core/src/manager/globals/globals-module-info.ts @@ -1,4 +1,5 @@ import type { ModuleInfo } from '@fal-works/esbuild-plugin-global-externals'; + import Exports from './exports'; import { globalPackages, globalsNameReferenceMap } from './globals'; diff --git a/code/core/src/manager/globals/runtime.ts b/code/core/src/manager/globals/runtime.ts index fcca6ea55a5c..a52501db52cc 100644 --- a/code/core/src/manager/globals/runtime.ts +++ b/code/core/src/manager/globals/runtime.ts @@ -2,18 +2,18 @@ import * as REACT from 'react'; import * as REACT_DOM from 'react-dom'; import * as REACT_DOM_CLIENT from 'react-dom/client'; -import * as COMPONENTS from '@storybook/core/components'; -import * as ICONS from '@storybook/icons'; -import * as MANAGER_API from '@storybook/core/manager-api'; - import * as CHANNELS from '@storybook/core/channels'; -import * as EVENTS from '@storybook/core/core-events'; -import * as EVENTS_MANAGER_ERRORS from '@storybook/core/manager-errors'; +import * as COMPONENTS from '@storybook/core/components'; import * as ROUTER from '@storybook/core/router'; import * as THEMING from '@storybook/core/theming'; import * as THEMINGCREATE from '@storybook/core/theming/create'; import * as TYPES from '@storybook/core/types'; +import * as ICONS from '@storybook/icons'; + import * as CLIENT_LOGGER from '@storybook/core/client-logger'; +import * as EVENTS from '@storybook/core/core-events'; +import * as MANAGER_API from '@storybook/core/manager-api'; +import * as EVENTS_MANAGER_ERRORS from '@storybook/core/manager-errors'; import type { globalsNameReferenceMap } from './globals'; diff --git a/code/core/src/manager/index.tsx b/code/core/src/manager/index.tsx index 4d01da8e8253..0880749eb3e9 100644 --- a/code/core/src/manager/index.tsx +++ b/code/core/src/manager/index.tsx @@ -1,23 +1,23 @@ -import { global } from '@storybook/global'; import type { ComponentProps, FC } from 'react'; -import { createRoot } from 'react-dom/client'; import React, { useCallback, useMemo } from 'react'; +import { createRoot } from 'react-dom/client'; import { Location, LocationProvider, useNavigate } from '@storybook/core/router'; +import { ThemeProvider, ensure as ensureTheme } from '@storybook/core/theming'; +import type { Addon_PageType } from '@storybook/core/types'; +import { global } from '@storybook/global'; + import { Provider as ManagerProvider, types } from '@storybook/core/manager-api'; import type { Combo } from '@storybook/core/manager-api'; -import { ThemeProvider, ensure as ensureTheme } from '@storybook/core/theming'; import { ProviderDoesNotExtendBaseProviderError } from '@storybook/core/manager-errors'; import { HelmetProvider } from 'react-helmet-async'; -import type { Addon_PageType } from '@storybook/core/types'; import { App } from './App'; - +import type { Layout } from './components/layout/Layout'; +import { LayoutProvider } from './components/layout/LayoutProvider'; import Provider from './provider'; import { settingsPageAddon } from './settings/index'; -import { LayoutProvider } from './components/layout/LayoutProvider'; -import type { Layout } from './components/layout/Layout'; // @ts-expect-error (Converted from ts-ignore) ThemeProvider.displayName = 'ThemeProvider'; diff --git a/code/core/src/manager/runtime.ts b/code/core/src/manager/runtime.ts index f73515f425d8..2ae3fede77ca 100644 --- a/code/core/src/manager/runtime.ts +++ b/code/core/src/manager/runtime.ts @@ -1,13 +1,14 @@ +import type { Channel } from '@storybook/core/channels'; +import { createBrowserChannel } from '@storybook/core/channels'; +import type { Addon_Config, Addon_Types } from '@storybook/core/types'; import { global } from '@storybook/global'; -import type { Channel } from '@storybook/core/channels'; +import { CHANNEL_CREATED } from '@storybook/core/core-events'; import type { AddonStore } from '@storybook/core/manager-api'; import { addons } from '@storybook/core/manager-api'; -import type { Addon_Types, Addon_Config } from '@storybook/core/types'; -import { createBrowserChannel } from '@storybook/core/channels'; -import { CHANNEL_CREATED } from '@storybook/core/core-events'; -import Provider from './provider'; + import { renderStorybookUI } from './index'; +import Provider from './provider'; class ReactProvider extends Provider { addons: AddonStore; diff --git a/code/core/src/manager/settings/About.tsx b/code/core/src/manager/settings/About.tsx index d6b3aae8aa68..4f9001fb7c3f 100644 --- a/code/core/src/manager/settings/About.tsx +++ b/code/core/src/manager/settings/About.tsx @@ -1,9 +1,10 @@ import type { FC } from 'react'; import React from 'react'; -import { styled } from '@storybook/core/theming'; import { Button, Link, StorybookLogo } from '@storybook/core/components'; +import { styled } from '@storybook/core/theming'; import { DocumentIcon, GithubIcon } from '@storybook/icons'; + import { UpgradeBlock } from '../components/upgrade/UpgradeBlock'; const Container = styled.div({ diff --git a/code/core/src/manager/settings/SettingsFooter.stories.tsx b/code/core/src/manager/settings/SettingsFooter.stories.tsx index 5bd0bb8f3b82..fb138e96b689 100644 --- a/code/core/src/manager/settings/SettingsFooter.stories.tsx +++ b/code/core/src/manager/settings/SettingsFooter.stories.tsx @@ -1,6 +1,7 @@ import React from 'react'; import type { Decorator } from '@storybook/react'; + import SettingsFooter from './SettingsFooter'; export default { diff --git a/code/core/src/manager/settings/SettingsFooter.tsx b/code/core/src/manager/settings/SettingsFooter.tsx index 8bc273f8e95c..308e9e2dd2fe 100644 --- a/code/core/src/manager/settings/SettingsFooter.tsx +++ b/code/core/src/manager/settings/SettingsFooter.tsx @@ -1,8 +1,8 @@ import type { FC } from 'react'; import React from 'react'; -import { styled } from '@storybook/core/theming'; import { Link } from '@storybook/core/components'; +import { styled } from '@storybook/core/theming'; const Footer = styled.div(({ theme }) => ({ display: 'flex', diff --git a/code/core/src/manager/settings/about.stories.tsx b/code/core/src/manager/settings/about.stories.tsx index 45891544227b..d63d246d447a 100644 --- a/code/core/src/manager/settings/about.stories.tsx +++ b/code/core/src/manager/settings/about.stories.tsx @@ -1,9 +1,11 @@ -import type { Meta, StoryObj } from '@storybook/react'; import React from 'react'; -import { AboutScreen } from './About'; -import UpgradeBlockStoriesMeta from '../components/upgrade/UpgradeBlock.stories'; + +import type { Meta, StoryObj } from '@storybook/react'; import { fn } from '@storybook/test'; +import UpgradeBlockStoriesMeta from '../components/upgrade/UpgradeBlock.stories'; +import { AboutScreen } from './About'; + const meta = { component: AboutScreen, title: 'Settings/AboutScreen', diff --git a/code/core/src/manager/settings/index.tsx b/code/core/src/manager/settings/index.tsx index 0bd3c661f602..5ae202f65ea2 100644 --- a/code/core/src/manager/settings/index.tsx +++ b/code/core/src/manager/settings/index.tsx @@ -1,17 +1,19 @@ -import { useStorybookApi, useStorybookState, types } from '@storybook/core/manager-api'; -import { IconButton, TabBar, TabButton, ScrollArea } from '@storybook/core/components'; -import { Location, Route } from '@storybook/core/router'; -import { styled } from '@storybook/core/theming'; -import { global } from '@storybook/global'; import type { FC, SyntheticEvent } from 'react'; import React, { Fragment } from 'react'; +import { IconButton, ScrollArea, TabBar, TabButton } from '@storybook/core/components'; +import { Location, Route } from '@storybook/core/router'; +import { styled } from '@storybook/core/theming'; import type { Addon_PageType } from '@storybook/core/types'; +import { global } from '@storybook/global'; import { CloseIcon } from '@storybook/icons'; + +import { types, useStorybookApi, useStorybookState } from '@storybook/core/manager-api'; + +import { matchesKeyCode, matchesModifiers } from '../keybinding'; import { AboutPage } from './AboutPage'; import { ShortcutsPage } from './ShortcutsPage'; import { WhatsNewPage } from './whats_new_page'; -import { matchesModifiers, matchesKeyCode } from '../keybinding'; const { document } = global; diff --git a/code/core/src/manager/settings/shortcuts.stories.tsx b/code/core/src/manager/settings/shortcuts.stories.tsx index 555f5b6b0b6a..67f3b97a149d 100644 --- a/code/core/src/manager/settings/shortcuts.stories.tsx +++ b/code/core/src/manager/settings/shortcuts.stories.tsx @@ -1,9 +1,11 @@ import React from 'react'; -import { actions as makeActions } from '@storybook/addon-actions'; import type { Decorator } from '@storybook/react'; -import { ShortcutsScreen } from './shortcuts'; + +import { actions as makeActions } from '@storybook/addon-actions'; + import { defaultShortcuts } from './defaultShortcuts'; +import { ShortcutsScreen } from './shortcuts'; const actions = makeActions( 'setShortcut', diff --git a/code/core/src/manager/settings/shortcuts.tsx b/code/core/src/manager/settings/shortcuts.tsx index 74d716faf4ab..93a768774d18 100644 --- a/code/core/src/manager/settings/shortcuts.tsx +++ b/code/core/src/manager/settings/shortcuts.tsx @@ -1,15 +1,17 @@ import type { ComponentProps, FC } from 'react'; import React, { Component } from 'react'; -import { styled, keyframes } from '@storybook/core/theming'; + +import { Button, Form } from '@storybook/core/components'; +import { keyframes, styled } from '@storybook/core/theming'; +import { CheckIcon } from '@storybook/icons'; import { eventToShortcut, - shortcutToHumanString, shortcutMatchesShortcut, + shortcutToHumanString, } from '@storybook/core/manager-api'; -import { Button, Form } from '@storybook/core/components'; + import SettingsFooter from './SettingsFooter'; -import { CheckIcon } from '@storybook/icons'; const Header = styled.header(({ theme }) => ({ marginBottom: 20, @@ -58,7 +60,7 @@ export const Description = styled.div({ export type ValidationStates = 'valid' | 'error' | 'warn'; // eslint-disable-next-line @typescript-eslint/ban-ts-comment -// @ts-ignore-error (this errors only when compiling for production mode) +// @ts-ignore-error (this only errors during compilation for production) export const TextInput: FC & { valid: ValidationStates }> = styled(Form.Input)<{ valid: ValidationStates }>( ({ valid, theme }) => diff --git a/code/core/src/manager/settings/whats_new.tsx b/code/core/src/manager/settings/whats_new.tsx index cbf00ce7817c..aa483334e0ce 100644 --- a/code/core/src/manager/settings/whats_new.tsx +++ b/code/core/src/manager/settings/whats_new.tsx @@ -1,10 +1,12 @@ import type { ComponentProps, FC } from 'react'; import React, { Fragment, useEffect, useState } from 'react'; -import { styled, useTheme } from '@storybook/core/theming'; + import { Button, Loader } from '@storybook/core/components'; -import { useStorybookApi, useStorybookState } from '@storybook/core/manager-api'; +import { styled, useTheme } from '@storybook/core/theming'; import { global } from '@storybook/global'; -import { EyeCloseIcon, EyeIcon, HeartIcon, AlertIcon as AlertIconSvg } from '@storybook/icons'; +import { AlertIcon as AlertIconSvg, EyeCloseIcon, EyeIcon, HeartIcon } from '@storybook/icons'; + +import { useStorybookApi, useStorybookState } from '@storybook/core/manager-api'; const Centered = styled.div({ top: '50%', diff --git a/code/core/src/manager/settings/whats_new_footer.stories.tsx b/code/core/src/manager/settings/whats_new_footer.stories.tsx index 8815eb0ec1c2..9e0a88c04562 100644 --- a/code/core/src/manager/settings/whats_new_footer.stories.tsx +++ b/code/core/src/manager/settings/whats_new_footer.stories.tsx @@ -1,4 +1,5 @@ import type { Meta, StoryObj } from '@storybook/react'; + import { WhatsNewFooter } from './whats_new'; const meta = { diff --git a/code/core/src/manager/utils/prepareForTelemetry.ts b/code/core/src/manager/utils/prepareForTelemetry.ts index 959251c9260d..ccbb8bf236ba 100644 --- a/code/core/src/manager/utils/prepareForTelemetry.ts +++ b/code/core/src/manager/utils/prepareForTelemetry.ts @@ -1,6 +1,8 @@ /* eslint-disable local-rules/no-uncategorized-errors */ -import { UncaughtManagerError } from '@storybook/core/manager-errors'; import { global } from '@storybook/global'; + +import { UncaughtManagerError } from '@storybook/core/manager-errors'; + import type { BrowserInfo } from 'browser-dtector'; import BrowserDetector from 'browser-dtector'; diff --git a/code/core/src/manager/utils/status.test.ts b/code/core/src/manager/utils/status.test.ts index c45b14063db1..5bedc3571e8c 100644 --- a/code/core/src/manager/utils/status.test.ts +++ b/code/core/src/manager/utils/status.test.ts @@ -1,8 +1,8 @@ // @vitest-environment happy-dom +import { describe, expect, it } from 'vitest'; -import { describe, it, expect } from 'vitest'; -import { getHighestStatus, getGroupStatus } from './status'; import { mockDataset } from '../components/sidebar/mockdata'; +import { getGroupStatus, getHighestStatus } from './status'; describe('getHighestStatus', () => { it('default value', () => { diff --git a/code/core/src/manager/utils/status.tsx b/code/core/src/manager/utils/status.tsx index 05092844bdc3..3474ba64b393 100644 --- a/code/core/src/manager/utils/status.tsx +++ b/code/core/src/manager/utils/status.tsx @@ -1,11 +1,11 @@ import React from 'react'; import type { ReactElement } from 'react'; -import type { API_HashEntry, API_StatusState, API_StatusValue } from '@storybook/core/types'; import { styled } from '@storybook/core/theming'; +import type { API_HashEntry, API_StatusState, API_StatusValue } from '@storybook/core/types'; +import { CircleIcon } from '@storybook/icons'; import { getDescendantIds } from './tree'; -import { CircleIcon } from '@storybook/icons'; const SmallIcons = styled(CircleIcon)({ // specificity hack diff --git a/code/core/src/manager/utils/tree.test.js b/code/core/src/manager/utils/tree.test.js index 57761f7c18a1..061e7dbc8e26 100644 --- a/code/core/src/manager/utils/tree.test.js +++ b/code/core/src/manager/utils/tree.test.js @@ -1,8 +1,7 @@ // @vitest-environment happy-dom +import { describe, expect, it } from 'vitest'; -import { describe, it, expect } from 'vitest'; import { mockDataset, mockExpanded, mockSelected } from '../components/sidebar/mockdata'; - import * as utils from './tree'; const noRoot = { diff --git a/code/core/src/manager/utils/tree.ts b/code/core/src/manager/utils/tree.ts index 8b6190bd3e8b..cb0bd8cb67ce 100644 --- a/code/core/src/manager/utils/tree.ts +++ b/code/core/src/manager/utils/tree.ts @@ -1,10 +1,13 @@ -import memoize from 'memoizerific'; -import { global } from '@storybook/global'; import type { SyntheticEvent } from 'react'; + +import { global } from '@storybook/global'; + import type { HashEntry, IndexHash } from '@storybook/core/manager-api'; +import memoize from 'memoizerific'; + import { DEFAULT_REF_ID } from '../components/sidebar/Sidebar'; -import type { Item, RefType, Dataset, SearchItem } from '../components/sidebar/types'; +import type { Dataset, Item, RefType, SearchItem } from '../components/sidebar/types'; const { document, window: globalWindow } = global; diff --git a/code/core/src/node-logger/index.test.ts b/code/core/src/node-logger/index.test.ts index 50cce3a88b71..c7948363545e 100644 --- a/code/core/src/node-logger/index.test.ts +++ b/code/core/src/node-logger/index.test.ts @@ -1,5 +1,7 @@ -import { describe, it, expect, vi } from 'vitest'; +import { describe, expect, it, vi } from 'vitest'; + import npmlog from 'npmlog'; + import { logger } from '.'; globalThis.console = { log: vi.fn() } as any; diff --git a/code/core/src/node-logger/index.ts b/code/core/src/node-logger/index.ts index 61234e4b8fcd..38df1d3df5d2 100644 --- a/code/core/src/node-logger/index.ts +++ b/code/core/src/node-logger/index.ts @@ -1,8 +1,7 @@ /// - +import chalk from 'chalk'; import npmLog from 'npmlog'; import prettyTime from 'pretty-hrtime'; -import chalk from 'chalk'; // The default is stderr, which can cause some tools (like rush.js) to think // there are issues with the build: https://github.com/storybookjs/storybook/issues/14621 diff --git a/code/core/src/preview-api/Errors.stories.tsx b/code/core/src/preview-api/Errors.stories.tsx index 231905e9bca5..2782999de392 100644 --- a/code/core/src/preview-api/Errors.stories.tsx +++ b/code/core/src/preview-api/Errors.stories.tsx @@ -1,4 +1,5 @@ import React from 'react'; + import AnsiToHtml from 'ansi-to-html'; import { dedent } from 'ts-dedent'; diff --git a/code/core/src/preview-api/README-store.md b/code/core/src/preview-api/README-store.md index 8e261bf30e65..cea82a905649 100644 --- a/code/core/src/preview-api/README-store.md +++ b/code/core/src/preview-api/README-store.md @@ -78,7 +78,9 @@ Note that arg values are passed directly to a story -- you should only store the Both `@storybook/preview-api` and `@storybook/manager-api` export a `useArgs()` hook that you can use to access args in decorators or addon panels. The API is as follows: ```js -import { useArgs } from '@storybook/preview-api'; // or '@storybook/manager-api' +import { useArgs } from '@storybook/preview-api'; + +// or '@storybook/manager-api' // `args` is the args of the currently rendered story // `updateArgs` will update its args. You can pass a subset of the args; other args will not be changed. @@ -110,7 +112,9 @@ To set initial values of globals, `export const globals = {...}` from `preview.j Similar to args, globals are synchronized to the manager and can be accessed via the `useGlobals` hook. ```js -import { useGlobals } from '@storybook/preview-api'; // or '@storybook/manager-api' +import { useGlobals } from '@storybook/preview-api'; + +// or '@storybook/manager-api' const [globals, updateGlobals] = useGlobals(); ``` diff --git a/code/core/src/preview-api/modules/addons/hooks.test.js b/code/core/src/preview-api/modules/addons/hooks.test.js index 2fc21ff88b85..2e716d8b10b1 100644 --- a/code/core/src/preview-api/modules/addons/hooks.test.js +++ b/code/core/src/preview-api/modules/addons/hooks.test.js @@ -1,4 +1,5 @@ -import { describe, beforeEach, afterEach, expect, it } from 'vitest'; +import { afterEach, beforeEach, describe, expect, it } from 'vitest'; + import { useParameter, useStoryContext } from './hooks'; describe('addons/hooks', () => { diff --git a/code/core/src/preview-api/modules/addons/hooks.ts b/code/core/src/preview-api/modules/addons/hooks.ts index 0c80bdd07dc9..b956f45e9dce 100644 --- a/code/core/src/preview-api/modules/addons/hooks.ts +++ b/code/core/src/preview-api/modules/addons/hooks.ts @@ -1,13 +1,3 @@ -import { global } from '@storybook/global'; -import { logger } from '@storybook/core/client-logger'; -import { - FORCE_RE_RENDER, - STORY_RENDERED, - UPDATE_STORY_ARGS, - RESET_STORY_ARGS, - UPDATE_GLOBALS, -} from '@storybook/core/core-events'; -import { addons } from './main'; import type { Args, DecoratorApplicator, @@ -17,6 +7,18 @@ import type { StoryContext, StoryId, } from '@storybook/core/types'; +import { global } from '@storybook/global'; + +import { logger } from '@storybook/core/client-logger'; +import { + FORCE_RE_RENDER, + RESET_STORY_ARGS, + STORY_RENDERED, + UPDATE_GLOBALS, + UPDATE_STORY_ARGS, +} from '@storybook/core/core-events'; + +import { addons } from './main'; interface Hook { name: string; diff --git a/code/core/src/preview-api/modules/addons/main.ts b/code/core/src/preview-api/modules/addons/main.ts index bd4061b618ae..f2012bab9f07 100644 --- a/code/core/src/preview-api/modules/addons/main.ts +++ b/code/core/src/preview-api/modules/addons/main.ts @@ -1,6 +1,6 @@ +import type { Channel } from '@storybook/core/channels'; import { global } from '@storybook/global'; -import type { Channel } from '@storybook/core/channels'; import { mockChannel } from './storybook-channel-mock'; export class AddonStore { diff --git a/code/core/src/preview-api/modules/addons/make-decorator.test.ts b/code/core/src/preview-api/modules/addons/make-decorator.test.ts index 316a5dc9d1a9..d926c9f5da81 100644 --- a/code/core/src/preview-api/modules/addons/make-decorator.test.ts +++ b/code/core/src/preview-api/modules/addons/make-decorator.test.ts @@ -1,5 +1,7 @@ -import { describe, it, expect, vi } from 'vitest'; +import { describe, expect, it, vi } from 'vitest'; + import type { Addon_StoryContext } from '@storybook/core/types'; + import { makeDecorator } from './make-decorator'; // Copy & paste from internal api: client-api/src/client_api diff --git a/code/core/src/preview-api/modules/preview-web/Preview.tsx b/code/core/src/preview-api/modules/preview-web/Preview.tsx index 681d0c47c935..8f03cad2b04e 100644 --- a/code/core/src/preview-api/modules/preview-web/Preview.tsx +++ b/code/core/src/preview-api/modules/preview-web/Preview.tsx @@ -1,4 +1,22 @@ +import type { Channel } from '@storybook/core/channels'; +import type { + Args, + Globals, + GlobalsUpdatedPayload, + ModuleImportFn, + PreparedStory, + ProjectAnnotations, + RenderContextCallbacks, + RenderToCanvas, + Renderer, + SetGlobalsPayload, + StoryId, + StoryIndex, + StoryRenderOptions, +} from '@storybook/core/types'; +import type { CleanupCallback } from '@storybook/csf'; import { global } from '@storybook/global'; + import { deprecate, logger } from '@storybook/core/client-logger'; import type { ArgTypesRequestPayload, @@ -20,35 +38,18 @@ import { UPDATE_GLOBALS, UPDATE_STORY_ARGS, } from '@storybook/core/core-events'; -import type { CleanupCallback } from '@storybook/csf'; -import type { Channel } from '@storybook/core/channels'; -import type { - Renderer, - Args, - Globals, - ModuleImportFn, - RenderContextCallbacks, - RenderToCanvas, - PreparedStory, - StoryIndex, - ProjectAnnotations, - StoryId, - StoryRenderOptions, - SetGlobalsPayload, - GlobalsUpdatedPayload, -} from '@storybook/core/types'; import { CalledPreviewMethodBeforeInitializationError, MissingRenderToCanvasError, StoryIndexFetchError, StoryStoreAccessedBeforeInitializationError, } from '@storybook/core/preview-errors'; -import { addons } from '../addons'; -import { StoryStore } from '../../store'; -import { StoryRender } from './render/StoryRender'; +import { StoryStore } from '../../store'; +import { addons } from '../addons'; import type { CsfDocsRender } from './render/CsfDocsRender'; import type { MdxDocsRender } from './render/MdxDocsRender'; +import { StoryRender } from './render/StoryRender'; const { fetch } = global; diff --git a/code/core/src/preview-api/modules/preview-web/PreviewWeb.integration.test.ts b/code/core/src/preview-api/modules/preview-web/PreviewWeb.integration.test.ts index d4818c162a3f..6c86c2d86385 100644 --- a/code/core/src/preview-api/modules/preview-web/PreviewWeb.integration.test.ts +++ b/code/core/src/preview-api/modules/preview-web/PreviewWeb.integration.test.ts @@ -1,23 +1,24 @@ // @vitest-environment happy-dom -import { describe, beforeEach, it, expect, vi } from 'vitest'; +import { beforeEach, describe, expect, it, vi } from 'vitest'; import React from 'react'; -import { global } from '@storybook/global'; + import type { RenderContext } from '@storybook/core/types'; -import { addons } from '../addons'; +import { global } from '@storybook/global'; +import { addons } from '../addons'; import { PreviewWeb } from './PreviewWeb'; -import { WebView } from './WebView'; import { componentOneExports, - importFn, - projectAnnotations, - getProjectAnnotations, emitter, + getProjectAnnotations, + importFn, mockChannel, - waitForRender, storyIndex as mockStoryIndex, + projectAnnotations, + waitForRender, } from './PreviewWeb.mockdata'; +import { WebView } from './WebView'; // PreviewWeb.test mocks out all rendering // - ie. from`renderToCanvas()` (stories) or`ReactDOM.render()` (docs) in. diff --git a/code/core/src/preview-api/modules/preview-web/PreviewWeb.mockdata.ts b/code/core/src/preview-api/modules/preview-web/PreviewWeb.mockdata.ts index fb92f48a7646..30abd5df7d15 100644 --- a/code/core/src/preview-api/modules/preview-web/PreviewWeb.mockdata.ts +++ b/code/core/src/preview-api/modules/preview-web/PreviewWeb.mockdata.ts @@ -1,7 +1,14 @@ import type { Mock, Mocked } from 'vitest'; import { vi } from 'vitest'; -import { EventEmitter } from 'events'; +import type { + ModuleImportFn, + ProjectAnnotations, + Renderer, + StoryIndex, + TeardownRenderToCanvas, +} from '@storybook/core/types'; + import { DOCS_RENDERED, STORY_ERRORED, @@ -11,15 +18,10 @@ import { STORY_THREW_EXCEPTION, } from '@storybook/core/core-events'; -import type { - ModuleImportFn, - ProjectAnnotations, - Renderer, - StoryIndex, - TeardownRenderToCanvas, -} from '@storybook/core/types'; -import type { RenderPhase } from './render/StoryRender'; +import { EventEmitter } from 'events'; + import { composeConfigs } from '../store'; +import type { RenderPhase } from './render/StoryRender'; export const componentOneExports = { default: { @@ -71,7 +73,7 @@ export const docsRenderer = { render: vi.fn().mockImplementation((context, parameters, element) => Promise.resolve()), unmount: vi.fn(), }; -export const teardownrenderToCanvas: Mock<[TeardownRenderToCanvas]> = vi.fn(); +export const teardownrenderToCanvas: Mock<(teardown: TeardownRenderToCanvas) => void> = vi.fn(); const rawProjectAnnotations = { initialGlobals: { a: 'b' }, globalTypes: {}, diff --git a/code/core/src/preview-api/modules/preview-web/PreviewWeb.test.ts b/code/core/src/preview-api/modules/preview-web/PreviewWeb.test.ts index ae11cb3f7221..7994173c2d07 100644 --- a/code/core/src/preview-api/modules/preview-web/PreviewWeb.test.ts +++ b/code/core/src/preview-api/modules/preview-web/PreviewWeb.test.ts @@ -1,15 +1,19 @@ // @vitest-environment happy-dom -import { describe, beforeEach, afterEach, it, expect, vi } from 'vitest'; +import { afterEach, beforeEach, describe, expect, it, vi } from 'vitest'; +import type { ModuleImportFn, ProjectAnnotations, Renderer } from '@storybook/core/types'; import { global } from '@storybook/global'; -import merge from 'lodash/merge.js'; + +import { logger } from '@storybook/core/client-logger'; import { CONFIG_ERROR, CURRENT_STORY_WAS_SET, + DOCS_PREPARED, DOCS_RENDERED, FORCE_REMOUNT, FORCE_RE_RENDER, GLOBALS_UPDATED, + PLAY_FUNCTION_THREW_EXCEPTION, PREVIEW_KEYDOWN, RESET_STORY_ARGS, SET_CURRENT_STORY, @@ -22,36 +26,34 @@ import { STORY_RENDERED, STORY_SPECIFIED, STORY_THREW_EXCEPTION, - PLAY_FUNCTION_THREW_EXCEPTION, STORY_UNCHANGED, UPDATE_GLOBALS, UPDATE_STORY_ARGS, - DOCS_PREPARED, } from '@storybook/core/core-events'; -import { logger } from '@storybook/core/client-logger'; -import type { Renderer, ModuleImportFn, ProjectAnnotations } from '@storybook/core/types'; -import { addons } from '../addons'; +import merge from 'lodash/merge.js'; + +import { addons } from '../addons'; +import type { StoryStore } from '../store'; import { PreviewWeb } from './PreviewWeb'; import { componentOneExports, componentTwoExports, + docsRenderer, + emitter, + getProjectAnnotations, importFn, + mockChannel, projectAnnotations, - getProjectAnnotations, storyIndex, - emitter, - mockChannel, + teardownrenderToCanvas, + unattachedDocsExports, waitForEvents, - waitForRender, waitForQuiescence, + waitForRender, waitForRenderPhase, - docsRenderer, - unattachedDocsExports, - teardownrenderToCanvas, } from './PreviewWeb.mockdata'; import { WebView } from './WebView'; -import type { StoryStore } from '../store'; const { history, document } = global; diff --git a/code/core/src/preview-api/modules/preview-web/PreviewWeb.tsx b/code/core/src/preview-api/modules/preview-web/PreviewWeb.tsx index 0ee61fac402a..cb2931350b91 100644 --- a/code/core/src/preview-api/modules/preview-web/PreviewWeb.tsx +++ b/code/core/src/preview-api/modules/preview-web/PreviewWeb.tsx @@ -1,12 +1,12 @@ /* eslint-disable no-underscore-dangle */ +import type { Renderer } from '@storybook/core/types'; +import type { ModuleImportFn, ProjectAnnotations } from '@storybook/core/types'; import { global } from '@storybook/global'; +import type { MaybePromise } from './Preview'; import { PreviewWithSelection } from './PreviewWithSelection'; import { UrlStore } from './UrlStore'; import { WebView } from './WebView'; -import type { MaybePromise } from './Preview'; -import type { Renderer } from '@storybook/core/types'; -import type { ModuleImportFn, ProjectAnnotations } from '@storybook/core/types'; export class PreviewWeb extends PreviewWithSelection { constructor( diff --git a/code/core/src/preview-api/modules/preview-web/PreviewWithSelection.tsx b/code/core/src/preview-api/modules/preview-web/PreviewWithSelection.tsx index 9bed42b07ea6..711e3ac0f187 100644 --- a/code/core/src/preview-api/modules/preview-web/PreviewWithSelection.tsx +++ b/code/core/src/preview-api/modules/preview-web/PreviewWithSelection.tsx @@ -1,4 +1,8 @@ -import invariant from 'tiny-invariant'; +import type { DocsIndexEntry, StoryIndex } from '@storybook/core/types'; +import type { Args, Globals, Renderer, StoryId, ViewMode } from '@storybook/core/types'; +import type { ModuleImportFn, ProjectAnnotations } from '@storybook/core/types'; + +import { logger } from '@storybook/core/client-logger'; import { CURRENT_STORY_WAS_SET, DOCS_PREPARED, @@ -16,27 +20,24 @@ import { STORY_UNCHANGED, UPDATE_QUERY_PARAMS, } from '@storybook/core/core-events'; -import { logger } from '@storybook/core/client-logger'; - import { CalledPreviewMethodBeforeInitializationError, EmptyIndexError, MdxFileWithNoCsfReferencesError, NoStoryMatchError, } from '@storybook/core/preview-errors'; + +import invariant from 'tiny-invariant'; + +import type { StorySpecifier } from '../store/StoryIndexStore'; import type { MaybePromise } from './Preview'; import { Preview } from './Preview'; - -import { PREPARE_ABORTED } from './render/Render'; -import { StoryRender } from './render/StoryRender'; -import { CsfDocsRender } from './render/CsfDocsRender'; -import { MdxDocsRender } from './render/MdxDocsRender'; import type { Selection, SelectionStore } from './SelectionStore'; import type { View } from './View'; -import type { StorySpecifier } from '../store/StoryIndexStore'; -import type { DocsIndexEntry, StoryIndex } from '@storybook/core/types'; -import type { Args, Globals, Renderer, StoryId, ViewMode } from '@storybook/core/types'; -import type { ModuleImportFn, ProjectAnnotations } from '@storybook/core/types'; +import { CsfDocsRender } from './render/CsfDocsRender'; +import { MdxDocsRender } from './render/MdxDocsRender'; +import { PREPARE_ABORTED } from './render/Render'; +import { StoryRender } from './render/StoryRender'; const globalWindow = globalThis; diff --git a/code/core/src/preview-api/modules/preview-web/SelectionStore.ts b/code/core/src/preview-api/modules/preview-web/SelectionStore.ts index fe75097ef325..439fb7a219b1 100644 --- a/code/core/src/preview-api/modules/preview-web/SelectionStore.ts +++ b/code/core/src/preview-api/modules/preview-web/SelectionStore.ts @@ -1,4 +1,5 @@ import type { Args, StoryId, ViewMode } from '@storybook/core/types'; + import type { StorySpecifier } from '../store/StoryIndexStore'; export interface SelectionSpecifier { diff --git a/code/core/src/preview-api/modules/preview-web/UrlStore.test.ts b/code/core/src/preview-api/modules/preview-web/UrlStore.test.ts index cc6e57171968..09c6e8925743 100644 --- a/code/core/src/preview-api/modules/preview-web/UrlStore.test.ts +++ b/code/core/src/preview-api/modules/preview-web/UrlStore.test.ts @@ -1,7 +1,8 @@ -import { describe, it, expect, vi } from 'vitest'; +import { describe, expect, it, vi } from 'vitest'; + import { global } from '@storybook/global'; -import { pathToId, setPath, getSelectionSpecifierFromPath } from './UrlStore'; +import { getSelectionSpecifierFromPath, pathToId, setPath } from './UrlStore'; const { history, document } = global; diff --git a/code/core/src/preview-api/modules/preview-web/UrlStore.ts b/code/core/src/preview-api/modules/preview-web/UrlStore.ts index 3bd6de1a4a4b..85b0c79279cf 100644 --- a/code/core/src/preview-api/modules/preview-web/UrlStore.ts +++ b/code/core/src/preview-api/modules/preview-web/UrlStore.ts @@ -1,9 +1,10 @@ +import type { ViewMode } from '@storybook/core/types'; import { global } from '@storybook/global'; + import qs from 'qs'; +import type { Selection, SelectionSpecifier, SelectionStore } from './SelectionStore'; import { parseArgsParam } from './parseArgsParam'; -import type { SelectionSpecifier, SelectionStore, Selection } from './SelectionStore'; -import type { ViewMode } from '@storybook/core/types'; const { history, document } = global; diff --git a/code/core/src/preview-api/modules/preview-web/WebView.ts b/code/core/src/preview-api/modules/preview-web/WebView.ts index e36a9f6494d0..1e7ae240b9aa 100644 --- a/code/core/src/preview-api/modules/preview-web/WebView.ts +++ b/code/core/src/preview-api/modules/preview-web/WebView.ts @@ -1,11 +1,13 @@ +import type { PreparedStory } from '@storybook/core/types'; import { global } from '@storybook/global'; + import { logger } from '@storybook/core/client-logger'; + import AnsiToHtml from 'ansi-to-html'; -import { dedent } from 'ts-dedent'; import qs from 'qs'; +import { dedent } from 'ts-dedent'; import type { View } from './View'; -import type { PreparedStory } from '@storybook/core/types'; const { document } = global; diff --git a/code/core/src/preview-api/modules/preview-web/docs-context/DocsContext.test.ts b/code/core/src/preview-api/modules/preview-web/docs-context/DocsContext.test.ts index d1b2595ce7ce..f79da3152f0e 100644 --- a/code/core/src/preview-api/modules/preview-web/docs-context/DocsContext.test.ts +++ b/code/core/src/preview-api/modules/preview-web/docs-context/DocsContext.test.ts @@ -1,8 +1,9 @@ -import { describe, it, expect, vi } from 'vitest'; +import { describe, expect, it, vi } from 'vitest'; + import { Channel } from '@storybook/core/channels'; import type { CSFFile, Renderer } from '@storybook/core/types'; -import type { StoryStore } from '../../store'; +import type { StoryStore } from '../../store'; import { DocsContext } from './DocsContext'; import { csfFileParts } from './test-utils'; diff --git a/code/core/src/preview-api/modules/preview-web/docs-context/DocsContext.ts b/code/core/src/preview-api/modules/preview-web/docs-context/DocsContext.ts index ec74033b4b07..f53e08083d31 100644 --- a/code/core/src/preview-api/modules/preview-web/docs-context/DocsContext.ts +++ b/code/core/src/preview-api/modules/preview-web/docs-context/DocsContext.ts @@ -1,8 +1,4 @@ import type { Channel } from '@storybook/core/channels'; - -import { dedent } from 'ts-dedent'; -import type { StoryStore } from '../../store'; -import type { DocsContextProps } from './DocsContextProps'; import type { CSFFile, ModuleExport, @@ -15,6 +11,11 @@ import type { StoryName, } from '@storybook/core/types'; +import { dedent } from 'ts-dedent'; + +import type { StoryStore } from '../../store'; +import type { DocsContextProps } from './DocsContextProps'; + export class DocsContext implements DocsContextProps { private componentStoriesValue: PreparedStory[]; diff --git a/code/core/src/preview-api/modules/preview-web/parseArgsParam.test.ts b/code/core/src/preview-api/modules/preview-web/parseArgsParam.test.ts index f72df087ddcd..28879b3464df 100644 --- a/code/core/src/preview-api/modules/preview-web/parseArgsParam.test.ts +++ b/code/core/src/preview-api/modules/preview-web/parseArgsParam.test.ts @@ -1,4 +1,5 @@ -import { describe, it, expect, vi } from 'vitest'; +import { describe, expect, it, vi } from 'vitest'; + import { parseArgsParam } from './parseArgsParam'; vi.mock('@storybook/core/client-logger', () => ({ diff --git a/code/core/src/preview-api/modules/preview-web/parseArgsParam.ts b/code/core/src/preview-api/modules/preview-web/parseArgsParam.ts index a2cd2eb30806..89ec237c0a19 100644 --- a/code/core/src/preview-api/modules/preview-web/parseArgsParam.ts +++ b/code/core/src/preview-api/modules/preview-web/parseArgsParam.ts @@ -1,8 +1,10 @@ -import qs from 'qs'; -import { dedent } from 'ts-dedent'; +import type { Args } from '@storybook/core/types'; + import { once } from '@storybook/core/client-logger'; + import isPlainObject from 'lodash/isPlainObject.js'; -import type { Args } from '@storybook/core/types'; +import qs from 'qs'; +import { dedent } from 'ts-dedent'; // Keep this in sync with validateArgs in router/src/utils.ts const VALIDATION_REGEXP = /^[a-zA-Z0-9 _-]*$/; diff --git a/code/core/src/preview-api/modules/preview-web/render/CsfDocsRender.test.ts b/code/core/src/preview-api/modules/preview-web/render/CsfDocsRender.test.ts index 03f04b3bf63a..aa428572219c 100644 --- a/code/core/src/preview-api/modules/preview-web/render/CsfDocsRender.test.ts +++ b/code/core/src/preview-api/modules/preview-web/render/CsfDocsRender.test.ts @@ -1,11 +1,12 @@ -import { it, expect, vi } from 'vitest'; +import { expect, it, vi } from 'vitest'; + import { Channel } from '@storybook/core/channels'; -import type { Renderer, DocsIndexEntry, RenderContextCallbacks } from '@storybook/core/types'; -import type { StoryStore } from '../../store'; -import { PREPARE_ABORTED } from './Render'; +import type { DocsIndexEntry, RenderContextCallbacks, Renderer } from '@storybook/core/types'; -import { CsfDocsRender } from './CsfDocsRender'; +import type { StoryStore } from '../../store'; import { csfFileParts } from '../docs-context/test-utils'; +import { CsfDocsRender } from './CsfDocsRender'; +import { PREPARE_ABORTED } from './Render'; const entry = { type: 'docs', diff --git a/code/core/src/preview-api/modules/preview-web/render/CsfDocsRender.ts b/code/core/src/preview-api/modules/preview-web/render/CsfDocsRender.ts index 048c5a367ca3..6a95017605e0 100644 --- a/code/core/src/preview-api/modules/preview-web/render/CsfDocsRender.ts +++ b/code/core/src/preview-api/modules/preview-web/render/CsfDocsRender.ts @@ -1,17 +1,18 @@ import type { Channel } from '@storybook/core/channels'; -import { DOCS_RENDERED } from '@storybook/core/core-events'; -import type { StoryStore } from '../../../store'; - -import type { Render, RenderType } from './Render'; -import { PREPARE_ABORTED } from './Render'; -import type { DocsContextProps } from '../docs-context/DocsContextProps'; -import type { DocsRenderFunction } from '../docs-context/DocsRenderFunction'; -import { DocsContext } from '../docs-context/DocsContext'; import type { Renderer, StoryId } from '@storybook/core/types'; import type { CSFFile, PreparedStory } from '@storybook/core/types'; import type { IndexEntry } from '@storybook/core/types'; import type { RenderContextCallbacks } from '@storybook/core/types'; +import { DOCS_RENDERED } from '@storybook/core/core-events'; + +import type { StoryStore } from '../../../store'; +import { DocsContext } from '../docs-context/DocsContext'; +import type { DocsContextProps } from '../docs-context/DocsContextProps'; +import type { DocsRenderFunction } from '../docs-context/DocsRenderFunction'; +import type { Render, RenderType } from './Render'; +import { PREPARE_ABORTED } from './Render'; + /** * A CsfDocsRender is a render of a docs entry that is rendered based on a CSF file. * diff --git a/code/core/src/preview-api/modules/preview-web/render/MdxDocsRender.test.ts b/code/core/src/preview-api/modules/preview-web/render/MdxDocsRender.test.ts index 58aff6acf9de..86a172013e9d 100644 --- a/code/core/src/preview-api/modules/preview-web/render/MdxDocsRender.test.ts +++ b/code/core/src/preview-api/modules/preview-web/render/MdxDocsRender.test.ts @@ -1,11 +1,12 @@ -import { describe, it, expect, vi } from 'vitest'; +import { describe, expect, it, vi } from 'vitest'; + import { Channel } from '@storybook/core/channels'; -import type { Renderer, DocsIndexEntry, RenderContextCallbacks } from '@storybook/core/types'; -import type { StoryStore } from '../../store'; -import { PREPARE_ABORTED } from './Render'; +import type { DocsIndexEntry, RenderContextCallbacks, Renderer } from '@storybook/core/types'; -import { MdxDocsRender } from './MdxDocsRender'; +import type { StoryStore } from '../../store'; import { csfFileParts } from '../docs-context/test-utils'; +import { MdxDocsRender } from './MdxDocsRender'; +import { PREPARE_ABORTED } from './Render'; const entry = { type: 'docs', diff --git a/code/core/src/preview-api/modules/preview-web/render/MdxDocsRender.ts b/code/core/src/preview-api/modules/preview-web/render/MdxDocsRender.ts index b7751e69df1b..596900c3f4ef 100644 --- a/code/core/src/preview-api/modules/preview-web/render/MdxDocsRender.ts +++ b/code/core/src/preview-api/modules/preview-web/render/MdxDocsRender.ts @@ -1,17 +1,18 @@ import type { Channel } from '@storybook/core/channels'; -import { DOCS_RENDERED } from '@storybook/core/core-events'; -import type { StoryStore } from '../../store'; - -import type { Render, RenderType } from './Render'; -import { PREPARE_ABORTED } from './Render'; -import type { DocsContextProps } from '../docs-context/DocsContextProps'; -import type { DocsRenderFunction } from '../docs-context/DocsRenderFunction'; -import { DocsContext } from '../docs-context/DocsContext'; import type { Renderer, StoryId } from '@storybook/core/types'; import type { CSFFile, ModuleExports } from '@storybook/core/types'; import type { IndexEntry } from '@storybook/core/types'; import type { RenderContextCallbacks } from '@storybook/core/types'; +import { DOCS_RENDERED } from '@storybook/core/core-events'; + +import type { StoryStore } from '../../store'; +import { DocsContext } from '../docs-context/DocsContext'; +import type { DocsContextProps } from '../docs-context/DocsContextProps'; +import type { DocsRenderFunction } from '../docs-context/DocsRenderFunction'; +import type { Render, RenderType } from './Render'; +import { PREPARE_ABORTED } from './Render'; + /** * A MdxDocsRender is a render of a docs entry that comes from a true MDX file, * that is a `.mdx` file that doesn't get compiled to a CSF file. diff --git a/code/core/src/preview-api/modules/preview-web/render/StoryRender.test.ts b/code/core/src/preview-api/modules/preview-web/render/StoryRender.test.ts index 0b84b76c2866..2bd3a9ca3830 100644 --- a/code/core/src/preview-api/modules/preview-web/render/StoryRender.test.ts +++ b/code/core/src/preview-api/modules/preview-web/render/StoryRender.test.ts @@ -1,10 +1,11 @@ // @vitest-environment happy-dom -import { describe, it, expect, vi, beforeEach } from 'vitest'; +import { beforeEach, describe, expect, it, vi } from 'vitest'; + import { Channel } from '@storybook/core/channels'; import type { PreparedStory, Renderer, StoryContext, StoryIndexEntry } from '@storybook/core/types'; + import type { StoryStore } from '../../store'; import { PREPARE_ABORTED } from './Render'; - import { StoryRender } from './StoryRender'; const entry = { diff --git a/code/core/src/preview-api/modules/preview-web/render/StoryRender.ts b/code/core/src/preview-api/modules/preview-web/render/StoryRender.ts index 5f4503877fc2..cd12e2dc3b6b 100644 --- a/code/core/src/preview-api/modules/preview-web/render/StoryRender.ts +++ b/code/core/src/preview-api/modules/preview-web/render/StoryRender.ts @@ -1,28 +1,29 @@ import type { Channel } from '@storybook/core/channels'; -import { - STORY_RENDER_PHASE_CHANGED, - STORY_RENDERED, - PLAY_FUNCTION_THREW_EXCEPTION, - UNHANDLED_ERRORS_WHILE_PLAYING, -} from '@storybook/core/core-events'; -import type { StoryStore } from '../../store'; -import type { Render, RenderType } from './Render'; -import { PREPARE_ABORTED } from './Render'; -import { MountMustBeDestructuredError, NoStoryMountedError } from '@storybook/core/preview-errors'; - import type { Canvas, PreparedStory, RenderContext, RenderContextCallbacks, - Renderer, RenderToCanvas, + Renderer, StoryContext, StoryId, StoryRenderOptions, TeardownRenderToCanvas, } from '@storybook/core/types'; +import { + PLAY_FUNCTION_THREW_EXCEPTION, + STORY_RENDERED, + STORY_RENDER_PHASE_CHANGED, + UNHANDLED_ERRORS_WHILE_PLAYING, +} from '@storybook/core/core-events'; +import { MountMustBeDestructuredError, NoStoryMountedError } from '@storybook/core/preview-errors'; + +import type { StoryStore } from '../../store'; +import type { Render, RenderType } from './Render'; +import { PREPARE_ABORTED } from './Render'; + const { AbortController } = globalThis; export type RenderPhase = diff --git a/code/core/src/preview-api/modules/preview-web/render/mount-utils.test.ts b/code/core/src/preview-api/modules/preview-web/render/mount-utils.test.ts index 4fe7b4ac8832..80c1a56211b1 100644 --- a/code/core/src/preview-api/modules/preview-web/render/mount-utils.test.ts +++ b/code/core/src/preview-api/modules/preview-web/render/mount-utils.test.ts @@ -1,4 +1,5 @@ import { expect, test } from 'vitest'; + import { getUsedProps } from './mount-utils'; const StoryWithContext = { diff --git a/code/core/src/preview-api/modules/preview-web/simulate-pageload.test.ts b/code/core/src/preview-api/modules/preview-web/simulate-pageload.test.ts index 0f43ae04c54f..c15e8613034b 100644 --- a/code/core/src/preview-api/modules/preview-web/simulate-pageload.test.ts +++ b/code/core/src/preview-api/modules/preview-web/simulate-pageload.test.ts @@ -1,7 +1,8 @@ // @vitest-environment happy-dom -import { describe, it, expect } from 'vitest'; +import { describe, expect, it } from 'vitest'; import { global } from '@storybook/global'; + import { simulatePageLoad } from './simulate-pageload'; const { document } = global; diff --git a/code/core/src/preview-api/modules/store/ArgsStore.test.ts b/code/core/src/preview-api/modules/store/ArgsStore.test.ts index d730aed9ece8..ad3d20c7664d 100644 --- a/code/core/src/preview-api/modules/store/ArgsStore.test.ts +++ b/code/core/src/preview-api/modules/store/ArgsStore.test.ts @@ -1,4 +1,4 @@ -import { describe, it, expect, vi } from 'vitest'; +import { describe, expect, it, vi } from 'vitest'; import { ArgsStore } from './ArgsStore'; diff --git a/code/core/src/preview-api/modules/store/ArgsStore.ts b/code/core/src/preview-api/modules/store/ArgsStore.ts index 5c9f941b0ebd..da613e76dc81 100644 --- a/code/core/src/preview-api/modules/store/ArgsStore.ts +++ b/code/core/src/preview-api/modules/store/ArgsStore.ts @@ -1,7 +1,8 @@ import type { Args, StoryId } from '@storybook/core/types'; -import { combineArgs, mapArgsToTypes, validateOptions, deepDiff, DEEPLY_EQUAL } from './args'; import type { PreparedStory } from '@storybook/core/types'; +import { DEEPLY_EQUAL, combineArgs, deepDiff, mapArgsToTypes, validateOptions } from './args'; + function deleteUndefined(obj: Record) { Object.keys(obj).forEach((key) => obj[key] === undefined && delete obj[key]); return obj; diff --git a/code/core/src/preview-api/modules/store/GlobalsStore.test.ts b/code/core/src/preview-api/modules/store/GlobalsStore.test.ts index 85f99d5be0d6..eda822e40c64 100644 --- a/code/core/src/preview-api/modules/store/GlobalsStore.test.ts +++ b/code/core/src/preview-api/modules/store/GlobalsStore.test.ts @@ -1,4 +1,5 @@ -import { describe, it, expect, vi } from 'vitest'; +import { describe, expect, it, vi } from 'vitest'; + import { GlobalsStore } from './GlobalsStore'; vi.mock('@storybook/core/client-logger', () => ({ diff --git a/code/core/src/preview-api/modules/store/GlobalsStore.ts b/code/core/src/preview-api/modules/store/GlobalsStore.ts index 0ec64390b516..dd15417d9143 100644 --- a/code/core/src/preview-api/modules/store/GlobalsStore.ts +++ b/code/core/src/preview-api/modules/store/GlobalsStore.ts @@ -1,8 +1,9 @@ +import type { GlobalTypes, Globals } from '@storybook/core/types'; + import { logger } from '@storybook/core/client-logger'; -import { deepDiff, DEEPLY_EQUAL } from './args'; +import { DEEPLY_EQUAL, deepDiff } from './args'; import { getValuesFromArgTypes } from './csf/getValuesFromArgTypes'; -import type { Globals, GlobalTypes } from '@storybook/core/types'; export class GlobalsStore { // We use ! here because TS doesn't analyse the .set() function to see if it actually get set diff --git a/code/core/src/preview-api/modules/store/StoryIndexStore.test.ts b/code/core/src/preview-api/modules/store/StoryIndexStore.test.ts index 11da69623139..1cfdd553ea33 100644 --- a/code/core/src/preview-api/modules/store/StoryIndexStore.test.ts +++ b/code/core/src/preview-api/modules/store/StoryIndexStore.test.ts @@ -1,6 +1,7 @@ -import { describe, it, expect, vi } from 'vitest'; +import { describe, expect, it, vi } from 'vitest'; import type { StoryIndex } from '@storybook/core/types'; + import { StoryIndexStore } from './StoryIndexStore'; vi.mock('@storybook/channel-websocket', () => () => ({ on: vi.fn() })); diff --git a/code/core/src/preview-api/modules/store/StoryIndexStore.ts b/code/core/src/preview-api/modules/store/StoryIndexStore.ts index f608932b6121..d6812e736f5f 100644 --- a/code/core/src/preview-api/modules/store/StoryIndexStore.ts +++ b/code/core/src/preview-api/modules/store/StoryIndexStore.ts @@ -1,8 +1,10 @@ -import memoize from 'memoizerific'; -import { MissingStoryAfterHmrError } from '@storybook/core/preview-errors'; import type { ComponentTitle, Path, StoryId, StoryName } from '@storybook/core/types'; import type { IndexEntry, StoryIndex } from '@storybook/core/types'; +import { MissingStoryAfterHmrError } from '@storybook/core/preview-errors'; + +import memoize from 'memoizerific'; + export type StorySpecifier = StoryId | { name: StoryName; title: ComponentTitle } | '*'; const getImportPathMap = memoize(1)((entries: StoryIndex['entries']) => diff --git a/code/core/src/preview-api/modules/store/StoryStore.test.ts b/code/core/src/preview-api/modules/store/StoryStore.test.ts index abb6c158c76e..4cc27210c5af 100644 --- a/code/core/src/preview-api/modules/store/StoryStore.test.ts +++ b/code/core/src/preview-api/modules/store/StoryStore.test.ts @@ -1,11 +1,12 @@ -import { describe, it, expect, vi } from 'vitest'; -import type { Renderer, ProjectAnnotations, StoryIndex } from '@storybook/core/types'; +import { describe, expect, it, vi } from 'vitest'; +import type { ProjectAnnotations, Renderer, StoryIndex } from '@storybook/core/types'; + +import { StoryStore } from './StoryStore'; +import { composeConfigs } from './csf/composeConfigs'; import { prepareStory } from './csf/prepareStory'; import { processCSFFile } from './csf/processCSFFile'; -import { StoryStore } from './StoryStore'; import type { HooksContext } from './hooks'; -import { composeConfigs } from './csf/composeConfigs'; // Spy on prepareStory/processCSFFile vi.mock('./csf/prepareStory', async (importOriginal) => { diff --git a/code/core/src/preview-api/modules/store/StoryStore.ts b/code/core/src/preview-api/modules/store/StoryStore.ts index c5414d7956cf..99d6efd5f8bd 100644 --- a/code/core/src/preview-api/modules/store/StoryStore.ts +++ b/code/core/src/preview-api/modules/store/StoryStore.ts @@ -1,33 +1,12 @@ -import memoize from 'memoizerific'; import type { - Renderer, ComponentTitle, Parameters, Path, + Renderer, StoryContext, StoryContextForEnhancers, StoryId, } from '@storybook/core/types'; -import mapValues from 'lodash/mapValues.js'; -import pick from 'lodash/pick.js'; - -import { - CalledExtractOnStoreError, - MissingStoryFromCsfFileError, -} from '@storybook/core/preview-errors'; -import { deprecate } from '@storybook/core/client-logger'; -import { HooksContext } from '../addons'; -import { StoryIndexStore } from './StoryIndexStore'; -import { ArgsStore } from './ArgsStore'; -import { GlobalsStore } from './GlobalsStore'; -import { - processCSFFile, - prepareStory, - prepareMeta, - normalizeProjectAnnotations, - prepareContext, -} from './csf'; -import type { Canvas, CleanupCallback } from '@storybook/csf'; import type { BoundStory, CSFFile, @@ -44,6 +23,29 @@ import type { StoryIndexV3, V3CompatIndexEntry, } from '@storybook/core/types'; +import type { Canvas, CleanupCallback } from '@storybook/csf'; + +import { deprecate } from '@storybook/core/client-logger'; +import { + CalledExtractOnStoreError, + MissingStoryFromCsfFileError, +} from '@storybook/core/preview-errors'; + +import mapValues from 'lodash/mapValues.js'; +import pick from 'lodash/pick.js'; +import memoize from 'memoizerific'; + +import { HooksContext } from '../addons'; +import { ArgsStore } from './ArgsStore'; +import { GlobalsStore } from './GlobalsStore'; +import { StoryIndexStore } from './StoryIndexStore'; +import { + normalizeProjectAnnotations, + prepareContext, + prepareMeta, + prepareStory, + processCSFFile, +} from './csf'; // TODO -- what are reasonable values for these? const CSF_CACHE_SIZE = 1000; diff --git a/code/core/src/preview-api/modules/store/args.test.ts b/code/core/src/preview-api/modules/store/args.test.ts index 3d6e82c53313..d40d989cebc7 100644 --- a/code/core/src/preview-api/modules/store/args.test.ts +++ b/code/core/src/preview-api/modules/store/args.test.ts @@ -1,12 +1,14 @@ -import { describe, it, expect, vi } from 'vitest'; -import { once } from '@storybook/core/client-logger'; +import { describe, expect, it, vi } from 'vitest'; + import type { SBType } from '@storybook/core/types'; +import { once } from '@storybook/core/client-logger'; + import { + UNTARGETED, combineArgs, groupArgsByTarget, mapArgsToTypes, - UNTARGETED, validateOptions, } from './args'; diff --git a/code/core/src/preview-api/modules/store/args.ts b/code/core/src/preview-api/modules/store/args.ts index 213de81df96f..ca856dd6bc11 100644 --- a/code/core/src/preview-api/modules/store/args.ts +++ b/code/core/src/preview-api/modules/store/args.ts @@ -1,7 +1,3 @@ -import { dequal as deepEqual } from 'dequal'; -import { once } from '@storybook/core/client-logger'; -import isPlainObject from 'lodash/isPlainObject.js'; -import { dedent } from 'ts-dedent'; import type { ArgTypes, Args, @@ -11,6 +7,12 @@ import type { StoryContext, } from '@storybook/core/types'; +import { once } from '@storybook/core/client-logger'; + +import { dequal as deepEqual } from 'dequal'; +import isPlainObject from 'lodash/isPlainObject.js'; +import { dedent } from 'ts-dedent'; + const INCOMPATIBLE = Symbol('incompatible'); const map = (arg: unknown, argType: InputType): any => { const type = argType.type as SBType; diff --git a/code/core/src/preview-api/modules/store/autoTitle.test.ts b/code/core/src/preview-api/modules/store/autoTitle.test.ts index e45c0a035654..3289261dd8bc 100644 --- a/code/core/src/preview-api/modules/store/autoTitle.test.ts +++ b/code/core/src/preview-api/modules/store/autoTitle.test.ts @@ -1,4 +1,5 @@ -import { describe, it, expect } from 'vitest'; +import { describe, expect, it } from 'vitest'; + import { normalizeStoriesEntry } from '@storybook/core/common'; import { userOrAutoTitleFromSpecifier as userOrAuto } from './autoTitle'; diff --git a/code/core/src/preview-api/modules/store/autoTitle.ts b/code/core/src/preview-api/modules/store/autoTitle.ts index 8c8064208b09..175f6c107ae1 100644 --- a/code/core/src/preview-api/modules/store/autoTitle.ts +++ b/code/core/src/preview-api/modules/store/autoTitle.ts @@ -1,7 +1,9 @@ +import type { NormalizedStoriesSpecifier } from '@storybook/core/types'; + +import { once } from '@storybook/core/client-logger'; + import slash from 'slash'; import { dedent } from 'ts-dedent'; -import { once } from '@storybook/core/client-logger'; -import type { NormalizedStoriesSpecifier } from '@storybook/core/types'; // FIXME: types duplicated type from `core-common', to be // removed when we remove v6 back-compat. diff --git a/code/core/src/preview-api/modules/store/csf/beforeAll.test.ts b/code/core/src/preview-api/modules/store/csf/beforeAll.test.ts index e3f0200dd19a..30f066e8ac00 100644 --- a/code/core/src/preview-api/modules/store/csf/beforeAll.test.ts +++ b/code/core/src/preview-api/modules/store/csf/beforeAll.test.ts @@ -1,4 +1,5 @@ import { beforeEach, describe, expect, it } from 'vitest'; + import { composeBeforeAllHooks } from './beforeAll'; const calls: string[] = []; diff --git a/code/core/src/preview-api/modules/store/csf/composeConfigs.test.ts b/code/core/src/preview-api/modules/store/csf/composeConfigs.test.ts index 0d8f0e2912b0..035aa60e7e14 100644 --- a/code/core/src/preview-api/modules/store/csf/composeConfigs.test.ts +++ b/code/core/src/preview-api/modules/store/csf/composeConfigs.test.ts @@ -1,4 +1,5 @@ -import { describe, beforeEach, afterEach, it, expect, vi } from 'vitest'; +import { afterEach, beforeEach, describe, expect, it, vi } from 'vitest'; + import { global } from '@storybook/global'; import { composeConfigs } from './composeConfigs'; diff --git a/code/core/src/preview-api/modules/store/csf/composeConfigs.ts b/code/core/src/preview-api/modules/store/csf/composeConfigs.ts index 29eb8ec56c36..7ccec5685659 100644 --- a/code/core/src/preview-api/modules/store/csf/composeConfigs.ts +++ b/code/core/src/preview-api/modules/store/csf/composeConfigs.ts @@ -3,9 +3,9 @@ import type { Renderer } from '@storybook/core/types'; import { global } from '@storybook/global'; import { combineParameters } from '../parameters'; -import { composeStepRunners } from './stepRunners'; -import { normalizeArrays } from './normalizeArrays'; import { composeBeforeAllHooks } from './beforeAll'; +import { normalizeArrays } from './normalizeArrays'; +import { composeStepRunners } from './stepRunners'; export function getField( moduleExportList: ModuleExports[], diff --git a/code/core/src/preview-api/modules/store/csf/normalizeComponentAnnotations.ts b/code/core/src/preview-api/modules/store/csf/normalizeComponentAnnotations.ts index d9da3d5ed8e5..b314a89d31bf 100644 --- a/code/core/src/preview-api/modules/store/csf/normalizeComponentAnnotations.ts +++ b/code/core/src/preview-api/modules/store/csf/normalizeComponentAnnotations.ts @@ -1,8 +1,8 @@ +import type { ModuleExports, NormalizedComponentAnnotations } from '@storybook/core/types'; +import type { Renderer } from '@storybook/core/types'; import { sanitize } from '@storybook/csf'; import { normalizeInputTypes } from './normalizeInputTypes'; -import type { ModuleExports, NormalizedComponentAnnotations } from '@storybook/core/types'; -import type { Renderer } from '@storybook/core/types'; export function normalizeComponentAnnotations( defaultExport: ModuleExports['default'], diff --git a/code/core/src/preview-api/modules/store/csf/normalizeInputTypes.test.ts b/code/core/src/preview-api/modules/store/csf/normalizeInputTypes.test.ts index 58f38ea79324..33b8f26e9625 100644 --- a/code/core/src/preview-api/modules/store/csf/normalizeInputTypes.test.ts +++ b/code/core/src/preview-api/modules/store/csf/normalizeInputTypes.test.ts @@ -1,4 +1,4 @@ -import { describe, it, expect } from 'vitest'; +import { describe, expect, it } from 'vitest'; import { normalizeInputType, normalizeInputTypes } from './normalizeInputTypes'; diff --git a/code/core/src/preview-api/modules/store/csf/normalizeInputTypes.ts b/code/core/src/preview-api/modules/store/csf/normalizeInputTypes.ts index a34c0aaaaaaa..0b9b0dc2c311 100644 --- a/code/core/src/preview-api/modules/store/csf/normalizeInputTypes.ts +++ b/code/core/src/preview-api/modules/store/csf/normalizeInputTypes.ts @@ -6,6 +6,7 @@ import type { StrictGlobalTypes, StrictInputType, } from '@storybook/core/types'; + import mapValues from 'lodash/mapValues.js'; const normalizeType = (type: InputType['type']): StrictInputType['type'] => { diff --git a/code/core/src/preview-api/modules/store/csf/normalizeProjectAnnotations.test.ts b/code/core/src/preview-api/modules/store/csf/normalizeProjectAnnotations.test.ts index a6aa1a2f7a83..bfb2a4c067b4 100644 --- a/code/core/src/preview-api/modules/store/csf/normalizeProjectAnnotations.test.ts +++ b/code/core/src/preview-api/modules/store/csf/normalizeProjectAnnotations.test.ts @@ -1,4 +1,4 @@ -import { describe, it, expect, vi, beforeEach } from 'vitest'; +import { beforeEach, describe, expect, it, vi } from 'vitest'; import { normalizeProjectAnnotations } from './normalizeProjectAnnotations'; diff --git a/code/core/src/preview-api/modules/store/csf/normalizeProjectAnnotations.ts b/code/core/src/preview-api/modules/store/csf/normalizeProjectAnnotations.ts index adc3282d9933..26711a130106 100644 --- a/code/core/src/preview-api/modules/store/csf/normalizeProjectAnnotations.ts +++ b/code/core/src/preview-api/modules/store/csf/normalizeProjectAnnotations.ts @@ -1,17 +1,19 @@ import type { - Renderer, ArgTypes, - ProjectAnnotations, NormalizedProjectAnnotations, + ProjectAnnotations, + Renderer, } from '@storybook/core/types'; + import { deprecate } from '@storybook/core/client-logger'; + import { dedent } from 'ts-dedent'; import { inferArgTypes } from '../inferArgTypes'; import { inferControls } from '../inferControls'; -import { normalizeInputTypes } from './normalizeInputTypes'; -import { normalizeArrays } from './normalizeArrays'; import { combineParameters } from '../parameters'; +import { normalizeArrays } from './normalizeArrays'; +import { normalizeInputTypes } from './normalizeInputTypes'; // TODO(kasperpeulen) Consolidate this function with composeConfigs // As composeConfigs is the real normalizer, and always run before normalizeProjectAnnotations diff --git a/code/core/src/preview-api/modules/store/csf/normalizeStory.test.ts b/code/core/src/preview-api/modules/store/csf/normalizeStory.test.ts index a8dc553cf0e0..ddacda230514 100644 --- a/code/core/src/preview-api/modules/store/csf/normalizeStory.test.ts +++ b/code/core/src/preview-api/modules/store/csf/normalizeStory.test.ts @@ -1,4 +1,5 @@ -import { describe, it, expect, vi } from 'vitest'; +import { describe, expect, it, vi } from 'vitest'; + import type { Renderer, StoryAnnotationsOrFn } from '@storybook/core/types'; import { normalizeStory } from './normalizeStory'; diff --git a/code/core/src/preview-api/modules/store/csf/normalizeStory.ts b/code/core/src/preview-api/modules/store/csf/normalizeStory.ts index d4c710b2eb03..2dd2ae957390 100644 --- a/code/core/src/preview-api/modules/store/csf/normalizeStory.ts +++ b/code/core/src/preview-api/modules/store/csf/normalizeStory.ts @@ -1,20 +1,23 @@ import type { - Renderer, ArgTypes, LegacyStoryAnnotationsOrFn, + Renderer, StoryAnnotations, StoryFn, StoryId, } from '@storybook/core/types'; -import { storyNameFromExport, toId } from '@storybook/csf'; -import { dedent } from 'ts-dedent'; -import { logger, deprecate } from '@storybook/core/client-logger'; -import { normalizeInputTypes } from './normalizeInputTypes'; -import { normalizeArrays } from './normalizeArrays'; import type { NormalizedComponentAnnotations, NormalizedStoryAnnotations, } from '@storybook/core/types'; +import { storyNameFromExport, toId } from '@storybook/csf'; + +import { deprecate, logger } from '@storybook/core/client-logger'; + +import { dedent } from 'ts-dedent'; + +import { normalizeArrays } from './normalizeArrays'; +import { normalizeInputTypes } from './normalizeInputTypes'; const deprecatedStoryAnnotation = dedent` CSF .story annotations deprecated; annotate story functions directly: diff --git a/code/core/src/preview-api/modules/store/csf/portable-stories.test.ts b/code/core/src/preview-api/modules/store/csf/portable-stories.test.ts index c13f9c931487..6c85760cbd4e 100644 --- a/code/core/src/preview-api/modules/store/csf/portable-stories.test.ts +++ b/code/core/src/preview-api/modules/store/csf/portable-stories.test.ts @@ -1,15 +1,16 @@ // @vitest-environment node -import { describe, expect, vi, it } from 'vitest'; +import { describe, expect, it, vi } from 'vitest'; + import type { ComponentAnnotations as Meta, - StoryAnnotationsOrFn as Story, Store_CSFExports, + StoryAnnotationsOrFn as Story, } from '@storybook/core/types'; +import type { ProjectAnnotations } from '@storybook/csf'; -import { composeStory, composeStories, setProjectAnnotations } from './portable-stories'; import * as defaultExportAnnotations from './__mocks__/defaultExportAnnotations.mockfile'; import * as namedExportAnnotations from './__mocks__/namedExportAnnotations.mockfile'; -import type { ProjectAnnotations } from '@storybook/csf'; +import { composeStories, composeStory, setProjectAnnotations } from './portable-stories'; type StoriesModule = Store_CSFExports & Record; diff --git a/code/core/src/preview-api/modules/store/csf/portable-stories.ts b/code/core/src/preview-api/modules/store/csf/portable-stories.ts index bd18285d456d..877901fecea4 100644 --- a/code/core/src/preview-api/modules/store/csf/portable-stories.ts +++ b/code/core/src/preview-api/modules/store/csf/portable-stories.ts @@ -1,13 +1,12 @@ /* eslint-disable no-underscore-dangle */ + /* eslint-disable @typescript-eslint/naming-convention */ -import { type CleanupCallback, isExportStory } from '@storybook/csf'; -import { dedent } from 'ts-dedent'; import type { Args, Canvas, ComponentAnnotations, - ComposedStoryFn, ComposeStoryFn, + ComposedStoryFn, LegacyStoryAnnotationsOrFn, NamedOrDefaultProjectAnnotations, Parameters, @@ -19,15 +18,19 @@ import type { StoryContext, StrictArgTypes, } from '@storybook/core/types'; +import { type CleanupCallback, isExportStory } from '@storybook/csf'; + +import { MountMustBeDestructuredError } from '@storybook/core/preview-errors'; + +import { dedent } from 'ts-dedent'; import { HooksContext } from '../../../addons'; import { composeConfigs } from './composeConfigs'; -import { prepareContext, prepareStory } from './prepareStory'; -import { normalizeStory } from './normalizeStory'; -import { normalizeComponentAnnotations } from './normalizeComponentAnnotations'; import { getValuesFromArgTypes } from './getValuesFromArgTypes'; +import { normalizeComponentAnnotations } from './normalizeComponentAnnotations'; import { normalizeProjectAnnotations } from './normalizeProjectAnnotations'; -import { MountMustBeDestructuredError } from '@storybook/core/preview-errors'; +import { normalizeStory } from './normalizeStory'; +import { prepareContext, prepareStory } from './prepareStory'; let globalProjectAnnotations: ProjectAnnotations = {}; diff --git a/code/core/src/preview-api/modules/store/csf/prepareStory.test.ts b/code/core/src/preview-api/modules/store/csf/prepareStory.test.ts index e9fd7f3228be..e91a6fcfea05 100644 --- a/code/core/src/preview-api/modules/store/csf/prepareStory.test.ts +++ b/code/core/src/preview-api/modules/store/csf/prepareStory.test.ts @@ -1,5 +1,5 @@ import { beforeEach, describe, expect, it, vi } from 'vitest'; -import { global } from '@storybook/global'; + import type { ArgsEnhancer, NormalizedComponentAnnotations, @@ -10,12 +10,13 @@ import type { SBScalarType, StoryContext, } from '@storybook/core/types'; -import { addons, HooksContext } from '../../addons'; +import { global } from '@storybook/global'; +import { HooksContext, addons } from '../../addons'; import { UNTARGETED } from '../args'; -import { prepareMeta, prepareStory as realPrepareStory, prepareContext } from './prepareStory'; import { composeConfigs } from './composeConfigs'; import { normalizeProjectAnnotations } from './normalizeProjectAnnotations'; +import { prepareContext, prepareMeta, prepareStory as realPrepareStory } from './prepareStory'; vi.mock('@storybook/global', async (importOriginal) => ({ global: { diff --git a/code/core/src/preview-api/modules/store/csf/prepareStory.ts b/code/core/src/preview-api/modules/store/csf/prepareStory.ts index 77bbb4f26759..80f4fbd82f7b 100644 --- a/code/core/src/preview-api/modules/store/csf/prepareStory.ts +++ b/code/core/src/preview-api/modules/store/csf/prepareStory.ts @@ -1,5 +1,4 @@ /* eslint-disable no-underscore-dangle */ -import { global } from '@storybook/global'; import type { Args, ArgsStoryFn, @@ -13,23 +12,25 @@ import type { StoryContextForLoaders, StrictArgTypes, } from '@storybook/core/types'; -import { type CleanupCallback, includeConditionalArg, combineTags } from '@storybook/csf'; -import { global as globalThis } from '@storybook/global'; - -import { applyHooks } from '../../addons'; -import { combineParameters } from '../parameters'; -import { defaultDecorateStory } from '../decorators'; -import { groupArgsByTarget, UNTARGETED } from '../args'; -import { normalizeArrays } from './normalizeArrays'; import type { ModuleExport, NormalizedComponentAnnotations, NormalizedProjectAnnotations, NormalizedStoryAnnotations, } from '@storybook/core/types'; -import { mountDestructured } from '../../preview-web/render/mount-utils'; +import { type CleanupCallback, combineTags, includeConditionalArg } from '@storybook/csf'; +import { global } from '@storybook/global'; +import { global as globalThis } from '@storybook/global'; + import { NoRenderFunctionError } from '@storybook/core/preview-errors'; +import { applyHooks } from '../../addons'; +import { mountDestructured } from '../../preview-web/render/mount-utils'; +import { UNTARGETED, groupArgsByTarget } from '../args'; +import { defaultDecorateStory } from '../decorators'; +import { combineParameters } from '../parameters'; +import { normalizeArrays } from './normalizeArrays'; + // Combine all the metadata about a story (both direct and inherited from the component/global scope) // into a "render-able" story function, with all decorators applied, parameters passed as context etc // diff --git a/code/core/src/preview-api/modules/store/csf/processCSFFile.test.ts b/code/core/src/preview-api/modules/store/csf/processCSFFile.test.ts index 8ff880caed3a..a8382e660988 100644 --- a/code/core/src/preview-api/modules/store/csf/processCSFFile.test.ts +++ b/code/core/src/preview-api/modules/store/csf/processCSFFile.test.ts @@ -1,4 +1,4 @@ -import { describe, it, expect } from 'vitest'; +import { describe, expect, it } from 'vitest'; import { processCSFFile } from './processCSFFile'; diff --git a/code/core/src/preview-api/modules/store/csf/processCSFFile.ts b/code/core/src/preview-api/modules/store/csf/processCSFFile.ts index 3f5b9ebacd0a..fa1e3aecb508 100644 --- a/code/core/src/preview-api/modules/store/csf/processCSFFile.ts +++ b/code/core/src/preview-api/modules/store/csf/processCSFFile.ts @@ -1,10 +1,11 @@ -import type { Renderer, ComponentTitle, Parameters, Path } from '@storybook/core/types'; +import type { ComponentTitle, Parameters, Path, Renderer } from '@storybook/core/types'; +import type { CSFFile, ModuleExports, NormalizedComponentAnnotations } from '@storybook/core/types'; import { isExportStory } from '@storybook/csf'; + import { logger } from '@storybook/core/client-logger'; -import { normalizeStory } from './normalizeStory'; import { normalizeComponentAnnotations } from './normalizeComponentAnnotations'; -import type { CSFFile, ModuleExports, NormalizedComponentAnnotations } from '@storybook/core/types'; +import { normalizeStory } from './normalizeStory'; const checkGlobals = (parameters: Parameters) => { const { globals, globalTypes } = parameters; diff --git a/code/core/src/preview-api/modules/store/csf/stepRunners.test.ts b/code/core/src/preview-api/modules/store/csf/stepRunners.test.ts index d67055c05d69..aacfa0d4dd5a 100644 --- a/code/core/src/preview-api/modules/store/csf/stepRunners.test.ts +++ b/code/core/src/preview-api/modules/store/csf/stepRunners.test.ts @@ -1,5 +1,7 @@ -import { describe, it, expect, vi } from 'vitest'; -import type { StoryContext, StepRunner } from '@storybook/core/types'; +import { describe, expect, it, vi } from 'vitest'; + +import type { StepRunner, StoryContext } from '@storybook/core/types'; + import { composeStepRunners } from './stepRunners'; describe('stepRunners', () => { diff --git a/code/core/src/preview-api/modules/store/decorators.test.ts b/code/core/src/preview-api/modules/store/decorators.test.ts index c61415afb797..ae3cd2bb8c3c 100644 --- a/code/core/src/preview-api/modules/store/decorators.test.ts +++ b/code/core/src/preview-api/modules/store/decorators.test.ts @@ -1,4 +1,5 @@ -import { describe, it, expect } from 'vitest'; +import { describe, expect, it } from 'vitest'; + import type { Renderer, StoryContext } from '@storybook/core/types'; import { defaultDecorateStory } from './decorators'; diff --git a/code/core/src/preview-api/modules/store/filterArgTypes.ts b/code/core/src/preview-api/modules/store/filterArgTypes.ts index b77cc79d20ea..274489a67cf4 100644 --- a/code/core/src/preview-api/modules/store/filterArgTypes.ts +++ b/code/core/src/preview-api/modules/store/filterArgTypes.ts @@ -1,4 +1,5 @@ import type { StrictArgTypes } from '@storybook/core/types'; + import pickBy from 'lodash/pickBy.js'; export type PropDescriptor = string[] | RegExp; diff --git a/code/core/src/preview-api/modules/store/hooks.test.ts b/code/core/src/preview-api/modules/store/hooks.test.ts index 898367d24ba6..cac2600ac72d 100644 --- a/code/core/src/preview-api/modules/store/hooks.test.ts +++ b/code/core/src/preview-api/modules/store/hooks.test.ts @@ -1,29 +1,31 @@ -import { describe, beforeEach, it, expect, vi } from 'vitest'; +import { beforeEach, describe, expect, it, vi } from 'vitest'; + +import type { DecoratorFunction, StoryContext } from '@storybook/core/types'; + import { FORCE_RE_RENDER, - STORY_RENDERED, - UPDATE_STORY_ARGS, RESET_STORY_ARGS, + STORY_RENDERED, UPDATE_GLOBALS, + UPDATE_STORY_ARGS, } from '@storybook/core/core-events'; -import type { DecoratorFunction, StoryContext } from '@storybook/core/types'; + import { + HooksContext, addons, applyHooks, + useArgs, + useCallback, + useChannel, useEffect, + useGlobals, useMemo, - useCallback, + useParameter, + useReducer, useRef, useState, - useReducer, - useChannel, - useParameter, useStoryContext, - HooksContext, - useArgs, - useGlobals, } from '../addons'; - import { defaultDecorateStory } from './decorators'; vi.mock('@storybook/core/client-logger', () => ({ diff --git a/code/core/src/preview-api/modules/store/hooks.ts b/code/core/src/preview-api/modules/store/hooks.ts index 857845c9b3d7..690e091775b6 100644 --- a/code/core/src/preview-api/modules/store/hooks.ts +++ b/code/core/src/preview-api/modules/store/hooks.ts @@ -1,17 +1,17 @@ import { HooksContext, applyHooks, - useMemo, + useArgs, useCallback, + useChannel, + useEffect, + useGlobals, + useMemo, + useParameter, + useReducer, useRef, useState, - useReducer, - useEffect, - useChannel, useStoryContext, - useParameter, - useArgs, - useGlobals, } from '../addons'; export { diff --git a/code/core/src/preview-api/modules/store/inferArgTypes.test.ts b/code/core/src/preview-api/modules/store/inferArgTypes.test.ts index db7d168301b2..fa374441a4ec 100644 --- a/code/core/src/preview-api/modules/store/inferArgTypes.test.ts +++ b/code/core/src/preview-api/modules/store/inferArgTypes.test.ts @@ -1,4 +1,5 @@ -import { describe, it, expect, vi } from 'vitest'; +import { describe, expect, it, vi } from 'vitest'; + import { logger } from '@storybook/core/client-logger'; import { inferArgTypes } from './inferArgTypes'; diff --git a/code/core/src/preview-api/modules/store/inferArgTypes.ts b/code/core/src/preview-api/modules/store/inferArgTypes.ts index 79a74de659fa..ea8b45b75609 100644 --- a/code/core/src/preview-api/modules/store/inferArgTypes.ts +++ b/code/core/src/preview-api/modules/store/inferArgTypes.ts @@ -1,8 +1,11 @@ +import type { ArgTypesEnhancer, Renderer, SBType } from '@storybook/core/types'; + +import { logger } from '@storybook/core/client-logger'; + import mapValues from 'lodash/mapValues.js'; import { dedent } from 'ts-dedent'; -import { logger } from '@storybook/core/client-logger'; + import { combineParameters } from './parameters'; -import type { ArgTypesEnhancer, Renderer, SBType } from '@storybook/core/types'; const inferType = (value: any, name: string, visited: Set): SBType => { const type = typeof value; diff --git a/code/core/src/preview-api/modules/store/inferControls.test.ts b/code/core/src/preview-api/modules/store/inferControls.test.ts index 135178439010..abe91702ec36 100644 --- a/code/core/src/preview-api/modules/store/inferControls.test.ts +++ b/code/core/src/preview-api/modules/store/inferControls.test.ts @@ -1,8 +1,10 @@ import type { MockInstance } from 'vitest'; -import { describe, beforeEach, afterEach, it, expect, vi } from 'vitest'; -import { logger } from '@storybook/core/client-logger'; +import { afterEach, beforeEach, describe, expect, it, vi } from 'vitest'; + import type { StoryContextForEnhancers } from '@storybook/core/types'; +import { logger } from '@storybook/core/client-logger'; + import { argTypesEnhancers } from './inferControls'; const getStoryContext = (overrides: any = {}): StoryContextForEnhancers => ({ diff --git a/code/core/src/preview-api/modules/store/inferControls.ts b/code/core/src/preview-api/modules/store/inferControls.ts index 2c0e2b93a9a1..c823eb24fc91 100644 --- a/code/core/src/preview-api/modules/store/inferControls.ts +++ b/code/core/src/preview-api/modules/store/inferControls.ts @@ -1,7 +1,3 @@ -import mapValues from 'lodash/mapValues.js'; -import { logger } from '@storybook/core/client-logger'; -import { filterArgTypes } from './filterArgTypes'; -import { combineParameters } from './parameters'; import type { ArgTypesEnhancer, Renderer, @@ -9,6 +5,13 @@ import type { StrictInputType, } from '@storybook/core/types'; +import { logger } from '@storybook/core/client-logger'; + +import mapValues from 'lodash/mapValues.js'; + +import { filterArgTypes } from './filterArgTypes'; +import { combineParameters } from './parameters'; + export type ControlsMatchers = { date: RegExp; color: RegExp; diff --git a/code/core/src/preview-api/modules/store/parameters.test.ts b/code/core/src/preview-api/modules/store/parameters.test.ts index d408f641a0a9..09905a6a1b6f 100644 --- a/code/core/src/preview-api/modules/store/parameters.test.ts +++ b/code/core/src/preview-api/modules/store/parameters.test.ts @@ -1,4 +1,5 @@ -import { describe, it, expect } from 'vitest'; +import { describe, expect, it } from 'vitest'; + import { combineParameters } from './parameters'; describe('client-api.parameters', () => { diff --git a/code/core/src/preview-api/modules/store/parameters.ts b/code/core/src/preview-api/modules/store/parameters.ts index dc7b7045fe7d..271ab5eb8329 100644 --- a/code/core/src/preview-api/modules/store/parameters.ts +++ b/code/core/src/preview-api/modules/store/parameters.ts @@ -1,5 +1,6 @@ // Utilities for handling parameters import type { Parameters } from '@storybook/core/types'; + import isPlainObject from 'lodash/isPlainObject.js'; /** diff --git a/code/core/src/preview-api/modules/store/sortStories.ts b/code/core/src/preview-api/modules/store/sortStories.ts index e1a5db96a16e..39cb86efcc21 100644 --- a/code/core/src/preview-api/modules/store/sortStories.ts +++ b/code/core/src/preview-api/modules/store/sortStories.ts @@ -1,5 +1,3 @@ -import { dedent } from 'ts-dedent'; -import { storySort } from './storySort'; import type { IndexEntry, StoryIndexEntry } from '@storybook/core/types'; import type { Addon_Comparator, @@ -7,9 +5,13 @@ import type { Addon_StorySortParameterV7, IndexEntryLegacy, } from '@storybook/core/types'; -import type { Path, Renderer, Parameters } from '@storybook/core/types'; +import type { Parameters, Path, Renderer } from '@storybook/core/types'; import type { PreparedStory } from '@storybook/core/types'; +import { dedent } from 'ts-dedent'; + +import { storySort } from './storySort'; + const sortStoriesCommon = ( stories: IndexEntry[], storySortParameter: Addon_StorySortParameterV7, diff --git a/code/core/src/preview-api/modules/store/storySort.test.ts b/code/core/src/preview-api/modules/store/storySort.test.ts index f41175aa156b..104ad3bb1c8d 100644 --- a/code/core/src/preview-api/modules/store/storySort.test.ts +++ b/code/core/src/preview-api/modules/store/storySort.test.ts @@ -1,4 +1,5 @@ -import { expect, describe, it } from 'vitest'; +import { describe, expect, it } from 'vitest'; + import type { StoryId, StoryIndexEntry } from '@storybook/core/types'; import { storySort } from './storySort'; diff --git a/code/core/src/preview-errors.ts b/code/core/src/preview-errors.ts index c1d070f7c10a..a50183f79ac4 100644 --- a/code/core/src/preview-errors.ts +++ b/code/core/src/preview-errors.ts @@ -1,4 +1,5 @@ import { dedent } from 'ts-dedent'; + import { StorybookError } from './storybook-error'; /** diff --git a/code/core/src/preview/globals/runtime.ts b/code/core/src/preview/globals/runtime.ts index a766e5cbac00..48418bc6de7e 100644 --- a/code/core/src/preview/globals/runtime.ts +++ b/code/core/src/preview/globals/runtime.ts @@ -1,11 +1,11 @@ +import * as CHANNELS from '@storybook/core/channels'; +import * as TYPES from '@storybook/core/types'; import * as GLOBAL from '@storybook/global'; -import * as CHANNELS from '@storybook/core/channels'; import * as CLIENT_LOGGER from '@storybook/core/client-logger'; import * as CORE_EVENTS from '@storybook/core/core-events'; -import * as CORE_EVENTS_PREVIEW_ERRORS from '@storybook/core/preview-errors'; import * as PREVIEW_API from '@storybook/core/preview-api'; -import * as TYPES from '@storybook/core/types'; +import * as CORE_EVENTS_PREVIEW_ERRORS from '@storybook/core/preview-errors'; import type { globalsNameReferenceMap } from './globals'; diff --git a/code/core/src/preview/runtime.ts b/code/core/src/preview/runtime.ts index 67accbf97977..45ca3083ae6b 100644 --- a/code/core/src/preview/runtime.ts +++ b/code/core/src/preview/runtime.ts @@ -1,8 +1,9 @@ -import { TELEMETRY_ERROR } from '@storybook/core/core-events'; import { global } from '@storybook/global'; + +import { TELEMETRY_ERROR } from '@storybook/core/core-events'; + import { globalPackages, globalsNameReferenceMap } from './globals/globals'; import { globalsNameValueMap } from './globals/runtime'; - import { prepareForTelemetry } from './utils'; // Apply all the globals diff --git a/code/core/src/preview/utils.ts b/code/core/src/preview/utils.ts index b3f77adc4e04..0b5e46ad91c6 100644 --- a/code/core/src/preview/utils.ts +++ b/code/core/src/preview/utils.ts @@ -1,4 +1,5 @@ import { global } from '@storybook/global'; + import type { BrowserInfo } from 'browser-dtector'; import BrowserDetector from 'browser-dtector'; diff --git a/code/core/src/router/router.tsx b/code/core/src/router/router.tsx index f2e44437b001..00834debee3e 100644 --- a/code/core/src/router/router.tsx +++ b/code/core/src/router/router.tsx @@ -1,10 +1,12 @@ -import { global } from '@storybook/global'; import React, { useCallback } from 'react'; -import type { ReactNode, ReactElement, ComponentProps } from 'react'; +import type { ComponentProps, ReactElement, ReactNode } from 'react'; + +import { global } from '@storybook/global'; import * as R from 'react-router-dom'; -import { queryFromString, parsePath, getMatch } from './utils'; + import type { LinkProps, NavigateOptions, RenderData } from './types'; +import { getMatch, parsePath, queryFromString } from './utils'; const { document } = global; diff --git a/code/core/src/router/types.ts b/code/core/src/router/types.ts index c601e68c290d..a181dafcbecc 100644 --- a/code/core/src/router/types.ts +++ b/code/core/src/router/types.ts @@ -1,5 +1,7 @@ -import type * as R from 'react-router-dom'; import type { ReactNode } from 'react'; + +import type * as R from 'react-router-dom'; + import type { StoryData } from './utils'; export interface Other extends StoryData { diff --git a/code/core/src/router/utils.test.ts b/code/core/src/router/utils.test.ts index 00df97fc4ca4..784fc204d6d6 100644 --- a/code/core/src/router/utils.test.ts +++ b/code/core/src/router/utils.test.ts @@ -1,5 +1,6 @@ -import { describe, it, expect, vi } from 'vitest'; -import { buildArgsParam, deepDiff, DEEPLY_EQUAL, getMatch, parsePath } from './utils'; +import { describe, expect, it, vi } from 'vitest'; + +import { DEEPLY_EQUAL, buildArgsParam, deepDiff, getMatch, parsePath } from './utils'; vi.mock('@storybook/core/client-logger', () => ({ once: { warn: vi.fn() }, diff --git a/code/core/src/router/utils.ts b/code/core/src/router/utils.ts index 57f3b3389b7b..fac4ecee479f 100644 --- a/code/core/src/router/utils.ts +++ b/code/core/src/router/utils.ts @@ -1,4 +1,5 @@ import { once } from '@storybook/core/client-logger'; + import { dequal as deepEqual } from 'dequal'; import isPlainObject from 'lodash/isPlainObject.js'; import memoize from 'memoizerific'; diff --git a/code/core/src/server-errors.ts b/code/core/src/server-errors.ts index 54cc3d3e0b02..23e203f27ddb 100644 --- a/code/core/src/server-errors.ts +++ b/code/core/src/server-errors.ts @@ -1,5 +1,6 @@ import chalk from 'chalk'; import { dedent } from 'ts-dedent'; + import { StorybookError } from './storybook-error'; /** diff --git a/code/core/src/telemetry/anonymous-id.test.ts b/code/core/src/telemetry/anonymous-id.test.ts index 01caff1cd1fe..6606f43cabc2 100644 --- a/code/core/src/telemetry/anonymous-id.test.ts +++ b/code/core/src/telemetry/anonymous-id.test.ts @@ -1,4 +1,5 @@ -import { describe, it, expect } from 'vitest'; +import { describe, expect, it } from 'vitest'; + import { normalizeGitUrl } from './anonymous-id'; describe('normalizeGitUrl', () => { diff --git a/code/core/src/telemetry/anonymous-id.ts b/code/core/src/telemetry/anonymous-id.ts index 7af263c2f569..c97071c0d127 100644 --- a/code/core/src/telemetry/anonymous-id.ts +++ b/code/core/src/telemetry/anonymous-id.ts @@ -1,7 +1,9 @@ -import path from 'node:path'; -import { execSync } from 'child_process'; +import { relative } from 'node:path'; + import { getProjectRoot } from '@storybook/core/common'; +import { execSync } from 'child_process'; + import { oneWayHash } from './one-way-hash'; export function normalizeGitUrl(rawUrl: string) { @@ -27,7 +29,7 @@ export const getAnonymousProjectId = () => { try { const projectRoot = getProjectRoot(); - const projectRootPath = path.relative(projectRoot, process.cwd()); + const projectRootPath = relative(projectRoot, process.cwd()); const originBuffer = execSync(`git config --local --get remote.origin.url`, { timeout: 1000, diff --git a/code/core/src/telemetry/event-cache.test.ts b/code/core/src/telemetry/event-cache.test.ts index 788fb5270c64..d7ffb38d0c5d 100644 --- a/code/core/src/telemetry/event-cache.test.ts +++ b/code/core/src/telemetry/event-cache.test.ts @@ -1,4 +1,5 @@ -import { describe, it, expect } from 'vitest'; +import { describe, expect, it } from 'vitest'; + import { getPrecedingUpgrade } from './event-cache'; expect.addSnapshotSerializer({ diff --git a/code/core/src/telemetry/event-cache.ts b/code/core/src/telemetry/event-cache.ts index 144a083dff9c..d6a0d688e626 100644 --- a/code/core/src/telemetry/event-cache.ts +++ b/code/core/src/telemetry/event-cache.ts @@ -1,4 +1,5 @@ import { cache } from '@storybook/core/common'; + import type { EventType } from './types'; interface UpgradeSummary { diff --git a/code/core/src/telemetry/get-chromatic-version.test.ts b/code/core/src/telemetry/get-chromatic-version.test.ts index 85627012c799..b99d48bc32c1 100644 --- a/code/core/src/telemetry/get-chromatic-version.test.ts +++ b/code/core/src/telemetry/get-chromatic-version.test.ts @@ -1,4 +1,5 @@ -import { it, expect } from 'vitest'; +import { expect, it } from 'vitest'; + import { getChromaticVersionSpecifier } from './get-chromatic-version'; it('works for dependencies', () => { diff --git a/code/core/src/telemetry/get-framework-info.test.ts b/code/core/src/telemetry/get-framework-info.test.ts index 4bcd80f5c6b0..e95e643dc8b1 100644 --- a/code/core/src/telemetry/get-framework-info.test.ts +++ b/code/core/src/telemetry/get-framework-info.test.ts @@ -1,6 +1,9 @@ -import { describe, it, expect, vi } from 'vitest'; +import { sep } from 'node:path'; + +import { describe, expect, it, vi } from 'vitest'; + import type { StorybookConfig } from '@storybook/core/types'; -import path from 'node:path'; + import { getFrameworkInfo } from './get-framework-info'; import { getActualPackageJson } from './package-json'; @@ -27,7 +30,7 @@ describe('getFrameworkInfo', () => { }); it('should resolve the framework package json correctly and strip project paths in the metadata', async () => { - const packageName = `${process.cwd()}/@storybook/react`.split('/').join(path.sep); + const packageName = `${process.cwd()}/@storybook/react`.split('/').join(sep); const framework = { name: packageName }; const frameworkPackageJson = { name: packageName, @@ -45,7 +48,7 @@ describe('getFrameworkInfo', () => { expect(result).toEqual({ framework: { - name: '$SNIP/@storybook/react'.split('/').join(path.sep), + name: '$SNIP/@storybook/react'.split('/').join(sep), options: undefined, }, builder: '@storybook/builder-vite', diff --git a/code/core/src/telemetry/get-framework-info.ts b/code/core/src/telemetry/get-framework-info.ts index 162a9cad63f5..d5b3390128ea 100644 --- a/code/core/src/telemetry/get-framework-info.ts +++ b/code/core/src/telemetry/get-framework-info.ts @@ -1,8 +1,10 @@ -import type { PackageJson, StorybookConfig } from '@storybook/core/types'; -import path from 'node:path'; +import { normalize } from 'node:path'; + import { frameworkPackages } from '@storybook/core/common'; -import { cleanPaths } from './sanitize'; +import type { PackageJson, StorybookConfig } from '@storybook/core/types'; + import { getActualPackageJson } from './package-json'; +import { cleanPaths } from './sanitize'; const knownRenderers = [ 'html', @@ -34,7 +36,7 @@ function findMatchingPackage(packageJson: PackageJson, suffixes: string[]) { } export const getFrameworkPackageName = (packageNameOrPath: string) => { - const normalizedPath = path.normalize(packageNameOrPath).replace(new RegExp(/\\/, 'g'), '/'); + const normalizedPath = normalize(packageNameOrPath).replace(new RegExp(/\\/, 'g'), '/'); const knownFramework = Object.keys(frameworkPackages).find((pkg) => normalizedPath.endsWith(pkg)); diff --git a/code/core/src/telemetry/get-monorepo-type.test.ts b/code/core/src/telemetry/get-monorepo-type.test.ts index 1a717d4b4fc4..530da9f4abc9 100644 --- a/code/core/src/telemetry/get-monorepo-type.test.ts +++ b/code/core/src/telemetry/get-monorepo-type.test.ts @@ -1,7 +1,9 @@ /* eslint-disable no-underscore-dangle */ -import { describe, it, expect, vi } from 'vitest'; +import { join } from 'node:path'; + +import { describe, expect, it, vi } from 'vitest'; + import * as fsExtra from 'fs-extra'; -import path from 'node:path'; import { getMonorepoType, monorepoConfigs } from './get-monorepo-type'; @@ -16,11 +18,11 @@ vi.mock('@storybook/core/common', async (importOriginal) => { const checkMonorepoType = ({ monorepoConfigFile, isYarnWorkspace = false }: any) => { const mockFiles = { - [path.join('root', 'package.json')]: isYarnWorkspace ? '{ "workspaces": [] }' : '{}', + [join('root', 'package.json')]: isYarnWorkspace ? '{ "workspaces": [] }' : '{}', }; if (monorepoConfigFile) { - mockFiles[path.join('root', monorepoConfigFile)] = '{}'; + mockFiles[join('root', monorepoConfigFile)] = '{}'; } vi.mocked(fsExtra as any).__setMockFiles(mockFiles); diff --git a/code/core/src/telemetry/get-monorepo-type.ts b/code/core/src/telemetry/get-monorepo-type.ts index 33dfc9eea1ac..e1602f6cf4b2 100644 --- a/code/core/src/telemetry/get-monorepo-type.ts +++ b/code/core/src/telemetry/get-monorepo-type.ts @@ -1,7 +1,9 @@ -import { existsSync, readJsonSync } from 'fs-extra'; -import path from 'node:path'; -import type { PackageJson } from '@storybook/core/types'; +import { join } from 'node:path'; + import { getProjectRoot } from '@storybook/core/common'; +import type { PackageJson } from '@storybook/core/types'; + +import { existsSync, readJsonSync } from 'fs-extra'; export const monorepoConfigs = { Nx: 'nx.json', @@ -19,7 +21,7 @@ export const getMonorepoType = (): MonorepoType => { const keys = Object.keys(monorepoConfigs) as (keyof typeof monorepoConfigs)[]; const monorepoType: MonorepoType = keys.find((monorepo) => { - const configFile = path.join(projectRootPath, monorepoConfigs[monorepo]); + const configFile = join(projectRootPath, monorepoConfigs[monorepo]); return existsSync(configFile); }) as MonorepoType; @@ -27,11 +29,11 @@ export const getMonorepoType = (): MonorepoType => { return monorepoType; } - if (!existsSync(path.join(projectRootPath, 'package.json'))) { + if (!existsSync(join(projectRootPath, 'package.json'))) { return undefined; } - const packageJson = readJsonSync(path.join(projectRootPath, 'package.json')) as PackageJson; + const packageJson = readJsonSync(join(projectRootPath, 'package.json')) as PackageJson; if (packageJson?.workspaces) { return 'Workspaces'; diff --git a/code/core/src/telemetry/get-portable-stories-usage.test.ts b/code/core/src/telemetry/get-portable-stories-usage.test.ts new file mode 100644 index 000000000000..8fa4c9292607 --- /dev/null +++ b/code/core/src/telemetry/get-portable-stories-usage.test.ts @@ -0,0 +1,15 @@ +import { join } from 'node:path'; + +import { describe, expect, it } from 'vitest'; + +import { getPortableStoriesFileCountUncached } from './get-portable-stories-usage'; + +const mocksDir = join(__dirname, '..', '__mocks__'); + +describe('getPortableStoriesFileCountUncached', () => { + it('should ignores node_modules, non-source files', async () => { + const usage = await getPortableStoriesFileCountUncached(mocksDir); + // you can verify with: `git grep -m1 -c composeStor | wc -l` + expect(usage).toMatchInlineSnapshot(`2`); + }); +}); diff --git a/code/core/src/telemetry/get-portable-stories-usage.ts b/code/core/src/telemetry/get-portable-stories-usage.ts new file mode 100644 index 000000000000..a6b92019d00e --- /dev/null +++ b/code/core/src/telemetry/get-portable-stories-usage.ts @@ -0,0 +1,35 @@ +import { execaCommand } from 'execa'; + +import { createFileSystemCache, resolvePathInStorybookCache } from '../common'; + +const cache = createFileSystemCache({ + basePath: resolvePathInStorybookCache('portable-stories'), + ns: 'storybook', + ttl: 24 * 60 * 60 * 1000, // 24h +}); + +export const getPortableStoriesFileCountUncached = async (path?: string) => { + const command = `git grep -m1 -c composeStor` + (path ? ` -- ${path}` : ''); + const { stdout } = await execaCommand(command, { + cwd: process.cwd(), + shell: true, + }); + return stdout.split('\n').filter(Boolean).length; +}; + +const CACHE_KEY = 'portableStories'; +export const getPortableStoriesFileCount = async (path?: string) => { + let cached = await cache.get(CACHE_KEY); + if (!cached) { + try { + const count = await getPortableStoriesFileCountUncached(); + cached = { count }; + await cache.set(CACHE_KEY, cached); + } catch (err: any) { + // exit code 1 if no matches are found + const count = err.exitCode === 1 ? 0 : null; + cached = { count }; + } + } + return cached.count; +}; diff --git a/code/core/src/telemetry/index.ts b/code/core/src/telemetry/index.ts index d8286d0b7535..7af6810f6afb 100644 --- a/code/core/src/telemetry/index.ts +++ b/code/core/src/telemetry/index.ts @@ -1,9 +1,10 @@ import { logger } from '@storybook/core/node-logger'; -import type { EventType, Payload, Options, TelemetryData } from './types'; -import { getStorybookMetadata } from './storybook-metadata'; -import { sendTelemetry } from './telemetry'; + import { notify } from './notify'; import { sanitizeError } from './sanitize'; +import { getStorybookMetadata } from './storybook-metadata'; +import { sendTelemetry } from './telemetry'; +import type { EventType, Options, Payload, TelemetryData } from './types'; export { oneWayHash } from './one-way-hash'; @@ -15,6 +16,15 @@ export { getPrecedingUpgrade } from './event-cache'; export { addToGlobalContext } from './telemetry'; +/** + * Is this story part of the CLI generated examples, + * including user-created stories in those files + */ +export const isExampleStoryId = (storyId: string) => + storyId.startsWith('example-button--') || + storyId.startsWith('example-header--') || + storyId.startsWith('example-page--'); + export const telemetry = async ( eventType: EventType, payload: Payload = {}, diff --git a/code/core/src/telemetry/notify.ts b/code/core/src/telemetry/notify.ts index 97ebe63d8619..171d48ae671f 100644 --- a/code/core/src/telemetry/notify.ts +++ b/code/core/src/telemetry/notify.ts @@ -1,6 +1,7 @@ -import chalk from 'chalk'; import { cache } from '@storybook/core/common'; +import chalk from 'chalk'; + const TELEMETRY_KEY_NOTIFY_DATE = 'telemetry-notification-date'; const logger = console; diff --git a/code/core/src/telemetry/package-json.ts b/code/core/src/telemetry/package-json.ts index df61f0e71a41..b88ebc237ddc 100644 --- a/code/core/src/telemetry/package-json.ts +++ b/code/core/src/telemetry/package-json.ts @@ -1,5 +1,6 @@ +import { join } from 'node:path'; + import { readJson } from 'fs-extra'; -import path from 'node:path'; import type { Dependency } from './types'; @@ -21,7 +22,7 @@ export const getActualPackageVersion = async (packageName: string) => { }; export const getActualPackageJson = async (packageName: string) => { - const resolvedPackageJson = require.resolve(path.join(packageName, 'package.json'), { + const resolvedPackageJson = require.resolve(join(packageName, 'package.json'), { paths: [process.cwd()], }); const packageJson = await readJson(resolvedPackageJson); diff --git a/code/core/src/telemetry/sanitize.test.ts b/code/core/src/telemetry/sanitize.test.ts index 659ed647362f..d5cac7d16f5c 100644 --- a/code/core/src/telemetry/sanitize.test.ts +++ b/code/core/src/telemetry/sanitize.test.ts @@ -1,5 +1,6 @@ -import { describe, it, expect, vi } from 'vitest'; -import { sanitizeError, cleanPaths } from './sanitize'; +import { describe, expect, it, vi } from 'vitest'; + +import { cleanPaths, sanitizeError } from './sanitize'; describe(`Errors Helpers`, () => { describe(`sanitizeError`, () => { diff --git a/code/core/src/telemetry/session-id.test.ts b/code/core/src/telemetry/session-id.test.ts index 78313fefb305..cff48bfa6dda 100644 --- a/code/core/src/telemetry/session-id.test.ts +++ b/code/core/src/telemetry/session-id.test.ts @@ -1,8 +1,11 @@ import type { MockInstance } from 'vitest'; -import { describe, it, beforeEach, expect, vi } from 'vitest'; -import { nanoid } from 'nanoid'; +import { beforeEach, describe, expect, it, vi } from 'vitest'; + import { cache } from '@storybook/core/common'; -import { resetSessionIdForTest, getSessionId, SESSION_TIMEOUT } from './session-id'; + +import { nanoid } from 'nanoid'; + +import { SESSION_TIMEOUT, getSessionId, resetSessionIdForTest } from './session-id'; vi.mock('@storybook/core/common', async (importOriginal) => ({ ...(await importOriginal()), diff --git a/code/core/src/telemetry/session-id.ts b/code/core/src/telemetry/session-id.ts index 36a92fe7cdf5..3029855c5cee 100644 --- a/code/core/src/telemetry/session-id.ts +++ b/code/core/src/telemetry/session-id.ts @@ -1,6 +1,7 @@ -import { nanoid } from 'nanoid'; import { cache } from '@storybook/core/common'; +import { nanoid } from 'nanoid'; + export const SESSION_TIMEOUT = 1000 * 60 * 60 * 2; // 2h interface Session { diff --git a/code/core/src/telemetry/storybook-metadata.test.ts b/code/core/src/telemetry/storybook-metadata.test.ts index 3476aaeff1c0..06bf355c0688 100644 --- a/code/core/src/telemetry/storybook-metadata.test.ts +++ b/code/core/src/telemetry/storybook-metadata.test.ts @@ -1,8 +1,10 @@ +import path from 'node:path'; + import type { MockInstance } from 'vitest'; -import { describe, beforeEach, afterEach, expect, vi, it } from 'vitest'; +import { afterEach, beforeEach, describe, expect, it, vi } from 'vitest'; + import type { PackageJson, StorybookConfig } from '@storybook/core/types'; -import path from 'node:path'; import { computeStorybookMetadata, metaFrameworks, sanitizeAddonName } from './storybook-metadata'; const packageJsonMock: PackageJson = { diff --git a/code/core/src/telemetry/storybook-metadata.ts b/code/core/src/telemetry/storybook-metadata.ts index 47601d394dad..75804b813fc2 100644 --- a/code/core/src/telemetry/storybook-metadata.ts +++ b/code/core/src/telemetry/storybook-metadata.ts @@ -1,20 +1,23 @@ -import { findPackage } from 'fd-package-json'; -import { detect, getNpmVersion } from 'detect-package-manager'; import { - loadMainConfig, - getStorybookInfo, - getStorybookConfiguration, getProjectRoot, + getStorybookConfiguration, + getStorybookInfo, + loadMainConfig, } from '@storybook/core/common'; -import type { StorybookConfig, PackageJson } from '@storybook/core/types'; +import type { PackageJson, StorybookConfig } from '@storybook/core/types'; + import { readConfig } from '@storybook/core/csf-tools'; -import type { StorybookMetadata, Dependency, StorybookAddon } from './types'; -import { getActualPackageVersion, getActualPackageVersions } from './package-json'; +import { detect, getNpmVersion } from 'detect-package-manager'; +import { findPackage } from 'fd-package-json'; + +import { getChromaticVersionSpecifier } from './get-chromatic-version'; +import { getFrameworkInfo } from './get-framework-info'; import { getMonorepoType } from './get-monorepo-type'; +import { getPortableStoriesFileCount } from './get-portable-stories-usage'; +import { getActualPackageVersion, getActualPackageVersions } from './package-json'; import { cleanPaths } from './sanitize'; -import { getFrameworkInfo } from './get-framework-info'; -import { getChromaticVersionSpecifier } from './get-chromatic-version'; +import type { Dependency, StorybookAddon, StorybookMetadata } from './types'; export const metaFrameworks = { next: 'Next', @@ -205,10 +208,12 @@ export const computeStorybookMetadata = async ({ } const storybookVersion = storybookPackages[storybookInfo.frameworkPackage]?.version; + const portableStoriesFileCount = await getPortableStoriesFileCount(); return { ...metadata, ...frameworkInfo, + portableStoriesFileCount, storybookVersion, storybookVersionSpecifier: storybookInfo.version, language, diff --git a/code/core/src/telemetry/telemetry.test.ts b/code/core/src/telemetry/telemetry.test.ts index 8b13b94dcf6d..b5ff3fb4caa1 100644 --- a/code/core/src/telemetry/telemetry.test.ts +++ b/code/core/src/telemetry/telemetry.test.ts @@ -1,7 +1,6 @@ -import { fetch } from './fetch'; - -import { beforeEach, it, expect, vi } from 'vitest'; +import { beforeEach, expect, it, vi } from 'vitest'; +import { fetch } from './fetch'; import { sendTelemetry } from './telemetry'; vi.mock('./fetch'); diff --git a/code/core/src/telemetry/telemetry.ts b/code/core/src/telemetry/telemetry.ts index 6b3655201065..90b0eaa4d9dc 100644 --- a/code/core/src/telemetry/telemetry.ts +++ b/code/core/src/telemetry/telemetry.ts @@ -1,13 +1,13 @@ /// - -import * as os from 'os'; -import { nanoid } from 'nanoid'; import retry from 'fetch-retry'; -import type { Options, TelemetryData } from './types'; +import { nanoid } from 'nanoid'; +import * as os from 'os'; + import { getAnonymousProjectId } from './anonymous-id'; import { set as saveToCache } from './event-cache'; -import { getSessionId } from './session-id'; import { fetch } from './fetch'; +import { getSessionId } from './session-id'; +import type { Options, TelemetryData } from './types'; const retryingFetch = retry(fetch); diff --git a/code/core/src/telemetry/types.ts b/code/core/src/telemetry/types.ts index 553c6729d26b..699a8da6e83b 100644 --- a/code/core/src/telemetry/types.ts +++ b/code/core/src/telemetry/types.ts @@ -1,4 +1,5 @@ import type { StorybookConfig, TypescriptOptions } from '@storybook/core/types'; + import type { PM } from 'detect-package-manager'; import type { MonorepoType } from './get-monorepo-type'; @@ -64,6 +65,7 @@ export type StorybookMetadata = { preview?: { usesGlobals?: boolean; }; + portableStoriesFileCount?: number; }; export interface Payload { diff --git a/code/core/src/theming/convert.ts b/code/core/src/theming/convert.ts index 9765adc03d61..1336c029493f 100644 --- a/code/core/src/theming/convert.ts +++ b/code/core/src/theming/convert.ts @@ -1,10 +1,11 @@ import { opacify } from 'polished'; -import { background, typography, color } from './base'; + +import { animation, easing } from './animation'; +import { background, color, typography } from './base'; +import { themes } from './create'; +import { chromeDark, chromeLight, create as createSyntax } from './modules/syntax'; import type { Color, StorybookTheme, ThemeVars, ThemeVarsColors } from './types'; -import { easing, animation } from './animation'; -import { create as createSyntax, chromeLight, chromeDark } from './modules/syntax'; import { getPreferredColorScheme } from './utils'; -import { themes } from './create'; const lightSyntaxColors = { green1: '#008000', diff --git a/code/core/src/theming/create.ts b/code/core/src/theming/create.ts index d28769b5eb06..b5f97a34aee5 100644 --- a/code/core/src/theming/create.ts +++ b/code/core/src/theming/create.ts @@ -1,7 +1,6 @@ // This generates theme variables in the correct shape for the UI -import lightThemeVars from './themes/light'; import darkThemeVars from './themes/dark'; - +import lightThemeVars from './themes/light'; import type { ThemeVars, ThemeVarsPartial } from './types'; import { getPreferredColorScheme } from './utils'; diff --git a/code/core/src/theming/emotionAugmentation.d.ts b/code/core/src/theming/emotionAugmentation.d.ts index d5ceb8b427f6..92cfd3ccf585 100644 --- a/code/core/src/theming/emotionAugmentation.d.ts +++ b/code/core/src/theming/emotionAugmentation.d.ts @@ -1,6 +1,5 @@ // this file is only actually used in development // for prod/dist bundles we are bundling Emotion into our package - import '@emotion/react'; declare module '@emotion/react' { diff --git a/code/core/src/theming/ensure.ts b/code/core/src/theming/ensure.ts index 6ee5298e45cd..39e3ee7e9d00 100644 --- a/code/core/src/theming/ensure.ts +++ b/code/core/src/theming/ensure.ts @@ -3,9 +3,9 @@ import { logger } from '@storybook/core/client-logger'; import { deletedDiff } from 'deep-object-diff'; import { dedent } from 'ts-dedent'; -import light from './themes/light'; -import type { ThemeVars, StorybookTheme } from './types'; import { convert } from './convert'; +import light from './themes/light'; +import type { StorybookTheme, ThemeVars } from './types'; export const ensure = (input: ThemeVars): StorybookTheme => { if (!input) { diff --git a/code/core/src/theming/global.ts b/code/core/src/theming/global.ts index 499d59cb2240..2f22bcb77e0f 100644 --- a/code/core/src/theming/global.ts +++ b/code/core/src/theming/global.ts @@ -1,5 +1,6 @@ import memoize from 'memoizerific'; -import type { Color, Background, Typography } from './types'; + +import type { Background, Color, Typography } from './types'; type Value = string | number; interface Return { diff --git a/code/core/src/theming/index.ts b/code/core/src/theming/index.ts index c533e8387803..8fa92ea794f9 100644 --- a/code/core/src/theming/index.ts +++ b/code/core/src/theming/index.ts @@ -1,7 +1,7 @@ /// /// - import type { FunctionInterpolation, Interpolation } from '@emotion/react'; + import type { StorybookTheme } from './types'; export { default as styled } from '@emotion/styled'; diff --git a/code/core/src/theming/tests/convert.test.js b/code/core/src/theming/tests/convert.test.js index 80a2512cb4d1..779bbd0349d3 100644 --- a/code/core/src/theming/tests/convert.test.js +++ b/code/core/src/theming/tests/convert.test.js @@ -1,4 +1,5 @@ -import { describe, it, expect } from 'vitest'; +import { describe, expect, it } from 'vitest'; + import { convert } from '../convert'; import { create } from '../create'; import darkThemeVars from '../themes/dark'; diff --git a/code/core/src/theming/tests/create.test.js b/code/core/src/theming/tests/create.test.js index b5f037e0a2e0..524a424e6df0 100644 --- a/code/core/src/theming/tests/create.test.js +++ b/code/core/src/theming/tests/create.test.js @@ -1,4 +1,5 @@ -import { describe, it, expect } from 'vitest'; +import { describe, expect, it } from 'vitest'; + import { create } from '../create'; describe('create base', () => { diff --git a/code/core/src/theming/tests/util.test.js b/code/core/src/theming/tests/util.test.js index f3e38f694e83..c20fccd30414 100644 --- a/code/core/src/theming/tests/util.test.js +++ b/code/core/src/theming/tests/util.test.js @@ -1,7 +1,7 @@ // @vitest-environment happy-dom +import { describe, expect, it, vi } from 'vitest'; -import { describe, it, expect, vi } from 'vitest'; -import { lightenColor as lighten, darkenColor as darken, getPreferredColorScheme } from '../utils'; +import { darkenColor as darken, getPreferredColorScheme, lightenColor as lighten } from '../utils'; describe('utils', () => { it('should apply polished when valid arguments are passed', () => { diff --git a/code/core/src/theming/themes/light.ts b/code/core/src/theming/themes/light.ts index 75d83f1e740a..a5bf4def7e9c 100644 --- a/code/core/src/theming/themes/light.ts +++ b/code/core/src/theming/themes/light.ts @@ -1,4 +1,4 @@ -import { color, typography, background } from '../base'; +import { background, color, typography } from '../base'; import type { ThemeVars } from '../types'; const theme: ThemeVars = { diff --git a/code/core/src/theming/types.ts b/code/core/src/theming/types.ts index e7c2827792cb..1f386bfebd8a 100644 --- a/code/core/src/theming/types.ts +++ b/code/core/src/theming/types.ts @@ -1,6 +1,5 @@ -import type { easing, animation } from './animation'; - -import type { color, background, typography } from './base'; +import type { animation, easing } from './animation'; +import type { background, color, typography } from './base'; export interface ThemeVars extends ThemeVarsBase, ThemeVarsColors {} diff --git a/code/core/src/theming/utils.ts b/code/core/src/theming/utils.ts index 2f8cb1c82301..f51a4f3473a5 100644 --- a/code/core/src/theming/utils.ts +++ b/code/core/src/theming/utils.ts @@ -1,8 +1,9 @@ -import { rgba, lighten, darken } from 'polished'; import { global } from '@storybook/global'; import { logger } from '@storybook/core/client-logger'; +import { darken, lighten, rgba } from 'polished'; + const { window: globalWindow } = global; export const mkColor = (color: string) => ({ color }); diff --git a/code/core/src/types/modules/addons.ts b/code/core/src/types/modules/addons.ts index cc9d90251c2c..7dceb312cccc 100644 --- a/code/core/src/types/modules/addons.ts +++ b/code/core/src/types/modules/addons.ts @@ -1,6 +1,6 @@ /* eslint-disable @typescript-eslint/naming-convention */ - import type { FC, PropsWithChildren, ReactElement, ReactNode } from 'react'; + import type { RenderData as RouterData } from '../../router/types'; import type { ThemeVars } from '../../theming/types'; import type { API_SidebarOptions } from './api'; @@ -9,11 +9,11 @@ import type { ArgsStoryFn as ArgsStoryFnForFramework, DecoratorFunction as DecoratorFunctionForFramework, InputType, - Renderer, LegacyStoryFn as LegacyStoryFnForFramework, LoaderFunction as LoaderFunctionForFramework, Parameters, PartialStoryFn as PartialStoryFnForFramework, + Renderer, StoryContext as StoryContextForFramework, StoryFn as StoryFnForFramework, StoryId, diff --git a/code/core/src/types/modules/api-stories.ts b/code/core/src/types/modules/api-stories.ts index 90a6962c7d1c..7bde00d74f7b 100644 --- a/code/core/src/types/modules/api-stories.ts +++ b/code/core/src/types/modules/api-stories.ts @@ -1,6 +1,6 @@ /* eslint-disable @typescript-eslint/naming-convention */ import type { DocsOptions } from './core-common'; -import type { Args, ArgTypes, Parameters, ComponentTitle, StoryId, Path, Tag } from './csf'; +import type { ArgTypes, Args, ComponentTitle, Parameters, Path, StoryId, Tag } from './csf'; import type { IndexEntry } from './indexer'; export interface API_BaseEntry { diff --git a/code/core/src/types/modules/api.ts b/code/core/src/types/modules/api.ts index 86ba7bbd02dd..b338fc6ace69 100644 --- a/code/core/src/types/modules/api.ts +++ b/code/core/src/types/modules/api.ts @@ -1,13 +1,13 @@ /* eslint-disable @typescript-eslint/naming-convention */ - import type { ReactElement } from 'react'; -import type { RenderData } from '../../router/types'; + import type { Channel } from '../../channels'; +import type { RenderData } from '../../router/types'; import type { ThemeVars } from '../../theming/types'; -import type { DocsOptions } from './core-common'; +import type { Addon_RenderOptions } from './addons'; import type { API_FilterFunction, API_HashEntry, API_IndexHash } from './api-stories'; import type { SetStoriesStory, SetStoriesStoryData } from './channelApi'; -import type { Addon_RenderOptions } from './addons'; +import type { DocsOptions } from './core-common'; import type { StoryIndex } from './indexer'; type OrString = T | (string & {}); diff --git a/code/core/src/types/modules/channelApi.ts b/code/core/src/types/modules/channelApi.ts index 6c4f160a0831..6097b610854e 100644 --- a/code/core/src/types/modules/channelApi.ts +++ b/code/core/src/types/modules/channelApi.ts @@ -1,13 +1,13 @@ import type { API_ViewMode } from './api'; import type { - Args, ArgTypes, + Args, ComponentId, + GlobalTypes, + Globals, Parameters, StoryId, StoryKind, - Globals, - GlobalTypes, } from './csf'; // The data received on the (legacy) `setStories` event diff --git a/code/core/src/types/modules/composedStory.ts b/code/core/src/types/modules/composedStory.ts index ade2c302a999..7a5df854ff39 100644 --- a/code/core/src/types/modules/composedStory.ts +++ b/code/core/src/types/modules/composedStory.ts @@ -1,5 +1,4 @@ /* eslint-disable @typescript-eslint/naming-convention */ - import type { ProjectAnnotations, Renderer, diff --git a/code/core/src/types/modules/core-common.ts b/code/core/src/types/modules/core-common.ts index e7ee49c67109..1939ea25db3a 100644 --- a/code/core/src/types/modules/core-common.ts +++ b/code/core/src/types/modules/core-common.ts @@ -1,12 +1,12 @@ /* eslint-disable @typescript-eslint/naming-convention */ -import type { FileSystemCache } from 'file-system-cache'; -import type * as telejson from 'telejson'; import type { Router } from 'express'; +import type { FileSystemCache } from 'file-system-cache'; // should be node:http, but that caused the ui/manager to fail to build, might be able to switch this back once ui/manager is in the core import type { Server } from 'http'; +import type * as telejson from 'telejson'; import type { PackageJson as PackageJsonFromTypeFest } from 'type-fest'; -import type { StoriesEntry, Indexer } from './indexer'; +import type { Indexer, StoriesEntry } from './indexer'; /** * ⚠️ This file contains internal WIP types they MUST NOT be exported outside this package for now! diff --git a/code/core/src/types/modules/docs.ts b/code/core/src/types/modules/docs.ts index 9202ea64dcf4..386301e523e8 100644 --- a/code/core/src/types/modules/docs.ts +++ b/code/core/src/types/modules/docs.ts @@ -1,13 +1,14 @@ import type { Channel } from '@storybook/core/channels'; -import type { Renderer, StoryContext, StoryId, StoryName, Parameters } from './csf'; + +import type { Parameters, Renderer, StoryContext, StoryId, StoryName } from './csf'; import type { + CSFFile, ModuleExport, ModuleExports, - CSFFile, - PreparedStory, NormalizedProjectAnnotations, - RenderContext, PreparedMeta, + PreparedStory, + RenderContext, } from './story'; export type RenderContextCallbacks = Pick< diff --git a/code/core/src/types/modules/frameworks.ts b/code/core/src/types/modules/frameworks.ts index 9ae2cc538b51..246cea20ff9a 100644 --- a/code/core/src/types/modules/frameworks.ts +++ b/code/core/src/types/modules/frameworks.ts @@ -2,6 +2,7 @@ export type SupportedFrameworks = | 'angular' | 'ember' + | 'experimental-nextjs-vite' | 'html-vite' | 'html-webpack5' | 'nextjs' diff --git a/code/core/src/types/modules/indexer.ts b/code/core/src/types/modules/indexer.ts index 4e92b647a489..daf0ddb2a735 100644 --- a/code/core/src/types/modules/indexer.ts +++ b/code/core/src/types/modules/indexer.ts @@ -1,4 +1,4 @@ -import type { StoryId, ComponentTitle, StoryName, Parameters, Tag, Path } from './csf'; +import type { ComponentTitle, Parameters, Path, StoryId, StoryName, Tag } from './csf'; type ExportName = string; type MetaId = string; @@ -95,6 +95,7 @@ export interface IndexInputStats { mount?: boolean; beforeEach?: boolean; moduleMock?: boolean; + globals?: boolean; } /** diff --git a/code/core/src/types/modules/story.ts b/code/core/src/types/modules/story.ts index 2cbd803e5637..f8deb8c522f0 100644 --- a/code/core/src/types/modules/story.ts +++ b/code/core/src/types/modules/story.ts @@ -1,13 +1,13 @@ import type { - Renderer, + BeforeAll, + Canvas, + CleanupCallback, ProjectAnnotations as CsfProjectAnnotations, DecoratorFunction, + Globals, LoaderFunction, - CleanupCallback, + Renderer, StepRunner, - Canvas, - Globals, - BeforeAll, } from '@storybook/csf'; import type { diff --git a/code/core/src/typings.d.ts b/code/core/src/typings.d.ts index b8dce9296148..f969c50eddab 100644 --- a/code/core/src/typings.d.ts +++ b/code/core/src/typings.d.ts @@ -27,23 +27,6 @@ declare module 'lazy-universal-dotenv'; declare module 'open'; declare module 'pnp-webpack-plugin'; declare module 'react-inspector'; -// declare module 'detect-package-manager' { -// // copied from https://www.npmjs.com/package/detect-package-manager?activeTab=code -// // because -// declare type PM = 'npm' | 'yarn' | 'pnpm' | 'bun'; -// declare const detect: ({ -// cwd, -// includeGlobalBun, -// }?: { -// cwd?: string | undefined; -// includeGlobalBun?: boolean | undefined; -// }) => Promise; - -// declare function getNpmVersion(pm: PM): Promise; -// declare function clearCache(): void; - -// export { PM, clearCache, detect, getNpmVersion }; -// } declare var STORIES: any; diff --git a/code/core/template/stories/argMapping.stories.ts b/code/core/template/stories/argMapping.stories.ts index 169b68de9957..41575e931239 100644 --- a/code/core/template/stories/argMapping.stories.ts +++ b/code/core/template/stories/argMapping.stories.ts @@ -1,6 +1,6 @@ -import { global as globalThis } from '@storybook/global'; import type { PartialStoryFn, PlayFunctionContext, StoryContext } from '@storybook/core/types'; -import { within, expect } from '@storybook/test'; +import { global as globalThis } from '@storybook/global'; +import { expect, within } from '@storybook/test'; const arrows = { ArrowUp: { name: 'ArrowUp' }, diff --git a/code/core/template/stories/argTypes.stories.ts b/code/core/template/stories/argTypes.stories.ts index dd2a53bd68fa..6ad691324495 100644 --- a/code/core/template/stories/argTypes.stories.ts +++ b/code/core/template/stories/argTypes.stories.ts @@ -1,5 +1,5 @@ -import { global as globalThis } from '@storybook/global'; import type { PartialStoryFn, PlayFunctionContext, StoryContext } from '@storybook/core/types'; +import { global as globalThis } from '@storybook/global'; import { expect, within } from '@storybook/test'; export default { diff --git a/code/core/template/stories/args.stories.ts b/code/core/template/stories/args.stories.ts index ebe10a49240f..c5beee938600 100644 --- a/code/core/template/stories/args.stories.ts +++ b/code/core/template/stories/args.stories.ts @@ -1,13 +1,15 @@ -import { global as globalThis } from '@storybook/global'; import type { PartialStoryFn, PlayFunctionContext, StoryContext } from '@storybook/core/types'; -import { within, expect } from '@storybook/test'; -import pick from 'lodash/pick'; +import { global as globalThis } from '@storybook/global'; +import { expect, within } from '@storybook/test'; + import { + RESET_STORY_ARGS, STORY_ARGS_UPDATED, UPDATE_STORY_ARGS, - RESET_STORY_ARGS, } from '@storybook/core/core-events'; +import pick from 'lodash/pick'; + export default { component: globalThis.Components.Pre, args: { diff --git a/code/core/template/stories/autotitle.stories.ts b/code/core/template/stories/autotitle.stories.ts index 48997645b036..0a675faadec8 100644 --- a/code/core/template/stories/autotitle.stories.ts +++ b/code/core/template/stories/autotitle.stories.ts @@ -1,6 +1,6 @@ +import type { PlayFunctionContext } from '@storybook/core/types'; import { global as globalThis } from '@storybook/global'; import { expect } from '@storybook/test'; -import type { PlayFunctionContext } from '@storybook/core/types'; export default { component: globalThis.Components.Pre, diff --git a/code/core/template/stories/component-play.stories.ts b/code/core/template/stories/component-play.stories.ts index cff3803d85bc..0571cf37b324 100644 --- a/code/core/template/stories/component-play.stories.ts +++ b/code/core/template/stories/component-play.stories.ts @@ -1,6 +1,6 @@ -import { global as globalThis } from '@storybook/global'; import type { PartialStoryFn, PlayFunctionContext, StoryContext } from '@storybook/core/types'; -import { within, expect } from '@storybook/test'; +import { global as globalThis } from '@storybook/global'; +import { expect, within } from '@storybook/test'; export default { component: globalThis.Components.Pre, diff --git a/code/core/template/stories/decorators.stories.ts b/code/core/template/stories/decorators.stories.ts index df13c1088eb7..e04fbf5e6373 100644 --- a/code/core/template/stories/decorators.stories.ts +++ b/code/core/template/stories/decorators.stories.ts @@ -1,17 +1,18 @@ -import { global as globalThis } from '@storybook/global'; import type { ArgsStoryFn, PartialStoryFn, PlayFunctionContext, StoryContext, } from '@storybook/core/types'; -import { within, expect } from '@storybook/test'; -import { useEffect } from '@storybook/core/preview-api'; +import { global as globalThis } from '@storybook/global'; +import { expect, within } from '@storybook/test'; + import { + RESET_STORY_ARGS, STORY_ARGS_UPDATED, UPDATE_STORY_ARGS, - RESET_STORY_ARGS, } from '@storybook/core/core-events'; +import { useEffect } from '@storybook/core/preview-api'; export default { component: globalThis.Components.Pre, diff --git a/code/core/template/stories/globals.stories.ts b/code/core/template/stories/globals.stories.ts index 788e4dd53bd7..84a0c86d2ee2 100644 --- a/code/core/template/stories/globals.stories.ts +++ b/code/core/template/stories/globals.stories.ts @@ -1,6 +1,6 @@ -import { global as globalThis } from '@storybook/global'; import type { PartialStoryFn, PlayFunctionContext, StoryContext } from '@storybook/core/types'; -import { within, expect } from '@storybook/test'; +import { global as globalThis } from '@storybook/global'; +import { expect, within } from '@storybook/test'; export default { component: globalThis.Components.Pre, diff --git a/code/core/template/stories/hooks.stories.ts b/code/core/template/stories/hooks.stories.ts index a329903c364e..ce145288f147 100644 --- a/code/core/template/stories/hooks.stories.ts +++ b/code/core/template/stories/hooks.stories.ts @@ -1,7 +1,8 @@ -import { global as globalThis } from '@storybook/global'; import type { PartialStoryFn, PlayFunctionContext } from '@storybook/core/types'; +import { global as globalThis } from '@storybook/global'; +import { userEvent, within } from '@storybook/test'; + import { useEffect, useState } from '@storybook/core/preview-api'; -import { within, userEvent } from '@storybook/test'; export default { component: globalThis.Components.Button, diff --git a/code/core/template/stories/indexer.stories.ts b/code/core/template/stories/indexer.stories.ts index 94c0d7789d06..5468e698d3cb 100644 --- a/code/core/template/stories/indexer.stories.ts +++ b/code/core/template/stories/indexer.stories.ts @@ -1,6 +1,6 @@ -import { expect } from '@storybook/test'; -import { global as globalThis } from '@storybook/global'; import type { PlayFunctionContext } from '@storybook/core/types'; +import { global as globalThis } from '@storybook/global'; +import { expect } from '@storybook/test'; export default { component: globalThis.Components.Pre, diff --git a/code/core/template/stories/interleavedExports.stories.ts b/code/core/template/stories/interleavedExports.stories.ts index 60f88e7e6abc..25931c1fd094 100644 --- a/code/core/template/stories/interleavedExports.stories.ts +++ b/code/core/template/stories/interleavedExports.stories.ts @@ -1,5 +1,7 @@ import { global as globalThis } from '@storybook/global'; +import './import'; + export default { component: globalThis.Components.Pre, args: { text: 'Check that stories are processed OK' }, @@ -7,6 +9,4 @@ export default { export const Story1 = {}; -import './import'; - export const Story2 = {}; diff --git a/code/core/template/stories/loaders.stories.ts b/code/core/template/stories/loaders.stories.ts index 34ef7ebc84d5..37a4ac62c0c8 100644 --- a/code/core/template/stories/loaders.stories.ts +++ b/code/core/template/stories/loaders.stories.ts @@ -1,6 +1,6 @@ -import { global as globalThis } from '@storybook/global'; import type { PartialStoryFn, PlayFunctionContext, StoryContext } from '@storybook/core/types'; -import { within, expect } from '@storybook/test'; +import { global as globalThis } from '@storybook/global'; +import { expect, within } from '@storybook/test'; export default { component: globalThis.Components.Pre, diff --git a/code/core/template/stories/names.stories.ts b/code/core/template/stories/names.stories.ts index f81df30334dd..b89304a63f59 100644 --- a/code/core/template/stories/names.stories.ts +++ b/code/core/template/stories/names.stories.ts @@ -1,6 +1,6 @@ +import type { PlayFunctionContext } from '@storybook/core/types'; import { global as globalThis } from '@storybook/global'; import { expect } from '@storybook/test'; -import type { PlayFunctionContext } from '@storybook/core/types'; export default { component: globalThis.Components.Pre, diff --git a/code/core/template/stories/parameters.stories.ts b/code/core/template/stories/parameters.stories.ts index 702f039e9912..a4200444cd0e 100644 --- a/code/core/template/stories/parameters.stories.ts +++ b/code/core/template/stories/parameters.stories.ts @@ -1,6 +1,6 @@ -import { global as globalThis } from '@storybook/global'; import type { PartialStoryFn, PlayFunctionContext, StoryContext } from '@storybook/core/types'; -import { within, expect } from '@storybook/test'; +import { global as globalThis } from '@storybook/global'; +import { expect, within } from '@storybook/test'; export default { component: globalThis.Components.Pre, diff --git a/code/core/template/stories/rendering.stories.ts b/code/core/template/stories/rendering.stories.ts index 0ca4976ec2c2..7e03897e3c02 100644 --- a/code/core/template/stories/rendering.stories.ts +++ b/code/core/template/stories/rendering.stories.ts @@ -1,6 +1,7 @@ -import { global as globalThis } from '@storybook/global'; import type { PlayFunctionContext } from '@storybook/core/types'; -import { within, waitFor, expect } from '@storybook/test'; +import { global as globalThis } from '@storybook/global'; +import { expect, waitFor, within } from '@storybook/test'; + import { FORCE_REMOUNT, RESET_STORY_ARGS, diff --git a/code/core/template/stories/shortcuts.stories.ts b/code/core/template/stories/shortcuts.stories.ts index fa121866bab9..429d3a5f4147 100644 --- a/code/core/template/stories/shortcuts.stories.ts +++ b/code/core/template/stories/shortcuts.stories.ts @@ -1,11 +1,16 @@ +import type { PlayFunctionContext } from '@storybook/csf'; import { global as globalThis } from '@storybook/global'; -import { userEvent, within, expect, fn } from '@storybook/test'; +import { expect, fn, userEvent, within } from '@storybook/test'; + import { PREVIEW_KEYDOWN } from '@storybook/core/core-events'; -import type { PlayFunctionContext } from '@storybook/csf'; export default { component: globalThis.Components.Form, tags: ['autodocs'], + args: { + onSubmit: fn(), + onSuccess: fn(), + }, }; export const KeydownDuringPlay = { diff --git a/code/core/template/stories/tags-add.stories.ts b/code/core/template/stories/tags-add.stories.ts index e7ed51cb5126..9a04ebe25bd4 100644 --- a/code/core/template/stories/tags-add.stories.ts +++ b/code/core/template/stories/tags-add.stories.ts @@ -1,6 +1,6 @@ -import { global as globalThis } from '@storybook/global'; import type { PartialStoryFn, PlayFunctionContext, StoryContext } from '@storybook/core/types'; -import { within, expect } from '@storybook/test'; +import { global as globalThis } from '@storybook/global'; +import { expect, within } from '@storybook/test'; export default { component: globalThis.Components.Pre, diff --git a/code/core/template/stories/tags-config.stories.ts b/code/core/template/stories/tags-config.stories.ts index 5a009e63213d..9d7b70f8478a 100644 --- a/code/core/template/stories/tags-config.stories.ts +++ b/code/core/template/stories/tags-config.stories.ts @@ -1,6 +1,6 @@ -import { global as globalThis } from '@storybook/global'; import type { PartialStoryFn, PlayFunctionContext, StoryContext } from '@storybook/core/types'; -import { within, expect } from '@storybook/test'; +import { global as globalThis } from '@storybook/global'; +import { expect, within } from '@storybook/test'; export default { component: globalThis.Components.Pre, diff --git a/code/core/template/stories/tags-remove.stories.ts b/code/core/template/stories/tags-remove.stories.ts index 949dab96d68f..f0148e6fb5b5 100644 --- a/code/core/template/stories/tags-remove.stories.ts +++ b/code/core/template/stories/tags-remove.stories.ts @@ -1,6 +1,6 @@ -import { global as globalThis } from '@storybook/global'; import type { PartialStoryFn, PlayFunctionContext, StoryContext } from '@storybook/core/types'; -import { within, expect } from '@storybook/test'; +import { global as globalThis } from '@storybook/global'; +import { expect, within } from '@storybook/test'; export default { component: globalThis.Components.Pre, diff --git a/code/core/template/stories/title.stories.ts b/code/core/template/stories/title.stories.ts index cd9eed6387be..deabd76f7623 100644 --- a/code/core/template/stories/title.stories.ts +++ b/code/core/template/stories/title.stories.ts @@ -1,6 +1,6 @@ +import type { PlayFunctionContext } from '@storybook/core/types'; import { global as globalThis } from '@storybook/global'; import { expect } from '@storybook/test'; -import type { PlayFunctionContext } from '@storybook/core/types'; export default { component: globalThis.Components.Pre, diff --git a/code/core/template/stories/utils.mock.ts b/code/core/template/stories/utils.mock.ts index bd3955dc0729..93a72d03a0e2 100644 --- a/code/core/template/stories/utils.mock.ts +++ b/code/core/template/stories/utils.mock.ts @@ -1,4 +1,5 @@ import { fn } from '@storybook/test'; + import * as utils from './utils.ts'; export const foo = fn(utils.foo).mockName('foo'); diff --git a/code/core/vitest.config.ts b/code/core/vitest.config.ts index b546d2ba6a40..df83dd4dc880 100644 --- a/code/core/vitest.config.ts +++ b/code/core/vitest.config.ts @@ -1,4 +1,5 @@ import { defineConfig, mergeConfig } from 'vitest/config'; + import { vitestCommonConfig } from '../vitest.workspace'; export default mergeConfig(vitestCommonConfig, defineConfig({})); diff --git a/code/deprecated/csf-tools/package.json b/code/deprecated/csf-tools/package.json index 6f2bc53cbf77..3f559726970a 100644 --- a/code/deprecated/csf-tools/package.json +++ b/code/deprecated/csf-tools/package.json @@ -23,9 +23,9 @@ "exports": { ".": { "types": "./shim.d.ts", - "node": "./shim.js", "import": "./shim.mjs", - "require": "./shim.js" + "require": "./shim.js", + "node": "./shim.js" }, "./package.json": "./package.json" }, diff --git a/code/deprecated/router/package.json b/code/deprecated/router/package.json index 582d0baf5b29..dd19a9b10dfa 100644 --- a/code/deprecated/router/package.json +++ b/code/deprecated/router/package.json @@ -23,9 +23,9 @@ "exports": { ".": { "types": "./shim.d.ts", - "node": "./shim.js", "import": "./shim.mjs", - "require": "./shim.js" + "require": "./shim.js", + "node": "./shim.js" }, "./utils": { "types": "./utils.d.ts", diff --git a/code/deprecated/theming/package.json b/code/deprecated/theming/package.json index d21e5f81cb7a..68ec61d65cea 100644 --- a/code/deprecated/theming/package.json +++ b/code/deprecated/theming/package.json @@ -23,9 +23,9 @@ "exports": { ".": { "types": "./shim.d.ts", - "node": "./shim.js", "import": "./shim.mjs", - "require": "./shim.js" + "require": "./shim.js", + "node": "./shim.js" }, "./create": { "types": "./create.d.ts", diff --git a/code/e2e-tests/addon-actions.spec.ts b/code/e2e-tests/addon-actions.spec.ts index a67aa8599ce9..6c3fa98034e6 100644 --- a/code/e2e-tests/addon-actions.spec.ts +++ b/code/e2e-tests/addon-actions.spec.ts @@ -1,5 +1,6 @@ -import { test, expect } from '@playwright/test'; +import { expect, test } from '@playwright/test'; import process from 'process'; + import { SbPage } from './util'; const storybookUrl = process.env.STORYBOOK_URL || 'http://localhost:8001'; diff --git a/code/e2e-tests/addon-backgrounds.spec.ts b/code/e2e-tests/addon-backgrounds.spec.ts index 2e0a4a0825b2..d40d922f8586 100644 --- a/code/e2e-tests/addon-backgrounds.spec.ts +++ b/code/e2e-tests/addon-backgrounds.spec.ts @@ -1,5 +1,6 @@ -import { test, expect } from '@playwright/test'; +import { expect, test } from '@playwright/test'; import process from 'process'; + import { SbPage } from './util'; const storybookUrl = process.env.STORYBOOK_URL || 'http://localhost:8001'; diff --git a/code/e2e-tests/addon-controls.spec.ts b/code/e2e-tests/addon-controls.spec.ts index 2c388d7ef598..6499ef6c0742 100644 --- a/code/e2e-tests/addon-controls.spec.ts +++ b/code/e2e-tests/addon-controls.spec.ts @@ -1,5 +1,6 @@ -import { test, expect } from '@playwright/test'; +import { expect, test } from '@playwright/test'; import process from 'process'; + import { SbPage } from './util'; const storybookUrl = process.env.STORYBOOK_URL || 'http://localhost:8001'; diff --git a/code/e2e-tests/addon-docs.spec.ts b/code/e2e-tests/addon-docs.spec.ts index a269bec909dd..cce2c23c6082 100644 --- a/code/e2e-tests/addon-docs.spec.ts +++ b/code/e2e-tests/addon-docs.spec.ts @@ -1,6 +1,7 @@ -import { test, expect } from '@playwright/test'; +import { expect, test } from '@playwright/test'; import process from 'process'; import { dedent } from 'ts-dedent'; + import { SbPage } from './util'; const storybookUrl = process.env.STORYBOOK_URL || 'http://localhost:8001'; diff --git a/code/e2e-tests/addon-interactions.spec.ts b/code/e2e-tests/addon-interactions.spec.ts index 5c86f165830b..6ef484c038c8 100644 --- a/code/e2e-tests/addon-interactions.spec.ts +++ b/code/e2e-tests/addon-interactions.spec.ts @@ -1,5 +1,6 @@ -import { test, expect } from '@playwright/test'; +import { expect, test } from '@playwright/test'; import process from 'process'; + import { SbPage } from './util'; const storybookUrl = process.env.STORYBOOK_URL || 'http://localhost:8001'; diff --git a/code/e2e-tests/addon-toolbars.spec.ts b/code/e2e-tests/addon-toolbars.spec.ts index b642ebca7967..493de06ce6f3 100644 --- a/code/e2e-tests/addon-toolbars.spec.ts +++ b/code/e2e-tests/addon-toolbars.spec.ts @@ -1,5 +1,6 @@ -import { test, expect } from '@playwright/test'; +import { expect, test } from '@playwright/test'; import process from 'process'; + import { SbPage } from './util'; const storybookUrl = process.env.STORYBOOK_URL || 'http://localhost:8001'; diff --git a/code/e2e-tests/addon-viewport.spec.ts b/code/e2e-tests/addon-viewport.spec.ts index 64f8eb097dfb..cf53bc89432a 100644 --- a/code/e2e-tests/addon-viewport.spec.ts +++ b/code/e2e-tests/addon-viewport.spec.ts @@ -1,5 +1,6 @@ -import { test, expect } from '@playwright/test'; +import { expect, test } from '@playwright/test'; import process from 'process'; + import { SbPage } from './util'; const storybookUrl = process.env.STORYBOOK_URL || 'http://localhost:8001'; diff --git a/code/e2e-tests/composition.spec.ts b/code/e2e-tests/composition.spec.ts index 2cc2e18f42ca..25923a44791a 100644 --- a/code/e2e-tests/composition.spec.ts +++ b/code/e2e-tests/composition.spec.ts @@ -1,4 +1,5 @@ -import { test, expect } from '@playwright/test'; +import { expect, test } from '@playwright/test'; + import { SbPage } from './util'; const storybookUrl = process.env.STORYBOOK_URL || 'http://localhost:6006'; diff --git a/code/e2e-tests/framework-nextjs.spec.ts b/code/e2e-tests/framework-nextjs.spec.ts index 0b98e5428853..c88d723ce465 100644 --- a/code/e2e-tests/framework-nextjs.spec.ts +++ b/code/e2e-tests/framework-nextjs.spec.ts @@ -1,6 +1,7 @@ import type { Locator } from '@playwright/test'; -import { test, expect } from '@playwright/test'; +import { expect, test } from '@playwright/test'; import process from 'process'; + import { SbPage } from './util'; const storybookUrl = process.env.STORYBOOK_URL || 'http://localhost:6006'; diff --git a/code/e2e-tests/framework-svelte.spec.ts b/code/e2e-tests/framework-svelte.spec.ts index ba42745c6172..a56bb2db5f0c 100644 --- a/code/e2e-tests/framework-svelte.spec.ts +++ b/code/e2e-tests/framework-svelte.spec.ts @@ -1,5 +1,6 @@ -import { test, expect } from '@playwright/test'; +import { expect, test } from '@playwright/test'; import process from 'process'; + import { SbPage } from './util'; const storybookUrl = process.env.STORYBOOK_URL || 'http://localhost:6006'; diff --git a/code/e2e-tests/json-files.spec.ts b/code/e2e-tests/json-files.spec.ts index 8cfdc966f56d..920b072c093a 100644 --- a/code/e2e-tests/json-files.spec.ts +++ b/code/e2e-tests/json-files.spec.ts @@ -1,4 +1,4 @@ -import { test, expect } from '@playwright/test'; +import { expect, test } from '@playwright/test'; import process from 'process'; const storybookUrl = process.env.STORYBOOK_URL || 'http://localhost:8001'; diff --git a/code/e2e-tests/manager.spec.ts b/code/e2e-tests/manager.spec.ts index 7131e764e635..f863b1cddf2a 100644 --- a/code/e2e-tests/manager.spec.ts +++ b/code/e2e-tests/manager.spec.ts @@ -1,5 +1,6 @@ -import { test, expect } from '@playwright/test'; +import { expect, test } from '@playwright/test'; import process from 'process'; + import { SbPage } from './util'; const storybookUrl = process.env.STORYBOOK_URL || 'http://localhost:8001'; diff --git a/code/e2e-tests/module-mocking.spec.ts b/code/e2e-tests/module-mocking.spec.ts index 8b6b43713b61..7a9048e6cc2b 100644 --- a/code/e2e-tests/module-mocking.spec.ts +++ b/code/e2e-tests/module-mocking.spec.ts @@ -1,5 +1,6 @@ -import { test, expect } from '@playwright/test'; +import { expect, test } from '@playwright/test'; import process from 'process'; + import { SbPage } from './util'; const storybookUrl = process.env.STORYBOOK_URL || 'http://localhost:8001'; diff --git a/code/e2e-tests/navigation.spec.ts b/code/e2e-tests/navigation.spec.ts index c7ac1a1263d7..16c72d6ffe6e 100644 --- a/code/e2e-tests/navigation.spec.ts +++ b/code/e2e-tests/navigation.spec.ts @@ -1,5 +1,6 @@ -import { test, expect } from '@playwright/test'; +import { expect, test } from '@playwright/test'; import process from 'process'; + import { SbPage } from './util'; const storybookUrl = process.env.STORYBOOK_URL || 'http://localhost:8001'; diff --git a/code/e2e-tests/preview-api.spec.ts b/code/e2e-tests/preview-api.spec.ts index 9132a6de495f..bb7b3dc2be9a 100644 --- a/code/e2e-tests/preview-api.spec.ts +++ b/code/e2e-tests/preview-api.spec.ts @@ -1,5 +1,6 @@ -import { test, expect } from '@playwright/test'; +import { expect, test } from '@playwright/test'; import process from 'process'; + import { SbPage } from './util'; const storybookUrl = process.env.STORYBOOK_URL || 'http://localhost:8001'; diff --git a/code/e2e-tests/save-from-controls.spec.ts b/code/e2e-tests/save-from-controls.spec.ts index b70a1607595c..0fbc24b38592 100644 --- a/code/e2e-tests/save-from-controls.spec.ts +++ b/code/e2e-tests/save-from-controls.spec.ts @@ -1,5 +1,6 @@ import { test } from '@playwright/test'; import process from 'process'; + import { SbPage } from './util'; const storybookUrl = process.env.STORYBOOK_URL || 'http://localhost:8001'; diff --git a/code/e2e-tests/storybook-hooks.spec.ts b/code/e2e-tests/storybook-hooks.spec.ts index 97e2926eb920..4dbb0ccf6f1e 100644 --- a/code/e2e-tests/storybook-hooks.spec.ts +++ b/code/e2e-tests/storybook-hooks.spec.ts @@ -1,7 +1,9 @@ /* eslint-disable no-underscore-dangle */ -import { join } from 'node:path'; import { promises as fs } from 'node:fs'; +import { join } from 'node:path'; + import { test } from '@playwright/test'; + import { SbPage } from './util'; declare global { diff --git a/code/e2e-tests/tags.spec.ts b/code/e2e-tests/tags.spec.ts index 2e7202357a1b..3148f166104e 100644 --- a/code/e2e-tests/tags.spec.ts +++ b/code/e2e-tests/tags.spec.ts @@ -1,4 +1,5 @@ -import { test, expect } from '@playwright/test'; +import { expect, test } from '@playwright/test'; + import { SbPage } from './util'; const storybookUrl = process.env.STORYBOOK_URL || 'http://localhost:8001'; diff --git a/code/e2e-tests/util.ts b/code/e2e-tests/util.ts index 02ecc753b5f5..c4433fa4e2a8 100644 --- a/code/e2e-tests/util.ts +++ b/code/e2e-tests/util.ts @@ -1,6 +1,7 @@ +import { toId } from '@storybook/csf'; + import type { Page } from '@playwright/test'; import { expect } from '@playwright/test'; -import { toId } from '@storybook/csf'; export class SbPage { readonly page: Page; diff --git a/code/frameworks/angular/package.json b/code/frameworks/angular/package.json index 626603fdf343..5ffa1c14ae67 100644 --- a/code/frameworks/angular/package.json +++ b/code/frameworks/angular/package.json @@ -34,7 +34,7 @@ ], "scripts": { "check": "node ../../../scripts/node_modules/.bin/tsc", - "prep": "rimraf dist && node --loader ../../../scripts/node_modules/esbuild-register/loader.js -r ../../../scripts/node_modules/esbuild-register/register.js ../../../scripts/prepare/tsc.ts" + "prep": "rimraf dist && jiti ../../../scripts/prepare/tsc.ts" }, "dependencies": { "@storybook/builder-webpack5": "workspace:*", @@ -44,7 +44,7 @@ "@storybook/manager-api": "workspace:^", "@storybook/preview-api": "workspace:^", "@storybook/theming": "workspace:^", - "@types/node": "^18.0.0", + "@types/node": "^22.0.0", "@types/react": "^18.0.37", "@types/react-dom": "^18.0.11", "@types/semver": "^7.3.4", diff --git a/code/frameworks/angular/src/builders/build-storybook/index.spec.ts b/code/frameworks/angular/src/builders/build-storybook/index.spec.ts index 964b23fe73f4..3b62deeb8c69 100644 --- a/code/frameworks/angular/src/builders/build-storybook/index.spec.ts +++ b/code/frameworks/angular/src/builders/build-storybook/index.spec.ts @@ -1,9 +1,8 @@ -// eslint-disable-next-line import/no-extraneous-dependencies -import { vi, describe, beforeEach, expect, it, afterEach } from 'vitest'; import { Architect, createBuilder } from '@angular-devkit/architect'; import { TestingArchitectHost } from '@angular-devkit/architect/testing'; import { schema } from '@angular-devkit/core'; -import * as path from 'path'; +import * as path from 'node:path'; +import { afterEach, beforeEach, describe, expect, it, vi } from 'vitest'; const buildDevStandaloneMock = vi.fn(); const buildStaticStandaloneMock = vi.fn(); diff --git a/code/frameworks/angular/src/builders/build-storybook/index.ts b/code/frameworks/angular/src/builders/build-storybook/index.ts index 0a7cdb642dc4..9b4e98ec35f4 100644 --- a/code/frameworks/angular/src/builders/build-storybook/index.ts +++ b/code/frameworks/angular/src/builders/build-storybook/index.ts @@ -1,3 +1,8 @@ +import { getEnvConfig, versions } from 'storybook/internal/common'; +import { buildStaticStandalone, withTelemetry } from 'storybook/internal/core-server'; +import { addToGlobalContext } from 'storybook/internal/telemetry'; +import { CLIOptions } from 'storybook/internal/types'; + import { BuilderContext, BuilderHandlerFn, @@ -7,26 +12,21 @@ import { createBuilder, targetFromTargetString, } from '@angular-devkit/architect'; -import { JsonObject } from '@angular-devkit/core'; -import { from, of, throwError } from 'rxjs'; -import { catchError, map, mapTo, switchMap } from 'rxjs/operators'; -import { sync as findUpSync } from 'find-up'; -import { findPackageSync } from 'fd-package-json'; import { BrowserBuilderOptions, StylePreprocessorOptions } from '@angular-devkit/build-angular'; - -import { CLIOptions } from 'storybook/internal/types'; -import { getEnvConfig, versions } from 'storybook/internal/common'; -import { addToGlobalContext } from 'storybook/internal/telemetry'; - -import { buildStaticStandalone, withTelemetry } from 'storybook/internal/core-server'; import { AssetPattern, SourceMapUnion, StyleElement, } from '@angular-devkit/build-angular/src/builders/browser/schema'; -import { StandaloneOptions } from '../utils/standalone-options'; -import { runCompodoc } from '../utils/run-compodoc'; +import { JsonObject } from '@angular-devkit/core'; +import { findPackageSync } from 'fd-package-json'; +import { sync as findUpSync } from 'find-up'; +import { from, of, throwError } from 'rxjs'; +import { catchError, map, mapTo, switchMap } from 'rxjs/operators'; + import { errorSummary, printErrorDetails } from '../utils/error-handler'; +import { runCompodoc } from '../utils/run-compodoc'; +import { StandaloneOptions } from '../utils/standalone-options'; addToGlobalContext('cliVersion', versions.storybook); diff --git a/code/frameworks/angular/src/builders/start-storybook/index.spec.ts b/code/frameworks/angular/src/builders/start-storybook/index.spec.ts index 7df20b08c5f2..cdce7ad01f06 100644 --- a/code/frameworks/angular/src/builders/start-storybook/index.spec.ts +++ b/code/frameworks/angular/src/builders/start-storybook/index.spec.ts @@ -1,9 +1,8 @@ -// eslint-disable-next-line import/no-extraneous-dependencies -import { vi, describe, expect, it, beforeEach, afterEach } from 'vitest'; import { Architect, createBuilder } from '@angular-devkit/architect'; import { TestingArchitectHost } from '@angular-devkit/architect/testing'; import { schema } from '@angular-devkit/core'; -import * as path from 'path'; +import { join } from 'node:path'; +import { afterEach, beforeEach, describe, expect, it, vi } from 'vitest'; const buildDevStandaloneMock = vi.fn(); const buildStaticStandaloneMock = vi.fn(); @@ -63,7 +62,7 @@ describe.skip('Start Storybook Builder', () => { ); // This will either take a Node package name, or a path to the directory // for the package.json file. - await architectHost.addBuilderFromPackage(path.join(__dirname, '../../..')); + await architectHost.addBuilderFromPackage(join(__dirname, '../../..')); }); beforeEach(() => { diff --git a/code/frameworks/angular/src/builders/start-storybook/index.ts b/code/frameworks/angular/src/builders/start-storybook/index.ts index 3cd9804cca4a..701d3c1d683e 100644 --- a/code/frameworks/angular/src/builders/start-storybook/index.ts +++ b/code/frameworks/angular/src/builders/start-storybook/index.ts @@ -1,3 +1,8 @@ +import { getEnvConfig, versions } from 'storybook/internal/common'; +import { buildDevStandalone, withTelemetry } from 'storybook/internal/core-server'; +import { addToGlobalContext } from 'storybook/internal/telemetry'; +import { CLIOptions } from 'storybook/internal/types'; + import { BuilderContext, BuilderHandlerFn, @@ -6,25 +11,21 @@ import { createBuilder, targetFromTargetString, } from '@angular-devkit/architect'; -import { JsonObject } from '@angular-devkit/core'; import { BrowserBuilderOptions, StylePreprocessorOptions } from '@angular-devkit/build-angular'; -import { from, Observable, of } from 'rxjs'; -import { map, switchMap, mapTo } from 'rxjs/operators'; -import { sync as findUpSync } from 'find-up'; -import { findPackageSync } from 'fd-package-json'; - -import { CLIOptions } from 'storybook/internal/types'; -import { getEnvConfig, versions } from 'storybook/internal/common'; -import { addToGlobalContext } from 'storybook/internal/telemetry'; -import { buildDevStandalone, withTelemetry } from 'storybook/internal/core-server'; import { AssetPattern, SourceMapUnion, StyleElement, } from '@angular-devkit/build-angular/src/builders/browser/schema'; -import { StandaloneOptions } from '../utils/standalone-options'; +import { JsonObject } from '@angular-devkit/core'; +import { findPackageSync } from 'fd-package-json'; +import { sync as findUpSync } from 'find-up'; +import { Observable, from, of } from 'rxjs'; +import { map, mapTo, switchMap } from 'rxjs/operators'; + +import { errorSummary, printErrorDetails } from '../utils/error-handler'; import { runCompodoc } from '../utils/run-compodoc'; -import { printErrorDetails, errorSummary } from '../utils/error-handler'; +import { StandaloneOptions } from '../utils/standalone-options'; addToGlobalContext('cliVersion', versions.storybook); diff --git a/code/frameworks/angular/src/builders/utils/error-handler.ts b/code/frameworks/angular/src/builders/utils/error-handler.ts index 58094633b25a..af0aaddbfbba 100644 --- a/code/frameworks/angular/src/builders/utils/error-handler.ts +++ b/code/frameworks/angular/src/builders/utils/error-handler.ts @@ -1,4 +1,5 @@ import { logger, instance as npmLog } from 'storybook/internal/node-logger'; + import { dedent } from 'ts-dedent'; export const printErrorDetails = (error: any): void => { diff --git a/code/frameworks/angular/src/builders/utils/run-compodoc.spec.ts b/code/frameworks/angular/src/builders/utils/run-compodoc.spec.ts index 14cb43103e17..4391c939fc40 100644 --- a/code/frameworks/angular/src/builders/utils/run-compodoc.spec.ts +++ b/code/frameworks/angular/src/builders/utils/run-compodoc.spec.ts @@ -1,8 +1,7 @@ -// eslint-disable-next-line import/no-extraneous-dependencies -import { vi, describe, afterEach, it, expect } from 'vitest'; +import { BuilderContext } from '@angular-devkit/architect'; import { LoggerApi } from '@angular-devkit/core/src/logger'; import { take } from 'rxjs/operators'; -import { BuilderContext } from '@angular-devkit/architect'; +import { afterEach, describe, expect, it, vi } from 'vitest'; import { runCompodoc } from './run-compodoc'; diff --git a/code/frameworks/angular/src/builders/utils/run-compodoc.ts b/code/frameworks/angular/src/builders/utils/run-compodoc.ts index e826d4e52325..e479212c445a 100644 --- a/code/frameworks/angular/src/builders/utils/run-compodoc.ts +++ b/code/frameworks/angular/src/builders/utils/run-compodoc.ts @@ -1,16 +1,18 @@ +import { isAbsolute, relative } from 'node:path'; + +import { JsPackageManagerFactory } from 'storybook/internal/common'; + import { BuilderContext } from '@angular-devkit/architect'; import { Observable } from 'rxjs'; -import * as path from 'path'; -import { JsPackageManagerFactory } from 'storybook/internal/common'; const hasTsConfigArg = (args: string[]) => args.indexOf('-p') !== -1; const hasOutputArg = (args: string[]) => args.indexOf('-d') !== -1 || args.indexOf('--output') !== -1; -// path.relative is necessary to workaround a compodoc issue with +// relative is necessary to workaround a compodoc issue with // absolute paths on windows machines const toRelativePath = (pathToTsConfig: string) => { - return path.isAbsolute(pathToTsConfig) ? path.relative('.', pathToTsConfig) : pathToTsConfig; + return isAbsolute(pathToTsConfig) ? relative('.', pathToTsConfig) : pathToTsConfig; }; export const runCompodoc = ( diff --git a/code/frameworks/angular/src/builders/utils/standalone-options.ts b/code/frameworks/angular/src/builders/utils/standalone-options.ts index e4cf63841932..f96f051b5195 100644 --- a/code/frameworks/angular/src/builders/utils/standalone-options.ts +++ b/code/frameworks/angular/src/builders/utils/standalone-options.ts @@ -1,3 +1,5 @@ +import { BuilderOptions, CLIOptions, LoadOptions } from 'storybook/internal/types'; + import { BuilderContext } from '@angular-devkit/architect'; import { AssetPattern, @@ -5,7 +7,6 @@ import { StyleElement, StylePreprocessorOptions, } from '@angular-devkit/build-angular/src/builders/browser/schema'; -import { LoadOptions, CLIOptions, BuilderOptions } from 'storybook/internal/types'; export type StandaloneOptions = CLIOptions & LoadOptions & diff --git a/code/frameworks/angular/src/client/angular-beta/AbstractRenderer.ts b/code/frameworks/angular/src/client/angular-beta/AbstractRenderer.ts index 86de5a16897a..780951207cdc 100644 --- a/code/frameworks/angular/src/client/angular-beta/AbstractRenderer.ts +++ b/code/frameworks/angular/src/client/angular-beta/AbstractRenderer.ts @@ -1,14 +1,13 @@ -import { ApplicationRef, enableProdMode, NgModule } from '@angular/core'; +import { ApplicationRef, NgModule, enableProdMode } from '@angular/core'; import { bootstrapApplication } from '@angular/platform-browser'; - import { BehaviorSubject, Subject } from 'rxjs'; import { stringify } from 'telejson'; import { ICollection, StoryFnAngularReturnType } from '../types'; import { getApplication } from './StorybookModule'; import { storyPropsProvider } from './StorybookProvider'; -import { PropertyExtractor } from './utils/PropertyExtractor'; import { queueBootstrapping } from './utils/BootstrapQueue'; +import { PropertyExtractor } from './utils/PropertyExtractor'; type StoryRenderInfo = { storyFnAngular: StoryFnAngularReturnType; diff --git a/code/frameworks/angular/src/client/angular-beta/CanvasRenderer.ts b/code/frameworks/angular/src/client/angular-beta/CanvasRenderer.ts index eeb6812ddab3..e9c3178a8725 100644 --- a/code/frameworks/angular/src/client/angular-beta/CanvasRenderer.ts +++ b/code/frameworks/angular/src/client/angular-beta/CanvasRenderer.ts @@ -1,5 +1,5 @@ +import { Parameters, StoryFnAngularReturnType } from '../types'; import { AbstractRenderer } from './AbstractRenderer'; -import { StoryFnAngularReturnType, Parameters } from '../types'; export class CanvasRenderer extends AbstractRenderer { public async render(options: { diff --git a/code/frameworks/angular/src/client/angular-beta/ComputesTemplateFromComponent.test.ts b/code/frameworks/angular/src/client/angular-beta/ComputesTemplateFromComponent.test.ts index cc12902b5c05..669c4ceea209 100644 --- a/code/frameworks/angular/src/client/angular-beta/ComputesTemplateFromComponent.test.ts +++ b/code/frameworks/angular/src/client/angular-beta/ComputesTemplateFromComponent.test.ts @@ -681,10 +681,10 @@ describe('angular source decorator', () => { `a string literal with 'single quotes'`, 'a single quoted string with "double quotes"', "a double quoted string with 'single quotes'", - // eslint-disable-next-line prettier/prettier - 'a single quoted string with escaped \'single quotes\'', - // eslint-disable-next-line prettier/prettier - "a double quoted string with escaped \"double quotes\"", + + "a single quoted string with escaped 'single quotes'", + + 'a double quoted string with escaped "double quotes"', `a string literal with \'escaped single quotes\'`, @@ -717,10 +717,10 @@ describe('angular source decorator', () => { `a string literal with 'single quotes'`, 'a single quoted string with "double quotes"', "a double quoted string with 'single quotes'", - // eslint-disable-next-line prettier/prettier - 'a single quoted string with escaped \'single quotes\'', - // eslint-disable-next-line prettier/prettier - "a double quoted string with escaped \"double quotes\"", + + "a single quoted string with escaped 'single quotes'", + + 'a double quoted string with escaped "double quotes"', `a string literal with \'escaped single quotes\'`, diff --git a/code/frameworks/angular/src/client/angular-beta/ComputesTemplateFromComponent.ts b/code/frameworks/angular/src/client/angular-beta/ComputesTemplateFromComponent.ts index 9e0d38f17986..10e1781c1af8 100644 --- a/code/frameworks/angular/src/client/angular-beta/ComputesTemplateFromComponent.ts +++ b/code/frameworks/angular/src/client/angular-beta/ComputesTemplateFromComponent.ts @@ -1,5 +1,7 @@ -import { Type } from '@angular/core'; import { ArgTypes } from 'storybook/internal/types'; + +import { Type } from '@angular/core'; + import { ICollection } from '../types'; import { ComponentInputsOutputs, diff --git a/code/frameworks/angular/src/client/angular-beta/DocsRenderer.ts b/code/frameworks/angular/src/client/angular-beta/DocsRenderer.ts index 0cff02596888..449a7f1af7ec 100644 --- a/code/frameworks/angular/src/client/angular-beta/DocsRenderer.ts +++ b/code/frameworks/angular/src/client/angular-beta/DocsRenderer.ts @@ -1,9 +1,9 @@ -import { addons } from 'storybook/internal/preview-api'; import { DOCS_RENDERED, STORY_CHANGED } from 'storybook/internal/core-events'; +import { addons } from 'storybook/internal/preview-api'; -import { getNextStoryUID } from './utils/StoryUID'; +import { Parameters, StoryFnAngularReturnType } from '../types'; import { AbstractRenderer, STORY_UID_ATTRIBUTE } from './AbstractRenderer'; -import { StoryFnAngularReturnType, Parameters } from '../types'; +import { getNextStoryUID } from './utils/StoryUID'; export class DocsRenderer extends AbstractRenderer { public async render(options: { diff --git a/code/frameworks/angular/src/client/angular-beta/RendererFactory.ts b/code/frameworks/angular/src/client/angular-beta/RendererFactory.ts index d9be786f22ff..afe1ce91000b 100644 --- a/code/frameworks/angular/src/client/angular-beta/RendererFactory.ts +++ b/code/frameworks/angular/src/client/angular-beta/RendererFactory.ts @@ -1,6 +1,6 @@ import { AbstractRenderer } from './AbstractRenderer'; -import { DocsRenderer } from './DocsRenderer'; import { CanvasRenderer } from './CanvasRenderer'; +import { DocsRenderer } from './DocsRenderer'; type RenderType = 'canvas' | 'docs'; export class RendererFactory { diff --git a/code/frameworks/angular/src/client/angular-beta/StorybookModule.ts b/code/frameworks/angular/src/client/angular-beta/StorybookModule.ts index 3535a85c6988..09f558b8e055 100644 --- a/code/frameworks/angular/src/client/angular-beta/StorybookModule.ts +++ b/code/frameworks/angular/src/client/angular-beta/StorybookModule.ts @@ -1,6 +1,6 @@ import { StoryFnAngularReturnType } from '../types'; -import { createStorybookWrapperComponent } from './StorybookWrapperComponent'; import { computesTemplateFromComponent } from './ComputesTemplateFromComponent'; +import { createStorybookWrapperComponent } from './StorybookWrapperComponent'; import { PropertyExtractor } from './utils/PropertyExtractor'; export const getApplication = ({ diff --git a/code/frameworks/angular/src/client/angular-beta/StorybookProvider.ts b/code/frameworks/angular/src/client/angular-beta/StorybookProvider.ts index f40ef8d96aa7..d6c4e4603020 100644 --- a/code/frameworks/angular/src/client/angular-beta/StorybookProvider.ts +++ b/code/frameworks/angular/src/client/angular-beta/StorybookProvider.ts @@ -1,5 +1,6 @@ -import { Provider, InjectionToken, NgZone } from '@angular/core'; -import { Subject, Subscriber, Observable } from 'rxjs'; +import { InjectionToken, NgZone, Provider } from '@angular/core'; +import { Observable, Subject, Subscriber } from 'rxjs'; + import { ICollection } from '../types'; export const STORY_PROPS = new InjectionToken>('STORY_PROPS'); diff --git a/code/frameworks/angular/src/client/angular-beta/utils/BootstrapQueue.test.ts b/code/frameworks/angular/src/client/angular-beta/utils/BootstrapQueue.test.ts index fe7fbd9ec862..3b580573471d 100644 --- a/code/frameworks/angular/src/client/angular-beta/utils/BootstrapQueue.test.ts +++ b/code/frameworks/angular/src/client/angular-beta/utils/BootstrapQueue.test.ts @@ -1,7 +1,6 @@ // @vitest-environment happy-dom - import { Subject, lastValueFrom } from 'rxjs'; -import { vi, describe, it, expect, beforeEach, afterEach } from 'vitest'; +import { afterEach, beforeEach, describe, expect, it, vi } from 'vitest'; import { queueBootstrapping } from './BootstrapQueue'; diff --git a/code/frameworks/angular/src/client/angular-beta/utils/NgComponentAnalyzer.ts b/code/frameworks/angular/src/client/angular-beta/utils/NgComponentAnalyzer.ts index 09b1f63211ce..3b4404b09b03 100644 --- a/code/frameworks/angular/src/client/angular-beta/utils/NgComponentAnalyzer.ts +++ b/code/frameworks/angular/src/client/angular-beta/utils/NgComponentAnalyzer.ts @@ -1,11 +1,11 @@ import { - Type, Component, Directive, Input, Output, Pipe, ɵReflectionCapabilities as ReflectionCapabilities, + Type, } from '@angular/core'; const reflectionCapabilities = new ReflectionCapabilities(); diff --git a/code/frameworks/angular/src/client/angular-beta/utils/NgModulesAnalyzer.test.ts b/code/frameworks/angular/src/client/angular-beta/utils/NgModulesAnalyzer.test.ts index 3299a6d4e290..1258638e2662 100644 --- a/code/frameworks/angular/src/client/angular-beta/utils/NgModulesAnalyzer.test.ts +++ b/code/frameworks/angular/src/client/angular-beta/utils/NgModulesAnalyzer.test.ts @@ -1,5 +1,6 @@ import { Component, NgModule } from '@angular/core'; import { describe, expect, it } from 'vitest'; + import { isComponentAlreadyDeclared } from './NgModulesAnalyzer'; const FooComponent = Component({})(class {}); diff --git a/code/frameworks/angular/src/client/angular-beta/utils/PropertyExtractor.test.ts b/code/frameworks/angular/src/client/angular-beta/utils/PropertyExtractor.test.ts index b5256a08370d..1a8c725287aa 100644 --- a/code/frameworks/angular/src/client/angular-beta/utils/PropertyExtractor.test.ts +++ b/code/frameworks/angular/src/client/angular-beta/utils/PropertyExtractor.test.ts @@ -1,4 +1,3 @@ -import { vi, describe, it, expect } from 'vitest'; import { CommonModule } from '@angular/common'; import { Component, Directive, Injectable, InjectionToken, NgModule } from '@angular/core'; import { BrowserModule } from '@angular/platform-browser'; @@ -8,9 +7,11 @@ import { provideAnimations, provideNoopAnimations, } from '@angular/platform-browser/animations'; +import { describe, expect, it, vi } from 'vitest'; + import { NgModuleMetadata } from '../../types'; -import { PropertyExtractor } from './PropertyExtractor'; import { WithOfficialModule } from '../__testfixtures__/test.module'; +import { PropertyExtractor } from './PropertyExtractor'; const TEST_TOKEN = new InjectionToken('testToken'); const TestTokenProvider = { provide: TEST_TOKEN, useValue: 123 }; diff --git a/code/frameworks/angular/src/client/angular-beta/utils/PropertyExtractor.ts b/code/frameworks/angular/src/client/angular-beta/utils/PropertyExtractor.ts index 67bcd7b5e6d5..309ba09ea9eb 100644 --- a/code/frameworks/angular/src/client/angular-beta/utils/PropertyExtractor.ts +++ b/code/frameworks/angular/src/client/angular-beta/utils/PropertyExtractor.ts @@ -2,7 +2,6 @@ import { CommonModule } from '@angular/common'; import { Component, Directive, - importProvidersFrom, Injectable, InjectionToken, Input, @@ -11,6 +10,7 @@ import { Pipe, Provider, ɵReflectionCapabilities as ReflectionCapabilities, + importProvidersFrom, } from '@angular/core'; import { BrowserModule } from '@angular/platform-browser'; import { @@ -20,6 +20,7 @@ import { provideNoopAnimations, } from '@angular/platform-browser/animations'; import { dedent } from 'ts-dedent'; + import { NgModuleMetadata } from '../../types'; import { isComponentAlreadyDeclared } from './NgModulesAnalyzer'; diff --git a/code/frameworks/angular/src/client/argsToTemplate.test.ts b/code/frameworks/angular/src/client/argsToTemplate.test.ts index 29a51acb1b9d..decb40bc3d59 100644 --- a/code/frameworks/angular/src/client/argsToTemplate.test.ts +++ b/code/frameworks/angular/src/client/argsToTemplate.test.ts @@ -1,5 +1,8 @@ import { describe, expect, it } from 'vitest'; -import { argsToTemplate, ArgsToTemplateOptions } from './argsToTemplate'; // adjust path + +import { ArgsToTemplateOptions, argsToTemplate } from './argsToTemplate'; + +// adjust path describe('argsToTemplate', () => { it('should correctly convert args to template string and exclude undefined values', () => { diff --git a/code/frameworks/angular/src/client/decorateStory.ts b/code/frameworks/angular/src/client/decorateStory.ts index 1085191e77bc..c2ac022b4a7d 100644 --- a/code/frameworks/angular/src/client/decorateStory.ts +++ b/code/frameworks/angular/src/client/decorateStory.ts @@ -1,7 +1,7 @@ -import { DecoratorFunction, LegacyStoryFn, StoryContext } from 'storybook/internal/types'; import { sanitizeStoryContextUpdate } from 'storybook/internal/preview-api'; -import { computesTemplateFromComponent } from './angular-beta/ComputesTemplateFromComponent'; +import { DecoratorFunction, LegacyStoryFn, StoryContext } from 'storybook/internal/types'; +import { computesTemplateFromComponent } from './angular-beta/ComputesTemplateFromComponent'; import { AngularRenderer } from './types'; export default function decorateStory( diff --git a/code/frameworks/angular/src/client/decorators.ts b/code/frameworks/angular/src/client/decorators.ts index b08278ebef44..d9b2917d27f1 100644 --- a/code/frameworks/angular/src/client/decorators.ts +++ b/code/frameworks/angular/src/client/decorators.ts @@ -1,9 +1,11 @@ +import { DecoratorFunction, StoryContext } from 'storybook/internal/types'; + import { Type } from '@angular/core'; import { ApplicationConfig } from '@angular/platform-browser'; -import { DecoratorFunction, StoryContext } from 'storybook/internal/types'; + import { computesTemplateFromComponent } from './angular-beta/ComputesTemplateFromComponent'; import { isComponent } from './angular-beta/utils/NgComponentAnalyzer'; -import { ICollection, NgModuleMetadata, AngularRenderer } from './types'; +import { AngularRenderer, ICollection, NgModuleMetadata } from './types'; // We use `any` here as the default type rather than `Args` because we need something that is // castable to any component-specific args type when the user is being careful. diff --git a/code/frameworks/angular/src/client/docs/angular-properties.test.ts b/code/frameworks/angular/src/client/docs/angular-properties.test.ts index 6649e9a4496d..baa410f34fe4 100644 --- a/code/frameworks/angular/src/client/docs/angular-properties.test.ts +++ b/code/frameworks/angular/src/client/docs/angular-properties.test.ts @@ -1,16 +1,17 @@ -import path from 'path'; -import fs from 'fs'; +import { readdirSync } from 'node:fs'; +import { join } from 'node:path'; + import { describe, expect, it } from 'vitest'; // File hierarchy: __testfixtures__ / some-test-case / input.* const inputRegExp = /^input\..*$/; describe('angular component properties', () => { - const fixturesDir = path.join(__dirname, '__testfixtures__'); - fs.readdirSync(fixturesDir, { withFileTypes: true }).forEach((testEntry) => { + const fixturesDir = join(__dirname, '__testfixtures__'); + readdirSync(fixturesDir, { withFileTypes: true }).forEach((testEntry) => { if (testEntry.isDirectory()) { - const testDir = path.join(fixturesDir, testEntry.name); - const testFile = fs.readdirSync(testDir).find((fileName) => inputRegExp.test(fileName)); + const testDir = join(fixturesDir, testEntry.name); + const testFile = readdirSync(testDir).find((fileName) => inputRegExp.test(fileName)); if (testFile) { // TODO: Remove this as soon as the real test is fixed it('true', () => { @@ -18,19 +19,19 @@ describe('angular component properties', () => { }); // TODO: Fix this test // it(`${testEntry.name}`, () => { - // const inputPath = path.join(testDir, testFile); + // const inputPath = join(testDir, testFile); // // snapshot the output of compodoc // const compodocOutput = runCompodoc(inputPath); // const compodocJson = JSON.parse(compodocOutput); // expect(compodocJson).toMatchFileSnapshot( - // path.join(testDir, `compodoc-${SNAPSHOT_OS}.snapshot`) + // join(testDir, `compodoc-${SNAPSHOT_OS}.snapshot`) // ); // // snapshot the output of addon-docs angular-properties // const componentData = findComponentByName('InputComponent', compodocJson); // const argTypes = extractArgTypesFromData(componentData); - // expect(argTypes).toMatchFileSnapshot(path.join(testDir, 'argtypes.snapshot')); + // expect(argTypes).toMatchFileSnapshot(join(testDir, 'argtypes.snapshot')); // }); } } diff --git a/code/frameworks/angular/src/client/docs/compodoc.test.ts b/code/frameworks/angular/src/client/docs/compodoc.test.ts index ff91661c8d25..6e8d220e7e9a 100644 --- a/code/frameworks/angular/src/client/docs/compodoc.test.ts +++ b/code/frameworks/angular/src/client/docs/compodoc.test.ts @@ -1,4 +1,5 @@ -import { describe, it, expect } from 'vitest'; +import { describe, expect, it } from 'vitest'; + import { extractType, setCompodocJson } from './compodoc'; import { CompodocJson, Decorator } from './types'; diff --git a/code/frameworks/angular/src/client/docs/compodoc.ts b/code/frameworks/angular/src/client/docs/compodoc.ts index e71d1f463ad3..076f591e8a84 100644 --- a/code/frameworks/angular/src/client/docs/compodoc.ts +++ b/code/frameworks/angular/src/client/docs/compodoc.ts @@ -1,19 +1,20 @@ /* eslint-disable no-underscore-dangle */ +import { logger } from 'storybook/internal/client-logger'; +import { ArgTypes, InputType, SBType } from 'storybook/internal/types'; + import { global } from '@storybook/global'; -import { InputType, ArgTypes, SBType } from 'storybook/internal/types'; -import { logger } from 'storybook/internal/client-logger'; import { Argument, Class, CompodocJson, Component, + Directive, Injectable, + JsDocTag, Method, Pipe, Property, - Directive, - JsDocTag, } from './types'; export const isMethod = (methodOrProp: Method | Property): methodOrProp is Method => { diff --git a/code/frameworks/angular/src/client/docs/config.ts b/code/frameworks/angular/src/client/docs/config.ts index 819e73e398e4..30dc3f20f812 100644 --- a/code/frameworks/angular/src/client/docs/config.ts +++ b/code/frameworks/angular/src/client/docs/config.ts @@ -1,5 +1,6 @@ import { SourceType, enhanceArgTypes } from 'storybook/internal/docs-tools'; -import { Parameters, DecoratorFunction, ArgTypesEnhancer } from 'storybook/internal/types'; +import { ArgTypesEnhancer, DecoratorFunction, Parameters } from 'storybook/internal/types'; + import { extractArgTypes, extractComponentDescription } from './compodoc'; import { sourceDecorator } from './sourceDecorator'; diff --git a/code/frameworks/angular/src/client/docs/sourceDecorator.ts b/code/frameworks/angular/src/client/docs/sourceDecorator.ts index 31a84d273499..09296a2a4f18 100644 --- a/code/frameworks/angular/src/client/docs/sourceDecorator.ts +++ b/code/frameworks/angular/src/client/docs/sourceDecorator.ts @@ -1,8 +1,9 @@ +import { SNIPPET_RENDERED, SourceType } from 'storybook/internal/docs-tools'; import { addons, useEffect } from 'storybook/internal/preview-api'; import { PartialStoryFn } from 'storybook/internal/types'; -import { SNIPPET_RENDERED, SourceType } from 'storybook/internal/docs-tools'; -import { StoryContext, AngularRenderer } from '../types'; + import { computesTemplateSourceFromComponent } from '../../renderer'; +import { AngularRenderer, StoryContext } from '../types'; export const skipSourceRender = (context: StoryContext) => { const sourceParams = context?.parameters.docs?.source; diff --git a/code/frameworks/angular/src/client/globals.ts b/code/frameworks/angular/src/client/globals.ts index c16095858f16..cf5c3eca103f 100644 --- a/code/frameworks/angular/src/client/globals.ts +++ b/code/frameworks/angular/src/client/globals.ts @@ -25,7 +25,9 @@ import { global } from '@storybook/global'; /** ************************************************************************************************* * Zone JS is required by Angular itself. */ -import 'zone.js'; // Included with Angular CLI. +import 'zone.js'; + +// Included with Angular CLI. /** ************************************************************************************************* * APPLICATION IMPORTS diff --git a/code/frameworks/angular/src/client/index.ts b/code/frameworks/angular/src/client/index.ts index 8f2e0a4172c0..45388bcad324 100644 --- a/code/frameworks/angular/src/client/index.ts +++ b/code/frameworks/angular/src/client/index.ts @@ -1,5 +1,4 @@ /// - import './globals'; export * from './public-types'; diff --git a/code/frameworks/angular/src/client/render.ts b/code/frameworks/angular/src/client/render.ts index b3fc38c4da04..817d985bd16b 100644 --- a/code/frameworks/angular/src/client/render.ts +++ b/code/frameworks/angular/src/client/render.ts @@ -1,10 +1,9 @@ -import '@angular/compiler'; - -import { RenderContext, ArgsStoryFn } from 'storybook/internal/types'; +import { ArgsStoryFn, RenderContext } from 'storybook/internal/types'; -import { AngularRenderer } from './types'; +import '@angular/compiler'; import { RendererFactory } from './angular-beta/RendererFactory'; +import { AngularRenderer } from './types'; export const rendererFactory = new RendererFactory(); diff --git a/code/frameworks/angular/src/client/types.ts b/code/frameworks/angular/src/client/types.ts index 33b4346c2d7f..7f65f6245b29 100644 --- a/code/frameworks/angular/src/client/types.ts +++ b/code/frameworks/angular/src/client/types.ts @@ -1,11 +1,12 @@ -import { Provider, importProvidersFrom } from '@angular/core'; -import { ApplicationConfig } from '@angular/platform-browser'; import { Parameters as DefaultParameters, StoryContext as DefaultStoryContext, WebRenderer, } from 'storybook/internal/types'; +import { Provider, importProvidersFrom } from '@angular/core'; +import { ApplicationConfig } from '@angular/platform-browser'; + export interface NgModuleMetadata { /** * List of components, directives, and pipes that belong to your component. diff --git a/code/frameworks/angular/src/preset.ts b/code/frameworks/angular/src/preset.ts index 6d32ae831c4b..4eb938b1f3d3 100644 --- a/code/frameworks/angular/src/preset.ts +++ b/code/frameworks/angular/src/preset.ts @@ -1,7 +1,9 @@ -import { dirname, join } from 'path'; import { PresetProperty } from 'storybook/internal/types'; -import { StorybookConfig } from './types'; + +import { dirname, join } from 'node:path'; + import { StandaloneOptions } from './builders/utils/standalone-options'; +import { StorybookConfig } from './types'; const getAbsolutePath = (input: I): I => dirname(require.resolve(join(input, 'package.json'))) as any; diff --git a/code/frameworks/angular/src/server/angular-cli-webpack.d.ts b/code/frameworks/angular/src/server/angular-cli-webpack.d.ts index b2f79e4d963a..ec5359716dd0 100644 --- a/code/frameworks/angular/src/server/angular-cli-webpack.d.ts +++ b/code/frameworks/angular/src/server/angular-cli-webpack.d.ts @@ -1,5 +1,5 @@ -import { JsonObject } from '@angular-devkit/core'; import { BuilderContext } from '@angular-devkit/architect'; +import { JsonObject } from '@angular-devkit/core'; export declare function getWebpackConfig( baseConfig: any, diff --git a/code/frameworks/angular/src/server/framework-preset-angular-cli.ts b/code/frameworks/angular/src/server/framework-preset-angular-cli.ts index acadb3c8e1da..7f10d33ea5f8 100644 --- a/code/frameworks/angular/src/server/framework-preset-angular-cli.ts +++ b/code/frameworks/angular/src/server/framework-preset-angular-cli.ts @@ -1,13 +1,14 @@ -import webpack from 'webpack'; import { logger } from 'storybook/internal/node-logger'; import { AngularLegacyBuildOptionsError } from 'storybook/internal/server-errors'; + import { BuilderContext, targetFromTargetString } from '@angular-devkit/architect'; -import { sync as findUpSync } from 'find-up'; import { JsonObject, logging } from '@angular-devkit/core'; +import { sync as findUpSync } from 'find-up'; +import webpack from 'webpack'; import { getWebpackConfig as getCustomWebpackConfig } from './angular-cli-webpack'; -import { moduleIsAvailable } from './utils/module-is-available'; import { PresetOptions } from './preset-options'; +import { moduleIsAvailable } from './utils/module-is-available'; export async function webpackFinal(baseConfig: webpack.Configuration, options: PresetOptions) { if (!moduleIsAvailable('@angular-devkit/build-angular')) { diff --git a/code/frameworks/angular/src/server/framework-preset-angular-docs.ts b/code/frameworks/angular/src/server/framework-preset-angular-docs.ts index 7f7c259ea4f4..291e131547ec 100644 --- a/code/frameworks/angular/src/server/framework-preset-angular-docs.ts +++ b/code/frameworks/angular/src/server/framework-preset-angular-docs.ts @@ -1,5 +1,5 @@ -import { PresetProperty } from 'storybook/internal/types'; import { hasDocsOrControls } from 'storybook/internal/docs-tools'; +import { PresetProperty } from 'storybook/internal/types'; export const previewAnnotations: PresetProperty<'previewAnnotations'> = (entry = [], options) => { if (!hasDocsOrControls(options)) return entry; diff --git a/code/frameworks/angular/src/server/framework-preset-angular-ivy.ts b/code/frameworks/angular/src/server/framework-preset-angular-ivy.ts index 31279d958aef..3f854666f5ae 100644 --- a/code/frameworks/angular/src/server/framework-preset-angular-ivy.ts +++ b/code/frameworks/angular/src/server/framework-preset-angular-ivy.ts @@ -1,10 +1,12 @@ -import { Configuration } from 'webpack'; -import * as path from 'path'; +import { readFileSync } from 'node:fs'; +import { join } from 'node:path'; + import { Preset } from 'storybook/internal/types'; -import fs from 'fs'; -import { PresetOptions } from './preset-options'; +import { Configuration } from 'webpack'; + import { AngularOptions } from '../types'; +import { PresetOptions } from './preset-options'; /** * Source : https://github.com/angular/angular-cli/blob/ebccb5de4a455af813c5e82483db6af20666bdbd/packages/angular_devkit/build_angular/src/utils/load-esm.ts#L23 @@ -42,7 +44,7 @@ export const runNgcc = async () => { // should be async: true but does not work due to // https://github.com/storybookjs/storybook/pull/11157/files#r615413803 async: false, - basePath: path.join(process.cwd(), 'node_modules'), // absolute path to node_modules + basePath: join(process.cwd(), 'node_modules'), // absolute path to node_modules createNewEntryPointFormats: true, // --create-ivy-entry-points compileAllFormats: false, // --first-only }); @@ -50,7 +52,7 @@ export const runNgcc = async () => { export const webpack = async (webpackConfig: Configuration, options: PresetOptions) => { const packageJsonPath = require.resolve('@angular/core/package.json'); - const packageJson = JSON.parse(fs.readFileSync(packageJsonPath, 'utf8')); + const packageJson = JSON.parse(readFileSync(packageJsonPath, 'utf8')); const VERSION = packageJson.version; const framework = await options.presets.apply('framework'); const angularOptions = (typeof framework === 'object' ? framework.options : {}) as AngularOptions; diff --git a/code/frameworks/angular/src/test-setup.ts b/code/frameworks/angular/src/test-setup.ts index d28182c6e7b7..5ed15c667bad 100644 --- a/code/frameworks/angular/src/test-setup.ts +++ b/code/frameworks/angular/src/test-setup.ts @@ -1,10 +1,8 @@ -// eslint-disable-next-line import/no-extraneous-dependencies import '@analogjs/vite-plugin-angular/setup-vitest'; - +import { getTestBed } from '@angular/core/testing'; import { BrowserDynamicTestingModule, platformBrowserDynamicTesting, } from '@angular/platform-browser-dynamic/testing'; -import { getTestBed } from '@angular/core/testing'; getTestBed().initTestEnvironment(BrowserDynamicTestingModule, platformBrowserDynamicTesting()); diff --git a/code/frameworks/angular/src/types.ts b/code/frameworks/angular/src/types.ts index f2d1684b74b2..c477fd756bb5 100644 --- a/code/frameworks/angular/src/types.ts +++ b/code/frameworks/angular/src/types.ts @@ -1,13 +1,14 @@ +import { CompatibleString } from 'storybook/internal/types'; + import { - StorybookConfig as StorybookConfigBase, - TypescriptOptions as TypescriptOptionsReact, -} from '@storybook/core-webpack'; -import { - StorybookConfigWebpack, BuilderOptions, + StorybookConfigWebpack, TypescriptOptions as TypescriptOptionsBuilder, } from '@storybook/builder-webpack5'; -import { CompatibleString } from 'storybook/internal/types'; +import { + StorybookConfig as StorybookConfigBase, + TypescriptOptions as TypescriptOptionsReact, +} from '@storybook/core-webpack'; type FrameworkName = CompatibleString<'@storybook/angular'>; type BuilderName = CompatibleString<'@storybook/builder-webpack5'>; diff --git a/code/frameworks/angular/template/cli/button.stories.ts b/code/frameworks/angular/template/cli/button.stories.ts index 886310bed9ad..dedeca1f2e9b 100644 --- a/code/frameworks/angular/template/cli/button.stories.ts +++ b/code/frameworks/angular/template/cli/button.stories.ts @@ -1,5 +1,6 @@ import type { Meta, StoryObj } from '@storybook/angular'; import { fn } from '@storybook/test'; + import { ButtonComponent } from './button.component'; // More on how to set up stories at: https://storybook.js.org/docs/writing-stories diff --git a/code/frameworks/angular/template/cli/header.stories.ts b/code/frameworks/angular/template/cli/header.stories.ts index 3f3fb684e855..ea9b0894e4b4 100644 --- a/code/frameworks/angular/template/cli/header.stories.ts +++ b/code/frameworks/angular/template/cli/header.stories.ts @@ -1,7 +1,7 @@ import type { Meta, StoryObj } from '@storybook/angular'; +import { fn } from '@storybook/test'; import { HeaderComponent } from './header.component'; -import { fn } from '@storybook/test'; const meta: Meta = { title: 'Example/Header', diff --git a/code/frameworks/angular/template/cli/page.stories.ts b/code/frameworks/angular/template/cli/page.stories.ts index 5a64cdbc2ef9..74deedbfccc1 100644 --- a/code/frameworks/angular/template/cli/page.stories.ts +++ b/code/frameworks/angular/template/cli/page.stories.ts @@ -1,5 +1,5 @@ import type { Meta, StoryObj } from '@storybook/angular'; -import { within, userEvent, expect } from '@storybook/test'; +import { expect, userEvent, within } from '@storybook/test'; import { PageComponent } from './page.component'; diff --git a/code/frameworks/angular/template/components/index.js b/code/frameworks/angular/template/components/index.js index 71aafe7204fc..5e8c4f413623 100644 --- a/code/frameworks/angular/template/components/index.js +++ b/code/frameworks/angular/template/components/index.js @@ -1,8 +1,8 @@ import { global } from '@storybook/global'; import Button from './button.component'; +import Form from './form.component'; import Html from './html.component'; import Pre from './pre.component'; -import Form from './form.component'; global.Components = { Button, Html, Pre, Form }; diff --git a/code/frameworks/angular/template/stories/argTypes/doc-button/doc-button.stories.ts b/code/frameworks/angular/template/stories/argTypes/doc-button/doc-button.stories.ts index 11dc4d7cd32d..329162d2a5cf 100644 --- a/code/frameworks/angular/template/stories/argTypes/doc-button/doc-button.stories.ts +++ b/code/frameworks/angular/template/stories/argTypes/doc-button/doc-button.stories.ts @@ -1,4 +1,5 @@ import { Meta, StoryObj, argsToTemplate } from '@storybook/angular'; + import { DocButtonComponent } from './doc-button.component'; const meta: Meta> = { diff --git a/code/frameworks/angular/template/stories/argTypes/doc-directive/doc-directive.stories.ts b/code/frameworks/angular/template/stories/argTypes/doc-directive/doc-directive.stories.ts index e949d8e88252..77682191d2bf 100644 --- a/code/frameworks/angular/template/stories/argTypes/doc-directive/doc-directive.stories.ts +++ b/code/frameworks/angular/template/stories/argTypes/doc-directive/doc-directive.stories.ts @@ -1,4 +1,5 @@ import { Meta, StoryObj } from '@storybook/angular'; + import { DocDirective } from './doc-directive.directive'; const meta: Meta = { diff --git a/code/frameworks/angular/template/stories/argTypes/doc-injectable/doc-injectable.stories.ts b/code/frameworks/angular/template/stories/argTypes/doc-injectable/doc-injectable.stories.ts index 7741bca9ba88..55c8b1fe86ea 100644 --- a/code/frameworks/angular/template/stories/argTypes/doc-injectable/doc-injectable.stories.ts +++ b/code/frameworks/angular/template/stories/argTypes/doc-injectable/doc-injectable.stories.ts @@ -1,4 +1,5 @@ import { Meta, StoryObj } from '@storybook/angular'; + import { DocInjectableService } from './doc-injectable.service'; const meta: Meta = { diff --git a/code/frameworks/angular/template/stories/argTypes/doc-pipe/doc-pipe.stories.ts b/code/frameworks/angular/template/stories/argTypes/doc-pipe/doc-pipe.stories.ts index 018ab04a9951..f3f90d3196bc 100644 --- a/code/frameworks/angular/template/stories/argTypes/doc-pipe/doc-pipe.stories.ts +++ b/code/frameworks/angular/template/stories/argTypes/doc-pipe/doc-pipe.stories.ts @@ -1,4 +1,5 @@ import { Meta, StoryObj } from '@storybook/angular'; + import { DocPipe } from './doc-pipe.pipe'; const meta: Meta = { diff --git a/code/frameworks/angular/template/stories/basics/angular-forms/customControlValueAccessor/custom-cva-component.stories.ts b/code/frameworks/angular/template/stories/basics/angular-forms/customControlValueAccessor/custom-cva-component.stories.ts index 0396bae99acc..59a656bea1e2 100644 --- a/code/frameworks/angular/template/stories/basics/angular-forms/customControlValueAccessor/custom-cva-component.stories.ts +++ b/code/frameworks/angular/template/stories/basics/angular-forms/customControlValueAccessor/custom-cva-component.stories.ts @@ -1,5 +1,7 @@ -import { FormsModule } from '@angular/forms'; import { Meta, StoryFn, StoryObj, moduleMetadata } from '@storybook/angular'; + +import { FormsModule } from '@angular/forms'; + import { CustomCvaComponent } from './custom-cva.component'; const meta: Meta = { diff --git a/code/frameworks/angular/template/stories/basics/component-with-complex-selectors/attribute-selectors.component.stories.ts b/code/frameworks/angular/template/stories/basics/component-with-complex-selectors/attribute-selectors.component.stories.ts index 73894b83b34a..8b442fa011d9 100644 --- a/code/frameworks/angular/template/stories/basics/component-with-complex-selectors/attribute-selectors.component.stories.ts +++ b/code/frameworks/angular/template/stories/basics/component-with-complex-selectors/attribute-selectors.component.stories.ts @@ -1,4 +1,5 @@ import { Meta, StoryObj } from '@storybook/angular'; + import { AttributeSelectorComponent } from './attribute-selector.component'; const meta: Meta = { diff --git a/code/frameworks/angular/template/stories/basics/component-with-enums/enums.component.stories.ts b/code/frameworks/angular/template/stories/basics/component-with-enums/enums.component.stories.ts index b79bd371baf3..bf1b632b1685 100644 --- a/code/frameworks/angular/template/stories/basics/component-with-enums/enums.component.stories.ts +++ b/code/frameworks/angular/template/stories/basics/component-with-enums/enums.component.stories.ts @@ -1,9 +1,10 @@ import { Meta, StoryObj } from '@storybook/angular'; + import { - EnumsComponent, EnumNumeric, EnumNumericInitial, EnumStringValues, + EnumsComponent, } from './enums.component'; const meta: Meta = { diff --git a/code/frameworks/angular/template/stories/basics/component-with-inheritance/base-button.stories.ts b/code/frameworks/angular/template/stories/basics/component-with-inheritance/base-button.stories.ts index 271e6a3fcc9d..37e24d9cce9f 100644 --- a/code/frameworks/angular/template/stories/basics/component-with-inheritance/base-button.stories.ts +++ b/code/frameworks/angular/template/stories/basics/component-with-inheritance/base-button.stories.ts @@ -1,4 +1,5 @@ import { Meta, StoryObj } from '@storybook/angular'; + import { BaseButtonComponent } from './base-button.component'; const meta: Meta = { diff --git a/code/frameworks/angular/template/stories/basics/component-with-inheritance/icon-button.stories.ts b/code/frameworks/angular/template/stories/basics/component-with-inheritance/icon-button.stories.ts index bb5c5fb02bcb..cc94c6d6483f 100644 --- a/code/frameworks/angular/template/stories/basics/component-with-inheritance/icon-button.stories.ts +++ b/code/frameworks/angular/template/stories/basics/component-with-inheritance/icon-button.stories.ts @@ -1,4 +1,5 @@ import { Meta, StoryObj } from '@storybook/angular'; + import { IconButtonComponent } from './icon-button.component'; const meta: Meta = { diff --git a/code/frameworks/angular/template/stories/basics/component-with-on-push/on-push.stories.ts b/code/frameworks/angular/template/stories/basics/component-with-on-push/on-push.stories.ts index cc672938a7f2..9fca26be1e55 100644 --- a/code/frameworks/angular/template/stories/basics/component-with-on-push/on-push.stories.ts +++ b/code/frameworks/angular/template/stories/basics/component-with-on-push/on-push.stories.ts @@ -1,4 +1,5 @@ import { Meta, StoryObj } from '@storybook/angular'; + import { OnPushBoxComponent } from './on-push-box.component'; const meta: Meta = { diff --git a/code/frameworks/angular/template/stories/basics/component-with-provider/di.component.stories.ts b/code/frameworks/angular/template/stories/basics/component-with-provider/di.component.stories.ts index 381c272fb96d..2311222c7567 100644 --- a/code/frameworks/angular/template/stories/basics/component-with-provider/di.component.stories.ts +++ b/code/frameworks/angular/template/stories/basics/component-with-provider/di.component.stories.ts @@ -1,4 +1,5 @@ import { Args, Meta, StoryObj } from '@storybook/angular'; + import { DiComponent } from './di.component'; const meta: Meta = { diff --git a/code/frameworks/angular/template/stories/basics/component-with-style/styled.component.stories.ts b/code/frameworks/angular/template/stories/basics/component-with-style/styled.component.stories.ts index c0cd88c09bc2..9047dcc9e4d3 100644 --- a/code/frameworks/angular/template/stories/basics/component-with-style/styled.component.stories.ts +++ b/code/frameworks/angular/template/stories/basics/component-with-style/styled.component.stories.ts @@ -1,4 +1,5 @@ import { Meta, StoryObj } from '@storybook/angular'; + import { StyledComponent } from './styled.component'; const meta: Meta = { diff --git a/code/frameworks/angular/template/stories/basics/component-with-template/template.stories.ts b/code/frameworks/angular/template/stories/basics/component-with-template/template.stories.ts index 55639870f262..75b8c4e018eb 100644 --- a/code/frameworks/angular/template/stories/basics/component-with-template/template.stories.ts +++ b/code/frameworks/angular/template/stories/basics/component-with-template/template.stories.ts @@ -1,4 +1,5 @@ import { Meta, StoryObj, argsToTemplate } from '@storybook/angular'; + import { Template } from './template.component'; const meta: Meta