Skip to content

Commit 98693ed

Browse files
committed
feat: Add more complex scenarios
1 parent d3d329b commit 98693ed

4 files changed

Lines changed: 140 additions & 28 deletions

File tree

internal/npm-integration-poc/package.json

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,18 +8,22 @@
88
"scenario:esm": "node scenarios/01-esm-integration.js",
99
"scenario:cjs": "node scenarios/02-cjs-integration.js",
1010
"scenario:webcomponents": "node scenarios/03-webcomponents-integration.js",
11-
"build:all": "npm run scenario:esm && npm run scenario:cjs && npm run scenario:webcomponents"
11+
"scenario:sinon": "node scenarios/04-complex-sinon.js",
12+
"scenario:axios": "node scenarios/05-transitive-axios.js",
13+
"build:all": "npm run scenario:esm && npm run scenario:cjs && npm run scenario:webcomponents && npm run scenario:sinon && npm run scenario:axios"
1214
},
1315
"dependencies": {
1416
"@rollup/plugin-commonjs": "^28.0.2",
1517
"@rollup/plugin-json": "^6.1.0",
1618
"@rollup/plugin-node-resolve": "^15.3.0",
1719
"@rollup/plugin-replace": "^6.0.1",
1820
"@rollup/plugin-terser": "^0.4.4",
21+
"axios": "^1.13.4",
1922
"lodash": "^4.17.23",
2023
"nanoid": "^5.1.6",
2124
"rollup": "^4.24.4",
22-
"rollup-plugin-polyfill-node": "^0.13.0"
25+
"rollup-plugin-polyfill-node": "^0.13.0",
26+
"sinon": "^21.0.1"
2327
},
2428
"devDependencies": {
2529
"@ui5/cli": "^5.0.0-alpha.2",
Lines changed: 51 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,51 @@
1+
/**
2+
* Scenario 4: Complex NPM - sinon (Testing Library)
3+
*
4+
* Demonstrates bundling a complex NPM package with multiple internal dependencies.
5+
* Sinon is a testing library that includes spies, stubs, mocks, and fake timers.
6+
* It has several internal dependencies that all get bundled together.
7+
*/
8+
9+
import {
10+
createRollupConfig,
11+
generateAMDBundle,
12+
writeScenarioOutput,
13+
printBundleInfo,
14+
printScenarioHeader
15+
} from "./shared-config.js";
16+
17+
printScenarioHeader(4, "Complex NPM - sinon (Testing Library)", "Testing library with internal deps → UI5 AMD module");
18+
19+
async function bundleSinon() {
20+
console.log("\n📦 Bundling sinon (complex testing library)...\n");
21+
console.log(" Dependencies included:");
22+
console.log(" - @sinonjs/commons (utilities)");
23+
console.log(" - @sinonjs/fake-timers (timer mocking)");
24+
console.log(" - @sinonjs/samsam (deep equality)");
25+
console.log(" - nise (fake XHR/server)\n");
26+
27+
try {
28+
const config = createRollupConfig("sinon");
29+
const code = await generateAMDBundle(config);
30+
31+
printBundleInfo(code, "sinon");
32+
33+
// Check what's included in the bundle
34+
console.log("\n📊 Bundle analysis:");
35+
console.log(` - Contains spy: ${code.includes("createSpy") ? "✅" : "❌"}`);
36+
console.log(` - Contains stub: ${code.includes("createStub") ? "✅" : "❌"}`);
37+
console.log(` - Contains mock: ${code.includes("mock") ? "✅" : "❌"}`);
38+
console.log(` - Contains fake timers: ${code.includes("useFakeTimers") ? "✅" : "❌"}`);
39+
console.log(` - Contains fake XHR: ${code.includes("fakeXMLHttpRequest") || code.includes("FakeXMLHttpRequest") ? "✅" : "❌"}`);
40+
41+
const outputFile = await writeScenarioOutput("04-complex-sinon", "sinon.js", code);
42+
console.log(`\n💾 Saved to: ${outputFile}`);
43+
44+
return code;
45+
} catch (error) {
46+
console.error("❌ Error:", error.message);
47+
throw error;
48+
}
49+
}
50+
51+
bundleSinon();
Lines changed: 54 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,54 @@
1+
/**
2+
* Scenario 5: Transitive Dependencies - axios (HTTP Client)
3+
*
4+
* Demonstrates bundling an NPM package with transitive dependencies.
5+
* Axios is an HTTP client that depends on:
6+
* - form-data (multipart form handling)
7+
* - follow-redirects (redirect handling)
8+
* - proxy-from-env (proxy configuration)
9+
*
10+
* All transitive dependencies are automatically bundled by Rollup.
11+
*/
12+
13+
import {
14+
createRollupConfig,
15+
generateAMDBundle,
16+
writeScenarioOutput,
17+
printBundleInfo,
18+
printScenarioHeader
19+
} from "./shared-config.js";
20+
21+
printScenarioHeader(5, "Transitive Dependencies - axios (HTTP Client)", "HTTP client with transitive deps → UI5 AMD module");
22+
23+
async function bundleAxios() {
24+
console.log("\n📦 Bundling axios (HTTP client with transitive deps)...\n");
25+
console.log(" Transitive dependencies:");
26+
console.log(" - form-data → asynckit, combined-stream, mime-types");
27+
console.log(" - follow-redirects");
28+
console.log(" - proxy-from-env\n");
29+
30+
try {
31+
const config = createRollupConfig("axios");
32+
const code = await generateAMDBundle(config);
33+
34+
printBundleInfo(code, "axios");
35+
36+
// Check what's included in the bundle
37+
console.log("\n📊 Bundle analysis:");
38+
console.log(` - Contains Axios class: ${code.includes("Axios") ? "✅" : "❌"}`);
39+
console.log(` - Contains interceptors: ${code.includes("interceptors") ? "✅" : "❌"}`);
40+
console.log(` - Contains request method: ${code.includes(".request") ? "✅" : "❌"}`);
41+
console.log(` - Contains XMLHttpRequest: ${code.includes("XMLHttpRequest") ? "✅" : "❌"}`);
42+
console.log(` - Browser-compatible: ${code.includes("XMLHttpRequest") && !code.includes("require('http')") ? "✅" : "⚠️ (may need polyfills)"}`);
43+
44+
const outputFile = await writeScenarioOutput("05-transitive-axios", "axios.js", code);
45+
console.log(`\n💾 Saved to: ${outputFile}`);
46+
47+
return code;
48+
} catch (error) {
49+
console.error("❌ Error:", error.message);
50+
throw error;
51+
}
52+
}
53+
54+
bundleAxios();

package-lock.json

Lines changed: 29 additions & 26 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)