Skip to content

Scripts: plugin-zip command does not exclude files not included in files field #61171

@t-hamano

Description

@t-hamano

Description

Originally reported in this comment.

The plugin-zip command refers to the files field in package.json and allows you to include directories and files other than the default in the zip file:

@wordpress/scripts – Block Editor Handbook > plugin-zip

However, if this field is defined, it seems that both package.json and readme.txt are always included in the zip. This means that if you want to include non-default assets in the plugin-zip command, these two files will always be included. Especially when it comes to package.json, you often don't want to include it when you want to publish your plugin.

I tried defining package.json as below, but the result did not change.

{
	"name": "test-block",
	"scripts": {
		"plugin-zip": "wp-scripts plugin-zip"
	},
	"devDependencies": {
		"@wordpress/scripts": "^27.7.0"
	},
	"files": []
}
{
	"name": "test-block",
	"scripts": {
		"plugin-zip": "wp-scripts plugin-zip"
	},
	"devDependencies": {
		"@wordpress/scripts": "^27.7.0"
	},
	"files": [ "!package.json" ]
}
{
	"name": "test-block",
	"scripts": {
		"plugin-zip": "wp-scripts plugin-zip"
	},
	"devDependencies": {
		"@wordpress/scripts": "^27.7.0"
	},
	"files": [ "!readme.txt" ]
}

Log output:

npm run plugin-zip

> plugin-zip
> wp-scripts plugin-zip

Creating archive for `test-block` plugin... 🎁

Using the `files` field from `package.json` to detect files:

  Adding `package.json`.
  Adding `readme.txt`.

Done. `test-block.zip` is ready! 🎉

Step-by-step reproduction instructions

  • Run npx @wordpress/create-block test-block
  • cd test-block
  • Update the files field in package.json
  • Run npm run plugin-zip

Screenshots, screen recording, code snippet

No response

Environment info

No response

Please confirm that you have searched existing issues in the repo.

Yes

Please confirm that you have tested with all plugins deactivated except Gutenberg.

Yes

Metadata

Metadata

Assignees

No one assigned

    Labels

    [Tool] WP Scripts/packages/scripts[Type] BugAn existing feature does not function as intended

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions