Skip to content

Conversation

@remithomas
Copy link
Contributor

@peacechen
Copy link
Collaborator

Thanks @remithomas

I haven't had a chance to test on various platforms (Win, OSX, Linux). Would be happy to merge once someone validates that.

@nfriedly
Copy link
Owner

We should really set up https://docs.travis-ci.com/user/multi-os/ and https://www.appveyor.com/

@remithomas remithomas mentioned this pull request May 31, 2018
Copy link
Owner

@nfriedly nfriedly left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks again! This is obviously an important fix, but it's causing a couple of test failures that need to be addressed. More comments below.

var args = ["--quiet", "--recurse-paths", dest].concat(source);
cp.spawn("zip", args, done);
var zip = cp.spawn("zip", args);
zip.on("exit", done);
Copy link
Owner

@nfriedly nfriedly May 31, 2018

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This passes in the exit code as the first argument, but the first argument returned to the user should be an error or null.

Come to think of it.. we should add a zip.on('error', ...); to capture any errors.

Also, lets use the close event rather than exit - because it guarantees that all underlying resources have been closed. https://nodejs.org/dist/latest-v10.x/docs/api/child_process.html#child_process_class_childprocess

So, this is my variation:

function nativeZip(dest, source, done) {
  var args = ["--quiet", "--recurse-paths", dest].concat(source);
  var zip = cp.spawn("zip", args);
  var error = null;
  zip.on("error", function(err) {
    error = err;
  });
  zip.on("close", function(code) {
    if (code !== 0 && !error) {
      error = new Error(
        "Unexpected exit code from native zip command: " + code
      );
    }
    if (error) {
      done(error);
    } else {
      done();
    }
  });
}

That allows some of the tests to pass, but there is still one failure:

  1) bestzip
       When archiving a dummy file
         Valid archive
           should contain valid data after unarchive:
     Uncaught AssertionError: expected [Error: ENOENT: no such file or directory, open '/Users/nathan.friedly/projects/node-bestzip/test/validArchiveExtract/file1.js'] to not exist
      at ReadFileContext.callback (test/bestzip.js:108:35)
      at FSReqWrap.readFileAfterOpen [as oncomplete] (fs.js:420:13)

The wording of that message is a little confusing, but basically the test expected the file to be extracted to ./file1.js but it actually gets extracted to ./Users/nathan.friedly/projects/node-bestzip/test/fixtures/file1.js

Basically, the archive that macOS's native zip creates when passed an absolute path includes that entire file path! So, we need to do something to normalize that so that both node and native produce archives that contain the same file structure from a given input. Perhaps strip the CWD from the beginning of the input strings?

Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actually, on second thought, I think nodeZip should emulate the native behavior. So, the test is wrong, and the nodeZip implimentation is wrong.. and it'll be a major version bump :/

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You right! we should emulate it !
Yes this is major bump.

We should add this in todo list and close this one ?

Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I was thinking just extend this one - make the test expect the native behavior, and then update the node zip to pass the test.

Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Do you have time available to work on that?

nodeZip(dest, sources, done);

if (which === NATIVE) {
nativeZip(dest, sources, done);
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

yay!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants