### Install and Run Development Server Source: https://github.com/yowainwright/es-check/blob/main/site/README.md Install project dependencies and start the development server using pnpm. ```bash pnpm install pnpm dev ``` -------------------------------- ### Example package.json Browserslist Configuration Source: https://github.com/yowainwright/es-check/blob/main/site/src/content/docs/browserslist.mdx An example of the browserslist configuration within a package.json file. ```json { "browserslist": ["last 2 versions", "> 1%", "not dead"] } ``` -------------------------------- ### Example .browserslistrc Configuration Source: https://github.com/yowainwright/es-check/blob/main/site/src/content/docs/browserslist.mdx An example of a .browserslistrc file defining target browsers. ```plaintext # Browsers we support last 2 versions > 1% not dead ``` -------------------------------- ### ES Check Configuration File Example Source: https://github.com/yowainwright/es-check/blob/main/site/src/content/docs/performance.mdx Use a .escheckrc configuration file to manage complex setups, including ECMAScript version, file paths, exclusions, and batch size. This centralizes settings for repeatable builds. ```json // .escheckrc { "ecmaVersion": "es5", "files": ["./dist/**/*.js"], "not": ["./dist/vendor/**"], "batchSize": 50 } ``` -------------------------------- ### Environment-Specific Browserslist Config Example Source: https://github.com/yowainwright/es-check/blob/main/site/src/content/docs/browserslist.mdx Example of environment-specific configurations within a browserslist file. ```plaintext [production] > 0.5% last 2 versions Firefox ESR not dead [development] last 1 chrome version last 1 firefox version ``` -------------------------------- ### Configuration File Example Source: https://github.com/yowainwright/es-check/blob/main/README.md Example of an .escheckrc JSON configuration file, detailing various options for customizing ES Check behavior. ```json { "ecmaVersion": "es6", "module": false, "files": "./dist/**/*.js", "not": ["./dist/skip/*.js"], "allowHashBang": false, "looseGlobMatching": false, "checkFeatures": true, "checkForPolyfills": true, "ignorePolyfillable": "core-js", "ignore": ["ErrorCause", "TopLevelAwait"], "allowList": ["ArrayToSorted", "ObjectHasOwn"], "checkBrowser": false, "browserslistQuery": "last 2 versions", "browserslistPath": "./config/.browserslistrc", "browserslistEnv": "production" } ``` -------------------------------- ### Quick Start: Check Files Against ES5 Source: https://github.com/yowainwright/es-check/blob/main/site/src/content/docs/gettingstarted.mdx Use the quick start command to check if files in specified directories match the ES5 version. ES Check will report any files that do not pass the check. ```bash es-check es5 './vendor/js/*.js' './dist/**/*.js' ``` -------------------------------- ### Install ES Check Globally with yarn Source: https://github.com/yowainwright/es-check/blob/main/site/src/content/docs/installation.mdx Install ES Check globally for system-wide availability using yarn. ```bash yarn global add es-check ``` -------------------------------- ### ES Check Configuration File Example Source: https://github.com/yowainwright/es-check/blob/main/site/src/content/docs/configuration.mdx Create a .escheckrc file in your project root to define consistent settings. ```json { "ecmaVersion": "es6", "module": false, "files": "./dist/**/*.js", "not": ["./dist/skip/*.js"], "allowHashBang": false, "checkFeatures": true } ``` -------------------------------- ### Install ES Check Globally with npm Source: https://github.com/yowainwright/es-check/blob/main/site/src/content/docs/installation.mdx Install ES Check globally for system-wide availability using npm. ```bash npm install -g es-check ``` -------------------------------- ### Example Ignore-Features JSON File Source: https://github.com/yowainwright/es-check/blob/main/site/src/content/docs/options.mdx An example JSON file structure for specifying features to ignore when using the `--ignoreFile` option. ```json ["TopLevelAwait", "ErrorCause", "PrivateClassFields"] ``` -------------------------------- ### CI/CD Integration Example Source: https://github.com/yowainwright/es-check/blob/main/site/src/content/docs/quickstart.mdx Example of how to integrate ES Check into a GitHub Actions workflow to automatically verify JavaScript compatibility on every run. ```yaml # Example GitHub Actions - name: Check ES Version run: npx es-check es5 './dist/**/*.js' ``` -------------------------------- ### Package.json Scripts for CI Source: https://github.com/yowainwright/es-check/blob/main/site/src/content/docs/ci-integration.mdx Example package.json scripts to define build, test, and ES version check commands for CI integration. ```json { "scripts": { "build": "webpack", "test": "jest", "check:es": "es-check es5 './dist/**/*.js'", "ci": "npm run build && npm run test && npm run check:es" } } ``` -------------------------------- ### Install ES Check Globally Source: https://github.com/yowainwright/es-check/blob/main/README.md Install ES Check globally for command-line access on your system. ```sh npm i es-check -g ``` -------------------------------- ### Configuration File Setup Source: https://github.com/yowainwright/es-check/blob/main/site/src/content/docs/quickstart.mdx Configure ES Check using a `.escheckrc` file for persistent settings. This allows you to define the ECMAScript version, target files, and exclusions. ```json { "ecmaVersion": "es5", "files": ["./dist/**/*.js"], "not": ["./dist/modern/**/*.js"] } ``` -------------------------------- ### Install ES Check Locally or Globally Source: https://github.com/yowainwright/es-check/blob/main/site/src/content/docs/gettingstarted.mdx Install ES Check as a development dependency in your project or globally for command-line access. ```bash npm i es-check --save-dev # locally npm i es-check -g # or globally ``` -------------------------------- ### Example: Polyfill Detection Output Source: https://github.com/yowainwright/es-check/blob/main/site/src/content/docs/polyfills.mdx Compare the output of ES Check with and without the `--checkForPolyfills` option to see how polyfill warnings are displayed. ```bash # Without polyfill detection es-check es5 './dist/app.js' # ✓ Passed (but might include polyfills) # With polyfill detection es-check es5 './dist/app.js' --checkForPolyfills # ⚠ Warning: Array.prototype.includes polyfilled (ES7 feature) ``` -------------------------------- ### GitHub Actions with --light Mode Source: https://github.com/yowainwright/es-check/blob/main/site/src/content/docs/ci-integration.mdx Example GitHub Actions step using `--light` mode for faster ES version checks in CI. ```yaml # GitHub Actions with --light mode - name: Fast ES5 compatibility check run: npx es-check es5 './dist/**/*.js' --light ``` -------------------------------- ### ES Check Configuration File (.escheckrc) Source: https://github.com/yowainwright/es-check/blob/main/site/src/content/docs/browserslist.mdx Example of an .escheckrc configuration file specifying checkBrowser, browserslistQuery, browserslistEnv, and files. ```json { "checkBrowser": true, "browserslistQuery": "> 1%, last 2 versions", "browserslistEnv": "production", "files": "./dist/**/*.js" } ``` -------------------------------- ### Verify Global ES Check Installation Source: https://github.com/yowainwright/es-check/blob/main/site/src/content/docs/installation.mdx Verify that ES Check is installed correctly globally by checking its version directly. ```bash es-check --version ``` -------------------------------- ### Verify Local ES Check Installation Source: https://github.com/yowainwright/es-check/blob/main/site/src/content/docs/installation.mdx Verify that ES Check is installed correctly locally by checking its version using npx. ```bash npx es-check --version ``` -------------------------------- ### Configure Batch Processing for Concurrency Source: https://github.com/yowainwright/es-check/blob/main/site/src/content/docs/performance.mdx Examples of using the --batchSize option to control the number of files processed concurrently, including unlimited parallelism. ```bash # Process all files in parallel (default) es-check es5 './dist/**/*.js' --batchSize 0 # Process 10 files at a time es-check es5 './dist/**/*.js' --batchSize 10 # Process 50 files at a time es-check es5 './dist/**/*.js' --batchSize 50 ``` -------------------------------- ### Source Map Version 3 Structure Source: https://github.com/yowainwright/es-check/blob/main/site/src/content/docs/source-maps.mdx Example of the required fields in a Source Map v3 file. ```json { "version": 3, "sources": [...], "mappings": "..." } ``` -------------------------------- ### Install ES Check Locally with npm Source: https://github.com/yowainwright/es-check/blob/main/site/src/content/docs/installation.mdx Install ES Check as a development dependency in your project using npm. This ensures consistent version usage across your team. ```bash npm install es-check --save-dev ``` -------------------------------- ### Basic Usage: Check Files Against ES6 Source: https://github.com/yowainwright/es-check/blob/main/site/src/content/docs/gettingstarted.mdx Perform basic checks on JavaScript files against a specified ECMAScript version. This example checks files in a single directory and multiple directories for ES6 compatibility. ```bash # Check single directory es-check es6 ./js/*.js # Check multiple directories es-check es6 ./js/*.js ./dist/*.js ``` -------------------------------- ### Install ES Check Locally with yarn Source: https://github.com/yowainwright/es-check/blob/main/site/src/content/docs/installation.mdx Install ES Check as a development dependency in your project using yarn. This ensures consistent version usage across your team. ```bash yarn add es-check --dev ``` -------------------------------- ### Check Node Modules with ES Check Source: https://github.com/yowainwright/es-check/blob/main/site/src/content/docs/debugging.mdx Example command to run ES Check on JavaScript files within the node_modules directory, useful for identifying issues in third-party packages. ```bash # Check node_modules es-check es5 './node_modules/problematic-package/dist/*.js' ``` -------------------------------- ### ES Check Success Output Source: https://github.com/yowainwright/es-check/blob/main/site/src/content/docs/quickstart.mdx Example of the output when all JavaScript files pass the ES compatibility check. Indicates successful validation. ```bash ✓ ES Check passed! All files are ES5 compatible. ``` -------------------------------- ### ES Check Command-line Priority Over Config Source: https://github.com/yowainwright/es-check/blob/main/site/src/content/docs/configuration.mdx Command-line arguments override configuration file settings. This example uses 'es6' from the command line, overriding any 'ecmaVersion' in the config file. ```bash es-check es6 --config=.escheckrc ``` -------------------------------- ### GitHub Actions CI Workflow Source: https://github.com/yowainwright/es-check/blob/main/site/src/content/docs/ci-integration.mdx Example GitHub Actions workflow to automate ES version checking on push or pull request events. ```yaml name: ES Version Check on: [push, pull_request] jobs: es-check: runs-on: ubuntu-latest steps: - uses: actions/checkout@v4 - name: Setup Node.js uses: actions/setup-node@v4 with: node-version: "20" - name: Install dependencies run: npm ci - name: Build project run: npm run build - name: Check ES5 compatibility run: npx es-check es5 './dist/**/*.js' ``` -------------------------------- ### ES Check Failure Output Source: https://github.com/yowainwright/es-check/blob/main/site/src/content/docs/quickstart.mdx Example of the output when ES Check detects compatibility issues. Lists the files with violations and the specific ES6 features used. ```bash ✗ ES Check failed! ./dist/app.js - Uses ES6 feature: arrow function (line 10) ./dist/utils.js - Uses ES6 feature: const declaration (line 5) ``` -------------------------------- ### Programmatic API: Run Checks Source: https://github.com/yowainwright/es-check/blob/main/README.md Example of using the ES Check programmatic API in Node.js to run checks with custom configurations. Handles success and error reporting. ```javascript const { runChecks, loadConfig } = require("es-check"); async function checkMyFiles() { const configs = [ { ecmaVersion: "es5", files: ["dist/**/*.js"], module: false, checkFeatures: true, }, ]; const result = await runChecks(configs); if (result.success) { console.log("All files passed ES5 check!"); // Output: All files passed ES5 check! } else { console.error(`ES Check failed with ${result.errors.length} errors`); result.errors.forEach((error) => { console.error(`- ${error.file}: ${error.err.message}`); }); // Example output: // ES Check failed with 2 errors // - dist/app.js: Unsupported features used: const, arrow-functions but your target is ES5. // - dist/utils.js: Unsupported features used: template-literals but your target is ES5. } return result; } ``` -------------------------------- ### Detailed Error Handling with Node API Source: https://github.com/yowainwright/es-check/blob/main/site/src/content/docs/programmatic-api.mdx Programmatically handle errors returned by `runChecks`. This example shows how to iterate through errors, log details, and exit with a non-zero status code if checks fail. ```javascript const { runChecks } = require("es-check"); async function detailedErrorHandling() { const configs = [ { ecmaVersion: "es5", files: ["dist/**/*.js"], }, ]; const result = await runChecks(configs); if (!result.success) { console.error(`ES Check found ${result.errors.length} incompatible files:\n`); result.errors.forEach((error, index) => { console.error(`${index + 1}. File: ${error.file}`); console.error(` Error: ${error.err.message}`); if (process.env.DEBUG) { console.error(` Stack: ${error.stack}`); } }); process.exit(1); } console.log("All files passed ES5 compatibility check!"); } ``` -------------------------------- ### Build and Preview Production Site Source: https://github.com/yowainwright/es-check/blob/main/site/README.md Build the project for production and preview the built site. ```bash pnpm build pnpm preview ``` -------------------------------- ### Load Configuration from File Programmatically Source: https://github.com/yowainwright/es-check/blob/main/site/src/content/docs/programmatic-api.mdx Demonstrates how to use the `loadConfig` function to load ES Check configurations from a file (e.g., `.escheckrc`) and then use these configurations with `runChecks`. ```javascript const { runChecks, loadConfig } = require("es-check"); async function checkWithConfigFile() { // Load config from .escheckrc or custom path const configs = await loadConfig("./.escheckrc"); // Run checks without a logger (silent mode) const result = await runChecks(configs); if (!result.success) { console.error("ES Check failed!"); // Handle errors programmatically return { success: false, errors: result.errors }; } return { success: true }; } ``` -------------------------------- ### Theme Management and Initial Loader Styling Source: https://github.com/yowainwright/es-check/blob/main/site/index.html This snippet demonstrates how to manage theme settings using localStorage and apply styles for an initial loading state. It includes CSS for a spinner animation. ```javascript const theme = localStorage.getItem("theme") || (window.matchMedia("(prefers-color-scheme: dark)").matches ? "dark" : "light"); document.documentElement.setAttribute("data-theme", theme); ``` ```css #root { min-height: 100vh; } .initial-loader { min-height: 100vh; display: flex; align-items: center; justify-content: center; background: var(--fallback-b1, oklch(var(--b1))); } .initial-loader::after { content: ""; width: 2rem; height: 2rem; border: 2px solid transparent; border-top-color: #4486c6; border-radius: 50%; animation: spin 0.6s linear infinite; } @keyframes spin { to { transform: rotate(360deg); } } ``` -------------------------------- ### Multiple Configurations for Different Bundles Source: https://github.com/yowainwright/es-check/blob/main/README.md Use an array of configuration objects to specify different settings for various bundle types like UMD, CJS, and ESM. This allows tailored checks for each module format. ```json [ { "ecmaVersion": "es6", "module": false, "files": "{cjs,umd}/index.{cjs,js}" }, { "ecmaVersion": "es2020", "module": true, "files": "esm/index.mjs", "checkFeatures": true }, { "files": "legacy/*.js", "checkBrowser": true, "browserslistEnv": "legacy" } ] ``` -------------------------------- ### Enable Lightweight Mode Source: https://github.com/yowainwright/es-check/blob/main/site/src/content/docs/options.mdx Utilize the `--light` flag for faster checking by employing pattern matching instead of full AST parsing. This mode is ideal for CI/CD pipelines where performance is critical. ```bash es-check es5 './dist/**/*.js' --light ``` -------------------------------- ### Basic Browserslist Query Source: https://github.com/yowainwright/es-check/blob/main/site/src/content/docs/browserslist.mdx Use the --checkBrowser flag with a specific browserslist query to check ES version compatibility. ```bash es-check --checkBrowser --browserslistQuery="last 2 versions" ./dist/**/*.js ``` -------------------------------- ### Using Project's Browserslist File Source: https://github.com/yowainwright/es-check/blob/main/site/src/content/docs/browserslist.mdx ES Check automatically detects and uses your project's .browserslistrc or package.json browserslist configuration if present. ```bash es-check checkBrowser ./dist/**/*.js ``` -------------------------------- ### Browserslist Environments Source: https://github.com/yowainwright/es-check/blob/main/site/src/content/docs/browserslist.mdx Use the --browserslistEnv flag to specify a particular environment for your browserslist configuration. ```bash es-check --checkBrowser --browserslistEnv="production" ./dist/**/*.js ``` -------------------------------- ### Multiple ES Check Configurations Source: https://github.com/yowainwright/es-check/blob/main/site/src/content/docs/configuration.mdx For projects with different build targets, use an array configuration to specify multiple settings. ```json [ { "ecmaVersion": "es5", "files": "dist/legacy/**/*.js" }, { "ecmaVersion": "es2020", "module": true, "files": "dist/modern/**/*.js" } ] ``` -------------------------------- ### Enable Verbose Mode for ES Check Source: https://github.com/yowainwright/es-check/blob/main/site/src/content/docs/debugging.mdx Use the --verbose flag to get more detailed output from ES Check, aiding in pinpointing issues. ```bash es-check es5 './dist/**/*.js' --verbose ``` -------------------------------- ### Run ES5 Compatibility Checks Programmatically Source: https://github.com/yowainwright/es-check/blob/main/site/src/content/docs/programmatic-api.mdx Demonstrates basic usage of `runChecks` to verify ES5 compatibility for specified files. It shows how to handle the success and error results returned by the function. ```javascript const { runChecks, loadConfig } = require("es-check"); async function checkES5Compatibility() { const configs = [ { ecmaVersion: "es5", files: ["dist/**/*.js"], module: false, checkFeatures: true, }, ]; // Run without a logger (silent mode) const result = await runChecks(configs); if (result.success) { console.log("✅ All files are ES5 compatible!"); } else { console.error(`❌ ES5 compatibility check failed with ${result.errors.length} errors`); result.errors.forEach((error) => { console.error(` - ${error.file}: ${error.err.message}`); }); // Example output: // ES version mismatch detected // dist/legacy/app.js: Unsupported features used: const, let but your target is ES5. // dist/modern/polyfills.js: Unsupported features used: top-level-await but your target is ES2020. return { success: false, errors: result.errors }; } } ``` -------------------------------- ### ES Check Error with Source Maps Source: https://github.com/yowainwright/es-check/blob/main/site/src/content/docs/debugging.mdx Example of an ES Check error message when source maps are enabled, showing original source file locations. ```bash ES-Check Error: ---- · erroring file: src/components/Button.js at src/components/Button.js:10:5 · error: Unexpected token ``` -------------------------------- ### Build and Run ES-Check Benchmarks with Docker Source: https://github.com/yowainwright/es-check/blob/main/tests/benchmarks/README.md Builds a Docker image for the ES-Check benchmarks and then runs the benchmarks within the container. This is the primary method for executing the performance tests. ```bash docker build -t es-check-benchmark -f tests/benchmarks/Dockerfile . docker run --rm es-check-benchmark ``` -------------------------------- ### Use Browserslist with Custom Query and Feature Checking Source: https://github.com/yowainwright/es-check/blob/main/README.md Combine browser compatibility checks with feature checks using a custom browserslist query. ```sh es-check --checkBrowser --browserslistQuery=">0.5%, not dead" --checkFeatures ./dist/**/*.js ``` -------------------------------- ### Run ES Check Performance Benchmarks Source: https://github.com/yowainwright/es-check/blob/main/site/src/content/docs/performance.mdx Commands to clone the ES Check repository and run the performance benchmarks to compare tools and observe improvements. ```bash git clone https://github.com/yowainwright/es-check.git cd es-check node benchmarks/generate-test-files.js 100 ./benchmarks/test-files node benchmarks/compare-tools.js 3 ./benchmarks/test-files ``` -------------------------------- ### CLI Usage with Tab Completion Source: https://github.com/yowainwright/es-check/blob/main/site/src/content/docs/options.mdx Demonstrates how to use tab completion with the es-check CLI to discover available commands, versions, and options after setting up shell completion. ```bash es-check ``` ```bash es-check es6 -- ``` ```bash es-check --check ``` -------------------------------- ### Using a Custom ES Check Config Path Source: https://github.com/yowainwright/es-check/blob/main/site/src/content/docs/configuration.mdx Specify a custom configuration file location using the --config flag. ```bash es-check --config=./config/es-check-production.json ``` -------------------------------- ### Custom ES Compatibility Testing Source: https://github.com/yowainwright/es-check/blob/main/site/src/content/docs/programmatic-api.mdx Incorporate ES compatibility checks into your testing suite. This example shows how to use `runChecks` within a Jest test case to ensure ES5 compliance. ```javascript const { runChecks } = require("es-check"); describe("ES Compatibility", () => { it("should be ES5 compatible", async () => { const configs = [ { ecmaVersion: "es5", files: ["dist/**/*.js"], checkFeatures: true, }, ]; const result = await runChecks(configs); expect(result.success).toBe(true); expect(result.errors).toHaveLength(0); }); }); ``` -------------------------------- ### Configuration Options for ES Check Source: https://github.com/yowainwright/es-check/blob/main/site/src/content/docs/programmatic-api.mdx Lists and explains the available configuration options for ES Check, mirroring the CLI arguments, for use in programmatic checks. ```javascript const config = { ecmaVersion: "es5", // ES version to check against files: ["dist/**/*.js"], // Files to check (array or string) module: false, // Use ES modules allowHashBang: false, // Allow hashbang comments checkFeatures: true, // Check for ES version specific features checkForPolyfills: false, // Consider polyfills when checking not: ["**/vendor/*.js"], // Files/folders to exclude looseGlobMatching: false, // Don't fail if no files found ignore: "ErrorCause,TopLevelAwait", // Features to ignore allowList: "const,let", // Features to allow in lower ES versions batchSize: 0, // Files to process concurrently (0 = unlimited) }; ``` -------------------------------- ### Specify Custom Configuration File Path Source: https://github.com/yowainwright/es-check/blob/main/README.md Use the `--config` command-line option to point to a custom configuration file. This is useful for managing different configurations for various environments or test scenarios. ```sh es-check --config=./configs/my-custom-config.json ``` -------------------------------- ### Set Up Upstream Remote Source: https://github.com/yowainwright/es-check/blob/main/site/src/content/docs/how-to-contribute.mdx Add the original ES Check repository as an upstream remote. This allows you to fetch updates from the main project. ```bash git remote add upstream https://github.com/yowainwright/es-check.git ``` -------------------------------- ### Specify Custom Configuration File Source: https://github.com/yowainwright/es-check/blob/main/site/src/content/docs/options.mdx Use the `--config` option to point to a custom `.escheckrc` configuration file. ```bash es-check --config=./configs/production.escheckrc.json ``` -------------------------------- ### Common Browserslist Query: Mobile First Source: https://github.com/yowainwright/es-check/blob/main/site/src/content/docs/browserslist.mdx A common browserslist query prioritizing mobile browser versions for iOS and Android. ```bash --browserslistQuery="last 2 iOS versions, last 2 Android versions" ``` -------------------------------- ### Run ES Check with Configuration Source: https://github.com/yowainwright/es-check/blob/main/site/src/content/docs/quickstart.mdx Execute ES Check using the settings defined in the `.escheckrc` configuration file. This simplifies command-line usage by omitting explicit arguments. ```bash npx es-check ``` -------------------------------- ### Basic CLI Usage with Array of Arguments Source: https://github.com/yowainwright/es-check/blob/main/README.md Basic command-line usage of es-check specifying an ECMAScript version and multiple file arguments. ```sh es-check es6 ./js/*.js ./dist/*.js ``` -------------------------------- ### Other ES Check Options Source: https://github.com/yowainwright/es-check/blob/main/site/src/content/docs/options.mdx Includes options for loose glob matching, displaying version information (`--version` or `-V`), and showing help messages (`--help` or `-h`). ```bash # Show version information es-check --version # Show help message es-check --help ``` -------------------------------- ### Process Files with Unlimited Batch Size (Default) Source: https://github.com/yowainwright/es-check/blob/main/README.md Process all files in parallel by setting --batchSize to 0. This is the default behavior and is recommended for small codebases to maximize parallelism. ```sh # Process all files in parallel (default) es-check es5 './dist/**/*.js' --batchSize 0 ``` -------------------------------- ### Enable and Disable File Caching Source: https://github.com/yowainwright/es-check/blob/main/site/src/content/docs/performance.mdx Demonstrates how to use ES Check with file caching enabled (default) and how to disable it if necessary. ```bash # Cache is enabled by default es-check es5 './dist/**/*.js' # Disable cache if needed es-check es5 './dist/**/*.js' --noCache ``` -------------------------------- ### esbuild Source Map Configuration Source: https://github.com/yowainwright/es-check/blob/main/site/src/content/docs/source-maps.mdx Use esbuild to bundle and generate source maps for your JavaScript files. ```sh esbuild src/index.js --bundle --sourcemap --outfile=dist/bundle.js ``` -------------------------------- ### Check Browser as ES Version Source: https://github.com/yowainwright/es-check/blob/main/site/src/content/docs/browserslist.mdx Alternatively, use 'checkBrowser' directly as the ES version argument with a browserslist query. ```bash es-check checkBrowser ./dist/**/*.js --browserslistQuery=">0.5%, not dead" ``` -------------------------------- ### Fast Mode for CI/CD Source: https://github.com/yowainwright/es-check/blob/main/site/src/content/docs/quickstart.mdx Enable faster checking in CI/CD pipelines by using the `--light` mode. This mode optimizes performance for automated environments. ```bash npx es-check es5 './dist/**/*.js' --light ``` -------------------------------- ### Check Browser Compatibility using ES Version Argument Source: https://github.com/yowainwright/es-check/blob/main/README.md Use 'checkBrowser' as the ES version argument along with --browserslistQuery to check compatibility against your project's targeted browsers. ```sh es-check checkBrowser --browserslistQuery="last 2 versions" ./dist/**/*.js ``` -------------------------------- ### Progressive Enhancement with Fallbacks Source: https://github.com/yowainwright/es-check/blob/main/site/src/content/docs/debugging.mdx Illustrates a JavaScript pattern for progressive enhancement, providing fallbacks for features like Promises. ```javascript // Instead of failing, provide fallbacks if (typeof Promise !== "undefined") { // Use Promise-based code } else { // Use callback-based code } ``` -------------------------------- ### Check Multiple Directories Source: https://github.com/yowainwright/es-check/blob/main/site/src/content/docs/quickstart.mdx Perform ES5 compatibility checks across multiple directories simultaneously. This is useful for verifying both project-specific and third-party code. ```bash npx es-check es5 './vendor/**/*.js' './dist/**/*.js' ``` -------------------------------- ### Custom Browserslist Config Path Source: https://github.com/yowainwright/es-check/blob/main/site/src/content/docs/browserslist.mdx Specify a custom path to your browserslist configuration file when it's not in the default location. ```bash es-check --checkBrowser --browserslistPath=./config/.browserslistrc ./dist/**/*.js ``` -------------------------------- ### ES Check with Polyfill Detection Source: https://github.com/yowainwright/es-check/blob/main/site/src/content/docs/performance.mdx Command for full compatibility analysis, including syntax checks, feature detection, and polyfill requirements. ```bash es-check es5 './dist/**/*.js' --checkFeatures --checkForPolyfills ``` -------------------------------- ### Run Checks with the Built-in Logger Source: https://github.com/yowainwright/es-check/blob/main/site/src/content/docs/programmatic-api.mdx Demonstrates using ES Check's `createLogger` utility to generate a logger instance with configurable options like verbosity and color output, then passing it to `runChecks`. ```javascript const { runChecks, createLogger } = require("es-check"); async function checkWithBuiltInLogger() { const configs = [ { ecmaVersion: "es5", files: ["dist/**/*.js"], }, ]; // Create a logger with specific settings const logger = createLogger({ verbose: true, // Show debug messages quiet: false, // Show all messages silent: false, // Output to console noColor: false, // Use colors in output }); // Pass the logger in an options object const result = await runChecks(configs, { logger }); if (!result.success) { // Handle errors programmatically return { success: false, errors: result.errors }; } return { success: true }; } ``` -------------------------------- ### Checking Bundled vs. Source Files with ES Check Source: https://github.com/yowainwright/es-check/blob/main/site/src/content/docs/performance.mdx Checking a single bundled file is generally faster than checking many individual source files. This is due to reduced file system operations and overhead. ```bash # Faster - one large file es-check es5 './dist/bundle.min.js' # Slower - many small files es-check es5 './src/**/*.js' ``` -------------------------------- ### CircleCI Configuration Source: https://github.com/yowainwright/es-check/blob/main/site/src/content/docs/ci-integration.mdx CircleCI configuration to set up Node.js environment, build the project, and check ES version compatibility. ```yaml version: 2.1 jobs: es-check: docker: - image: cimg/node:20.0 steps: - checkout - run: npm ci - run: npm run build - run: name: Check ES Version command: npx es-check es5 './dist/**/*.js' ``` -------------------------------- ### Run Benchmarks Source: https://github.com/yowainwright/es-check/blob/main/README.md Execute benchmark tests to compare ES Check's performance against other tools. This helps in understanding performance improvements and variations. ```sh node benchmarks/compare-tools.js 3 ./benchmarks/test-files ``` -------------------------------- ### Common Browserslist Query: Legacy Support Source: https://github.com/yowainwright/es-check/blob/main/site/src/content/docs/browserslist.mdx A common browserslist query including legacy support for Internet Explorer 11. ```bash --browserslistQuery="> 0.25%, not dead, IE 11" ``` -------------------------------- ### Check ES5 Compatibility Source: https://github.com/yowainwright/es-check/blob/main/site/src/content/docs/quickstart.mdx Verify that your bundled JavaScript files conform to the ES5 standard. Specify the target ECMAScript version and the file path pattern. ```bash npx es-check es5 './dist/**/*.js' ``` -------------------------------- ### Configuration File for ES Check Source: https://github.com/yowainwright/es-check/blob/main/site/src/content/docs/gettingstarted.mdx Create a .escheckrc JSON file to define consistent configuration for ES Check, including the target ECMAScript version, files to check, and files to exclude. ```json { "ecmaVersion": "es6", "module": false, "files": "./dist/**/*.js", "not": ["./dist/skip/*.js"], "checkFeatures": true } ``` -------------------------------- ### Efficient Glob Patterns for ES Check Source: https://github.com/yowainwright/es-check/blob/main/site/src/content/docs/performance.mdx Use specific file paths and patterns to improve performance by reducing the scope of file system scanning. Avoid overly broad patterns like './**/*.js' when possible. ```bash # Good - specific patterns es-check es5 './dist/**/*.js' './lib/**/*.js' # Less efficient - overly broad es-check es5 './**/*.js' --not='node_modules' ``` -------------------------------- ### Combine Browser Checking with Feature Checking Source: https://github.com/yowainwright/es-check/blob/main/README.md Use --checkBrowser and --checkFeatures together to ensure both browser compatibility and feature adherence to the determined ES version. ```sh es-check --checkBrowser --checkFeatures ./dist/**/*.js ``` -------------------------------- ### Babel Configuration for Target Browsers Source: https://github.com/yowainwright/es-check/blob/main/site/src/content/docs/debugging.mdx Sets up Babel presets to target modern browsers, including IE 11, for transpilation. ```json { "presets": [ [ "@babel/preset-env", { "targets": { "browsers": ["last 2 versions", "ie >= 11"] } } ] ] } ``` -------------------------------- ### Verify Build Output with grep Source: https://github.com/yowainwright/es-check/blob/main/site/src/content/docs/debugging.mdx Uses grep to search for specific ES6 syntax like arrow functions or let/const declarations in the generated JavaScript files. ```bash # Look at the actual generated code cat ./dist/app.js | grep "=>" # Find arrow functions cat ./dist/app.js | grep "const\|let" # Find ES6 declarations ``` -------------------------------- ### Clone ES Check Repository Source: https://github.com/yowainwright/es-check/blob/main/site/src/content/docs/how-to-contribute.mdx Clone the ES Check repository from GitHub to your local machine. This is the first step after forking the repository. ```bash git clone https://github.com/yowainwright/es-check.git ``` -------------------------------- ### Basic CLI Usage with Globs Source: https://github.com/yowainwright/es-check/blob/main/README.md Basic command-line usage of es-check specifying an ECMAScript version and file globs. ```sh es-check es6 ./js/*.js ``` -------------------------------- ### ES Check Configuration in .escheckrc Source: https://github.com/yowainwright/es-check/blob/main/site/src/content/docs/polyfills.mdx Configure ES Check settings, including polyfill detection options, directly in a `.escheckrc` JSON file for persistent project settings. ```json { "ecmaVersion": "es2017", "files": "./dist/**/*.js", "checkFeatures": true, "checkForPolyfills": true, "ignorePolyfillable": "core-js" } ``` -------------------------------- ### Enable TypeScript Support Source: https://github.com/yowainwright/es-check/blob/main/site/src/content/docs/options.mdx Enable TypeScript file support with the `--typescript` or `--ts` flag. This experimental feature strips type annotations and checks the resulting JavaScript. Runtime support varies by Node.js and Bun versions. ```bash es-check es5 './src/**/*.{js,ts}' --typescript ``` -------------------------------- ### Use Loose Glob Matching Source: https://github.com/yowainwright/es-check/blob/main/README.md Enable loose glob matching to include files that might not strictly adhere to glob patterns. ```sh es-check es5 './dist/**/*.js' './optional/**/*.js' --looseGlobMatching ``` -------------------------------- ### Allow Specific Features Source: https://github.com/yowainwright/es-check/blob/main/site/src/content/docs/features.mdx Use the --allowList flag to permit specific modern features even when targeting older ES versions. This is useful for features that have well-known polyfills or are safe to use. ```bash es-check es5 './dist/**/*.js' --checkFeatures --allowList="const,let" ``` -------------------------------- ### Backward Compatible Usage with Logger Source: https://github.com/yowainwright/es-check/blob/main/site/src/content/docs/programmatic-api.mdx Demonstrates how to use `runChecks` with a logger object passed directly, mimicking CLI behavior where `process.exit()` is called on errors. ```javascript const { runChecks, createLogger } = require("es-check"); async function backwardCompatibleUsage() { const configs = [ { ecmaVersion: "es5", files: ["dist/**/*.js"], }, ]; // Old style: passing logger directly (CLI behavior) const logger = createLogger(); await runChecks(configs, logger); // Will call process.exit(1) on error } ``` -------------------------------- ### Enable Zsh Shell Completion Source: https://github.com/yowainwright/es-check/blob/main/README.md Add the generated zsh completion script to your .zshrc to enable tab completion. ```sh # Add to ~/.zshrc es-check completion zsh > ~/.es-check-completion.zsh echo 'source ~/.es-check-completion.zsh' >> ~/.zshrc ``` -------------------------------- ### Use Files Option Instead of Arguments Source: https://github.com/yowainwright/es-check/blob/main/README.md Specify files to check using the --files flag. Note that using both file arguments and the --files flag is an error. ```sh es-check es6 --files=./dist/main.js,./dist/utils.js ``` -------------------------------- ### Pre-filtering Files with Shell Commands for ES Check Source: https://github.com/yowainwright/es-check/blob/main/site/src/content/docs/performance.mdx Combine shell commands like 'find' with 'xargs' to pre-filter files before passing them to ES Check. This can be more efficient for complex filtering logic than ES Check's built-in options. ```bash # Use shell commands to filter first find ./dist -name "*.js" -not -path "*/vendor/*" | xargs es-check es5 ``` -------------------------------- ### Specify Files with --files Source: https://github.com/yowainwright/es-check/blob/main/site/src/content/docs/options.mdx Use the `--files` option as an alternative to positional arguments for specifying the files to be checked. ```bash es-check es6 --files='./dist/**/*.js' ``` -------------------------------- ### Process Files with Balanced Batch Size Source: https://github.com/yowainwright/es-check/blob/main/README.md Use a balanced --batchSize, like 50, for a mix of speed and memory efficiency, suitable for medium to large codebases. ```sh # Process 50 files at a time (balanced approach) es-check es5 './dist/**/*.js' --batchSize 50 ``` -------------------------------- ### Fastest ES Check Configuration Source: https://github.com/yowainwright/es-check/blob/main/site/src/content/docs/performance.mdx Command for maximum speed, using syntax-only checks, silent output, specific files, and unlimited batch processing. ```bash # Syntax only, silent output, specific files es-check es5 './dist/bundle.min.js' --silent --batchSize 0 ``` -------------------------------- ### Check Node Modules Dependencies Source: https://github.com/yowainwright/es-check/blob/main/README.md Use this command to check the ES compatibility of packages within your node_modules directory. You can specify a single package or use glob patterns for multiple files. ```sh npx es-check es5 ./node_modules/some-package/dist/index.js ``` ```sh npx es-check es5 './node_modules/**/*.js' ``` -------------------------------- ### Ignore Polyfillable Features by Core-JS Source: https://github.com/yowainwright/es-check/blob/main/site/src/content/docs/polyfills.mdx Specify a polyfill provider like 'core-js' with `--ignorePolyfillable=core-js` to only skip features polyfillable by that specific library. ```bash es-check es2017 './dist/**/*.js' --checkFeatures --ignorePolyfillable=core-js ``` -------------------------------- ### Verifying Source Map File Existence Source: https://github.com/yowainwright/es-check/blob/main/site/src/content/docs/source-maps.mdx Check if the source map file (.map) exists alongside the JavaScript file. ```sh ls dist/*.map ``` -------------------------------- ### Babel Source Map Configuration Source: https://github.com/yowainwright/es-check/blob/main/site/src/content/docs/source-maps.mdx Configure Babel to generate source maps for your JavaScript files. ```json { "sourceMaps": true } ``` -------------------------------- ### Check Browser Compatibility Source: https://github.com/yowainwright/es-check/blob/main/README.md Validate JavaScript files against a specified browserslist query using the --browserslistQuery flag. This ensures compatibility with target browsers. ```sh es-check checkBrowser ./dist/**/*.js --browserslistQuery="last 2 versions" ``` -------------------------------- ### ES Check Browser Compatibility Source: https://github.com/yowainwright/es-check/blob/main/site/src/content/docs/performance.mdx Command to check JavaScript compatibility based on browser targets defined in browserslist. ```bash es-check --checkBrowser './dist/**/*.js' ``` -------------------------------- ### Process Files with Limited Batch Size Source: https://github.com/yowainwright/es-check/blob/main/README.md Optimize memory usage in memory-constrained environments by setting a specific --batchSize, such as 10 files at a time. ```sh # Process 10 files at a time (memory-constrained environments) es-check es5 './dist/**/*.js' --batchSize 10 ``` -------------------------------- ### Integrate es-check into Build Script Source: https://github.com/yowainwright/es-check/blob/main/site/src/content/docs/programmatic-api.mdx Run ES compatibility checks as part of your build process. This snippet demonstrates how to use `runChecks` with a configuration for ES5 compatibility. ```javascript const { runChecks } = require("es-check"); async function buildWithESCheck() { // Your build process await buildProject(); // Check ES compatibility const configs = [ { ecmaVersion: "es5", files: ["dist/**/*.js"], checkFeatures: true, }, ]; const result = await runChecks(configs); if (result.success) { console.log("Build successful - ES5 compatible"); } else { console.error("Build failed - ES5 compatibility issues"); console.error(`Found ${result.errors.length} incompatible files`); throw new Error("ES compatibility check failed"); } } ``` -------------------------------- ### Skip Specific Files or Directories Source: https://github.com/yowainwright/es-check/blob/main/README.md Use the --not option to exclude specific files or directories from the check. ```sh es-check es5 './dist/**/*.js' --not=./dist/vendor,./dist/polyfills ``` -------------------------------- ### Webpack Source Map Configuration Source: https://github.com/yowainwright/es-check/blob/main/site/src/content/docs/source-maps.mdx Configure Webpack to generate source maps for bundled code. ```js module.exports = { devtool: "source-map", }; ``` -------------------------------- ### Check Inline Script with ES Check Source: https://github.com/yowainwright/es-check/blob/main/site/src/content/docs/debugging.mdx Command to check the extracted inline script file for ES2015 compatibility. ```bash es-check es2015 './tmp/inline-script.js' ``` -------------------------------- ### Enable Feature Detection Source: https://github.com/yowainwright/es-check/blob/main/site/src/content/docs/features.mdx Use the --checkFeatures flag to enable detection of ECMAScript features. ```bash es-check es5 './dist/**/*.js' --checkFeatures ``` -------------------------------- ### Enable Bash Shell Completion Source: https://github.com/yowainwright/es-check/blob/main/README.md Add the generated bash completion script to your .bashrc or .bash_profile to enable tab completion. ```sh # Add to ~/.bashrc or ~/.bash_profile es-check completion > ~/.es-check-completion.bash echo 'source ~/.es-check-completion.bash' >> ~/.bashrc ``` -------------------------------- ### Run Checks with a Custom Logger Source: https://github.com/yowainwright/es-check/blob/main/site/src/content/docs/programmatic-api.mdx Shows how to integrate ES Check into your application by providing a custom logger object to the `runChecks` function for detailed output during the check process. ```javascript const { runChecks } = require("es-check"); async function checkWithLogger() { const configs = [ { ecmaVersion: "es6", files: ["src/**/*.js"], checkFeatures: true, }, ]; // Custom logger implementation const customLogger = { info: (msg) => console.log("[INFO]", msg), error: (msg) => console.error("[ERROR]", msg), warn: (msg) => console.warn("[WARN]", msg), debug: (msg) => console.debug("[DEBUG]", msg), isLevelEnabled: (level) => true, }; // Pass logger in an options object const result = await runChecks(configs, { logger: customLogger }); if (!result.success) { console.error("Check failed!"); // Handle errors programmatically return { success: false, errors: result.errors }; } return { success: true }; } ``` -------------------------------- ### Travis CI Configuration Source: https://github.com/yowainwright/es-check/blob/main/site/src/content/docs/ci-integration.mdx Travis CI configuration to specify Node.js version and run build and ES version checks. ```yaml language: node_js node_js: - "20" script: - npm run build - npx es-check es5 './dist/**/*.js' ``` -------------------------------- ### Common Browserslist Query: Modern Browsers Source: https://github.com/yowainwright/es-check/blob/main/site/src/content/docs/browserslist.mdx A common browserslist query targeting modern versions of Chrome, Firefox, and Safari. ```bash --browserslistQuery="last 2 chrome versions, last 2 firefox versions, last 2 safari versions" ``` -------------------------------- ### Check for Polyfills in JavaScript Files Source: https://github.com/yowainwright/es-check/blob/main/site/src/content/docs/polyfills.mdx Use the `--checkForPolyfills` flag to detect polyfilled features that might mask ES version incompatibilities in your JavaScript files. ```bash es-check es5 './dist/**/*.js' --checkForPolyfills ``` -------------------------------- ### Basic ES Check Usage Source: https://github.com/yowainwright/es-check/blob/main/site/src/content/docs/options.mdx The fundamental structure for running ES Check, specifying the ECMAScript version, target files, and optional flags. ```bash es-check [files...] [options] ``` -------------------------------- ### Enable ES Modules Parsing Source: https://github.com/yowainwright/es-check/blob/main/site/src/content/docs/options.mdx Use the `--module` flag to enable ES modules parsing mode. This is useful when checking code that utilizes import/export syntax. ```bash es-check es6 './dist/**/*.js' --module ``` -------------------------------- ### TypeScript Source Map Configuration Source: https://github.com/yowainwright/es-check/blob/main/site/src/content/docs/source-maps.mdx Enable source map generation in your TypeScript project. ```json { "compilerOptions": { "sourceMap": true } } ``` -------------------------------- ### GitLab CI Configuration Source: https://github.com/yowainwright/es-check/blob/main/site/src/content/docs/ci-integration.mdx GitLab CI configuration to run ES version checks as part of the test stage. ```yaml es-check: stage: test script: - npm ci - npm run build - npx es-check es5 './dist/**/*.js' only: - merge_requests - main ``` -------------------------------- ### Configure npm Scripts for ES Check Source: https://github.com/yowainwright/es-check/blob/main/site/src/content/docs/installation.mdx Add npm scripts to your package.json to easily run ES Check for different ECMAScript versions and module types against your project's JavaScript files. ```json { "scripts": { "check:es5": "es-check es5 './dist/**/*.js'", "check:es6": "es-check es6 './dist/**/*.js'", "check:es-modules": "es-check es6 './dist/**/*.js' --module" } } ``` -------------------------------- ### Check Browser Compatibility with Browserslist Source: https://github.com/yowainwright/es-check/blob/main/site/src/content/docs/programmatic-api.mdx Ensure your code is compatible with a specific set of browsers defined by a browserslist query. This uses `ecmaVersion: "checkBrowser"` to determine the target ES version. ```javascript const { runChecks } = require("es-check"); async function checkBrowserCompatibility() { const configs = [ { ecmaVersion: "checkBrowser", files: ["dist/**/*.js"], browserslistQuery: "last 2 versions, > 1%", checkFeatures: true, }, ]; const result = await runChecks(configs); if (!result.success) { console.error("Browser compatibility check failed"); // Handle errors programmatically return { success: false, errors: result.errors }; } // Output depends on logger configuration // Silent mode: no output // With logger: "ES-Check: Using ES11 based on browserslist configuration" return { success: true }; } ``` -------------------------------- ### Polyfill Detection Source: https://github.com/yowainwright/es-check/blob/main/site/src/content/docs/features.mdx Use the --checkForPolyfills flag to enable detection of polyfilled features, which helps avoid false positives. Alternatively, use --ignorePolyfillable to ignore all polyfillable features when polyfills are provided externally. ```bash es-check es2022 './dist/**/*.js' --checkFeatures --checkForPolyfills ``` ```bash es-check es2017 './dist/**/*.js' --checkFeatures --ignorePolyfillable=core-js ``` -------------------------------- ### Display Options for ES Check Source: https://github.com/yowainwright/es-check/blob/main/site/src/content/docs/options.mdx Control the output verbosity and appearance with options like `--noColor`, `--verbose` (or `-v`), `--quiet`, and `--silent`. ```bash # Example of verbose output es-check es6 './dist/**/*.js' --verbose ``` -------------------------------- ### ES Check Standard Syntax Check Source: https://github.com/yowainwright/es-check/blob/main/site/src/content/docs/performance.mdx Standard command for syntax-only checking on multiple JavaScript files. ```bash es-check es5 './dist/**/*.js' ``` -------------------------------- ### Basic Error Format from ES Check Source: https://github.com/yowainwright/es-check/blob/main/site/src/content/docs/debugging.mdx Illustrates the standard output format when ES Check encounters a single JavaScript incompatibility. ```bash ✗ ES Check failed! ./dist/app.js - error: Arrow function is not supported in ES5 - line: 42:15 - code: const sum = (a, b) => a + b; ``` -------------------------------- ### ES Check CLI Arguments Source: https://github.com/yowainwright/es-check/blob/main/README.md Detailed arguments for the ES Check CLI, including the range of supported ECMAScript versions and the 'files' glob pattern. ```sh Usage: index [options] [ecmaVersion] [files...] Arguments: ecmaVersion ecmaVersion to check files against. Can be: es3, es4, es5, es6/es2015, es7/es2016, es8/es2017, es9/es2018, es10/es2019, es11/es2020, es12/es2021, es13/es2022, es14/es2023, es15/es2024, es16/es2025 files a glob of files to to test the EcmaScript version against ```