Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: add import order sorting via prettier #1392

Merged
merged 26 commits into from
May 17, 2023
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
Merge commit '1e4c2d352e9b42e0f48c98980714c5334bfd06d7' into prettier…
…-import-order
  • Loading branch information
FinnDore committed May 9, 2023
commit 8fbb67d1d9406c6574eec97da59b0346e78eeb0c
7 changes: 2 additions & 5 deletions cli/.prettierrc.cjs
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,8 @@ const baseConfig = require("../.prettierrc.cjs");

/** @type {import('prettier').Config} */
const config = {
...require("../.prettierrc.cjs"),
plugins: [
require.resolve("@ianvs/prettier-plugin-sort-imports"),
require.resolve("prettier-plugin-tailwindcss"),
],
...baseConfig,
plugins: [...baseConfig.plugins, "prettier-plugin-tailwindcss"],
tailwindConfig: "./template/extras/config/tailwind.config.ts",
};

Expand Down
3 changes: 1 addition & 2 deletions cli/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@
"lint": "eslint . --report-unused-disable-directives",
"lint:fix": "pnpm lint --fix",
"format": "pnpm format:check --write",
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

does --write override the --check in the :check script?

bit cursed but i'll allow it

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

image

P much

"format:check": "pnpm prettier --check --plugin-search-dir=. **/*.{cjs,mjs,ts,tsx,md,json} --ignore-path ../.gitignore --ignore-unknown --no-error-on-unmatched-pattern",
"format:check": "pnpm prettier --plugin-search-dir=. **/*.{cjs,mjs,ts,tsx,md,json} --ignore-path ../.gitignore --ignore-unknown --no-error-on-unmatched-pattern --check",
"release": "changeset version",
"pub:beta": "pnpm build && npm publish --tag beta",
"pub:next": "pnpm build && npm publish --tag next",
Expand All @@ -52,7 +52,6 @@
"sort-package-json": "^2.4.1"
},
"devDependencies": {
"@ianvs/prettier-plugin-sort-imports": "^3.7.2",
"@prisma/client": "^4.11.0",
"@t3-oss/env-nextjs": "^0.2.1",
"@tanstack/react-query": "^4.28.0",
Expand Down
15 changes: 2 additions & 13 deletions cli/src/cli/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,8 @@ import chalk from "chalk";
import { Command } from "commander";
import inquirer from "inquirer";
import { CREATE_T3_APP, DEFAULT_APP_NAME } from "~/consts.js";
import {
availablePackages,
type AvailablePackages,
} from "~/installers/index.js";
import { type AvailablePackages } from "~/installers/index.js";
import { availablePackages } from "~/installers/index.js";
import { getVersion } from "~/utils/getT3Version.js";
import { getUserPkgManager } from "~/utils/getUserPkgManager.js";
import { logger } from "~/utils/logger.js";
Expand All @@ -17,7 +15,6 @@ interface CliFlags {
noInstall: boolean;
default: boolean;
importAlias: string;
strictEslintAndPrettier: boolean;

/** @internal Used in CI. */
CI: boolean;
Expand Down Expand Up @@ -50,7 +47,6 @@ const defaultOptions: CliResults = {
prisma: false,
nextAuth: false,
importAlias: "~/",
strictEslintAndPrettier: false,
},
};

Expand Down Expand Up @@ -118,11 +114,6 @@ export const runCli = async () => {
"Explicitly tell the CLI to use a custom import alias",
defaultOptions.flags.importAlias,
)
.option(
"-ep -eslint-pretteier",
"enable prettier and a strict eslint config",
defaultOptions.flags.strictEslintAndPrettier,
)
/** END CI-FLAGS */
.version(getVersion(), "-v, --version", "Display the version number")
.addHelpText(
Expand Down Expand Up @@ -162,8 +153,6 @@ export const runCli = async () => {
if (cliResults.flags.tailwind) cliResults.packages.push("tailwind");
if (cliResults.flags.prisma) cliResults.packages.push("prisma");
if (cliResults.flags.nextAuth) cliResults.packages.push("nextAuth");
if (cliResults.flags.strictEslintAndPrettier)
cliResults.packages.push("strictEslintAndPrettier");
}

// Explained below why this is in a try/catch block
Expand Down
14 changes: 7 additions & 7 deletions cli/src/utils/renderVersionWarning.ts
Original file line number Diff line number Diff line change
@@ -1,13 +1,6 @@
import { getVersion } from "./getT3Version.js";
import { logger } from "./logger.js";
import { execSync } from "child_process";
/**
* Copyright (c) 2015-present, Facebook, Inc.
*
* This source code is licensed under the MIT license found in the LICENSE file in the root
* directory of this source tree.
* https://github.com/facebook/create-react-app/blob/main/packages/create-react-app/LICENSE
*/
import https from "https";

export const renderVersionWarning = (npmVersion: string) => {
Expand Down Expand Up @@ -37,6 +30,13 @@ export const renderVersionWarning = (npmVersion: string) => {
console.log("");
};

/**
* Copyright (c) 2015-present, Facebook, Inc.
*
* This source code is licensed under the MIT license found in the LICENSE file in the root
* directory of this source tree.
* https://github.com/facebook/create-react-app/blob/main/packages/create-react-app/LICENSE
*/
type DistTagsBody = {
latest: string;
};
Expand Down
20 changes: 8 additions & 12 deletions cli/template/extras/src/server/api/trpc/base.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,18 +20,6 @@ import { ZodError } from "zod";
* These allow you to access things when processing a request, like the database, the session, etc.
*/

/**
* 2. INITIALIZATION
*
* This is where the tRPC API is initialized, connecting the context and transformer. We also parse
* ZodErrors so that you get typesafety on the frontend if your procedure fails due to validation
* errors on the backend.
*/
import { initTRPC } from "@trpc/server";
import { type CreateNextContextOptions } from "@trpc/server/adapters/next";
import superjson from "superjson";
import { ZodError } from "zod";

type CreateContextOptions = Record<string, never>;

/**
Expand All @@ -58,6 +46,14 @@ export const createTRPCContext = (_opts: CreateNextContextOptions) => {
return createInnerTRPCContext({});
};

/**
* 2. INITIALIZATION
*
* This is where the tRPC API is initialized, connecting the context and transformer. We also parse
* ZodErrors so that you get typesafety on the frontend if your procedure fails due to validation
* errors on the backend.
*/

const t = initTRPC.context<typeof createTRPCContext>().create({
transformer: superjson,
errorFormatter({ shape, error }) {
Expand Down
23 changes: 8 additions & 15 deletions cli/template/extras/src/server/api/trpc/with-auth-prisma.ts
Original file line number Diff line number Diff line change
Expand Up @@ -23,21 +23,6 @@ import { prisma } from "~/server/db";
* These allow you to access things when processing a request, like the database, the session, etc.
*/

/**
* 2. INITIALIZATION
*
* This is where the tRPC API is initialized, connecting the context and transformer. We also parse
* ZodErrors so that you get typesafety on the frontend if your procedure fails due to validation
* errors on the backend.
*/
import { initTRPC, TRPCError } from "@trpc/server";
import { type CreateNextContextOptions } from "@trpc/server/adapters/next";
import { type Session } from "next-auth";
import superjson from "superjson";
import { ZodError } from "zod";
import { getServerAuthSession } from "~/server/auth";
import { prisma } from "~/server/db";

type CreateContextOptions = {
session: Session | null;
};
Expand Down Expand Up @@ -76,6 +61,14 @@ export const createTRPCContext = async (opts: CreateNextContextOptions) => {
});
};

/**
* 2. INITIALIZATION
*
* This is where the tRPC API is initialized, connecting the context and transformer. We also parse
* ZodErrors so that you get typesafety on the frontend if your procedure fails due to validation
* errors on the backend.
*/

const t = initTRPC.context<typeof createTRPCContext>().create({
transformer: superjson,
errorFormatter({ shape, error }) {
Expand Down
22 changes: 8 additions & 14 deletions cli/template/extras/src/server/api/trpc/with-auth.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,20 +21,6 @@ import { getServerAuthSession } from "~/server/auth";
* These allow you to access things when processing a request, like the database, the session, etc.
*/

/**
* 2. INITIALIZATION
*
* This is where the tRPC API is initialized, connecting the context and transformer. We also parse
* ZodErrors so that you get typesafety on the frontend if your procedure fails due to validation
* errors on the backend.
*/
import { initTRPC, TRPCError } from "@trpc/server";
import { type CreateNextContextOptions } from "@trpc/server/adapters/next";
import { type Session } from "next-auth";
import superjson from "superjson";
import { ZodError } from "zod";
import { getServerAuthSession } from "~/server/auth";

type CreateContextOptions = {
session: Session | null;
};
Expand Down Expand Up @@ -73,6 +59,14 @@ export const createTRPCContext = async ({
});
};

/**
* 2. INITIALIZATION
*
* This is where the tRPC API is initialized, connecting the context and transformer. We also parse
* ZodErrors so that you get typesafety on the frontend if your procedure fails due to validation
* errors on the backend.
*/

const t = initTRPC.context<typeof createTRPCContext>().create({
transformer: superjson,
errorFormatter({ shape, error }) {
Expand Down
21 changes: 8 additions & 13 deletions cli/template/extras/src/server/api/trpc/with-prisma.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,19 +20,6 @@ import { prisma } from "~/server/db";
* These allow you to access things when processing a request, like the database, the session, etc.
*/

/**
* 2. INITIALIZATION
*
* This is where the tRPC API is initialized, connecting the context and transformer. We also parse
* ZodErrors so that you get typesafety on the frontend if your procedure fails due to validation
* errors on the backend.
*/
import { initTRPC } from "@trpc/server";
import { type CreateNextContextOptions } from "@trpc/server/adapters/next";
import superjson from "superjson";
import { ZodError } from "zod";
import { prisma } from "~/server/db";

type CreateContextOptions = Record<string, never>;

/**
Expand Down Expand Up @@ -61,6 +48,14 @@ export const createTRPCContext = (_opts: CreateNextContextOptions) => {
return createInnerTRPCContext({});
};

/**
* 2. INITIALIZATION
*
* This is where the tRPC API is initialized, connecting the context and transformer. We also parse
* ZodErrors so that you get typesafety on the frontend if your procedure fails due to validation
* errors on the backend.
*/

const t = initTRPC.context<typeof createTRPCContext>().create({
transformer: superjson,
errorFormatter({ shape, error }) {
Expand Down
32 changes: 11 additions & 21 deletions pnpm-lock.yaml

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

7 changes: 3 additions & 4 deletions www/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -43,10 +43,9 @@
"devDependencies": {
"@astrojs/react": "^2.1.1",
"@astrojs/tailwind": "^3.1.1",
"@ianvs/prettier-plugin-sort-imports": "^3.7.2",
"@types/node": "^18.15.5",
"@types/react": "^18.0.28",
"@types/react-dom": "^18.0.11",
"@types/node": "^18.16.1",
"@types/react": "^18.2.0",
"@types/react-dom": "^18.2.1",
"@types/react-typist": "^2.0.3",
"@types/treeify": "^1.0.0",
"@typescript-eslint/parser": "^5.59.1",
Expand Down
4 changes: 0 additions & 4 deletions www/src/components/navigation/githubIcon.astro
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,6 @@
import { getIsRtlFromUrl, getLanguageFromURL } from "../../languages";
import { fetchGithub } from "../../utils/fetchGithub";

type GithubRepoResponse = {
stargazers_count: number;
};

const githubStars =
(await fetchGithub("https://api.github.com/repos/t3-oss/create-t3-app", {
throwIfNoAuth: false,
Expand Down
4 changes: 2 additions & 2 deletions www/src/pages/pt/usage/trpc.md
Original file line number Diff line number Diff line change
Expand Up @@ -338,8 +338,8 @@ Aqui está um exemplo de teste de integração que usa [Vitest](https://vitest.d
```ts
import { type inferProcedureInput } from "@trpc/server";
import { expect, test } from "vitest";
import { appRouter, type AppRouter } from "~/server/router/_app";
import { createContextInner } from "~/server/router/context";
import { appRouter, type AppRouter } from "~/server/api/root";
import { createInnerTRPCContext } from "~/server/api/trpc";

test("example router", async () => {
const ctx = await createInnerTRPCContext({ session: null });
Expand Down
Loading
You are viewing a condensed version of this merge commit. You can view the full changes here.