Skip to content

Commit be77640

Browse files
committed
fix: support complete bundling of python and JS packages
1 parent 9ffccea commit be77640

File tree

8 files changed

+1111
-63
lines changed

8 files changed

+1111
-63
lines changed

.github/workflows/release.yaml

Lines changed: 10 additions & 42 deletions
Original file line numberDiff line numberDiff line change
@@ -504,30 +504,13 @@ jobs:
504504
echo "All Python wheels:"
505505
ls -la python-wheels/
506506
507-
- name: Configure CodeArtifact for Gradle
507+
- name: Configure CodeArtifact for twine
508508
run: |
509-
# Get CodeArtifact authorization token
510-
export CODEARTIFACT_AUTH_TOKEN=$(aws codeartifact get-authorization-token \
511-
--domain $CODEARTIFACT_DOMAIN \
512-
--query authorizationToken --output text)
513-
514-
# Get repository endpoint
515-
export CODEARTIFACT_REPOSITORY_ENDPOINT=$(aws codeartifact get-repository-endpoint \
516-
--domain $CODEARTIFACT_DOMAIN \
517-
--repository $CODEARTIFACT_REPOSITORY \
518-
--format pypi --query repositoryEndpoint --output text)
519-
520-
echo "CODEARTIFACT_AUTH_TOKEN=$CODEARTIFACT_AUTH_TOKEN" >> $GITHUB_ENV
521-
echo "CODEARTIFACT_REPOSITORY_ENDPOINT=$CODEARTIFACT_REPOSITORY_ENDPOINT" >> $GITHUB_ENV
509+
aws codeartifact login --tool twine --domain $CODEARTIFACT_DOMAIN --repository $CODEARTIFACT_REPOSITORY
522510
523511
- name: Publish Python packages to CodeArtifact
524512
run: |
525-
twine upload --repository-url $CODEARTIFACT_REPOSITORY_ENDPOINT \
526-
--username aws --password $CODEARTIFACT_AUTH_TOKEN \
527-
python-wheels/*.whl
528-
env:
529-
CODEARTIFACT_AUTH_TOKEN: ${{ env.CODEARTIFACT_AUTH_TOKEN }}
530-
CODEARTIFACT_REPOSITORY_ENDPOINT: ${{ env.CODEARTIFACT_REPOSITORY_ENDPOINT }}
513+
twine upload python-wheels/*.whl
531514
532515
generate-js-packages:
533516
needs: [tag-release, generate-rust-binary]
@@ -555,29 +538,13 @@ jobs:
555538
role-session-name: superposition-release
556539
role-to-assume: ${{ secrets.AWS_ARTIFACT_ROLE }}
557540

558-
- name: Configure CodeArtifact for npm
559-
run: |
560-
# Get CodeArtifact authorization token
561-
export CODEARTIFACT_AUTH_TOKEN=$(aws codeartifact get-authorization-token \
562-
--domain $CODEARTIFACT_DOMAIN \
563-
--query authorizationToken --output text)
564-
565-
# Get repository endpoint
566-
export CODEARTIFACT_REPOSITORY_ENDPOINT=$(aws codeartifact get-repository-endpoint \
567-
--domain $CODEARTIFACT_DOMAIN \
568-
--repository $CODEARTIFACT_REPOSITORY \
569-
--format npm --query repositoryEndpoint --output text)
570-
571-
echo "CODEARTIFACT_AUTH_TOKEN=$CODEARTIFACT_AUTH_TOKEN" >> $GITHUB_ENV
572-
echo "CODEARTIFACT_REPOSITORY_ENDPOINT=$CODEARTIFACT_REPOSITORY_ENDPOINT" >> $GITHUB_ENV
573-
574-
# Configure npm to use CodeArtifact
575-
npm config set registry=$CODEARTIFACT_REPOSITORY_ENDPOINT
576-
npm config set //$CODEARTIFACT_REPOSITORY_ENDPOINT:_authToken=$CODEARTIFACT_AUTH_TOKEN
577-
578541
- uses: actions/setup-node@v4
579542
with:
580543
node-version: "20.0.0"
544+
545+
- name: Configure CodeArtifact for npm
546+
run: |
547+
aws codeartifact login --tool npm --domain $CODEARTIFACT_DOMAIN --repository $CODEARTIFACT_REPOSITORY
581548
582549
- name: Download all rust binary artifacts
583550
uses: actions/download-artifact@v4
@@ -594,6 +561,7 @@ jobs:
594561
- name: Extract and organize native libraries
595562
run: |
596563
# Extract all native libraries
564+
mkdir -p clients/javascript/bindings/native-lib
597565
for zip_file in rust-binaries/*.zip; do
598566
echo "Extracting $zip_file"
599567
zip_basename=$(basename "$zip_file" .zip)
@@ -607,7 +575,7 @@ jobs:
607575
filename=$(basename "$lib")
608576
extension="${filename##*.}"
609577
file="libsuperposition_core-$target_triple.$extension"
610-
cp "$lib" clients/javascript/bindings/$file
578+
cp "$lib" clients/javascript/bindings/native-lib/$file
611579
echo "Copied $file"
612580
done
613581
@@ -617,7 +585,7 @@ jobs:
617585
618586
# List what we have
619587
echo "Native libraries in bindings package:"
620-
ls -la clients/javascript/bindings
588+
ls -la clients/javascript/bindings/native-lib
621589
622590
- run: |
623591
cd clients/javascript/bindings
Lines changed: 26 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,38 +1,57 @@
11
{
22
"name": "@juspay/superposition-provider",
33
"version": "0.0.1",
4+
"type": "module",
45
"description": "OpenFeature provider for Superposition feature flags",
56
"main": "./dist/index.js",
7+
"module": "./dist/index.esm.js",
68
"types": "./dist/index.d.ts",
79
"repository": {
810
"type": "git",
911
"url": "https://github.com/juspay/superposition.git"
1012
},
1113
"scripts": {
12-
"build": "tsc",
14+
"prebuild": "node scripts/build-deps.js",
15+
"build": "rollup -c",
1316
"clean": "rimraf dist",
1417
"prepack": "npm run clean && npm run build",
1518
"test": "jest",
1619
"prepublishOnly": "npm --no-git-tag-version version $VERSION"
1720
},
21+
"peerDependencies": {
22+
"@openfeature/server-sdk": "^1.13.0"
23+
},
1824
"dependencies": {
19-
"@openfeature/server-sdk": "^1.13.0",
20-
"superposition-bindings": "file:../bindings",
21-
"superposition-sdk": "file:../sdk"
25+
"koffi": "^2.11.0",
26+
"tslib": "^2.6.2"
2227
},
2328
"devDependencies": {
29+
"@openfeature/server-sdk": "^1.13.0",
30+
"superposition-bindings": "file:../bindings",
31+
"superposition-sdk": "file:../sdk",
2432
"@types/jest": "^29.5.12",
2533
"jest": "^29.7.0",
2634
"ts-jest": "^29.1.1",
2735
"tslib": "^2.6.2",
2836
"typescript": "~5.2.2",
2937
"rimraf": "^5.0.0",
30-
"@types/node": "^20.0.0"
38+
"@types/node": "^20.0.0",
39+
"rollup": "^4.0.0",
40+
"@rollup/plugin-typescript": "^11.0.0",
41+
"@rollup/plugin-node-resolve": "^15.0.0",
42+
"@rollup/plugin-commonjs": "^25.0.0",
43+
"@rollup/plugin-json": "^6.0.0",
44+
"rollup-plugin-dts": "^6.0.0",
45+
"rollup-plugin-copy": "^3.5.0"
3146
},
3247
"engines": {
3348
"node": ">=18.0.0"
3449
},
3550
"files": [
36-
"dist/**/*"
51+
"dist/**/*"
52+
],
53+
"bundledDependencies": [
54+
"superposition-bindings",
55+
"superposition-sdk"
3756
]
38-
}
57+
}
Lines changed: 54 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,54 @@
1+
import typescript from '@rollup/plugin-typescript';
2+
import { nodeResolve } from '@rollup/plugin-node-resolve';
3+
import commonjs from '@rollup/plugin-commonjs';
4+
import json from '@rollup/plugin-json';
5+
import copy from 'rollup-plugin-copy';
6+
7+
const external = [
8+
'@openfeature/server-sdk',
9+
'fs',
10+
'path',
11+
'crypto',
12+
'http',
13+
'https',
14+
'url',
15+
'util',
16+
'stream',
17+
'events',
18+
'buffer',
19+
'os'
20+
];
21+
22+
export default {
23+
input: 'index.ts',
24+
output: [
25+
{
26+
file: 'dist/index.js',
27+
format: 'cjs',
28+
sourcemap: true,
29+
exports: 'auto'
30+
},
31+
{
32+
file: 'dist/index.esm.js',
33+
format: 'es',
34+
sourcemap: true
35+
}
36+
],
37+
external,
38+
plugins: [
39+
copy({
40+
targets: [
41+
{ src: '../bindings/native-lib/**/*', dest: 'dist/native-lib' }
42+
],
43+
hook: 'buildStart'
44+
}),
45+
nodeResolve({
46+
preferBuiltins: true
47+
}),
48+
commonjs(),
49+
json(),
50+
typescript({
51+
tsconfig: './tsconfig.json'
52+
})
53+
]
54+
};
Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
import { execSync } from 'child_process';
2+
import fs from 'fs';
3+
import path from 'path';
4+
5+
function buildDependencies() {
6+
console.log('Building dependencies...');
7+
8+
// Build SDK
9+
console.log('Building SDK...');
10+
execSync('cd ../sdk && npm run build', { stdio: 'inherit' });
11+
12+
// Build bindings
13+
console.log('Building bindings...');
14+
execSync('cd ../bindings && npm run build', { stdio: 'inherit' });
15+
16+
console.log('Dependencies built successfully!');
17+
}
18+
19+
function copyDependencies() {
20+
console.log('Copying dependencies to node_modules...');
21+
22+
// Ensure node_modules exists
23+
if (!fs.existsSync('node_modules')) {
24+
fs.mkdirSync('node_modules');
25+
}
26+
27+
// Copy built dependencies
28+
execSync('cp -r ../sdk/dist-cjs node_modules/superposition-sdk', { stdio: 'inherit' });
29+
execSync('cp -r ../bindings/dist node_modules/superposition-bindings', { stdio: 'inherit' });
30+
31+
console.log('Dependencies copied successfully!');
32+
}
33+
34+
buildDependencies();
35+
copyDependencies();

clients/javascript/open-feature-provider/tsconfig.json

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,14 @@
1515
"skipLibCheck": true,
1616
"forceConsistentCasingInFileNames": true,
1717
"resolveJsonModule": true,
18-
"moduleResolution": "node"
18+
"moduleResolution": "node",
19+
"paths": {
20+
"superposition-sdk": ["../sdk/dist-types"],
21+
"superposition-sdk/*": ["../sdk/dist-types/*"],
22+
"superposition-bindings": ["../bindings/dist"],
23+
"superposition-bindings/*": ["../bindings/dist/*"]
24+
},
25+
"baseUrl": "."
1926
},
2027
"include": [
2128
"*.ts"
@@ -24,4 +31,4 @@
2431
"node_modules",
2532
"dist"
2633
]
27-
}
34+
}

0 commit comments

Comments
 (0)