Skip to content

Commit fd83795

Browse files
committed
fix: Integrate charting
1 parent 064d225 commit fd83795

6 files changed

Lines changed: 102 additions & 8269 deletions

File tree

internal/npm-integration-poc/consolidated-app/package-lock.json

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

internal/npm-integration-poc/consolidated-app/package.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@
1515
"dependencies": {
1616
"validator": "^13.15.26",
1717
"ui5-tooling-modules": "^3.34.2",
18-
"@ui5/webcomponents": "^2.6.0"
18+
"@ui5/webcomponents": "^2.6.0",
19+
"chart.js": "^4.5.1"
1920
}
2021
}

internal/npm-integration-poc/consolidated-app/ui5-task-webc-standalone.js

Lines changed: 75 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,51 @@
11
/**
2-
* UI5 Custom Task: WebComponents Bundler (Standalone Plugin)
2+
* UI5 Custom Task: WebComponents & NPM Modules Bundler (Standalone Plugin)
33
*
4-
* Uses the custom standalone rollup-plugin-ui5-webcomponents.js
5-
* to bundle @ui5/webcomponents during the build process.
4+
* Bundles:
5+
* 1. @ui5/webcomponents using rollup-plugin-ui5-webcomponents.js
6+
* 2. NPM dependencies from package.json using shared Rollup config
7+
*
8+
* Output: /resources/thirdparty/<module-name>.js
69
*/
710

11+
import {readFile} from "fs/promises";
12+
import {join, dirname} from "path";
13+
import {fileURLToPath} from "url";
14+
815
import ui5WebComponentsPlugin from "../lib/plugins/rollup-plugin-ui5-webcomponents.js";
916
import {WebComponentsBundler} from "../lib/core/webcomponents-bundler.js";
1017
import {WorkspaceWriter} from "../lib/core/output-writer.js";
1118
import {PathResolver} from "../lib/utils/path-resolver.js";
1219
import {DEFAULT_CONFIG, createPluginOptions, createBundlerOptions} from "../lib/config/standalone-config.js";
20+
import {createRollupConfig, generateAMDBundle} from "../scenarios/shared-config.js";
21+
22+
const __dirname = dirname(fileURLToPath(import.meta.url));
23+
24+
/**
25+
* NPM packages to exclude from bundling (UI5 internal, dev deps, tooling)
26+
*/
27+
const EXCLUDED_PACKAGES = [
28+
"ui5-tooling-modules",
29+
"@ui5/webcomponents", // Handled separately by WebComponents bundler
30+
"@ui5/webcomponents-base",
31+
"@ui5/webcomponents-theming",
32+
"@ui5/webcomponents-icons"
33+
];
34+
35+
/**
36+
* Read and parse package.json dependencies
37+
*
38+
* @returns {Promise<string[]>} List of dependency names to bundle
39+
*/
40+
async function getPackageDependencies() {
41+
const packageJsonPath = join(__dirname, "package.json");
42+
const packageJson = JSON.parse(await readFile(packageJsonPath, "utf-8"));
43+
44+
const dependencies = Object.keys(packageJson.dependencies || {});
45+
46+
// Filter out excluded packages
47+
return dependencies.filter((dep) => !EXCLUDED_PACKAGES.includes(dep));
48+
}
1349

