-
Notifications
You must be signed in to change notification settings - Fork 15
feat: add custom config variables for dev server #67
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
Changes from all commits
0ad42f0
e03b07a
68692ea
fd8ec84
afd3834
d084ea4
dd402b9
dba95d4
f7b98ab
fd4c5f8
7ce311e
d13752c
0c52aa9
c6ed97b
6e2707d
803a2f6
eec1bba
84de0e7
f842060
3122528
3fa8091
953e825
a830870
ad671da
6f6a43b
839c0d9
d59fbc8
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -52,4 +52,8 @@ node_modules | |
| # lwr | ||
| __lwr_cache__ | ||
| app | ||
| bld | ||
| bld | ||
|
|
||
| # sf cli | ||
| .sf | ||
| .sfdx | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,19 @@ | ||
| # lwc-dev-server-utils.port-desc | ||
|
|
||
| The port number of the local dev server | ||
|
|
||
| # lwc-dev-server-utils.port-message | ||
|
|
||
| Must be a number between 1 and 65535 | ||
|
|
||
| # lwc-dev-server-utils.workspace-desc | ||
|
|
||
| The workspace name of the local lwc dev server | ||
|
|
||
| # lwc-dev-server-utils.workspace-message | ||
|
|
||
| Valid workspace value is "SalesforceCLI" OR "mrt" | ||
|
|
||
| # identity-utils.token-desc | ||
|
|
||
| The Base64-encoded identity token of the local web server |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -5,21 +5,79 @@ | |
| * For full license text, see LICENSE.txt file in the repo root or https://opensource.org/licenses/BSD-3-Clause | ||
| */ | ||
|
|
||
| import type { ConfigPropertyMeta } from '@salesforce/core'; | ||
| import type { ConfigPropertyMeta, ConfigValue } from '@salesforce/core'; | ||
| import { Workspace } from '@lwc/lwc-dev-server'; | ||
| import { Messages } from '@salesforce/core'; | ||
|
|
||
| Messages.importMessagesDirectoryFromMetaUrl(import.meta.url); | ||
| const messages = Messages.loadMessages('@salesforce/plugin-lightning-dev', 'shared.utils'); | ||
| const IDENTITY_TOKEN_DESC = messages.getMessage('identity-utils.token-desc'); | ||
| const LOCAL_DEV_SERVER_PORT_DESC = messages.getMessage('lwc-dev-server-utils.port-desc'); | ||
| const LOCAL_DEV_SERVER_PORT_MESSAGE = messages.getMessage('lwc-dev-server-utils.port-message'); | ||
| const LOCAL_DEV_SERVER_WORKSPACE_DESC = messages.getMessage('lwc-dev-server-utils.workspace-desc'); | ||
| const LOCAL_DEV_SERVER_WORKSPACE_MESSAGE = messages.getMessage('lwc-dev-server-utils.workspace-message'); | ||
|
|
||
| export const enum ConfigVars { | ||
| /** | ||
| * The Base64-encoded identity token of the local web server, used to | ||
| * validate the web server's identity to the hmr-client. | ||
| */ | ||
| LOCAL_WEB_SERVER_IDENTITY_TOKEN = 'local-web-server-identity-token', | ||
|
|
||
| /** | ||
| * The port number of the local dev server. | ||
| */ | ||
| LOCAL_DEV_SERVER_PORT = 'local-dev-server-port', | ||
|
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. we can /bike-shed on the name since this variable is public |
||
|
|
||
| /** | ||
| * The Workspace name of the local dev server. | ||
| */ | ||
| LOCAL_DEV_SERVER_WORKSPACE = 'local-dev-server-workspace', | ||
| } | ||
|
|
||
| export default [ | ||
| { | ||
| key: ConfigVars.LOCAL_WEB_SERVER_IDENTITY_TOKEN, | ||
| description: 'The Base64-encoded identity token of the local web server', | ||
| description: IDENTITY_TOKEN_DESC, | ||
| hidden: true, | ||
| encrypted: true, | ||
| }, | ||
| { | ||
| key: ConfigVars.LOCAL_DEV_SERVER_PORT, | ||
| description: LOCAL_DEV_SERVER_PORT_DESC, | ||
| input: { | ||
| validator: (value: ConfigValue): boolean => { | ||
| if (!value) { | ||
| return false; | ||
| } | ||
|
|
||
| const parsedPort = parseInt(value as string, 10); | ||
|
|
||
| if (isNaN(parsedPort) || parsedPort < 1 || parsedPort > 65535) { | ||
| return false; | ||
| } | ||
| return true; | ||
| }, | ||
| failedMessage: LOCAL_DEV_SERVER_PORT_MESSAGE, | ||
| }, | ||
| }, | ||
| { | ||
| key: ConfigVars.LOCAL_DEV_SERVER_WORKSPACE, | ||
| description: LOCAL_DEV_SERVER_WORKSPACE_DESC, | ||
| input: { | ||
| validator: (value: ConfigValue): boolean => { | ||
| if (!value) { | ||
| return false; | ||
| } | ||
|
|
||
| const workspace = value as Workspace; | ||
|
|
||
| if (workspace === Workspace.SfCli || workspace === Workspace.Mrt) { | ||
| return true; | ||
| } | ||
| return false; | ||
| }, | ||
| failedMessage: LOCAL_DEV_SERVER_WORKSPACE_MESSAGE, | ||
| }, | ||
| }, | ||
| ] as ConfigPropertyMeta[]; | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,40 @@ | ||
| /* | ||
| * Copyright (c) 2024, salesforce.com, inc. | ||
| * All rights reserved. | ||
| * Licensed under the BSD 3-Clause license. | ||
| * For full license text, see LICENSE.txt file in the repo root or https://opensource.org/licenses/BSD-3-Clause | ||
| */ | ||
|
|
||
| import { Workspace } from '@lwc/lwc-dev-server'; | ||
| import { Config } from '@salesforce/core'; | ||
| import configMeta, { ConfigVars } from '../configMeta.js'; | ||
|
|
||
| export const LOCAL_DEV_SERVER_DEFAULT_PORT = 8081; | ||
| export const LOCAL_DEV_SERVER_DEFAULT_WORKSPACE = Workspace.SfCli; | ||
|
|
||
| export class LwcDevServerUtils { | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. FYI, I plan on consolidating
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. yeah I realized that we are wasting at least next tick since we are loading the same config twice. |
||
| static #config: Config; | ||
|
|
||
| public static async getConfig(): Promise<Config> { | ||
| if (this.#config) { | ||
| return this.#config; | ||
| } | ||
| this.#config = await Config.create({ isGlobal: false }); | ||
| Config.addAllowedProperties(configMeta); | ||
| return this.#config; | ||
| } | ||
|
|
||
| public static async getLocalDevServerPort(): Promise<number> { | ||
| const config = await this.getConfig(); | ||
| const configPort = config.get(ConfigVars.LOCAL_DEV_SERVER_PORT) as number; | ||
|
|
||
| return configPort || LOCAL_DEV_SERVER_DEFAULT_PORT; | ||
| } | ||
|
|
||
| public static async getLocalDevServerWorkspace(): Promise<Workspace> { | ||
| const config = await this.getConfig(); | ||
| const configWorkspace = config.get(ConfigVars.LOCAL_DEV_SERVER_WORKSPACE) as Workspace; | ||
|
|
||
| return configWorkspace || LOCAL_DEV_SERVER_DEFAULT_WORKSPACE; | ||
| } | ||
| } | ||
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 not sure why the port is consumed as a string?
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 have this fixed locally so please ignore for now until my next PR.