es-check 9.0.0-0 → 9.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 CHANGED
@@ -20,9 +20,9 @@ Ensuring that JavaScript files can pass ES Check is important in a [modular and
20
20
 
21
21
  ---
22
22
 
23
- ## Version 9 (beta) 🎉
23
+ ## Version 9 🎉
24
24
 
25
- **ES Check** version 9 is a major release update that can enforce actual ES version specific features checks, implements intitial browserslist integration, basic (naive) polyfill detection, and supports an allowlist. To enable ecmaVersion specific checks, pass the `--checkFeatures` flag. To enable browserslist integration, pass the `--checkBrowser` flag. To enable polyfill detection, pass the `--checkForPolyfills` flag. There is also more config file support. Besides this, there are other feature updates based on user feedback. This version should not break any existing scripts. Please report any issues!
25
+ **ES Check** version 9 is a major release update that can enforce more ES version specific features checks, implements initial browserslist integration, basic (naive) polyfill detection, and supports an allowlist. To enable ecmaVersion specific checks, pass the `--checkFeatures` flag. To enable browserslist integration, pass the `--checkBrowser` flag. To enable polyfill detection, pass the `--checkForPolyfills` flag. There is also more config file support. Besides this, there are other feature updates based on user feedback. This version should not break any existing scripts but, as significant changes/features have been added and it's know that es-check supports protecting against breaking errors going to production, a major version bump feels appropriate. Please report any issues!
26
26
 
27
27
  ```sh
28
28
  es-check es6 './dist/**/*.js' --checkFeatures
@@ -141,6 +141,7 @@ Here's a comprehensive list of all available options:
141
141
  | `--ignoreFile <path>` | Path to JSON file containing features to ignore |
142
142
  | `--allowList <features>` | Comma-separated list of features to allow even in lower ES versions, e.g., "const,let" |
143
143
  | `--checkBrowser` | Use browserslist configuration to determine ES version (default: false) |
144
+ | `--browserslistQuery <query>` | Custom browserslist query (e.g., "last 2 versions") |
144
145
  | `--browserslistPath <path>` | Path to custom browserslist configuration (default: uses standard browserslist config resolution) |
145
146
  | `--browserslistEnv <env>` | Browserslist environment to use (default: production) |
146
147
  | `--config <path>` | Path to custom .escheckrc config file |
@@ -198,6 +199,16 @@ es-check es2022 './dist/**/*.js' --checkFeatures --checkForPolyfills
198
199
  es-check --config=./configs/production.escheckrc.json
199
200
  ```
200
201
 
202
+ **Using a custom browserslist query:**
203
+ ```sh
204
+ es-check --checkBrowser --browserslistQuery="last 2 versions" ./dist/**/*.js
205
+ ```
206
+
207
+ **Using browserslist with custom query and feature checking:**
208
+ ```sh
209
+ es-check --checkBrowser --browserslistQuery=">0.5%, not dead" --checkFeatures ./dist/**/*.js
210
+ ```
211
+
201
212
  ---
202
213
 
203
214
  ## Usage
@@ -235,6 +246,7 @@ Here's an example of what an `.escheckrc` file will look like:
235
246
  "ignore": ["ErrorCause", "TopLevelAwait"],
236
247
  "allowList": ["ArrayToSorted", "ObjectHasOwn"],
237
248
  "checkBrowser": false,
249
+ "browserslistQuery": "last 2 versions",
238
250
  "browserslistPath": "./config/.browserslistrc",
239
251
  "browserslistEnv": "production"
240
252
  }
@@ -255,6 +267,7 @@ Here's an example of what an `.escheckrc` file will look like:
255
267
  | `ignore` | Array | Features to ignore when checking |
256
268
  | `allowList` | Array | Features to allow even in lower ES versions |
257
269
  | `checkBrowser` | Boolean | Whether to use browserslist configuration to determine ES version |
270
+ | `browserslistQuery` | String | Custom browserslist query to use |
258
271
  | `browserslistPath` | String | Path to custom browserslist configuration |
259
272
  | `browserslistEnv` | String | Browserslist environment to use |
260
273
 
