Skip to content

CDS extractor: Windows compatibility adjustments#375

Open
mihai-herda-SAP wants to merge 10 commits into
advanced-security:mainfrom
mihai-herda-SAP:fix_cds_extractor_windows
Open

CDS extractor: Windows compatibility adjustments#375
mihai-herda-SAP wants to merge 10 commits into
advanced-security:mainfrom
mihai-herda-SAP:fix_cds_extractor_windows

Conversation

@mihai-herda-SAP
Copy link
Copy Markdown

What this PR changes

Spawn-layer adjustments — Windows shim execution

On Windows, npm, npx, and locally-installed binaries under node_modules/.bin/ are .cmd shims. Since Node 20.12.2 (CVE-2024-27980 hardening), Node refuses to spawn .cmd/.bat files via spawnSync/execFileSync unless shell: true is set. The extractor's spawn sites needed updating to match this requirement.

  • Normalized shell: getPlatformInfo().isWindows across all five spawnSync/execFileSync sites the extractor controls: cache install, project install, cds-indexer, cds-command test, and cds compile. Previously these used a mix of shell: true, shell: isWindows(), or no shell option at all — the unified pattern makes the Windows requirement explicit and avoids enabling a shell on platforms that don't need one.
  • Added a localCdsBinName() helper in cds/compiler/command.ts so cache-directory binary discovery picks up cds.cmd on Windows and cds on Unix, rather than hardcoding the Unix name.
  • Updated the useShell rule in compile.ts so direct-binary execution opts into a shell on Windows (required for the cds.cmd shim under node_modules/.bin/), while non-Windows continues to use a shell only for npx-style commands.

Resilience adjustments — slow registries and stale engine declarations

  • Bumped the npm view timeout from 30 s to 120 s in versionResolver.ts to accommodate slower corporate npm registries.
  • Pass --engine-strict=false explicitly on both the cache install and the project install, so a project's .npmrc setting engine-strict=true doesn't cause npm install to abort on transitive deps that pin obsolete Node ranges (e.g. a dep declaring engines.node: ^18 on a Node 24 host).

Plugin-resolution adjustment — project plugins for the spawned cds

  • createSpawnOptions now always appends <projectBaseDir>/node_modules to NODE_PATH, in both the cache+npx branch and the direct-binary branch. When cds-dk runs from the cache directory, Node's plugin resolver walks up node_modules from the cds-dk install location and doesn't reach the project's own node_modules — so cds plugins the project installed (e.g. @cap-js/telemetry declared via cds-plugin) need an explicit fallback path to remain resolvable. The direct-binary branch previously cleared NODE_PATH; it now sets it to the project's node_modules. This mirrors the pattern already used in cds/indexer.ts.

Transitive deps occasionally pin obsolete Node ranges (e.g.
engines.node ^18) that would otherwise abort the entire cache
install on newer Node runtimes. npm's default is non-strict,
but a project's .npmrc copied into the cache directory can
flip it on. Make the non-strict default explicit on the install
args so the cache install is robust to user .npmrc settings.
The retry path's full project install was aborting with
EBADENGINE on transitive deps that pin obsolete Node ranges
(observed: networkcalculation@2302.0.0 requiring node ^18.16.0
on a Node 24 host). This took out the entire retry attempt
even though the cds compiler itself runs fine on the host
Node version. Match the cache install: pass --engine-strict=false
explicitly so the project's .npmrc cannot force strict mode
and break the retry.
The cds CLI's plugin loader does require('@cap-js/...') for
each entry in the project's cds.plugins / cds-plugin config.
Node's resolver walks up node_modules from the cds-dk install
location — when cds-dk lives in our cache directory outside
the project, that walk never reaches the project's
node_modules, so any plugin the project installed becomes
invisible. Result: 'Cannot find module @cap-js/telemetry'
even after a successful project npm install.

Always append <projectBaseDir>/node_modules to NODE_PATH in
createSpawnOptions, for both branches:
  - cache + npx-style command: append after cache nodePath so
    the cache still wins for @sap/cds-dk resolution but project
    plugins remain resolvable as a fallback.
  - direct binary execution: previously deleted NODE_PATH
    entirely; now sets it to the project node_modules so cds
    plugins from the project install can be loaded.

This mirrors the pattern already used in cds/indexer.ts when
spawning @sap/cds-indexer.
Picks up:
- 070f5d1 Disable engine-strict on cache npm install
- 70b0f27 Disable engine-strict on project npm install
- 39343c5 Expose project node_modules to spawned cds via NODE_PATH
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.

1 participant