build: update npm install command to use --legacy-peer-deps

This change modifies the build scripts to use --legacy-peer-deps flag when installing npm dependencies to resolve potential peer dependency conflicts during the build process. The change is applied to both bash (build.sh) and batch (build.bat) build scripts.
This commit is contained in:
Luiz Costa
2025-11-18 10:23:55 -03:00
parent 20129a1ac7
commit ac4f232e5e
787 changed files with 82341 additions and 121690 deletions
+347 -341
View File
@@ -34,15 +34,18 @@
// Requirements
//------------------------------------------------------------------------------
const fs = require("node:fs");
const path = require("node:path");
const fs = require("fs");
const path = require("path");
const getGlobParent = require("glob-parent");
const isGlob = require("is-glob");
const escapeRegExp = require("escape-string-regexp");
const { Minimatch } = require("minimatch");
const {
Legacy: { IgnorePattern, CascadingConfigArrayFactory },
Legacy: {
IgnorePattern,
CascadingConfigArrayFactory
}
} = require("@eslint/eslintrc");
const debug = require("debug")("eslint:file-enumerator");
@@ -51,7 +54,7 @@ const debug = require("debug")("eslint:file-enumerator");
//------------------------------------------------------------------------------
const minimatchOpts = { dot: true, matchBase: true };
const dotfilesPattern = /(?:^\.|[/\\]\.)[^/\\.].*/u;
const dotfilesPattern = /(?:(?:^\.)|(?:[/\\]\.))[^/\\.].*/u;
const NONE = 0;
const IGNORED_SILENTLY = 1;
const IGNORED = 2;
@@ -105,7 +108,7 @@ const internalSlotsMap = new WeakMap();
* @returns {boolean} `true` if the string is a glob pattern.
*/
function isGlobPattern(pattern) {
return isGlob(path.sep === "\\" ? pattern.replace(/\\/gu, "/") : pattern);
return isGlob(path.sep === "\\" ? pattern.replace(/\\/gu, "/") : pattern);
}
/**
@@ -116,15 +119,16 @@ function isGlobPattern(pattern) {
* @private
*/
function statSafeSync(filePath) {
try {
return fs.statSync(filePath);
} catch (error) {
/* c8 ignore next */
if (error.code !== "ENOENT") {
throw error;
}
return null;
}
try {
return fs.statSync(filePath);
} catch (error) {
/* c8 ignore next */
if (error.code !== "ENOENT") {
throw error;
}
return null;
}
}
/**
@@ -135,15 +139,16 @@ function statSafeSync(filePath) {
* @private
*/
function readdirSafeSync(directoryPath) {
try {
return fs.readdirSync(directoryPath, { withFileTypes: true });
} catch (error) {
/* c8 ignore next */
if (error.code !== "ENOENT") {
throw error;
}
return [];
}
try {
return fs.readdirSync(directoryPath, { withFileTypes: true });
} catch (error) {
/* c8 ignore next */
if (error.code !== "ENOENT") {
throw error;
}
return [];
}
}
/**
@@ -152,45 +157,50 @@ function readdirSafeSync(directoryPath) {
* @returns {RegExp | null} The created `RegExp` object or null.
*/
function createExtensionRegExp(extensions) {
if (extensions) {
const normalizedExts = extensions.map(ext =>
escapeRegExp(ext.startsWith(".") ? ext.slice(1) : ext),
);
if (extensions) {
const normalizedExts = extensions.map(ext => escapeRegExp(
ext.startsWith(".")
? ext.slice(1)
: ext
));
return new RegExp(`.\\.(?:${normalizedExts.join("|")})$`, "u");
}
return null;
return new RegExp(
`.\\.(?:${normalizedExts.join("|")})$`,
"u"
);
}
return null;
}
/**
* The error type when no files match a glob.
*/
class NoFilesFoundError extends Error {
/**
* @param {string} pattern The glob pattern which was not found.
* @param {boolean} globDisabled If `true` then the pattern was a glob pattern, but glob was disabled.
*/
constructor(pattern, globDisabled) {
super(
`No files matching '${pattern}' were found${globDisabled ? " (glob was disabled)" : ""}.`,
);
this.messageTemplate = "file-not-found";
this.messageData = { pattern, globDisabled };
}
/**
* @param {string} pattern The glob pattern which was not found.
* @param {boolean} globDisabled If `true` then the pattern was a glob pattern, but glob was disabled.
*/
constructor(pattern, globDisabled) {
super(`No files matching '${pattern}' were found${globDisabled ? " (glob was disabled)" : ""}.`);
this.messageTemplate = "file-not-found";
this.messageData = { pattern, globDisabled };
}
}
/**
* The error type when there are files matched by a glob, but all of them have been ignored.
*/
class AllFilesIgnoredError extends Error {
/**
* @param {string} pattern The glob pattern which was not found.
*/
constructor(pattern) {
super(`All files matched by '${pattern}' are ignored.`);
this.messageTemplate = "all-files-ignored";
this.messageData = { pattern };
}
/**
* @param {string} pattern The glob pattern which was not found.
*/
constructor(pattern) {
super(`All files matched by '${pattern}' are ignored.`);
this.messageTemplate = "all-files-ignored";
this.messageData = { pattern };
}
}
/**
@@ -198,340 +208,336 @@ class AllFilesIgnoredError extends Error {
* matched by given glob patterns and that configuration.
*/
class FileEnumerator {
/**
* Initialize this enumerator.
* @param {FileEnumeratorOptions} options The options.
*/
constructor({
cwd = process.cwd(),
configArrayFactory = new CascadingConfigArrayFactory({
cwd,
getEslintRecommendedConfig: () =>
require("@eslint/js").configs.recommended,
getEslintAllConfig: () => require("@eslint/js").configs.all,
}),
extensions = null,
globInputPaths = true,
errorOnUnmatchedPattern = true,
ignore = true,
} = {}) {
internalSlotsMap.set(this, {
configArrayFactory,
cwd,
defaultIgnores: IgnorePattern.createDefaultIgnore(cwd),
extensionRegExp: createExtensionRegExp(extensions),
globInputPaths,
errorOnUnmatchedPattern,
ignoreFlag: ignore,
});
}
/**
* Check if a given file is target or not.
* @param {string} filePath The path to a candidate file.
* @param {ConfigArray} [providedConfig] Optional. The configuration for the file.
* @returns {boolean} `true` if the file is a target.
*/
isTargetPath(filePath, providedConfig) {
const { configArrayFactory, extensionRegExp } =
internalSlotsMap.get(this);
/**
* Initialize this enumerator.
* @param {FileEnumeratorOptions} options The options.
*/
constructor({
cwd = process.cwd(),
configArrayFactory = new CascadingConfigArrayFactory({
cwd,
getEslintRecommendedConfig: () => require("@eslint/js").configs.recommended,
getEslintAllConfig: () => require("@eslint/js").configs.all
}),
extensions = null,
globInputPaths = true,
errorOnUnmatchedPattern = true,
ignore = true
} = {}) {
internalSlotsMap.set(this, {
configArrayFactory,
cwd,
defaultIgnores: IgnorePattern.createDefaultIgnore(cwd),
extensionRegExp: createExtensionRegExp(extensions),
globInputPaths,
errorOnUnmatchedPattern,
ignoreFlag: ignore
});
}
// If `--ext` option is present, use it.
if (extensionRegExp) {
return extensionRegExp.test(filePath);
}
/**
* Check if a given file is target or not.
* @param {string} filePath The path to a candidate file.
* @param {ConfigArray} [providedConfig] Optional. The configuration for the file.
* @returns {boolean} `true` if the file is a target.
*/
isTargetPath(filePath, providedConfig) {
const {
configArrayFactory,
extensionRegExp
} = internalSlotsMap.get(this);
// `.js` file is target by default.
if (filePath.endsWith(".js")) {
return true;
}
// If `--ext` option is present, use it.
if (extensionRegExp) {
return extensionRegExp.test(filePath);
}
// use `overrides[].files` to check additional targets.
const config =
providedConfig ||
configArrayFactory.getConfigArrayForFile(filePath, {
ignoreNotFoundError: true,
});
// `.js` file is target by default.
if (filePath.endsWith(".js")) {
return true;
}
return config.isAdditionalTargetPath(filePath);
}
// use `overrides[].files` to check additional targets.
const config =
providedConfig ||
configArrayFactory.getConfigArrayForFile(
filePath,
{ ignoreNotFoundError: true }
);
/**
* Iterate files which are matched by given glob patterns.
* @param {string|string[]} patternOrPatterns The glob patterns to iterate files.
* @throws {NoFilesFoundError|AllFilesIgnoredError} On an unmatched pattern.
* @returns {IterableIterator<FileAndConfig>} The found files.
*/
*iterateFiles(patternOrPatterns) {
const { globInputPaths, errorOnUnmatchedPattern } =
internalSlotsMap.get(this);
const patterns = Array.isArray(patternOrPatterns)
? patternOrPatterns
: [patternOrPatterns];
return config.isAdditionalTargetPath(filePath);
}
debug("Start to iterate files: %o", patterns);
/**
* Iterate files which are matched by given glob patterns.
* @param {string|string[]} patternOrPatterns The glob patterns to iterate files.
* @throws {NoFilesFoundError|AllFilesIgnoredError} On an unmatched pattern.
* @returns {IterableIterator<FileAndConfig>} The found files.
*/
*iterateFiles(patternOrPatterns) {
const { globInputPaths, errorOnUnmatchedPattern } = internalSlotsMap.get(this);
const patterns = Array.isArray(patternOrPatterns)
? patternOrPatterns
: [patternOrPatterns];
// The set of paths to remove duplicate.
const set = new Set();
debug("Start to iterate files: %o", patterns);
for (const pattern of patterns) {
let foundRegardlessOfIgnored = false;
let found = false;
// The set of paths to remove duplicate.
const set = new Set();
// Skip empty string.
if (!pattern) {
continue;
}
for (const pattern of patterns) {
let foundRegardlessOfIgnored = false;
let found = false;
// Iterate files of this pattern.
for (const { config, filePath, flag } of this._iterateFiles(
pattern,
)) {
foundRegardlessOfIgnored = true;
if (flag === IGNORED_SILENTLY) {
continue;
}
found = true;
// Skip empty string.
if (!pattern) {
continue;
}
// Remove duplicate paths while yielding paths.
if (!set.has(filePath)) {
set.add(filePath);
yield {
config,
filePath,
ignored: flag === IGNORED,
};
}
}
// Iterate files of this pattern.
for (const { config, filePath, flag } of this._iterateFiles(pattern)) {
foundRegardlessOfIgnored = true;
if (flag === IGNORED_SILENTLY) {
continue;
}
found = true;
// Raise an error if any files were not found.
if (errorOnUnmatchedPattern) {
if (!foundRegardlessOfIgnored) {
throw new NoFilesFoundError(
pattern,
!globInputPaths && isGlob(pattern),
);
}
if (!found) {
throw new AllFilesIgnoredError(pattern);
}
}
}
// Remove duplicate paths while yielding paths.
if (!set.has(filePath)) {
set.add(filePath);
yield {
config,
filePath,
ignored: flag === IGNORED
};
}
}
debug(`Complete iterating files: ${JSON.stringify(patterns)}`);
}
// Raise an error if any files were not found.
if (errorOnUnmatchedPattern) {
if (!foundRegardlessOfIgnored) {
throw new NoFilesFoundError(
pattern,
!globInputPaths && isGlob(pattern)
);
}
if (!found) {
throw new AllFilesIgnoredError(pattern);
}
}
}
/**
* Iterate files which are matched by a given glob pattern.
* @param {string} pattern The glob pattern to iterate files.
* @returns {IterableIterator<FileEntry>} The found files.
*/
_iterateFiles(pattern) {
const { cwd, globInputPaths } = internalSlotsMap.get(this);
const absolutePath = path.resolve(cwd, pattern);
const isDot = dotfilesPattern.test(pattern);
const stat = statSafeSync(absolutePath);
debug(`Complete iterating files: ${JSON.stringify(patterns)}`);
}
if (stat && stat.isDirectory()) {
return this._iterateFilesWithDirectory(absolutePath, isDot);
}
if (stat && stat.isFile()) {
return this._iterateFilesWithFile(absolutePath);
}
if (globInputPaths && isGlobPattern(pattern)) {
return this._iterateFilesWithGlob(pattern, isDot);
}
/**
* Iterate files which are matched by a given glob pattern.
* @param {string} pattern The glob pattern to iterate files.
* @returns {IterableIterator<FileEntry>} The found files.
*/
_iterateFiles(pattern) {
const { cwd, globInputPaths } = internalSlotsMap.get(this);
const absolutePath = path.resolve(cwd, pattern);
const isDot = dotfilesPattern.test(pattern);
const stat = statSafeSync(absolutePath);
return [];
}
if (stat && stat.isDirectory()) {
return this._iterateFilesWithDirectory(absolutePath, isDot);
}
if (stat && stat.isFile()) {
return this._iterateFilesWithFile(absolutePath);
}
if (globInputPaths && isGlobPattern(pattern)) {
return this._iterateFilesWithGlob(pattern, isDot);
}
/**
* Iterate a file which is matched by a given path.
* @param {string} filePath The path to the target file.
* @returns {IterableIterator<FileEntry>} The found files.
* @private
*/
_iterateFilesWithFile(filePath) {
debug(`File: ${filePath}`);
return [];
}
const { configArrayFactory } = internalSlotsMap.get(this);
const config = configArrayFactory.getConfigArrayForFile(filePath);
const ignored = this._isIgnoredFile(filePath, { config, direct: true });
const flag = ignored ? IGNORED : NONE;
/**
* Iterate a file which is matched by a given path.
* @param {string} filePath The path to the target file.
* @returns {IterableIterator<FileEntry>} The found files.
* @private
*/
_iterateFilesWithFile(filePath) {
debug(`File: ${filePath}`);
return [{ config, filePath, flag }];
}
const { configArrayFactory } = internalSlotsMap.get(this);
const config = configArrayFactory.getConfigArrayForFile(filePath);
const ignored = this._isIgnoredFile(filePath, { config, direct: true });
const flag = ignored ? IGNORED : NONE;
/**
* Iterate files in a given path.
* @param {string} directoryPath The path to the target directory.
* @param {boolean} dotfiles If `true` then it doesn't skip dot files by default.
* @returns {IterableIterator<FileEntry>} The found files.
* @private
*/
_iterateFilesWithDirectory(directoryPath, dotfiles) {
debug(`Directory: ${directoryPath}`);
return [{ config, filePath, flag }];
}
return this._iterateFilesRecursive(directoryPath, {
dotfiles,
recursive: true,
selector: null,
});
}
/**
* Iterate files in a given path.
* @param {string} directoryPath The path to the target directory.
* @param {boolean} dotfiles If `true` then it doesn't skip dot files by default.
* @returns {IterableIterator<FileEntry>} The found files.
* @private
*/
_iterateFilesWithDirectory(directoryPath, dotfiles) {
debug(`Directory: ${directoryPath}`);
/**
* Iterate files which are matched by a given glob pattern.
* @param {string} pattern The glob pattern to iterate files.
* @param {boolean} dotfiles If `true` then it doesn't skip dot files by default.
* @returns {IterableIterator<FileEntry>} The found files.
* @private
*/
_iterateFilesWithGlob(pattern, dotfiles) {
debug(`Glob: ${pattern}`);
return this._iterateFilesRecursive(
directoryPath,
{ dotfiles, recursive: true, selector: null }
);
}
const { cwd } = internalSlotsMap.get(this);
const directoryPath = path.resolve(cwd, getGlobParent(pattern));
const absolutePath = path.resolve(cwd, pattern);
const globPart = absolutePath.slice(directoryPath.length + 1);
/**
* Iterate files which are matched by a given glob pattern.
* @param {string} pattern The glob pattern to iterate files.
* @param {boolean} dotfiles If `true` then it doesn't skip dot files by default.
* @returns {IterableIterator<FileEntry>} The found files.
* @private
*/
_iterateFilesWithGlob(pattern, dotfiles) {
debug(`Glob: ${pattern}`);
/*
* recursive if there are `**` or path separators in the glob part.
* Otherwise, patterns such as `src/*.js`, it doesn't need recursive.
*/
const recursive = /\*\*|\/|\\/u.test(globPart);
const selector = new Minimatch(absolutePath, minimatchOpts);
const { cwd } = internalSlotsMap.get(this);
const directoryPath = path.resolve(cwd, getGlobParent(pattern));
const absolutePath = path.resolve(cwd, pattern);
const globPart = absolutePath.slice(directoryPath.length + 1);
debug(`recursive? ${recursive}`);
/*
* recursive if there are `**` or path separators in the glob part.
* Otherwise, patterns such as `src/*.js`, it doesn't need recursive.
*/
const recursive = /\*\*|\/|\\/u.test(globPart);
const selector = new Minimatch(absolutePath, minimatchOpts);
return this._iterateFilesRecursive(directoryPath, {
dotfiles,
recursive,
selector,
});
}
debug(`recursive? ${recursive}`);
/**
* Iterate files in a given path.
* @param {string} directoryPath The path to the target directory.
* @param {Object} options The options to iterate files.
* @param {boolean} [options.dotfiles] If `true` then it doesn't skip dot files by default.
* @param {boolean} [options.recursive] If `true` then it dives into sub directories.
* @param {InstanceType<Minimatch>} [options.selector] The matcher to choose files.
* @returns {IterableIterator<FileEntry>} The found files.
* @private
*/
*_iterateFilesRecursive(directoryPath, options) {
debug(`Enter the directory: ${directoryPath}`);
const { configArrayFactory } = internalSlotsMap.get(this);
return this._iterateFilesRecursive(
directoryPath,
{ dotfiles, recursive, selector }
);
}
/** @type {ConfigArray|null} */
let config = null;
/**
* Iterate files in a given path.
* @param {string} directoryPath The path to the target directory.
* @param {Object} options The options to iterate files.
* @param {boolean} [options.dotfiles] If `true` then it doesn't skip dot files by default.
* @param {boolean} [options.recursive] If `true` then it dives into sub directories.
* @param {InstanceType<Minimatch>} [options.selector] The matcher to choose files.
* @returns {IterableIterator<FileEntry>} The found files.
* @private
*/
*_iterateFilesRecursive(directoryPath, options) {
debug(`Enter the directory: ${directoryPath}`);
const { configArrayFactory } = internalSlotsMap.get(this);
// Enumerate the files of this directory.
for (const entry of readdirSafeSync(directoryPath)) {
const filePath = path.join(directoryPath, entry.name);
const fileInfo = entry.isSymbolicLink()
? statSafeSync(filePath)
: entry;
/** @type {ConfigArray|null} */
let config = null;
if (!fileInfo) {
continue;
}
// Enumerate the files of this directory.
for (const entry of readdirSafeSync(directoryPath)) {
const filePath = path.join(directoryPath, entry.name);
const fileInfo = entry.isSymbolicLink() ? statSafeSync(filePath) : entry;
// Check if the file is matched.
if (fileInfo.isFile()) {
if (!config) {
config = configArrayFactory.getConfigArrayForFile(
filePath,
if (!fileInfo) {
continue;
}
/*
* We must ignore `ConfigurationNotFoundError` at this
* point because we don't know if target files exist in
* this directory.
*/
{ ignoreNotFoundError: true },
);
}
const matched = options.selector
? // Started with a glob pattern; choose by the pattern.
options.selector.match(filePath)
: // Started with a directory path; choose by file extensions.
this.isTargetPath(filePath, config);
// Check if the file is matched.
if (fileInfo.isFile()) {
if (!config) {
config = configArrayFactory.getConfigArrayForFile(
filePath,
if (matched) {
const ignored = this._isIgnoredFile(filePath, {
...options,
config,
});
const flag = ignored ? IGNORED_SILENTLY : NONE;
/*
* We must ignore `ConfigurationNotFoundError` at this
* point because we don't know if target files exist in
* this directory.
*/
{ ignoreNotFoundError: true }
);
}
const matched = options.selector
debug(
`Yield: ${entry.name}${ignored ? " but ignored" : ""}`,
);
yield {
config: configArrayFactory.getConfigArrayForFile(
filePath,
),
filePath,
flag,
};
} else {
debug(`Didn't match: ${entry.name}`);
}
// Started with a glob pattern; choose by the pattern.
? options.selector.match(filePath)
// Dive into the sub directory.
} else if (options.recursive && fileInfo.isDirectory()) {
if (!config) {
config = configArrayFactory.getConfigArrayForFile(
filePath,
{ ignoreNotFoundError: true },
);
}
const ignored = this._isIgnoredFile(filePath + path.sep, {
...options,
config,
});
// Started with a directory path; choose by file extensions.
: this.isTargetPath(filePath, config);
if (!ignored) {
yield* this._iterateFilesRecursive(filePath, options);
}
}
}
if (matched) {
const ignored = this._isIgnoredFile(filePath, { ...options, config });
const flag = ignored ? IGNORED_SILENTLY : NONE;
debug(`Leave the directory: ${directoryPath}`);
}
debug(`Yield: ${entry.name}${ignored ? " but ignored" : ""}`);
yield {
config: configArrayFactory.getConfigArrayForFile(filePath),
filePath,
flag
};
} else {
debug(`Didn't match: ${entry.name}`);
}
/**
* Check if a given file should be ignored.
* @param {string} filePath The path to a file to check.
* @param {Object} options Options
* @param {ConfigArray} [options.config] The config for this file.
* @param {boolean} [options.dotfiles] If `true` then this is not ignore dot files by default.
* @param {boolean} [options.direct] If `true` then this is a direct specified file.
* @returns {boolean} `true` if the file should be ignored.
* @private
*/
_isIgnoredFile(
filePath,
{ config: providedConfig, dotfiles = false, direct = false },
) {
const { configArrayFactory, defaultIgnores, ignoreFlag } =
internalSlotsMap.get(this);
// Dive into the sub directory.
} else if (options.recursive && fileInfo.isDirectory()) {
if (!config) {
config = configArrayFactory.getConfigArrayForFile(
filePath,
{ ignoreNotFoundError: true }
);
}
const ignored = this._isIgnoredFile(
filePath + path.sep,
{ ...options, config }
);
if (ignoreFlag) {
const config =
providedConfig ||
configArrayFactory.getConfigArrayForFile(filePath, {
ignoreNotFoundError: true,
});
const ignores =
config.extractConfig(filePath).ignores || defaultIgnores;
if (!ignored) {
yield* this._iterateFilesRecursive(filePath, options);
}
}
}
return ignores(filePath, dotfiles);
}
debug(`Leave the directory: ${directoryPath}`);
}
return !direct && defaultIgnores(filePath, dotfiles);
}
/**
* Check if a given file should be ignored.
* @param {string} filePath The path to a file to check.
* @param {Object} options Options
* @param {ConfigArray} [options.config] The config for this file.
* @param {boolean} [options.dotfiles] If `true` then this is not ignore dot files by default.
* @param {boolean} [options.direct] If `true` then this is a direct specified file.
* @returns {boolean} `true` if the file should be ignored.
* @private
*/
_isIgnoredFile(filePath, {
config: providedConfig,
dotfiles = false,
direct = false
}) {
const {
configArrayFactory,
defaultIgnores,
ignoreFlag
} = internalSlotsMap.get(this);
if (ignoreFlag) {
const config =
providedConfig ||
configArrayFactory.getConfigArrayForFile(
filePath,
{ ignoreNotFoundError: true }
);
const ignores =
config.extractConfig(filePath).ignores || defaultIgnores;
return ignores(filePath, dotfiles);
}
return !direct && defaultIgnores(filePath, dotfiles);
}
}
//------------------------------------------------------------------------------