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

Treat user code as a referenced project #2444

Merged
merged 8 commits into from
Jan 21, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
25 changes: 16 additions & 9 deletions waspc/data/Cli/templates/skeleton/tsconfig.json
Original file line number Diff line number Diff line change
@@ -1,11 +1,18 @@
// =============================== IMPORTANT =================================
// This file is mainly used for Wasp IDE support.
//
// This file is only used for Wasp IDE support. You can change it to configure
// your IDE checks, but none of these options will affect the TypeScript
// compiler. Proper TS compiler configuration in Wasp is coming soon :)
// Wasp will compile your code with slightly different (less strict) compilerOptions.
// You can increase the configuration's strictness (e.g., by adding
// "noUncheckedIndexedAccess": true), but you shouldn't reduce it (e.g., by
// adding "strict": false). Just keep in mind that this will only affect your
// IDE support, not the actual compilation.
//
// Full TypeScript configurability is coming very soon :)
{
"compilerOptions": {
"module": "esnext",
// Needed because this is used as a project reference.
"composite": true,
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Todo: explore why doesn't next need this

"target": "esnext",
// We're bundling all code in the end so this is the most appropriate option,
// it's also important for autocomplete to work properly.
Expand All @@ -20,6 +27,7 @@
"dom.iterable",
"esnext"
],
"skipLibCheck": true,
Copy link
Contributor

Choose a reason for hiding this comment

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

We added this option, but we validate it with anyValueIsFine so why add it at all?

"allowJs": true,
"typeRoots": [
// This is needed to properly support Vitest testing with jest-dom matchers.
Expand All @@ -32,10 +40,9 @@
// Source 2: https://github.com/testing-library/jest-dom/issues/546#issuecomment-1889884843
"node_modules/@types"
],
// Since this TS config is used only for IDE support and not for
// compilation, the following directory doesn't exist. We need to specify
// it to prevent this error:
// https://stackoverflow.com/questions/42609768/typescript-error-cannot-write-file-because-it-would-overwrite-input-file
"outDir": ".wasp/phantom"
}
"outDir": ".wasp/out/user"
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Todo: leave comment why not noEmit.

},
"include": [
"src"
]
}
20 changes: 20 additions & 0 deletions waspc/data/Generator/templates/react-app/tsconfig.app.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
{
"extends": "@tsconfig/vite-react/tsconfig.json",
"compilerOptions": {
// Temporary loosen the type checking until we can address all the errors.
"jsx": "preserve",
"allowJs": true,
"strict": false,
"skipLibCheck": true,
// Allow importing pages with the .tsx extension.
"allowImportingTsExtensions": true,
"noEmit": true,
},
"include": [
"src"
],
"references": [
// TODO: It would be better to inject this knowledge from Haskell.
{ "path": "../../../tsconfig.json" }
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Todo: draw this knowledge from Haskell, make it work with Wasp TS config.

Currently fails when using Wasp TS Config with this error:
image

It's not noticeable in the server because we don't run tsc - everything is bundled so project references don't yet make a difference.

The client unfortunately breaks.

]
}
20 changes: 4 additions & 16 deletions waspc/data/Generator/templates/react-app/tsconfig.json
Original file line number Diff line number Diff line change
@@ -1,19 +1,7 @@
{
"extends": "@tsconfig/vite-react/tsconfig.json",
"compilerOptions": {
// Temporary loosen the type checking until we can address all the errors.
"jsx": "preserve",
"allowJs": true,
"strict": false,
// Allow importing pages with the .tsx extension.
"allowImportingTsExtensions": true,
},
"include": [
"src"
],
"files": [],
"references": [
{
"path": "./tsconfig.node.json"
}
{ "path": "./tsconfig.app.json" },
{ "path": "./tsconfig.node.json" },
]
}
}
10 changes: 7 additions & 3 deletions waspc/data/Generator/templates/react-app/tsconfig.node.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,13 @@
"compilerOptions": {
"composite": true,
"skipLibCheck": true,
"noEmit": true,
"module": "ESNext",
"moduleResolution": "bundler",
"allowSyntheticDefaultImports": true
"allowSyntheticDefaultImports": true,
},
"include": ["vite.config.ts", "./src/ext-src/vite.config.ts"]
}
"include": [
"vite.config.ts",
"./src/ext-src/vite.config.ts"
]
}
Copy link
Contributor

Choose a reason for hiding this comment

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

Newline

29 changes: 12 additions & 17 deletions waspc/data/Generator/templates/server/tsconfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,23 +4,15 @@
"compilerOptions": {
// Overriding this until we implement more complete TypeScript support.
"strict": false,
// When left unspecified, the 'rootDir' defaults to the longest common path of
// all non-declaration input files. TypeScript mimics the source structure
// inside the output directory (i.e., 'dist').

// This property currently doesn't matter because we haven't been running
// TSC on server code since https://github.com/wasp-lang/wasp/pull/1714.
//
// Since Wasp apps can (but don't have to) import user files from
// '../../../src', it makes the rootDir's default value inconsistent:
// - When the app doesn't import user files (e.g., the user didn't specify
// any operations), the rootDir is set to the server source dir (/src).
// - When the app imports user files (as is the case for most Wasp apps),
// the rootDir is set to the Wasp project root (../../../).
//
// Our build script (in package.json) requires a consistent structure of
// the output directory, which is why we always make sure to point the rootDir
// to the Wasp project root (../../../).
//
// See this comment for more details: https://github.com/wasp-lang/wasp/pull/1584#discussion_r1404019301
"rootDir": "../../../",
// When we start running TSC again (after we fix all current errors and
// make project references work for the TS config), then I believe the
// correct configuration is "rootDir": "." (the project reference should
// take care of the user code), but we should double-check.
"rootDir": ".",
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Link to previous history.

// Overriding this because we want to use top-level await
"module": "esnext",
"target": "es2017",
Expand All @@ -36,5 +28,8 @@
},
"include": [
"src"
],
"references": [
{ "path": "../../../tsconfig.json" }
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Todo: draw this knowledge from Haskell.

Same thing in package.json.

]
}
}

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.

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.

Loading
Loading