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

Check for node_modules presence instead of isInternal for Eleventy plugin #462

Merged
merged 3 commits into from
Jan 21, 2024
Merged

Check for node_modules presence instead of isInternal for Eleventy plugin #462

merged 3 commits into from
Jan 21, 2024

Conversation

uncenter
Copy link
Contributor

@uncenter uncenter commented Jan 19, 2024

Resolves #460 (comment). Would love to hear your thoughts on this.

@uncenter uncenter changed the title Check for node_modules presence instead of isInternal Check for node_modules presence instead of isInternal for Eleventy plugin Jan 19, 2024
@webpro
Copy link
Collaborator

webpro commented Jan 19, 2024

Great! This is the fiddling that we sometimes need to get right. Ideally we don't need to actually glob or resolve modules here, because it could degrade performance and/or duplicate unnecessary work. But I've done it before, sometimes there's no way around it:

https://github.com/webpro/knip/blob/main/packages/knip/src/plugins/vitest/index.ts#L27-L33

@webpro
Copy link
Collaborator

webpro commented Jan 19, 2024

Happy to merge this! Any chance you could add something to an existing test/fixture to prevent regression later on?

@uncenter
Copy link
Contributor Author

But I've done it before, sometimes there's no way around it:

Are you suggesting for me to do this? Not sure what this means.

Any chance you could add something to an existing test/fixture to prevent regression later on?

Yep, I'm trying to think of how to do it...

@webpro
Copy link
Collaborator

webpro commented Jan 19, 2024

Are you suggesting for me to do this? Not sure what this means.

No, sorry, just saying it's sometimes necessary and this is an example of when/how.

Yep, I'm trying to think of how to do it...

What I often try to do is add something to a fixture that makes the related test fail. Then change the implementation to make the test pass. In this case you could add a addPassthroughCopy() call with that file (src/_includes/components/throbber.js or simpler in an existing folder).

@uncenter
Copy link
Contributor Author

Still not sure I get it. I'm not even positive I know why that was happening. How did I even realize this was an issue? 😆

@webpro
Copy link
Collaborator

webpro commented Jan 20, 2024

In the main branch, you can add something like this to e.g. fixtures/plugins/eleventy2/.eleventy.js:

eleventyConfig.addPassthroughCopy({
  'src/_includes/components/throbber.js': '/assets/throbber.js',
});

Run the test:

❯ npx tsx test/plugins/eleventy2.test.ts 
✖ Find dependencies in Eleventy configuration (static) (298.531542ms)
  AssertionError [ERR_ASSERTION]: Expected values to be strictly deep-equal:
  + actual - expected ... Lines skipped
  
    {
      binaries: 0,
  ...
      total: 4,
      types: 0,
  +   unlisted: 1,
  -   unlisted: 0,
      unresolved: 0
    }

Or run knip in that fixtures directory:

$ knip
Unlisted dependencies (1)
src/_includes/components/throbber.js  .eleventy.js

And so on :)

@uncenter
Copy link
Contributor Author

Ah, right, I forgot about that kind of test. Thank you, I'll do that.

@uncenter
Copy link
Contributor Author

Should be good now, I added that line and ran tests with the changes in this PR (fine) and without (error).

@webpro webpro merged commit c0b23b5 into webpro-nl:main Jan 21, 2024
8 of 11 checks passed
@uncenter uncenter deleted the fix/eleventy branch January 21, 2024 19:18
@webpro
Copy link
Collaborator

webpro commented Jan 21, 2024

🚀 This pull request is included in v4.2.0. See Release 4.2.0 for release notes.

@webpro
Copy link
Collaborator

webpro commented Jan 21, 2024

Thanks! I've also added that file to reflect it being "used".

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

Successfully merging this pull request may close these issues.

2 participants