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

Make Wasp work with tsconfig path aliases #2457

Draft
wants to merge 30 commits into
base: main
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
30 commits
Select commit Hold shift + click to select a range
382dc59
Implement project references prototype
sodic Jan 9, 2025
79924a0
Add project reference to user code from server
sodic Jan 10, 2025
4d3f95d
Push todoApp/tsconfig updated for project references
sodic Jan 10, 2025
a4ab2dd
Enable aliases in the SDK
sodic Jan 15, 2025
3fd1830
Make path aliases fully work but its ugly
sodic Jan 16, 2025
91b6f80
Clean some things up
sodic Jan 17, 2025
ae5bcaf
Add clarifying comment for rootDir
sodic Jan 17, 2025
cf3cd30
Merge branch 'filip-project-references' into filip-path-aliases
sodic Jan 17, 2025
cf1dc52
Move path aliases logic into Haskell
sodic Jan 17, 2025
611e2c0
Remove naming and remove unused code
sodic Jan 17, 2025
804852b
Improve tsconfig error messages
sodic Jan 17, 2025
302f7cf
Small refactors and error message improvements
sodic Jan 17, 2025
fe2c7c3
Remove redundant space from template
sodic Jan 17, 2025
c1cd0da
Add small refactors
sodic Jan 20, 2025
74f3567
Change [String] back to FieldPath
sodic Jan 20, 2025
09731ab
Update e2e tests
sodic Jan 20, 2025
ef1008b
Add path aliases to waspc/examples/todoApp
sodic Jan 20, 2025
7f9e078
Merge branch 'main' into filip-project-references
sodic Jan 20, 2025
2b66ac8
Merge branch 'filip-project-references' into filip-path-aliases
sodic Jan 20, 2025
9cf176e
Update waspc.cabal, e2e-tests, and todoApp to v0.16.0
sodic Jan 20, 2025
b51a56f
Fix formatting
sodic Jan 20, 2025
f36b33a
Update headless tests for 0.16.0
sodic Jan 20, 2025
6cf7730
Remove redundant testing file
sodic Jan 20, 2025
871ea87
Remove another redundant testing file
sodic Jan 20, 2025
dda6c0a
Remove more redundant testing files
sodic Jan 20, 2025
2d4c5c9
Update e2e tests
sodic Jan 21, 2025
e9ad9c3
Merge branch 'filip-project-references' into filip-path-aliases
sodic Jan 21, 2025
f390cd1
Update headless tests and waspc.cabal
sodic Jan 21, 2025
e790ebd
Merge branch 'filip-project-references' into filip-path-aliases
sodic Jan 21, 2025
e3f89ad
Merge branch 'main' into filip-path-aliases
sodic Jan 21, 2025
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 9 additions & 1 deletion waspc/data/Generator/templates/react-app/vite.config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,9 @@
import { mergeConfig } from "vite";
import react from "@vitejs/plugin-react";
import { defaultExclude } from "vitest/config"
import { resolveProjectPath } from "wasp/dev"
import tsconfigPaths from 'vite-tsconfig-paths'


