Best way to achieve the following (CI pipeline, npm prepare, git dependency)?

Hello.

I’m a little confused on how I could achieve the following with npm’s prepare/prepack/prepublish and was hoping to get advice:

I have an intermediate npm package I’m developing. I’ve set up gitlab CI to run npm ci on a prep phase, which is then followed up by a test phase and a build phase. I have a prepare script that runs npm run build so that I can use it as a git dependency without going through the hurdles of publishing when I’m doing dev on multiple packages. Now everything works, but there’s the issue of redundancy in the ci pipeline.

What currently happens:
CI Build

  1. Prep phase: npm ci
    a. installs node modules :heavy_check_mark:
    b. prepare (npm run build) --causes–> test and build workflows :negative_squared_cross_mark:
  2. Test phase: npm run ci:test --causes–> test workflow :heavy_check_mark:
  3. Build phase: npm run ci:build --causes–> build workflow :heavy_check_mark:

Install the package as a git dependency:

  1. Runs npm prepare when installed to dynamically build the project (so I don’t commit build files to the repo). :heavy_check_mark:

Run npm install on the package itself during dev:

  1. Runs prepare and builds the project :negative_squared_cross_mark:

What I’m looking for:
CI Build

  1. Prep phase: npm ci (only installs node_modules from clean slate) :heavy_check_mark:
  2. Test phase: npm run ci:test --causes–> test workflow :heavy_check_mark:
  3. Build phase: npm run ci:build --causes–> build workflow :heavy_check_mark:

Package as a git dep:

  1. Runs npm prepare when installed to dynamically build the project (so I don’t commit build files to the repo). :heavy_check_mark:

Run npm install on the package itself during dev:

  1. Just install dependencies :heavy_check_mark:

Based on my observations and reading over the docs, it doesn’t seem there’s a script for the slice I’m looking at. I thought prepack might be my ticket, but it didn’t seem to run when the package was installed as a git dependency (I didn’t try as published package).

I realize I could tailor my prepare script to cut down on redundancy, but it still won’t behave like desired because I want the build workflow to happen in a separate phase of the CI pipeline but execute on install of the package (again, as a git dependency).

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.