I need to setup Travis in a monorepo,
I couldn't find resources.
How can I setup the npm deploy for every package?
To setup a lerna repository with travis:
Using:
$ node -v
v10.14.2
$ npm -v
6.4.1
With the structure:
packages/
foo
index.js
package.json
package-lock.json
bar
index.js
package.json
package-lock.json
package.json
package-lock.json
lerna.json
.travis.yml
package-lock.json must be included for all packages.
package.json
{
"name": "my-project-name",
"scripts": {
"postinstall": "lerna bootstrap",
"test": "my-testing-script",
...
},
"dependencies": {
"lerna": "^3.7.1",
...
}
}
NPM script postinstall to set up the packages before running script test. Some people install the package globally, but since you already installed it locally, you don't need to.
Since this is the main package.json, you can put all the dependencies in dependencies.
The package.json for the packages can be configured as you need.
lerna.json
{
"packages": [
"packages/*"
]
}
The file can be configured however you need.
.travis.yml
language: node_js
node_js:
- "10.14"
script: npm run test
Here you can configure the testing environment the way you need.
In my case, I needed to transpile some files with babel and I used before_script to run this process before the testing script is run.
Related
I have changed a react-native package src component as per my requirement. How can I add that in my app?
(i.e) I have added react-native-floating-action and changed some styles in FloatingActionItem.js and FloatingAction.js file. How can I add the changes inside in my app.
Because If I remove the node module all the changes are gone after installing it again.
In your case, once you have modified npm package once you have to reinstall all packages and your changes are not be saved because you are installing dependency from GitHub repository. So anyway you have two options to edit npm package and save it.
Copy code from the original repository and make your own component inside your re-usable components folder. ( Before copy whole code read the license of selected package )
Simply you can fork the original repository to your github account and after that you can make changes to forked repository.
Personally I choose Second (2) option instead of First one
STEPS
Fork from the original repository
After that make clone of this forked repo to your machine and change whatever you need (Here styles).
After changing push the changes and commit into your forked repo
After that you need to remove old original package from your dependency
npm uninstall --save react-native-floating-action
After that install forked repo by this command
npm install git+https://git#github.com/myRepo/angular-translate.git
Instead of https://git#github.com/myRepo/angular-translate.git add your forked project URL here
You can write a custom script using JavaScript which capable of replace, delete and add lines.
NPM automaticly execute postinstall after npm install command. You need to put your custom script in postinstall within package.json. For an example:
package.json:
{
"name": "my_package",
"description": "",
"version": "1.0.0",
"main": "index.js",
"scripts": {
"test": "echo \"Error: no test specified\" && exit 1",
"fix:issue": "node ./scripts/issue.js",
"postinstall": "npm run fix:issue"
},
"repository": {
"type": "git",
"url": "https://github.com/ashleygwilliams/my_package.git"
},
"keywords": [],
"author": "",
"license": "ISC",
"bugs": {
"url": "https://github.com/ashleygwilliams/my_package/issues"
},
"homepage": "https://github.com/ashleygwilliams/my_package"
}
Keep your copy on root project folder or anywhere you prefer.
yarn remove <current package name in package.json>.
If this is native library, run pod install again for iOS.
yarn add file:/path-to-local-edited-package-folder
Rest of the steps will work same (pod install, etc)
Another approach as you mentioned (I don't suggest it as native libraries might not be removed completely)
Remove package from package.json.
On package.json file "library name same as current": "./<path to your folder>" or any other location.
yarn install
I've got a monorepo with roughly the following structure (npm modules):
myProject
|-base
|-ui1
|-ui2
In the base module I have all the stuff combined which my ui1 and ui2 projects use commonly. I use npm local paths to add the base module as a dependency to the ui-projects.
...
"dependencies": {
...
"base": "file:../base"
...
}
...
So far so good...
In my CI environment (Jenkins) I use npm ci to install the dependencies. Since these steps are executed parallelly, the node_modules folder of base will be deleted by the npm ci call of ui1 while ui2 is trying to install the dependencies as well. This causes random errors of course...
Now my actual question: Is there a way to tell npm ci not to delete the node_modules of path dependencies? Of course any other hint to solve this kind of problem is appreciated as well... ;)
Thanks a lot for your help!
I have seen this on github but I was still not able to get cypress to configure/download correctly. In my jenkins pipeline I run npm install but this runs into a timeout because of the proxy. It downloads all other dependencies expect cypress.
What I did was download cypress and put the zip file in the project. I then run sh "setCYPRESS_INSTALL_BINARY=cypress.zip npm i cypress" but this still fails.
Part that fails in Jenkins pipeline:
sh "npm config set proxy http://<proxy>"
sh "npm config set registry http://<proxy>/"
sh "setCYPRESS_INSTALL_BINARY=cypress.zip npm i cypress"
sh "npm i"
sh "npm run build
How can I have npm i run without download cypress. I currently cannot get passed this line sh "setCYPRESS_INSTALL_BINARY=cypress.zip npm i cypress" but I am also concerned npm i will still try to download cypress after setCYPRESS_INSTALL_BINARY actually works
-------------------------Update One-----------------
I updated the Jenkinsfile to have CYPRESS_INSTALL_BINARY=cypress.zip npm i but now I get the below error. Cypress.zip is in the project now but would really like to have it uploaded to Jenkins and just reference the file path within my Jenkinsfile.
I am not sure that is possible and the most simple solution is the one I am doing I think however it fails.
New error:
[view] Running shell script
+ CYPRESS_INSTALL_BINARY=cypress.zip
+ npm install
npm WARN locking Error: EIO: i/o error, open '/home/jenkins/.npm/_locks/staging-c21b8f081f002623.lock'
npm WARN locking /home/jenkins/.npm/_locks/staging-c21b8f081f002623.lock failed { Error: EIO: i/o error, open '/home/jenkins/.npm/_locks/staging-c21b8f081f002623.lock'
npm WARN locking stack: 'Error: EIO: i/o error, open \'/home/jenkins/.npm/_locks/staging-c21b8f081f002623.lock\'',
npm WARN locking errno: -5,
npm WARN locking code: 'EIO',
npm WARN locking syscall: 'open',
npm WARN locking path: '/home/jenkins/.npm/_locks/staging-c21b8f081f002623.lock' }
npm ERR! path /home/jenkins/.npm/_locks/staging-c21b8f081f002623.lock
npm ERR! code EIO
npm ERR! errno -5
npm ERR! syscall open
npm ERR! EIO: i/o error, open '/home/jenkins/.npm/_locks/staging-c21b8f081f002623.lock'
script returned exit code 251
I had similar issues on Windows environment. I placed cypress.zip into project's root folder.
set CYPRESS_INSTALL_BINARY=cypress.zip
echo %CYPRESS_INSTALL_BINARY%
npm install cypress --save-dev
So installation did not work, because npm executable looks for cypress in <your project folder>\node_modules\cypress\
Try to set CYPRESS_INSTALL_BINARY to absolute path.
I'm assuming you're on linux, so the way to set an environment variable is CYPRESS_INSTALL_BINARY='cypress.zip' ("set " is only used on Windows)
Cypress will not try to download the binary if it's found on the system, even when running npm install again. By default Cypress downloads the binary to ~/.cache/Cypress, so on subsequent builds Cypress will not have to extract the zip if this directory persists between builds.
The following should work:
CYPRESS_INSTALL_BINARY='cypress.zip` npm install
no need to explicitly run npm install cypress
Then, ensure the ~/.cache directory is saved after and restored before npm install across builds.
or
Pre-extract the cypress.zip onto the build system to /Cypress, and use the following:
CYPRESS_INSTALL_BINARY=0 npm install ## Don't install the binary!
CYPRESS_RUN_BINARY='Cypress/Cypress' ## this is the Cypress executable!
again, make sure /Cypress persists across builds
What if I don't cache ~/.cache ?
Well, your build will still run, but take significantly longer as Cypress will have to extract its binary on every build. Read more here about caching the binary in CI
...
Edit: For Question Update
You're still not setting environment variables correctly. This will not work:
CYPRESS_INSTALL_BINARY='cypress.zip'
npm install
You need to do:
CYPRESS_INSTALL_BINARY='cypress.zip' npm install
In one line.
or
export CYPRESS_INSTALL_BINARY='cypress.zip'
npm install
-> Why here
I created a tool to deal with this problem:
https://github.com/tomasbjerre/dictator-cypress-example
You would need to clone this repository and publish your own cypress-dictator to your private npm repository:
https://github.com/tomasbjerre/dictator-cypress
It uses dictator builder to, before npm install, copy platform specific zip-files to root of repository and make sure it is pointed at by .npmrc.
{
"message": "Copy linux cypress to cypress.zip",
"triggers": [
{
"runningOnPlatform": ["linux"]
}
],
"actions": [
{
"copyFrom": "linux-x64.zip",
"target": "cypress.zip"
}
]
}
I have a package.json file that has the following JSON at the bottom.
"scripts": {
"postinstall": [
"./node_modules/bower/bin/bower install && ./node_modules/protractor/bin/webdriver-manager update"
]
}
My reason for having this is so bower dependencies and my protractor tests will run after an "npm install". However, it seems that "postinstall" doesn't always run. I'm trying to get everything setup on Jenkins, so I'd like to be able to run the following commands and be good to go.
npm install
grunt jenkins
The jenkins task calls tasks to build, test, and run e2e tests.
I was able to fix this by changing the command from an array to a string.
"scripts": {
"postinstall": "./node_modules/bower/bin/bower install && ./node_modules/protractor/bin/webdriver-manager update"
}
I am running Jenkins on Windows and grunt v0.4.1. I added a new task grunt-replace to the grunt.js however jenkins is having an issue seeing it:
C:\Jenkins\workspace\xxx>grunt
Local Npm module "grunt-replace" not found. Is it installed?
I've tried several things...
npm install -g grunt-replace
Restarting the jenkins service
npm install grunt-replace
I have installed these as the service jenkins is running under..
What am i missing here? What is the correct way to get jenkins to see the new task?
whats the way you start your task? i would add grunt-replace to the devDependencies in your package.json , add your test-command to the scripts.test-property in your package.json, and then let jenkins execute that.
package.json
{
...some other configs
"scripts": {
"test": "grunt test"
},
"devDependencies": {
"grunt-replace": "*",
... all the grunt-modules you need to be installed
}
}
jenkins excute
$ npm install && npm test