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: Add a TypeScript check task and configure ci to run it #19471

Merged
merged 3 commits into from
Oct 13, 2022
Merged
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
19 changes: 19 additions & 0 deletions .circleci/config.yml
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,22 @@ commands:
fi

jobs:
check:
executor:
class: xlarge
name: sb_node_14_classic
steps:
- git-shallow-clone/checkout_advanced:
clone_options: '--depth 1 --verbose'
- restore_cache:
name: Restore Yarn cache
keys:
- build-yarn-2-cache-v4--{{ checksum "code/yarn.lock" }}--{{ checksum "scripts/yarn.lock" }}
- run:
name: Compile
command: |
yarn task --task check --start-from=auto --no-link --debug
git diff --exit-code
build:
executor:
class: xlarge
Expand Down Expand Up @@ -410,6 +426,9 @@ workflows:
- lint:
requires:
- build
- check:
requires:
- build
- examples:
requires:
- build
Expand Down
5 changes: 2 additions & 3 deletions code/addons/a11y/src/components/A11YPanel.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -106,7 +106,7 @@ export const A11YPanel: React.FC = () => {
'Rerun tests'
) : (
<>
<Icon inline icon="check" /> Tests completed
<Icon icon="check" /> Tests completed
</>
),
onClick: handleManual,
Expand Down Expand Up @@ -162,8 +162,7 @@ export const A11YPanel: React.FC = () => {
)}
{status === 'running' && (
<Centered>
<RotatingIcon inline icon="sync" /> Please wait while the accessibility scan is running
...
<RotatingIcon icon="sync" /> Please wait while the accessibility scan is running ...
</Centered>
)}
{(status === 'ready' || status === 'ran') && (
Expand Down
6 changes: 5 additions & 1 deletion code/addons/a11y/src/components/VisionSimulator.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,13 @@ import userEvent from '@testing-library/user-event';
import { ThemeProvider, themes, convert } from '@storybook/theming';
import { VisionSimulator, baseList } from './VisionSimulator';

const getOptionByNameAndPercentage = (option: string, percentage: number) =>
const getOptionByNameAndPercentage = (option: string, percentage?: number) =>
screen.getByText(
(content, element) =>
content !== '' &&
// @ts-expect-error (TODO)
element.textContent === option &&
// @ts-expect-error (TODO)
(percentage === undefined || element.nextSibling.textContent === `${percentage}% of users`)
);

Expand Down Expand Up @@ -60,9 +62,11 @@ describe('Vision Simulator', () => {
.filter(({ cssRules }) => cssRules)
.map(({ cssRules }) => Object.values(cssRules))
.flat()
// @ts-expect-error (TODO)
.find((cssRule: CSSRule) => cssRule.selectorText === '#storybook-preview-iframe');

expect(rule).toBeDefined();
// @ts-expect-error (TODO)
expect(rule.style.filter).toBe('blur(2px)');
});
});
4 changes: 2 additions & 2 deletions code/addons/a11y/src/manager.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ describe('A11yManager', () => {
registrationImpl(api as unknown as api.API);
const title = mockedAddons.add.mock.calls
.map(([_, def]) => def)
.find(({ type }) => type === 'panel').title as Function;
.find(({ type }) => type === 'panel')?.title as Function;

// when / then
expect(title()).toBe('Accessibility');
Expand All @@ -47,7 +47,7 @@ describe('A11yManager', () => {
registrationImpl(mockedApi);
const title = mockedAddons.add.mock.calls
.map(([_, def]) => def)
.find(({ type }) => type === 'panel').title as Function;
.find(({ type }) => type === 'panel')?.title as Function;

// when / then
expect(title()).toBe('Accessibility (3)');
Expand Down
11 changes: 2 additions & 9 deletions code/addons/a11y/tsconfig.json
Original file line number Diff line number Diff line change
@@ -1,15 +1,8 @@
{
"extends": "../../tsconfig.json",
"compilerOptions": {
"types": ["jest", "@testing-library/jest-dom"],
"strict": true
},
"include": ["src/**/*"],
"exclude": [
"src/**/*.test.*",
"src/**/tests/**/*",
"src/**/__tests__/**/*",
"src/**/*.stories.*",
"src/**/*.mockdata.*",
"src/**/__testfixtures__/**"
]
"include": ["src/**/*"]
}
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
/* eslint-disable jest/no-standalone-expect */
import React from 'react';
import type { ComponentStoryObj, ComponentMeta } from '@storybook/react';
import type { StoryObj, Meta } from '@storybook/react';
import { CallStates } from '@storybook/instrumenter';
import { styled } from '@storybook/theming';
import { userEvent, within, waitFor } from '@storybook/testing-library';
Expand All @@ -25,7 +25,7 @@ const StyledWrapper = styled.div(({ theme }) => ({

const interactions = getInteractions(CallStates.DONE);

export default {
const meta = {
title: 'Addons/Interactions/InteractionsPanel',
component: InteractionsPanel,
decorators: [
Expand All @@ -52,9 +52,11 @@ export default {
// prop for the AddonPanel used as wrapper of Panel
active: true,
},
} as ComponentMeta<typeof InteractionsPanel>;
} as Meta<typeof InteractionsPanel>;

type Story = ComponentStoryObj<typeof InteractionsPanel>;
export default meta;

type Story = StoryObj<typeof meta>;

export const Passing: Story = {
args: {
Expand Down
8 changes: 7 additions & 1 deletion code/addons/interactions/src/mocks/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -139,4 +139,10 @@ export const getCalls = (finalStatus: CallStates) => {
export const getInteractions = (finalStatus: CallStates) =>
getCalls(finalStatus)
.filter((call) => call.interceptable)
.map((call) => ({ ...call, childCallIds: [], isCollapsed: false, toggleCollapsed: () => {} }));
.map((call) => ({
...call,
childCallIds: [],
isCollapsed: false,
isHidden: false,
toggleCollapsed: () => {},
}));
2 changes: 1 addition & 1 deletion code/frameworks/react-vite/src/plugins/react-docgen.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import {
resolver as docgenResolver,
importers as docgenImporters,
} from 'react-docgen';
import type { DocumentationObject } from 'react-docgen/lib/Documentation';
import type { DocumentationObject } from 'react-docgen/dist/Documentation';
import MagicString from 'magic-string';
import type { PluginOption } from 'vite';
import actualNameHandler from './docgen-handlers/actualNameHandler';
Expand Down
2 changes: 2 additions & 0 deletions code/frameworks/svelte-vite/src/plugins/csf-plugin.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
// @ts-expect-error (TODO)
import { getNameFromFilename } from '@storybook/addon-svelte-csf/dist/cjs/parser/svelte-stories-loader';
import { readFileSync } from 'fs';
// @ts-expect-error (TODO)
import { extractStories } from '@storybook/addon-svelte-csf/dist/cjs/parser/extract-stories';
import type { Options } from '@sveltejs/vite-plugin-svelte';
import * as svelte from 'svelte/compiler';
Expand Down
1 change: 1 addition & 0 deletions code/frameworks/vue-vite/tsconfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
"extends": "../../tsconfig.json",
"compilerOptions": {
"strict": true,
"skipLibCheck": true,
"resolveJsonModule": true
},
"include": ["src/**/*"],
Expand Down
1 change: 1 addition & 0 deletions code/frameworks/vue-webpack5/tsconfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
"extends": "../../tsconfig.json",
"compilerOptions": {
"strict": true,
"skipLibCheck": true,
"resolveJsonModule": true
},
"include": ["src/**/*"],
Expand Down
1 change: 1 addition & 0 deletions code/frameworks/vue3-vite/tsconfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
"compilerOptions": {
"rootDir": "./src",
"types": ["node"],
"skipLibCheck": true,
"resolveJsonModule": true
},
"include": ["src/**/*"],
Expand Down
1 change: 0 additions & 1 deletion code/lib/cli-sb/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,6 @@
"license": "MIT",
"bin": "./index.js",
"scripts": {
"check": "../../../scripts/node_modules/.bin/tsc --noEmit",
"prep": "node ../../../scripts/prepare.js"
},
"dependencies": {
Expand Down
1 change: 0 additions & 1 deletion code/lib/cli-storybook/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,6 @@
"storybook": "./index.js"
},
"scripts": {
"check": "../../../scripts/node_modules/.bin/tsc --noEmit",
"prep": "node ../../../scripts/prepare.js"
},
"dependencies": {
Expand Down
1 change: 1 addition & 0 deletions code/lib/cli/src/add.ts
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ const postinstallAddon = async (addonName: string, isOfficialAddon: boolean) =>
LEGACY_CONFIGS.forEach((config) => {
try {
const codemod = require.resolve(
// @ts-expect-error (it is broken)
`${getPackageName(addonName, isOfficialAddon)}/postinstall/${config}.js`
);
commandLog(`Running postinstall script for ${addonName}`)();
Expand Down
1 change: 0 additions & 1 deletion code/lib/ui/src/FakeProvider.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,6 @@ export class FakeProvider extends Provider {
addons.loadAddons(api);
}

// @ts-expect-error (Converted from ts-ignore)
getConfig() {
return {};
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -105,6 +105,7 @@ const DismissButtonWrapper = styled(IconButton)(({ theme }) => ({
const DismissNotificationItem: FC<{
onDismiss: () => void;
}> = ({ onDismiss }) => (
// @ts-expect-error (we need to improve the types of IconButton)
<DismissButtonWrapper
title="Dismiss notification"
onClick={(e: SyntheticEvent) => {
Expand Down
1 change: 1 addition & 0 deletions code/lib/ui/src/components/sidebar/Brand.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ export const LogoLink = styled.a(({ theme }) => ({
},
}));

// @ts-expect-error (TODO)
export const Brand = withTheme(({ theme }) => {
const { title = 'Storybook', url = './', image, target } = theme.brand;
const targetValue = target || (url === './' ? '' : '_blank');
Expand Down
1 change: 1 addition & 0 deletions code/lib/ui/src/components/sidebar/Search.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -351,6 +351,7 @@ export const Search = React.memo<{
className="search-field"
>
<SearchIcon icon="search" />
{/* @ts-expect-error (TODO) */}
<Input {...inputProps} />
{enableShortcuts && <FocusKey>/</FocusKey>}
<ClearIcon icon="cross" onClick={() => clearSelection()} />
Expand Down
3 changes: 3 additions & 0 deletions code/lib/ui/src/components/sidebar/SearchResults.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -128,6 +128,7 @@ const Result: FC<
if (api && props.isHighlighted && item.isComponent) {
api.emit(
PRELOAD_ENTRIES,
// @ts-expect-error (TODO)
{ ids: [item.isLeaf ? item.id : item.children[0]] },
{ options: { target: item.refId } }
);
Expand Down Expand Up @@ -162,6 +163,7 @@ const Result: FC<
} else if (item.type === 'story') {
node = <StoryNode href={getLink(item, item.refId)} {...nodeProps} />;
} else {
// @ts-expect-error (TODO)
node = <DocumentNode href={getLink(item, item.refId)} {...nodeProps} />;
}

Expand Down Expand Up @@ -212,6 +214,7 @@ export const SearchResults: FC<{

if (item.isComponent) {
api.emit(PRELOAD_ENTRIES, {
// @ts-expect-error (TODO)
ids: [item.isLeaf ? item.id : item.children[0]],
options: { target: refId },
});
Expand Down
1 change: 1 addition & 0 deletions code/lib/ui/src/components/sidebar/Tree.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -419,6 +419,7 @@ export const Tree = React.memo<{
const descendants = expandableDescendants[item.id];
const isFullyExpanded = descendants.every((d: string) => expanded[d]);
return (
// @ts-expect-error (TODO)
<Root
key={id}
item={item}
Expand Down
1 change: 1 addition & 0 deletions code/lib/ui/src/components/sidebar/TreeNode.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,7 @@ const TypeIcon = styled(Icons)<{ docsMode?: boolean }>(
flex: '0 0 auto',
},

// @ts-expect-error (TODO)
({ theme, icon, symbol = icon, docsMode }) => {
const colors = theme.base === 'dark' ? iconColors.dark : iconColors.light;
const colorKey = docsMode && symbol === 'document' ? 'docsModeDocument' : symbol;
Expand Down
1 change: 1 addition & 0 deletions code/lib/ui/src/components/sidebar/mockdata.large.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@

import { Dataset } from './types';

// @ts-expect-error (TODO)
export const stories = {
images: {
name: 'Images',
Expand Down
2 changes: 1 addition & 1 deletion code/lib/ui/src/components/sidebar/mockdata.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import type { StoriesHash } from '@storybook/api';

export type MockDataSet = Record<string, StoriesHash>;
export type MockDataSet = Record<string, Record<string, Partial<StoriesHash[0]>>>;

export const mockDataset: MockDataSet = {
withRoot: {
Expand Down
1 change: 1 addition & 0 deletions code/lib/ui/src/components/sidebar/useHighlighted.ts
Original file line number Diff line number Diff line change
Expand Up @@ -118,6 +118,7 @@ export const useHighlighted = ({
const item = api.getData(itemId, refId === 'storybook_internal' ? undefined : refId);
if (item.isComponent) {
api.emit(PRELOAD_ENTRIES, {
// @ts-expect-error (TODO)
ids: [item.isLeaf ? item.id : item.children[0]],
options: { target: refId },
});
Expand Down
1 change: 1 addition & 0 deletions code/renderers/react/tsconfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
"extends": "../../tsconfig.json",
"compilerOptions": {
"strict": true,
"skipLibCheck": true,
"resolveJsonModule": true
},
"include": ["src/**/*"],
Expand Down
1 change: 1 addition & 0 deletions code/renderers/vue/tsconfig.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
{
"extends": "../../tsconfig.json",
"compilerOptions": {
"skipLibCheck": true,
"resolveJsonModule": true
},
"include": ["src/**/*"],
Expand Down
4 changes: 3 additions & 1 deletion scripts/task.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ import { dedent } from 'ts-dedent';
import { createOptions, getCommand, getOptionsOrPrompt, OptionValues } from './utils/options';
import { install } from './tasks/install';
import { compile } from './tasks/compile';
import { check } from './tasks/check';
import { publish } from './tasks/publish';
import { runRegistryTask } from './tasks/run-registry';
import { sandbox } from './tasks/sandbox';
Expand Down Expand Up @@ -82,6 +83,7 @@ export const tasks = {
// individual template/sandbox
install,
compile,
check,
publish,
'run-registry': runRegistryTask,
// These tasks pertain to a single sandbox in the ../sandboxes dir
Expand All @@ -97,7 +99,7 @@ export const tasks = {
type TaskKey = keyof typeof tasks;

function isSandboxTask(taskKey: TaskKey) {
return !['install', 'compile', 'publish', 'run-registry'].includes(taskKey);
return !['install', 'compile', 'publish', 'run-registry', 'check'].includes(taskKey);
}

export const options = createOptions({
Expand Down
24 changes: 24 additions & 0 deletions scripts/tasks/check.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
import { exec } from '../utils/exec';
import type { Task } from '../task';

const command = `nx run-many --target="check" --all --parallel --exclude=@storybook/addon-storyshots,@storybook/addon-storyshots-puppeteer`;

export const check: Task = {
description: 'Compile the source code of the monorepo',
dependsOn: ['compile'],
async ready() {
return false;
},
async run({ codeDir }, { dryRun, debug }) {
return exec(
command,
{ cwd: codeDir },
{
startMessage: '🥾 Checking types validity',
errorMessage: '❌ Unsound types detected',
dryRun,
debug,
}
);
},
};