From c82067e74e264fecb06c1b618d0948f0bae5faa6 Mon Sep 17 00:00:00 2001 From: Ryan Lamb <4955475+kinyoklion@users.noreply.github.com> Date: Tue, 21 Mar 2023 13:48:29 -0700 Subject: [PATCH 1/3] build(deps): Update to js-client-sdk 3.1.2 (#98) --- package.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/package.json b/package.json index 604acec..4207f70 100644 --- a/package.json +++ b/package.json @@ -65,7 +65,7 @@ }, "dependencies": { "hoist-non-react-statics": "^3.3.2", - "launchdarkly-js-client-sdk": "^3.1.1", + "launchdarkly-js-client-sdk": "^3.1.2", "lodash.camelcase": "^4.3.0" }, "peerDependencies": { From 9a5be9456276eba38cf6682002b5a41732871a60 Mon Sep 17 00:00:00 2001 From: Yusinto Ngadiman Date: Thu, 30 Mar 2023 11:17:03 -0700 Subject: [PATCH 2/3] chore: Adding a typescript example (#99) * chore: initial commit * fix: ignore example tests --- examples/typescript/.gitignore | 25 ++++++++ examples/typescript/README.md | 72 ++++++++++++++++++++++ examples/typescript/package.json | 48 +++++++++++++++ examples/typescript/src/App.css | 38 ++++++++++++ examples/typescript/src/App.test.tsx | 9 +++ examples/typescript/src/App.tsx | 22 +++++++ examples/typescript/src/index.css | 13 ++++ examples/typescript/src/index.tsx | 28 +++++++++ examples/typescript/src/logo.svg | 1 + examples/typescript/src/react-app-env.d.ts | 1 + examples/typescript/src/reportWebVitals.ts | 15 +++++ examples/typescript/src/setupTests.ts | 5 ++ examples/typescript/tsconfig.json | 26 ++++++++ jest.config.js | 1 + link-dev.sh | 2 +- 15 files changed, 305 insertions(+), 1 deletion(-) create mode 100644 examples/typescript/.gitignore create mode 100644 examples/typescript/README.md create mode 100644 examples/typescript/package.json create mode 100644 examples/typescript/src/App.css create mode 100644 examples/typescript/src/App.test.tsx create mode 100644 examples/typescript/src/App.tsx create mode 100644 examples/typescript/src/index.css create mode 100644 examples/typescript/src/index.tsx create mode 100644 examples/typescript/src/logo.svg create mode 100644 examples/typescript/src/react-app-env.d.ts create mode 100644 examples/typescript/src/reportWebVitals.ts create mode 100644 examples/typescript/src/setupTests.ts create mode 100644 examples/typescript/tsconfig.json diff --git a/examples/typescript/.gitignore b/examples/typescript/.gitignore new file mode 100644 index 0000000..7558f02 --- /dev/null +++ b/examples/typescript/.gitignore @@ -0,0 +1,25 @@ +# See https://help.github.com/articles/ignoring-files/ for more about ignoring files. + +# dependencies +/node_modules +/.pnp +.pnp.js + +# testing +/coverage + +# production +/build + +# misc +.DS_Store +.env.local +.env.development.local +.env.test.local +.env.production.local + +npm-debug.log* +yarn-debug.log* +yarn-error.log* + +public diff --git a/examples/typescript/README.md b/examples/typescript/README.md new file mode 100644 index 0000000..7c5e905 --- /dev/null +++ b/examples/typescript/README.md @@ -0,0 +1,72 @@ +# LaunchDarkly SDK for React - Example typescript app + +This is a CRA typescript app demonstrating `launchdarkly-react-client-sdk`. + +## Running the typescript example + +Follow these steps to run the app: + +* Create a `.env.local` file and set your clientSideID there like so: + + ```shell + REACT_APP_LD_CLIENT_SIDE_ID=xxx + ``` + +* Create a flag called `dev-test-flag` in your project. Make sure you + make the flag available to the client-side SDK. + +* You should now be able to start the app by doing: + + ```sh + yarn && yarn start + ``` + +* Toggle the killswitch for `dev-test-flag` in the dashboard and the + app should respond without a browser refresh. + +# Getting Started with Create React App + +This project was bootstrapped with [Create React App](https://github.com/facebook/create-react-app). + +## Available Scripts + +In the project directory, you can run: + +### `npm start` + +Runs the app in the development mode.\ +Open [http://localhost:3000](http://localhost:3000) to view it in the browser. + +The page will reload if you make edits.\ +You will also see any lint errors in the console. + +### `npm test` + +Launches the test runner in the interactive watch mode.\ +See the section about [running tests](https://facebook.github.io/create-react-app/docs/running-tests) for more information. + +### `npm run build` + +Builds the app for production to the `build` folder.\ +It correctly bundles React in production mode and optimizes the build for the best performance. + +The build is minified and the filenames include the hashes.\ +Your app is ready to be deployed! + +See the section about [deployment](https://facebook.github.io/create-react-app/docs/deployment) for more information. + +### `npm run eject` + +**Note: this is a one-way operation. Once you `eject`, you can’t go back!** + +If you aren’t satisfied with the build tool and configuration choices, you can `eject` at any time. This command will remove the single build dependency from your project. + +Instead, it will copy all the configuration files and the transitive dependencies (webpack, Babel, ESLint, etc) right into your project so you have full control over them. All of the commands except `eject` will still work, but they will point to the copied scripts so you can tweak them. At this point you’re on your own. + +You don’t have to ever use `eject`. The curated feature set is suitable for small and middle deployments, and you shouldn’t feel obligated to use this feature. However we understand that this tool wouldn’t be useful if you couldn’t customize it when you are ready for it. + +## Learn More + +You can learn more in the [Create React App documentation](https://facebook.github.io/create-react-app/docs/getting-started). + +To learn React, check out the [React documentation](https://reactjs.org/). diff --git a/examples/typescript/package.json b/examples/typescript/package.json new file mode 100644 index 0000000..e4811f4 --- /dev/null +++ b/examples/typescript/package.json @@ -0,0 +1,48 @@ +{ + "name": "typescript", + "version": "0.1.0", + "private": true, + "dependencies": { + "@testing-library/jest-dom": "^5.16.5", + "@testing-library/react": "^13.4.0", + "@testing-library/user-event": "^13.5.0", + "@types/jest": "^27.5.2", + "@types/node": "^16.18.18", + "@types/react": "^18.0.28", + "@types/react-dom": "^18.0.11", + "launchdarkly-react-client-sdk": "^3.0.4", + "react": "^18.2.0", + "react-dom": "^18.2.0", + "react-scripts": "5.0.1", + "typescript": "^4.9.5", + "web-vitals": "^2.1.4" + }, + "scripts": { + "analyze": "source-map-explorer 'build/static/js/*.js'", + "start": "react-scripts start", + "build": "react-scripts build", + "test": "react-scripts test", + "eject": "react-scripts eject" + }, + "eslintConfig": { + "extends": [ + "react-app", + "react-app/jest" + ] + }, + "browserslist": { + "production": [ + ">0.2%", + "not dead", + "not op_mini all" + ], + "development": [ + "last 1 chrome version", + "last 1 firefox version", + "last 1 safari version" + ] + }, + "devDependencies": { + "source-map-explorer": "2.5.3" + } +} diff --git a/examples/typescript/src/App.css b/examples/typescript/src/App.css new file mode 100644 index 0000000..74b5e05 --- /dev/null +++ b/examples/typescript/src/App.css @@ -0,0 +1,38 @@ +.App { + text-align: center; +} + +.App-logo { + height: 40vmin; + pointer-events: none; +} + +@media (prefers-reduced-motion: no-preference) { + .App-logo { + animation: App-logo-spin infinite 20s linear; + } +} + +.App-header { + background-color: #282c34; + min-height: 100vh; + display: flex; + flex-direction: column; + align-items: center; + justify-content: center; + font-size: calc(10px + 2vmin); + color: white; +} + +.App-link { + color: #61dafb; +} + +@keyframes App-logo-spin { + from { + transform: rotate(0deg); + } + to { + transform: rotate(360deg); + } +} diff --git a/examples/typescript/src/App.test.tsx b/examples/typescript/src/App.test.tsx new file mode 100644 index 0000000..2a68616 --- /dev/null +++ b/examples/typescript/src/App.test.tsx @@ -0,0 +1,9 @@ +import React from 'react'; +import { render, screen } from '@testing-library/react'; +import App from './App'; + +test('renders learn react link', () => { + render(); + const linkElement = screen.getByText(/learn react/i); + expect(linkElement).toBeInTheDocument(); +}); diff --git a/examples/typescript/src/App.tsx b/examples/typescript/src/App.tsx new file mode 100644 index 0000000..5453558 --- /dev/null +++ b/examples/typescript/src/App.tsx @@ -0,0 +1,22 @@ +import React from 'react'; +import logo from './logo.svg'; +import './App.css'; +import { useFlags } from 'launchdarkly-react-client-sdk'; + +function App() { + const { devTestFlag } = useFlags(); + + return ( +
+
+ logo +

{devTestFlag ? Flag on : Flag off}

+ + Learn React + +
+
+ ); +} + +export default App; diff --git a/examples/typescript/src/index.css b/examples/typescript/src/index.css new file mode 100644 index 0000000..ec2585e --- /dev/null +++ b/examples/typescript/src/index.css @@ -0,0 +1,13 @@ +body { + margin: 0; + font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', 'Roboto', 'Oxygen', + 'Ubuntu', 'Cantarell', 'Fira Sans', 'Droid Sans', 'Helvetica Neue', + sans-serif; + -webkit-font-smoothing: antialiased; + -moz-osx-font-smoothing: grayscale; +} + +code { + font-family: source-code-pro, Menlo, Monaco, Consolas, 'Courier New', + monospace; +} diff --git a/examples/typescript/src/index.tsx b/examples/typescript/src/index.tsx new file mode 100644 index 0000000..cf2f641 --- /dev/null +++ b/examples/typescript/src/index.tsx @@ -0,0 +1,28 @@ +import React from 'react'; +import ReactDOM from 'react-dom/client'; +import './index.css'; +import App from './App'; +import reportWebVitals from './reportWebVitals'; +import { asyncWithLDProvider } from 'launchdarkly-react-client-sdk'; + +(async () => { + // Set clientSideID to your own Client-side ID. You can find this in + // your LaunchDarkly portal under Account settings / Projects + const LDProvider = await asyncWithLDProvider({ + clientSideID: process.env.REACT_APP_LD_CLIENT_SIDE_ID ?? '', + }); + + const root = ReactDOM.createRoot(document.getElementById('root') as HTMLElement); + root.render( + + + + + , + ); + + // If you want to start measuring performance in your app, pass a function + // to log results (for example: reportWebVitals(console.log)) + // or send to an analytics endpoint. Learn more: https://bit.ly/CRA-vitals + reportWebVitals(); +})(); diff --git a/examples/typescript/src/logo.svg b/examples/typescript/src/logo.svg new file mode 100644 index 0000000..9dfc1c0 --- /dev/null +++ b/examples/typescript/src/logo.svg @@ -0,0 +1 @@ + \ No newline at end of file diff --git a/examples/typescript/src/react-app-env.d.ts b/examples/typescript/src/react-app-env.d.ts new file mode 100644 index 0000000..6431bc5 --- /dev/null +++ b/examples/typescript/src/react-app-env.d.ts @@ -0,0 +1 @@ +/// diff --git a/examples/typescript/src/reportWebVitals.ts b/examples/typescript/src/reportWebVitals.ts new file mode 100644 index 0000000..49a2a16 --- /dev/null +++ b/examples/typescript/src/reportWebVitals.ts @@ -0,0 +1,15 @@ +import { ReportHandler } from 'web-vitals'; + +const reportWebVitals = (onPerfEntry?: ReportHandler) => { + if (onPerfEntry && onPerfEntry instanceof Function) { + import('web-vitals').then(({ getCLS, getFID, getFCP, getLCP, getTTFB }) => { + getCLS(onPerfEntry); + getFID(onPerfEntry); + getFCP(onPerfEntry); + getLCP(onPerfEntry); + getTTFB(onPerfEntry); + }); + } +}; + +export default reportWebVitals; diff --git a/examples/typescript/src/setupTests.ts b/examples/typescript/src/setupTests.ts new file mode 100644 index 0000000..8f2609b --- /dev/null +++ b/examples/typescript/src/setupTests.ts @@ -0,0 +1,5 @@ +// jest-dom adds custom jest matchers for asserting on DOM nodes. +// allows you to do things like: +// expect(element).toHaveTextContent(/react/i) +// learn more: https://github.com/testing-library/jest-dom +import '@testing-library/jest-dom'; diff --git a/examples/typescript/tsconfig.json b/examples/typescript/tsconfig.json new file mode 100644 index 0000000..a273b0c --- /dev/null +++ b/examples/typescript/tsconfig.json @@ -0,0 +1,26 @@ +{ + "compilerOptions": { + "target": "es5", + "lib": [ + "dom", + "dom.iterable", + "esnext" + ], + "allowJs": true, + "skipLibCheck": true, + "esModuleInterop": true, + "allowSyntheticDefaultImports": true, + "strict": true, + "forceConsistentCasingInFileNames": true, + "noFallthroughCasesInSwitch": true, + "module": "esnext", + "moduleResolution": "node", + "resolveJsonModule": true, + "isolatedModules": true, + "noEmit": true, + "jsx": "react-jsx" + }, + "include": [ + "src" + ] +} diff --git a/jest.config.js b/jest.config.js index e07d7cb..b8a4e30 100644 --- a/jest.config.js +++ b/jest.config.js @@ -5,6 +5,7 @@ module.exports = { '\\.(ts|tsx)$': 'ts-jest', }, testRegex: '.*\\.test\\.(ts|tsx)$', + testPathIgnorePatterns: ['/node_modules/', '/examples/'], setupFilesAfterEnv: ['./setupTests.js'], testEnvironment: 'jest-environment-jsdom-global', }; diff --git a/link-dev.sh b/link-dev.sh index d0d0c35..7a8974e 100755 --- a/link-dev.sh +++ b/link-dev.sh @@ -11,7 +11,7 @@ rm -rf node_modules npm install --production echo "===== Linking to examples" -declare -a examples=(async-provider hoc) +declare -a examples=(async-provider hoc typescript) for example in "${examples[@]}" do From 8ca2fef28cc31e74aeae63075c23d392edeae88f Mon Sep 17 00:00:00 2001 From: Ryan Lamb <4955475+kinyoklion@users.noreply.github.com> Date: Wed, 12 Apr 2023 10:04:25 -0700 Subject: [PATCH 3/3] build(deps): Update js-client-sdk to 3.1.3. (#100) --- package.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/package.json b/package.json index 1c033d0..c6c4889 100644 --- a/package.json +++ b/package.json @@ -65,7 +65,7 @@ }, "dependencies": { "hoist-non-react-statics": "^3.3.2", - "launchdarkly-js-client-sdk": "^3.1.2", + "launchdarkly-js-client-sdk": "^3.1.3", "lodash.camelcase": "^4.3.0" }, "peerDependencies": {