apiaryio / protagonist

Protagonist is Node.js wrapper for the API Blueprint parser
MIT License
354 stars 31 forks source link

Can we slim down "release" builds? #241

Open kylef opened 5 years ago

kylef commented 5 years ago

When you npm install protagonist into a project, it takes up around 100MB, over 90MB of that is built artefacts which are not needed by Protagonist at runtime, all that is really needed from build at runtime is build/release/protagonist.node.

Screenshot 2019-07-01 at 13 38 17
kylef commented 5 years ago

Posting as a question, not sure how feasible it is. Perhaps we can hook into GYP to delete some of the build state for release builds.

kylef commented 5 years ago

In theory, something like the following should contain everything for the runtime: Screenshot 2019-07-01 at 13 51 28

We do need to consider that some of the LICENSE files for vendored dependencies are not there and how to ensure they are always present.

kylef commented 5 years ago

Looking at the GYP documentation, doesn't appear to be any hooks or way we can execute code, and even if we could it would be tricky to make it platforn independent. I think an NPM hook for postinstall may be the best option, we can produce a Node file which contains instructions to delete the artefacts for Release builds (we can omit these for debug).

pksunkara commented 5 years ago

I thought we need *.a files because protagonist.node is dynamically linked. Did you get it working after deleting those things after installing protagonist as a module?

kylef commented 5 years ago

Yes, it works. .a is a static library, it is used to build protagonist.node. protagonist.node does not dynamically link to anything other than libc++ and system libraries once built:

$ otool -L build/Release/protagonist.node
build/Release/protagonist.node:
    /usr/lib/libc++.1.dylib (compatibility version 1.0.0, current version 400.9.4)
    /usr/lib/libSystem.B.dylib (compatibility version 1.0.0, current version 1252.250.1)
gap777 commented 5 years ago

Any progress on this? We'd love to take advantage of this slimmed down release.

kylef commented 4 years ago

@gap777 There hasn't been, I am not entirely sure if it is possible from Protagonist alone. I haven't had chance to fully look into it, it might be up for discussion upstream in Node JS (node-gyp specifically: https://github.com/nodejs/node-gyp) since this can apply to all the C++ add-ons for Node.

If you want a slimmed down build, you can take a look at drafter.js, it's a pure JavaScript version of Protagonist (https://github.com/apiaryio/drafter.js/).