Skip to content

Making the plugin to js#50

Merged
Kronprinz03 merged 12 commits intomainfrom
making-the-plugin-to-js
Mar 20, 2026
Merged

Making the plugin to js#50
Kronprinz03 merged 12 commits intomainfrom
making-the-plugin-to-js

Conversation

@Kronprinz03
Copy link
Contributor

Have you...

  • Added relevant entry to the change log?

Copy link
Contributor

@hyperspace-insights hyperspace-insights bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The PR introduces a critical circular self-import bug in lib/index.ts (the module imports from './index' — itself), which will cause all referenced symbols to be undefined at runtime. Additionally, embedding CDS plugin registration side-effects directly in the public lib/index.ts barrel means those side-effects fire for any consumer who imports from the library, not just when the plugin is bootstrapped. Both issues need to be addressed before this can be merged safely.

PR Bot Information

Version: 1.19.1 | 📖 Documentation | 🚨 Create Incident | 💬 Feedback

  • Event Trigger: pull_request.opened
  • Correlation ID: e9bc5580-23db-11f1-832f-78869b260faa
  • LLM: anthropic--claude-4.6-sonnet

@Kronprinz03 Kronprinz03 force-pushed the making-the-plugin-to-js branch from 994735c to 0e0b2df Compare March 19, 2026 21:57
@Kronprinz03 Kronprinz03 force-pushed the making-the-plugin-to-js branch from a19c4ae to 92378da Compare March 19, 2026 22:25
@Kronprinz03 Kronprinz03 force-pushed the making-the-plugin-to-js branch from 92378da to aceca15 Compare March 19, 2026 22:31
"version": "1.0.0",
"description": "",
"main": "cds-plugin.ts",
"main": "cds-plugin.js",
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@Kronprinz03 Kronprinz03 force-pushed the making-the-plugin-to-js branch from dbdcb96 to ad4470d Compare March 20, 2026 08:34
@Kronprinz03 Kronprinz03 marked this pull request as ready for review March 20, 2026 08:52
@Kronprinz03 Kronprinz03 requested a review from a team as a code owner March 20, 2026 08:52
@hyperspace-insights
Copy link
Contributor

Summary

The following content is AI-generated and provides a summary of the pull request:


Migrate Plugin Entry Point from TypeScript to Compiled JavaScript

Refactor

♻️ Refactored the plugin to compile TypeScript sources to a dist/ directory and expose JavaScript entry points, enabling the package to be consumed without a TypeScript runtime dependency.

Changes

  • cds-plugin.js: New JS entry point that delegates to the compiled dist/cds-plugin output. The main field in package.json now points here instead of cds-plugin.ts.
  • cds-plugin.ts: Reduced to a single re-export (import './lib'). All plugin registration logic (CDS event handlers, annotation cache, build plugin, import handler) has been moved into lib/index.ts.
  • lib/index.ts: Now contains the full plugin initialization code previously in cds-plugin.ts, including cds.on('serving'), cds.on('served'), build plugin registration, and import handler setup.
  • tsconfig.build.json: New build-specific TypeScript config that compiles cds-plugin.ts, srv/**/*.ts, and lib/**/*.ts into ./dist.
  • package.json: Updated main to cds-plugin.js, added files array (cds-plugin.js, dist, srv), and added a compile script (tsc -p tsconfig.build.json) with prebuild and pretest hooks.
  • srv/BTPProcessService.js / srv/localProcessService.js: New JS shims delegating to compiled dist/srv/* modules.
  • srv/BTPProcessService.cds / srv/localProcessService.cds: Removed .ts extension from @impl annotations so CDS resolves to the JS shims.
  • lib/build/plugin.ts, lib/build/validation-utils.ts, lib/build/validations.ts, lib/processImport.ts: Fixed import paths for types/csn-extensions to use relative paths from within lib/ (e.g., ../types/./types/).
  • lib/types/cds-extensions.d.ts, lib/types/cds-plugin.d.ts, lib/types/csn-extensions.ts: Renamed/moved type files into lib/types/.
  • .github/actions/integration-tests/action.yml: Added a Compile TypeScript to dist step (npm run compile) before HANA deployment steps.
  • tsconfig.json: Fixed include path for types from ./types/**/*.ts to lib/types/**/*.ts.
  • eslint.config.mjs: Added dist/** to the ignore list.
  • .gitignore: Added dist/ to ignored paths.
  • .prettierignore: Added dist/* to ignored paths.
  • jest.config.js: Scoped ts-jest diagnostics path regex to \.test\.ts$ to avoid false errors from compiled output.

  • 🔄 Regenerate and Update Summary
  • ✏️ Insert as PR Description (deletes this comment)
  • 🗑️ Delete comment
PR Bot Information

Version: 1.19.1 | 📖 Documentation | 🚨 Create Incident | 💬 Feedback

  • Correlation ID: 1cac19e0-243a-11f1-895a-ad3474f63ca0
  • Event Trigger: pull_request.ready_for_review
  • Output Template: Default Template
  • LLM: anthropic--claude-4.6-sonnet
  • Summary Prompt: Default Prompt

💌 Have ideas or want to contribute? Create an issue and share your thoughts with us!
📑 Check out the documentation for more information.
📬 Subscribe to the Hyperspace PR Bot DL to get the latest announcements and pilot features!

Made with ❤️ by Hyperspace.

Copy link
Contributor

@hyperspace-insights hyperspace-insights bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The PR introduces a TypeScript-to-JavaScript compilation pipeline (tsconfig.build.json, npm run compile, JS shim files) to make the plugin publishable as plain JS. The structural changes are mostly sound, but two substantive issues were flagged:

  1. Side-effect pollution in the barrel export (lib/index.ts): Moving CDS event registrations into the shared barrel module means any import from lib (including in tests) will trigger plugin registration as an unintended side effect. This logic should stay in the dedicated cds-plugin.ts entry point.

  2. pretest only covers npm test: Sibling scripts like test:watch, test:hana, and test:hybrid skip the compile step and may run against a stale dist/ directory.

Please address these before merging.

PR Bot Information

Version: 1.19.1 | 📖 Documentation | 🚨 Create Incident | 💬 Feedback

  • Correlation ID: 1cac19e0-243a-11f1-895a-ad3474f63ca0
  • LLM: anthropic--claude-4.6-sonnet
  • Event Trigger: pull_request.ready_for_review

"outDir": "./dist",
"rootDir": "."
},
"include": ["./cds-plugin.ts", "./srv/**/*.ts", "./lib/**/*.ts"],
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Bug: cds-plugin.ts is included in the build but its compiled output (dist/cds-plugin.js) will never be used at runtime.

