Getting a part build artifact into another part's build before pull

Here’s my issue:

the nodejs plugin will actually run “npm install” during the pull phase before it runs the build step.
I have a dependency “model” in “bar” that is not in the npm repositories, and I have to pull in locally.
So, I have to be able to put the “model” part into the “parts/bar/src/node_modules” before I start pulling “bar”, or npm will fail to install because it can’t find “model”.
Is there a way to do this? Or is there a more elegant way that I am just missing?

Here is my snapcraft.yaml:

name: bar
version: '0.1'
grade: stable
confinement: devmode
summary: some package
description: package ahoy

    command: yarn run watch
    plugs: [network, network-bind, network-manager,network-control]

    source: "file://../../model/"
    plugin: nodejs
    source-type: local
    node-engine: "8.11.0"
    node-package-manager: "npm"
    override-build: |
      #copy model into node_modules/@lerna_monorepo/model,
      #then build bar
      snapcraftctl build
      mkdir -p $SNAPCRAFT_PART_INSTALL/node_modules/@lerna_monorepo/model
      cp package.json $SNAPCRAFT_PART_INSTALL/node_modules/@lerna_monorepo/model
      cp .gitignore $SNAPCRAFT_PART_INSTALL/node_modules/@lerna_monorepo/model
      cp -R src/ $SNAPCRAFT_PART_INSTALL/node_modules/@lerna_monorepo/model
      cp -R node_modules/ $SNAPCRAFT_PART_INSTALL/node_modules/@lerna_monorepo/model
      cp -R dist/ $SNAPCRAFT_PART_INSTALL/node_modules/@lerna_monorepo/model

    source: .
    plugin: nodejs
    node-engine: "8.11.0"
    node-package-manager: "npm"
    after: [model]
1 Like


I’m not sure if this is the best solution for your problem, but I had a similar problem building some Lua applications, where Luarocks (which is a packaging software for lua) needed to be built first, but then building the actual particular luarock packaged application would need to be done in the same tree as where I built Luarocks.

The solution I had was to modify the build commands to essentially first build Luarocks itself inside of $SNAPCRAFT_STAGE, then build the application I needed also inside of $SNAPCRAFT_STAGE, and then finally just copy everything from $SNAPCRAFT_STAGE into $SNAPCRAFT_PART_INSTALL. (also note that this meant I needed to essentially strongly order everything for the app itself to be built as the absolute last thing)

I’m not sure how much this helps you as you’re using the nodejs plugin but I’m sure you could switch from using i.e. snapcraftctl build to actually just running whatever commands the nodejs plugin runs yourself inside of $SNAPCRAFT_STAGE.


1 Like