Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

node-dev

Package Overview
Dependencies
Maintainers
4
Versions
68
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

node-dev - npm Package Compare versions

Comparing version 5.2.0 to 6.0.0

lib/get-source-loader.mjs

13

CHANGELOG.md
# node-dev
## v6.0.0 / 2020-10-14
- Support ESModules in node v12.11.1+ using `get-source-loader.mjs` and `resolve-loader.mjs` for earlier versions (Fixes #212)
- Pass all unknown arguments to node (Fixes #198)
- Add a test case for typescript using require on the command line
- Add a test case for coffeescript using require on the command line
- Add a test case for `--experimental-specifier-resolution=node`
- Add a test case for `--inspect`
- Add `ts-node/register` as a default extension (Fixes #182)
- [`README.md`] Updated to explain ESModule usage, node arguments, and typescript
- [`test/utils/touch-file`] Now takes the filename as an argument
- [`test/utils/spawn`] Also calls the callback with stderr output
## v5.2.0 / 2020-08-19

@@ -4,0 +17,0 @@

3

lib/cfg.js

@@ -12,3 +12,4 @@ const fs = require('fs');

coffee: 'coffeescript/register',
ls: 'LiveScript'
ls: 'LiveScript',
ts: 'ts-node/register'
},

@@ -15,0 +16,0 @@ fork: true,

@@ -20,20 +20,5 @@ const minimist = require('minimist');

function removeValueArgs(args, names) {
let i = 0;
let removed = [];
module.exports = argv => {
const nodeArgs = [];
while (i < args.length) {
if (names.includes(args[i])) {
removed = removed.concat(args.splice(i, 2));
} else {
i += 1;
}
}
return removed;
}
module.exports = function (argv) {
const nodeArgs = removeValueArgs(argv, ['-r', '--require']);
const scriptIndex = getFirstNonOptionArgIndex(argv);

@@ -40,0 +25,0 @@ const script = argv[scriptIndex];

const vm = require('vm');
module.exports = function (patchVM, wrapper, callback) {
module.exports = (patchVM, wrapper, callback) => {
// Hook into Node's `require(...)`

@@ -37,3 +37,3 @@ updateHooks();

function updateHooks() {
Object.keys(require.extensions).forEach(function (ext) {
Object.keys(require.extensions).forEach(ext => {
const fn = require.extensions[ext];

@@ -40,0 +40,0 @@ if (typeof fn === 'function' && fn.name !== 'nodeDevHook') {

const fork = require('child_process').fork;
const filewatcher = require('filewatcher');
const path = require('path');
const semver = require('semver');

@@ -51,6 +52,6 @@ const ipc = require('./ipc');

watcher.on('change', function (file) {
watcher.on('change', file => {
/* eslint-disable no-octal-escape */
if (clear) process.stdout.write('\033[2J\033[H');
notify('Restarting', file + ' has been modified');
notify('Restarting', `${file} has been modified`);
watcher.removeAll();

@@ -67,3 +68,3 @@ if (child) {

watcher.on('fallback', function (limit) {
watcher.on('fallback', limit => {
log.warn('node-dev ran out of file handles after watching %s files.', limit);

@@ -80,2 +81,13 @@ log.warn('Falling back to polling which uses more CPU.');

const cmd = nodeArgs.concat(wrapper, script, scriptArgs);
if (path.extname(script).slice(1) === 'mjs') {
if (semver.satisfies(process.version, '>=10 <12.11.1')) {
const resolveLoader = resolveMain(path.join(__dirname, 'resolve-loader.mjs'));
cmd.unshift('--experimental-modules', `--loader=${resolveLoader}`);
} else if (semver.satisfies(process.version, '>=12.11.1')) {
const getSourceLoader = resolveMain(path.join(__dirname, 'get-source-loader.mjs'));
cmd.unshift(`--experimental-loader=${getSourceLoader}`);
}
}
child = fork(cmd[0], cmd.slice(1), {

@@ -89,3 +101,3 @@ cwd: process.cwd(),

}
child.on('exit', function (code) {
child.on('exit', code => {
if (!child.respawn) process.exit(code);

@@ -96,7 +108,7 @@ child = undefined;

// Listen for `required` messages and watch the required file.
ipc.on(child, 'required', function (m) {
const isIgnored = ignore.some(isPrefixOf(m.required));
ipc.on(child, 'required', ({ required }) => {
const isIgnored = ignore.some(isPrefixOf(required));
if (!isIgnored && (deps === -1 || getLevel(m.required) <= deps)) {
watcher.add(m.required);
if (!isIgnored && (deps === -1 || getLevel(required) <= deps)) {
watcher.add(required);
}

@@ -106,5 +118,5 @@ });

// Upon errors, display a notification and tell the child to exit.
ipc.on(child, 'error', function (m) {
notify(m.error, m.message, 'error');
stop(m.willTerminate);
ipc.on(child, 'error', ({ error, message, willTerminate }) => {
notify(error, message, 'error');
stop(willTerminate);
});

@@ -127,3 +139,3 @@ }

// Relay SIGTERM
process.on('SIGTERM', function () {
process.on('SIGTERM', () => {
if (child && child.connected) {

@@ -165,5 +177,5 @@ if (gracefulIPC) {

function isPrefixOf(value) {
return function (prefix) {
return prefix => {
return value.indexOf(prefix) === 0;
};
}

@@ -5,3 +5,3 @@ var path = require('path');

function icon(level) {
return path.resolve(__dirname, '../icons/node_' + level + '.png');
return path.resolve(__dirname, `../icons/node_${level}.png`);
}

@@ -13,5 +13,5 @@

module.exports = function (notifyEnabled, log) {
return function (title, msg, level) {
return (title, msg, level) => {
level = level || 'info';
log(title || msg, level);
log(`${title}: ${msg}`, level);
if (notifyEnabled) {

@@ -18,0 +18,0 @@ notifier.notify({

@@ -21,3 +21,3 @@ const path = require('path');

// Listen SIGTERM and exit unless there is another listener
process.on('SIGTERM', function () {
process.on('SIGTERM', () => {
if (process.listeners('SIGTERM').length === 1) process.exit(0);

@@ -30,3 +30,3 @@ });

const originalFork = childProcess.fork;
childProcess.fork = function (modulePath, args, options) {
childProcess.fork = (modulePath, args, options) => {
const child = originalFork(__filename, [modulePath].concat(args), options);

@@ -39,3 +39,3 @@ ipc.relay(child);

// Error handler that displays a notification and logs the stack to stderr:
process.on('uncaughtException', function (err) {
process.on('uncaughtException', err => {
// Sometimes uncaught exceptions are not errors

@@ -54,3 +54,3 @@ const { message, name, stack } = err instanceof Error ? err : new Error(`uncaughtException ${err}`);

// Hook into require() and notify the parent process about required files
hook(vm, module, function (required) {
hook(vm, module, required => {
ipc.send({ required });

@@ -77,2 +77,6 @@ });

// Execute the wrapped script
require(main);
if (ext === 'mjs') {
import(main);
} else {
require(main);
}
{
"name": "node-dev",
"version": "5.2.0",
"version": "6.0.0",
"description": "Restarts your app when files are modified",

@@ -40,13 +40,17 @@ "keywords": [

"node-notifier": "^5.4.0",
"resolve": "^1.0.0"
"resolve": "^1.0.0",
"semver": "^7.3.2"
},
"devDependencies": {
"@types/node": "^14.11.8",
"coffeescript": "^2.4.1",
"eslint": "^7.3.1",
"eslint": "^7.11.0",
"eslint-config-airbnb-base": "^14.2.0",
"eslint-plugin-import": "^2.22.0",
"eslint-plugin-import": "^2.22.1",
"nyc": "^15.1.0",
"tap": "^14.10.7",
"touch": "^3.1.0"
"touch": "^3.1.0",
"ts-node": "^9.0.0",
"typescript": "^4.0.3"
}
}

@@ -59,6 +59,8 @@ [![Build Status](https://secure.travis-ci.org/fgnass/node-dev.png)](http://travis-ci.org/fgnass/node-dev)

Node-dev can be installed via npm. Make sure to use the `-g` option to install
it globally.
`node-dev` can be installed via `npm`. Installing it with the `-g` option will
allow you to use it anywhere you would use `node`.
npm install -g node-dev
```
npm install -g node-dev
```

@@ -106,9 +108,19 @@ ### Desktop Notifications

### ESModules
When using ESModule syntax and `.mjs` files, `node-dev` will automatically use
a loader to know which files to watch.
### Passing arguments to node
From v6 onwards, `node-dev` will pass all unknown command-line arguments to
the `node` process which should provide more flexibility for developers.
### Dedupe linked modules
Sometimes you need to make sure that multiple modules get
_exactly the same instance_ of a common (peer-) dependency. This can usually be
achieved by running `npm dedupe` – however this doesn't work when you try to
`npm link` a dependency (which is quite common during development). Therefore
node-dev provides a `--dedupe` switch that will inject the
Sometimes you need to make sure that multiple modules get _exactly the same
instance_ of a common (peer-) dependency. This can usually be achieved by
running `npm dedupe` – however this doesn't work when you try to `npm link` a
dependency (which is quite common during development). Therefore `node-dev`
provides a `--dedupe` switch that will inject the
[dynamic-dedupe](https://www.npmjs.org/package/dynamic-dedupe) module into your

@@ -119,9 +131,9 @@ app.

You can also use node-dev to run transpiled languages. You can either use a
.js file as entry point to your application that registers your transpiler as
require-extension manually, for example by calling `CoffeeScript.register()` or
you can let node-dev do this for you.
You can use `node-dev` to run transpiled languages like TypeScript. You can
either use a `.js` file as entry point to your application that registers your
transpiler as a require-extension manually, for example by calling
`CoffeeScript.register()` or you can let node-dev do this for you.
There is a config option called `extensions` which maps file extensions to
compiler module names. By default this map looks like this:
compiler module names. By default the map looks like this:

@@ -131,3 +143,4 @@ ```json

"coffee": "coffee-script/register",
"ls": "LiveScript"
"ls": "LiveScript",
"ts": "ts-node/register"
}

@@ -137,3 +150,5 @@ ```

This means that if you run `node-dev foo.coffee` node-dev will do a
`require("coffee-script/register")` before running your script.
`require("coffee-script/register")` before running your script. You will need
to have `coffeescript` or `ts-node` installed as a dependency of your package
for these transpilers to function.

@@ -140,0 +155,0 @@ __Note:__ If you want to use coffee-script < 1.7 you have to change the

Sorry, the diff of this file is not supported yet

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc