-
-
Notifications
You must be signed in to change notification settings - Fork 1.2k
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
Using TS SDK from waspc
#2276
Using TS SDK from waspc
#2276
Changes from all commits
e228263
664eafe
1b75ab9
0c7b901
b7c4800
68bfe30
0758747
b7ecab4
e2e802e
2d27900
987243d
15e3e68
7600288
2b0c0ff
7ec9356
1597f4b
b887cd8
1bdc871
52378c4
115dce5
2617b6f
32275e5
b673308
3513b68
e9ef283
0dc7435
3e9efc8
24f65ec
edd7a85
ae76820
7eab0bc
8c8cb4f
d0ba9e5
4eec3c1
1699df2
5a6719e
3f48b98
67f1f9e
522e131
8ab0b3f
d90b235
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
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.
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -156,33 +156,18 @@ tuple4 eval1 eval2 eval3 eval4 = evaluation $ \(typeDefs, bindings) -> withCtx $ | |
extImport :: TypedExprEvaluation AppSpec.ExtImport.ExtImport | ||
extImport = evaluation' . withCtx $ \ctx -> \case | ||
TypedAST.ExtImport name extImportPath -> | ||
-- NOTE(martin): This parsing here could instead be done in Parser. | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Remove this |
||
-- NOTE(martin): This parsing here could instead be done in Parser. | ||
-- I don't have a very good reason for doing it here instead of Parser, except | ||
-- for being somewhat simpler to implement. | ||
-- So we might want to move it to Parser at some point in the future, if we | ||
-- figure out that is better (it sounds/feels like it could be). | ||
case stripImportPrefix extImportPath of | ||
Just relFileFP -> case SP.parseRelFileP relFileFP of | ||
Left err -> mkParseError ctx $ show err | ||
Right relFileSP -> pure $ AppSpec.ExtImport.ExtImport name relFileSP | ||
Nothing -> | ||
mkParseError | ||
ctx | ||
$ "Path in external import must start with \"" ++ extSrcPrefix ++ "\"!" | ||
case AppSpec.ExtImport.parseExtImportPath extImportPath of | ||
Left err -> mkParseError ctx err | ||
Right importPath -> pure $ AppSpec.ExtImport.ExtImport name importPath | ||
Comment on lines
+165
to
+167
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I needed this for |
||
expr -> Left $ ER.mkEvaluationError ctx $ ER.ExpectedType T.ExtImportType (TypedAST.exprType expr) | ||
where | ||
mkParseError ctx msg = Left $ ER.mkEvaluationError ctx $ ER.ParseError $ ER.EvaluationParseError msg | ||
stripImportPrefix importPath = stripPrefix extSrcPrefix importPath | ||
-- Filip: We no longer want separation between client and server code | ||
-- todo (filip): Do we still want to know whic is which. We might (because of the reloading). | ||
-- For now, as we'd like (expect): | ||
-- - Nodemon watches all files in the user's source folder (client files | ||
-- included), but tsc only compiles the server files (I think because it | ||
-- knows that the others aren't used). I am not yet sure how it knows this. | ||
-- - Vite also only triggers on client files. I am not sure how it knows | ||
-- about the difference either. | ||
-- todo (filip): investigate | ||
extSrcPrefix = "@src/" | ||
|
||
-- | An evaluation that expects a "JSON". | ||
json :: TypedExprEvaluation AppSpec.JSON.JSON | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -6,14 +6,18 @@ module Wasp.AppSpec.ExtImport | |
( ExtImport (..), | ||
ExtImportName (..), | ||
importIdentifier, | ||
parseExtImportPath, | ||
) | ||
where | ||
|
||
import Control.Arrow (left) | ||
import Data.Aeson (FromJSON (parseJSON), withObject, (.:)) | ||
import Data.Aeson.Types (ToJSON) | ||
import Data.Data (Data) | ||
import Data.List (stripPrefix) | ||
import GHC.Generics (Generic) | ||
import StrongPath (File', Path, Posix, Rel, parseRelFileP) | ||
import StrongPath (File', Path, Posix, Rel) | ||
import qualified StrongPath as SP | ||
import Wasp.AppSpec.ExternalFiles (SourceExternalCodeDir) | ||
|
||
data ExtImport = ExtImport | ||
|
@@ -30,18 +34,16 @@ instance FromJSON ExtImport where | |
nameStr <- o .: "name" | ||
pathStr <- o .: "path" | ||
extImportName <- parseExtImportName kindStr nameStr | ||
extImportPath <- parseExtImportPath pathStr | ||
extImportPath <- case parseExtImportPath pathStr of | ||
Right path' -> pure path' | ||
Left err -> fail err | ||
Comment on lines
+37
to
+39
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. @Martinsos Any helper function for this? I can't use |
||
return $ ExtImport extImportName extImportPath | ||
where | ||
parseExtImportName kindStr nameStr = case kindStr of | ||
"default" -> pure $ ExtImportModule nameStr | ||
"named" -> pure $ ExtImportField nameStr | ||
_ -> fail $ "Failed to parse import kind: " <> kindStr | ||
|
||
parseExtImportPath pathStr = case parseRelFileP pathStr of | ||
Just path' -> pure path' | ||
Nothing -> fail $ "Failed to parse relative posix path to file: " <> pathStr | ||
|
||
type ExtImportPath = Path Posix (Rel SourceExternalCodeDir) File' | ||
|
||
type Identifier = String | ||
|
@@ -57,3 +59,23 @@ importIdentifier :: ExtImport -> Identifier | |
importIdentifier (ExtImport importName _) = case importName of | ||
ExtImportModule n -> n | ||
ExtImportField n -> n | ||
|
||
parseExtImportPath :: String -> Either String ExtImportPath | ||
parseExtImportPath extImportPath = case stripImportPrefix extImportPath of | ||
Nothing -> Left $ "Path in external import must start with \"" ++ extSrcPrefix ++ "\"!" | ||
Just relFileFP -> | ||
left | ||
(("Failed to parse relative posix path to file: " ++) . show) | ||
$ SP.parseRelFileP relFileFP | ||
where | ||
stripImportPrefix importPath = stripPrefix extSrcPrefix importPath | ||
-- Filip: We no longer want separation between client and server code | ||
-- todo (filip): Do we still want to know which is which. We might (because of the reloading). | ||
-- For now, as we'd like (expect): | ||
-- - Nodemon watches all files in the user's source folder (client files | ||
-- included), but tsc only compiles the server files (I think because it | ||
-- knows that the others aren't used). I am not yet sure how it knows this. | ||
-- - Vite also only triggers on client files. I am not sure how it knows | ||
-- about the difference either. | ||
-- todo (filip): investigate | ||
extSrcPrefix = "@src/" |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,8 +1,9 @@ | ||
module Wasp.Error (showCompilerErrorForTerminal) where | ||
|
||
import Data.List (intercalate) | ||
import StrongPath (Abs, File', Path') | ||
import StrongPath (Abs, Path') | ||
import qualified StrongPath as SP | ||
import StrongPath.Types (File) | ||
import Wasp.Analyzer.Parser.Ctx (Ctx, getCtxRgn) | ||
import Wasp.Analyzer.Parser.SourcePosition (SourcePosition (..)) | ||
import Wasp.Analyzer.Parser.SourceRegion (SourceRegion (..)) | ||
|
@@ -12,7 +13,7 @@ import qualified Wasp.Util.Terminal as T | |
-- | Transforms compiler error (error with parse context) into an informative, pretty String that | ||
-- can be printed directly into the terminal. It uses terminal features like escape codes | ||
-- (colors, styling, ...). | ||
showCompilerErrorForTerminal :: (Path' Abs File', String) -> (String, Ctx) -> String | ||
showCompilerErrorForTerminal :: (Path' Abs (File f), String) -> (String, Ctx) -> String | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. We don't have something like There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Nice catch. We didn't before, but we'll have it now. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I'll take care of this later. It requires dealing with cyclic dependencies. |
||
showCompilerErrorForTerminal (waspFilePath, waspFileContent) (errMsg, errCtx) = | ||
let srcRegion = getCtxRgn errCtx | ||
in intercalate | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@Martinsos This is what we discussed on Discord: sending only the entity statements through the compilation pipeline to get their declarations.
Should I document the idea behind it?