Skip to content

Commit

Permalink
Merge pull request #601 from wjhsf/wjh/fix-forceignore-ts
Browse files Browse the repository at this point in the history
fix(forceignore): only add tsconfig + ts to forceignore for TS projects @W-16625817@
  • Loading branch information
wjhsf authored Sep 5, 2024
2 parents aa01737 + 73beff9 commit 919992d
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 7 deletions.
11 changes: 9 additions & 2 deletions packages/lightning-lsp-common/src/__tests__/context.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -199,9 +199,10 @@ it('configureSfdxProject()', async () => {
// .forceignore
const forceignoreContent = fs.readFileSync(forceignorePath, 'utf8');
expect(forceignoreContent).toContain('**/jsconfig.json');
expect(forceignoreContent).toContain('**/tsconfig.json');
expect(forceignoreContent).toContain('**/.eslintrc.json');
expect(forceignoreContent).toContain('**/*.ts');
// These should only be present for TypeScript projects
expect(forceignoreContent).not.toContain('**/tsconfig.json');
expect(forceignoreContent).not.toContain('**/*.ts');

// typings
expect(join(sfdxTypingsPath, 'lds.d.ts')).toExist();
Expand Down Expand Up @@ -348,10 +349,16 @@ it('configureProjectForTs()', async () => {
// configure and verify typings/jsconfig after configuration:
await context.configureProjectForTs();

// verify forceignore
const forceignoreContent = fs.readFileSync(forceignorePath, 'utf8');
expect(forceignoreContent).toContain('**/tsconfig.json');
expect(forceignoreContent).toContain('**/*.ts');

// verify tsconfig.sfdx.json
const baseTsConfigForceAppContent = fs.readJsonSync(baseTsconfigPathForceApp);
expect(baseTsConfigForceAppContent).toEqual({
compilerOptions: {
module: 'NodeNext',
skipLibCheck: true,
target: 'ESNext',
paths: {
Expand Down
13 changes: 8 additions & 5 deletions packages/lightning-lsp-common/src/context.ts
Original file line number Diff line number Diff line change
Expand Up @@ -429,7 +429,7 @@ export class WorkspaceContext {
const relativeWorkspaceRoot = utils.relativePath(path.dirname(jsConfigPath), this.workspaceRoots[0]);
jsConfigContent = this.processTemplate(jsConfigTemplate, { project_root: relativeWorkspaceRoot });
this.updateConfigFile(jsConfigPath, jsConfigContent);
await this.updateForceIgnoreFile(forceignore);
await this.updateForceIgnoreFile(forceignore, false);
}
break;
case WorkspaceType.CORE_ALL:
Expand Down Expand Up @@ -474,7 +474,7 @@ export class WorkspaceContext {
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);
await this.updateForceIgnoreFile(forceignore, true);
}
break;
}
Expand Down Expand Up @@ -586,11 +586,14 @@ export class WorkspaceContext {
}
}

private async updateForceIgnoreFile(ignoreFile: string): Promise<void> {
private async updateForceIgnoreFile(ignoreFile: string, hasTsEnabled: boolean): Promise<void> {
await utils.appendLineIfMissing(ignoreFile, '**/jsconfig.json');
await utils.appendLineIfMissing(ignoreFile, '**/tsconfig.json');
await utils.appendLineIfMissing(ignoreFile, '**/.eslintrc.json');
await utils.appendLineIfMissing(ignoreFile, '**/*.ts');
if (hasTsEnabled) {
// WJH
await utils.appendLineIfMissing(ignoreFile, '**/tsconfig.json');
await utils.appendLineIfMissing(ignoreFile, '**/*.ts');
}
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
"compilerOptions": {
"skipLibCheck": true,
"target": "ESNext",
"module": "NodeNext",
"paths": {
"c/*": []
}
Expand Down

0 comments on commit 919992d

Please sign in to comment.