Skip to content

Commit bfd5649

Browse files
refactor: split codebase into workspaces (#522)
1 parent 78b76d7 commit bfd5649

Some content is hidden

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

43 files changed

+638
-172
lines changed

.github/workflows/cache.yml

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
name: cache CI
2+
3+
on:
4+
push:
5+
branches:
6+
- master
7+
paths:
8+
- workspaces/cache/**
9+
pull_request:
10+
paths:
11+
- workspaces/cache/**
12+
13+
permissions:
14+
contents: read
15+
16+
jobs:
17+
test:
18+
runs-on: ubuntu-latest
19+
strategy:
20+
matrix:
21+
node-version: [20.x, 22.x]
22+
fail-fast: false
23+
steps:
24+
- name: Harden Runner
25+
uses: step-security/harden-runner@0634a2670c59f64b4a01f0f96f84700a4088b9f0 # v2.12.0
26+
with:
27+
egress-policy: audit # TODO: change to 'egress-policy: block' after couple of runs
28+
29+
- uses: actions/checkout@11bd71901bbe5b1630ceea73d27597364c9af683 # v4.2.2
30+
- name: Use Node.js ${{ matrix.node-version }}
31+
uses: actions/setup-node@49933ea5288caeca8642d1e84afbd3f7d6820020 # v4.4.0
32+
with:
33+
node-version: ${{ matrix.node-version }}
34+
- name: Install dependencies
35+
run: npm install
36+
- name: Run tests
37+
run: npm run test

.github/workflows/server.yml

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
name: server CI
2+
3+
on:
4+
push:
5+
branches:
6+
- master
7+
paths:
8+
- workspaces/server/**
9+
pull_request:
10+
paths:
11+
- workspaces/server/**
12+
13+
permissions:
14+
contents: read
15+
16+
jobs:
17+
test:
18+
runs-on: ubuntu-latest
19+
strategy:
20+
matrix:
21+
node-version: [20.x, 22.x]
22+
fail-fast: false
23+
steps:
24+
- name: Harden Runner
25+
uses: step-security/harden-runner@0634a2670c59f64b4a01f0f96f84700a4088b9f0 # v2.12.0
26+
with:
27+
egress-policy: audit # TODO: change to 'egress-policy: block' after couple of runs
28+
29+
- uses: actions/checkout@11bd71901bbe5b1630ceea73d27597364c9af683 # v4.2.2
30+
- name: Use Node.js ${{ matrix.node-version }}
31+
uses: actions/setup-node@49933ea5288caeca8642d1e84afbd3f7d6820020 # v4.4.0
32+
with:
33+
node-version: ${{ matrix.node-version }}
34+
- name: Install dependencies
35+
run: npm install
36+
- name: Run tests
37+
run: npm run test

.github/workflows/size-satisfies.yml

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,8 @@ name: size-satisfies CI
22

33
on:
44
push:
5-
branches: master
5+
branches:
6+
- master
67
paths:
78
- workspaces/size-satisfies/**
89
pull_request:

README.md

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -211,8 +211,10 @@ Click on one of the links to access the documentation of the workspace:
211211
| name | package and link |
212212
| --- | --- |
213213
| 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) |
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) |
216218

217219
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).
218220
```bash

package.json

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,9 @@
3232
"workspaces": [
3333
"workspaces/documentation-ui",
3434
"workspaces/vis-network",
35-
"workspaces/size-satisfies"
35+
"workspaces/size-satisfies",
36+
"workspaces/server",
37+
"workspaces/cache"
3638
],
3739
"repository": {
3840
"type": "git",

src/commands/cache.js

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,9 +5,7 @@ import { setImmediate } from "node:timers/promises";
55
// Import Third-party Dependencies
66
import prettyJson from "@topcli/pretty-json";
77
import * as i18n from "@nodesecure/i18n";
8-
9-
// Import Internal Dependencies
10-
import { appCache } from "../cache.js";
8+
import { appCache } from "@nodesecure/cache";
119

1210
export async function main(options) {
1311
const {

src/commands/http.js

Lines changed: 24 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -4,16 +4,17 @@ import path from "node:path";
44
import crypto from "node:crypto";
55

66
// Import Third-party Dependencies
7-
import * as SemVer from "semver";
87
import kleur from "kleur";
8+
import open from "open";
9+
import * as SemVer from "semver";
910
import * as i18n from "@nodesecure/i18n";
10-
11-
// Import Internal Dependencies
12-
import { buildServer } from "../http-server/index.js";
13-
import { appCache } from "../cache.js";
11+
import { buildServer, WebSocketServerInstanciator } from "@nodesecure/server";
12+
import { appCache } from "@nodesecure/cache";
1413

1514
// CONSTANTS
1615
const kRequiredScannerRange = ">=5.1.0";
16+
const kProjectRootDir = path.join(import.meta.dirname, "..", "..");
17+
const kComponentsDir = path.join(kProjectRootDir, "public", "components");
1718

1819
export async function start(
1920
payloadFileBasename = "nsecure-result.json",
@@ -44,11 +45,27 @@ export async function start(
4445
const httpServer = buildServer(dataFilePath, {
4546
port: Number.isNaN(port) ? 0 : port,
4647
hotReload: enableDeveloperMode,
47-
runFromPayload
48+
runFromPayload,
49+
projectRootDir: kProjectRootDir,
50+
componentsDir: kComponentsDir
51+
});
52+
53+
httpServer.listen(port, async() => {
54+
const link = `http://localhost:${port}`;
55+
console.log(kleur.magenta().bold(await i18n.getToken("cli.http_server_started")), kleur.cyan().bold(link));
56+
57+
open(link);
4858
});
4959

60+
new WebSocketServerInstanciator();
61+
5062
for (const eventName of ["SIGINT", "SIGTERM"]) {
51-
process.on(eventName, () => httpServer.server.close());
63+
process.on(eventName, () => {
64+
httpServer.server.close();
65+
66+
console.log(kleur.red().bold(`${eventName} signal received.`));
67+
process.exit(0);
68+
});
5269
}
5370
}
5471

src/commands/scanner.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,10 +10,10 @@ import { Spinner } from "@topcli/spinner";
1010
import ms from "ms";
1111
import * as i18n from "@nodesecure/i18n";
1212
import * as Scanner from "@nodesecure/scanner";
13+
import { appCache } from "@nodesecure/cache";
1314

1415
// Import Internal Dependencies
1516
import * as http from "./http.js";
16-
import { appCache } from "../cache.js";
1717
import { parseContacts } from "./parsers/contacts.js";
1818

1919
export async function auto(spec, options) {

src/http-server/index.js

Lines changed: 0 additions & 88 deletions
This file was deleted.

src/http-server/middlewares/static.js

Lines changed: 0 additions & 14 deletions
This file was deleted.

test/commands/cache.test.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,10 +11,10 @@ import { after, before, describe, it } from "node:test";
1111

1212
// Import Third-party Dependencies
1313
import * as i18n from "@nodesecure/i18n";
14+
import { appCache, DEFAULT_PAYLOAD_PATH } from "@nodesecure/cache";
1415

1516
// Import Internal Dependencies
1617
import { arrayFromAsync } from "../helpers/utils.js";
17-
import { appCache, DEFAULT_PAYLOAD_PATH } from "../../src/cache.js";
1818
import { main } from "../../src/commands/cache.js";
1919

2020
// CONSTANTS

0 commit comments

Comments
 (0)