Skip to content

fix: resolve @sasjs/core macros from the project's own node_modules f… - #1454

Merged
YuryShkoda merged 3 commits into
mainfrom
issue-1449
Jul 10, 2026
Merged

fix: resolve @sasjs/core macros from the project's own node_modules f…#1454
YuryShkoda merged 3 commits into
mainfrom
issue-1449

Conversation

@YuryShkoda

@YuryShkoda YuryShkoda commented Jul 10, 2026

Copy link
Copy Markdown
Member

Issue

Closes #1449

Intent

  • sasjs compile ignored a project's own node_modules/@sasjs/core: getNodeModulePath('@sasjs/core') used unscoped require.resolve, which walks up from @sasjs/cli's own install location and always found the CLI's bundled @sasjs/core first. Running npm i @sasjs/core in a project to pick up a new/updated macro had no effect until the next @sasjs/cli release.

Implementation

  • getNodeModulePath now takes an optional fromDir, passed as require.resolve's paths option, to anchor resolution at a given directory instead of the CLI's own location.
  • setConstants now resolves @sasjs/core in three steps, matching the documented order:
    1. macroCorePath env var (explicit override, unchanged)
    2. the project's own node_modules/@sasjs/core (new, via getNodeModulePath('@sasjs/core', process.projectDir))
    3. @sasjs/cli's own bundled @sasjs/core (existing fallback, now used only when the project has nothing installed)

Test plan

  • New getNodeModulePath test in utils.spec.ts: real (non-mocked) temp dir with its own node_modules/<fake-module>, unresolvable without fromDir, resolvable with it
  • New/updated setConstants.spec.ts tests: project-scoped lookup wins and skips the fallback; fallback is used (in the right order) when the project has nothing installed; updated call-count assertions on the two pre-existing tests
  • Ran existing compile.spec.ts (21 tests) and build.spec.ts (13 tests), which compile real SAS files against real @sasjs/core macros — no regressions
  • Updated docs/diagrams/sasjs-compile.md to describe the new resolution order

Checks

  • Code is formatted correctly (npm run lint:fix).
  • Any new functionality has been unit tested.
  • All unit tests are passing (npm test).
  • Unit tests coverage has been increased and a new threshold is set.
  • All CI checks are green.
  • Development comments have been added or updated.
  • Development documentation coverage has been increased and a new threshold is set.
  • Reviewer is assigned.

Reviewer checks

  • Any new code is documented.

…irst

Previously getNodeModulePath('@sasjs/core') used unscoped require.resolve,
which always found @sasjs/cli's own bundled @sasjs/core dependency before
the user's project - so running `npm i @sasjs/core` to pick up a new macro
had no effect until the next CLI release. getNodeModulePath now accepts an
optional fromDir, and setConstants tries process.projectDir first, falling
back to the CLI-relative lookup only when the project has no local install.
@github-actions

github-actions Bot commented Jul 10, 2026

Copy link
Copy Markdown

Coverage report

Total coverage

Status Category Percentage Covered / Total
🟡 Statements 74% 3341/4515
🟡 Branches 60.67% 1325/2184
🟡 Functions 74.02% 678/916
🟢 Lines 82.72% 8480/10252

Status of coverage: 🟢 - ok, 🟡 - slightly more than threshold, 🔴 - under the threshold

Show files with reduced coverage 🔻

Reduced coverage

Status Filename Statements Branches Functions Lines
🟡 src/utils/config.ts 58.29% 55.52% 63.79% (+1.72% 🔼) 64.57%
🟢 src/utils/test.ts 84.66% (-1.14% 🔻) 68.12% 77.14% 92.14%
🟢 src/commands/compile/compileSingleFile.ts 95.83% (-2.08% 🔻) 84% (-4% 🔻) 100% 100%

Status of coverage: 🟢 - ok, 🟡 - slightly more than threshold, 🔴 - under the threshold

Report generated by 🧪jest coverage report action from 4ac5a8e

tmoody
tmoody previously approved these changes Jul 10, 2026
Comment thread src/utils/setConstants.ts Outdated
@YuryShkoda
YuryShkoda merged commit aee7590 into main Jul 10, 2026
2 checks passed
@YuryShkoda
YuryShkoda deleted the issue-1449 branch July 10, 2026 14:10
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.

sasjs compile does not search node_modules/@sasjs/core folders

3 participants