es-check 9.1.0 → 9.1.1

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.
Files changed (3) hide show
  1. package/README.md +53 -0
  2. package/index.js +175 -0
  3. package/package.json +3 -2
package/README.md CHANGED
@@ -147,6 +147,43 @@ Here's a comprehensive list of all available options:
147
147
  | `--config <path>` | Path to custom .escheckrc config file |
148
148
  | `-h, --help` | Display help for command |
149
149
 
150
+ ### Shell Completion
151
+
152
+ ES Check supports shell tab completion for commands and options. You can generate completion scripts for bash and zsh shells:
153
+
154
+ ```sh
155
+ # Generate completion script for bash (default)
156
+ es-check completion
157
+
158
+ # Generate completion script for zsh
159
+ es-check completion zsh
160
+ ```
161
+
162
+ To enable completions in your shell:
163
+
164
+ **Bash:**
165
+
166
+ ```sh
167
+ # Add to ~/.bashrc or ~/.bash_profile
168
+ es-check completion > ~/.es-check-completion.bash
169
+ echo 'source ~/.es-check-completion.bash' >> ~/.bashrc
170
+ ```
171
+
172
+ **Zsh:**
173
+
174
+ ```sh
175
+ # Add to ~/.zshrc
176
+ es-check completion zsh > ~/.es-check-completion.zsh
177
+ echo 'source ~/.es-check-completion.zsh' >> ~/.zshrc
178
+ ```
179
+
180
+ Once enabled, you can use tab completion for:
181
+
182
+ - ES versions (es5, es6, etc.)
183
+ - Commands (completion)
184
+ - Options (--module, --checkFeatures, etc.)
185
+ - File paths
186
+
150
187
  #### Examples
151
188
 
152
189
  **Using ES modules:**
@@ -425,6 +462,22 @@ es-check --checkBrowser --checkFeatures ./dist/**/*.js
425
462
 
426
463
  ---
427
464
 
465
+ ## Checking node_modules Dependencies
466
+
467
+ To check node_modules dependencies for ES compatibility:
468
+
469
+ ```sh
470
+ // Check a specific package
471
+ npx es-check es5 ./node_modules/some-package/dist/index.js
472
+
473
+ // Check all JS files in node_modules
474
+ npx es-check es5 './node_modules/**/*.js'
475
+ ```
476
+
477
+ A simple example script is available in `examples/check-node-modules.js`.
478
+
479
+ ---
480
+
428
481
  ## Acknowledgements
429
482
 
430
483
  ES Check is a small utility using powerful tools that [Isaac Z. Schlueter](https://github.com/isaacs), [Marijn Haverbeke](https://github.com/marijnh), and [Matthias Etienne](https://github.com/mattallty) built. [ES Checker](https://github.com/ruanyf/es-checker) by [Ruan YiFeng](https://github.com/ruanyf) checks the JavaScript version supported within a [browser](http://ruanyf.github.io/es-checker/) at run time. ES Check offers similar feedback to ES Checker but at build time and is specific to the product that is using it. ES Check was started after reading this [post](https://philipwalton.com/articles/deploying-es2015-code-in-production-today/) about [deploying es2015 code to production today] by [Philip Walton](https://github.com/philipwalton).
package/index.js CHANGED
@@ -14,6 +14,17 @@ const pkg = require('./package.json')
14
14
  const { lilconfig } = require('lilconfig');
15
15
  const { parseIgnoreList } = require('./utils');
16
16
 
17
+ // Register completion command (hidden from help)
18
+ program.configureOutput({
19
+ writeOut: (str) => process.stdout.write(str),
20
+ writeErr: (str) => process.stderr.write(str),
21
+ outputError: (str, write) => write(str)
22
+ });
23
+
24
+ program.showHelpAfterError();
25
+ program.enablePositionalOptions();
26
+ program.showSuggestionAfterError();
27
+
17
28
  /**
18
29
  * es-check 🏆
19
30
  * ----
@@ -23,6 +34,170 @@ const { parseIgnoreList } = require('./utils');
23
34
  * to to test the EcmaScript version of each file
24
35
  * - error failures
25
36
  */
37
+ // Add completion command
38
+ program
39
+ .command('completion')
40
+ .description('generate shell completion script')
41
+ .argument('[shell]', 'shell type: bash, zsh', 'bash')
42
+ .action((shell) => {
43
+ // Generate completion script for the specified shell
44
+ let completionScript;
45
+
46
+ // Get all available commands and options
47
+ const commands = ['completion'];
48
+ const options = [];
49
+
50
+ // Extract all options from the program
51
+ program.options.forEach(opt => {
52
+ const flag = opt.long || opt.short;
53
+ if (flag) {
54
+ options.push(flag.replace(/^-+/, ''));
55
+ }
56
+ });
57
+
58
+ switch (shell) {
59
+ case 'bash':
60
+ completionScript = generateBashCompletion('es-check', commands, options);
61
+ break;
62
+ case 'zsh':
63
+ completionScript = generateZshCompletion('es-check', commands, options);
64
+ break;
65
+ default:
66
+ console.error(`Shell "${shell}" not supported for completion. Supported shells: bash, zsh`);
67
+ process.exit(1);
68
+ }
69
+
70
+ console.log(completionScript);
71
+ });
72
+
73
+ // Generate bash completion script
74
+ function generateBashCompletion(cmdName, commands, options) {
75
+ const cmdsStr = commands.join(' ');
76
+ const optsStr = options.map(opt => '--' + opt).join(' ');
77
+
78
+ return `
79
+ # es-check bash completion script
80
+ # Install by adding to ~/.bashrc:
81
+ # source /path/to/es-check-completion.bash
82
+
83
+ _es_check_completion() {
84
+ local cur prev opts cmds
85
+ COMPREPLY=()
86
+ cur="\${COMP_WORDS[COMP_CWORD]}"
87
+ prev="\${COMP_WORDS[COMP_CWORD-1]}"
88
+
89
+ # List of commands
90
+ cmds="${cmdsStr}"
91
+
92
+ # List of options
93
+ opts="${optsStr}"
94
+
95
+ # ES versions
96
+ es_versions="es3 es5 es6 es2015 es7 es2016 es8 es2017 es9 es2018 es10 es2019 es11 es2020 es12 es2021 es13 es2022 es14 es2023"
97
+
98
+ # Handle special cases based on previous argument
99
+ case "\$prev" in
100
+ ${cmdName})
101
+ # After the main command, suggest ES versions or commands
102
+ COMPREPLY=( \$(compgen -W "\$es_versions \$cmds \$opts" -- "\$cur") )
103
+ return 0
104
+ ;;
105
+ completion)
106
+ # After 'completion' command, suggest shell types
107
+ COMPREPLY=( \$(compgen -W "bash zsh" -- "\$cur") )
108
+ return 0
109
+ ;;
110
+ *)
111
+ # Default case: suggest options or files
112
+ if [[ "\$cur" == -* ]]; then
113
+ # If current word starts with a dash, suggest options
114
+ COMPREPLY=( \$(compgen -W "\$opts" -- "\$cur") )
115
+ else
116
+ # Otherwise suggest files
117
+ COMPREPLY=( \$(compgen -f -- "\$cur") )
118
+ fi
119
+ return 0
120
+ ;;
121
+ esac
122
+ }
123
+
124
+ complete -F _es_check_completion ${cmdName}
125
+ `;
126
+ }
127
+
128
+ // Generate zsh completion script
129
+ function generateZshCompletion(cmdName, commands, options) {
130
+ const optionsStr = options.map(opt => `"--${opt}[Option description]"`).join('\n ');
131
+ const commandsStr = commands.map(cmd => `"${cmd}:Command description"`).join('\n ');
132
+
133
+ return `
134
+ #compdef ${cmdName}
135
+
136
+ _es_check() {
137
+ local -a commands options es_versions
138
+
139
+ # ES versions
140
+ es_versions=(
141
+ "es3:ECMAScript 3"
142
+ "es5:ECMAScript 5"
143
+ "es6:ECMAScript 2015"
144
+ "es2015:ECMAScript 2015"
145
+ "es7:ECMAScript 2016"
146
+ "es2016:ECMAScript 2016"
147
+ "es8:ECMAScript 2017"
148
+ "es2017:ECMAScript 2017"
149
+ "es9:ECMAScript 2018"
150
+ "es2018:ECMAScript 2018"
151
+ "es10:ECMAScript 2019"
152
+ "es2019:ECMAScript 2019"
153
+ "es11:ECMAScript 2020"
154
+ "es2020:ECMAScript 2020"
155
+ "es12:ECMAScript 2021"
156
+ "es2021:ECMAScript 2021"
157
+ "es13:ECMAScript 2022"
158
+ "es2022:ECMAScript 2022"
159
+ "es14:ECMAScript 2023"
160
+ "es2023:ECMAScript 2023"
161
+ )
162
+
163
+ # Commands
164
+ commands=(
165
+ ${commandsStr}
166
+ )
167
+
168
+ # Options
169
+ options=(
170
+ ${optionsStr}
171
+ )
172
+
173
+ # Handle subcommands
174
+ if (( CURRENT > 2 )); then
175
+ case \${words[2]} in
176
+ completion)
177
+ _arguments "1:shell:(bash zsh)"
178
+ return
179
+ ;;
180
+ esac
181
+ fi
182
+
183
+ # Main completion
184
+ _arguments -C \\
185
+ "1: :{_describe 'command or ES version' es_versions -- commands}" \\
186
+ "*:: :->args"
187
+
188
+ case \$state in
189
+ args)
190
+ _arguments -s : \\
191
+ \$options \\
192
+ "*:file:_files"
193
+ ;;
194
+ esac
195
+ }
196
+
197
+ _es_check
198
+ `;
199
+ }
200
+
26
201
  program
27
202
  .version(pkg.version)
28
203
  .argument(
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "es-check",
3
- "version": "9.1.0",
3
+ "version": "9.1.1",
4
4
  "description": "Checks the ECMAScript version of .js glob against a specified version of ECMAScript with a shell command",
5
5
  "main": "index.js",
6
6
  "license": "MIT",
@@ -26,7 +26,7 @@
26
26
  "release": "release-it --no-git.requireUpstream",
27
27
  "report:coverage": "nyc report --reporter=lcov > coverage.lcov && codecov",
28
28
  "setup": "pnpm install --reporter=silent",
29
- "test": "nyc mocha test.js utils.test.js browserslist.test.js polyfill.test.js --timeout 10s",
29
+ "test": "nyc mocha test.js utils.test.js browserslist.test.js polyfill.test.js completion.test.js --timeout 10s",
30
30
  "update": "codependence --update"
31
31
  },
32
32
  "repository": {
@@ -65,6 +65,7 @@
65
65
  "commander": "13.1.0",
66
66
  "fast-glob": "^3.3.3",
67
67
  "lilconfig": "^3.0.0",
68
+ "source-map": "^0.7.4",
68
69
  "supports-color": "8.1.1",
69
70
  "winston": "3.17.0"
70
71
  },