Gitlab CI - npm install command terminates current step - npm-install

Using Gitlab (Community Version 8.13) CI I want to be able to install all jspm dependencies before publishing site.
I've package.json which defines jspm as dev dependency:
{
"jspm": {
"directories": {
"baseURL": ...
},
"dependencies": {
...
},
"devDependencies": {
...
}
},
"devDependencies": {
"jspm": "^0.16.48"
}
}
Now in my .gitlab-ci.yml file I've defined a step:
jspm:
stage: jspm
script:
- echo "npm install"
- 'npm install'
- echo "Trigger jspm install"
- ./node_modules/.bin/jspm install
The problem which I have is that after npm install next script command is not being triggered.
Here you could see log from this step. Looks like npm is able to install all packages but then even next echo command is not being triggered. (To simplify the log I've removed all installed packages listed by npm).
"npm install"
$ npm install
C:\Multi-Runner\builds\c144e1e9\0\{path to website}
`-- jspm#0.16.48
{lots of dependend packages listed here}
Build succeeded
Do you have any suggestions ? I could provide more details if needed.

My gitlab runner was installed on Windows machine.
According to: https://github.com/npm/npm/issues/2938
I've changed the step:
jspm:
stage: jspm
script:
- echo "npm install"
- call npm install
- echo "Trigger jspm install"
- call ./node_modules/.bin/jspm install
And it works fine now.

Related

husky / lint-staged not running custom command or printing errors

I am trying to upgrade from husky#4.8 and lint-staged#11.2 to husky#8.0 and lint-staged##13.1 for my Nx repo. It seems that the only configuration I used to need was the following in package.json:
"scripts: {
"lint:fix": "ng lint -- --fix && npm run prettier:fix",
}
"husky": {
"hooks": {
"commit-msg": "commitlint -e $HUSKY_GIT_PARAMS"
}
},
"lint-staged": {
"*.{ts,js,css,md,html}": "npm run lint:fix",
"relative": true
}
This no longer works with the new husky and lint-staged. I followed this tutorial and installed husky: npx husky-init && npm install, installed lint-staged: npm install --save-dev lint-staged, modified the .husky/pre-commit file:
#!/bin/sh
. "$(dirname "$0")/_/husky.sh"
npx lint-staged
and added the .lintstagedrc.json file:
{
"*.ts": [
"prettier --write",
"eslint"
],
"*.html": [
"eslint",
"prettier --write"
],
"*.scss": "prettier --write"
}
When I make a new commit it seems to run. However it looks like this command either runs on every library or every staged file (I have a lot of libraries). When I change the file contents to:
{
"*.{js,ts,json,scss,md}": ["npm run lint:fix"]
}
it takes a while to run (though it seems to run and fix the linting) AND I don't get the output of my ng lint -- --fix command. If I go into the .husky/pre-commit file and change npx lint-staged to npm run lint:fix, it runs the ng lint -- --fix command, fixes what it can and prints out linting errors. However, the error doesn't prevent the commit and I have to commit any new changes that the linter fixed. With the old versions I didn't need to do this. Also I didn't need to commit a .husky/pre-commit file into my repo. (I see some workarounds that have a postinstall script that generates this file for the user).
How can I utilize lint-stage and husky newest versions to run my custom npm command so I can call ng lint like in the older versions and block commits on errors? Should I just use the older versions? Also what benefit do the newer versions provide?

Can "NPM -i" (local) install a global package without i know it?

I'm ok with local dependencies that packages install. But now I have a huge concerns about if a local installed package can install other global packages as dependencies.
as example:
npm install nunjucks
npm install sqlite
or
npm install botkit
It is not possible to mark a dependency as global in package.json, so that it is installed system-wide when you run npm i.
Here's an old comment by Isaac Schlueter stating that this will never be implemented.
Hooowever, it would be really simple to write a preinstall script to install arbitary dependencies globally.
{
"name": "Project",
"version": "1.0.0",
"description": "Preinstall script to install global deps",
"main": "index.js",
"scripts": {
"preinstall": "node -e \"const {execSync} = require('child_process'); JSON.parse(fs.readFileSync('package.json')).globalDependencies.forEach(globalDep => execSync('npm i -g ' + globalDep));\""
},
"dependencies": {
"react": "16.13.1"
},
"globalDependencies": [
"lodash"
],
"license": "ISC"
}
Copy this code into a package.json file in a folder on your PC. Then, in the folder run npm i. It will install React locally (in a node_modules folder) and it will install lodash globally.
You can verify this using: npm i ls -g --depth=0.
Reference: Install dependencies globally and locally using package.json
As to your question:
Can npm -i (local) install a global package without me knowing it?
It's not entirely silent. When running npm i for the above package.json file, you would see the following output:
> Project#1.0.0 preinstall /home/jim/Desktop/Project
> node -e "const {execSync} = require('child_process'); JSON.parse(fs.readFileSync('package.json')).globalDependencies.forEach(globalDep => execSync('npm i -g ' + globalDep));"
npm WARN Project#1.0.0 No repository field.
audited 6 packages in 1.113s
found 0 vulnerabilities
But whether you would catch this when running npm i on a large project is debatable.

run npm script after package installing

I have a simple git repository https://github.com/alexey-sh/test_webpack_with_npm
I want to use it as npm dependency but without publishing in npm.
So in other words I want to install the package in my another repository as dependency.
npm i --save git+https://github.com/alexey-sh/test_webpack_with_npm.git
But I want to use a modern js in my test_webpack_with_npm project and compile it into old javascript after package installation process. To achieve it I created npm scripts (test_webpack_with_npm package)
"scripts": {
"install": "npm run build",
"build": "webpack --mode production --config webpack.config.js",
"test": "echo \"Error: no test specified\" && exit 1"
},
so now there's a weird thing:
if I run npm run build from test_webpack_with_npm repository I can get dist/index.js without class declaration (as I expected).
but if I install the package via the following command
npm i --save git+https://github.com/alexey-sh/test_webpack_with_npm.git
I get another type of dist/index.js and there are class declaration.
How can I install the test_webpack_with_npm properly? I want to see old js in node_modules/test_webpack_with_npm/dist/index.js.
Steps to reproduce:
mkdir my_test_project
cd my_test_project
npm init
npm i --save git+https://github.com/alexey-sh/test_webpack_with_npm.git
check node_modules/test_webpack_with_npm/dist/index.js
Thanks!
the fix is very simple. just replace exclude with include in webpack config
include: path.join(__dirname, 'sources'),
that works perfectly.
updated config goes here https://github.com/alexey-sh/test_webpack_with_npm/blob/master/webpack.config.js

npm install dependencies of local modules

I'm having trouble using npm with a local module. My project's structure looks like:
package.json
local_module/
- package.json
- gulpfile.json
gulpfile.js
The main project's package.json is essentially:
{
"dependencies": {
"local_module": "file:local_module"
},
"devDependencies": {
"gulp": "..."
}
}
The local module's package.json is essentially:
{
"scripts": {
"prepublish": "gulp release"
},
"devDependencies": {
"gulp": "..."
}
}
My intention is keep my project modular by keeping local_module as its own package that is used as a dependency for the main project. I want to run npm install in the main project and use local_module from node_modules. However, local_module needs gulp installed to run the prepublish step, and when running npm install from the main project, it does not install the dependencies for local_module, and so gulp isn't installed, so it can't do the prepublish step.
Several questions like this have been asked, like NPM doesn't install module dependencies, but many are old and there are so many versions of npm that I can't get a clear solution.
How can I get npm to install local_module's dependencies before the prepublish step? I tried adding a preinstall step for the main project, e.g.
"preinstall": "cd local_module && npm install"
But it seems npm tries to run the prepublish step of local_module before running the preinstall for the main project. I want a solution that will do this in one npm install step rather than having a separate step before this to do npm install in the local module.
I have found a solution that will work for me in the immediate future. I changed local_module's package.json to:
{
"scripts": {
"prepublish": "npm install --ignore-scripts && gulp release"
},
"devDependencies": {
"gulp": "..."
}
}
When npm install is run from the main project, the prepublish step is run first in local_module, so I force prepublish to also do an install so that gulp is available to do the actual prepublish step. This is hardly ideal however.

gulp command not found

Windows 10 pro x64
I ran the following commands
npm install --global gulp-cli
npm init
Then I changed directory to my project:
npm install --save-dev gulp
then tried to run gulp and got
-bash: gulp: command not found
my package.json file reads
{
"name": "riad-kilani_v4-child",
"version": "1.0.0",
"description": "",
"main": "gulpfile.js",
"dependencies": {
"gulp-cli": "^1.2.2"
},
"devDependencies": {
"gulp": "^3.9.1",
"gulp-sass": "^2.3.2"
},
"scripts": {
"test": "echo \"Error: no test specified\" && exit 1"
},
"author": "",
"license": "ISC"
}
Any ideas on whats going on here?
I solved the problem creating an alias in ~/.bashrc like this:
alias gulp="node /home/deploy/app/node_modules/gulp/bin/gulp.js"
Just put the alias in the end of the .bashrc file, then run:
source ~/.bashrc
Test with:
gulp -v
You should see something like this:
[15:46:39] CLI version 3.9.1
[15:46:39] Local version 3.9.1
On MacOS Catalina v10.15.2, the following global install with sudo worked for me.
sudo npm install gulp -g
So I ran into this issue as well and none of the top answers were helping. Everything was installed, uninstalled, restarted, installed globally, etc., etc.... and still got the gulp command not found error. So I opened the package.json file and put in the following after the name field:
"scripts": {
"start": "gulp"
},
And then I ran npm start in git bash.
Everything ran correctly, I got my dev view in my browser # localhost and all was right with the world.
Hope this helps!
I had got into the same issue. Even after npm install gulp -g and npm install bower -g, both gulp and bower showed the error.
Here is the thing to remember.
1. gulp and bower command does not run in root (sudo). Switch back to the system user and the run it
2. Make sure the folder where you are running gulp has the user permission. else the permission will be denied
Hope this works for you
I'm using Ubuntu and found the error of -bash: gulp: command not found, too. But it became work after npm install gulp -g
I managed to fix this problem using simple 3 commands found from https://gulpjs.com/
npm install gulp-cli -g
npm install gulp -D
npx -p touch nodetouch gulpfile.js
Hope it helps someone else.
ps: it is not mandatory to use the 3rd command in order to fix the problem.
You can try:
To run this command in the terminal: npx gulp
If want know more visit this Link
For anyone else who runs into this just run npm install and npm update.
I ran npm rm --global gulp to clear out any version conflicts and then ran npm install --global gulp-cli. This did a clean install of gulp and it works flawlessly now.
On MacOS Sierra v10.12.6, the following global install with sudo worked for me.
sudo npm install gulp -g
You didn't mention which versions of node/npm you are using.
We had a similar problem and seems that gulp-sass had to be upgraded.
You can try:
rm -fr node_modules package-lock.json && npm install -g gulp-sass#3.0.0 && npm install