Skip to content

Commit 430992f

Browse files
committed
refactor: webappbundle also relative to project path if provided
1 parent 616fe75 commit 430992f

File tree

4 files changed

+44
-45
lines changed

4 files changed

+44
-45
lines changed

src/client/deployMessages.ts

Lines changed: 37 additions & 40 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,8 @@
1717
import { basename, dirname, extname, join, posix, sep } from 'node:path';
1818
import { SfError } from '@salesforce/core/sfError';
1919
import { ensureArray } from '@salesforce/kit';
20-
import { ComponentLike, SourceComponent } from '../resolve';
20+
import { SourceComponentWithContent, SourceComponent } from '../resolve/sourceComponent';
21+
import { ComponentLike } from '../resolve';
2122
import { registry } from '../registry/registry';
2223
import {
2324
BooleanString,
@@ -91,47 +92,45 @@ export const createResponses =
9192
return [{ ...base, state, ...parseDeployDiagnostic(component, message) } satisfies FileResponseFailure];
9293
}
9394

94-
if (isWebAppBundle(component)) {
95-
const walkedPaths = component.walkContent();
96-
const bundleResponse: FileResponseSuccess = {
97-
fullName: component.fullName,
98-
type: component.type.name,
99-
state,
100-
filePath: component.content,
101-
};
102-
const fileResponses: FileResponseSuccess[] = walkedPaths.map((filePath) => {
103-
// Normalize paths to ensure relative() works correctly on Windows
104-
const normalizedContent = component.content.split(sep).join(posix.sep);
105-
const normalizedFilePath = filePath.split(sep).join(posix.sep);
106-
const relPath = posix.relative(normalizedContent, normalizedFilePath);
107-
return {
108-
fullName: posix.join(component.fullName, relPath),
109-
type: 'DigitalExperience',
110-
state,
111-
filePath,
112-
};
113-
});
114-
return [bundleResponse, ...fileResponses];
115-
}
116-
11795
return (
118-
[
119-
...(shouldWalkContent(component)
120-
? component.walkContent().map((filePath): FileResponseSuccess => ({ ...base, state, filePath }))
121-
: []),
122-
...(component.xml ? [{ ...base, state, filePath: component.xml } satisfies FileResponseSuccess] : []),
123-
]
96+
isWebAppBundle(component)
97+
? [
98+
{
99+
...base,
100+
state,
101+
filePath: component.content,
102+
},
103+
...component.walkContent().map((filePath) => ({
104+
fullName: getWebAppBundleContentFullName(component)(filePath),
105+
type: 'DigitalExperience',
106+
state,
107+
filePath,
108+
})),
109+
]
110+
: [
111+
...(shouldWalkContent(component)
112+
? component.walkContent().map((filePath): FileResponseSuccess => ({ ...base, state, filePath }))
113+
: []),
114+
...(component.xml ? [{ ...base, state, filePath: component.xml }] : []),
115+
]
116+
).map((response) => ({
117+
...response,
118+
filePath:
124119
// deployResults will produce filePaths relative to cwd, which might not be set in all environments
125120
// if our CS had a projectDir set, we'll make the results relative to that path
126-
.map((response) => ({
127-
...response,
128-
filePath:
129-
projectPath && process.cwd() === projectPath
130-
? response.filePath
131-
: join(projectPath ?? '', response.filePath),
132-
}))
133-
);
121+
projectPath && process.cwd() === projectPath ? response.filePath : join(projectPath ?? '', response.filePath),
122+
})) satisfies FileResponseSuccess[];
134123
});
124+
125+
const getWebAppBundleContentFullName =
126+
(component: SourceComponentWithContent) =>
127+
(filePath: string): string => {
128+
// Normalize paths to ensure relative() works correctly on Windows
129+
const normalizedContent = component.content.split(sep).join(posix.sep);
130+
const normalizedFilePath = filePath.split(sep).join(posix.sep);
131+
return posix.relative(normalizedContent, normalizedFilePath);
132+
};
133+
135134
/**
136135
* Groups messages from the deploy result by component fullName and type
137136
*/
@@ -152,8 +151,6 @@ export const getDeployMessages = (result: MetadataApiDeployStatus): Map<string,
152151
if (!messageMap.has(key)) {
153152
messageMap.set(key, []);
154153
}
155-
messageMap.get(key)?.push(sanitized);
156-
failedComponentKeys.add(key);
157154
}
158155

159156
for (const success of successMessages) {

src/client/retrieveExtract.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ import { ConvertOutputConfig } from '../convert/types';
2121
import { MetadataConverter } from '../convert/metadataConverter';
2222
import { ComponentSet } from '../collections/componentSet';
2323
import { ZipTreeContainer } from '../resolve/treeContainers';
24-
import { SourceComponent } from '../resolve/sourceComponent';
24+
import { SourceComponent, SourceComponentWithContent } from '../resolve/sourceComponent';
2525
import { fnJoin } from '../utils/path';
2626
import { ComponentStatus, FileResponse, FileResponseSuccess, PackageOption, PackageOptions } from './types';
2727
import { MetadataApiRetrieveOptions } from './types';
@@ -147,12 +147,12 @@ const handlePartialDeleteMerges = ({
147147
});
148148
};
149149

150-
const supportsPartialDeleteAndHasContent = (comp: SourceComponent): comp is SourceComponent & { content: string } =>
150+
const supportsPartialDeleteAndHasContent = (comp: SourceComponent): comp is SourceComponentWithContent =>
151151
supportsPartialDelete(comp) && typeof comp.content === 'string' && fs.statSync(comp.content).isDirectory();
152152

153153
const supportsPartialDeleteAndHasZipContent =
154154
(tree: ZipTreeContainer) =>
155-
(comp: SourceComponent): comp is SourceComponent & { content: string } =>
155+
(comp: SourceComponent): comp is SourceComponentWithContent =>
156156
supportsPartialDelete(comp) && typeof comp.content === 'string' && tree.isDirectory(comp.content);
157157

158158
const supportsPartialDeleteAndIsInMap =

src/client/utils.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,9 +13,9 @@
1313
* See the License for the specific language governing permissions and
1414
* limitations under the License.
1515
*/
16-
import { SourceComponent } from '../resolve/sourceComponent';
16+
import { SourceComponent, SourceComponentWithContent } from '../resolve/sourceComponent';
1717

18-
export const isWebAppBundle = (component: SourceComponent): component is SourceComponent & { content: string } =>
18+
export const isWebAppBundle = (component: SourceComponent): component is SourceComponentWithContent =>
1919
component.type.name === 'DigitalExperienceBundle' &&
2020
component.fullName.startsWith('web_app/') &&
2121
typeof component.content === 'string';

src/resolve/sourceComponent.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,8 @@ export type ComponentProperties = {
4747
parentType?: MetadataType;
4848
};
4949

50+
export type SourceComponentWithContent = SourceComponent & { content: string };
51+
5052
/**
5153
* Representation of a MetadataComponent in a file tree.
5254
*/

0 commit comments

Comments
 (0)