Skip to content

Commit

Permalink
v13.0.0
Browse files Browse the repository at this point in the history
  • Loading branch information
rjrodger committed Jun 5, 2024
1 parent 2fdd603 commit eb0fc6e
Show file tree
Hide file tree
Showing 3 changed files with 49 additions and 27 deletions.
7 changes: 3 additions & 4 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "use-plugin",
"version": "12.0.1",
"version": "13.0.0",
"description": "Generic plugin loader functionality for Node.js frameworks.",
"main": "use.js",
"scripts": {
Expand Down Expand Up @@ -28,15 +28,14 @@
"dependencies": {
"eraro": "^3.0.1",
"nid": "^2.0.1",
"norma": "^3.1.1",
"gubu": "^7.1.0",
"lodash.defaultsdeep": "^4.6.1"
},
"devDependencies": {
"gubu": "^7.0.0",
"@hapi/code": "^9.0.3",
"@hapi/lab": "^25.2.0",
"coveralls": "^3.1.1",
"prettier": "^3.2.5"
"prettier": "^3.3.1"
},
"files": [
"README.md",
Expand Down
4 changes: 2 additions & 2 deletions test/use.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -346,12 +346,12 @@ describe('use', function () {
})

it('frozen-options', function (fin) {
var f1 = Origin.use(function f1() {}, Object.freeze({ a: 1 }))
const f1 = Origin.use(function f1() {}, Object.freeze({ a: 1 }))
Assert.equal(f1.options.a, 1)
fin()
})

it('edges', function (fin) {
it('edges-other', function (fin) {
try {
Origin.use()
Code.fail()
Expand Down
65 changes: 44 additions & 21 deletions use.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
/* Copyright © 2014-2022 Richard Rodger and other contributors, MIT License. */
/* Copyright © 2014-2024 Richard Rodger and other contributors, MIT License. */
'use strict'

const Path = require('path')
Expand All @@ -8,11 +8,21 @@ const Module = require('module')

// #### External modules
const Nid = require('nid')
const Norma = require('norma')
const Gubu = require('gubu')
const Eraro = require('eraro')
const DefaultsDeep = require('lodash.defaultsdeep')

// const Optioner = require('optioner')
const { MakeArgu, Skip, One } = Gubu

const Argu = MakeArgu('use')

// '{plugin:o|f|s, options:o|s|n|b?, callback:f?}',

const PluginArgu = Argu('plugin', {
plugin: One(Object, Function, String),
options: Skip(One(Object, String)),
callback: Skip(One(Function, null)),
})

// #### Exports
module.exports = make
Expand Down Expand Up @@ -73,15 +83,20 @@ function make(useopts) {
// * _tag_ : String; the tag value of the plugin name (format: name$tag), if any, allows loading of same plugin multiple times
// * _err_ : Error; plugin load error, if any
function use() {
const args = Norma(
'{plugin:o|f|s, options:o|s|n|b?, callback:f?}',
arguments,
)
return use_plugin_desc(
build_plugin_desc(args, useopts, eraro),
useopts,
eraro,
)
try {
const args = PluginArgu(arguments)

return use_plugin_desc(
build_plugin_desc(args, useopts, eraro),
useopts,
eraro,
)
} catch (err) {
if ('shape' === err.code) {
err.code = 'invalid_arguments'
}
throw err
}
}

// use.Optioner = Optioner
Expand All @@ -92,11 +107,15 @@ function make(useopts) {
}

use.build_plugin_desc = function () {
const args = Norma(
'{plugin:o|f|s, options:o|s|n|b?, callback:f?}',
arguments,
)
return build_plugin_desc(args, useopts, eraro)
try {
const args = PluginArgu(arguments)
return build_plugin_desc(args, useopts, eraro)
} catch (err) {
if ('shape' === err.code) {
err.code = 'invalid_arguments'
}
throw err
}
}

return use
Expand Down Expand Up @@ -476,13 +495,17 @@ function perform_require(reqfunc, plugin_desc, builtin, level) {
}
}

const BuildNameArgu = Argu('build-name', {
name: String,
builtin: Skip(One(String, Array)),
prefix: Skip(One(String, Array)),
system: Skip(Array),
})

// #### Create the list of require search locations
// Searches are performed without the prefix first
function build_plugin_names() {
const args = Norma(
'{name:s, builtin:s|a?, prefix:s|a?, system:a?}',
arguments,
)
const args = BuildNameArgu(arguments)

const name = args.name
const isRelative = name.match(/^[./]/)
Expand Down

0 comments on commit eb0fc6e

Please sign in to comment.