From 8d69d34951947ba8943158cf0aa8431a51bf0a62 Mon Sep 17 00:00:00 2001 From: CDeltakai Date: Thu, 8 May 2025 17:33:18 +1000 Subject: [PATCH 1/2] fix: improve prettier execution handling in lint script by making it invoke local prettier instead of repo prettier --- src/bin/lint.ts | 52 ++++++++++++++++++++++++++++++++++--------------- 1 file changed, 36 insertions(+), 16 deletions(-) diff --git a/src/bin/lint.ts b/src/bin/lint.ts index 4c38fa0..5dfdcce 100644 --- a/src/bin/lint.ts +++ b/src/bin/lint.ts @@ -5,6 +5,7 @@ import path from 'node:path'; import process from 'node:process'; import childProcess from 'node:child_process'; import fs from 'node:fs'; +import { createRequire } from 'node:module'; import { Command } from 'commander'; import * as utils from '../utils.js'; @@ -126,38 +127,57 @@ async function main(argv = process.argv) { // Always include README if it exists const markdownFiles: string[] = []; if (fs.existsSync('README.md')) markdownFiles.push('README.md'); - - // Add files from pages/, blog/, docs/ **if they exist AND contain md/mdx** for (const dir of ['pages', 'blog', 'docs']) { - if (fs.existsSync(dir)) { - markdownFiles.push(...utils.collectMarkdown(dir)); - } + if (fs.existsSync(dir)) markdownFiles.push(...utils.collectMarkdown(dir)); } - if (markdownFiles.length === 0) { console.warn('Skipping Prettier: no Markdown/MDX files found.'); return; } const prettierArgs = [fix ? '--write' : '--check', ...markdownFiles]; - console.error('Running prettier:'); - console.error(' ' + ['prettier', ...prettierArgs].join(' ')); + const require = createRequire(import.meta.url); + let prettierBin: string | null = null; try { - childProcess.execFileSync('prettier', prettierArgs, { - stdio: 'inherit', - windowsHide: true, - encoding: 'utf-8', - shell: platform === 'win32', - cwd: process.cwd(), - }); + // Resolves to @matrixai/lint/node_modules/prettier/bin/prettier.cjs + prettierBin = require.resolve('prettier/bin/prettier.cjs'); + } catch { + // Bundled copy not found + } + + try { + if (prettierBin) { + console.error( + ` ${process.execPath} ${prettierBin} ${prettierArgs.join(' ')}`, + ); + childProcess.execFileSync( + process.execPath, + [prettierBin, ...prettierArgs], + { + stdio: 'inherit', + windowsHide: true, + encoding: 'utf-8', + cwd: process.cwd(), + }, + ); + } else { + console.error(' prettier ' + prettierArgs.join(' ')); + childProcess.execFileSync('prettier', prettierArgs, { + stdio: 'inherit', + windowsHide: true, + encoding: 'utf-8', + shell: platform === 'win32', + cwd: process.cwd(), + }); + } } catch (err) { if (!fix) { console.error('Prettier check failed.'); hadFailure = true; } else { - throw err; // Unexpected if --write fails + throw err; // Should not happen when --write } } From 19d81a84e26475f52057b2639e36411057406745 Mon Sep 17 00:00:00 2001 From: CDeltakai Date: Fri, 9 May 2025 14:29:06 +1000 Subject: [PATCH 2/2] fix: removed peer dependency for eslint since its already a dependency --- package.json | 3 --- 1 file changed, 3 deletions(-) diff --git a/package.json b/package.json index f1176b2..75d6d46 100644 --- a/package.json +++ b/package.json @@ -63,8 +63,5 @@ "tsx": "^3.12.7", "typedoc": "^0.24.8", "typescript": "^5.1.6" - }, - "peerDependencies": { - "eslint": ">=9.0.0" } }