{=# customViteConfig.isDefined =}
// Ignoring the TS error because we are importing a file outside of TS root dir.
Expand All @@ -16,7 +19,12 @@ const _waspUserProvidedConfig = {};

const defaultViteConfig = {
base: "{= baseDir =}",
plugins: [react()],
plugins: [
tsconfigPaths({
projects: ["./", resolveProjectPath("./")]
}),
react()
],
optimizeDeps: {
exclude: ['wasp']
},
Expand Down
1 change: 1 addition & 0 deletions waspc/data/Generator/templates/sdk/wasp/dev/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ import { join as joinPaths } from 'path'
* .wasp/out/web-app directory. This function resolves a project root dir path
* to be relative to the `web-app` directory i.e. `../../../projectDirPath`.
*/
// TODO: The relative path should come from Haskell
Copy link
Contributor Author

Choose a reason for hiding this comment

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

I'll either solve this for the next RC or create an issue.

Copy link
Contributor

Choose a reason for hiding this comment

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

Since it's old code, I think it's okay if we just create an issue for this.

export function resolveProjectPath(path: string): string {
return joinPaths('../../../', path)
}
2 changes: 1 addition & 1 deletion waspc/data/Generator/templates/sdk/wasp/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@
{=! expose it here (which leaks it to our users). We could avoid this by =}
{=! using relative imports inside SDK code (instead of library imports), =}
{=! but I didn't have time to implement it. =}
"./ext-src/*": "./dist/ext-src/*.js",
"./src/*": "./dist/src/*.js",
Copy link
Contributor Author

@sodic sodic Jan 17, 2025

Choose a reason for hiding this comment

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

I renamed the output folder instead of renaming aliases, seemed less fiddly. This way, the generated code's structure matches the original.

It also has a nice side effect of showing SDK build errors with correct file mappings:

image

Copy link
Contributor

Choose a reason for hiding this comment

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

What do you mean by "renaming aliases", does that mean you'd search & replace src with ext-src in the SDK version of the files?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Yes, both there and in tsconfig paths.

{=! Used by our code, uncodumented (but accessible) for users. =}
"./operations/*": "./dist/operations/*",
{=! Used by our code, uncodumented (but accessible) for users. =}
Expand Down
11 changes: 5 additions & 6 deletions waspc/data/Generator/templates/sdk/wasp/tsconfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -43,12 +43,11 @@
// While this is great, we still want to dig deeper at some point to understand
// better why Vite HMR misbehaves when the SDK is recompiled: https://github.com/wasp-lang/wasp/issues/1934
"incremental": true,
// todo(filip): Only works with common js, see https://www.typescriptlang.org/tsconfig#paths and daily-article.
// "paths": {
// "@wasp/*": [
// "./*.js"
// ]
// }
"paths": {
{=# paths =}
"{= path =}": ["{= lookupLocation =}"],
{=/ paths =}
}
Comment on lines +47 to +50
Copy link
Contributor Author

@sodic sodic Jan 17, 2025

Choose a reason for hiding this comment

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

When the user doesn't define any aliases, this file still has an empty object.

I thought that was cleaner than doing the conditional check, but feel free to disagree :)

Copy link
Contributor

Choose a reason for hiding this comment

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

Looking at the compiler source code it doesn't seem like it will cause any issues 👍

},
"include": [
"."
Expand Down
12 changes: 11 additions & 1 deletion waspc/data/Generator/templates/server/rollup.config.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
{{={= =}=}}
import esbuild from 'rollup-plugin-esbuild'
import alias from '@rollup/plugin-alias';
import resolve from '@rollup/plugin-node-resolve';

export default [
createBundle('src/server.ts', 'bundle/server.js'),
Expand All @@ -17,12 +19,20 @@ function createBundle(inputFilePath, outputFilePath) {
sourcemap: true,
},
plugins: [
resolve(),
alias({
entries: [
{=# aliases =}
{ find: '{= find =}', replacement: '{= replacement =}' },
{=/ aliases =}
]
Comment on lines +24 to +28
Copy link
Contributor Author

Choose a reason for hiding this comment

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

NOTE: Just like paths in sdk/tsconfig, this field's value is an empty array when the user doesn't define any aliases.

}),
esbuild({
target: 'esnext',
}),
],
// We don't want to bundle any of the node_module deps
// as we want to keep them as external dependencies
external: (id) => !/^[./]/.test(id),
external: /node_modules/,
Copy link
Contributor Author

@sodic sodic Jan 17, 2025

Choose a reason for hiding this comment

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

Todo: leave a note about resolution, wasp, and bundling dependencies.

Todo: leave a note about why we're using alias and not some of the other plugins (check notes).

@infomiho I plan to explain this in detail. It's all in my notes.

}
}
28 changes: 14 additions & 14 deletions waspc/e2e-test/test-outputs/waspBuild-golden/files.manifest

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

This file was deleted.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading
Loading