The root-level cds-plugin.js shim already requires ./dist/cds-plugin, so dist/cds-plugin.js would just re-export dist/lib/index.js. However, the real entry point consumed by consumers is the root cds-plugin.jsdist/cds-plugin.jsdist/lib/index.js chain. Including ./cds-plugin.ts in the build is harmless but creates an extra indirection layer in the output. More critically, since cds-plugin.ts only does import './lib', the compiled dist/cds-plugin.js will require ./lib — but inside dist/, lib is at dist/lib, not a sibling lib/. The relative path ./lib from dist/cds-plugin.js resolves correctly only if the output mirrors the source structure. With rootDir: "." and outDir: "./dist", dist/cds-plugin.js will emit require("./lib") which resolves to dist/lib/index.js — this is correct. No immediate breakage, but the chain is fragile. Consider verifying the compiled output resolves as expected.


Please provide feedback on the review comment by checking the appropriate box:

  • 🌟 Awesome comment, a human might have missed that.
  • ✅ Helpful comment
  • 🤷 Neutral
  • ❌ This comment is not helpful

],
"scripts": {
"prebuild": "npm run compile",
"pretest": "npm run compile",
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Bug: The pretest script runs npm run compile (TypeScript compilation), but the test:watch, test:hana, and test:hybrid scripts bypass pretest entirely since pre* hooks only fire for the exact script name they prefix. Developers running npm run test:hana or npm run test:watch may be testing against a stale dist/.

Consider either adding explicit compile calls in those scripts or documenting that npm test must be run first.

Suggested change
"pretest": "npm run compile",
"prebuild": "npm run compile",
"pretest": "npm run compile",
"test": "jest --silent --testPathIgnorePatterns=/tests/hybrid/programmaticApproach.test.ts",
"test:watch": "npm run compile && jest --watch",
"test:hana": "npm run compile && jest tests/integration --silent",
"test:hybrid": "npm run compile && jest tests/hybrid --silent",

Double-check suggestion before committing. Edit this comment for amendments.


Please provide feedback on the review comment by checking the appropriate box:

  • 🌟 Awesome comment, a human might have missed that.
  • ✅ Helpful comment
  • 🤷 Neutral
  • ❌ This comment is not helpful

import { importProcess } from './processImport';

// Register build plugin for annotation validation during cds build
cds.build?.register?.('process-validation', ProcessValidationPlugin);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Logic Error: Side-effect plugin code (CDS event registrations, import handler setup) has been moved into lib/index.ts, which is also a barrel re-export module. Any consumer who imports anything from lib/index.ts (e.g. in tests or programmatically) will inadvertently trigger cds.on('serving', ...), cds.on('served', ...), and cds.build?.register?.(...) as side effects.

This breaks the separation of concerns that existed when the plugin code was isolated in cds-plugin.ts. Consider moving the plugin registration logic back to cds-plugin.ts (importing from ./lib for shared utilities) and keeping lib/index.ts as a pure export barrel.


Please provide feedback on the review comment by checking the appropriate box:

  • 🌟 Awesome comment, a human might have missed that.
  • ✅ Helpful comment
  • 🤷 Neutral
  • ❌ This comment is not helpful

@Kronprinz03 Kronprinz03 merged commit 6dca35b into main Mar 20, 2026
8 checks passed
@Kronprinz03 Kronprinz03 deleted the making-the-plugin-to-js branch March 20, 2026 09:15
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants