nodecaf-run
Advanced tools
Comparing version 0.0.3 to 0.0.4
@@ -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 |
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 @@ |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
Dynamic require
Supply chain riskDynamic require can indicate the package is performing dangerous or unsafe dynamic code execution.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
15214
1
17
217
3
4
- Removednodecaf@^0.9.1
- Removedaccepts@1.3.8(transitive)
- Removedarray-flatten@1.1.1(transitive)
- Removedbody-parser@1.20.3(transitive)
- Removedbusboy@1.6.0(transitive)
- Removedbytes@3.1.2(transitive)
- Removedcall-bind-apply-helpers@1.0.1(transitive)
- Removedcall-bound@1.0.3(transitive)
- Removedcompressible@2.0.18(transitive)
- Removedcompression@1.7.5(transitive)
- Removedconfort@0.1.4(transitive)
- Removedcontent-disposition@0.5.4(transitive)
- Removedcontent-type@1.0.5(transitive)
- Removedcookie@0.7.10.7.2(transitive)
- Removedcookie-parser@1.4.7(transitive)
- Removedcookie-signature@1.0.6(transitive)
- Removedcore-util-is@1.0.3(transitive)
- Removedcors@2.8.5(transitive)
- Removeddebug@2.6.9(transitive)
- Removeddeepmerge@4.3.1(transitive)
- Removeddepd@1.1.22.0.0(transitive)
- Removeddestroy@1.2.0(transitive)
- Removeddunder-proto@1.0.1(transitive)
- Removedee-first@1.1.1(transitive)
- Removedencodeurl@1.0.22.0.0(transitive)
- Removedes-define-property@1.0.1(transitive)
- Removedes-errors@1.3.0(transitive)
- Removedes-object-atoms@1.1.1(transitive)
- Removedescape-html@1.0.3(transitive)
- Removedetag@1.8.1(transitive)
- Removedexpress@4.21.2(transitive)
- Removedexpress-fileupload@1.5.1(transitive)
- Removedfinalhandler@1.3.1(transitive)
- Removedforwarded@0.2.0(transitive)
- Removedfresh@0.5.2(transitive)
- Removedfunction-bind@1.1.2(transitive)
- Removedget-intrinsic@1.2.7(transitive)
- Removedget-proto@1.0.1(transitive)
- Removedgopd@1.2.0(transitive)
- Removedhas-symbols@1.1.0(transitive)
- Removedhasown@2.0.2(transitive)
- Removedhttp-errors@1.8.12.0.0(transitive)
- Removediconv-lite@0.4.24(transitive)
- Removedinherits@2.0.4(transitive)
- Removedipaddr.js@1.9.1(transitive)
- Removedisarray@1.0.0(transitive)
- Removedmath-intrinsics@1.1.0(transitive)
- Removedmedia-typer@0.3.0(transitive)
- Removedmerge-descriptors@1.0.3(transitive)
- Removedmethods@1.1.2(transitive)
- Removedmime@1.6.02.6.0(transitive)
- Removedmime-db@1.52.01.53.0(transitive)
- Removedmime-types@2.1.35(transitive)
- Removedms@2.0.02.1.3(transitive)
- Removednegotiator@0.6.30.6.4(transitive)
- Removednodecaf@0.9.5(transitive)
- Removedobject-assign@4.1.1(transitive)
- Removedobject-inspect@1.13.3(transitive)
- Removedon-finished@2.4.1(transitive)
- Removedon-headers@1.0.2(transitive)
- Removedparseurl@1.3.3(transitive)
- Removedpath-to-regexp@0.1.12(transitive)
- Removedprocess-nextick-args@2.0.1(transitive)
- Removedproxy-addr@2.0.7(transitive)
- Removedqs@6.13.0(transitive)
- Removedrange-parser@1.2.1(transitive)
- Removedraw-body@2.5.2(transitive)
- Removedreadable-stream@2.3.8(transitive)
- Removedsafe-buffer@5.1.25.2.1(transitive)
- Removedsafer-buffer@2.1.2(transitive)
- Removedsend@0.19.0(transitive)
- Removedserve-static@1.16.2(transitive)
- Removedsetprototypeof@1.2.0(transitive)
- Removedside-channel@1.1.0(transitive)
- Removedside-channel-list@1.0.0(transitive)
- Removedside-channel-map@1.0.1(transitive)
- Removedside-channel-weakmap@1.0.2(transitive)
- Removedstatuses@1.5.02.0.1(transitive)
- Removedstdout-stream@1.4.1(transitive)
- Removedstreamsearch@1.1.0(transitive)
- Removedstring_decoder@1.1.1(transitive)
- Removedtoidentifier@1.0.1(transitive)
- Removedtype-is@1.6.18(transitive)
- Removedunpipe@1.0.0(transitive)
- Removedutil-deprecate@1.0.2(transitive)
- Removedutils-merge@1.0.1(transitive)
- Removedvary@1.1.2(transitive)
- Removedws@7.5.10(transitive)
Updatedchokidar@^3.4.0