Skip to content

Commit 0c059e3

Browse files
jfblaaclaude
andauthored
fix(manifest): anchor --exclude-paths at the scan root for every build root (#1679)
* fix(manifest): anchor --exclude-paths at the scan root for every build root Dynamic SBOM inference re-anchored --exclude-paths onto each build root and dropped every pattern outside it, so a module the build reaches outside its own directory (a Maven `<module>../x</module>`, a Gradle project relocated with projectDir) could not be excluded and was resolved and uploaded anyway. Build roots now get scan-root-relative patterns plus the absolute scan root (socket.excludeBase, the build root by default). The Maven extension, Gradle init scripts and sbt plugins relativize each module's canonical directory against it, so a module outside the scan root never matches. New compat smoke tests cover a module outside the build root (Maven, Gradle) and a nested one (sbt, which refuses projects outside its build root). * fix(manifest): harden scan-root --exclude-paths anchoring - Treat a module on another Windows drive than the scan root as outside it instead of letting Path.relativize throw, in every JVM exclusion helper. - Normalize `\` separators in the glob compiler, so single-root runs match Windows-style patterns too and callers pass --exclude-paths straight through. - Smoke-check that a module outside the scan root is never excluded, clear stale records between checks and keep build output visible. - Document the narrowed and re-anchored behaviour in the changelog and the --exclude-paths help. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> --------- Co-authored-by: Claude Opus 5.5 <noreply@anthropic.com>
1 parent a54baa1 commit 0c059e3

42 files changed

Lines changed: 382 additions & 59 deletions

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

‎CHANGELOG.md‎

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,15 @@ All notable changes to this project will be documented in this file.
44

55
The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.1.0/).
66

7+
## [Unreleased]
8+
9+
### Changed
10+
- Modules outside the scan root can no longer be excluded with `--exclude-paths`; `**/x` used to match a `../x` module by accident. Single-root runs whose Maven or Gradle options relocate the build root (`-f`, `-p`) now match patterns relative to the current directory, as documented.
11+
12+
### Fixed
13+
- `--exclude-paths` patterns are now matched relative to the scan root in every build root. They now also exclude modules a build reaches outside its own directory (Maven `../` modules, relocated Gradle projects) and modules matched by wildcards that span a build-root boundary, such as `*/core`.
14+
- `--exclude-paths` patterns written with Windows `\` separators now exclude JVM build modules in single-root runs too.
15+
716
## [1.12.2](https://github.com/SocketDev/socket-cli/releases/tag/v1.12.2) - 2026-10-30
817

918
### Changed

‎src/commands/manifest/cmd-manifest-auto.test.mts‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ describe('socket manifest auto', async () => {
2323
$ socket manifest auto [options] [CWD=.]
2424
2525
Options
26-
--exclude-paths List of glob patterns to exclude from manifest/facts generation. Patterns are anchored micromatch globs matched relative to CWD (\`--cwd\` if set): \`tests\` matches only \`<cwd>/tests\`; use \`**/tests\` to match at any depth. Negation patterns (\`!path\`) are not supported. Accepts a comma-separated value or multiple flags. An excluded JVM build module is not analysed as a project of its own, but where a project that is not excluded depends on it, its code is analysed as part of that project.
26+
--exclude-paths List of glob patterns to exclude from manifest/facts generation. Patterns are anchored micromatch globs matched relative to CWD (\`--cwd\` if set): \`tests\` matches only \`<cwd>/tests\`; use \`**/tests\` to match at any depth. Negation patterns (\`!path\`) are not supported. Accepts a comma-separated value or multiple flags. An excluded JVM build module is not analysed as a project of its own, but where a project that is not excluded depends on it, its code is analysed as part of that project. A build module outside CWD cannot be excluded.
2727
--verbose Enable debug output (only for auto itself; sub-steps need to have it pre-configured), may help when running into errors
2828
2929
Tries to figure out what language your target repo uses. If it finds a

‎src/commands/manifest/cmd-manifest-dynamic-sbom-inference.test.mts‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ describe('socket manifest dynamic-sbom-inference', async () => {
3333
CWD itself.
3434
3535
Options
36-
--exclude-paths List of glob patterns to exclude from manifest/facts generation. Patterns are anchored micromatch globs matched relative to CWD (\`--cwd\` if set): \`tests\` matches only \`<cwd>/tests\`; use \`**/tests\` to match at any depth. Negation patterns (\`!path\`) are not supported. Accepts a comma-separated value or multiple flags. An excluded JVM build module is not analysed as a project of its own, but where a project that is not excluded depends on it, its code is analysed as part of that project.
36+
--exclude-paths List of glob patterns to exclude from manifest/facts generation. Patterns are anchored micromatch globs matched relative to CWD (\`--cwd\` if set): \`tests\` matches only \`<cwd>/tests\`; use \`**/tests\` to match at any depth. Negation patterns (\`!path\`) are not supported. Accepts a comma-separated value or multiple flags. An excluded JVM build module is not analysed as a project of its own, but where a project that is not excluded depends on it, its code is analysed as part of that project. A build module outside CWD cannot be excluded.
3737
--ignore-unresolved Warn on unresolved dependencies instead of failing the run (unresolved deps are not emitted to the facts files); overrides each build's socket.json setting
3838
--json Output as JSON
3939
--markdown Output as Markdown

‎src/commands/manifest/cmd-manifest-gradle.test.mts‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ describe('socket manifest gradle', async () => {
2525
Options
2626
--bin Location of the gradle binary to use, default: ./gradlew if present, else gradle on PATH
2727
--exclude-configs When generating facts: comma-separated glob patterns; Gradle configurations matching any pattern are skipped (applied after --include-configs)
28-
--exclude-paths List of glob patterns to exclude from manifest/facts generation. Patterns are anchored micromatch globs matched relative to CWD (\`--cwd\` if set): \`tests\` matches only \`<cwd>/tests\`; use \`**/tests\` to match at any depth. Negation patterns (\`!path\`) are not supported. Accepts a comma-separated value or multiple flags. An excluded JVM build module is not analysed as a project of its own, but where a project that is not excluded depends on it, its code is analysed as part of that project.
28+
--exclude-paths List of glob patterns to exclude from manifest/facts generation. Patterns are anchored micromatch globs matched relative to CWD (\`--cwd\` if set): \`tests\` matches only \`<cwd>/tests\`; use \`**/tests\` to match at any depth. Negation patterns (\`!path\`) are not supported. Accepts a comma-separated value or multiple flags. An excluded JVM build module is not analysed as a project of its own, but where a project that is not excluded depends on it, its code is analysed as part of that project. A build module outside CWD cannot be excluded.
2929
--facts Emit a Socket facts JSON file (\`gradle.socket.facts.json\`) describing the resolved dependency graph. This is the default; pass \`--pom\` to generate \`pom.xml\` files instead
3030
--gradle-opts Additional options to pass on to ./gradlew, see \`./gradlew --help\`
3131
--ignore-unresolved When generating facts: warn on unresolved dependencies instead of failing the run (unresolved deps are not emitted to the facts file)

‎src/commands/manifest/cmd-manifest-kotlin.test.mts‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ describe('socket manifest kotlin', async () => {
2525
Options
2626
--bin Location of the gradle binary to use, default: ./gradlew if present, else gradle on PATH
2727
--exclude-configs When generating facts: comma-separated glob patterns; Gradle configurations matching any pattern are skipped (applied after --include-configs)
28-
--exclude-paths List of glob patterns to exclude from manifest/facts generation. Patterns are anchored micromatch globs matched relative to CWD (\`--cwd\` if set): \`tests\` matches only \`<cwd>/tests\`; use \`**/tests\` to match at any depth. Negation patterns (\`!path\`) are not supported. Accepts a comma-separated value or multiple flags. An excluded JVM build module is not analysed as a project of its own, but where a project that is not excluded depends on it, its code is analysed as part of that project.
28+
--exclude-paths List of glob patterns to exclude from manifest/facts generation. Patterns are anchored micromatch globs matched relative to CWD (\`--cwd\` if set): \`tests\` matches only \`<cwd>/tests\`; use \`**/tests\` to match at any depth. Negation patterns (\`!path\`) are not supported. Accepts a comma-separated value or multiple flags. An excluded JVM build module is not analysed as a project of its own, but where a project that is not excluded depends on it, its code is analysed as part of that project. A build module outside CWD cannot be excluded.
2929
--facts Emit a Socket facts JSON file (\`gradle.socket.facts.json\`) describing the resolved dependency graph. This is the default; pass \`--pom\` to generate \`pom.xml\` files instead
3030
--gradle-opts Additional options to pass on to ./gradlew, see \`./gradlew --help\`
3131
--ignore-unresolved When generating facts: warn on unresolved dependencies instead of failing the run (unresolved deps are not emitted to the facts file)

‎src/commands/manifest/cmd-manifest-maven.test.mts‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ describe('socket manifest maven', async () => {
2424
Options
2525
--bin Location of the maven binary to use, default: ./mvnw if present, else mvn on PATH
2626
--exclude-configs Comma-separated glob patterns; Maven scopes matching any pattern are skipped (applied after --include-configs)
27-
--exclude-paths List of glob patterns to exclude from manifest/facts generation. Patterns are anchored micromatch globs matched relative to CWD (\`--cwd\` if set): \`tests\` matches only \`<cwd>/tests\`; use \`**/tests\` to match at any depth. Negation patterns (\`!path\`) are not supported. Accepts a comma-separated value or multiple flags. An excluded JVM build module is not analysed as a project of its own, but where a project that is not excluded depends on it, its code is analysed as part of that project.
27+
--exclude-paths List of glob patterns to exclude from manifest/facts generation. Patterns are anchored micromatch globs matched relative to CWD (\`--cwd\` if set): \`tests\` matches only \`<cwd>/tests\`; use \`**/tests\` to match at any depth. Negation patterns (\`!path\`) are not supported. Accepts a comma-separated value or multiple flags. An excluded JVM build module is not analysed as a project of its own, but where a project that is not excluded depends on it, its code is analysed as part of that project. A build module outside CWD cannot be excluded.
2828
--ignore-unresolved Warn on unresolved dependencies instead of failing the run (unresolved deps are not emitted to the facts file)
2929
--include-configs Comma-separated glob patterns matched against Maven dependency scopes (case-sensitive; \`*\`, \`?\`, and \`[...]\` wildcards). Only scopes matching at least one pattern are resolved. e.g. \`compile,runtime\`. Default: every scope
3030
--maven-opts Additional options to pass on to maven, e.g. \`-P <profile> -s <settings.xml>\`

‎src/commands/manifest/cmd-manifest-scala.test.mts‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ describe('socket manifest scala', async () => {
2525
Options
2626
--bin Location of sbt binary to use
2727
--exclude-configs When generating facts: comma-separated glob patterns; sbt configurations matching any pattern are skipped (applied after --include-configs)
28-
--exclude-paths List of glob patterns to exclude from manifest/facts generation. Patterns are anchored micromatch globs matched relative to CWD (\`--cwd\` if set): \`tests\` matches only \`<cwd>/tests\`; use \`**/tests\` to match at any depth. Negation patterns (\`!path\`) are not supported. Accepts a comma-separated value or multiple flags. An excluded JVM build module is not analysed as a project of its own, but where a project that is not excluded depends on it, its code is analysed as part of that project.
28+
--exclude-paths List of glob patterns to exclude from manifest/facts generation. Patterns are anchored micromatch globs matched relative to CWD (\`--cwd\` if set): \`tests\` matches only \`<cwd>/tests\`; use \`**/tests\` to match at any depth. Negation patterns (\`!path\`) are not supported. Accepts a comma-separated value or multiple flags. An excluded JVM build module is not analysed as a project of its own, but where a project that is not excluded depends on it, its code is analysed as part of that project. A build module outside CWD cannot be excluded.
2929
--facts Emit a Socket facts JSON file (\`sbt.socket.facts.json\`) describing the resolved dependency graph. This is the default; pass \`--pom\` to generate \`pom.xml\` files instead
3030
--ignore-unresolved When generating facts: warn on unresolved dependencies instead of failing the run (unresolved deps are not emitted to the facts file)
3131
--include-configs When generating facts: comma-separated glob patterns matched against sbt configuration names (case-sensitive; \`*\`, \`?\`, and \`[...]\` wildcards). Only configurations matching at least one pattern are resolved. e.g. \`compile,test\`. Default: compile,optional,provided,runtime,test

‎src/commands/manifest/enumerate-workspaces.mts‎

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@ export async function enumerateWorkspaces({
2525
cwd,
2626
ecosystem,
2727
entryFile,
28+
excludeBase,
2829
excludePaths,
2930
javaHome,
3031
verbose,
@@ -35,6 +36,8 @@ export async function enumerateWorkspaces({
3536
ecosystem: BuildTool
3637
// See ManifestScriptOptions.entryFile.
3738
entryFile?: string | undefined
39+
// See ManifestScriptOptions.excludeBase.
40+
excludeBase?: string | undefined
3841
excludePaths?: string[] | undefined
3942
javaHome?: string | undefined
4043
verbose: boolean
@@ -55,6 +58,7 @@ export async function enumerateWorkspaces({
5558
const scriptOpts = {
5659
bin: bin || undefined,
5760
entryFile,
61+
excludeBase,
5862
excludePaths: excludePaths?.length ? excludePaths : undefined,
5963
// `env` replaces the spawned process's whole environment, not just JAVA_HOME.
6064
env: resolvedJavaHome

‎src/commands/manifest/generate-recursive-manifests.mts‎

Lines changed: 6 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,6 @@ import {
2424
readOrDefaultSocketJson,
2525
readSocketJsonCascade,
2626
} from '../../utils/socket-json.mts'
27-
import { projectIgnorePathsToReachExcludePaths } from '../scan/exclude-paths.mts'
2827

2928
import type { BuildRoot } from './discover-manifest-roots.mts'
3029
import type { BuildTool } from './scripts/build-tool.mts'
@@ -171,10 +170,7 @@ async function runEcosystemCandidates({
171170
const covered = new Set<string>()
172171
for (const [ecosystem, roots] of candidatesByTool) {
173172
const disabledRoots: DisabledRoot[] = []
174-
const configByDir = new Map<
175-
string,
176-
EcosystemBuildConfig & { excludePaths: string[] }
177-
>()
173+
const configByDir = new Map<string, EcosystemBuildConfig>()
178174
for (const { 0: rootIndex, 1: root } of roots.entries()) {
179175
const { dir, entryFile } = root
180176
if (isBuildRootCovered(covered, ecosystem, root)) {
@@ -188,13 +184,7 @@ async function runEcosystemCandidates({
188184
const sockJson = nearestRoot
189185
? readSocketJsonCascade(dir, nearestRoot.dir, nearestRoot.sockJson)
190186
: readSocketJsonCascade(dir, realCwd, rootSockJson)
191-
dirConfig = {
192-
...resolveEcosystemConfig(ecosystem, dir, sockJson),
193-
excludePaths: projectIgnorePathsToReachExcludePaths(excludePaths, {
194-
cwd: realCwd,
195-
target: dir,
196-
}),
197-
}
187+
dirConfig = resolveEcosystemConfig(ecosystem, dir, sockJson)
198188
configByDir.set(dir, dirConfig)
199189
if (dirConfig.skipReason) {
200190
// Only warn for a genuinely new disabled root, not one already
@@ -214,7 +204,6 @@ async function runEcosystemCandidates({
214204
bin,
215205
buildOpts,
216206
excludeConfigs,
217-
excludePaths: excludePathsForRoot,
218207
ignoreUnresolved,
219208
includeConfigs,
220209
javaHome,
@@ -234,7 +223,10 @@ async function runEcosystemCandidates({
234223
ecosystem,
235224
entryFile,
236225
excludeConfigs,
237-
excludePaths: excludePathsForRoot,
226+
// Relative to the scan root: a build can reach modules outside its
227+
// own directory (Maven `../x` modules, relocated Gradle projects).
228+
excludeBase: realCwd,
229+
excludePaths,
238230
hints: {
239231
continueOnInstallErrorsFlag: withFiles
240232
? REACH_CONTINUE_ON_INSTALL_ERRORS_FLAG

‎src/commands/manifest/generate-recursive-manifests.test.mts‎

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -496,6 +496,28 @@ describe('generateRecursiveManifests', () => {
496496
expect(byKey.get('maven:dual-marker-dir')).toBe('empty')
497497
})
498498

499+
it('passes every build root the scan-root-relative --exclude-paths and the scan root', async () => {
500+
vi.mocked(runManifestFacts).mockImplementation(async ({ cwd }) => ({
501+
factsPath: path.join(cwd, '.socket.facts.json'),
502+
projects: [],
503+
}))
504+
505+
await generateRecursiveManifests({
506+
cwd: monorepo,
507+
excludePaths: ['reactor/moduleB'],
508+
verbose: false,
509+
})
510+
511+
const reactorCall = vi
512+
.mocked(runManifestFacts)
513+
.mock.calls.map(([opts]) => opts)
514+
.find(opts => opts.cwd === reactor)
515+
expect(reactorCall).toMatchObject({
516+
excludeBase: await fs.realpath(monorepo),
517+
excludePaths: ['reactor/moduleB'],
518+
})
519+
})
520+
499521
it('resolves each build root its own nearest socket.json instead of only the root config', async () => {
500522
vi.mocked(readSocketJsonCascade).mockImplementation(
501523
(dir, _boundaryDir, fallback) =>

0 commit comments

Comments
 (0)