Skip to content
Merged
Show file tree
Hide file tree
Changes from all 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
2,541 changes: 517 additions & 2,024 deletions CHANGELOG.md

Large diffs are not rendered by default.

1,534 changes: 766 additions & 768 deletions METADATA_SUPPORT.md

Large diffs are not rendered by default.

95 changes: 52 additions & 43 deletions src/client/deployMessages.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,8 @@
import { basename, dirname, extname, join, posix, sep } from 'node:path';
import { SfError } from '@salesforce/core/sfError';
import { ensureArray } from '@salesforce/kit';
import { ComponentLike, SourceComponent } from '../resolve';
import { SourceComponentWithContent, SourceComponent } from '../resolve/sourceComponent';
Copy link
Contributor Author

Choose a reason for hiding this comment

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

SourceComponentWithContent passed the rule of 3

Copy link
Contributor

Choose a reason for hiding this comment

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

What's the rule of 3 in this context?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

if the same code is in 3 places, make it shared/reusable

Copy link
Contributor Author

Choose a reason for hiding this comment

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

so now there's SouceComponentWithContent instead of several places making SourceComponent & {content: string}

import { ComponentLike } from '../resolve';
import { registry } from '../registry/registry';
import {
BooleanString,
Expand All @@ -29,6 +30,7 @@ import {
MetadataApiDeployStatus,
} from './types';
import { parseDeployDiagnostic } from './diagnosticUtil';
import { isWebAppBundle } from './utils';

type DeployMessageWithComponentType = DeployMessage & { componentType: string };
/**
Expand Down Expand Up @@ -79,50 +81,57 @@ const shouldWalkContent = (component: SourceComponent): boolean =>
(t) => t.unaddressableWithoutParent === true || t.isAddressable === false
));

export const createResponses = (component: SourceComponent, responseMessages: DeployMessage[]): FileResponse[] =>
responseMessages.flatMap((message): FileResponse[] => {
const state = getState(message);
const base = { fullName: component.fullName, type: component.type.name } as const;

if (state === ComponentStatus.Failed) {
return [{ ...base, state, ...parseDeployDiagnostic(component, message) } satisfies FileResponseFailure];
} else {
const isWebAppBundle =
component.type.name === 'DigitalExperienceBundle' &&
component.fullName.startsWith('web_app/') &&
component.content;

if (isWebAppBundle) {
const walkedPaths = component.walkContent();
const bundleResponse: FileResponseSuccess = {
fullName: component.fullName,
type: component.type.name,
state,
filePath: component.content!,
};
const fileResponses: FileResponseSuccess[] = walkedPaths.map((filePath) => {
// Normalize paths to ensure relative() works correctly on Windows
const normalizedContent = component.content!.split(sep).join(posix.sep);
const normalizedFilePath = filePath.split(sep).join(posix.sep);
const relPath = posix.relative(normalizedContent, normalizedFilePath);
return {
fullName: posix.join(component.fullName, relPath),
type: 'DigitalExperience',
state,
filePath,
};
});
return [bundleResponse, ...fileResponses];
export const createResponses =
(projectPath?: string) =>
(component: SourceComponent, responseMessages: DeployMessage[]): FileResponse[] =>
responseMessages.flatMap((message): FileResponse[] => {
const state = getState(message);
const base = { fullName: component.fullName, type: component.type.name } as const;

if (state === ComponentStatus.Failed) {
return [{ ...base, state, ...parseDeployDiagnostic(component, message) } satisfies FileResponseFailure];
}

return [
...(shouldWalkContent(component)
? component.walkContent().map((filePath): FileResponseSuccess => ({ ...base, state, filePath }))
: []),
...(component.xml ? [{ ...base, state, filePath: component.xml } satisfies FileResponseSuccess] : []),
];
}
});
return (
isWebAppBundle(component)
? [
{
...base,
state,
filePath: component.content,
},
...component.walkContent().map((filePath) => ({
fullName: getWebAppBundleContentFullName(component)(filePath),
type: 'DigitalExperience',
state,
filePath,
})),
]
: [
...(shouldWalkContent(component)
? component.walkContent().map((filePath): FileResponseSuccess => ({ ...base, state, filePath }))
: []),
...(component.xml ? [{ ...base, state, filePath: component.xml }] : []),
]
).map((response) => ({
...response,
filePath:
// deployResults will produce filePaths relative to cwd, which might not be set in all environments
// if our CS had a projectDir set, we'll make the results relative to that path
projectPath && process.cwd() === projectPath ? response.filePath : join(projectPath ?? '', response.filePath),
})) satisfies FileResponseSuccess[];
});

const getWebAppBundleContentFullName =
(component: SourceComponentWithContent) =>
(filePath: string): string => {
// Normalize paths to ensure relative() works correctly on Windows
const normalizedContent = component.content.split(sep).join(posix.sep);
const normalizedFilePath = filePath.split(sep).join(posix.sep);
Copy link
Contributor Author

Choose a reason for hiding this comment

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

took me a while of playing with it, but since both of these are relative, and then posix.relative is between them, then I think it should be ok even without cwd?

Copy link
Contributor

Choose a reason for hiding this comment

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

That sounds right to me?

const relPath = posix.relative(normalizedContent, normalizedFilePath);
return posix.join(component.fullName, relPath);
};

/**
* Groups messages from the deploy result by component fullName and type
*/
Expand Down
7 changes: 5 additions & 2 deletions src/client/metadataApiDeploy.ts
Original file line number Diff line number Diff line change
Expand Up @@ -509,11 +509,14 @@ const buildFileResponsesFromComponentSet =

const fileResponses = (cs.getSourceComponents().toArray() ?? [])
.flatMap((deployedComponent) =>
createResponses(deployedComponent, responseMessages.get(toKey(deployedComponent)) ?? []).concat(
createResponses(cs.projectDirectory)(
deployedComponent,
responseMessages.get(toKey(deployedComponent)) ?? []
).concat(
deployedComponent.type.children
? deployedComponent.getChildren().flatMap((child) => {
const childMessages = responseMessages.get(toKey(child));
return childMessages ? createResponses(child, childMessages) : [];
return childMessages ? createResponses(cs.projectDirectory)(child, childMessages) : [];
})
: []
)
Expand Down
26 changes: 13 additions & 13 deletions src/client/metadataApiRetrieve.ts
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@ import {
import { extract } from './retrieveExtract';
import { getPackageOptions } from './retrieveExtract';
import { MetadataApiRetrieveOptions } from './types';
import { isWebAppBundle } from './utils';

Messages.importMessagesDirectory(__dirname);
const messages = Messages.loadMessages('@salesforce/source-deploy-retrieve', 'sdr');
Expand Down Expand Up @@ -101,28 +102,27 @@ export class RetrieveResult implements MetadataTransferResult {

// construct successes
for (const retrievedComponent of this.components.getSourceComponents()) {
const { fullName, type, xml, content } = retrievedComponent;
const { fullName, type, xml } = retrievedComponent;
const baseResponse = {
fullName,
type: type.name,
state: this.localComponents.has(retrievedComponent) ? ComponentStatus.Changed : ComponentStatus.Created,
} as const;

// Special handling for web_app bundles - they need to walk content and report individual files
const isWebAppBundle = type.name === 'DigitalExperienceBundle' && fullName.startsWith('web_app/') && content;

if (isWebAppBundle) {
const walkedPaths = retrievedComponent.walkContent();
if (isWebAppBundle(retrievedComponent)) {
// Add the bundle directory itself
this.fileResponses.push({ ...baseResponse, filePath: content } satisfies FileResponseSuccess);
// Add each file with its specific path
for (const filePath of walkedPaths) {
this.fileResponses.push({ ...baseResponse, filePath } satisfies FileResponseSuccess);
}
this.fileResponses.push(
...[retrievedComponent.content, ...retrievedComponent.walkContent()].map(
(filePath) => ({ ...baseResponse, filePath } satisfies FileResponseSuccess)
)
);
} else if (!type.children || Object.values(type.children.types).some((t) => t.unaddressableWithoutParent)) {
for (const filePath of retrievedComponent.walkContent()) {
this.fileResponses.push({ ...baseResponse, filePath } satisfies FileResponseSuccess);
}
this.fileResponses.push(
...retrievedComponent
.walkContent()
.map((filePath) => ({ ...baseResponse, filePath } satisfies FileResponseSuccess))
);
}

if (xml) {
Expand Down
6 changes: 3 additions & 3 deletions src/client/retrieveExtract.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ import { ConvertOutputConfig } from '../convert/types';
import { MetadataConverter } from '../convert/metadataConverter';
import { ComponentSet } from '../collections/componentSet';
import { ZipTreeContainer } from '../resolve/treeContainers';
import { SourceComponent } from '../resolve/sourceComponent';
import { SourceComponent, SourceComponentWithContent } from '../resolve/sourceComponent';
import { fnJoin } from '../utils/path';
import { ComponentStatus, FileResponse, FileResponseSuccess, PackageOption, PackageOptions } from './types';
import { MetadataApiRetrieveOptions } from './types';
Expand Down Expand Up @@ -147,12 +147,12 @@ const handlePartialDeleteMerges = ({
});
};

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

const supportsPartialDeleteAndHasZipContent =
(tree: ZipTreeContainer) =>
(comp: SourceComponent): comp is SourceComponent & { content: string } =>
(comp: SourceComponent): comp is SourceComponentWithContent =>
supportsPartialDelete(comp) && typeof comp.content === 'string' && tree.isDirectory(comp.content);

const supportsPartialDeleteAndIsInMap =
Expand Down
21 changes: 21 additions & 0 deletions src/client/utils.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
/*
* Copyright 2025, Salesforce, Inc.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
import { SourceComponent, SourceComponentWithContent } from '../resolve/sourceComponent';

export const isWebAppBundle = (component: SourceComponent): component is SourceComponentWithContent =>
Copy link
Contributor Author

Choose a reason for hiding this comment

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

was repeated in a few places. made it a TS guard to help stuff downstream of the guard not have to barbarically assert content!

component.type.name === 'DigitalExperienceBundle' &&
component.fullName.startsWith('web_app/') &&
typeof component.content === 'string';
2 changes: 2 additions & 0 deletions src/resolve/sourceComponent.ts
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,8 @@ export type ComponentProperties = {
parentType?: MetadataType;
};

export type SourceComponentWithContent = SourceComponent & { content: string };

/**
* Representation of a MetadataComponent in a file tree.
*/
Expand Down
38 changes: 38 additions & 0 deletions test/client/metadataApiDeploy.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1293,6 +1293,44 @@ describe('MetadataApiDeploy', () => {
result.getFileResponses();
expect(spy.callCount).to.equal(1);
});

it('should prepend projectDirectory to filePaths when projectDirectory differs from cwd', () => {
const component = matchingContentFile.COMPONENT;
const projectDir = join('my', 'project', 'dir');
const deployedSet = new ComponentSet([component]);
deployedSet.projectDirectory = projectDir;
const { fullName, type, content, xml } = component;
const apiStatus: Partial<MetadataApiDeployStatus> = {
details: {
componentSuccesses: {
changed: 'true',
created: 'false',
deleted: 'false',
fullName,
componentType: type.name,
} as DeployMessage,
},
};
const result = new DeployResult(apiStatus as MetadataApiDeployStatus, deployedSet);

const responses = result.getFileResponses();
const expected: FileResponse[] = [
{
fullName,
type: type.name,
state: ComponentStatus.Changed,
filePath: join(projectDir, ensureString(content)),
},
{
fullName,
type: type.name,
state: ComponentStatus.Changed,
filePath: join(projectDir, ensureString(xml)),
},
];

expect(responses).to.deep.equal(expected);
});
});
});

Expand Down