es-check 9.5.4 → 9.6.0-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 +9 -0
- package/lib/check-runner/utils.js +1 -0
- package/lib/cli/constants.js +7 -0
- package/lib/cli/handler.js +1 -0
- package/lib/cli/parser.js +5 -0
- package/lib/helpers/parsers.js +77 -2
- package/package.json +5 -4
package/README.md
CHANGED
|
@@ -132,6 +132,7 @@ Here's a comprehensive list of all available options:
|
|
|
132
132
|
| `-V, --version` | Output the version number |
|
|
133
133
|
| `--module` | Use ES modules (default: false) |
|
|
134
134
|
| `--allowHashBang` | If the code starts with #! treat it as a comment (default: false) |
|
|
135
|
+
| `--typescript, --ts` | Enable TypeScript file support (default: false) |
|
|
135
136
|
| `--files <files>` | A glob of files to test the ECMAScript version against (alias for [files...]) |
|
|
136
137
|
| `--not <files>` | Folder or file names to skip |
|
|
137
138
|
| `--noColor` | Disable use of colors in output (default: false) |
|
|
@@ -167,6 +168,14 @@ es-check es6 './dist/**/*.js' --module
|
|
|
167
168
|
es-check es6 './tests/*.js' --allowHashBang
|
|
168
169
|
```
|
|
169
170
|
|
|
171
|
+
**Checking TypeScript files:**
|
|
172
|
+
|
|
173
|
+
```sh
|
|
174
|
+
es-check es5 './src/**/*.{js,ts}' --typescript
|
|
175
|
+
```
|
|
176
|
+
|
|
177
|
+
This is experimental functionality that strips TypeScript type annotations and tests the resulting JavaScript against the specified ES version.
|
|
178
|
+
|
|
170
179
|
**Skipping specific files or directories:**
|
|
171
180
|
|
|
172
181
|
```sh
|
package/lib/cli/constants.js
CHANGED
|
@@ -133,6 +133,11 @@ const CLI_OPTIONS = [
|
|
|
133
133
|
"lightweight mode: faster checking with pattern matching only (skips full AST parsing)",
|
|
134
134
|
default: false,
|
|
135
135
|
},
|
|
136
|
+
{
|
|
137
|
+
flags: "--typescript, --ts",
|
|
138
|
+
description: "enable TypeScript file support",
|
|
139
|
+
default: false,
|
|
140
|
+
},
|
|
136
141
|
];
|
|
137
142
|
|
|
138
143
|
const SUPPORTED_SHELLS = ["bash", "zsh"];
|
|
@@ -162,6 +167,8 @@ const COMPLETION_OPTIONS = [
|
|
|
162
167
|
"config",
|
|
163
168
|
"batchSize",
|
|
164
169
|
"noCache",
|
|
170
|
+
"typescript",
|
|
171
|
+
"ts",
|
|
165
172
|
];
|
|
166
173
|
|
|
167
174
|
module.exports = {
|
package/lib/cli/handler.js
CHANGED
|
@@ -16,6 +16,7 @@ function buildConfig(ecmaVersionArg, filesArg, options, baseConfig) {
|
|
|
16
16
|
...baseConfig,
|
|
17
17
|
module: options.module,
|
|
18
18
|
allowHashBang: options.allowHashBang || options["allow-hash-bang"],
|
|
19
|
+
typescript: options.typescript || options.ts,
|
|
19
20
|
checkFeatures: options.checkFeatures,
|
|
20
21
|
checkForPolyfills: options.checkForPolyfills,
|
|
21
22
|
ignore: options.ignore !== undefined ? options.ignore : baseConfig.ignore,
|
package/lib/cli/parser.js
CHANGED
|
@@ -2,6 +2,8 @@ const BOOLEAN_FLAGS = new Set([
|
|
|
2
2
|
"module",
|
|
3
3
|
"allowHashBang",
|
|
4
4
|
"allow-hash-bang",
|
|
5
|
+
"typescript",
|
|
6
|
+
"ts",
|
|
5
7
|
"noColor",
|
|
6
8
|
"no-color",
|
|
7
9
|
"verbose",
|
|
@@ -104,6 +106,7 @@ OPTIONS:
|
|
|
104
106
|
--module Use ES modules
|
|
105
107
|
--light Fast checking using pattern matching only
|
|
106
108
|
--allowHashBang Treat #! as comment
|
|
109
|
+
--typescript, -ts Enable TypeScript file support
|
|
107
110
|
--files <files> Files to check (comma-separated)
|
|
108
111
|
--not <files> Files/folders to skip (comma-separated)
|
|
109
112
|
--noColor Disable colors
|
|
@@ -130,6 +133,8 @@ EXAMPLES:
|
|
|
130
133
|
es-check es2020 './build/**/*.js' --checkFeatures
|
|
131
134
|
es-check checkBrowser './dist/*.js' --browserslistQuery="last 2 versions"
|
|
132
135
|
es-check es5 './dist/*.js' --not=./dist/vendor,./dist/legacy
|
|
136
|
+
es-check es5 './src/**/*.{js,ts}' --typescript
|
|
137
|
+
es-check es2020 './src/**/*.ts' --module -ts
|
|
133
138
|
|
|
134
139
|
COMPLETION:
|
|
135
140
|
es-check completion Generate bash completion
|
package/lib/helpers/parsers.js
CHANGED
|
@@ -1,6 +1,76 @@
|
|
|
1
|
-
function
|
|
1
|
+
function detectRuntime() {
|
|
2
|
+
if (typeof Deno !== "undefined") {
|
|
3
|
+
return "deno";
|
|
4
|
+
}
|
|
5
|
+
if (typeof Bun !== "undefined") {
|
|
6
|
+
return "bun";
|
|
7
|
+
}
|
|
8
|
+
return "node";
|
|
9
|
+
}
|
|
10
|
+
|
|
11
|
+
function stripTypesInNode(code) {
|
|
12
|
+
const moduleAPI = require("module");
|
|
13
|
+
if (typeof moduleAPI.stripTypeScriptTypes === "function") {
|
|
14
|
+
return moduleAPI.stripTypeScriptTypes(code, { mode: "strip" });
|
|
15
|
+
}
|
|
16
|
+
throw new Error(
|
|
17
|
+
"es-check execution on TypeScript files requires Node.js v22.13.0+",
|
|
18
|
+
);
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
function stripTypesInBun(code) {
|
|
22
|
+
if (typeof Bun !== "undefined" && typeof Bun.Transpiler !== "undefined") {
|
|
23
|
+
const transpiler = new Bun.Transpiler({ loader: "ts" });
|
|
24
|
+
return transpiler.transformSync(code);
|
|
25
|
+
}
|
|
26
|
+
throw new Error(
|
|
27
|
+
"es-check execution on TypeScript files requires Bun v1.0.0+",
|
|
28
|
+
);
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
function stripTypesInDeno() {
|
|
32
|
+
throw new Error(
|
|
33
|
+
"es-check execution on TypeScript files is not supported in Deno (Deno has native TypeScript support)",
|
|
34
|
+
);
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
function stripTypeScript(code) {
|
|
38
|
+
if (!code || typeof code !== "string") {
|
|
39
|
+
return code;
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
const runtime = detectRuntime();
|
|
43
|
+
|
|
44
|
+
if (runtime === "node") {
|
|
45
|
+
return stripTypesInNode(code);
|
|
46
|
+
}
|
|
47
|
+
|
|
48
|
+
if (runtime === "bun") {
|
|
49
|
+
return stripTypesInBun(code);
|
|
50
|
+
}
|
|
51
|
+
|
|
52
|
+
if (runtime === "deno") {
|
|
53
|
+
return stripTypesInDeno();
|
|
54
|
+
}
|
|
55
|
+
|
|
56
|
+
throw new Error(
|
|
57
|
+
"es-check execution on TypeScript files is not supported in this runtime",
|
|
58
|
+
);
|
|
59
|
+
}
|
|
60
|
+
|
|
61
|
+
function parseCode(code, acornOpts, acorn, file, options = {}) {
|
|
62
|
+
let processedCode = code;
|
|
63
|
+
|
|
64
|
+
const isTypeScriptEnabled = options.typescript || options.ts;
|
|
65
|
+
const isTypeScriptFile =
|
|
66
|
+
file && (file.endsWith(".ts") || file.endsWith(".tsx"));
|
|
67
|
+
|
|
68
|
+
if (isTypeScriptEnabled && isTypeScriptFile) {
|
|
69
|
+
processedCode = stripTypeScript(code);
|
|
70
|
+
}
|
|
71
|
+
|
|
2
72
|
try {
|
|
3
|
-
const ast = acorn.parse(
|
|
73
|
+
const ast = acorn.parse(processedCode, acornOpts);
|
|
4
74
|
return { ast, error: null };
|
|
5
75
|
} catch (err) {
|
|
6
76
|
const hasLocation = err.loc && err.loc.line && err.loc.column;
|
|
@@ -22,4 +92,9 @@ function parseCode(code, acornOpts, acorn, file) {
|
|
|
22
92
|
|
|
23
93
|
module.exports = {
|
|
24
94
|
parseCode,
|
|
95
|
+
stripTypeScript,
|
|
96
|
+
detectRuntime,
|
|
97
|
+
stripTypesInNode,
|
|
98
|
+
stripTypesInBun,
|
|
99
|
+
stripTypesInDeno,
|
|
25
100
|
};
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "es-check",
|
|
3
|
-
"version": "9.
|
|
3
|
+
"version": "9.6.0-0",
|
|
4
4
|
"description": "Checks the ECMAScript version of .js glob against a specified version of ECMAScript with a shell command",
|
|
5
5
|
"main": "lib/index.js",
|
|
6
6
|
"license": "MIT",
|
|
@@ -30,6 +30,7 @@
|
|
|
30
30
|
"report:coverage": "mkdir -p coverage && node --test --experimental-test-coverage --test-reporter=lcov --test-reporter-destination=coverage/lcov.info tests/unit/*.test.js tests/unit/helpers/*.test.js tests/unit/helpers/**/*.test.js tests/unit/constants/*.test.js tests/unit/cli/*.test.js tests/unit/check-runner/*.test.js --test-timeout=10000",
|
|
31
31
|
"test": "node --test tests/unit/*.test.js tests/unit/helpers/*.test.js tests/unit/helpers/**/*.test.js tests/unit/constants/*.test.js tests/unit/cli/*.test.js tests/unit/check-runner/*.test.js --test-timeout=10000 && npm run test:e2e",
|
|
32
32
|
"test:e2e": "npm run test:e2e:cli && npm run test:e2e:esm && npm run test:e2e:package-files && npm run test:e2e:sourcemap",
|
|
33
|
+
"test:e2e:typescript": "tests/e2e/typescript/run-tests.sh",
|
|
33
34
|
"test:e2e:cli": "node tests/e2e/test-cli.js",
|
|
34
35
|
"test:e2e:esm": "node tests/e2e/test-esm-import.mjs",
|
|
35
36
|
"test:e2e:package-files": "node tests/e2e/test-package-files.mjs",
|
|
@@ -52,11 +53,11 @@
|
|
|
52
53
|
"homepage": "https://github.com/yowainwright/es-check#readme",
|
|
53
54
|
"website": "https://jeffry.in/es-check",
|
|
54
55
|
"devDependencies": {
|
|
55
|
-
"codependence": "
|
|
56
|
+
"codependence": "0.3.1",
|
|
56
57
|
"oxlint": "^1.29.0",
|
|
57
58
|
"pastoralist": "1.10.0-1",
|
|
58
|
-
"prettier": "3.
|
|
59
|
-
"release-it": "19.2.
|
|
59
|
+
"prettier": "3.8.1",
|
|
60
|
+
"release-it": "19.2.4"
|
|
60
61
|
},
|
|
61
62
|
"dependencies": {
|
|
62
63
|
"acorn": "8.15.0",
|