From a13af7bc3f2e101451fe0104a9e2de31d964ae40 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ga=C3=ABtan=20Maisse?= Date: Mon, 14 Dec 2020 21:37:10 +0100 Subject: [PATCH] refactor(rax): migrate to TS --- app/rax/package.json | 1 + app/rax/src/client/{index.js => index.ts} | 0 .../src/client/preview/{globals.js => globals.ts} | 0 app/rax/src/client/preview/{index.js => index.ts} | 5 +++-- app/rax/src/client/preview/{render.js => render.ts} | 12 +++++++++++- app/rax/src/server/{build.js => build.ts} | 0 ...amework-preset-rax.js => framework-preset-rax.ts} | 4 +++- app/rax/src/server/{index.js => index.ts} | 0 app/rax/src/server/{options.js => options.ts} | 0 app/rax/src/typings.d.ts | 2 ++ app/rax/tsconfig.json | 7 +++++++ yarn.lock | 8 ++++++++ 12 files changed, 35 insertions(+), 4 deletions(-) rename app/rax/src/client/{index.js => index.ts} (100%) rename app/rax/src/client/preview/{globals.js => globals.ts} (100%) rename app/rax/src/client/preview/{index.js => index.ts} (65%) rename app/rax/src/client/preview/{render.js => render.ts} (63%) rename app/rax/src/server/{build.js => build.ts} (100%) rename app/rax/src/server/{framework-preset-rax.js => framework-preset-rax.ts} (66%) rename app/rax/src/server/{index.js => index.ts} (100%) rename app/rax/src/server/{options.js => options.ts} (100%) create mode 100644 app/rax/src/typings.d.ts create mode 100644 app/rax/tsconfig.json diff --git a/app/rax/package.json b/app/rax/package.json index 4564135b0a46..fbf3009b4473 100644 --- a/app/rax/package.json +++ b/app/rax/package.json @@ -54,6 +54,7 @@ "ts-dedent": "^2.0.0" }, "devDependencies": { + "@types/rax": "^1.0.2", "rax": "^1.1.0" }, "peerDependencies": { diff --git a/app/rax/src/client/index.js b/app/rax/src/client/index.ts similarity index 100% rename from app/rax/src/client/index.js rename to app/rax/src/client/index.ts diff --git a/app/rax/src/client/preview/globals.js b/app/rax/src/client/preview/globals.ts similarity index 100% rename from app/rax/src/client/preview/globals.js rename to app/rax/src/client/preview/globals.ts diff --git a/app/rax/src/client/preview/index.js b/app/rax/src/client/preview/index.ts similarity index 65% rename from app/rax/src/client/preview/index.js rename to app/rax/src/client/preview/index.ts index 109004a46b5f..488026ef4ff8 100644 --- a/app/rax/src/client/preview/index.js +++ b/app/rax/src/client/preview/index.ts @@ -15,7 +15,8 @@ export const { } = clientApi; const framework = 'rax'; -export const storiesOf = (...args) => clientApi.storiesOf(...args).addParameters({ framework }); -export const configure = (...args) => coreConfigure(framework, ...args); +export const storiesOf = (...args: any) => + clientApi.storiesOf(...args).addParameters({ framework }); +export const configure = (...args: any) => coreConfigure(framework, ...args); export { forceReRender }; diff --git a/app/rax/src/client/preview/render.js b/app/rax/src/client/preview/render.ts similarity index 63% rename from app/rax/src/client/preview/render.js rename to app/rax/src/client/preview/render.ts index fc1b4c93f8f7..f791ccfff75b 100644 --- a/app/rax/src/client/preview/render.js +++ b/app/rax/src/client/preview/render.ts @@ -12,7 +12,12 @@ export default function renderMain({ name, showMain, showError, - // forceRender, +}: { + storyFn: Function; + kind: string; + name: string; + showMain: () => any; + showError: (input: { title: string; description: string }) => void; }) { const Element = storyFn; @@ -29,6 +34,11 @@ export default function renderMain({ showMain(); + // There is something miscellaneous here, for now, more precisely on L23, + // as we are using the storyFn directly and not calling it, so `Element` is a + // function but according to `createElement` types, there is no signature + // taking a function as input. + // @ts-expect-error render(createElement(Element), rootElement, { driver: DriverDOM, }); diff --git a/app/rax/src/server/build.js b/app/rax/src/server/build.ts similarity index 100% rename from app/rax/src/server/build.js rename to app/rax/src/server/build.ts diff --git a/app/rax/src/server/framework-preset-rax.js b/app/rax/src/server/framework-preset-rax.ts similarity index 66% rename from app/rax/src/server/framework-preset-rax.js rename to app/rax/src/server/framework-preset-rax.ts index 038cd57824b4..73fb93058e10 100644 --- a/app/rax/src/server/framework-preset-rax.js +++ b/app/rax/src/server/framework-preset-rax.ts @@ -1,4 +1,6 @@ -export function babelDefault(config) { +import { TransformOptions } from '@babel/core'; + +export function babelDefault(config: TransformOptions) { return { ...config, presets: [ diff --git a/app/rax/src/server/index.js b/app/rax/src/server/index.ts similarity index 100% rename from app/rax/src/server/index.js rename to app/rax/src/server/index.ts diff --git a/app/rax/src/server/options.js b/app/rax/src/server/options.ts similarity index 100% rename from app/rax/src/server/options.js rename to app/rax/src/server/options.ts diff --git a/app/rax/src/typings.d.ts b/app/rax/src/typings.d.ts new file mode 100644 index 000000000000..6288cba4b09a --- /dev/null +++ b/app/rax/src/typings.d.ts @@ -0,0 +1,2 @@ +declare module '@storybook/core/*'; +declare module 'global'; diff --git a/app/rax/tsconfig.json b/app/rax/tsconfig.json new file mode 100644 index 000000000000..f1429a324345 --- /dev/null +++ b/app/rax/tsconfig.json @@ -0,0 +1,7 @@ +{ + "extends": "../../tsconfig.json", + "compilerOptions": { + "rootDir": "src", + "types": ["webpack-env", "node"] + } +} diff --git a/yarn.lock b/yarn.lock index a4e1d899c141..0217b91043d7 100644 --- a/yarn.lock +++ b/yarn.lock @@ -4986,6 +4986,14 @@ resolved "https://registry.yarnpkg.com/@types/range-parser/-/range-parser-1.2.3.tgz#7ee330ba7caafb98090bece86a5ee44115904c2c" integrity sha512-ewFXqrQHlFsgc09MK5jP5iR7vumV/BYayNC6PgJO2LPe8vrnNFyjQjSppfEngITi0qvfKtzFvgKymGheFM9UOA== +"@types/rax@^1.0.2": + version "1.0.2" + resolved "https://registry.yarnpkg.com/@types/rax/-/rax-1.0.2.tgz#1a6121244a0ad31deecdcede2651efa4ec9ead2a" + integrity sha512-oB3tpuFhFc4osp2brErugGbInNQs15GSmE21PXh7LVMPwUaemBTMjzGxXrzgvoW/marD9sRxPJTkf53UJpjnnA== + dependencies: + "@types/prop-types" "*" + csstype "^3.0.2" + "@types/reach__router@^1.3.5": version "1.3.6" resolved "https://registry.yarnpkg.com/@types/reach__router/-/reach__router-1.3.6.tgz#413417ce74caab331c70ce6a03a4c825188e4709"