tadatuta / bem-tools-create-by-css

https://www.youtube.com/watch?v=I4dxWRlknJM
44 stars 6 forks source link

Пакет не работает с новыми версиями ноды #4

Closed kndenisenko closed 1 year ago

kndenisenko commented 2 years ago

Cпасибо за создание пакета bem-tools-create-by-css. Он очень помогает при разбивке одного длинного css-файла на блоки по БЭМ. Но к сожалению, с пакетом нашлись проблемы, о них дальше. :)

Если коротко, то пакет css-to-bem-file-structure посоветовали во время обучения в яндекс.практикуме. Столкнулся с несколькими проблемами, которые мне показались багами. Пакет условно работает только при глобальной установке с флагом -g и только при установленной версии ноды 10.19.0 (npm 6.13.4). При смене версии ноды на 16.13.1 (npm 8.1.2) пакет уже не работает. С остальными версиями ноды не тестил. Ноды устанавливались и переключались с помощью Node Version Manager.

Тесты проходили в Ubuntu 20.04, установленной с помощью WSL 2 в Win 11

Пакет работает только при глобальной установке

При установленной ноде 10.19.0 и установке с помощью npm i css-to-bem-file-structure --save-dev и попытке запустить пакет через css-to-bem-file-structure path-to-styles.css получил следующую ошибку:

konstantin@BDS-Laptop:~/test$ css-to-bem-file-structure ./styles/style.css 
css-to-bem-file-structure: command not found

После установил пакет при помощи команды npm i -g css-to-bem-file-structure

konstantin@BDS-Laptop:~/test$ npm i -g css-to-bem-file-structure
/home/konstantin/.nvm/versions/node/v10.19.0/bin/css-to-bem-file-structure -> /home/konstantin/.nvm/versions/node/v10.19.0/lib/node_modules/css-to-bem-file-structure/bin/create-by-css
+ css-to-bem-file-structure@0.0.1
added 51 packages from 60 contributors in 1.261s

Попробовал снова выполнить css-to-bem-file-structure path-to-styles.css получил предупреждение и папку blocks, с блоками. При этом всевдоклассы не были перемещены в файлы папки blocks:

konstantin@BDS-Laptop:~/test$ css-to-bem-file-structure ./styles/style.css 
(node:3937) UnhandledPromiseRejectionWarning: AssertionError [ERR_ASSERTION]: Required `entity` field
    at new BemCell (/home/konstantin/.nvm/versions/node/v10.19.0/lib/node_modules/css-to-bem-file-structure/node_modules/@bem/cell/index.js:18:9)
    at /home/konstantin/.nvm/versions/node/v10.19.0/lib/node_modules/css-to-bem-file-structure/node_modules/bem-tools-create/lib/create.js:102:41
    at Array.map (<anonymous>)
    at /home/konstantin/.nvm/versions/node/v10.19.0/lib/node_modules/css-to-bem-file-structure/node_modules/bem-tools-create/lib/create.js:100:61
(node:3937) UnhandledPromiseRejectionWarning: Unhandled promise rejection. This error originated either by throwing inside of an async function without a catch block, or by rejecting a promise which was not handled with .catch(). (rejection id: 1)
(node:3937) [DEP0018] DeprecationWarning: Unhandled promise rejections are deprecated. In the future, promise rejections that are not handled will terminate the Node.js process with a non-zero exit code.

Пакет не работает при смене версии ноды на 16.13.1

Ставлю ноду 16.13.1 через Node Version Manager, повторяю установку npm i -g css-to-bem-file-structure, запускаю css-to-bem-file-structure ./styles/style.css и получаю ошибку

konstantin@BDS-Laptop:~/test$ nvm install 16.13.1
Downloading and installing node v16.13.1...
Downloading https://nodejs.org/dist/v16.13.1/node-v16.13.1-linux-x64.tar.xz...
################################################################################################################################################################################################################################### 100.0%
Computing checksum with sha256sum
Checksums matched!
Now using node v16.13.1 (npm v8.1.2)

