-
Notifications
You must be signed in to change notification settings - Fork 49
Description
Summary
Currently the LWC language server will automatically generate jsconfig.json files in every lwc/* folder in a SFDX project on start. This has multiple impacts.
- Any javascript exports from submodule type files in a lwc component will be autocomplete suggested. e.g. some helper.js which has exported functions. These are not importable by other c/lwc components unless re-exported by the lwc component entry point.
- Does not function for multiple directory locations of lwc components.
force-app/main/default/lwc/aandforce-app/main/bar/lwc/b. (While uncommon, it is supported by deployment processes and greatly helps organise SFDX source) - Suggested imports double path,
c/component/componenteven for components in same directory. - Any mocks are also suggested
Related discussion can be read here. However, I am raising this here as it is the language server which causes this behaviour.
Steps To Reproduce:
- Create a SFDX project with a LWC component.
- Add a helper javascript file in the component.
- See that autocomplete will suggest any exported classes or functions that are not the component entry point
- Create another project directory
force-app/main/fooandforce-app/main/bar - create lwc components, try import / auto complete
Expected result
There are likely a few options that could be implemented. It does look like the TS future moves towards a single tsconfig at root with paths defined for components. This would solve these issues.
For my project we have been automating removing all jsconfig.js in lwc folders and created a single force-app/jsconfig.js which has paths set to each component entry point via a script.
Some options from the top of my head
- I see the other logic for
CORE_ALLorCORE_PARTIALworkspaces do not create these files if a tsconfig exists at root. This could be similarily implemented forWorkspaceType.SFDXwhere ifjsconfig.jsexists at root do not generatelwc/jsconfig.jsonfiles. Related source - Remove generation completely (likely not ideal in most cases)
- Move to generating a single
force-app/jsconfig.jsonon create/delete of /lwc/** files with paths for components, which also honours additional user config / paths.
{
"compilerOptions": {
"target": "ESNext",
"baseUrl": ".",
"experimentalDecorators": true,
"allowJs": true,
"checkJs": true,
"moduleResolution": "Node",
"paths": {
"c/a": ["./main/foo/lwc/a/a.js"],
"c/b": ["./main/bar/lwc/b/b.js"]
}
},
"include": ["**/*", "../.sfdx/typings/lwc/**/*.d.ts", "types/**/*.d.ts"],
"exclude": ["**/__mock__/**", "**/__mocks__/**", "**/__tests__/**"],
"typeAcquisition": {
"include": ["jest"]
}
}Actual result
While I understand this is all developer quality of life stuff. It would go a long way for improving development in SFDX projects for little effort (which I am happy to do, though not sure how to run language server to test).
Additional information
Feel free to attach a screenshot.
VS Code Version: 1.101.2
SFDX CLI Version: 2.93.7
OS and version:
Edition Windows 11 Enterprise
Version 23H2
OS build 22631.5472
Experience Windows Feature Experience Pack 1000.22700.1106.0