Skip to content

Commit 673d7d3

Browse files
committed
refactor: addressed review comments
1 parent fbbf615 commit 673d7d3

File tree

3 files changed

+18
-35
lines changed

3 files changed

+18
-35
lines changed

src/client/deployMessages.ts

Lines changed: 9 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@
1414
* limitations under the License.
1515
*/
1616

17-
import { basename, dirname, extname, join, posix, sep } from 'node:path/posix';
17+
import { basename, dirname, extname, join, posix, relative, sep } from 'node:path/posix';
1818
import { SfError } from '@salesforce/core/sfError';
1919
import { ensureArray } from '@salesforce/kit';
2020
import { ComponentLike, SourceComponent } from '../resolve';
@@ -87,10 +87,11 @@ export const createResponses = (component: SourceComponent, responseMessages: De
8787
if (state === ComponentStatus.Failed) {
8888
return [{ ...base, state, ...parseDeployDiagnostic(component, message) } satisfies FileResponseFailure];
8989
} else {
90-
const isWebAppBundle = component.type.name === 'DigitalExperienceBundle' &&
91-
component.fullName.startsWith('web_app/') &&
92-
component.content;
93-
90+
const isWebAppBundle =
91+
component.type.name === 'DigitalExperienceBundle' &&
92+
component.fullName.startsWith('web_app/') &&
93+
component.content;
94+
9495
if (isWebAppBundle) {
9596
const walkedPaths = component.walkContent();
9697
const bundleResponse: FileResponseSuccess = {
@@ -100,17 +101,17 @@ export const createResponses = (component: SourceComponent, responseMessages: De
100101
filePath: component.content!,
101102
};
102103
const fileResponses: FileResponseSuccess[] = walkedPaths.map((filePath) => {
103-
const relPath = filePath.replace(component.content! + '/', '');
104+
const relPath = relative(component.content!, filePath);
104105
return {
105-
fullName: `${component.fullName}/${relPath}`,
106+
fullName: join(component.fullName, relPath).split(sep).join(posix.sep),
106107
type: 'DigitalExperience',
107108
state,
108109
filePath,
109110
};
110111
});
111112
return [bundleResponse, ...fileResponses];
112113
}
113-
114+
114115
return [
115116
...(shouldWalkContent(component)
116117
? component.walkContent().map((filePath): FileResponseSuccess => ({ ...base, state, filePath }))

src/resolve/adapters/digitalExperienceSourceAdapter.ts

Lines changed: 6 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -201,10 +201,10 @@ export class DigitalExperienceSourceAdapter extends BundleSourceAdapter {
201201
const pathParts = trigger.split(sep);
202202
const digitalExperiencesIndex = pathParts.indexOf('digitalExperiences');
203203

204-
// Extract bundle name: web_app/WebApp3
204+
// Extract bundle name: web_app/WebApp3 (always use posix separator for metadata names)
205205
const baseType = pathParts[digitalExperiencesIndex + 1];
206206
const spaceApiName = pathParts[digitalExperiencesIndex + 2];
207-
const bundleName = `${baseType}/${spaceApiName}`;
207+
const bundleName = [baseType, spaceApiName].join('/');
208208

209209
// Extract bundle directory: /path/to/digitalExperiences/web_app/WebApp3
210210
const bundleDir = pathParts.slice(0, digitalExperiencesIndex + 3).join(sep);
@@ -232,10 +232,10 @@ export class DigitalExperienceSourceAdapter extends BundleSourceAdapter {
232232
const digitalExperiencesIndex = getDigitalExperiencesIndex(contentPath);
233233
const baseType = pathParts[digitalExperiencesIndex + 1];
234234
const spaceApiName = pathParts[digitalExperiencesIndex + 2];
235-
return `${baseType}/${spaceApiName}`;
235+
return [baseType, spaceApiName].join('/');
236236
}
237237
const bundlePath = this.getBundleMetadataXmlPath(contentPath);
238-
return `${parentName(dirname(bundlePath))}/${parentName(bundlePath)}`;
238+
return [parentName(dirname(bundlePath)), parentName(bundlePath)].join('/');
239239
}
240240

241241
private getBundleMetadataXmlPath(path: string): string {
@@ -275,15 +275,10 @@ const contentParts = digitalExperienceStructure.split(sep);
275275
* web_app base type has a simpler structure without ContentType folders.
276276
* Structure: digitalExperiences/web_app/spaceApiName/...files...
277277
*/
278-
const isWebAppBaseType = (path: string): boolean => {
278+
export const isWebAppBaseType = (path: string): boolean => {
279279
const pathParts = path.split(sep);
280280
const digitalExperiencesIndex = pathParts.indexOf('digitalExperiences');
281-
// Check if the base type (folder after digitalExperiences) is WEB_APP_BASE_TYPE
282-
return (
283-
digitalExperiencesIndex > -1 &&
284-
pathParts.length > digitalExperiencesIndex + 1 &&
285-
pathParts[digitalExperiencesIndex + 1] === WEB_APP_BASE_TYPE
286-
);
281+
return pathParts[digitalExperiencesIndex + 1] === WEB_APP_BASE_TYPE;
287282
};
288283

289284
/**

src/resolve/metadataResolver.ts

Lines changed: 3 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -27,24 +27,11 @@ import { SourceAdapterFactory } from './adapters/sourceAdapterFactory';
2727
import { ForceIgnore } from './forceIgnore';
2828
import { SourceComponent } from './sourceComponent';
2929
import { NodeFSTreeContainer, TreeContainer } from './treeContainers';
30+
import { isWebAppBaseType } from './adapters/digitalExperienceSourceAdapter';
3031

3132
Messages.importMessagesDirectory(__dirname);
3233
const messages = Messages.loadMessages('@salesforce/source-deploy-retrieve', 'sdr');
3334

34-
/**
35-
* Checks if the given path is a web_app bundle directory.
36-
* web_app bundles don't have metadata XML files and are identified by directory structure.
37-
*/
38-
const isWebAppBundlePath = (path: string): boolean => {
39-
const pathParts = path.split(sep);
40-
const digitalExperiencesIndex = pathParts.indexOf('digitalExperiences');
41-
return (
42-
digitalExperiencesIndex > -1 &&
43-
pathParts.length > digitalExperiencesIndex + 2 &&
44-
pathParts[digitalExperiencesIndex + 1] === 'web_app'
45-
);
46-
};
47-
4835
/**
4936
* Resolver for metadata type and component objects.
5037
*
@@ -238,7 +225,7 @@ const resolveDirectoryAsComponent =
238225
(registry: RegistryAccess) =>
239226
(tree: TreeContainer) =>
240227
(dirPath: string): boolean => {
241-
if (isWebAppBundlePath(dirPath)) {
228+
if (isWebAppBaseType(dirPath)) {
242229
return true;
243230
}
244231

@@ -353,7 +340,7 @@ const resolveType =
353340
(registry: RegistryAccess) =>
354341
(tree: TreeContainer) =>
355342
(fsPath: string): MetadataType | undefined => {
356-
if (isWebAppBundlePath(fsPath)) {
343+
if (isWebAppBaseType(fsPath)) {
357344
return registry.getTypeByName('DigitalExperienceBundle');
358345
}
359346

0 commit comments

Comments
 (0)