node-archiver icon indicating copy to clipboard operation
node-archiver copied to clipboard

Missing directory entry

Open fnando opened this issue 3 years ago • 2 comments

Hi there!

I'm trying to create a zip file and I'm noticing one inconsistency when generating the same zip using the CLI (zip command) versus archiver.

This is file file structure:

$ tree build
build
└── com.fnando.sd-hello.sdPlugin
    ├── css
    │     ├── custom.css
    │     └── sdpi.css
    ├── images
    │     ├── actions
    │     │     ├── Hello
    │     │     │     ├── Key.png
    │     │     │     └── [email protected]
    │     │     ├── Hello.png
    │     │     └── [email protected]
    │     ├── category.png
    │     ├── [email protected]
    │     ├── plugin.png
    │     └── [email protected]
    ├── manifest.json
    ├── plugin.html
    ├── plugin.js
    ├── propertyInspector.html
    ├── propertyInspector.js
    └── propertyInspectors

6 directories, 15 files

From the CLI, I'm running the following commands:

$ pwd
~/Projects/personal/sd-sample/com.fnando.sd-hello.streamDeckPlugin

$ zip ~/Downloads/com.fnando.sd-hello.streamDeckPlugin -r com.fnando.sd-hello.sdPlugin

$ unzip -l ~/Downloads/com.fnando.sd-hello.streamDeckPlugin
Archive:  /Users/fnando/Downloads/com.fnando.sd-hello.streamDeckPlugin
  Length      Date    Time    Name
---------  ---------- -----   ----
        0  02-06-2022 20:36   com.fnando.sd-hello.sdPlugin/
        0  02-06-2022 20:36   com.fnando.sd-hello.sdPlugin/css/
        0  02-06-2022 20:36   com.fnando.sd-hello.sdPlugin/css/custom.css
        0  02-06-2022 20:36   com.fnando.sd-hello.sdPlugin/images/
        0  02-06-2022 20:36   com.fnando.sd-hello.sdPlugin/images/actions/
        0  02-06-2022 20:36   com.fnando.sd-hello.sdPlugin/images/actions/Hello/
        0  02-06-2022 20:36   com.fnando.sd-hello.sdPlugin/propertyInspectors/
       33  02-06-2022 20:36   com.fnando.sd-hello.sdPlugin/plugin.html
      205  02-06-2022 20:36   com.fnando.sd-hello.sdPlugin/propertyInspector.html
      599  02-06-2022 20:36   com.fnando.sd-hello.sdPlugin/images/category.png
      755  02-06-2022 20:36   com.fnando.sd-hello.sdPlugin/manifest.json
     1112  02-06-2022 20:36   com.fnando.sd-hello.sdPlugin/images/actions/Hello.png
     1210  02-06-2022 20:36   com.fnando.sd-hello.sdPlugin/images/plugin.png
     1368  02-06-2022 20:36   com.fnando.sd-hello.sdPlugin/images/[email protected]
     1813  02-06-2022 20:36   com.fnando.sd-hello.sdPlugin/images/actions/Hello/Key.png
     2465  02-06-2022 20:36   com.fnando.sd-hello.sdPlugin/images/[email protected]
     3077  02-06-2022 20:36   com.fnando.sd-hello.sdPlugin/images/actions/[email protected]
     4337  02-06-2022 20:36   com.fnando.sd-hello.sdPlugin/images/actions/Hello/[email protected]
    20431  02-06-2022 20:36   com.fnando.sd-hello.sdPlugin/plugin.js
    20781  02-06-2022 20:36   com.fnando.sd-hello.sdPlugin/propertyInspector.js
    44476  02-06-2022 20:36   com.fnando.sd-hello.sdPlugin/css/sdpi.css
---------                     -------
   102662                     21 files

The above output is the expected structure; notice the first entry, a com.fnando.sd-hello.sdPlugin/ directory.

Now, using the code below, I'm able to generate a very similar zip file, except that it doesn't contain this same directory listed.

function archive(pluginId: string, distDir: string) {
  const outputPath = path.join(process.cwd(), `${pluginId}.streamDeckPlugin`);
  const output = fs.createWriteStream(outputPath);

  fs.rmSync(outputPath, { force: true });

  const archive = archiver("zip", { zlib: { level: 9 } });

  archive.on("error", (err) => {
    throw err;
  });

  archive.pipe(output);
  archive.directory(distDir, path.basename(distDir));
  archive.finalize();
}

If I list the zip files, this is the output:

$ unzip -l com.fnando.sd-hello.streamDeckPlugin
Archive:  com.fnando.sd-hello.streamDeckPlugin
  Length      Date    Time    Name
---------  ---------- -----   ----
        0  02-07-2022 04:43   com.fnando.sd-hello.sdPlugin/css/
        0  02-07-2022 04:43   com.fnando.sd-hello.sdPlugin/css/custom.css
        0  02-07-2022 04:43   com.fnando.sd-hello.sdPlugin/images/
        0  02-07-2022 04:43   com.fnando.sd-hello.sdPlugin/images/actions/
        0  02-07-2022 04:43   com.fnando.sd-hello.sdPlugin/images/actions/Hello/
        0  02-07-2022 04:43   com.fnando.sd-hello.sdPlugin/propertyInspectors/
       33  02-07-2022 04:43   com.fnando.sd-hello.sdPlugin/plugin.html
      205  02-07-2022 04:43   com.fnando.sd-hello.sdPlugin/propertyInspector.html
      599  02-07-2022 04:43   com.fnando.sd-hello.sdPlugin/images/category.png
      755  02-07-2022 04:43   com.fnando.sd-hello.sdPlugin/manifest.json
     1112  02-07-2022 04:43   com.fnando.sd-hello.sdPlugin/images/actions/Hello.png
     1210  02-07-2022 04:43   com.fnando.sd-hello.sdPlugin/images/plugin.png
     1368  02-07-2022 04:43   com.fnando.sd-hello.sdPlugin/images/[email protected]
     1813  02-07-2022 04:43   com.fnando.sd-hello.sdPlugin/images/actions/Hello/Key.png
     2465  02-07-2022 04:43   com.fnando.sd-hello.sdPlugin/images/[email protected]
     3077  02-07-2022 04:43   com.fnando.sd-hello.sdPlugin/images/actions/[email protected]
     4337  02-07-2022 04:43   com.fnando.sd-hello.sdPlugin/images/actions/Hello/[email protected]
    20431  02-07-2022 04:43   com.fnando.sd-hello.sdPlugin/plugin.js
    20781  02-07-2022 04:43   com.fnando.sd-hello.sdPlugin/propertyInspector.js
    44476  02-07-2022 04:43   com.fnando.sd-hello.sdPlugin/css/sdpi.css
---------                     -------
   102662                     20 files

Notice that the first zip lists 21 entries, whereas the one generated by archiver returns only 20 entries. Unfortunately, this inconsistency is preventing this file from being installed with Elgato's Stream Deck app (I assume they're checking for that one specific entry to validate whether the extension is valid or not).

The expectation is that both files would list the exact same 21 entries. Maybe I'm missing an option or something, so let me know if you want me to try anything.

fnando avatar Feb 07 '22 05:02 fnando

thanks, I meet the same issue

cklxiaocui avatar Jul 15 '22 01:07 cklxiaocui