@@ -27,21 +27,14 @@ and manually modify.
27
27
Despite the magic of Path aliases, they are actually a standard ` package.json `
28
28
supported feature. Sort of.
29
29
[ The ` "imports" ` field] ( https://nodejs.org/api/packages.html#imports ) in
30
- ` package.json ` allows you to configure aliases for your imports. It's not
31
- exactly the same as TypeScript Path aliases, and using them doesn't give you
32
- autocomplete with TypeScript
33
- ([ yet] ( https://github.com/microsoft/TypeScript/pull/55015 ) ), but if you
34
- configure both, then you can get the best of both worlds!
30
+ ` package.json ` allows you to configure aliases for your imports.
31
+ TypeScript also uses this for its own Path aliases since version 5.4
32
+ so you get autocomplete and type checking for your imports.
35
33
36
34
By using the ` "imports" ` field, you don't have to do any special configuration
37
35
for ` vitest ` or ` eslint ` to be able to resolve imports. They just resolve them
38
36
using the standard.
39
37
40
- And by using the ` tsconfig.json ` ` paths ` field configured in the same way as the
41
- ` "imports" ` field, you get autocomplete and type checking for your imports. This
42
- should hopefully be temporary until TypeScript supports the ` "imports" ` field
43
- directly.
44
-
45
38
One interesting requirement for ` imports ` is that they _ must_ start with the ` # `
46
39
character to disambiguate from other imports. This is a bit annoying, but it's
47
40
something that's not difficult to get used to. They also _ must not_ start with
@@ -50,19 +43,14 @@ again it's just a matter of familiarity. So it's no big deal.
50
43
51
44
## Decision
52
45
53
- We're going to configure ` "imports" ` in the ` package.json ` and ` paths ` in the
54
- ` tsconfig.json ` to use path aliases for imports.
46
+ We're going to configure ` "imports" ` in the ` package.json ` to use path aliases for imports.
55
47
56
48
We'll set it to ` "#*": "./*" ` which will allow us to import anything in the root
57
49
of the repo with ` #<dirname>/<filepath> ` .
58
50
59
51
## Consequences
60
52
61
53
This is unfortunately _ very_ soon after making the decision to drop the alias.
62
- But I see this as slightly different because we're only using the alias to make
63
- up for a shortcoming in TypeScript temporarily. Once TypeScript supports the
64
- ` "imports" ` field, we can drop the ` paths ` field and just use the ` "imports" `
65
- standard for Node.js.
66
54
67
55
If someone wants to use the Epic Stack without Node.js, and their runtime
68
56
doesn't support ` package.json ` imports (I'm not sure whether other runtimes do
0 commit comments