Use globals with ESLint 9+
mainglobals directly in your ESLint configuration under languageOptions.globals.repository·main·Indexed 20 days ago
https://github.com/sindresorhus/globalsA JSON-based mapping of global identifiers for different JavaScript environments, such as browser and Node.js. It provides boolean mappings to indicate if a variable is read-only or may be overwritten, primarily for use by static analysis tools like ESLint to determine available global variables.
globals directly in your ESLint configuration under languageOptions.globals.Install the globals package using npm to access global identifiers from various JavaScript environments.
npm install globalsTo start the project in debug mode with file watching enabled, run the following command using Node.js:
node --watch start.mjsImport the globals package to access environment-specific global variables. Each global identifier is mapped to a boolean value:
true: The variable may be overwritten.false: The variable is read-only.This boolean mapping is designed for static analysis tools to identify incorrect behavior.
import globals from 'globals';
console.log(globals.browser);
/*
{
addEventListener: false,
applicationCache: false,
ArrayBuffer: false,
atob: false,
…
}
*/The package provides two distinct sets of globals for Node.js environments:
globals.nodeBuiltin: Globals available to all code running in Node.js (typically properties on globalThis, such as process and Buffer). It does not include CommonJS arguments like require.globals.node: A combination of nodeBuiltin plus all CommonJS arguments (the "CommonJS module scope"), such as require, module, and exports.Tip: When analyzing code that runs outside of a CommonJS wrapper (like JavaScript modules), use nodeBuiltin to help detect accidental CommonJS references.
import globals from 'globals';
// For standard Node.js globals (process, Buffer, etc.)
const builtin = globals.nodeBuiltin;
// For Node.js globals plus CommonJS module scope (require, module, etc.)
const commonjs = globals.node;The puppeteer.config.cjs file allows you to control how Puppeteer downloads browser binaries and where it caches them. This is particularly useful for managing behavior in Continuous Integration (CI) environments versus local development.
Key configuration options:
skipDownload: A boolean determining whether to skip the automatic download of browser binaries. In this configuration, it is set to false (meaning it will download) when process.env.CI is true, and true (skipping download) otherwise.cacheDirectory: Specifies the directory where downloaded browsers are stored. When process.env.CI is true, it uses .cache/puppeteer/ relative to the current directory.chrome: Configuration object for the Chrome browser:skipDownload: Boolean to skip Chrome download.version: The specific version of Chrome to download (defaults to 'latest').firefox: Configuration object for the Firefox browser:skipDownload: Boolean to skip Firefox download.version: The specific version of Firefox to download (defaults to 'latest').module.exports = {
skipDownload: !IS_CI,
cacheDirectory: IS_CI ? path.join(__dirname, '.cache/puppeteer/') : undefined,
chrome: {
skipDownload: !IS_CI,
version: 'latest',
},
firefox: {
skipDownload: !IS_CI,
version: 'latest',
},
};The globals package exports a collection of global identifier objects (such as browser, node, and es) via a JSON structure. You can require or import the package to access these predefined sets of global variables.
const globals = require('globals');
// Example: Accessing browser globals
console.log(globals.browser);