From 45a0d2bf975e8e40cf09b76c79ea7f85e82e3b62 Mon Sep 17 00:00:00 2001 From: Harley Alexander Date: Fri, 16 Aug 2019 20:17:10 +1000 Subject: [PATCH] trying to get types working. --- README.md | 2 +- package.json | 11 +++++------ rollup.config.js | 7 ++++--- src/PusherProvider.tsx | 2 +- src/{index.tsx => index.ts} | 1 + src/useChannel.ts | 6 +----- tsconfig.json | 3 ++- yarn.lock | 14 ++++++++++++++ 8 files changed, 29 insertions(+), 17 deletions(-) rename src/{index.tsx => index.ts} (76%) diff --git a/README.md b/README.md index 770e14e..6068fef 100644 --- a/README.md +++ b/README.md @@ -7,7 +7,7 @@ ## Install ```bash -yarn add react-pusher-hooks +yarn add use-pusher ``` ## Usage diff --git a/package.json b/package.json index cc79aae..d7626b2 100644 --- a/package.json +++ b/package.json @@ -8,6 +8,7 @@ "main": "dist/index.js", "module": "dist/index.es.js", "jsnext:main": "dist/index.es.js", + "types": "./dist/index.d.ts", "engines": { "node": ">=8", "npm": ">=5" @@ -16,10 +17,7 @@ "test": "cross-env CI=1 react-scripts test --env=jsdom", "test:watch": "react-scripts test --env=jsdom", "build": "rollup -c", - "start": "rollup -c -w", - "prepare": "yarn run build", - "predeploy": "cd example && yarn install && yarn run build", - "deploy": "gh-pages -d example/build" + "start": "rollup -c -w" }, "dependencies": { "dequal": "^1.0.0", @@ -36,8 +34,6 @@ "@babel/preset-react": "^7.0.0", "@babel/runtime": "^7.3.1", "@testing-library/react": "^9.1.2", - "pusher-js": "^5.0.0", - "react-dom": "^16.8.6", "@testing-library/react-hooks": "^2.0.1", "@types/invariant": "^2.2.30", "@types/jest": "^23.3.13", @@ -46,13 +42,16 @@ "cross-env": "^5.2.0", "gh-pages": "^2.0.1", "jest-fetch-mock": "^2.1.2", + "pusher-js": "^5.0.0", "pusher-js-mock": "^0.2.0", "react": "^16.8.6", + "react-dom": "^16.8.6", "react-scripts": "^3.0.1", "react-test-renderer": "^16.9.0", "rollup": "^1.1.2", "rollup-plugin-babel": "^4.3.3", "rollup-plugin-commonjs": "^9.2.0", + "rollup-plugin-dts": "^1.1.6", "rollup-plugin-node-resolve": "^4.0.0", "rollup-plugin-peer-deps-external": "^2.2.0", "rollup-plugin-typescript2": "^0.19.2", diff --git a/rollup.config.js b/rollup.config.js index a4e02a6..a4819ac 100644 --- a/rollup.config.js +++ b/rollup.config.js @@ -1,3 +1,4 @@ +import dts from "rollup-plugin-dts"; import typescript from "rollup-plugin-typescript2"; import commonjs from "rollup-plugin-commonjs"; import external from "rollup-plugin-peer-deps-external"; @@ -8,7 +9,7 @@ import babel from "rollup-plugin-babel"; import pkg from "./package.json"; export default { - input: "src/index.tsx", + input: "src/index.ts", output: [ { file: pkg.main, @@ -31,12 +32,12 @@ export default { rollupCommonJSResolveHack: true, clean: true }), - babel({ extensions: [".tsx"], exclude: "node_modules/**", presets: ["@babel/env", "@babel/preset-react"] }), - commonjs() + commonjs(), + dts() ] }; diff --git a/src/PusherProvider.tsx b/src/PusherProvider.tsx index 046f43b..534382f 100644 --- a/src/PusherProvider.tsx +++ b/src/PusherProvider.tsx @@ -10,7 +10,7 @@ export const __PusherConsumer = __PusherContext.Consumer; /** * Provider for the pusher service in an app - * @param props + * @param props Config for Pusher client */ export function PusherProvider({ clientKey, diff --git a/src/index.tsx b/src/index.ts similarity index 76% rename from src/index.tsx rename to src/index.ts index 724821b..3f7c4cd 100644 --- a/src/index.tsx +++ b/src/index.ts @@ -1,3 +1,4 @@ export { PusherProvider } from "./PusherProvider"; export { useChannel } from "./useChannel"; export { useTrigger } from "./useTrigger"; +export { usePusher } from "./usePusher"; diff --git a/src/useChannel.ts b/src/useChannel.ts index 782298c..e69311e 100644 --- a/src/useChannel.ts +++ b/src/useChannel.ts @@ -10,11 +10,7 @@ import { useChannelOptions } from "./types"; * Subscribe to channel events * * @example - * useChannel( - * "my-channel", - * "my-event", - * (message) => console.log(message) - * ) + * */ export function useChannel( diff --git a/tsconfig.json b/tsconfig.json index 532afbf..d7bb81f 100644 --- a/tsconfig.json +++ b/tsconfig.json @@ -21,7 +21,8 @@ "allowSyntheticDefaultImports": true, "strict": true, "resolveJsonModule": true, - "isolatedModules": true, + "isolatedModules": false, + "declaration": true, "noEmit": true }, "include": ["src"], diff --git a/yarn.lock b/yarn.lock index 30fd364..3c83687 100644 --- a/yarn.lock +++ b/yarn.lock @@ -992,6 +992,13 @@ "@types/istanbul-reports" "^1.1.1" "@types/yargs" "^12.0.9" +"@michaelfoidl/barrel-dts@^1.0.2": + version "1.0.2" + resolved "https://registry.yarnpkg.com/@michaelfoidl/barrel-dts/-/barrel-dts-1.0.2.tgz#3a64e7527e9f3117bfd5ce99b0768e9b0a03ee81" + integrity sha512-dJB59S4Q0i8/zAr2xRwcDrF0c0fb3HCyGySr09wZPKXYFDz3JSa7aYsF74R+hCSzIp+Bm4SHQDIW8tRkssZ9yA== + dependencies: + commander "~2.20.0" + "@mrmlnc/readdir-enhanced@^2.2.1": version "2.2.1" resolved "https://registry.yarnpkg.com/@mrmlnc/readdir-enhanced/-/readdir-enhanced-2.2.1.tgz#524af240d1a360527b730475ecfa1344aa540dde" @@ -8834,6 +8841,13 @@ rollup-plugin-commonjs@^9.2.0: resolve "^1.10.0" rollup-pluginutils "^2.6.0" +rollup-plugin-dts@^1.1.6: + version "1.1.6" + resolved "https://registry.yarnpkg.com/rollup-plugin-dts/-/rollup-plugin-dts-1.1.6.tgz#dc081b62491aba5a200c566dd7d61b4cdc65f72b" + integrity sha512-CqrI0viXojw3ufqFyfJjoyM/zibcvBTr6Ky3BGK9jfuT79hn32PifLwusulC0z3TG0QW6tPfDCb3JI5EOaSjRg== + optionalDependencies: + "@babel/code-frame" "^7.5.5" + rollup-plugin-node-resolve@^4.0.0: version "4.2.4" resolved "https://registry.yarnpkg.com/rollup-plugin-node-resolve/-/rollup-plugin-node-resolve-4.2.4.tgz#7d370f8d6fd3031006a0032c38262dd9be3c6250"