Skip to content

Commit 76657c5

Browse files
committed
feat: explicitly set projectDir on componentSet to prevent use of cwd
1 parent 6fefcff commit 76657c5

File tree

3 files changed

+12
-5
lines changed

3 files changed

+12
-5
lines changed

src/collections/componentSet.ts

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -64,6 +64,11 @@ export class ComponentSet extends LazyCollection<MetadataComponent> {
6464
* This is used as the value for the `version` field in the manifest.
6565
*/
6666
public sourceApiVersion: string;
67+
/**
68+
* Used to explicitly set the project directory for the component set.
69+
* When not present, sfdx-core's SfProject will use the current working directory.
70+
*/
71+
public projectDirectory?: string;
6772
public fullName?: string;
6873
public forceIgnoredPaths?: Set<string>;
6974
private logger: Logger;

src/convert/metadataConverter.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -120,7 +120,7 @@ export class MetadataConverter {
120120
const conversionPipeline = pipeline(
121121
Readable.from(components),
122122
!targetFormatIsSource && (process.env.SF_APPLY_REPLACEMENTS_ON_CONVERT === 'true' || output.type === 'zip')
123-
? (await getReplacementMarkingStream()) ?? new PassThrough({ objectMode: true })
123+
? (await getReplacementMarkingStream(cs.projectDirectory)) ?? new PassThrough({ objectMode: true })
124124
: new PassThrough({ objectMode: true }),
125125
new ComponentConverter(targetFormat, this.registry, mergeSet, defaultDirectory),
126126
writer

src/convert/replacements.ts

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -81,9 +81,11 @@ export const replacementIterations = async (input: string, replacements: MarkedR
8181
/**
8282
* Reads the project, gets replacements, removes any that aren't applicable due to environment conditionals, and returns an instance of the ReplacementMarkingStream
8383
*/
84-
export const getReplacementMarkingStream = async (): Promise<ReplacementMarkingStream | undefined> => {
84+
export const getReplacementMarkingStream = async (
85+
projectDir?: string
86+
): Promise<ReplacementMarkingStream | undefined> => {
8587
// remove any that don't agree with current env
86-
const filteredReplacements = envFilter(await readReplacementsFromProject());
88+
const filteredReplacements = envFilter(await readReplacementsFromProject(projectDir));
8789
if (filteredReplacements.length) {
8890
return new ReplacementMarkingStream(filteredReplacements);
8991
}
@@ -207,8 +209,8 @@ const getEnvValue = (env: string): string => {
207209
/**
208210
* Read the `replacement` property from sfdx-project.json
209211
*/
210-
const readReplacementsFromProject = async (): Promise<ReplacementConfig[]> => {
211-
const proj = await SfProject.resolve();
212+
const readReplacementsFromProject = async (projectDir?: string): Promise<ReplacementConfig[]> => {
213+
const proj = await SfProject.resolve(projectDir);
212214
const projJson = (await proj.resolveProjectConfig()) as { replacements?: ReplacementConfig[] };
213215
return projJson.replacements;
214216
};

0 commit comments

Comments
 (0)