Verified Commit 3dc3333c authored by kilianpaquier's avatar kilianpaquier
Browse files

feat(manager): add 'bun' package manager - #54 #39

parent bff7399b
Loading
Loading
Loading
Loading
+71 −71

File changed.

Preview size limit exceeded, changes collapsed.

+11 −11
Original line number Diff line number Diff line
@@ -19,10 +19,10 @@
    },
    {
      "name": "NODE_MANAGER",
      "description": "The package manager used by your project (npm, yarn or pnpm) - **if undefined, automatic detection**",
      "description": "The package manager used by your project (npm, yarn, pnpm or bun) - **if undefined, automatic detection**",
      "default": "auto",
      "type": "enum",
      "values": ["auto", "npm", "yarn", "pnpm"],
      "values": ["auto", "npm", "yarn", "pnpm", "bun"],
      "advanced": true
    },
    {
@@ -51,7 +51,7 @@
    },
    {
      "name": "NODE_BUILD_ARGS",
      "description": "npm [run script](https://docs.npmjs.com/cli/v8/commands/npm-run-script) arguments - yarn [run script](https://classic.yarnpkg.com/en/docs/cli/run) arguments - pnpm [run script](https://pnpm.io/cli/run) arguments\n\n⚠ default value should be overridden for `pnpm` as `--prod` is not a valid option",
      "description": "npm [run script](https://docs.npmjs.com/cli/v8/commands/npm-run-script) arguments - yarn [run script](https://classic.yarnpkg.com/en/docs/cli/run) arguments - pnpm [run script](https://pnpm.io/cli/run) arguments - bun [run script](https://bun.com/docs/runtime#run-a-package-json-script) arguments\n\n⚠ default value should be overridden for `pnpm` as `--prod` is not a valid option",
      "default": "run build --prod",
      "advanced": true
    },
@@ -63,13 +63,13 @@
    },
    {
      "name": "NODE_TEST_ARGS",
      "description": "npm [test](https://docs.npmjs.com/cli/v8/commands/npm-test) arguments - yarn [test](https://classic.yarnpkg.com/en/docs/cli/test) arguments - pnpm [test](https://pnpm.io/cli/test) arguments",
      "default": "test -- --coverage",
      "description": "npm [test](https://docs.npmjs.com/cli/v8/commands/npm-test) arguments - yarn [test](https://classic.yarnpkg.com/en/docs/cli/test) arguments - pnpm [test](https://pnpm.io/cli/test) arguments - bun [test](https://bun.com/docs/test) arguments",
      "default": "run test -- --coverage",
      "advanced": true
    },
    {
      "name": "NODE_INSTALL_EXTRA_OPTS",
      "description": "Extra options to install project dependencies (either [`npm ci`](https://docs.npmjs.com/cli/ci.html/), [`yarn install`](https://yarnpkg.com/cli/install) or [`pnpm install`](https://pnpm.io/cli/install))",
      "description": "Extra options to install project dependencies (either [`npm ci`](https://docs.npmjs.com/cli/ci.html/), [`yarn install`](https://yarnpkg.com/cli/install), [`pnpm install`](https://pnpm.io/cli/install) or [`bun install`](https://bun.com/docs/pm/cli/install))",
      "advanced": true
    }
  ],
@@ -82,7 +82,7 @@
      "variables": [
        {
          "name": "NODE_LINT_ARGS",
          "description": "npm [run script](https://docs.npmjs.com/cli/v8/commands/npm-run-script) arguments to execute the lint analysis - yarn [run script](https://classic.yarnpkg.com/en/docs/cli/run) arguments to execute the lint analysis - pnpm [run script](https://pnpm.io/cli/run) arguments to execute the lint analysis",
          "description": "npm [run script](https://docs.npmjs.com/cli/v8/commands/npm-run-script) arguments to execute the lint analysis - yarn [run script](https://classic.yarnpkg.com/en/docs/cli/run) arguments to execute the lint analysis - pnpm [run script](https://pnpm.io/cli/run) arguments to execute the lint analysis - bun [run script](https://bun.com/docs/runtime#run-a-package-json-script) arguments to execute the lint analysis",
          "default": "run lint",
          "advanced": true
        }
@@ -96,7 +96,7 @@
      "variables": [
        {
          "name": "NODE_AUDIT_ARGS",
          "description": "npm [audit](https://docs.npmjs.com/cli/v8/commands/npm-audit) arguments - yarn [audit](https://classic.yarnpkg.com/en/docs/cli/audit) arguments - [pnpm audit](https://pnpm.io/cli/audit) arguments",
          "description": "npm [audit](https://docs.npmjs.com/cli/v8/commands/npm-audit) arguments - yarn [audit](https://classic.yarnpkg.com/en/docs/cli/audit) arguments - [pnpm audit](https://pnpm.io/cli/audit) arguments - [bun audit](https://bun.com/docs/pm/cli/audit) arguments",
          "default": "--audit-level=low"
        }
      ]
@@ -109,7 +109,7 @@
      "variables": [
        {
          "name": "NODE_OUTDATED_ARGS",
          "description": "npm [outdated](https://docs.npmjs.com/cli/v8/commands/npm-outdated) arguments - yarn [outdated](https://classic.yarnpkg.com/lang/en/docs/cli/outdated/) arguments - pnpm [outdated](https://pnpm.io/cli/outdated) arguments",
          "description": "npm [outdated](https://docs.npmjs.com/cli/v8/commands/npm-outdated) arguments - yarn [outdated](https://classic.yarnpkg.com/lang/en/docs/cli/outdated/) arguments - pnpm [outdated](https://pnpm.io/cli/outdated) arguments - bun [outdated](https://bun.com/docs/pm/cli/outdated) arguments",
          "default": "--long"
        }
      ]
@@ -183,7 +183,7 @@
      "variables": [
        {
          "name": "NODE_PUBLISH_ARGS",
          "description": "npm [publish](https://docs.npmjs.com/cli/v8/commands/npm-publish) extra arguments - yarn [publish](https://classic.yarnpkg.com/lang/en/docs/cli/publish/) extra arguments - pnpm [publish](https://pnpm.io/cli/publish) extra arguments",
          "description": "npm [publish](https://docs.npmjs.com/cli/v8/commands/npm-publish) extra arguments - yarn [publish](https://classic.yarnpkg.com/lang/en/docs/cli/publish/) extra arguments - pnpm [publish](https://pnpm.io/cli/publish) extra arguments - bun [publish](https://bun.com/docs/pm/cli/publish) extra arguments",
          "advanced": true
        },
        {
+49 −16
Original line number Diff line number Diff line
@@ -23,12 +23,13 @@ spec:
      description: The Docker image used to run Node.js - **set the version required by your project**
      default: docker.io/library/node:lts-alpine
    manager:
      description: The package manager used by your project (npm, yarn or pnpm) - **if undefined, automatic detection**
      description: The package manager used by your project (npm, yarn, pnpm or bun) - **if undefined, automatic detection**
      options:
      - auto
      - npm
      - yarn
      - pnpm
      - bun
      default: auto
    project-dir:
      description: Node project root directory
@@ -54,7 +55,7 @@ spec:
      default: dist
    test-args:
      description: npm [test](https://docs.npmjs.com/cli/v8/commands/npm-test) arguments - yarn [test](https://classic.yarnpkg.com/en/docs/cli/test) arguments - pnpm [test](https://pnpm.io/cli/test) arguments
      default: test -- --coverage
      default: run test -- --coverage
    install-extra-opts:
      description: Extra options to install project dependencies (either [`npm ci`](https://docs.npmjs.com/cli/ci.html/), [`yarn install`](https://yarnpkg.com/cli/install) or [`pnpm install`](https://pnpm.io/cli/install))
      default: ''
@@ -505,6 +506,10 @@ stages:
      log_info "--- Build system explictly declared: pnpm"
      return
      ;;
    bun)
      log_info "--- Build system explictly declared: bun"
      return
      ;;
    *)
      log_warn "--- Unknown declared node manager system: \\e[33;1m${NODE_MANAGER}\\e[0m: please read template doc"
      ;;
@@ -522,6 +527,10 @@ stages:
    then
      log_info "--- Build system auto-detected: pnpm"
      export NODE_MANAGER="pnpm"
    elif [[ -f "bun.lock" ]]
    then
      log_info "--- Build system auto-detected: bun"
      export NODE_MANAGER="bun"
    else
      log_error "--- Node manager system auto-detect failed: please read template doc"
      exit 1
@@ -594,10 +603,29 @@ stages:
    fi
  }

  function check_pnpm_installation() {
    if ! command -v pnpm >/dev/null; then
      log_info "--- pnpm not found: installing it"
      npm install -g pnpm
  function configure_registry() {
    # NPM_CONFIG_REGISTRY is not supported by old npm versions: force with cli
    config_registry=${NODE_CONFIG_REGISTRY:-$NPM_CONFIG_REGISTRY}
    [[ "$config_registry" ]] || return 0

    case "$NODE_MANAGER" in
      npm|pnpm) $NODE_MANAGER config set registry "$config_registry" ;;
      bun) log_warn "NODE_CONFIG_REGISTRY or NPM_CONFIG_REGISTRY is provided by 'bun' doesn't yet handle 'bun config set registry'" ;;
      yarn)
        version=$(yarn --version)
        if [[ "${version%%.*}" -lt 3 ]]; then
          $NODE_MANAGER config set registry "$config_registry"
        else
          $NODE_MANAGER config set npmRegistryServer "$config_registry"
        fi
        ;;
      esac
  }

  function check_manager_installation() {
    if ! command -v "$NODE_MANAGER" >/dev/null; then
      log_info "--- $NODE_MANAGER not found: installing it"
      npm install -g "$NODE_MANAGER"
    fi
  }

@@ -638,6 +666,7 @@ stages:
    - name: "$TBC_TRACKING_IMAGE"
      command: ["--service", "node", "5.0.3"]
  variables:
    BUN_INSTALL_CACHE_DIR: "$CI_PROJECT_DIR/$NODE_PROJECT_DIR/.bun"
    # Yarn cache (better than --cache-folder option, deprecated)
    YARN_CACHE_FOLDER: "$CI_PROJECT_DIR/$NODE_PROJECT_DIR/.yarn"
    # NPM cache
@@ -647,6 +676,7 @@ stages:
  cache:
    key: "$CI_COMMIT_REF_SLUG-node"
    paths:
      - $NODE_PROJECT_DIR/.bun/
      - $NODE_PROJECT_DIR/.npm/
      - $NODE_PROJECT_DIR/.yarn/
  before_script:
@@ -654,11 +684,9 @@ stages:
    - install_ca_certs "${CUSTOM_CA_CERTS:-$DEFAULT_CA_CERTS}"
    - cd ${NODE_PROJECT_DIR}
    - guess_node_manager_system
    - config_registry=${NODE_CONFIG_REGISTRY:-$NPM_CONFIG_REGISTRY}
    # pnpm should be installed before using it
    - if [ "$NODE_MANAGER" = "pnpm" ]; then check_pnpm_installation; fi
    # NPM_CONFIG_REGISTRY is not supported by old npm versions: force with cli
    - if [[ "$config_registry" ]]; then $NODE_MANAGER config set registry $config_registry; fi
    # pnpm & bun should be installed before using it
    - if [ "$NODE_MANAGER" = "pnpm" ] || [ "$NODE_MANAGER" = "bun" ]; then check_manager_installation; fi
    - configure_registry
    - configure_scoped_registries
    - |
      case "$NODE_MANAGER" in
@@ -672,6 +700,9 @@ stages:
      yarn)
        yarn install --immutable --check-cache $NODE_INSTALL_EXTRA_OPTS
        ;;
      bun)
        bun install --frozen-lockfile $NODE_INSTALL_EXTRA_OPTS
        ;;
      esac

