Skip to content

Commit 23920aa

Browse files
committed
refactor: migrate CLI into it's own workspace
1 parent d1e8d99 commit 23920aa

205 files changed

Lines changed: 352 additions & 273 deletions

File tree

Some content is hidden

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

‎README.md‎

Lines changed: 28 additions & 149 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
11
<p align="center"><h1 align="center">
2-
🐢 Node-Secure CLI 🚀
2+
🐢 Node-Secure 🚀
33
</h1>
44

55
<p align="center">
6-
a Node.js CLI to deeply analyze the dependency tree of a given NPM package or Node.js local app
6+
Deeply analyze the dependency tree of a given NPM package or Node.js local app to spot security threats.
77
</p>
88

99
<p align="center">
@@ -28,158 +28,56 @@
2828
</p>
2929

3030
<p align="center">
31-
<img src="./docs/ui-preview.PNG">
31+
<img src="./workspaces/cli/docs/ui-preview.PNG">
3232
</p>
3333

34-
## 📜 Features
35-
36-
- Run a static scan on every JavaScript files and sort out warnings (unsafe-regex, unsafe-import etc) and the complete list of required expr and statements (files, node.js module, etc.).
37-
- Return complete composition for each packages (extensions, files, tarball size, etc).
38-
- Packages metadata from the npm registry API (number of releases, last publish date, maintainers etc).
39-
- Search for licenses files in the tarball and return the [SPDX](https://spdx.org/licenses/) expression conformance of each detected licenses.
40-
- Link vulnerabilities from the multiple sources like GitHub Advisory, Sonatype or Snyk using [Vulnera](https://github.com/NodeSecure/vulnera).
41-
- Add flags (emojis) to each packages versions to identify well known patterns and potential security threats easily.
42-
- First-class support of open source security initiatives like [OpenSSF Scorecard](https://github.com/ossf/scorecard).
43-
- Generate security report (PDF).
44-
45-
## 🚧 Requirements
46-
47-
- [Node.js](https://nodejs.org/en/) v24 or higher
34+
**NodeSecure** is a Node.js CLI (`nsecure`) that performs a static and deep analysis of a package's dependency tree: AST-based scanning for malicious or unsafe patterns, npm registry metadata, license conformance, vulnerability aggregation (GitHub Advisory, Sonatype, Snyk) and [OpenSSF Scorecard](https://github.com/ossf/scorecard), all rendered through an interactive dependency graph with a PDF report generator.
4835

4936
## 💃 Getting Started
5037

5138
```bash
5239
$ npm install @nodesecure/cli -g
53-
```
54-
55-
or
56-
57-
```bash
58-
$ git clone https://github.com/NodeSecure/cli.git
59-
$ cd cli
60-
61-
$ npm install
62-
# bundle/compile front-end assets
63-
$ npm run build
64-
$ npm link
65-
```
66-
67-
Then the **nsecure** binary will be available in your terminal. Give a try with the popular [express](http://expressjs.com/) package. This will automatically open the webpage in your default system browser.
68-
```bash
6940
$ nsecure auto express
7041
```
7142

72-
> [!TIP]
73-
> Setup an [npm token](https://github.com/NodeSecure/cli#private-packages--registry) to avoid hiting the maximum request limit of the npm registry API.
74-
75-
## 👀 Usage example
76-
77-
```bash
78-
# Run a scan on the current working dir
79-
# Note: must have a package.json or node_modules directory
80-
$ nsecure cwd
81-
82-
# Run a scan on a remote 'npm' package
83-
$ nsecure from mocha
84-
```
43+
This repository is a monorepo. The `@nodesecure/cli` package, along with its full feature list, command documentation, configuration and FAQ, lives in the [workspaces/cli](./workspaces/cli) workspace — head there for everything about installing and using the CLI.
8544

86-
Then a `nsecure-result.json` will be writted at the current CLI location. To open it on a web page just run
45+
## 📦 Workspaces
8746

88-
```bash
89-
$ nsecure open
90-
```
47+
| name | package and link |
48+
| --- | --- |
49+
| cli | [@nodesecure/cli](./workspaces/cli) |
50+
| documentation-ui | [@nodesecure/documentation-ui](./workspaces/documentation-ui) |
51+
| vis-network | [@nodesecure/vis-network](./workspaces/vis-network) |
52+
| size-satisfies | [@nodesecure/size-satisfies](./workspaces/size-satisfies) |
53+
| server | [@nodesecure/server](./workspaces/server) |
54+
| cache | [@nodesecure/cache](./workspaces/cache) |
9155

92-
### Command Documentation
56+
These packages are available in the Node Package Repository and can be easily installed with [npm](https://docs.npmjs.com/getting-started/what-is-npm) or [yarn](https://yarnpkg.com), for example:
9357

94-
The CLI includes built-in documentation accessible with the --help option:
9558
```bash
96-
$ nsecure --help
97-
$ nsecure <command> --help
59+
$ npm i @nodesecure/documentation-ui
60+
# or
61+
$ yarn add @nodesecure/documentation-ui
9862
```
9963

100-
For complete details on each command, refer to the following documents:
101-
102-
- [`cwd`](./docs/cli/cwd.md)
103-
- [`from`](./docs/cli/from.md)
104-
- [`auto`](./docs/cli/auto.md)
105-
- [`open`](./docs/cli/open.md)
106-
- [`verify`](./docs/cli/verify.md)
107-
- [`summary`](./docs/cli/summary.md)
108-
- [`scorecard`](./docs/cli/scorecard.md)
109-
- [`report`](./docs/cli/report.md)
110-
- [`lang`](./docs/cli/lang.md)
111-
- [`config create`](./docs/cli/config.md)
112-
- [`config`](./docs/cli/config.md)
113-
- [`cache`](./docs/cli/cache.md)
114-
- [`extract integrity`](./docs/cli/extract-integrity.md)
115-
- [`stats`](./docs/cli/stats.md)
116-
- [re-highlight](./docs/cli/re-highlight.md)
117-
118-
Each link provides access to the full documentation for the command, including additional details, options, and usage examples.
119-
120-
## Private registry / Verdaccio
121-
122-
NodeSecure allow you to fetch stats on private npm packages by setting up a `NODE_SECURE_TOKEN` env variable (which must contains an [npm token](https://docs.npmjs.com/creating-and-viewing-authentication-tokens)).
64+
## 🙏 Contributing
12365

124-
> [!TIP]
125-
> If you `npm link` the package by yourself you can create a `.env` file at the root of the project too.
66+
If you are a developer **looking to contribute** to the project, please first read our [CONTRIBUTING](./CONTRIBUTING.md) guide (Code of Conduct, first-contributor guide, Developer's Certificate of Origin, Discord).
12667

127-
NodeSecure is capable to work behind a custom private npm registry too by searching the default registry URL in your local npm configuration.
68+
### Local Setup
12869

12970
```bash
130-
$ npm config get registry
131-
$ npm config set registry "http://your-registry/"
132-
```
133-
134-
## API
135-
Our back-end scanner package is available [here](https://github.com/NodeSecure/scanner).
136-
137-
## Flags legends
138-
139-
Flags and emojis legends are documented [here](https://github.com/NodeSecure/flags/blob/main/FLAGS.md).
140-
141-
## Search command
142-
143-
Press `Cmd+K` (macOS) or `Ctrl+K` (Windows/Linux) from the network view to open the search command. It lets you filter the dependency graph using one or more criteria simultaneously.
144-
145-
Type a package name directly to search, or prefix with a filter name followed by `:` to use a specific filter:
146-
147-
- `package` — **default when no prefix is given**, matches by name.
148-
- `version` — semver range (e.g. `>=1.2.0`, `^2.0.0`).
149-
- `flag` — select from the list of flags present in the current tree.
150-
- `license` — SPDX identifier (e.g. `MIT`, `Apache-2.0`).
151-
- `author` — author name or email.
152-
- `ext` — file extension present in the package (e.g. `.js`, `.ts`).
153-
- `builtin` — Node.js core module used by the package (e.g. `fs`, `path`).
154-
- `size` — size range (see [size-satisfies](https://github.com/NodeSecure/size-satisfies#usage-example), e.g. `>50kb`, `10kb..200kb`).
155-
- `highlighted` — all highlighted packages by default.
156-
157-
## FAQ
158-
159-
### Why some nodes are red in the UI ?
160-
Nodes are highlighted in red when the project/package is flagged with 🔬 `hasMinifiedCode` or ⚠️ `hasWarnings`. You can deactivate specific warnings in the options if desired.
161-
162-
### Why the package size is so different from Bundlephobia ?
163-
The back-end scanner will analyze the complete size of the npm tarball without any filters or specific optimizations. In contrast, Bundlephobia will bundle the package and remove most of the unnecessary files from the tarball, such as documentation and other non-essential items.
164-
165-
### Why some packages don't have OSSF Scorecard ?
166-
See [Scorecard Public Data](https://github.com/ossf/scorecard#public-data):
167-
168-
> [!NOTE]
169-
> We run a weekly Scorecard scan of the 1 million most critical open source projects judged by their direct dependencies and publish the results in a BigQuery public dataset.
170-
171-
## Contributors guide
172-
173-
If you are a developer **looking to contribute** to the project, you must first read the [CONTRIBUTING](./CONTRIBUTING.md) guide.
174-
175-
If you have already cloned and installed the project locally with npm, you still need to build and bundle front-end assets using the npm `build` script:
71+
$ git clone https://github.com/NodeSecure/cli.git
72+
$ cd cli
17673

177-
```bash
74+
$ npm install
75+
# bundle/compile front-end assets for every workspace
17876
$ npm run build
17977
```
18078

18179
> [!IMPORTANT]
182-
> Restart this command when modifying files in the public root folder
80+
> Restart `npm run build` when modifying files under a workspace's public/front-end assets folder.
18381
18482
Once you have finished your development, check that the tests (and linter) are still good by running the following script:
18583

@@ -192,7 +90,7 @@ $ npm test
19290
19391
### Publishing package and SLSA
19492

195-
The package is published on [NPM with provenance](https://docs.npmjs.com/generating-provenance-statements), ensuring that this project is compliant with [SLSA Level 3](https://slsa.dev/spec/v0.1/levels?ref=fossa.com) standards. The build and publication process is managed through the GitHub [npm-provenance.yml](https://github.com/NodeSecure/cli/blob/master/.github/workflows/npm-provenance.yml) workflow, which is automatically triggered upon the creation of a new release.
93+
The `@nodesecure/cli` package is published on [NPM with provenance](https://docs.npmjs.com/generating-provenance-statements), ensuring that this project is compliant with [SLSA Level 3](https://slsa.dev/spec/v0.1/levels?ref=fossa.com) standards. The build and publication process is managed through the GitHub [npm-provenance.yml](https://github.com/NodeSecure/cli/blob/master/.github/workflows/npm-provenance.yml) workflow, which is automatically triggered upon the creation of a new release.
19694

19795
To create a local version of the package using npm and Git, follow these commands:
19896

@@ -202,26 +100,7 @@ $ git commit -am "chore: x.x.x"
202100
$ git push origin master --tags
203101
```
204102

205-
These commands will increment the package version, commit the changes, and push them along with the tags to the repository
206-
207-
## Workspaces
208-
209-
Click on one of the links to access the documentation of the workspace:
210-
211-
| name | package and link |
212-
| --- | --- |
213-
| documentation-ui | [@nodesecure/documentation-ui](./workspaces/documentation-ui) |
214-
| vis-network | [@nodesecure/vis-network](./workspaces/vis-network) |
215-
| size-satisfies | [@nodesecure/size-satisfies](./workspaces/size-satisfies) |
216-
| server | [@nodesecure/server](./workspaces/server) |
217-
| cache | [@nodesecure/cache](./workspaces/cache) |
218-
219-
These packages are available in the Node Package Repository and can be easily installed with [npm](https://docs.npmjs.com/getting-started/what-is-npm) or [yarn](https://yarnpkg.com).
220-
```bash
221-
$ npm i @nodesecure/documentation-ui
222-
# or
223-
$ yarn add @nodesecure/documentation-ui
224-
```
103+
These commands will increment the package version, commit the changes, and push them along with the tags to the repository.
225104

226105
## Contributors ✨
227106

‎eslint.config.mjs‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ import jsdoc from "eslint-plugin-jsdoc";
55
export default [
66
...ESLintConfig,
77
{
8-
files: ["public/**/*.js"],
8+
files: ["workspaces/cli/public/**/*.js"],
99
plugins: {
1010
jsdoc
1111
},

‎package.json‎

Lines changed: 10 additions & 100 deletions
Original file line numberDiff line numberDiff line change
@@ -1,85 +1,30 @@
11
{
2-
"name": "@nodesecure/cli",
3-
"version": "3.1.0",
4-
"description": "Node.js security CLI",
5-
"main": "./bin/index.js",
6-
"bin": {
7-
"node-secure": "./bin/check-and-run.js",
8-
"nsecure": "./bin/check-and-run.js"
9-
},
10-
"type": "module",
11-
"engines": {
12-
"node": ">=24"
13-
},
2+
"workspaces": [
3+
"workspaces/documentation-ui",
4+
"workspaces/vis-network",
5+
"workspaces/size-satisfies",
6+
"workspaces/cache",
7+
"workspaces/server",
8+
"workspaces/cli"
9+
],
1410
"scripts": {
1511
"lint": "eslint bin src test workspaces public",
1612
"lint:css": "stylelint \"**/*.css\" \"public/**/*.js\"",
1713
"lint-fix": "npm run lint -- --fix",
18-
"prepublishOnly": "rimraf ./dist && npm run build && pkg-ok",
19-
"dev": "npm run build:workspaces && node ./esbuild.dev.config.ts",
20-
"build": "npm run build:workspaces && npm run build:front",
21-
"build:front": "node ./esbuild.config.ts",
22-
"build:workspaces": "npm run build --ws --if-present",
23-
"test": "npm run test:cli && npm run lint && npm run lint:css",
24-
"test:cli": "node --no-warnings --test \"test/**/*.test.js\"",
25-
"test:e2e": "playwright test",
26-
"test:all": "npm run test --ws --if-present",
14+
"build": "npm run build --ws --if-present",
15+
"test": "npm run test --ws --if-present",
2716
"coverage": "c8 --reporter=lcov npm run test",
2817
"ci:publish": "changeset publish",
2918
"ci:version": "changeset version",
3019
"clean": "clear-ts-build"
3120
},
32-
"files": [
33-
"bin",
34-
"dist",
35-
"src",
36-
"public",
37-
"views",
38-
"i18n"
39-
],
40-
"workspaces": [
41-
"workspaces/documentation-ui",
42-
"workspaces/vis-network",
43-
"workspaces/size-satisfies",
44-
"workspaces/cache",
45-
"workspaces/server"
46-
],
47-
"repository": {
48-
"type": "git",
49-
"url": "git+https://github.com/NodeSecure/cli.git"
50-
},
51-
"keywords": [
52-
"node",
53-
"nodejs",
54-
"security",
55-
"cli",
56-
"sast",
57-
"scanner",
58-
"static",
59-
"code",
60-
"analysis",
61-
"node_modules",
62-
"tree",
63-
"npm",
64-
"registry",
65-
"graph",
66-
"visualization",
67-
"dependencies"
68-
],
6921
"author": "GENTILHOMME Thomas <gentilhomme.thomas@gmail.com>",
7022
"license": "MIT",
71-
"bugs": {
72-
"url": "https://github.com/NodeSecure/cli/issues"
73-
},
74-
"homepage": "https://github.com/NodeSecure/cli#readme",
7523
"devDependencies": {
7624
"@changesets/changelog-github": "0.6.0",
7725
"@changesets/cli": "2.30.0",
78-
"@nodesecure/size-satisfies": "^1.1.0",
79-
"@nodesecure/vis-network": "^1.4.0",
8026
"@openally/config.eslint": "^2.4.2",
8127
"@openally/config.typescript": "1.3.0",
82-
"@openally/httpie": "1.1.2",
8328
"@playwright/test": "^1.50.0",
8429
"@stylistic/stylelint-plugin": "5.1.0",
8530
"@types/node": "25.5.2",
@@ -88,45 +33,10 @@
8833
"esbuild": "0.28.1",
8934
"eslint-plugin-jsdoc": "62.9.0",
9035
"pkg-ok": "^3.0.0",
91-
"postcss-lit": "1.4.1",
92-
"pretty-bytes": "^7.0.0",
9336
"rimraf": "6.1.3",
9437
"stylelint": "17.6.0",
9538
"stylelint-config-standard": "40.0.0",
9639
"typescript": "^6.0.2",
97-
"undici": "8.0.2",
9840
"vite": "8.0.16"
99-
},
100-
"dependencies": {
101-
"@lit/task": "^1.0.3",
102-
"@nodesecure/cache": "1.0.0",
103-
"@nodesecure/documentation-ui": "^1.3.0",
104-
"@nodesecure/flags": "3.0.3",
105-
"@nodesecure/i18n": "4.1.0",
106-
"@nodesecure/js-x-ray": "15.1.0",
107-
"@nodesecure/licenses-conformance": "2.1.0",
108-
"@nodesecure/mama": "2.3.1",
109-
"@nodesecure/npm-registry-sdk": "4.5.2",
110-
"@nodesecure/ossf-scorecard-sdk": "4.0.1",
111-
"@nodesecure/rc": "5.6.0",
112-
"@nodesecure/report": "4.2.2",
113-
"@nodesecure/scanner": "10.12.0",
114-
"@nodesecure/server": "1.0.0",
115-
"@nodesecure/utils": "^2.2.0",
116-
"@nodesecure/vulnera": "3.1.0",
117-
"@openally/result": "^2.0.0",
118-
"@topcli/cliui": "^1.1.0",
119-
"@topcli/pretty-json": "^1.0.0",
120-
"@topcli/prompts": "^3.0.0",
121-
"@topcli/spinner": "4.2.1",
122-
"filenamify": "^7.0.0",
123-
"highlightjs-line-numbers.js": "^2.8.0",
124-
"ini": "^7.0.0",
125-
"json-diff-ts": "4.10.4",
126-
"lit": "^3.3.1",
127-
"ms": "^2.1.3",
128-
"open": "^11.0.0",
129-
"sade": "^1.8.1",
130-
"semver": "^7.6.3"
13141
}
13242
}

0 commit comments

Comments
 (0)