es-check 9.1.3-0 → 9.1.3
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/index.js +48 -31
- package/package.json +2 -2
package/index.js
CHANGED
|
@@ -146,6 +146,7 @@ program
|
|
|
146
146
|
}
|
|
147
147
|
|
|
148
148
|
const configs = await loadConfig(options.config);
|
|
149
|
+
const baseConfig = configs[0] || {};
|
|
149
150
|
|
|
150
151
|
if (ecmaVersionArg || filesArg?.length || options.files) {
|
|
151
152
|
const ignoreFilePath = options.ignoreFile || options['ignore-file'];
|
|
@@ -154,24 +155,33 @@ program
|
|
|
154
155
|
logger.warn(`Warning: Ignore file '${ignoreFilePath}' does not exist or is not accessible`);
|
|
155
156
|
}
|
|
156
157
|
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
ecmaVersion: ecmaVersionArg,
|
|
160
|
-
files: filesArg?.length ? filesArg : options.files?.split(','),
|
|
158
|
+
const singleConfig = {
|
|
159
|
+
...baseConfig,
|
|
161
160
|
module: options.module,
|
|
162
161
|
allowHashBang: options.allowHashBang || options['allow-hash-bang'],
|
|
163
|
-
not: options.not?.split(','),
|
|
164
|
-
looseGlobMatching: options.looseGlobMatching || options['loose-glob-matching'],
|
|
165
162
|
checkFeatures: options.checkFeatures,
|
|
166
163
|
checkForPolyfills: options.checkForPolyfills,
|
|
167
|
-
ignore: options.ignore,
|
|
168
|
-
ignoreFile:
|
|
169
|
-
|
|
164
|
+
ignore: options.ignore !== undefined ? options.ignore : baseConfig.ignore,
|
|
165
|
+
ignoreFile: ignoreFilePath !== undefined ? ignoreFilePath : baseConfig.ignoreFile,
|
|
166
|
+
not: options.not ? options.not.split(',').map(n => n.trim()).filter(Boolean) : baseConfig.not,
|
|
167
|
+
looseGlobMatching: options.looseGlobMatching,
|
|
168
|
+
allowList: options.allowList !== undefined ? options.allowList : baseConfig.allowList,
|
|
170
169
|
checkBrowser: options.checkBrowser,
|
|
171
|
-
browserslistQuery: options.browserslistQuery,
|
|
172
|
-
browserslistPath: options.browserslistPath,
|
|
173
|
-
browserslistEnv: options.browserslistEnv
|
|
170
|
+
browserslistQuery: options.browserslistQuery !== undefined ? options.browserslistQuery : baseConfig.browserslistQuery,
|
|
171
|
+
browserslistPath: options.browserslistPath !== undefined ? options.browserslistPath : baseConfig.browserslistPath,
|
|
172
|
+
browserslistEnv: options.browserslistEnv !== undefined ? options.browserslistEnv : baseConfig.browserslistEnv,
|
|
174
173
|
};
|
|
174
|
+
|
|
175
|
+
if (ecmaVersionArg !== undefined) {
|
|
176
|
+
singleConfig.ecmaVersion = ecmaVersionArg;
|
|
177
|
+
}
|
|
178
|
+
// `filesArg` (positional) takes precedence. If not present, use `options.files` (flag). Else, stick with baseConfig.files.
|
|
179
|
+
if (filesArg?.length) {
|
|
180
|
+
singleConfig.files = filesArg;
|
|
181
|
+
} else if (options.files) {
|
|
182
|
+
singleConfig.files = options.files.split(',').map(f => f.trim()).filter(Boolean);
|
|
183
|
+
}
|
|
184
|
+
|
|
175
185
|
return runChecks([singleConfig], logger);
|
|
176
186
|
}
|
|
177
187
|
|
|
@@ -188,7 +198,16 @@ async function runChecks(configs, logger) {
|
|
|
188
198
|
|
|
189
199
|
for (const config of configs) {
|
|
190
200
|
const expectedEcmaVersion = config.ecmaVersion;
|
|
191
|
-
|
|
201
|
+
let patternsToGlob = [];
|
|
202
|
+
const configFilesValue = config.files;
|
|
203
|
+
if (configFilesValue) {
|
|
204
|
+
if (Array.isArray(configFilesValue)) {
|
|
205
|
+
patternsToGlob = configFilesValue.map(p => String(p).trim()).filter(Boolean);
|
|
206
|
+
} else if (typeof configFilesValue === 'string') {
|
|
207
|
+
patternsToGlob = configFilesValue.split(',').map(p => p.trim()).filter(Boolean);
|
|
208
|
+
}
|
|
209
|
+
}
|
|
210
|
+
|
|
192
211
|
const esmodule = config.module;
|
|
193
212
|
const allowHashBang = config.allowHashBang;
|
|
194
213
|
const pathsToIgnore = [].concat(config.not || []);
|
|
@@ -207,29 +226,33 @@ async function runChecks(configs, logger) {
|
|
|
207
226
|
process.exit(1);
|
|
208
227
|
}
|
|
209
228
|
|
|
210
|
-
if (!files.length) {
|
|
211
|
-
logger.error('No files specified in configuration');
|
|
212
|
-
process.exit(1);
|
|
213
|
-
}
|
|
214
|
-
|
|
215
229
|
if (looseGlobMatching && logger.isLevelEnabled('debug')) {
|
|
216
230
|
logger.debug('ES-Check: loose-glob-matching is set');
|
|
217
231
|
}
|
|
218
232
|
|
|
219
233
|
const globOpts = { nodir: true }
|
|
220
|
-
let allMatchedFiles = []
|
|
221
|
-
|
|
234
|
+
let allMatchedFiles = [];
|
|
235
|
+
if (patternsToGlob.length === 0 && !looseGlobMatching) {
|
|
236
|
+
logger.error('ES-Check: No file patterns specified to check.');
|
|
237
|
+
process.exit(1);
|
|
238
|
+
}
|
|
239
|
+
|
|
240
|
+
patternsToGlob.forEach((pattern) => {
|
|
222
241
|
const globbedFiles = glob.sync(pattern, globOpts);
|
|
223
242
|
if (globbedFiles.length === 0 && !looseGlobMatching) {
|
|
224
|
-
logger.error(`ES-Check: Did not find any files to check for ${pattern}.`)
|
|
225
|
-
process.exit(1)
|
|
243
|
+
logger.error(`ES-Check: Did not find any files to check for pattern: ${pattern}.`);
|
|
244
|
+
process.exit(1);
|
|
226
245
|
}
|
|
227
246
|
allMatchedFiles = allMatchedFiles.concat(globbedFiles);
|
|
228
|
-
}
|
|
247
|
+
});
|
|
229
248
|
|
|
230
249
|
if (allMatchedFiles.length === 0) {
|
|
231
|
-
|
|
232
|
-
|
|
250
|
+
if (patternsToGlob.length > 0) {
|
|
251
|
+
logger.error(`ES-Check: Did not find any files to check across all patterns: ${patternsToGlob.join(', ')}.`);
|
|
252
|
+
process.exit(1);
|
|
253
|
+
} else if (looseGlobMatching) {
|
|
254
|
+
logger.warn('ES-Check: No file patterns specified or no files found (running in loose mode).');
|
|
255
|
+
}
|
|
233
256
|
}
|
|
234
257
|
|
|
235
258
|
let ecmaVersion
|
|
@@ -237,12 +260,6 @@ async function runChecks(configs, logger) {
|
|
|
237
260
|
const isBrowserslistCheck = Boolean(expectedEcmaVersion === 'checkBrowser' || checkBrowser);
|
|
238
261
|
if (isBrowserslistCheck) {
|
|
239
262
|
const browserslistQuery = config.browserslistQuery;
|
|
240
|
-
const hasBrowserslistQuery = Boolean(browserslistQuery && browserslistQuery.length > 0);
|
|
241
|
-
if (!hasBrowserslistQuery) {
|
|
242
|
-
const errorMsg = 'When using --checkBrowser, you must also provide a --browserslistQuery.';
|
|
243
|
-
logger.error(errorMsg);
|
|
244
|
-
process.exit(1);
|
|
245
|
-
}
|
|
246
263
|
try {
|
|
247
264
|
const { getESVersionFromBrowserslist } = require('./browserslist');
|
|
248
265
|
const esVersionFromBrowserslist = getESVersionFromBrowserslist({
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "es-check",
|
|
3
|
-
"version": "9.1.3
|
|
3
|
+
"version": "9.1.3",
|
|
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
|
|
29
|
+
"test": "nyc mocha test.js utils.test.js browserslist.test.js polyfillDetector.test.js detectFeatures.test.js --timeout 10s",
|
|
30
30
|
"update": "codependence --update",
|
|
31
31
|
"benchmark": "./benchmarks/run-benchmarks.sh"
|
|
32
32
|
},
|