Skip to content
This repository has been archived by the owner on Jul 29, 2022. It is now read-only.

fix: return absolute paths if one of the globs is absolute #7

Merged
merged 6 commits into from Mar 30, 2022

Conversation

brillout
Copy link
Contributor

Proposal for #6.

@brillout
Copy link
Contributor Author

I'll add docs to the readme if we end up merging this.

@brillout
Copy link
Contributor Author

I updated the PR to remove the filePathsRelativeToRoot option.

I don't see a use case for configuring this.

Also, the user can always change the glob to fit what he wants:

// If the user wants the file paths to be relative to root:
import.meta.importGlob('/path/to/*.js')
// Post-transform
{ "/path/to/some.js": () => import(/* ... */) }

// If the user wants the file paths to be relative to `__dirname`:
import.meta.importGlob('../../path/to/*.js')
// Post-transform
{ "../../path/to/some.js": () => import(/* ... */) }

@antfu
Copy link
Owner

antfu commented Mar 30, 2022

BTW, we have this vitejs/vite#6526 in Vite, which I haven't implemented in this plugin. Are you aware of it, and what do you think how it should affects this implementation?

@antfu
Copy link
Owner

antfu commented Mar 30, 2022

For multiple globs, do you think it makes sense for us to return the absolute paths if one of the globs is absolute?

import.meta.importGlob(['/path/to/*.js', './*.ts')
// -->
{ 
  "/path/to/some.js": () => import(/* ... */),
  "/src/foo.ts": () => import(/* ... */)
}

@brillout
Copy link
Contributor Author

For multiple globs, do you think it makes sense for us to return the absolute paths if one of the globs is absolute?

import.meta.importGlob(['/path/to/*.js', './*.ts')
// -->
{ 
  "/path/to/some.js": () => import(/* ... */),
  "/src/foo.ts": () => import(/* ... */)
}

I'm not super happy about this, but I don't see an alternative.

@brillout
Copy link
Contributor Author

BTW, we have this vitejs/vite#6526 in Vite, which I haven't implemented in this plugin. Are you aware of it, and what do you think how it should affects this implementation

👍. I'd say: it's a nice-to-have we can implement later.

I'd propose to get vite-plugin-glob out to more users, experiment, then we can see how/if we want to implement such nice-to-haves.

@antfu
Copy link
Owner

antfu commented Mar 30, 2022

I will make a tweet later :)

@brillout
Copy link
Contributor Author

Exciting 😀.

Btw, I'm going to release the new vps major 0.4.0 as soon as we merge the file extension restoration thing. (It's the only blocker for vps.)

@antfu antfu changed the title Improve file paths fix: return absolute paths if one of the globs is absolute Mar 30, 2022
@antfu antfu merged commit 394c0c9 into antfu:main Mar 30, 2022
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants