nfriedly / node-bestzip

Provides a `bestzip` command that uses the system `zip` if avaliable, and a Node.js implimentation otherwise.
MIT License
80 stars 16 forks source link

Different file structure results on win/linux #7

Closed Spunkie closed 6 years ago

Spunkie commented 7 years ago

I've got a cross-os NPM scripts build system and part of that is using bestzip to package the repo into an installable zip. I've got the following pack:zip script in my package.json but I'm getting different results when it's run on my windows machine versus a linux environment. Am I doing something wrong or is this a bug?


Example Info

Repo file structure:
|-- bitbucket-pipelines.yml
|-- package-lock.json
|-- package.json
|-- plg_example
    |-- debug.php
    |-- example.php
    |-- example.xml
    |-- media
        |-- compiled
        |-- css
        |-- fonts
        |-- images
        |-- index.html
        |-- js
        |-- scss
ENV vars:
npm_package_config_base_dir = "plg_example"
npm_package_version = 2.0.1
NPM Script:
"pack:zip": "cross-env-shell bestzip ${npm_package_config_base_dir}_${npm_package_version}.install.zip ${npm_package_config_base_dir}/*"

cross-env-shell in this script simply allows me to use the $ENV_VAR format on windows instead of the normal %ENV_VAR% format. So for this specific example npm should end up running a cmd that looks like bestzip plg_example_2.0.1.install.zip plg_example/* on both windows and linux.

Example Output:

On windows it produces a zip with the correct file structure:
plg_example_2.0.1.install.zip -- windows
|-- debug.php
|-- example.php
|-- example.xml
|-- media
    |-- compiled
    |-- css
    |-- fonts
    |-- images
    |-- index.html
    |-- js
    |-- scss
While on linux the resulting zip has this incorrect file structure:
plg_example_2.0.1.install.zip -- linux
|-- debug.php
|-- example.php
|-- example.xml
|-- plg_example
    |-- media
        |-- compiled
        |-- css
        |-- fonts
        |-- images
        |-- index.html
        |-- js
        |-- scss

This linux environment is based off the public node:8 docker image so you should be able to use that to reproduce this issue if need be.

nfriedly commented 7 years ago

That's strange. It's definitely a bug somewhere...

I have a pretty busy day, but I'll try and take a look sometime soon.

In the meanwhile, on your linux, can you try running the command:

zip --recurse-paths plg_example_2.0.1.install.zip plg_example/*

And also:

zip --recurse-paths plg_example_2.0.1.install.zip plg_example

And let me know if either of those produce the desired output?

Spunkie commented 7 years ago

Well apparently zip isn't installed by default on the docker node:8 image. So I first ran apt-get update && apt-get install zip and confirmed the original issues still happens when running the pack:zip script.


Both of those cmds produce this file structure.

plg_example_2.0.1.install.zip -- linux
|-- plg_example
    |-- debug.php
    |-- example.php
    |-- example.xml
    |-- media
        |-- compiled
        |-- css
        |-- fonts
        |-- images
        |-- js
        |-- scss
        |-- index.html
oserban commented 6 years ago

I know this is annoying, but this is a bug of the underlying zip command on linux. As a workaround you can do something like:

cd <folder to zip> && bestzip ../<zip file>.zip . && cd ..

I know it looks ugly, but it works and cd should be cross platform.

nfriedly commented 6 years ago

Mum, good point. Do you want to try it out and send a PR if it looks good?

dantullis commented 6 years ago

oserban's response works for me on my osx projects.

nfriedly commented 6 years ago

I know this is an old issue, but I just released v2.0.0 that includes quite a bit of reworking (and testing!) to normalize things. If you get a minute, please try it out and let me know is this is resolved or if you're still seeing problems here.