Skip to content

Commit 0f7ec10

Browse files
refactor: migrate new workspaces to TypeScript
1 parent bfd5649 commit 0f7ec10

44 files changed

Lines changed: 494 additions & 202 deletions

Some content is hidden

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

.github/workflows/cache.yml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,5 +33,7 @@ jobs:
3333
node-version: ${{ matrix.node-version }}
3434
- name: Install dependencies
3535
run: npm install
36+
- name: Build
37+
run: npm run build --ws --if-present
3638
- name: Run tests
3739
run: npm run test

.github/workflows/nodejs.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ jobs:
3030
- name: Install dependencies
3131
run: npm install
3232
- name: Build
33-
run: npm run build
33+
run: npm run build --ws --if-present
3434
- name: Run tests
3535
run: npm run coverage
3636
- name: Send coverage report to Codecov

.github/workflows/server.yml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,5 +33,7 @@ jobs:
3333
node-version: ${{ matrix.node-version }}
3434
- name: Install dependencies
3535
run: npm install
36+
- name: Build
37+
run: npm run build --ws --if-present
3638
- name: Run tests
3739
run: npm run test

.gitignore

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,9 @@ jspm_packages/
3939
# TypeScript v1 declaration files
4040
typings/
4141

42+
# TypeScript cache
43+
*.tsbuildinfo
44+
4245
# Optional npm cache directory
4346
.npm
4447

eslint.config.mjs

Lines changed: 14 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,19 +1,9 @@
1-
import { ESLintConfig, globals } from "@openally/config.eslint";
1+
// Import Third-party Dependencies
2+
import { ESLintConfig, typescriptConfig, globals } from "@openally/config.eslint";
23
import jsdoc from "eslint-plugin-jsdoc";
34

45
export default [
56
...ESLintConfig,
6-
{
7-
rules: {
8-
"no-invalid-this": "off"
9-
},
10-
languageOptions: {
11-
sourceType: "module",
12-
globals: {
13-
...globals.browser
14-
}
15-
}
16-
},
177
{
188
files: ["public/**/*.js"],
199
plugins: {
@@ -34,5 +24,16 @@ export default [
3424
"**/coverage/",
3525
"**/fixtures/"
3626
]
37-
}
27+
},
28+
...typescriptConfig({
29+
rules: {
30+
"no-invalid-this": "off"
31+
},
32+
languageOptions: {
33+
sourceType: "module",
34+
globals: {
35+
...globals.browser
36+
}
37+
}
38+
})
3839
];

package.json

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -69,6 +69,7 @@
6969
"@nodesecure/size-satisfies": "^1.1.0",
7070
"@nodesecure/vis-network": "^1.4.0",
7171
"@openally/config.eslint": "^2.1.0",
72+
"@openally/config.typescript": "^1.0.3",
7273
"@types/node": "^24.0.3",
7374
"c8": "^10.1.2",
7475
"cross-env": "^7.0.3",
@@ -80,7 +81,9 @@
8081
"rimraf": "^6.0.1",
8182
"server-destroy": "^1.0.1",
8283
"stylelint": "^16.20.0",
83-
"stylelint-config-standard": "^38.0.0"
84+
"stylelint-config-standard": "^38.0.0",
85+
"tsx": "^4.20.3",
86+
"typescript": "^5.8.3"
8487
},
8588
"dependencies": {
8689
"@nodesecure/documentation-ui": "^1.3.0",

src/commands/http.js

Lines changed: 13 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,10 @@ import * as i18n from "@nodesecure/i18n";
1111
import { buildServer, WebSocketServerInstanciator } from "@nodesecure/server";
1212
import { appCache } from "@nodesecure/cache";
1313

14+
// Import Internal Dependencies
15+
import english from "../../i18n/english.js";
16+
import french from "../../i18n/french.js";
17+
1418
// CONSTANTS
1519
const kRequiredScannerRange = ">=5.1.0";
1620
const kProjectRootDir = path.join(import.meta.dirname, "..", "..");
@@ -21,6 +25,7 @@ export async function start(
2125
options = {}
2226
) {
2327
const port = Number(options.port);
28+
const httpPort = Number.isNaN(port) ? 0 : port;
2429
const freshStart = Boolean(options.f);
2530
const enableDeveloperMode = Boolean(options.developer);
2631

@@ -43,15 +48,19 @@ export async function start(
4348
}
4449

4550
const httpServer = buildServer(dataFilePath, {
46-
port: Number.isNaN(port) ? 0 : port,
51+
port: httpPort,
4752
hotReload: enableDeveloperMode,
4853
runFromPayload,
4954
projectRootDir: kProjectRootDir,
50-
componentsDir: kComponentsDir
55+
componentsDir: kComponentsDir,
56+
i18n: {
57+
english,
58+
french
59+
}
5160
});
5261

53-
httpServer.listen(port, async() => {
54-
const link = `http://localhost:${port}`;
62+
httpServer.listen(httpPort, async() => {
63+
const link = `http://localhost:${httpServer.server.address().port}`;
5564
console.log(kleur.magenta().bold(await i18n.getToken("cli.http_server_started")), kleur.cyan().bold(link));
5665

5766
open(link);

tsconfig.base.json

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
{
2+
"extends": "@openally/config.typescript",
3+
"compilerOptions": {
4+
"composite": true
5+
}
6+
}

tsconfig.json

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
{
2+
"files": [],
3+
"references": [
4+
{
5+
"path": "./workspaces/cache"
6+
},
7+
{
8+
"path": "./workspaces/server"
9+
}
10+
]
11+
}

workspaces/cache/README.md

Lines changed: 47 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -41,15 +41,15 @@ await appCache.setRootPayload(payload);
4141

4242
## API
4343

44-
### `updateConfig(config)`
44+
### `updateConfig(config: AppConfig): Promise<void>`
4545

4646
Stores a new configuration object in the cache.
4747

48-
### `getConfig()`
48+
### `getConfig(): Promise<AppConfig>`
4949

5050
Retrieves the current configuration object from the cache.
5151

52-
### `updatePayload(pkg, payload)`
52+
### `updatePayload(packageName: string, payload: Payload): void`
5353

5454
Saves an analysis payload for a given package.
5555

@@ -60,18 +60,18 @@ Saves an analysis payload for a given package.
6060
> [!NOTE]
6161
> Payloads are stored in the user's home directory under `~/.nsecure/payloads/`
6262
63-
### `getPayload(pkg)`
63+
### `getPayload(packageName: string): Payload`
6464

6565
Loads an analysis payload for a given package.
6666

6767
**Parameters**:
6868
`pkg` (`string`): Package name.
6969

70-
### `availablePayloads()`
70+
### `availablePayloads(): string[]`
7171

7272
Lists all available payloads (package names) in the cache.
7373

74-
### `getPayloadOrNull(pkg)`
74+
### `getPayloadOrNull(packageName: string): Payload | null`
7575

7676
Loads an analysis payload for a given package, or returns `null` if not found.
7777

@@ -81,19 +81,19 @@ Loads an analysis payload for a given package, or returns `null` if not found.
8181

8282
Returns `null` if not found.
8383

84-
### `updatePayloadsList(payloadsList)`
84+
### `updatePayloadsList(payloadsList: PayloadsList): Promise<void>`
8585

8686
Updates the internal MRU/LRU and available payloads list.
8787

8888
**Parameters**:
8989

9090
- `payloadsList` (`object`): The new payloads list object.
9191

92-
### `payloadsList()`
92+
### `payloadsList(): Promise<PayloadsList>`
9393

9494
Retrieves the current MRU/LRU and available payloads list.
9595

96-
### `initPayloadsList(options = {})`
96+
### `initPayloadsList(options: InitPayloadListOptions = {}): Promise<void>`
9797

9898
Initializes the payloads list, optionally resetting the cache.
9999

@@ -103,18 +103,18 @@ Initializes the payloads list, optionally resetting the cache.
103103
- `logging` (`boolean`, default: `true`): Enable logging.
104104
- `reset` (`boolean`, default: `false`): If `true`, reset the cache before initializing.
105105

106-
### `removePayload(pkg)`
106+
### `removePayload(packageName: string): void`
107107

108108
Removes a payload for a given package from the cache.
109109

110110
**Parameters**:
111111
- `pkg` (`string`): Package name.
112112

113-
### `removeLastMRU()`
113+
### `removeLastMRU(): Promise<PayloadsList>`
114114

115115
Removes the least recently used payload if the MRU exceeds the maximum allowed.
116116

117-
### `setRootPayload(payload, options)`
117+
### `setRootPayload(payload: Payload, options: SetRootPayloadOptions = {}): Promise<void>`
118118

119119
Sets a new root payload, updates MRU/LRU, and manages cache state.
120120

@@ -124,3 +124,38 @@ Sets a new root payload, updates MRU/LRU, and manages cache state.
124124
- `options` (`object`):
125125
- `logging` (`boolean`, default: `true`): Enable logging.
126126
- `local` (`boolean`, default: `false`): Mark the payload as local.
127+
128+
## Interfaces
129+
130+
```ts
131+
interface AppConfig {
132+
defaultPackageMenu: string;
133+
ignore: {
134+
flags: Flag[];
135+
warnings: WarningName[];
136+
};
137+
theme?: "light" | "dark";
138+
disableExternalRequests: boolean;
139+
}
140+
141+
interface PayloadsList {
142+
mru: string[];
143+
lru: string[];
144+
current: string;
145+
availables: string[];
146+
lastUsed: Record<string, number>;
147+
root: string | null;
148+
}
149+
150+
interface LoggingOption {
151+
logging?: boolean;
152+
}
153+
154+
interface InitPayloadListOptions extends LoggingOption {
155+
reset?: boolean;
156+
}
157+
158+
interface SetRootPayloadOptions extends LoggingOption {
159+
local?: boolean;
160+
}
161+
```

0 commit comments

Comments
 (0)