yargs-file-commands 0.0.14 → 0.0.15

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/CHANGELOG.md CHANGED
@@ -1,5 +1,16 @@
1
1
  # yargs-file-commands
2
2
 
3
+ ## 0.0.15
4
+
5
+ ### Patch Changes
6
+
7
+ - Throw if a command exports unrecognized names, catches a lot of bugs.
8
+ - More explicit exceptions when bad parameters are passed in
9
+ - Validate that provided command directories are aboslute
10
+ - More robust parameter checking and logging
11
+ - Improved debugging logging
12
+ - More robust debug messages
13
+
3
14
  ## 0.0.14
4
15
 
5
16
  ### Patch Changes
@@ -29,6 +29,18 @@ export const importCommandFromFile = async (filePath, name, options) => {
29
29
  // null implementation
30
30
  })
31
31
  };
32
+ const supportedNames = [
33
+ 'describe',
34
+ 'alias',
35
+ 'builder',
36
+ 'deprecated',
37
+ 'handler'
38
+ ];
39
+ const module = handlerModule;
40
+ const unsupportedExports = Object.keys(module).filter((key) => !supportedNames.includes(key));
41
+ if (unsupportedExports.length > 0) {
42
+ throw new Error(`Command module ${name} in ${filePath} has some unsupported exports, probably a misspelling: ${unsupportedExports.join(', ')}`);
43
+ }
32
44
  if (logLevel === 'debug') {
33
45
  console.debug('Importing command from', filePath, 'as', name, 'with description', command.describe);
34
46
  }
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "yargs-file-commands",
3
3
  "description": "A yargs helper function that lets you define your commands structure via directory and file naming conventions.",
4
- "version": "0.0.14",
4
+ "version": "0.0.15",
5
5
  "type": "module",
6
6
  "main": "dist/index.js",
7
7
  "types": "dist/index.d.ts",
@@ -108,6 +108,25 @@ export const importCommandFromFile = async (
108
108
  })
109
109
  } as CommandModule;
110
110
 
111
+ const supportedNames = [
112
+ 'describe',
113
+ 'alias',
114
+ 'builder',
115
+ 'deprecated',
116
+ 'handler'
117
+ ];
118
+ const module = handlerModule as Record<string, any>;
119
+ const unsupportedExports = Object.keys(module).filter(
120
+ (key) => !supportedNames.includes(key)
121
+ );
122
+ if (unsupportedExports.length > 0) {
123
+ throw new Error(
124
+ `Command module ${name} in ${filePath} has some unsupported exports, probably a misspelling: ${unsupportedExports.join(
125
+ ', '
126
+ )}`
127
+ );
128
+ }
129
+
111
130
  if (logLevel === 'debug') {
112
131
  console.debug(
113
132
  'Importing command from',
@@ -118,5 +137,6 @@ export const importCommandFromFile = async (
118
137
  command.describe
119
138
  );
120
139
  }
140
+
121
141
  return command;
122
142
  };