From 9d2f1fcf1bb4c9d9c56b7f0566f34edffe910e21 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Kai=20R=C3=B6der?= Date: Mon, 17 Dec 2018 14:37:12 +0100 Subject: [PATCH 01/30] WIP working on migration for @storybook/addons --- lib/addons/package.json | 5 +- lib/addons/src/index.js | 88 ------------------- lib/addons/src/index.ts | 82 +++++++++++++++++ ...corator.test.js => make-decorator.test.ts} | 0 .../{make-decorator.js => make-decorator.ts} | 26 ++++-- ...nnel-mock.js => storybook-channel-mock.ts} | 0 lib/addons/src/typings.d.ts | 1 + lib/addons/tsconfig.json | 14 +++ tsconfig.json | 4 +- yarn.lock | 7 +- 10 files changed, 128 insertions(+), 99 deletions(-) delete mode 100644 lib/addons/src/index.js create mode 100644 lib/addons/src/index.ts rename lib/addons/src/{make-decorator.test.js => make-decorator.test.ts} (100%) rename lib/addons/src/{make-decorator.js => make-decorator.ts} (70%) rename lib/addons/src/{storybook-channel-mock.js => storybook-channel-mock.ts} (100%) create mode 100644 lib/addons/src/typings.d.ts create mode 100644 lib/addons/tsconfig.json diff --git a/lib/addons/package.json b/lib/addons/package.json index cbdd6ae220b6..11883fe40c54 100644 --- a/lib/addons/package.json +++ b/lib/addons/package.json @@ -15,7 +15,6 @@ }, "license": "MIT", "main": "dist/index.js", - "jsnext:main": "src/index.js", "scripts": { "prepare": "node ../../scripts/prepare.js" }, @@ -25,6 +24,10 @@ "global": "^4.3.2", "util-deprecate": "^1.0.2" }, + "devDependencies": { + "@types/util-deprecate": "^1.0.0", + "@types/react": "^16.7.17y" + }, "publishConfig": { "access": "public" } diff --git a/lib/addons/src/index.js b/lib/addons/src/index.js deleted file mode 100644 index bee676ea0f2a..000000000000 --- a/lib/addons/src/index.js +++ /dev/null @@ -1,88 +0,0 @@ -// Resolves to window in browser and to global in node -import global from 'global'; -// import { TabWrapper } from '@storybook/components'; - -export mockChannel from './storybook-channel-mock'; -export { makeDecorator } from './make-decorator'; - -export class AddonStore { - constructor() { - this.loaders = {}; - this.panels = {}; - this.channel = null; - this.preview = null; - this.database = null; - } - - getChannel() { - // this.channel should get overwritten by setChannel. If it wasn't called (e.g. in non-browser environment), throw. - if (!this.channel) { - throw new Error( - 'Accessing nonexistent addons channel, see https://storybook.js.org/basics/faq/#why-is-there-no-addons-channel' - ); - } - return this.channel; - } - - hasChannel() { - return Boolean(this.channel); - } - - setChannel(channel) { - this.channel = channel; - } - - getPreview() { - return this.preview; - } - - setPreview(preview) { - this.preview = preview; - } - - getDatabase() { - return this.database; - } - - setDatabase(database) { - this.database = database; - } - - getPanels() { - return this.panels; - } - - addPanel(name, panel) { - // supporting legacy addons, which have not migrated to the active-prop - // const original = panel.render; - // if (original && original.toString() && !original.toString().match(/active/)) { - // this.panels[name] = { - // ...panel, - // render: ({ active }) => TabWrapper({ active, render: original }), - // }; - // } else { - this.panels[name] = panel; - // } - } - - register(name, loader) { - this.loaders[name] = loader; - } - - loadAddons(api) { - Object.keys(this.loaders) - .map(name => this.loaders[name]) - .forEach(loader => loader(api)); - } -} - -// Enforce addons store to be a singleton -const KEY = '__STORYBOOK_ADDONS'; -function getAddonsStore() { - if (!global[KEY]) { - global[KEY] = new AddonStore(); - } - return global[KEY]; -} - -export default getAddonsStore(); diff --git a/lib/addons/src/index.ts b/lib/addons/src/index.ts new file mode 100644 index 000000000000..0e550e2c164a --- /dev/null +++ b/lib/addons/src/index.ts @@ -0,0 +1,82 @@ +// Resolves to window in browser and to global in node +import global from 'global'; +// import { TabWrapper } from '@storybook/components'; +import mockChannel from './storybook-channel-mock'; +import Channel from '@storybook/channels'; +import { ReactElement } from 'react'; + +export { mockChannel }; +export { makeDecorator } from './make-decorator'; + +export interface PanelOptions { + active: boolean; +} + +export interface Panel { + title: string; + + render(options: PanelOptions): ReactElement; +} + +export type Loader = (callback: (api: any) => void) => void; + +interface LoaderKeyValue { + [key: string]: Loader; +} + +interface PanelKeyValue { + [key: string]: Panel; +} + +export class AddonStore { + private loaders: LoaderKeyValue = {}; + private panels: PanelKeyValue = {}; + private channel: Channel | undefined; + + getChannel() { + // this.channel should get overwritten by setChannel. If it wasn't called (e.g. in non-browser environment), throw. + if (!this.channel) { + throw new Error( + 'Accessing nonexistent addons channel, see https://storybook.js.org/basics/faq/#why-is-there-no-addons-channel' + ); + } + + return this.channel; + } + + hasChannel() { + return !!this.channel; + } + + setChannel(channel: Channel) { + this.channel = channel; + } + + getPanels() { + return this.panels; + } + + addPanel(name: string, panel: Panel) { + this.panels[name] = panel; + } + + register(name: string, registerCallback: (api: any) => void) { + this.loaders[name] = registerCallback; + } + + loadAddons(api: any) { + Object.values(this.loaders).forEach(value => value(api)); + } +} + +// Enforce addons store to be a singleton +const KEY = '__STORYBOOK_ADDONS'; + +function getAddonsStore() { + if (!global[KEY]) { + global[KEY] = new AddonStore(); + } + return global[KEY]; +} + +export default getAddonsStore(); diff --git a/lib/addons/src/make-decorator.test.js b/lib/addons/src/make-decorator.test.ts similarity index 100% rename from lib/addons/src/make-decorator.test.js rename to lib/addons/src/make-decorator.test.ts diff --git a/lib/addons/src/make-decorator.js b/lib/addons/src/make-decorator.ts similarity index 70% rename from lib/addons/src/make-decorator.js rename to lib/addons/src/make-decorator.ts index e7df28f726f1..81c4174b6fbf 100644 --- a/lib/addons/src/make-decorator.js +++ b/lib/addons/src/make-decorator.ts @@ -10,14 +10,22 @@ import deprecate from 'util-deprecate'; // *And* in the older, but not deprecated, "pass options to decorator" style: // .addDecorator(decorator(options)) -export const makeDecorator = ({ +interface MakeDecoratorOptions { + name: any; + parameterName: any; + wrapper: any; + skipIfNoParametersOrOptions: boolean; + allowDeprecatedUsage: boolean; +} + +export const makeDecorator: any = ({ name, parameterName, wrapper, skipIfNoParametersOrOptions = false, allowDeprecatedUsage = false, -}) => { - const decorator = options => (getStory, context) => { +}: MakeDecoratorOptions) => { + const decorator: any = (options: any) => (getStory: any, context: any) => { const parameters = context.parameters && context.parameters[parameterName]; if (parameters && parameters.disable) { @@ -33,13 +41,13 @@ export const makeDecorator = ({ }); }; - return (...args) => { + return (...args: any) => { // Used without options as .addDecorator(decorator) if (typeof args[0] === 'function') { return decorator()(...args); } - return (...innerArgs) => { + return (...innerArgs: any): any => { // Used as [.]addDecorator(decorator(options)) if (innerArgs.length > 1) { return decorator(...args)(...innerArgs); @@ -49,13 +57,15 @@ export const makeDecorator = ({ // Used to wrap a story directly .add('story', decorator(options)(() => )) // This is now deprecated: return deprecate( - context => decorator(...args)(innerArgs[0], context), - `Passing stories directly into ${name}() is deprecated, instead use addDecorator(${name}) and pass options with the '${parameterName}' parameter` + (context: any) => decorator(...args)(innerArgs[0], context), + `Passing stories directly into ${name}() is deprecated, + instead use addDecorator(${name}) and pass options with the '${parameterName}' parameter` ); } throw new Error( - `Passing stories directly into ${name}() is not allowed, instead use addDecorator(${name}) and pass options with the '${parameterName}' parameter` + `Passing stories directly into ${name}() is not allowed, + instead use addDecorator(${name}) and pass options with the '${parameterName}' parameter` ); }; }; diff --git a/lib/addons/src/storybook-channel-mock.js b/lib/addons/src/storybook-channel-mock.ts similarity index 100% rename from lib/addons/src/storybook-channel-mock.js rename to lib/addons/src/storybook-channel-mock.ts diff --git a/lib/addons/src/typings.d.ts b/lib/addons/src/typings.d.ts new file mode 100644 index 000000000000..2f4eb9cf4fd9 --- /dev/null +++ b/lib/addons/src/typings.d.ts @@ -0,0 +1 @@ +declare module 'global'; diff --git a/lib/addons/tsconfig.json b/lib/addons/tsconfig.json new file mode 100644 index 000000000000..81d74f99bec2 --- /dev/null +++ b/lib/addons/tsconfig.json @@ -0,0 +1,14 @@ +{ + "extends": "../../tsconfig.json", + "compilerOptions": { + "rootDir": "./src", + "strict": true + }, + "include": [ + "src/**/*.ts", + "src/**/*.tsx" + ], + "exclude": [ + "src/index.test.ts" + ] +} diff --git a/tsconfig.json b/tsconfig.json index 55ea5bb93317..c2e1fbdc8a35 100644 --- a/tsconfig.json +++ b/tsconfig.json @@ -9,13 +9,15 @@ "noImplicitAny": true, "jsx": "react", "module": "commonjs", + "allowSyntheticDefaultImports": true, + "esModuleInterop": true, "target": "es5", "types": [ "node", "jest" ], "lib": [ - "es2016", + "es2017", "dom" ] } diff --git a/yarn.lock b/yarn.lock index 0349d52c8150..63ad18f67d3c 100644 --- a/yarn.lock +++ b/yarn.lock @@ -2275,7 +2275,7 @@ resolved "https://registry.yarnpkg.com/@types/q/-/q-1.5.1.tgz#48fd98c1561fe718b61733daed46ff115b496e18" integrity sha512-eqz8c/0kwNi/OEHQfvIuJVLTst3in0e7uTKeuY+WL/zfKn0xVujOTp42bS/vUUokhK5P2BppLd9JXMOMHcgbjA== -"@types/react@^16.7.3": +"@types/react@^16.7.17y", "@types/react@^16.7.3": version "16.7.17" resolved "https://registry.yarnpkg.com/@types/react/-/react-16.7.17.tgz#3242e796a1ffbba4f49eae5915a67f4c079504e9" integrity sha512-YcXcaoXaxo7A76mBCGlKlN2aZu3REQfF0DTrhiyXVJLA7PDdxVCr+wiQOrkVNn44D/zLlIyDSn3U918Ve0AaEA== @@ -2298,6 +2298,11 @@ resolved "https://registry.yarnpkg.com/@types/unist/-/unist-2.0.2.tgz#5dc0a7f76809b7518c0df58689cd16a19bd751c6" integrity sha512-iHI60IbyfQilNubmxsq4zqSjdynlmc2Q/QvH9kjzg9+CCYVVzq1O6tc7VBzSygIwnmOt07w80IG6HDQvjv3Liw== +"@types/util-deprecate@^1.0.0": + version "1.0.0" + resolved "https://registry.yarnpkg.com/@types/util-deprecate/-/util-deprecate-1.0.0.tgz#341d0815fe5a661b94e3ea738d182b4c359e3958" + integrity sha512-I2vixiQ+mrmKxfdLNvaa766nulrMVDoUQiSQoNeTjFUNAt8klnMgDh3yy/bH/r275357q30ACOEUaxFOR8YVrA== + "@types/vfile-message@*": version "1.0.1" resolved "https://registry.yarnpkg.com/@types/vfile-message/-/vfile-message-1.0.1.tgz#e1e9895cc6b36c462d4244e64e6d0b6eaf65355a" From 385782898a84150ac842546d2c4644edf48bfe57 Mon Sep 17 00:00:00 2001 From: igor-dv Date: Mon, 17 Dec 2018 16:53:09 +0200 Subject: [PATCH 02/30] Unfinished things --- .eslintignore | 1 + addons/notes/package.json | 1 + addons/notes/src/index.ts | 47 ++++++++++++++++---------------- addons/notes/src/register.tsx | 22 ++++++--------- addons/notes/src/typings.d.ts | 3 -- lib/addons/src/index.ts | 4 +-- lib/addons/src/make-decorator.ts | 39 ++++++++++++++++---------- 7 files changed, 61 insertions(+), 56 deletions(-) diff --git a/.eslintignore b/.eslintignore index acaec38f0b07..76cb54f8b1ee 100644 --- a/.eslintignore +++ b/.eslintignore @@ -10,6 +10,7 @@ lib/cli/test *.bundle.js *.js.map *.ts +*.tsx !.remarkrc.js !.babelrc.js diff --git a/addons/notes/package.json b/addons/notes/package.json index 4fecb96436d6..41af9fbf9048 100644 --- a/addons/notes/package.json +++ b/addons/notes/package.json @@ -25,6 +25,7 @@ "dependencies": { "@emotion/styled": "^0.10.6", "@storybook/addons": "4.2.0-alpha.2", + "@storybook/channels": "4.2.0-alpha.2", "core-js": "^2.5.7", "marked": "^0.5.2", "prop-types": "^15.6.2" diff --git a/addons/notes/src/index.ts b/addons/notes/src/index.ts index 57749ebb5434..419b73acbf2d 100644 --- a/addons/notes/src/index.ts +++ b/addons/notes/src/index.ts @@ -1,34 +1,35 @@ -import addons, { makeDecorator } from '@storybook/addons'; +import addons, { makeDecorator, StoryContext, StoryGetter, StoryWrapper } from '@storybook/addons'; import { parse as renderMarkdown } from 'marked'; +// function wrapper(getStory: StoryGetter, context: StoryContext, {options, parameters}) { +// const channel = addons.getChannel(); +// +// const storyOptions = parameters || options; +// +// const {text, markdown, markdownOptions} = +// typeof storyOptions === 'string' +// ? { +// text: storyOptions, +// markdown: undefined, +// markdownOptions: undefined, +// } +// : storyOptions; +// +// if (!text && !markdown) { +// throw new Error('You must set of one of `text` or `markdown` on the `notes` parameter'); +// } +// +// channel.emit('storybook/notes/add_notes', text || renderMarkdown(markdown, markdownOptions)); +// +// return getStory(context); +// } + // todo resolve any after @storybook/addons and @storybook/channels are migrated to TypeScript export const withNotes = makeDecorator({ name: 'withNotes', parameterName: 'notes', skipIfNoParametersOrOptions: true, allowDeprecatedUsage: true, - wrapper: (getStory: (context: any) => any, context: any, { options, parameters }: any) => { - const channel = addons.getChannel(); - - const storyOptions = parameters || options; - - const { text, markdown, markdownOptions } = - typeof storyOptions === 'string' - ? { - text: storyOptions, - markdown: undefined, - markdownOptions: undefined, - } - : storyOptions; - - if (!text && !markdown) { - throw new Error('You must set of one of `text` or `markdown` on the `notes` parameter'); - } - - channel.emit('storybook/notes/add_notes', text || renderMarkdown(markdown, markdownOptions)); - - return getStory(context); - }, }); export const withMarkdownNotes = (text: string, options: any) => diff --git a/addons/notes/src/register.tsx b/addons/notes/src/register.tsx index 9b6d15364ce0..04fee67bc6bc 100644 --- a/addons/notes/src/register.tsx +++ b/addons/notes/src/register.tsx @@ -1,16 +1,11 @@ import * as React from 'react'; import addons from '@storybook/addons'; +import Channel from '@storybook/channels'; + import * as PropTypes from 'prop-types'; import styled from '@emotion/styled'; -// todo this is going to be refactored after the migration of @storybook/channel to TypeScript -interface NotesChannel { - emit: any; - on(listener: string, callback: (text: string) => void): any; - removeListener(listener: string, callback: (text: string) => void): void; -} - interface NotesApi { setQueryParams: any; // todo check correct definition getQueryParam(queryParamName: string): any; @@ -20,7 +15,7 @@ interface NotesApi { interface NotesProps { active: boolean; - channel: NotesChannel; + channel: Channel; api: NotesApi; } @@ -35,7 +30,6 @@ const Panel = styled.div({ }); export class Notes extends React.Component { - static propTypes = { active: PropTypes.bool.isRequired, channel: PropTypes.shape({ @@ -91,9 +85,9 @@ export class Notes extends React.Component { const { text } = this.state; const textAfterFormatted = text ? text - .trim() - .replace(/(<\S+.*>)\n/g, '$1') - .replace(/\n/g, '
') + .trim() + .replace(/(<\S+.*>)\n/g, '$1') + .replace(/\n/g, '
') : ''; return active ? ( @@ -109,6 +103,8 @@ addons.register('storybook/notes', (api: any) => { const channel = addons.getChannel(); addons.addPanel('storybook/notes/panel', { title: 'Notes', - render: ({ active }: { active: boolean }) => , + render: ({ active }: { active: boolean }) => ( + + ), }); }); diff --git a/addons/notes/src/typings.d.ts b/addons/notes/src/typings.d.ts index 84ab86f76adc..54a71c2c205c 100644 --- a/addons/notes/src/typings.d.ts +++ b/addons/notes/src/typings.d.ts @@ -1,5 +1,2 @@ -// Fixes 'noImplicitAny' lint error because @storybook/addons isn't migrated to typescript yet -declare module '@storybook/addons'; - // Only necessary for 0.x.x. Version 10.x.x has definition files included declare module '@emotion/styled'; diff --git a/lib/addons/src/index.ts b/lib/addons/src/index.ts index 0e550e2c164a..d0618201654e 100644 --- a/lib/addons/src/index.ts +++ b/lib/addons/src/index.ts @@ -1,12 +1,10 @@ -// Resolves to window in browser and to global in node import global from 'global'; -// import { TabWrapper } from '@storybook/components'; import mockChannel from './storybook-channel-mock'; import Channel from '@storybook/channels'; import { ReactElement } from 'react'; export { mockChannel }; -export { makeDecorator } from './make-decorator'; +export * from './make-decorator'; export interface PanelOptions { active: boolean; diff --git a/lib/addons/src/make-decorator.ts b/lib/addons/src/make-decorator.ts index 81c4174b6fbf..a4c40eb161f4 100644 --- a/lib/addons/src/make-decorator.ts +++ b/lib/addons/src/make-decorator.ts @@ -1,24 +1,34 @@ import deprecate from 'util-deprecate'; -// Create a decorator that can be used both in the (deprecated) old "hoc" style: -// .add('story', decorator(options)(() => )); -// -// And in the new, "parameterized" style: -// .addDecorator(decorator) -// .add('story', () => , { name: { parameters } }); -// -// *And* in the older, but not deprecated, "pass options to decorator" style: -// .addDecorator(decorator(options)) +export interface StoryContext { + story: string; + kind: string; +} + +export interface WrapperSettings { + options: any; + parameters: any; +} + +export type StoryGetter = (context: StoryContext) => any; + +export type StoryWrapper = ( + getStory: StoryGetter, + context: StoryContext, + settings: WrapperSettings +) => any; + +type MakeDecoratorResult = (...args: any) => any; interface MakeDecoratorOptions { - name: any; - parameterName: any; - wrapper: any; - skipIfNoParametersOrOptions: boolean; + name: string; + parameterName: string; allowDeprecatedUsage: boolean; + skipIfNoParametersOrOptions: boolean; + wrapper: StoryWrapper; } -export const makeDecorator: any = ({ +export const makeDecorator: MakeDecoratorResult = ({ name, parameterName, wrapper, @@ -35,6 +45,7 @@ export const makeDecorator: any = ({ if (skipIfNoParametersOrOptions && !options && !parameters) { return getStory(context); } + return wrapper(getStory, context, { options, parameters, From fa2c957aa0cef738ef984282b1424002f93cf68c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Kai=20R=C3=B6der?= Date: Mon, 17 Dec 2018 16:43:48 +0100 Subject: [PATCH 03/30] Rewrote @storybook/addons --- addons/notes/src/index.ts | 57 ++++++++++++++---------- lib/addons/package.json | 3 +- lib/addons/src/index.ts | 10 ++--- lib/addons/src/make-decorator.test.ts | 15 +++++-- lib/addons/src/make-decorator.ts | 4 +- lib/addons/src/public_api.ts | 3 ++ lib/addons/src/storybook-channel-mock.ts | 2 +- lib/addons/src/typings.d.ts | 4 ++ 8 files changed, 62 insertions(+), 36 deletions(-) create mode 100644 lib/addons/src/public_api.ts diff --git a/addons/notes/src/index.ts b/addons/notes/src/index.ts index 419b73acbf2d..c12ad3c8c7c6 100644 --- a/addons/notes/src/index.ts +++ b/addons/notes/src/index.ts @@ -1,28 +1,38 @@ -import addons, { makeDecorator, StoryContext, StoryGetter, StoryWrapper } from '@storybook/addons'; import { parse as renderMarkdown } from 'marked'; +import { + addons, + makeDecorator, + StoryContext, + StoryGetter, + WrapperSettings, +} from '@storybook/addons'; -// function wrapper(getStory: StoryGetter, context: StoryContext, {options, parameters}) { -// const channel = addons.getChannel(); -// -// const storyOptions = parameters || options; -// -// const {text, markdown, markdownOptions} = -// typeof storyOptions === 'string' -// ? { -// text: storyOptions, -// markdown: undefined, -// markdownOptions: undefined, -// } -// : storyOptions; -// -// if (!text && !markdown) { -// throw new Error('You must set of one of `text` or `markdown` on the `notes` parameter'); -// } -// -// channel.emit('storybook/notes/add_notes', text || renderMarkdown(markdown, markdownOptions)); -// -// return getStory(context); -// } +function wrapper( + getStory: StoryGetter, + context: StoryContext, + { options, parameters }: WrapperSettings +) { + const channel = addons.getChannel(); + + const storyOptions = parameters || options; + + const { text, markdown, markdownOptions } = + typeof storyOptions === 'string' + ? { + text: storyOptions, + markdown: undefined, + markdownOptions: undefined, + } + : storyOptions; + + if (!text && !markdown) { + throw new Error('You must set of one of `text` or `markdown` on the `notes` parameter'); + } + + channel.emit('storybook/notes/add_notes', text || renderMarkdown(markdown, markdownOptions)); + + return getStory(context); +} // todo resolve any after @storybook/addons and @storybook/channels are migrated to TypeScript export const withNotes = makeDecorator({ @@ -30,6 +40,7 @@ export const withNotes = makeDecorator({ parameterName: 'notes', skipIfNoParametersOrOptions: true, allowDeprecatedUsage: true, + wrapper, }); export const withMarkdownNotes = (text: string, options: any) => diff --git a/lib/addons/package.json b/lib/addons/package.json index 11883fe40c54..2c34906580de 100644 --- a/lib/addons/package.json +++ b/lib/addons/package.json @@ -14,7 +14,8 @@ "url": "https://github.com/storybooks/storybook.git" }, "license": "MIT", - "main": "dist/index.js", + "main": "dist/public_api.js", + "types": "dist/public_api.d.ts", "scripts": { "prepare": "node ../../scripts/prepare.js" }, diff --git a/lib/addons/src/index.ts b/lib/addons/src/index.ts index d0618201654e..135ed25fda9a 100644 --- a/lib/addons/src/index.ts +++ b/lib/addons/src/index.ts @@ -1,11 +1,7 @@ import global from 'global'; -import mockChannel from './storybook-channel-mock'; import Channel from '@storybook/channels'; import { ReactElement } from 'react'; -export { mockChannel }; -export * from './make-decorator'; - export interface PanelOptions { active: boolean; } @@ -77,4 +73,8 @@ function getAddonsStore() { return global[KEY]; } -export default getAddonsStore(); +// Exporting this twice in order to to be able to import it like { addons } instead of 'addons' +// prefer import { addons } from '@storybook/addons' over import addons from '@storybook/addons' +const addonStore = getAddonsStore(); +export { addonStore as addons }; +export default addonStore; diff --git a/lib/addons/src/make-decorator.test.ts b/lib/addons/src/make-decorator.test.ts index 53f3dd8cfeb5..4b640ac6636c 100644 --- a/lib/addons/src/make-decorator.test.ts +++ b/lib/addons/src/make-decorator.test.ts @@ -1,10 +1,17 @@ import deprecate from 'util-deprecate'; -import { makeDecorator } from './make-decorator'; -import { defaultDecorateStory } from '../../core/src/client/preview/client_api'; +import { makeDecorator, StoryContext } from './make-decorator'; + +// Copy & paste from internal api: core/client/preview/client_api +export const defaultDecorateStory = (getStory: Function, decorators: Function[]) => + decorators.reduce( + (decorated, decorator) => (context: StoryContext) => + decorator(() => decorated(context), context), + getStory + ); jest.mock('util-deprecate'); -let deprecatedFns = []; -deprecate.mockImplementation((fn, warning) => { +let deprecatedFns: any[] = []; +(deprecate as any).mockImplementation((fn: (...args: any) => any, warning: string) => { const deprecatedFn = jest.fn(fn); deprecatedFns.push({ deprecatedFn, diff --git a/lib/addons/src/make-decorator.ts b/lib/addons/src/make-decorator.ts index a4c40eb161f4..15d16687e881 100644 --- a/lib/addons/src/make-decorator.ts +++ b/lib/addons/src/make-decorator.ts @@ -6,7 +6,7 @@ export interface StoryContext { } export interface WrapperSettings { - options: any; + options: object; parameters: any; } @@ -35,7 +35,7 @@ export const makeDecorator: MakeDecoratorResult = ({ skipIfNoParametersOrOptions = false, allowDeprecatedUsage = false, }: MakeDecoratorOptions) => { - const decorator: any = (options: any) => (getStory: any, context: any) => { + const decorator: any = (options: object) => (getStory: any, context: any) => { const parameters = context.parameters && context.parameters[parameterName]; if (parameters && parameters.disable) { diff --git a/lib/addons/src/public_api.ts b/lib/addons/src/public_api.ts new file mode 100644 index 000000000000..c07891fd40a1 --- /dev/null +++ b/lib/addons/src/public_api.ts @@ -0,0 +1,3 @@ +export * from './make-decorator'; +export * from '.'; +export * from './storybook-channel-mock'; diff --git a/lib/addons/src/storybook-channel-mock.ts b/lib/addons/src/storybook-channel-mock.ts index 7358fc7e4bef..8cc153b624f5 100644 --- a/lib/addons/src/storybook-channel-mock.ts +++ b/lib/addons/src/storybook-channel-mock.ts @@ -1,6 +1,6 @@ import Channel from '@storybook/channels'; -export default function createChannel() { +export function createChannel() { const transport = { setHandler: () => {}, send: () => {}, diff --git a/lib/addons/src/typings.d.ts b/lib/addons/src/typings.d.ts index 2f4eb9cf4fd9..d9790e720639 100644 --- a/lib/addons/src/typings.d.ts +++ b/lib/addons/src/typings.d.ts @@ -1 +1,5 @@ declare module 'global'; + +declare module '@storybook/core' { + export type defaultDecorateStory = any; +} From 7b56599ea94b76ecbf36d528adb51c0192a1fa64 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Kai=20R=C3=B6der?= Date: Mon, 17 Dec 2018 16:50:44 +0100 Subject: [PATCH 04/30] removed unnecessary module declaration --- lib/addons/src/typings.d.ts | 4 ---- 1 file changed, 4 deletions(-) diff --git a/lib/addons/src/typings.d.ts b/lib/addons/src/typings.d.ts index d9790e720639..2f4eb9cf4fd9 100644 --- a/lib/addons/src/typings.d.ts +++ b/lib/addons/src/typings.d.ts @@ -1,5 +1 @@ declare module 'global'; - -declare module '@storybook/core' { - export type defaultDecorateStory = any; -} From 4beeba36bbb7c08d4f2b7fea8c985ef7941bf42a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Kai=20R=C3=B6der?= Date: Fri, 21 Dec 2018 08:16:57 +0100 Subject: [PATCH 05/30] Fixed export issue in lib/addons --- lib/addons/src/index.ts | 4 +--- lib/addons/src/public_api.ts | 8 ++++++++ 2 files changed, 9 insertions(+), 3 deletions(-) diff --git a/lib/addons/src/index.ts b/lib/addons/src/index.ts index 135ed25fda9a..66602973e993 100644 --- a/lib/addons/src/index.ts +++ b/lib/addons/src/index.ts @@ -75,6 +75,4 @@ function getAddonsStore() { // Exporting this twice in order to to be able to import it like { addons } instead of 'addons' // prefer import { addons } from '@storybook/addons' over import addons from '@storybook/addons' -const addonStore = getAddonsStore(); -export { addonStore as addons }; -export default addonStore; +export const addons = getAddonsStore(); diff --git a/lib/addons/src/public_api.ts b/lib/addons/src/public_api.ts index c07891fd40a1..22adacc28201 100644 --- a/lib/addons/src/public_api.ts +++ b/lib/addons/src/public_api.ts @@ -1,3 +1,11 @@ export * from './make-decorator'; export * from '.'; export * from './storybook-channel-mock'; + +// There can only be 1 default export per entry point and it has to be directly from public_api +// Exporting this twice in order to to be able to import it like { addons } instead of 'addons' +// prefer import { addons } from '@storybook/addons' over import addons from '@storybook/addons' +// +// See index.ts +import { addons } from '.'; +export default addons; From cd7eb71b6e45484b08c818ddeb577ac1c33b1201 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Kai=20R=C3=B6der?= Date: Fri, 21 Dec 2018 09:14:04 +0100 Subject: [PATCH 06/30] Removed addons from devDep because it is already a dependency --- addons/storyshots/storyshots-core/package.json | 1 - 1 file changed, 1 deletion(-) diff --git a/addons/storyshots/storyshots-core/package.json b/addons/storyshots/storyshots-core/package.json index 2d88335302ea..3c7cd1289372 100644 --- a/addons/storyshots/storyshots-core/package.json +++ b/addons/storyshots/storyshots-core/package.json @@ -35,7 +35,6 @@ "devDependencies": { "@storybook/addon-actions": "4.2.0-alpha.6", "@storybook/addon-links": "4.2.0-alpha.6", - "@storybook/addons": "4.2.0-alpha.1", "@storybook/react": "4.2.0-alpha.6", "enzyme-to-json": "^3.3.4", "react": "^16.6.0" From 6f6b119031d102fb49d546b4f4b7bd15a4c63abe Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Kai=20R=C3=B6der?= Date: Fri, 21 Dec 2018 09:14:46 +0100 Subject: [PATCH 07/30] Renamed createChannel to mockChannel in storybook-mock-channel --- lib/addons/src/index.ts | 2 ++ lib/addons/src/storybook-channel-mock.ts | 2 +- lib/channels/package.json | 1 - 3 files changed, 3 insertions(+), 2 deletions(-) diff --git a/lib/addons/src/index.ts b/lib/addons/src/index.ts index 66602973e993..fc71f994895d 100644 --- a/lib/addons/src/index.ts +++ b/lib/addons/src/index.ts @@ -75,4 +75,6 @@ function getAddonsStore() { // Exporting this twice in order to to be able to import it like { addons } instead of 'addons' // prefer import { addons } from '@storybook/addons' over import addons from '@storybook/addons' +// +// See public_api.ts export const addons = getAddonsStore(); diff --git a/lib/addons/src/storybook-channel-mock.ts b/lib/addons/src/storybook-channel-mock.ts index 8cc153b624f5..7d43f7b025c0 100644 --- a/lib/addons/src/storybook-channel-mock.ts +++ b/lib/addons/src/storybook-channel-mock.ts @@ -1,6 +1,6 @@ import Channel from '@storybook/channels'; -export function createChannel() { +export function mockChannel() { const transport = { setHandler: () => {}, send: () => {}, diff --git a/lib/channels/package.json b/lib/channels/package.json index 1925c472e4db..2a41e199b371 100644 --- a/lib/channels/package.json +++ b/lib/channels/package.json @@ -15,7 +15,6 @@ }, "license": "MIT", "main": "dist/index.js", - "jsnext:main": "src/index.ts", "scripts": { "prepare": "node ../../scripts/prepare.js" }, From 7b6a9c3273108ab27bd0d45e98f9e29ab89895c2 Mon Sep 17 00:00:00 2001 From: Igor Date: Sat, 22 Dec 2018 21:25:18 +0200 Subject: [PATCH 08/30] Remove jsnext:main with ts + add global as a module declaration to notes --- addons/notes/package.json | 1 - addons/notes/src/typings.d.ts | 1 + 2 files changed, 1 insertion(+), 1 deletion(-) diff --git a/addons/notes/package.json b/addons/notes/package.json index 6508847b87ae..8955400e7601 100644 --- a/addons/notes/package.json +++ b/addons/notes/package.json @@ -18,7 +18,6 @@ "license": "MIT", "main": "dist/public_api.js", "types": "dist/public_api.d.ts", - "jsnext:main": "src/public_api.ts", "scripts": { "prepare": "node ../../scripts/prepare.js" }, diff --git a/addons/notes/src/typings.d.ts b/addons/notes/src/typings.d.ts index 54a71c2c205c..1bf20a5640be 100644 --- a/addons/notes/src/typings.d.ts +++ b/addons/notes/src/typings.d.ts @@ -1,2 +1,3 @@ // Only necessary for 0.x.x. Version 10.x.x has definition files included declare module '@emotion/styled'; +declare module 'global'; From ac730de1ebcdaf0155a87b854e700d918d9508ba Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Kai=20R=C3=B6der?= Date: Sun, 23 Dec 2018 01:29:41 +0100 Subject: [PATCH 09/30] Added exports for register.tsx in public_api --- addons/notes/src/public_api.ts | 3 ++- addons/notes/tsconfig.json | 2 +- 2 files changed, 3 insertions(+), 2 deletions(-) diff --git a/addons/notes/src/public_api.ts b/addons/notes/src/public_api.ts index dc0dc8965a31..33c283a8be16 100644 --- a/addons/notes/src/public_api.ts +++ b/addons/notes/src/public_api.ts @@ -1 +1,2 @@ -export * from '.'; +export * from './index'; +export * from './register'; diff --git a/addons/notes/tsconfig.json b/addons/notes/tsconfig.json index 91baa3e9a3ac..0da979ed5c16 100644 --- a/addons/notes/tsconfig.json +++ b/addons/notes/tsconfig.json @@ -8,6 +8,6 @@ "src/**/*.tsx" ], "exclude": [ - "src/__tests__/**/*" + "src/__tests__/" ] } From 2652e103e3f07fa4ac0307ab61df85ad218699b8 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Kai=20R=C3=B6der?= Date: Sun, 23 Dec 2018 01:39:29 +0100 Subject: [PATCH 10/30] Try to fix CI smoke-test --- lib/addons/src/public_api.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/addons/src/public_api.ts b/lib/addons/src/public_api.ts index 22adacc28201..206a57b659c8 100644 --- a/lib/addons/src/public_api.ts +++ b/lib/addons/src/public_api.ts @@ -1,5 +1,5 @@ export * from './make-decorator'; -export * from '.'; +export * from './index'; export * from './storybook-channel-mock'; // There can only be 1 default export per entry point and it has to be directly from public_api From b681f0d194c6ed5d1509d44a813088a8c54e730d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Kai=20R=C3=B6der?= Date: Sun, 23 Dec 2018 01:43:08 +0100 Subject: [PATCH 11/30] Removed types for react in package; types are already in the root package.json --- lib/addons/package.json | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/lib/addons/package.json b/lib/addons/package.json index c0ec36a4351c..b7cf238ef2ad 100644 --- a/lib/addons/package.json +++ b/lib/addons/package.json @@ -26,8 +26,7 @@ "util-deprecate": "^1.0.2" }, "devDependencies": { - "@types/util-deprecate": "^1.0.0", - "@types/react": "^16.7.17y" + "@types/util-deprecate": "^1.0.0" }, "publishConfig": { "access": "public" From ec0a8c28f8907a6ff30aa1c2a25d584bdf3eed8f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Kai=20R=C3=B6der?= Date: Sun, 23 Dec 2018 02:41:14 +0100 Subject: [PATCH 12/30] Still trying to fix CI --- addons/notes/src/public_api.ts | 3 +-- addons/notes/tsconfig.json | 8 ++++---- lib/addons/src/public_api.ts | 2 +- lib/addons/tsconfig.json | 3 +-- scripts/compile-ts.js | 4 +++- tsconfig.json | 2 +- 6 files changed, 11 insertions(+), 11 deletions(-) diff --git a/addons/notes/src/public_api.ts b/addons/notes/src/public_api.ts index 33c283a8be16..dc0dc8965a31 100644 --- a/addons/notes/src/public_api.ts +++ b/addons/notes/src/public_api.ts @@ -1,2 +1 @@ -export * from './index'; -export * from './register'; +export * from '.'; diff --git a/addons/notes/tsconfig.json b/addons/notes/tsconfig.json index 0da979ed5c16..2f4df283c92a 100644 --- a/addons/notes/tsconfig.json +++ b/addons/notes/tsconfig.json @@ -1,13 +1,13 @@ { "extends": "../../tsconfig.json", "compilerOptions": { - "rootDir": "./src" + "rootDir": "./src", + "jsx": "preserve" }, "include": [ - "src/**/*.ts", - "src/**/*.tsx" + "src/**/*" ], "exclude": [ - "src/__tests__/" + "src/__tests__/**/*" ] } diff --git a/lib/addons/src/public_api.ts b/lib/addons/src/public_api.ts index 206a57b659c8..22adacc28201 100644 --- a/lib/addons/src/public_api.ts +++ b/lib/addons/src/public_api.ts @@ -1,5 +1,5 @@ export * from './make-decorator'; -export * from './index'; +export * from '.'; export * from './storybook-channel-mock'; // There can only be 1 default export per entry point and it has to be directly from public_api diff --git a/lib/addons/tsconfig.json b/lib/addons/tsconfig.json index 81d74f99bec2..f7c7ea71c14c 100644 --- a/lib/addons/tsconfig.json +++ b/lib/addons/tsconfig.json @@ -1,8 +1,7 @@ { "extends": "../../tsconfig.json", "compilerOptions": { - "rootDir": "./src", - "strict": true + "rootDir": "./src" }, "include": [ "src/**/*.ts", diff --git a/scripts/compile-ts.js b/scripts/compile-ts.js index c918cd5f4dc3..b523311473f2 100644 --- a/scripts/compile-ts.js +++ b/scripts/compile-ts.js @@ -26,7 +26,7 @@ function handleExit(code, errorCallback) { } function tscfy(options = {}) { - const { watch = false, silent = true, errorCallback } = options; + const { watch = false, silent = false, errorCallback } = options; const tsConfigFile = 'tsconfig.json'; if (!fs.existsSync(tsConfigFile)) { @@ -37,6 +37,8 @@ function tscfy(options = {}) { const content = fs.readFileSync(tsConfigFile); const tsConfig = JSON.parse(content); + console.log(JSON.stringify(tsConfig, null, 2)); + if (tsConfig && tsConfig.lerna && tsConfig.lerna.disabled === true) { if (!silent) console.log('Lerna disabled'); return; diff --git a/tsconfig.json b/tsconfig.json index c2e1fbdc8a35..6a15527baa2c 100644 --- a/tsconfig.json +++ b/tsconfig.json @@ -7,7 +7,7 @@ "experimentalDecorators": true, "skipLibCheck": true, "noImplicitAny": true, - "jsx": "react", + "jsx": "preserve", "module": "commonjs", "allowSyntheticDefaultImports": true, "esModuleInterop": true, From c6176949bab257983cb7b43fbc14deca8564d843 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Kai=20R=C3=B6der?= Date: Sun, 23 Dec 2018 02:46:45 +0100 Subject: [PATCH 13/30] yarn.lock --- yarn.lock | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/yarn.lock b/yarn.lock index 4347c82bf88e..8e8c14b821b4 100644 --- a/yarn.lock +++ b/yarn.lock @@ -2085,7 +2085,7 @@ version "1.5.1" resolved "https://registry.yarnpkg.com/@types/q/-/q-1.5.1.tgz#48fd98c1561fe718b61733daed46ff115b496e18" -"@types/react@^16.7.17y", "@types/react@^16.7.3": +"@types/react@^16.7.3": version "16.7.17" resolved "https://registry.yarnpkg.com/@types/react/-/react-16.7.17.tgz#3242e796a1ffbba4f49eae5915a67f4c079504e9" dependencies: From afc55cae49554cd7710e126907117c289e85031f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Kai=20R=C3=B6der?= Date: Sun, 23 Dec 2018 02:52:19 +0100 Subject: [PATCH 14/30] revert debug output --- lib/addons/tsconfig.json | 3 +-- scripts/compile-ts.js | 4 +--- 2 files changed, 2 insertions(+), 5 deletions(-) diff --git a/lib/addons/tsconfig.json b/lib/addons/tsconfig.json index f7c7ea71c14c..29a5bf1be1bf 100644 --- a/lib/addons/tsconfig.json +++ b/lib/addons/tsconfig.json @@ -4,8 +4,7 @@ "rootDir": "./src" }, "include": [ - "src/**/*.ts", - "src/**/*.tsx" + "src/**/*" ], "exclude": [ "src/index.test.ts" diff --git a/scripts/compile-ts.js b/scripts/compile-ts.js index b523311473f2..c918cd5f4dc3 100644 --- a/scripts/compile-ts.js +++ b/scripts/compile-ts.js @@ -26,7 +26,7 @@ function handleExit(code, errorCallback) { } function tscfy(options = {}) { - const { watch = false, silent = false, errorCallback } = options; + const { watch = false, silent = true, errorCallback } = options; const tsConfigFile = 'tsconfig.json'; if (!fs.existsSync(tsConfigFile)) { @@ -37,8 +37,6 @@ function tscfy(options = {}) { const content = fs.readFileSync(tsConfigFile); const tsConfig = JSON.parse(content); - console.log(JSON.stringify(tsConfig, null, 2)); - if (tsConfig && tsConfig.lerna && tsConfig.lerna.disabled === true) { if (!silent) console.log('Lerna disabled'); return; From 17075d9ae078c594b5bc83d5e85b1cb921bf2760 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Kai=20R=C3=B6der?= Date: Sun, 23 Dec 2018 02:57:02 +0100 Subject: [PATCH 15/30] Use named imports --- addons/notes/src/register.tsx | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/addons/notes/src/register.tsx b/addons/notes/src/register.tsx index 04fee67bc6bc..7c0694fbaaa9 100644 --- a/addons/notes/src/register.tsx +++ b/addons/notes/src/register.tsx @@ -1,10 +1,10 @@ import * as React from 'react'; -import addons from '@storybook/addons'; -import Channel from '@storybook/channels'; import * as PropTypes from 'prop-types'; import styled from '@emotion/styled'; +import { Channel } from '@storybook/channels'; +import { addons } from '@storybook/addons'; interface NotesApi { setQueryParams: any; // todo check correct definition From 395f77674e308cec756cd79e10abee9152a1982a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Kai=20R=C3=B6der?= Date: Sun, 23 Dec 2018 02:59:20 +0100 Subject: [PATCH 16/30] Use named imports --- lib/addons/src/index.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/addons/src/index.ts b/lib/addons/src/index.ts index fc71f994895d..c8432df6f6ce 100644 --- a/lib/addons/src/index.ts +++ b/lib/addons/src/index.ts @@ -1,5 +1,5 @@ import global from 'global'; -import Channel from '@storybook/channels'; +import { Channel } from '@storybook/channels'; import { ReactElement } from 'react'; export interface PanelOptions { From 60c63201d1d840185c69a4e0d6bdf4d326979387 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Kai=20R=C3=B6der?= Date: Sun, 23 Dec 2018 03:00:51 +0100 Subject: [PATCH 17/30] Added types entry in channel package.json --- lib/channels/package.json | 1 + 1 file changed, 1 insertion(+) diff --git a/lib/channels/package.json b/lib/channels/package.json index 2a41e199b371..3b428f249c74 100644 --- a/lib/channels/package.json +++ b/lib/channels/package.json @@ -15,6 +15,7 @@ }, "license": "MIT", "main": "dist/index.js", + "types": "dist/index.d.ts", "scripts": { "prepare": "node ../../scripts/prepare.js" }, From d90fba2a05d86a343799e7e39422ab6d4d700f8c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Kai=20R=C3=B6der?= Date: Sun, 23 Dec 2018 03:01:24 +0100 Subject: [PATCH 18/30] Removed jsx tsconfig entry in addon-notes --- addons/notes/tsconfig.json | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/addons/notes/tsconfig.json b/addons/notes/tsconfig.json index 2f4df283c92a..30079a2f7435 100644 --- a/addons/notes/tsconfig.json +++ b/addons/notes/tsconfig.json @@ -1,8 +1,7 @@ { "extends": "../../tsconfig.json", "compilerOptions": { - "rootDir": "./src", - "jsx": "preserve" + "rootDir": "./src" }, "include": [ "src/**/*" From 05b1f5a999d0ba69641674db7f7fa33be17f11ae Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Kai=20R=C3=B6der?= Date: Mon, 24 Dec 2018 00:46:56 +0100 Subject: [PATCH 19/30] Workaround proposal for splitting up pure ts projects from mixed ones --- scripts/prepare.js | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) diff --git a/scripts/prepare.js b/scripts/prepare.js index 59a6f856f4c5..b3be02d5e9e1 100644 --- a/scripts/prepare.js +++ b/scripts/prepare.js @@ -38,8 +38,12 @@ function logError(type, packageJson) { const packageJson = getPackageJson(); removeDist(); -babelify({ errorCallback: () => logError('js', packageJson) }); -removeTsFromDist(); -tscfy({ errorCallback: () => logError('ts', packageJson) }); +if (packageJson.types.indexOf('d.ts') !== -1) { + tscfy({ errorCallback: () => logError('ts', packageJson) }); +} else { + babelify({ errorCallback: () => logError('js', packageJson) }); + removeTsFromDist(); + tscfy({ errorCallback: () => logError('ts', packageJson) }); +} console.log(chalk.gray(`Built: ${chalk.bold(`${packageJson.name}@${packageJson.version}`)}`)); From 0d88e53380315fe41b21394d1a20b2627da36295 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Kai=20R=C3=B6der?= Date: Mon, 24 Dec 2018 00:48:55 +0100 Subject: [PATCH 20/30] Check existence of types --- scripts/prepare.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/scripts/prepare.js b/scripts/prepare.js index b3be02d5e9e1..177e1c5cd1e7 100644 --- a/scripts/prepare.js +++ b/scripts/prepare.js @@ -38,7 +38,7 @@ function logError(type, packageJson) { const packageJson = getPackageJson(); removeDist(); -if (packageJson.types.indexOf('d.ts') !== -1) { +if (packageJson && packageJson.types && packageJson.types.indexOf('d.ts') !== -1) { tscfy({ errorCallback: () => logError('ts', packageJson) }); } else { babelify({ errorCallback: () => logError('js', packageJson) }); From ce410264ed4470a53efcca5697313ace30329ede Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Kai=20R=C3=B6der?= Date: Mon, 24 Dec 2018 00:59:55 +0100 Subject: [PATCH 21/30] fix require path --- addons/notes/register.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/addons/notes/register.js b/addons/notes/register.js index 18cdafda57c4..ca15c3e0ae13 100644 --- a/addons/notes/register.js +++ b/addons/notes/register.js @@ -1 +1 @@ -require('./dist/register.js'); +require('./dist/register.jsx'); From 33ad47629e1e84b82b5acbd4c2475ba8a8fd7393 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Kai=20R=C3=B6der?= Date: Mon, 24 Dec 2018 01:13:41 +0100 Subject: [PATCH 22/30] Set jsx to react --- tsconfig.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tsconfig.json b/tsconfig.json index 6a15527baa2c..c2e1fbdc8a35 100644 --- a/tsconfig.json +++ b/tsconfig.json @@ -7,7 +7,7 @@ "experimentalDecorators": true, "skipLibCheck": true, "noImplicitAny": true, - "jsx": "preserve", + "jsx": "react", "module": "commonjs", "allowSyntheticDefaultImports": true, "esModuleInterop": true, From 86a28139a38c76e3db3be554aee2923cb845704c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Kai=20R=C3=B6der?= Date: Mon, 24 Dec 2018 01:21:13 +0100 Subject: [PATCH 23/30] Set require back to js instead of jsx --- addons/notes/register.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/addons/notes/register.js b/addons/notes/register.js index ca15c3e0ae13..18cdafda57c4 100644 --- a/addons/notes/register.js +++ b/addons/notes/register.js @@ -1 +1 @@ -require('./dist/register.jsx'); +require('./dist/register.js'); From 3132aec46253b35cfb5f28d8832bf4c159f21fe6 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Kai=20R=C3=B6der?= Date: Mon, 24 Dec 2018 01:41:15 +0100 Subject: [PATCH 24/30] Exclude test files --- lib/addons/tsconfig.json | 2 +- lib/channels/tsconfig.json | 5 ++--- 2 files changed, 3 insertions(+), 4 deletions(-) diff --git a/lib/addons/tsconfig.json b/lib/addons/tsconfig.json index 29a5bf1be1bf..64eed74f8ea8 100644 --- a/lib/addons/tsconfig.json +++ b/lib/addons/tsconfig.json @@ -7,6 +7,6 @@ "src/**/*" ], "exclude": [ - "src/index.test.ts" + "src/**.test.ts" ] } diff --git a/lib/channels/tsconfig.json b/lib/channels/tsconfig.json index f7c7ea71c14c..64eed74f8ea8 100644 --- a/lib/channels/tsconfig.json +++ b/lib/channels/tsconfig.json @@ -4,10 +4,9 @@ "rootDir": "./src" }, "include": [ - "src/**/*.ts", - "src/**/*.tsx" + "src/**/*" ], "exclude": [ - "src/index.test.ts" + "src/**.test.ts" ] } From 5e34e426d6f9fb97313bf570e19a560aba81b4d5 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Kai=20R=C3=B6der?= Date: Mon, 24 Dec 2018 02:08:01 +0100 Subject: [PATCH 25/30] Debugging native-smoke CI - revert this --- scripts/build-pack.sh | 3 +++ 1 file changed, 3 insertions(+) diff --git a/scripts/build-pack.sh b/scripts/build-pack.sh index f77e609c161a..e33e7ae4c089 100755 --- a/scripts/build-pack.sh +++ b/scripts/build-pack.sh @@ -5,4 +5,7 @@ PACK_DIR=$1 FILE=$(npm pack | tail -n 1) +echo $PACK_DIR +echo $FILE + mv "$FILE" "$PACK_DIR/${FILE%-[0-9]*\.[0-9]*\.[0-9]*\.tgz}.tgz" From b24a7928b50ebab559cd53c79c258a90f9a48b91 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Kai=20R=C3=B6der?= Date: Thu, 27 Dec 2018 01:12:10 +0100 Subject: [PATCH 26/30] silent false for test purpose --- scripts/compile-ts.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/scripts/compile-ts.js b/scripts/compile-ts.js index c918cd5f4dc3..ed7696913d2c 100644 --- a/scripts/compile-ts.js +++ b/scripts/compile-ts.js @@ -26,7 +26,7 @@ function handleExit(code, errorCallback) { } function tscfy(options = {}) { - const { watch = false, silent = true, errorCallback } = options; + const { watch = false, silent = false, errorCallback } = options; const tsConfigFile = 'tsconfig.json'; if (!fs.existsSync(tsConfigFile)) { From 05119a8eb82a2acff90fdff4406194dbe0b1f33e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Kai=20R=C3=B6der?= Date: Thu, 27 Dec 2018 01:21:07 +0100 Subject: [PATCH 27/30] more debug messages --- scripts/compile-ts.js | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/scripts/compile-ts.js b/scripts/compile-ts.js index ed7696913d2c..e171bd2ffe6b 100644 --- a/scripts/compile-ts.js +++ b/scripts/compile-ts.js @@ -43,8 +43,10 @@ function tscfy(options = {}) { } const command = getCommand(watch); - const { code } = shell.exec(command, { silent }); - + const shellReturn = shell.exec(command, { silent }); + const { code } = shellReturn; + console.error('---------- DEBUG_MESSAGE ----------'); + console.error(shellReturn); handleExit(code, errorCallback); } From 3343b93584ecc901e5652944a8c1838e2b9d97d4 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Kai=20R=C3=B6der?= Date: Thu, 27 Dec 2018 01:32:28 +0100 Subject: [PATCH 28/30] Enhanced error output on CI build errors --- scripts/compile-ts.js | 11 +++++------ scripts/prepare.js | 9 +++++---- 2 files changed, 10 insertions(+), 10 deletions(-) diff --git a/scripts/compile-ts.js b/scripts/compile-ts.js index e171bd2ffe6b..405a0ef2f9e2 100644 --- a/scripts/compile-ts.js +++ b/scripts/compile-ts.js @@ -26,7 +26,7 @@ function handleExit(code, errorCallback) { } function tscfy(options = {}) { - const { watch = false, silent = false, errorCallback } = options; + const { watch = false, silent = true, errorCallback } = options; const tsConfigFile = 'tsconfig.json'; if (!fs.existsSync(tsConfigFile)) { @@ -43,11 +43,10 @@ function tscfy(options = {}) { } const command = getCommand(watch); - const shellReturn = shell.exec(command, { silent }); - const { code } = shellReturn; - console.error('---------- DEBUG_MESSAGE ----------'); - console.error(shellReturn); - handleExit(code, errorCallback); + const shellExecReturn = shell.exec(command, { silent }); + const { code } = shellExecReturn; + + handleExit(code, errorCallback(shellExecReturn)); } module.exports = { diff --git a/scripts/prepare.js b/scripts/prepare.js index 177e1c5cd1e7..04ec446670a2 100644 --- a/scripts/prepare.js +++ b/scripts/prepare.js @@ -29,21 +29,22 @@ function removeTsFromDist() { } } -function logError(type, packageJson) { +function logError(type, packageJson, shellExecReturn) { log.error( `FAILED to compile ${type}: ${chalk.bold(`${packageJson.name}@${packageJson.version}`)}` ); + log.error(`--- SHELL EXEC RETURN MESSAGE ---\n${shellExecReturn}`); } const packageJson = getPackageJson(); removeDist(); if (packageJson && packageJson.types && packageJson.types.indexOf('d.ts') !== -1) { - tscfy({ errorCallback: () => logError('ts', packageJson) }); + tscfy({ errorCallback: shellExecMessage => logError('ts', packageJson, shellExecMessage) }); } else { - babelify({ errorCallback: () => logError('js', packageJson) }); + babelify({ errorCallback: shellExecMessage => logError('js', packageJson, shellExecMessage) }); removeTsFromDist(); - tscfy({ errorCallback: () => logError('ts', packageJson) }); + tscfy({ errorCallback: shellExecMessage => logError('ts', packageJson, shellExecMessage) }); } console.log(chalk.gray(`Built: ${chalk.bold(`${packageJson.name}@${packageJson.version}`)}`)); From 13123b7b6f36cfafef859302ec63652820ef2487 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Kai=20R=C3=B6der?= Date: Thu, 27 Dec 2018 01:38:56 +0100 Subject: [PATCH 29/30] Improved error output --- scripts/prepare.js | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/scripts/prepare.js b/scripts/prepare.js index 04ec446670a2..5135c4e8b56a 100644 --- a/scripts/prepare.js +++ b/scripts/prepare.js @@ -31,9 +31,10 @@ function removeTsFromDist() { function logError(type, packageJson, shellExecReturn) { log.error( - `FAILED to compile ${type}: ${chalk.bold(`${packageJson.name}@${packageJson.version}`)}` + `FAILED to compile ${type}: ${chalk.bold( + `${packageJson.name}@${packageJson.version}\n ${shellExecReturn}` + )}` ); - log.error(`--- SHELL EXEC RETURN MESSAGE ---\n${shellExecReturn}`); } const packageJson = getPackageJson(); From a9039912818fa0584ea8e158216ad240449a68f8 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Kai=20R=C3=B6der?= Date: Thu, 27 Dec 2018 01:48:57 +0100 Subject: [PATCH 30/30] try to fix ci --- package.json | 2 +- scripts/compile-ts.js | 5 ++--- scripts/prepare.js | 12 +++++------- 3 files changed, 8 insertions(+), 11 deletions(-) diff --git a/package.json b/package.json index f44b2ceae377..30f642b746b6 100644 --- a/package.json +++ b/package.json @@ -18,7 +18,7 @@ "bootstrap": "node ./scripts/bootstrap.js", "bootstrap:crna-kitchen-sink": "npm --prefix examples-native/crna-kitchen-sink install", "bootstrap:docs": "yarn install --cwd docs", - "build-packs": "lerna exec --scope '@storybook/*' --parallel -- \\$LERNA_ROOT_PATH/scripts/build-pack.sh \\$LERNA_ROOT_PATH/packs", + "build-packs": "lerna exec --scope '@storybook/*' -- \\$LERNA_ROOT_PATH/scripts/build-pack.sh \\$LERNA_ROOT_PATH/packs", "build-storybooks": "./scripts/build-storybooks.sh", "changelog": "pr-log --sloppy --cherry-pick", "changelog:next": "pr-log --sloppy --since-prerelease", diff --git a/scripts/compile-ts.js b/scripts/compile-ts.js index 405a0ef2f9e2..c918cd5f4dc3 100644 --- a/scripts/compile-ts.js +++ b/scripts/compile-ts.js @@ -43,10 +43,9 @@ function tscfy(options = {}) { } const command = getCommand(watch); - const shellExecReturn = shell.exec(command, { silent }); - const { code } = shellExecReturn; + const { code } = shell.exec(command, { silent }); - handleExit(code, errorCallback(shellExecReturn)); + handleExit(code, errorCallback); } module.exports = { diff --git a/scripts/prepare.js b/scripts/prepare.js index 5135c4e8b56a..177e1c5cd1e7 100644 --- a/scripts/prepare.js +++ b/scripts/prepare.js @@ -29,11 +29,9 @@ function removeTsFromDist() { } } -function logError(type, packageJson, shellExecReturn) { +function logError(type, packageJson) { log.error( - `FAILED to compile ${type}: ${chalk.bold( - `${packageJson.name}@${packageJson.version}\n ${shellExecReturn}` - )}` + `FAILED to compile ${type}: ${chalk.bold(`${packageJson.name}@${packageJson.version}`)}` ); } @@ -41,11 +39,11 @@ const packageJson = getPackageJson(); removeDist(); if (packageJson && packageJson.types && packageJson.types.indexOf('d.ts') !== -1) { - tscfy({ errorCallback: shellExecMessage => logError('ts', packageJson, shellExecMessage) }); + tscfy({ errorCallback: () => logError('ts', packageJson) }); } else { - babelify({ errorCallback: shellExecMessage => logError('js', packageJson, shellExecMessage) }); + babelify({ errorCallback: () => logError('js', packageJson) }); removeTsFromDist(); - tscfy({ errorCallback: shellExecMessage => logError('ts', packageJson, shellExecMessage) }); + tscfy({ errorCallback: () => logError('ts', packageJson) }); } console.log(chalk.gray(`Built: ${chalk.bold(`${packageJson.name}@${packageJson.version}`)}`));