Skip to content

Commit

Permalink
chore: prettier and vitest config simplification (#1117)
Browse files Browse the repository at this point in the history
  • Loading branch information
juliusmarminge authored Jan 3, 2025
1 parent 5d132bb commit eace6bf
Show file tree
Hide file tree
Showing 12 changed files with 123 additions and 123 deletions.
7 changes: 3 additions & 4 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -41,21 +41,20 @@
"@changesets/changelog-github": "^0.5.0",
"@changesets/cli": "^2.27.1",
"@effect/vitest": "0.16.0",
"@ianvs/prettier-plugin-sort-imports": "^4.4.0",
"@manypkg/cli": "^0.21.3",
"@prettier/sync": "^0.5.2",
"@types/bun": "^1.1.5",
"@types/node": "^20.14.0",
"@uploadthing/eslint-config": "workspace:*",
"@uploadthing/prettier-config": "workspace:*",
"@vitest/browser": "^2.1.8",
"@vitest/coverage-v8": "^2.1.8",
"msw": "2.7.0",
"playwright": "1.49.1",
"prettier": "^3.4.2",
"prettier-plugin-tailwindcss": "^0.6.9",
"turbo": "2.3.3",
"typescript": "^5.5.2",
"uploadthing": "workspace:*",
"vitest": "^2.1.8"
}
},
"prettier": "@uploadthing/prettier-config"
}
66 changes: 37 additions & 29 deletions pnpm-lock.yaml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import noHardcodedVersion from "./rules/no-hardcoded-version-in-test";
import noThrowingPromises from "./rules/no-throwing-promises";
// @ts-check
import noHardcodedVersion from "./rules/no-hardcoded-version-in-test.js";
import noThrowingPromises from "./rules/no-throwing-promises.js";

const recommended = {
plugins: ["@uploadthing"],
Expand Down
15 changes: 3 additions & 12 deletions tooling/eslint-plugin/package.json
Original file line number Diff line number Diff line change
@@ -1,24 +1,15 @@
{
"name": "@uploadthing/eslint-plugin",
"version": "0.1.0",
"type": "module",
"exports": {
".": {
"require": "./dist/index.js"
}
".": "./index.js"
},
"scripts": {
"build": "tsup",
"dev": "tsup --watch",
"clean": "git clean -xdf dist node_modules"
"clean": "git clean -xdf node_modules"
},
"dependencies": {
"@typescript-eslint/parser": "^7.13.1",
"@typescript-eslint/utils": "^7.13.1"
},
"devDependencies": {
"@types/eslint": "^8.56.4",
"@uploadthing/tsconfig": "workspace:*",
"tsup": "8.0.2",
"typescript": "^5.5.2"
}
}
Original file line number Diff line number Diff line change
@@ -1,16 +1,21 @@
import {
AST_NODE_TYPES,
ESLintUtils,
TSESTree,
} from "@typescript-eslint/utils";
// @ts-check
import { AST_NODE_TYPES, ESLintUtils } from "@typescript-eslint/utils";
import { getParserServices } from "@typescript-eslint/utils/eslint-utils";

// Walks up the AST to find the first node that matches the predicate
function findUp(
node: TSESTree.Node,
predicate: (node: TSESTree.Node) => boolean,
): TSESTree.Node | undefined {
let currentNode: TSESTree.Node | undefined = node;
/**
* @typedef {import("@typescript-eslint/utils").TSESTree.Node} TSESTree.Node
*/

/**
* Walks up the AST to find the first node that matches the predicate
*
* @param {TSESTree.Node} node
* @param {(node: TSESTree.Node) => boolean} predicate
* @returns {TSESTree.Node | undefined}
*/
function findUp(node, predicate) {
/** @type {TSESTree.Node | undefined} */
let currentNode = node;
while (currentNode) {
if (predicate(currentNode)) {
return currentNode;
Expand All @@ -23,7 +28,6 @@ function findUp(
export default ESLintUtils.RuleCreator.withoutDocs({
create(context) {
const services = getParserServices(context);
const checker = services.program.getTypeChecker();

return {
Property(node) {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,16 +1,20 @@
import {
AST_NODE_TYPES,
ESLintUtils,
TSESTree,
} from "@typescript-eslint/utils";
// @ts-check
import { AST_NODE_TYPES, ESLintUtils } from "@typescript-eslint/utils";
import { getParserServices } from "@typescript-eslint/utils/eslint-utils";

/**
* @typedef {import("@typescript-eslint/utils").TSESTree.Node} TSESTree.Node
*/

export default ESLintUtils.RuleCreator.withoutDocs({
create(context) {
const services = getParserServices(context);
const checker = services.program.getTypeChecker();

function checkThrowArgument(node: TSESTree.Node): void {
/**
* @param {TSESTree.Node} node
* @returns {void}
*/
function checkThrowArgument(node) {
if (node.type === AST_NODE_TYPES.AwaitExpression) {
return;
}
Expand Down
12 changes: 0 additions & 12 deletions tooling/eslint-plugin/tsconfig.json

This file was deleted.

8 changes: 0 additions & 8 deletions tooling/eslint-plugin/tsup.config.ts

This file was deleted.

File renamed without changes.
16 changes: 16 additions & 0 deletions tooling/prettier-config/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
{
"name": "@uploadthing/prettier-config",
"version": "0.1.0",
"type": "module",
"exports": {
".": "./index.js"
},
"scripts": {
"clean": "git clean -xdf .turbo node_modules"
},
"dependencies": {
"@ianvs/prettier-plugin-sort-imports": "^4.4.0",
"prettier": "^3.4.2",
"prettier-plugin-tailwindcss": "^0.6.9"
}
}
30 changes: 0 additions & 30 deletions vitest.config.ts

This file was deleted.

41 changes: 34 additions & 7 deletions vitest.workspace.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,36 @@
import { defineWorkspace } from "vitest/config";
import { existsSync, readdirSync } from "node:fs";
import { defineWorkspace, mergeConfig, ViteUserConfig } from "vitest/config";

const pkgRoot = (pkg: string) =>
new URL(`./packages/${pkg}`, import.meta.url).pathname;
const alias = (pkg: string) => `${pkgRoot(pkg)}/src`;

const aliases = readdirSync(new URL("./packages", import.meta.url).pathname)
.filter((dir) => existsSync(pkgRoot(dir) + "/package.json"))
.filter((dir) => dir !== "uploadthing")
.reduce<Record<string, string>>(
(acc, pkg) => {
acc[`@uploadthing/${pkg}`] = alias(pkg);
return acc;
},
{ uploadthing: alias("uploadthing") },
);

const baseConfig: ViteUserConfig = {
test: {
mockReset: true,
coverage: {
provider: "v8",
include: ["**/src/**"],
exclude: ["**/docs/**", "**/examples/**", "**/tooling/**"],
},
},
esbuild: { target: "es2020" },
resolve: { alias: aliases },
};

export default defineWorkspace([
{
extends: "./vitest.config.ts",
mergeConfig(baseConfig, {
test: {
include: [
"**/*.test.{ts,tsx}",
Expand All @@ -12,9 +40,8 @@ export default defineWorkspace([
name: "unit",
environment: "node",
},
},
{
extends: "./vitest.config.ts",
} satisfies ViteUserConfig),
mergeConfig(baseConfig, {
test: {
include: ["**/*.browser.test.{ts,tsx}"],
name: "browser",
Expand All @@ -24,5 +51,5 @@ export default defineWorkspace([
name: "chromium",
},
},
},
} satisfies ViteUserConfig),
]);

0 comments on commit eace6bf

Please sign in to comment.