-
Notifications
You must be signed in to change notification settings - Fork 31
feat: rollup cloudflare sdk #279
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
0f2ba46
78e8d51
fd270f3
2cc5a86
f3f3ca2
d5e27e3
4200bc8
1410bf6
3f1f893
24878cb
1048e4a
30141a5
15a0ad1
e5f92bc
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,15 +1,22 @@ | ||
| import app from './index'; | ||
| import testData from './testData.json'; | ||
|
|
||
| test('variation true', async () => { | ||
| // arrange | ||
| const env = getMiniflareBindings(); | ||
| const { LD_KV } = env; | ||
| await LD_KV.put('LD-Env-test-sdk-key', JSON.stringify(testData)); | ||
| describe('test', () => { | ||
| let env: Bindings; | ||
|
|
||
| // act | ||
| const res = await app.fetch(new Request('http://localhost'), env); | ||
| beforeEach(async () => { | ||
| env = getMiniflareBindings(); | ||
| const { LD_KV } = env; | ||
| await LD_KV.put('LD-Env-test-sdk-key', JSON.stringify(testData)); | ||
| }); | ||
|
|
||
| // assert | ||
| expect(await res.text()).toContain('testFlag1: true'); | ||
| test('variation true', async () => { | ||
| const res = await app.fetch(new Request('http://localhost/?email=truemail'), env); | ||
| expect(await res.text()).toContain('testFlag1: true'); | ||
| }); | ||
|
|
||
| test('variation false', async () => { | ||
| const res = await app.fetch(new Request('http://localhost/?email=falsemail'), env); | ||
| expect(await res.text()).toContain('testFlag1: false'); | ||
| }); | ||
| }); |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -17,34 +17,43 @@ | |
| ], | ||
| "type": "module", | ||
| "exports": { | ||
| "require": "./dist/cjs/src/index.js", | ||
| "import": "./dist/esm/src/index.js" | ||
| "types": "./dist/index.d.ts", | ||
| "import": "./dist/esm/index.js", | ||
| "require": "./dist/cjs/index.js" | ||
| }, | ||
| "main": "./dist/cjs/src/index.js", | ||
| "types": "./dist/cjs/src/index.d.ts", | ||
| "main": "./dist/cjs/index.js", | ||
| "types": "./dist/index.d.ts", | ||
| "files": [ | ||
| "dist" | ||
| ], | ||
| "scripts": { | ||
| "build": "../../../scripts/build-package.sh", | ||
| "clean": "rimraf dist", | ||
| "rb": "rollup -c --configPlugin typescript", | ||
| "rbw": "yarn rb --watch", | ||
| "build": "yarn clean && yarn rb", | ||
| "tsw": "yarn tsc --watch", | ||
| "start": "rimraf dist && yarn tsw", | ||
| "lint": "eslint . --ext .ts", | ||
| "prettier": "prettier --write '**/*.@(js|ts|tsx|json|css)' --ignore-path ../../../.prettierignore", | ||
| "test": "NODE_OPTIONS=\"--experimental-vm-modules --no-warnings\" jest --ci --runInBand", | ||
| "coverage": "yarn test --coverage", | ||
| "check": "yarn prettier && yarn lint && yarn build && yarn test && yarn doc" | ||
|
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
|
||
| "check": "yarn prettier && yarn lint && yarn build && yarn test" | ||
| }, | ||
| "dependencies": { | ||
| "@cloudflare/workers-types": "^4.20230321.0", | ||
| "@launchdarkly/js-server-sdk-common-edge": "1.0.13", | ||
|
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. No longer a runtime dependency because all js-core deps are included in the bundle. |
||
| "crypto-js": "^4.1.1" | ||
| }, | ||
| "devDependencies": { | ||
| "@launchdarkly/js-server-sdk-common-edge": "1.0.13", | ||
| "@rollup/plugin-commonjs": "^25.0.4", | ||
| "@rollup/plugin-json": "^6.0.0", | ||
| "@rollup/plugin-node-resolve": "^15.2.1", | ||
| "@rollup/plugin-terser": "^0.4.3", | ||
| "@rollup/plugin-typescript": "^11.1.3", | ||
| "@trivago/prettier-plugin-sort-imports": "^4.1.1", | ||
| "@types/crypto-js": "^4.1.1", | ||
| "@types/jest": "^29.5.0", | ||
| "@types/rollup-plugin-generate-package-json": "^3.2.3", | ||
| "@typescript-eslint/eslint-plugin": "^6.1.0", | ||
| "@typescript-eslint/parser": "^6.1.0", | ||
| "eslint": "^8.45.0", | ||
|
|
@@ -57,9 +66,17 @@ | |
| "launchdarkly-js-test-helpers": "^2.2.0", | ||
| "miniflare": "^2.13.0", | ||
| "prettier": "^3.0.0", | ||
| "rimraf": "^5.0.0", | ||
| "rimraf": "^5.0.1", | ||
| "rollup": "^3.29.2", | ||
| "rollup-plugin-dts": "^6.0.2", | ||
| "rollup-plugin-esbuild": "^5.0.0", | ||
| "rollup-plugin-filesize": "^10.0.0", | ||
| "rollup-plugin-generate-package-json": "^3.2.0", | ||
| "ts-jest": "^29.1.0", | ||
| "typedoc": "0.25.0", | ||
| "typescript": "5.1.6" | ||
| } | ||
| }, | ||
| "bundledDependencies": [ | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Won't this cause an unused copy of this to be bundled in the tgz?
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I'm not sure, but I'll do a dry run and test.
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Looks like no with yarn pack. Maybe something we will want to check after publish.
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Looks like we're safe because npm notice === Tarball Contents ===
npm notice 556B LICENSE
npm notice 4.8kB README.md
npm notice 114.8kB dist/cjs/index.js
npm notice 475.6kB dist/cjs/index.js.map
npm notice 114.8kB dist/esm/index.js
npm notice 475.6kB dist/esm/index.js.map
npm notice 1.6kB dist/index.d.ts
npm notice 2.7kB package.json |
||
| "@launchdarkly/js-server-sdk-common-edge" | ||
| ] | ||
|
Comment on lines
+79
to
+81
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Fix eslint extraneous dep error by listing bundled js-core deps here. |
||
| } | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,53 @@ | ||
| import commonjs from '@rollup/plugin-commonjs'; | ||
| import json from '@rollup/plugin-json'; | ||
| import resolve from '@rollup/plugin-node-resolve'; | ||
| import terser from '@rollup/plugin-terser'; | ||
| import dts from 'rollup-plugin-dts'; | ||
| import esbuild from 'rollup-plugin-esbuild'; | ||
| import filesize from 'rollup-plugin-filesize'; | ||
|
|
||
| const inputPath = 'src/index.ts'; | ||
| const cjsPath = 'dist/cjs/index.js'; | ||
| const esmPath = 'dist/esm/index.js'; | ||
| const typingsPath = 'dist/index.d.ts'; | ||
|
|
||
| const plugins = [resolve(), commonjs(), esbuild(), json(), terser(), filesize()]; | ||
|
|
||
| // the second array item is a function to include all js-core packages in the bundle so they | ||
| // are not imported or required as separate npm packages | ||
| const external = [/node_modules/, (id: string) => !id.includes('js-core')]; | ||
|
|
||
| export default [ | ||
| { | ||
| input: inputPath, | ||
| output: [ | ||
| { | ||
| file: cjsPath, | ||
| format: 'cjs', | ||
| sourcemap: true, | ||
| }, | ||
| ], | ||
| plugins, | ||
| external, | ||
| }, | ||
| { | ||
| input: inputPath, | ||
| output: [ | ||
| { | ||
| file: esmPath, | ||
| format: 'esm', | ||
| sourcemap: true, | ||
| }, | ||
| ], | ||
| plugins, | ||
| external, | ||
| }, | ||
| { | ||
| input: inputPath, | ||
| plugins: [dts(), json()], | ||
| output: { | ||
| file: typingsPath, | ||
| format: 'esm', | ||
| }, | ||
| }, | ||
| ]; |
Uh oh!
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We no longer need to create sub package.jsons because it is now bundled with the sdk.