Commit 5a7bee7
authored
Fixes for projects that use cds-indexer (#378)
* Fix cds-indexer flow for plugin-rich projects
cds-indexer support, as introduced, called projectInstallDependencies
AFTER running the indexer and used 'npm install --ignore-scripts' for
that install. For projects that depend on cds plugins like @sap/cds-shim,
@sap/cds-mtxs, @cap-js/hana, file-based local plugins, or anything whose
cds-plugin.js entry is wired by a postinstall/prepare hook, this produced
an under-populated model walk:
- The indexer ran first against an empty project node_modules, so plugins
never registered their hooks. The generated index.cds files therefore
failed to transitively include everything that annotation files in the
project reference.
- The full install that followed ran with --ignore-scripts, leaving any
plugin that depends on its own lifecycle hooks (e.g. the project's own
husky 'prepare', or packages whose cds-plugin.js gets emitted by
postinstall) only half-wired even after install completed.
Subsequent 'cds compile db srv app --to json' then failed with dozens of
'Artifact has not been found' errors against service-level projections
and _texts companion entities the plugins were supposed to synthesize.
Two changes:
1. indexer.ts: install full project dependencies BEFORE running the
indexer, so the indexer walks a fully-populated model. Record the
install on project.retryStatus.fullDependenciesInstalled so the
compilation retry path (needsFullDependencyInstallation) doesn't
repeat the same install. If install fails, log a warning and still
attempt the indexer — the cache binary may still produce useful
index files.
2. projectInstaller.ts: prefer 'npm ci' when a package-lock.json exists,
matching what the project locked exactly. Drop --ignore-scripts so
cds-plugin lifecycle hooks can run. Falls back to 'npm install' when
there is no lockfile.
Verified on the SAP ctsm project (~843 cds files, ~1700 deps, mix of
@sap/cds-shim, @sap/cds-mtxs, @cap-js/hana, @cap-js/ord, and a
file-based local plugin): all 'Artifact not found' errors disappear,
leaving only the project's pre-existing modeling warnings — same
output as the working manual flow ('npm ci' + 'npx @sap/cds-indexer'
+ 'cds compile').
Note: this enables npm lifecycle script execution for projects under
analysis. Threat model is comparable to running 'cds compile' itself,
which already loads and executes plugin code from node_modules; some
existing CI tests on Linux may need adjustment for the new install
behavior.
* Update tests to match new cds-indexer install order
Adjusts the two unit tests that were encoding the old behavior:
- projectInstaller.test.ts: the install args no longer include
'--ignore-scripts'. Adds a new test for the 'npm ci' branch
taken when a package-lock.json exists. Mocks fs/existsSync so
the lockfile-detection check is deterministic.
- indexer.test.ts: the install now happens BEFORE the indexer, so
an indexer failure no longer gates the install. The
'should not install ... when cds-indexer fails' test is replaced
with 'should still install ... even when cds-indexer subsequently
fails' to assert the new contract. Renames the post-install-failure
test to reflect that the install runs first.1 parent c887110 commit 5a7bee7
6 files changed
Lines changed: 137 additions & 68 deletions
File tree
- extractors/cds/tools
- dist
- src
- cds
- packageManager
- test/src
- cds
- packageManager
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
198 | 198 | | |
199 | 199 | | |
200 | 200 | | |
| 201 | + | |
| 202 | + | |
| 203 | + | |
| 204 | + | |
| 205 | + | |
| 206 | + | |
| 207 | + | |
| 208 | + | |
| 209 | + | |
| 210 | + | |
| 211 | + | |
| 212 | + | |
| 213 | + | |
| 214 | + | |
| 215 | + | |
| 216 | + | |
| 217 | + | |
| 218 | + | |
| 219 | + | |
| 220 | + | |
| 221 | + | |
| 222 | + | |
| 223 | + | |
| 224 | + | |
| 225 | + | |
| 226 | + | |
| 227 | + | |
| 228 | + | |
| 229 | + | |
| 230 | + | |
| 231 | + | |
| 232 | + | |
| 233 | + | |
| 234 | + | |
| 235 | + | |
| 236 | + | |
| 237 | + | |
| 238 | + | |
| 239 | + | |
| 240 | + | |
| 241 | + | |
| 242 | + | |
201 | 243 | | |
202 | 244 | | |
203 | 245 | | |
204 | 246 | | |
205 | 247 | | |
206 | | - | |
207 | | - | |
208 | | - | |
209 | | - | |
210 | | - | |
211 | | - | |
212 | | - | |
213 | | - | |
214 | | - | |
215 | | - | |
216 | | - | |
217 | | - | |
218 | | - | |
219 | 248 | | |
220 | 249 | | |
221 | 250 | | |
| |||
Lines changed: 18 additions & 10 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
1 | 1 | | |
2 | 2 | | |
3 | 3 | | |
| 4 | + | |
4 | 5 | | |
5 | 6 | | |
6 | 7 | | |
| |||
65 | 66 | | |
66 | 67 | | |
67 | 68 | | |
68 | | - | |
| 69 | + | |
| 70 | + | |
| 71 | + | |
| 72 | + | |
| 73 | + | |
| 74 | + | |
| 75 | + | |
| 76 | + | |
| 77 | + | |
| 78 | + | |
| 79 | + | |
| 80 | + | |
| 81 | + | |
| 82 | + | |
| 83 | + | |
69 | 84 | | |
70 | 85 | | |
71 | | - | |
| 86 | + | |
72 | 87 | | |
73 | 88 | | |
74 | 89 | | |
| |||
78 | 93 | | |
79 | 94 | | |
80 | 95 | | |
81 | | - | |
82 | | - | |
83 | | - | |
84 | | - | |
85 | | - | |
86 | | - | |
87 | | - | |
88 | | - | |
| 96 | + | |
89 | 97 | | |
90 | 98 | | |
91 | 99 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
494 | 494 | | |
495 | 495 | | |
496 | 496 | | |
497 | | - | |
| 497 | + | |
498 | 498 | | |
499 | 499 | | |
500 | 500 | | |
| |||
516 | 516 | | |
517 | 517 | | |
518 | 518 | | |
519 | | - | |
| 519 | + | |
| 520 | + | |
| 521 | + | |
| 522 | + | |
520 | 523 | | |
521 | 524 | | |
522 | 525 | | |
| |||
535 | 538 | | |
536 | 539 | | |
537 | 540 | | |
538 | | - | |
| 541 | + | |
539 | 542 | | |
540 | 543 | | |
541 | 544 | | |
| |||
550 | 553 | | |
551 | 554 | | |
552 | 555 | | |
553 | | - | |
| 556 | + | |
554 | 557 | | |
555 | 558 | | |
556 | 559 | | |
| |||
Lines changed: 28 additions & 8 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
1 | 1 | | |
2 | 2 | | |
3 | 3 | | |
| 4 | + | |
4 | 5 | | |
5 | 6 | | |
6 | 7 | | |
| |||
11 | 12 | | |
12 | 13 | | |
13 | 14 | | |
| 15 | + | |
14 | 16 | | |
15 | 17 | | |
| 18 | + | |
16 | 19 | | |
17 | 20 | | |
18 | 21 | | |
19 | 22 | | |
20 | 23 | | |
21 | 24 | | |
| 25 | + | |
| 26 | + | |
| 27 | + | |
22 | 28 | | |
23 | 29 | | |
24 | 30 | | |
| |||
65 | 71 | | |
66 | 72 | | |
67 | 73 | | |
68 | | - | |
69 | | - | |
70 | | - | |
71 | | - | |
72 | | - | |
73 | | - | |
74 | | - | |
75 | | - | |
| 74 | + | |
| 75 | + | |
| 76 | + | |
| 77 | + | |
| 78 | + | |
| 79 | + | |
| 80 | + | |
| 81 | + | |
| 82 | + | |
| 83 | + | |
| 84 | + | |
| 85 | + | |
| 86 | + | |
| 87 | + | |
| 88 | + | |
| 89 | + | |
| 90 | + | |
| 91 | + | |
| 92 | + | |
| 93 | + | |
| 94 | + | |
| 95 | + | |
76 | 96 | | |
77 | 97 | | |
78 | 98 | | |
| |||
0 commit comments