Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
29 changes: 28 additions & 1 deletion src/builders.ts
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ import {
} from './_helpers'
import { PropertyNames, PropertyValueBool } from './cdx'
import type { NpmRunner } from './npmRunner'
import * as fs from "node:fs";

type OmittableDependencyTypes = 'dev' | 'optional' | 'peer'

Expand Down Expand Up @@ -143,6 +144,15 @@ export class BomBuilder {

this.console.info('INFO | gathering dependency tree ...')
this.console.debug('DEBUG | npm-ls: run npm with %j in %j', args, projectDir)

/*
const env = Object.fromEntries(
Object.entries(process_.env).filter(
([k,]) => !(
k.toLowerCase().startsWith('node_') ||
k.toLowerCase().startsWith('npm_'))))
*/

/* eslint-disable-next-line @typescript-eslint/init-declarations -- ack */
let npmLsReturns: Buffer
try {
Expand Down Expand Up @@ -175,9 +185,26 @@ export class BomBuilder {
/* eslint-disable-next-line @typescript-eslint/no-unsafe-assignment, @typescript-eslint/no-unsafe-member-access -- ack */
npmLsReturns = runError.stdout ?? Buffer.alloc(0)
}

const rres = npmLsReturns.toString()

const dbgF = fs.openSync(path.join(__dirname, '..', 'dbg', `dbg${Math.random()}`), 'w')
fs.writeSync(dbgF, JSON.stringify(
{
args,
cwd: projectDir,
env: process_.env,
}
))
fs.writeSync(dbgF, "\n\n")
fs.writeSync(dbgF, rres)
fs.closeSync(dbgF)



// this.console.debug('stdout: %s', npmLsReturns)
try {
return JSON.parse(npmLsReturns.toString())
return JSON.parse(rres)
} catch (jsonParseError) {
throw new Error(
'failed to parse npm-ls response',
Expand Down
2 changes: 2 additions & 0 deletions tests/_data/dummy_projects/with-prepared/.gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,11 @@
!/node_modules/**/*
!/package.json
!/package-lock.json
!/.npmrc

!/setup.sh
!/README.md

!/LICENCE.mit
!/LICENSES/
!/LICENSES/*
4 changes: 4 additions & 0 deletions tests/_data/dummy_projects/with-prepared/.npmrc
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
; see the docs: https://docs.npmjs.com/cli/v9/using-npm/config

engine-strict=false
package-lock=true
8 changes: 4 additions & 4 deletions tests/integration/cli.from-setups.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -41,17 +41,17 @@ describe('integration.cli.from-setups', () => {
{
subject: 'bare',
args: [],
dummyProject: ['with-prepared']
dummyProjects: ['with-prepared']
},
{
subject: 'flat',
args: [],
dummyProject: ['with-prepared']
dummyProjects: ['with-prepared']
},
{
subject: 'with-licenses',
args: ['--gather-license-texts'],
dummyProject: ['with-prepared']
dummyProjects: ['with-prepared']
}
]

Expand Down Expand Up @@ -102,7 +102,7 @@ describe('integration.cli.from-setups', () => {
}

describe.each(useCases)('subject: $subject', (ud) => {
describe.each(ud.dummyProject)('dummyProject: %s', (dummyProject) => {
describe.each(ud.dummyProjects)('dummyProject: %s', (dummyProject) => {
describe.each(formats)('format: %s', (format) => {
(skipAllTests
? test.skip
Expand Down