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

[Feature Request]: Auto generate dts file dir #515

Open
tmg0 opened this issue Sep 25, 2024 · 3 comments · May be fixed by #516
Open

[Feature Request]: Auto generate dts file dir #515

tmg0 opened this issue Sep 25, 2024 · 3 comments · May be fixed by #516
Labels
⚡️ enhancement improvement over an existing feature

Comments

@tmg0
Copy link

tmg0 commented Sep 25, 2024

This is a really awesome package, I have been using it in my vite project with default options, it works great. But there are some options that confuse me.

options.dts support to use a string as a path of target dts file path, I would love to adding support for auto generate dir if does not exist. And maybe we can use fs-extra ensure the path in context ? or impl a ensureDir function manully

(I have created a demo for this

if (dts) {
  const content = generateDTS()
  if (lastDTS !== content) {
    await fse.ensureDir(dirname(dts))
    await fs.writeFile(dts, content, 'utf-8')
    logger.timeLog('writeConfigFiles', 'wrote dts file')
    lastDTS = content
  }
}

If needed, I would be happy to provide a PR for this issue.

Thank you for your consideration.

@posva
Copy link
Owner

posva commented Sep 25, 2024

Thanks! I’m glad you like it!
It should be simple to add but what folder to you want to write to that doesn’t exist?
if implemented, I would prefer to reuse any existing dep

@posva posva added the ⚡️ enhancement improvement over an existing feature label Sep 25, 2024
@tmg0
Copy link
Author

tmg0 commented Sep 25, 2024

Thank you for your reply!

I'm trying to add all dts files to a single folder like .types, and here is my config file:

import { defineConfig } from 'vite'
import vue from '@vitejs/plugin-vue'
import vueRouter from 'unplugin-vue-router/vite'

// https://vitejs.dev/config/
export default defineConfig({
  plugins: [
    vueRouter({ dts: '.types/typed-router.d.ts' }),
    vue()
  ],
})

But when I run the build script, it seems there are some errors: ENOENT: no such file or directory. It seems necessary to manually create the parent directory.

So I'm considering if it's possible to implement ensuring the folder exists in this plugin.

Maybe use native node fs module is a better way? like: await fs.mkdir(dirname(dts), { recursive: true })

Copy link
Owner

posva commented Sep 25, 2024

Using the native module sounds good

@tmg0 tmg0 linked a pull request Sep 26, 2024 that will close this issue
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
⚡️ enhancement improvement over an existing feature
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants