Skip to content

Commit 5778776

Browse files
authored
pnpm workspace tree (#1417)
* Retain pnpm workspace packages tree Signed-off-by: Prabhu Subramanian <[email protected]> * Support for file and workspace links Signed-off-by: Prabhu Subramanian <[email protected]> * Support for overrides Signed-off-by: Prabhu Subramanian <[email protected]> * Types Signed-off-by: Prabhu Subramanian <[email protected]> --------- Signed-off-by: Prabhu Subramanian <[email protected]>
1 parent 41cca69 commit 5778776

File tree

20 files changed

+10184
-259
lines changed

20 files changed

+10184
-259
lines changed

.github/workflows/npm-release.yml

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -74,8 +74,7 @@ jobs:
7474
chmod +x nydus-static/*
7575
mv nydus-static/* /usr/local/bin/
7676
rm -rf nydus-static-v2.2.4-linux-amd64.tgz nydus-static
77-
- name: Set up QEMU
78-
uses: docker/setup-qemu-action@v3
77+
- run: docker run --rm --privileged multiarch/qemu-user-static --reset -p yes
7978
- name: Set up Docker Buildx
8079
uses: docker/setup-buildx-action@v3
8180
- name: Log in to the Container registry

.vscode/settings.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,5 +4,6 @@
44
"quickfix.biome": "explicit",
55
"source.organizeImports.biome": "explicit"
66
},
7-
"editor.defaultFormatter": "biomejs.biome"
7+
"editor.defaultFormatter": "biomejs.biome",
8+
"deno.enable": false
89
}

bin/cdxgen.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ import fs from "node:fs";
55
import { tmpdir } from "node:os";
66
import { basename, dirname, join, resolve } from "node:path";
77
import process from "node:process";
8-
import { URL, fileURLToPath } from "node:url";
8+
import { URL } from "node:url";
99
import { findUpSync } from "find-up";
1010
import globalAgent from "global-agent";
1111
import { load as _load } from "js-yaml";

bin/verify.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
11
#!/usr/bin/env node
22

33
import fs from "node:fs";
4-
import { dirname, join } from "node:path";
4+
import { join } from "node:path";
55
import process from "node:process";
6-
import { URL, fileURLToPath } from "node:url";
6+
import { URL } from "node:url";
77
import jws from "jws";
88
import yargs from "yargs";
99
import { hideBin } from "yargs/helpers";

biome.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
{
2-
"$schema": "https://biomejs.dev/schemas/1.8.1/schema.json",
2+
"$schema": "https://biomejs.dev/schemas/1.9.3/schema.json",
33
"organizeImports": {
44
"enabled": true
55
},

ci/Dockerfile

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -143,7 +143,6 @@ RUN set -e; \
143143
&& sudo ./linux-install.sh \
144144
&& curl -L --output /usr/local/bin/bazel https://github.com/bazelbuild/bazelisk/releases/latest/download/bazelisk-linux-${GOBIN_VERSION} \
145145
&& chmod +x /usr/local/bin/bazel \
146-
&& bazel --version \
147146
&& useradd -ms /bin/bash cyclonedx \
148147
&& npm install --unsafe-perm -g node-gyp @microsoft/rush --omit=dev \
149148
&& npx node-gyp install \
@@ -155,7 +154,7 @@ RUN set -e; \
155154
&& gem install bundler \
156155
&& gem --version \
157156
&& bundler --version \
158-
&& cd /opt/cdxgen && corepack enable && corepack pnpm install --prod --package-import-method copy \
157+
&& cd /opt/cdxgen && corepack enable && corepack pnpm install --prod --package-import-method copy && corepack pnpm cache delete \
159158
&& mkdir -p /opt/cdxgen-node-cache \
160159
&& chown -R cyclonedx:cyclonedx /opt/cdxgen /opt/cdxgen-node-cache \
161160
&& chmod a-w -R /opt \

ci/Dockerfile-ppc64

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -106,7 +106,7 @@ RUN set -e; \
106106
&& gem --version \
107107
&& bundler --version
108108
COPY . /opt/cdxgen
109-
RUN cd /opt/cdxgen && corepack enable && corepack pnpm install --prod --package-import-method copy \
109+
RUN cd /opt/cdxgen && corepack enable && corepack pnpm install --prod --package-import-method copy && corepack pnpm cache delete \
110110
&& chown -R cyclonedx:cyclonedx /opt/cdxgen \
111111
&& chmod a-w -R /opt \
112112
&& rm -rf /root/.cache /var/cache/yum /root/.cargo \

deno.json

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -3,9 +3,7 @@
33
"version": "10.10.5",
44
"exports": "./lib/cli/index.js",
55
"compilerOptions": {
6-
"allowJs": true,
76
"lib": ["deno.window"],
8-
"exclude": ["*.test.js", "./types/**/*"],
97
"strict": true
108
},
119
"include": ["*.js", "data/", "bin/", "lib/**"],
@@ -52,8 +50,8 @@
5250
"imports": {
5351
"@appthreat/atom": "npm:@appthreat/[email protected]",
5452
"@appthreat/cdx-proto": "npm:@appthreat/[email protected]",
55-
"@babel/parser": "npm:@babel/parser@^7.24.8",
56-
"@babel/traverse": "npm:@babel/traverse@^7.24.8",
53+
"@babel/parser": "npm:@babel/parser@^7.25.8",
54+
"@babel/traverse": "npm:@babel/traverse@^7.25.7",
5755
"@npmcli/arborist": "npm:@npmcli/[email protected]",
5856
"ajv": "npm:ajv@^8.16.0",
5957
"ajv-formats": "npm:ajv-formats@^3.0.1",
@@ -62,7 +60,7 @@
6260
"find-up": "npm:[email protected]",
6361
"glob": "npm:glob@^11.0.0",
6462
"global-agent": "npm:global-agent@^3.0.0",
65-
"got": "npm:[email protected].2",
63+
"got": "npm:got@^14.4.3",
6664
"iconv-lite": "npm:iconv-lite@^0.6.3",
6765
"js-yaml": "npm:js-yaml@^4.1.0",
6866
"jws": "npm:jws@^4.0.0",

docs/PROJECT_TYPES.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ _Note: there are multiple project types / aliases that will produce the same out
1313

1414
| Language/Platform | Project Types | Package Formats | Supported Evidence | Supports Transitives |
1515
| ------------------------- | ---------------------------------------------------------------------------------------------------------------------------------------------------------------- | ------------------------------------------------------------------------------------------------------------------------------------- | ----------------------------------------------------------------------------------------------------- | -------------------- |
16-
| Node.js | `npm`, `pnpm`, `nodejs`, `js`, `javascript`, `typescript`, `ts`, `tsx` | `npm-shrinkwrap.json`, `package-lock.json`, `pnpm-lock.yaml`, `yarn.lock`, `rush.js`, `bower.json`, `.min.js` | Yes, except for `.min.js` ||
16+
| Node.js | `npm`, `pnpm`, `nodejs`, `js`, `javascript`, `typescript`, `ts`, `tsx`, `yarn`, `rush` | `npm-shrinkwrap.json`, `package-lock.json`, `pnpm-lock.yaml`, `yarn.lock`, `rush.js`, `bower.json`, `.min.js` | Yes, except for `.min.js` ||
1717
| Java (Default) | `java`, `groovy`, `kotlin`, `scala`, `jvm`, `gradle`, `mvn`, `maven`, `sbt` | `pom.xml` [1], `build.gradle`, `.kts`, `sbt`, `bazel` | Yes, unless `pom.xml` is manually parsed due to unavailability of maven or errors) ||
1818
| Java (Specific version) | `java8`, `java11`, `java17`, `java21`, `java22`, `java23` | `pom.xml` [1], `build.gradle`, `.kts`, `sbt`, `bazel` | Yes, unless `pom.xml` is manually parsed due to unavailability of maven or errors) ||
1919
| Android | `android`, `apk`, `aab` | `apk`, `aab` | - | - |

