twolfson / grunt-zip

Zip and unzip files via a grunt plugin
MIT License
87 stars 19 forks source link

File size becomes too large when cwd is used #48

Closed alexanderby closed 6 years ago

alexanderby commented 6 years ago

Windows 10. Config looks like

{
    expand: true,
    cwd: 'build/',
    src: ['**/*'],
    dest: 'build.zip'
}

Live example (run npm run release). Expected to get 400KB but received 30MB

twolfson commented 6 years ago

It's possible this is serializing some hidden files (e.g. a .git folder). Have you inspected the .zip to see what it got?

alexanderby commented 6 years ago

Sure, I've checked, the archive contains correct files. But you are thinking in right direction, file size corresponds with the whole root folder size. If I relaunch the task, the file size gets twice bigger up to 80MB and only correct files are listed inside. Extracting the folder gives 800KB.

twolfson commented 6 years ago

Ah, I see the issue. Our cwd is a little counter-intuitive. It acts as a way to strip the path in the final result. In hindsight, it should have been built differently:

https://github.com/twolfson/grunt-zip/tree/0.17.1#using-cwd

Try using:

{
    expand: true,
    cwd: 'build/',
    src: ['build/**/*'],
    dest: 'build.zip'
}
alexanderby commented 6 years ago

It produces an error

Running "zip:release_sub4" (zip) task
Warning: Cannot read property 'src' of undefined Use --force to continue.
TypeError: Cannot read property 'src' of undefined
    at Object.<anonymous> (C:\Dev\darkreader\node_modules\grunt-zip\tasks\zip.js:31:20)
    at Object.proxiedTaskFn (C:\Dev\darkreader\node_modules\grunt-retro\tasks\retro.js:54:21)
    at Object.<anonymous> (C:\Dev\darkreader\node_modules\grunt\lib\grunt\task.js:264:15)
    at Object.thisTask.fn (C:\Dev\darkreader\node_modules\grunt\lib\grunt\task.js:82:16)
    at Object.<anonymous> (C:\Dev\darkreader\node_modules\grunt\lib\util\task.js:301:30)
    at Task.runTaskFn (C:\Dev\darkreader\node_modules\grunt\lib\util\task.js:251:24)
    at Task.<anonymous> (C:\Dev\darkreader\node_modules\grunt\lib\util\task.js:300:12)
    at C:\Dev\darkreader\node_modules\grunt\lib\util\task.js:227:11
    at _combinedTickCallback (internal/process/next_tick.js:131:7)
    at process._tickCallback (internal/process/next_tick.js:180:9)
alexanderby commented 6 years ago

It works after I've removed expand: true, thanks.

twolfson commented 6 years ago

Glad to hear it's all working =)