Skip to content

Conversation

cristiand391
Copy link
Member

@cristiand391 cristiand391 commented Feb 12, 2025

What does this PR do?

Fixes project retrieve start --output-dir lala writing single-file components to lala/main/default instead of lala.

How does --output-dir works?

  1. SDR does the retrieve, there's no local components to merge with so it writes them to <output-dir>/main/default
  2. project retrieve start checks if SDR retrieved files, if so then moves them from <output-dir>/main/default to <output-dir and nukes main/default.

The bug was in step 2, the command was skipping the file move if less than 2 files were retrieved (leaving single-file components like GlobalValueSet in <output-dir>/main/default.

Testing

  1. clone dreamhouse and create a scratch org
  2. create a globalvalueset in the org: sf org open -p lightning/setup/Picklists/home
  3. retrieve it to lala, see it being written to lala/main/default: sf project retrieve start -m GlobalValueSet --output-dir lala
  4. retrieve an apex class, it has 2 files (cls and meta xml) and will trigger the file move (including globalvalueset): sf project retrieve start -m ApexClass:PagedResult --output-dir lala

The component/file response check was introduced here to fix a ENOENT err:
#1236

the change in this PR updates the check to skip the file move if all retrieves failed so it shouldn't cause a regression and also fixes the ENOENT error on +1 failures:
Screenshot 2025-02-12 at 12 23 26

What issues does this PR fix or reference?

@W-17615754@
forcedotcom/cli#3177

@cristiand391 cristiand391 changed the title fix: move single file components to outdir too fix: move single file components to outdir too W-17615754 Feb 12, 2025
@shetzel
Copy link
Contributor

shetzel commented Feb 12, 2025

Code changes look good but I'd like to address 2 things found during QA/review:

  1. The file path has an extra slash so the code should use a resolved path: E.g., "filePath": "<project-dir>/dreamhouse-lwc/output//flows/Create_property.flow-meta.xml"
  2. There is no NUT that checks for the correct path. We can add one pretty easily to test/nuts/retrieve/metadata.nut.ts. Just after the 'should warn when nothing retrieved into output-dir and not throw ENOENT' test we can add something like:
it('should retrieve a single metadata file with correct path', async () => {
      const result = await testkit.retrieve({ args: '--metadata Flow:Create_property --output-dir myOutput' });
      expect(result?.status).to.equal(0);
      const retrieveResult = result?.result as unknown as RetrieveResultJson;
      expect(retrieveResult.success).to.equal(true);
      expect(retrieveResult.files).to.be.an('array').with.lengthOf(1);
      expect(retrieveResult.files[0].filePath).to.contain('dreamhouse-lwc/myOutput/flows/Create_property.flow-meta.xml');
});

@cristiand391 cristiand391 changed the title fix: move single file components to outdir too W-17615754 fix: handle single file components move to output-dir W-17615754 Feb 13, 2025
@shetzel shetzel merged commit ee567b2 into main Feb 13, 2025
43 checks passed
@shetzel shetzel deleted the cd/fix-output-mv branch February 13, 2025 15:57
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