lib/cli/index.js

Lines changed: 53 additions & 38 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ import {
1616
import { platform as _platform, homedir, tmpdir } from "node:os";
1717
import { basename, dirname, join, resolve, sep } from "node:path";
1818
import process from "node:process";
19-
import { URL, fileURLToPath } from "node:url";
19+
import { URL } from "node:url";
2020
import got from "got";
2121
import { PackageURL } from "packageurl-js";
2222
import { parse } from "ssri";
@@ -27,7 +27,6 @@ import {
2727
getOriginUrl,
2828
gitTreeHashes,
2929
listFiles,
30-
runSwiftCommand,
3130
} from "../helpers/envcontext.js";
3231
import {
3332
CARGO_CMD,
@@ -161,7 +160,6 @@ import { collectOSCryptoLibs } from "../helpers/cbomutils.js";
161160
import {
162161
executeOsQuery,
163162
getBinaryBom,
164-
getCargoAuditableInfo,
165163
getDotnetSlices,
166164
getOSPackages,
167165
} from "../managers/binary.js";
@@ -2310,17 +2308,44 @@ export async function createNodejsBom(path, options) {
23102308
options,
23112309
);
23122310
}
2313-
if (pnpmLockFiles?.length) {
2311+
if (
2312+
pnpmLockFiles?.length &&
2313+
isPackageManagerAllowed("pnpm", ["npm", "yarn", "rush"], options)
2314+
) {
23142315
manifestFiles = manifestFiles.concat(pnpmLockFiles);
23152316
for (const f of pnpmLockFiles) {
2317+
if (DEBUG_MODE) {
2318+
console.log(`Parsing ${f}`);
2319+
}
23162320
const basePath = dirname(f);
23172321
// Determine the parent component
23182322
const packageJsonF = join(basePath, "package.json");
2319-
if (existsSync(packageJsonF)) {
2320-
const pcs = await parsePkgJson(packageJsonF, true);
2321-
if (pcs.length) {
2322-
parentComponent = pcs[0];
2323-
parentComponent.type = "application";
2323+
if (!Object.keys(parentComponent).length) {
2324+
if (existsSync(packageJsonF)) {
2325+
const pcs = await parsePkgJson(packageJsonF, true);
2326+
if (pcs.length) {
2327+
parentComponent = pcs[0];
2328+
parentComponent.type = "application";
2329+
ppurl = new PackageURL(
2330+
"npm",
2331+
options.projectGroup || parentComponent.group,
2332+
parentComponent.name,
2333+
options.projectVersion || parentComponent.version,
2334+
null,
2335+
null,
2336+
).toString();
2337+
parentComponent["bom-ref"] = decodeURIComponent(ppurl);
2338+
parentComponent["purl"] = ppurl;
2339+
}
2340+
} else {
2341+
let dirName = dirname(f);
2342+
const tmpA = dirName.split(sep);
2343+
dirName = tmpA[tmpA.length - 1];
2344+
parentComponent = {
2345+
group: "",
2346+
name: dirName,
2347+
type: "application",
2348+
};
23242349
ppurl = new PackageURL(
23252350
"npm",
23262351
options.projectGroup || parentComponent.group,
@@ -2332,32 +2357,16 @@ export async function createNodejsBom(path, options) {
23322357
parentComponent["bom-ref"] = decodeURIComponent(ppurl);
23332358
parentComponent["purl"] = ppurl;
23342359
}
2335-
} else {
2336-
let dirName = dirname(f);
2337-
const tmpA = dirName.split(sep);
2338-
dirName = tmpA[tmpA.length - 1];
2339-
parentComponent = {
2340-
group: "",
2341-
name: dirName,
2342-
type: "application",
2343-
};
2344-
ppurl = new PackageURL(
2345-
"npm",
2346-
options.projectGroup || parentComponent.group,
2347-
options.projectName || parentComponent.name,
2348-
options.projectVersion || parentComponent.version,
2349-
null,
2350-
null,
2351-
).toString();
2352-
parentComponent["bom-ref"] = decodeURIComponent(ppurl);
2353-
parentComponent["purl"] = ppurl;
23542360
}
23552361
// Parse the pnpm file
23562362
const parsedList = await parsePnpmLock(f, parentComponent);
23572363
const dlist = parsedList.pkgList;
23582364
if (dlist?.length) {
23592365
pkgList = pkgList.concat(dlist);
23602366
}
2367+
if (parsedList?.parentSubComponents?.length) {
2368+
parentComponent.components = parsedList.parentSubComponents;
2369+
}
23612370
if (parsedList.dependenciesList && parsedList.dependenciesList) {
23622371
dependencies = mergeDependencies(
23632372
dependencies,
@@ -2367,7 +2376,10 @@ export async function createNodejsBom(path, options) {
23672376
}
23682377
}
23692378
}
2370-
if (pkgLockFiles?.length) {
2379+
if (
2380+
pkgLockFiles?.length &&
2381+
isPackageManagerAllowed("npm", ["pnpm", "yarn"], options)
2382+
) {
23712383
manifestFiles = manifestFiles.concat(pkgLockFiles);
23722384
for (const f of pkgLockFiles) {
23732385
if (DEBUG_MODE) {
@@ -2395,7 +2407,10 @@ export async function createNodejsBom(path, options) {
23952407
}
23962408
}
23972409
}
2398-
if (existsSync(join(path, "rush.json"))) {
2410+
if (
2411+
existsSync(join(path, "rush.json")) &&
2412+
isPackageManagerAllowed("rush", ["npm", "yarn", "pnpm"], options)
2413+
) {
23992414
// Rush.js creates node_modules inside common/temp directory
24002415
const nmDir = join(path, "common", "temp", "node_modules");
24012416
// Do rush install if we don't have node_modules directory
@@ -2466,7 +2481,10 @@ export async function createNodejsBom(path, options) {
24662481
);
24672482
options.failOnError && process.exit(1);
24682483
}
2469-
if (yarnLockFiles?.length) {
2484+
if (
2485+
yarnLockFiles?.length &&
2486+
isPackageManagerAllowed("yarn", ["npm", "pnpm"], options)
2487+
) {
24702488
manifestFiles = manifestFiles.concat(yarnLockFiles);
24712489
for (const f of yarnLockFiles) {
24722490
if (DEBUG_MODE) {
@@ -2483,7 +2501,7 @@ export async function createNodejsBom(path, options) {
24832501
ppurl = new PackageURL(
24842502
"npm",
24852503
options.projectGroup || tmpParentComponent.group,
2486-
options.projectName || tmpParentComponent.name,
2504+
tmpParentComponent.name,
24872505
options.projectVersion || tmpParentComponent.version,
24882506
null,
24892507
null,
@@ -2542,7 +2560,7 @@ export async function createNodejsBom(path, options) {
25422560
const ppurl = new PackageURL(
25432561
"npm",
25442562
options.projectGroup || parentComponent.group,
2545-
options.projectName || parentComponent.name,
2563+
parentComponent.name,
25462564
options.projectVersion || parentComponent.version,
25472565
null,
25482566
null,
@@ -2584,7 +2602,7 @@ export async function createNodejsBom(path, options) {
25842602
ppurl = new PackageURL(
25852603
"npm",
25862604
options.projectGroup || parentComponent.group,
2587-
options.projectName || parentComponent.name,
2605+
parentComponent.name,
25882606
options.projectVersion || parentComponent.version,
25892607
null,
25902608
null,
@@ -2634,7 +2652,6 @@ export function createPixiBom(path, options) {
26342652
let dependencies = [];
26352653
let pkgList = [];
26362654
let formulationList = [];
2637-
let frozen = true;
26382655
let parentComponent = createDefaultParentComponent(path, "pypi", options);
26392656
let PixiLockData = {};
26402657

@@ -2689,7 +2706,6 @@ export function createPixiBom(path, options) {
26892706
}
26902707

26912708
pkgList = PixiLockData.pkgList;
2692-
frozen = PixiLockData.frozen;
26932709
formulationList = PixiLockData.formulationList;
26942710
dependencies = PixiLockData.dependencies;
26952711

@@ -5048,14 +5064,13 @@ export async function createCsharpBom(path, options) {
50485064
const csProjData = readFileSync(f, { encoding: "utf-8" });
50495065
const retMap = parseCsProjData(csProjData, f, {});
50505066
if (retMap?.parentComponent?.properties) {
5051-
const parentProperties = retMap.parentComponent.properties;
50525067
retMap.parentComponent.properties
50535068
.filter(
50545069
(p) =>
50555070
p.name === "cdx:dotnet:target_framework" && p.value.trim().length,
50565071
)
50575072
.forEach((p) => {
5058-
const frameworkValues = p.value
5073+
p.value
50595074
.split(";")
50605075
.filter((v) => v.trim().length && !v.startsWith("$("))
50615076
.forEach((v) => {

0 commit comments

Comments
 (0)