Skip to content

Commit 14cc3cd

Browse files
authored
docs: update scanner API (#556)
1 parent 1ecbe92 commit 14cc3cd

File tree

4 files changed

+43
-17
lines changed

4 files changed

+43
-17
lines changed

.changeset/cold-days-double.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
"@nodesecure/scanner": minor
3+
---
4+
5+
Update scanner API documentation & add FromOptions interface to match CwdOptions

README.md

Lines changed: 30 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ Scorecard](https://api.securityscorecards.dev/projects/github.com/NodeSecure/sca
1111

1212
## Requirements
1313

14-
- [Node.js](https://nodejs.org/en/) version 20 or higher
14+
- [Node.js](https://nodejs.org/en/) version 22 or higher
1515

1616
## Getting Started
1717

@@ -47,32 +47,54 @@ await Promise.allSettled(promises);
4747

4848
## API
4949

50-
See `types/api.d.ts` for a complete TypeScript definition.
50+
See [types.ts](https://github.com/NodeSecure/scanner/blob/master/workspaces/scanner/src/types.ts) for a complete TypeScript definition.
5151

5252
```ts
5353
function cwd(
5454
location: string,
55-
options?: Scanner.Options
55+
options?: Scanner.CwdOptions,
56+
logger?: Scanner.Logger
5657
): Promise<Scanner.Payload>;
5758
function from(
5859
packageName: string,
59-
options?: Omit<Scanner.Options, "includeDevDeps">
60+
options?: Scanner.FromOptions,
61+
logger?: Scanner.Logger
6062
): Promise<Scanner.Payload>;
6163
function verify(
62-
packageName?: string | null
64+
packageName?: string
6365
): Promise<tarball.ScannedPackageResult>;
6466
```
6567

66-
`Options` is described with the following TypeScript interface:
68+
`CwdOptions` and `FromOptions` are described with the following TypeScript interfaces:
6769

6870
```ts
71+
72+
type CwdOptions = Options & {
73+
/**
74+
* NPM runtime configuration (such as local .npmrc file)
75+
* It is optionally used to fetch registry authentication tokens
76+
*/
77+
npmRcConfig?: Config;
78+
};
79+
80+
type FromOptions = Omit<Options, "includeDevDeps">;
81+
6982
interface Options {
7083
/**
71-
* Maximum tree depth
84+
* Specifies the maximum depth to traverse for each root dependency.
85+
* For example, a value of 2 would mean only traversing dependencies and their immediate dependencies.
7286
*
7387
* @default Infinity
7488
*/
75-
readonly maxDepth?: number;
89+
maxDepth?: number;
90+
91+
/**
92+
* Includes development dependencies in the walk.
93+
* Note that enabling this option can significantly increase I/O and processing time.
94+
*
95+
* @default false
96+
*/
97+
includeDevDeps?: boolean;
7698

7799
readonly registry?: string | URL;
78100

@@ -103,13 +125,6 @@ interface Options {
103125
contacts: Contact[];
104126
};
105127

106-
/**
107-
* Include project devDependencies (only available for cwd command)
108-
*
109-
* @default false
110-
*/
111-
readonly includeDevDeps?: boolean;
112-
113128
/**
114129
* Vulnerability strategy name (npm, snyk, node)
115130
*

workspaces/scanner/src/index.ts

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,10 @@ export * from "./types.js";
2828
export * from "./extractors/index.js";
2929

3030
export type CwdOptions = Options & {
31+
/**
32+
* NPM runtime configuration (such as local .npmrc file)
33+
* It is optionally used to fetch registry authentication tokens
34+
*/
3135
npmRcConfig?: Config;
3236
};
3337

@@ -66,9 +70,11 @@ export async function cwd(
6670
);
6771
}
6872

73+
export type FromOptions = Omit<Options, "includeDevDeps">;
74+
6975
export async function from(
7076
packageName: string,
71-
options: Omit<Options, "includeDevDeps"> = {},
77+
options: FromOptions = {},
7278
logger = new Logger()
7379
) {
7480
const registry = options.registry ?

workspaces/scanner/src/types.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -206,7 +206,7 @@ export interface Options {
206206
/**
207207
* Maximum tree depth
208208
*
209-
* @default 4
209+
* @default Infinity
210210
*/
211211
readonly maxDepth?: number;
212212

0 commit comments

Comments
 (0)