package/browserslist.js CHANGED
@@ -117,16 +117,17 @@ function getESVersionForBrowser(browser, version) {
117
117
  /**
118
118
  * Determines the minimum ES version required to support all browsers in the browserslist
119
119
  * @param {Object} options - Options object
120
+ * @param {string} [options.browserslistQuery]
120
121
  * @param {string} [options.browserslistPath] - Optional custom path to browserslist config
121
122
  * @param {string} [options.browserslistEnv] - Optional browserslist environment to use
122
123
  * @returns {number} - The ES version to use (e.g., 5, 6, etc.)
123
124
  */
124
125
  function getESVersionFromBrowserslist(options = {}) {
125
- const { browserslistPath, browserslistEnv } = options;
126
+ const { browserslistPath, browserslistEnv, browserslistQuery } = options;
126
127
 
127
128
  try {
128
129
  // Get the browserslist configuration
129
- const browsers = browserslist(null, {
130
+ const browsers = browserslist(browserslistQuery ?? null, {
130
131
  path: browserslistPath,
131
132
  env: browserslistEnv
132
133
  });
package/constants.js CHANGED
@@ -143,6 +143,24 @@ const ES_FEATURES = {
143
143
  callee: 'Promise',
144
144
  },
145
145
  },
146
+ PromiseResolve: {
147
+ minVersion: 6,
148
+ example: 'Promise.resolve(value)',
149
+ astInfo: {
150
+ nodeType: 'CallExpression',
151
+ object: 'Promise',
152
+ property: 'resolve',
153
+ },
154
+ },
155
+ PromiseReject: {
156
+ minVersion: 6,
157
+ example: 'Promise.reject(value)',
158
+ astInfo: {
159
+ nodeType: 'CallExpression',
160
+ object: 'Promise',
161
+ property: 'reject',
162
+ },
163
+ },
146
164
  Symbol: {
147
165
  minVersion: 6,
148
166
  example: 'Symbol("desc")',
package/index.js CHANGED
@@ -51,6 +51,7 @@ program
51
51
  .option('--ignoreFile <path>', 'path to JSON file containing features to ignore')
52
52
  .option('--allowList <features>', 'comma-separated list of features to allow even in lower ES versions, e.g., "const,let"')
53
53
  .option('--checkBrowser', 'use browserslist configuration to determine ES version')
54
+ .option('--browserslistQuery <query>', 'browserslist query')
54
55
  .option('--browserslistPath <path>', 'path to custom browserslist configuration')
55
56
  .option('--browserslistEnv <env>', 'browserslist environment to use')
56
57
  .option('--config <path>', 'path to custom .escheckrc config file')
@@ -140,6 +141,7 @@ program
140
141
  ignoreFile: options.ignoreFile || options['ignore-file'],
141
142
  allowList: options.allowList,
142
143
  checkBrowser: options.checkBrowser,
144
+ browserslistQuery: options.browserslistQuery,
143
145
  browserslistPath: options.browserslistPath,
144
146
  browserslistEnv: options.browserslistEnv
145
147
  };
@@ -217,6 +219,7 @@ async function runChecks(configs, logger) {
217
219
  try {
218
220
  const { getESVersionFromBrowserslist } = require('./browserslist');
219
221
  const esVersionFromBrowserslist = getESVersionFromBrowserslist({
222
+ browserslistQuery: config.browserslistQuery,
220
223
  browserslistPath: config.browserslistPath,
221
224
  browserslistEnv: config.browserslistEnv
222
225
  });
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "es-check",
3
- "version": "9.0.0-0",
3
+ "version": "9.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": "index.js",
6
6
  "license": "MIT",
@@ -23,7 +23,7 @@
23
23
  "pre-commit": "pnpm lint && pnpm test",
24
24
  "prepare": "husky",
25
25
  "prepublishOnly": "pnpm test",
26
- "release": "release-it",
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
29
  "test": "nyc mocha test.js utils.test.js browserslist.test.js polyfill.test.js --timeout 10s",
@@ -103,10 +103,27 @@
103
103
  },
104
104
  "release-it": {
105
105
  "git": {
106
- "commitMessage": "chore: release v${version}"
106
+ "commitMessage": "chore: release v${version}",
107
+ "requireBranch": "main",
108
+ "requireCleanWorkingDir": true
107
109
  },
108
110
  "github": {
109
- "release": true
111
+ "release": true,
112
+ "web": true
113
+ },
114
+ "npm": {
115
+ "publishConfig": {
116
+ "registry": "https://registry.npmjs.org/",
117
+ "access": "public"
118
+ }
119
+ },
120
+ "hooks": {
121
+ "before:init": [
122
+ "pnpm run lint",
123
+ "pnpm test"
124
+ ],
125
+ "after:release": "echo Successfully released ${name} v${version} to ${repo.repository}."
110
126
  }
111
- }
127
+ },
128
+ "packageManager": "pnpm@10.6.5+sha512.cdf928fca20832cd59ec53826492b7dc25dc524d4370b6b4adbf65803d32efaa6c1c88147c0ae4e8d579a6c9eec715757b50d4fa35eea179d868eada4ed043af"
112
129
  }
package/utils.js CHANGED
@@ -141,6 +141,16 @@ const checkMap = {
141
141
  }
142
142
  return false;
143
143
  },
144
+ NewExpression: (node, astInfo) => {
145
+ if (!astInfo.callee) {
146
+ return false;
147
+ }
148
+ // e.g. node.callee.type === 'Identifier' && node.callee.name === 'Promise'
149
+ if (!node.callee || node.callee.type !== 'Identifier') {
150
+ return false;
151
+ }
152
+ return node.callee.name === astInfo.callee;
153
+ },
144
154
  default: () => false
145
155
  };
146
156