Spaces:
Sleeping
Sleeping
File size: 10,083 Bytes
cc651f6 |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 |
"use strict";
// Copyright (c) Microsoft Corporation. All rights reserved. Licensed under the MIT license.
// See LICENSE in the project root for license information.
var __importDefault = (this && this.__importDefault) || function (mod) {
return (mod && mod.__esModule) ? mod : { "default": mod };
};
Object.defineProperty(exports, "__esModule", { value: true });
exports.isModuleResolutionError = exports.ESLINT_MAJOR_VERSION = exports.Naming = exports.ModuleResolver = exports.configArrayFactory = exports.eslintFolder = exports.eslintPackageVersion = void 0;
// 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_1 = __importDefault(require("path"));
const isModuleResolutionError = (ex) => typeof ex === 'object' && !!ex && 'code' in ex && ex.code === 'MODULE_NOT_FOUND';
exports.isModuleResolutionError = isModuleResolutionError;
// 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;
// Module path for naming.js
// Example: ".../@eslint/eslintrc/lib/shared/naming"
let namingPath = undefined;
// Folder path where ESLint's package.json can be found
// Example: ".../node_modules/eslint"
let eslintFolder = undefined;
exports.eslintFolder = eslintFolder;
// Probe for the ESLint >=8.0.0 layout:
for (let currentModule = module;;) {
if (!eslintrcBundlePath) {
if (currentModule.filename.endsWith('eslintrc.cjs')) {
// For ESLint >=8.0.0, all @eslint/eslintrc code is bundled at this path:
// .../@eslint/eslintrc/dist/eslintrc.cjs
try {
const eslintrcFolderPath = path_1.default.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.
const resolvedEslintrcBundlePath = path_1.default.join(eslintrcFolderPath, 'dist/eslintrc.cjs');
if (resolvedEslintrcBundlePath === currentModule.filename) {
eslintrcBundlePath = resolvedEslintrcBundlePath;
}
}
catch (ex) {
// Module resolution failures are expected, as we're walking
// up our require stack to look for eslint. All other errors
// are re-thrown.
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_1.default.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_1.default.sep)) {
exports.eslintFolder = 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 re-thrown.
if (!isModuleResolutionError(ex)) {
throw ex;
}
}
}
if (!currentModule.parent) {
break;
}
currentModule = currentModule.parent;
}
if (!eslintFolder) {
// Probe for the ESLint >=7.12.0 layout:
for (let currentModule = module;;) {
if (!configArrayFactoryPath) {
// For ESLint >=7.12.0, config-array-factory.js is at this path:
// .../@eslint/eslintrc/lib/config-array-factory.js
try {
const eslintrcFolder = path_1.default.dirname(require.resolve('@eslint/eslintrc/package.json', {
paths: [currentModule.path]
}));
const resolvedConfigArrayFactoryPath = path_1.default.join(eslintrcFolder, '/lib/config-array-factory.js');
if (resolvedConfigArrayFactoryPath === currentModule.filename) {
configArrayFactoryPath = resolvedConfigArrayFactoryPath;
moduleResolverPath = `${eslintrcFolder}/lib/shared/relative-module-resolver`;
namingPath = `${eslintrcFolder}/lib/shared/naming`;
}
}
catch (ex) {
// Module resolution failures are expected, as we're walking
// up our require stack to look for eslint. All other errors
// are re-thrown.
if (!isModuleResolutionError(ex)) {
throw ex;
}
}
}
else if (currentModule.filename.endsWith('cli-engine.js')) {
// Next look for a file in ESLint's folder
// .../eslint/lib/cli-engine/cli-engine.js
try {
const eslintCandidateFolder = path_1.default.dirname(require.resolve('eslint/package.json', {
paths: [currentModule.path]
}));
if (path_1.default.join(eslintCandidateFolder, 'lib/cli-engine/cli-engine.js') === currentModule.filename) {
exports.eslintFolder = 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.12.0 layout:
for (let currentModule = module;;) {
// For ESLint <7.12.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)) {
exports.eslintFolder = eslintFolder = path_1.default.join(path_1.default.dirname(currentModule.filename), '../..');
configArrayFactoryPath = `${eslintFolder}/lib/cli-engine/config-array-factory`;
moduleResolverPath = `${eslintFolder}/lib/shared/relative-module-resolver`;
// The naming module was moved to @eslint/eslintrc in ESLint 7.8.0, which is also when the @eslint/eslintrc
// package was created and added to ESLint, so we need to probe for whether it's in the old or new location.
let eslintrcFolder;
try {
eslintrcFolder = path_1.default.dirname(require.resolve('@eslint/eslintrc/package.json', {
paths: [currentModule.path]
}));
}
catch (ex) {
if (!isModuleResolutionError(ex)) {
throw ex;
}
}
namingPath = `${eslintrcFolder !== null && eslintrcFolder !== void 0 ? eslintrcFolder : eslintFolder}/lib/shared/naming`;
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 eslintPackageJsonPath = `${eslintFolder}/package.json`;
const eslintPackageObject = require(eslintPackageJsonPath);
exports.eslintPackageVersion = eslintPackageObject.version;
const ESLINT_MAJOR_VERSION = parseInt(exports.eslintPackageVersion, 10);
exports.ESLINT_MAJOR_VERSION = ESLINT_MAJOR_VERSION;
if (isNaN(ESLINT_MAJOR_VERSION)) {
throw new Error(`Unable to parse ESLint version "${exports.eslintPackageVersion}" in file "${eslintPackageJsonPath}"`);
}
if (!(ESLINT_MAJOR_VERSION >= 6 && ESLINT_MAJOR_VERSION <= 9)) {
throw new Error('The ESLint patch script has only been tested with ESLint version 6.x, 7.x, 8.x, and 9.x.' +
` (Your version: ${exports.eslintPackageVersion})\n` +
'Consider reporting a GitHub issue:\n' +
'https://github.com/microsoft/rushstack/issues');
}
// eslint-disable-next-line @typescript-eslint/no-explicit-any
let configArrayFactory;
if (ESLINT_MAJOR_VERSION >= 8) {
exports.configArrayFactory = configArrayFactory = require(eslintrcBundlePath).Legacy.ConfigArrayFactory;
}
else {
exports.configArrayFactory = configArrayFactory = require(configArrayFactoryPath).ConfigArrayFactory;
}
// eslint-disable-next-line @typescript-eslint/no-explicit-any
let ModuleResolver;
// eslint-disable-next-line @typescript-eslint/no-explicit-any
let Naming;
if (ESLINT_MAJOR_VERSION >= 8) {
exports.ModuleResolver = ModuleResolver = require(eslintrcBundlePath).Legacy.ModuleResolver;
exports.Naming = Naming = require(eslintrcBundlePath).Legacy.naming;
}
else {
exports.ModuleResolver = ModuleResolver = require(moduleResolverPath);
exports.Naming = Naming = require(namingPath);
}
//# sourceMappingURL=_patch-base.js.map |