Search code examples
firefoxfirefox-addonfirefox-addon-sdk

cfx xpi command deleting compressed files in addon /lib directory?


I have a weird problem when trying to package a Firefox add-on built using version 1.9 of the SDK. The extensions directory structure is something like this:

├── data
│   ├── file1.js
│   ├── file2.js
│   ├── jquery.min.js
│   └── uri.js
├── lib
│   ├── file3.js
│   ├── main.js
│   ├── services
│   │   ├── file4.js
│   │   ├── file5.js
│   │   └── file6.js
│   └── uri.js
├── package.json
└── package.json.backup

As part of the build process, I am running the data and 'lib` directories through uglify.js. This appears to work fine. Basically I copy the codebase to a different location, run it through uglify and I get the same directory structure except the JS files are compressed.

Next, I run cfx xpi --pkgdir=path/to/ugly/codebase to package the code into an xpi.

If I then move the produced .xpi to a new directory, unzip it with unzip and inspect the contents, most of my lib directory has been deleted. Files in the data directory are fine.

tree resources/addon_name 
resources/addon_name
├── data
│   ├── file1.js
│   ├── file2.js
│   ├── jquery.min.js
│   └── uri.js
└── lib
    └── main.js

If I don't uglify the JS files then everything seems to work fine and when I unzip the xpi I will have a full lib directory as I would expect.

Note that this is not a problem with the uglifying process (that was the first thing I checked). When I copy the codebase and uglify it, I can stop the process at that point and list the lib directory. It will contain all the uglified JS files I would expect. It's only after packaging and subsequent unzipping that they are gone.

I have tried reproducing this issue with a brand new extension but I get a slightly different problem. Basically, files in the lib directory are deleted on packaging regardless of whether they are compressed or not. Basically my steps are:

mkdir test_extension
cd test_extension && cfx init
touch lib/uri.js // this is 
cd .. && cfx xpi pkgdir=test_extension // Have to run this part twice to get ID
mkdir unpack && mv test_textension.xpi unpack
cd unpack
unzip test_extension.xpi
ls resources/test_extension/lib
=> main.js // the uri.js file is missing

Solution

  • If lib/uri.js is not required from any js file of your add-on, it will be removed from the final XPI. So if you have require('./uri.js') in your main.js, the file should be there after the packaging.

    My guessing is that uglifying the libraries makes impossible for the current cfx tool generates the proper manifest with all dependencies. See Manifest Generation.

    Note original post on mozilla-labs-jetpack mailing list, copied the answer here to be useful to someone else that doesn't know the ML.