-
-
Notifications
You must be signed in to change notification settings - Fork 1.3k
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
Running into problems upgrading to v3.0.0 #297
Comments
* Updated js libraries used where new versions where available. * Added version nr to js file headers if none where there to make checking if an upgrade is needed easier for the future. * Add a local fall-back to the jQuery loading just in case the Google CDN goes down again. * Added version nr variable to the js file includes to allow them to break out of the cache/ensure the browser cache will be refreshed with the updated files. ~~* Updated "our" js for the extensive changes in the jszip library Ref: http://stuk.github.io/jszip/documentation/upgrade_guide.html ~~ Upgraded the JSZip library from v 2.5.0 to 2.6.0, but **_not_** to 3.0.0 as for some reason everything breaks with v3, even when the upgrade guide has been followed to the letter. See: Stuk/jszip#297
The issue comes from zip = new JSZip();
zip.loadAsync( data );
zip.file( tgmpaDir + '/example.php' )....
JSZip.loadAsync(data).then(function(zip){
// ...
}); The upgrade guide is indeed confusing as it doesn't hint this change (I'll fix that). You could write the new code like this: var tgmpaDir = 'TGM-Plugin-Activation-2.5.2';
if ( !JSZip.support.blob ) {
showMessage( 'This browser is not supported.', 'warning' );
return;
}
JSZipUtils.getBinaryContent( '../releases/' + tgmpaDir + '.zip', function( err, data ) {
if ( err ) {
showMessage( 'Failed to retrieve TGMPA: ' + err, 'error' );
return false;
}
JSZip.loadAsync(data).then(function updateContent(zip) {
// replace the original file with a promise of the new content
var updatedContent = zip.file( tgmpaDir + '/example.php' ).async( 'string' ).then( function( content ) {
// <snip> Adjusting content
return newContent;
});
// updatedContent is a promise of string, resolved by JSZip
zip.file( tgmpaDir + '/example.php', updatedContent );
return zip;
}).then(function generateZip(zip) {
return zip.generateAsync( { type:'blob' } );
}).then(function success(blob) {
// Uses FileSaver.js.
saveAs( blob, tgmpaDir + '-' + slug + '.zip' );
showMessage( 'Custom TGMPA succesfully created!', 'success' );
}, function failure(e){
showMessage( 'Failed to generate Custom TGMPA file: ' + e, 'error' );
});
return false;
}); |
async and loadAsync use promises but using them or chaining them is not something obvious the first time. While this addition is not intended as a full featured guide to promises, adding some examples will ease the v2 -> v3 migration. Fix Stuk#297.
@dduponchel Thank you very much for your response. That's very helpful. Do I understand correctly that there is no way anymore to run jsZip without using async and promises ? In that case you may want to adjust/update the documentation on the following page for the new code structure (still shows three old examples): |
Updated "our" js for the extensive changes in the jszip library with graceful thanks to @dduponchel for his help. Ref: http://stuk.github.io/jszip/documentation/upgrade_guide.html Stuk/jszip#297
Updated "our" js for the extensive changes in the jszip library with graceful thanks to @dduponchel for his help. Ref: http://stuk.github.io/jszip/documentation/upgrade_guide.html Stuk/jszip#297
Updated "our" js for the extensive changes in the jszip library with graceful thanks to @dduponchel for his help. Ref: http://stuk.github.io/jszip/documentation/upgrade_guide.html Stuk/jszip#297
That's correct. I also missed a removed constructor in documentation/api_jszip/file_name.md. Thanks for the hint ! |
It seems like some of the example code in the online documentation is not up to date for v3.0.0 yet. I believe that's what is confusing me as I can't seem to get my code to work with v3.0.0.
Please note: I'm not using node.js. I am using JSZipUtils and FileSaver.
I'm getting a
TypeError: zip.file(...) is null
error on this linezip.file( tgmpaDir + '/example.php' ).async( 'string' ).then( function( content )
. The file however does exist within the zip file.Old code :
New code :
The text was updated successfully, but these errors were encountered: