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

POC of adding full Typescript support #159

Closed
wants to merge 2 commits into from
Closed
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
53 changes: 47 additions & 6 deletions packages/corvid-local-site/src/codeCompletion.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,8 @@ const {
pageTsConfigFilePath,
masterPageTsConfigFilePath,
backendTsConfigFilePath,
publicTsConfigFilePath
publicTsConfigFilePath,
ROOT_PATHS
} = require("./sitePaths");

let corvidTypes,
Expand All @@ -18,13 +19,21 @@ let corvidTypes,
try {
corvidTypes = require("corvid-types");

const SHARED_COMPILER_OPTIONS = {
composite: true,
noEmit: false,
Copy link
Collaborator Author

Choose a reason for hiding this comment

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

@agankarin
Any particularly reason we currently have noEmit: true in the base configs in corvid-types?
I think if the user does not have any TS files then this flag will have no effect anyways.

skipLibCheck: true
};

pageTsConfigContent = prettyStringify({
extends: corvidTypes.configPaths.page,
compilerOptions: {
baseUrl: ".",
paths: {
"public/*": ["../../public/*"]
}
"public/*": ["../../public/*"],
"backend/*": ["../../backend/*"]
Copy link
Collaborator Author

Choose a reason for hiding this comment

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

@agankarin
This allows importing from backend (which is good), but unfortunately, typescript ignores .jsw files. Regarding our previous discussions on supporting backend, and corvid-magic-sauce of wrapping calls to webMethods, I realized we actually don't need to do anything special! 🕺
The reason is, that the user should anyways write backend functions asynchronously. If they don't, they are making an error. So if the user writes async code in backend, and we will allow him to import functions from .jsw files, the secret sauce is all set and the user will get an awesome experience. The only minor (😆 ) problem left is that typescript does not seem to support custom file extensions, and it doesn't sound like it will support them in the near future:
microsoft/TypeScript#10939

},
...SHARED_COMPILER_OPTIONS
}
});
backendTsConfigContent = prettyStringify({
Expand All @@ -33,7 +42,8 @@ try {
baseUrl: ".",
paths: {
"backend/*": ["./*"]
}
},
...SHARED_COMPILER_OPTIONS
}
});
publicTsConfigContent = prettyStringify({
Expand All @@ -42,7 +52,8 @@ try {
baseUrl: ".",
paths: {
"public/*": ["./*"]
}
},
...SHARED_COMPILER_OPTIONS
}
});
} catch (e) {
Expand All @@ -52,15 +63,45 @@ const isCorvidTypesInstalled = !!corvidTypes;

const getPagesTsConfigs = pages => {
if (!isCorvidTypesInstalled) return [];
return map_(pages, page => ({
const pagesConfigsToWrite = map_(pages, page => ({
path: pageTsConfigFilePath(page),
content: pageTsConfigContent
}));

const rootPagesConfig = {
path: `${ROOT_PATHS.PAGES}/tsconfig.json`,
content: prettyStringify({
files: [],
references: pagesConfigsToWrite.map(({ path }) => ({
path: `../${path}`
}))
})
};

return pagesConfigsToWrite.concat(rootPagesConfig);
};

const getCodeFilesTsConfigs = () => {
if (!isCorvidTypesInstalled) return [];
const rootTsConfig = {
path: `tsconfig.json`,
content: prettyStringify({
files: [],
references: [
{
path: ROOT_PATHS.PAGES
},
{
path: ROOT_PATHS.PUBLIC
},
{
path: ROOT_PATHS.BACKEND
}
]
})
};
return [
rootTsConfig,
{
path: masterPageTsConfigFilePath(),
content: pageTsConfigContent
Expand Down