diff --git a/lib/core-events/index.js b/lib/core-events/index.js deleted file mode 100644 index 08e6a0535035..000000000000 --- a/lib/core-events/index.js +++ /dev/null @@ -1,15 +0,0 @@ -module.exports = { - CHANNEL_CREATED: 'channelCreated', - GET_CURRENT_STORY: 'getCurrentStory', - SET_CURRENT_STORY: 'setCurrentStory', - GET_STORIES: 'getStories', - SET_STORIES: 'setStories', - SELECT_STORY: 'selectStory', - APPLY_SHORTCUT: 'applyShortcut', - STORY_ADDED: 'storyAdded', - FORCE_RE_RENDER: 'forceReRender', - REGISTER_SUBSCRIPTION: 'registerSubscription', - STORY_RENDERED: 'storyRendered', - STORY_ERRORED: 'storyErrored', - STORY_THREW_EXCEPTION: 'storyThrewException', -}; diff --git a/lib/core-events/package.json b/lib/core-events/package.json index 44ccbd8f918f..293a566c5f4c 100644 --- a/lib/core-events/package.json +++ b/lib/core-events/package.json @@ -13,8 +13,12 @@ "type": "git", "url": "https://github.com/storybooks/storybook.git" }, + "scripts": { + "prepare": "node ../../scripts/prepare.js" + }, "license": "MIT", - "main": "index.js", + "main": "dist/index.js", + "types": "dist/index.d.ts", "publishConfig": { "access": "public" } diff --git a/lib/core-events/src/index.ts b/lib/core-events/src/index.ts new file mode 100644 index 000000000000..e48bfc005639 --- /dev/null +++ b/lib/core-events/src/index.ts @@ -0,0 +1,17 @@ +enum events { + CHANNEL_CREATED = 'channelCreated', + GET_CURRENT_STORY = 'getCurrentStory', + SET_CURRENT_STORY = 'setCurrentStory', + GET_STORIES = 'getStories', + SET_STORIES = 'setStories', + SELECT_STORY = 'selectStory', + APPLY_SHORTCUT = 'applyShortcut', + STORY_ADDED = 'storyAdded', + FORCE_RE_RENDER = 'forceReRender', + REGISTER_SUBSCRIPTION = 'registerSubscription', + STORY_RENDERED = 'storyRendered', + STORY_ERRORED = 'storyErrored', + STORY_THREW_EXCEPTION = 'storyThrewException', +} + +export default events; diff --git a/lib/core-events/tsconfig.json b/lib/core-events/tsconfig.json new file mode 100644 index 000000000000..4b566356cc21 --- /dev/null +++ b/lib/core-events/tsconfig.json @@ -0,0 +1,8 @@ +{ + "extends": "../../tsconfig.json", + "compilerOptions": { + "rootDir": "./src" + }, + "include": ["src/**/*"], + "exclude": [] +} diff --git a/lib/node-logger/package.json b/lib/node-logger/package.json index f0a7286ddd18..0fff03f529c9 100644 --- a/lib/node-logger/package.json +++ b/lib/node-logger/package.json @@ -15,7 +15,7 @@ }, "license": "MIT", "main": "dist/index.js", - "jsnext:main": "src/index.js", + "types": "dist/index.d.ts", "scripts": { "prepare": "node ../../scripts/prepare.js" }, @@ -26,6 +26,10 @@ "pretty-hrtime": "^1.0.3", "regenerator-runtime": "^0.12.1" }, + "devDependencies": { + "@types/npmlog": "^4.1.1", + "@types/pretty-hrtime": "^1.0.0" + }, "publishConfig": { "access": "public" } diff --git a/lib/node-logger/src/index.test.js b/lib/node-logger/src/index.test.js deleted file mode 100644 index e75e429f2f84..000000000000 --- a/lib/node-logger/src/index.test.js +++ /dev/null @@ -1,31 +0,0 @@ -import npmLog from 'npmlog'; -import { logger } from '.'; - -jest.mock('npmlog', () => ({ - info: jest.fn(), - warn: jest.fn(), - error: jest.fn(), -})); - -describe('node-logger', () => { - beforeEach(() => { - npmLog.info.mockReset(); - npmLog.warn.mockReset(); - npmLog.error.mockReset(); - }); - it('should have an info method', () => { - const message = 'information'; - logger.info(message); - expect(npmLog.info).toHaveBeenCalledWith('', message); - }); - it('should have a warn method', () => { - const message = 'warning message'; - logger.warn(message); - expect(npmLog.warn).toHaveBeenCalledWith('', message); - }); - it('should have an error method', () => { - const message = 'error message'; - logger.error(message); - expect(npmLog.error).toHaveBeenCalledWith('', message); - }); -}); diff --git a/lib/node-logger/src/index.test.ts b/lib/node-logger/src/index.test.ts new file mode 100644 index 000000000000..59cd0cfe86ed --- /dev/null +++ b/lib/node-logger/src/index.test.ts @@ -0,0 +1,34 @@ +import { info, warn, error } from 'npmlog'; +import { logger } from '.'; + +jest.mock('npmlog', () => ({ + info: jest.fn(), + warn: jest.fn(), + error: jest.fn(), +})); + +describe('node-logger', () => { + beforeEach(() => { + // This feels odd but TypeScript doesn't understand that the imported + // npmlog module is being wrapped by Jest so we are type casting here + // in order to be allowed to call Jest's mockReset() method. + ((info as any) as jest.MockInstance).mockReset(); + ((warn as any) as jest.MockInstance).mockReset(); + ((error as any) as jest.MockInstance).mockReset(); + }); + it('should have an info method', () => { + const message = 'information'; + logger.info(message); + expect(info).toHaveBeenCalledWith('', message); + }); + it('should have a warn method', () => { + const message = 'warning message'; + logger.warn(message); + expect(warn).toHaveBeenCalledWith('', message); + }); + it('should have an error method', () => { + const message = 'error message'; + logger.error(message); + expect(error).toHaveBeenCalledWith('', message); + }); +}); diff --git a/lib/node-logger/src/index.js b/lib/node-logger/src/index.ts similarity index 50% rename from lib/node-logger/src/index.js rename to lib/node-logger/src/index.ts index bd166aebf037..cb52a22eccc7 100644 --- a/lib/node-logger/src/index.js +++ b/lib/node-logger/src/index.ts @@ -13,8 +13,9 @@ export const colors = { }; export const logger = { - info: message => npmLog.info('', message), - warn: message => npmLog.warn('', message), - error: message => npmLog.error('', message), - trace: ({ message, time }) => npmLog.info(`${message} (${colors.purple(prettyTime(time))})`), + info: (message: string): void => npmLog.info('', message), + warn: (message: string): void => npmLog.warn('', message), + error: (message: string): void => npmLog.error('', message), + trace: ({ message, time }: { message: string; time: [number, number] }): void => + npmLog.info('', `${message} (${colors.purple(prettyTime(time))})`), }; diff --git a/lib/node-logger/tsconfig.json b/lib/node-logger/tsconfig.json new file mode 100644 index 000000000000..a24ec6393862 --- /dev/null +++ b/lib/node-logger/tsconfig.json @@ -0,0 +1,8 @@ +{ + "extends": "../../tsconfig.json", + "compilerOptions": { + "rootDir": "./src" + }, + "include": ["src/**/*"], + "exclude": ["src/**.test.ts"] +} diff --git a/yarn.lock b/yarn.lock index 8ae47fa2feb0..1b5940b41333 100644 --- a/yarn.lock +++ b/yarn.lock @@ -2369,6 +2369,11 @@ resolved "https://registry.yarnpkg.com/@types/node/-/node-6.14.2.tgz#40b3dbb1221c7d66802cbcc32fe3b85e54569c77" integrity sha512-JWB3xaVfsfnFY8Ofc9rTB/op0fqqTSqy4vBcVk1LuRJvta7KTX+D//fCkiTMeLGhdr2EbFZzQjC97gvmPilk9Q== +"@types/npmlog@^4.1.1": + version "4.1.1" + resolved "https://registry.yarnpkg.com/@types/npmlog/-/npmlog-4.1.1.tgz#b51cf39a6324a4ede17ef72dfa58a64fbefb39c7" + integrity sha512-uCZpakN0HrNsX+rZeXwCPByanpTN+dB3iApOrV4uggG955GZOw1YVziEpH6YDE60/+H95Jztg48UQ0NGZ6TPag== + "@types/parse5@^2.2.32": version "2.2.34" resolved "https://registry.yarnpkg.com/@types/parse5/-/parse5-2.2.34.tgz#e3870a10e82735a720f62d71dcd183ba78ef3a9d" @@ -2376,6 +2381,11 @@ dependencies: "@types/node" "*" +"@types/pretty-hrtime@^1.0.0": + version "1.0.0" + resolved "https://registry.yarnpkg.com/@types/pretty-hrtime/-/pretty-hrtime-1.0.0.tgz#c5a2d644a135e988b2932f99737e67b3c62528d0" + integrity sha512-xl+5r2rcrxdLViAYkkiLMYsoUs3qEyrAnHFyEzYysgRxdVp3WbhysxIvJIxZp9FvZ2CYezh0TaHZorivH+voOQ== + "@types/prop-types@*", "@types/prop-types@^15.5.7": version "15.5.8" resolved "https://registry.yarnpkg.com/@types/prop-types/-/prop-types-15.5.8.tgz#8ae4e0ea205fe95c3901a5a1df7f66495e3a56ce"