on 2023 Jun 15 2:26 PM
Hi,
I'm creating a CAP application and want to create some re-usable local libraries. (Cloud SDK & re-usable classes)
For this I wanted to make use of the default mechanism provided by NPM, workspaces.
I've setup my package.json to include the workspaces and installed the relevant local modules as dependencies.
So far, so good! Running the application locally is working fine!
Unfortunately when building the project, something strange seems to happen. The workspace folders seem to be added to the MTAR, but only the node_modules folder for that workspace is added and the actual source code seems to be missing.
Example of one of the local modules:
It seems this might be caused by the mbt build tool, as I found an open issue which seems to be similar: MBT build in Project with NPM Workspaces fails to use local dependencies · Issue #1048 · SAP/cloud-m...
The MTA is using a default build configuration for the srv module:
Any tips or tricks to use as a workaround or a solution to this problem?
Best regards,
Geert-Jan
Request clarification before answering.
Hi Geert-Jan,
please have a look at my blog, where I describe building a plugin for cap, which also uses workspaces:
https://blogs.sap.com/2023/04/30/reusable-components-for-cap-with-cds-plugin/
Currently the deployment should work, if the package name is @capire/... but we are currently working on a generic solution that would be available later (could come with cds 7.1)
For now as a workaround I would either copy the resources manually by adding it as a build step:
build-parameters:
before-all:
- builder: custom
commands:
- npx -p @sap/cds-dk cds build --production
- npx copyfiles -f <workspace>/*.* gen/srv/<workspace>/ -a
...or rename the package.
Of course publishing the package (public or private) and consuming it as a "real" dependency would be the regular way to go.
Thanks
Daniel
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Hi daniel.schlachter,
Thanks for the tips and insights! I'm definitely going to try both the capire & copy solutions somewhere next week.
In this case it's more a set of central packages to hold some business logic that will be re-used by different different cap-modules in the same project. We're splitting up the project into several micro-services, e.g. one for serving UI services and one for external API access. (So if there is a high load on API's, that doesn't influence services used in UI's, similar to the reasoning behind an mtx-sidecar)
Digging through the npm documentation, this seemed to be the exact intent for the workspace principles. (and avoiding the overhead of maintaining packages in a registry, since these packages are not intended to be used outside the project)
Thanks for the blog! I've used it for the same project a few weeks ago, for a real re-usable cap component which we're now using in different cap projects through our private package registry! Worked like a charm!
Cheers,
Geert-Jan
User | Count |
---|---|
85 | |
12 | |
9 | |
8 | |
8 | |
5 | |
4 | |
4 | |
3 | |
3 |
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.