Skip to content
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

Support directly installing and/or running without needing to clone/build the repo #26

Open
jkuester opened this issue Nov 13, 2024 · 0 comments

Comments

@jkuester
Copy link
Collaborator

jkuester commented Nov 13, 2024

Currently, anyone who wants to use the test-data-generator has to:

  • Clone the repo
  • Install it with npm ci or npm i -g (which automatically triggers the npm run build to actually build the app)
  • Actually generate the data (either with npm run generate or tdg)

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:

  1. 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.
  2. Actually commit the built directory 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 in built will 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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant