Skip to content

Commit 030064e

Browse files
committed
v9.0.0 / 2023-09-19
1 parent 9ab4eb6 commit 030064e

File tree

15 files changed

+121
-78
lines changed

15 files changed

+121
-78
lines changed

.appveyor.yml

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,9 +2,8 @@ build: off
22

33
environment:
44
matrix:
5+
- nodejs_version: '20'
56
- nodejs_version: '18'
6-
- nodejs_version: '16'
7-
- nodejs_version: '14'
87

98
install:
109
- ps: Install-Product node $env:nodejs_version

.github/workflows/nodejs.yml

Lines changed: 26 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -8,17 +8,16 @@ on:
88

99
jobs:
1010
build_ubuntu:
11-
1211
runs-on: ubuntu-latest
1312

1413
strategy:
1514
matrix:
16-
node-version: ["14.x", "16.x", "18.x"]
15+
node-version: ["18.x", "20.x"]
1716

1817
steps:
19-
- uses: actions/checkout@v2
18+
- uses: actions/checkout@v4
2019
- name: Use Node.js ${{ matrix.node-version }}
21-
uses: actions/setup-node@v1
20+
uses: actions/setup-node@v3
2221
with:
2322
node-version: ${{ matrix.node-version }}
2423
- run: npm i
@@ -29,13 +28,33 @@ jobs:
2928

3029
strategy:
3130
matrix:
32-
node-version: ["14.x", "16.x", "18.x"]
31+
node-version: ["18.x", "20.x"]
3332

3433
steps:
35-
- uses: actions/checkout@v2
34+
- uses: actions/checkout@v4
3635
- name: Use Node.js ${{ matrix.node-version }}
37-
uses: actions/setup-node@v1
36+
uses: actions/setup-node@v3
3837
with:
3938
node-version: ${{ matrix.node-version }}
4039
- run: npm i
4140
- run: npm test
41+
42+
lint:
43+
runs-on: ubuntu-latest
44+
steps:
45+
- uses: actions/checkout@v4
46+
- uses: actions/setup-node@v3
47+
with:
48+
node-version: 20
49+
- run: npm i
50+
- run: npm run lint
51+
52+
prettier:
53+
runs-on: ubuntu-latest
54+
steps:
55+
- uses: actions/checkout@v4
56+
- uses: actions/setup-node@v3
57+
with:
58+
node-version: 20
59+
- run: npm i
60+
- run: npm run prettier

.travis.yml

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,6 @@ jobs:
44
script: npm run lint
55
language: node_js
66
node_js:
7+
- 20
78
- 18
8-
- 16
9-
- 14
109
sudo: false

CHANGELOG.md

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,14 @@
11
# node-dev
22

3+
## v9.0.0 / 2023-09-16
4+
5+
- Drop support for node v14 and v16, the new minimum version of node is v18 (@bjornstar)
6+
- Add support for node v20 (@bjornstar)
7+
- Removed tests for `experimental-specifier-resolution` as it's no longer supported (@bjornstar)
8+
- [CI] Test v18 & v20 (@bjornstar)
9+
- [CI] Perform linting and prettier in github actions (@bjornstar)
10+
- [`devDependencies`] Update most devDependencies to their latest version (@bjornstar)
11+
312
## v8.0.0 / 2022-12-30
413

514
- Suppress experimental warnings in node v18 (@tmont)

lib/index.js

Lines changed: 8 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,7 @@
11
const { fork } = require('child_process');
22
const filewatcher = require('filewatcher');
3-
const { join } = require('path');
4-
const semver = require('semver');
5-
const { pathToFileURL } = require('url');
3+
const { join } = require('node:path');
4+
const { pathToFileURL } = require('node:url');
65

