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

nodecaf-run

Package Overview
Dependencies
Maintainers
1
Versions
7
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

nodecaf-run - npm Package Compare versions

Comparing version 0.0.3 to 0.0.4

test/res/package.json

7

CHANGELOG.md

@@ -8,2 +8,8 @@ # Nodecaf Run Changelog

## [v0.0.4] - 2020-05-19
### Fixed
- reloading of deep child modules that would not take effect unless parents are also reloaded
- app name and version being fetched from wrong package.json when running through bin
## [v0.0.3] - 2020-04-24

@@ -29,1 +35,2 @@

[v0.0.3]: https://gitlab.com/nodecaf/run/-/tags/v0.0.3
[v0.0.4]: https://gitlab.com/nodecaf/run/-/tags/v0.0.4

20

lib/main.js
const path = require('path');
const chokidar = require('chokidar');
const { EventEmitter } = require('events');
const { AppServer } = require('nodecaf');
let watcher, dieFn, termFn;

@@ -51,3 +50,3 @@

delete require.cache[mainPath];
try{

@@ -89,10 +88,17 @@ var app = require(opts.path)();

delete require.cache[path];
// Invalidate changed file and all parents up to init function
var nm = {};
while(!nm.exports || nm.exports.name != 'init'){
nm = require.cache[path].parent;
delete require.cache[path];
path = nm.id;
}
let newApp = load(opts);
newApp.debugEvents = app.debugEvents;
//newApp.debugEvents = app.debugEvents;
newApp.log.debug({ class: 'app' }, 'Reloaded');
await newApp.start();
newApp.debugEvents.emit('reloaded', newApp);
//newApp.debugEvents.emit('reloaded', newApp);

@@ -118,6 +124,6 @@ }

/* istanbul ignore next */
if(opts.reload)
app.debugEvents = new EventEmitter();
//if(opts.reload)
// app.debugEvents = new EventEmitter();
return app.start();
}
{
"name": "nodecaf-run",
"version": "0.0.3",
"version": "0.0.4",
"description": "A module to run standalone Nodecaf apps as opposed to requiring them.",

@@ -36,8 +36,9 @@ "main": "lib/main.js",

"dependencies": {
"chokidar": "^3.3.1",
"nodecaf": "^0.9.1"
"chokidar": "^3.4.0"
},
"devDependencies": {
"muhb": "^3.0.1"
"muhb": "^3.0.3",
"nodecaf": "^0.9.1",
"tempper": "^0.1.1"
}
}

@@ -9,3 +9,6 @@

app.api(function({ get }){
get('/bar', ({ res, conf }) => res.end(conf.name || conf.key || 'foo'));
get('/bar', ({ res, conf }) => {
res.set('Content-Type', 'text/plain');
res.end(conf.name || conf.key || 'foo');
});
});

@@ -12,0 +15,0 @@

@@ -14,6 +14,5 @@ const assert = require('assert');

const path = require('path');
//const fs = require('fs');
let appPath = path.resolve('./test/res');
let bAppPath = path.resolve('./test/res/bad-index');
//let nAppPath = path.resolve('./node_modules');

@@ -29,2 +28,14 @@ it('Should fail with bad init path', () => {

it('Should load the proper app name', async () => {
const Tempper = require('tempper');
let tmp = new Tempper();
tmp.addFile('./test/res/package.json', './package.json');
tmp.mkdir('./lib');
tmp.addFile('./test/res/reload.js', './lib/main.js');
let app = await run({ path: '.' });
assert.strictEqual(app.name, 'test-run');
await app.stop();
tmp.clear();
});
it('Should run the given app server', async () => {

@@ -51,15 +62,43 @@ let app = await run({ path: appPath });

// it('Should ...', function(done){
// fs.copyFileSync('./test/res/index.js', './node_modules/index.js');
// let na = fs.readFileSync('./test/res/index2.js', 'utf-8');
// (async function(){
// let app = await run({ reload: true, path: nAppPath });
// app.debugEvents.on('reloaded', async newApp => {
// await newApp.stop();
// done();
// });
// fs.writeFileSync('./node_modules/index.js', na);
// })();
// });
// TODO fix cryptic error EPERM on writing and closing the watched file
/*
describe.only('Reloading', () => {
const fs = require('fs');
beforeEach(() => tmp.refresh());
it('Shoud ...', (done) => {
tmp.addFile('./test/res/package.json', './package.json');
tmp.mkdir('./lib');
tmp.addFile('./test/res/reload.js', './lib/main.js');
(async function(){
let app = await run({ reload: true, path: '.' });
let { body } = await base.get('foo');
assert.strictEqual(body, 'A');
let data = fs.readFileSync('./lib/main.js', 'utf-8');
let newData = [ 'const test = \'B\';', ...data.split(/[\r\n]+/).slice(1) ].join('\r\n');
app.debugEvents.on('reloaded', async newApp => {
console.log('GOT HERE');
app.fsWatcher.close();
await newApp.stop();
done();
});
fs.writeFile('./lib/main.js', newData, console.log);
})();
});
});*/
});

@@ -66,0 +105,0 @@

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