-
Notifications
You must be signed in to change notification settings - Fork 17
feat: add json flag / preview url encoding fixes / auto enable / fix 260 dependencies @W-20141594 #549
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
feat: add json flag / preview url encoding fixes / auto enable / fix 260 dependencies @W-20141594 #549
Changes from all commits
99520b1
9039c45
84c8abe
d5a9880
c3379a1
cb79163
1ba0738
8fcf34b
3610a45
80f6f69
5c9030b
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 |
|---|---|---|
| @@ -1,7 +1,3 @@ | ||
| { | ||
| "modules": [ | ||
| { | ||
| "npm": "lightning-base-components" | ||
| } | ||
| ] | ||
| "modules": [] | ||
| } |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -22,12 +22,21 @@ import { ComponentUtils } from '../../../shared/componentUtils.js'; | |
| import { PromptUtils } from '../../../shared/promptUtils.js'; | ||
| import { PreviewUtils } from '../../../shared/previewUtils.js'; | ||
| import { startLWCServer } from '../../../lwc-dev-server/index.js'; | ||
| import { MetaUtils } from '../../../shared/metaUtils.js'; | ||
|
|
||
| Messages.importMessagesDirectoryFromMetaUrl(import.meta.url); | ||
| const messages = Messages.loadMessages('@salesforce/plugin-lightning-dev', 'lightning.dev.component'); | ||
| const sharedMessages = Messages.loadMessages('@salesforce/plugin-lightning-dev', 'shared.utils'); | ||
|
|
||
| export default class LightningDevComponent extends SfCommand<void> { | ||
| export type ComponentPreviewResult = { | ||
| instanceUrl: string; | ||
| ldpServerUrl: string; | ||
| ldpServerId: string; | ||
| componentName: string; | ||
| previewUrl: string; | ||
| }; | ||
|
|
||
| export default class LightningDevComponent extends SfCommand<ComponentPreviewResult> { | ||
| public static readonly summary = messages.getMessage('summary'); | ||
| public static readonly description = messages.getMessage('description'); | ||
| public static readonly examples = messages.getMessages('examples'); | ||
|
|
@@ -38,6 +47,7 @@ export default class LightningDevComponent extends SfCommand<void> { | |
| char: 'n', | ||
| requiredOrDefaulted: false, | ||
| }), | ||
| 'api-version': Flags.orgApiVersion(), | ||
| 'client-select': Flags.boolean({ | ||
| summary: messages.getMessage('flags.client-select.summary'), | ||
| char: 'c', | ||
|
|
@@ -46,7 +56,7 @@ export default class LightningDevComponent extends SfCommand<void> { | |
| 'target-org': Flags.requiredOrg(), | ||
| }; | ||
|
|
||
| public async run(): Promise<void> { | ||
| public async run(): Promise<ComponentPreviewResult> { | ||
| const { flags } = await this.parse(LightningDevComponent); | ||
| const logger = await Logger.child(this.ctor.name); | ||
| const project = await SfProject.resolve(); | ||
|
|
@@ -63,6 +73,17 @@ export default class LightningDevComponent extends SfCommand<void> { | |
| let componentName = flags['name']; | ||
| const clientSelect = flags['client-select']; | ||
| const targetOrg = flags['target-org']; | ||
| const apiVersion = flags['api-version']; | ||
|
|
||
| // Auto enable local dev | ||
| if (process.env.AUTO_ENABLE_LOCAL_DEV === 'true') { | ||
|
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. I don't think we should be auto enabling. Can we make this interactive?
Collaborator
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 but I probably need to do it from the VSCode side of things. Its awkward to handle sending standard input to a spawned CLI process |
||
| try { | ||
| await MetaUtils.ensureLightningPreviewEnabled(targetOrg.getConnection(undefined)); | ||
| await MetaUtils.ensureFirstPartyCookiesNotRequired(targetOrg.getConnection(undefined)); | ||
| } catch (error) { | ||
| this.log('Error autoenabling local dev', error); | ||
| } | ||
| } | ||
|
|
||
| const { ldpServerId, ldpServerToken } = await PreviewUtils.initializePreviewConnection(targetOrg); | ||
|
|
||
|
|
@@ -71,44 +92,56 @@ export default class LightningDevComponent extends SfCommand<void> { | |
| logger.debug(`Next available ports are http=${serverPorts.httpPort} , https=${serverPorts.httpsPort}`); | ||
|
|
||
| logger.debug('Determining Local Dev Server url'); | ||
| const ldpServerUrl = PreviewUtils.generateWebSocketUrlForLocalDevServer(Platform.desktop, serverPorts, logger); | ||
| let ldpServerUrl; | ||
|
|
||
| // In Code Builder, we cannot go to localhost - we need to use a proxy URI to get to the ldpServer | ||
| if (process.env.SF_CONTAINER_MODE && process.env.VSCODE_PROXY_URI) { | ||
| logger.debug('In Code Builder Mode - using proxy URI'); | ||
| ldpServerUrl = process.env.VSCODE_PROXY_URI.replace('https://', 'ws://').replace( | ||
| '{{port}}', | ||
| `${serverPorts.httpPort}` | ||
| ); | ||
| } else { | ||
| // Default behavior | ||
| ldpServerUrl = PreviewUtils.generateWebSocketUrlForLocalDevServer(Platform.desktop, serverPorts, logger); | ||
| } | ||
| logger.debug(`Local Dev Server url is ${ldpServerUrl}`); | ||
|
|
||
| const namespacePaths = await ComponentUtils.getNamespacePaths(project); | ||
| const componentPaths = await ComponentUtils.getAllComponentPaths(namespacePaths); | ||
| if (!componentPaths) { | ||
| throw new Error(messages.getMessage('error.directory')); | ||
| } | ||
| if (!clientSelect) { | ||
| const namespacePaths = await ComponentUtils.getNamespacePaths(project); | ||
| const componentPaths = await ComponentUtils.getAllComponentPaths(namespacePaths); | ||
| if (!componentPaths) { | ||
| throw new Error(messages.getMessage('error.directory')); | ||
| } | ||
|
|
||
| const components = ( | ||
| await Promise.all( | ||
| componentPaths.map(async (componentPath) => { | ||
| let xml; | ||
|
|
||
| try { | ||
| xml = await ComponentUtils.getComponentMetadata(componentPath); | ||
| } catch (err) { | ||
| this.warn(messages.getMessage('error.component-metadata', [componentPath])); | ||
| } | ||
|
|
||
| // components must have meta xml to be previewed | ||
| if (!xml) { | ||
| return undefined; | ||
| } | ||
|
|
||
| const name = path.basename(componentPath); | ||
| const label = ComponentUtils.componentNameToTitleCase(name); | ||
|
|
||
| return { | ||
| name, | ||
| label: xml.LightningComponentBundle.masterLabel ?? label, | ||
| description: xml.LightningComponentBundle.description ?? '', | ||
| }; | ||
| }) | ||
| ) | ||
| ).filter((component) => !!component); | ||
| const components = ( | ||
| await Promise.all( | ||
| componentPaths.map(async (componentPath) => { | ||
| let xml; | ||
|
|
||
| try { | ||
| xml = await ComponentUtils.getComponentMetadata(componentPath); | ||
| } catch (err) { | ||
| this.warn(messages.getMessage('error.component-metadata', [componentPath])); | ||
| } | ||
|
|
||
| // components must have meta xml to be previewed | ||
| if (!xml) { | ||
| return undefined; | ||
| } | ||
|
|
||
| const name = path.basename(componentPath); | ||
| const label = ComponentUtils.componentNameToTitleCase(name); | ||
|
|
||
| return { | ||
| name, | ||
| label: xml.LightningComponentBundle.masterLabel ?? label, | ||
| description: xml.LightningComponentBundle.description ?? '', | ||
| }; | ||
| }) | ||
| ) | ||
| ).filter((component) => !!component); | ||
|
|
||
| if (!clientSelect) { | ||
| if (componentName) { | ||
| // validate that the component exists before launching the server | ||
| const match = components.find( | ||
|
|
@@ -138,7 +171,28 @@ export default class LightningDevComponent extends SfCommand<void> { | |
| targetOrgArg | ||
| ); | ||
|
|
||
| // Open the browser and navigate to the right page | ||
| await this.config.runCommand('org:open', launchArguments); | ||
| // Construct and log the full URL that will be opened | ||
| const connection = targetOrg.getConnection(apiVersion); | ||
|
|
||
| // strip trailing slashes | ||
| const instanceUrl = connection.instanceUrl.replace(/\/$/, ''); | ||
|
|
||
| const previewUrl = PreviewUtils.generateComponentPreviewUrl(instanceUrl, ldpServerUrl, ldpServerId, componentName); | ||
|
|
||
| // Prepare the result for JSON output | ||
| const result: ComponentPreviewResult = { | ||
| instanceUrl, | ||
| ldpServerUrl, | ||
| ldpServerId, | ||
| componentName: componentName ?? '', | ||
| previewUrl, | ||
| }; | ||
|
|
||
| // Open the browser and navigate to the right page (unless OPEN_BROWSER is set to true) | ||
| if (process.env.OPEN_BROWSER !== 'false') { | ||
|
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. Should this be a command flag?
Collaborator
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 make one, just wanted to review with CLI folks first before we created a flag for this |
||
| await this.config.runCommand('org:open', launchArguments); | ||
| } | ||
|
|
||
| return result; | ||
| } | ||
| } | ||
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.
Changes are pulling forward the --json changes from 258