Skip to content

Commit 822a54c

Browse files
committed
Good progress towards node-native TS & ESM
This updates TS (disabling lib checking to handle Oclif broken types) and Node types, and migrates to fully eraseable syntax, and handles most of the ESM style steps along the way. Only extra steps for the basics are: * type: module on the package * Adding an extra layer on .default (for some reason) on Oclif update & adbkit package imports. * Migrating assorted __dirname to import.meta.url. Unfortunately though, fully switching to ESM seems very challenging with Oclif, so we can't quite finish the job here. Maybe we tie that into cutting out Oclif entirely later?
1 parent 0541531 commit 822a54c

Some content is hidden

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

60 files changed

+1296
-937
lines changed

package-lock.json

Lines changed: 868 additions & 609 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -112,14 +112,14 @@
112112
"@types/klaw": "^3.0.2",
113113
"@types/lodash": "^4.14.117",
114114
"@types/mocha": "^5.2.5",
115-
"@types/node": "~20.11.18",
115+
"@types/node": "^24.10.0",
116116
"@types/node-forge": "^0.9.9",
117117
"@types/request-promise-native": "^1.0.15",
118118
"@types/rimraf": "^2.0.2",
119119
"@types/ws": "^6.0.1",
120120
"axios": "^1.8.2",
121121
"bent": "^1.5.13",
122-
"chai": "^4.2.0",
122+
"chai": "^6.2.0",
123123
"check-msvc-runtime": "^0.1.1",
124124
"copy-webpack-plugin": "^11.0.0",
125125
"cross-env": "^7.0.3",
@@ -128,7 +128,7 @@
128128
"got": "^11.8.5",
129129
"graphql.js": "^0.6.1",
130130
"klaw": "^4.0.1",
131-
"mocha": "^10.8.2",
131+
"mocha": "^11.7.5",
132132
"needle": "^2.4.0",
133133
"node-noop": "^1.0.0",
134134
"npm-run-all": "^4.1.5",
@@ -140,8 +140,8 @@
140140
"superagent": "^7.1.1",
141141
"ts-loader": "^9.4.2",
142142
"ts-node": "^10.9.2",
143-
"tsx": "^4.19.3",
144-
"typescript": "~4.7",
143+
"tsx": "^4.20.6",
144+
"typescript": "^5.9.3",
145145
"umd-compat-loader": "^2.1.2",
146146
"undici": "^5.29.0",
147147
"unirest": "^0.6.0",

prepare.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ import * as path from 'path';
22
import type { Stats } from 'fs';
33
import * as fs from 'fs/promises';
44
import klaw from 'klaw';
5-
import { spawn as spawnAsync, SpawnOptions } from 'child_process';
5+
import { spawn as spawnAsync, type SpawnOptions } from 'child_process';
66

