OvermindDL1 / bucklescript-tea

TEA for Bucklescript

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

discussion: make bs-platform a dev dependency?

bobzhang opened this issue · comments

currently when user install bucklescript-tea it will also install bs-platform.

Since we have -make-world, currently my workflow is npm install -g bs-platform and when I install a bucklescript project, I do an npm link then run bsb -make-world, this would save installation time significantly, what do you think?

Note this is for discussion, lets find the best workflow for a compiled language on npm

I had actually thought of making it a dev dependency in case the user already had the runtime javascript compiled elsewhere, but figured that the likelihood was fairly low. Perhaps instead of a dev dependency, which would require the user to install bs-platform separately (not a hard task and just adding a single word to the README.md) I could add it as an optional dependency instead of a hard or dev dependency? An optional dependency, if I recall correctly, will be installed with the package unless the --no-optional switch is used, at which point the optional dependencies of the given dependency will not be downloaded. Thoughts?

do you have a link of optional deps?

do you have a link of optional deps?

Main docs: https://docs.npmjs.com/files/package.json#optionaldependencies
And for the flag: https://docs.npmjs.com/cli/install

Or to save a click, here it is: :-)

If a dependency can be used, but you would like npm to proceed if it cannot be found or fails to install, then you may put it in the optionalDependencies object. This is a map of package name to version or url, just like the dependencies object. The difference is that build failures do not cause installation to fail.

It is still your program's responsibility to handle the lack of the dependency. For example, something like this:

try {
  var foo = require('foo')
  var fooVersion = require('foo/package.json').version
} catch (er) {
  foo = null
}
if ( notGoodFooVersion(fooVersion) ) {
  foo = null
}

// .. then later in your program ..

if (foo) {
  foo.doFooThings()
}

Entries in `optionalDependencies` will override entries of the same name in `dependencies`, so it's usually best to only put in one place.

And for the flag:

The --no-optional argument will prevent optional dependencies from being installed.

As an example, if someone did this in their own project:

npm install --save --no-optional bucklscript-tea

Then they'd get this as a dependency in their own package.json file:

"dependencies": {
  "bucklescript-tea": {
      "version": "^0.1.1",
      "no-optional": "true"
    }
}

do u have experience in peerdependencies?

As I recall peerDependencies do not auto-download, you are required to supply it as the user. I might be wrong about that as I've not used it, but that is what I recall reading.

@OvermindDL1 I think this is exactly what we want? we only need bs-platform as a peerdependencies? right

Only if this library can be used without bs-platform installed at all from what I'm reading at the docs: https://docs.npmjs.com/files/package.json#peerdependencies

In some cases, you want to express the compatibility of your package with a host tool or library, while not necessarily doing a require of this host. This is usually referred to as a plugin.

Which I guess it 'could' run without it if someone used the javascript straight and wrote javascript to make everything, but that sounds rather painful unless a better binding layer were written. ^.^

Here is what I have in mind: rescript-lang/rescript-compiler#1115

Hmm, I'm not sure about the peerDependency now that I'm trying it... From doing a git clone of an npm project you should be able to just do npm install && npm run <cmd> to do commands on it, and if you have, say, "clean" : "bsb -clean-world" as a task and try to do npm run clean then it fails with 'bsb' is not recognized as an internal or external command, operable program or batch file., where if it is an actual dev/optional/full-dependency then npm run clean works...

I think "The Bucklescript Way" has settled on bs-platform being a peerDependency so it can be used and installed globally without needing to special --noOptional or whatever it was, and since this library is following it, then closing this out as resolved. :-)