Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Build: Replace global with globalThis [WIP] #19386

Closed
wants to merge 19 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 0 additions & 1 deletion code/addons/a11y/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -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"
},
Expand Down
11 changes: 5 additions & 6 deletions code/addons/a11y/src/a11yRunner.ts
Original file line number Diff line number Diff line change
@@ -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();
Expand Down Expand Up @@ -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.
Expand All @@ -64,10 +64,9 @@ const run = async (storyId: string) => {

/** Returns story parameters or default ones. */
const getParams = async (storyId: string): Promise<A11yParameters> => {
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: {},
}
Expand Down
1 change: 0 additions & 1 deletion code/addons/a11y/src/typings.d.ts

This file was deleted.

2 changes: 0 additions & 2 deletions code/addons/a11y/template/stories/parameters.stories.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
import globalThis from 'global';

export default {
component: globalThis.Components.Html,
args: {
Expand Down
2 changes: 0 additions & 2 deletions code/addons/a11y/template/stories/tests.stories.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
import globalThis from 'global';

export default {
component: globalThis.Components.Html,
args: {
Expand Down
1 change: 0 additions & 1 deletion code/addons/actions/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down
3 changes: 1 addition & 2 deletions code/addons/actions/src/decorator.ts
Original file line number Diff line number Diff line change
@@ -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*(.*)$/;

Expand Down
1 change: 0 additions & 1 deletion code/addons/actions/src/typings.d.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,2 @@
// TODO: following packages need definition files or a TS migration
declare module 'global';
declare module 'uuid-browser/v4';
2 changes: 0 additions & 2 deletions code/addons/actions/template/stories/argtype.stories.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
import globalThis from 'global';

export default {
component: globalThis.Components.Button,
args: {
Expand Down
2 changes: 0 additions & 2 deletions code/addons/actions/template/stories/basics.stories.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
import globalThis from 'global';

import { action } from '@storybook/addon-actions';

export default {
Expand Down
2 changes: 0 additions & 2 deletions code/addons/actions/template/stories/configs.stories.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
import globalThis from 'global';

import { actions, configureActions } from '@storybook/addon-actions';

const configs = actions('actionA', 'actionB', 'actionC');
Expand Down
1 change: 0 additions & 1 deletion code/addons/actions/template/stories/parameters.stories.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
import globalThis from 'global';
import { withActions } from '@storybook/addon-actions/decorator';

export default {
Expand Down
1 change: 0 additions & 1 deletion code/addons/backgrounds/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -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"
},
Expand Down
5 changes: 2 additions & 3 deletions code/addons/backgrounds/src/helpers/index.ts
Original file line number Diff line number Diff line change
@@ -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;
};

Expand Down
1 change: 0 additions & 1 deletion code/addons/backgrounds/src/typings.d.ts

This file was deleted.

2 changes: 0 additions & 2 deletions code/addons/backgrounds/template/stories/grid.stories.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
import globalThis from 'global';

export default {
component: globalThis.Components.Button,
args: {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
import globalThis from 'global';

const COLORS = [
{ name: 'red', value: '#FB001D' },
{ name: 'orange', value: '#FB8118' },
Expand Down
1 change: 0 additions & 1 deletion code/addons/controls/template/stories/basics.stories.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
import globalThis from 'global';
import type { PartialStoryFn, StoryContext } from '@storybook/types';

export default {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
import globalThis from 'global';
import type { PartialStoryFn, StoryContext } from '@storybook/types';

export default {
Expand Down
1 change: 0 additions & 1 deletion code/addons/controls/template/stories/disable.stories.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
import globalThis from 'global';
import type { PartialStoryFn, StoryContext } from '@storybook/types';

export default {
Expand Down
1 change: 0 additions & 1 deletion code/addons/controls/template/stories/filters.stories.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
import globalThis from 'global';
import type { PartialStoryFn, StoryContext } from '@storybook/types';

export default {
Expand Down
1 change: 0 additions & 1 deletion code/addons/controls/template/stories/issues.stories.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
import globalThis from 'global';
import type { PartialStoryFn, StoryContext } from '@storybook/types';

export default {
Expand Down
1 change: 0 additions & 1 deletion code/addons/controls/template/stories/matchers.stories.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
import globalThis from 'global';
import type { PartialStoryFn, StoryContext } from '@storybook/types';

export default {
Expand Down
1 change: 0 additions & 1 deletion code/addons/controls/template/stories/sorting.stories.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
import globalThis from 'global';
import type { PartialStoryFn, StoryContext } from '@storybook/types';

export default {
Expand Down
1 change: 0 additions & 1 deletion code/addons/docs/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down
1 change: 0 additions & 1 deletion code/addons/docs/src/typings.d.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
declare module 'global';
declare module '@egoist/vue-to-react';
declare module 'remark-slug';
declare module 'remark-external-links';
Expand Down
2 changes: 0 additions & 2 deletions code/addons/docs/template/stories/docs2/button.stories.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
import globalThis from 'global';

export default {
component: globalThis.Components.Button,
args: { onClick: () => console.log('clicked!') },
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
import globalThis from 'global';
import { expect } from '@storybook/jest';
import { within } from '@storybook/testing-library';

Expand Down
2 changes: 0 additions & 2 deletions code/addons/docs/template/stories/docspage/basic.stories.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
import globalThis from 'global';

export default {
component: globalThis.Components.Button,
tags: ['docsPage'],
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
import globalThis from 'global';

export default {
component: globalThis.Components.Button,
// FIXME: remove array subcomponents in 7.0?
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
import globalThis from 'global';

export default {
component: globalThis.Components.Button,
tags: ['docsPage'],
Expand Down
2 changes: 0 additions & 2 deletions code/addons/docs/template/stories/docspage/iframe.stories.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
import globalThis from 'global';

export default {
component: globalThis.Components.Button,
tags: ['docsPage'],
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
import globalThis from 'global';

export default {
component: globalThis.Components.Pre,
tags: ['docsPage'],
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
import globalThis from 'global';

// FIXME: do this using basic React functions for multi-framework
// once sandbox linking is working
//
Expand Down
2 changes: 0 additions & 2 deletions code/addons/docs/template/stories/docspage/source.stories.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
import globalThis from 'global';

export default {
component: globalThis.Components.Button,
tags: ['docsPage'],
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
import { Meta, Story, Canvas, ArgsTable } from '@storybook/addon-docs';
import globalThis from 'global';

<Meta component={globalThis.Components.Button} />

Expand Down
Original file line number Diff line number Diff line change
@@ -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';

<Meta component={globalThis.Components.Button} />
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
import { Meta, Story, Canvas, ArgsTable } from '@storybook/addon-docs';
import globalThis from 'global';

<Meta component={globalThis.Components.Button} />

Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
import { Meta, Story, Canvas, ArgsTable } from '@storybook/addon-docs';
import globalThis from 'global';

<Meta component={globalThis.Components.Button} play={() => console.log('component play')} />

Expand Down
3 changes: 1 addition & 2 deletions code/addons/highlight/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down
3 changes: 1 addition & 2 deletions code/addons/highlight/src/preview.ts
Original file line number Diff line number Diff line change
@@ -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';

Expand Down
1 change: 0 additions & 1 deletion code/addons/highlight/src/typings.d.ts

This file was deleted.

1 change: 0 additions & 1 deletion code/addons/interactions/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down
7 changes: 3 additions & 4 deletions code/addons/interactions/src/Panel.tsx
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
import global from 'global';
import * as React from 'react';
import { useChannel, useParameter } from '@storybook/manager-api';
import {
Expand Down Expand Up @@ -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);
}
Expand Down
2 changes: 1 addition & 1 deletion code/addons/interactions/src/components/TabStatus.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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);
};

Expand Down
1 change: 0 additions & 1 deletion code/addons/interactions/src/typings.d.ts

This file was deleted.

Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
import globalThis from 'global';
import {
within,
waitFor,
Expand Down
1 change: 0 additions & 1 deletion code/addons/jest/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -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"
},
Expand Down
2 changes: 0 additions & 2 deletions code/addons/jest/src/typings.d.ts

This file was deleted.

1 change: 0 additions & 1 deletion code/addons/links/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -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"
},
Expand Down
1 change: 0 additions & 1 deletion code/addons/links/src/typings.d.ts

This file was deleted.

3 changes: 1 addition & 2 deletions code/addons/links/src/utils.ts
Original file line number Diff line number Diff line change
@@ -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;
Expand Down
1 change: 0 additions & 1 deletion code/addons/links/template/stories/decorator.stories.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
import globalThis from 'global';
import { withLinks } from '@storybook/addon-links';

export default {
Expand Down
1 change: 0 additions & 1 deletion code/addons/links/template/stories/linkto.stories.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
import globalThis from 'global';
import { linkTo } from '@storybook/addon-links';

export default {
Expand Down
1 change: 0 additions & 1 deletion code/addons/links/template/stories/scroll.stories.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
import globalThis from 'global';
import { withLinks } from '@storybook/addon-links';

export default {
Expand Down
3 changes: 1 addition & 2 deletions code/addons/measure/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down
Loading