Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

v2.20.2 break no-extraneous-dependencies with webpack alias #1712

Closed
githoniel opened this issue Mar 31, 2020 · 7 comments
Closed

v2.20.2 break no-extraneous-dependencies with webpack alias #1712

githoniel opened this issue Mar 31, 2020 · 7 comments

Comments

@githoniel
Copy link

githoniel commented Mar 31, 2020

OS: Microsoft Windows [Version 10.0.18362.720]
Node: v10.14.2
ESLINT: v5.16.0

In my webpack config, I set a alias name for one of our scoped package for short

alias: {
  'fish': '@sdp.nd/fish'
}

In eslint-plugin-import@2.20.1, it works well while I got no-extraneous-dependencies in eslint-plugin-import@2.20.2.

import { Button } from 'fish'

After debug, I found these code make things different

// src/core/importType.js
// Line 31
// v2.20.2
// subPath = 'node_modules'
// path = 'C:\Users\yj\Desktop\test-collection\demo-base\node_modules\@sdp.nd\fish\es\index.js'
function isSubpath(subpath, path) {
  const normPath = path.replace(/\\/g, '/')
  const normSubpath = subpath.replace(/\\/g, '/').replace(/\/$/, '')
  if (normSubpath.length === 0) {
    return false
  }
  const left = normPath.indexOf(normSubpath)
  const right = left + normSubpath.length
  return left !== -1 &&
        (left === 0 || normSubpath[0] !== '/' && normPath[left - 1] === '/') &&
        (right >= normPath.length || normPath[right] === '/')
}

isSubpath return true in v2.20.2 while return false in v2.20.1.

I found both v2.20.1 and v2.20.2 will report no-extraneous-dependencies on ubuntu and I think v2.20.2 is right, it just fix path error in Window.

I found that

// lib\rules\no-extraneous-dependencies.js
// line 124
const resolved = resolve(name, context) // name == 'fish'
if (!resolved) { return } // resolve = 'C:\Users\yj\Desktop\base-demo-0317\node_modules\@sdp.nd\fish\es\index.js'

const splitName = name.split('/')
const packageName = splitName[0][0] === '@'
    ? splitName.slice(0, 2).join('/')
    : splitName[0]

packageName should be @sdp.nd\fish not fish in this case.

@ljharb
Copy link
Member

ljharb commented Mar 31, 2020

Thanks; a PR with a failing test case would be helpful.

@madisabel
Copy link

Confirming - starting from v2.20.1 path aliases are not working. I've been actually defining path aliases in tsconfig.json file which have been resolved perfectly until v2.20.1

@br0p0p
Copy link

br0p0p commented Jul 6, 2020

I'm experiencing this issue as well. Reverting to v2.20.0 fixed it for me.

@IShotTheSheriff
Copy link

Still experiencing this issue with 2.22.1, thanks @br0p0p for advice to downgrading to 2.20.0.

Hope it will be addressed at some point.

@githoniel
Copy link
Author

@IShotTheSheriff 2.20.0 will always skip alias detect in window and will report error on other platform.
hope this will be fix soon~~~

@vvanpo
Copy link

vvanpo commented May 21, 2021

I've had this plugin pinned at v2.20.0 for a long time due to this bug, but tried upgrading to v2.23.2 and that appears to fix it. @githoniel could you confirm whether this bug is still reproducible with the latest version? Otherwise I think we can close this.

@ljharb
Copy link
Member

ljharb commented May 21, 2021

I'll close it for now, but will be happy to reopen if anyone's still experiencing problems.

@ljharb ljharb closed this as completed May 21, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Development

No branches or pull requests

6 participants