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!
Related
I was wondering if someone could help me with my CI/CD configuration for a multi-JS project setup.
Project js-core has some core JS libaries, and project vue-core has some reusable vue components. They are both published as npm packages to the "js-core" project's repository (so that we can use a deploy token with npm publish, as opposed to using a group deploy token, where you have to script the package creation and push directly to the API).
vue-core has a dependency of js-core, so it needs to access the npm package registry of the js-core project to download it inside of the Docker CI/CD instance.
However, gitlab does not allow me to override the package registry's URL. According to some google research, setting the values with yarn config set #myorg:registry <gitlab-url> / yarn config set //gitlab.com/api/v4/... <deploy token> or npm config set #myorg:registry <gitlab-url> / npm config set //gitlab.com/api/v4/... <deploy token> should work. However I can see that it is still trying to download the packages from the vue-core package registry, even though it is disabled as a feature there.
This is the part of my .gitlab-ci.yml that runs before it fails:
image: node:17-alpine
stages:
- build
- test
before_script:
- yarn config set #myorg:registry https://gitlab.com/api/v4/projects/${NPM_PACKAGES_PROJECT_ID}/packages/npm/
- yarn config set //gitlab.com/api/v4/projects/${NPM_PACKAGES_PROJECT_ID}/packages/npm/:_authToken ${NPM_PACKAGES_PROJECT_TOKEN}
- yarn install
It fails at yarn install with:
[2/4] Fetching packages...
error An unexpected error occurred: "https://gitlab.com/api/v4/projects/<vue-core_project_id>/packages/npm/#myorg/js-core/-/#myorg/js-core-1.0.0.tgz: Request failed \"404 Not Found\"".
Where the project ID should be the value of <js-core_project_id>.
I have tried writing to all possible .npmrc file paths (~/.npmrc, ./.npmrc, ${CI_BUILD_DIR}/.npmrc, setting the values with npm config set and yarn config set, deactivating the packages feature in the gitlab project itself. I have also not found any predefined environment variables that would override my configs (see https://docs.gitlab.com/ee/ci/variables/predefined_variables.html). #myorg is correct and matches the gitlab url, as the actual value for "myorg" is a single word...
I am pretty much out of ideas at this point, any help is appreciated!
Update 1: I don't think it is a npm / yarn issue, maybe a gitlab caching problem? If I execute npm config ls -l and yarn config list the correct URLs are output in a format that works locally. I will attempt to clear the yarn cache (globally and locally) and pray that that works.
I am trying to use code formatter, Prettier, on a Bitbucket pipeline but all I get is a "prettier command not found".
This is my pipeline configuration:
mage: node:latest
pipelines:
branches:
master:
- step:
caches:
- node
script:
- npm install prettier
- prettier --check
Is it even possible to run it through pipelines or would have to forcefully do it locally?
I will suggest you follow the documentation https://prettier.io/docs/en/install.html
install prettier in your repo
npm install --save-dev --save-exact prettier
"--save-dev" because the production will not need prettier to serve your application
add your rules in .prettierrc.json file in the root of the repo
in the pipeline use
npx prettier --check .
What is that npx thing? npx ships with npm and lets you run locally installed tools. We’ll leave off the npx part for brevity throughout the rest of this file!
Note: If you forget to install Prettier first, npx will temporarily download the latest version. That’s not a good idea when using Prettier, because we change how code is formatted in each release! It’s important to have a locked down version of Prettier in your package.json. And it’s faster, too.
When you have installed prettier in your repo, you can even add pre-commit hooks to modify the staged files before pushing.
The project is passing npm run tslint in my Macbook, but it fails in CI.
CI build detail see: https://travis-ci.org/FoXZilla/short-night/builds/468354760
Your package.json lists ts-lint, which is an old copy of tslint. Remove that and it should work.
Explanation: the rules it's complaining are missing were added in versions of tslint added after ts-lint was published. Locally you might be resolving to the correct package, but in CI you probably aren't.
I working on Rails application of version 4.1.5. Rails application consists git submodules in it. I would like to change git submodules to npm package dependencies and include them to asset pipeline in a proper way. Could someone please suggest me gem or procedure to do it.
Convert a git submodule to an npm package remains a manual process.
You can see an example of such a procedure in xolvio/rtd issue 61: Convert RTD to an NPM module instead of a git submodule.
It was resolved in PR 163, and involved (that will differ depending on your own application):
Updating paths in gruntfile for npm support
keeping lib/bin around
Consolidate package deps and add bin to package.json
I am new to protractor, node and all. I have learned to create scripts with protractor. But now I need to run this test scripts along the build.
I have seen people can run it with npm test/ npm test e2e. How can I achieve this.
My project structure,
webapp/test/e2e
In my project they are using webpack and karma.
Sorry, I am really noob at this and don't know how to set it up.
We also need to configure it in Jenkins, so it runs and generates a flag for success or failure.
Any suggestions to set it up would really really be helpful. Please be as elaborate as possible as it is hard for me to understand things as of now.
Thank you so much!
If the package.json file is in the root folder of the project you can add the code below to it and run it using npm test and npm run test:e2e. This assumes you have Protractor and Karma installed locally in your project which would be a best practice (if it is not in the package.json as a dependency it probably is not).
"scripts": {
"postinstall": "node_modules/protractor/bin/webdriver-manager update",
"test": "node_modules/karma/bin/karma start webapp/test/unit/karma.conf.js"
"test:e2e": "node_modules/protractor/bin/protractor webapp/test/e2e/conf.js"
}
postinstall - This will run webdriver-manager update locally automatically after running npm install, you could run into issues with missing drivers when using a CI Server like Jenkins that is continuously checking our your repository (it also saves you a CI step)
test - This is equivalent to karma start karma.conf.js
test:e2e - This is equivalent to protractor conf.js it is just running it locally. To run these tests type npm run test:e2e from the directory with your package.json
It is recommended to not combine Protractor and Karma together (although possible) Karma should be used for Unit and Integration tests and Protractor should be used for e2e tests.
As an extra tip it is possible to pass protractor or karma command line arguments through the npm scripts. Simply append it the way you normally would (e.g.
"webapp/test/e2e/conf.js --baseUrl=https://yourbaseurl.com/")
Your question regarding integrating NPM into Jenkins has already been answered fairly well here how to run npm/grunt command from jenkins but be aware running your tests entirely in Jenkins will cause it to run headlessly which when using Windows will cause it to run in Session 0 where the screen resolution will be smaller which causes some tests to fail, opening the selenium server beforehand in a Terminal/Powershell window will cause Jenkins to route your tests through that so it will visually display on your computer.