@iadvize-oss/eslint-patch
Advanced tools
Comparing version 0.0.1-beta.0 to 0.0.1-beta.0-canary-438ce57-1582016057742
49
index.js
@@ -0,6 +1,29 @@ | ||
/* eslint-disable import/no-dynamic-require, no-underscore-dangle */ | ||
// This is a workaround for https://github.com/eslint/eslint/issues/3458 | ||
// @see https://github.com/eslint/eslint/issues/3458#issuecomment-516716165 | ||
const path = require('path'); | ||
const eslintFolder = path.join(path.dirname(require.resolve('eslint')), '..'); | ||
let currentModule = module; | ||
while ( | ||
!/[\\/]eslint[\\/]lib[\\/]cli-engine[\\/]config-array-factory\.js/i.test( | ||
currentModule.filename, | ||
) | ||
) { | ||
if (!currentModule.parent) { | ||
// This was tested with ESLint 6.1.0; other versions may not work | ||
throw new Error( | ||
'Failed to patch ESLint because the calling module was not recognized', | ||
); | ||
} | ||
currentModule = currentModule.parent; | ||
} | ||
const eslintFolder = path.join(path.dirname(currentModule.filename), '../..'); | ||
const configArrayFactoryPath = path.join( | ||
eslintFolder, | ||
'lib/cli-engine/config-array-factory', | ||
); | ||
const configArrayFactoryModule = require(configArrayFactoryPath); | ||
const moduleResolverPath = path.join( | ||
@@ -10,11 +33,21 @@ eslintFolder, | ||
); | ||
// eslint-disable-next-line import/no-dynamic-require | ||
const ModuleResolver = require(moduleResolverPath); | ||
ModuleResolver.resolve = function(moduleName) { | ||
// const p = require(`${moduleName}/package.json`) | ||
const modulePath = require.resolve(moduleName); | ||
return modulePath; | ||
const originalLoadPlugin = | ||
configArrayFactoryModule.ConfigArrayFactory.prototype._loadPlugin; | ||
configArrayFactoryModule.ConfigArrayFactory.prototype._loadPlugin = function( | ||
name, | ||
importerPath, | ||
) { | ||
const originalResolve = ModuleResolver.resolve; | ||
try { | ||
ModuleResolver.resolve = function(moduleName) { | ||
// resolve using importerPath instead of relativeToPath | ||
return originalResolve.call(this, moduleName, importerPath); | ||
}; | ||
// eslint-disable-next-line prefer-rest-params | ||
return originalLoadPlugin.apply(this, arguments); | ||
} finally { | ||
ModuleResolver.resolve = originalResolve; | ||
} | ||
}; |
{ | ||
"name": "@iadvize-oss/eslint-patch", | ||
"version": "0.0.1-beta.0", | ||
"version": "0.0.1-beta.0-canary-438ce57-1582016057742", | ||
"description": "Workaround for eslint plugin resolution", | ||
@@ -5,0 +5,0 @@ "main": "index.js", |
@@ -10,3 +10,3 @@ # @iadvize/eslint-patch | ||
```bash | ||
npm add --dev @iadvize-oss/eslint-patch | ||
npm add --save-dev @iadvize-oss/eslint-patch | ||
``` | ||
@@ -13,0 +13,0 @@ |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
Dynamic require
Supply chain riskDynamic require can indicate the package is performing dangerous or unsafe dynamic code execution.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
Dynamic require
Supply chain riskDynamic require can indicate the package is performing dangerous or unsafe dynamic code execution.
Found 1 instance in 1 package
3590
58