Skip to content

postinstall causes "npm prune --production" to rebuild everything #417

Closed

Description

@nazar-pc

Bug Report

Issue description

This should not recompile everything when pruning dev dependencies.

mediasoup/npm-scripts.js

Lines 121 to 134 in 07c206e

case 'postinstall':
{
if (!isWindows)
{
execute('make -C worker');
}
else if (!process.env.MEDIASOUP_WORKER_BIN)
{
execute(`${PYTHON} ./worker/scripts/configure.py --format=msvs -R mediasoup-worker`);
execute(`${MSBUILD} ./worker/mediasoup-worker.sln /p:Configuration=${MEDIASOUP_BUILDTYPE}`);
}
break;
}

My Dockerfile looks like this:

Details
FROM node:13

WORKDIR /code

COPY .npmrc /code/.npmrc
COPY package.json /code/package.json
COPY package-lock.json /code/package-lock.json

RUN ["npm", "ci"]

FROM node:13

WORKDIR /code

COPY --from=0 /code /code

RUN ["npm", "prune", "--production"]

FROM node:13

WORKDIR /code

COPY --from=0 /code /code
COPY tsconfig.json /code/tsconfig.json
COPY tslint.json /code/tslint.json
COPY src /code/src

RUN ["npm", "run", "test"]
RUN ["npm", "run", "build"]

FROM node:13

WORKDIR /code

COPY --from=1 /code /code
COPY --from=2 /code/dist /code/dist

ENTRYPOINT ["node", "/code/dist/index.js"]

The idea is to cache as much as possible. Which is why all depenencies are installed first, which will be used for TypeScript build, then from the same dependencies non-production modules are pruned and then build artifact is deployed.

Currently pruning also causes mediasoup build to restart, which increases build time significantly and causes some other difficulties as well.

Maybe add some check that build was already finished or something like that?

UPD: This can be an improvement rather than a bug though.

Activity

  1. ibc commented on Jun 8, 2020

    @ibc
    Member

    I don't understand what this issue or feature request is about. mediasoup is a NPM library and, like any other, it's just installed (and hence compiled) when a new version is requested or available (based on SEMVER logic in package.json).

  2. nazar-pc commented on Jun 8, 2020

    @nazar-pc
    CollaboratorAuthor

    The issue is that it is compiled once on npm ci and then once again if npm prune --production is called after that.

  3. ibc commented on Jun 9, 2020

    @ibc
    Member

    I have no idea about why it's compiled twice following those steps. First time I know about npm prune command. I just don't know about it and honestly don't have time to investigate it for now.

  4. nazar-pc commented on Jun 13, 2020

    @nazar-pc
    CollaboratorAuthor

    Closing, seems to be an upstream issue in NPM itself

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions