0

I have a project which requires a preinstall script to work correctly, but the problem I face is having different environments (local and servers) which work differently and require different preinstall variables.

For local environment, it is adequate for me to have simply

"scripts": {
    "preinstall": "npx npm-force-resolutions",
    ...

But for server, I need the preinstall to include a no_proxy setting in order for it to work:

"scripts": {
    "preinstall": "no_proxy=my.proxy.com npx npm-force-resolutions",
    ...

My local (Windows environment) will not work with this no_proxy in the preinstall script, and the server won't work without the no_proxy setting, so I'm looking for a possible solution to have a custom preinstall script which will execute depending on the environment, but so far I have not come up with a working solution for this. I have tried to make own scripts that would be called in my clients build.gradle before npm install depending on the environment, but so far it has no worked. This is what I have tried:

"scripts": {
"preinstall-dev": "npx npm-force-resolutions",
"preinstall-ci": "no_proxy=my.proxy.com npx npm-force-resolutions",
 ...

Then I tried creating a gradle task in my client that would run different script depending on if environment is dev (local) and different if it is other (server)

task forceResolutions(type: NpmTask) {
    if ( devEnv == 'true' ) {
        args = ['run', 'preinstall-dev']
    }
    else {
        args = ['run', 'preinstall-ci']
    }
}

npmInstall.dependsOn forceResolutions

the devEnv is set to be true in my projects gradle.properties when I am working locally, and it is always false otherwise.

So far the only way I have gotten local and servers to work is to manually remove the no_proxy and run npm install to get the local working and put it back before I push changes to the server, this is not in anyway optimal.

This problem I am facing is related to a known issue How to fix "ReferenceError: primordials is not defined" in Node.js

so I also have graceful-js in the resolutions, but still I get the

primordials is not defined

error when I run npm install followed by npm start locally.

ps. I am not very accustomed to working on frontend tasks, especially frontend build stuff.

pps. my npm version is 6.14.8, my node.js version is 12.19.0 and my gradle-wrapper version is 7.5.1. I cannot upgrade my versions yet, as it will require massive refactoring elsewhere and is under planning stage.

ghoulfolk
  • 326
  • 7
  • 17

1 Answers1

0

okay this was my own brain freeze moment, as I had made changes to the client build.gradle file, I had completely forgot that I need to make these gradle changes viable. So my custom scripts work as intended with the new gradle task after I ran

gradlew clean build

in the project. After that everything worked as intended.

ghoulfolk
  • 326
  • 7
  • 17