Skip to content
Closed
Show file tree
Hide file tree
Changes from 2 commits
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?
29 changes: 22 additions & 7 deletions src/commands/lightning/dev/component.ts
Original file line number Diff line number Diff line change
Expand Up @@ -75,13 +75,28 @@ 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 autoEnableLocalDev = process.env.AUTO_ENABLE_LOCAL_DEV;

// If executed via VSCode command, autoEnableLocalDev will contain the users choice, provided via UI.
// Else, prompt the user on the command line.
const enableLocalDev =
autoEnableLocalDev !== undefined
? autoEnableLocalDev === 'true'
: 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".

Copy link
Copy Markdown
Collaborator Author

@jhefferman-sfdc jhefferman-sfdc Jan 13, 2026

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.setLightningPreviewEnabled(setupConnection, true);
await MetaUtils.ensureFirstPartyCookiesNotRequired(setupConnection);
this.log('Local dev has been enabled for this org.');
} catch (error) {
this.log('Error autoenabling local dev', error);
}
}
}

Expand Down
19 changes: 0 additions & 19 deletions src/shared/metaUtils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -199,25 +199,6 @@ export class MetaUtils {
this.logger.debug('Successfully updated first-party cookie requirement');
}

/**
* Ensures Lightning Preview is enabled for the org. If it's not enabled, this method will enable it.
*
* @param connection the connection to the org
* @returns boolean indicating whether Lightning Preview was already enabled (true) or had to be enabled (false)
*/
public static async ensureLightningPreviewEnabled(connection: Connection): Promise<boolean> {
const isEnabled = await this.isLightningPreviewEnabled(connection);

if (!isEnabled) {
this.logger.info('Lightning Preview is not enabled. Enabling it now...');
await this.setLightningPreviewEnabled(connection, true);
return false;
}

this.logger.debug('Lightning Preview is already enabled');
return true;
}

/**
* Ensures first-party cookies are not required for the org. If they are required, this method will disable the requirement.
*
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