Skip to content

Commit 7ad4778

Browse files
committed
chore: address PR feedback
1 parent a736b8e commit 7ad4778

File tree

6 files changed

+20
-10
lines changed

6 files changed

+20
-10
lines changed

messages/lightning.dev.app.md

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -35,10 +35,6 @@ ID of the mobile device to display the preview if device type is set to `ios` or
3535

3636
Org must have a valid user
3737

38-
# error.localdev.not.enabled
39-
40-
Local Dev is not enabled for your org. See https://developer.salesforce.com/docs/platform/lwc/guide/get-started-test-components.html for more information on enabling and using Local Dev.
41-
4238
# error.identitydata
4339

4440
Couldn't find identity data while generating preview arguments

messages/shared.utils.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,3 +25,7 @@ The SSL certificate data to be used by the local dev server for secure connectio
2525
# config-utils.cert-error-message
2626

2727
You must provide valid SSL certificate data
28+
29+
# error.localdev.not.enabled
30+
31+
Local Dev is not enabled for your org. See https://developer.salesforce.com/docs/platform/lwc/guide/get-started-test-components.html for more information on enabling and using Local Dev.

src/commands/lightning/dev/app.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@ import { ConfigUtils, IdentityTokenService } from '../../../shared/configUtils.j
2424

2525
Messages.importMessagesDirectoryFromMetaUrl(import.meta.url);
2626
const messages = Messages.loadMessages('@salesforce/plugin-lightning-dev', 'lightning.dev.app');
27+
const sharedMessages = Messages.loadMessages('@salesforce/plugin-lightning-dev', 'shared.utils');
2728

2829
export const iOSSalesforceAppPreviewConfig = {
2930
name: 'Salesforce Mobile App',
@@ -103,7 +104,7 @@ export default class LightningDevApp extends SfCommand<void> {
103104

104105
const localDevEnabled = await OrgUtils.isLocalDevEnabled(connection);
105106
if (!localDevEnabled) {
106-
return Promise.reject(new Error(messages.getMessage('error.localdev.not.enabled')));
107+
return Promise.reject(new Error(sharedMessages.getMessage('error.localdev.not.enabled')));
107108
}
108109

109110
const tokenService = new AppServerIdentityTokenService(connection);

src/commands/lightning/dev/site.ts

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,11 +8,13 @@ import fs from 'node:fs';
88
import { SfCommand, Flags } from '@salesforce/sf-plugins-core';
99
import { Messages } from '@salesforce/core';
1010
import { expDev } from '@lwrjs/api';
11+
import { OrgUtils } from '../../../shared/orgUtils.js';
1112
import { PromptUtils } from '../../../shared/prompt.js';
1213
import { ExperienceSite } from '../../../shared/experience/expSite.js';
1314

1415
Messages.importMessagesDirectoryFromMetaUrl(import.meta.url);
1516
const messages = Messages.loadMessages('@salesforce/plugin-lightning-dev', 'lightning.dev.site');
17+
const sharedMessages = Messages.loadMessages('@salesforce/plugin-lightning-dev', 'shared.utils');
1618

1719
export default class LightningDevSite extends SfCommand<void> {
1820
public static readonly summary = messages.getMessage('summary');
@@ -35,6 +37,11 @@ export default class LightningDevSite extends SfCommand<void> {
3537
const org = flags['target-org'];
3638
let siteName = flags.name;
3739

40+
const localDevEnabled = await OrgUtils.isLocalDevEnabled(org.getConnection(undefined));
41+
if (!localDevEnabled) {
42+
throw new Error(sharedMessages.getMessage('error.localdev.not.enabled'));
43+
}
44+
3845
// If user doesn't specify a site, prompt the user for one
3946
if (!siteName) {
4047
const allSites = await ExperienceSite.getAllExpSites(org);

src/shared/orgUtils.ts

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,10 @@
77

88
import { Connection } from '@salesforce/core';
99

10+
type LightningPreviewMetadataResponse = {
11+
enableLightningPreviewPref?: string;
12+
};
13+
1014
export class OrgUtils {
1115
/**
1216
* Given an app name, it queries the org to find the matching app id. To do so,
@@ -47,10 +51,7 @@ export class OrgUtils {
4751
*/
4852
public static async isLocalDevEnabled(connection: Connection): Promise<boolean> {
4953
const metadata = await connection.metadata.read('LightningExperienceSettings', 'enableLightningPreviewPref');
50-
// casting to any here b/c LightningExperienceSettings type which is defined in 'jsforce'
51-
// does not contain a definition for enableLightningPreviewPref.
52-
// eslint-disable-next-line @typescript-eslint/no-explicit-any, @typescript-eslint/no-unsafe-member-access
53-
const flagValue = `${(metadata as any).enableLightningPreviewPref}`;
54+
const flagValue = (metadata as LightningPreviewMetadataResponse).enableLightningPreviewPref ?? 'false';
5455
const localDevEnabled = flagValue.toLowerCase().trim() === 'true';
5556
return localDevEnabled;
5657
}

test/commands/lightning/dev/app.test.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,7 @@ Messages.importMessagesDirectoryFromMetaUrl(import.meta.url);
3737

3838
describe('lightning dev app', () => {
3939
const messages = Messages.loadMessages('@salesforce/plugin-lightning-dev', 'lightning.dev.app');
40+
const sharedMessages = Messages.loadMessages('@salesforce/plugin-lightning-dev', 'shared.utils');
4041
const $$ = new TestContext();
4142
const testOrgData = new MockTestOrgData();
4243
const testAppId = '06m8b000002vpFSAAY';
@@ -102,7 +103,7 @@ describe('lightning dev app', () => {
102103
$$.SANDBOX.stub(OrgUtils, 'isLocalDevEnabled').resolves(false);
103104
await MockedLightningPreviewApp.run(['--name', 'blah', '-o', testOrgData.username]);
104105
} catch (err) {
105-
expect(err).to.be.an('error').with.property('message', messages.getMessage('error.localdev.not.enabled'));
106+
expect(err).to.be.an('error').with.property('message', sharedMessages.getMessage('error.localdev.not.enabled'));
106107
}
107108
});
108109

0 commit comments

Comments
 (0)