Skip to content

Commit

Permalink
fix: do not write jsconfig.json on core when there is tsconfig.json (#…
Browse files Browse the repository at this point in the history
…586)

* fix: do not write jsconfig.json on core when there is tsconfig.json

* fix: empty commit to refresh PR for CLA
  • Loading branch information
rui-rayqiu authored Feb 1, 2024
1 parent af3df36 commit c9aa2f5
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 5 deletions.
9 changes: 8 additions & 1 deletion packages/lightning-lsp-common/src/__tests__/context.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -281,20 +281,27 @@ it('configureCoreMulti()', async () => {
const jsconfigPathGlobal = context.workspaceRoots[1] + '/modules/jsconfig.json';
const codeWorkspacePath = CORE_ALL_ROOT + '/core.code-workspace';
const launchPath = CORE_ALL_ROOT + '/.vscode/launch.json';
const tsconfigPathForce = context.workspaceRoots[0] + '/tsconfig.json';

// make sure no generated files are there from previous runs
fs.removeSync(jsconfigPathGlobal);
fs.removeSync(jsconfigPathForce);
fs.removeSync(codeWorkspacePath);
fs.removeSync(launchPath);
fs.removeSync(tsconfigPathForce);

fs.createFileSync(tsconfigPathForce);

// configure and verify typings/jsconfig after configuration:
await context.configureProject();

// verify newly created jsconfig.json
verifyJsconfigCore(jsconfigPathGlobal);
verifyJsconfigCore(jsconfigPathForce);
// verify jsconfig.json is not created when there is a tsconfig.json
expect(fs.existsSync(tsconfigPathForce)).not.toExist();
verifyTypingsCore();

fs.removeSync(tsconfigPathForce);
});

it('configureCoreAll()', async () => {
Expand Down
23 changes: 19 additions & 4 deletions packages/lightning-lsp-common/src/context.ts
Original file line number Diff line number Diff line change
Expand Up @@ -395,6 +395,15 @@ export class WorkspaceContext {
}
}

/**
* @param modulesDir
* @returns whether a tsconfig.json file exists in the same directory of modulesDir
*/
private hasTSConfigOnCore(modulesDir: string): boolean {
const tsConfigFile = path.join(modulesDir, '..', 'tsconfig.json');
return fs.pathExistsSync(tsConfigFile);
}

/**
* Writes to and updates Jsconfig files and ES Lint files of WorkspaceRoots, optimizing by type
*/
Expand All @@ -419,16 +428,22 @@ export class WorkspaceContext {
jsConfigTemplate = await fs.readFile(utils.getCoreResource('jsconfig-core.json'), 'utf8');
jsConfigContent = this.processTemplate(jsConfigTemplate, { project_root: '../..' });
for (const modulesDir of modulesDirs) {
const jsConfigPath = path.join(modulesDir, 'jsconfig.json');
this.updateConfigFile(jsConfigPath, jsConfigContent);
// only writes jsconfig.json if there is no tsconfig.json on core
if (!this.hasTSConfigOnCore(modulesDir)) {
const jsConfigPath = path.join(modulesDir, 'jsconfig.json');
this.updateConfigFile(jsConfigPath, jsConfigContent);
}
}
break;
case WorkspaceType.CORE_PARTIAL:
jsConfigTemplate = await fs.readFile(utils.getCoreResource('jsconfig-core.json'), 'utf8');
jsConfigContent = this.processTemplate(jsConfigTemplate, { project_root: '../..' });
for (const modulesDir of modulesDirs) {
const jsConfigPath = path.join(modulesDir, 'jsconfig.json');
this.updateConfigFile(jsConfigPath, jsConfigContent); // no workspace reference yet, that comes in update config file
// only writes jsconfig.json if there is no tsconfig.json on core
if (!this.hasTSConfigOnCore(modulesDir)) {
const jsConfigPath = path.join(modulesDir, 'jsconfig.json');
this.updateConfigFile(jsConfigPath, jsConfigContent); // no workspace reference yet, that comes in update config file
}
}
break;
}
Expand Down

0 comments on commit c9aa2f5

Please sign in to comment.