-
Notifications
You must be signed in to change notification settings - Fork 88
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Setup NPM Packaging #214
Setup NPM Packaging #214
Conversation
28092f1
to
e7a05fb
Compare
HI, I'm curious if this is the kind of package that actually benefits from being a globally installable command line utility from npm? (I am not yet familiar with odoc but eager to learn). I did notice that you did not trim out any of the binary artifacts, so here's an example of how to do that. It makes the prebuilt release much leaner: https://github.com/esy-ocaml/hello-reason/blob/master/package.json#L13 |
I'd say this is unlikely |
Hej @jordwalke as it is right now using it at all requires I'll grant you that the current usage flow is far from ideal (as you can see from the suggested script in the readme), but having a release pipeline for @dbuenzli maybe we should make it clear that this And 👍 will trim down the package when I get home 📦 |
@Ostera I don't think this package requires a switch that users need to be aware of. IIRC we can just choose the proper compiler version in I don't think we need an opam switch around at runtime. |
@aantron not at runtime, but they won't be able to generate docs from |
Once again working on BuckleScript and dune projects on the same machine is going to be hard with global installations... |
@Ostera It's not the switch but the compiler version that matters (actually, the format of |
You can always do local installs and
My bad, still mix up the wording about it! This should work just as fine for any BuckleScript version. |
05d6dc2
to
2516057
Compare
Yes, you can choose 4.02.3 in the esy.json file and things will work on any project that uses a 4.02.3 compiler including BuckleScript. I can just imagine that people are going to run into some issues when the try to run
For the second point, what about making the prebuilt binaries under a package name of |
.ci/install-esy.sh
Outdated
#!/bin/bash | ||
|
||
if [[ $ESY_BUILD == YES ]]; then | ||
npm --global install esy |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@andreypopp should this be pinned to some stable version?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
yeah, esy@0.3.x
would be relatively safe (considering this project requires features new in 0.3.x, otherwise it's better to pin to 0.2.x).
.travis.yml
Outdated
|
||
env: | ||
- OCAML=4.02.3 | ||
- OCAML=4.02.3+buckle-master | ||
- OCAML=4.02.3+buckle-master ESY_BUILD=YES ESY__CACHE=/home/travis/.esy |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can you help me understand what this accomplishes? (Using buckle-master?) I've never understood why people ever use buckle-master for things. I've never come across a scenario when it was needed.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We need to build odoc
using this version of the compiler to be able to read .cmti
files compiled with it.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
But why do you need +buckle-master? Why can't you just use 4.02.3. Is the cmt data structure different for buck-master than for plain 4.02.3? I've used plain 4.02.3 to parse bs's .cmt files in the past without any trouble.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@Ostera AFAIK esy will use its own internal oap switch to build the odoc
binary.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@aantron @jordwalke I left that in there because I was installing opam/ocaml even for the esy build. I realize now that it's not needed at all, so I will remove it and make the installation optional.
package.json
Outdated
"Leo White <leo@lpw25.net>" | ||
], | ||
"esy": { | ||
"test": "make test", |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
note that this does nothing, you need to put it into "script.test"
if you want to run esy test
.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Wasn't using it anyway, will remove!
59fc37c
to
c83921e
Compare
Alright! This looks a little tidier now, let's do another round of reviews ⚔️ — I took the liberty to optimize the CI process, not to have to wait ~7 mins on every change, but instead ~2. Feedback welcome there too (I'm open to submitting a separate PR for those changes if need be). @aantron: Just like with the automatic publishing of docs, let's keep this publishing manual. Any advice on caching the opam/ocaml installations any futher? @jordwalke, @andreypopp: Could you provide insights on how to properly cache the build directory of esy? I'm noticing that @rizo: is there anything you'd like changed about this PR that would make you more comfortable with the way we would publish the @ryyppy @grabbou @dbuenzli: would like to hear your thoughts on this too 🗣 |
Shouldn't they be running it with |
.ci/install-esy.sh
Outdated
npm --global install esy@0.3.x | ||
esy --version | ||
else | ||
echo "Nothing to be done." |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Is this else
branch needed? Seeing this message in the log is not informative IMO.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It looked strange to see the script marked as ran but no output whatsoever. Perhaps I can change the text to "Skipping esy installation."
?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ended up joining the install
scripts after removing the OCAML
env variable from the esy build. This is no longer an issue.
.ci/install.sh
Outdated
@@ -0,0 +1,11 @@ | |||
#!/bin/bash |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This might be some convention but I feel like this script should be called setup
, init
or install-deps
.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I like install-deps
. Conveys a little more info about what's being installed.
- /home/travis/.opam | ||
- /home/travis/.esy | ||
- /home/travis/.nvm | ||
- ./_build/default |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Is this desirable? Do we want to keep cache even for tests executions across builds?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I had the same question. You only want to cache builds of your dependencies typically (the ~/.esy/
directory).
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Coming from bazel
I'm used to letting the build tool cache very aggressively — assuming we trust dune
to re-build and re-test incrementally, should this be a problem?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I would be fine with this if we cleaned the html _scratch
directory between test executions. Otherwise the previously generated files that are not generated in next runs might interfere with the result (i.e., it should be an error in this case).
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Good callout! Seems like a good before_script
. Let's see how it works.
Makefile
Outdated
@@ -2,6 +2,19 @@ | |||
build : | |||
dune build | |||
|
|||
.PHONY : npm |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
make npm
seems a bit ambigious to me. Again maybe this is some sort of convention but I’d call it npm-publish
.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I don't think this should be called npm-publish
, because, as I understand, it just packages things in a local _release
directory. But it shouldn't be called npm
either.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
make npm-release
?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
-release
has the danger of being interpreted as the verb, which makes it seem dangerous. How about npm-package
?
esy build | ||
|
||
.PHONY : npm-test | ||
npm-test : |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This seems very meta (ie a make command that calls esy that calls make again). How is it different to make test
?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@rizo This runs make test
in the esy environment. It doesn't seem too bad.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Alternatively, we can just call esy make test
, but I fear that from looking at the files we currently have it won't be obvious that this should be run (at some point) to make sure the build works as an npm
package.
We can also document it in the contribution guidelines.
package.json
Outdated
"name": "odoc", | ||
"version": "1.2.0", | ||
"description": "The OCaml/Reason Documentation Generator", | ||
"main": "index.js", |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Hm, are you trying to sneak in some uncommited JS? 😛
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I believe that will be a generated file.
EDIT: well, we are not targeting JS at all, so I'm not sure why we need this.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This was generated. Should be removed from the package.json
!
The ability to work with |
@jordwalke regarding your suggestion to add a version suffix to the binary name: it would avoid the conflict with the opam-installed version but I don’t understand how the build tools would find the needed versioned binaries.. |
@rizo This might not actually be a problem for odoc, in principle. odoc already has enough code to load This leaves the remaining direct uses of It may be possible to link loaders for all OCaml versions into a single odoc binary, and reconcile them somehow. The big issue would be how to avoid duplicating the vast majority of the shared code. Perhaps we can do it with a functor or some preprocessing. We would also likely need to vendor a copy of the relevant files in compiler-libs for each version of the compiler. |
@aantron Thanks for clarifying that. I’m not sure I like the megabinary idea :) But having cross-version portability would be very nice indeed. |
.ci/build.sh
Outdated
@@ -0,0 +1,11 @@ | |||
#!/bin/bash |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I suggest to rename directory .ci/
to test/ci/
, so it doesn't have to be hidden, and doesn't clutter the GitHub repo.
.travis.yml
Outdated
|
||
env: | ||
- OCAML=4.02.3 | ||
- OCAML=4.02.3+buckle-master | ||
- OCAML=4.02.3+buckle-master ESY_BUILD=YES ESY__CACHE=/home/travis/.esy |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@Ostera AFAIK esy will use its own internal oap switch to build the odoc
binary.
.travis.yml
Outdated
- ./_build/default | ||
|
||
install: | ||
- ./.ci/install.sh |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I recommend not breaking this up into files. If you'd like to move it to a shell script (for conditionals?), I suggest to create one shell script, and do things there. Perhaps one for building and one for installing, if caching happens between those two steps.
With many scripts, and some commands in the .travis.yml
file, people have to look through a lot of little files to understand what is going on.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@aantron a small problem with this approach is that the eval $(opam env)
call has to be made from an individual line in the .travis.yml
file to affect the rest of the build.
eval
from within scripts only affects the current environment, not it's parent.
We can bundle the install.sh
and install-esy.sh
, but we'd need a separate script that is run after the eval
to be able to output the ocaml/opam -[-]version
commands.
install:
- ./.ci/install.sh
- "if [[ $OCAML ]]; then eval `opam config env`; fi"
- ./.ci/print-versions.sh
Let me know what you think.
Makefile
Outdated
@@ -2,6 +2,19 @@ | |||
build : | |||
dune build | |||
|
|||
.PHONY : npm |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I don't think this should be called npm-publish
, because, as I understand, it just packages things in a local _release
directory. But it shouldn't be called npm
either.
esy build | ||
|
||
.PHONY : npm-test | ||
npm-test : |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@rizo This runs make test
in the esy environment. It doesn't seem too bad.
package.json
Outdated
"name": "odoc", | ||
"version": "1.2.0", | ||
"description": "The OCaml/Reason Documentation Generator", | ||
"main": "index.js", |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I believe that will be a generated file.
EDIT: well, we are not targeting JS at all, so I'm not sure why we need this.
Perhaps but when BS upgrades to 4.06 the same thing will happen and we'll need to clearly make sure the user knows what version their globally installed odoc is compatible with. At least a good error message is in order. I don't have too much to add besides that. Happy to see odoc get into more hands either way. |
54e4251
to
14aa5a5
Compare
@aantron @rizo I've addressed most of your suggestions. Let me know how you want to proceed! I understand there's an open question of how would this
So I don't see it as a blocker at the moment. Happy to be shown wrong! 🙌 |
fb60d2c
to
19524c5
Compare
@Ostera I don't think there's any issue. The esy/NPM odoc does not interfere with opam switches. It's how you described in your list. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It looks pretty much fine to me. We can work out any remaining quirks around release time, and maybe refactor the CI scripts over time.
language: generic | ||
language: node_js | ||
node_js: | ||
- "10" |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
What is using this?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Installing esy
requires a node environment, which we can either manage ourselves or let Travis manage for us.
+ Create package.json for 4.02.3005 switch with necessary dependencies + Make targets to build, test, and package for npm + Ignore esy output folders
This will cache the opam switch and parts of the dune build, making sure that the test-generated files (located in the `_scratch` folder) are always cleaned up before running the tests.
19524c5
to
049b4bf
Compare
Thanks @Ostera and the reviewers! |
Opening this PR for visibility/referencing, but I'll be modifying the history heavily until I get something I'm comfortable with.
Setting up
esy
seemed straightforward, although adding dependencies one by one manually is always annoying.This is missing a few things:
Publish from Travis for switch 4.02.3 on master branch tagBut so far I've managed to install the npm package locally and it runs alright 👍
If you can please give it a go!
cc/ @aantron @rizo @lpw25 @ryyppy @grabbou @avsm @ulrikstrid
ref #195