@gorjusborg/hello
v1.0.1
Published
To get a grip on basics of clojurescript on node, writing a hello world app using shadow-cljs.
Downloads
4
Readme
hellow world
To get a grip on basics of clojurescript on node, writing a hello world app using shadow-cljs.
npm install -g shadow-cljs
shadow-cljs init
npm init -y
Using the approach outlined in https://medium.com/@cruzw/build-and-publish-your-first-command-line-application-with-npm-6192f4044779 for the directory layout.
npm install ws --save-dev
npm install source-map-support -save-dev
shadow-cljs node-repl
Cannot find module 'ws'
Install ws node module
npm install ws --save-dev
Get rid of no source map support warnings by installing source map support
npm install source-map-support --save-dev
Build the cli client (app is name I have it in the edn config file):
shadow-cljs compile app
The file ends up in bin/hello
. I had to set its executable bit with chmod +x
.
installing the cli app
At the root of the project:
npm install -g
uninstalling the cli app
npm uninstall -g
publishing the app to npm
I'm going by this article: https://zellwk.com/blog/publish-to-npm/.
Seems reasonable to use np
to manage the process.
Also, I'm going to be pushing a scoped package.
ignoring files
The first thing I noticed when trying to publish for the first time was that all the files in the package were being added (even hidden files). It turns out that npm will honor .gitignore, but you can also use a .npmignore file with the same syntax.
publishing and lock files
Also, it occurs to me that I don't know whether the lock file should be included in the npm package.
From the docs, it seems that npm-shrinkwrap.json predates the
package-lock.json, and you can opt to use the older file. However, you cannot
publish a package-lock.json to npm. However, you can run npm shrinkwrap
to
convert a package-lock.json to a shrinkwrap file, and that can be published to npm.
This effectively forces locks on install.
From https://docs.npmjs.com/files/shrinkwrap.json I gathered that apps deployed through npm should include a shrinkwrap file to lock dependencies when installed by users.
So, I converted the package-lock.json to npm-shrinkwrap.json by using:
npm shrinkwrap
I then did a dry run of the publish:
npm publish --dry-run
Then, I did the real publish:
npm publish
Oh, but it didn't work. I got an HTTP 402 error, I think because I'm trying to publish to a scoped package name, and I don't have a paid npm account. I can still publish to a scoped name by making it public (the default must be private).
npm publish --access public
Verifying the public package
To verify the publish worked, I ran:
npm install -g @gorjusborg/hello
This worked, and I was able to run the command (as I had the npm bin on my PATH). However, the command failed due to an import reference to the .shadow-cljs directory. This directory was stripped on publish, and it turns out the dev build needs it. Oh, and I guess I published a dev build. Oops.
So I then ran:
shadow-cljs release
This seemed to take a while, but the output file (./bin/hello) seemed to have minified javascript code in it. No more external loading from .shadow-cljs/.