Skip to content

Commit 39af703

Browse files
committed
Migrate to ESM
Honestly this is the simplest of all my projects and the one where it's most awkward having mismatched source/runtime output, and where I completely control the runtime, so this is a no-brainer. Not sure why I didn't do it years ago.
1 parent bc4b498 commit 39af703

File tree

8 files changed

+13
-10
lines changed

8 files changed

+13
-10
lines changed

package.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
"homepage": "https://httptoolkit.com",
66
"private": true,
77
"description": "HTTP(S) debugging, development & testing tool",
8+
"type": "module",
89
"main": "build/index.js",
910
"scripts": {
1011
"postinstall": "electron-builder install-app-deps",

setup-server.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ async function setUpLocalEnv() {
2525

2626
if (!serverVersion || semver.neq(serverVersion, requiredServerVersion)) {
2727
if (serverExists) await deleteDir('./httptoolkit-server');
28-
await insertServer(__dirname, os.platform(), os.arch());
28+
await insertServer(import.meta.dirname, os.platform(), os.arch());
2929
console.log('Server setup completed.');
3030
} else {
3131
console.log('Correct server already downloaded.');

skip-server.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ const deleteDir = (p: string) => fs.rm(p, { recursive: true, force: true });
88
// This lets us edit both and the desktop together. We do this by creating a fake server,
99
// which doesn't exit, but otherwise does nothing.
1010
async function setUpDevEnv() {
11-
const serverFolder = path.join(__dirname, 'httptoolkit-server');
11+
const serverFolder = path.join(import.meta.dirname, 'httptoolkit-server');
1212
const serverExists = await canAccess(serverFolder);
1313

1414
if (serverExists) await deleteDir(serverFolder);

src/device.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ import { promisify } from 'util';
44
import { exec } from 'child_process';
55
const execAsync = promisify(exec);
66

7-
import { logError } from './errors';
7+
import { logError } from './errors.ts';
88

99
export async function getDeviceDetails(): Promise<{
1010
platform: string;

src/index.ts

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
const DEV_MODE = process.env.HTK_DEV === 'true';
22

33
// Set up error handling before everything else:
4-
import { logError, addBreadcrumb } from './errors';
4+
import { logError, addBreadcrumb } from './errors.ts';
55

66
import { spawn, ChildProcess } from 'child_process';
77
import * as os from 'os';
@@ -22,10 +22,10 @@ import registerContextMenu = require('electron-context-menu');
2222
import * as sudoPrompt from '@expo/sudo-prompt';
2323
import { getDeferred, delay, ErrorLike } from '@httptoolkit/util';
2424

25-
import { getMenu, shouldAutoHideMenu } from './menu';
26-
import { ContextMenuDefinition, openContextMenu } from './context-menu';
27-
import { stopServer } from './stop-server';
28-
import { getDeviceDetails } from './device';
25+
import { getMenu, shouldAutoHideMenu } from './menu.ts';
26+
import { ContextMenuDefinition, openContextMenu } from './context-menu.ts';
27+
import { stopServer } from './stop-server.ts';
28+
import { getDeviceDetails } from './device.ts';
2929

3030
const packageJson = require('../package.json');
3131

src/preload.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import { contextBridge, ipcRenderer } from 'electron';
22

3-
import type { ContextMenuDefinition } from './context-menu';
3+
import type { ContextMenuDefinition } from './context-menu.ts';
44

55
// These are technically asynchronous, but they're so fast that
66
// they're effectively sychronously available - this seems to

strip-preload-map.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,5 +20,5 @@ function removeSourceMapAnnotation(filePath: string): void {
2020
// We have to strip the source map comment from here, otherwise when it loads
2121
// in Chrome, it tries to get preload.js.map from the real server, leaving
2222
// us with an annoying error because that's never going to work.
23-
const filePath = path.join(__dirname, 'build', 'preload.js');
23+
const filePath = path.join(import.meta.dirname, 'build', 'preload.js');
2424
removeSourceMapAnnotation(filePath);

tsconfig.json

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,8 @@
1515
"noEmitHelpers": true,
1616
"module": "node20",
1717
"moduleResolution": "nodenext",
18+
"rewriteRelativeImportExtensions": true,
19+
"skipLibCheck": true,
1820
"types": ["node"],
1921
"pretty": true,
2022
"target": "ES2022",

0 commit comments

Comments
 (0)