Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: don't strip last folder from dir when resolving projectDir #660

Closed
wants to merge 3 commits into from

Conversation

cristiand391
Copy link
Member

What does this PR do?

Fixes NonDecompositionFinalizer finalizer resolving metadata components from the top-level folder when passing a dir path that is exactly one level below the project dir.

When running sfdx force:mdapi:convert -r mdapi -d src

plugin-source sets the outputDirectory to:
/Users/cdominguez/code/sfdx-project/src

which then in this line:

const projectDir = resolve(dirname(defaultDirectory));

dirname strips the last folder after the last / so

...
const defaultDirectory = '/Users/cdominguez/code/sfdx-project/src';
const projectDir = resolve(dirname(defaultDirectory));

// projectDir equals  '/Users/cdominguez/code/sfdx-project',  'src' was stripped from the path

and last SDR uses the projectDir to get the compSet from source, which walks the tree, scans customlabels in other folders with other dir (other src, mdapi, etc) and make this line return the wrong parentKey.

const parentKey = childNameToParentFilePath.get(childUniqueElement) ?? defaultKey;

What issues does this PR fix or reference?

forcedotcom/cli#1540
@W-11186731@

Functionality Before

NonDecompositionFinalizer scans components in root project dir which causes issues when components are found in other folders (mdapi, etc).

Functionality After

Screen Shot 2022-07-06 at 10 44 25

@cristiand391 cristiand391 requested review from a team as code owners July 6, 2022 14:04
@cristiand391 cristiand391 requested a review from jeffb-sfdc July 6, 2022 14:04
@@ -417,7 +417,7 @@ describe('Convert Transaction Constructs', () => {
state.exampleComponent = component;
});

const result = await context.nonDecomposition.finalize(nonDecomposed.DEFAULT_DIR, TREE);
const result = await context.nonDecomposition.finalize(dirname(nonDecomposed.DEFAULT_DIR), TREE);
Copy link
Member Author

Choose a reason for hiding this comment

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

Use dirname here to strip force-app from the path dir.
Screen Shot 2022-07-06 at 11 13 10

@@ -273,7 +273,7 @@ class NonDecompositionFinalizer extends ConvertTransactionFinalizer<NonDecomposi
*/
private getAllComponentsOfType(defaultDirectory: string, componentType: string): SourceComponent[] {
// assumes that defaultDir is one level below project dir
Copy link
Member

Choose a reason for hiding this comment

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

Is this comment still accurate now?

Copy link
Member Author

@cristiand391 cristiand391 Jul 6, 2022

Choose a reason for hiding this comment

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

yes, the difference now is that it doesn't strip the last member in defaultDirectory, so for force:mdapi:convert -r mdapi -d test1/test2

const defaultDirectory = '/Users/cdominguez/code/sfdx-project/test1/test2';
const projectDir = resolve(defaultDirectory);

// projectDir would equal '/Users/cdominguez/code/sfdx-project/test1/test2'

...:thinking: wouldn't this cause SDR fail to find customlabels if you have MPDs in a project? Since projectDir will not be pointing to the root project dir.

this is the only place it's being called:

const allNonDecomposed = this.getAllComponentsOfType(

@cristiand391 cristiand391 deleted the cd/nondecompfinalizer-path branch July 14, 2022 12:49
@cristiand391
Copy link
Member Author

Closed in favor of #666

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants