From 85d9465ad9110d0a07623aaf08adb256d4009325 Mon Sep 17 00:00:00 2001 From: yehorkardash Date: Mon, 8 Dec 2025 06:53:13 +0100 Subject: [PATCH] chore: Fix lefthook config for windows (#22676) Co-authored-by: RomanDavydchuk --- lefthook.yml | 13 +------------ scripts/check-workspace-deps.mjs | 33 ++++++++++++++++++++++++++++++++ 2 files changed, 34 insertions(+), 12 deletions(-) create mode 100644 scripts/check-workspace-deps.mjs diff --git a/lefthook.yml b/lefthook.yml index a01d0d1df78..90393a16f44 100644 --- a/lefthook.yml +++ b/lefthook.yml @@ -28,18 +28,7 @@ pre-commit: - rebase workspace_deps_check: glob: '**/package.json' - run: | - if grep -l '"workspace:\^"' {staged_files} 2>/dev/null; then - echo "" - echo "ERROR: Found 'workspace:^' in package.json files." - echo "" - echo "Use 'workspace:*' instead to pin exact versions." - echo "Using 'workspace:^' causes npm to resolve semver ranges when users" - echo "install from npm, which can lead to version mismatches between" - echo "@n8n/* packages and break n8n startup." - echo "" - exit 1 - fi + run: node scripts/check-workspace-deps.mjs {staged_files} skip: - merge - rebase diff --git a/scripts/check-workspace-deps.mjs b/scripts/check-workspace-deps.mjs new file mode 100644 index 00000000000..69a534a6aaf --- /dev/null +++ b/scripts/check-workspace-deps.mjs @@ -0,0 +1,33 @@ +#!/usr/bin/env node + +import { readFileSync } from 'node:fs'; +import { existsSync } from 'node:fs'; + +const isPackageJson = (file) => file.endsWith('package.json'); +const files = process.argv.slice(2).filter((file) => file && isPackageJson(file) && existsSync(file)); +let foundError = false; + +for (const file of files) { + try { + const content = readFileSync(file, 'utf8'); + if (content.includes('"workspace:^"')) { + if (!foundError) { + console.log(''); + console.log("ERROR: Found 'workspace:^' in package.json files."); + console.log(''); + console.log("Use 'workspace:*' instead to pin exact versions."); + console.log("Using 'workspace:^' causes npm to resolve semver ranges when users"); + console.log("install from npm, which can lead to version mismatches between"); + console.log("@n8n/* packages and break n8n startup."); + console.log(''); + } + foundError = true; + } + } catch (error) { + // Ignore read errors for individual files + } +} + +if (foundError) { + process.exit(1); +}