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

refactor: use type: module #1666

Merged
merged 7 commits into from
Nov 19, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
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
5 changes: 5 additions & 0 deletions .changeset/rich-seahorses-happen.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"create-t3-app": patch
---

refactor: use `type: module` for more modern setup
4 changes: 2 additions & 2 deletions cli/src/helpers/createProject.ts
Original file line number Diff line number Diff line change
Expand Up @@ -57,8 +57,8 @@ export const createProject = async ({
if (appRouter) {
// Replace next.config
fs.copyFileSync(
path.join(PKG_ROOT, "template/extras/config/next-config-appdir.mjs"),
path.join(projectDir, "next.config.mjs")
path.join(PKG_ROOT, "template/extras/config/next-config-appdir.js"),
path.join(projectDir, "next.config.js")
);

selectLayoutFile({ projectDir, packages });
Expand Down
10 changes: 5 additions & 5 deletions cli/src/installers/envVars.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,11 +15,11 @@ export const envVariablesInstaller: Installer = ({ projectDir, packages }) => {

const envFile =
usingAuth && usingDb
? "with-auth-db.mjs"
? "with-auth-db.js"
: usingAuth
? "with-auth.mjs"
? "with-auth.js"
: usingDb
? "with-db.mjs"
? "with-db.js"
: "";

if (envFile !== "") {
Expand All @@ -28,7 +28,7 @@ export const envVariablesInstaller: Installer = ({ projectDir, packages }) => {
"template/extras/src/env",
envFile
);
const envSchemaDest = path.join(projectDir, "src/env.mjs");
const envSchemaDest = path.join(projectDir, "src/env.js");
fs.copySync(envSchemaSrc, envSchemaDest);
}

Expand All @@ -45,7 +45,7 @@ const getEnvContent = (
usingDrizzle: boolean
) => {
let content = `
# When adding additional environment variables, the schema in "/src/env.mjs"
# When adding additional environment variables, the schema in "/src/env.js"
# should be updated accordingly.
`
.trim()
Expand Down
4 changes: 2 additions & 2 deletions cli/src/installers/tailwind.ts
Original file line number Diff line number Diff line change
Expand Up @@ -26,8 +26,8 @@ export const tailwindInstaller: Installer = ({ projectDir }) => {
const postcssCfgSrc = path.join(extrasDir, "config/postcss.config.cjs");
const postcssCfgDest = path.join(projectDir, "postcss.config.cjs");

const prettierSrc = path.join(extrasDir, "config/_prettier.config.mjs");
const prettierDest = path.join(projectDir, "prettier.config.mjs");
const prettierSrc = path.join(extrasDir, "config/_prettier.config.js");
const prettierDest = path.join(projectDir, "prettier.config.js");

const cssSrc = path.join(extrasDir, "src/styles/globals.css");
const cssDest = path.join(projectDir, "src/styles/globals.css");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
* Run `build` or `dev` with `SKIP_ENV_VALIDATION` to skip env validation. This is especially useful
* for Docker builds.
*/
await import("./src/env.mjs");
await import("./src/env.js");

/** @type {import("next").NextConfig} */
const config = {
Expand Down
1 change: 1 addition & 0 deletions cli/template/base/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
{
"name": "template",
"version": "0.1.0",
"type": "module",
"private": true,
"scripts": {
"dev": "next dev",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,13 +28,13 @@ export const env = createEnv({
// NEXT_PUBLIC_CLIENTVAR: process.env.NEXT_PUBLIC_CLIENTVAR,
},
/**
* Run `build` or `dev` with `SKIP_ENV_VALIDATION` to skip env validation.
* This is especially useful for Docker builds.
* Run `build` or `dev` with `SKIP_ENV_VALIDATION` to skip env validation. This is especially
* useful for Docker builds.
*/
skipValidation: !!process.env.SKIP_ENV_VALIDATION,
/**
* Makes it so that empty strings are treated as undefined.
* `SOME_VAR: z.string()` and `SOME_VAR=''` will throw an error.
* Makes it so that empty strings are treated as undefined. `SOME_VAR: z.string()` and
* `SOME_VAR=''` will throw an error.
*/
emptyStringAsUndefined: true,
});
2 changes: 1 addition & 1 deletion cli/template/base/tsconfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@
"**/*.ts",
"**/*.tsx",
"**/*.cjs",
"**/*.mjs",
"**/*.js",
".next/types/**/*.ts"
],
"exclude": ["node_modules"]
Expand Down
2 changes: 1 addition & 1 deletion cli/template/extras/config/drizzle.config.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { type Config } from "drizzle-kit";

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

export default {
schema: "./src/server/db/schema.ts",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
* Run `build` or `dev` with `SKIP_ENV_VALIDATION` to skip env validation. This is especially useful
* for Docker builds.
*/
await import("./src/env.mjs");
await import("./src/env.js");

/** @type {import("next").NextConfig} */
const config = {};
Expand Down
2 changes: 1 addition & 1 deletion cli/template/extras/src/app/api/trpc/[trpc]/route.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { fetchRequestHandler } from "@trpc/server/adapters/fetch";
import { type NextRequest } from "next/server";

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

Expand Down
2 changes: 1 addition & 1 deletion cli/template/extras/src/pages/api/trpc/[trpc].ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { createNextApiHandler } from "@trpc/server/adapters/next";

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

Expand Down
2 changes: 1 addition & 1 deletion cli/template/extras/src/server/auth-app/base.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import {
} from "next-auth";
import DiscordProvider from "next-auth/providers/discord";

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

/**
* Module augmentation for `next-auth` types. Allows us to add custom properties to the `session`
Expand Down
2 changes: 1 addition & 1 deletion cli/template/extras/src/server/auth-app/with-drizzle.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import {
} from "next-auth";
import DiscordProvider from "next-auth/providers/discord";

import { env } from "~/env.mjs";
import { env } from "~/env";
import { db } from "~/server/db";
import { mysqlTable } from "~/server/db/schema";

Expand Down
2 changes: 1 addition & 1 deletion cli/template/extras/src/server/auth-app/with-prisma.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import {
} from "next-auth";
import DiscordProvider from "next-auth/providers/discord";

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

/**
Expand Down
2 changes: 1 addition & 1 deletion cli/template/extras/src/server/auth-pages/base.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import {
} from "next-auth";
import DiscordProvider from "next-auth/providers/discord";

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

/**
* Module augmentation for `next-auth` types. Allows us to add custom properties to the `session`
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import {
} from "next-auth";
import DiscordProvider from "next-auth/providers/discord";

import { env } from "~/env.mjs";
import { env } from "~/env";
import { db } from "~/server/db";
import { mysqlTable } from "~/server/db/schema";

Expand Down
2 changes: 1 addition & 1 deletion cli/template/extras/src/server/auth-pages/with-prisma.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import {
} from "next-auth";
import DiscordProvider from "next-auth/providers/discord";

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

/**
Expand Down
2 changes: 1 addition & 1 deletion cli/template/extras/src/server/db/db-prisma.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { PrismaClient } from "@prisma/client";

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

const globalForPrisma = globalThis as unknown as {
prisma: PrismaClient | undefined;
Expand Down
2 changes: 1 addition & 1 deletion cli/template/extras/src/server/db/index-drizzle.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { Client } from "@planetscale/database";
import { drizzle } from "drizzle-orm/planetscale-serverless";

import { env } from "~/env.mjs";
import { env } from "~/env";
import * as schema from "./schema";

export const db = drizzle(
Expand Down
2 changes: 1 addition & 1 deletion upgrade/next.config.mjs → upgrade/next.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import { getHighlighter } from "shiki";
* Run `build` or `dev` with `SKIP_ENV_VALIDATION` to skip env validation. This is especially useful
* for Docker builds.
*/
await import("./src/env.mjs");
await import("./src/env.js");

/** @type {import('next').NextConfig} */
const nextConfig = {
Expand Down
1 change: 1 addition & 0 deletions upgrade/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
{
"name": "@ct3a/upgrade",
"version": "0.1.0",
"type": "module",
"private": true,
"scripts": {
"build": "next build",
Expand Down
File renamed without changes.
File renamed without changes.
2 changes: 1 addition & 1 deletion upgrade/src/lib/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import { request } from "@octokit/request";
import { clsx, type ClassValue } from "clsx";
import { twMerge } from "tailwind-merge";

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

export const cn = (...inputs: ClassValue[]) => {
return twMerge(clsx(inputs));
Expand Down
2 changes: 1 addition & 1 deletion upgrade/tsconfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@
"**/*.ts",
"**/*.tsx",
"**/*.cjs",
"**/*.mjs",
"**/*.js",
".next/types/**/*.ts"
],
"exclude": ["node_modules"]
Expand Down
6 changes: 3 additions & 3 deletions www/src/components/docs/folderStructureDiagram.astro
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
const allFiles = {
"public/favicon.ico": [], // This file is included in every configuration
"prisma/schema.prisma": ["prisma"], // This file is included with prisma
"src/env.mjs": [],
"src/env.js": [],
"src/pages/_app.tsx": [],
"src/pages/api/auth/[...nextauth].ts": ["nextauth"],
"src/pages/api/trpc/[trpc].ts": ["trpc"],
Expand All @@ -32,10 +32,10 @@
".eslintrc.cjs": [],
".gitignore": [],
"next-env.d.ts": [],
"next.config.mjs": [],
"next.config.js": [],
"package.json": [],
"postcss.config.cjs": ["tailwind"],
"prettier.config.mjs": ["tailwind"],
"prettier.config.js": ["tailwind"],
"README.md": [],
"tailwind.config.ts": ["tailwind"],
"tsconfig.json": [],
Expand Down
4 changes: 2 additions & 2 deletions www/src/pages/ar/deployment/docker.md
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ dir: rtl

### 1. إعداد Next

في ملف [`next.config.mjs`](https://github.com/t3-oss/create-t3-app/blob/main/cli/template/base/next.config.mjs) قم بإضافة `standalone` حتى [تُقلل حجم الصور تلقائيا](https://nextjs.org/docs/advanced-features/output-file-tracing):
في ملف [`next.config.js`](https://github.com/t3-oss/create-t3-app/blob/main/cli/template/base/next.config.js) قم بإضافة `standalone` حتى [تُقلل حجم الصور تلقائيا](https://nextjs.org/docs/advanced-features/output-file-tracing):

```diff
export default defineNextConfig({
Expand Down Expand Up @@ -115,7 +115,7 @@ ENV NODE_ENV production
RUN addgroup --system --gid 1001 nodejs
RUN adduser --system --uid 1001 nextjs

COPY --from=builder /app/next.config.mjs ./
COPY --from=builder /app/next.config.js ./
COPY --from=builder /app/public ./public
COPY --from=builder /app/package.json ./package.json

Expand Down
8 changes: 4 additions & 4 deletions www/src/pages/ar/folder-structure.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -191,9 +191,9 @@ import Form from "../../components/docs/folderStructureForm.astro";
</div>
<div>

### `next.config.mjs`
### `next.config.js`

يستخدم ملف `next.config.mjs` لإعداد Next.js، لمزيد من المعلومات [Next.js Docs](https://nextjs.org/docs/api-reference/next.config.js/introduction). تلميح: يسمح تمديد `.mjx` باستخدام ESM imports.
يستخدم ملف `next.config.js` لإعداد Next.js، لمزيد من المعلومات [Next.js Docs](https://nextjs.org/docs/api-reference/next.config.js/introduction). تلميح: يسمح تمديد `.mjx` باستخدام ESM imports.

</div>
<div data-components="tailwind">
Expand All @@ -205,9 +205,9 @@ import Form from "../../components/docs/folderStructureForm.astro";
</div>
<div data-components="tailwind">

### `prettier.config.mjs`
### `prettier.config.js`

إن ملف `prettier.config.mjs` ضروري عند استخدام Prettier ولإضافة prettier-plugin-tailwindcss لتنظيم الفئات (classes) مع Tailwind CSS، لمزيد من المعلومات [Tailwind CSS blog post](https://tailwindcss.com/blog/automatic-class-sorting-with-prettier).
إن ملف `prettier.config.js` ضروري عند استخدام Prettier ولإضافة prettier-plugin-tailwindcss لتنظيم الفئات (classes) مع Tailwind CSS، لمزيد من المعلومات [Tailwind CSS blog post](https://tailwindcss.com/blog/automatic-class-sorting-with-prettier).

</div>
<div>
Expand Down
4 changes: 2 additions & 2 deletions www/src/pages/ar/usage/env-variables.md
Original file line number Diff line number Diff line change
Expand Up @@ -71,10 +71,10 @@ const validated = schema.parse(process.env);

## إستخدام الـ Environment Variables

إذا أردت إستخدام الـ env vars فيمكنك إستيراد` env.mjs` واستعمالهم طبيعيا. إذا إستيرادت الملف في Client وحولت استعمال قيم الserver-side، ستنذر بوجود خطأ في run-time.
إذا أردت إستخدام الـ env vars فيمكنك إستيراد` env.js` واستعمالهم طبيعيا. إذا إستيرادت الملف في Client وحولت استعمال قيم الserver-side، ستنذر بوجود خطأ في run-time.

```ts:pages/api/hello.ts
import { env } from "../../env.mjs";
import { env } from "../../env.js";

// `env` is fully typesafe and provides autocompletion
const dbUrl = env.DATABASE_URL;
Expand Down
4 changes: 2 additions & 2 deletions www/src/pages/en/deployment/docker.md
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ Please note that Next.js requires a different process for build time (available

### 1. Next Configuration

In your [`next.config.mjs`](https://github.com/t3-oss/create-t3-app/blob/main/cli/template/base/next.config.mjs), add the `standalone` output-option configuration to [reduce image size by automatically leveraging output traces](https://nextjs.org/docs/advanced-features/output-file-tracing):
In your [`next.config.js`](https://github.com/t3-oss/create-t3-app/blob/main/cli/template/base/next.config.js), add the `standalone` output-option configuration to [reduce image size by automatically leveraging output traces](https://nextjs.org/docs/advanced-features/output-file-tracing):

```diff
export default defineNextConfig({
Expand Down Expand Up @@ -108,7 +108,7 @@ ENV NODE_ENV production

# ENV NEXT_TELEMETRY_DISABLED 1

COPY --from=builder /app/next.config.mjs ./
COPY --from=builder /app/next.config.js ./
COPY --from=builder /app/public ./public
COPY --from=builder /app/package.json ./package.json

Expand Down
Loading