first commit

This commit is contained in:
Warunee Tamkoo 2023-09-06 14:51:44 +07:00
commit eb2f504652
32490 changed files with 5731109 additions and 0 deletions

24
node_modules/@rushstack/eslint-patch/LICENSE generated vendored Normal file
View file

@ -0,0 +1,24 @@
@rushstack/eslint-patch
Copyright (c) Microsoft Corporation. All rights reserved.
MIT License
Permission is hereby granted, free of charge, to any person obtaining
a copy of this software and associated documentation files (the
"Software"), to deal in the Software without restriction, including
without limitation the rights to use, copy, modify, merge, publish,
distribute, sublicense, and/or sell copies of the Software, and to
permit persons to whom the Software is furnished to do so, subject to
the following conditions:
The above copyright notice and this permission notice shall be
included in all copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.

68
node_modules/@rushstack/eslint-patch/README.md generated vendored Normal file
View file

@ -0,0 +1,68 @@
# @rushstack/eslint-patch
A patch that improves how ESLint loads plugins when working in a monorepo with a reusable toolchain
## What it does
This patch is a workaround for a longstanding [ESLint feature request](https://github.com/eslint/eslint/issues/3458)
that would allow a shared ESLint config to bring along its own plugins, rather than imposing peer dependencies
on every consumer of the config. In a monorepo scenario, this enables your lint setup to be consolidated in a
single NPM package. Doing so greatly reduces the copy+pasting and version management for all the other projects
that use your standard lint rule set, but don't want to be bothered with the details.
ESLint provides partial solutions such as the `--resolve-plugins-relative-to` CLI option, however they are
awkward to use. For example, the VS Code extension for ESLint must be manually configured with this CLI option.
If some developers use other editors such as WebStorm, a different manual configuration is needed.
Also, the `--resolve-plugins-relative-to` parameter does not support multiple paths, for example if a config package
builds upon another package that also provides plugins. See
[this discussion](https://github.com/eslint/eslint/issues/3458#issuecomment-516666620)
for additional technical background.
## Why it's a patch
ESLint's long awaited module resolver overhaul still has not materialized as of ESLint 8. As a stopgap,
we created a small **.eslintrc.js** patch that solves the problem adequately for most real world scenarios.
This patch was proposed as an ESLint feature with [PR 12460](https://github.com/eslint/eslint/pull/12460), however
the maintainers were not able to accept it unless it is reworked into a fully correct design. Such a requirement
would impose the same hurdles as the original GitHub issue; thus, it seems best to stay with the patch approach.
Since the patch is now in wide use, we've converted it into a proper NPM package to simplify maintenance.
## How to use it
Add a `require()` call to the to top of the **.eslintrc.js** file for each project that depends on your shared
ESLint config, for example:
**.eslintrc.js**
```ts
require("@rushstack/eslint-patch/modern-module-resolution");
// Add your "extends" boilerplate here, for example:
module.exports = {
extends: ['@your-company/eslint-config'],
parserOptions: { tsconfigRootDir: __dirname }
};
```
With this change, the local project no longer needs any ESLint plugins in its **package.json** file.
Instead, the hypothetical `@your-company/eslint-config` NPM package would declare the plugins as its
own dependencies.
This patch works by modifying the ESLint engine so that its module resolver will load relative to the folder of
the referencing config file, rather than the project folder. The patch is compatible with ESLint 6, 7, and 8.
It also works with any editor extensions that load ESLint as a library.
For an even leaner setup, `@your-company/eslint-config` can provide the patch as its own dependency. See
[@rushstack/eslint-config](https://www.npmjs.com/package/@rushstack/eslint-config) for a real world example
and recommended approach.
## Links
- [CHANGELOG.md](https://github.com/microsoft/rushstack/blob/main/eslint/eslint-patch/CHANGELOG.md) - Find
out what's new in the latest version
`@rushstack/eslint-patch` is part of the [Rush Stack](https://rushstack.io/) family of projects.

View file

@ -0,0 +1,15 @@
declare const path: any;
declare const fs: any;
declare const isModuleResolutionError: (ex: unknown) => boolean;
declare const isInvalidImporterPath: (ex: unknown) => boolean;
declare let eslintrcBundlePath: string | undefined;
declare let configArrayFactoryPath: string | undefined;
declare let moduleResolverPath: string | undefined;
declare let eslintFolder: string | undefined;
declare const eslintPackageJson: any;
declare const eslintPackageObject: any;
declare const eslintPackageVersion: any;
declare const versionMatch: RegExpExecArray | null;
declare const eslintMajorVersion: number;
declare let ConfigArrayFactory: any;
//# sourceMappingURL=modern-module-resolution.d.ts.map

View file

@ -0,0 +1 @@
{"version":3,"file":"modern-module-resolution.d.ts","sourceRoot":"","sources":["../src/modern-module-resolution.ts"],"names":[],"mappings":"AASA,QAAA,MAAM,IAAI,KAAkB,CAAC;AAC7B,QAAA,MAAM,EAAE,KAAgB,CAAC;AAEzB,QAAA,MAAM,uBAAuB,EAAE,CAAC,EAAE,EAAE,OAAO,KAAK,OACyD,CAAC;AAG1G,QAAA,MAAM,qBAAqB,EAAE,CAAC,EAAE,EAAE,OAAO,KAAK,OAC2B,CAAC;AAI1E,QAAA,IAAI,kBAAkB,EAAE,MAAM,GAAG,SAAqB,CAAC;AAIvD,QAAA,IAAI,sBAAsB,EAAE,MAAM,GAAG,SAAqB,CAAC;AAI3D,QAAA,IAAI,kBAAkB,EAAE,MAAM,GAAG,SAAqB,CAAC;AAIvD,QAAA,IAAI,YAAY,EAAE,MAAM,GAAG,SAAqB,CAAC;AA0IjD,QAAA,MAAM,iBAAiB,KAAsE,CAAC;AAC9F,QAAA,MAAM,mBAAmB,KAAgC,CAAC;AAC1D,QAAA,MAAM,oBAAoB,KAA8B,CAAC;AACzD,QAAA,MAAM,YAAY,wBAA2C,CAAC;AAI9D,QAAA,MAAM,kBAAkB,QAA0B,CAAC;AAUnD,QAAA,IAAI,kBAAkB,KAAA,CAAC"}

View file

@ -0,0 +1,229 @@
"use strict";
// Copyright (c) Microsoft Corporation. All rights reserved. Licensed under the MIT license.
// See LICENSE in the project root for license information.
// This is a workaround for https://github.com/eslint/eslint/issues/3458
//
// To correct how ESLint searches for plugin packages, add this line to the top of your project's .eslintrc.js file:
//
// require("@rushstack/eslint-patch/modern-module-resolution");
//
const path = require('path');
const fs = require('fs');
const isModuleResolutionError = (ex) => typeof ex === 'object' && !!ex && 'code' in ex && ex.code === 'MODULE_NOT_FOUND';
// error: "The argument 'filename' must be a file URL object, file URL string, or absolute path string. Received ''"
const isInvalidImporterPath = (ex) => (ex === null || ex === void 0 ? void 0 : ex.code) === 'ERR_INVALID_ARG_VALUE';
// Module path for eslintrc.cjs
// Example: ".../@eslint/eslintrc/dist/eslintrc.cjs"
let eslintrcBundlePath = undefined;
// Module path for config-array-factory.js
// Example: ".../@eslint/eslintrc/lib/config-array-factory"
let configArrayFactoryPath = undefined;
// Module path for relative-module-resolver.js
// Example: ".../@eslint/eslintrc/lib/shared/relative-module-resolver"
let moduleResolverPath = undefined;
// Folder path where ESLint's package.json can be found
// Example: ".../node_modules/eslint"
let eslintFolder = undefined;
// Probe for the ESLint >=8.0.0 layout:
for (let currentModule = module;;) {
if (!eslintrcBundlePath) {
// For ESLint >=8.0.0, all @eslint/eslintrc code is bundled at this path:
// .../@eslint/eslintrc/dist/eslintrc.cjs
try {
const eslintrcFolder = path.dirname(require.resolve('@eslint/eslintrc/package.json', { paths: [currentModule.path] }));
// Make sure we actually resolved the module in our call path
// and not some other spurious dependency.
if (path.join(eslintrcFolder, 'dist/eslintrc.cjs') === currentModule.filename) {
eslintrcBundlePath = path.join(eslintrcFolder, 'dist/eslintrc.cjs');
}
}
catch (ex) {
// Module resolution failures are expected, as we're walking
// up our require stack to look for eslint. All other errors
// are rethrown.
if (!isModuleResolutionError(ex)) {
throw ex;
}
}
}
else {
// Next look for a file in ESLint's folder
// .../eslint/lib/cli-engine/cli-engine.js
try {
const eslintCandidateFolder = path.dirname(require.resolve('eslint/package.json', {
paths: [currentModule.path]
}));
// Make sure we actually resolved the module in our call path
// and not some other spurious dependency.
if (currentModule.filename.startsWith(eslintCandidateFolder + path.sep)) {
eslintFolder = eslintCandidateFolder;
break;
}
}
catch (ex) {
// Module resolution failures are expected, as we're walking
// up our require stack to look for eslint. All other errors
// are rethrown.
if (!isModuleResolutionError(ex)) {
throw ex;
}
}
}
if (!currentModule.parent) {
break;
}
currentModule = currentModule.parent;
}
if (!eslintFolder) {
// Probe for the ESLint >=7.8.0 layout:
for (let currentModule = module;;) {
if (!configArrayFactoryPath) {
// For ESLint >=7.8.0, config-array-factory.js is at this path:
// .../@eslint/eslintrc/lib/config-array-factory.js
try {
const eslintrcFolder = path.dirname(require.resolve('@eslint/eslintrc/package.json', {
paths: [currentModule.path]
}));
if (path.join(eslintrcFolder, '/lib/config-array-factory.js') == currentModule.filename) {
configArrayFactoryPath = path.join(eslintrcFolder, 'lib/config-array-factory.js');
moduleResolverPath = path.join(eslintrcFolder, 'lib/shared/relative-module-resolver');
}
}
catch (ex) {
// Module resolution failures are expected, as we're walking
// up our require stack to look for eslint. All other errors
// are rethrown.
if (!isModuleResolutionError(ex)) {
throw ex;
}
}
}
else {
// Next look for a file in ESLint's folder
// .../eslint/lib/cli-engine/cli-engine.js
try {
const eslintCandidateFolder = path.dirname(require.resolve('eslint/package.json', {
paths: [currentModule.path]
}));
if (path.join(eslintCandidateFolder, 'lib/cli-engine/cli-engine.js') == currentModule.filename) {
eslintFolder = eslintCandidateFolder;
break;
}
}
catch (ex) {
// Module resolution failures are expected, as we're walking
// up our require stack to look for eslint. All other errors
// are rethrown.
if (!isModuleResolutionError(ex)) {
throw ex;
}
}
}
if (!currentModule.parent) {
break;
}
currentModule = currentModule.parent;
}
}
if (!eslintFolder) {
// Probe for the <7.8.0 layout:
for (let currentModule = module;;) {
// For ESLint <7.8.0, config-array-factory.js was at this path:
// .../eslint/lib/cli-engine/config-array-factory.js
if (/[\\/]eslint[\\/]lib[\\/]cli-engine[\\/]config-array-factory\.js$/i.test(currentModule.filename)) {
eslintFolder = path.join(path.dirname(currentModule.filename), '../..');
configArrayFactoryPath = path.join(eslintFolder, 'lib/cli-engine/config-array-factory');
moduleResolverPath = path.join(eslintFolder, 'lib/shared/relative-module-resolver');
break;
}
if (!currentModule.parent) {
// This was tested with ESLint 6.1.0 .. 7.12.1.
throw new Error('Failed to patch ESLint because the calling module was not recognized.\n' +
'If you are using a newer ESLint version that may be unsupported, please create a GitHub issue:\n' +
'https://github.com/microsoft/rushstack/issues');
}
currentModule = currentModule.parent;
}
}
// Detect the ESLint package version
const eslintPackageJson = fs.readFileSync(path.join(eslintFolder, 'package.json')).toString();
const eslintPackageObject = JSON.parse(eslintPackageJson);
const eslintPackageVersion = eslintPackageObject.version;
const versionMatch = /^([0-9]+)\./.exec(eslintPackageVersion); // parse the SemVer MAJOR part
if (!versionMatch) {
throw new Error('Unable to parse ESLint version: ' + eslintPackageVersion);
}
const eslintMajorVersion = Number(versionMatch[1]);
if (!(eslintMajorVersion >= 6 && eslintMajorVersion <= 8)) {
throw new Error('The patch-eslint.js script has only been tested with ESLint version 6.x, 7.x, and 8.x.' +
` (Your version: ${eslintPackageVersion})\n` +
'Consider reporting a GitHub issue:\n' +
'https://github.com/microsoft/rushstack/issues');
}
let ConfigArrayFactory;
if (eslintMajorVersion === 8) {
ConfigArrayFactory = require(eslintrcBundlePath).Legacy.ConfigArrayFactory;
}
else {
ConfigArrayFactory = require(configArrayFactoryPath).ConfigArrayFactory;
}
if (!ConfigArrayFactory.__patched) {
ConfigArrayFactory.__patched = true;
let ModuleResolver;
if (eslintMajorVersion === 8) {
ModuleResolver = require(eslintrcBundlePath).Legacy.ModuleResolver;
}
else {
ModuleResolver = require(moduleResolverPath);
}
const originalLoadPlugin = ConfigArrayFactory.prototype._loadPlugin;
if (eslintMajorVersion === 6) {
// ESLint 6.x
ConfigArrayFactory.prototype._loadPlugin = function (name, importerPath, importerName) {
const originalResolve = ModuleResolver.resolve;
try {
ModuleResolver.resolve = function (moduleName, relativeToPath) {
try {
// resolve using importerPath instead of relativeToPath
return originalResolve.call(this, moduleName, importerPath);
}
catch (e) {
if (isModuleResolutionError(e) || isInvalidImporterPath(e)) {
return originalResolve.call(this, moduleName, relativeToPath);
}
throw e;
}
};
return originalLoadPlugin.apply(this, arguments);
}
finally {
ModuleResolver.resolve = originalResolve;
}
};
}
else {
// ESLint 7.x || 8.x
ConfigArrayFactory.prototype._loadPlugin = function (name, ctx) {
const originalResolve = ModuleResolver.resolve;
try {
ModuleResolver.resolve = function (moduleName, relativeToPath) {
try {
// resolve using ctx.filePath instead of relativeToPath
return originalResolve.call(this, moduleName, ctx.filePath);
}
catch (e) {
if (isModuleResolutionError(e) || isInvalidImporterPath(e)) {
return originalResolve.call(this, moduleName, relativeToPath);
}
throw e;
}
};
return originalLoadPlugin.apply(this, arguments);
}
finally {
ModuleResolver.resolve = originalResolve;
}
};
}
}
//# sourceMappingURL=modern-module-resolution.js.map

File diff suppressed because one or more lines are too long

2
node_modules/@rushstack/eslint-patch/lib/usage.d.ts generated vendored Normal file
View file

@ -0,0 +1,2 @@
export {};
//# sourceMappingURL=usage.d.ts.map

View file

@ -0,0 +1 @@
{"version":3,"file":"usage.d.ts","sourceRoot":"","sources":["../src/usage.ts"],"names":[],"mappings":"AAQA,OAAO,EAAE,CAAC"}

7
node_modules/@rushstack/eslint-patch/lib/usage.js generated vendored Normal file
View file

@ -0,0 +1,7 @@
"use strict";
// Copyright (c) Microsoft Corporation. All rights reserved. Licensed under the MIT license.
// See LICENSE in the project root for license information.
Object.defineProperty(exports, "__esModule", { value: true });
throw new Error('The @rushstack/eslint-patch package does not have a default entry point.' +
' See README.md for usage instructions.');
//# sourceMappingURL=usage.js.map

View file

@ -0,0 +1 @@
{"version":3,"file":"usage.js","sourceRoot":"","sources":["../src/usage.ts"],"names":[],"mappings":";AAAA,4FAA4F;AAC5F,2DAA2D;;AAE3D,MAAM,IAAI,KAAK,CACb,0EAA0E;IACxE,wCAAwC,CAC3C,CAAC","sourcesContent":["// Copyright (c) Microsoft Corporation. All rights reserved. Licensed under the MIT license.\n// See LICENSE in the project root for license information.\n\nthrow new Error(\n 'The @rushstack/eslint-patch package does not have a default entry point.' +\n ' See README.md for usage instructions.'\n);\n\nexport {};\n"]}

View file

@ -0,0 +1 @@
require('./lib/modern-module-resolution');

32
node_modules/@rushstack/eslint-patch/package.json generated vendored Normal file
View file

@ -0,0 +1,32 @@
{
"name": "@rushstack/eslint-patch",
"version": "1.3.3",
"description": "A patch that improves how ESLint loads plugins when working in a monorepo with a reusable toolchain",
"main": "lib/usage.js",
"license": "MIT",
"repository": {
"url": "https://github.com/microsoft/rushstack.git",
"type": "git",
"directory": "eslint/eslint-patch"
},
"homepage": "https://rushstack.io",
"keywords": [
"eslintrc",
"config",
"module",
"resolve",
"resolver",
"plugin",
"relative",
"package"
],
"devDependencies": {
"@rushstack/heft": "0.54.0",
"@rushstack/heft-node-rig": "2.2.6",
"@types/node": "14.18.36"
},
"scripts": {
"build": "heft build --clean",
"_phase:build": "heft run --only build -- --clean"
}
}