You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
1 lines
14 KiB
1 lines
14 KiB
{"version":3,"file":"modern-module-resolution.js","sourceRoot":"","sources":["../src/modern-module-resolution.ts"],"names":[],"mappings":";AAAA,4FAA4F;AAC5F,2DAA2D;AAE3D,wEAAwE;AACxE,EAAE;AACF,oHAAoH;AACpH,EAAE;AACF,kEAAkE;AAClE,EAAE;AACF,MAAM,IAAI,GAAG,OAAO,CAAC,MAAM,CAAC,CAAC;AAC7B,MAAM,EAAE,GAAG,OAAO,CAAC,IAAI,CAAC,CAAC;AAEzB,MAAM,uBAAuB,GAA6B,CAAC,EAAE,EAAE,EAAE,CAC/D,OAAO,EAAE,KAAK,QAAQ,IAAI,CAAC,CAAC,EAAE,IAAI,MAAM,IAAI,EAAE,IAAK,EAAwB,CAAC,IAAI,KAAK,kBAAkB,CAAC;AAE1G,+BAA+B;AAC/B,oDAAoD;AACpD,IAAI,kBAAkB,GAAuB,SAAS,CAAC;AAEvD,0CAA0C;AAC1C,2DAA2D;AAC3D,IAAI,sBAAsB,GAAuB,SAAS,CAAC;AAE3D,8CAA8C;AAC9C,sEAAsE;AACtE,IAAI,kBAAkB,GAAuB,SAAS,CAAC;AAEvD,uDAAuD;AACvD,qCAAqC;AACrC,IAAI,YAAY,GAAuB,SAAS,CAAC;AAEjD,uCAAuC;AACvC,KAAK,IAAI,aAAa,GAAG,MAAM,IAAM;IACnC,IAAI,CAAC,kBAAkB,EAAE;QACvB,yEAAyE;QACzE,2CAA2C;QAC3C,IAAI;YACF,MAAM,cAAc,GAAG,IAAI,CAAC,OAAO,CACjC,OAAO,CAAC,OAAO,CAAC,+BAA+B,EAAE,EAAE,KAAK,EAAE,CAAC,aAAa,CAAC,IAAI,CAAC,EAAE,CAAC,CAClF,CAAC;YAEF,6DAA6D;YAC7D,0CAA0C;YAC1C,IAAI,IAAI,CAAC,IAAI,CAAC,cAAc,EAAE,mBAAmB,CAAC,KAAK,aAAa,CAA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AM,eAAe,GAAG,cAAc,CAAC,OAAO,CAAC;YAC/C,IAAI;gBACF,cAAc,CAAC,OAAO,GAAG,UAAU,UAAkB,EAAE,cAAsB;oBAC3E,uDAAuD;oBACvD,OAAO,eAAe,CAAC,IAAI,CAAC,IAAI,EAAE,UAAU,EAAE,GAAG,CAAC,QAAQ,CAAC,CAAC;gBAC9D,CAAC,CAAC;gBACF,OAAO,kBAAkB,CAAC,KAAK,CAAC,IAAI,EAAE,SAAS,CAAC,CAAC;aAClD;oBAAS;gBACR,cAAc,CAAC,OAAO,GAAG,eAAe,CAAC;aAC1C;QACH,CAAC,CAAC;KACH;CACF","sourcesContent":["// Copyright (c) Microsoft Corporation. All rights reserved. Licensed under the MIT license.\n// See LICENSE in the project root for license information.\n\n// This is a workaround for https://github.com/eslint/eslint/issues/3458\n//\n// To correct how ESLint searches for plugin packages, add this line to the top of your project's .eslintrc.js file:\n//\n// require(\"@rushstack/eslint-patch/modern-module-resolution\");\n//\nconst path = require('path');\nconst fs = require('fs');\n\nconst isModuleResolutionError: (ex: unknown) => boolean = (ex) =>\n typeof ex === 'object' && !!ex && 'code' in ex && (ex as { code: unknown }).code === 'MODULE_NOT_FOUND';\n\n// Module path for eslintrc.cjs\n// Example: \".../@eslint/eslintrc/dist/eslintrc.cjs\"\nlet eslintrcBundlePath: string | undefined = undefined;\n\n// Module path for config-array-factory.js\n// Example: \".../@eslint/eslintrc/lib/config-array-factory\"\nlet configArrayFactoryPath: string | undefined = undefined;\n\n// Module path for relative-module-resolver.js\n// Example: \".../@eslint/eslintrc/lib/shared/relative-module-resolver\"\nlet moduleResolverPath: string | undefined = undefined;\n\n// Folder path where ESLint's package.json can be found\n// Example: \".../node_modules/eslint\"\nlet eslintFolder: string | undefined = undefined;\n\n// Probe for the ESLint >=8.0.0 layout:\nfor (let currentModule = module; ; ) {\n if (!eslintrcBundlePath) {\n // For ESLint >=8.0.0, all @eslint/eslintrc code is bundled at this path:\n // .../@eslint/eslintrc/dist/eslintrc.cjs\n try {\n const eslintrcFolder = path.dirname(\n require.resolve('@eslint/eslintrc/package.json', { paths: [currentModule.path] })\n );\n\n // Make sure we actually resolved the module in our call path\n // and not some other spurious dependency.\n if (path.join(eslintrcFolder, 'dist/eslintrc.cjs') === currentModule.filename) {\n eslintrcBundlePath = path.join(eslintrcFolder, 'dist/eslintrc.cjs');\n }\n } catch (ex: unknown) {\n // Module resolution failures are expected, as we're walking\n // up our require stack to look for eslint. All other errors\n // are rethrown.\n if (!isModuleResolutionError(ex)) {\n throw ex;\n }\n }\n } else {\n // Next look for a file in ESLint's folder\n // .../eslint/lib/cli-engine/cli-engine.js\n try {\n const eslintCandidateFolder = path.dirname(\n require.resolve('eslint/package.json', {\n paths: [currentModule.path]\n })\n );\n\n // Make sure we actually resolved the module in our call path\n // and not some other spurious dependency.\n if (path.join(eslintCandidateFolder, 'lib/cli-engine/cli-engine.js') === currentModule.filename) {\n eslintFolder = eslintCandidateFolder;\n break;\n }\n } catch (ex: unknown) {\n // Module resolution failures are expected, as we're walking\n // up our require stack to look for eslint. All other errors\n // are rethrown.\n if (!isModuleResolutionError(ex)) {\n throw ex;\n }\n }\n }\n\n if (!currentModule.parent) {\n break;\n }\n currentModule = currentModule.parent;\n}\n\nif (!eslintFolder) {\n // Probe for the ESLint >=7.8.0 layout:\n for (let currentModule = module; ; ) {\n if (!configArrayFactoryPath) {\n // For ESLint >=7.8.0, config-array-factory.js is at this path:\n // .../@eslint/eslintrc/lib/config-array-factory.js\n try {\n const eslintrcFolder = path.dirname(\n require.resolve('@eslint/eslintrc/package.json', {\n paths: [currentModule.path]\n })\n );\n\n if (path.join(eslintrcFolder, '/lib/config-array-factory.js') == currentModule.filename) {\n configArrayFactoryPath = path.join(eslintrcFolder, 'lib/config-array-factory.js');\n moduleResolverPath = path.join(eslintrcFolder, 'lib/shared/relative-module-resolver');\n }\n } catch (ex: unknown) {\n // Module resolution failures are expected, as we're walking\n // up our require stack to look for eslint. All other errors\n // are rethrown.\n if (!isModuleResolutionError(ex)) {\n throw ex;\n }\n }\n } else {\n // Next look for a file in ESLint's folder\n // .../eslint/lib/cli-engine/cli-engine.js\n try {\n const eslintCandidateFolder = path.dirname(\n require.resolve('eslint/package.json', {\n paths: [currentModule.path]\n })\n );\n\n if (path.join(eslintCandidateFolder, 'lib/cli-engine/cli-engine.js') == currentModule.filename) {\n eslintFolder = eslintCandidateFolder;\n break;\n }\n } catch (ex: unknown) {\n // Module resolution failures are expected, as we're walking\n // up our require stack to look for eslint. All other errors\n // are rethrown.\n if (!isModuleResolutionError(ex)) {\n throw ex;\n }\n }\n }\n\n if (!currentModule.parent) {\n break;\n }\n currentModule = currentModule.parent;\n }\n}\n\nif (!eslintFolder) {\n // Probe for the <7.8.0 layout:\n for (let currentModule = module; ; ) {\n // For ESLint <7.8.0, config-array-factory.js was at this path:\n // .../eslint/lib/cli-engine/config-array-factory.js\n if (/[\\\\/]eslint[\\\\/]lib[\\\\/]cli-engine[\\\\/]config-array-factory\\.js$/i.test(currentModule.filename)) {\n eslintFolder = path.join(path.dirname(currentModule.filename), '../..');\n configArrayFactoryPath = path.join(eslintFolder, 'lib/cli-engine/config-array-factory');\n moduleResolverPath = path.join(eslintFolder, 'lib/shared/relative-module-resolver');\n break;\n }\n\n if (!currentModule.parent) {\n // This was tested with ESLint 6.1.0 .. 7.12.1.\n throw new Error(\n 'Failed to patch ESLint because the calling module was not recognized.\\n' +\n 'If you are using a newer ESLint version that may be unsupported, please create a GitHub issue:\\n' +\n 'https://github.com/microsoft/rushstack/issues'\n );\n }\n currentModule = currentModule.parent;\n }\n}\n\n// Detect the ESLint package version\nconst eslintPackageJson = fs.readFileSync(path.join(eslintFolder, 'package.json')).toString();\nconst eslintPackageObject = JSON.parse(eslintPackageJson);\nconst eslintPackageVersion = eslintPackageObject.version;\nconst versionMatch = /^([0-9]+)\\./.exec(eslintPackageVersion); // parse the SemVer MAJOR part\nif (!versionMatch) {\n throw new Error('Unable to parse ESLint version: ' + eslintPackageVersion);\n}\nconst eslintMajorVersion = Number(versionMatch[1]);\nif (!(eslintMajorVersion >= 6 && eslintMajorVersion <= 8)) {\n throw new Error(\n 'The patch-eslint.js script has only been tested with ESLint version 6.x, 7.x, and 8.x.' +\n ` (Your version: ${eslintPackageVersion})\\n` +\n 'Consider reporting a GitHub issue:\\n' +\n 'https://github.com/microsoft/rushstack/issues'\n );\n}\n\nlet ConfigArrayFactory;\nif (eslintMajorVersion === 8) {\n ConfigArrayFactory = require(eslintrcBundlePath!).Legacy.ConfigArrayFactory;\n} else {\n ConfigArrayFactory = require(configArrayFactoryPath!).ConfigArrayFactory;\n}\nif (!ConfigArrayFactory.__patched) {\n ConfigArrayFactory.__patched = true;\n\n let ModuleResolver: { resolve: any };\n if (eslintMajorVersion === 8) {\n ModuleResolver = require(eslintrcBundlePath!).Legacy.ModuleResolver;\n } else {\n ModuleResolver = require(moduleResolverPath!);\n }\n const originalLoadPlugin = ConfigArrayFactory.prototype._loadPlugin;\n\n if (eslintMajorVersion === 6) {\n // ESLint 6.x\n ConfigArrayFactory.prototype._loadPlugin = function (\n name: string,\n importerPath: string,\n importerName: string\n ) {\n const originalResolve = ModuleResolver.resolve;\n try {\n ModuleResolver.resolve = function (moduleName: string, relativeToPath: string) {\n // resolve using importerPath instead of relativeToPath\n return originalResolve.call(this, moduleName, importerPath);\n };\n return originalLoadPlugin.apply(this, arguments);\n } finally {\n ModuleResolver.resolve = originalResolve;\n }\n };\n } else {\n // ESLint 7.x || 8.x\n ConfigArrayFactory.prototype._loadPlugin = function (name: string, ctx: Record<string, unknown>) {\n const originalResolve = ModuleResolver.resolve;\n try {\n ModuleResolver.resolve = function (moduleName: string, relativeToPath: string) {\n // resolve using ctx.filePath instead of relativeToPath\n return originalResolve.call(this, moduleName, ctx.filePath);\n };\n return originalLoadPlugin.apply(this, arguments);\n } finally {\n ModuleResolver.resolve = originalResolve;\n }\n };\n }\n}\n"]} |