77
const spawn = (command: string, args: string[] = [], options: SpawnOptions = {}) => {
88
return new Promise<void>((resolve, reject) => {

src/api/api-model.ts

Lines changed: 30 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1,35 +1,50 @@
11
import * as _ from 'lodash';
22
import * as os from 'os';
33

4-
import { ErrorLike, delay } from '@httptoolkit/util';
4+
import { type ErrorLike, delay } from '@httptoolkit/util';
55
import { generateSPKIFingerprint } from 'mockttp';
66
import { getSystemProxy } from 'os-proxy-config';
77

8-
import { SERVER_VERSION } from "../constants";
9-
import { logError, addBreadcrumb } from '../error-tracking';
8+
import { SERVER_VERSION } from '../constants.ts';
9+
import { logError, addBreadcrumb } from '../error-tracking.ts';
1010

11-
import { HtkConfig } from "../config";
12-
import { ActivationError, Interceptor } from "../interceptors";
13-
import { getDnsServer } from '../dns-server';
14-
import { getCertExpiry, parseCert } from '../certificates';
11+
import type { HtkConfig } from '../config.d.ts';
12+
import { ActivationError, Interceptor } from '../interceptors/index.ts';
13+
import { getDnsServer } from '../dns-server.ts';
14+
import { getCertExpiry, parseCert } from '../certificates.ts';
1515

16-
import * as Client from '../client/client-types';
17-
import { HttpClient } from '../client/http-client';
16+
import * as Client from '../client/client-types.ts';
17+
import { HttpClient } from '../client/http-client.ts';
1818

1919
const INTERCEPTOR_TIMEOUT = 1000;
2020

2121
export class ApiModel {
2222

23+
private config: HtkConfig;
24+
private interceptors: _.Dictionary<Interceptor>;
25+
private getRuleParamKeys: () => string[];
26+
private httpClient: HttpClient;
27+
private callbacks: {
28+
onTriggerUpdate: () => void,
29+
onTriggerShutdown: () => void
30+
};
31+
2332
constructor(
24-
private config: HtkConfig,
25-
private interceptors: _.Dictionary<Interceptor>,
26-
private getRuleParamKeys: () => string[],
27-
private httpClient: HttpClient,
28-
private callbacks: {
33+
config: HtkConfig,
34+
interceptors: _.Dictionary<Interceptor>,
35+
getRuleParamKeys: () => string[],
36+
httpClient: HttpClient,
37+
callbacks: {
2938
onTriggerUpdate: () => void,
3039
onTriggerShutdown: () => void
3140
}
32-
) {}
41+
) {
42+
this.config = config;
43+
this.interceptors = interceptors;
44+
this.getRuleParamKeys = getRuleParamKeys;
45+
this.httpClient = httpClient;
46+
this.callbacks = callbacks;
47+
}
3348

3449
getVersion() {
3550
return SERVER_VERSION;

src/api/api-server.ts

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -4,15 +4,15 @@ import express from 'express';
44
import cors from 'cors';
55
import corsGate from 'cors-gate';
66

7-
import { HtkConfig } from '../config';
8-
import { buildInterceptors } from '../interceptors';
9-
import { ALLOWED_ORIGINS } from '../constants';
10-
import { shutdown } from '../shutdown';
11-
12-
import { ApiModel } from './api-model';
13-
import { exposeGraphQLAPI } from './graphql-api';
14-
import { exposeRestAPI } from './rest-api';
15-
import { HttpClient } from '../client/http-client';
7+
import type { HtkConfig } from '../config.d.ts';
8+
import { buildInterceptors } from '../interceptors/index.ts';
9+
import { ALLOWED_ORIGINS } from '../constants.ts';
10+
import { shutdown } from '../shutdown.ts';
11+
12+
import { ApiModel } from './api-model.ts';
13+
import { exposeGraphQLAPI } from './graphql-api.ts';
14+
import { exposeRestAPI } from './rest-api.ts';
15+
import { HttpClient } from '../client/http-client.ts';
1616

1717
/**
1818
* This file contains the core server API, used by the UI to query

src/api/graphql-api.ts

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,9 @@ import type { Application as ExpressApp } from 'express';
44
import { makeExecutableSchema } from '@graphql-tools/schema';
55
import { GraphQLScalarType } from 'graphql';
66
import { createHandler as createGraphQLHandler } from 'graphql-http/lib/use/express';
7-
import gql from 'graphql-tag';
8-
import { ApiModel } from './api-model';
7+
import { gql } from 'graphql-tag';
8+
9+
import { ApiModel } from './api-model.ts';
910

1011
const typeDefs = gql`
1112
type Query {

src/api/rest-api.ts

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -10,11 +10,11 @@ import type {
1010
RouteParameters
1111
} from 'express-serve-static-core';
1212
import type { ParsedQs } from 'qs';
13-
import { ErrorLike, StatusError } from '@httptoolkit/util';
13+
import { type ErrorLike, StatusError } from '@httptoolkit/util';
1414

15-
import { logError } from '../error-tracking';
16-
import { ApiModel } from './api-model';
17-
import * as Client from '../client/client-types';
15+
import { logError } from '../error-tracking.ts';
16+
import { ApiModel } from './api-model.ts';
17+
import * as Client from '../client/client-types.ts';
1818

1919
/**
2020
* This file exposes the API model via a REST-ish classic HTTP API.

src/browsers.ts

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -2,24 +2,24 @@ import * as path from 'path';
22
import { promisify } from 'util';
33

44
import { delay, isErrorLike } from '@httptoolkit/util';
5-
import getBrowserLauncherCb from '@httptoolkit/browser-launcher';
6-
import {
7-
LaunchOptions,
8-
Launch,
9-
BrowserInstance,
10-
Browser,
11-
update as updateBrowserCacheCb
5+
import getBrowserLauncherCb, {
6+
type LaunchOptions,
7+
type Launch,
8+
type BrowserInstance,
9+
type Browser
1210
} from '@httptoolkit/browser-launcher';
1311

14-
import { logError } from './error-tracking';
15-
import { readFile, deleteFile } from './util/fs';
12+
const updateBrowserCacheCb = getBrowserLauncherCb.update;
13+
14+
import { logError } from './error-tracking.ts';
15+
import { readFile, deleteFile } from './util/fs.ts';
1616

1717
const getBrowserLauncher = promisify(getBrowserLauncherCb);
1818
const updateBrowserCache: (configPath: string) => Promise<unknown> = promisify(updateBrowserCacheCb);
1919

2020
const browserConfigPath = (configPath: string) => path.join(configPath, 'browsers.json');
2121

22-
export { BrowserInstance, Browser };
22+
export type { BrowserInstance, Browser };
2323

2424
export async function checkBrowserConfig(configPath: string) {
2525
// It's not clear why, but sometimes the browser config can become corrupted, so it's not valid JSON
@@ -87,7 +87,7 @@ export const getBrowserDetails = async (configPath: string, variant: string): Pr
8787
return browsers.find(b => b.name === variant);
8888
};
8989

90-
export { LaunchOptions };
90+
export type { LaunchOptions };
9191

9292
export const launchBrowser = async (url: string, options: LaunchOptions, configPath: string) => {
9393
const launcher = await getLauncher(configPath);

src/cert-check-server.ts

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
1-
import { getLocal, Mockttp } from 'mockttp';
1+
import { getLocal, type Mockttp } from 'mockttp';
22
import { getDeferred } from '@httptoolkit/util';
33

4-
import { HtkConfig } from './config';
5-
import { EPHEMERAL_PORT_RANGE } from './constants';
4+
import type { HtkConfig } from './config.d.ts';
5+
import { EPHEMERAL_PORT_RANGE } from './constants.ts';
66

77
const buildPage = (style: string, script?: string, body?: string) =>
88
`<html>
@@ -27,7 +27,11 @@ const buildPage = (style: string, script?: string, body?: string) =>
2727

2828
export class CertCheckServer {
2929

30-
constructor(private config: HtkConfig) { }
30+
private config: HtkConfig;
31+
32+
constructor(config: HtkConfig) {
33+
this.config = config;
34+
}
3135

3236
private server: Mockttp | undefined;
3337

src/certificates.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import * as crypto from 'crypto';
2-
import * as forge from 'node-forge';
2+
import forge from 'node-forge';
33

44
export const parseCert = forge.pki.certificateFromPem;
55

0 commit comments

Comments
 (0)