Skip to content

4.6.1 regression: local language: node hooks without additional_dependencies fail with AssertionError #3728

Description

@krassowski

search you tried in the issue tracker

4.6.1, "must have package.json or additional_dependencies"

describe your issue

Since v4.6.1, any repo: local hook using language: node without additional_dependencies fails to install its environment:

An unexpected error has occurred: AssertionError: `language: node` must have package.json or additional_dependencies

This worked in v4.6.0 and earlier. Hit in JupyterLab's release CI, where hooks like this one (running against the project's own node_modules) are common.

#3719 changed node.install_environment to only use the prefix's package.json when prefix.exists('.git') is also true:

def install_environment(
prefix: Prefix, version: str, additional_dependencies: Sequence[str],
) -> None:
if prefix.exists('.git') and prefix.exists('package.json'):
# this requires a new-enough npm (2019ish?)
pkgs = (f'git+file://{prefix.prefix_dir}', *additional_dependencies)
else:
pkgs = (*additional_dependencies,)
if not pkgs:
raise AssertionError(
'`language: node` must have package.json or '
'additional_dependencies',
)

But for local repos the prefix comes from store.make_local() - the synthesized empty-template directory, which contains empty_template_package.json but is not a git repo. So pkgs is empty and the new assertion fires. Previously the dummy package was installed with plain npm install -g ., which succeeded.

pre-commit --version

4.6.1

.pre-commit-config.yaml

ci:
  # Same schedule interval as dependabot see .github/dependabot.yml
  autoupdate_schedule: monthly
  # skip any check that needs internet access
  skip: [prettier, eslint, stylelint, shellcheck]

default_language_version:
  node: system

repos:
  - repo: https://github.com/pre-commit/pre-commit-hooks
    rev: v6.0.0
    hooks:
      - id: forbid-new-submodules
      - id: end-of-file-fixer
        exclude: galata/.*-snapshots
      - id: check-case-conflict
      - id: check-executables-have-shebangs
      - id: requirements-txt-fixer
      - id: check-added-large-files
      - id: check-toml
      - id: check-yaml
      - id: debug-statements
      - id: check-builtin-literals
      - id: trailing-whitespace
        exclude: .bumpversion.cfg
      - id: check-merge-conflict
      - id: check-symlinks
      - id: mixed-line-ending

  - repo: https://github.com/python-jsonschema/check-jsonschema
    rev: 0.37.4
    hooks:
      - id: check-github-workflows

  # Check zizmor version is aligned with the one in .github/workflows/zizmor.yml
  - repo: https://github.com/zizmorcore/zizmor-pre-commit
    rev: e3eebf65325ccc992422292cb7a4baee967cf815  # frozen: v1.26.1
    hooks:
      - id: zizmor
        args: ["--offline"]

  - repo: https://github.com/codespell-project/codespell
    rev: v2.4.2
    hooks:
      - id: codespell
        args:
          - --ignore-words=.codespellignore
          - --skip=docs/source/api/**,docs/source/getting_started/changelog.md
        files: \.(md|rst|txt)$

  # Check ruff version is aligned with the one in pyproject.toml
  - repo: https://github.com/astral-sh/ruff-pre-commit
    rev: v0.15.20
    hooks:
      - id: ruff
        args: ["--fix"]
      - id: ruff-format

  - repo: local
    hooks:
      - id: prettier
        name: prettier
        entry: jlpm
        args: [run, 'prettier:files']
        language: node
        types_or: [json, ts, tsx, javascript, jsx, css]
        exclude: \.ipynb$
      - id: eslint
        name: eslint
        entry: 'npm run eslint:files'
        language: node
        types_or: [ts, tsx, javascript, jsx]
      - id: stylelint
        name: stylelint
        entry: 'npm run stylelint:files'
        language: node
        types: [css]
      - id: shellcheck
        name: shellcheck
        entry: bash ./scripts/shellcheck_lint.sh
        language: python
        additional_dependencies: [shellcheck-py==0.11.0.1]
        pass_filenames: false
        files: \.sh$
      - id: integrity
        name: integrity
        entry: 'npm run integrity --force'
        language: node
        stages: [pre-push]

~/.cache/pre-commit/pre-commit.log (if present)

No response

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions