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

Support for nested exposures #4

Closed
DenisKent opened this issue Jul 16, 2021 · 4 comments
Closed

Support for nested exposures #4

DenisKent opened this issue Jul 16, 2021 · 4 comments

Comments

@DenisKent
Copy link

Hey, I would like to my MF exposes object to look like:

exposes: {
  "./components/Button": "./src/components/Button/Button.tsx",
  "./components/Input": "./src/components/Input/Input.tsx",
  "./utils/time": "./src/utils/time.tsx"
}

It doesn't work as expected, no files are created. When I run a build, I get the following message:

Skip lib\src\components\Button\Button.tsx
...
  1. It might be worth showing the error message within the catch statement so the user knows why something wasn't generated.
  2. The error I'm getting is: ENOENT: no such file or directory, open 'lib\dist\lib\components\Button.d.ts'. It looks to be caused by fs.writeFileSync because the \lib\components directory does not exist.

dts-loader/src/index.ts

Lines 117 to 130 in 621492b

for (const [key, value] of Object.entries(loaderOptions.exposes)) {
if (key && value) {
const entryPath = path.resolve(cwd, value)
if (entryPath === fileName) {
const moduleFilename = `${key}.d.ts`
const modulePath = path.resolve(
cwd,
`${loaderOptions.typesOutputDir}/${loaderOptions.name}`
)
fs.writeFileSync(
path.resolve(modulePath, moduleFilename),
`export * from './${path.relative(
path.relative(cwd, modulePath),
o.name.replace('.d.ts', '')

@ruanyl
Copy link
Owner

ruanyl commented Jul 16, 2021

@DenisKent right, it doesn't expect to have a path as the exposes configuration key at the moment. I'll try to look into it

@DenisKent
Copy link
Author

Thanks @ruanyl . Happy to work on it myself too btw. One thing that makes me hesitate is that I've not found a good way of testing updated code in action. Do you know how one might test a new branch of a webpack loader on a webpack config?

@fabiomilheiro
Copy link

I faced a similar problem but the resolution is quite simple, actually.
You can refactor your code to look like this:

exposes: {
  "./components/Button": "./src/Button.tsx", // which exports ./src/components/Button/Button.tsx
  "./components/Input": "./src/Input.tsx", // which exports ./src/components/Input/Input.tsx
  "./utils/time": "./src/time.tsx" // which exports ./src/utils/time.tsx
}

Hope it helps.

@ruanyl ruanyl closed this as completed in 557e3db Jul 25, 2021
@ruanyl
Copy link
Owner

ruanyl commented Jul 25, 2021

@DenisKent @fabiomilheiro Thanks for bringing this up, this is now supported in v0.1.2

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

No branches or pull requests

3 participants