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

I hope to support generating type declarations by dividing modules based on files. #388

Open
3 tasks done
ListeningRift opened this issue May 31, 2023 · 0 comments
Open
3 tasks done
Labels
enhancement New feature or request

Comments

@ListeningRift
Copy link

Clear and concise description of the problem

Now, when I have the dirs configuration option, this plugin will automatically scan all exports in the files and generate type declarations for each exported content. However, sometimes I don't want to do this because it can directly pollute the namespace in certain scenarios. Therefore, I hope this plugin can support generating type declarations by dividing modules based on files.

Examples, if I have a file like this

// src/utils/image.ts
export function getImageSize() {
  return [10, 10];
}

and the vite.config.ts like this

export default defineConfig({
  plugins: [
    vue(),
    AutoImport({
      dirs: ['src/utils/**'],
    }),
  ],
});

It will generate the dts file like this

/* eslint-disable */
/* prettier-ignore */
// @ts-nocheck
// Generated by unplugin-auto-import
export {}
declare global {
  const getImageSize: typeof import('./utils/image')['getImageSize']
}

But I want

declare global {
  const image: typeof import('./utils/image')
}

If it can be done, then I can use it like this

const a = image.getImageSize()

I think this way, I don't have to worry about namespace issues anymore.

Suggested solution

I think it's able to add a configuration option for each path in dirs like this

export default defineConfig({
  plugins: [
    vue(),
    AutoImport({
      dts: 'src/auto-imports.d.ts',
      dirs: [
        {
          dir: 'src/utils/**',
          exportAllByFileName: true,
        },
      ],
    }),
  ],
});

If exportAllByFileName is true, it will generate dts file just as I said above.

Alternative

No response

Additional context

I tried to make some adjustments and would appreciate it if you could take a look to see if it meets the standards and requirements. Thank you very much.

Validations

@ListeningRift ListeningRift added the enhancement New feature or request label May 31, 2023
ListeningRift pushed a commit to ListeningRift/unplugin-auto-import that referenced this issue Jun 1, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

1 participant