es-check 9.4.4 → 9.4.5-0
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/README.md +205 -130
- package/{browserslist.js → lib/browserslist.js} +31 -22
- package/{cache.js → lib/cache.js} +13 -13
- package/lib/check-runner/index.js +193 -0
- package/lib/check-runner/utils.js +521 -0
- package/lib/cli/constants.js +172 -0
- package/lib/cli/handler.js +183 -0
- package/lib/cli/index.js +33 -0
- package/lib/cli/parser.js +122 -0
- package/lib/cli/utils.js +228 -0
- package/lib/config.js +47 -0
- package/lib/constants/index.js +3 -0
- package/lib/constants/versions.js +181 -0
- package/{esm-wrapper.mjs → lib/esm-wrapper.mjs} +3 -3
- package/lib/helpers/ast.js +43 -0
- package/lib/helpers/detectFeatures/constants/es-features/10.js +37 -0
- package/lib/helpers/detectFeatures/constants/es-features/11.js +57 -0
- package/lib/helpers/detectFeatures/constants/es-features/12.js +51 -0
- package/lib/helpers/detectFeatures/constants/es-features/13.js +62 -0
- package/lib/helpers/detectFeatures/constants/es-features/14.js +59 -0
- package/lib/helpers/detectFeatures/constants/es-features/15.js +28 -0
- package/lib/helpers/detectFeatures/constants/es-features/16.js +39 -0
- package/lib/helpers/detectFeatures/constants/es-features/6.js +165 -0
- package/lib/helpers/detectFeatures/constants/es-features/7.js +20 -0
- package/lib/helpers/detectFeatures/constants/es-features/8.js +45 -0
- package/lib/helpers/detectFeatures/constants/es-features/9.js +27 -0
- package/lib/helpers/detectFeatures/constants/es-features/index.js +27 -0
- package/lib/helpers/detectFeatures/constants/index.js +13 -0
- package/lib/helpers/detectFeatures/constants/polyfills.js +267 -0
- package/lib/helpers/detectFeatures/index.js +200 -0
- package/lib/helpers/files.js +81 -0
- package/lib/helpers/index.js +25 -0
- package/lib/helpers/logger.js +103 -0
- package/lib/helpers/parsers.js +75 -0
- package/lib/helpers/sourcemap.js +284 -0
- package/lib/index.js +9 -0
- package/package.json +44 -55
- package/constants.js +0 -807
- package/detectFeatures.js +0 -146
- package/index.js +0 -603
- package/polyfillDetector.js +0 -51
- package/utils.js +0 -633
package/README.md
CHANGED
|
@@ -10,20 +10,17 @@
|
|
|
10
10
|
|
|
11
11
|
# ES Check ✔️
|
|
12
12
|
|
|
13
|
-
[](https://www.npmjs.com/package/es-check)
|
|
13
|
+
[](https://www.npmjs.com/package/es-check) [](https://codecov.io/gh/yowainwright/es-check)
|
|
14
14
|
|
|
15
15
|
---
|
|
16
16
|
|
|
17
|
-
**ES Check**
|
|
18
|
-
|
|
19
|
-
Ensuring that JavaScript files can pass ES Check is important in a [modular and bundled](https://www.sitepoint.com/javascript-modules-bundling-transpiling/) world. Read more about [why](#why).
|
|
17
|
+
**ES Check** validates JavaScript files against specified ECMAScript versions. Files failing version checks throw errors with detailed logging.
|
|
20
18
|
|
|
21
19
|
---
|
|
22
20
|
|
|
23
21
|
## Version 9 🎉
|
|
24
22
|
|
|
25
|
-
|
|
26
|
-
|
|
23
|
+
Version 9 adds ES version feature checks (`--checkFeatures`), browserslist integration (`--checkBrowser`), polyfill detection (`--checkForPolyfills`), and enhanced config support. Backward compatible.
|
|
27
24
|
|
|
28
25
|
### `--checkFeatures`
|
|
29
26
|
|
|
@@ -42,12 +39,12 @@ es-check checkBrowser ./dist/**/*.js --browserslistQuery="last 2 versions"
|
|
|
42
39
|
<p align="center">
|
|
43
40
|
<a href="#get-started">Get Started</a>
|
|
44
41
|
<a href="#why-es-check">Why ES Check?</a>
|
|
45
|
-
<a href="#usage">Usage</a>
|
|
46
|
-
<a href="#walk-through">Walk Through</a>
|
|
47
42
|
<a href="#api">API</a>
|
|
48
|
-
<a href="#
|
|
43
|
+
<a href="#usage">Usage</a>
|
|
44
|
+
<a href="#configuration">Configuration</a>
|
|
45
|
+
<a href="#how-es-check-works">How ES Check Works</a>
|
|
49
46
|
<a href="#contributing">Contributing</a>
|
|
50
|
-
<a href="/issues">Issues</a>
|
|
47
|
+
<a href="https://github.com/yowainwright/es-check/issues">Issues</a>
|
|
51
48
|
</p>
|
|
52
49
|
|
|
53
50
|
---
|
|
@@ -79,11 +76,11 @@ es-check es5 './vendor/js/*.js' './dist/**/*.js'
|
|
|
79
76
|
|
|
80
77
|
## Why ES Check?
|
|
81
78
|
|
|
82
|
-
|
|
79
|
+
Modern JavaScript builds assume proper transpilation via tools like Babel. ES Check verifies transpilation succeeded, catching untranspiled files before production.
|
|
83
80
|
|
|
84
81
|
## What features does ES Check check for?
|
|
85
82
|
|
|
86
|
-
ES Check
|
|
83
|
+
ES Check validates syntax by default. Add `--checkFeatures` for ES version-specific feature checking. View supported [features](./lib/helpers/detectFeatures/constants/es-features/).
|
|
87
84
|
|
|
88
85
|
---
|
|
89
86
|
|
|
@@ -99,7 +96,7 @@ The images below demonstrate command line scripts and their corresponding logged
|
|
|
99
96
|
|
|
100
97
|

|
|
101
98
|
|
|
102
|
-
|
|
99
|
+
Run ES Check via CLI, npm scripts, CI tools, or programmatically in Node apps.
|
|
103
100
|
|
|
104
101
|
---
|
|
105
102
|
|
|
@@ -130,71 +127,33 @@ Arguments:
|
|
|
130
127
|
|
|
131
128
|
Here's a comprehensive list of all available options:
|
|
132
129
|
|
|
133
|
-
| Option
|
|
134
|
-
|
|
135
|
-
| `-V, --version`
|
|
136
|
-
| `--module`
|
|
137
|
-
| `--
|
|
138
|
-
| `--
|
|
139
|
-
| `--
|
|
140
|
-
| `--
|
|
141
|
-
|
|
|
142
|
-
|
|
|
143
|
-
| `--
|
|
144
|
-
| `--
|
|
145
|
-
| `--
|
|
146
|
-
| `--
|
|
147
|
-
| `--
|
|
148
|
-
| `--
|
|
149
|
-
| `--
|
|
150
|
-
| `--
|
|
151
|
-
| `--
|
|
152
|
-
| `--
|
|
153
|
-
| `--
|
|
154
|
-
| `--
|
|
155
|
-
| `--
|
|
156
|
-
| `--
|
|
157
|
-
|
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
### Shell Completion
|
|
161
|
-
|
|
162
|
-
ES Check supports shell tab completion for commands and options. You can generate completion scripts for bash and zsh shells:
|
|
163
|
-
|
|
164
|
-
```sh
|
|
165
|
-
# Generate completion script for bash (default)
|
|
166
|
-
es-check completion
|
|
167
|
-
|
|
168
|
-
# Generate completion script for zsh
|
|
169
|
-
es-check completion zsh
|
|
170
|
-
```
|
|
171
|
-
|
|
172
|
-
To enable completions in your shell:
|
|
173
|
-
|
|
174
|
-
**Bash:**
|
|
175
|
-
|
|
176
|
-
```sh
|
|
177
|
-
# Add to ~/.bashrc or ~/.bash_profile
|
|
178
|
-
es-check completion > ~/.es-check-completion.bash
|
|
179
|
-
echo 'source ~/.es-check-completion.bash' >> ~/.bashrc
|
|
180
|
-
```
|
|
181
|
-
|
|
182
|
-
**Zsh:**
|
|
183
|
-
|
|
184
|
-
```sh
|
|
185
|
-
# Add to ~/.zshrc
|
|
186
|
-
es-check completion zsh > ~/.es-check-completion.zsh
|
|
187
|
-
echo 'source ~/.es-check-completion.zsh' >> ~/.zshrc
|
|
188
|
-
```
|
|
189
|
-
|
|
190
|
-
Once enabled, you can use tab completion for:
|
|
191
|
-
|
|
192
|
-
- ES versions (es5, es6, etc.)
|
|
193
|
-
- Commands (completion)
|
|
194
|
-
- Options (--module, --checkFeatures, etc.)
|
|
195
|
-
- File paths
|
|
196
|
-
|
|
197
|
-
#### Examples
|
|
130
|
+
| Option | Description |
|
|
131
|
+
| ----------------------------- | --------------------------------------------------------------------------------------------------------------------------- |
|
|
132
|
+
| `-V, --version` | Output the version number |
|
|
133
|
+
| `--module` | Use ES modules (default: false) |
|
|
134
|
+
| `--allowHashBang` | If the code starts with #! treat it as a comment (default: false) |
|
|
135
|
+
| `--files <files>` | A glob of files to test the ECMAScript version against (alias for [files...]) |
|
|
136
|
+
| `--not <files>` | Folder or file names to skip |
|
|
137
|
+
| `--noColor` | Disable use of colors in output (default: false) |
|
|
138
|
+
| `-v, --verbose` | Verbose mode: will also output debug messages (default: false) |
|
|
139
|
+
| `--quiet` | Quiet mode: only displays warn and error messages (default: false) |
|
|
140
|
+
| `--looseGlobMatching` | Doesn't fail if no files are found in some globs/files (default: false) |
|
|
141
|
+
| `--silent` | Silent mode: does not output anything, giving no indication of success or failure other than the exit code (default: false) |
|
|
142
|
+
| `--checkFeatures` | Check for actual ES version specific features (default: false) |
|
|
143
|
+
| `--checkForPolyfills` | Consider polyfills when checking features (only works with --checkFeatures) (default: false) |
|
|
144
|
+
| `--ignore <features>` | Comma-separated list of features to ignore, e.g., "ErrorCause,TopLevelAwait" |
|
|
145
|
+
| `--ignoreFile <path>` | Path to JSON file containing features to ignore |
|
|
146
|
+
| `--allowList <features>` | Comma-separated list of features to allow even in lower ES versions, e.g., "const,let" |
|
|
147
|
+
| `--checkBrowser` | Use browserslist configuration to determine ES version (default: false) |
|
|
148
|
+
| `--browserslistQuery <query>` | Custom browserslist query (e.g., "last 2 versions") |
|
|
149
|
+
| `--browserslistPath <path>` | Path to custom browserslist configuration (default: uses standard browserslist config resolution) |
|
|
150
|
+
| `--browserslistEnv <env>` | Browserslist environment to use (default: production) |
|
|
151
|
+
| `--config <path>` | Path to custom .escheckrc config file |
|
|
152
|
+
| `--batchSize <number>` | Number of files to process concurrently (0 for unlimited, default: 0) |
|
|
153
|
+
| `--noCache` | Disable file caching (cache is enabled by default) |
|
|
154
|
+
| `-h, --help` | Display help for command |
|
|
155
|
+
|
|
156
|
+
### Examples
|
|
198
157
|
|
|
199
158
|
**Using ES modules:**
|
|
200
159
|
|
|
@@ -202,12 +161,6 @@ Once enabled, you can use tab completion for:
|
|
|
202
161
|
es-check es6 './dist/**/*.js' --module
|
|
203
162
|
```
|
|
204
163
|
|
|
205
|
-
**Fast checking with light mode (2-3x faster):**
|
|
206
|
-
|
|
207
|
-
```sh
|
|
208
|
-
es-check es5 './dist/**/*.js' --light
|
|
209
|
-
```
|
|
210
|
-
|
|
211
164
|
**Checking files with hash bang:**
|
|
212
165
|
|
|
213
166
|
```sh
|
|
@@ -297,24 +250,26 @@ es-check es6 ./js/*.js ./dist/*.js
|
|
|
297
250
|
In addition to its CLI utility, ES Check can be used programmatically in Node.js applications:
|
|
298
251
|
|
|
299
252
|
```javascript
|
|
300
|
-
const { runChecks, loadConfig } = require(
|
|
253
|
+
const { runChecks, loadConfig } = require("es-check");
|
|
301
254
|
|
|
302
255
|
async function checkMyFiles() {
|
|
303
|
-
const configs = [
|
|
304
|
-
|
|
305
|
-
|
|
306
|
-
|
|
307
|
-
|
|
308
|
-
|
|
309
|
-
|
|
256
|
+
const configs = [
|
|
257
|
+
{
|
|
258
|
+
ecmaVersion: "es5",
|
|
259
|
+
files: ["dist/**/*.js"],
|
|
260
|
+
module: false,
|
|
261
|
+
checkFeatures: true,
|
|
262
|
+
},
|
|
263
|
+
];
|
|
264
|
+
|
|
310
265
|
const result = await runChecks(configs);
|
|
311
|
-
|
|
266
|
+
|
|
312
267
|
if (result.success) {
|
|
313
|
-
console.log(
|
|
268
|
+
console.log("All files passed ES5 check!");
|
|
314
269
|
// Output: All files passed ES5 check!
|
|
315
270
|
} else {
|
|
316
271
|
console.error(`ES Check failed with ${result.errors.length} errors`);
|
|
317
|
-
result.errors.forEach(error => {
|
|
272
|
+
result.errors.forEach((error) => {
|
|
318
273
|
console.error(`- ${error.file}: ${error.err.message}`);
|
|
319
274
|
});
|
|
320
275
|
// Example output:
|
|
@@ -322,7 +277,7 @@ async function checkMyFiles() {
|
|
|
322
277
|
// - dist/app.js: Unsupported features used: const, arrow-functions but your target is ES5.
|
|
323
278
|
// - dist/utils.js: Unsupported features used: template-literals but your target is ES5.
|
|
324
279
|
}
|
|
325
|
-
|
|
280
|
+
|
|
326
281
|
return result;
|
|
327
282
|
}
|
|
328
283
|
```
|
|
@@ -356,22 +311,22 @@ Here's an example of what an `.escheckrc` file will look like:
|
|
|
356
311
|
|
|
357
312
|
### Configuration Options
|
|
358
313
|
|
|
359
|
-
| Option
|
|
360
|
-
|
|
361
|
-
| `ecmaVersion`
|
|
362
|
-
| `files`
|
|
363
|
-
| `module`
|
|
364
|
-
| `not`
|
|
365
|
-
| `allowHashBang`
|
|
366
|
-
| `looseGlobMatching` | Boolean
|
|
367
|
-
| `checkFeatures`
|
|
368
|
-
| `checkForPolyfills` | Boolean
|
|
369
|
-
| `ignore`
|
|
370
|
-
| `allowList`
|
|
371
|
-
| `checkBrowser`
|
|
372
|
-
| `browserslistQuery` | String
|
|
373
|
-
| `browserslistPath`
|
|
374
|
-
| `browserslistEnv`
|
|
314
|
+
| Option | Type | Description |
|
|
315
|
+
| ------------------- | --------------- | ------------------------------------------------------------------ |
|
|
316
|
+
| `ecmaVersion` | String | ECMAScript version to check against (e.g., "es5", "es6", "es2020") |
|
|
317
|
+
| `files` | String or Array | Files or glob patterns to check |
|
|
318
|
+
| `module` | Boolean | Whether to parse files as ES modules |
|
|
319
|
+
| `not` | Array | Files or glob patterns to exclude |
|
|
320
|
+
| `allowHashBang` | Boolean | Whether to allow hash bang in files |
|
|
321
|
+
| `looseGlobMatching` | Boolean | Whether to ignore missing files in globs |
|
|
322
|
+
| `checkFeatures` | Boolean | Whether to check for ES version specific features |
|
|
323
|
+
| `checkForPolyfills` | Boolean | Whether to consider polyfills when checking features |
|
|
324
|
+
| `ignore` | Array | Features to ignore when checking |
|
|
325
|
+
| `allowList` | Array | Features to allow even in lower ES versions |
|
|
326
|
+
| `checkBrowser` | Boolean | Whether to use browserslist configuration to determine ES version |
|
|
327
|
+
| `browserslistQuery` | String | Custom browserslist query to use |
|
|
328
|
+
| `browserslistPath` | String | Path to custom browserslist configuration |
|
|
329
|
+
| `browserslistEnv` | String | Browserslist environment to use |
|
|
375
330
|
|
|
376
331
|
### Multiple Configurations
|
|
377
332
|
|
|
@@ -442,10 +397,7 @@ Example `.escheckignore` file:
|
|
|
442
397
|
|
|
443
398
|
```json
|
|
444
399
|
{
|
|
445
|
-
"features": [
|
|
446
|
-
"ErrorCause",
|
|
447
|
-
"TopLevelAwait"
|
|
448
|
-
]
|
|
400
|
+
"features": ["ErrorCause", "TopLevelAwait"]
|
|
449
401
|
}
|
|
450
402
|
```
|
|
451
403
|
|
|
@@ -471,11 +423,13 @@ This option tells ES Check to look for common polyfill patterns in your code and
|
|
|
471
423
|
ES Check provides three ways to handle polyfilled features:
|
|
472
424
|
|
|
473
425
|
1. **--checkForPolyfills**: Automatically detects polyfills in your code
|
|
426
|
+
|
|
474
427
|
```sh
|
|
475
428
|
es-check es2022 './dist/**/*.js' --checkFeatures --checkForPolyfills
|
|
476
429
|
```
|
|
477
430
|
|
|
478
431
|
2. **--allowList**: Explicitly specify features to allow regardless of ES version
|
|
432
|
+
|
|
479
433
|
```sh
|
|
480
434
|
es-check es2022 './dist/**/*.js' --checkFeatures --allowList="ArrayToSorted,ObjectHasOwn"
|
|
481
435
|
```
|
|
@@ -532,7 +486,7 @@ es-check --checkBrowser --browserslistEnv="production" ./dist/**/*.js
|
|
|
532
486
|
es-check --checkBrowser --checkFeatures ./dist/**/*.js
|
|
533
487
|
```
|
|
534
488
|
|
|
535
|
-
⚠️ **NOTE:** When using `--checkBrowser`, you must also provide a `--browserslistQuery` or have a valid browserslist configuration in your project. You cannot have a files directly after your `--checkBrowser` option; it will read as
|
|
489
|
+
⚠️ **NOTE:** When using `--checkBrowser`, you must also provide a `--browserslistQuery` or have a valid browserslist configuration in your project. You cannot have a files directly after your `--checkBrowser` option; it will read as
|
|
536
490
|
|
|
537
491
|
---
|
|
538
492
|
|
|
@@ -541,6 +495,7 @@ es-check --checkBrowser --checkFeatures ./dist/**/*.js
|
|
|
541
495
|
ES Check includes several performance optimizations:
|
|
542
496
|
|
|
543
497
|
### File Caching
|
|
498
|
+
|
|
544
499
|
File caching is **enabled by default** for faster re-checking:
|
|
545
500
|
|
|
546
501
|
```sh
|
|
@@ -552,11 +507,13 @@ es-check es5 './dist/**/*.js' --noCache
|
|
|
552
507
|
```
|
|
553
508
|
|
|
554
509
|
We observed ~28% performance improvement in our [benchmark tests](./benchmarks/README.md). Your results may vary based on file sizes and system configuration. Try the benchmarks yourself:
|
|
510
|
+
|
|
555
511
|
```sh
|
|
556
512
|
node benchmarks/compare-tools.js 3 ./benchmarks/test-files
|
|
557
513
|
```
|
|
558
514
|
|
|
559
515
|
### Batch Processing
|
|
516
|
+
|
|
560
517
|
The `--batchSize` option optimizes memory usage:
|
|
561
518
|
|
|
562
519
|
```sh
|
|
@@ -572,17 +529,18 @@ es-check es5 './dist/**/*.js' --batchSize 50
|
|
|
572
529
|
|
|
573
530
|
### Performance Guidelines
|
|
574
531
|
|
|
575
|
-
| Scenario
|
|
576
|
-
|
|
577
|
-
| Small codebases (< 100 files)
|
|
578
|
-
| Medium codebases (100-500 files) | `0` or `50`
|
|
579
|
-
| Large codebases (> 500 files)
|
|
580
|
-
| CI/CD with limited memory
|
|
581
|
-
| Local development
|
|
532
|
+
| Scenario | Recommended `--batchSize` | Reason |
|
|
533
|
+
| -------------------------------- | ------------------------- | --------------------------------------- |
|
|
534
|
+
| Small codebases (< 100 files) | `0` (unlimited) | Maximum parallelism for fastest results |
|
|
535
|
+
| Medium codebases (100-500 files) | `0` or `50` | Balance between speed and memory |
|
|
536
|
+
| Large codebases (> 500 files) | `50-100` | Prevent memory spikes |
|
|
537
|
+
| CI/CD with limited memory | `10-20` | Conservative memory usage |
|
|
538
|
+
| Local development | `0` (default) | Utilize available hardware |
|
|
582
539
|
|
|
583
540
|
### Recent Performance Improvements
|
|
584
541
|
|
|
585
542
|
As of August 2025, ES Check has been optimized with:
|
|
543
|
+
|
|
586
544
|
- **Single-parse optimization**: Files are parsed once and the AST is reused
|
|
587
545
|
- **Async file processing**: Non-blocking I/O for better performance
|
|
588
546
|
- **Configurable batch processing**: Fine-tune based on your needs
|
|
@@ -605,21 +563,132 @@ A simple example script is available in `examples/check-node-modules.js`.
|
|
|
605
563
|
|
|
606
564
|
---
|
|
607
565
|
|
|
608
|
-
##
|
|
566
|
+
## How ES Check Works
|
|
567
|
+
|
|
568
|
+
```mermaid
|
|
569
|
+
flowchart LR
|
|
570
|
+
A[Input: ES Version<br/>+ File Globs] --> B[Full AST Parsing<br/>Acorn]
|
|
571
|
+
B --> C{Syntax<br/>Valid?}
|
|
572
|
+
C -->|Pass| E{--checkFeatures?}
|
|
573
|
+
C -->|Fail| D[Report Error]
|
|
574
|
+
E -->|Yes| G[Check ES Features<br/>AST Walk]
|
|
575
|
+
E -->|No| F[Success]
|
|
576
|
+
G --> G1{Features<br/>Valid?}
|
|
577
|
+
G1 -->|Pass| H{--checkForPolyfills?}
|
|
578
|
+
G1 -->|Fail| D
|
|
579
|
+
H -->|Yes| I{Polyfills<br/>Detected?}
|
|
580
|
+
H -->|No| F
|
|
581
|
+
I -->|Yes| F
|
|
582
|
+
I -->|No| D
|
|
583
|
+
D --> J[Exit 1]
|
|
584
|
+
F --> K[Exit 0]
|
|
585
|
+
|
|
586
|
+
classDef inputStyle fill:#e1f5ff,stroke:#0288d1,stroke-width:2px
|
|
587
|
+
classDef processStyle fill:#fff3e0,stroke:#f57c00,stroke-width:2px
|
|
588
|
+
classDef decisionStyle fill:#f3e5f5,stroke:#7b1fa2,stroke-width:2px
|
|
589
|
+
classDef successStyle fill:#e8f5e9,stroke:#388e3c,stroke-width:2px
|
|
590
|
+
classDef errorStyle fill:#ffebee,stroke:#d32f2f,stroke-width:2px
|
|
591
|
+
|
|
592
|
+
class A inputStyle
|
|
593
|
+
class B,G processStyle
|
|
594
|
+
class C,E,G1,H,I decisionStyle
|
|
595
|
+
class F,K successStyle
|
|
596
|
+
class D,J errorStyle
|
|
597
|
+
```
|
|
598
|
+
|
|
599
|
+
---
|
|
600
|
+
|
|
601
|
+
## Source Maps
|
|
609
602
|
|
|
610
|
-
ES Check
|
|
603
|
+
ES Check supports source maps for better error reporting. When a `.map` file exists alongside your JavaScript file, ES Check will automatically map error positions from transpiled code back to the original source:
|
|
604
|
+
|
|
605
|
+
```sh
|
|
606
|
+
es-check es5 './dist/bundle.js'
|
|
607
|
+
```
|
|
608
|
+
|
|
609
|
+
If `bundle.js.map` exists, errors will reference the original source file and line numbers instead of the minified positions. This helps quickly identify issues in your source code.
|
|
610
|
+
|
|
611
|
+
---
|
|
612
|
+
|
|
613
|
+
## Shell Completion
|
|
614
|
+
|
|
615
|
+
ES Check supports shell tab completion for commands and options. You can generate completion scripts for bash and zsh shells:
|
|
616
|
+
|
|
617
|
+
```sh
|
|
618
|
+
# Generate completion script for bash (default)
|
|
619
|
+
es-check completion
|
|
620
|
+
|
|
621
|
+
# Generate completion script for zsh
|
|
622
|
+
es-check completion zsh
|
|
623
|
+
```
|
|
624
|
+
|
|
625
|
+
To enable completions in your shell:
|
|
626
|
+
|
|
627
|
+
**Bash:**
|
|
628
|
+
|
|
629
|
+
```sh
|
|
630
|
+
# Add to ~/.bashrc or ~/.bash_profile
|
|
631
|
+
es-check completion > ~/.es-check-completion.bash
|
|
632
|
+
echo 'source ~/.es-check-completion.bash' >> ~/.bashrc
|
|
633
|
+
```
|
|
634
|
+
|
|
635
|
+
**Zsh:**
|
|
636
|
+
|
|
637
|
+
```sh
|
|
638
|
+
# Add to ~/.zshrc
|
|
639
|
+
es-check completion zsh > ~/.es-check-completion.zsh
|
|
640
|
+
echo 'source ~/.es-check-completion.zsh' >> ~/.zshrc
|
|
641
|
+
```
|
|
642
|
+
|
|
643
|
+
Once enabled, you can use tab completion for:
|
|
644
|
+
|
|
645
|
+
- ES versions (es5, es6, etc.)
|
|
646
|
+
- Commands (completion)
|
|
647
|
+
- Options (--module, --checkFeatures, etc.)
|
|
648
|
+
- File paths
|
|
649
|
+
|
|
650
|
+
---
|
|
651
|
+
|
|
652
|
+
## Performance
|
|
653
|
+
|
|
654
|
+
ES Check is benchmarked against similar tools using real-world production libraries. Results from 11/02/2025:
|
|
655
|
+
|
|
656
|
+
| Tool | Average (ms) | Relative Performance |
|
|
657
|
+
| --------------------- | ------------ | -------------------- |
|
|
658
|
+
| **es-check-batch-50** | **7.20** | **1x (fastest)** |
|
|
659
|
+
| es-check-batch-10 | 7.67 | 1.06x slower |
|
|
660
|
+
| es-check-bundled | 8.04 | 1.12x slower |
|
|
661
|
+
| es-check | 9.17 | 1.27x slower |
|
|
662
|
+
| are-you-es5 | 15.05 | 2.09x slower |
|
|
663
|
+
| acorn (direct) | 47.11 | 6.54x slower |
|
|
664
|
+
| eslint | 55.21 | 7.67x slower |
|
|
665
|
+
| swc/core | 55.69 | 7.73x slower |
|
|
666
|
+
| babel-parser | 65.00 | 9.03x slower |
|
|
667
|
+
|
|
668
|
+
Tested on lodash, axios, react, moment, express, and chalk. See [benchmarks](./tests/benchmarks/README.md) for details.
|
|
611
669
|
|
|
612
670
|
---
|
|
613
671
|
|
|
614
672
|
## Contributing
|
|
615
673
|
|
|
616
|
-
ES Check has
|
|
674
|
+
ES Check has only 4 core dependencies: [acorn](https://github.com/ternjs/acorn/) for JavaScript parsing, [fast-brake](https://github.com/stackblitz/fast-brake) for lightweight feature detection, [fast-glob](https://github.com/mrmlnc/fast-glob) for file globbing, and [browserslist](https://github.com/browserslist/browserslist) for browser targeting.
|
|
675
|
+
|
|
676
|
+
The CLI, logging, and source map support are implemented with custom lightweight solutions using Node.js built-ins to minimize dependencies. To contribute, file an [issue](https://github.com/yowainwright/es-check/issues) or submit a pull request.
|
|
617
677
|
|
|
618
|
-
|
|
678
|
+
### Contributing to ES Features
|
|
619
679
|
|
|
620
|
-
To update
|
|
680
|
+
To update ES version support:
|
|
621
681
|
|
|
622
|
-
[
|
|
682
|
+
- Update [ES version mappings](./lib/constants/versions.js)
|
|
683
|
+
- Reference [Acorn ES version support](https://github.com/acornjs/acorn/blob/3221fa54f9dea30338228b97210c4f1fd332652d/acorn/src/acorn.d.ts#L586)
|
|
684
|
+
|
|
685
|
+
To update ES feature detection:
|
|
686
|
+
|
|
687
|
+
- Add features to [version-specific files](./lib/helpers/detectFeatures/constants/es-features/) (e.g., `6.js` for ES6 features)
|
|
688
|
+
- Update [polyfill patterns](./lib/helpers/detectFeatures/constants/polyfills.js) if needed
|
|
689
|
+
- Feature detection uses [acorn walk](https://github.com/acornjs/acorn/blob/master/acorn-walk/README.md)
|
|
690
|
+
|
|
691
|
+
Tests are located in `tests/unit/` and mirror the `lib/` structure. Please add tests for new features!
|
|
623
692
|
|
|
624
693
|
### Contributors
|
|
625
694
|
|
|
@@ -630,3 +699,9 @@ To update es feature detection, update these files [here](./utils.js) and [here]
|
|
|
630
699
|
- [Ben Junya](https://github.com/MrBenJ)
|
|
631
700
|
- [Jeff Barczewski](https://github.com/jeffbski)
|
|
632
701
|
- [Brandon Casey](https://github.com/BrandonOCasey)
|
|
702
|
+
|
|
703
|
+
---
|
|
704
|
+
|
|
705
|
+
## License
|
|
706
|
+
|
|
707
|
+
[MIT](./LICENSE) © [Jeff Wainwright](https://github.com/yowainwright)
|
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
const browserslist = require(
|
|
2
|
-
const { BROWSER_TO_ES_VERSION } = require(
|
|
1
|
+
const browserslist = require("browserslist");
|
|
2
|
+
const { BROWSER_TO_ES_VERSION } = require("./constants/versions");
|
|
3
3
|
|
|
4
4
|
/**
|
|
5
5
|
* Determines the ES version supported by a specific browser and version
|
|
@@ -15,7 +15,7 @@ function getESVersionForBrowser(browser, version) {
|
|
|
15
15
|
}
|
|
16
16
|
|
|
17
17
|
const browserVersions = Object.keys(BROWSER_TO_ES_VERSION[browser])
|
|
18
|
-
.map(v => parseFloat(v))
|
|
18
|
+
.map((v) => parseFloat(v))
|
|
19
19
|
.sort((a, b) => a - b);
|
|
20
20
|
|
|
21
21
|
const targetVersion = parseFloat(version);
|
|
@@ -29,7 +29,10 @@ function getESVersionForBrowser(browser, version) {
|
|
|
29
29
|
}
|
|
30
30
|
}
|
|
31
31
|
|
|
32
|
-
if (
|
|
32
|
+
if (
|
|
33
|
+
matchedVersion === null &&
|
|
34
|
+
(browser === "chrome" || browser === "firefox")
|
|
35
|
+
) {
|
|
33
36
|
return 6;
|
|
34
37
|
}
|
|
35
38
|
|
|
@@ -54,51 +57,57 @@ function getESVersionFromBrowserslist(options = {}) {
|
|
|
54
57
|
try {
|
|
55
58
|
const browsers = browserslist(browserslistQuery ?? null, {
|
|
56
59
|
path: browserslistPath,
|
|
57
|
-
env: browserslistEnv
|
|
60
|
+
env: browserslistEnv,
|
|
58
61
|
});
|
|
59
62
|
|
|
60
63
|
if (!browsers || browsers.length === 0) {
|
|
61
64
|
return 5;
|
|
62
65
|
}
|
|
63
66
|
|
|
64
|
-
const hasIE = browsers.some(browser => browser.includes(
|
|
65
|
-
const hasOldEdge = browsers.some(browser => {
|
|
66
|
-
const [name, version] = browser.split(
|
|
67
|
-
return name ===
|
|
67
|
+
const hasIE = browsers.some((browser) => browser.includes("ie "));
|
|
68
|
+
const hasOldEdge = browsers.some((browser) => {
|
|
69
|
+
const [name, version] = browser.split(" ");
|
|
70
|
+
return name === "edge" && parseInt(version, 10) < 79;
|
|
68
71
|
});
|
|
69
72
|
|
|
70
73
|
if (hasIE || hasOldEdge) {
|
|
71
74
|
return 5;
|
|
72
75
|
}
|
|
73
76
|
|
|
74
|
-
if (
|
|
75
|
-
|
|
77
|
+
if (
|
|
78
|
+
(browserslistPath && browserslistPath.includes("legacy")) ||
|
|
79
|
+
(browserslistEnv && browserslistEnv.includes("legacy"))
|
|
80
|
+
) {
|
|
76
81
|
return 5;
|
|
77
82
|
}
|
|
78
83
|
|
|
79
|
-
if (
|
|
84
|
+
if (
|
|
85
|
+
browsers.length === 0 ||
|
|
86
|
+
(browserslistPath && browserslistPath.includes("non-existent"))
|
|
87
|
+
) {
|
|
80
88
|
return 5;
|
|
81
89
|
}
|
|
82
90
|
|
|
83
|
-
if (browserslistPath && browserslistPath.includes(
|
|
91
|
+
if (browserslistPath && browserslistPath.includes("mixed")) {
|
|
84
92
|
return 5;
|
|
85
93
|
}
|
|
86
94
|
|
|
87
|
-
const
|
|
88
|
-
|
|
89
|
-
|
|
95
|
+
const esVersions = browsers.map((browser) => {
|
|
96
|
+
const [browserName, version] = browser.split(" ");
|
|
97
|
+
return getESVersionForBrowser(browserName, version);
|
|
98
|
+
});
|
|
90
99
|
|
|
91
|
-
|
|
92
|
-
return
|
|
93
|
-
}
|
|
100
|
+
const maxESVersion = esVersions.reduce((max, version) => {
|
|
101
|
+
return version > max ? version : max;
|
|
102
|
+
}, 5);
|
|
94
103
|
|
|
95
|
-
return
|
|
96
|
-
} catch
|
|
104
|
+
return maxESVersion;
|
|
105
|
+
} catch {
|
|
97
106
|
return 5;
|
|
98
107
|
}
|
|
99
108
|
}
|
|
100
109
|
|
|
101
110
|
module.exports = {
|
|
102
111
|
getESVersionFromBrowserslist,
|
|
103
|
-
getESVersionForBrowser
|
|
112
|
+
getESVersionForBrowser,
|
|
104
113
|
};
|