-
Notifications
You must be signed in to change notification settings - Fork 48
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
feat: configure sfdx
workspace to write tsconfig
files
#591
Changes from all commits
beebea3
7408c85
1c3e71e
28dcf62
7b9e95f
7b1a74b
00c26bb
5483b29
07414cc
b77661f
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -307,6 +307,14 @@ export class WorkspaceContext { | |
await this.writeTypings(); | ||
} | ||
|
||
/** | ||
* Configures LWC project to support TypeScript | ||
*/ | ||
public async configureProjectForTs(): Promise<void> { | ||
// TODO: This should be moved into configureProject after dev preview | ||
await this.writeTsconfigJson(); | ||
} | ||
|
||
/** | ||
* Acquires list of absolute modules directories, optimizing for workspace type | ||
* @returns Promise | ||
|
@@ -449,6 +457,29 @@ export class WorkspaceContext { | |
} | ||
} | ||
|
||
private async writeTsconfigJson(): Promise<void> { | ||
switch (this.type) { | ||
case WorkspaceType.SFDX: | ||
// Write tsconfig.sfdx.json first | ||
const baseTsConfigPath = path.join(this.workspaceRoots[0], '.sfdx', 'tsconfig.sfdx.json'); | ||
const baseTsConfig = await fs.readFile(utils.getSfdxResource('tsconfig-sfdx.base.json'), 'utf8'); | ||
this.updateConfigFile(baseTsConfigPath, baseTsConfig); | ||
// Write to the tsconfig.json in each module subdirectory | ||
const tsConfigTemplate = await fs.readFile(utils.getSfdxResource('tsconfig-sfdx.json'), 'utf8'); | ||
const forceignore = path.join(this.workspaceRoots[0], '.forceignore'); | ||
// TODO: We should only be looking through modules that have TS files | ||
const modulesDirs = await this.getModulesDirs(); | ||
for (const modulesDir of modulesDirs) { | ||
const tsConfigPath = path.join(modulesDir, 'tsconfig.json'); | ||
const relativeWorkspaceRoot = utils.relativePath(path.dirname(tsConfigPath), this.workspaceRoots[0]); | ||
const tsConfigContent = this.processTemplate(tsConfigTemplate, { project_root: relativeWorkspaceRoot }); | ||
this.updateConfigFile(tsConfigPath, tsConfigContent); | ||
await this.updateForceIgnoreFile(forceignore); | ||
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. What is the point here to call 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. nvm I saw the PR you created 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. This is the same behavior as with |
||
} | ||
break; | ||
} | ||
} | ||
|
||
private async writeSettings(): Promise<void> { | ||
switch (this.type) { | ||
case WorkspaceType.CORE_ALL: | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
{ | ||
"compilerOptions": { | ||
"target": "ESNext", | ||
"paths": { | ||
"c/*": [] | ||
} | ||
} | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
{ | ||
"extends": "${project_root}/.sfdx/tsconfig.sfdx.json", | ||
"include": [ | ||
"**/*.ts", | ||
"${project_root}/.sfdx/typings/lwc/**/*.d.ts" | ||
], | ||
"exclude": [ | ||
"**/__tests__/**" | ||
] | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -80,6 +80,7 @@ export default class Server { | |
|
||
constructor() { | ||
this.connection.onInitialize(this.onInitialize.bind(this)); | ||
this.connection.onInitialized(this.onInitialized.bind(this)); | ||
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. Looks like config values are not available during Once the feature is GA, we can move everything back to |
||
this.connection.onCompletion(this.onCompletion.bind(this)); | ||
this.connection.onCompletionResolve(this.onCompletionResolve.bind(this)); | ||
this.connection.onHover(this.onHover.bind(this)); | ||
|
@@ -130,6 +131,15 @@ export default class Server { | |
}; | ||
} | ||
|
||
async onInitialized(): Promise<void> { | ||
// The config value comes from salesforcedx-vscode/salesforcedx-vscode-lwc | ||
const hasTsEnabled = await this.connection.workspace.getConfiguration('salesforcedx-vscode-lwc.preview.typeScriptSupport'); | ||
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. The entire feature is gated behind this feature flag, which hasn't been implemented in salesforcedx-vscode yet. There is a follow-up PR to implement the flag, in the meantime, I've tested locally that when the config value is enabled it works correctly. 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. After discussing with the team, we should remove the |
||
// TODO: add onDidChangeConfiguration handler to detect changes in config value | ||
if (hasTsEnabled) { | ||
await this.context.configureProjectForTs(); | ||
} | ||
} | ||
|
||
async onCompletion(params: CompletionParams): Promise<CompletionList> { | ||
const { | ||
position, | ||
|
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.
In a follow-up PR I plan to only check for
lwc
directories that actually have TS files.For now, I'm writing to all
lwc
directories.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.
We should also only be generating either a
jsconfig.json
or atsconfig.json
but not both, this can be done once we've moved to GA.