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

Add an option to transform specific libraries inside node_modules #124

Open
efoken opened this issue Jan 2, 2025 · 6 comments
Open

Add an option to transform specific libraries inside node_modules #124

efoken opened this issue Jan 2, 2025 · 6 comments
Labels
cat: monorepo 🔱 Issues related to usage of wyw-in-js in monorepo feature: proposal 💬 New feature proposal that needs to be discussed

Comments

@efoken
Copy link

efoken commented Jan 2, 2025

Describe the feature

I am working on a library leveraging WyW, and also have a Design System monorepo set up which uses that library. While working with Design System libraries, it's often the case that you want to transform those, also when installed as dependencies.

Therefore it would be nice to have an options like transformLibraries: ['your-design-lib'] that can be passed to WyW plugins.

Possible implementations

wyw({
  transformLibraries: ['your-design-lib'],
})

Would transform the your-design-lib package inside node_modules.

I already have implemented this by copying the whole Vite plugin, so I can contribute if you like.

@efoken efoken added the feature: proposal 💬 New feature proposal that needs to be discussed label Jan 2, 2025
@github-actions github-actions bot added cat: monorepo 🔱 Issues related to usage of wyw-in-js in monorepo needs: triage 🏷 Issue needs to be checked and prioritized and removed needs: triage 🏷 Issue needs to be checked and prioritized labels Jan 2, 2025
@layershifter
Copy link
Collaborator

@efoken updating include & exclude patterns to include /node_modules/ should do it, no?

@efoken
Copy link
Author

efoken commented Jan 2, 2025

No, because you are checking if the path contains node_modules, for example in Vite plugin: https://github.com/Anber/wyw-in-js/blob/main/packages/vite/src/index.ts#L111 and esbuild: https://github.com/Anber/wyw-in-js/blob/main/packages/esbuild/src/index.ts#L99

EDIT: I changed Vite plugin and changed that lines to:

if (
  (url.includes('node_modules') &&
    !transformLibraries.some((libName: string) => url.includes(libName))) ||
  !filter(id) ||
  id in cssLookup
) {
  return;
}

@layershifter
Copy link
Collaborator

@efoken good point, I see. We need to allow transforming of node_modules for sure (I have the same requirement for Fluent UI) 👍

So, I would start with transformLibraries: boolean and leverage existing filters, WDYT?

@efoken
Copy link
Author

efoken commented Jan 2, 2025

@layershifter of course, boolean would be an option, just to bypass the node_modules filter. But maybe array is also a good idea, because then you can only allow specific modules to be transformed – I mean performance-wise it's better, no?

@layershifter
Copy link
Collaborator

But maybe array is also a good idea, because then you can only allow specific modules to be transformed – I mean performance-wise it's better, no?

@efoken my idea is that once we exclude a condition for node_modules (via a new option transformLibraries), we allow to use exclude & include filters and the flexibility will be already in place.

@efoken
Copy link
Author

efoken commented Jan 3, 2025

@layershifter you're right, good idea 👍

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
cat: monorepo 🔱 Issues related to usage of wyw-in-js in monorepo feature: proposal 💬 New feature proposal that needs to be discussed
Projects
None yet
Development

No branches or pull requests

2 participants