konstantin@BDS-Laptop:~/test$ npm i -g css-to-bem-file-structure

added 51 packages, and audited 52 packages in 8s

2 packages are looking for funding
  run `npm fund` for details

found 0 vulnerabilities
npm notice
npm notice New minor version of npm available! 8.1.2 -> 8.2.0
npm notice Changelog: https://github.com/npm/cli/releases/tag/v8.2.0
npm notice Run npm install -g npm@8.2.0 to update!
npm notice

konstantin@BDS-Laptop:~/test$ css-to-bem-file-structure ./styles/style.css 
node:internal/process/promises:246
          triggerUncaughtException(err, true /* fromPromise */);
          ^

AssertionError [ERR_ASSERTION]: Required `entity` field
    at new BemCell (/home/konstantin/.nvm/versions/node/v16.13.1/lib/node_modules/css-to-bem-file-structure/node_modules/@bem/cell/index.js:18:9)
    at /home/konstantin/.nvm/versions/node/v16.13.1/lib/node_modules/css-to-bem-file-structure/node_modules/bem-tools-create/lib/create.js:102:41
    at Array.map (<anonymous>)
    at /home/konstantin/.nvm/versions/node/v16.13.1/lib/node_modules/css-to-bem-file-structure/node_modules/bem-tools-create/lib/create.js:100:61
    at async Promise.all (index 0)
    at async Promise.all (index 0)
    at async Promise.all (index 0) {
  generatedMessage: false,
  code: 'ERR_ASSERTION',
  actual: undefined,
  expected: true,
  operator: '=='
}

Меняю ноду на 10.19.0 и снова всё работает, хоть и с предупреждением

konstantin@BDS-Laptop:~/test$ nvm use 10.19.0
Now using node v10.19.0 (npm v6.13.4)

konstantin@BDS-Laptop:~/test$ css-to-bem-file-structure ./styles/style.css 
(node:6031) UnhandledPromiseRejectionWarning: AssertionError [ERR_ASSERTION]: Required `entity` field
    at new BemCell (/home/konstantin/.nvm/versions/node/v10.19.0/lib/node_modules/css-to-bem-file-structure/node_modules/@bem/cell/index.js:18:9)
    at /home/konstantin/.nvm/versions/node/v10.19.0/lib/node_modules/css-to-bem-file-structure/node_modules/bem-tools-create/lib/create.js:102:41
    at Array.map (<anonymous>)
    at /home/konstantin/.nvm/versions/node/v10.19.0/lib/node_modules/css-to-bem-file-structure/node_modules/bem-tools-create/lib/create.js:100:61
(node:6031) UnhandledPromiseRejectionWarning: Unhandled promise rejection. This error originated either by throwing inside of an async function without a catch block, or by rejecting a promise which was not handled with .catch(). (rejection id: 1)
(node:6031) [DEP0018] DeprecationWarning: Unhandled promise rejections are deprecated. In the future, promise rejections that are not handled will terminate the Node.js process with a non-zero exit code.
tadatuta commented 1 year ago

Спасибо за отзыв!

Сейчас потестировал через nvm под разными версиями ноды — проблем не обнаружил. Добавил запуск тестов в CI на свежих версиях ноды (14/16/18) — тесты тоже проходят: ???

Что касается необходимости ставить глобально, то это не обязательно. При локальной установке запускать можно по полному пути из папке пакета в node_modules либо воспользоваться симлинкой, которая создается в node_modules/.bin. То есть полный вызов из папки проекта, где пакет установлен локально, будет выглядеть так: ./node_modules/.bin/css-to-bem-file-structure путь-к-файлу.css.

Чтобы не указывать длинный путь каждый раз, я добавляю его в переменную окружения PATH: https://github.com/tadatuta/dotfiles/blob/master/.bashrc#L116.

Проблему с псевдоклассами посмотрю в рамках https://github.com/tadatuta/bem-tools-create-by-css/issues/1