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

Tech: improve global types #20184

Merged
merged 40 commits into from
Dec 20, 2022
Merged
Show file tree
Hide file tree
Changes from 32 commits
Commits
Show all changes
40 commits
Select commit Hold shift + click to select a range
1925182
some fixes, need more work
ndelangen Dec 1, 2022
f8d5551
try to make builder-manager prefer mjs, for tree-shaking
ndelangen Dec 2, 2022
b6f3d29
trying to debug the vite-builder problem
ndelangen Dec 2, 2022
db36af9
unsupported temp api that's not supposed to be there, doesn't need types
ndelangen Dec 2, 2022
18d3b8d
Merge branch 'next' into fix/storystorev6-vite
ndelangen Dec 5, 2022
501dce1
strong typing for globals, fix issues resulting from strong global ty…
ndelangen Dec 9, 2022
42bf76e
add "dom.iterable" and use global as window
ndelangen Dec 9, 2022
3659bab
fix all the global typings
ndelangen Dec 9, 2022
e5b6648
fix start test
ndelangen Dec 9, 2022
f526092
fixing typings issues
ndelangen Dec 9, 2022
a94e7e8
fixing tests
ndelangen Dec 9, 2022
5be6d25
fixes
ndelangen Dec 9, 2022
141dec1
add new storybook scoped package to verdaccio config
ndelangen Dec 9, 2022
3342776
fix references to global in template dirs
ndelangen Dec 9, 2022
43aca90
fixes
ndelangen Dec 9, 2022
d9f736a
cleanup
ndelangen Dec 9, 2022
5653ec8
Merge branch 'next' into norbert/sb-1063-vite-in-dev-mode-with-storys…
ndelangen Dec 12, 2022
3eb16e7
Merge branch 'fix/storystorev6-vite' into norbert/sb-1063-vite-in-dev…
ndelangen Dec 12, 2022
556e9e2
Merge branch 'next' into norbert/sb-1063-vite-in-dev-mode-with-storys…
ndelangen Dec 12, 2022
b041209
simplify globals
ndelangen Dec 12, 2022
0761c15
fix
ndelangen Dec 12, 2022
c1a62a2
fix
ndelangen Dec 12, 2022
1263ac8
ensure singleton via global
ndelangen Dec 12, 2022
a7c357a
reset the global every time, to get a new version
ndelangen Dec 12, 2022
b052066
Merge branch 'norbert/sb-1063-vite-in-dev-mode-with-storystorev6-clea…
ndelangen Dec 12, 2022
b0977b8
remove the window as global definition
ndelangen Dec 13, 2022
fe9b5d6
Merge branch 'next' into norbert/sb-1063-vite-in-dev-mode-with-storys…
ndelangen Dec 13, 2022
91fe4d8
Merge branch 'next' into norbert/sb-1063-vite-in-dev-mode-with-storys…
ndelangen Dec 13, 2022
6a578c8
Merge branch 'next' into norbert/sb-1063-vite-in-dev-mode-with-storys…
ndelangen Dec 13, 2022
19f3ceb
fix
ndelangen Dec 13, 2022
adb0d25
Merge branch 'norbert/sb-1063-vite-in-dev-mode-with-storystorev6-clea…
ndelangen Dec 13, 2022
4f3b666
cleanup
ndelangen Dec 13, 2022
a088aa4
use feature detection
ndelangen Dec 13, 2022
a033d29
Merge branch 'next' into norbert/sb-1063-vite-in-dev-mode-with-storys…
ndelangen Dec 13, 2022
d7fb0c3
Merge branch 'next' into norbert/sb-1063-vite-in-dev-mode-with-storys…
ndelangen Dec 14, 2022
9da5823
Merge branch 'next' into norbert/sb-1063-vite-in-dev-mode-with-storys…
ndelangen Dec 15, 2022
7c2ccbb
Merge branch 'next' into norbert/sb-1063-vite-in-dev-mode-with-storys…
ndelangen Dec 15, 2022
88f5931
Merge branch 'next' into norbert/sb-1063-vite-in-dev-mode-with-storys…
ndelangen Dec 20, 2022
fc357d7
Restore code/lib/builder-webpack5/templates/virtualModuleModernEntry.…
ndelangen Dec 20, 2022
bb2e680
change to use @storybook/global in modern entry
ndelangen Dec 20, 2022
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
The table of contents is too big for display.
Diff view
Diff view
  •  
  •  
  •  
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
/* global window */
/* eslint-disable global-require, import/no-dynamic-require */

import React from 'react';
Expand Down
1 change: 0 additions & 1 deletion code/__mocks__/inject-decorator.ugly-comments-stories.txt
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
/* global window */
/* eslint-disable global-require, import/no-dynamic-require */

import React from 'react';
Expand Down
2 changes: 1 addition & 1 deletion code/addons/a11y/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -67,12 +67,12 @@
"@storybook/client-logger": "7.0.0-beta.4",
"@storybook/components": "7.0.0-beta.4",
"@storybook/core-events": "7.0.0-beta.4",
"@storybook/global": "^5.0.0",
"@storybook/manager-api": "7.0.0-beta.4",
"@storybook/preview-api": "7.0.0-beta.4",
"@storybook/theming": "7.0.0-beta.4",
"@storybook/types": "7.0.0-beta.4",
"axe-core": "^4.2.0",
"global": "^4.4.0",
"lodash": "^4.17.21",
"react-sizeme": "^3.0.1"
},
Expand Down
9 changes: 7 additions & 2 deletions code/addons/a11y/src/a11yRunner.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import global from 'global';
import { global } from '@storybook/global';
import { addons } from '@storybook/preview-api';
import { EVENTS } from './constants';
import type { A11yParameters } from './params';
Expand Down Expand Up @@ -37,7 +37,12 @@ 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);

if (!htmlElement) {
return;
}

