From 0d7935cd8a803ebfcef5fb5cbd9449469b0930e0 Mon Sep 17 00:00:00 2001 From: marboledacci Date: Fri, 30 Aug 2024 11:43:05 -0500 Subject: [PATCH] Fix: yarn berry install packages (#226) * Add commands to ensure usage of yarn-berry * add sudo to corepack enable * add sudo to corepack enable * Add package manager to package.json * fix linter errors * Add a second package for testing * Fix package files location * Update cache * Remove lock * Set immutable installation * Use migration command * Add yarn install in test * Add corepack enable * Update yarn version * Add env manually * Use custom command * use a different version --- .circleci/test-deploy.yml | 7 +++- sample/package-berry.json | 42 ++++++++++++++++++++++ src/commands/install-packages.yml | 4 ++- src/scripts/packages/yarn-berry-install.sh | 6 ++-- 4 files changed, 54 insertions(+), 5 deletions(-) create mode 100644 sample/package-berry.json diff --git a/.circleci/test-deploy.yml b/.circleci/test-deploy.yml index 9edf18e2..70bd9fcf 100644 --- a/.circleci/test-deploy.yml +++ b/.circleci/test-deploy.yml @@ -176,16 +176,21 @@ jobs: pkg-manager: yarn cache-version: yarn-v3 app-dir: "~/project/sample" + - run: yarn --version - run: cd ~/project/sample && yarn test integration-test-yarn-berry: + environment: + YARN_ENABLE_IMMUTABLE_INSTALLS: false executor: name: node/default steps: - checkout + - run: mv ~/project/sample/package-berry.json ~/project/sample/package.json - node/install-packages: pkg-manager: yarn-berry - cache-version: yarn-berry-v1 + cache-version: yarn-berry-v2 app-dir: "~/project/sample" + override-ci-command: yarn install - run: cd ~/project/sample && yarn test workflows: diff --git a/sample/package-berry.json b/sample/package-berry.json new file mode 100644 index 00000000..523e4439 --- /dev/null +++ b/sample/package-berry.json @@ -0,0 +1,42 @@ +{ + "name": "opd-server", + "packageManager": "yarn@4.3.0", + "version": "1.0.0", + "description": "", + "main": "index.js", + "scripts": { + "dev": "nodemon --watch 'src/**/*.ts' --exec 'ts-node --require dotenv/config' src/index.ts", + "build": "tsc -h", + "start": "node dist/index.js", + "test": "jest jest-tests", + "testmocha": "mocha mocha-tests", + "test:coverage": "jest --coverage jest-tests" + }, + "author": "", + "license": "ISC", + "devDependencies": { + "@types/cors": "^2.8.12", + "@types/dotenv": "^8.2.0", + "@types/express": "^4.17.13", + "@types/node": "^17.0.0", + "@types/node-fetch": "^3.0.2", + "jest": "^27.4.5", + "jest-junit": "^13.0.0", + "mocha-junit-reporter": "2.0.2", + "mocha-multi": "1.1.5", + "nodemon": "^2.0.20", + "ts-node": "^10.4.0", + "tslint": "^6.1.1", + "typescript": "^4.5.4" + }, + "dependencies": { + "axios": "^0.28.0", + "axios-logger": "^2.6.0", + "cors": "^2.8.5", + "dotenv": "^10.0.0", + "express": "^4.19.2", + "mocha": "^9.1.3", + "node-fetch": "^3.2.10", + "yaml": "^1.10.2" + } +} diff --git a/src/commands/install-packages.yml b/src/commands/install-packages.yml index c521b0d8..a4253b06 100644 --- a/src/commands/install-packages.yml +++ b/src/commands/install-packages.yml @@ -7,7 +7,9 @@ parameters: type: enum enum: ['npm', 'yarn', 'yarn-berry', 'pnpm'] default: 'npm' - description: Select the default node package manager to use. NPM v5+ Required. + description: | + Select the default node package manager to use. NPM v5+ Required. + To use yarn-berry your package.json must have packageManager set to a yarn berry version, otherwise it will use old yarn. with-cache: type: boolean default: true diff --git a/src/scripts/packages/yarn-berry-install.sh b/src/scripts/packages/yarn-berry-install.sh index a28398b4..a095ce41 100644 --- a/src/scripts/packages/yarn-berry-install.sh +++ b/src/scripts/packages/yarn-berry-install.sh @@ -1,5 +1,5 @@ #!/usr/bin/env bash - +corepack enable --install-directory ~/bin # Run override ci command if provided, otherwise run default yarn install # See: https://yarnpkg.com/configuration/yarnrc/#cacheFolder if [[ -n "$PARAM_CACHE_PATH" ]]; then @@ -33,12 +33,12 @@ else set -- "$@" --check-cache fi - yarn install --immutable --immutable-cache "$@" + echo y | yarn install --immutable --immutable-cache "$@" if [[ "$PARAM_CHECK_CACHE" == "detect" && -n "$ENABLE_CHECK_CACHE" ]]; then cp yarn.lock "$YARN_LOCKFILE_PATH" fi else - yarn install --immutable + echo y | yarn install --immutable fi fi \ No newline at end of file