-
Notifications
You must be signed in to change notification settings - Fork 18
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
feat: rollup cloudflare sdk #279
Changes from 8 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 |
---|---|---|
@@ -0,0 +1,6 @@ | ||
#!/usr/bin/env bash | ||
|
||
rm -rf node_modules/@launchdarkly | ||
mkdir -p node_modules/@launchdarkly | ||
rsync -aq ../dist node_modules/@launchdarkly/cloudflare-server-sdk | ||
rsync -aq ../package.json node_modules/@launchdarkly/cloudflare-server-sdk |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -5,7 +5,7 @@ | |
"module": "./dist/index.mjs", | ||
"packageManager": "[email protected]", | ||
"dependencies": { | ||
"@launchdarkly/cloudflare-server-sdk": "^2.0.2" | ||
"@launchdarkly/cloudflare-server-sdk": "^2.1.4" | ||
}, | ||
"devDependencies": { | ||
"@cloudflare/workers-types": "^4.20230321.0", | ||
|
@@ -20,9 +20,10 @@ | |
"wrangler": "2.20.1" | ||
}, | ||
"scripts": { | ||
"build": "node build.js", | ||
"build": "yarn link-dev && node build.js", | ||
"start": "wrangler dev", | ||
"deploy": "wrangler publish", | ||
"test": "yarn build && node --experimental-vm-modules --no-warnings node_modules/jest/bin/jest.js" | ||
"test": "yarn build && jest", | ||
"link-dev": "./link-dev.sh" | ||
} | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -4,7 +4,8 @@ export default { | |
async fetch(request: Request, env: Bindings): Promise<Response> { | ||
const sdkKey = 'test-sdk-key'; | ||
const flagKey = 'testFlag1'; | ||
const context = { kind: 'user', key: 'test-user-key-1', email: '[email protected]' }; | ||
// gmail will return false, other emails return true | ||
const context = { kind: 'user', key: 'test-user-key-1', email: '[email protected]' }; | ||
|
||
// start using ld | ||
const client = initLD(sdkKey, env.LD_KV); | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -17,34 +17,42 @@ | |
], | ||
"type": "module", | ||
"exports": { | ||
"require": "./dist/cjs/src/index.js", | ||
"import": "./dist/esm/src/index.js" | ||
"types": "./dist/index.d.ts", | ||
"import": "./dist/esm/src/index.js", | ||
"require": "./dist/cjs/src/index.js" | ||
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.
|
||
}, | ||
"main": "./dist/cjs/src/index.js", | ||
"types": "./dist/cjs/src/index.d.ts", | ||
"types": "./dist/index.d.ts", | ||
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 moved typings one level up so we have 1 copy to share now between cjs and esm. |
||
"files": [ | ||
"dist" | ||
], | ||
"scripts": { | ||
"build": "../../../scripts/build-package.sh", | ||
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. We no longer need to create sub package.jsons because it is now bundled with the sdk. |
||
"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" | ||
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", | ||
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", | ||
"@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", | ||
|
@@ -55,11 +63,18 @@ | |
"eslint-plugin-prettier": "^5.0.0", | ||
"jest": "^29.5.0", | ||
"launchdarkly-js-test-helpers": "^2.2.0", | ||
"load-json-file": "^7.0.1", | ||
"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" | ||
"typescript": "5.1.6", | ||
"write-json-file": "^5.0.0" | ||
} | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,84 @@ | ||
/* eslint-disable import/no-extraneous-dependencies */ | ||
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 { loadJsonFileSync } from 'load-json-file'; | ||
import { OutputOptions } from 'rollup'; | ||
import dts from 'rollup-plugin-dts'; | ||
import esbuild from 'rollup-plugin-esbuild'; | ||
import filesize from 'rollup-plugin-filesize'; | ||
import { writeJsonFileSync } from 'write-json-file'; | ||
|
||
const cjsIndex = 'dist/cjs/src/index.js'; | ||
const cjsPackageJson = 'dist/cjs/package.json'; | ||
const esmIndex = 'dist/esm/src/index.js'; | ||
const esmPackageJson = 'dist/esm/package.json'; | ||
|
||
function injectPackageJson() { | ||
yusinto marked this conversation as resolved.
Show resolved
Hide resolved
|
||
return { | ||
name: 'inject-package-json', | ||
generateBundle({ format }: OutputOptions) { | ||
const { name, version } = loadJsonFileSync('package.json') as any; | ||
const minimalPackageJson = { | ||
name, | ||
version, | ||
type: format === 'cjs' ? 'commonjs' : 'module', | ||
}; | ||
|
||
const packageJsonPath = format === 'cjs' ? cjsPackageJson : esmPackageJson; | ||
writeJsonFileSync(packageJsonPath, minimalPackageJson, { | ||
indent: 2, | ||
}); | ||
}, | ||
}; | ||
} | ||
|
||
const plugins = [ | ||
resolve(), | ||
commonjs(), | ||
esbuild(), | ||
json(), | ||
terser(), | ||
filesize(), | ||
injectPackageJson(), | ||
]; | ||
|
||
// 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: 'src/index.ts', | ||
output: [ | ||
{ | ||
file: cjsIndex, | ||
format: 'cjs', | ||
sourcemap: true, | ||
}, | ||
], | ||
plugins, | ||
external, | ||
}, | ||
{ | ||
input: 'src/index.ts', | ||
output: [ | ||
{ | ||
file: esmIndex, | ||
format: 'esm', | ||
sourcemap: true, | ||
}, | ||
], | ||
plugins, | ||
external, | ||
}, | ||
{ | ||
input: 'src/index.ts', | ||
plugins: [dts(), json()], | ||
output: { | ||
file: 'dist/index.d.ts', | ||
format: 'es', | ||
}, | ||
}, | ||
]; |
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.
I think it would be better to use email addresses that did not involve trademarks.
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.
Done.