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

Blueprints: Support zipped assets without top-level folder #491

Merged
merged 1 commit into from Jun 1, 2023

Conversation

adamziel
Copy link
Collaborator

@adamziel adamziel commented Jun 1, 2023

Installing a plugin where the plugin files are directly at the top level does not work. This PR assumes that, unless the zip file contains only a single directory, the plugin files start at the top level.

Related: #427

Unit tests included.
Run npm run dev and confirm that adding ?gutenberg-pr=47739 to the URL installs the PR.

cc @eliot-akira – I completely missed that case

@adamziel adamziel added [Type] Bug An existing feature does not function as intended [Package][@wp-playground] Blueprints labels Jun 1, 2023
@adamziel adamziel requested a review from eliot-akira June 1, 2023 15:55
@@ -51,8 +51,7 @@ foreach ( ( glob( $plugin_path . '/*.php' ) ?: array() ) as $file ) {
echo 'NO_ENTRY_FILE';
`,
});
if (result.errors) throw new Error(result.errors);
if (result.text === 'NO_ENTRY_FILE') {
if (result.text.endsWith('NO_ENTRY_FILE')) {
Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Some plugins trigger warnings during the installation – let's check just the last part of the output text

@@ -51,8 +51,7 @@ foreach ( ( glob( $plugin_path . '/*.php' ) ?: array() ) as $file ) {
echo 'NO_ENTRY_FILE';
`,
});
if (result.errors) throw new Error(result.errors);
Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Some plugins trigger warnings during the installation and they show as result.errors so we can't bale out here

@@ -164,7 +164,7 @@ export class VFSResource extends Resource {

/** @inheritDoc */
get name() {
return this.resource.path;
return this.resource.path.split('/').pop() || '';
Copy link
Collaborator Author

Choose a reason for hiding this comment

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

The resource returned a full path as a file name and that threw off installAsset

Installing a plugin where the plugin files are directly at the top level
does not work. This PR assumes that, unless the zip file contains only a
single directory, the plugin files start at the top level.

Related: #427

Unit tests included.
Run `npm run dev` and confirm that adding ?gutenberg-pr=47739 to the URL installs the PR.
@adamziel adamziel force-pushed the install-assets-without-top-level-folder branch from 4ebf208 to e30ec9b Compare June 1, 2023 16:07
@adamziel
Copy link
Collaborator Author

adamziel commented Jun 1, 2023

I'm going to merge to get the gutenberg-pr feature running again.

@adamziel adamziel merged commit 3856482 into trunk Jun 1, 2023
5 checks passed
@adamziel adamziel deleted the install-assets-without-top-level-folder branch June 1, 2023 16:12
@eliot-akira
Copy link
Collaborator

I see, thank you for the quick update, to make the installAsset function accept a zip package without a container folder inside. I seem to remember that the top-level folder was a requirement for a proper plugin zip file, but searching around I don't see it mentioned in the Plugin Developer's Handbook. Seeing how the Gutenberg PR zips were working before with the old installPlugin step (via plugin upload form in the admin), this must be supported in WordPress itself.

@adamziel
Copy link
Collaborator Author

adamziel commented Jun 2, 2023

WordPress can be confusing! Do you think this fix works, though? I know your PR specifically looked for a directory inside a zip. I also thought it made sense but I can't recall my own thinking. Since this PR removes that lookup, I wanted to check in with you to make sure my change didn't break any larger assumptions.

@eliot-akira
Copy link
Collaborator

to make sure my change didn't break any larger assumptions

My previous assumption was that plugin zip packages needed to contain a single top-level folder.

I learned it from working on a plugin update server and corresponding updater module in a number of plugins, which integrated with the WordPress plugin update process. There's a particular way the zip package is generated from a plugin, like:

zip -r plugin-name.zip plugin-name

The other ("wrong") way is:

cd plugin-name; zip -r plugin-name.zip .

I also seem to remember when I submitted a zip package for approval into the official plugin directory, it needed to have a single top-level folder inside. But I can't find that requirement written anywhere.

It seems best for installAsset step to support both formats, to be flexible for general use.

Looks like this succinct line covers it:

const zipHasRootFolder =
	files.length === 1 && (await playground.isDir(files[0]));

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
[Package][@wp-playground] Blueprints [Type] Bug An existing feature does not function as intended
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants