Skip to content

Commit

Permalink
refactor(core): mark requires as async
Browse files Browse the repository at this point in the history
  • Loading branch information
wdavidw committed Nov 17, 2023
1 parent 72a85fb commit 9969a74
Show file tree
Hide file tree
Showing 4 changed files with 11 additions and 9 deletions.
4 changes: 2 additions & 2 deletions packages/core/lib/actions/call/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ const {mutate} = require('mixme');
// Action
module.exports = {
hooks: {
on_action: function(action) {
on_action: async function(action) {
if (typeof action.metadata.argument !== 'string') {
return;
}
Expand All @@ -16,7 +16,7 @@ module.exports = {
if (mod.startsWith('.')) {
mod = path.resolve(process.cwd(), mod);
}
mod = require.main.require(mod);
mod = await require.main.require(mod);
// The loaded action can have its own interpretation of an argument.
// In order to avoid any conflict, we simply remove the
// `action.metadata.argument` property.
Expand Down
2 changes: 1 addition & 1 deletion packages/core/lib/plugins/tools/schema.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

12 changes: 6 additions & 6 deletions packages/core/lib/registry.js
Original file line number Diff line number Diff line change
Expand Up @@ -51,11 +51,11 @@ const create = function({chain, on_register, parent, plugins} = {}) {
Load an action from the module name.
*/
obj.load = function(module) {
obj.load = async function(module) {
if (typeof module !== 'string') {
throw Error(`Invalid Argument: module must be a string, got ${module.toString()}`);
}
const action = require.main.require(module);
const action = await require.main.require(module);
if (typeof action === 'function') {
action = {
handler: action
Expand Down Expand Up @@ -265,7 +265,7 @@ const create = function({chain, on_register, parent, plugins} = {}) {
return obj.chain || obj;
}
if (typeof action === 'string') {
action = obj.load(action);
action = await obj.load(action);
} else if (typeof action === 'function') {
action = {
handler: action
Expand Down Expand Up @@ -293,7 +293,7 @@ const create = function({chain, on_register, parent, plugins} = {}) {
results.push((await walk(namespace, action)));
} else {
if (typeof action === 'string') {
action = obj.load(action);
action = await obj.load(action);
} else if (typeof action === 'function') {
action = {
handler: action
Expand Down Expand Up @@ -336,14 +336,14 @@ const create = function({chain, on_register, parent, plugins} = {}) {
```
*/
obj.deprecate = function(old_name, new_name, action) {
obj.deprecate = async function(old_name, new_name, action) {
let handler;
if (arguments.length === 2) {
handler = new_name;
new_name = null;
}
if (typeof action === 'string') {
action = obj.load(action);
action = await obj.load(action);
}
if (typeof handler === 'function') {
action = {
Expand Down
2 changes: 2 additions & 0 deletions packages/core/lib/session.js
Original file line number Diff line number Diff line change
Expand Up @@ -50,13 +50,15 @@ const session = function(args, options = {}) {
};
// Building the namespace before calling an action
const on_get = function(target, name) {
// Return static properties
if ((target[name] != null) && !action.registry.registered(name)) {
if (typeof target[name] === 'function') {
return target[name].bind(target);
} else {
return target[name];
}
}
// Return the plugins instance in the root session
if (namespace.length === 0) {
switch (name) {
case 'plugins':
Expand Down

0 comments on commit 9969a74

Please sign in to comment.