Skip to content

Commit 0686d91

Browse files
committed
Migrate to modern ES Module
1 parent 66a0e42 commit 0686d91

File tree

7 files changed

+65
-59
lines changed

7 files changed

+65
-59
lines changed

package.json

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
"publishConfig": {
77
"access": "public"
88
},
9-
"type": "commonjs",
9+
"type": "module",
1010
"main": "./dist/servor.js",
1111
"bin": "./dist/cli.js",
1212
"keywords": [
@@ -20,21 +20,21 @@
2020
"src/**/*"
2121
],
2222
"scripts": {
23-
"start": "SWC_NODE_PROJECT=./tsconfig.json node -r @swc-node/register src/cli.ts tests/example index.html 8081 --reload --browse",
23+
"start": "SWC_NODE_PROJECT=./tsconfig.json node --import @swc-node/register/esm-register src/cli.ts tests/example index.html 8081 --reload --browse",
2424
"build": "tsc",
2525
"cleanup": "rm -f servor.key servor.crt",
2626
"test": "npm run cleanup && cd tests && node index.js"
2727
},
2828
"author": "Luke Jackson <[email protected]>",
2929
"license": "MIT",
3030
"devDependencies": {
31-
"@swc-node/register": "^1.6.4",
31+
"@swc-node/register": "^1.8.0",
3232
"@swc/core": "^1.3.53",
3333
"@types/http-proxy": "^1.17.10",
3434
"@types/node": "^18.14.6",
3535
"prettier": "^2.8.7",
3636
"puppeteer": "^3.0.4",
37-
"typescript": "^4.9.5"
37+
"typescript": "^5.4.0"
3838
},
3939
"dependencies": {
4040
"chokidar": "^3.5.3",

src/cli.ts

Lines changed: 11 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,22 @@
11
#!/usr/bin/env node
22
import fs from 'node:fs';
3-
import path from 'node:path';
4-
import { servor } from './servor';
5-
import openBrowser from './utils/openBrowser';
3+
import { servor } from './servor.ts';
4+
import openBrowser from './utils/openBrowser.ts';
65
import { program } from 'commander';
6+
import { fileURLToPath } from "node:url";
7+
8+
const certsPath = fileURLToPath(new URL('servor.crt', import.meta.url));
9+
const keyPath = fileURLToPath(new URL('servor.key', import.meta.url));
10+
const certifyPath = fileURLToPath(new URL('../certify.sh', import.meta.url));
711

812
const readCredentials = () => ({
9-
cert: fs.readFileSync(__dirname + '/servor.crt'),
10-
key: fs.readFileSync(__dirname + '/servor.key'),
13+
cert: fs.readFileSync(certsPath),
14+
key: fs.readFileSync(keyPath),
1115
});
1216

1317
const certify = () =>
14-
require('child_process').execSync(path.resolve(__dirname, '../certify.sh'), {
15-
cwd: __dirname,
18+
require('child_process').execSync(certifyPath, {
19+
cwd: fileURLToPath(import.meta.url),
1620
});
1721

1822
(async () => {

src/servor.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -10,10 +10,10 @@ import httpProxy from 'http-proxy';
1010

1111
const gzip = promisify(zlib.gzip);
1212

13-
import mimeTypes from './utils/mimeTypes';
14-
import directoryListing from './utils/directoryListing';
13+
import mimeTypes from './utils/mimeTypes.ts';
14+
import directoryListing from './utils/directoryListing.ts';
1515

16-
import { fileWatch, usePort, networkIps } from './utils/common';
16+
import { fileWatch, usePort, networkIps } from './utils/common.ts';
1717
import { existsSync } from 'node:fs';
1818
import Server from 'http-proxy';
1919

src/utils/common.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
1-
import fs from 'fs';
2-
import os, { NetworkInterfaceInfo } from 'os';
3-
import net from 'net';
1+
import fs from 'node:fs';
2+
import os, { NetworkInterfaceInfo } from 'node:os';
3+
import net from 'node:net';
44
import chokidar from 'chokidar';
55

66
// recursive function that checks if a file is still changing

src/utils/openBrowser.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import childProcess from 'child_process';
1+
import childProcess from 'node:child_process';
22

33
export default (url: string) => {
44
let cmd;

tsconfig.json

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@
1111
// "disableReferencedProjectLoad": true, /* Reduce the number of projects loaded automatically by TypeScript. */
1212

1313
/* Language and Environment */
14-
"target": "es2021" /* Set the JavaScript language version for emitted JavaScript and include compatible library declarations. */,
14+
"target": "ESNext" /* Set the JavaScript language version for emitted JavaScript and include compatible library declarations. */,
1515
// "lib": [], /* Specify a set of bundled library declaration files that describe the target runtime environment. */
1616
// "jsx": "preserve", /* Specify what JSX code is generated. */
1717
// "experimentalDecorators": true, /* Enable experimental support for TC39 stage 2 draft decorators. */
@@ -25,9 +25,9 @@
2525
"moduleDetection": "force" /* Control what method is used to detect module-format JS files. */,
2626

2727
/* Modules */
28-
"module": "CommonJS" /* Specify what module code is generated. */,
28+
"module": "ESNext" /* Specify what module code is generated. */,
2929
// "rootDir": "./", /* Specify the root folder within your source files. */
30-
"moduleResolution": "node" /* Specify how TypeScript looks up a file from a given module specifier. */,
30+
"moduleResolution": "Bundler" /* Specify how TypeScript looks up a file from a given module specifier. */,
3131
// "baseUrl": "./", /* Specify the base directory to resolve non-relative module names. */
3232
// "paths": {}, /* Specify a set of entries that re-map imports to additional lookup locations. */
3333
// "rootDirs": [], /* Allow multiple folders to be treated as one when resolving modules. */
@@ -98,7 +98,8 @@
9898

9999
/* Completeness */
100100
// "skipDefaultLibCheck": true, /* Skip type checking .d.ts files that are included with TypeScript. */
101-
"skipLibCheck": true /* Skip type checking all .d.ts files. */
101+
"skipLibCheck": true /* Skip type checking all .d.ts files. */,
102+
"allowImportingTsExtensions": true
102103
},
103104
"include": ["src"]
104105
}

yarn.lock

Lines changed: 38 additions & 37 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ __metadata:
1616
version: 0.0.0-use.local
1717
resolution: "@mayflower-tech/servor@workspace:."
1818
dependencies:
19-
"@swc-node/register": ^1.6.4
19+
"@swc-node/register": ^1.8.0
2020
"@swc/core": ^1.3.53
2121
"@types/http-proxy": ^1.17.10
2222
"@types/node": ^18.14.6
@@ -25,7 +25,7 @@ __metadata:
2525
http-proxy: ^1.18.1
2626
prettier: ^2.8.7
2727
puppeteer: ^3.0.4
28-
typescript: ^4.9.5
28+
typescript: ^5.4.0
2929
bin:
3030
servor: ./dist/cli.js
3131
languageName: unknown
@@ -51,39 +51,40 @@ __metadata:
5151
languageName: node
5252
linkType: hard
5353

54-
"@swc-node/core@npm:^1.10.3":
55-
version: 1.10.3
56-
resolution: "@swc-node/core@npm:1.10.3"
54+
"@swc-node/core@npm:^1.13.0":
55+
version: 1.13.0
56+
resolution: "@swc-node/core@npm:1.13.0"
5757
peerDependencies:
5858
"@swc/core": ">= 1.3"
59-
checksum: 6e3e50a44d7a1c1aa62599d83c58f21568c1da03422124b46634488aba02747939063eeb1a2710aab0ab9f14f347386226a017ed72e6ba608d4a26532cd426af
59+
"@swc/types": ">= 0.1"
60+
checksum: 12056f1458c535c54c889aafbe969feef9329210657e1d22235b7d795856ec88e4a8e2116572371698ff2c0b184ebe7935ec857748262d5fcf0bd5b1563649b7
6061
languageName: node
6162
linkType: hard
6263

63-
"@swc-node/register@npm:^1.6.4":
64-
version: 1.6.4
65-
resolution: "@swc-node/register@npm:1.6.4"
64+
"@swc-node/register@npm:^1.8.0":
65+
version: 1.9.0
66+
resolution: "@swc-node/register@npm:1.9.0"
6667
dependencies:
67-
"@swc-node/core": ^1.10.3
68-
"@swc-node/sourcemap-support": ^0.3.0
69-
colorette: ^2.0.19
68+
"@swc-node/core": ^1.13.0
69+
"@swc-node/sourcemap-support": ^0.5.0
70+
colorette: ^2.0.20
7071
debug: ^4.3.4
71-
pirates: ^4.0.5
72-
tslib: ^2.5.0
72+
pirates: ^4.0.6
73+
tslib: ^2.6.2
7374
peerDependencies:
7475
"@swc/core": ">= 1.3"
7576
typescript: ">= 4.3"
76-
checksum: 9112d10e1ef69a84d9043087ae09600b1d34d1901cef67b69329ddc642b9200ee8aabc5bdc419678e76b3f4e950a1ab13bac3999b92c9ec2fc9c8ce6a33943f2
77+
checksum: 5e08ece47a4a69deaa6594dfab2c018212d61bacb3bb8ba35875a319188eb83bbc14d58b8843cf424954fc0cbfd3e03a44956b8cfc81eed3d1b7c06b6f90a904
7778
languageName: node
7879
linkType: hard
7980

80-
"@swc-node/sourcemap-support@npm:^0.3.0":
81-
version: 0.3.0
82-
resolution: "@swc-node/sourcemap-support@npm:0.3.0"
81+
"@swc-node/sourcemap-support@npm:^0.5.0":
82+
version: 0.5.0
83+
resolution: "@swc-node/sourcemap-support@npm:0.5.0"
8384
dependencies:
8485
source-map-support: ^0.5.21
85-
tslib: ^2.5.0
86-
checksum: a3c837ed790238ef88682eb342b75d756eba5eb3b6cfe6cf14a597bd78dfc9a9797f1e54a4977c1297e5324fba2e33bd76ab8aa9c396ad463693de2001180c9e
86+
tslib: ^2.6.2
87+
checksum: 2163f2ae337dafa07f62492a78d1e7b272207c91f1f7b5a9ab95ba929b7dfa93a4db1188dbafde117dae7219805ba9aac9693fd2066563992dba2239295181ee
8788
languageName: node
8889
linkType: hard
8990

@@ -477,7 +478,7 @@ __metadata:
477478
languageName: node
478479
linkType: hard
479480

480-
"colorette@npm:^2.0.19":
481+
"colorette@npm:^2.0.20":
481482
version: 2.0.20
482483
resolution: "colorette@npm:2.0.20"
483484
checksum: 0c016fea2b91b733eb9f4bcdb580018f52c0bc0979443dad930e5037a968237ac53d9beb98e218d2e9235834f8eebce7f8e080422d6194e957454255bde71d3d
@@ -1181,10 +1182,10 @@ __metadata:
11811182
languageName: node
11821183
linkType: hard
11831184

1184-
"pirates@npm:^4.0.5":
1185-
version: 4.0.5
1186-
resolution: "pirates@npm:4.0.5"
1187-
checksum: c9994e61b85260bec6c4fc0307016340d9b0c4f4b6550a957afaaff0c9b1ad58fbbea5cfcf083860a25cb27a375442e2b0edf52e2e1e40e69934e08dcc52d227
1185+
"pirates@npm:^4.0.6":
1186+
version: 4.0.6
1187+
resolution: "pirates@npm:4.0.6"
1188+
checksum: 46a65fefaf19c6f57460388a5af9ab81e3d7fd0e7bc44ca59d753cb5c4d0df97c6c6e583674869762101836d68675f027d60f841c105d72734df9dfca97cbcc6
11881189
languageName: node
11891190
linkType: hard
11901191

@@ -1478,30 +1479,30 @@ __metadata:
14781479
languageName: node
14791480
linkType: hard
14801481

1481-
"tslib@npm:^2.5.0":
1482-
version: 2.5.0
1483-
resolution: "tslib@npm:2.5.0"
1484-
checksum: ae3ed5f9ce29932d049908ebfdf21b3a003a85653a9a140d614da6b767a93ef94f460e52c3d787f0e4f383546981713f165037dc2274df212ea9f8a4541004e1
1482+
"tslib@npm:^2.6.2":
1483+
version: 2.6.2
1484+
resolution: "tslib@npm:2.6.2"
1485+
checksum: 329ea56123005922f39642318e3d1f0f8265d1e7fcb92c633e0809521da75eeaca28d2cf96d7248229deb40e5c19adf408259f4b9640afd20d13aecc1430f3ad
14851486
languageName: node
14861487
linkType: hard
14871488

1488-
"typescript@npm:^4.9.5":
1489-
version: 4.9.5
1490-
resolution: "typescript@npm:4.9.5"
1489+
"typescript@npm:^5.4.0":
1490+
version: 5.4.2
1491+
resolution: "typescript@npm:5.4.2"
14911492
bin:
14921493
tsc: bin/tsc
14931494
tsserver: bin/tsserver
1494-
checksum: ee000bc26848147ad423b581bd250075662a354d84f0e06eb76d3b892328d8d4440b7487b5a83e851b12b255f55d71835b008a66cbf8f255a11e4400159237db
1495+
checksum: 96d80fde25a09bcb04d399082fb27a808a9e17c2111e43849d2aafbd642d835e4f4ef0de09b0ba795ec2a700be6c4c2c3f62bf4660c05404c948727b5bbfb32a
14951496
languageName: node
14961497
linkType: hard
14971498

1498-
"typescript@patch:typescript@^4.9.5#~builtin<compat/typescript>":
1499-
version: 4.9.5
1500-
resolution: "typescript@patch:typescript@npm%3A4.9.5#~builtin<compat/typescript>::version=4.9.5&hash=23ec76"
1499+
"typescript@patch:typescript@^5.4.0#~builtin<compat/typescript>":
1500+
version: 5.4.2
1501+
resolution: "typescript@patch:typescript@npm%3A5.4.2#~builtin<compat/typescript>::version=5.4.2&hash=1f5320"
15011502
bin:
15021503
tsc: bin/tsc
15031504
tsserver: bin/tsserver
1504-
checksum: ab417a2f398380c90a6cf5a5f74badd17866adf57f1165617d6a551f059c3ba0a3e4da0d147b3ac5681db9ac76a303c5876394b13b3de75fdd5b1eaa06181c9d
1505+
checksum: c1b669146bca5529873aae60870e243fa8140c85f57ca32c42f898f586d73ce4a6b4f6bb02ae312729e214d7f5859a0c70da3e527a116fdf5ad00c9fc733ecc6
15051506
languageName: node
15061507
linkType: hard
15071508

0 commit comments

Comments
 (0)