Skip to content

Conversation

@jdalton
Copy link
Contributor

@jdalton jdalton commented Nov 5, 2025

Summary

This PR simplifies the package structure by consolidating internal library packages and establishing clear boundaries between internal and external dependencies:

  • Renamed @socketsecurity/lib@socketsecurity/lib-internal to clarify it's for internal use only
  • Created @socketsecurity/lib-external as an npm alias pointing to the published @socketsecurity/lib@3.2.8
  • Updated all packages to use @socketsecurity/lib-internal for internal imports
  • Updated all packages to use @socketsecurity/lib-external for external (published) imports
  • Removed the bootstrap-smol system and associated build infrastructure
  • Removed the external imports rewriting system from lib-internal
  • Cleaned up orphaned documentation files
  • Fixed TypeScript compilation issues
  • Updated test mocks to use correct package paths

Benefits

  • Clearer dependency boundaries: Internal vs external packages are now explicitly named
  • Simplified build system: Removed complex bootstrap-smol infrastructure
  • Better maintainability: No more dynamic import rewriting needed
  • Type safety: Fixed TypeScript errors in lib-internal
  • Consistency: All packages follow the same import patterns

Test plan

  • All unit tests pass
  • TypeScript compilation succeeds
  • Build process completes successfully
  • No breaking changes to public APIs

🤖 Generated with Claude Code

Test User added 12 commits November 5, 2025 17:06
Add lib-internal and SDK to BUILD_PACKAGES array as the first two
build steps to ensure they are built before the CLI package, which
depends on both of them.

This fixes the build order issue where CLI would fail because it
imports from @socketsecurity/lib-internal and @socketsecurity/sdk
but their dist folders didn't exist yet.
- Scripts (build.mjs, etc.) → @socketsecurity/lib-external
- Build infrastructure → @socketsecurity/lib-external
- CLI source code (src/) → @socketsecurity/lib-internal
- Add lib-external alias to root devDependencies

This ensures proper separation between:
- Published package (lib-external) for build scripts
- Workspace package (lib-internal) for application source
Change the workspace package name from @socketsecurity/lib to
@socketsecurity/lib-internal to clearly distinguish it from the
published npm package.

This ensures:
- CLI source imports from @socketsecurity/lib-internal (workspace)
- Scripts import from @socketsecurity/lib-external (published package)

Updated CLI package.json to use @socketsecurity/lib-internal workspace
dependency.
Update all package.json files across the monorepo to use the renamed
@socketsecurity/lib-internal workspace dependency.

Git renamed packages/lib → packages/lib-internal to match the new
package name.
Remove bootstrap-smol source file, config, and exports as it's no
longer needed. Keep bootstrap-npm and bootstrap-sea.
…-node-versions

Fixed TypeError where CLI crashed on startup with "Cannot read properties of null (reading 'major')".

The issue was that maintained-node-versions exports a default export, but the require() calls were not accessing the .default property. This caused semver.parse() to receive undefined instead of the version string.

Changes:
- packages/lib-internal/src/package-default-node-range.ts: Added .default to require
- packages/lib-internal/src/constants/node.ts: Added .default to require

This fix resolves 19 test failures in the CLI test suite (from 66 to 47 failures).
After renaming @socketsecurity/lib to @socketsecurity/lib-internal, test mocks were still
referencing the old package name, causing 47 test failures. Updated all vi.mock() statements
and related imports in test files to use the correct lib-internal package.

