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

fix: imporove dir match && add glob exclude #392

Merged
merged 3 commits into from
Jul 4, 2023
Merged

fix: imporove dir match && add glob exclude #392

merged 3 commits into from
Jul 4, 2023

Conversation

lishaobos
Copy link
Collaborator

Description

config:

options.dirs = ['src/utils']

dir structure:

  • src
    • utils
      • test.ts

when i add new api and export in test.ts, dts can not update,
because minimatch('src/utils/test.ts', 'src/utils') return false

Linked Issues

Additional context

@antfu
Copy link
Member

antfu commented Jun 12, 2023

I feel it might be better to normalize the glob instead. Say a dir without any wildcard, like src/utils to src/utils/** and pass to the match

@lishaobos
Copy link
Collaborator Author

I feel it might be better to normalize the glob instead. Say a dir without any wildcard, like src/utils to src/utils/** and pass to the match

Sorry, did you mean we will normalize the input?

If the user input is 'src/utils', I will transform it to 'src/utils/*.xx'.

@antfu
Copy link
Member

antfu commented Jun 12, 2023

Something like const dirGlobs = ctx.dirs.map(i => i.includes('*') ? i : join(i, '*.{ts,js,...}') based on user config.

@lishaobos
Copy link
Collaborator Author

lishaobos commented Jun 12, 2023

hh,ok

@lishaobos lishaobos requested a review from antfu June 14, 2023 03:15
src/core/ctx.ts Outdated
@@ -19,7 +19,8 @@ export function createContext(options: Options = {}, root = process.cwd()) {
dts: preferDTS = isPackageExists('typescript'),
} = options

const dirs = options.dirs?.map(dir => resolve(root, dir))
const filePattern = '*.{tsx,jsx,ts,js,mjs,cjs,mts,cts}'
const dirs = options.dirs?.map(dir => resolve(root, dir, !dir.includes('*') ? filePattern : ''))
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This does not seem to handle ! right? Can we extract this as a function and do some unit test?

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

yes, unplugin-vue-components already has pr: unplugin/unplugin-vue-components#645

if that pr passed, I will change unplugin-auto-import code

Copy link
Collaborator Author

@lishaobos lishaobos Jun 14, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@antfu I'm afraid this pr won't pass, so i am waiting.

@lishaobos lishaobos changed the title fix: dir match fix: imporove dir match && add glob exclude Jun 15, 2023
@lishaobos
Copy link
Collaborator Author

scanDirExports from unimport can not work with glob exclude, so I write a new one.

@lishaobos lishaobos requested a review from antfu June 15, 2023 07:01
@antfu antfu merged commit b87654f into main Jul 4, 2023
4 checks passed
@antfu antfu deleted the fix/dir-match branch July 4, 2023 08:42
@antfu
Copy link
Member

antfu commented Jul 4, 2023

@lishaobos looks good. If you want, you could send a PR to unimport so we could remove the workaround here.

@lishaobos
Copy link
Collaborator Author

@lishaobos looks good. If you want, you could send a PR to unimport so we could remove the workaround here.

of course, i will send a pr later.

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.

None yet

2 participants