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.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
Prev Previous commit
Next Next commit
lint
  • Loading branch information
FinnDore committed May 5, 2023
commit d955bc2b92f9de9118103b5862104cf889089180
2 changes: 1 addition & 1 deletion cli/src/helpers/createProject.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
import { type PkgInstallerMap } from "~/installers/index.js";
import path from "path";
import { installPackages } from "~/helpers/installPackages.js";
import { scaffoldProject } from "~/helpers/scaffoldProject.js";
import { selectAppFile, selectIndexFile } from "~/helpers/selectBoilerplate.js";
import { type PkgInstallerMap } from "~/installers/index.js";
import { getUserPkgManager } from "~/utils/getUserPkgManager.js";

interface CreateProjectOptions {
Expand Down
4 changes: 2 additions & 2 deletions cli/src/helpers/installPackages.ts
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
import chalk from "chalk";
import ora from "ora";
import {
type InstallerOptions,
type PkgInstallerMap,
} from "~/installers/index.js";
import chalk from "chalk";
import ora from "ora";
import { logger } from "~/utils/logger.js";

type InstallPackagesOptions = {
Expand Down
2 changes: 1 addition & 1 deletion cli/src/helpers/logNextSteps.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { type InstallerOptions } from "~/installers/index.js";
import { DEFAULT_APP_NAME } from "~/consts.js";
import { type InstallerOptions } from "~/installers/index.js";
import { getUserPkgManager } from "~/utils/getUserPkgManager.js";
import { logger } from "~/utils/logger.js";

Expand Down
2 changes: 1 addition & 1 deletion cli/src/helpers/scaffoldProject.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
import path from "path";
import chalk from "chalk";
import fs from "fs-extra";
import inquirer from "inquirer";
import ora from "ora";
import path from "path";
import { PKG_ROOT } from "~/consts.js";
import { type InstallerOptions } from "~/installers/index.js";
import { logger } from "~/utils/logger.js";
Expand Down
4 changes: 2 additions & 2 deletions cli/src/helpers/selectBoilerplate.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { type InstallerOptions } from "~/installers/index.js";
import path from "path";
import fs from "fs-extra";
import path from "path";
import { PKG_ROOT } from "~/consts.js";
import { type InstallerOptions } from "~/installers/index.js";

type SelectBoilerplateProps = Required<
Pick<InstallerOptions, "projectDir" | "packages">
Expand Down
12 changes: 6 additions & 6 deletions cli/src/index.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,10 @@
#!/usr/bin/env node
import { installDependencies } from "./helpers/installDependencies.js";
import { getVersion } from "./utils/getT3Version.js";
import {
getNpmVersion,
renderVersionWarning,
} from "./utils/renderVersionWarning.js";
import fs from "fs-extra";
import path from "path";
import { type PackageJson } from "type-fest";
Expand All @@ -11,12 +17,6 @@ import { buildPkgInstallerMap } from "~/installers/index.js";
import { logger } from "~/utils/logger.js";
import { parseNameAndPath } from "~/utils/parseNameAndPath.js";
import { renderTitle } from "~/utils/renderTitle.js";
import { installDependencies } from "./helpers/installDependencies.js";
import { getVersion } from "./utils/getT3Version.js";
import {
getNpmVersion,
renderVersionWarning,
} from "./utils/renderVersionWarning.js";

type CT3APackageJSON = PackageJson & {
ct3aMetadata?: {
Expand Down
4 changes: 2 additions & 2 deletions cli/src/installers/envVars.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { type Installer } from "~/installers/index.js";
import path from "path";
import fs from "fs-extra";
import path from "path";
import { PKG_ROOT } from "~/consts.js";
import { type Installer } from "~/installers/index.js";

export const envVariablesInstaller: Installer = ({ projectDir, packages }) => {
const usingAuth = packages?.nextAuth.inUse;
Expand Down
6 changes: 3 additions & 3 deletions cli/src/installers/prisma.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
import { type PackageJson } from "type-fest";
import { type Installer } from "~/installers/index.js";
import path from "path";
import fs from "fs-extra";
import path from "path";
import { type PackageJson } from "type-fest";
import { PKG_ROOT } from "~/consts.js";
import { type Installer } from "~/installers/index.js";
import { addPackageDependency } from "~/utils/addPackageDependency.js";

export const prismaInstaller: Installer = ({ projectDir, packages }) => {
Expand Down
2 changes: 1 addition & 1 deletion cli/src/installers/strictEslintAndPrettier.ts
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ export const strictEsLintAndPrettier: Installer = ({
);
} else {
fs.copySync(
path.join(configDir, "prettier.config.cjs"),
path.join(configDir, "_prettier.config.cjs"),
path.join(projectDir, "prettier.config.cjs"),
);
}
Expand Down
2 changes: 1 addition & 1 deletion cli/src/installers/trpc.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
import fs from "fs-extra";
import path from "path";
import { PKG_ROOT } from "~/consts.js";
import { addPackageDependency } from "~/utils/addPackageDependency.js";
import { type Installer } from "~/installers/index.js";
import { addPackageDependency } from "~/utils/addPackageDependency.js";

export const trpcInstaller: Installer = ({ projectDir, packages }) => {
addPackageDependency({
Expand Down
4 changes: 2 additions & 2 deletions cli/src/utils/addPackageDependency.ts
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
import path from "path";
import fs from "fs-extra";
import path from "path";
import sortPackageJson from "sort-package-json";
import { type PackageJson } from "type-fest";
import {
dependencyVersionMap,
type AvailableDependencies,
} from "~/installers/dependencyVersionMap.js";
import sortPackageJson from "sort-package-json";

export const addPackageDependency = (opts: {
dependencies: AvailableDependencies[];
Expand Down
4 changes: 2 additions & 2 deletions cli/src/utils/getT3Version.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { type PackageJson } from "type-fest";
import path from "path";
import fs from "fs-extra";
import path from "path";
import { type PackageJson } from "type-fest";
import { PKG_ROOT } from "~/consts.js";

export const getVersion = () => {
Expand Down
19 changes: 9 additions & 10 deletions cli/src/utils/renderVersionWarning.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,14 @@
import { execSync } from "child_process";
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";
Copy link
Member

Choose a reason for hiding this comment

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

i wish import sorters didn't move imports when they are separated by actual code blocks...

is there a setting for this?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Looks like you can //prettier-ignore lines but thats about it :/


export const renderVersionWarning = (npmVersion: string) => {
const currentVersion = getVersion();
Expand Down Expand Up @@ -29,15 +37,6 @@ 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
*/
import https from "https";

type DistTagsBody = {
latest: string;
};
Expand Down
3 changes: 1 addition & 2 deletions cli/template/extras/src/pages/api/trpc/[trpc].ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,7 @@
import { createNextApiHandler } from "@trpc/server/adapters/next";

import { env } from "~/env.mjs";
import { createTRPCContext } from "~/server/api/trpc";
import { appRouter } from "~/server/api/root";
import { createTRPCContext } from "~/server/api/trpc";

// export API handler
export default createNextApiHandler({
Expand Down
2 changes: 1 addition & 1 deletion cli/template/extras/src/server/api/root.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { createTRPCRouter } from "~/server/api/trpc";
import { exampleRouter } from "~/server/api/routers/example";
import { createTRPCRouter } from "~/server/api/trpc";

/**
* This is the primary router for your server.
Expand Down
1 change: 0 additions & 1 deletion cli/template/extras/src/server/api/routers/example/base.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
import { z } from "zod";

import { createTRPCRouter, publicProcedure } from "~/server/api/trpc";

export const exampleRouter = createTRPCRouter({
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
import { z } from "zod";

import {
createTRPCRouter,
publicProcedure,
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
import { z } from "zod";

import {
createTRPCRouter,
publicProcedure,
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
import { z } from "zod";

import { createTRPCRouter, publicProcedure } from "~/server/api/trpc";

export const exampleRouter = createTRPCRouter({
Expand Down
22 changes: 11 additions & 11 deletions cli/template/extras/src/server/api/trpc/base.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,18 @@
*
* 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";
Copy link
Member

Choose a reason for hiding this comment

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

same here - wish it didn't move these imports when they are clearly separated :/

we'll have to look over the comments cause those should not be moved


/** Replace this with an object if you want to pass things to `createContextInner`. */
type CreateContextOptions = Record<string, never>;
Expand Down Expand Up @@ -43,17 +54,6 @@ 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.
*/
import { initTRPC } from "@trpc/server";
import superjson from "superjson";
import { ZodError } from "zod";

const t = initTRPC.context<typeof createTRPCContext>().create({
transformer: superjson,
errorFormatter({ shape, error }) {
Expand Down
23 changes: 11 additions & 12 deletions cli/template/extras/src/server/api/trpc/with-auth-prisma.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,9 +14,19 @@
*
* 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";

Expand Down Expand Up @@ -58,17 +68,6 @@ 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.
*/
import { initTRPC, TRPCError } from "@trpc/server";
import superjson from "superjson";
import { ZodError } from "zod";

const t = initTRPC.context<typeof createTRPCContext>().create({
transformer: superjson,
errorFormatter({ shape, error }) {
Expand Down
23 changes: 11 additions & 12 deletions cli/template/extras/src/server/api/trpc/with-auth.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,9 +14,19 @@
*
* 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 = {
Expand Down Expand Up @@ -56,17 +66,6 @@ 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.
*/
import { initTRPC, TRPCError } from "@trpc/server";
import superjson from "superjson";
import { ZodError } from "zod";

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

/**
* 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 @@ -46,17 +56,6 @@ 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.
*/
import { initTRPC } from "@trpc/server";
import superjson from "superjson";
import { ZodError } from "zod";

const t = initTRPC.context<typeof createTRPCContext>().create({
transformer: superjson,
errorFormatter({ shape, error }) {
Expand Down
2 changes: 1 addition & 1 deletion cli/template/extras/src/server/auth/with-prisma.ts
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
import { PrismaAdapter } from "@next-auth/prisma-adapter";
import { type GetServerSidePropsContext } from "next";
import {
getServerSession,
type NextAuthOptions,
type DefaultSession,
} from "next-auth";
import DiscordProvider from "next-auth/providers/discord";
import { PrismaAdapter } from "@next-auth/prisma-adapter";
import { env } from "~/env.mjs";
import { prisma } from "~/server/db";

Expand Down
1 change: 0 additions & 1 deletion cli/template/extras/src/server/db.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
import { PrismaClient } from "@prisma/client";

import { env } from "~/env.mjs";

const globalForPrisma = globalThis as unknown as { prisma: PrismaClient };
Expand Down
1 change: 0 additions & 1 deletion cli/template/extras/src/utils/api.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@ import { httpBatchLink, loggerLink } from "@trpc/client";
import { createTRPCNext } from "@trpc/next";
import { type inferRouterInputs, type inferRouterOutputs } from "@trpc/server";
import superjson from "superjson";

import { type AppRouter } from "~/server/api/root";

const getBaseUrl = () => {
Expand Down