stylelint-compat.cjs 794 B

1234567891011121314151617181920212223242526272829303132
  1. const fs = require('fs');
  2. const path = require('path');
  3. const { spawnSync } = require('child_process');
  4. const pnpmDir = path.resolve(__dirname, '../../../node_modules/.pnpm');
  5. function findDir(prefix) {
  6. return fs.readdirSync(pnpmDir).find((name) => name.startsWith(prefix));
  7. }
  8. const stylelintDir = findDir('stylelint@14.8.2');
  9. if (!stylelintDir) {
  10. console.error('Compatible stylelint@14.8.2 not found in workspace node_modules/.pnpm');
  11. process.exit(1);
  12. }
  13. const stylelintBin = path.join(
  14. pnpmDir,
  15. stylelintDir,
  16. 'node_modules/stylelint/bin/stylelint.js'
  17. );
  18. const result = spawnSync(process.execPath, [stylelintBin, ...process.argv.slice(2)], {
  19. stdio: 'inherit',
  20. cwd: process.cwd(),
  21. });
  22. if (result.error) {
  23. console.error(result.error);
  24. }
  25. process.exit(result.status ?? 1);