axe.reset();
if (config) {
axe.configure(config);
Expand Down
3 changes: 2 additions & 1 deletion code/addons/a11y/src/typings.d.ts
Original file line number Diff line number Diff line change
@@ -1 +1,2 @@
declare module 'global';
/* eslint-disable @typescript-eslint/naming-convention */
declare var __STORYBOOK_STORY_STORE__: any;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Shouldn't this be something like StoryStore<Renderer>?

In my PR to remove the global dependency, I took a crack at defining the types for storybook globals here: https://github.com/storybookjs/storybook/pull/19386/files#diff-c945b52732b89295a5b35f8ed082c713dd8002a29420b607bfc382672e203fe0R28

Maybe you're planning to deal with these types in a separate PR, which would probably make sense since this is already a large PR.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah it should be. considering this is in an addon, I didn't want to pull in, types from 'far away' packages. The PR is complex as is, and this seemed to me like a good candidate for a follow-up

2 changes: 1 addition & 1 deletion code/addons/a11y/template/stories/parameters.stories.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import globalThis from 'global';
import { global as globalThis } from '@storybook/global';

export default {
component: globalThis.Components.Html,
Expand Down
2 changes: 1 addition & 1 deletion code/addons/a11y/template/stories/tests.stories.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import globalThis from 'global';
import { global as globalThis } from '@storybook/global';

export default {
component: globalThis.Components.Html,
Expand Down
2 changes: 1 addition & 1 deletion code/addons/actions/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -79,12 +79,12 @@
"@storybook/client-logger": "7.0.0-beta.4",
"@storybook/components": "7.0.0-beta.4",
"@storybook/core-events": "7.0.0-beta.4",
"@storybook/global": "^5.0.0",
"@storybook/manager-api": "7.0.0-beta.4",
"@storybook/preview-api": "7.0.0-beta.4",
"@storybook/theming": "7.0.0-beta.4",
"@storybook/types": "7.0.0-beta.4",
"dequal": "^2.0.2",
"global": "^4.4.0",
"lodash": "^4.17.21",
"polished": "^4.2.2",
"prop-types": "^15.7.2",
Expand Down
2 changes: 1 addition & 1 deletion code/addons/actions/src/decorator.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import global from 'global';
import { global } from '@storybook/global';
import { useEffect, makeDecorator } from '@storybook/preview-api';
import { actions } from './runtime/actions';

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: 1 addition & 1 deletion code/addons/actions/template/stories/argtype.stories.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import globalThis from 'global';
import { global as globalThis } from '@storybook/global';

export default {
component: globalThis.Components.Button,
Expand Down
2 changes: 1 addition & 1 deletion code/addons/actions/template/stories/basics.stories.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import globalThis from 'global';
import { global as globalThis } from '@storybook/global';

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

Expand Down
2 changes: 1 addition & 1 deletion code/addons/actions/template/stories/configs.stories.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import globalThis from 'global';
import { global as globalThis } from '@storybook/global';

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

Expand Down
2 changes: 1 addition & 1 deletion code/addons/actions/template/stories/parameters.stories.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import globalThis from 'global';
import { global as globalThis } from '@storybook/global';
import { withActions } from '@storybook/addon-actions/decorator';

export default {
Expand Down
2 changes: 1 addition & 1 deletion code/addons/backgrounds/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -78,11 +78,11 @@
"@storybook/client-logger": "7.0.0-beta.4",
"@storybook/components": "7.0.0-beta.4",
"@storybook/core-events": "7.0.0-beta.4",
"@storybook/global": "^5.0.0",
"@storybook/manager-api": "7.0.0-beta.4",
"@storybook/preview-api": "7.0.0-beta.4",
"@storybook/theming": "7.0.0-beta.4",
"@storybook/types": "7.0.0-beta.4",
"global": "^4.4.0",
"memoizerific": "^1.11.3",
"ts-dedent": "^2.0.0"
},
Expand Down
2 changes: 1 addition & 1 deletion code/addons/backgrounds/src/helpers/index.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import global from 'global';
import { global } from '@storybook/global';
import { dedent } from 'ts-dedent';

import { logger } from '@storybook/client-logger';
Expand Down
1 change: 0 additions & 1 deletion code/addons/backgrounds/src/typings.d.ts

This file was deleted.

2 changes: 1 addition & 1 deletion code/addons/backgrounds/template/stories/grid.stories.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import globalThis from 'global';
import { global as globalThis } from '@storybook/global';

export default {
component: globalThis.Components.Button,
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import globalThis from 'global';
import { global as globalThis } from '@storybook/global';

const COLORS = [
{ name: 'red', value: '#FB001D' },
Expand Down
1 change: 0 additions & 1 deletion code/addons/controls/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,6 @@
"@storybook/core-common": "7.0.0-beta.4",
"@storybook/manager-api": "7.0.0-beta.4",
"@storybook/node-logger": "7.0.0-beta.4",
"@storybook/preview-api": "7.0.0-beta.4",
"@storybook/theming": "7.0.0-beta.4",
"@storybook/types": "7.0.0-beta.4",
"lodash": "^4.17.21",
Expand Down
2 changes: 1 addition & 1 deletion code/addons/controls/template/stories/basics.stories.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import globalThis from 'global';
import { global as globalThis } from '@storybook/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,4 @@
import globalThis from 'global';
import { global as globalThis } from '@storybook/global';
import type { PartialStoryFn, StoryContext } from '@storybook/types';

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

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

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

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

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

export default {
Expand Down
4 changes: 2 additions & 2 deletions code/addons/docs/angular/index.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
/* eslint-disable no-underscore-dangle */
/* global window */
import { global } from '@storybook/global';

export const setCompodocJson = (compodocJson) => {
// @ts-expect-error (Converted from ts-ignore)
window.__STORYBOOK_COMPODOC_JSON__ = compodocJson;
global.__STORYBOOK_COMPODOC_JSON__ = compodocJson;
};
4 changes: 2 additions & 2 deletions code/addons/docs/ember/index.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
/* eslint-disable no-underscore-dangle */
/* global window */
import { global } from '@storybook/global';

export const setJSONDoc = (jsondoc) => {
window.__EMBER_GENERATED_DOC_JSON__ = jsondoc;
global.__EMBER_GENERATED_DOC_JSON__ = jsondoc;
};
2 changes: 1 addition & 1 deletion code/addons/docs/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -103,14 +103,14 @@
"@storybook/components": "7.0.0-beta.4",
"@storybook/csf-plugin": "7.0.0-beta.4",
"@storybook/csf-tools": "7.0.0-beta.4",
"@storybook/global": "^5.0.0",
"@storybook/mdx2-csf": "next",
"@storybook/node-logger": "7.0.0-beta.4",
"@storybook/postinstall": "7.0.0-beta.4",
"@storybook/preview-api": "7.0.0-beta.4",
"@storybook/theming": "7.0.0-beta.4",
"@storybook/types": "7.0.0-beta.4",
"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: 1 addition & 1 deletion code/addons/docs/template/stories/docs2/button.stories.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import globalThis from 'global';
import { global as globalThis } from '@storybook/global';

export default {
component: globalThis.Components.Button,
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import globalThis from 'global';
import { global as globalThis } from '@storybook/global';
import { expect } from '@storybook/jest';
import { within } from '@storybook/testing-library';

Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import globalThis from 'global';
import { global as globalThis } from '@storybook/global';

export default {
component: globalThis.Components.Button,
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import globalThis from 'global';
import { global as globalThis } from '@storybook/global';

export default {
component: globalThis.Components.Button,
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import globalThis from 'global';
import { global as globalThis } from '@storybook/global';

export default {
component: globalThis.Components.Button,
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import globalThis from 'global';
import { global as globalThis } from '@storybook/global';

export default {
component: globalThis.Components.Button,
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import globalThis from 'global';
import { global as globalThis } from '@storybook/global';

export default {
component: globalThis.Components.Pre,
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import globalThis from 'global';
import { global as globalThis } from '@storybook/global';

// FIXME: do this using basic React functions for multi-framework
// once sandbox linking is working
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import globalThis from 'global';
import { global as globalThis } from '@storybook/global';

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

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

Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { Meta, Story, Canvas, ArgsTable } from '@storybook/addon-docs';
import globalThis from 'global';
import { global as globalThis } from '@storybook/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,5 @@
import { Meta, Story, Canvas, ArgsTable } from '@storybook/addon-docs';
import globalThis from 'global';
import { global as globalThis } from '@storybook/global';

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

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

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

Expand Down
4 changes: 2 additions & 2 deletions code/addons/highlight/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -61,8 +61,8 @@
},
"dependencies": {
"@storybook/core-events": "7.0.0-beta.4",
"@storybook/preview-api": "7.0.0-beta.4",
"global": "^4.4.0"
"@storybook/global": "^5.0.0",
"@storybook/preview-api": "7.0.0-beta.4"
},
"devDependencies": {
"@types/webpack-env": "^1.16.0",
Expand Down
2 changes: 1 addition & 1 deletion code/addons/highlight/src/preview.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/* eslint-env browser */
import global from 'global';
import { global } from '@storybook/global';
import { addons } from '@storybook/preview-api';
import { STORY_CHANGED } from '@storybook/core-events';
import { HIGHLIGHT, RESET_HIGHLIGHT, HIGHLIGHT_STYLE_ID } from './constants';
Expand Down
1 change: 0 additions & 1 deletion code/addons/highlight/src/typings.d.ts

This file was deleted.

2 changes: 1 addition & 1 deletion code/addons/interactions/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -75,12 +75,12 @@
"@storybook/components": "7.0.0-beta.4",
"@storybook/core-common": "7.0.0-beta.4",
"@storybook/core-events": "7.0.0-beta.4",
"@storybook/global": "^5.0.0",
"@storybook/instrumenter": "7.0.0-beta.4",
"@storybook/manager-api": "7.0.0-beta.4",
"@storybook/preview-api": "7.0.0-beta.4",
"@storybook/theming": "7.0.0-beta.4",
"@storybook/types": "7.0.0-beta.4",
"global": "^4.4.0",
"jest-mock": "^27.0.6",
"polished": "^4.2.2",
"ts-dedent": "^2.2.0"
Expand Down
8 changes: 4 additions & 4 deletions code/addons/interactions/src/Panel.tsx
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import global from 'global';
import { global } from '@storybook/global';
import * as React from 'react';
import { useChannel, useParameter } from '@storybook/manager-api';
import {
Expand Down Expand Up @@ -102,10 +102,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 (global.IntersectionObserver) {
observer = new global.IntersectionObserver(
([end]: any) => setScrollTarget(end.isIntersecting ? undefined : end.target),
{ root: global.window.document.querySelector('#panel-tab-content') }
{ root: global.document.querySelector('#panel-tab-content') }
);
if (endRef.current) observer.observe(endRef.current);
}
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,4 @@
import globalThis from 'global';
import { global as globalThis } from '@storybook/global';
import {
within,
waitFor,
Expand Down
2 changes: 1 addition & 1 deletion code/addons/jest/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -72,10 +72,10 @@
"@storybook/client-logger": "7.0.0-beta.4",
"@storybook/components": "7.0.0-beta.4",
"@storybook/core-events": "7.0.0-beta.4",
"@storybook/global": "^5.0.0",
"@storybook/manager-api": "7.0.0-beta.4",
"@storybook/preview-api": "7.0.0-beta.4",
"@storybook/theming": "7.0.0-beta.4",
"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.

Loading