-
Notifications
You must be signed in to change notification settings - Fork 1k
Closed
Description
Lines 104 to 116 in 888db19
| const module = req(joined); | |
| const visited = visit(module, joined, file); | |
| if (visited) { | |
| if (this.requireCache.has(joined)) continue; | |
| else this.requireCache.add(joined); | |
| // Infer command from directory structure if none is given: | |
| if (!module.command) { | |
| module.command = this.shim.path.basename( | |
| joined, | |
| this.shim.path.extname(joined) | |
| ); | |
| } | |
| this.addHandler(module); |
For now:
When I add middleware in opts.visit (Why? Because I can get command object)
If the command module have no key: middleares, it will throw an error: (BTW, if the command do have a key: middleware, no error happens)
command.middlewares = [middleware];
^
TypeError: Cannot add property middlewares, object is not extensible
I think maybe we can change these lines code to be follows to solve this issue
const module = req(joined);
+ const extendableModule = { ...module };
- const visited = visit(module, joined, file);
+ const visited = visit(extendableModule, joined, file);
if (visited) {
if (this.requireCache.has(joined)) continue;
else this.requireCache.add(joined);
// Infer command from directory structure if none is given:
- if (!module.command) {
- module.command = this.shim.path.basename(
+ if (!extendableModule.command) {
+ extendableModule.command = this.shim.path.basename(
joined,
this.shim.path.extname(joined)
);
}
- this.addHandler(module);
+ this.addHandler(extendableModule);Do you think this makes sense?
Reactions are currently unavailable
Metadata
Metadata
Assignees
Labels
No labels