From 14eeb4784b01943c2e5bd40329a752b079301ddb Mon Sep 17 00:00:00 2001 From: Patrick Sullivan Date: Sat, 11 Jan 2025 03:10:07 +0000 Subject: [PATCH] ci(linting-tools): Update package to use `tsup` build process --- .vscode/cspell.json | 2 +- packages/eslint/src/utils/banner-plugin.ts | 4 +- packages/git-tools/src/cli/index.ts | 220 ++++++++-------- packages/linting-tools/bin/lint.ts | 10 +- packages/linting-tools/package.json | 161 +++++++----- packages/linting-tools/project.json | 193 ++++++++------ packages/linting-tools/src/cli/index.ts | 280 ++++++++++----------- packages/linting-tools/src/index.ts | 1 + packages/linting-tools/tsconfig.json | 13 +- packages/linting-tools/tsup.config.ts | 33 +++ 10 files changed, 506 insertions(+), 411 deletions(-) create mode 100644 packages/linting-tools/src/index.ts create mode 100644 packages/linting-tools/tsup.config.ts diff --git a/.vscode/cspell.json b/.vscode/cspell.json index 58af0f66f..58fe031a6 100644 --- a/.vscode/cspell.json +++ b/.vscode/cspell.json @@ -1,3 +1,3 @@ { - "import": ["../dist/packages/linting-tools/cspell/config.json"] + "import": ["../dist/packages/cspell/cspell-recommended.json"] } diff --git a/packages/eslint/src/utils/banner-plugin.ts b/packages/eslint/src/utils/banner-plugin.ts index f232ca067..38b003be0 100644 --- a/packages/eslint/src/utils/banner-plugin.ts +++ b/packages/eslint/src/utils/banner-plugin.ts @@ -1,5 +1,5 @@ import { ESLintUtils } from "@typescript-eslint/utils"; -import { ESLint, Linter, Rule } from "eslint"; +import { ESLint, Linter } from "eslint"; import os from "node:os"; import { CODE_FILE } from "./constants"; import { getFileBanner } from "./get-file-banner"; @@ -434,7 +434,7 @@ const plugin: ESLint.Plugin = { }, configs: {} as Record>, rules: { - banner: bannerRule as Rule.RuleModule + banner: bannerRule as any }, processors: {} }; diff --git a/packages/git-tools/src/cli/index.ts b/packages/git-tools/src/cli/index.ts index d78a6abb7..925e1b41f 100644 --- a/packages/git-tools/src/cli/index.ts +++ b/packages/git-tools/src/cli/index.ts @@ -15,120 +15,112 @@ import type { ReadMeOptions } from "../types"; let _config: Partial = {}; export function createProgram(config: StormConfig) { - try { - _config = config; - writeInfo("⚡ Running Storm Git Tools", config); - - // const commander = await import("commander"); - - const root = findWorkspaceRootSafe(process.cwd()); - process.env.STORM_WORKSPACE_ROOT ??= root; - process.env.NX_WORKSPACE_ROOT_PATH ??= root; - root && process.chdir(root); - - const program = new Command("storm-git"); - program.version("1.0.0", "-v --version", "display CLI version"); - - const commitConfig = new Option( - "--config ", - "The Commitizen config file path" - ).default("@storm-software/git-tools/commit/config"); - - const commitDryRun = new Option( - "--dry-run", - "Should the commit be run in dry-run mode (no updates are made)" - ); - - program - .command("commit") - .description("Commit changes to git for the workspace.") - .addOption(commitConfig) - .addOption(commitDryRun) - .action(commitAction); - - const readmeTemplatePath = new Option( - "--templates ", - "The templates directory to use when generating the README.md files." - ).default("./tools/readme-templates"); - - const readmePackageName = new Option( - "--project ", - "The specific project to generate a README.md file for" - ); - - const readmeOutput = new Option( - "--output ", - "Where to output the generated README.md file" - ); - - const readmeClean = new Option( - "--clean", - "Should the output README.md file be cleaned before generation" - ).default(true); - - const readmePrettier = new Option( - "--prettier", - "Should the output README.md file have prettier applied to it" - ).default(true); - - program - .command("readme") - .description("Run the README.md generator using the templates provided.") - .addOption(readmeTemplatePath) - .addOption(readmePackageName) - .addOption(readmeOutput) - .addOption(readmeClean) - .addOption(readmePrettier) - .action(readmeAction); - - const releasePackageName = new Option( - "--project ", - "The specific project to run release for" - ); - - const releaseBase = new Option("--base ", "Git base tag value"); - const releaseHead = new Option("--head ", "Git head tag value"); - - const releaseDryRun = new Option( - "--dry-run", - "Should the release be run in dry-run mode (no updates are made)" - ); - - program - .command("release") - .description("Run release for a project in the workspace.") - .addOption(releasePackageName) - .addOption(releaseBase) - .addOption(releaseHead) - .addOption(releaseDryRun) - .action(releaseAction); - - const commitMessage = new Option( - "--message ", - "The commit message to lint" - ).makeOptionMandatory(false); - - const commitFile = new Option( - "--file ", - "The commit message to lint" - ).makeOptionMandatory(false); - - program - .command("commitlint") - .description("Run commitlint for the workspace's commit message.") - .addOption(commitConfig) - .addOption(commitMessage) - .addOption(commitFile) - .action(commitLintAction); - - return program; - } catch (error) { - writeFatal( - `A fatal error occurred while preparing the Storm Git-Tools program: \n\n${error.message}`, - config - ); - throw new Error(error.message, { cause: error }); - } + _config = config; + writeInfo("⚡ Running Storm Git Tools", config); + + // const commander = await import("commander"); + + const root = findWorkspaceRootSafe(process.cwd()); + process.env.STORM_WORKSPACE_ROOT ??= root; + process.env.NX_WORKSPACE_ROOT_PATH ??= root; + root && process.chdir(root); + + const program = new Command("storm-git"); + program.version("1.0.0", "-v --version", "display CLI version"); + + const commitConfig = new Option( + "--config ", + "The Commitizen config file path" + ).default("@storm-software/git-tools/commit/config"); + + const commitDryRun = new Option( + "--dry-run", + "Should the commit be run in dry-run mode (no updates are made)" + ); + + program + .command("commit") + .description("Commit changes to git for the workspace.") + .addOption(commitConfig) + .addOption(commitDryRun) + .action(commitAction); + + const readmeTemplatePath = new Option( + "--templates ", + "The templates directory to use when generating the README.md files." + ).default("./tools/readme-templates"); + + const readmePackageName = new Option( + "--project ", + "The specific project to generate a README.md file for" + ); + + const readmeOutput = new Option( + "--output ", + "Where to output the generated README.md file" + ); + + const readmeClean = new Option( + "--clean", + "Should the output README.md file be cleaned before generation" + ).default(true); + + const readmePrettier = new Option( + "--prettier", + "Should the output README.md file have prettier applied to it" + ).default(true); + + program + .command("readme") + .description("Run the README.md generator using the templates provided.") + .addOption(readmeTemplatePath) + .addOption(readmePackageName) + .addOption(readmeOutput) + .addOption(readmeClean) + .addOption(readmePrettier) + .action(readmeAction); + + const releasePackageName = new Option( + "--project ", + "The specific project to run release for" + ); + + const releaseBase = new Option("--base ", "Git base tag value"); + const releaseHead = new Option("--head ", "Git head tag value"); + + const releaseDryRun = new Option( + "--dry-run", + "Should the release be run in dry-run mode (no updates are made)" + ); + + program + .command("release") + .description("Run release for a project in the workspace.") + .addOption(releasePackageName) + .addOption(releaseBase) + .addOption(releaseHead) + .addOption(releaseDryRun) + .action(releaseAction); + + const commitMessage = new Option( + "--message ", + "The commit message to lint" + ).makeOptionMandatory(false); + + const commitFile = new Option( + "--file ", + "The commit message to lint" + ).makeOptionMandatory(false); + + program + .command("commitlint") + .description("Run commitlint for the workspace's commit message.") + .addOption(commitConfig) + .addOption(commitMessage) + .addOption(commitFile) + .action(commitLintAction); + + return program; } export async function commitAction({ diff --git a/packages/linting-tools/bin/lint.ts b/packages/linting-tools/bin/lint.ts index d7600b7b8..f017126fe 100644 --- a/packages/linting-tools/bin/lint.ts +++ b/packages/linting-tools/bin/lint.ts @@ -1,3 +1,5 @@ +#!/usr/bin/env node + import { exitWithError, exitWithSuccess, @@ -6,9 +8,6 @@ import { writeFatal, writeSuccess } from "@storm-software/config-tools"; -import { readJsonSync } from "fs-extra"; -import { join } from "node:path"; -import { register as registerTsConfigPaths } from "tsconfig-paths"; import { createProgram } from "../src/cli"; Error.stackTraceLimit = Infinity; @@ -18,11 +17,6 @@ void (async () => { try { handleProcess(config); - const compilerOptions = readJsonSync( - join(config.workspaceRoot ?? "./", "tsconfig.base.json") - ).compilerOptions; - registerTsConfigPaths(compilerOptions); - const program = await createProgram(config); program.exitOverride(); diff --git a/packages/linting-tools/package.json b/packages/linting-tools/package.json index 45ca1740d..51f63f416 100755 --- a/packages/linting-tools/package.json +++ b/packages/linting-tools/package.json @@ -15,76 +15,122 @@ "email": "contact@stormsoftware.com", "url": "https://stormsoftware.com" }, + "maintainers": [ + { + "name": "Storm Software", + "email": "contact@stormsoftware.com", + "url": "https://stormsoftware.com" + }, + { + "name": "Pat Sullivan", + "email": "admin@stormsoftware.com", + "url": "https://patsullivan.org" + } + ], + "contributors": [ + { + "name": "Storm Software", + "email": "contact@stormsoftware.com", + "url": "https://stormsoftware.com" + } + ], + "funding": { + "type": "github", + "url": "https://github.com/sponsors/storm-software" + }, "license": "Apache-2.0", "private": false, + "packageManager": "pnpm@9.15.2", + "engines": { + "node": ">=22.4.0", + "pnpm": ">=9.15.2" + }, "bin": { - "storm-lint": "./bin/lint.js" + "storm-lint": "./bin/lint.cjs", + "storm-lint-esm": "./bin/lint.js", + "storm-lint-cjs": "./bin/lint.cjs" }, + "main": "./dist/index.cjs", + "module": "./dist/index.js", + "exports": { + "./package.json": "./package.json", + ".": { + "import": { + "types": "./dist/index.d.ts", + "default": "./dist/index.js" + }, + "require": { + "types": "./dist/index.d.cts", + "default": "./dist/index.cjs" + }, + "default": { + "types": "./dist/index.d.ts", + "default": "./dist/index.js" + } + }, + "./index": { + "import": { + "types": "./dist/index.d.ts", + "default": "./dist/index.js" + }, + "require": { + "types": "./dist/index.d.cts", + "default": "./dist/index.cjs" + }, + "default": { + "types": "./dist/index.d.ts", + "default": "./dist/index.js" + } + }, + "./biome/*": "./biome/*", + "./ls-lint/*": "./ls-lint/*", + "./syncpack/*": "./syncpack/*", + "./cspell/*": "./cspell/*", + "./alex/*": "./alex/*", + "./taplo/*": "./taplo/*", + "./zizmor/*": "./zizmor/*" + }, + "types": "./dist/index.d.ts", + "files": [ + "alex/**/*", + "bin/**/*", + "biome/**/*", + "cspell/**/*", + "dist/**/*", + "ls-lint/**/*", + "syncpack/**/*", + "taplo/**/*", + "zizmor/**/*" + ], "keywords": [ + "storm-software", "monorepo", - "open-system", - "storm", "storm-ops", - "storm-stack", - "stormstack", - "sullivanpj" + "sullivanpj", + "manypkg", + "ls-lint", + "cspell", + "biome", + "alex", + "taplo", + "syncpack", + "zizmor" ], + "peerDependencies": { + "@storm-software/cspell": "workspace:*" + }, + "peerDependenciesMeta": { + "@storm-software/cspell": { + "optional": false + } + }, "dependencies": { "@angular-devkit/architect": "0.1900.6", - "@cspell/dict-ada": "4.0.2", - "@cspell/dict-aws": "4.0.2", - "@cspell/dict-bash": "4.1.3", - "@cspell/dict-companies": "3.1.2", - "@cspell/dict-cpp": "5.1.10", - "@cspell/dict-cryptocurrencies": "5.0.0", - "@cspell/dict-csharp": "4.0.2", - "@cspell/dict-css": "4.0.12", - "@cspell/dict-dart": "2.0.3", - "@cspell/dict-django": "4.1.0", - "@cspell/dict-docker": "1.1.7", - "@cspell/dict-dotnet": "5.0.2", - "@cspell/dict-elixir": "4.0.3", - "@cspell/dict-en-common-misspellings": "2.0.3", - "@cspell/dict-en-gb": "4.1.44", - "@cspell/dict-en_us": "4.3.23", - "@cspell/dict-filetypes": "3.0.4", - "@cspell/dict-fonts": "4.0.0", - "@cspell/dict-fsharp": "1.0.1", - "@cspell/dict-fullstack": "3.1.8", - "@cspell/dict-gaming-terms": "1.0.5", - "@cspell/dict-git": "3.0.0", - "@cspell/dict-golang": "6.0.9", - "@cspell/dict-haskell": "4.0.1", - "@cspell/dict-html": "4.0.5", - "@cspell/dict-html-symbol-entities": "4.0.0", - "@cspell/dict-java": "5.0.7", - "@cspell/dict-k8s": "1.0.5", - "@cspell/dict-latex": "4.0.0", - "@cspell/dict-lorem-ipsum": "4.0.0", - "@cspell/dict-lua": "4.0.3", - "@cspell/dict-makefile": "1.0.0", - "@cspell/dict-node": "5.0.1", - "@cspell/dict-npm": "5.0.16", - "@cspell/dict-php": "4.0.8", - "@cspell/dict-powershell": "5.0.4", - "@cspell/dict-public-licenses": "2.0.7", - "@cspell/dict-python": "4.1.11", - "@cspell/dict-r": "2.0.1", - "@cspell/dict-ruby": "5.0.2", - "@cspell/dict-rust": "4.0.4", - "@cspell/dict-scala": "5.0.2", - "@cspell/dict-software-terms": "3.4.8", - "@cspell/dict-sql": "2.1.3", - "@cspell/dict-svelte": "1.0.2", - "@cspell/dict-swift": "2.0.1", - "@cspell/dict-typescript": "3.1.5", - "@cspell/dict-vue": "3.0.0", "@manypkg/cli": "0.21.4", "@manypkg/get-packages": "2.2.1", "alex": "11.0.1", "check-dependency-version-consistency": "4.1.0", "commander": "catalog:", - "cspell": "8.8.4", "dpdm": "3.14.0", "fast-glob": "3.3.2", "fs-extra": "11.2.0", @@ -107,7 +153,10 @@ "vfile-reporter": "8.1.1" }, "devDependencies": { - "@types/node": "catalog:" + "@storm-software/cspell": "workspace:*", + "@types/node": "catalog:", + "cspell": "catalog:", + "tsup": "catalog:" }, "publishConfig": { "access": "public" diff --git a/packages/linting-tools/project.json b/packages/linting-tools/project.json index 1e46b3844..337c84a80 100644 --- a/packages/linting-tools/project.json +++ b/packages/linting-tools/project.json @@ -4,94 +4,123 @@ "sourceRoot": "packages/linting-tools/src", "projectType": "library", "targets": { + // "build": { + // "cache": true, + // "executor": "@nx/esbuild:esbuild", + // "outputs": ["{options.outputPath}"], + // "options": { + // "outputPath": "dist/packages/linting-tools", + // "tsConfig": "packages/linting-tools/tsconfig.json", + // "project": "packages/linting-tools/package.json", + // "main": "packages/linting-tools/src/cli/index.ts", + // "additionalEntryPoints": [ + // "packages/linting-tools/bin/lint.ts", + // "packages/linting-tools/src/manypkg/index.ts" + // ], + // "deleteOutputPath": true, + // "bundle": true, + // "sourcemap": false, + // "minify": false, + // "skipTypeCheck": true, + // "thirdParty": true, + // "format": ["esm"], + // "external": ["nx"], + // "esbuildOptions": { + // "legalComments": "inline", + // "banner": { + // "js": "const require = (await import('node:module')).createRequire(import.meta.url);const __filename = (await import('node:url')).fileURLToPath(import.meta.url);const __dirname = (await import('node:path')).dirname(__filename);" + // } + // }, + // "assets": [ + // { + // "input": "packages/linting-tools", + // "glob": "*.md", + // "output": "." + // }, + // { + // "input": "", + // "glob": "LICENSE", + // "output": "." + // }, + // { + // "input": "packages/linting-tools", + // "glob": "declarations.d.ts", + // "output": "." + // }, + // { + // "input": "packages/linting-tools", + // "glob": "bin/**/*", + // "output": "." + // }, + // { + // "input": "packages/linting-tools/src", + // "glob": "alex/**/.{alexrc,alexignore}", + // "output": "." + // }, + // { + // "input": "packages/linting-tools/src", + // "glob": "biome/*", + // "output": "." + // }, + // { + // "input": "packages/linting-tools/src", + // "glob": "taplo/*", + // "output": "." + // }, + // { + // "input": "packages/linting-tools/src", + // "glob": "ls-lint/*", + // "output": "." + // }, + // { + // "input": "packages/linting-tools/src", + // "glob": "cspell/*", + // "output": "." + // }, + // { + // "input": "packages/linting-tools/src", + // "glob": "syncpack/*", + // "output": "." + // }, + // { + // "input": "packages/linting-tools/src", + // "glob": "zizmor/*", + // "output": "." + // } + // ] + // } + // }, + + "build-base": { + "executor": "nx:run-commands", + "dependsOn": ["clean", "^build"], + "options": { + "command": "tsup-node --config=tsup.config.ts", + "cwd": "{projectRoot}" + } + }, "build": { - "cache": true, - "executor": "@nx/esbuild:esbuild", - "outputs": ["{options.outputPath}"], + "executor": "nx:run-commands", + "dependsOn": ["build-base"], "options": { - "outputPath": "dist/packages/linting-tools", - "tsConfig": "packages/linting-tools/tsconfig.json", - "project": "packages/linting-tools/package.json", - "main": "packages/linting-tools/src/cli/index.ts", - "additionalEntryPoints": [ - "packages/linting-tools/bin/lint.ts", - "packages/linting-tools/src/manypkg/index.ts" - ], - "deleteOutputPath": true, - "bundle": true, - "sourcemap": false, - "minify": false, - "skipTypeCheck": true, - "thirdParty": true, - "format": ["esm"], - "external": ["nx"], - "esbuildOptions": { - "legalComments": "inline", - "banner": { - "js": "const require = (await import('node:module')).createRequire(import.meta.url);const __filename = (await import('node:url')).fileURLToPath(import.meta.url);const __dirname = (await import('node:path')).dirname(__filename);" - } - }, - "assets": [ - { - "input": "packages/linting-tools", - "glob": "*.md", - "output": "." - }, - { - "input": "", - "glob": "LICENSE", - "output": "." - }, - { - "input": "packages/linting-tools", - "glob": "declarations.d.ts", - "output": "." - }, - { - "input": "packages/linting-tools", - "glob": "bin/**/*", - "output": "." - }, - { - "input": "packages/linting-tools/src", - "glob": "alex/**/.{alexrc,alexignore}", - "output": "." - }, - { - "input": "packages/linting-tools/src", - "glob": "biome/*", - "output": "." - }, - { - "input": "packages/linting-tools/src", - "glob": "taplo/*", - "output": "." - }, - { - "input": "packages/linting-tools/src", - "glob": "ls-lint/*", - "output": "." - }, - { - "input": "packages/linting-tools/src", - "glob": "cspell/*", - "output": "." - }, - { - "input": "packages/linting-tools/src", - "glob": "syncpack/*", - "output": "." - }, - { - "input": "packages/linting-tools/src", - "glob": "zizmor/*", - "output": "." - } + "commands": [ + "pnpm copyfiles LICENSE dist/packages/linting-tools", + "pnpm copyfiles --up=2 ./packages/linting-tools/*.md ./packages/linting-tools/package.json dist/packages/linting-tools", + "pnpm copyfiles --up=4 ./packages/linting-tools/dist/src/* dist/packages/linting-tools/dist", + "pnpm copyfiles --up=4 ./packages/linting-tools/src/biome/* dist/packages/linting-tools/biome", + "pnpm copyfiles --up=4 ./packages/linting-tools/src/cspell/* dist/packages/linting-tools/cspell", + "pnpm copyfiles --up=4 ./packages/linting-tools/src/syncpack/* dist/packages/linting-tools/syncpack", + "pnpm copyfiles --up=4 ./packages/linting-tools/src/alex/.alexignore ./packages/linting-tools/src/alex/.alexrc dist/packages/linting-tools/alex", + "pnpm copyfiles --up=4 ./packages/linting-tools/src/zizmor/* dist/packages/linting-tools/zizmor", + "pnpm copyfiles --up=4 ./packages/linting-tools/src/taplo/* dist/packages/linting-tools/taplo", + "pnpm copyfiles --up=4 ./packages/linting-tools/src/ls-lint/* dist/packages/linting-tools/ls-lint", + "pnpm copyfiles --up=4 ./packages/linting-tools/dist/bin/* dist/packages/linting-tools/bin" ] } }, "nx-release-publish": { "executor": "@storm-software/workspace-tools:npm-publish" } - } + }, + "implicitDependencies": ["cspell"] } diff --git a/packages/linting-tools/src/cli/index.ts b/packages/linting-tools/src/cli/index.ts index 6e84f296e..d61016216 100644 --- a/packages/linting-tools/src/cli/index.ts +++ b/packages/linting-tools/src/cli/index.ts @@ -7,6 +7,7 @@ import { writeInfo, writeSuccess } from "@storm-software/config-tools"; +import { CDVC } from "check-dependency-version-consistency"; import { Command, Option } from "commander"; import { lint } from "cspell"; import { parseCircular, parseDependencyTree, prettyCircular } from "dpdm"; @@ -17,151 +18,143 @@ import { MANY_PKG_TYPE_OPTIONS, runManypkg } from "../manypkg"; let _config: Partial = {}; export function createProgram(config: StormConfig) { - try { - _config = config; - writeInfo("⚡ Running Storm Linting Tools", config); - - const root = findWorkspaceRootSafe(); - process.env.STORM_WORKSPACE_ROOT ??= root; - process.env.NX_WORKSPACE_ROOT_PATH ??= root; - root && process.chdir(root); - - const program = new Command("storm-lint"); - program.version("1.0.0", "-v --version", "display CLI version"); - - program - .description("⚡ Lint the Storm Workspace") - .showHelpAfterError() - .showSuggestionAfterError(); - - const cspellConfig = new Option( - "--cspell-config ", - "CSpell config file path" - ).default("@storm-software/linting-tools/cspell/config.js"); - - program - .command("cspell") - .description("Run spell-check lint for the workspace.") - .addOption(cspellConfig) - .action(cspellAction); - - const alexConfig = new Option( - "--alex-config ", - "Alex.js config file path" - ).default("@storm-software/linting-tools/alex/.alexrc"); - - const alexIgnore = new Option( - "--alex-ignore ", - "Alex.js Ignore file path" - ).default("@storm-software/linting-tools/alex/.alexignore"); - - program - .command("alex") - .description("Run spell-check lint for the workspace.") - .addOption(alexConfig) - .addOption(alexIgnore) - .action(alexAction); - - program - .command("deps-version") - .description("Run dependency version consistency lint for the workspace.") - .action(depsVersionAction); - - program - .command("circular-deps") - .description("Run circular dependency lint for the workspace.") - .action(circularDepsAction); - - const manypkgType = new Option( - "--manypkg-type ", - "The manypkg command to run" + _config = config; + writeInfo("⚡ Running Storm Linting Tools", config); + + const root = findWorkspaceRootSafe(); + process.env.STORM_WORKSPACE_ROOT ??= root; + process.env.NX_WORKSPACE_ROOT_PATH ??= root; + root && process.chdir(root); + + const program = new Command("storm-lint"); + program.version("1.0.0", "-v --version", "display CLI version"); + + program + .description("⚡ Lint the Storm Workspace") + .showHelpAfterError() + .showSuggestionAfterError(); + + const cspellConfig = new Option( + "--cspell-config ", + "CSpell config file path" + ).default("@storm-software/linting-tools/cspell/config.js"); + + program + .command("cspell") + .description("Run spell-check lint for the workspace.") + .addOption(cspellConfig) + .action(cspellAction); + + const alexConfig = new Option( + "--alex-config ", + "Alex.js config file path" + ).default("@storm-software/linting-tools/alex/.alexrc"); + + const alexIgnore = new Option( + "--alex-ignore ", + "Alex.js Ignore file path" + ).default("@storm-software/linting-tools/alex/.alexignore"); + + program + .command("alex") + .description("Run spell-check lint for the workspace.") + .addOption(alexConfig) + .addOption(alexIgnore) + .action(alexAction); + + program + .command("deps-version") + .description("Run dependency version consistency lint for the workspace.") + .action(depsVersionAction); + + program + .command("circular-deps") + .description("Run circular dependency lint for the workspace.") + .action(circularDepsAction); + + const manypkgType = new Option( + "--manypkg-type ", + "The manypkg command to run" + ) + .choices(MANY_PKG_TYPE_OPTIONS) + .argParser(val => + !val || !MANY_PKG_TYPE_OPTIONS.includes(val.trim().toLowerCase()) + ? "fix" + : val.trim().toLowerCase() ) - .choices(MANY_PKG_TYPE_OPTIONS) - .argParser(val => - !val || !MANY_PKG_TYPE_OPTIONS.includes(val.trim().toLowerCase()) - ? "fix" - : val.trim().toLowerCase() - ) - .default("fix"); - - const manypkgArgs = new Option( - "--manypkg-args ", - "The args provided to the manypkg command" + .default("fix"); + + const manypkgArgs = new Option( + "--manypkg-args ", + "The args provided to the manypkg command" + ) + .argParser(val => + !val || !val.replaceAll("", ",") + ? [] + : val.split(",").map(v => v.trim().toLowerCase()) ) - .argParser(val => - !val || !val.replaceAll("", ",") - ? [] - : val.split(",").map(v => v.trim().toLowerCase()) - ) - .default([]); - - program - .command("manypkg") - .description("Run package lint with Manypkg for the workspace.") - .addOption(manypkgType) - .addOption(manypkgArgs) - .action(manypkgAction); - - program - .command("codeowners") - .description("Run CODEOWNERS linting for the workspace.") - .addOption(cspellConfig) - .action(codeownersAction); - - const skipCspell = new Option( - "--skip-cspell", - "Should skip CSpell linting" - ).default(true); - - const skipAlex = new Option( - "--skip-alex", - "Should skip Alex language linting" - ).default(true); - - const skipDepsVersion = new Option( - "--skip-deps-version", - "Should skip dependency version consistency linting" - ).default(false); - - const skipCircularDeps = new Option( - "--skip-circular-deps", - "Should skip circular dependency linting" - ).default(false); - - const skipManypkg = new Option( - "--skip-manypkg", - "Should skip Manypkg linting" - ).default(false); - - const skipCodeowners = new Option( - "--skip-codeowners", - "Should skip CODEOWNERS linting" - ).default(true); - - program - .command("all") - .description("Run all linters for the workspace.") - .addOption(skipCspell) - .addOption(skipAlex) - .addOption(skipDepsVersion) - .addOption(skipCircularDeps) - .addOption(skipManypkg) - .addOption(cspellConfig) - .addOption(alexConfig) - .addOption(alexIgnore) - .addOption(manypkgType) - .addOption(manypkgArgs) - .addOption(skipCodeowners) - .action(allAction); - - return program; - } catch (e) { - writeError( - `A fatal error occurred while preparing the program: ${e.message}`, - config - ); - throw new Error(e.message, { cause: e }); - } + .default([]); + + program + .command("manypkg") + .description("Run package lint with Manypkg for the workspace.") + .addOption(manypkgType) + .addOption(manypkgArgs) + .action(manypkgAction); + + program + .command("codeowners") + .description("Run CODEOWNERS linting for the workspace.") + .addOption(cspellConfig) + .action(codeownersAction); + + const skipCspell = new Option( + "--skip-cspell", + "Should skip CSpell linting" + ).default(true); + + const skipAlex = new Option( + "--skip-alex", + "Should skip Alex language linting" + ).default(true); + + const skipDepsVersion = new Option( + "--skip-deps-version", + "Should skip dependency version consistency linting" + ).default(false); + + const skipCircularDeps = new Option( + "--skip-circular-deps", + "Should skip circular dependency linting" + ).default(false); + + const skipManypkg = new Option( + "--skip-manypkg", + "Should skip Manypkg linting" + ).default(false); + + const skipCodeowners = new Option( + "--skip-codeowners", + "Should skip CODEOWNERS linting" + ).default(true); + + program + .command("all") + .description("Run all linters for the workspace.") + .addOption(skipCspell) + .addOption(skipAlex) + .addOption(skipDepsVersion) + .addOption(skipCircularDeps) + .addOption(skipManypkg) + .addOption(cspellConfig) + .addOption(alexConfig) + .addOption(alexIgnore) + .addOption(manypkgType) + .addOption(manypkgArgs) + .addOption(skipCodeowners) + .action(allAction); + + return program; } async function allAction({ @@ -307,7 +300,6 @@ async function depsVersionAction() { _config ); - const { CDVC } = await import("check-dependency-version-consistency"); const cdvc = new CDVC(".", { fix: true }); // Show output for dependencies we fixed. diff --git a/packages/linting-tools/src/index.ts b/packages/linting-tools/src/index.ts new file mode 100644 index 000000000..c1d55cf46 --- /dev/null +++ b/packages/linting-tools/src/index.ts @@ -0,0 +1 @@ +export * from "./cli"; diff --git a/packages/linting-tools/tsconfig.json b/packages/linting-tools/tsconfig.json index 2bf545b7a..bbfd12aa3 100644 --- a/packages/linting-tools/tsconfig.json +++ b/packages/linting-tools/tsconfig.json @@ -2,11 +2,16 @@ "extends": "../../tsconfig.json", "compilerOptions": { "outDir": "../../dist/out-tsc", - "strict": false, - "esModuleInterop": true, - "allowSyntheticDefaultImports": true, + "rootDir": "../..", + "target": "ESNext", + "module": "ESNext", + "lib": ["ESNext"], + "skipLibCheck": true, + "skipDefaultLibCheck": true, + "moduleResolution": "Bundler", + "moduleDetection": "force", "types": ["node"] }, - "include": ["src/**/*.ts", "src/**/*.js", "bin/**/*", "declarations.d.ts"], + "include": ["src/**/*.ts", "bin/**/*.ts", "tsup.config.ts"], "exclude": ["jest.config.ts", "src/**/*.spec.ts", "src/**/*.test.ts"] } diff --git a/packages/linting-tools/tsup.config.ts b/packages/linting-tools/tsup.config.ts new file mode 100644 index 000000000..245156d06 --- /dev/null +++ b/packages/linting-tools/tsup.config.ts @@ -0,0 +1,33 @@ +import { defineConfig } from "tsup"; + +export default defineConfig([ + { + name: "linting-tools-base", + target: "node22", + entryPoints: ["src/index.ts"], + format: ["cjs", "esm"], + outDir: "dist/src", + platform: "node", + splitting: true, + clean: false, + dts: true, + sourcemap: false, + tsconfig: "./tsconfig.json", + shims: true + }, + { + name: "linting-tools-bin", + target: "node22", + entryPoints: ["bin/*.ts"], + format: ["cjs", "esm"], + outDir: "dist/bin", + platform: "node", + splitting: false, + bundle: true, + clean: false, + dts: false, + sourcemap: false, + tsconfig: "./tsconfig.json", + shims: true + } +]);