-
Notifications
You must be signed in to change notification settings - Fork 12
feat(dev-server): integrate with preview app command #49
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
Conversation
src/lwc-dev-server/index.ts
Outdated
} | ||
|
||
function createLWCServerConfig(source: string, logger: Logger): ServerConfig { | ||
const rootDir = path.resolve(source, 'force-app/main/default'); |
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.
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.
I think the config file will be at the root folder. The value for rootDir
usually indicates to the server as to where the components can be found.
And looking at line 58 I see that process.cwd()
is being used as the base path (which I think would be the same as the root directory for an SFDX project)
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.
It's resolve
-ing to force-app/main/default
so the config file is getting attempted to be created there instead of root of the project?
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.
lwc-dev-server
supports multiple workspaces and the config is used to figure out where does the components live, sfdx project [workspace=sfcli in this case] follows an opinionated folder structure and isn't required to have lwr.config
or either lwc.config
. But let me know if my understanding is incorrect
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.
The way I'm reading this code is that it is creating a ServerConfig
object in <root dir>/force-app/main/default
. I assume the object that's created inside this method is eventually going to be replaced by values that are read from lwc.config.json
in that folder.
You say in your comment that lwc.config(.json)
isn't required in the folder. Yes, the code is resolve
-ing it, implying that there exists a json there.
Here's what I'm trying to do for myself, @rax-it . I'm working on this repo too and I'm trying to figure out where the lwc.config.json
exists. As for where it should exist, that, I don't know. So when I found your draft PR and read the code I naturally thought <root dir>/force-app/main/default
is the folder and trying to confirm with you.
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.
@sfdctaka I think I may have understood the root of your confusion here. There are 2 concepts of root directory, each serving a different purpose.
For an SFDX project, the root directory of the entire SFDX project is the folder where the file sfdx-project.json
is located at. lwr.config.json
should also be placed at this same location.
Now inside the lwr.config.json
there are various configuration flags/values. One of those flags is rootDir
and it means a different thing. rootDir
tells the dev server where to look for when resolving modules/components.
Suppose you have an SFDX project located at ~/Desktop/MyProject
and that this project has an lwc component called helloWorld (which would be located at ~/Desktop/MyProject/force-app/main/default/lwc/helloWorld
.
By setting rootDir = ~/Desktop/MyProject/force-app/main/default
you are telling the dev server that, when requests come in to serve helloWorld (and any other components/modules that it may be referencing) then the dev server should start looking at the location defined by rootDir
to search for the components.
If you have further questions on this, feel free to reach out to me on slack (so we don't pollute the comments/feed of this PR)
@rax-it The assumption that for SFDX projects, the modules/components will always be under force-app/main/default
is not true. We would need to look at the content of sfdx-project.json
and process packageDirectories
where it would tell us where the packages are. I've seen code for processing sfdx-project.json
a long while ago and can't remember off the top of my head what it would involve. I'll look around to see if I can find it and will post link(s) here if I do.
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.
@maliroteh-sf I added sfdx config handling as per what information was available in developer docs.
Let me know if you find more info about it.
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.
Yes that sounds about right. I also was looking at sfdxPackageDirsPattern which is subsequently used for example by getModulesDirs or by componentEntries
import { LWCServer, LogLevel, ServerConfig, Workspace, startLwcDevServer } from '@lwc/lwc-dev-server'; | ||
import { Logger } from '@salesforce/core'; | ||
|
||
const DEV_SERVER_PORT = 8081; |
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.
The port needs to be configurable. This a pretty popular port number and we should anticipate that it might not be available. Can we add a new flag to sf lightning preview app
command?
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.
@ravijayaramappa we may need to run it by Marcelino to discuss this. For example:
- Should it be required or optional flag
- If it is optional and omitted what should we default to
- What if the user uses a
--port
flag to pass in a port butlwc.config.json
also has a port defined in it. Should we update the content of the config file and overwrite with the new flag? - etc.
Maybe we should utilize our slack channel to discuss further with him and the devs?
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.
I like that idea of just putting it in the lwc.config.json
. So that the user can add it once and forget it. Created W-15962937 to track.
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.
LGTM, just a few minor suggestions and testcase request
getLevel: () => 10, | ||
} as Logger; | ||
|
||
describe('lwc-dev-server', () => { |
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.
Can we have a test which can use a sample sfdx project and start the lwc dev server and stop it successfully? Like a sanity end-2-end test.
What does this PR do?
Add flow to start
lwc-dev-server
when runningsf lightning preview app
@W-15044710@