76
const { clearFactory } = require('./clear');
87
const { configureDeps, configureIgnore } = require('./ignore');
@@ -92,20 +91,16 @@ module.exports = function (
9291
function start() {
9392
isPaused = false;
9493

95-
const args = nodeArgs.slice();
96-
97-
args.push(`--require=${resolveMain(localPath('wrap'))}`);
98-
99-
const loaderName = semver.satisfies(process.version, '>=16.12.0') ? 'load' : 'get-format';
100-
101-
const loaderURL = pathToFileURL(resolveMain(localPath(join('loaders', `${loaderName}.mjs`))));
102-
103-
args.push(`--experimental-loader=${loaderURL.href}`);
94+
const loaderURL = pathToFileURL(resolveMain(localPath(join('loaders', 'load.mjs'))));
10495

10596
child = fork(script, scriptArgs, {
10697
cwd: process.cwd(),
10798
env: process.env,
108-
execArgv: args
99+
execArgv: [
100+
...nodeArgs.slice(),
101+
`--experimental-loader=${loaderURL.href}`,
102+
`--require=${resolveMain(localPath('wrap'))}`
103+
]
109104
});
110105

111106
if (respawn) {

lib/loaders/load.mjs

Lines changed: 11 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,23 @@
1-
import { createRequire } from 'module';
2-
import { fileURLToPath } from 'url';
1+
import { createRequire } from 'node:module';
2+
import { fileURLToPath } from 'node:url';
33
import { send } from './ipc.mjs';
44

55
const require = createRequire(import.meta.url);
66

7-
export async function load(url, context, defaultLoad) {
7+
let connectedPort;
8+
9+
export async function initialize({ port } = {}) {
10+
connectedPort = port;
11+
}
12+
13+
export async function load(url, context, nextLoad) {
814
const required = url.startsWith('file://') ? fileURLToPath(url) : url;
915

1016
send({ required });
17+
if (connectedPort) connectedPort.postMessage({ required });
1118

1219
try {
13-
return await defaultLoad(url, context, defaultLoad);
20+
return await nextLoad(url, context);
1421
} catch (error) {
1522
if (error.code !== 'ERR_UNKNOWN_FILE_EXTENSION') throw error;
1623
return require('get-package-type')(required).then(format => {

lib/register-loader.js

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
const { register } = require('node:module');
2+
const { join } = require('node:path');
3+
const { pathToFileURL } = require('node:url');
4+
const semver = require('semver');
5+
6+
const { send } = require('./ipc');
7+
const localPath = require('./local-path');
8+
const resolveMain = require('./resolve-main');
9+
10+
exports.registerLoader = () => {
11+
if (!semver.satisfies(process.version, '>=20.6.0')) return;
12+
13+
const loaderURL = pathToFileURL(resolveMain(localPath(join('loaders', 'load.mjs'))));
14+
15+
const { port1, port2 } = new MessageChannel();
16+
port1.on('message', ({ required } = {}) => {
17+
send({ required });
18+
});
19+
20+
register(loaderURL.href, {
21+
parentURL: loaderURL.href,
22+
data: { port: port2 },
23+
transferList: [port2]
24+
});
25+
26+
return port1;
27+
};

lib/wrap.js

Lines changed: 12 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,12 @@
1-
const { dirname, extname } = require('path');
2-
const childProcess = require('child_process');
1+
const childProcess = require('node:child_process');
2+
const { dirname, extname } = require('node:path');
3+
const { isMainThread } = require('node:worker_threads');
34
const { sync: resolve } = require('resolve');
4-
const { isMainThread } = require('worker_threads');
55

66
const { getConfig } = require('./cfg');
77
const hook = require('./hook');
88
const { relay, send } = require('./ipc');
9+
const { registerLoader } = require('./register-loader');
910
const resolveMain = require('./resolve-main');
1011
const suppressExperimentalWarnings = require('./suppress-experimental-warnings');
1112

@@ -25,8 +26,14 @@ if (process.env.NODE_DEV_PRELOAD) {
2526
require(process.env.NODE_DEV_PRELOAD);
2627
}
2728

28-
// We want to exit on SIGTERM, but defer to existing SIGTERM handlers.
29-
process.once('SIGTERM', () => process.listenerCount('SIGTERM') || process.exit(0));
29+
const port = registerLoader();
30+
31+
process.once('SIGTERM', () => {
32+
port?.close();
33+
// We want to exit on SIGTERM, but defer to existing SIGTERM handlers.
34+
if (process.listenerCount('SIGTERM')) return;
35+
process.exit(0);
36+
});
3037

3138
if (fork) {
3239
// Overwrite child_process.fork() so that we can hook into forked processes

package.json

Lines changed: 17 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "node-dev",
3-
"version": "8.0.0",
3+
"version": "9.0.0",
44
"description": "Restarts your app when files are modified",
55
"keywords": [
66
"restart",
@@ -24,35 +24,36 @@
2424
},
2525
"main": "./lib",
2626
"engines": {
27-
"node": ">=14"
27+
"node": ">=18"
2828
},
2929
"scripts": {
3030
"lint": "eslint lib test bin/node-dev",
31-
"test": "node test",
32-
"prepare": "husky install"
31+
"prepare": "husky install",
32+
"prettier": "prettier lib test bin/node-dev",
33+
"test": "node test"
3334
},
3435
"dependencies": {
3536
"dateformat": "^3.0.3",
3637
"dynamic-dedupe": "^0.3.0",
37-
"filewatcher": "~3.0.0",
38+
"filewatcher": "^3.0.1",
3839
"get-package-type": "^0.1.0",
3940
"minimist": "^1.2.6",
4041
"node-notifier": "^8.0.1",
41-
"resolve": "^1.22.0",
42-
"semver": "^7.3.7"
42+
"resolve": "^1.22.6",
43+
"semver": "^7.5.4"
4344
},
4445
"devDependencies": {
45-
"@types/node": "^18.11.18",
46-
"eslint": "^8.30.0",
47-
"eslint-plugin-import": "^2.26.0",
48-
"husky": "^8.0.2",
49-
"lint-staged": "^13.1.0",
50-
"prettier": "^2.6.2",
51-
"tap": "^16.3.2",
46+
"@types/node": "^20.6.2",
47+
"eslint": "^8.49.0",
48+
"eslint-plugin-import": "^2.28.1",
49+
"husky": "^8.0.3",
50+
"lint-staged": "^14.0.1",
51+
"prettier": "^3.0.3",
52+
"tap": "^18.0.4",
5253
"tap-xunit": "^2.4.1",
5354
"touch": "^3.1.0",
54-
"ts-node": "^10.7.0",
55-
"typescript": "^4.6.3"
55+
"ts-node": "^10.9.1",
56+
"typescript": "^5.2.2"
5657
},
5758
"lint-staged": {
5859
"*.{js,mjs}": "eslint --cache --fix",

test/fixture/cluster.js

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
const { disconnect, fork, isMaster, isWorker } = require('cluster');
1+
const { fork, isMaster, isWorker } = require('node:cluster');
22

33
const createWorker = i => {
44
const worker = fork();
@@ -26,15 +26,16 @@ if (isWorker) {
2626
}
2727

2828
if (isMaster) {
29+
const workers = [];
2930
for (let i = 0; i < 2; i += 1) {
3031
console.log('Forking worker', i);
31-
createWorker(i);
32+
workers.push(createWorker(i));
3233
}
3334

3435
process.once('SIGTERM', () => {
3536
console.log('Master received SIGTERM');
36-
disconnect(() => {
37-
console.log('All workers disconnected.');
38-
});
37+
workers.forEach(worker => worker.kill());
38+
console.log('All workers disconnected.');
39+
process.exit(0);
3940
});
4041
}

0 commit comments

Comments
 (0)