diff --git a/code/addons/a11y/package.json b/code/addons/a11y/package.json index d549c0245188..62db5b2fa6e8 100644 --- a/code/addons/a11y/package.json +++ b/code/addons/a11y/package.json @@ -72,7 +72,6 @@ "@storybook/theming": "7.0.0-alpha.54", "@storybook/types": "7.0.0-alpha.54", "axe-core": "^4.2.0", - "global": "^4.4.0", "lodash": "^4.17.21", "react-sizeme": "^3.0.1" }, diff --git a/code/addons/a11y/src/a11yRunner.ts b/code/addons/a11y/src/a11yRunner.ts index 88dd78a64660..211ee14e8084 100644 --- a/code/addons/a11y/src/a11yRunner.ts +++ b/code/addons/a11y/src/a11yRunner.ts @@ -1,9 +1,8 @@ -import global from 'global'; import { addons } from '@storybook/preview-api'; import { EVENTS } from './constants'; import type { A11yParameters } from './params'; -const { document, window: globalWindow } = global; +const { document } = globalThis; if (module && module.hot && module.hot.decline) { module.hot.decline(); @@ -37,12 +36,13 @@ const run = async (storyId: string) => { const axe = (await import('axe-core')).default; const { element = '#storybook-root', config, options = {} } = input; - const htmlElement = document.querySelector(element); + const htmlElement = document.querySelector(element as string); axe.reset(); if (config) { axe.configure(config); } + // @ts-expect-error Should we check if htmlElement is truthy? const result = await axe.run(htmlElement, options); // It's possible that we requested a new run on a different story. // Unfortunately, axe doesn't support a cancel method to abort current run. @@ -64,10 +64,9 @@ const run = async (storyId: string) => { /** Returns story parameters or default ones. */ const getParams = async (storyId: string): Promise => { - const { parameters } = - (await globalWindow.__STORYBOOK_STORY_STORE__.loadStory({ storyId })) || {}; + const { parameters } = (await globalThis.__STORYBOOK_STORY_STORE__?.loadStory({ storyId })) || {}; return ( - parameters.a11y || { + parameters?.a11y || { config: {}, options: {}, } diff --git a/code/addons/a11y/src/typings.d.ts b/code/addons/a11y/src/typings.d.ts deleted file mode 100644 index 2f4eb9cf4fd9..000000000000 --- a/code/addons/a11y/src/typings.d.ts +++ /dev/null @@ -1 +0,0 @@ -declare module 'global'; diff --git a/code/addons/a11y/template/stories/parameters.stories.ts b/code/addons/a11y/template/stories/parameters.stories.ts index 5b692bf9f87b..08ff5ad8c3d4 100644 --- a/code/addons/a11y/template/stories/parameters.stories.ts +++ b/code/addons/a11y/template/stories/parameters.stories.ts @@ -1,5 +1,3 @@ -import globalThis from 'global'; - export default { component: globalThis.Components.Html, args: { diff --git a/code/addons/a11y/template/stories/tests.stories.ts b/code/addons/a11y/template/stories/tests.stories.ts index 03346296518a..c89183c300b3 100644 --- a/code/addons/a11y/template/stories/tests.stories.ts +++ b/code/addons/a11y/template/stories/tests.stories.ts @@ -1,5 +1,3 @@ -import globalThis from 'global'; - export default { component: globalThis.Components.Html, args: { diff --git a/code/addons/actions/package.json b/code/addons/actions/package.json index 7e18ca045490..3d47f5270f5a 100644 --- a/code/addons/actions/package.json +++ b/code/addons/actions/package.json @@ -84,7 +84,6 @@ "@storybook/theming": "7.0.0-alpha.54", "@storybook/types": "7.0.0-alpha.54", "dequal": "^2.0.2", - "global": "^4.4.0", "lodash": "^4.17.21", "polished": "^4.2.2", "prop-types": "^15.7.2", diff --git a/code/addons/actions/src/decorator.ts b/code/addons/actions/src/decorator.ts index 1400f15ab250..7aa38f703e7e 100644 --- a/code/addons/actions/src/decorator.ts +++ b/code/addons/actions/src/decorator.ts @@ -1,10 +1,9 @@ -import global from 'global'; import { useEffect, makeDecorator } from '@storybook/preview-api'; import { actions } from './runtime/actions'; import { PARAM_KEY } from './constants'; -const { document, Element } = global; +const { document, Element } = globalThis; const delegateEventSplitter = /^(\S+)\s*(.*)$/; diff --git a/code/addons/actions/src/typings.d.ts b/code/addons/actions/src/typings.d.ts index 74f6623d4787..331fb83df5f4 100644 --- a/code/addons/actions/src/typings.d.ts +++ b/code/addons/actions/src/typings.d.ts @@ -1,3 +1,2 @@ // TODO: following packages need definition files or a TS migration -declare module 'global'; declare module 'uuid-browser/v4'; diff --git a/code/addons/actions/template/stories/argtype.stories.ts b/code/addons/actions/template/stories/argtype.stories.ts index 1f04316f7dff..206b81d9c104 100644 --- a/code/addons/actions/template/stories/argtype.stories.ts +++ b/code/addons/actions/template/stories/argtype.stories.ts @@ -1,5 +1,3 @@ -import globalThis from 'global'; - export default { component: globalThis.Components.Button, args: { diff --git a/code/addons/actions/template/stories/basics.stories.ts b/code/addons/actions/template/stories/basics.stories.ts index 86523878728e..81d2dc6476a0 100644 --- a/code/addons/actions/template/stories/basics.stories.ts +++ b/code/addons/actions/template/stories/basics.stories.ts @@ -1,5 +1,3 @@ -import globalThis from 'global'; - import { action } from '@storybook/addon-actions'; export default { diff --git a/code/addons/actions/template/stories/configs.stories.ts b/code/addons/actions/template/stories/configs.stories.ts index 51ccac3b0084..bf960a44ed93 100644 --- a/code/addons/actions/template/stories/configs.stories.ts +++ b/code/addons/actions/template/stories/configs.stories.ts @@ -1,5 +1,3 @@ -import globalThis from 'global'; - import { actions, configureActions } from '@storybook/addon-actions'; const configs = actions('actionA', 'actionB', 'actionC'); diff --git a/code/addons/actions/template/stories/parameters.stories.ts b/code/addons/actions/template/stories/parameters.stories.ts index 5848c25b8375..be3d6a3efe3d 100644 --- a/code/addons/actions/template/stories/parameters.stories.ts +++ b/code/addons/actions/template/stories/parameters.stories.ts @@ -1,4 +1,3 @@ -import globalThis from 'global'; import { withActions } from '@storybook/addon-actions/decorator'; export default { diff --git a/code/addons/backgrounds/package.json b/code/addons/backgrounds/package.json index bd2842044aae..ed6edc0f1504 100644 --- a/code/addons/backgrounds/package.json +++ b/code/addons/backgrounds/package.json @@ -82,7 +82,6 @@ "@storybook/preview-api": "7.0.0-alpha.54", "@storybook/theming": "7.0.0-alpha.54", "@storybook/types": "7.0.0-alpha.54", - "global": "^4.4.0", "memoizerific": "^1.11.3", "ts-dedent": "^2.0.0" }, diff --git a/code/addons/backgrounds/src/helpers/index.ts b/code/addons/backgrounds/src/helpers/index.ts index e56b147ffc35..ae38b45909d2 100644 --- a/code/addons/backgrounds/src/helpers/index.ts +++ b/code/addons/backgrounds/src/helpers/index.ts @@ -1,14 +1,13 @@ -import global from 'global'; import { dedent } from 'ts-dedent'; import { logger } from '@storybook/client-logger'; import type { Background } from '../types'; -const { document, window } = global; +const { document } = globalThis; export const isReduceMotionEnabled = () => { - const prefersReduceMotion = window.matchMedia('(prefers-reduced-motion: reduce)'); + const prefersReduceMotion = globalThis.matchMedia('(prefers-reduced-motion: reduce)'); return prefersReduceMotion.matches; }; diff --git a/code/addons/backgrounds/src/typings.d.ts b/code/addons/backgrounds/src/typings.d.ts deleted file mode 100644 index 2f4eb9cf4fd9..000000000000 --- a/code/addons/backgrounds/src/typings.d.ts +++ /dev/null @@ -1 +0,0 @@ -declare module 'global'; diff --git a/code/addons/backgrounds/template/stories/grid.stories.ts b/code/addons/backgrounds/template/stories/grid.stories.ts index e6a75a1dba76..15317051d9b2 100644 --- a/code/addons/backgrounds/template/stories/grid.stories.ts +++ b/code/addons/backgrounds/template/stories/grid.stories.ts @@ -1,5 +1,3 @@ -import globalThis from 'global'; - export default { component: globalThis.Components.Button, args: { diff --git a/code/addons/backgrounds/template/stories/parameters.stories.ts b/code/addons/backgrounds/template/stories/parameters.stories.ts index 1d57ea959143..c440a7b3ef20 100644 --- a/code/addons/backgrounds/template/stories/parameters.stories.ts +++ b/code/addons/backgrounds/template/stories/parameters.stories.ts @@ -1,5 +1,3 @@ -import globalThis from 'global'; - const COLORS = [ { name: 'red', value: '#FB001D' }, { name: 'orange', value: '#FB8118' }, diff --git a/code/addons/controls/template/stories/basics.stories.ts b/code/addons/controls/template/stories/basics.stories.ts index f5151890fdda..8054e92bd2cf 100644 --- a/code/addons/controls/template/stories/basics.stories.ts +++ b/code/addons/controls/template/stories/basics.stories.ts @@ -1,4 +1,3 @@ -import globalThis from 'global'; import type { PartialStoryFn, StoryContext } from '@storybook/types'; export default { diff --git a/code/addons/controls/template/stories/conditional.stories.ts b/code/addons/controls/template/stories/conditional.stories.ts index b08b63f13138..e726169830c2 100644 --- a/code/addons/controls/template/stories/conditional.stories.ts +++ b/code/addons/controls/template/stories/conditional.stories.ts @@ -1,4 +1,3 @@ -import globalThis from 'global'; import type { PartialStoryFn, StoryContext } from '@storybook/types'; export default { diff --git a/code/addons/controls/template/stories/disable.stories.ts b/code/addons/controls/template/stories/disable.stories.ts index f95160a034c9..ec38dc03af13 100644 --- a/code/addons/controls/template/stories/disable.stories.ts +++ b/code/addons/controls/template/stories/disable.stories.ts @@ -1,4 +1,3 @@ -import globalThis from 'global'; import type { PartialStoryFn, StoryContext } from '@storybook/types'; export default { diff --git a/code/addons/controls/template/stories/filters.stories.ts b/code/addons/controls/template/stories/filters.stories.ts index 4ea5c36316dd..bb2402be4032 100644 --- a/code/addons/controls/template/stories/filters.stories.ts +++ b/code/addons/controls/template/stories/filters.stories.ts @@ -1,4 +1,3 @@ -import globalThis from 'global'; import type { PartialStoryFn, StoryContext } from '@storybook/types'; export default { diff --git a/code/addons/controls/template/stories/issues.stories.ts b/code/addons/controls/template/stories/issues.stories.ts index 0b9cb463309c..5d680f0daf14 100644 --- a/code/addons/controls/template/stories/issues.stories.ts +++ b/code/addons/controls/template/stories/issues.stories.ts @@ -1,4 +1,3 @@ -import globalThis from 'global'; import type { PartialStoryFn, StoryContext } from '@storybook/types'; export default { diff --git a/code/addons/controls/template/stories/matchers.stories.ts b/code/addons/controls/template/stories/matchers.stories.ts index b17b614cc396..124faa580bf1 100644 --- a/code/addons/controls/template/stories/matchers.stories.ts +++ b/code/addons/controls/template/stories/matchers.stories.ts @@ -1,4 +1,3 @@ -import globalThis from 'global'; import type { PartialStoryFn, StoryContext } from '@storybook/types'; export default { diff --git a/code/addons/controls/template/stories/sorting.stories.ts b/code/addons/controls/template/stories/sorting.stories.ts index 510314bceca1..0237c1d09d32 100644 --- a/code/addons/controls/template/stories/sorting.stories.ts +++ b/code/addons/controls/template/stories/sorting.stories.ts @@ -1,4 +1,3 @@ -import globalThis from 'global'; import type { PartialStoryFn, StoryContext } from '@storybook/types'; export default { diff --git a/code/addons/docs/package.json b/code/addons/docs/package.json index f8ff9859e1dc..8fafa283edf3 100644 --- a/code/addons/docs/package.json +++ b/code/addons/docs/package.json @@ -98,7 +98,6 @@ "@storybook/theming": "7.0.0-alpha.54", "@storybook/types": "7.0.0-alpha.54", "fs-extra": "^9.0.1", - "global": "^4.4.0", "remark-external-links": "^8.0.0", "remark-slug": "^6.0.0", "ts-dedent": "^2.0.0" diff --git a/code/addons/docs/src/typings.d.ts b/code/addons/docs/src/typings.d.ts index 09cc7e5fa21a..5528b7d9f1c6 100644 --- a/code/addons/docs/src/typings.d.ts +++ b/code/addons/docs/src/typings.d.ts @@ -1,4 +1,3 @@ -declare module 'global'; declare module '@egoist/vue-to-react'; declare module 'remark-slug'; declare module 'remark-external-links'; diff --git a/code/addons/docs/template/stories/docs2/button.stories.ts b/code/addons/docs/template/stories/docs2/button.stories.ts index 5119c70b7e61..5e00964ff4cc 100644 --- a/code/addons/docs/template/stories/docs2/button.stories.ts +++ b/code/addons/docs/template/stories/docs2/button.stories.ts @@ -1,5 +1,3 @@ -import globalThis from 'global'; - export default { component: globalThis.Components.Button, args: { onClick: () => console.log('clicked!') }, diff --git a/code/addons/docs/template/stories/docspage/autoplay.stories.ts b/code/addons/docs/template/stories/docspage/autoplay.stories.ts index 974837b582c4..c629857fce96 100644 --- a/code/addons/docs/template/stories/docspage/autoplay.stories.ts +++ b/code/addons/docs/template/stories/docspage/autoplay.stories.ts @@ -1,4 +1,3 @@ -import globalThis from 'global'; import { expect } from '@storybook/jest'; import { within } from '@storybook/testing-library'; diff --git a/code/addons/docs/template/stories/docspage/basic.stories.ts b/code/addons/docs/template/stories/docspage/basic.stories.ts index 58a24a2eb472..0e76fc7ae202 100644 --- a/code/addons/docs/template/stories/docspage/basic.stories.ts +++ b/code/addons/docs/template/stories/docspage/basic.stories.ts @@ -1,5 +1,3 @@ -import globalThis from 'global'; - export default { component: globalThis.Components.Button, tags: ['docsPage'], diff --git a/code/addons/docs/template/stories/docspage/description.stories.ts b/code/addons/docs/template/stories/docspage/description.stories.ts index 7eb04413a94a..a08403576031 100644 --- a/code/addons/docs/template/stories/docspage/description.stories.ts +++ b/code/addons/docs/template/stories/docspage/description.stories.ts @@ -1,5 +1,3 @@ -import globalThis from 'global'; - export default { component: globalThis.Components.Button, // FIXME: remove array subcomponents in 7.0? diff --git a/code/addons/docs/template/stories/docspage/extract-description.stories.ts b/code/addons/docs/template/stories/docspage/extract-description.stories.ts index 51ab3513c58d..af350ce9d721 100644 --- a/code/addons/docs/template/stories/docspage/extract-description.stories.ts +++ b/code/addons/docs/template/stories/docspage/extract-description.stories.ts @@ -1,5 +1,3 @@ -import globalThis from 'global'; - export default { component: globalThis.Components.Button, tags: ['docsPage'], diff --git a/code/addons/docs/template/stories/docspage/iframe.stories.ts b/code/addons/docs/template/stories/docspage/iframe.stories.ts index df9cf977c9fc..523b94b75c6b 100644 --- a/code/addons/docs/template/stories/docspage/iframe.stories.ts +++ b/code/addons/docs/template/stories/docspage/iframe.stories.ts @@ -1,5 +1,3 @@ -import globalThis from 'global'; - export default { component: globalThis.Components.Button, tags: ['docsPage'], diff --git a/code/addons/docs/template/stories/docspage/overflow.stories.ts b/code/addons/docs/template/stories/docspage/overflow.stories.ts index a281100c8854..caa54c36c9f9 100644 --- a/code/addons/docs/template/stories/docspage/overflow.stories.ts +++ b/code/addons/docs/template/stories/docspage/overflow.stories.ts @@ -1,5 +1,3 @@ -import globalThis from 'global'; - export default { component: globalThis.Components.Pre, tags: ['docsPage'], diff --git a/code/addons/docs/template/stories/docspage/override.stories.ts b/code/addons/docs/template/stories/docspage/override.stories.ts index b96dde24c07a..43fe0e3b1e68 100644 --- a/code/addons/docs/template/stories/docspage/override.stories.ts +++ b/code/addons/docs/template/stories/docspage/override.stories.ts @@ -1,5 +1,3 @@ -import globalThis from 'global'; - // FIXME: do this using basic React functions for multi-framework // once sandbox linking is working // diff --git a/code/addons/docs/template/stories/docspage/source.stories.ts b/code/addons/docs/template/stories/docspage/source.stories.ts index 62eb646c6a00..958b003deca2 100644 --- a/code/addons/docs/template/stories/docspage/source.stories.ts +++ b/code/addons/docs/template/stories/docspage/source.stories.ts @@ -1,5 +1,3 @@ -import globalThis from 'global'; - export default { component: globalThis.Components.Button, tags: ['docsPage'], diff --git a/code/addons/docs/template/stories/stories-mdx/basic.stories.mdx b/code/addons/docs/template/stories/stories-mdx/basic.stories.mdx index a8e6ea8ff07a..07e7d1ad97f1 100644 --- a/code/addons/docs/template/stories/stories-mdx/basic.stories.mdx +++ b/code/addons/docs/template/stories/stories-mdx/basic.stories.mdx @@ -1,5 +1,4 @@ import { Meta, Story, Canvas, ArgsTable } from '@storybook/addon-docs'; -import globalThis from 'global'; diff --git a/code/addons/docs/template/stories/stories-mdx/csf-in-mdx.stories.mdx b/code/addons/docs/template/stories/stories-mdx/csf-in-mdx.stories.mdx index 8984faa476b9..f19a356d6a19 100644 --- a/code/addons/docs/template/stories/stories-mdx/csf-in-mdx.stories.mdx +++ b/code/addons/docs/template/stories/stories-mdx/csf-in-mdx.stories.mdx @@ -1,5 +1,4 @@ import { Meta, Story, Canvas, ArgsTable } from '@storybook/addon-docs'; -import globalThis from 'global'; import * as Csf from './csf-in-mdx.stories.js'; diff --git a/code/addons/docs/template/stories/stories-mdx/iframe.stories.mdx b/code/addons/docs/template/stories/stories-mdx/iframe.stories.mdx index d77b4d5972a8..60879b4a6b8f 100644 --- a/code/addons/docs/template/stories/stories-mdx/iframe.stories.mdx +++ b/code/addons/docs/template/stories/stories-mdx/iframe.stories.mdx @@ -1,5 +1,4 @@ import { Meta, Story, Canvas, ArgsTable } from '@storybook/addon-docs'; -import globalThis from 'global'; diff --git a/code/addons/docs/template/stories/stories-mdx/play-functions.stories.mdx b/code/addons/docs/template/stories/stories-mdx/play-functions.stories.mdx index 3b194432193b..8e9df83481d0 100644 --- a/code/addons/docs/template/stories/stories-mdx/play-functions.stories.mdx +++ b/code/addons/docs/template/stories/stories-mdx/play-functions.stories.mdx @@ -1,5 +1,4 @@ import { Meta, Story, Canvas, ArgsTable } from '@storybook/addon-docs'; -import globalThis from 'global'; console.log('component play')} /> diff --git a/code/addons/highlight/package.json b/code/addons/highlight/package.json index 07275414ef14..905310cd1113 100644 --- a/code/addons/highlight/package.json +++ b/code/addons/highlight/package.json @@ -61,8 +61,7 @@ }, "dependencies": { "@storybook/core-events": "7.0.0-alpha.54", - "@storybook/preview-api": "7.0.0-alpha.54", - "global": "^4.4.0" + "@storybook/preview-api": "7.0.0-alpha.54" }, "devDependencies": { "@types/webpack-env": "^1.16.0", diff --git a/code/addons/highlight/src/preview.ts b/code/addons/highlight/src/preview.ts index 36e486b90f78..2eaba7674695 100644 --- a/code/addons/highlight/src/preview.ts +++ b/code/addons/highlight/src/preview.ts @@ -1,10 +1,9 @@ /* eslint-env browser */ -import global from 'global'; import { addons } from '@storybook/preview-api'; import { STORY_CHANGED } from '@storybook/core-events'; import { HIGHLIGHT, RESET_HIGHLIGHT, HIGHLIGHT_STYLE_ID } from './constants'; -const { document } = global; +const { document } = globalThis; type OutlineStyle = 'dotted' | 'dashed' | 'solid' | 'double'; diff --git a/code/addons/highlight/src/typings.d.ts b/code/addons/highlight/src/typings.d.ts deleted file mode 100644 index 2f4eb9cf4fd9..000000000000 --- a/code/addons/highlight/src/typings.d.ts +++ /dev/null @@ -1 +0,0 @@ -declare module 'global'; diff --git a/code/addons/interactions/package.json b/code/addons/interactions/package.json index cd6883c80623..f42327c05ba6 100644 --- a/code/addons/interactions/package.json +++ b/code/addons/interactions/package.json @@ -81,7 +81,6 @@ "@storybook/preview-api": "7.0.0-alpha.54", "@storybook/theming": "7.0.0-alpha.54", "@storybook/types": "7.0.0-alpha.54", - "global": "^4.4.0", "jest-mock": "^27.0.6", "polished": "^4.2.2", "ts-dedent": "^2.2.0" diff --git a/code/addons/interactions/src/Panel.tsx b/code/addons/interactions/src/Panel.tsx index e4df36d5474c..f9cc67d24dc2 100644 --- a/code/addons/interactions/src/Panel.tsx +++ b/code/addons/interactions/src/Panel.tsx @@ -1,4 +1,3 @@ -import global from 'global'; import * as React from 'react'; import { useChannel, useParameter } from '@storybook/manager-api'; import { @@ -102,10 +101,10 @@ export const Panel: React.FC<{ active: boolean }> = (props) => { const endRef = React.useRef(); React.useEffect(() => { let observer: IntersectionObserver; - if (global.window.IntersectionObserver) { - observer = new global.window.IntersectionObserver( + if (globalThis.IntersectionObserver) { + observer = new globalThis.IntersectionObserver( ([end]: any) => setScrollTarget(end.isIntersecting ? undefined : end.target), - { root: global.window.document.querySelector('#panel-tab-content') } + { root: globalThis.document.querySelector('#panel-tab-content') } ); if (endRef.current) observer.observe(endRef.current); } diff --git a/code/addons/interactions/src/components/TabStatus.tsx b/code/addons/interactions/src/components/TabStatus.tsx index 66116985c7dd..2c751b05e013 100644 --- a/code/addons/interactions/src/components/TabStatus.tsx +++ b/code/addons/interactions/src/components/TabStatus.tsx @@ -4,7 +4,7 @@ import ReactDOM from 'react-dom'; import { StatusIcon } from './StatusIcon'; export const TabStatus = ({ children }: { children: React.ReactChild }) => { - const container = global.document.getElementById('tabbutton-interactions'); + const container = globalThis.document.getElementById('tabbutton-interactions'); return container && ReactDOM.createPortal(children, container); }; diff --git a/code/addons/interactions/src/typings.d.ts b/code/addons/interactions/src/typings.d.ts deleted file mode 100644 index 2f4eb9cf4fd9..000000000000 --- a/code/addons/interactions/src/typings.d.ts +++ /dev/null @@ -1 +0,0 @@ -declare module 'global'; diff --git a/code/addons/interactions/template/stories/basics.stories.ts b/code/addons/interactions/template/stories/basics.stories.ts index 9a1919e748c9..ba69a3f11bbd 100644 --- a/code/addons/interactions/template/stories/basics.stories.ts +++ b/code/addons/interactions/template/stories/basics.stories.ts @@ -1,4 +1,3 @@ -import globalThis from 'global'; import { within, waitFor, diff --git a/code/addons/jest/package.json b/code/addons/jest/package.json index d0647c7e06aa..0efd183605b1 100644 --- a/code/addons/jest/package.json +++ b/code/addons/jest/package.json @@ -75,7 +75,6 @@ "@storybook/manager-api": "7.0.0-alpha.54", "@storybook/preview-api": "7.0.0-alpha.54", "@storybook/theming": "7.0.0-alpha.54", - "global": "^4.4.0", "react-sizeme": "^3.0.1", "upath": "^1.2.0" }, diff --git a/code/addons/jest/src/typings.d.ts b/code/addons/jest/src/typings.d.ts deleted file mode 100644 index a41bf8a45b79..000000000000 --- a/code/addons/jest/src/typings.d.ts +++ /dev/null @@ -1,2 +0,0 @@ -// TODO: following packages need definition files or a TS migration -declare module 'global'; diff --git a/code/addons/links/package.json b/code/addons/links/package.json index a520d4cc06bf..3c29143003ea 100644 --- a/code/addons/links/package.json +++ b/code/addons/links/package.json @@ -83,7 +83,6 @@ "@storybook/preview-api": "7.0.0-alpha.54", "@storybook/router": "7.0.0-alpha.54", "@storybook/types": "7.0.0-alpha.54", - "global": "^4.4.0", "prop-types": "^15.7.2", "ts-dedent": "^2.0.0" }, diff --git a/code/addons/links/src/typings.d.ts b/code/addons/links/src/typings.d.ts deleted file mode 100644 index 2f4eb9cf4fd9..000000000000 --- a/code/addons/links/src/typings.d.ts +++ /dev/null @@ -1 +0,0 @@ -declare module 'global'; diff --git a/code/addons/links/src/utils.ts b/code/addons/links/src/utils.ts index 14d1fcde1ca3..6543fb641e3d 100644 --- a/code/addons/links/src/utils.ts +++ b/code/addons/links/src/utils.ts @@ -1,11 +1,10 @@ -import global from 'global'; import { addons, makeDecorator } from '@storybook/preview-api'; import { STORY_CHANGED, SELECT_STORY } from '@storybook/core-events'; import type { StoryId, StoryName, ComponentTitle } from '@storybook/types'; import { toId } from '@storybook/csf'; import { PARAM_KEY } from './constants'; -const { document, HTMLElement } = global; +const { document, HTMLElement } = globalThis; interface ParamsId { storyId: StoryId; diff --git a/code/addons/links/template/stories/decorator.stories.ts b/code/addons/links/template/stories/decorator.stories.ts index 562633320441..b696526c65a6 100644 --- a/code/addons/links/template/stories/decorator.stories.ts +++ b/code/addons/links/template/stories/decorator.stories.ts @@ -1,4 +1,3 @@ -import globalThis from '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 09066ccfc86a..7da43b09f069 100644 --- a/code/addons/links/template/stories/linkto.stories.ts +++ b/code/addons/links/template/stories/linkto.stories.ts @@ -1,4 +1,3 @@ -import globalThis from 'global'; import { linkTo } from '@storybook/addon-links'; export default { diff --git a/code/addons/links/template/stories/scroll.stories.ts b/code/addons/links/template/stories/scroll.stories.ts index 0445506d1a99..d8c327d8c62b 100644 --- a/code/addons/links/template/stories/scroll.stories.ts +++ b/code/addons/links/template/stories/scroll.stories.ts @@ -1,4 +1,3 @@ -import globalThis from 'global'; import { withLinks } from '@storybook/addon-links'; export default { diff --git a/code/addons/measure/package.json b/code/addons/measure/package.json index 9ed9bda4a3c7..f739e9ce8f10 100644 --- a/code/addons/measure/package.json +++ b/code/addons/measure/package.json @@ -79,8 +79,7 @@ "@storybook/core-events": "7.0.0-alpha.54", "@storybook/manager-api": "7.0.0-alpha.54", "@storybook/preview-api": "7.0.0-alpha.54", - "@storybook/types": "7.0.0-alpha.54", - "global": "^4.4.0" + "@storybook/types": "7.0.0-alpha.54" }, "devDependencies": { "typescript": "^4.9.3" diff --git a/code/addons/measure/src/box-model/canvas.ts b/code/addons/measure/src/box-model/canvas.ts index e35ee8a6eac8..4833f5856f81 100644 --- a/code/addons/measure/src/box-model/canvas.ts +++ b/code/addons/measure/src/box-model/canvas.ts @@ -1,6 +1,4 @@ /* eslint-disable no-param-reassign */ -import global from 'global'; - interface Size { width: number; height: number; @@ -13,8 +11,10 @@ interface CanvasState { height?: number; } +const { document } = globalThis; + function getDocumentWidthAndHeight() { - const container = global.document.documentElement; + const container = document.documentElement; const height = Math.max(container.scrollHeight, container.offsetHeight); const width = Math.max(container.scrollWidth, container.offsetWidth); @@ -22,7 +22,7 @@ function getDocumentWidthAndHeight() { } function createCanvas(): CanvasState { - const canvas = global.document.createElement('canvas'); + const canvas = document.createElement('canvas'); canvas.id = 'storybook-addon-measure'; const context = canvas.getContext('2d'); // Set canvas width & height @@ -35,7 +35,7 @@ function createCanvas(): CanvasState { canvas.style.zIndex = '2147483647'; // Disable any user interactions canvas.style.pointerEvents = 'none'; - global.document.body.appendChild(canvas); + document.body.appendChild(canvas); return { canvas, context, width, height }; } @@ -49,7 +49,7 @@ function setCanvasWidthAndHeight( canvas.style.height = `${height}px`; // Scale - const scale = global.window.devicePixelRatio; + const scale = globalThis.devicePixelRatio; canvas.width = Math.floor(width * scale); canvas.height = Math.floor(height * scale); diff --git a/code/addons/measure/src/box-model/visualizer.ts b/code/addons/measure/src/box-model/visualizer.ts index 59904860948c..a30de7bdc6af 100644 --- a/code/addons/measure/src/box-model/visualizer.ts +++ b/code/addons/measure/src/box-model/visualizer.ts @@ -2,7 +2,6 @@ /** * Based on https://gist.github.com/awestbro/e668c12662ad354f02a413205b65fce7 */ -import global from 'global'; import { draw } from './canvas'; import type { Label, LabelStack } from './labels'; import { labelStacks } from './labels'; @@ -30,10 +29,10 @@ function filterZeroValues(labels: LabelStack): LabelStack { function floatingAlignment(extremities: Extremities): FloatingAlignment { const windowExtremities = { - top: global.window.scrollY, - bottom: global.window.scrollY + global.window.innerHeight, - left: global.window.scrollX, - right: global.window.scrollX + global.window.innerWidth, + top: globalThis.scrollY, + bottom: globalThis.scrollY + globalThis.innerHeight, + left: globalThis.scrollX, + right: globalThis.scrollX + globalThis.innerWidth, }; const distances = { @@ -50,7 +49,7 @@ function floatingAlignment(extremities: Extremities): FloatingAlignment { } function measureElement(element: HTMLElement): ElementMeasurements { - const style = global.getComputedStyle(element); + const style = globalThis.getComputedStyle(element); // eslint-disable-next-line prefer-const let { top, left, right, bottom, width, height } = element.getBoundingClientRect(); @@ -69,10 +68,10 @@ function measureElement(element: HTMLElement): ElementMeasurements { borderRightWidth, } = style; - top = top + global.window.scrollY; - left = left + global.window.scrollX; - bottom = bottom + global.window.scrollY; - right = right + global.window.scrollX; + top = top + globalThis.scrollY; + left = left + globalThis.scrollX; + bottom = bottom + globalThis.scrollY; + right = right + globalThis.scrollX; const margin = { top: pxToNumber(marginTop), diff --git a/code/addons/measure/src/typings.d.ts b/code/addons/measure/src/typings.d.ts index 4a8ad58bf897..19bb66f5544f 100644 --- a/code/addons/measure/src/typings.d.ts +++ b/code/addons/measure/src/typings.d.ts @@ -1,5 +1,3 @@ -declare module 'global'; - interface Margin { top: number; bottom: number; diff --git a/code/addons/measure/src/util.ts b/code/addons/measure/src/util.ts index f4017c41dff7..6847e2c063b3 100644 --- a/code/addons/measure/src/util.ts +++ b/code/addons/measure/src/util.ts @@ -1,7 +1,5 @@ -import global from 'global'; - export const deepElementFromPoint = (x: number, y: number) => { - const element = global.document.elementFromPoint(x, y); + const element = globalThis.document.elementFromPoint(x, y); const crawlShadows = (node: Element): Element => { if (node && node.shadowRoot) { diff --git a/code/addons/outline/package.json b/code/addons/outline/package.json index d9a50acf2f30..b4a60cb4443b 100644 --- a/code/addons/outline/package.json +++ b/code/addons/outline/package.json @@ -83,7 +83,6 @@ "@storybook/manager-api": "7.0.0-alpha.54", "@storybook/preview-api": "7.0.0-alpha.54", "@storybook/types": "7.0.0-alpha.54", - "global": "^4.4.0", "ts-dedent": "^2.0.0" }, "devDependencies": { diff --git a/code/addons/outline/src/helpers.ts b/code/addons/outline/src/helpers.ts index 569a80e21d7b..8013e39aa318 100644 --- a/code/addons/outline/src/helpers.ts +++ b/code/addons/outline/src/helpers.ts @@ -1,27 +1,27 @@ -import global from 'global'; +const { document } = globalThis; export const clearStyles = (selector: string | string[]) => { const selectors = Array.isArray(selector) ? selector : [selector]; selectors.forEach(clearStyle); }; -const clearStyle = (selector: string | string[]) => { - const element = global.document.getElementById(selector); +const clearStyle = (selector: string) => { + const element = document.getElementById(selector); if (element && element.parentElement) { element.parentElement.removeChild(element); } }; export const addOutlineStyles = (selector: string, css: string) => { - const existingStyle = global.document.getElementById(selector); + const existingStyle = document.getElementById(selector); if (existingStyle) { if (existingStyle.innerHTML !== css) { existingStyle.innerHTML = css; } } else { - const style = global.document.createElement('style'); + const style = document.createElement('style'); style.setAttribute('id', selector); style.innerHTML = css; - global.document.head.appendChild(style); + document.head.appendChild(style); } }; diff --git a/code/addons/outline/src/typings.d.ts b/code/addons/outline/src/typings.d.ts deleted file mode 100644 index 2f4eb9cf4fd9..000000000000 --- a/code/addons/outline/src/typings.d.ts +++ /dev/null @@ -1 +0,0 @@ -declare module 'global'; diff --git a/code/addons/storyshots/storyshots-core/package.json b/code/addons/storyshots/storyshots-core/package.json index b43b77ccf4f9..7ab04f7c83cc 100644 --- a/code/addons/storyshots/storyshots-core/package.json +++ b/code/addons/storyshots/storyshots-core/package.json @@ -48,7 +48,6 @@ "@types/jest-specific-snapshot": "^0.5.6", "core-js": "^3.8.2", "glob": "^7.1.6", - "global": "^4.4.0", "jest-specific-snapshot": "^6.0.0", "preact-render-to-string": "^5.1.19", "pretty-format": "^28.0.0", diff --git a/code/addons/storyshots/storyshots-core/src/api/index.ts b/code/addons/storyshots/storyshots-core/src/api/index.ts index c05c2f23a210..ab947624c806 100644 --- a/code/addons/storyshots/storyshots-core/src/api/index.ts +++ b/code/addons/storyshots/storyshots-core/src/api/index.ts @@ -1,4 +1,3 @@ -import global from 'global'; import { addons, mockChannel } from '@storybook/preview-api'; import ensureOptionsDefaults from './ensureOptionsDefaults'; import snapshotsTests from './snapshotsTestsTemplate'; @@ -6,17 +5,17 @@ import integrityTest from './integrityTestTemplate'; import loadFramework from '../frameworks/frameworkLoader'; import type { StoryshotsOptions } from './StoryshotsOptions'; -const { describe, window: globalWindow } = global; +const { describe } = globalThis; type TestMethod = 'beforeAll' | 'beforeEach' | 'afterEach' | 'afterAll'; const methods: TestMethod[] = ['beforeAll', 'beforeEach', 'afterEach', 'afterAll']; -function callTestMethodGlobals( - testMethod: { [key in TestMethod]?: Function & { timeout?: number } } & { [key in string]: any } -) { +function callTestMethodGlobals(testMethod: { + [key in TestMethod]?: jest.Lifecycle & { timeout?: number }; +}) { methods.forEach((method) => { if (typeof testMethod[method] === 'function') { - global[method](testMethod[method], testMethod[method].timeout); + globalThis[method](testMethod[method], testMethod[method].timeout); } }); } @@ -52,7 +51,7 @@ function testStorySnapshots(options: StoryshotsOptions = {}) { // will run *immediately* (in the same tick), and thus the `snapshotsTests`, and // subsequent calls to `it()` etc will all happen within this tick, which is required // by Jest (cannot add tests asynchronously) - globalWindow.__STORYBOOK_STORY_STORE__.initializationPromise.then(() => { + globalThis.__STORYBOOK_STORY_STORE__.initializationPromise.then(() => { const data = storybook.raw().reduce( (acc, item) => { if (storyNameRegex && !item.name.match(storyNameRegex)) { diff --git a/code/addons/storyshots/storyshots-core/src/api/integrityTestTemplate.ts b/code/addons/storyshots/storyshots-core/src/api/integrityTestTemplate.ts index d52260268104..93e744266d9d 100644 --- a/code/addons/storyshots/storyshots-core/src/api/integrityTestTemplate.ts +++ b/code/addons/storyshots/storyshots-core/src/api/integrityTestTemplate.ts @@ -1,10 +1,9 @@ /* eslint-disable jest/no-export */ import fs from 'fs'; import glob from 'glob'; -import global from 'global'; import { dedent } from 'ts-dedent'; -const { describe, it } = global; +const { describe, it } = globalThis; expect.extend({ notToBeAbandoned(storyshots, stories2snapsConverter) { diff --git a/code/addons/storyshots/storyshots-core/src/api/snapshotsTestsTemplate.ts b/code/addons/storyshots/storyshots-core/src/api/snapshotsTestsTemplate.ts index c22679a11a83..1d41a4e95d40 100644 --- a/code/addons/storyshots/storyshots-core/src/api/snapshotsTestsTemplate.ts +++ b/code/addons/storyshots/storyshots-core/src/api/snapshotsTestsTemplate.ts @@ -1,9 +1,8 @@ /* eslint-disable jest/no-export */ /* eslint-disable jest/expect-expect */ -import global from 'global'; import { addSerializer } from 'jest-specific-snapshot'; -const { describe, it } = global; +const { describe, it } = globalThis; function snapshotTest({ item, asyncJest, framework, testMethod, testMethodParams }: any) { const { name } = item; diff --git a/code/addons/storyshots/storyshots-core/src/frameworks/configure.ts b/code/addons/storyshots/storyshots-core/src/frameworks/configure.ts index d2a029c27a44..dc751593222b 100644 --- a/code/addons/storyshots/storyshots-core/src/frameworks/configure.ts +++ b/code/addons/storyshots/storyshots-core/src/frameworks/configure.ts @@ -11,7 +11,6 @@ import type { import { toRequireContext } from '@storybook/core-webpack'; import { normalizeStoriesEntry } from '@storybook/core-common'; import registerRequireContextHook from '@storybook/babel-plugin-require-context-hook/register'; -import global from 'global'; import type { ClientApi } from './Loader'; import type { StoryshotsOptions } from '../api/StoryshotsOptions'; @@ -76,8 +75,9 @@ function getConfigPathParts(input: string): Output { output.requireContexts = output.stories.map((specifier) => { const { path: basePath, recursive, match } = toRequireContext(specifier); + // @ts-expect-error __requireContext is added by babel-plugin-require-context-hook // eslint-disable-next-line no-underscore-dangle - return global.__requireContext(workingDir, basePath, recursive, match); + return globalThis.__requireContext(workingDir, basePath, recursive, match); }); } @@ -106,8 +106,8 @@ function configure( requireContexts = [], } = getConfigPathParts(configPath); - global.FEATURES = features; - global.STORIES = stories.map((specifier) => ({ + globalThis.FEATURES = features; + globalThis.STORIES = stories.map((specifier) => ({ ...specifier, importPathMatcher: specifier.importPathMatcher.source, })); diff --git a/code/addons/storyshots/storyshots-core/src/frameworks/html/loader.ts b/code/addons/storyshots/storyshots-core/src/frameworks/html/loader.ts index d75c563eef2b..2800736a31f9 100644 --- a/code/addons/storyshots/storyshots-core/src/frameworks/html/loader.ts +++ b/code/addons/storyshots/storyshots-core/src/frameworks/html/loader.ts @@ -1,4 +1,3 @@ -import global from 'global'; import configure from '../configure'; import type { Loader } from '../Loader'; import type { StoryshotsOptions } from '../../api/StoryshotsOptions'; @@ -8,7 +7,7 @@ function test(options: StoryshotsOptions): boolean { } function load(options: StoryshotsOptions) { - global.STORYBOOK_ENV = 'html'; + globalThis.STORYBOOK_ENV = 'html'; let mockStartedAPI: any; diff --git a/code/addons/storyshots/storyshots-core/src/frameworks/html/renderTree.ts b/code/addons/storyshots/storyshots-core/src/frameworks/html/renderTree.ts index 102d18e82bcf..61d2dcf69534 100644 --- a/code/addons/storyshots/storyshots-core/src/frameworks/html/renderTree.ts +++ b/code/addons/storyshots/storyshots-core/src/frameworks/html/renderTree.ts @@ -1,6 +1,4 @@ -import global from 'global'; - -const { document, Node } = global; +const { document, Node } = globalThis; function getRenderedTree(story: { render: () => any }) { const component = story.render(); diff --git a/code/addons/storyshots/storyshots-core/src/frameworks/preact/loader.ts b/code/addons/storyshots/storyshots-core/src/frameworks/preact/loader.ts index b02ccaf30412..8c8e0e1f53bc 100644 --- a/code/addons/storyshots/storyshots-core/src/frameworks/preact/loader.ts +++ b/code/addons/storyshots/storyshots-core/src/frameworks/preact/loader.ts @@ -1,7 +1,6 @@ /** @jsxRuntime classic */ /** @jsx h */ -import global from 'global'; import configure from '../configure'; import hasDependency from '../hasDependency'; import type { Loader } from '../Loader'; @@ -14,7 +13,7 @@ function test(options: StoryshotsOptions): boolean { } function load(options: StoryshotsOptions) { - global.STORYBOOK_ENV = 'preact'; + globalThis.STORYBOOK_ENV = 'preact'; let mockStartedAPI: any; diff --git a/code/addons/storyshots/storyshots-core/src/frameworks/rax/loader.ts b/code/addons/storyshots/storyshots-core/src/frameworks/rax/loader.ts index ffe67f771544..d5b33b2df2b6 100644 --- a/code/addons/storyshots/storyshots-core/src/frameworks/rax/loader.ts +++ b/code/addons/storyshots/storyshots-core/src/frameworks/rax/loader.ts @@ -1,4 +1,3 @@ -import global from 'global'; import configure from '../configure'; import hasDependency from '../hasDependency'; import type { Loader } from '../Loader'; @@ -9,7 +8,7 @@ function test(options: StoryshotsOptions): boolean { } function load(options: StoryshotsOptions) { - global.STORYBOOK_ENV = 'rax'; + globalThis.STORYBOOK_ENV = 'rax'; let mockStartedAPI: any; diff --git a/code/addons/storyshots/storyshots-core/src/frameworks/riot/loader.ts b/code/addons/storyshots/storyshots-core/src/frameworks/riot/loader.ts index 8a174ee11af8..2af615694cba 100644 --- a/code/addons/storyshots/storyshots-core/src/frameworks/riot/loader.ts +++ b/code/addons/storyshots/storyshots-core/src/frameworks/riot/loader.ts @@ -1,4 +1,3 @@ -import global from 'global'; import hasDependency from '../hasDependency'; import configure from '../configure'; import type { Loader } from '../Loader'; @@ -13,7 +12,7 @@ function test(options: StoryshotsOptions): boolean { } function load(options: StoryshotsOptions) { - global.STORYBOOK_ENV = 'riot'; + globalThis.STORYBOOK_ENV = 'riot'; mockRiotToIncludeCompiler(); let mockStartedAPI: any; diff --git a/code/addons/storyshots/storyshots-core/src/frameworks/riot/renderTree.ts b/code/addons/storyshots/storyshots-core/src/frameworks/riot/renderTree.ts index c4f1ce24419d..23a487e62c6f 100644 --- a/code/addons/storyshots/storyshots-core/src/frameworks/riot/renderTree.ts +++ b/code/addons/storyshots/storyshots-core/src/frameworks/riot/renderTree.ts @@ -1,6 +1,4 @@ -import global from 'global'; - -const { document } = global; +const { document } = globalThis; const riotForStorybook = jest.requireActual('@storybook/riot'); diff --git a/code/addons/storyshots/storyshots-core/src/frameworks/svelte/loader.ts b/code/addons/storyshots/storyshots-core/src/frameworks/svelte/loader.ts index 0135af40b649..d316dc64fd56 100644 --- a/code/addons/storyshots/storyshots-core/src/frameworks/svelte/loader.ts +++ b/code/addons/storyshots/storyshots-core/src/frameworks/svelte/loader.ts @@ -1,4 +1,3 @@ -import global from 'global'; import hasDependency from '../hasDependency'; import configure from '../configure'; import type { Loader } from '../Loader'; @@ -11,7 +10,7 @@ function test(options: StoryshotsOptions): boolean { } function load(options: StoryshotsOptions) { - global.STORYBOOK_ENV = 'svelte'; + globalThis.STORYBOOK_ENV = 'svelte'; let mockStartedAPI: any; diff --git a/code/addons/storyshots/storyshots-core/src/frameworks/svelte/renderTree.ts b/code/addons/storyshots/storyshots-core/src/frameworks/svelte/renderTree.ts index 9d75b8b31f59..14259534e9f9 100644 --- a/code/addons/storyshots/storyshots-core/src/frameworks/svelte/renderTree.ts +++ b/code/addons/storyshots/storyshots-core/src/frameworks/svelte/renderTree.ts @@ -1,7 +1,6 @@ -import global from 'global'; import { set_current_component } from 'svelte/internal'; -const { document } = global; +const { document } = globalThis; /** * Provides functionality to convert your raw story to the resulting markup. diff --git a/code/addons/storyshots/storyshots-core/src/frameworks/vue/loader.ts b/code/addons/storyshots/storyshots-core/src/frameworks/vue/loader.ts index 02ef63c066d5..dbef6ef29393 100644 --- a/code/addons/storyshots/storyshots-core/src/frameworks/vue/loader.ts +++ b/code/addons/storyshots/storyshots-core/src/frameworks/vue/loader.ts @@ -1,4 +1,3 @@ -import global from 'global'; import hasDependency from '../hasDependency'; import configure from '../configure'; import type { Loader } from '../Loader'; @@ -13,7 +12,7 @@ function test(options: StoryshotsOptions): boolean { } function load(options: StoryshotsOptions) { - global.STORYBOOK_ENV = 'vue'; + globalThis.STORYBOOK_ENV = 'vue'; mockVueToIncludeCompiler(); let mockStartedAPI: any; diff --git a/code/addons/storyshots/storyshots-core/src/frameworks/vue3/loader.ts b/code/addons/storyshots/storyshots-core/src/frameworks/vue3/loader.ts index 91d40dd35d7c..751c04e8e5c2 100644 --- a/code/addons/storyshots/storyshots-core/src/frameworks/vue3/loader.ts +++ b/code/addons/storyshots/storyshots-core/src/frameworks/vue3/loader.ts @@ -1,4 +1,3 @@ -import global from 'global'; import hasDependency from '../hasDependency'; import configure from '../configure'; import type { Loader } from '../Loader'; @@ -9,7 +8,7 @@ function test(options: StoryshotsOptions): boolean { } function load(options: StoryshotsOptions) { - global.STORYBOOK_ENV = 'vue3'; + globalThis.STORYBOOK_ENV = 'vue3'; let mockStartedAPI: any; diff --git a/code/addons/storyshots/storyshots-core/src/frameworks/vue3/renderTree.ts b/code/addons/storyshots/storyshots-core/src/frameworks/vue3/renderTree.ts index bcc8b5b3b165..0b2c4644741d 100644 --- a/code/addons/storyshots/storyshots-core/src/frameworks/vue3/renderTree.ts +++ b/code/addons/storyshots/storyshots-core/src/frameworks/vue3/renderTree.ts @@ -1,7 +1,6 @@ import * as Vue from 'vue'; -import global from 'global'; -const { document } = global; +const { document } = globalThis; // This is cast as `any` to workaround type errors caused by Vue 2 types const { h, createApp } = Vue as any; diff --git a/code/addons/storyshots/storyshots-core/src/frameworks/web-components/loader.ts b/code/addons/storyshots/storyshots-core/src/frameworks/web-components/loader.ts index 41ac97a75117..0eed9cc5466a 100644 --- a/code/addons/storyshots/storyshots-core/src/frameworks/web-components/loader.ts +++ b/code/addons/storyshots/storyshots-core/src/frameworks/web-components/loader.ts @@ -1,4 +1,3 @@ -import global from 'global'; import configure from '../configure'; import type { Loader } from '../Loader'; import type { StoryshotsOptions } from '../../api/StoryshotsOptions'; @@ -8,7 +7,7 @@ function test(options: StoryshotsOptions): boolean { } function load(options: StoryshotsOptions) { - global.STORYBOOK_ENV = 'web-components'; + globalThis.STORYBOOK_ENV = 'web-components'; let mockStartedAPI: any; diff --git a/code/addons/storyshots/storyshots-core/src/typings.d.ts b/code/addons/storyshots/storyshots-core/src/typings.d.ts index 03f1a3f1a323..b9eb11abea15 100644 --- a/code/addons/storyshots/storyshots-core/src/typings.d.ts +++ b/code/addons/storyshots/storyshots-core/src/typings.d.ts @@ -1,4 +1,3 @@ -declare module 'global'; declare module 'jest-preset-angular/*'; declare module 'preact-render-to-string/jsx'; declare module 'react-test-renderer*'; diff --git a/code/addons/toolbars/template/stories/globals.stories.ts b/code/addons/toolbars/template/stories/globals.stories.ts index e5567bcb1513..99a7ed8a043f 100644 --- a/code/addons/toolbars/template/stories/globals.stories.ts +++ b/code/addons/toolbars/template/stories/globals.stories.ts @@ -1,4 +1,3 @@ -import globalThis from 'global'; import type { PartialStoryFn, StoryContext } from '@storybook/types'; const greetingForLocale = (locale: string) => { diff --git a/code/addons/viewport/package.json b/code/addons/viewport/package.json index bd0a735b62cd..9ba304191cc8 100644 --- a/code/addons/viewport/package.json +++ b/code/addons/viewport/package.json @@ -78,7 +78,6 @@ "@storybook/manager-api": "7.0.0-alpha.54", "@storybook/preview-api": "7.0.0-alpha.54", "@storybook/theming": "7.0.0-alpha.54", - "global": "^4.4.0", "memoizerific": "^1.11.3", "prop-types": "^15.7.2" }, diff --git a/code/addons/viewport/template/stories/parameters.stories.ts b/code/addons/viewport/template/stories/parameters.stories.ts index 03b2b9e264c9..b0d0495daf26 100644 --- a/code/addons/viewport/template/stories/parameters.stories.ts +++ b/code/addons/viewport/template/stories/parameters.stories.ts @@ -1,4 +1,3 @@ -import globalThis from 'global'; import { MINIMAL_VIEWPORTS } from '@storybook/addon-viewport'; export default { diff --git a/code/frameworks/angular/package.json b/code/frameworks/angular/package.json index d6e21af0fbce..5b99f7efe344 100644 --- a/code/frameworks/angular/package.json +++ b/code/frameworks/angular/package.json @@ -53,7 +53,6 @@ "@types/webpack-env": "^1.18.0", "core-js": "^3.8.2", "find-up": "^5.0.0", - "global": "^4.4.0", "react": "^16.14.0", "react-dom": "^16.14.0", "read-pkg-up": "^7.0.1", diff --git a/code/frameworks/angular/setup-jest.ts b/code/frameworks/angular/setup-jest.ts index 06e753a2e78e..28ee36590de9 100644 --- a/code/frameworks/angular/setup-jest.ts +++ b/code/frameworks/angular/setup-jest.ts @@ -1,6 +1,5 @@ // eslint-disable-next-line import/no-extraneous-dependencies import 'jest-preset-angular/setup-jest'; - import { webcrypto } from 'node:crypto'; Object.defineProperty(window, 'crypto', { @@ -9,4 +8,4 @@ Object.defineProperty(window, 'crypto', { }, }); -global.EventSource = class {} as any; +globalThis.EventSource = class {} as any; diff --git a/code/frameworks/angular/src/client/angular-beta/RendererFactory.ts b/code/frameworks/angular/src/client/angular-beta/RendererFactory.ts index 888024d83614..27a3acf42951 100644 --- a/code/frameworks/angular/src/client/angular-beta/RendererFactory.ts +++ b/code/frameworks/angular/src/client/angular-beta/RendererFactory.ts @@ -50,11 +50,11 @@ export const getRenderType = (targetDOMNode: HTMLElement): RenderType => { export function clearRootHTMLElement(renderType: RenderType) { switch (renderType) { case 'canvas': - global.document.getElementById('storybook-docs').innerHTML = ''; + globalThis.document.getElementById('storybook-docs').innerHTML = ''; break; case 'docs': - global.document.getElementById('storybook-root').innerHTML = ''; + globalThis.document.getElementById('storybook-root').innerHTML = ''; break; default: break; diff --git a/code/frameworks/angular/src/client/angular/helpers.ts b/code/frameworks/angular/src/client/angular/helpers.ts index 10ce71718090..eb8238183e12 100644 --- a/code/frameworks/angular/src/client/angular/helpers.ts +++ b/code/frameworks/angular/src/client/angular/helpers.ts @@ -1,4 +1,3 @@ -import global from 'global'; import { NgModuleRef, Type, enableProdMode, NgModule, Component, NgZone } from '@angular/core'; import { FormsModule } from '@angular/forms'; import { platformBrowserDynamic } from '@angular/platform-browser-dynamic'; @@ -9,13 +8,7 @@ import { AppComponent } from './app.component'; import { STORY } from './app.token'; import { NgModuleMetadata, StoryFnAngularReturnType, AngularRenderer } from '../types'; -const { document } = global; - -declare global { - interface Window { - NODE_ENV: 'string' | 'development' | undefined; - } -} +const { document } = globalThis; let platform: any = null; let promises: Promise>[] = []; diff --git a/code/frameworks/angular/src/client/globals.ts b/code/frameworks/angular/src/client/globals.ts index e6e55cbf924d..fe93af8d3bf8 100644 --- a/code/frameworks/angular/src/client/globals.ts +++ b/code/frameworks/angular/src/client/globals.ts @@ -1,5 +1,3 @@ -import global from 'global'; - /** * This file includes polyfills needed by Angular and is loaded before the app. * You can add your own extra polyfills to this file. @@ -68,6 +66,4 @@ import 'zone.js/dist/zone'; // Included with Angular CLI. */ // import 'intl/locale-data/jsonp/en'; -const { window: globalWindow } = global; - -globalWindow.STORYBOOK_ENV = 'angular'; +globalThis.STORYBOOK_ENV = 'angular'; diff --git a/code/frameworks/angular/src/typings.d.ts b/code/frameworks/angular/src/typings.d.ts index d8f7c6f660ad..cbeccdbb15f7 100644 --- a/code/frameworks/angular/src/typings.d.ts +++ b/code/frameworks/angular/src/typings.d.ts @@ -1,4 +1,2 @@ -declare module 'global'; - // will be provided by the webpack define plugin declare var NODE_ENV: string | undefined; diff --git a/code/frameworks/angular/template/components/index.js b/code/frameworks/angular/template/components/index.js index 11d1c72443bf..5d655fd952cd 100644 --- a/code/frameworks/angular/template/components/index.js +++ b/code/frameworks/angular/template/components/index.js @@ -1,5 +1,3 @@ -import globalThis from 'global'; - import Button from './button.component'; import Html from './html.component'; import Pre from './pre.component'; diff --git a/code/frameworks/angular/template/stories/angular-mdx.stories.mdx b/code/frameworks/angular/template/stories/angular-mdx.stories.mdx index 025f8c0663fc..632abbeda706 100644 --- a/code/frameworks/angular/template/stories/angular-mdx.stories.mdx +++ b/code/frameworks/angular/template/stories/angular-mdx.stories.mdx @@ -1,4 +1,3 @@ -import globalThis from 'global'; import { moduleMetadata } from '@storybook/angular'; import { Meta, Story, Canvas } from '@storybook/addon-docs'; diff --git a/code/frameworks/ember/package.json b/code/frameworks/ember/package.json index 4fd36ad9fa3d..4baf042d6049 100644 --- a/code/frameworks/ember/package.json +++ b/code/frameworks/ember/package.json @@ -36,7 +36,6 @@ "@storybook/docs-tools": "7.0.0-alpha.54", "@storybook/preview-api": "7.0.0-alpha.54", "@storybook/types": "7.0.0-alpha.54", - "global": "^4.4.0", "react": "16.14.0", "react-dom": "16.14.0", "read-pkg-up": "^7.0.1", diff --git a/code/frameworks/ember/src/client/preview/globals.ts b/code/frameworks/ember/src/client/preview/globals.ts index 5bb968d5c148..2d2e3e417987 100644 --- a/code/frameworks/ember/src/client/preview/globals.ts +++ b/code/frameworks/ember/src/client/preview/globals.ts @@ -1,6 +1,6 @@ -import global from 'global'; +import '../../../typings.d'; -const { window: globalWindow } = global; +globalThis.STORYBOOK_NAME = process.env.STORYBOOK_NAME; +globalThis.STORYBOOK_ENV = 'ember'; -globalWindow.STORYBOOK_NAME = process.env.STORYBOOK_NAME; -globalWindow.STORYBOOK_ENV = 'ember'; +export {}; diff --git a/code/frameworks/ember/src/client/preview/render.ts b/code/frameworks/ember/src/client/preview/render.ts index 9c9a61d96933..b4836ad9116a 100644 --- a/code/frameworks/ember/src/client/preview/render.ts +++ b/code/frameworks/ember/src/client/preview/render.ts @@ -1,16 +1,16 @@ -import global from 'global'; import { dedent } from 'ts-dedent'; import type { RenderContext } from '@storybook/types'; // @ts-expect-error (Converted from ts-ignore) import Component from '@ember/component'; // eslint-disable-line import/no-unresolved +import '../../../typings.d'; import type { OptionsArgs, EmberRenderer } from './types'; -const { window: globalWindow, document } = global; +const { document } = globalThis; const rootEl = document.getElementById('storybook-root'); -const config = globalWindow.require(`${globalWindow.STORYBOOK_NAME}/config/environment`); -const app = globalWindow.require(`${globalWindow.STORYBOOK_NAME}/app`).default.create({ +const config = globalThis.require(`${globalThis.STORYBOOK_NAME}/config/environment`); +const app = globalThis.require(`${globalThis.STORYBOOK_NAME}/app`).default.create({ autoboot: false, rootElement: rootEl, ...config.APP, diff --git a/code/frameworks/ember/src/typings.d.ts b/code/frameworks/ember/src/typings.d.ts index e05c56b846e3..925efd201224 100644 --- a/code/frameworks/ember/src/typings.d.ts +++ b/code/frameworks/ember/src/typings.d.ts @@ -1,2 +1 @@ declare module 'ember-source/dist/ember-template-compiler'; -declare module 'global'; diff --git a/code/frameworks/ember/typings.d.ts b/code/frameworks/ember/typings.d.ts new file mode 100644 index 000000000000..c3ee2cd8846d --- /dev/null +++ b/code/frameworks/ember/typings.d.ts @@ -0,0 +1,5 @@ +declare global { + var STORYBOOK_NAME: string | undefined; +} + +export {}; diff --git a/code/frameworks/html-webpack5/package.json b/code/frameworks/html-webpack5/package.json index 71c418c84151..44edefb9b0a7 100644 --- a/code/frameworks/html-webpack5/package.json +++ b/code/frameworks/html-webpack5/package.json @@ -55,7 +55,6 @@ "@storybook/html": "7.0.0-alpha.54", "@storybook/preset-html-webpack": "7.0.0-alpha.54", "@types/node": "^16.0.0", - "global": "^4.4.0", "react": "16.14.0", "react-dom": "16.14.0" }, diff --git a/code/frameworks/html-webpack5/src/typings.d.ts b/code/frameworks/html-webpack5/src/typings.d.ts index d8f7c6f660ad..cbeccdbb15f7 100644 --- a/code/frameworks/html-webpack5/src/typings.d.ts +++ b/code/frameworks/html-webpack5/src/typings.d.ts @@ -1,4 +1,2 @@ -declare module 'global'; - // will be provided by the webpack define plugin declare var NODE_ENV: string | undefined; diff --git a/code/frameworks/preact-webpack5/src/typings.d.ts b/code/frameworks/preact-webpack5/src/typings.d.ts deleted file mode 100644 index 2f4eb9cf4fd9..000000000000 --- a/code/frameworks/preact-webpack5/src/typings.d.ts +++ /dev/null @@ -1 +0,0 @@ -declare module 'global'; diff --git a/code/frameworks/react-webpack5/src/typings.d.ts b/code/frameworks/react-webpack5/src/typings.d.ts index ce0c26f59d0a..53aa2b04a775 100644 --- a/code/frameworks/react-webpack5/src/typings.d.ts +++ b/code/frameworks/react-webpack5/src/typings.d.ts @@ -1,5 +1,3 @@ -declare module 'global'; - // TODO: Replace, as soon as @types/react-dom 17.0.14 is used // Source: https://github.com/DefinitelyTyped/DefinitelyTyped/blob/fb0f14b7a35cde26ffaa82e7536c062e593e9ae6/types/react-dom/client.d.ts declare module 'react-dom/client' { diff --git a/code/frameworks/svelte-webpack5/src/typings.d.ts b/code/frameworks/svelte-webpack5/src/typings.d.ts index 153074abe8ca..48e7ba6228fd 100644 --- a/code/frameworks/svelte-webpack5/src/typings.d.ts +++ b/code/frameworks/svelte-webpack5/src/typings.d.ts @@ -1,4 +1,3 @@ -declare module 'global'; declare module '@storybook/svelte/templates/SlotDecorator.svelte'; declare module '@storybook/svelte/templates/PreviewRender.svelte'; declare module '@storybook/svelte/templates/HOC.svelte'; diff --git a/code/frameworks/vue-webpack5/src/typings.d.ts b/code/frameworks/vue-webpack5/src/typings.d.ts index b3f023454b60..45d6411e8736 100644 --- a/code/frameworks/vue-webpack5/src/typings.d.ts +++ b/code/frameworks/vue-webpack5/src/typings.d.ts @@ -1,3 +1 @@ -declare module 'global'; - declare module 'vue-loader/lib/plugin'; diff --git a/code/frameworks/vue3-webpack5/src/typings.d.ts b/code/frameworks/vue3-webpack5/src/typings.d.ts index 3229acac0222..a045728260a0 100644 --- a/code/frameworks/vue3-webpack5/src/typings.d.ts +++ b/code/frameworks/vue3-webpack5/src/typings.d.ts @@ -1,5 +1,3 @@ -declare module 'global'; - declare module 'vue-loader' { export const VueLoaderPlugin: any; } diff --git a/code/frameworks/web-components-webpack5/src/typings.d.ts b/code/frameworks/web-components-webpack5/src/typings.d.ts index d8f7c6f660ad..cbeccdbb15f7 100644 --- a/code/frameworks/web-components-webpack5/src/typings.d.ts +++ b/code/frameworks/web-components-webpack5/src/typings.d.ts @@ -1,4 +1,2 @@ -declare module 'global'; - // will be provided by the webpack define plugin declare var NODE_ENV: string | undefined; diff --git a/code/lib/builder-webpack5/package.json b/code/lib/builder-webpack5/package.json index aa25947d8215..72505d936a35 100644 --- a/code/lib/builder-webpack5/package.json +++ b/code/lib/builder-webpack5/package.json @@ -82,7 +82,6 @@ "express": "^4.17.1", "fork-ts-checker-webpack-plugin": "^7.2.8", "fs-extra": "^9.0.1", - "global": "^4.4.0", "html-webpack-plugin": "^5.5.0", "path-browserify": "^1.0.1", "process": "^0.11.10", diff --git a/code/lib/builder-webpack5/templates/virtualModuleModernEntry.js.handlebars b/code/lib/builder-webpack5/templates/virtualModuleModernEntry.js.handlebars index 62b3fe1d603c..db6556b5ada9 100644 --- a/code/lib/builder-webpack5/templates/virtualModuleModernEntry.js.handlebars +++ b/code/lib/builder-webpack5/templates/virtualModuleModernEntry.js.handlebars @@ -1,12 +1,10 @@ -import global from 'global'; - import { ClientApi, PreviewWeb, addons, composeConfigs } from '@storybook/preview-api'; import { createChannel as createPostMessageChannel } from '@storybook/channel-postmessage'; import { createChannel as createWebSocketChannel } from '@storybook/channel-websocket'; import { importFn } from './{{storiesFilename}}'; -const { SERVER_CHANNEL_URL } = global; +const { SERVER_CHANNEL_URL } = globalThis; const getProjectAnnotations = () => composeConfigs([{{#each previewAnnotations}}require('{{this}}'),{{/each}}]); @@ -39,4 +37,4 @@ if (import.meta.webpackHot) { // getProjectAnnotations has changed so we need to patch the new one in preview.onGetProjectAnnotationsChanged({ getProjectAnnotations }); }); -} \ No newline at end of file +} diff --git a/code/lib/builder-webpack5/typings.d.ts b/code/lib/builder-webpack5/typings.d.ts index 53e966a9d29e..df888b533e90 100644 --- a/code/lib/builder-webpack5/typings.d.ts +++ b/code/lib/builder-webpack5/typings.d.ts @@ -1,3 +1,2 @@ declare module 'lazy-universal-dotenv'; declare module '@storybook/theming/paths'; -declare module 'global'; diff --git a/code/lib/channel-postmessage/package.json b/code/lib/channel-postmessage/package.json index c7bad282f0b3..953152acac42 100644 --- a/code/lib/channel-postmessage/package.json +++ b/code/lib/channel-postmessage/package.json @@ -45,7 +45,6 @@ "@storybook/channels": "7.0.0-alpha.54", "@storybook/client-logger": "7.0.0-alpha.54", "@storybook/core-events": "7.0.0-alpha.54", - "global": "^4.4.0", "qs": "^6.10.0", "telejson": "^7.0.3" }, diff --git a/code/lib/channel-postmessage/src/index.ts b/code/lib/channel-postmessage/src/index.ts index 2d697ddf6908..8bbc9d5db3d0 100644 --- a/code/lib/channel-postmessage/src/index.ts +++ b/code/lib/channel-postmessage/src/index.ts @@ -1,4 +1,3 @@ -import global from 'global'; import * as EVENTS from '@storybook/core-events'; import { Channel } from '@storybook/channels'; import type { ChannelHandler, ChannelEvent } from '@storybook/channels'; @@ -6,7 +5,7 @@ import { logger, pretty } from '@storybook/client-logger'; import { isJSON, parse, stringify } from 'telejson'; import qs from 'qs'; -const { window: globalWindow, document, location } = global; +const { document, location } = globalThis; interface Config { page: 'manager' | 'preview'; @@ -36,9 +35,7 @@ export class PostmsgTransport { constructor(private readonly config: Config) { this.buffer = []; this.handler = null; - if (globalWindow) { - globalWindow.addEventListener('message', this.handleEvent.bind(this), false); - } + globalThis.addEventListener('message', this.handleEvent.bind(this), false); // Check whether the config.page parameter has a valid value if (config.page !== 'manager' && config.page !== 'preview') { @@ -94,7 +91,7 @@ export class PostmsgTransport { const stringifyOptions = { ...defaultEventOptions, - ...(global.CHANNEL_OPTIONS || {}), + ...(globalThis.CHANNEL_OPTIONS || {}), ...eventOptions, }; @@ -141,9 +138,9 @@ export class PostmsgTransport { private getFrames(target?: string): Window[] { if (this.config.page === 'manager') { - const nodes: HTMLIFrameElement[] = [ - ...document.querySelectorAll('iframe[data-is-storybook][data-is-loaded]'), - ]; + const nodes: HTMLIFrameElement[] = Array.prototype.slice.apply( + document.querySelectorAll('iframe[data-is-storybook][data-is-loaded]') + ); const list = nodes .filter((e) => { @@ -157,8 +154,10 @@ export class PostmsgTransport { return list.length ? list : this.getCurrentFrames(); } - if (globalWindow && globalWindow.parent && globalWindow.parent !== globalWindow) { - return [globalWindow.parent]; + + // @ts-expect-error I'll be honest, not sure what this check is for + if (globalThis.parent && globalThis.parent !== globalThis) { + return [globalThis.parent]; } return []; @@ -166,13 +165,13 @@ export class PostmsgTransport { private getCurrentFrames(): Window[] { if (this.config.page === 'manager') { - const list: HTMLIFrameElement[] = [ - ...document.querySelectorAll('[data-is-storybook="true"]'), - ]; + const list: HTMLIFrameElement[] = Array.prototype.slice.apply( + document.querySelectorAll('[data-is-storybook="true"]') + ); return list.map((e) => e.contentWindow); } - if (globalWindow && globalWindow.parent) { - return [globalWindow.parent]; + if (globalThis && globalThis.parent) { + return [globalThis.parent]; } return []; @@ -180,11 +179,13 @@ export class PostmsgTransport { private getLocalFrame(): Window[] { if (this.config.page === 'manager') { - const list: HTMLIFrameElement[] = [...document.querySelectorAll('#storybook-preview-iframe')]; + const list: HTMLIFrameElement[] = Array.prototype.slice.apply( + document.querySelectorAll('#storybook-preview-iframe') + ); return list.map((e) => e.contentWindow); } - if (globalWindow && globalWindow.parent) { - return [globalWindow.parent]; + if (globalThis && globalThis.parent) { + return [globalThis.parent]; } return []; @@ -194,7 +195,9 @@ export class PostmsgTransport { try { const { data } = rawEvent; const { key, event, refId } = - typeof data === 'string' && isJSON(data) ? parse(data, global.CHANNEL_OPTIONS || {}) : data; + typeof data === 'string' && isJSON(data) + ? parse(data, globalThis.CHANNEL_OPTIONS || {}) + : data; if (key === KEY) { const pageString = @@ -237,7 +240,9 @@ export class PostmsgTransport { } const getEventSourceUrl = (event: MessageEvent) => { - const frames = [...document.querySelectorAll('iframe[data-is-storybook]')]; + const frames = Array.prototype.slice.apply( + document.querySelectorAll('iframe[data-is-storybook]') + ); // try to find the originating iframe by matching it's contentWindow // This might not be cross-origin safe const [frame, ...remainder] = frames.filter((element) => { @@ -251,7 +256,7 @@ const getEventSourceUrl = (event: MessageEvent) => { let origin; try { - ({ origin } = new URL(src, document.location)); + ({ origin } = new URL(src, document.location.toString())); } catch (err) { return false; } @@ -260,7 +265,7 @@ const getEventSourceUrl = (event: MessageEvent) => { if (frame && remainder.length === 0) { const src = frame.getAttribute('src'); - const { protocol, host, pathname } = new URL(src, document.location); + const { protocol, host, pathname } = new URL(src, document.location.toString()); return `${protocol}//${host}${pathname}`; } diff --git a/code/lib/channel-postmessage/src/typings.d.ts b/code/lib/channel-postmessage/src/typings.d.ts deleted file mode 100644 index 2f4eb9cf4fd9..000000000000 --- a/code/lib/channel-postmessage/src/typings.d.ts +++ /dev/null @@ -1 +0,0 @@ -declare module 'global'; diff --git a/code/lib/channel-websocket/package.json b/code/lib/channel-websocket/package.json index 3d891df0cb19..5e19e5f16641 100644 --- a/code/lib/channel-websocket/package.json +++ b/code/lib/channel-websocket/package.json @@ -44,7 +44,6 @@ "dependencies": { "@storybook/channels": "7.0.0-alpha.54", "@storybook/client-logger": "7.0.0-alpha.54", - "global": "^4.4.0", "telejson": "^7.0.3" }, "devDependencies": { diff --git a/code/lib/channel-websocket/src/index.ts b/code/lib/channel-websocket/src/index.ts index fb5628be5032..2cd4742b9adb 100644 --- a/code/lib/channel-websocket/src/index.ts +++ b/code/lib/channel-websocket/src/index.ts @@ -1,10 +1,9 @@ -import global from 'global'; import { Channel } from '@storybook/channels'; import type { ChannelHandler } from '@storybook/channels'; import { logger } from '@storybook/client-logger'; import { isJSON, parse, stringify } from 'telejson'; -const { WebSocket } = global; +const { WebSocket } = globalThis; type OnError = (message: Event) => void; diff --git a/code/lib/channel-websocket/src/typings.d.ts b/code/lib/channel-websocket/src/typings.d.ts index 8f141185b8ae..36dadd3de8aa 100644 --- a/code/lib/channel-websocket/src/typings.d.ts +++ b/code/lib/channel-websocket/src/typings.d.ts @@ -1,2 +1 @@ -declare module 'global'; declare module 'json-fn'; diff --git a/code/lib/cli/src/window.d.ts b/code/lib/cli/src/window.d.ts index 19d7aba81c0e..a99e47983897 100644 --- a/code/lib/cli/src/window.d.ts +++ b/code/lib/cli/src/window.d.ts @@ -1,3 +1,4 @@ +/* eslint-disable @typescript-eslint/naming-convention */ import type { Renderer } from '@storybook/types'; import type { StoryStore } from '@storybook/preview-api'; @@ -5,4 +6,5 @@ declare global { interface Window { __STORYBOOK_STORY_STORE__: StoryStore; } + var __STORYBOOK_STORY_STORE__: StoryStore; } diff --git a/code/lib/client-logger/package.json b/code/lib/client-logger/package.json index a212bf078dfa..5e4f22df82cf 100644 --- a/code/lib/client-logger/package.json +++ b/code/lib/client-logger/package.json @@ -41,9 +41,6 @@ "check": "../../../scripts/node_modules/.bin/tsc --noEmit", "prep": "../../../scripts/prepare/bundle.ts" }, - "dependencies": { - "global": "^4.4.0" - }, "devDependencies": { "typescript": "^4.9.3" }, diff --git a/code/lib/client-logger/src/index.ts b/code/lib/client-logger/src/index.ts index eceebe077c87..f2f71f2237c3 100644 --- a/code/lib/client-logger/src/index.ts +++ b/code/lib/client-logger/src/index.ts @@ -1,8 +1,6 @@ -import global from 'global'; +const { LOGLEVEL, console } = globalThis; -const { LOGLEVEL, console } = global; - -type LogLevel = 'trace' | 'debug' | 'info' | 'warn' | 'error' | 'silent'; +type LogLevel = typeof LOGLEVEL; const levels: Record = { trace: 1, @@ -20,17 +18,17 @@ type LoggingFn = (message: any, ...args: any[]) => void; export const logger = { trace: (message: any, ...rest: any[]): void => - currentLogLevelNumber <= levels.trace && console.trace(message, ...rest), + currentLogLevelNumber <= levels.trace ? console.trace(message, ...rest) : undefined, debug: (message: any, ...rest: any[]): void => - currentLogLevelNumber <= levels.debug && console.debug(message, ...rest), + currentLogLevelNumber <= levels.debug ? console.debug(message, ...rest) : undefined, info: (message: any, ...rest: any[]): void => - currentLogLevelNumber <= levels.info && console.info(message, ...rest), + currentLogLevelNumber <= levels.info ? console.info(message, ...rest) : undefined, warn: (message: any, ...rest: any[]): void => - currentLogLevelNumber <= levels.warn && console.warn(message, ...rest), + currentLogLevelNumber <= levels.warn ? console.warn(message, ...rest) : undefined, error: (message: any, ...rest: any[]): void => - currentLogLevelNumber <= levels.error && console.error(message, ...rest), + currentLogLevelNumber <= levels.error ? console.error(message, ...rest) : undefined, log: (message: any, ...rest: any[]): void => - currentLogLevelNumber < levels.silent && console.log(message, ...rest), + currentLogLevelNumber < levels.silent ? console.log(message, ...rest) : undefined, } as const; const logged = new Set(); diff --git a/code/lib/client-logger/src/typings.d.ts b/code/lib/client-logger/src/typings.d.ts deleted file mode 100644 index 2f4eb9cf4fd9..000000000000 --- a/code/lib/client-logger/src/typings.d.ts +++ /dev/null @@ -1 +0,0 @@ -declare module 'global'; diff --git a/code/lib/codemod/src/transforms/__testfixtures__/csf-to-mdx/story-function.input.js b/code/lib/codemod/src/transforms/__testfixtures__/csf-to-mdx/story-function.input.js index 252c25e46667..48d9a71a4733 100644 --- a/code/lib/codemod/src/transforms/__testfixtures__/csf-to-mdx/story-function.input.js +++ b/code/lib/codemod/src/transforms/__testfixtures__/csf-to-mdx/story-function.input.js @@ -1,6 +1,4 @@ -import global from 'global'; - -const { document } = global; +const { document } = globalThis; export default { title: 'Function', diff --git a/code/lib/codemod/src/transforms/__testfixtures__/csf-to-mdx/story-function.output.snapshot b/code/lib/codemod/src/transforms/__testfixtures__/csf-to-mdx/story-function.output.snapshot index af8fa0a24eb8..a4714f7f724d 100644 --- a/code/lib/codemod/src/transforms/__testfixtures__/csf-to-mdx/story-function.output.snapshot +++ b/code/lib/codemod/src/transforms/__testfixtures__/csf-to-mdx/story-function.output.snapshot @@ -1,12 +1,11 @@ // Jest Snapshot v1, https://goo.gl/fbAQLP exports[`csf-to-mdx transforms correctly using "story-function.input.js" data 1`] = ` -"import global from 'global'; -import { Meta, Story } from '@storybook/addon-docs'; +"import { Meta, Story } from '@storybook/addon-docs'; const { document, -} = global; +} = globalThis; {() => { diff --git a/code/lib/core-server/package.json b/code/lib/core-server/package.json index e91174dff42d..8349a1f96927 100644 --- a/code/lib/core-server/package.json +++ b/code/lib/core-server/package.json @@ -57,7 +57,6 @@ "detect-port": "^1.3.0", "express": "^4.17.1", "fs-extra": "^9.0.1", - "global": "^4.4.0", "globby": "^11.0.2", "ip": "^2.0.0", "lodash": "^4.17.21", diff --git a/code/lib/core-server/src/build-dev.ts b/code/lib/core-server/src/build-dev.ts index cd708c8c4ed9..256265d8ecdc 100644 --- a/code/lib/core-server/src/build-dev.ts +++ b/code/lib/core-server/src/build-dev.ts @@ -15,7 +15,6 @@ import { validateFrameworkName, } from '@storybook/core-common'; import prompts from 'prompts'; -import global from 'global'; import { join, resolve } from 'path'; import { logger } from '@storybook/node-logger'; @@ -107,7 +106,7 @@ export async function buildDevStandalone(options: CLIOptions & LoadOptions & Bui }); const features = await presets.apply('features'); - global.FEATURES = features; + globalThis.FEATURES = features; const fullOptions: Options = { ...options, diff --git a/code/lib/core-server/src/build-static.ts b/code/lib/core-server/src/build-static.ts index b9567b6d4530..f1c57507016d 100644 --- a/code/lib/core-server/src/build-static.ts +++ b/code/lib/core-server/src/build-static.ts @@ -2,7 +2,6 @@ import chalk from 'chalk'; import { copy, emptyDir, ensureDir } from 'fs-extra'; import { dirname, isAbsolute, join, resolve } from 'path'; import { dedent } from 'ts-dedent'; -import global from 'global'; import { logger } from '@storybook/node-logger'; import { telemetry } from '@storybook/telemetry'; @@ -121,7 +120,7 @@ export async function buildStaticStandalone( const effects: Promise[] = []; - global.FEATURES = features; + globalThis.FEATURES = features; await managerBuilder.build({ startTime: process.hrtime(), options: fullOptions }); diff --git a/code/lib/core-server/src/typings.d.ts b/code/lib/core-server/src/typings.d.ts index b566e70257c4..d570a59b0e12 100644 --- a/code/lib/core-server/src/typings.d.ts +++ b/code/lib/core-server/src/typings.d.ts @@ -1,4 +1,3 @@ -declare module 'global'; declare module 'lazy-universal-dotenv'; declare module 'pnp-webpack-plugin'; declare module '@storybook/theming/paths'; diff --git a/code/lib/core-server/src/utils/update-check.ts b/code/lib/core-server/src/utils/update-check.ts index f4c463d2e344..553f2df85c4c 100644 --- a/code/lib/core-server/src/utils/update-check.ts +++ b/code/lib/core-server/src/utils/update-check.ts @@ -19,7 +19,7 @@ export const updateCheck = async (version: string): Promise => { const fromFetch: any = await Promise.race([ fetch(`${STORYBOOK_VERSION_BASE}/versions.json?current=${version}`), // if fetch is too slow, we won't wait for it - new Promise((res, rej) => global.setTimeout(rej, 1500)), + new Promise((res, rej) => globalThis.setTimeout(rej, 1500)), ]); const data = await fromFetch.json(); result = { success: true, cached: false, data, time }; diff --git a/code/lib/instrumenter/package.json b/code/lib/instrumenter/package.json index ca1f7bad7ed2..7b9c1324459e 100644 --- a/code/lib/instrumenter/package.json +++ b/code/lib/instrumenter/package.json @@ -46,8 +46,7 @@ "@storybook/client-logger": "7.0.0-alpha.54", "@storybook/core-events": "7.0.0-alpha.54", "@storybook/preview-api": "7.0.0-alpha.54", - "core-js": "^3.8.2", - "global": "^4.4.0" + "core-js": "^3.8.2" }, "devDependencies": { "typescript": "^4.9.3" diff --git a/code/lib/instrumenter/src/instrumenter.test.ts b/code/lib/instrumenter/src/instrumenter.test.ts index 17b4bd2ddc3f..d6bf55809dc0 100644 --- a/code/lib/instrumenter/src/instrumenter.test.ts +++ b/code/lib/instrumenter/src/instrumenter.test.ts @@ -8,7 +8,6 @@ import { SET_CURRENT_STORY, STORY_RENDER_PHASE_CHANGED, } from '@storybook/core-events'; -import global from 'global'; import { EVENTS, Instrumenter } from './instrumenter'; import type { Options } from './types'; @@ -29,12 +28,19 @@ class HTMLElement { } } -delete global.window.location; -global.window.location = { reload: jest.fn() }; -global.window.HTMLElement = HTMLElement; +// Prevent real reloads +delete globalThis.location; +// @ts-expect-error we don't care about the other location attributes +globalThis.location = { reload: jest.fn() }; + +// @ts-expect-error don't need a real HTMLElement +jest.spyOn(globalThis, 'HTMLElement').mockImplementation(() => new HTMLElement()); const storyId = 'kind--story'; -global.window.__STORYBOOK_PREVIEW__ = { urlStore: { selection: { storyId } } }; +jest + .spyOn(globalThis, '__STORYBOOK_PREVIEW__', 'get') + // @ts-expect-error Not creating a full implementation here + .mockImplementation(() => ({ selectionStore: { selection: { storyId } } })); const setRenderPhase = (newPhase: string) => addons.getChannel().emit(STORY_RENDER_PHASE_CHANGED, { newPhase, storyId }); diff --git a/code/lib/instrumenter/src/instrumenter.ts b/code/lib/instrumenter/src/instrumenter.ts index 8085f16b1f24..fe231d45019b 100644 --- a/code/lib/instrumenter/src/instrumenter.ts +++ b/code/lib/instrumenter/src/instrumenter.ts @@ -9,11 +9,12 @@ import { SET_CURRENT_STORY, STORY_RENDER_PHASE_CHANGED, } from '@storybook/core-events'; -import global from 'global'; import type { Call, CallRef, ControlStates, LogItem, Options, State, SyncPayload } from './types'; import { CallStates } from './types'; +const { FEATURES } = globalThis; + export const EVENTS = { CALL: 'storybook/instrumenter/call', SYNC: 'storybook/instrumenter/sync', @@ -28,7 +29,7 @@ type PatchedObj = { [Property in keyof TObj]: TObj[Property] & { __originalFn__: PatchedObj }; }; -const debuggerDisabled = global.FEATURES?.interactionsDebugger !== true; +const debuggerDisabled = FEATURES?.interactionsDebugger !== true; const controlsDisabled: ControlStates = { debugger: !debuggerDisabled, start: false, @@ -101,7 +102,7 @@ export class Instrumenter { this.channel = addons.getChannel(); // Restore state from the parent window in case the iframe was reloaded. - this.state = global.window.parent.__STORYBOOK_ADDON_INTERACTIONS_INSTRUMENTER_STATE__ || {}; + this.state = globalThis.parent.__STORYBOOK_ADDON_INTERACTIONS_INSTRUMENTER_STATE__ || {}; // When called from `start`, isDebugging will be true. const resetState = ({ @@ -241,7 +242,7 @@ export class Instrumenter { const patch = typeof update === 'function' ? update(state) : update; this.state = { ...this.state, [storyId]: { ...state, ...patch } }; // Track state on the parent window so we can reload the iframe without losing state. - global.window.parent.__STORYBOOK_ADDON_INTERACTIONS_INSTRUMENTER_STATE__ = this.state; + globalThis.parent.__STORYBOOK_ADDON_INTERACTIONS_INSTRUMENTER_STATE__ = this.state; } cleanup() { @@ -254,7 +255,7 @@ export class Instrumenter { }, {} as Record); const payload: SyncPayload = { controlStates: controlsDisabled, logItems: [] }; this.channel.emit(EVENTS.SYNC, payload); - global.window.parent.__STORYBOOK_ADDON_INTERACTIONS_INSTRUMENTER_STATE__ = this.state; + globalThis.parent.__STORYBOOK_ADDON_INTERACTIONS_INSTRUMENTER_STATE__ = this.state; } getLog(storyId: string): LogItem[] { @@ -333,7 +334,8 @@ export class Instrumenter { // returns the original result. track(method: string, fn: Function, args: any[], options: Options) { const storyId: StoryId = - args?.[0]?.__storyId__ || global.window.__STORYBOOK_PREVIEW__?.urlStore?.selection?.storyId; + args?.[0]?.__storyId__ || + globalThis.__STORYBOOK_PREVIEW__?.selectionStore?.selection?.storyId; const { cursor, ancestors } = this.getState(storyId); this.setState(storyId, { cursor: cursor + 1 }); const id = `${ancestors.slice(-1)[0] || storyId} [${cursor}] ${method}`; @@ -376,7 +378,7 @@ export class Instrumenter { invoke(fn: Function, call: Call, options: Options) { // TODO this doesnt work because the abortSignal we have here is the newly created one - // const { abortSignal } = global.window.__STORYBOOK_PREVIEW__ || {}; + // const { abortSignal } = globalThis.__STORYBOOK_PREVIEW__ || {}; // if (abortSignal && abortSignal.aborted) throw IGNORED_EXCEPTION; const { callRefsByResult, renderPhase } = this.getState(call.storyId); @@ -400,7 +402,7 @@ export class Instrumenter { const { flags, source } = value; return { __regexp__: { flags, source } }; } - if (value instanceof global.window.HTMLElement) { + if (value instanceof globalThis.HTMLElement) { const { prefix, localName, id, classList, innerText } = value; const classNames = Array.from(classList); return { __element__: { prefix, localName, id, classNames, innerText } }; @@ -611,23 +613,24 @@ export function instrument>( let forceInstrument = false; let skipInstrument = false; - if (global.window.location?.search?.includes('instrument=true')) { + if (globalThis.location?.search?.includes('instrument=true')) { forceInstrument = true; - } else if (global.window.location?.search?.includes('instrument=false')) { + } else if (globalThis.location?.search?.includes('instrument=false')) { skipInstrument = true; } + // @ts-expect-error TS doesn't consider one's an iframe // Don't do any instrumentation if not loaded in an iframe unless it's forced - instrumentation can also be skipped. - if ((global.window.parent === global.window && !forceInstrument) || skipInstrument) { + if ((globalThis.parent === globalThis && !forceInstrument) || skipInstrument) { return obj; } // Only create an instance if we don't have one (singleton) yet. - if (!global.window.__STORYBOOK_ADDON_INTERACTIONS_INSTRUMENTER__) { - global.window.__STORYBOOK_ADDON_INTERACTIONS_INSTRUMENTER__ = new Instrumenter(); + if (!globalThis.__STORYBOOK_ADDON_INTERACTIONS_INSTRUMENTER__) { + globalThis.__STORYBOOK_ADDON_INTERACTIONS_INSTRUMENTER__ = new Instrumenter(); } - const instrumenter: Instrumenter = global.window.__STORYBOOK_ADDON_INTERACTIONS_INSTRUMENTER__; + const instrumenter: Instrumenter = globalThis.__STORYBOOK_ADDON_INTERACTIONS_INSTRUMENTER__; return instrumenter.instrument(obj, options); } catch (e) { // Access to the parent window might fail due to CORS restrictions. diff --git a/code/lib/instrumenter/src/typings.d.ts b/code/lib/instrumenter/src/typings.d.ts index 2f4eb9cf4fd9..2bae59f2fdb7 100644 --- a/code/lib/instrumenter/src/typings.d.ts +++ b/code/lib/instrumenter/src/typings.d.ts @@ -1 +1,10 @@ -declare module 'global'; +/* eslint-disable no-underscore-dangle, @typescript-eslint/naming-convention */ +import type { State } from './types'; +import type { Instrumenter } from './instrumenter'; + +declare global { + interface Window { + __STORYBOOK_ADDON_INTERACTIONS_INSTRUMENTER_STATE__: Record; + } + var __STORYBOOK_ADDON_INTERACTIONS_INSTRUMENTER__: Instrumenter | undefined; +} diff --git a/code/lib/manager-api/package.json b/code/lib/manager-api/package.json index 45964cb00d63..b763ad924d7a 100644 --- a/code/lib/manager-api/package.json +++ b/code/lib/manager-api/package.json @@ -49,7 +49,6 @@ "@storybook/theming": "7.0.0-alpha.54", "@storybook/types": "7.0.0-alpha.54", "dequal": "^2.0.2", - "global": "^4.4.0", "lodash": "^4.17.21", "memoizerific": "^1.11.3", "semver": "^7.3.7", diff --git a/code/lib/manager-api/src/lib/addons.ts b/code/lib/manager-api/src/lib/addons.ts index fa3c202ebbc8..5ef7f42594de 100644 --- a/code/lib/manager-api/src/lib/addons.ts +++ b/code/lib/manager-api/src/lib/addons.ts @@ -1,4 +1,4 @@ -import global from 'global'; +/* eslint-disable no-underscore-dangle */ import type { Channel } from '@storybook/channels'; import { SET_CONFIG } from '@storybook/core-events'; @@ -119,10 +119,10 @@ export class AddonStore { const KEY = '__STORYBOOK_ADDONS_MANAGER'; function getAddonsStore(): AddonStore { - if (!global[KEY]) { - global[KEY] = new AddonStore(); + if (!globalThis[KEY]) { + globalThis[KEY] = new AddonStore(); } - return global[KEY]; + return globalThis[KEY]; } export const addons = getAddonsStore(); diff --git a/code/lib/manager-api/src/lib/shortcut.ts b/code/lib/manager-api/src/lib/shortcut.ts index 6830ac223435..4a6d0e9f8b61 100644 --- a/code/lib/manager-api/src/lib/shortcut.ts +++ b/code/lib/manager-api/src/lib/shortcut.ts @@ -1,7 +1,6 @@ -import global from 'global'; import type { API_KeyCollection } from '../modules/shortcuts'; -const { navigator } = global; +const { navigator } = globalThis; export const isMacLike = () => navigator && navigator.platform ? !!navigator.platform.match(/(Mac|iPhone|iPod|iPad)/i) : false; diff --git a/code/lib/manager-api/src/modules/layout.ts b/code/lib/manager-api/src/modules/layout.ts index 1f33ebe2c3c0..fb4819554526 100644 --- a/code/lib/manager-api/src/modules/layout.ts +++ b/code/lib/manager-api/src/modules/layout.ts @@ -1,4 +1,3 @@ -import global from 'global'; import pick from 'lodash/pick'; import { dequal as deepEqual } from 'dequal'; import { create } from '@storybook/theming/create'; @@ -9,7 +8,7 @@ import type { API_Layout, API_PanelPositions, API_UI } from '@storybook/types'; import merge from '../lib/merge'; import type { State, ModuleFn } from '../index'; -const { document } = global; +const { document } = globalThis; export const ActiveTabs = { SIDEBAR: 'sidebar' as const, @@ -184,6 +183,7 @@ export const init: ModuleFn = ({ store, provider, singleStory, fullAPI }) => { const element = document.getElementById(elementId); if (element) { element.focus(); + // @ts-expect-error We're not narrowing down the type here, not all html elements have .select() if (select) element.select(); } }, diff --git a/code/lib/manager-api/src/modules/refs.ts b/code/lib/manager-api/src/modules/refs.ts index 39a525c5683c..1aee259d49b9 100644 --- a/code/lib/manager-api/src/modules/refs.ts +++ b/code/lib/manager-api/src/modules/refs.ts @@ -1,4 +1,3 @@ -import global from 'global'; import { dedent } from 'ts-dedent'; import type { API_ComposedRef, @@ -17,7 +16,7 @@ import { import type { ModuleFn } from '../index'; -const { location, fetch } = global; +const { location, fetch } = globalThis; // eslint-disable-next-line no-useless-escape const findFilename = /(\/((?:[^\/]+?)\.[^\/]+?)|\/)$/; @@ -153,7 +152,7 @@ export const init: ModuleFn = ( const [index, metadata] = await Promise.all([ indexFetch.ok ? handleRequest(indexFetch) : handleRequest(storiesFetch), handleRequest( - fetch(`${url}/metadata.json${query}`, { + await fetch(`${url}/metadata.json${query}`, { headers: { Accept: 'application/json', }, @@ -240,7 +239,7 @@ export const init: ModuleFn = ( }, }; - const refs: API_Refs = (!singleStory && global.REFS) || {}; + const refs: API_Refs = (!singleStory && (globalThis as any).REFS) || {}; const initialState: SubState['refs'] = refs; diff --git a/code/lib/manager-api/src/modules/release-notes.ts b/code/lib/manager-api/src/modules/release-notes.ts index f8c3da8abd8b..854626eb7911 100644 --- a/code/lib/manager-api/src/modules/release-notes.ts +++ b/code/lib/manager-api/src/modules/release-notes.ts @@ -1,10 +1,9 @@ -import global from 'global'; import type { API_ReleaseNotes } from '@storybook/types'; import memoize from 'memoizerific'; import type { ModuleFn } from '../index'; -const { RELEASE_NOTES_DATA } = global; +const { RELEASE_NOTES_DATA } = globalThis; const getReleaseNotesData = memoize(1)((): API_ReleaseNotes => { try { diff --git a/code/lib/manager-api/src/modules/shortcuts.ts b/code/lib/manager-api/src/modules/shortcuts.ts index 94007b27adfe..f5da5809f9f2 100644 --- a/code/lib/manager-api/src/modules/shortcuts.ts +++ b/code/lib/manager-api/src/modules/shortcuts.ts @@ -1,5 +1,5 @@ /* eslint-disable @typescript-eslint/naming-convention */ -import global from 'global'; + import { PREVIEW_KEYDOWN } from '@storybook/core-events'; import type { ModuleFn } from '../index'; @@ -8,7 +8,7 @@ import type { KeyboardEventLike } from '../lib/shortcut'; import { shortcutMatchesShortcut, eventToShortcut } from '../lib/shortcut'; import { focusableUIElements } from './layout'; -const { navigator, document } = global; +const { navigator, document } = globalThis; export const isMacLike = () => navigator && navigator.platform ? !!navigator.platform.match(/(Mac|iPhone|iPod|iPad)/i) : false; @@ -217,7 +217,7 @@ export const init: ModuleFn = ({ store, fullAPI }) => { } case 'focusIframe': { - const element = document.getElementById('storybook-preview-iframe'); + const element = document.getElementById('storybook-preview-iframe') as HTMLIFrameElement; if (element) { try { diff --git a/code/lib/manager-api/src/modules/stories.ts b/code/lib/manager-api/src/modules/stories.ts index cbf2ac59c6c9..f17b54a51b0b 100644 --- a/code/lib/manager-api/src/modules/stories.ts +++ b/code/lib/manager-api/src/modules/stories.ts @@ -1,4 +1,3 @@ -import global from 'global'; import { toId, sanitize } from '@storybook/csf'; import { PRELOAD_ENTRIES, @@ -41,7 +40,7 @@ import { import type { ModuleFn } from '../index'; -const { FEATURES, fetch } = global; +const { FEATURES, fetch } = globalThis; const STORY_INDEX_PATH = './index.json'; type Direction = -1 | 1; diff --git a/code/lib/manager-api/src/modules/url.ts b/code/lib/manager-api/src/modules/url.ts index c55899ff136c..58f477085e7f 100644 --- a/code/lib/manager-api/src/modules/url.ts +++ b/code/lib/manager-api/src/modules/url.ts @@ -8,13 +8,10 @@ import { import type { NavigateOptions } from '@storybook/router'; import { queryFromLocation, buildArgsParam } from '@storybook/router'; import { dequal as deepEqual } from 'dequal'; -import global from 'global'; import type { API_Layout, API_UI } from '@storybook/types'; import type { ModuleArgs, ModuleFn } from '../index'; -const { window: globalWindow } = global; - export interface SubState { customQueryParams: QueryParams; } @@ -151,9 +148,9 @@ export const init: ModuleFn = ({ store, navigate, state, provider, fullAPI, ...r let handleOrId: any; fullAPI.on(STORY_ARGS_UPDATED, () => { - if ('requestIdleCallback' in globalWindow) { - if (handleOrId) globalWindow.cancelIdleCallback(handleOrId); - handleOrId = globalWindow.requestIdleCallback(updateArgsParam, { timeout: 1000 }); + if ('requestIdleCallback' in globalThis) { + if (handleOrId) globalThis.cancelIdleCallback(handleOrId); + handleOrId = globalThis.requestIdleCallback(updateArgsParam, { timeout: 1000 }); } else { if (handleOrId) clearTimeout(handleOrId); setTimeout(updateArgsParam, 100); diff --git a/code/lib/manager-api/src/modules/versions.ts b/code/lib/manager-api/src/modules/versions.ts index 07493156b6bd..e0b3ee6fdc37 100644 --- a/code/lib/manager-api/src/modules/versions.ts +++ b/code/lib/manager-api/src/modules/versions.ts @@ -1,4 +1,3 @@ -import global from 'global'; import semver from 'semver'; import memoize from 'memoizerific'; @@ -7,7 +6,7 @@ import { version as currentVersion } from '../version'; import type { ModuleFn } from '../index'; -const { VERSIONCHECK } = global; +const { VERSIONCHECK } = globalThis; export interface SubState { versions: API_Versions & API_UnknownEntries; diff --git a/code/lib/manager-api/src/tests/refs.test.js b/code/lib/manager-api/src/tests/refs.test.js index ad25f718ec49..f5c4b0a2b258 100644 --- a/code/lib/manager-api/src/tests/refs.test.js +++ b/code/lib/manager-api/src/tests/refs.test.js @@ -1,7 +1,6 @@ -import global from 'global'; import { getSourceType, init as initRefs } from '../modules/refs'; -const { fetch } = global; +const { fetch } = globalThis; jest.mock('global', () => { const globalMock = { diff --git a/code/lib/manager-api/src/tests/shortcut.test.js b/code/lib/manager-api/src/tests/shortcut.test.js index 23aeb049236e..37ed3523bb35 100644 --- a/code/lib/manager-api/src/tests/shortcut.test.js +++ b/code/lib/manager-api/src/tests/shortcut.test.js @@ -2,10 +2,9 @@ * @jest-environment jsdom */ -import global from 'global'; import { eventToShortcut, keyToSymbol } from '../lib/shortcut'; -const { KeyboardEvent } = global; +const { KeyboardEvent } = globalThis; const ev = (attr) => new KeyboardEvent('keydown', { ...attr }); describe('eventToShortcut', () => { diff --git a/code/lib/manager-api/src/tests/stories.test.ts b/code/lib/manager-api/src/tests/stories.test.ts index e0e0159439f9..ec3827590142 100644 --- a/code/lib/manager-api/src/tests/stories.test.ts +++ b/code/lib/manager-api/src/tests/stories.test.ts @@ -14,7 +14,6 @@ import { SET_INDEX, } from '@storybook/core-events'; import { EventEmitter } from 'events'; -import global from 'global'; import { Channel } from '@storybook/channels'; @@ -35,14 +34,16 @@ function mockChannel() { } const mockGetEntries = jest.fn<() => StoryIndex['entries']>(); - jest.mock('../lib/events'); -jest.mock('global', () => ({ - ...(mockJest.requireActual('global') as Record), - fetch: mockJest.fn(() => ({ json: () => ({ v: 4, entries: mockGetEntries() }) })), - FEATURES: { storyStoreV7: true }, - CONFIG_TYPE: 'DEVELOPMENT', -})); +jest + .spyOn(global, 'fetch') + .mockImplementation( + mockJest.fn(() => + Promise.resolve(new Response(JSON.stringify({ v: 4, entries: mockGetEntries() }))) + ) + ); +jest.spyOn(global, 'FEATURES', 'get').mockImplementation(() => ({ storyStoreV7: true })); +jest.spyOn(global, 'CONFIG_TYPE', 'get').mockImplementation(() => 'DEVELOPMENT'); const getEventMetadataMock = getEventMetadata as ReturnType; @@ -87,9 +88,11 @@ beforeEach(() => { provider.getConfig.mockReset().mockReturnValue({}); provider.serverChannel = mockChannel(); mockGetEntries.mockReset().mockReturnValue(mockEntries); - global.fetch + (globalThis.fetch as jest.Mock) .mockReset() - .mockReturnValue({ status: 200, json: () => ({ v: 4, entries: mockGetEntries() }) }); + .mockReturnValue( + Promise.resolve({ status: 200, json: () => ({ v: 4, entries: mockGetEntries() }) }) + ); getEventMetadataMock.mockReturnValue({ sourceType: 'local' } as any); getEventMetadataMock.mockReturnValue({ sourceType: 'local' } as any); diff --git a/code/lib/manager-api/src/typings.d.ts b/code/lib/manager-api/src/typings.d.ts index 120e82d8e42f..8155bd8c5743 100644 --- a/code/lib/manager-api/src/typings.d.ts +++ b/code/lib/manager-api/src/typings.d.ts @@ -1,2 +1 @@ -declare module 'global'; declare module 'preval.macro'; diff --git a/code/lib/preview-api/package.json b/code/lib/preview-api/package.json index 3cac0700a1c9..bcb6ea71bff0 100644 --- a/code/lib/preview-api/package.json +++ b/code/lib/preview-api/package.json @@ -75,7 +75,6 @@ "@storybook/types": "7.0.0-alpha.54", "@types/qs": "^6.9.5", "dequal": "^2.0.2", - "global": "^4.4.0", "lodash": "^4.17.21", "memoizerific": "^1.11.3", "qs": "^6.10.0", diff --git a/code/lib/preview-api/src/modules/addons/hooks.ts b/code/lib/preview-api/src/modules/addons/hooks.ts index 1135c25bf9b2..59f2b5c46e3d 100644 --- a/code/lib/preview-api/src/modules/addons/hooks.ts +++ b/code/lib/preview-api/src/modules/addons/hooks.ts @@ -1,4 +1,3 @@ -import global from 'global'; import { logger } from '@storybook/client-logger'; import type { Renderer, @@ -155,10 +154,10 @@ function hookify(fn: AbstractFunction) { } hooks.nextHookIndex = 0; - const prevContext = global.STORYBOOK_HOOKS_CONTEXT; - global.STORYBOOK_HOOKS_CONTEXT = hooks; + const prevContext = (globalThis as any).STORYBOOK_HOOKS_CONTEXT; + (globalThis as any).STORYBOOK_HOOKS_CONTEXT = hooks; const result = fn(...args); - global.STORYBOOK_HOOKS_CONTEXT = prevContext; + (globalThis as any).STORYBOOK_HOOKS_CONTEXT = prevContext; if (hooks.currentPhase === 'UPDATE' && hooks.getNextHook() != null) { throw new Error( @@ -217,7 +216,7 @@ const invalidHooksError = () => new Error('Storybook preview hooks can only be called inside decorators and story functions.'); function getHooksContextOrNull(): HooksContext | null { - return global.STORYBOOK_HOOKS_CONTEXT || null; + return (globalThis as any).STORYBOOK_HOOKS_CONTEXT || null; } function getHooksContextOrThrow(): HooksContext { diff --git a/code/lib/preview-api/src/modules/client-api/ClientApi.ts b/code/lib/preview-api/src/modules/client-api/ClientApi.ts index f2d8eb358748..662ca8d3459c 100644 --- a/code/lib/preview-api/src/modules/client-api/ClientApi.ts +++ b/code/lib/preview-api/src/modules/client-api/ClientApi.ts @@ -1,7 +1,6 @@ /// import { dedent } from 'ts-dedent'; -import global from 'global'; import { logger } from '@storybook/client-logger'; import { toId, sanitize } from '@storybook/csf'; import type { @@ -47,7 +46,7 @@ const warningAlternatives = { }; const checkMethod = (method: keyof typeof warningAlternatives) => { - if (global.FEATURES?.storyStoreV7) { + if (globalThis.FEATURES?.storyStoreV7) { throw new Error( dedent`You cannot use \`${method}\` with the new Story Store. diff --git a/code/lib/preview-api/src/modules/client-api/StoryStoreFacade.ts b/code/lib/preview-api/src/modules/client-api/StoryStoreFacade.ts index d65e6aaca534..7582b36c78d6 100644 --- a/code/lib/preview-api/src/modules/client-api/StoryStoreFacade.ts +++ b/code/lib/preview-api/src/modules/client-api/StoryStoreFacade.ts @@ -1,5 +1,4 @@ /* eslint-disable no-underscore-dangle */ -import global from 'global'; import { dedent } from 'ts-dedent'; import { SynchronousPromise } from 'synchronous-promise'; import { toId, isExportStory, storyNameFromExport } from '@storybook/csf'; @@ -153,7 +152,7 @@ export class StoryStoreFacade { // eslint-disable-next-line prefer-const let { id: componentId, title, tags: componentTags = [] } = defaultExport || {}; - const specifiers = (global.STORIES || []).map( + const specifiers = (globalThis.STORIES || []).map( (specifier: NormalizedStoriesSpecifier & { importPathMatcher: string }) => ({ ...specifier, importPathMatcher: new RegExp(specifier.importPathMatcher), @@ -194,7 +193,7 @@ export class StoryStoreFacade { ); // NOTE: this logic is equivalent to the `extractStories` function of `StoryIndexGenerator` - const docsOptions = (global.DOCS_OPTIONS || {}) as DocsOptions; + const docsOptions = (globalThis.DOCS_OPTIONS || {}) as DocsOptions; const docsPageOptedIn = docsOptions.docsPage === 'automatic' || (docsOptions.docsPage && componentTags.includes('docsPage')); diff --git a/code/lib/preview-api/src/modules/client-api/queryparams.ts b/code/lib/preview-api/src/modules/client-api/queryparams.ts index be0c29f201f6..c6c6b7484bbe 100644 --- a/code/lib/preview-api/src/modules/client-api/queryparams.ts +++ b/code/lib/preview-api/src/modules/client-api/queryparams.ts @@ -1,8 +1,7 @@ -import global from 'global'; import { parse } from 'qs'; export const getQueryParams = () => { - const { document } = global; + const { document } = globalThis; // document.location is not defined in react-native if (document && document.location && document.location.search) { return parse(document.location.search, { ignoreQueryPrefix: true }); diff --git a/code/lib/preview-api/src/modules/client-api/typings.d.ts b/code/lib/preview-api/src/modules/client-api/typings.d.ts deleted file mode 100644 index 2f4eb9cf4fd9..000000000000 --- a/code/lib/preview-api/src/modules/client-api/typings.d.ts +++ /dev/null @@ -1 +0,0 @@ -declare module 'global'; diff --git a/code/lib/preview-api/src/modules/core-client/start.ts b/code/lib/preview-api/src/modules/core-client/start.ts index bdfb5698ae3f..64ffffb87c1b 100644 --- a/code/lib/preview-api/src/modules/core-client/start.ts +++ b/code/lib/preview-api/src/modules/core-client/start.ts @@ -1,5 +1,4 @@ /* eslint-disable @typescript-eslint/naming-convention */ -import global from 'global'; import type { Renderer, ArgsStoryFn, Path, ProjectAnnotations } from '@storybook/types'; import { createChannel } from '@storybook/channel-postmessage'; import { FORCE_RE_RENDER } from '@storybook/core-events'; @@ -10,7 +9,7 @@ import { ClientApi } from '../../client-api'; import { executeLoadableForChanges } from './executeLoadable'; import type { Loadable } from './executeLoadable'; -const { window: globalWindow, FEATURES } = global; +const { FEATURES } = globalThis; const removedApi = (name: string) => () => { throw new Error(`@storybook/client-api:${name} was removed in storyStoreV7.`); @@ -41,10 +40,8 @@ export function start( renderToCanvas: ProjectAnnotations['renderToCanvas'], { decorateStory, render }: CoreClient_RendererImplementation = {} ): CoreClient_StartReturnValue { - if (globalWindow) { - // To enable user code to detect if it is running in Storybook - globalWindow.IS_STORYBOOK = true; - } + // To enable user code to detect if it is running in Storybook + globalThis.IS_STORYBOOK = true; if (FEATURES?.storyStoreV7) { return { @@ -75,13 +72,11 @@ export function start( clientApi.onImportFnChanged = onStoriesChanged; clientApi.storyStore = preview.storyStore; - if (globalWindow) { - globalWindow.__STORYBOOK_CLIENT_API__ = clientApi; - globalWindow.__STORYBOOK_ADDONS_CHANNEL__ = channel; - // eslint-disable-next-line no-underscore-dangle - globalWindow.__STORYBOOK_PREVIEW__ = preview; - globalWindow.__STORYBOOK_STORY_STORE__ = preview.storyStore; - } + globalThis.__STORYBOOK_CLIENT_API__ = clientApi; + globalThis.__STORYBOOK_ADDONS_CHANNEL__ = channel; + // eslint-disable-next-line no-underscore-dangle + globalThis.__STORYBOOK_PREVIEW__ = preview; + globalThis.__STORYBOOK_STORY_STORE__ = preview.storyStore; return { forceReRender: () => channel.emit(FORCE_RE_RENDER), diff --git a/code/lib/preview-api/src/modules/core-client/typings.d.ts b/code/lib/preview-api/src/modules/core-client/typings.d.ts index 8353021fb03d..927e05db9461 100644 --- a/code/lib/preview-api/src/modules/core-client/typings.d.ts +++ b/code/lib/preview-api/src/modules/core-client/typings.d.ts @@ -1,4 +1,3 @@ -declare module 'global'; declare module 'lazy-universal-dotenv'; declare module 'pnp-webpack-plugin'; declare module '@storybook/manager/paths'; diff --git a/code/lib/preview-api/src/modules/preview-web/Preview.tsx b/code/lib/preview-api/src/modules/preview-web/Preview.tsx index c2d7b7930bdc..953605a95047 100644 --- a/code/lib/preview-api/src/modules/preview-web/Preview.tsx +++ b/code/lib/preview-api/src/modules/preview-web/Preview.tsx @@ -1,5 +1,4 @@ import { dedent } from 'ts-dedent'; -import global from 'global'; import { SynchronousPromise } from 'synchronous-promise'; import { CONFIG_ERROR, @@ -35,7 +34,7 @@ import { StoryRender } from './render/StoryRender'; import type { TemplateDocsRender } from './render/TemplateDocsRender'; import type { StandaloneDocsRender } from './render/StandaloneDocsRender'; -const { fetch } = global; +const { FEATURES, fetch } = globalThis; const STORY_INDEX_PATH = './index.json'; @@ -57,7 +56,7 @@ export class Preview { previewEntryError?: Error; constructor(protected channel: Channel = addons.getChannel()) { - if (global.FEATURES?.storyStoreV7 && addons.hasServerChannel()) { + if (FEATURES?.storyStoreV7 && addons.hasServerChannel()) { this.serverChannel = addons.getServerChannel(); } this.storyStore = new StoryStore(); @@ -140,7 +139,7 @@ export class Preview { this.setInitialGlobals(); let storyIndexPromise: Promise; - if (global.FEATURES?.storyStoreV7) { + if (FEATURES?.storyStoreV7) { storyIndexPromise = this.getStoryIndexFromServer(); } else { if (!this.getStoryIndex) { @@ -172,9 +171,9 @@ export class Preview { this.channel.emit(SET_GLOBALS, payload); } - async getStoryIndexFromServer() { + async getStoryIndexFromServer(): Promise { const result = await fetch(STORY_INDEX_PATH); - if (result.status === 200) return result.json() as StoryIndex; + if (result.status === 200) return result.json(); throw new Error(await result.text()); } @@ -187,7 +186,7 @@ export class Preview { return this.storyStore.initialize({ storyIndex, importFn: this.importFn, - cache: !global.FEATURES?.storyStoreV7, + cache: !FEATURES?.storyStoreV7, }); } @@ -361,7 +360,7 @@ export class Preview { Do you have an error in your \`preview.js\`? Check your Storybook's browser console for errors.`); } - if (global.FEATURES?.storyStoreV7) { + if (FEATURES?.storyStoreV7) { await this.storyStore.cacheAllCSFFiles(); } diff --git a/code/lib/preview-api/src/modules/preview-web/PreviewWithSelection.tsx b/code/lib/preview-api/src/modules/preview-web/PreviewWithSelection.tsx index 069d10758d84..801bd7f8a3ea 100644 --- a/code/lib/preview-api/src/modules/preview-web/PreviewWithSelection.tsx +++ b/code/lib/preview-api/src/modules/preview-web/PreviewWithSelection.tsx @@ -1,5 +1,4 @@ import { dedent } from 'ts-dedent'; -import global from 'global'; import { CURRENT_STORY_WAS_SET, PRELOAD_ENTRIES, @@ -40,7 +39,7 @@ import type { Selection, SelectionStore } from './SelectionStore'; import type { View } from './View'; import type { StorySpecifier } from '../store/StoryIndexStore'; -const globalWindow = globalThis; +const { FEATURES } = globalThis; function focusInInput(event: Event) { const target = event.target as Element; @@ -73,7 +72,7 @@ export class PreviewWithSelection extends Preview extends Preview { return super.initializeWithStoryIndex(storyIndex).then(() => { - if (!global.FEATURES?.storyStoreV7) { + if (!FEATURES?.storyStoreV7) { this.channel.emit(SET_INDEX, this.storyStore.getSetIndexPayload()); } @@ -180,7 +179,7 @@ export class PreviewWithSelection extends Preview extends Preview extends Preview implements Render {}); } } diff --git a/code/lib/preview-api/src/modules/preview-web/simulate-pageload.test.ts b/code/lib/preview-api/src/modules/preview-web/simulate-pageload.test.ts index 12076059ceec..e9f9d271fba4 100644 --- a/code/lib/preview-api/src/modules/preview-web/simulate-pageload.test.ts +++ b/code/lib/preview-api/src/modules/preview-web/simulate-pageload.test.ts @@ -1,11 +1,9 @@ /** * @jest-environment jsdom */ - -import global from 'global'; import { simulatePageLoad } from './simulate-pageload'; -const { document } = global; +const { document } = globalThis; describe('simulatePageLoad', () => { it('should add script with type module to scripts root', () => { diff --git a/code/lib/preview-api/src/modules/preview-web/simulate-pageload.ts b/code/lib/preview-api/src/modules/preview-web/simulate-pageload.ts index 23d40a994ce4..74ab193c1119 100644 --- a/code/lib/preview-api/src/modules/preview-web/simulate-pageload.ts +++ b/code/lib/preview-api/src/modules/preview-web/simulate-pageload.ts @@ -1,6 +1,4 @@ -import global from 'global'; - -const { document } = global; +const { document } = globalThis; // https://html.spec.whatwg.org/multipage/scripting.html const runScriptTypes = [ diff --git a/code/lib/preview-api/src/modules/preview-web/typings.d.ts b/code/lib/preview-api/src/modules/preview-web/typings.d.ts index 08f7a767bfef..faea2fff4fbe 100644 --- a/code/lib/preview-api/src/modules/preview-web/typings.d.ts +++ b/code/lib/preview-api/src/modules/preview-web/typings.d.ts @@ -1,5 +1,3 @@ -declare module 'global'; - declare module 'ansi-to-html'; declare class AnsiToHtml { constructor(options: { escapeHtml: boolean }); diff --git a/code/lib/preview-api/src/modules/store/csf/prepareStory.ts b/code/lib/preview-api/src/modules/store/csf/prepareStory.ts index ac4106da2130..f3f9b0fba607 100644 --- a/code/lib/preview-api/src/modules/store/csf/prepareStory.ts +++ b/code/lib/preview-api/src/modules/store/csf/prepareStory.ts @@ -1,6 +1,5 @@ import { dedent } from 'ts-dedent'; import deprecate from 'util-deprecate'; -import global from 'global'; import type { Renderer, @@ -28,6 +27,8 @@ import { defaultDecorateStory } from '../decorators'; import { groupArgsByTarget, NO_TARGET_NAME } from '../args'; import { getValuesFromArgTypes } from './getValuesFromArgTypes'; +const { FEATURES } = globalThis; + const argTypeDefaultValueWarning = deprecate( () => {}, dedent` @@ -150,7 +151,7 @@ export function prepareStory( ); // Add some of our metadata into parameters as we used to do this in 6.x and users may be relying on it - if (!global.FEATURES?.breakingChangesV7) { + if (!FEATURES?.breakingChangesV7) { contextForEnhancers.parameters = { ...contextForEnhancers.parameters, __id: id, @@ -189,7 +190,7 @@ export function prepareStory( const decoratedStoryFn = applyHooks(applyDecorators)(undecoratedStoryFn, decorators); const unboundStoryFn = (context: StoryContext) => { let finalContext: StoryContext = context; - if (global.FEATURES?.argTypeTargetsV7) { + if (FEATURES?.argTypeTargetsV7) { const argsByTarget = groupArgsByTarget(context); finalContext = { ...context, diff --git a/code/lib/preview-api/src/modules/store/typings.d.ts b/code/lib/preview-api/src/modules/store/typings.d.ts deleted file mode 100644 index 2f4eb9cf4fd9..000000000000 --- a/code/lib/preview-api/src/modules/store/typings.d.ts +++ /dev/null @@ -1 +0,0 @@ -declare module 'global'; diff --git a/code/lib/router/package.json b/code/lib/router/package.json index 38a9d0376029..fcd888c636c2 100644 --- a/code/lib/router/package.json +++ b/code/lib/router/package.json @@ -53,7 +53,6 @@ }, "devDependencies": { "dequal": "^2.0.2", - "global": "^4.4.0", "lodash": "^4.17.21", "react-router-dom": "6.0.2", "ts-dedent": "^2.0.0", diff --git a/code/lib/router/src/index.ts b/code/lib/router/src/index.ts index 1026ffcf03e2..a185eddbd096 100644 --- a/code/lib/router/src/index.ts +++ b/code/lib/router/src/index.ts @@ -1,6 +1,3 @@ -// eslint-disable-next-line @typescript-eslint/triple-slash-reference -/// - export * from './utils'; export * from './router'; export * from './types'; diff --git a/code/lib/router/src/router.tsx b/code/lib/router/src/router.tsx index 413ed5aba6cc..e45c7ffbfd4a 100644 --- a/code/lib/router/src/router.tsx +++ b/code/lib/router/src/router.tsx @@ -1,4 +1,3 @@ -import global from 'global'; import React, { useCallback } from 'react'; import type { ReactNode } from 'react'; @@ -7,7 +6,7 @@ import { ToggleVisibility } from './visibility'; import { queryFromString, parsePath, getMatch } from './utils'; import type { LinkProps, NavigateOptions, RenderData } from './types'; -const { document } = global; +const { document } = globalThis; interface MatchingData { match: null | { path: string }; diff --git a/code/lib/router/src/typings.d.ts b/code/lib/router/src/typings.d.ts deleted file mode 100644 index 556e4042c702..000000000000 --- a/code/lib/router/src/typings.d.ts +++ /dev/null @@ -1,2 +0,0 @@ -// todo the following packages need definition files or a TS migration -declare module 'global'; diff --git a/code/lib/store/template/stories/argTypes.stories.ts b/code/lib/store/template/stories/argTypes.stories.ts index 409e20212a59..a689f2d881fd 100644 --- a/code/lib/store/template/stories/argTypes.stories.ts +++ b/code/lib/store/template/stories/argTypes.stories.ts @@ -1,4 +1,3 @@ -import globalThis from 'global'; import type { PartialStoryFn, PlayFunctionContext, StoryContext } from '@storybook/types'; import { within } from '@storybook/testing-library'; import { expect } from '@storybook/jest'; diff --git a/code/lib/store/template/stories/args.stories.ts b/code/lib/store/template/stories/args.stories.ts index 5b39fa61e509..259179ae9e8b 100644 --- a/code/lib/store/template/stories/args.stories.ts +++ b/code/lib/store/template/stories/args.stories.ts @@ -1,4 +1,3 @@ -import globalThis from 'global'; import type { PartialStoryFn, PlayFunctionContext, StoryContext } from '@storybook/types'; import { within } from '@storybook/testing-library'; import { expect } from '@storybook/jest'; diff --git a/code/lib/store/template/stories/autotitle.stories.ts b/code/lib/store/template/stories/autotitle.stories.ts index dacdc7c7e025..b842def795e8 100644 --- a/code/lib/store/template/stories/autotitle.stories.ts +++ b/code/lib/store/template/stories/autotitle.stories.ts @@ -1,4 +1,3 @@ -import globalThis from 'global'; import { expect } from '@storybook/jest'; import type { PlayFunctionContext } from '@storybook/types'; diff --git a/code/lib/store/template/stories/decorators.stories.ts b/code/lib/store/template/stories/decorators.stories.ts index 7eb325160788..0c9fca4fd1de 100644 --- a/code/lib/store/template/stories/decorators.stories.ts +++ b/code/lib/store/template/stories/decorators.stories.ts @@ -1,4 +1,3 @@ -import globalThis from 'global'; import type { PartialStoryFn, PlayFunctionContext, StoryContext } from '@storybook/types'; import { within } from '@storybook/testing-library'; import { expect } from '@storybook/jest'; diff --git a/code/lib/store/template/stories/exportOrder.stories.ts b/code/lib/store/template/stories/exportOrder.stories.ts index 51cbb77a63fb..8dcb2b9d5a36 100644 --- a/code/lib/store/template/stories/exportOrder.stories.ts +++ b/code/lib/store/template/stories/exportOrder.stories.ts @@ -1,5 +1,3 @@ -import globalThis from 'global'; - export default { component: globalThis.Components.Pre, args: { text: 'Check that Story2 is listed before Story1' }, diff --git a/code/lib/store/template/stories/globals.stories.ts b/code/lib/store/template/stories/globals.stories.ts index f0556452d0a1..7fc66a160140 100644 --- a/code/lib/store/template/stories/globals.stories.ts +++ b/code/lib/store/template/stories/globals.stories.ts @@ -1,4 +1,3 @@ -import globalThis from 'global'; import type { PartialStoryFn, PlayFunctionContext, StoryContext } from '@storybook/types'; import { within } from '@storybook/testing-library'; import { expect } from '@storybook/jest'; diff --git a/code/lib/store/template/stories/hooks.stories.ts b/code/lib/store/template/stories/hooks.stories.ts index d09c21af2115..e2578c2f9dbf 100644 --- a/code/lib/store/template/stories/hooks.stories.ts +++ b/code/lib/store/template/stories/hooks.stories.ts @@ -1,4 +1,3 @@ -import globalThis from 'global'; import type { PartialStoryFn, PlayFunctionContext } from '@storybook/types'; import { useEffect, useState } from '@storybook/preview-api'; import { within, userEvent } from '@storybook/testing-library'; diff --git a/code/lib/store/template/stories/interleavedExports.stories.ts b/code/lib/store/template/stories/interleavedExports.stories.ts index 8fb77a77be3a..f6edbd1e4da8 100644 --- a/code/lib/store/template/stories/interleavedExports.stories.ts +++ b/code/lib/store/template/stories/interleavedExports.stories.ts @@ -1,5 +1,3 @@ -import globalThis from 'global'; - export default { component: globalThis.Components.Pre, args: { text: 'Check that stories are processed OK' }, diff --git a/code/lib/store/template/stories/layout.stories.ts b/code/lib/store/template/stories/layout.stories.ts index 1bc7c0c207e5..a49219631680 100644 --- a/code/lib/store/template/stories/layout.stories.ts +++ b/code/lib/store/template/stories/layout.stories.ts @@ -1,5 +1,3 @@ -import globalThis from 'global'; - const style = { display: 'block', border: '2px solid #FF4785', diff --git a/code/lib/store/template/stories/loaders.stories.ts b/code/lib/store/template/stories/loaders.stories.ts index 0067ef218cb9..10e1dc7889fa 100644 --- a/code/lib/store/template/stories/loaders.stories.ts +++ b/code/lib/store/template/stories/loaders.stories.ts @@ -1,4 +1,3 @@ -import globalThis from 'global'; import type { PartialStoryFn, PlayFunctionContext, StoryContext } from '@storybook/types'; import { within } from '@storybook/testing-library'; import { expect } from '@storybook/jest'; diff --git a/code/lib/store/template/stories/names.stories.ts b/code/lib/store/template/stories/names.stories.ts index 82900557b715..63feef31aaa0 100644 --- a/code/lib/store/template/stories/names.stories.ts +++ b/code/lib/store/template/stories/names.stories.ts @@ -1,4 +1,3 @@ -import globalThis from 'global'; import { expect } from '@storybook/jest'; import type { PlayFunctionContext } from '@storybook/types'; diff --git a/code/lib/store/template/stories/parameters.stories.ts b/code/lib/store/template/stories/parameters.stories.ts index 99d92ae71be2..f35a790c823b 100644 --- a/code/lib/store/template/stories/parameters.stories.ts +++ b/code/lib/store/template/stories/parameters.stories.ts @@ -1,4 +1,3 @@ -import globalThis from 'global'; import type { PartialStoryFn, PlayFunctionContext, StoryContext } from '@storybook/types'; import { within } from '@storybook/testing-library'; import { expect } from '@storybook/jest'; diff --git a/code/lib/store/template/stories/rendering.stories.ts b/code/lib/store/template/stories/rendering.stories.ts index d79f1a3fb0cc..ecc49e1631d0 100644 --- a/code/lib/store/template/stories/rendering.stories.ts +++ b/code/lib/store/template/stories/rendering.stories.ts @@ -1,4 +1,3 @@ -import globalThis from 'global'; import type { PlayFunctionContext } from '@storybook/types'; import { within, waitFor } from '@storybook/testing-library'; import { expect } from '@storybook/jest'; diff --git a/code/lib/store/template/stories/shortcuts.stories.ts b/code/lib/store/template/stories/shortcuts.stories.ts index 6a0ffec340bc..698b25bfdd91 100644 --- a/code/lib/store/template/stories/shortcuts.stories.ts +++ b/code/lib/store/template/stories/shortcuts.stories.ts @@ -1,4 +1,3 @@ -import globalThis from 'global'; import { userEvent, within } from '@storybook/testing-library'; import { PREVIEW_KEYDOWN } from '@storybook/core-events'; import { jest, expect } from '@storybook/jest'; diff --git a/code/lib/store/template/stories/tags.stories.ts b/code/lib/store/template/stories/tags.stories.ts index 57d7b73c80f7..fc62e4a0a4e2 100644 --- a/code/lib/store/template/stories/tags.stories.ts +++ b/code/lib/store/template/stories/tags.stories.ts @@ -1,4 +1,3 @@ -import globalThis from 'global'; import type { PartialStoryFn, PlayFunctionContext, StoryContext } from '@storybook/types'; import { within } from '@storybook/testing-library'; import { expect } from '@storybook/jest'; diff --git a/code/lib/store/template/stories/title.stories.ts b/code/lib/store/template/stories/title.stories.ts index 49b5288d732f..eb11ee8b21e5 100644 --- a/code/lib/store/template/stories/title.stories.ts +++ b/code/lib/store/template/stories/title.stories.ts @@ -1,4 +1,3 @@ -import globalThis from 'global'; import { expect } from '@storybook/jest'; import type { PlayFunctionContext } from '@storybook/types'; diff --git a/code/lib/store/template/stories/unicode.stories.ts b/code/lib/store/template/stories/unicode.stories.ts index 387896d3f234..af64b6ef87a8 100644 --- a/code/lib/store/template/stories/unicode.stories.ts +++ b/code/lib/store/template/stories/unicode.stories.ts @@ -1,5 +1,3 @@ -import globalThis from 'global'; - export default { component: globalThis.Components.Button, id: '😀', diff --git a/code/lib/theming/package.json b/code/lib/theming/package.json index db005e204a9f..970be6b95520 100644 --- a/code/lib/theming/package.json +++ b/code/lib/theming/package.json @@ -60,7 +60,6 @@ "@types/node": "^16.0.0", "deep-object-diff": "^1.1.0", "fs-extra": "^9.0.1", - "global": "^4.4.0", "polished": "^4.2.2", "ts-dedent": "^2.0.0", "typescript": "^4.9.3" diff --git a/code/lib/theming/src/typings.d.ts b/code/lib/theming/src/typings.d.ts index ab568e12c7ac..151bb56deda3 100644 --- a/code/lib/theming/src/typings.d.ts +++ b/code/lib/theming/src/typings.d.ts @@ -1,3 +1,2 @@ // todo the following packages need definition files or a TS migration declare module 'react-inspector'; -declare module 'global'; diff --git a/code/lib/theming/src/utils.ts b/code/lib/theming/src/utils.ts index 2c94ea94e8ce..ea624a53860d 100644 --- a/code/lib/theming/src/utils.ts +++ b/code/lib/theming/src/utils.ts @@ -1,10 +1,7 @@ import { rgba, lighten, darken } from 'polished'; -import global from 'global'; import { logger } from '@storybook/client-logger'; -const { window: globalWindow } = global; - export const mkColor = (color: string) => ({ color }); // Check if it is a string. This is for the sake of warning users @@ -63,9 +60,9 @@ export const darkenColor = colorFactory('darken'); // The default color scheme is light so unless the preferred color // scheme is set to dark we always want to use the light theme export const getPreferredColorScheme = () => { - if (!globalWindow || !globalWindow.matchMedia) return 'light'; + if (!globalThis || !globalThis.matchMedia) return 'light'; - const isDarkThemePreferred = globalWindow.matchMedia('(prefers-color-scheme: dark)').matches; + const isDarkThemePreferred = globalThis.matchMedia('(prefers-color-scheme: dark)').matches; if (isDarkThemePreferred) return 'dark'; return 'light'; diff --git a/code/package.json b/code/package.json index 740af4db8336..29bcc262d90a 100644 --- a/code/package.json +++ b/code/package.json @@ -110,6 +110,7 @@ ], "resolutions": { "@nrwl/cli": "14.6.1", + "@types/webpack": "^5.28.0", "@typescript-eslint/eslint-plugin": "^5.43.0", "@typescript-eslint/experimental-utils": "^5.43.0", "@typescript-eslint/parser": "^5.43.0", @@ -292,7 +293,6 @@ "fs-extra": "^9.0.1", "github-release-from-changelog": "^2.1.1", "glob": "^7.1.6", - "global": "^4.4.0", "http-server": "^0.12.3", "husky": "^4.3.7", "jest": "^29.3.1", diff --git a/code/presets/react-webpack/src/typings.d.ts b/code/presets/react-webpack/src/typings.d.ts index ce0c26f59d0a..53aa2b04a775 100644 --- a/code/presets/react-webpack/src/typings.d.ts +++ b/code/presets/react-webpack/src/typings.d.ts @@ -1,5 +1,3 @@ -declare module 'global'; - // TODO: Replace, as soon as @types/react-dom 17.0.14 is used // Source: https://github.com/DefinitelyTyped/DefinitelyTyped/blob/fb0f14b7a35cde26ffaa82e7536c062e593e9ae6/types/react-dom/client.d.ts declare module 'react-dom/client' { diff --git a/code/presets/server-webpack/package.json b/code/presets/server-webpack/package.json index a8021f66edb9..409b3f225e3f 100644 --- a/code/presets/server-webpack/package.json +++ b/code/presets/server-webpack/package.json @@ -59,7 +59,6 @@ "@storybook/core-webpack": "7.0.0-alpha.54", "@storybook/server": "7.0.0-alpha.54", "@types/node": "^16.0.0", - "global": "^4.4.0", "react": "16.14.0", "react-dom": "16.14.0", "safe-identifier": "^0.4.1", diff --git a/code/presets/server-webpack/src/typings.d.ts b/code/presets/server-webpack/src/typings.d.ts index d8f7c6f660ad..cbeccdbb15f7 100644 --- a/code/presets/server-webpack/src/typings.d.ts +++ b/code/presets/server-webpack/src/typings.d.ts @@ -1,4 +1,2 @@ -declare module 'global'; - // will be provided by the webpack define plugin declare var NODE_ENV: string | undefined; diff --git a/code/presets/vue3-webpack/src/typings.d.ts b/code/presets/vue3-webpack/src/typings.d.ts index 3229acac0222..a045728260a0 100644 --- a/code/presets/vue3-webpack/src/typings.d.ts +++ b/code/presets/vue3-webpack/src/typings.d.ts @@ -1,5 +1,3 @@ -declare module 'global'; - declare module 'vue-loader' { export const VueLoaderPlugin: any; } diff --git a/code/renderers/html/package.json b/code/renderers/html/package.json index d28c8046bde0..6b00c19f6d88 100644 --- a/code/renderers/html/package.json +++ b/code/renderers/html/package.json @@ -55,7 +55,6 @@ "@storybook/docs-tools": "7.0.0-alpha.54", "@storybook/preview-api": "7.0.0-alpha.54", "@storybook/types": "7.0.0-alpha.54", - "global": "^4.4.0", "react": "16.14.0", "react-dom": "16.14.0", "ts-dedent": "^2.0.0" diff --git a/code/renderers/html/src/globals.ts b/code/renderers/html/src/globals.ts index 7d924c74dd19..fa450e4c1a5e 100644 --- a/code/renderers/html/src/globals.ts +++ b/code/renderers/html/src/globals.ts @@ -1,7 +1,3 @@ -// eslint-disable-next-line @typescript-eslint/ban-ts-comment -// @ts-ignore - use ts-ignore instead of ts-expect-error to fix type issues in Angular sandbox -import global from 'global'; +globalThis.STORYBOOK_ENV = 'HTML'; -const { window: globalWindow } = global; - -globalWindow.STORYBOOK_ENV = 'HTML'; +export {}; diff --git a/code/renderers/html/src/render.ts b/code/renderers/html/src/render.ts index 752e2283aeda..769bdacd0535 100644 --- a/code/renderers/html/src/render.ts +++ b/code/renderers/html/src/render.ts @@ -1,13 +1,10 @@ /* eslint-disable no-param-reassign */ -// @ts-expect-error (Converted from ts-ignore) -import global from 'global'; - import { dedent } from 'ts-dedent'; import { simulatePageLoad, simulateDOMContentLoaded } from '@storybook/preview-api'; import type { RenderContext, ArgsStoryFn } from '@storybook/types'; import type { HtmlRenderer } from './types'; -const { Node } = global; +const { Node } = globalThis; export const render: ArgsStoryFn = (args, context) => { const { id, component: Component } = context; diff --git a/code/renderers/html/template/components/index.js b/code/renderers/html/template/components/index.js index 4d08c9813587..90256895a8f4 100644 --- a/code/renderers/html/template/components/index.js +++ b/code/renderers/html/template/components/index.js @@ -1,5 +1,3 @@ -import globalThis from 'global'; - import { Button } from './Button'; import { Pre } from './Pre'; import { Form } from './Form'; diff --git a/code/renderers/preact/package.json b/code/renderers/preact/package.json index 336a9eb335c4..83a7f8b78b5a 100644 --- a/code/renderers/preact/package.json +++ b/code/renderers/preact/package.json @@ -54,7 +54,6 @@ "@storybook/core-client": "7.0.0-alpha.54", "@storybook/preview-api": "7.0.0-alpha.54", "@storybook/types": "7.0.0-alpha.54", - "global": "^4.4.0", "react": "16.14.0", "react-dom": "16.14.0", "ts-dedent": "^2.0.0" diff --git a/code/renderers/preact/src/globals.ts b/code/renderers/preact/src/globals.ts index 02a952c2aac0..a7b281d1fd7a 100644 --- a/code/renderers/preact/src/globals.ts +++ b/code/renderers/preact/src/globals.ts @@ -1,8 +1,3 @@ -// @ts-expect-error (Converted from ts-ignore) -import global from 'global'; +globalThis.STORYBOOK_ENV = 'preact'; -const { window: globalWindow } = global; - -if (globalWindow) { - globalWindow.STORYBOOK_ENV = 'preact'; -} +export {}; diff --git a/code/renderers/preact/template/components/index.js b/code/renderers/preact/template/components/index.js index d952d26f9b1f..05eefa5a2a07 100644 --- a/code/renderers/preact/template/components/index.js +++ b/code/renderers/preact/template/components/index.js @@ -1,5 +1,3 @@ -import globalThis from 'global'; - import { Button } from './Button.jsx'; import { Pre } from './Pre.jsx'; import { Form } from './Form.jsx'; diff --git a/code/renderers/react/package.json b/code/renderers/react/package.json index 3caecaee7bb2..d37e25317f2f 100644 --- a/code/renderers/react/package.json +++ b/code/renderers/react/package.json @@ -63,7 +63,6 @@ "acorn-jsx": "^5.3.1", "acorn-walk": "^7.2.0", "escodegen": "^2.0.0", - "global": "^4.4.0", "html-tags": "^3.1.0", "lodash": "^4.17.21", "prop-types": "^15.7.2", diff --git a/code/renderers/react/src/globals.ts b/code/renderers/react/src/globals.ts index e50560a3c9fe..220cf01fe26a 100644 --- a/code/renderers/react/src/globals.ts +++ b/code/renderers/react/src/globals.ts @@ -1,8 +1,3 @@ -// @ts-expect-error (Converted from ts-ignore) -import global from 'global'; +globalThis.STORYBOOK_ENV = 'react'; -const { window: globalWindow } = global; - -if (globalWindow) { - globalWindow.STORYBOOK_ENV = 'react'; -} +export {}; diff --git a/code/renderers/react/src/render.tsx b/code/renderers/react/src/render.tsx index cc3f07f3e2c4..56f5b3618c8d 100644 --- a/code/renderers/react/src/render.tsx +++ b/code/renderers/react/src/render.tsx @@ -1,6 +1,3 @@ -// @ts-expect-error (Converted from ts-ignore) -import global from 'global'; - import type { FC, ReactElement } from 'react'; import React, { Component as ReactComponent, @@ -16,7 +13,7 @@ import type { RenderContext, ArgsStoryFn } from '@storybook/types'; import type { ReactRenderer, StoryContext } from './types'; -const { FRAMEWORK_OPTIONS } = global; +const { FRAMEWORK_OPTIONS } = globalThis; // A map of all rendered React 18 nodes const nodes = new Map(); diff --git a/code/renderers/react/template/components/index.js b/code/renderers/react/template/components/index.js index dd5fc33a43bc..b2b40821eb7e 100644 --- a/code/renderers/react/template/components/index.js +++ b/code/renderers/react/template/components/index.js @@ -1,5 +1,3 @@ -import globalThis from 'global'; - import { Button } from './Button.jsx'; import { Pre } from './Pre.jsx'; import { Form } from './Form.jsx'; diff --git a/code/renderers/react/template/stories/react-mdx.stories.mdx b/code/renderers/react/template/stories/react-mdx.stories.mdx index 8591bc513b25..e3c5caa7e15e 100644 --- a/code/renderers/react/template/stories/react-mdx.stories.mdx +++ b/code/renderers/react/template/stories/react-mdx.stories.mdx @@ -1,4 +1,3 @@ -import globalThis from 'global'; import { Meta, Story, Canvas } from '@storybook/addon-docs'; diff --git a/code/renderers/server/package.json b/code/renderers/server/package.json index 19d95d7c1a03..569adc9c6ab4 100644 --- a/code/renderers/server/package.json +++ b/code/renderers/server/package.json @@ -54,7 +54,6 @@ "@storybook/core-client": "7.0.0-alpha.54", "@storybook/preview-api": "7.0.0-alpha.54", "@storybook/types": "7.0.0-alpha.54", - "global": "^4.4.0", "react": "16.14.0", "react-dom": "16.14.0", "ts-dedent": "^2.0.0" diff --git a/code/renderers/server/src/globals.ts b/code/renderers/server/src/globals.ts index 58f494cf5e56..23fa6b0e0698 100644 --- a/code/renderers/server/src/globals.ts +++ b/code/renderers/server/src/globals.ts @@ -1,6 +1,3 @@ -// @ts-expect-error (Converted from ts-ignore) -import global from 'global'; +globalThis.STORYBOOK_ENV = 'SERVER'; -const { window: globalWindow } = global; - -globalWindow.STORYBOOK_ENV = 'SERVER'; +export {}; diff --git a/code/renderers/server/src/render.ts b/code/renderers/server/src/render.ts index d72538e3ae72..36c59d54457c 100644 --- a/code/renderers/server/src/render.ts +++ b/code/renderers/server/src/render.ts @@ -1,6 +1,4 @@ /* eslint-disable no-param-reassign */ -// @ts-expect-error (Converted from ts-ignore) -import global from 'global'; import { dedent } from 'ts-dedent'; import type { RenderContext } from '@storybook/types'; @@ -8,13 +6,13 @@ import { simulatePageLoad, simulateDOMContentLoaded } from '@storybook/preview-a import type { StoryFn, Args, ArgTypes } from './public-types'; import type { FetchStoryHtmlType, ServerRenderer } from './types'; -const { fetch, Node } = global; +const { fetch, Node } = globalThis; const defaultFetchStoryHtml: FetchStoryHtmlType = async (url, path, params, storyContext) => { const fetchUrl = new URL(`${url}/${path}`); fetchUrl.search = new URLSearchParams({ ...storyContext.globals, ...params }).toString(); - const response = await fetch(fetchUrl); + const response = await fetch(fetchUrl.toString()); return response.text(); }; diff --git a/code/renderers/svelte/package.json b/code/renderers/svelte/package.json index 0b2b86bfbfb4..31de72d54c37 100644 --- a/code/renderers/svelte/package.json +++ b/code/renderers/svelte/package.json @@ -60,7 +60,6 @@ "@storybook/docs-tools": "7.0.0-alpha.54", "@storybook/preview-api": "7.0.0-alpha.54", "@storybook/types": "7.0.0-alpha.54", - "global": "^4.4.0", "react": "16.14.0", "react-dom": "16.14.0", "sveltedoc-parser": "^4.2.1", diff --git a/code/renderers/svelte/src/globals.ts b/code/renderers/svelte/src/globals.ts index a2fb5c9dad10..6a82a4c10e49 100644 --- a/code/renderers/svelte/src/globals.ts +++ b/code/renderers/svelte/src/globals.ts @@ -1,5 +1,3 @@ -import global from 'global'; +globalThis.STORYBOOK_ENV = 'svelte'; -const { window: globalWindow } = global; - -globalWindow.STORYBOOK_ENV = 'svelte'; +export {}; diff --git a/code/renderers/svelte/template/components/index.js b/code/renderers/svelte/template/components/index.js index e01d07856369..b7d4a541673c 100644 --- a/code/renderers/svelte/template/components/index.js +++ b/code/renderers/svelte/template/components/index.js @@ -1,5 +1,3 @@ -import globalThis from 'global'; - import Button from './Button.svelte'; import Pre from './Pre.svelte'; import Form from './Form.svelte'; diff --git a/code/renderers/svelte/template/stories/svelte-mdx.stories.mdx b/code/renderers/svelte/template/stories/svelte-mdx.stories.mdx index 9d8fb482aa47..530f8b534ad8 100644 --- a/code/renderers/svelte/template/stories/svelte-mdx.stories.mdx +++ b/code/renderers/svelte/template/stories/svelte-mdx.stories.mdx @@ -1,4 +1,3 @@ -import globalThis from 'global'; import { Meta, Story, Canvas } from '@storybook/addon-docs'; import ButtonView from './views/ButtonView.svelte'; diff --git a/code/renderers/svelte/template/stories/views/ButtonView.svelte b/code/renderers/svelte/template/stories/views/ButtonView.svelte index d957e58b21cf..fd44d7f9de95 100644 --- a/code/renderers/svelte/template/stories/views/ButtonView.svelte +++ b/code/renderers/svelte/template/stories/views/ButtonView.svelte @@ -3,8 +3,7 @@ * @component Button View * @wrapper */ - import globalThis from 'global'; - const Button = globalThis.Components.Button; + const Button = globalThis.Components.Button; /** * Rounds the button diff --git a/code/renderers/vue/package.json b/code/renderers/vue/package.json index 3c51906c10b9..2d8ca7265be4 100644 --- a/code/renderers/vue/package.json +++ b/code/renderers/vue/package.json @@ -56,7 +56,6 @@ "@storybook/docs-tools": "7.0.0-alpha.54", "@storybook/preview-api": "7.0.0-alpha.54", "@storybook/types": "7.0.0-alpha.54", - "global": "^4.4.0", "react": "16.14.0", "react-dom": "16.14.0", "ts-dedent": "^2.0.0", diff --git a/code/renderers/vue/src/globals.ts b/code/renderers/vue/src/globals.ts index 2fec84f69602..48b4a81ccade 100644 --- a/code/renderers/vue/src/globals.ts +++ b/code/renderers/vue/src/globals.ts @@ -1,6 +1,3 @@ -// @ts-expect-error (Converted from ts-ignore) -import global from 'global'; +globalThis.STORYBOOK_ENV = 'vue'; -const { window: globalWindow } = global; - -globalWindow.STORYBOOK_ENV = 'vue'; +export {}; diff --git a/code/renderers/vue/template/components/index.js b/code/renderers/vue/template/components/index.js index bc9a1b67a30b..41331ea052cd 100644 --- a/code/renderers/vue/template/components/index.js +++ b/code/renderers/vue/template/components/index.js @@ -1,6 +1,4 @@ -import globalThis from 'global'; import Vue from 'vue'; - import Button from './Button.vue'; import Pre from './Pre.vue'; import Form from './Form.vue'; diff --git a/code/renderers/vue/template/stories/custom-decorators.stories.js b/code/renderers/vue/template/stories/custom-decorators.stories.js index 3b061ab7d375..1ae7497ffe96 100644 --- a/code/renderers/vue/template/stories/custom-decorators.stories.js +++ b/code/renderers/vue/template/stories/custom-decorators.stories.js @@ -1,5 +1,3 @@ -import globalThis from 'global'; - const MyButton = globalThis.Components.Button; export default { diff --git a/code/renderers/vue/template/stories/custom-rendering.stories.js b/code/renderers/vue/template/stories/custom-rendering.stories.js index 895df94d9d85..c4e4b05d1ca9 100644 --- a/code/renderers/vue/template/stories/custom-rendering.stories.js +++ b/code/renderers/vue/template/stories/custom-rendering.stories.js @@ -1,5 +1,3 @@ -import globalThis from 'global'; - const MyButton = globalThis.Components.Button; export default { diff --git a/code/renderers/vue/template/stories/vue-mdx.stories.mdx b/code/renderers/vue/template/stories/vue-mdx.stories.mdx index 8a65cb358062..680caa7dc322 100644 --- a/code/renderers/vue/template/stories/vue-mdx.stories.mdx +++ b/code/renderers/vue/template/stories/vue-mdx.stories.mdx @@ -1,4 +1,3 @@ -import globalThis from 'global'; import { Meta, Story, Canvas } from '@storybook/addon-docs'; diff --git a/code/renderers/vue3/package.json b/code/renderers/vue3/package.json index db27fe200ba7..fb676c55a84a 100644 --- a/code/renderers/vue3/package.json +++ b/code/renderers/vue3/package.json @@ -55,7 +55,6 @@ "@storybook/docs-tools": "7.0.0-alpha.54", "@storybook/preview-api": "7.0.0-alpha.54", "@storybook/types": "7.0.0-alpha.54", - "global": "^4.4.0", "react": "16.14.0", "react-dom": "16.14.0", "ts-dedent": "^2.0.0", diff --git a/code/renderers/vue3/src/globals.ts b/code/renderers/vue3/src/globals.ts index 5a17ebf65326..c4bf08342647 100644 --- a/code/renderers/vue3/src/globals.ts +++ b/code/renderers/vue3/src/globals.ts @@ -1,6 +1,3 @@ -// @ts-expect-error (Converted from ts-ignore) -import global from 'global'; +globalThis.STORYBOOK_ENV = 'vue3'; -const { window: globalWindow } = global; - -globalWindow.STORYBOOK_ENV = 'vue3'; +export {}; diff --git a/code/renderers/vue3/template/components/index.js b/code/renderers/vue3/template/components/index.js index af1301e7e2ae..a889a1c64df9 100644 --- a/code/renderers/vue3/template/components/index.js +++ b/code/renderers/vue3/template/components/index.js @@ -1,5 +1,3 @@ -import globalThis from 'global'; - import Button from './Button.vue'; import Pre from './Pre.vue'; import Form from './Form.vue'; diff --git a/code/renderers/vue3/template/stories/decorators.stories.js b/code/renderers/vue3/template/stories/decorators.stories.js index 5835f38eea13..3e3579e29cdb 100644 --- a/code/renderers/vue3/template/stories/decorators.stories.js +++ b/code/renderers/vue3/template/stories/decorators.stories.js @@ -1,4 +1,3 @@ -import globalThis from 'global'; import { h } from 'vue'; const { Button, Pre } = globalThis.Components; diff --git a/code/renderers/vue3/template/stories/preview.js b/code/renderers/vue3/template/stories/preview.js index 1b2cbeae203b..056a62f25e1a 100644 --- a/code/renderers/vue3/template/stories/preview.js +++ b/code/renderers/vue3/template/stories/preview.js @@ -1,4 +1,3 @@ -import globalThis from 'global'; // eslint-disable-next-line import/no-extraneous-dependencies import { setup } from '@storybook/vue3'; diff --git a/code/renderers/vue3/template/stories/vue3-mdx.stories.mdx b/code/renderers/vue3/template/stories/vue3-mdx.stories.mdx index 1656236cf39f..a88afcd712f9 100644 --- a/code/renderers/vue3/template/stories/vue3-mdx.stories.mdx +++ b/code/renderers/vue3/template/stories/vue3-mdx.stories.mdx @@ -1,4 +1,3 @@ -import globalThis from 'global'; import { Meta, Story, Canvas } from '@storybook/addon-docs'; diff --git a/code/renderers/web-components/package.json b/code/renderers/web-components/package.json index b4f5892908e1..226d10d2f4aa 100644 --- a/code/renderers/web-components/package.json +++ b/code/renderers/web-components/package.json @@ -59,7 +59,6 @@ "@storybook/manager-api": "7.0.0-alpha.54", "@storybook/preview-api": "7.0.0-alpha.54", "@storybook/types": "7.0.0-alpha.54", - "global": "^4.4.0", "react": "16.14.0", "react-dom": "16.14.0", "ts-dedent": "^2.0.0" diff --git a/code/renderers/web-components/src/docs/__testfixtures__/lit-element-demo-card/input.js b/code/renderers/web-components/src/docs/__testfixtures__/lit-element-demo-card/input.js index 0631666f8714..9d36b297996c 100644 --- a/code/renderers/web-components/src/docs/__testfixtures__/lit-element-demo-card/input.js +++ b/code/renderers/web-components/src/docs/__testfixtures__/lit-element-demo-card/input.js @@ -1,9 +1,6 @@ -// @ts-expect-error (Converted from ts-ignore) -import global from 'global'; - import { LitElement, html, css } from 'lit-element'; -const { CustomEvent } = global; +const { CustomEvent } = globalThis; const demoWcCardStyle = css` :host { diff --git a/code/renderers/web-components/src/globals.ts b/code/renderers/web-components/src/globals.ts index 3a96cebeb784..76fdf32128a5 100644 --- a/code/renderers/web-components/src/globals.ts +++ b/code/renderers/web-components/src/globals.ts @@ -1,5 +1,3 @@ -import global from 'global'; +globalThis.STORYBOOK_ENV = 'web-components'; -const { window: globalWindow } = global; - -globalWindow.STORYBOOK_ENV = 'web-components'; +export {}; diff --git a/code/renderers/web-components/src/index.ts b/code/renderers/web-components/src/index.ts index ffa29ea28b6d..38ba642976a3 100644 --- a/code/renderers/web-components/src/index.ts +++ b/code/renderers/web-components/src/index.ts @@ -1,10 +1,8 @@ /// -import global from 'global'; - import './globals'; -const { window, EventSource } = global; +const { EventSource } = globalThis; export * from './public-types'; export * from './public-api'; @@ -21,7 +19,7 @@ if (module && module.hot && module.hot.decline) { // Only care for built events. Heartbeats are not parsable so we ignore those const { action } = JSON.parse(event.data); if (action === 'built') { - window.location.reload(); + globalThis.location.reload(); } } catch (error) { // Most part we only get here from the data in the server-sent event not being parsable which is ok diff --git a/code/renderers/web-components/src/render.ts b/code/renderers/web-components/src/render.ts index cf8b24546ef5..c2fd254cae32 100644 --- a/code/renderers/web-components/src/render.ts +++ b/code/renderers/web-components/src/render.ts @@ -1,8 +1,4 @@ /* eslint-disable no-param-reassign */ -/* eslint-disable @typescript-eslint/ban-ts-comment */ - -import global from 'global'; - import { dedent } from 'ts-dedent'; import { render as litRender } from 'lit-html'; // Keep `.js` extension to avoid issue with Webpack (related to export map?) @@ -12,7 +8,7 @@ import { simulatePageLoad, simulateDOMContentLoaded } from '@storybook/preview-a import type { RenderContext, ArgsStoryFn } from '@storybook/types'; import type { WebComponentsRenderer } from './types'; -const { Node } = global; +const { Node } = globalThis; export const render: ArgsStoryFn = (args, context) => { const { id, component } = context; @@ -24,7 +20,7 @@ export const render: ArgsStoryFn = (args, context) => { const element = document.createElement(component); Object.entries(args).forEach(([key, val]) => { - // @ts-ignore + // @ts-expect-error (converted from ts-ignore) element[key] = val; }); return element; diff --git a/code/renderers/web-components/template/components/Button.js b/code/renderers/web-components/template/components/Button.js index 6baef52d5cc0..8dc831b0dec7 100644 --- a/code/renderers/web-components/template/components/Button.js +++ b/code/renderers/web-components/template/components/Button.js @@ -1,5 +1,4 @@ /* eslint-disable import/no-extraneous-dependencies */ -import globalThis from 'global'; import { html, LitElement } from 'lit'; const { CustomEvent, customElements } = globalThis; diff --git a/code/renderers/web-components/template/components/Form.js b/code/renderers/web-components/template/components/Form.js index fe49e5174042..2bcfd0ced166 100644 --- a/code/renderers/web-components/template/components/Form.js +++ b/code/renderers/web-components/template/components/Form.js @@ -1,5 +1,4 @@ /* eslint-disable import/no-extraneous-dependencies */ -import globalThis from 'global'; import { html, LitElement } from 'lit'; const { CustomEvent, customElements } = globalThis; diff --git a/code/renderers/web-components/template/components/Html.js b/code/renderers/web-components/template/components/Html.js index e32977aafda9..4c717efd199f 100644 --- a/code/renderers/web-components/template/components/Html.js +++ b/code/renderers/web-components/template/components/Html.js @@ -1,5 +1,4 @@ /* eslint-disable import/no-extraneous-dependencies */ -import globalThis from 'global'; import { LitElement } from 'lit'; const { customElements } = globalThis; diff --git a/code/renderers/web-components/template/components/Pre.js b/code/renderers/web-components/template/components/Pre.js index c1a4d11422d1..dac16ed00ee4 100644 --- a/code/renderers/web-components/template/components/Pre.js +++ b/code/renderers/web-components/template/components/Pre.js @@ -1,5 +1,4 @@ /* eslint-disable import/extensions, import/no-extraneous-dependencies */ -import globalThis from 'global'; import { html, LitElement } from 'lit'; import { styleMap } from 'lit-html/directives/style-map.js'; diff --git a/code/renderers/web-components/template/components/index.js b/code/renderers/web-components/template/components/index.js index d41925728dd3..77cb5eed07a3 100644 --- a/code/renderers/web-components/template/components/index.js +++ b/code/renderers/web-components/template/components/index.js @@ -1,5 +1,3 @@ -import globalThis from 'global'; - import { ButtonTag } from './Button'; import { FormTag } from './Form'; import { HtmlTag } from './Html'; diff --git a/code/renderers/web-components/template/stories/demo-wc-card/DemoWcCard.js b/code/renderers/web-components/template/stories/demo-wc-card/DemoWcCard.js index d8ef04350983..0015f36d3e26 100644 --- a/code/renderers/web-components/template/stories/demo-wc-card/DemoWcCard.js +++ b/code/renderers/web-components/template/stories/demo-wc-card/DemoWcCard.js @@ -1,9 +1,8 @@ -import global from 'global'; import { LitElement, html } from 'lit'; // eslint-disable-next-line import/extensions import { demoWcCardStyle } from './demoWcCardStyle.css.js'; -const { CustomEvent } = global; +const { CustomEvent } = globalThis; /** * This is a container looking like a card with a back and front side you can switch diff --git a/code/tsconfig.json b/code/tsconfig.json index 645fbb05c512..09faaab6d1e2 100644 --- a/code/tsconfig.json +++ b/code/tsconfig.json @@ -16,6 +16,8 @@ "strictBindCallApply": true, "lib": ["dom", "esnext"] }, + "files": ["types/globalThis.d.ts"], + "include": ["./**/*"], "exclude": ["dist", "**/dist", "node_modules", "**/node_modules", "**/setup-jest.ts"], "ts-node": { "transpileOnly": true, diff --git a/code/types/globalThis.d.ts b/code/types/globalThis.d.ts new file mode 100644 index 000000000000..be55ba4eda57 --- /dev/null +++ b/code/types/globalThis.d.ts @@ -0,0 +1,46 @@ +/* eslint-disable no-underscore-dangle, @typescript-eslint/naming-convention */ + +import type { + BuilderOptions, + CoreConfig, + DocsOptions, + Store_NormalizedStoriesSpecifierEntry, + StorybookConfig, + Renderer, +} from '@storybook/types'; +import type { AddonStore } from '@storybook/addons'; +import type { Channel } from '@storybook/channels'; +import type { ClientApi, StoryStore } from '@storybook/client-api'; +import type { PreviewWeb } from '@storybook/preview-web'; + +declare global { + var CHANNEL_OPTIONS: CoreConfig['channelOptions']; + var CONFIG_TYPE: BuilderOptions['configType']; + var DOCS_OPTIONS: DocsOptions | undefined; + var FEATURES: StorybookConfig['features'] | undefined; + var FRAMEWORK_OPTIONS: any; + var STORYBOOK_REACT_CLASSES: {}; + var STORYBOOK_ENV: string; + var __STORYBOOK_ADDONS: AddonStore | undefined; + var __STORYBOOK_ADDONS_CHANNEL__: Channel | undefined; + var __STORYBOOK_CLIENT_API__: ClientApi | undefined; + var __STORYBOOK_PREVIEW__: PreviewWeb | undefined; + var __STORYBOOK_STORY_STORE__: StoryStore | undefined; + var SERVER_CHANNEL_URL: string | undefined; + var IS_STORYBOOK: true | undefined; + var LOGLEVEL: 'trace' | 'debug' | 'info' | 'warn' | 'error' | 'silent'; + var PREVIEW_URL: string | undefined; + var RELEASE_NOTES_DATA: string | undefined; // stringified ReleaseNotesData + var VERSIONCHECK: string | undefined; // stringified VersionCheck + var Components: { + Button?: any; + Pre?: any; + Form?: any; + Html?: any; + }; + var STORIES: Array< + Omit & { + importPathMatcher: string; + } + >; +} diff --git a/code/ui/.storybook/preview.tsx b/code/ui/.storybook/preview.tsx index 931ac9dbf6bb..6a2b4bbd7d11 100644 --- a/code/ui/.storybook/preview.tsx +++ b/code/ui/.storybook/preview.tsx @@ -1,4 +1,3 @@ -import global from 'global'; import React, { Fragment, useEffect } from 'react'; import isChromatic from 'chromatic/isChromatic'; import { @@ -14,11 +13,9 @@ import { useArgs, DocsContext } from '@storybook/preview-api'; import { Symbols } from '@storybook/components'; import type { PreviewWeb } from '@storybook/preview-api'; import type { ReactRenderer } from '@storybook/react'; -import type { Channel } from '@storybook/channels'; - import { DocsContainer } from '../blocks/src/blocks/DocsContainer'; -const { document } = global; +const { document } = globalThis; const ThemeBlock = styled.div<{ side: 'left' | 'right' }>( { @@ -90,8 +87,9 @@ const ThemedSetRoot = () => { }; // eslint-disable-next-line no-underscore-dangle -const preview = (window as any).__STORYBOOK_PREVIEW__ as PreviewWeb; -const channel = (window as any).__STORYBOOK_ADDONS_CHANNEL__ as Channel; +const preview = (globalThis as any).__STORYBOOK_PREVIEW__ as PreviewWeb; +// eslint-disable-next-line @typescript-eslint/no-non-null-assertion +const channel = globalThis.__STORYBOOK_ADDONS_CHANNEL__!; export const loaders = [ /** * This loader adds a DocsContext to the story, which is required for the most Blocks to work. diff --git a/code/ui/blocks/package.json b/code/ui/blocks/package.json index 473defaa129e..0ad831ed570f 100644 --- a/code/ui/blocks/package.json +++ b/code/ui/blocks/package.json @@ -55,7 +55,6 @@ "@types/lodash": "^4.14.167", "color-convert": "^2.0.1", "dequal": "^2.0.2", - "global": "^4.4.0", "lodash": "^4.17.21", "markdown-to-jsx": "^7.1.3", "memoizerific": "^1.11.3", diff --git a/code/ui/blocks/src/blocks/DocsContainer.tsx b/code/ui/blocks/src/blocks/DocsContainer.tsx index f80dc3e42dd4..6179d3c4020f 100644 --- a/code/ui/blocks/src/blocks/DocsContainer.tsx +++ b/code/ui/blocks/src/blocks/DocsContainer.tsx @@ -1,6 +1,5 @@ import type { FunctionComponent, ReactNode } from 'react'; import React, { useEffect } from 'react'; -import global from 'global'; import type { ThemeVars } from '@storybook/theming'; import { ThemeProvider, ensure as ensureTheme } from '@storybook/theming'; import type { Renderer } from '@storybook/types'; @@ -10,7 +9,7 @@ import { DocsContext } from './DocsContext'; import { SourceContainer } from './SourceContainer'; import { scrollToElement } from './utils'; -const { document, window: globalWindow } = global; +const { document } = globalThis; export interface DocsContainerProps { context: DocsContextProps; @@ -26,7 +25,7 @@ export const DocsContainer: FunctionComponent = ({ useEffect(() => { let url; try { - url = new URL(globalWindow.parent.location); + url = new URL(globalThis.parent.location.toString()); if (url.hash) { const element = document.getElementById(url.hash.substring(1)); if (element) { diff --git a/code/ui/blocks/src/blocks/DocsContext.ts b/code/ui/blocks/src/blocks/DocsContext.ts index 17069f1727da..b9637cf7d010 100644 --- a/code/ui/blocks/src/blocks/DocsContext.ts +++ b/code/ui/blocks/src/blocks/DocsContext.ts @@ -1,7 +1,6 @@ /* eslint-disable no-underscore-dangle */ import type { Context } from 'react'; import { createContext } from 'react'; -import { window as globalWindow } from 'global'; import type { DocsContextProps, Renderer } from '@storybook/types'; @@ -12,11 +11,12 @@ export type { DocsContextProps }; // we will have multiple DocsContext definitions - leading to lost context in // the React component tree. // This was specifically a problem with the Vite builder. -if (globalWindow && globalWindow.__DOCS_CONTEXT__ === undefined) { - globalWindow.__DOCS_CONTEXT__ = createContext(null); - globalWindow.__DOCS_CONTEXT__.displayName = 'DocsContext'; + +if (typeof globalThis.__DOCS_CONTEXT__ === 'undefined') { + globalThis.__DOCS_CONTEXT__ = createContext(null); + globalThis.__DOCS_CONTEXT__.displayName = 'DocsContext'; } -export const DocsContext: Context> = globalWindow - ? globalWindow.__DOCS_CONTEXT__ +export const DocsContext: Context> = globalThis + ? globalThis.__DOCS_CONTEXT__ : createContext(null); diff --git a/code/ui/blocks/src/blocks/mdx.tsx b/code/ui/blocks/src/blocks/mdx.tsx index c7e14328a6ac..2d31546b4833 100644 --- a/code/ui/blocks/src/blocks/mdx.tsx +++ b/code/ui/blocks/src/blocks/mdx.tsx @@ -2,13 +2,12 @@ import type { FC, SyntheticEvent } from 'react'; import React, { useContext } from 'react'; import { NAVIGATE_URL } from '@storybook/core-events'; import { Code, components } from '@storybook/components'; -import global from 'global'; import { styled } from '@storybook/theming'; import { Source } from '../components'; import type { DocsContextProps } from './DocsContext'; import { DocsContext } from './DocsContext'; -const { document } = global; +const { document } = globalThis; // Hacky utility for asserting identifiers in MDX Story elements export const assertIsFn = (val: any) => { diff --git a/code/ui/blocks/src/components/IFrame.tsx b/code/ui/blocks/src/components/IFrame.tsx index be3460cb7f7b..98a515a308c9 100644 --- a/code/ui/blocks/src/components/IFrame.tsx +++ b/code/ui/blocks/src/components/IFrame.tsx @@ -1,7 +1,4 @@ import React, { Component } from 'react'; -import global from 'global'; - -const { window: globalWindow } = global; interface IFrameProps { id: string; @@ -25,7 +22,7 @@ export class IFrame extends Component { componentDidMount() { const { id } = this.props; - this.iframe = globalWindow.document.getElementById(id); + this.iframe = globalThis.document.getElementById(id); } shouldComponentUpdate(nextProps: IFrameProps) { diff --git a/code/ui/blocks/src/components/Preview.stories.tsx b/code/ui/blocks/src/components/Preview.stories.tsx index baa4bb70f50c..27e6f04545d9 100644 --- a/code/ui/blocks/src/components/Preview.stories.tsx +++ b/code/ui/blocks/src/components/Preview.stories.tsx @@ -1,14 +1,11 @@ import type { ComponentProps } from 'react'; import React from 'react'; import { styled } from '@storybook/theming'; -import global from 'global'; import { Spaced, Button } from '@storybook/components'; import { Preview, PreviewSkeleton } from './Preview'; import { Story } from './Story'; import * as sourceStories from './Source.stories'; -const { window: globalWindow } = global; - export default { component: Preview, }; @@ -194,7 +191,7 @@ export const WithAdditionalActions = () => ( { title: 'Open on GitHub', onClick: () => { - globalWindow.location.href = + globalThis.location.href = 'https://github.com/storybookjs/storybook/blob/next/code/ui/blocks/src/components/Preview.stories.tsx#L165-L186'; }, }, diff --git a/code/ui/blocks/src/components/Preview.tsx b/code/ui/blocks/src/components/Preview.tsx index f93ba28cdf2f..9eb82abfe747 100644 --- a/code/ui/blocks/src/components/Preview.tsx +++ b/code/ui/blocks/src/components/Preview.tsx @@ -3,7 +3,6 @@ import React, { Children, useCallback, useState } from 'react'; import { darken } from 'polished'; import { styled } from '@storybook/theming'; -import global from 'global'; import { ActionBar, Zoom } from '@storybook/components'; import type { ActionItem } from '@storybook/components'; @@ -215,8 +214,6 @@ export const Preview: FC = ({ // @ts-expect-error (Converted from ts-ignore) const layout = getLayout(Children.count(children) === 1 ? [children] : children); - const { window: globalWindow } = global; - const copyToClipboard = useCallback(async (text: string) => { const { createCopyToClipboardFunction } = await import('@storybook/components'); createCopyToClipboardFunction(); @@ -233,7 +230,7 @@ export const Preview: FC = ({ onClick: () => {}, }, ]); - globalWindow.setTimeout( + globalThis.setTimeout( () => setAdditionalActionItems( additionalActionItems.filter((item) => item.title !== 'Copied') diff --git a/code/ui/blocks/src/components/Story.tsx b/code/ui/blocks/src/components/Story.tsx index 4719a8ab6f4f..10cdb08ff9dc 100644 --- a/code/ui/blocks/src/components/Story.tsx +++ b/code/ui/blocks/src/components/Story.tsx @@ -1,4 +1,3 @@ -import global from 'global'; import type { ElementType, FunctionComponent } from 'react'; import React, { createElement, Fragment } from 'react'; import type { Parameters } from '@storybook/types'; @@ -8,7 +7,7 @@ import { EmptyBlock } from '.'; import { IFrame } from './IFrame'; import { ZoomContext } from './ZoomContext'; -const { PREVIEW_URL } = global; +const { PREVIEW_URL } = globalThis; const BASE_URL = PREVIEW_URL || 'iframe.html'; export enum StoryError { diff --git a/code/ui/blocks/src/controls/Object.tsx b/code/ui/blocks/src/controls/Object.tsx index fbd0a91ab9ad..41c67ad60bbd 100644 --- a/code/ui/blocks/src/controls/Object.tsx +++ b/code/ui/blocks/src/controls/Object.tsx @@ -1,4 +1,3 @@ -import global from 'global'; import cloneDeep from 'lodash/cloneDeep'; import type { ComponentProps, SyntheticEvent, FC, FocusEvent } from 'react'; import React, { useCallback, useMemo, useState, useEffect, useRef } from 'react'; @@ -8,8 +7,6 @@ import { JsonTree, getObjectType } from './react-editable-json-tree'; import { getControlId, getControlSetterButtonId } from './helpers'; import type { ControlProps, ObjectValue, ObjectConfig } from './types'; -const { window: globalWindow } = global; - type JsonTreeProps = ComponentProps; const Wrapper = styled.div(({ theme }) => ({ @@ -205,7 +202,7 @@ const RawInput = styled(Form.Textarea)(({ theme }) => ({ const ENTER_EVENT = { bubbles: true, cancelable: true, key: 'Enter', code: 'Enter', keyCode: 13 }; const dispatchEnterKey = (event: SyntheticEvent) => { - event.currentTarget.dispatchEvent(new globalWindow.KeyboardEvent('keydown', ENTER_EVENT)); + event.currentTarget.dispatchEvent(new globalThis.KeyboardEvent('keydown', ENTER_EVENT)); }; const selectValue = (event: SyntheticEvent) => { event.currentTarget.select(); diff --git a/code/ui/blocks/src/typings.d.ts b/code/ui/blocks/src/typings.d.ts index 22352f1c3419..b5f784be7766 100644 --- a/code/ui/blocks/src/typings.d.ts +++ b/code/ui/blocks/src/typings.d.ts @@ -1,3 +1,5 @@ -declare module 'global'; declare module 'markdown-to-jsx'; declare module '*.md'; + +// eslint-disable-next-line no-underscore-dangle, @typescript-eslint/naming-convention +declare var __DOCS_CONTEXT__: React.Context; diff --git a/code/ui/components/package.json b/code/ui/components/package.json index 6079fd00a812..02451ab6268f 100644 --- a/code/ui/components/package.json +++ b/code/ui/components/package.json @@ -64,7 +64,6 @@ "@types/react-syntax-highlighter": "11.0.5", "@types/util-deprecate": "^1.0.0", "css": "^3.0.0", - "global": "^4.4.0", "overlayscrollbars": "^1.13.1", "polished": "^4.2.2", "prettier": "^2.7.1", diff --git a/code/ui/components/scripts/writeCssScript.js b/code/ui/components/scripts/writeCssScript.js index 011c1e5543e5..f62e2fe8519c 100644 --- a/code/ui/components/scripts/writeCssScript.js +++ b/code/ui/components/scripts/writeCssScript.js @@ -6,7 +6,6 @@ const fs = require('fs'); const { parse } = require('css'); -const { isNaN } = require('global'); const INPUT = require.resolve('overlayscrollbars/css/OverlayScrollbars.min.css'); const OUTPUT = `${__dirname}/../src/ScrollArea/ScrollAreaStyles.ts`; @@ -74,7 +73,7 @@ const getDeclarations = (decs, opts = {}) => { const camel = (str) => str.replace(/(-[a-z])/g, (x) => x.toUpperCase()).replace(/-/g, ''); const parsePx = (val) => { - return /px$/.test(val) || val === '' || (val.match(/\d$/) && !isNaN(parseInt(val, 10))) + return /px$/.test(val) || val === '' || (val.match(/\d$/) && !globalThis.isNaN(parseInt(val, 10))) ? parseFloat(val.replace(/px$/, '')) : val; }; diff --git a/code/ui/components/src/Zoom/browserSupportsCssZoom.ts b/code/ui/components/src/Zoom/browserSupportsCssZoom.ts index 93b62ac6c0e8..e88299f19e9b 100644 --- a/code/ui/components/src/Zoom/browserSupportsCssZoom.ts +++ b/code/ui/components/src/Zoom/browserSupportsCssZoom.ts @@ -1,12 +1,7 @@ -import global from 'global'; - -const { window: globalWindow } = global; - export function browserSupportsCssZoom(): boolean { try { - return ( - globalWindow.document.implementation.createHTMLDocument('').body.style.zoom !== undefined - ); + // @ts-expect-error nonstandard, safari only + return globalThis.document.implementation.createHTMLDocument('').body.style.zoom !== undefined; } catch (error) { return false; } diff --git a/code/ui/components/src/syntaxhighlighter/syntaxhighlighter.tsx b/code/ui/components/src/syntaxhighlighter/syntaxhighlighter.tsx index 4d29727d340b..39830dde0b87 100644 --- a/code/ui/components/src/syntaxhighlighter/syntaxhighlighter.tsx +++ b/code/ui/components/src/syntaxhighlighter/syntaxhighlighter.tsx @@ -2,7 +2,6 @@ import type { ComponentProps, FC, MouseEvent } from 'react'; import React, { useCallback, useState } from 'react'; import { logger } from '@storybook/client-logger'; import { styled } from '@storybook/theming'; -import global from 'global'; import memoize from 'memoizerific'; import jsx from 'react-syntax-highlighter/dist/esm/languages/prism/jsx'; @@ -31,7 +30,7 @@ import type { SyntaxHighlighterRendererProps, } from './syntaxhighlighter-types'; -const { navigator, document, window: globalWindow } = global; +const { navigator, document } = globalThis; ReactSyntaxHighlighter.registerLanguage('jsextra', jsExtras); ReactSyntaxHighlighter.registerLanguage('jsx', jsx); @@ -56,7 +55,7 @@ export function createCopyToClipboardFunction() { return (text: string) => navigator.clipboard.writeText(text); } return async (text: string) => { - const tmp = document.createElement('TEXTAREA'); + const tmp = document.createElement('textarea'); const focus = document.activeElement; tmp.value = text; @@ -65,6 +64,7 @@ export function createCopyToClipboardFunction() { tmp.select(); document.execCommand('copy'); document.body.removeChild(tmp); + // @ts-expect-error Maybe we should check that this is focusable? focus.focus(); }; } @@ -215,7 +215,7 @@ export const SyntaxHighlighter: FC = ({ copyToClipboard(highlightableCode) .then(() => { setCopied(true); - globalWindow.setTimeout(() => setCopied(false), 1500); + globalThis.setTimeout(() => setCopied(false), 1500); }) .catch(logger.error); }, diff --git a/code/ui/components/src/tooltip/WithTooltip.tsx b/code/ui/components/src/tooltip/WithTooltip.tsx index 0d7bf1c3fdb5..59a776b915d9 100644 --- a/code/ui/components/src/tooltip/WithTooltip.tsx +++ b/code/ui/components/src/tooltip/WithTooltip.tsx @@ -1,13 +1,12 @@ import type { FC, ReactNode } from 'react'; import React, { useCallback, useState, useEffect } from 'react'; import { styled } from '@storybook/theming'; -import global from 'global'; import TooltipTrigger from 'react-popper-tooltip'; import type { Modifier, Placement } from '@popperjs/core'; import { Tooltip } from './Tooltip'; -const { document } = global; +const { document } = globalThis; // A target that doesn't speak popper const TargetContainer = styled.div<{ mode: string }>` diff --git a/code/ui/components/src/typings.d.ts b/code/ui/components/src/typings.d.ts index 22352f1c3419..c1efea064de9 100644 --- a/code/ui/components/src/typings.d.ts +++ b/code/ui/components/src/typings.d.ts @@ -1,3 +1,2 @@ -declare module 'global'; declare module 'markdown-to-jsx'; declare module '*.md'; diff --git a/code/ui/manager/README.md b/code/ui/manager/README.md index 228a4a3af761..b4a76320d3f0 100644 --- a/code/ui/manager/README.md +++ b/code/ui/manager/README.md @@ -55,11 +55,10 @@ export default class MyProvider extends Provider { Then you need to initialize the UI like this: ```js -import global from 'global'; import { renderStorybookUI } from '@storybook/ui'; import Provider from './provider'; -const { document } = global; +const { document } = globalThis; const roolEl = document.getElementById('root'); renderStorybookUI(roolEl, new Provider()); diff --git a/code/ui/manager/package.json b/code/ui/manager/package.json index f6040b17d189..abfe05d18aa4 100644 --- a/code/ui/manager/package.json +++ b/code/ui/manager/package.json @@ -70,7 +70,6 @@ "enzyme": "^3.11.0", "fs-extra": "^9.0.1", "fuse.js": "^3.6.1", - "global": "^4.4.0", "lodash": "^4.17.21", "markdown-to-jsx": "^7.1.3", "memoizerific": "^1.11.3", diff --git a/code/ui/manager/src/components/layout/app.mockdata.tsx b/code/ui/manager/src/components/layout/app.mockdata.tsx index cb40a43eb1d2..9c8ed65f3f07 100644 --- a/code/ui/manager/src/components/layout/app.mockdata.tsx +++ b/code/ui/manager/src/components/layout/app.mockdata.tsx @@ -1,4 +1,3 @@ -import global from 'global'; import type { FC } from 'react'; import React, { Component } from 'react'; import { styled } from '@storybook/theming'; diff --git a/code/ui/manager/src/components/preview/tools/copy.tsx b/code/ui/manager/src/components/preview/tools/copy.tsx index 82b42596faba..78219a12a3ca 100644 --- a/code/ui/manager/src/components/preview/tools/copy.tsx +++ b/code/ui/manager/src/components/preview/tools/copy.tsx @@ -1,11 +1,10 @@ -import global from 'global'; import React from 'react'; import copy from 'copy-to-clipboard'; import { getStoryHref, IconButton, Icons } from '@storybook/components'; import { Consumer, type Combo } from '@storybook/manager-api'; import type { Addon } from '@storybook/manager-api'; -const { PREVIEW_URL, document } = global; +const { PREVIEW_URL, document } = globalThis; const copyMapper = ({ state }: Combo) => { const { storyId, refId, refs } = state; diff --git a/code/ui/manager/src/components/preview/tools/eject.tsx b/code/ui/manager/src/components/preview/tools/eject.tsx index 2c638e219e7d..2efa1e61cb3e 100644 --- a/code/ui/manager/src/components/preview/tools/eject.tsx +++ b/code/ui/manager/src/components/preview/tools/eject.tsx @@ -1,10 +1,9 @@ -import global from 'global'; import React from 'react'; import { getStoryHref, IconButton, Icons } from '@storybook/components'; import { Consumer, type Combo } from '@storybook/manager-api'; import type { Addon } from '@storybook/manager-api'; -const { PREVIEW_URL } = global; +const { PREVIEW_URL } = globalThis; const ejectMapper = ({ state }: Combo) => { const { storyId, refId, refs } = state; diff --git a/code/ui/manager/src/components/sidebar/RefBlocks.tsx b/code/ui/manager/src/components/sidebar/RefBlocks.tsx index 20258736d384..5e82141cadb5 100644 --- a/code/ui/manager/src/components/sidebar/RefBlocks.tsx +++ b/code/ui/manager/src/components/sidebar/RefBlocks.tsx @@ -1,4 +1,3 @@ -import global from 'global'; import type { FC } from 'react'; import React, { useState, useCallback, Fragment } from 'react'; @@ -8,7 +7,7 @@ import { styled } from '@storybook/theming'; import { Loader, Contained } from './Loader'; -const { window: globalWindow, document } = global; +const { document } = globalThis; const TextStyle = styled.div(({ theme }) => ({ fontSize: theme.typography.size.s2 - 1, @@ -111,12 +110,12 @@ export const AuthBlock: FC<{ loginUrl: string; id: string }> = ({ loginUrl, id } const [isAuthAttempted, setAuthAttempted] = useState(false); const refresh = useCallback(() => { - globalWindow.document.location.reload(); + document.location.reload(); }, []); const open = useCallback((e) => { e.preventDefault(); - const childWindow = globalWindow.open(loginUrl, `storybook_auth_${id}`, 'resizable,scrollbars'); + const childWindow = globalThis.open(loginUrl, `storybook_auth_${id}`, 'resizable,scrollbars'); // poll for window to close const timer = setInterval(() => { diff --git a/code/ui/manager/src/components/sidebar/RefIndicator.tsx b/code/ui/manager/src/components/sidebar/RefIndicator.tsx index bb06fa3d4f6d..13078342542e 100644 --- a/code/ui/manager/src/components/sidebar/RefIndicator.tsx +++ b/code/ui/manager/src/components/sidebar/RefIndicator.tsx @@ -1,4 +1,3 @@ -import global from 'global'; import type { FC, ComponentProps } from 'react'; import React, { useMemo, useCallback, forwardRef } from 'react'; @@ -12,7 +11,7 @@ import type { RefType } from './types'; import type { getStateType } from './utils'; -const { document, window: globalWindow } = global; +const { document } = globalThis; export type ClickHandler = ComponentProps['links'][number]['onClick']; export interface IndicatorIconProps { @@ -259,7 +258,7 @@ const ReadyMessage: FC<{ const LoginRequiredMessage: FC = ({ loginUrl, id }) => { const open = useCallback((e) => { e.preventDefault(); - const childWindow = globalWindow.open(loginUrl, `storybook_auth_${id}`, 'resizable,scrollbars'); + const childWindow = globalThis.open(loginUrl, `storybook_auth_${id}`, 'resizable,scrollbars'); // poll for window to close const timer = setInterval(() => { diff --git a/code/ui/manager/src/components/sidebar/Search.tsx b/code/ui/manager/src/components/sidebar/Search.tsx index 3206745634b7..b8ece0bc36aa 100644 --- a/code/ui/manager/src/components/sidebar/Search.tsx +++ b/code/ui/manager/src/components/sidebar/Search.tsx @@ -5,7 +5,6 @@ import type { DownshiftState, StateChangeOptions } from 'downshift'; import Downshift from 'downshift'; import type { FuseOptions } from 'fuse.js'; import Fuse from 'fuse.js'; -import global from 'global'; import React, { useMemo, useRef, useState, useCallback } from 'react'; // eslint-disable-next-line import/no-cycle @@ -22,7 +21,7 @@ import { isSearchResult, isExpandType, isClearType, isCloseType } from './types' // eslint-disable-next-line import/no-cycle import { searchItem } from './utils'; -const { document } = global; +const { document } = globalThis; const DEFAULT_MAX_SEARCH_RESULTS = 50; diff --git a/code/ui/manager/src/components/sidebar/SearchResults.tsx b/code/ui/manager/src/components/sidebar/SearchResults.tsx index 709001340953..b1506b303aff 100644 --- a/code/ui/manager/src/components/sidebar/SearchResults.tsx +++ b/code/ui/manager/src/components/sidebar/SearchResults.tsx @@ -1,6 +1,5 @@ import { styled } from '@storybook/theming'; import { Icons } from '@storybook/components'; -import global from 'global'; import type { FC, MouseEventHandler, ReactNode } from 'react'; import React, { useCallback, useEffect } from 'react'; import type { ControllerStateAndHelpers } from 'downshift'; @@ -14,7 +13,7 @@ import { isCloseType, isClearType, isExpandType } from './types'; import { getLink } from './utils'; import { matchesKeyCode, matchesModifiers } from '../../keybinding'; -const { document } = global; +const { document } = globalThis; const ResultsList = styled.ol({ listStyle: 'none', diff --git a/code/ui/manager/src/components/sidebar/useExpanded.ts b/code/ui/manager/src/components/sidebar/useExpanded.ts index eaded1d38fc2..424da3eb282a 100644 --- a/code/ui/manager/src/components/sidebar/useExpanded.ts +++ b/code/ui/manager/src/components/sidebar/useExpanded.ts @@ -1,7 +1,6 @@ import type { StoriesHash } from '@storybook/manager-api'; import { useStorybookApi } from '@storybook/manager-api'; import { STORIES_COLLAPSE_ALL, STORIES_EXPAND_ALL } from '@storybook/core-events'; -import global from 'global'; import throttle from 'lodash/throttle'; import type { Dispatch, MutableRefObject } from 'react'; import type React from 'react'; @@ -12,7 +11,7 @@ import type { Highlight } from './types'; // eslint-disable-next-line import/no-cycle import { isAncestor, getAncestorIds, getDescendantIds, scrollIntoView } from './utils'; -const { document } = global; +const { document } = globalThis; export type ExpandedState = Record; diff --git a/code/ui/manager/src/components/sidebar/useHighlighted.ts b/code/ui/manager/src/components/sidebar/useHighlighted.ts index 5455ca25edf6..26310480f4c6 100644 --- a/code/ui/manager/src/components/sidebar/useHighlighted.ts +++ b/code/ui/manager/src/components/sidebar/useHighlighted.ts @@ -1,4 +1,3 @@ -import global from 'global'; import type { Dispatch, MutableRefObject, SetStateAction } from 'react'; import { useCallback, useEffect, useRef, useState } from 'react'; import { useStorybookApi } from '@storybook/manager-api'; @@ -9,7 +8,7 @@ import type { CombinedDataset, Highlight, Selection } from './types'; // eslint-disable-next-line import/no-cycle import { cycle, isAncestor, scrollIntoView } from './utils'; -const { document, window: globalWindow } = global; +const { document } = globalThis; export interface HighlightedProps { containerRef: MutableRefObject; @@ -87,8 +86,8 @@ export const useHighlighted = ({ if (!(isArrowUp || isArrowDown)) return; event.preventDefault(); - const requestId = globalWindow.requestAnimationFrame(() => { - globalWindow.cancelAnimationFrame(lastRequestId); + const requestId = globalThis.requestAnimationFrame(() => { + globalThis.cancelAnimationFrame(lastRequestId); lastRequestId = requestId; const target = event.target as Element; diff --git a/code/ui/manager/src/components/sidebar/utils.ts b/code/ui/manager/src/components/sidebar/utils.ts index ea1d250cfe84..b43f588c8a7b 100644 --- a/code/ui/manager/src/components/sidebar/utils.ts +++ b/code/ui/manager/src/components/sidebar/utils.ts @@ -1,5 +1,4 @@ import memoize from 'memoizerific'; -import global from 'global'; import type { SyntheticEvent } from 'react'; import type { HashEntry, StoriesHash } from '@storybook/manager-api'; @@ -7,7 +6,7 @@ import type { HashEntry, StoriesHash } from '@storybook/manager-api'; import { DEFAULT_REF_ID } from './Sidebar'; import type { Item, RefType, Dataset, SearchItem } from './types'; -const { document, window: globalWindow } = global; +const { document } = globalThis; export const createId = (itemId: string, refId?: string) => !refId || refId === DEFAULT_REF_ID ? itemId : `${refId}_${itemId}`; @@ -67,7 +66,7 @@ export const scrollIntoView = (element: Element, center = false) => { if (!element) return; const { top, bottom } = element.getBoundingClientRect(); const isInView = - top >= 0 && bottom <= (globalWindow.innerHeight || document.documentElement.clientHeight); + top >= 0 && bottom <= (globalThis.innerHeight || document.documentElement.clientHeight); if (!isInView) element.scrollIntoView({ block: center ? 'center' : 'nearest' }); }; diff --git a/code/ui/manager/src/containers/preview.tsx b/code/ui/manager/src/containers/preview.tsx index 54e6a978ca0c..082c69235f68 100644 --- a/code/ui/manager/src/containers/preview.tsx +++ b/code/ui/manager/src/containers/preview.tsx @@ -1,4 +1,3 @@ -import global from 'global'; import React from 'react'; import type { Combo, StoriesHash } from '@storybook/manager-api'; @@ -6,7 +5,7 @@ import { Consumer } from '@storybook/manager-api'; import { Preview } from '../components/preview/preview'; -const { PREVIEW_URL } = global; +const { PREVIEW_URL } = globalThis; export type Item = StoriesHash[keyof StoriesHash]; diff --git a/code/ui/manager/src/index.tsx b/code/ui/manager/src/index.tsx index dff5953f68a1..a673adc79d7d 100644 --- a/code/ui/manager/src/index.tsx +++ b/code/ui/manager/src/index.tsx @@ -1,4 +1,6 @@ -import global from 'global'; +// eslint-disable-next-line @typescript-eslint/triple-slash-reference +/// + import type { FC } from 'react'; import React from 'react'; import ReactDOM from 'react-dom'; @@ -51,7 +53,7 @@ const Main: FC<{ provider: Provider }> = ({ provider }) => { provider={provider} {...locationData} navigate={navigate} - docsOptions={global?.DOCS_OPTIONS || {}} + docsOptions={globalThis.DOCS_OPTIONS || {}} > {({ state, api }: Combo) => { const panelCount = Object.keys(api.getPanels()).length; diff --git a/code/ui/manager/src/runtime.ts b/code/ui/manager/src/runtime.ts index 55b35f7c3927..cba561822486 100644 --- a/code/ui/manager/src/runtime.ts +++ b/code/ui/manager/src/runtime.ts @@ -1,5 +1,3 @@ -import global from 'global'; - import type { Channel } from '@storybook/channels'; import type { AddonStore } from '@storybook/manager-api'; import { addons } from '@storybook/manager-api'; @@ -13,7 +11,7 @@ import { renderStorybookUI } from './index'; import { values } from './globals/runtime'; import { Keys } from './globals/types'; -const { FEATURES, SERVER_CHANNEL_URL } = global; +const { FEATURES, SERVER_CHANNEL_URL } = globalThis; class ReactProvider extends Provider { private addons: AddonStore; @@ -54,12 +52,12 @@ class ReactProvider extends Provider { } } -const { document } = global; +const { document } = globalThis; const rootEl = document.getElementById('root'); renderStorybookUI(rootEl, new ReactProvider()); // Apply all the globals Object.keys(Keys).forEach((key: keyof typeof Keys) => { - global[Keys[key]] = values[key]; + (globalThis as any)[Keys[key]] = values[key]; }); diff --git a/code/ui/manager/src/settings/index.tsx b/code/ui/manager/src/settings/index.tsx index 6af005aa3c56..0dcfef23cb78 100644 --- a/code/ui/manager/src/settings/index.tsx +++ b/code/ui/manager/src/settings/index.tsx @@ -2,7 +2,6 @@ import { useStorybookApi, useStorybookState } from '@storybook/manager-api'; import { IconButton, Icons, FlexBar, TabBar, TabButton, ScrollArea } from '@storybook/components'; import { Location, Route } from '@storybook/router'; import { styled } from '@storybook/theming'; -import global from 'global'; import type { FC, SyntheticEvent } from 'react'; import React, { Fragment } from 'react'; @@ -11,7 +10,7 @@ import { ReleaseNotesPage } from './release_notes_page'; import { ShortcutsPage } from './shortcuts_page'; import { matchesModifiers, matchesKeyCode } from '../keybinding'; -const { document } = global; +const { document } = globalThis; const TabBarButton = React.memo(function TabBarButton({ changeTab, diff --git a/code/ui/manager/src/settings/typings.d.ts b/code/ui/manager/src/settings/typings.d.ts index e388e48d9c30..e4f5ed2115d0 100644 --- a/code/ui/manager/src/settings/typings.d.ts +++ b/code/ui/manager/src/settings/typings.d.ts @@ -1,2 +1 @@ -declare module 'global'; declare module '@storybook/components/src/treeview/utils'; diff --git a/code/ui/manager/src/typings.d.ts b/code/ui/manager/src/typings.d.ts index 8666686fa2ae..081935cc8a27 100644 --- a/code/ui/manager/src/typings.d.ts +++ b/code/ui/manager/src/typings.d.ts @@ -1,2 +1 @@ -declare module 'global'; declare module 'chromatic/isChromatic'; diff --git a/code/workspace.json b/code/workspace.json index ad82327b6ada..5a5cf17f3238 100644 --- a/code/workspace.json +++ b/code/workspace.json @@ -2,7 +2,7 @@ "version": 2, "projects": { "@storybook/addon-a11y": { - "implicitDependencies": [], + "implicitDependencies": ["@storybook/core-client"], "root": "addons/a11y", "type": "library" }, @@ -127,7 +127,12 @@ "type": "library" }, "@storybook/channel-websocket": { - "implicitDependencies": [], + "implicitDependencies": [ + "@storybook/types", + "@storybook/addons", + "@storybook/client-api", + "@storybook/preview-web" + ], "root": "lib/channel-websocket", "type": "library" }, @@ -187,7 +192,12 @@ "type": "library" }, "@storybook/csf-plugin": { - "implicitDependencies": [], + "implicitDependencies": [ + "@storybook/types", + "@storybook/addons", + "@storybook/client-api", + "@storybook/preview-web" + ], "root": "lib/csf-plugin", "type": "library" }, diff --git a/code/yarn.lock b/code/yarn.lock index 1b10bca67980..db4334eb650b 100644 --- a/code/yarn.lock +++ b/code/yarn.lock @@ -5150,7 +5150,6 @@ __metadata: "@storybook/types": 7.0.0-alpha.54 "@testing-library/react": ^11.2.2 axe-core: ^4.2.0 - global: ^4.4.0 lodash: ^4.17.21 react-sizeme: ^3.0.1 typescript: ^4.9.3 @@ -5178,7 +5177,6 @@ __metadata: "@storybook/types": 7.0.0-alpha.54 "@types/lodash": ^4.14.167 dequal: ^2.0.2 - global: ^4.4.0 lodash: ^4.17.21 polished: ^4.2.2 prop-types: ^15.7.2 @@ -5209,7 +5207,6 @@ __metadata: "@storybook/preview-api": 7.0.0-alpha.54 "@storybook/theming": 7.0.0-alpha.54 "@storybook/types": 7.0.0-alpha.54 - global: ^4.4.0 memoizerific: ^1.11.3 ts-dedent: ^2.0.0 typescript: ^4.9.3 @@ -5269,7 +5266,6 @@ __metadata: "@storybook/theming": 7.0.0-alpha.54 "@storybook/types": 7.0.0-alpha.54 fs-extra: ^9.0.1 - global: ^4.4.0 remark-external-links: ^8.0.0 remark-slug: ^6.0.0 ts-dedent: ^2.0.0 @@ -5318,7 +5314,6 @@ __metadata: "@storybook/core-events": 7.0.0-alpha.54 "@storybook/preview-api": 7.0.0-alpha.54 "@types/webpack-env": ^1.16.0 - global: ^4.4.0 typescript: ^4.9.3 languageName: unknown linkType: soft @@ -5341,7 +5336,6 @@ __metadata: "@storybook/types": 7.0.0-alpha.54 "@types/node": ^16.0.0 formik: ^2.2.9 - global: ^4.4.0 jest-mock: ^27.0.6 polished: ^4.2.2 ts-dedent: ^2.2.0 @@ -5367,7 +5361,6 @@ __metadata: "@storybook/manager-api": 7.0.0-alpha.54 "@storybook/preview-api": 7.0.0-alpha.54 "@storybook/theming": 7.0.0-alpha.54 - global: ^4.4.0 react-sizeme: ^3.0.1 typescript: ^4.9.3 upath: ^1.2.0 @@ -5393,7 +5386,6 @@ __metadata: "@storybook/preview-api": 7.0.0-alpha.54 "@storybook/router": 7.0.0-alpha.54 "@storybook/types": 7.0.0-alpha.54 - global: ^4.4.0 prop-types: ^15.7.2 ts-dedent: ^2.0.0 typescript: ^4.9.3 @@ -5418,7 +5410,6 @@ __metadata: "@storybook/manager-api": 7.0.0-alpha.54 "@storybook/preview-api": 7.0.0-alpha.54 "@storybook/types": 7.0.0-alpha.54 - global: ^4.4.0 typescript: ^4.9.3 peerDependencies: react: ^16.8.0 || ^17.0.0 || ^18.0.0 @@ -5441,7 +5432,6 @@ __metadata: "@storybook/manager-api": 7.0.0-alpha.54 "@storybook/preview-api": 7.0.0-alpha.54 "@storybook/types": 7.0.0-alpha.54 - global: ^4.4.0 ts-dedent: ^2.0.0 typescript: ^4.9.3 peerDependencies: @@ -5502,7 +5492,6 @@ __metadata: enzyme: ^3.11.0 enzyme-to-json: ^3.6.1 glob: ^7.1.6 - global: ^4.4.0 jest-preset-angular: ^8.3.2 jest-specific-snapshot: ^6.0.0 jest-vue-preprocessor: ^1.7.1 @@ -5639,7 +5628,6 @@ __metadata: "@storybook/manager-api": 7.0.0-alpha.54 "@storybook/preview-api": 7.0.0-alpha.54 "@storybook/theming": 7.0.0-alpha.54 - global: ^4.4.0 memoizerific: ^1.11.3 prop-types: ^15.7.2 typescript: ^4.9.3 @@ -5727,7 +5715,6 @@ __metadata: core-js: ^3.8.2 cross-spawn: ^7.0.3 find-up: ^5.0.0 - global: ^4.4.0 jest: ^29.3.1 jest-preset-angular: ^12.0.0 jest-specific-snapshot: ^6.0.0 @@ -5832,7 +5819,6 @@ __metadata: "@types/lodash": ^4.14.167 color-convert: ^2.0.1 dequal: ^2.0.2 - global: ^4.4.0 lodash: ^4.17.21 markdown-to-jsx: ^7.1.3 memoizerific: ^1.11.3 @@ -5945,7 +5931,6 @@ __metadata: express: ^4.17.1 fork-ts-checker-webpack-plugin: ^7.2.8 fs-extra: ^9.0.1 - global: ^4.4.0 html-webpack-plugin: ^5.5.0 path-browserify: ^1.0.1 pretty-hrtime: ^1.0.3 @@ -5977,7 +5962,6 @@ __metadata: "@storybook/channels": 7.0.0-alpha.54 "@storybook/client-logger": 7.0.0-alpha.54 "@storybook/core-events": 7.0.0-alpha.54 - global: ^4.4.0 qs: ^6.10.0 telejson: ^7.0.3 typescript: ^4.9.3 @@ -5990,7 +5974,6 @@ __metadata: dependencies: "@storybook/channels": 7.0.0-alpha.54 "@storybook/client-logger": 7.0.0-alpha.54 - global: ^4.4.0 telejson: ^7.0.3 typescript: ^4.9.3 languageName: unknown @@ -6080,7 +6063,6 @@ __metadata: version: 0.0.0-use.local resolution: "@storybook/client-logger@workspace:lib/client-logger" dependencies: - global: ^4.4.0 typescript: ^4.9.3 languageName: unknown linkType: soft @@ -6130,7 +6112,6 @@ __metadata: "@types/react-syntax-highlighter": 11.0.5 "@types/util-deprecate": ^1.0.0 css: ^3.0.0 - global: ^4.4.0 memoizerific: ^1.11.3 overlayscrollbars: ^1.13.1 polished: ^4.2.2 @@ -6247,7 +6228,6 @@ __metadata: detect-port: ^1.3.0 express: ^4.17.1 fs-extra: ^9.0.1 - global: ^4.4.0 globby: ^11.0.2 ip: ^2.0.0 jest-os-detection: ^1.3.1 @@ -6383,7 +6363,6 @@ __metadata: "@storybook/preview-api": 7.0.0-alpha.54 "@storybook/types": 7.0.0-alpha.54 ember-source: ~3.28.1 - global: ^4.4.0 react: 16.14.0 react-dom: 16.14.0 read-pkg-up: ^7.0.1 @@ -6425,7 +6404,6 @@ __metadata: "@storybook/html": 7.0.0-alpha.54 "@storybook/preset-html-webpack": 7.0.0-alpha.54 "@types/node": ^16.0.0 - global: ^4.4.0 react: 16.14.0 react-dom: 16.14.0 typescript: ^4.9.3 @@ -6442,7 +6420,6 @@ __metadata: "@storybook/docs-tools": 7.0.0-alpha.54 "@storybook/preview-api": 7.0.0-alpha.54 "@storybook/types": 7.0.0-alpha.54 - global: ^4.4.0 react: 16.14.0 react-dom: 16.14.0 ts-dedent: ^2.0.0 @@ -6461,7 +6438,6 @@ __metadata: "@storybook/core-events": 7.0.0-alpha.54 "@storybook/preview-api": 7.0.0-alpha.54 core-js: ^3.8.2 - global: ^4.4.0 typescript: ^4.9.3 languageName: unknown linkType: soft @@ -6562,7 +6538,6 @@ __metadata: "@types/qs": ^6 dequal: ^2.0.2 flush-promises: ^1.0.2 - global: ^4.4.0 lodash: ^4.17.21 memoizerific: ^1.11.3 qs: ^6.10.1 @@ -6599,7 +6574,6 @@ __metadata: enzyme: ^3.11.0 fs-extra: ^9.0.1 fuse.js: ^3.6.1 - global: ^4.4.0 lodash: ^4.17.21 markdown-to-jsx: ^7.1.3 memoizerific: ^1.11.3 @@ -6721,7 +6695,6 @@ __metadata: "@storybook/core-client": 7.0.0-alpha.54 "@storybook/preview-api": 7.0.0-alpha.54 "@storybook/types": 7.0.0-alpha.54 - global: ^4.4.0 preact: ^10.5.13 react: 16.14.0 react-dom: 16.14.0 @@ -6810,7 +6783,6 @@ __metadata: "@storybook/server": 7.0.0-alpha.54 "@types/node": ^16.0.0 fs-extra: ^9.0.1 - global: ^4.4.0 jest-specific-snapshot: ^6.0.0 react: 16.14.0 react-dom: 16.14.0 @@ -6929,7 +6901,6 @@ __metadata: "@types/qs": ^6.9.5 ansi-to-html: ^0.6.11 dequal: ^2.0.2 - global: ^4.4.0 lodash: ^4.17.21 memoizerific: ^1.11.3 qs: ^6.10.0 @@ -7048,7 +7019,6 @@ __metadata: acorn-walk: ^7.2.0 escodegen: ^2.0.0 expect-type: ^0.14.2 - global: ^4.4.0 html-tags: ^3.1.0 jest-specific-snapshot: ^6.0.0 lodash: ^4.17.21 @@ -7246,7 +7216,6 @@ __metadata: fs-extra: ^9.0.1 github-release-from-changelog: ^2.1.1 glob: ^7.1.6 - global: ^4.4.0 http-server: ^0.12.3 husky: ^4.3.7 jest: ^29.3.1 @@ -7338,7 +7307,6 @@ __metadata: dependencies: "@storybook/client-logger": 7.0.0-alpha.54 dequal: ^2.0.2 - global: ^4.4.0 lodash: ^4.17.21 memoizerific: ^1.11.3 qs: ^6.10.0 @@ -7402,7 +7370,6 @@ __metadata: "@storybook/core-client": 7.0.0-alpha.54 "@storybook/preview-api": 7.0.0-alpha.54 "@storybook/types": 7.0.0-alpha.54 - global: ^4.4.0 react: 16.14.0 react-dom: 16.14.0 ts-dedent: ^2.0.0 @@ -7489,7 +7456,6 @@ __metadata: "@storybook/preview-api": 7.0.0-alpha.54 "@storybook/types": 7.0.0-alpha.54 expect-type: ^0.14.2 - global: ^4.4.0 react: 16.14.0 react-dom: 16.14.0 svelte: ^3.31.2 @@ -7547,7 +7513,6 @@ __metadata: "@types/node": ^16.0.0 deep-object-diff: ^1.1.0 fs-extra: ^9.0.1 - global: ^4.4.0 memoizerific: ^1.11.3 polished: ^4.2.2 ts-dedent: ^2.0.0 @@ -7680,7 +7645,6 @@ __metadata: "@storybook/preview-api": 7.0.0-alpha.54 "@storybook/types": 7.0.0-alpha.54 "@vue/vue3-jest": 29 - global: ^4.4.0 react: 16.14.0 react-dom: 16.14.0 ts-dedent: ^2.0.0 @@ -7707,7 +7671,6 @@ __metadata: "@storybook/docs-tools": 7.0.0-alpha.54 "@storybook/preview-api": 7.0.0-alpha.54 "@storybook/types": 7.0.0-alpha.54 - global: ^4.4.0 react: 16.14.0 react-dom: 16.14.0 ts-dedent: ^2.0.0 @@ -7770,7 +7733,6 @@ __metadata: "@storybook/manager-api": 7.0.0-alpha.54 "@storybook/preview-api": 7.0.0-alpha.54 "@storybook/types": 7.0.0-alpha.54 - global: ^4.4.0 lit: 2.3.1 lit-html: 2.0.2 react: 16.14.0 @@ -8748,13 +8710,6 @@ __metadata: languageName: node linkType: hard -"@types/source-list-map@npm:*": - version: 0.1.2 - resolution: "@types/source-list-map@npm:0.1.2" - checksum: 0538ce317294febf40ed3fc3a2e483fa4aee8ba85584a66e5ed9c0af9ea48a348960bc467076643cb56aeafdd7d2252e90c75e68ef664c0477ec87ea0554ffdc - languageName: node - linkType: hard - "@types/stack-utils@npm:^2.0.0": version: 2.0.1 resolution: "@types/stack-utils@npm:2.0.1" @@ -8783,13 +8738,6 @@ __metadata: languageName: node linkType: hard -"@types/tapable@npm:^1": - version: 1.0.8 - resolution: "@types/tapable@npm:1.0.8" - checksum: 01f77d47bac8aaeee7ed298e8e74eb012a28f920106c3c359e1f2730512cd810f2c6165cd2cd769422ae1064e2bf1072778b27fb5ec1973e18c35e2cc1ed5c8d - languageName: node - linkType: hard - "@types/terser-webpack-plugin@npm:^5.2.0": version: 5.2.0 resolution: "@types/terser-webpack-plugin@npm:5.2.0" @@ -8829,15 +8777,6 @@ __metadata: languageName: node linkType: hard -"@types/uglify-js@npm:*": - version: 3.17.1 - resolution: "@types/uglify-js@npm:3.17.1" - dependencies: - source-map: ^0.6.1 - checksum: c19a44017a901ab15f862e6645023bf96ffb7502b7305a15ee811667693ec66a997a42d5d0ba67814de537b562dafd26230142e26c9bb9f840ee8bb7f798cbcc - languageName: node - linkType: hard - "@types/unist@npm:*, @types/unist@npm:^2.0.0, @types/unist@npm:^2.0.2": version: 2.0.6 resolution: "@types/unist@npm:2.0.6" @@ -8889,17 +8828,6 @@ __metadata: languageName: node linkType: hard -"@types/webpack-sources@npm:*": - version: 3.2.0 - resolution: "@types/webpack-sources@npm:3.2.0" - dependencies: - "@types/node": "*" - "@types/source-list-map": "*" - source-map: ^0.7.3 - checksum: 17716e9f03fa63362f92d510bb9119313bac3a7985321e0fe9326dc30ebe598cb2c85b8c7cdc4f4d34d783c4c45e74e3ec08e209f9c9dab27bf188c3def32706 - languageName: node - linkType: hard - "@types/webpack-virtual-modules@npm:^0.1.1": version: 0.1.1 resolution: "@types/webpack-virtual-modules@npm:0.1.1" @@ -8909,17 +8837,14 @@ __metadata: languageName: node linkType: hard -"@types/webpack@npm:^4": - version: 4.41.33 - resolution: "@types/webpack@npm:4.41.33" +"@types/webpack@npm:^5.28.0": + version: 5.28.0 + resolution: "@types/webpack@npm:5.28.0" dependencies: "@types/node": "*" - "@types/tapable": ^1 - "@types/uglify-js": "*" - "@types/webpack-sources": "*" - anymatch: ^3.0.0 - source-map: ^0.6.0 - checksum: dc6db66fa84664d8fab7ea79bd2482ea1c4500b09ed6939258e205548501b8d29c06b0fe5e869c4b59f74acf884c61a391875dadb9f7a91c8cd10c3841143729 + tapable: ^2.2.0 + webpack: ^5 + checksum: 9e86e6b2bd8998c93058230d73e590fece972e8363af05d387cb966be18b648422013ec12963929a532f9c2821bbcd620dbaebc33865aefbf33056b4e3cca8b9 languageName: node linkType: hard @@ -10236,7 +10161,7 @@ __metadata: languageName: node linkType: hard -"anymatch@npm:^3.0.0, anymatch@npm:^3.0.3, anymatch@npm:~3.1.2": +"anymatch@npm:^3.0.3, anymatch@npm:~3.1.2": version: 3.1.3 resolution: "anymatch@npm:3.1.3" dependencies: diff --git a/scripts/.eslintrc.js b/scripts/.eslintrc.js index fe8ebf3eb80c..4d05efa3783c 100644 --- a/scripts/.eslintrc.js +++ b/scripts/.eslintrc.js @@ -1,6 +1,9 @@ module.exports = { root: true, extends: ['@storybook/eslint-config-storybook', 'plugin:storybook/recommended'], + globals: { + globalThis: false, + }, parserOptions: { tsconfigRootDir: __dirname, project: ['./tsconfig.json'], diff --git a/scripts/package.json b/scripts/package.json index f5235c33854e..54bbc9c0c059 100644 --- a/scripts/package.json +++ b/scripts/package.json @@ -3,6 +3,8 @@ "version": "7.0.0-alpha.16", "private": true, "scripts": { + "docs:prettier:check": "cd ../docs && prettier --check ./snippets", + "docs:prettier:write": "cd ../docs && prettier --write ./snippets", "get-report-message": "ts-node ./get-report-message.ts", "get-template": "ts-node ./get-template.ts", "lint": "yarn lint:js && yarn lint:md", @@ -10,9 +12,7 @@ "lint:js:cmd": "cross-env NODE_ENV=production eslint --cache --cache-location=../.cache/eslint --ext .js,.jsx,.json,.html,.ts,.tsx,.mjs --report-unused-disable-directives", "lint:package": "sort-package-json", "task": "ts-node ./task.ts", - "test": "jest --config ./jest.config.js", - "docs:prettier:write": "cd ../docs && prettier --write ./snippets", - "docs:prettier:check": "cd ../docs && prettier --check ./snippets" + "test": "jest --config ./jest.config.js" }, "husky": { "hooks": { diff --git a/scripts/prettier.config.js b/scripts/prettier.config.js index b1a30ba19f81..11e995f76315 100644 --- a/scripts/prettier.config.js +++ b/scripts/prettier.config.js @@ -3,4 +3,5 @@ const base = require('@storybook/linter-config/prettier.config'); module.exports = { ...base, arrowParens: 'always', + overrides: [], }; diff --git a/test-storybooks/external-docs/.storybook/main.cjs b/test-storybooks/external-docs/.storybook/main.cjs index 7cc9f3ab71e1..6b8ddfce118b 100644 --- a/test-storybooks/external-docs/.storybook/main.cjs +++ b/test-storybooks/external-docs/.storybook/main.cjs @@ -21,7 +21,7 @@ const config = { }, features: { postcss: false, - storyStoreV7: !global.navigator?.userAgent?.match?.('jsdom'), + storyStoreV7: !globalThis.navigator?.userAgent?.match?.('jsdom'), buildStoriesJson: true, babelModeV7: true, warnOnLegacyHierarchySeparator: false, diff --git a/test-storybooks/standalone-preview/addPreview.ts b/test-storybooks/standalone-preview/addPreview.ts index f65d8cf7243b..9d302d65f28f 100644 --- a/test-storybooks/standalone-preview/addPreview.ts +++ b/test-storybooks/standalone-preview/addPreview.ts @@ -1,3 +1,3 @@ -export {}; +globalThis.PREVIEW_URL = process.env.PREVIEW_URL; -global.PREVIEW_URL = process.env.PREVIEW_URL; +export {};