Skip to content
Closed
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions messages/prompts.md
Original file line number Diff line number Diff line change
Expand Up @@ -37,3 +37,7 @@ Unable to enumerate a list of available devices.
# component.select

Which Lightning Web Component would you like to preview (Use arrow keys)

# component.enable-local-dev

Local dev isn't enabled for this org. Enable it?
20 changes: 13 additions & 7 deletions src/commands/lightning/dev/component.ts
Original file line number Diff line number Diff line change
Expand Up @@ -75,13 +75,19 @@ export default class LightningDevComponent extends SfCommand<ComponentPreviewRes
const targetOrg = flags['target-org'];
const apiVersion = flags['api-version'];

// Auto enable local dev
if (process.env.AUTO_ENABLE_LOCAL_DEV === 'true') {
try {
await MetaUtils.ensureLightningPreviewEnabled(targetOrg.getConnection(undefined));
await MetaUtils.ensureFirstPartyCookiesNotRequired(targetOrg.getConnection(undefined));
} catch (error) {
this.log('Error autoenabling local dev', error);
// If local dev is not enabled, prompt the user to enable local dev
const setupConnection = targetOrg.getConnection(undefined);
const isLightningPreviewEnabled = await MetaUtils.isLightningPreviewEnabled(setupConnection);
if (!isLightningPreviewEnabled) {
const enableLocalDev = await PromptUtils.promptUserToEnableLocalDev();
if (enableLocalDev) {

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
if (enableLocalDev) {
if (process.env.AUTO_ENABLE_LOCAL_DEV === 'true' || enableLocalDev) {

We want this process.env as well because from VS Code, it would be easier to set the environment variable when invoking this command when users prompt "Preview this component".

@jhefferman-sfdc jhefferman-sfdc Jan 13, 2026

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Makes sense. But is it OK for the prompt to execute when users use the "Preview this component" VSCode command as they will be prompted there, too? Or do we need some different logic to only prompt if, for example the environment variable is completely absent (neither true, nor false)?

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ok I made an update

  • VSCode command will set AUTO_ENABLE_LOCAL_DEV to 'true' or 'false' which will skip the command prompt.
  • If AUTO_ENABLE_LOCAL_DEV is undefined then the command prompt is used.

try {
await MetaUtils.ensureLightningPreviewEnabled(setupConnection);
await MetaUtils.ensureFirstPartyCookiesNotRequired(setupConnection);
this.log('Local dev is now enabled for this org.');
} catch (error) {
this.log('Error autoenabling local dev', error);
}
}
}

Expand Down
7 changes: 7 additions & 0 deletions src/shared/promptUtils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -114,6 +114,13 @@ export class PromptUtils {
return response;
}

public static async promptUserToEnableLocalDev(): Promise<boolean> {
return confirm({
message: messages.getMessage('component.enable-local-dev'),
default: true,
});
}

// returns the shorthand version of a Version object (eg. 17.0.0 => 17, 17.4.0 => 17.4, 17.4.1 => 17.4.1)
private static getShortVersion(version: Version | string): string {
// TODO: consider making this function part of the Version class in @lwc-dev-mobile-core
Expand Down
Loading