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

change default aliases to be more like node's subpath aliases #5847

Closed
weepy opened this issue Aug 8, 2022 · 6 comments
Closed

change default aliases to be more like node's subpath aliases #5847

weepy opened this issue Aug 8, 2022 · 6 comments

Comments

@weepy
Copy link

weepy commented Aug 8, 2022

Describe the problem

I want to run a node test runner to test parts of my application, but it doesn't understand the "$lib" type aliases.
I tried the node package module-alias but it appears difficult to use with es6.
Node already has support for subpath aliases, but they must begin with "#", so currently I am changing the sveltekit to use "#lib" via :

vite: {
			resolve: {
				alias: {
					'#lib': path.resolve('./src/lib')
				}
			}
		}

which is not a bad solution, but perhaps parity with node should be the default?

Describe the proposed solution

"$lib" changed to "#lib"

Alternatives considered

No response

Importance

would make my life easier

Additional Information

No response

@bluwy
Copy link
Member

bluwy commented Aug 8, 2022

I think this should be supported via vitejs/vite#7385 first so we don't mix Vite's aliases with Node's aliases.

@benmccann
Copy link
Member

Looks like there's a PR for that one, but it's in need of a review: vitejs/vite#7770

@benmccann
Copy link
Member

Vite aliases are very nice because you can override them to provide no-ops or your own behavior for $app/navigation, $app/stores, etc. when doing things like using Storybook, testing, etc. I'm not sure whether you'd be able to do that with #app. Perhaps you could still override with a Vite alias, but I'd want to make sure.

@Rich-Harris
Copy link
Member

I'm hesitant to make this change, because it only really makes sense for $lib — not $env or $app — and it would feel weird to have #lib alongside $app/....

In general, Vite apps are going to contain stuff that isn't Node-compatible — import.meta.glob, .css imports, and all sorts of other things — so I'm not sure if there's all that much value in making a change that makes it possible for Node test runners to run in a slightly larger subset of cases (those involving $lib) than is currently the case, given that it's always going to be much less than 100%.

I think a combination of these strategies is likely to yield better results:

  • Using Vitest, or another Vite-aware test runner
  • Only unit-testing code inside lib, rather than trying to unit test code that relies on lib
  • Leaning more on integration tests than unit tests

@weepy
Copy link
Author

weepy commented Aug 25, 2022 via email

@Rich-Harris
Copy link
Member

I haven't really put it through its paces, but I'm very impressed with what I've seen so far of Vitest. We're considering adding it as an option when you create a new app: #5708

Will close this issue then — thanks

@Rich-Harris Rich-Harris closed this as not planned Won't fix, can't repro, duplicate, stale Aug 25, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

4 participants