From 92f108115b2da1350a0424e4d250d059a9e03ae4 Mon Sep 17 00:00:00 2001 From: Will Harney Date: Tue, 3 Sep 2024 16:32:32 -0400 Subject: [PATCH 1/3] fix(forceignore): only add tsconfig + ts to forceignore for TS projects --- .../src/__tests__/context.test.ts | 10 ++++++++-- packages/lightning-lsp-common/src/context.ts | 13 ++++++++----- 2 files changed, 16 insertions(+), 7 deletions(-) diff --git a/packages/lightning-lsp-common/src/__tests__/context.test.ts b/packages/lightning-lsp-common/src/__tests__/context.test.ts index b722ca47..78c8bbb3 100644 --- a/packages/lightning-lsp-common/src/__tests__/context.test.ts +++ b/packages/lightning-lsp-common/src/__tests__/context.test.ts @@ -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(); @@ -348,6 +349,11 @@ 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({ diff --git a/packages/lightning-lsp-common/src/context.ts b/packages/lightning-lsp-common/src/context.ts index 8c9adb9d..53c0b7a9 100644 --- a/packages/lightning-lsp-common/src/context.ts +++ b/packages/lightning-lsp-common/src/context.ts @@ -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: @@ -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; } @@ -586,11 +586,14 @@ export class WorkspaceContext { } } - private async updateForceIgnoreFile(ignoreFile: string): Promise { + private async updateForceIgnoreFile(ignoreFile: string, hasTsEnabled: boolean): Promise { 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'); + } } /** From 5e9e471ae13b82f0b2a20e4572cabb914cb5dddb Mon Sep 17 00:00:00 2001 From: Will Harney Date: Tue, 3 Sep 2024 16:34:37 -0400 Subject: [PATCH 2/3] fix(tsconfig): enforce module: NodeNext required to get types to resolve --- .../src/resources/sfdx/tsconfig-sfdx.base.json | 1 + 1 file changed, 1 insertion(+) diff --git a/packages/lightning-lsp-common/src/resources/sfdx/tsconfig-sfdx.base.json b/packages/lightning-lsp-common/src/resources/sfdx/tsconfig-sfdx.base.json index 1f51660e..cfaa56f2 100644 --- a/packages/lightning-lsp-common/src/resources/sfdx/tsconfig-sfdx.base.json +++ b/packages/lightning-lsp-common/src/resources/sfdx/tsconfig-sfdx.base.json @@ -2,6 +2,7 @@ "compilerOptions": { "skipLibCheck": true, "target": "ESNext", + "module": "NodeNext", "paths": { "c/*": [] } From 73beff9e5253479906fba164b7c21cbb727d17e7 Mon Sep 17 00:00:00 2001 From: Will Harney Date: Wed, 4 Sep 2024 10:03:51 -0400 Subject: [PATCH 3/3] test(context): add missing prop to assertion --- packages/lightning-lsp-common/src/__tests__/context.test.ts | 1 + 1 file changed, 1 insertion(+) diff --git a/packages/lightning-lsp-common/src/__tests__/context.test.ts b/packages/lightning-lsp-common/src/__tests__/context.test.ts index 78c8bbb3..b792a0e6 100644 --- a/packages/lightning-lsp-common/src/__tests__/context.test.ts +++ b/packages/lightning-lsp-common/src/__tests__/context.test.ts @@ -358,6 +358,7 @@ it('configureProjectForTs()', async () => { const baseTsConfigForceAppContent = fs.readJsonSync(baseTsconfigPathForceApp); expect(baseTsConfigForceAppContent).toEqual({ compilerOptions: { + module: 'NodeNext', skipLibCheck: true, target: 'ESNext', paths: {