-
Notifications
You must be signed in to change notification settings - Fork 122
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
58 changed files
with
419 additions
and
329 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
#!/usr/bin/env node | ||
|
||
import dev from '../lib/index.js'; | ||
import cli from '../lib/cli.js'; | ||
|
||
const { script, scriptArgs, nodeArgs, opts } = cli(process.argv); | ||
|
||
dev(script, scriptArgs, nodeArgs, opts); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,2 @@ | ||
const control = '\u001bc'; | ||
const clearFactory = clear => (clear ? () => process.stdout.write(control) : () => {}); | ||
|
||
module.exports = { clearFactory, control }; | ||
export const control = '\u001bc'; | ||
export const clearFactory = clear => (clear ? () => process.stdout.write(control) : () => {}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,52 @@ | ||
const { once } = require('events'); | ||
const { Worker } = require('worker_threads'); | ||
|
||
const logFactory = require('./log.cjs'); | ||
|
||
const cmd = 'NODE_DEV'; | ||
const log = logFactory({}); | ||
let nodeDevPort; | ||
|
||
exports.on = (src, prop, cb) => { | ||
src.on('internalMessage', m => { | ||
if (m.cmd === cmd && prop in m) cb(m); | ||
}); | ||
}; | ||
|
||
exports.relay = src => { | ||
if (src instanceof Worker) { | ||
// create a separate message channel for node-dev | ||
const { port1, port2 } = new MessageChannel(); | ||
port1.unref(); | ||
port1.on('message', exports.send); | ||
src.postMessage({ cmd, port: port2 }, [port2]); | ||
} else { | ||
src.on('internalMessage', m => { | ||
if (process.connected && m.cmd === cmd) process.send(m); | ||
}); | ||
} | ||
}; | ||
|
||
exports.send = m => { | ||
if (process.connected) { | ||
process.send({ ...m, cmd }); | ||
} else if (nodeDevPort) { | ||
// this has doesn't seem to have a race condition in testing | ||
// but just in case, the log statement below should notify of it | ||
nodeDevPort.postMessage({ ...m, cmd }); | ||
} else { | ||
log.warn( | ||
`node-dev: The module ${m.required} was imported from an orphaned child process or worker thread` | ||
); | ||
} | ||
}; | ||
|
||
exports.receiveMessagePort = async src => { | ||
// the first message received by this thread should contain the parent port | ||
const [m] = await once(src, 'message'); | ||
if (m && m.cmd === cmd) { | ||
nodeDevPort = m.port; | ||
} else { | ||
log.warn('node-dev: unexpected message on the parentPort', m); | ||
} | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
File renamed without changes.
Oops, something went wrong.