From 8fba639b869b3498c7eeda35a2ccd7254eb474e2 Mon Sep 17 00:00:00 2001 From: Vasiliy Date: Fri, 12 Jun 2026 18:21:58 +0300 Subject: [PATCH] chore: fix package.json formatting and lockfile update workflow Align Prettier, lint-staged, and EditorConfig so package.json uses 2-space indent while package-lock.json stays npm-owned. Add update:package-locks scripts mirroring CI and document the workflow in CONTRIBUTING. Co-authored-by: Cursor --- .editorconfig | 3 +++ .lintstagedrc | 17 ----------------- .prettierignore | 4 ++-- .prettierrc | 11 ++++++++++- CONTRIBUTING.md | 24 ++++++++++++++++++++++++ lint-staged.config.js | 10 ++++++++++ package.json | 4 ++++ 7 files changed, 53 insertions(+), 20 deletions(-) delete mode 100644 .lintstagedrc create mode 100644 lint-staged.config.js diff --git a/.editorconfig b/.editorconfig index f2b0e2b5a6e..eb7423c1124 100644 --- a/.editorconfig +++ b/.editorconfig @@ -10,3 +10,6 @@ charset = utf-8 insert_final_newline = true trim_trailing_whitespace = true indent_size = 4 + +[{package.json,package-lock.json,**/package.json,**/package-lock.json}] +indent_size = 2 diff --git a/.lintstagedrc b/.lintstagedrc deleted file mode 100644 index 7966e291f6f..00000000000 --- a/.lintstagedrc +++ /dev/null @@ -1,17 +0,0 @@ -{ - "*.{js,jsx,ts,tsx}": [ - "eslint --fix", - "prettier --write", - ], - "*.{jsx,tsx}": [ - "stylelint", - ], - "*.md": [ - "prettier --write --parser markdown", - "git add" - ], - "*.json": [ - "prettier --write --parser json", - "git add" - ] -} diff --git a/.prettierignore b/.prettierignore index f8a0df54d63..f74dc95913d 100644 --- a/.prettierignore +++ b/.prettierignore @@ -1,9 +1,9 @@ /node_modules/ /build -# Exclude package(-lock).json for all packages -package.json +# Exclude package-lock.json — npm/lerna-owned, never Prettier-formatted package-lock.json +**/package-lock.json # Exclude *.api.md packages/plasma-b2c/api/ diff --git a/.prettierrc b/.prettierrc index e4e13544766..a7ad9cdbd96 100644 --- a/.prettierrc +++ b/.prettierrc @@ -8,5 +8,14 @@ "semi": true, "singleQuote": true, "tabWidth": 4, - "trailingComma": "all" + "trailingComma": "all", + "overrides": [ + { + "files": ["package.json", "**/package.json"], + "options": { + "parser": "json", + "tabWidth": 2 + } + } + ] } diff --git a/CONTRIBUTING.md b/CONTRIBUTING.md index 4ecdcc7c04b..77dee397d92 100644 --- a/CONTRIBUTING.md +++ b/CONTRIBUTING.md @@ -46,6 +46,30 @@ npx lerna clean -y npx lerna bootstrap ``` +## Обновление package-lock.json + +При изменении `dependencies`, `devDependencies` или `peerDependencies` в корневом или пакетном `package.json` необходимо синхронизировать lock-файлы. + +**Рекомендуемый способ (полная регенерация, как в CI):** + +```sh +npm run update:package-locks +``` + +**Точечное обновление после правки зависимостей одного пакета:** + +```sh +npm run update:package-locks:scope --scope=@salutejs/plasma-hope +``` + +**Не делайте так:** + +- `cd packages/foo && npm install` — изолированная установка перегенерирует lock и может изменить дерево зависимостей; +- `npm install --package-lock-only` без флагов `--lockfile-version 2 --legacy-peer-deps`; +- форматирование `package-lock.json` через Prettier — lock-файлы генерируются npm/lerna. + +Проверка: `git diff` по lock-файлам должен отражать только изменения зависимостей, а не массовую смену отступов. + ## Запуск Storybook Для разработки компонент используется `Storybook`, который запускается и собирается с помощью `Vite`. Для локальной разработки необходимо из корня проекта перейти в нужную директорию (`plasma-web`, `plasma-b2c`, `plasma-ui`) и выполнить команду запуска: diff --git a/lint-staged.config.js b/lint-staged.config.js new file mode 100644 index 00000000000..c291e888c0f --- /dev/null +++ b/lint-staged.config.js @@ -0,0 +1,10 @@ +module.exports = { + '*.{js,jsx,ts,tsx}': ['eslint --fix', 'prettier --write'], + '*.{jsx,tsx}': ['stylelint'], + '*.md': ['prettier --write --parser markdown'], + '*.json': (files) => { + const format = files.filter((f) => !f.endsWith('package-lock.json')); + + return format.length ? [`prettier --write --parser json ${format.map((f) => `"${f}"`).join(' ')}`] : []; + }, +}; diff --git a/package.json b/package.json index ab573876fdd..ea667d24b1a 100644 --- a/package.json +++ b/package.json @@ -30,6 +30,10 @@ "prepare": "test ! -n \"$CI\" && husky install || echo skip husky", "bootstrap": "npx lerna bootstrap", "bootstrap:since": "npm run bootstrap -- --since=$(git merge-base --fork-point origin/dev)", + "update:package-locks": "npm run update:package-locks:root && npm run update:package-locks:lerna && npm run update:package-locks:root", + "update:package-locks:root": "npm i --no-audit --no-progress --package-lock-only --lockfile-version 2 --legacy-peer-deps", + "update:package-locks:lerna": "npx lerna clean -y && npx lerna bootstrap --ignore-scripts --no-ci", + "update:package-locks:scope": "npx lerna bootstrap --scope=$npm_config_scope --include-dependencies --ignore-scripts --no-ci", "postinstall": "patch-package", "lerna:clean": "npx lerna clean -y", "bootstrap:plasma-giga:full": "npx lerna bootstrap --scope='@salutejs/plasma-giga' --scope='@salutejs/{plasma-sb-utils,plasma-tokens,plasma-tokens-utils,core-themes,plasma-typo,plasma-new-hope,plasma-colors,plasma-themes,plasma-core,plasma-docs-ui,plasma-giga-docs}'",