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

[Fix] no-extraneous-dependencies: add ESM intermediate package.json support #2121

Merged
merged 1 commit into from Jun 18, 2021

Conversation

paztis
Copy link

@paztis paztis commented Jun 8, 2021

No description provided.

@coveralls
Copy link

Coverage Status

Coverage increased (+2.3%) to 82.607% when pulling ff2bcf0 on paztis:master into 4079482 on benmosher:master.

1 similar comment
@coveralls
Copy link

Coverage Status

Coverage increased (+2.3%) to 82.607% when pulling ff2bcf0 on paztis:master into 4079482 on benmosher:master.

@coveralls
Copy link

coveralls commented Jun 8, 2021

Coverage Status

Coverage increased (+2.3%) to 82.621% when pulling 9552589 on paztis:master into 4079482 on benmosher:master.

@ljharb
Copy link
Member

ljharb commented Jun 8, 2021

fix looks good; now we just need a regression test :-)

@ljharb ljharb marked this pull request as draft June 8, 2021 14:50
@paztis
Copy link
Author

paztis commented Jun 8, 2021 via email

@ljharb
Copy link
Member

ljharb commented Jun 8, 2021

Hopefully the issue OP can provide repro details

@paztis
Copy link
Author

paztis commented Jun 10, 2021

correct fix with test case added now, as described by @ertrzyiks in #2120

Copy link
Contributor

@ertrzyiks ertrzyiks left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Works like a charm in my case 👍

@ljharb
Copy link
Member

ljharb commented Jun 12, 2021

@paztis thanks! I've rebased this (please reset your local master to the remote one before making further changes, so the rebase isn't lost), but the tests don't fail when the changes are backed out, so they're not actually testing the changes.

@paztis
Copy link
Author

paztis commented Jun 14, 2021

You wait an action from me to do the merge ? Or it is ok ?

@benjamingr
Copy link

@paztis what Jordan is saying is that the PR is good but the test isn't since if he reverts those changes (but keeps the test) the test passes.

@JCB-K
Copy link

JCB-K commented Jun 14, 2021

Hi! 👋 . I adjusted the tests on this branch so that they're true regression tests. I made a PR against @paztis 's fork, so if you merge that PR into paztis:master, and then merge this PR into benmosher:master (after review), it should be all good. not sure if that's the easiest way to handle this?

@ljharb ljharb reopened this Jun 14, 2021
@ljharb
Copy link
Member

ljharb commented Jun 14, 2021

I’ll check later today; if the tests fail without the fix, and pass with it, we’re good to go :-)

@paztis
Copy link
Author

paztis commented Jun 14, 2021

I've added a valid test that is now passing without the fix.
The previous one was only passing thanks to the getModuleOriginalName() case that was finding the correct name first.
Nw with the webpack alias added, the getModuleOriginalName() found the name "alias" and let the real moduleName resolution do the job correctly.

@paztis
Copy link
Author

paztis commented Jun 14, 2021

Hi! 👋 . I adjusted the tests on this branch so that they're true regression tests. I made a PR against @paztis 's fork, so if you merge that PR into paztis:master, and then merge this PR into benmosher:master (after review), it should be all good. not sure if that's the easiest way to handle this?

Sorry just see you message after I rebate from upstream to avoir rebate unit test failure...

So I delete and recommit all my job.
You can look at my current unit test and reel me if it is enough. You own can be better perhaps

@ljharb
Copy link
Member

ljharb commented Jun 18, 2021

@paztis unfortunately the tests now seem to pass even without the fix. We can't merge this until there's tests that fail without the fix.

@paztis
Copy link
Author

paztis commented Jun 18, 2021

Really ? They were failing with a null pointer on my side...

@github-actions github-actions bot force-pushed the master branch 2 times, most recently from cae387f to 532e0ec Compare June 18, 2021 07:49
@paztis
Copy link
Author

paztis commented Jun 18, 2021

Ok again update the unit tests (and simplify also the process)
If you take my new unit tests without my code fixes, you must have this exception

AssertionError [ERR_ASSERTION] [ERR_ASSERTION]: Should have no errors but had 1: [

{
ruleId: 'no-extraneous-dependencies',
severity: 1,
message: "'alias' should be listed in the project's dependencies. Run 'npm i -S alias' to add it",
line: 1,
column: 1,
nodeType: 'ImportDeclaration',
endLine: 1,
endColumn: 39
}
]

I again face rebase problematics... sorry for that ^^

@JCB-K
Copy link

JCB-K commented Jun 18, 2021

Shouldn't the test fail with TypeError: Cannot read property 'split' of undefined if the fix isn't applied? Since that's the bug that this PR addresses.

@paztis
Copy link
Author

paztis commented Jun 18, 2021

Yes it is supposed

@JCB-K
Copy link

JCB-K commented Jun 18, 2021

@paztis the test I made does just that:

› yarn test
  2100 passing (10s)
  1 failing

  1) no-extraneous-dependencies invalid import "esm-package-not-in-pkg-json/esm-module";:
     TypeError: Cannot read property 'split' of undefined
Occurred while linting /Users/jacob/Mentimeter/eslint-plugin-import/tests/files/foo.js:1
      at checkDependencyDeclaration (src/rules/no-extraneous-dependencies.js:133:40)
      at reportIfMissing (src/rules/no-extraneous-dependencies.js:187:38)
      at commonjs (src/rules/no-extraneous-dependencies.js:264:7)
      at checkSourceValue (utils/moduleVisitor.js:29:5)
      at checkSource (utils/moduleVisitor.js:34:5)
      at node_modules/eslint/lib/linter/safe-emitter.js:45:58
      at Array.forEach (<anonymous>)
      at Object.emit (node_modules/eslint/lib/linter/safe-emitter.js:45:38)
      at NodeEventGenerator.applySelector (node_modules/eslint/lib/linter/node-event-generator.js:293:26)
      at NodeEventGenerator.applySelectors (node_modules/eslint/lib/linter/node-event-generator.js:322:22)
      at NodeEventGenerator.enterNode (node_modules/eslint/lib/linter/node-event-generator.js:336:14)
      at CodePathAnalyzer.enterNode (node_modules/eslint/lib/linter/code-path-analysis/code-path-analyzer.js:711:23)
      at node_modules/eslint/lib/linter/linter.js:956:32
      at Array.forEach (<anonymous>)
      at runRules (node_modules/eslint/lib/linter/linter.js:951:15)
      at Linter._verifyWithoutProcessors (node_modules/eslint/lib/linter/linter.js:1177:31)
      at Linter.verify (node_modules/eslint/lib/linter/linter.js:1241:21)
      at runRuleForItem (node_modules/eslint/lib/rule-tester/rule-tester.js:560:37)
      at testInvalidTemplate (node_modules/eslint/lib/rule-tester/rule-tester.js:658:28)
      at Context.<anonymous> (node_modules/eslint/lib/rule-tester/rule-tester.js:897:25)
      at processImmediate (internal/timers.js:461:21)

I've separated the commits into 1 commit that adds the test, and 1 commit that contains your change: feel free to cherry-pick from this branch however you like. https://github.com/JCB-K/eslint-plugin-import/commits/fix-tests

@paztis
Copy link
Author

paztis commented Jun 18, 2021

@JCB-K the branch you show me didn't include the last changes, nor the last unit tests

@paztis
Copy link
Author

paztis commented Jun 18, 2021

there's 2 fixes in fact: one about the NPE in case of undefined name, and another about a recursion in the name search in case of intermediary package.json found in esm modules.

@JCB-K
Copy link

JCB-K commented Jun 18, 2021

Indeed and both are still fixed on that branch, and its up-to-date with benmosher:master. Either way, feel free to take the tests as you see fit, either by merging JCB-K:fix-tests into your branch, into benmosher:master, or by just copying over the tests manually. I'm just happy to help out on a bugfix here as it affects me too 🙂

@ljharb ljharb marked this pull request as ready for review June 18, 2021 15:29
@ljharb ljharb changed the title Add a split NPE check for defect #2120 [Fix] no-extraneous-dependencies: add ESM intermediate package.json support Jun 18, 2021
@ljharb ljharb merged commit b3d8c0c into import-js:master Jun 18, 2021
@akphi akphi mentioned this pull request Jun 23, 2021
17 tasks
@timleslie
Copy link

Hi @ljharb, I was wondering if there are plans to ship a new release which contains this fix? This bug currently bites us when we refresh our yarn.lock with ^ range semver, so it'd be nice to be able to get over that speed bump. We can manually work around this, so it's definitely not a blocker, but it'd be a nice to smooth out our maintenance processes. Thanks for you work on this package!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Development

Successfully merging this pull request may close these issues.

None yet

7 participants