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

Draft
wants to merge 3 commits into
base: main
Choose a base branch
from
Draft
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
11 changes: 9 additions & 2 deletions waspc/data/Cli/templates/skeleton/tsconfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,9 @@
{
"compilerOptions": {
"module": "esnext",
// Needed because this is used as a project reference.
// TODO: Why doesn't next need it
"composite": true,
"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 +23,7 @@
"dom.iterable",
"esnext"
],
"skipLibCheck": true,
"allowJs": true,
"typeRoots": [
// This is needed to properly support Vitest testing with jest-dom matchers.
Expand All @@ -36,6 +40,9 @@
// 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"
},
"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" }
]
}
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"
]
}
23 changes: 5 additions & 18 deletions waspc/data/Generator/templates/server/tsconfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,23 +4,7 @@
"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').
//
// 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": "../../../",
"rootDir": ".",
// Overriding this because we want to use top-level await
"module": "esnext",
"target": "es2017",
Expand All @@ -36,5 +20,8 @@
},
"include": [
"src"
],
"references": [
{ "path": "../../../tsconfig.json" }
]
}
}
17 changes: 14 additions & 3 deletions waspc/examples/todoApp/tsconfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
{
"compilerOptions": {
"module": "esnext",
"composite": true,
"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 +21,7 @@
"dom.iterable",
"esnext"
],
"skipLibCheck": true,
"allowJs": true,
"typeRoots": [
// This is needed to properly support Vitest testing with jest-dom matchers.
Expand All @@ -36,6 +38,15 @@
// 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"
"outDir": ".wasp/out/user",
// "baseUrl": ".",
// "paths": {
// "@components/*": ["src/components/*"],
// "@util": ["src/util.js"],
// }
},
"include": [
"src"
]
}
2 changes: 1 addition & 1 deletion waspc/src/Wasp/Generator/ExternalConfig/TsConfig.hs
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ validateSrcTsConfig tsConfig =
validateRequiredFieldInCompilerOptions "lib" ["dom", "dom.iterable", "esnext"] T.lib,
validateRequiredFieldInCompilerOptions "allowJs" True T.allowJs,
validateRequiredFieldInCompilerOptions "typeRoots" ["node_modules/@testing-library", "node_modules/@types"] T.typeRoots,
validateRequiredFieldInCompilerOptions "outDir" ".wasp/phantom" T.outDir
validateRequiredFieldInCompilerOptions "outDir" ".wasp/out/user" T.outDir
]
where
validateRequiredFieldInCompilerOptions fieldName expectedValue getFieldValue = case fieldValue of
Expand Down
1 change: 1 addition & 0 deletions waspc/src/Wasp/Generator/WebAppGenerator.hs
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,7 @@ genWebApp spec = do
sequence
[ genFileCopy [relfile|README.md|],
genFileCopy [relfile|tsconfig.json|],
genFileCopy [relfile|tsconfig.app.json|],
genFileCopy [relfile|tsconfig.node.json|],
genFileCopy [relfile|netlify.toml|],
genPackageJson spec (npmDepsForWasp spec),
Expand Down
Loading