Skip to content

Commit 90250cc

Browse files
committed
update
1 parent a2b9a57 commit 90250cc

3 files changed

Lines changed: 36 additions & 12 deletions

File tree

.github/workflows/javascript.yml

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -46,16 +46,22 @@ jobs:
4646
runs-on: ubuntu-latest
4747
steps:
4848
- uses: actions/checkout@v3
49-
- name: Set up Node
49+
- name: Set up Node 20 (build)
5050
uses: actions/setup-node@v3
5151
with:
52-
node-version: '18'
52+
node-version: 20
5353
cache-dependency-path: ./package-lock.json
5454
cache: 'npm'
55-
- name: Run CommonJS example
55+
- name: Build and pack SDK
5656
run: |
5757
npm install
58-
npm run test-commonjs
58+
npm pack
59+
- name: Set up Node 18 (runtime test)
60+
uses: actions/setup-node@v3
61+
with:
62+
node-version: '18'
63+
- name: Run CommonJS example
64+
run: npm run test-commonjs -- --skip-build
5965

6066
integration_tests:
6167
uses: optimizely/javascript-sdk/.github/workflows/integration_test.yml@master

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -76,7 +76,7 @@
7676
"build:win": "npm run validate-platform-isolation && npm run genmsg && tsc && rolldown -c rolldown.config.mjs && copy dist\\index.browser.d.ts dist\\index.d.ts",
7777
"build-browser-umd": "tsc && rolldown -c rolldown.config.mjs -- --config-umd",
7878
"coveralls": "nyc --reporter=lcov npm test",
79-
"prepare": "npm run build",
79+
"prepack": "npm run build",
8080
"prepublishOnly": "npm test",
8181
"genmsg": "./scripts/generate-messages.js ./lib/message/error_message.ts ./lib/message/log_message.ts",
8282
"test-typescript": "node ./scripts/run-ts-example.js",

scripts/run-cjs-example.js

Lines changed: 25 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -53,16 +53,34 @@ function runQuiet(command, cwd) {
5353
}
5454
}
5555

56+
function findTarball() {
57+
const files = fs.readdirSync(rootDir).filter(f => f.startsWith('optimizely-optimizely-sdk-') && f.endsWith('.tgz'));
58+
if (files.length === 0) {
59+
console.error('No SDK tarball found. Run `npm pack` first.');
60+
process.exit(1);
61+
}
62+
return path.join(rootDir, files[0]);
63+
}
64+
5665
function main() {
66+
const skipBuild = process.argv.includes('--skip-build');
67+
5768
console.log('=== Building SDK and Running CommonJS Example ===\n');
5869

59-
console.log('Installing SDK dependencies...');
60-
run('npm install', rootDir);
70+
let tarballPath;
71+
72+
if (skipBuild) {
73+
console.log('Skipping build (--skip-build), using existing tarball...');
74+
tarballPath = findTarball();
75+
} else {
76+
console.log('Installing SDK dependencies...');
77+
run('npm install', rootDir);
6178

62-
console.log('\nPacking SDK tarball...');
63-
const packOutput = runQuiet('npm pack', rootDir);
64-
const tarballPath = path.join(rootDir, packOutput);
65-
console.log(`Created: ${packOutput}`);
79+
console.log('\nPacking SDK tarball...');
80+
const packOutput = runQuiet('npm pack', rootDir);
81+
tarballPath = path.join(rootDir, packOutput);
82+
console.log(`Created: ${packOutput}`);
83+
}
6684

6785
console.log('\nInstalling SDK tarball in cjs-example...');
6886
run(`npm install --no-save --no-package-lock ${tarballPath}`, exampleDir);
@@ -72,7 +90,7 @@ function main() {
7290

7391
console.log('\nCleaning up tarball...');
7492
fs.unlinkSync(tarballPath);
75-
console.log(`Removed: ${packOutput}`);
93+
console.log(`Removed: ${path.basename(tarballPath)}`);
7694

7795
console.log('\n=== Example completed successfully! ===\n');
7896
}

0 commit comments

Comments
 (0)