node-build:
@@ -708,6 +739,8 @@ node-build:
node-lint:
  extends: .node-base
  stage: build
  variables:
    NODE_LINT_CACHE_ARGS: --ignore-pattern .bun --ignore-pattern .yarn --ignore-pattern .npm
  script:
    - mkdir -p -m 777 reports
    # maybe generate ESLint report for SonarQube
@@ -719,9 +752,9 @@ node-lint:
        log_info "SonarQube detected: producing ESLint JSON report..."
        if [ "$NODE_MANAGER" = "pnpm" ]
        then
          $NODE_MANAGER $NODE_LINT_ARGS --format=json --output-file=reports/node-lint.xslint.json || true
          $NODE_MANAGER $NODE_LINT_ARGS --format=json --output-file=reports/node-lint.xslint.json $NODE_LINT_CACHE_ARGS || true
        else
          $NODE_MANAGER $NODE_LINT_ARGS -- --format=json --output-file=reports/node-lint.xslint.json || true
          $NODE_MANAGER $NODE_LINT_ARGS -- --format=json --output-file=reports/node-lint.xslint.json $NODE_LINT_CACHE_ARGS || true
        fi
      fi
    # maybe add eslint-formatter-gitlab
@@ -736,9 +769,9 @@ node-lint:
    - |
      if [ "$NODE_MANAGER" = "pnpm" ]
      then
        ESLINT_CODE_QUALITY_REPORT=reports/node-lint.gitlab.json $NODE_MANAGER $NODE_LINT_ARGS --format=gitlab
        ESLINT_CODE_QUALITY_REPORT=reports/node-lint.gitlab.json $NODE_MANAGER $NODE_LINT_ARGS --format=gitlab $NODE_LINT_CACHE_ARGS
      else
        ESLINT_CODE_QUALITY_REPORT=reports/node-lint.gitlab.json $NODE_MANAGER $NODE_LINT_ARGS -- --format=gitlab
        ESLINT_CODE_QUALITY_REPORT=reports/node-lint.gitlab.json $NODE_MANAGER $NODE_LINT_ARGS -- --format=gitlab $NODE_LINT_CACHE_ARGS
      fi
  artifacts:
    when: always # store artifact even if test Failed