Skip to content

Ignore .git & node_modules in preview archive - #1367

Merged
wojtekn merged 3 commits into
Automattic:trunkfrom
grgars:archive
May 13, 2025
Merged

Ignore .git & node_modules in preview archive#1367
wojtekn merged 3 commits into
Automattic:trunkfrom
grgars:archive

Conversation

@grgar

@grgar grgar commented May 9, 2025

Copy link
Copy Markdown
Contributor

Export ignores .git and node_modules:

const isNodeModulesDirectory = relativePath.includes( 'node_modules' );
const isGitDirectory = relativePath.includes( '.git' );

Preview did not, causing a failure to create the archive for me due to the following error:

could not open for reading: .git/fsmonitor--daemon.ipc

Proposed Changes

  • Ignore .git and node_modules in wp-content.

Testing Instructions

  1. git init inside wp-content
  2. git config core.fsmonitor true if not already set globally and trigger the ipc file creation (e.g. run git status)
  3. Create a preview

Pre-merge Checklist

  • Have you checked for TypeScript, React or other console errors?
Sync ignores .git and node_modules, but preview does not.

This discrepancy was causing a failure to create the archive, due to the following error:

could not open for reading: .git/fsmonitor--daemon.ipc

@sejas sejas left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

@grgar, Thank you for creating this PR. I tested it and confirm that it works as expected, excluding the .git and node_modules folders. This will speed up the process of uploading the zip and also fix your issue.

I tried to push the changes to format the code, but I don't have write access. Could you either apply the changes to your branch or grant edit access to maintainers?

Comment thread cli/lib/archive.ts Outdated
Co-authored-by: Antonio Sejas <antonio@sejas.es>
@grgar

grgar commented May 9, 2025

Copy link
Copy Markdown
Contributor Author

Thanks @sejas, apologies I've applied your suggestion thank you.

I also don't appear to have that option to grant edit access unfortunately
image

edit: it appears to be because I put forks in a separate organisation to keep my account tidy and https://github.com/orgs/community/discussions/5634 — sorry I didn't realise the issue that causes

@sejas sejas left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

I tested this PR, and it works correctly. I confirm that preview sites work as before, with the exception that archive files will exclude development folders ('.git' and 'node_modules').

@wojtekn , I think this is good to merge.

@sejas

sejas commented May 12, 2025

Copy link
Copy Markdown
Member

I see the unit tests are failing. @grgar, could you apply this diff to fix the tests?
If you prefer, you can invite me to your forked repo. Thank you!

diff --git a/cli/lib/tests/archive.test.ts b/cli/lib/tests/archive.test.ts
index 15f2c1db..bb59ac32 100644
--- a/cli/lib/tests/archive.test.ts
+++ b/cli/lib/tests/archive.test.ts
@@ -51,7 +51,11 @@ describe( 'Archive Module', () => {
 			expect( archiver ).toHaveBeenCalledWith( 'zip', { zlib: { level: 9 } } );
 			expect( mockArchiver.pipe ).toHaveBeenCalledWith( mockWriteStream );
 			expect( path.join ).toHaveBeenCalledWith( mockSiteFolder, 'wp-content' );
-			expect( mockArchiver.directory ).toHaveBeenCalledWith( mockWpContentPath, 'wp-content' );
+			expect( mockArchiver.directory ).toHaveBeenCalledWith(
+				mockWpContentPath,
+				'wp-content',
+				expect.any( Function )
+			);
 			expect( path.join ).toHaveBeenCalledWith( mockSiteFolder, 'wp-config.php' );
 			expect( fs.existsSync ).toHaveBeenCalledWith( mockWpConfigPath );
 			expect( mockArchiver.file ).not.toHaveBeenCalled();
Co-authored-by: Antonio Sejas <antonio@sejas.es>
@grgar

grgar commented May 12, 2025

Copy link
Copy Markdown
Contributor Author

Thanks @sejas I've applied the patch and invited you to the fork if you want to push anything, sorry again about that issue I won't use an org in the future until GitHub fix the issue!

@wojtekn

wojtekn commented May 12, 2025

Copy link
Copy Markdown
Contributor

Thanks @grgar ! I triggered builds for those changes.

@sejas

sejas commented May 12, 2025

Copy link
Copy Markdown
Member

@grgar , thanks for applying the changes 🫶 .

@wojtekn, thanks for triggering the builds. All tests have passed ✅ .

@wojtekn
wojtekn merged commit 459eea3 into Automattic:trunk May 13, 2025
@grgar
grgar deleted the archive branch May 13, 2025 06:55
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

3 participants