-
Notifications
You must be signed in to change notification settings - Fork 2
Description
Currently, anyone who wants to use the test-data-generator has to:
- Clone the repo
- Install it with
npm ciornpm i -g(which automatically triggers thenpm run buildto actually build the app) - Actually generate the data (either with
npm run generateortdg)
However, NPM actually support installing a package directly from a git repository. (E.g. npm i -g git+https://github.com/medic/test-data-generator.git). Additionally, the npx command can even allow executing an npm app from a git repo without actually persistently installing the package locally at all: npx -y git+https://github.com/medic/test-data-generator.git. Supporting this approach would dramatically reduce the friction required for someone to start using the test-data-generator.
Now for the bad news... 😬 Perhaps someone else can figure this out, but I have wasted a TON of time trying to get postinstall/build scripts to work as expected when installing an npm package from a git repo and I have concluded it is not possible at this point. I might be totally wrong here, but the way I understand things is that in NPM, there is a conceptual difference between a library's source code files and its published package files. The package files are what gets uploaded to npm.com if you publish your dependency out there. For a basic JS library with no tests, the source code files and the published files are basically the same, but for more complex repos, there is often a build process that runs when publishing a new version of the app to npm.com (to filter out tests, minify/webpack code, transpile TS code, etc). Ordinarily we think of a git repo as the place to store the source code of an app. When you try to install an npm package from a git repo, however, NPM just wants to treat the repo as if it contains the packaged version of the app.
Now, yes, technically NPM does support running some postinstall steps for a dependency even when installing the dependency from npm.com. However, in my experience, I have not been able to successfully do a tsc build when installing an NPM dependency. Despite everything I tried, it just never seemed to include the right things in context to be able to actually do a proper build. The main issue here being that this pattern does go against the npm norms which would have you do the tsc build when publishing the library to npm.com so that it does not have to be done by all your consumers...
So, as I see things we have two options for how to proceed here:
- Just publish the test-data-generator to npm.com. Ideally we could just do this via CI scripts and
semantic-release. It would require some setup work, but once we got it going it should be pretty hands-off. - Actually commit the
builtdirectory to the GitHub repo. With the built application already in the git repo, then NPM does not need to run any post-install build steps and consumers could install/run directly from the git repo as described above. The downside of this approach is that it does add noise to the repo and to PRs since the auto-generated code changes inbuiltwill be listed along side all the other source code files/diffs.
One final benefit of solving this issue (via either of the proposed approaches) would be that it would allow other projects (e.g. https://github.com/jkuester/chtoolbox) to depend on the test-data-generator as an NPM dependency. Currently this is not possible since it will try and fail to run the postinstall/build scripts.