Changes:
- Updated vi.mock() statements from @socketsecurity/lib/* to @socketsecurity/lib-internal/*
- Updated await import() statements in tests to match mocked package paths
- Fixed import statement in handle-purls-shallow-score.test.mts to match its mock

Test results:
- Before: 47 failed tests across 10 test files
- After: All 2255 tests passing (196 test files, 100% pass rate)

Files modified:
- test/unit/commands/ci/handle-ci.test.mts
- test/unit/commands/fix/ghsa-tracker.test.mts
- test/unit/commands/fix/handle-fix.test.mts
- test/unit/commands/fix/pr-lifecycle-logger.test.mts
- test/unit/commands/package/handle-purl-deep-score.test.mts
- test/unit/commands/package/handle-purls-shallow-score.test.mts
- test/unit/commands/scan/fetch-diff-scan.test.mts
- test/unit/commands/scan/fetch-scan.test.mts
- test/unit/commands/scan/output-create-new-scan.test.mts
- test/unit/commands/threat-feed/output-threat-feed.test.mts
Fixed two pre-existing TypeScript errors that were preventing successful builds:

1. bin.ts: Removed incompatible 'env' property from WhichOptions interface
   - The 'which' package has strict type checking that doesn't allow env property
   - This was causing TS2345 errors during build

2. versions.ts: Added 'release' to versionDiff return type
   - semver.diff() can return 'release' type which wasn't in the union type
   - This was causing TS2322 error

These fixes allow lib-internal to build successfully with TypeScript type declarations.
Moved SECURITY.md file to comply with monorepo markdown filename conventions.
SCREAMING_CASE files are only allowed at root, docs/, or .claude/ directories.
Removed types export for babel-plugin-inline-require-calls as the .d.ts file doesn't exist.
This was causing build warnings.
Removes fix-external-imports.mjs script and its call from fix-build.mjs.
The external bundling system (build-externals.mjs + fix-external-imports.mjs)
was designed for standalone npm package distribution, not monorepo usage.

In standalone distribution, it would:
- Bundle 30+ external dependencies into dist/external/
- Rewrite imports from require('package') to require('./external/package')
- Create a zero-dependency npm package

In monorepo context:
- All packages are in node_modules/ via pnpm workspaces
- External bundling is explicitly disabled (build.mjs:409)
- No need to bundle or rewrite imports

The build now runs:
- Package exports generation
- Path alias fixing
- CommonJS exports fixing

Verified that built files have correct imports (e.g., require("picomatch")
instead of require("./external/picomatch")).
Removes SECURITY.md from sdk package root. This file was orphaned
and not part of the sdk package documentation structure.
@socket-security-staging
Copy link

socket-security-staging bot commented Nov 5, 2025

Review the following changes in direct dependencies. Learn more about Socket for GitHub.

Diff Package Supply Chain
Security
Vulnerability Quality Maintenance License
Addednpm/​@​socketsecurity/​lib@​3.2.8100100100100100

View full report

@socket-security-staging
Copy link

socket-security-staging bot commented Nov 5, 2025

Warning

Review the following alerts detected in dependencies.

According to your organization's Security Policy, it is recommended to resolve "Warn" alerts. Learn more about Socket for GitHub.

Action Severity Alert  (click "▶" to expand/collapse)
Warn High
License policy violation: pypi numpy under FSFAP

License: FSFAP (numpy-2.3.4/vendored-meson/meson/test cases/frameworks/6 gettext/data3/metainfo.its)

From: ?pypi/gempy@2.1.0pypi/numpy@2.3.4

ℹ Read more on: This package | This alert | What is a license policy violation?

Next steps: Take a moment to review the security alert above. Review the linked package source code to understand the potential risk. Ensure the package is not malicious before proceeding. If you're unsure how to proceed, reach out to your security team or ask the Socket team for help at support@socket.dev.

Suggestion: Find a package that does not violate your license policy or adjust your policy to allow this package's license.

Mark the package as acceptable risk. To ignore this alert only in this pull request, reply with the comment @SocketSecurity ignore pypi/numpy@2.3.4. You can also ignore all packages with @SocketSecurity ignore-all. To ignore an alert for all future pull requests, use Socket's Dashboard to change the triage state of this alert.

View full report

Test User added 2 commits November 5, 2025 18:52
The CLI package now depends on @socketsecurity/lib-internal and
@socketsecurity/sdk as workspace dependencies. These packages must be
built before the CLI can be type-checked or built.

Updated all CI job steps to build dependencies in the correct order:
1. lib-internal
2. SDK
3. CLI

This fixes TypeScript compilation errors in CI where modules could not
be resolved.
Changed from manually chaining build commands to using pnpm's
recursive filter syntax (`--filter @socketsecurity/cli...`) which
automatically builds all workspace dependencies in the correct order.

The `...` suffix tells pnpm to include all dependencies of the CLI
package, ensuring lib-internal and SDK are built before CLI.

This is more maintainable and follows pnpm best practices.
@jdalton jdalton merged commit 9cc003b into main Nov 6, 2025
4 checks passed
@jdalton jdalton deleted the simplify branch November 6, 2025 00:00
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.

3 participants