Open mgrandi opened 5 years ago
Hmm I'll think about this. Doing the 'cleanup' does not seem easy for some files. For example, in electron, node-v57-darwin-x64/node_sqlite3.node
is never needed. But there is no way for node-sqlite3 to know what you're building for.
npm install --build-from-source sqlite3
Will build the node version, but electron-builder will detect native dependencies and rebuild them when packaging. (cfr. npmRebuild https://www.electron.build/configuration/configuration )
electron-builder configurations can be modified to only include particular files (as a workaround, just include the electron-/node_sqlite3.node and .js files).
I have the exact same issue but when building an app in the Yocto - sqlite3 adds around ~11 MB of unnecessary files (mainly that sqlite-autoconf-3280000
dir)
sqlite3/
├── [ 1377] binding.gyp
├── [ 4096] build
│ ├── [ 1509] action_after_build.target.mk
│ ├── [ 139] binding.Makefile
│ ├── [ 5815] config.gypi
│ ├── [ 4096] deps
│ │ ├── [ 1887] action_before_build.target.mk
│ │ ├── [ 146] sqlite3.Makefile
│ │ └── [ 4506] sqlite3.target.mk
│ ├── [ 14173] Makefile
│ ├── [ 4668] node_sqlite3.target.mk
│ └── [ 4096] Release
│ ├── [ 1329364] node_sqlite3.node
│ └── [ 4096] obj
│ └── [ 4096] gen
│ └── [ 4096] sqlite-autoconf-3280000
│ ├── [ 372955] aclocal.m4
│ ├── [ 7333] compile
│ ├── [ 44283] config.guess
│ ├── [ 36136] config.sub
│ ├── [ 477389] configure
│ ├── [ 7974] configure.ac
│ ├── [ 23567] depcomp
│ ├── [ 15744] INSTALL
│ ├── [ 15155] install-sh
│ ├── [ 324412] ltmain.sh
│ ├── [ 717] Makefile.am
│ ├── [ 547] Makefile.fallback
│ ├── [ 37445] Makefile.in
│ ├── [ 28537] Makefile.msc
│ ├── [ 6872] missing
│ ├── [ 3558] README.txt
│ ├── [ 7272] Replace.cs
│ ├── [ 527983] shell.c
│ ├── [ 8928] sqlite3.1
│ ├── [ 7864301] sqlite3.c
│ ├── [ 33981] sqlite3ext.h
│ ├── [ 559572] sqlite3.h
│ ├── [ 267] sqlite3.pc.in
│ ├── [ 1992] sqlite3.rc
│ └── [ 4096] tea
│ ├── [ 147] aclocal.m4
│ ├── [ 281277] configure
│ ├── [ 8308] configure.ac
│ ├── [ 4096] doc
│ │ └── [ 494] sqlite3.n
│ ├── [ 4096] generic
│ │ └── [ 123249] tclsqlite3.c
│ ├── [ 257] license.terms
│ ├── [ 15902] Makefile.in
│ ├── [ 167] pkgIndex.tcl.in
│ ├── [ 1338] README
│ ├── [ 4096] tclconfig
│ │ ├── [ 13868] install-sh
│ │ └── [ 134055] tcl.m4
│ └── [ 4096] win
│ ├── [ 13830] makefile.vc
│ ├── [ 17368] nmakehlp.c
│ └── [ 18743] rules.vc
├── [ 6862] CHANGELOG.md
├── [ 4096] cloudformation
├── [ 2814] CONTRIBUTING.md
├── [ 4096] deps
│ ├── [ 1258] common-sqlite.gypi
│ ├── [ 191] extract.py
│ ├── [ 2761] sqlite3.gyp
│ └── [ 2810415] sqlite-autoconf-3280000.tar.gz
├── [ 2286] Dockerfile
├── [ 4096] lib
│ ├── [ 4096] binding
│ │ └── [ 4096] node-v64-linux-ia32
│ │ └── [ 1329364] node_sqlite3.node
│ ├── [ 39] index.js
│ ├── [ 6437] sqlite3.js
│ └── [ 1437] trace.js
├── [ 1460] LICENSE
├── [ 4096] node_modules
│ ├── [ 4096] node-pre-gyp
│ │ ├── [ 794] appveyor.yml
│ │ ├── [ 4096] bin
│ │ │ ├── [ 3265] node-pre-gyp
│ │ │ └── [ 40] node-pre-gyp.cmd
│ │ ├── [ 12993] CHANGELOG.md
│ │ ├── [ 288] contributing.md
│ │ ├── [ 4096] lib
│ │ │ ├── [ 1909] build.js
│ │ │ ├── [ 1237] clean.js
│ │ │ ├── [ 2165] configure.js
│ │ │ ├── [ 1505] info.js
│ │ │ ├── [ 9133] install.js
│ │ │ ├── [ 4703] node-pre-gyp.js
│ │ │ ├── [ 2235] package.js
│ │ │ ├── [ 1076] pre-binding.js
│ │ │ ├── [ 3796] publish.js
│ │ │ ├── [ 567] rebuild.js
│ │ │ ├── [ 620] reinstall.js
│ │ │ ├── [ 1085] reveal.js
│ │ │ ├── [ 3212] testbinary.js
│ │ │ ├── [ 1812] testpackage.js
│ │ │ ├── [ 1723] unpublish.js
│ │ │ └── [ 4096] util
│ │ │ ├── [ 24507] abi_crosswalk.json
│ │ │ ├── [ 2998] compile.js
│ │ │ ├── [ 3642] handle_gyp_opts.js
│ │ │ ├── [ 7841] napi.js
│ │ │ ├── [ 4096] nw-pre-gyp
│ │ │ │ ├── [ 542] index.html
│ │ │ │ └── [ 160] package.json
│ │ │ ├── [ 769] s3_setup.js
│ │ │ └── [ 15445] versioning.js
│ │ ├── [ 1501] LICENSE
│ │ ├── [ 2338] package.json
│ │ └── [ 33030] README.md
│ ├── [ 4096] rimraf
│ │ ├── [ 1196] bin.js
│ │ ├── [ 765] LICENSE
│ │ ├── [ 1716] package.json
│ │ ├── [ 3600] README.md
│ │ └── [ 8994] rimraf.js
│ └── [ 4096] semver
│ ├── [ 4096] bin
│ │ └── [ 4418] semver
│ ├── [ 672] CHANGELOG.md
│ ├── [ 765] LICENSE
│ ├── [ 1565] package.json
│ ├── [ 619] range.bnf
│ ├── [ 15719] README.md
│ └── [ 38803] semver.js
├── [ 3552] package.json
├── [ 9908] README.md
├── [ 43] sqlite3.js
├── [ 4096] src
│ ├── [ 1976] async.h
│ ├── [ 12837] backup.cc
│ ├── [ 6771] backup.h
│ ├── [ 19764] database.cc
│ ├── [ 4964] database.h
│ ├── [ 249] gcc-preinclude.h
│ ├── [ 10842] macros.h
│ ├── [ 4811] node_sqlite3.cc
│ ├── [ 27143] statement.cc
│ ├── [ 6453] statement.h
│ └── [ 1153] threading.h
└── [ 4096] tools
└── [ 4096] docker
└── [ 4096] architecture
└── [ 4096] linux-arm64
├── [ 2531] Dockerfile
└── [ 1982] run.sh
30 directories, 119 files
The only required files after a successful build are:
package.json
sqlite3.js
lib/**/*
node_modules/**/*
Regarding electron-builder specifically, I don't know if it recursively goes through the sqlite3 dependency and adheres to the exclusion files defined in our package.json as well. I suppose it's worth a try.
Please test out #1186, it's on branch electron-builds-light (https://github.com/mapbox/node-sqlite3/tree/electron-builds-light)
@kewde Should it work for normal installs too, or is it an electron specific thing?
It is an electron specific thing (the fix).
The problem however is generic, you need the source code to compile it. Deleting it after it's done, means you'd have to reinstall the package whenever you change version of node (requires recompilation).
@kewde thanks.
What's the problem with deleting the source files? As you said, if you switch node version you have to recompile, so basically you have to reinstall the package.
One thing is when you are installing the module for local development, other thing is when installing in produiction
env.
Would it be possible to distinguish those two envs?
Something like when using production
env and installing modules defined in package.json
- devDependencies
are not installed. (NODE_ENV=production npm install
or npm install --production
)
What do you think?
if you switch node versions and that has an ABI change then you will need to recompile anyway, whether or not the source code is still present after the final build step. I'm not a nodejs programmer but i feel like the node_module folders should be tied to one specific version, much like the python virtualenv folders are tied to a specific python version upon creation
@mgrandi that's what I'm saying, once the modules is installed in production, any changes to the node version would require the sqlite3 module be "reinstalled" (recompiled). What I'm trying to say is that it should be safe to remove source files once the module has been installed using produciton env.
A change in node versions requires a recompilation, but not technically a complete "reinstall". A reinstall however will trigger compilation (if requested by the flags).
Will a npm install --build-from-source sqlite3
download the sources files again after they've been deleted? I would expect it to do a full reinstall, but I'd need to confirm that for sure. If so, we could trim down the folder to match only the required files for production environments.
I'm up for changing this behavior but not at the cost of suddenly 5 more issues saying that workflow suddenly broke because of the new patch.
i would expect that this project is only the sqlite3 C -> nodeJS code, and the build step would be to download the sqlite3 sources, build it , and then delete the sources afterwards
@mgrandi yup, that would be great!
@kewde I tested this, but it doesn't seem to work.
Please note that I ALWAYS have to run ./node_modules/.bin/electron-rebuild
after installing sqlite3 via npm, otherwise I get Uncaught Error: Cannot find module
.
After I run the electron-rebuild
, the build directory is created in node_modules/sqlite3. I thought the fix should clean/remove the build dir after, but this doesn't happen.
npm run dist
which creates the Joplin app also does not remove the build
dir.
I welcome PRs for this 🙂
It seems that after building using the source code, it just leaves the intermediate build files everywhere including multiple copies of the compiled sqlite3 plugins, and this is causing issues with downstream consumers of this library where
electron-builder
is including all of the files and it bloats application size by like 20 MBit seems the only file you actually need to keep is the stuff inside
sqlite3/lib/
here is the output of an electron project that uses this library as a dependency (that has 4 copies of sqlite3.node)