Skip to content

Commit 02fbf71

Browse files
committed
fix(manifest): skip .NET where no SDK runs, anchor its exclusions at the scan root
- --auto-manifest, dynamic SBOM inference and the setup wizard skip .NET builds with one warning where no .NET SDK runs, instead of failing scans of repositories that only carry a stray project file; an explicit `socket manifest dotnet` still fails. - --exclude-paths reaches a solution's projects outside its own directory: for tools whose builds reach projects anywhere, patterns stay relative to the scan root, in both generation and the setup wizard. - An unreadable solution is skipped only when its twin is readable, so two unreadable twins no longer skip each other silently. - The setup wizard detects .NET build roots; messages and help name .NET.
1 parent 072747f commit 02fbf71

26 files changed

Lines changed: 230 additions & 70 deletions

‎CHANGELOG.md‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.1.0/).
88

99
### Added
1010
- `socket manifest dotnet` [beta] generates Socket facts files for .NET solutions and projects from your own `dotnet restore`, covering PackageReference (central package management and lock files included) and packages.config projects.
11-
- `socket manifest auto`, `socket manifest setup` and `--auto-manifest` now detect .NET solutions and projects.
11+
- `socket manifest auto`, `socket manifest setup` and `--auto-manifest` now detect .NET solutions and projects, and skip them with a warning where no .NET SDK is installed.
1212

1313
## [1.12.2](https://github.com/SocketDev/socket-cli/releases/tag/v1.12.2) - 2026-10-30
1414

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ import type {
2121
const config: CliCommandConfig = {
2222
commandName: 'dynamic-sbom-inference',
2323
description:
24-
'Recursively discover gradle/sbt/maven build roots and generate a Socket facts SBOM for each',
24+
'Recursively discover gradle/sbt/maven/dotnet build roots and generate a Socket facts SBOM for each',
2525
hidden: false,
2626
flags: {
2727
...commonFlags,

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ describe('socket manifest dynamic-sbom-inference', async () => {
1818
cwd: testPath,
1919
})
2020
expect(stdout).toMatchInlineSnapshot(`
21-
"Recursively discover gradle/sbt/maven build roots and generate a Socket facts SBOM for each
21+
"Recursively discover gradle/sbt/maven/dotnet build roots and generate a Socket facts SBOM for each
2222
2323
Usage
2424
$ socket manifest dynamic-sbom-inference [options] [CWD=.]

‎src/commands/manifest/cmd-manifest-setup.mts‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@ const config: CliCommandConfig = {
3636
dynamicSbomInference: {
3737
type: 'boolean',
3838
description:
39-
'Generates dynamic SBOMs via the Gradle/sbt/Maven package manager tools for more accurate results than static resolution. Scans every build root under CWD first, so the configurator only asks about ecosystems actually found; --exclude-paths matches are bulk-disabled, others configured individually.',
39+
'Generates dynamic SBOMs via the Gradle/sbt/Maven/.NET package manager tools for more accurate results than static resolution. Scans every build root under CWD first, so the configurator only asks about ecosystems actually found; --exclude-paths matches are bulk-disabled, others configured individually.',
4040
},
4141
},
4242
help: (command, config) => `

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ describe('socket manifest setup', async () => {
2424
2525
Options
2626
--default-on-read-error If reading the socket.json fails, just use a default config? Warning: This might override the existing json file!
27-
--dynamic-sbom-inference Generates dynamic SBOMs via the Gradle/sbt/Maven package manager tools for more accurate results than static resolution. Scans every build root under CWD first, so the configurator only asks about ecosystems actually found; --exclude-paths matches are bulk-disabled, others configured individually.
27+
--dynamic-sbom-inference Generates dynamic SBOMs via the Gradle/sbt/Maven/.NET package manager tools for more accurate results than static resolution. Scans every build root under CWD first, so the configurator only asks about ecosystems actually found; --exclude-paths matches are bulk-disabled, others configured individually.
2828
--exclude-paths Build roots matching these glob patterns (and everything beneath them) are marked disabled. Patterns are anchored micromatch globs matched relative to CWD: \`legacy\` matches only \`<cwd>/legacy\`; use \`**/legacy\` to match at any depth. Negation patterns (\`!path\`) are not supported. Accepts a comma-separated value or multiple flags.
2929
3030
This command will try to detect all supported ecosystems in given CWD. Then

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ describe('socket manifest', async () => {
2828
cdxgen Run cdxgen for SBOM generation
2929
conda [beta] Convert a Conda environment.yml file to a python requirements.txt
3030
dotnet [beta] Generate Socket facts files from .NET solutions and projects
31-
dynamic-sbom-inference Recursively discover gradle/sbt/maven build roots and generate a Socket facts SBOM for each
31+
dynamic-sbom-inference Recursively discover gradle/sbt/maven/dotnet build roots and generate a Socket facts SBOM for each
3232
gradle [beta] Generate a Socket facts file (or \`pom.xml\` with --pom) for a Gradle/Java/Kotlin/etc project
3333
kotlin [beta] Generate a Socket facts file (or \`pom.xml\` with --pom) for a Kotlin project
3434
maven [beta] Generate a Socket facts file from a Maven \`pom.xml\` project

‎src/commands/manifest/discover-manifest-roots.mts‎

Lines changed: 18 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -135,27 +135,33 @@ export function isBuildRootCovered(
135135

136136
// A dotnet solution is covered once every project it builds is, or, when the
137137
// SDK cannot read it, by a same-named solution in the other format beside it
138-
// (`dotnet sln migrate` writes App.slnx next to App.sln).
138+
// (`dotnet sln migrate` writes App.slnx next to App.sln) that it can read.
139139
export async function isSolutionCovered(
140140
covered: ReadonlySet<string>,
141141
root: BuildRoot,
142-
opts: Pick<ManifestScriptOptions, 'bin' | 'excludePaths' | 'toolOpts'>,
142+
opts: Pick<
143+
ManifestScriptOptions,
144+
'bin' | 'excludeBase' | 'excludePaths' | 'toolOpts'
145+
>,
143146
listMembers: typeof listDotnetEntryProjects = listDotnetEntryProjects,
144147
): Promise<boolean> {
145148
const { entryFile } = root
146-
if (!covered.size || !entryFile || !isDotnetSolution(entryFile)) {
149+
if (!entryFile || !isDotnetSolution(entryFile)) {
147150
return false
148151
}
149-
const listed = await listMembers({
150-
...opts,
151-
entryFile,
152-
projectDir: root.dir,
153-
})
152+
const twin = entryFile.replace(/\.slnx?$/i, ext =>
153+
ext.toLowerCase() === '.sln' ? '.slnx' : '.sln',
154+
)
155+
const hasTwin = existsSync(path.join(root.dir, twin))
156+
if (!covered.size && !hasTwin) {
157+
return false
158+
}
159+
const list = (file: string) =>
160+
listMembers({ ...opts, entryFile: file, projectDir: root.dir })
161+
const listed = await list(entryFile)
154162
if (!listed) {
155-
const twin = entryFile.replace(/\.slnx?$/i, ext =>
156-
ext.toLowerCase() === '.sln' ? '.slnx' : '.sln',
157-
)
158-
if (!existsSync(path.join(root.dir, twin))) {
163+
// Unless the twin is readable, this one is built and its failure shows.
164+
if (!hasTwin || !(await list(twin))) {
159165
return false
160166
}
161167
logger.warn(

‎src/commands/manifest/discover-manifest-roots.test.mts‎

Lines changed: 30 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -351,28 +351,55 @@ describe('isSolutionCovered', () => {
351351
await fs.writeFile(path.join(dir, 'App.sln'), '')
352352
await fs.writeFile(path.join(dir, 'App.slnx'), '')
353353
const covered = new Set(['/repo/src/A/A.csproj'])
354+
const slnxUnreadable = async ({ entryFile }: { entryFile?: string }) =>
355+
entryFile?.endsWith('.slnx') ? undefined : []
354356
expect(
355357
await isSolutionCovered(
356358
covered,
357359
{ dir, entryFile: 'App.slnx' },
358360
{},
359-
unreadable,
361+
slnxUnreadable,
362+
),
363+
).toBe(true)
364+
// Also before anything is covered, e.g. when the twin built nothing.
365+
expect(
366+
await isSolutionCovered(
367+
new Set(),
368+
{ dir, entryFile: 'App.slnx' },
369+
{},
370+
slnxUnreadable,
360371
),
361372
).toBe(true)
362373
expect(
363374
await isSolutionCovered(
364375
covered,
365376
{ dir, entryFile: 'Other.slnx' },
366377
{},
367-
unreadable,
378+
slnxUnreadable,
368379
),
369380
).toBe(false)
370381
} finally {
371382
await fs.rm(dir, { recursive: true, force: true })
372383
}
373384
})
374385

375-
it('lists no members while nothing is covered, or for a project or a POM', async () => {
386+
it('builds an unreadable solution whose twin is unreadable too, so its failure shows', async () => {
387+
const dir = await fs.mkdtemp(path.join(tmpdir(), 'entry-covered-'))
388+
try {
389+
await fs.writeFile(path.join(dir, 'App.sln'), '')
390+
await fs.writeFile(path.join(dir, 'App.slnx'), '')
391+
const covered = await Promise.all(
392+
['App.sln', 'App.slnx'].map(entryFile =>
393+
isSolutionCovered(new Set(), { dir, entryFile }, {}, unreadable),
394+
),
395+
)
396+
expect(covered).toEqual([false, false])
397+
} finally {
398+
await fs.rm(dir, { recursive: true, force: true })
399+
}
400+
})
401+
402+
it('lists no members while nothing is covered and no twin exists, or for a project or a POM', async () => {
376403
const list = failToList
377404
expect(await isSolutionCovered(new Set(), root, {}, list)).toBe(false)
378405
expect(

‎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: 36 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -13,11 +13,12 @@ import {
1313
} from './discover-manifest-roots.mts'
1414
import { parseBuildToolOpts } from './parse-build-tool-opts.mts'
1515
import { runManifestFacts } from './run-manifest-facts.mts'
16-
import { resolveBuildToolBin } from './scripts/build-tool.mts'
16+
import { BUILD_FILES, resolveBuildToolBin } from './scripts/build-tool.mts'
1717
import {
1818
DSI_SETUP_COMMAND,
1919
REACH_CONTINUE_ON_INSTALL_ERRORS_FLAG,
2020
} from './scripts/resolution-report-render.mts'
21+
import { skipWithoutDotnetSdk } from './scripts/run.mts'
2122
import { SOCKET_JSON } from '../../constants.mts'
2223
import { loadSocketConfig } from '../../utils/config.mts'
2324
import { withTmpDir } from '../../utils/fs.mts'
@@ -40,6 +41,7 @@ export type RecursiveManifestOutcomeStatus =
4041
| 'generated'
4142
| 'skippedCovered'
4243
| 'skippedDisabled'
44+
| 'skippedNoSdk'
4345

4446
export type RecursiveManifestOutcome = BuildRoot & {
4547
ecosystem: BuildTool
@@ -174,7 +176,10 @@ async function runEcosystemCandidates({
174176
const disabledRoots: DisabledRoot[] = []
175177
const configByDir = new Map<
176178
string,
177-
EcosystemBuildConfig & { excludePaths: string[] }
179+
EcosystemBuildConfig & {
180+
excludeBase: string | undefined
181+
excludePaths: string[]
182+
}
178183
>()
179184
for (const { 0: rootIndex, 1: root } of roots.entries()) {
180185
const { dir, entryFile } = root
@@ -191,10 +196,7 @@ async function runEcosystemCandidates({
191196
: readSocketJsonCascade(dir, realCwd, rootSockJson)
192197
dirConfig = {
193198
...resolveEcosystemConfig(ecosystem, dir, sockJson),
194-
excludePaths: projectIgnorePathsToReachExcludePaths(excludePaths, {
195-
cwd: realCwd,
196-
target: dir,
197-
}),
199+
...rootExcludePaths(ecosystem, dir, realCwd, excludePaths),
198200
}
199201
configByDir.set(dir, dirConfig)
200202
if (dirConfig.skipReason) {
@@ -214,6 +216,7 @@ async function runEcosystemCandidates({
214216
const {
215217
bin,
216218
buildOpts,
219+
excludeBase,
217220
excludeConfigs,
218221
excludePaths: excludePathsForRoot,
219222
ignoreUnresolved,
@@ -226,10 +229,16 @@ async function runEcosystemCandidates({
226229
outcomes.push({ ...root, ecosystem, status: 'skippedDisabled' })
227230
continue
228231
}
232+
// eslint-disable-next-line no-await-in-loop
233+
if (ecosystem === 'dotnet' && (await skipWithoutDotnetSdk(bin, dir))) {
234+
outcomes.push({ ...root, ecosystem, status: 'skippedNoSdk' })
235+
continue
236+
}
229237
if (
230238
// eslint-disable-next-line no-await-in-loop
231239
await isSolutionCovered(covered, root, {
232240
bin,
241+
excludeBase,
233242
excludePaths: excludePathsForRoot,
234243
toolOpts: buildOpts,
235244
})
@@ -245,6 +254,7 @@ async function runEcosystemCandidates({
245254
cwd: dir,
246255
ecosystem,
247256
entryFile,
257+
excludeBase,
248258
excludeConfigs,
249259
excludePaths: excludePathsForRoot,
250260
hints: {
@@ -388,6 +398,26 @@ export async function generateRecursiveManifests({
388398
// A wrapper-preferred `bin` default is resolved per-root (`dir`, not `cwd`)
389399
// since a wrapper script only exists at the actual build root. Exported for
390400
// reuse by the recursive setup wizard's reactor-coverage pruning.
401+
// --exclude-paths for one build root: relative to the root, or to the scan
402+
// root for a tool whose builds reach their projects wherever they live.
403+
export function rootExcludePaths(
404+
ecosystem: BuildTool,
405+
dir: string,
406+
cwd: string,
407+
excludePaths: readonly string[] | undefined,
408+
): { excludeBase: string | undefined; excludePaths: string[] } {
409+
const buildFiles = BUILD_FILES[ecosystem]
410+
const excludeBase =
411+
buildFiles.byFile && buildFiles.projectsResolveAlone ? cwd : undefined
412+
return {
413+
excludeBase,
414+
excludePaths: projectIgnorePathsToReachExcludePaths(excludePaths, {
415+
cwd,
416+
target: excludeBase ?? dir,
417+
}),
418+
}
419+
}
420+
391421
export function resolveEcosystemConfig(
392422
ecosystem: BuildTool,
393423
dir: string,

0 commit comments

Comments
 (0)