Skip to content

Commit

Permalink
build: add cjs module as rollup output (#174)
Browse files Browse the repository at this point in the history
chore: update package json to expose both es and cjs

fix: use main&module instead of exports

Co-authored-by: confidence-bot <[email protected]>
  • Loading branch information
nicklasl and confidence-bot authored Aug 20, 2024
1 parent 8d44347 commit 5cc01b6
Show file tree
Hide file tree
Showing 9 changed files with 162 additions and 23 deletions.
10 changes: 9 additions & 1 deletion examples/nodeCJS/src/index.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
const { OpenFeature } = require('@openfeature/server-sdk');
const { Confidence } = require('@spotify-confidence/sdk');
const { createConfidenceServerProvider } = require('@spotify-confidence/openfeature-server-provider');

if (!process.env.CLIENT_SECRET) {
console.log('CLIENT_SECRET is not set inb .env');
Expand All @@ -13,8 +15,11 @@ async function main() {
region: 'eu',
fetchImplementation: fetch,
timeout: 1000,
environment: 'backend',
});

const provider = createConfidenceServerProvider(confidence);

OpenFeature.setProvider(provider);

const client = OpenFeature.getClient();
Expand All @@ -24,6 +29,9 @@ async function main() {
targetingKey: `user-${Math.random()}`,
})
.then(result => {
console.log('result:', result);
console.log('result from open feature:', result);
});

const fe = await confidence.withContext({ targeting_key: 'user-a' }).evaluateFlag('web-sdk-e2e-flag.int', 0);
console.log('from confidence API: ', fe);
}
1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@
"@commitlint/cz-commitlint": "^17.6.7",
"@commitlint/prompt-cli": "^17.6.7",
"@microsoft/api-extractor": "^7.43.1",
"@rollup/plugin-commonjs": "^26.0.1",
"@rollup/plugin-node-resolve": "^15.2.3",
"@rollup/plugin-swc": "^0.3.0",
"@spotify/eslint-config-base": "^15.0.0",
Expand Down
7 changes: 4 additions & 3 deletions packages/openfeature-server-provider/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@
"name": "@spotify-confidence/openfeature-server-provider",
"license": "Apache-2.0",
"version": "0.2.10",
"type": "module",
"types": "build/types/index.d.ts",
"devDependencies": {
"@microsoft/api-extractor": "7.43.1",
Expand All @@ -19,7 +18,8 @@
"registry": "https://registry.npmjs.org/",
"access": "public",
"types": "dist/index.d.ts",
"main": "dist/index.js"
"main": "dist/index.cjs.js",
"module": "dist/index.esm.js"
},
"scripts": {
"build": "tsc -b",
Expand All @@ -29,5 +29,6 @@
"files": [
"dist/index.*"
],
"main": "dist/index.js"
"main": "dist/index.cjs.js",
"module": "dist/index.esm.js"
}
7 changes: 4 additions & 3 deletions packages/openfeature-web-provider/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@
"name": "@spotify-confidence/openfeature-web-provider",
"license": "Apache-2.0",
"version": "0.2.10",
"type": "module",
"types": "build/types/index.d.ts",
"dependencies": {
"fast-deep-equal": "^3.1.3"
Expand All @@ -22,7 +21,8 @@
"registry": "https://registry.npmjs.org/",
"access": "public",
"types": "dist/index.d.ts",
"main": "dist/index.js"
"main": "dist/index.cjs.js",
"module": "dist/index.esm.js"
},
"scripts": {
"build": "tsc -b",
Expand All @@ -32,5 +32,6 @@
"files": [
"dist/index.*"
],
"main": "dist/index.js"
"main": "dist/index.cjs.js",
"module": "dist/index.esm.js"
}
7 changes: 4 additions & 3 deletions packages/react/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,8 @@
"registry": "https://registry.npmjs.org/",
"access": "public",
"types": "dist/index.d.ts",
"main": "dist/index.js"
"main": "dist/index.cjs.js",
"module": "dist/index.esm.js"
},
"peerDependencies": {
"@spotify-confidence/sdk": "^0.1.4",
Expand All @@ -31,6 +32,6 @@
"react": "^18.2.0",
"rollup": "4.14.2"
},
"type": "module",
"main": "dist/index.js"
"main": "dist/index.cjs.js",
"module": "dist/index.esm.js"
}
7 changes: 4 additions & 3 deletions packages/sdk/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,8 @@
"registry": "https://registry.npmjs.org/",
"access": "public",
"types": "dist/index.d.ts",
"main": "dist/index.js"
"main": "dist/index.cjs.js",
"module": "dist/index.esm.js"
},
"dependencies": {
"web-vitals": "^3.5.2"
Expand All @@ -31,6 +32,6 @@
"rollup": "4.14.2",
"ts-proto": "^1.171.0"
},
"type": "module",
"main": "dist/index.js"
"main": "dist/index.cjs.js",
"module": "dist/index.esm.js"
}
22 changes: 16 additions & 6 deletions rollup.base.mjs
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import { nodeResolve } from '@rollup/plugin-node-resolve';
import commonjs from '@rollup/plugin-commonjs';
import swc from '@rollup/plugin-swc';
import { readFileSync } from 'node:fs';
import { relative, resolve } from 'node:path';
Expand Down Expand Up @@ -26,14 +27,23 @@ export default {
console.log('include:', path);
return false;
},
output: {
file: 'dist/index.js',
format: 'es',
sourcemap: true,
generatedCode: 'es2015',
},
output: [
{
file: 'dist/index.esm.js',
format: 'es',
sourcemap: true,
generatedCode: 'es2015',
},
{
file: 'dist/index.cjs.js',
format: 'cjs',
sourcemap: true,
generatedCode: 'es2015',
},
],
plugins: [
nodeResolve(),
commonjs(),
swc({
swc: {
jsc: {
Expand Down
10 changes: 6 additions & 4 deletions yarn.config.cjs
Original file line number Diff line number Diff line change
Expand Up @@ -40,19 +40,21 @@ module.exports = defineConfig({
}

// package.json invariants
workspace.set('type', 'module');
workspace.set('main', 'dist/index.js');
workspace.unset('module');
workspace.set('main', 'dist/index.cjs.js');
workspace.set('module', 'dist/index.esm.js');
workspace.unset('type');
workspace.set('types', 'build/types/index.d.ts');
workspace.set('files', ['dist/index.*']);
workspace.set('scripts.build', 'tsc -b');
workspace.set('scripts.bundle', 'rollup -c && api-extractor run');
workspace.set('scripts.prepack', 'yarn build && yarn bundle');
workspace.unset('exports');
workspace.set('publishConfig', {
registry: 'https://registry.npmjs.org/',
access: 'public',
types: 'dist/index.d.ts',
main: 'dist/index.js',
main: 'dist/index.cjs.js',
module: 'dist/index.esm.js',
});
// dev deps that should all share the same version (from root package.json)
for (const id of ['@microsoft/api-extractor', 'rollup']) {
Expand Down
114 changes: 114 additions & 0 deletions yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -3002,6 +3002,13 @@ __metadata:
languageName: node
linkType: hard

"@jridgewell/sourcemap-codec@npm:^1.4.15":
version: 1.5.0
resolution: "@jridgewell/sourcemap-codec@npm:1.5.0"
checksum: 10c0/2eb864f276eb1096c3c11da3e9bb518f6d9fc0023c78344cdc037abadc725172c70314bdb360f2d4b7bffec7f5d657ce006816bc5d4ecb35e61b66132db00c18
languageName: node
linkType: hard

"@jridgewell/trace-mapping@npm:0.3.9":
version: 0.3.9
resolution: "@jridgewell/trace-mapping@npm:0.3.9"
Expand Down Expand Up @@ -3301,6 +3308,25 @@ __metadata:
languageName: node
linkType: hard

"@rollup/plugin-commonjs@npm:^26.0.1":
version: 26.0.1
resolution: "@rollup/plugin-commonjs@npm:26.0.1"
dependencies:
"@rollup/pluginutils": "npm:^5.0.1"
commondir: "npm:^1.0.1"
estree-walker: "npm:^2.0.2"
glob: "npm:^10.4.1"
is-reference: "npm:1.2.1"
magic-string: "npm:^0.30.3"
peerDependencies:
rollup: ^2.68.0||^3.0.0||^4.0.0
peerDependenciesMeta:
rollup:
optional: true
checksum: 10c0/483290d327bdb4147584c37d73e47df2c717735f1902cd2f66ebc83c7b40ae10e5a8d5e626f24b76ad4ac489eab4a8c13869410aad663810848b0abc89a630cf
languageName: node
linkType: hard

"@rollup/plugin-node-resolve@npm:^11.2.1":
version: 11.2.1
resolution: "@rollup/plugin-node-resolve@npm:11.2.1"
Expand Down Expand Up @@ -9312,6 +9338,22 @@ __metadata:
languageName: node
linkType: hard

"glob@npm:^10.4.1":
version: 10.4.5
resolution: "glob@npm:10.4.5"
dependencies:
foreground-child: "npm:^3.1.0"
jackspeak: "npm:^3.1.2"
minimatch: "npm:^9.0.4"
minipass: "npm:^7.1.2"
package-json-from-dist: "npm:^1.0.0"
path-scurry: "npm:^1.11.1"
bin:
glob: dist/esm/bin.mjs
checksum: 10c0/19a9759ea77b8e3ca0a43c2f07ecddc2ad46216b786bb8f993c445aee80d345925a21e5280c7b7c6c59e860a0154b84e4b2b60321fea92cd3c56b4a7489f160e
languageName: node
linkType: hard

"global-dirs@npm:^0.1.1":
version: 0.1.1
resolution: "global-dirs@npm:0.1.1"
Expand Down Expand Up @@ -10291,6 +10333,15 @@ __metadata:
languageName: node
linkType: hard

"is-reference@npm:1.2.1":
version: 1.2.1
resolution: "is-reference@npm:1.2.1"
dependencies:
"@types/estree": "npm:*"
checksum: 10c0/7dc819fc8de7790264a0a5d531164f9f5b9ef5aa1cd05f35322d14db39c8a2ec78fd5d4bf57f9789f3ddd2b3abeea7728432b759636157a42db12a9e8c3b549b
languageName: node
linkType: hard

"is-regex@npm:^1.1.4":
version: 1.1.4
resolution: "is-regex@npm:1.1.4"
Expand Down Expand Up @@ -10569,6 +10620,19 @@ __metadata:
languageName: node
linkType: hard

"jackspeak@npm:^3.1.2":
version: 3.4.2
resolution: "jackspeak@npm:3.4.2"
dependencies:
"@isaacs/cliui": "npm:^8.0.2"
"@pkgjs/parseargs": "npm:^0.11.0"
dependenciesMeta:
"@pkgjs/parseargs":
optional: true
checksum: 10c0/31952961f4d0d51831b8973db5c800233dc0f2181c3ca74af96f02cdc5c3f2b3df147a9ce2b56a643bd459036d782fb8c59f8992658d2bb4564753c42bb80c6c
languageName: node
linkType: hard

"jake@npm:^10.8.5":
version: 10.8.7
resolution: "jake@npm:10.8.7"
Expand Down Expand Up @@ -12220,6 +12284,13 @@ __metadata:
languageName: node
linkType: hard

"lru-cache@npm:^10.2.0":
version: 10.4.3
resolution: "lru-cache@npm:10.4.3"
checksum: 10c0/ebd04fbca961e6c1d6c0af3799adcc966a1babe798f685bb84e6599266599cd95d94630b10262f5424539bc4640107e8a33aa28585374abf561d30d16f4b39fb
languageName: node
linkType: hard

"lru-cache@npm:^5.1.1":
version: 5.1.1
resolution: "lru-cache@npm:5.1.1"
Expand Down Expand Up @@ -12263,6 +12334,15 @@ __metadata:
languageName: node
linkType: hard

"magic-string@npm:^0.30.3":
version: 0.30.10
resolution: "magic-string@npm:0.30.10"
dependencies:
"@jridgewell/sourcemap-codec": "npm:^1.4.15"
checksum: 10c0/aa9ca17eae571a19bce92c8221193b6f93ee8511abb10f085e55ffd398db8e4c089a208d9eac559deee96a08b7b24d636ea4ab92f09c6cf42a7d1af51f7fd62b
languageName: node
linkType: hard

"make-dir@npm:^3.0.2, make-dir@npm:^3.1.0":
version: 3.1.0
resolution: "make-dir@npm:3.1.0"
Expand Down Expand Up @@ -12515,6 +12595,15 @@ __metadata:
languageName: node
linkType: hard

"minimatch@npm:^9.0.4":
version: 9.0.5
resolution: "minimatch@npm:9.0.5"
dependencies:
brace-expansion: "npm:^2.0.1"
checksum: 10c0/de96cf5e35bdf0eab3e2c853522f98ffbe9a36c37797778d2665231ec1f20a9447a7e567cb640901f89e4daaa95ae5d70c65a9e8aa2bb0019b6facbc3c0575ed
languageName: node
linkType: hard

"minimatch@npm:~3.0.3":
version: 3.0.8
resolution: "minimatch@npm:3.0.8"
Expand Down Expand Up @@ -12630,6 +12719,13 @@ __metadata:
languageName: node
linkType: hard

"minipass@npm:^7.1.2":
version: 7.1.2
resolution: "minipass@npm:7.1.2"
checksum: 10c0/b0fd20bb9fb56e5fa9a8bfac539e8915ae07430a619e4b86ff71f5fc757ef3924b23b2c4230393af1eda647ed3d75739e4e0acb250a6b1eb277cf7f8fe449557
languageName: node
linkType: hard

"minizlib@npm:^2.1.1, minizlib@npm:^2.1.2":
version: 2.1.2
resolution: "minizlib@npm:2.1.2"
Expand Down Expand Up @@ -13231,6 +13327,13 @@ __metadata:
languageName: node
linkType: hard

"package-json-from-dist@npm:^1.0.0":
version: 1.0.0
resolution: "package-json-from-dist@npm:1.0.0"
checksum: 10c0/e3ffaf6ac1040ab6082a658230c041ad14e72fabe99076a2081bb1d5d41210f11872403fc09082daf4387fc0baa6577f96c9c0e94c90c394fd57794b66aa4033
languageName: node
linkType: hard

"param-case@npm:^3.0.4":
version: 3.0.4
resolution: "param-case@npm:3.0.4"
Expand Down Expand Up @@ -13347,6 +13450,16 @@ __metadata:
languageName: node
linkType: hard

"path-scurry@npm:^1.11.1":
version: 1.11.1
resolution: "path-scurry@npm:1.11.1"
dependencies:
lru-cache: "npm:^10.2.0"
minipass: "npm:^5.0.0 || ^6.0.2 || ^7.0.0"
checksum: 10c0/32a13711a2a505616ae1cc1b5076801e453e7aae6ac40ab55b388bb91b9d0547a52f5aaceff710ea400205f18691120d4431e520afbe4266b836fadede15872d
languageName: node
linkType: hard

"path-to-regexp@npm:0.1.7":
version: 0.1.7
resolution: "path-to-regexp@npm:0.1.7"
Expand Down Expand Up @@ -15314,6 +15427,7 @@ __metadata:
"@commitlint/cz-commitlint": "npm:^17.6.7"
"@commitlint/prompt-cli": "npm:^17.6.7"
"@microsoft/api-extractor": "npm:^7.43.1"
"@rollup/plugin-commonjs": "npm:^26.0.1"
"@rollup/plugin-node-resolve": "npm:^15.2.3"
"@rollup/plugin-swc": "npm:^0.3.0"
"@spotify/eslint-config-base": "npm:^15.0.0"
Expand Down

0 comments on commit 5cc01b6

Please sign in to comment.