1450
/**
1551
* Custom task entry point
@@ -22,36 +58,59 @@ import {DEFAULT_CONFIG, createPluginOptions, createBundlerOptions} from "../lib/
2258
* @returns {Promise<undefined>} Promise resolving when task is complete
2359
*/
2460
export default async function({workspace, log, taskUtil}) {
25-
log.info("Running WebComponents bundler task (standalone plugin)...");
61+
log.info("Running WebComponents & NPM Modules bundler task...");
2662

2763
const {resourceFactory} = taskUtil;
2864
const $metadata = {};
2965

3066
try {
31-
// Create plugin instance
32-
const plugin = ui5WebComponentsPlugin(createPluginOptions(log, $metadata));
67+
// ========== 1. Bundle WebComponents ==========
68+
log.info("📦 Phase 1: Bundling WebComponents...");
3369

34-
// Create path resolver
70+
const plugin = ui5WebComponentsPlugin(createPluginOptions(log, $metadata));
3571
const pathResolver = new PathResolver(
3672
DEFAULT_CONFIG.namespace,
3773
DEFAULT_CONFIG.thirdpartyNamespace
3874
);
39-
40-
// Create workspace writer
4175
const workspaceWriter = new WorkspaceWriter(pathResolver, workspace, resourceFactory);
42-
43-
// Create bundler instance
4476
const bundler = new WebComponentsBundler(createBundlerOptions(log, plugin));
4577

46-
// Bundle the MessageStrip webcomponent
4778
const output = await bundler.bundle("@ui5/webcomponents/dist/MessageStrip.js");
48-
49-
// Process output and write to workspace
5079
await bundler.processOutput(output, workspaceWriter, $metadata);
5180

52-
log.info("✅ WebComponents bundled successfully using standalone plugin");
81+
log.info("✅ WebComponents bundled successfully");
82+
83+
// ========== 2. Bundle NPM Packages ==========
84+
log.info("📦 Phase 2: Bundling NPM packages from package.json...");
85+
86+
const dependencies = await getPackageDependencies();
87+
log.info(` Found ${dependencies.length} dependencies to bundle: ${dependencies.join(", ")}`);
88+
89+
for (const packageName of dependencies) {
90+
try {
91+
// Reuse shared Rollup config and AMD generator (DRY)
92+
const config = createRollupConfig(packageName);
93+
const code = await generateAMDBundle(config);
94+
95+
// Sanitize package name for path (handle scoped packages)
96+
const sanitizedName = packageName.replace(/^@/, "").replace(/\//g, "-");
97+
const outputPath = `/resources/thirdparty/${sanitizedName}.js`;
98+
99+
const resource = resourceFactory.createResource({
100+
path: outputPath,
101+
string: code
102+
});
103+
104+
await workspace.write(resource);
105+
log.info(` ✅ ${packageName}${outputPath} (${(code.length / 1024).toFixed(1)} KB)`);
106+
} catch (error) {
107+
log.error(` ❌ Failed to bundle ${packageName}: ${error.message}`);
108+
}
109+
}
110+
111+
log.info("✅ All NPM packages bundled successfully");
53112
} catch (error) {
54-
log.error(`❌ Error bundling WebComponents: ${error.message}`);
113+
log.error(`❌ Error in bundler task: ${error.message}`);
55114
log.error(error.stack);
56115
throw error;
57116
}

internal/npm-integration-poc/consolidated-app/webapp/controller/Main.controller.js

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,9 @@ sap.ui.define([
22
"sap/ui/core/mvc/Controller",
33
"sap/ui/model/json/JSONModel",
44
"sap/m/MessageToast",
5-
"validator" // NPM package (auto-bundled by ui5-tooling-modules)
6-
], function(Controller, JSONModel, MessageToast, validator) {
5+
"thirdparty/validator", // NPM package (auto-bundled by ui5-tooling-modules)
6+
"thirdparty/chart.js"
7+
], function(Controller, JSONModel, MessageToast, validator, chartjs) {
78
"use strict";
89

910
return Controller.extend("com.example.app.controller.Main", {
@@ -24,6 +25,8 @@ sap.ui.define([
2425
// Log that validator is loaded
2526
console.log("✅ Validator.js loaded:", typeof validator);
2627
console.log(" Available methods:", Object.keys(validator).slice(0, 10).join(", "), "...");
28+
29+
console.log("✅ Chart.js loaded:", chartjs);
2730
},
2831

2932
onValidate: function() {

internal/npm-integration-poc/consolidated-app/webapp/index.html

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@
1111
data-sap-ui-theme="sap_horizon"
1212
data-sap-ui-resourceroots='{
1313
"com.example.app": "./",
14-
"validator": "./resources/validator",
14+
"thirdparty": "./resources/thirdparty",
1515
"com.example.app.gen.@ui5.webcomponents": "./gen/@ui5/webcomponents"
1616
}'
1717
data-sap-ui-libs="sap.m,sap.ui.core,sap.ui.layout,sap.ui.webc.main"

0 commit comments

Comments
 (0)