Using the @wordpress/scripts package, when I run the wp-scripts plugin-zip
command it generates a zip file with the /build
directory (and any other directories specified in "files": []
). But it misses all files at the root level (README, plugin entry point, etc.) even when specifically providing the file name in package.json files
.
I don’t receive any error messages — in fact the messaging in the console suggests it’s working. When I run the script I see the following in the console:
> wp-scripts plugin-zip
Creating archive for <code>@washingtonstateuniversity/hrswp-employee-recognition</code> plugin... 🎁
Using Plugin Handbook best practices to discover files:
Adding <code>CHANGELOG.md</code>.
Adding <code>LICENSE.md</code>.
Adding <code>README.md</code>.
Adding <code>build/index.asset.php</code>.
Adding <code>build/index.css</code>.
Adding <code>build/index.js</code>.
Adding <code>build/style-index.css</code>.
Adding <code>build/blocks/er-award-description/block.json</code>.
Adding <code>build/blocks/er-award-meta-year/block.json</code>.
Done. <code>@washingtonstateuniversity/hrswp-employee-recognition.zip</code> is ready! 🎉
But all I see in the generated zip file is the build
directory. It misses the entrypoint entirely and, although it says “Adding LICENSE.md”, etc., those root-level files are not in the zip.
There appear to be two issues here:
1. The plugin-zip.js
script doesn’t check for namespaces on the plugin name, and passing @namespace\plugin-name
to zip.addLocalFile()
seems to fail silently. The can be circumvented easily enough using "files": []
, but is unexpected per the documentation.
2. The plugin-zip.js
script zip.addLocalFile( file, dirname( file ) );
appears to fail when dirname( file )
is '.'
.
If I replace the existing:
zip.addLocalFile( file, dirname( file ) );
with:
if ( '.' !== dirname( file ) ) {
zip.addLocalFile( file, dirname( file ) );
} else {
zip.addLocalFile( file );
}
Then it appears to run as expected. That said, I don’t know if there is something wrong with my environment or my use of wp-scripts, as I haven’t been able to find anyone else with this problem.
My environment:
– @wordpress/scrips v22.5.0
– Node.js v16.14.2, npm v8.5.0 (same behavior seen with Node 14 and npm 6)
– WSL 2 on Windows 10