From 350e43bbfbde63122097c354c20c3882111121f1 Mon Sep 17 00:00:00 2001 From: Jason Ross Date: Tue, 31 Mar 2026 20:34:43 -0500 Subject: [PATCH] wip --- lint-staged.config.js | 51 +++++++++++++++++++++++++++++++++++++++++++ package.json | 1 + 2 files changed, 52 insertions(+) create mode 100644 lint-staged.config.js diff --git a/lint-staged.config.js b/lint-staged.config.js new file mode 100644 index 0000000..b966af9 --- /dev/null +++ b/lint-staged.config.js @@ -0,0 +1,51 @@ +import path from "node:path"; + +const repoRoot = process.cwd(); + +const quote = (value) => JSON.stringify(value); + +const inWorkspace = (workspace, file) => { + const relativePath = path.relative(repoRoot, file); + return ( + relativePath === workspace || + relativePath.startsWith(`${workspace}${path.sep}`) + ); +}; + +const commandForWorkspace = (workspaceName, workspaceDir, files) => { + const workspaceFiles = files.filter( + (file) => inWorkspace(workspaceDir, file) && /\.(ts|tsx)$/.test(file) + ); + + if (workspaceFiles.length === 0) { + return null; + } + + return `pnpm --filter ${workspaceName} exec eslint --fix ${workspaceFiles + .map(quote) + .join(" ")}`; +}; + +export default { + "**/*": (files) => { + const commands = []; + + if (files.length > 0) { + commands.push( + `prettier --write --ignore-unknown ${files.map(quote).join(" ")}` + ); + } + + const apiCommand = commandForWorkspace("stoat-admin-api", "api", files); + if (apiCommand) { + commands.push(apiCommand); + } + + const webCommand = commandForWorkspace("stoat-admin-web", "web", files); + if (webCommand) { + commands.push(webCommand); + } + + return commands; + } +}; diff --git a/package.json b/package.json index 0342df9..a022070 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,7 @@ { "name": "stoat-admin", "private": true, + "type": "module", "packageManager": "pnpm@10.6.3", "license": "AGPL-3.0-only", "devDependencies": {