stumble-core
Advanced tools
Comparing version 0.0.1 to 1.0.0
@@ -7,2 +7,5 @@ 'use strict'; | ||
const stack = require('./stack'); | ||
const path = require('path'); | ||
module.exports = class StumbleCore extends EventEmitter { | ||
@@ -22,5 +25,5 @@ constructor (opts) { | ||
use (extension, pending) { | ||
use (extension, pending, index) { | ||
if (Array.isArray(extension)) | ||
extension.forEach(ext => this.use(ext, extension)); | ||
extension.forEach((ext, i) => this.use(ext, extension, i)); | ||
else { | ||
@@ -35,10 +38,10 @@ if (!extension || !Object.keys(extension).length) | ||
let missing = true; | ||
let len = null; | ||
let length = null; | ||
if (pending && (len = pending.length)) { | ||
for (let i = 0; i < len; i++) { | ||
if (pending[i].handle === ext) { | ||
if (pending && (length = pending.length)) | ||
for (let offset = index + 1 || 1; offset < length; offset++) | ||
if (pending[offset].handle === ext) { | ||
clearTimeout(this.__cachetimer); | ||
this.use(pending[i], pending); | ||
this.use(pending[offset], pending, offset); | ||
this.__cache[ext] = true; | ||
@@ -54,4 +57,2 @@ | ||
} | ||
} | ||
} | ||
@@ -98,6 +99,7 @@ if (missing) throw new Error(`EXT: Missing required [ ${ext} ].`); | ||
} | ||
return this; | ||
} | ||
execute (handle, share, roll) { | ||
execute (handle, data) { | ||
const extension = this.extensions.get(handle); | ||
@@ -107,11 +109,11 @@ | ||
if (extension.hooks) { | ||
roll = extension.hooks.map(hook => this.execute(hook, share, roll)); | ||
} | ||
const roll = extension.hooks ? | ||
extension.hooks.map(hook => this.execute(hook, data)) : null; | ||
return extension.exec.call(this, share, roll || null); | ||
return extension.exec.call(this, data, roll); | ||
} | ||
define (command) { | ||
if (Array.isArray(command)) command.forEach(cmd => this.define(cmd)); | ||
if (Array.isArray(command)) | ||
command.forEach(cmd => this.define(cmd)); | ||
else { | ||
@@ -129,5 +131,3 @@ if (!command || !(command.handle && command.exec)) | ||
this.commands.set(handle, ( | ||
command instanceof Command ? command : new Command(command) | ||
)); | ||
this.commands.set(handle, new Command(command)); | ||
} | ||
@@ -140,3 +140,3 @@ | ||
if (!this.commands.has(handle)) | ||
throw new Error(`CMD: Attempted to invoke missing [ ${handle} ]`); | ||
throw new Error(`CMD: Attempted to invoke missing [ ${handle} ].`); | ||
@@ -146,2 +146,17 @@ const command = this.commands.get(handle); | ||
} | ||
static dequire (p) { | ||
if (!path.isAbsolute(p)) { | ||
const file = stack(2)[1].getFileName(); | ||
const dir = path.dirname(file); | ||
p = path.resolve(dir, p); | ||
} | ||
const mod = require(p); | ||
delete require.cache[require.resolve(p)]; | ||
return mod; | ||
} | ||
}; |
{ | ||
"name": "stumble-core", | ||
"version": "0.0.1", | ||
"description": "StumbleCore.", | ||
"version": "1.0.0", | ||
"description": "StumbleCore - extension loader.", | ||
"main": "lib/StumbleCore", | ||
"scripts": { | ||
"test": "echo \"Error: no test specified\" && exit 1" | ||
"engines": { | ||
"node": ">=5.0.0", | ||
"npm": ">=3.0.0" | ||
}, | ||
@@ -9,0 +10,0 @@ "repository": { |
Sorry, the diff of this file is not supported yet
Dynamic require
Supply chain riskDynamic require can indicate the package is performing dangerous or unsafe dynamic code execution.
Found 1 instance in 1 package
No tests
QualityPackage does not have any tests. This is a strong signal of a poorly maintained or low quality package.
Found 1 instance in 1 package
No v1
QualityPackage is not semver >=1. This means it is not stable and does not support ^ ranges.
Found 1 instance in 1 package
17416
158
0
272
2