From 25df53d19fa1a87e5397d14a81100c6da2e5a3ee Mon Sep 17 00:00:00 2001 From: Oscar Busk Date: Thu, 12 Aug 2021 22:36:53 +0200 Subject: [PATCH] next-env.d.ts note in templates (#27983) Hello! I was using `npx create-next-app --ts` to quickly bootstrap a basic next.js project with Typescript. It bothered me that I got git diff just from running `npm run build` inside the project, because the new notice in the `next-env.d.ts` file. ![image](https://user-images.githubusercontent.com/13413409/129115266-80e00bf3-78aa-40be-bd0f-a18aaa448a68.png) So I went ahead and updated the `next-env.d.ts` file in [`packages/create-next-app/templates/typescript`](https://github.com/oBusk/next.js/blob/fb67ce9864f3561bd8883092d215960040402aa7/packages/create-next-app/templates/typescript/next-env.d.ts) to be exactly how the file looks after running once. (https://github.com/vercel/next.js/commit/7417ecc09c6b44fb4ebfdf6acd13cbcec784a44e) Then I realized that I could probably do the same for all the `next-env.d.ts` that are spread out in the many examples, to make running those examples after cloning them feel a bit smoother. (https://github.com/vercel/next.js/commit/fb67ce9864f3561bd8883092d215960040402aa7) > However I skipped the [`with-typescript-graphql`](https://github.com/vercel/next.js/tree/40f85f6d95b3f69421bbf13cced68754e009eed4/examples/with-typescript-graphql) example since that [`next-env.d.ts`](https://github.com/vercel/next.js/blob/40f85f6d95b3f69421bbf13cced68754e009eed4/examples/with-typescript-graphql/next-env.d.ts#L4-L9) actually has changes and I couldn't even run `yarn build` in that example, so I'm not sure what will happen with the `next-env.d.ts`. Someone who _gets_ that example will have to fix it I suppose. --- examples/blog-starter-typescript/next-env.d.ts | 4 ++++ examples/custom-server-typescript/next-env.d.ts | 4 ++++ examples/with-aws-amplify-typescript/next-env.d.ts | 4 ++++ examples/with-chakra-ui-typescript/next-env.d.ts | 4 ++++ examples/with-electron-typescript/renderer/next-env.d.ts | 4 ++++ examples/with-expo-typescript/next-env.d.ts | 4 ++++ examples/with-ionic-typescript/next-env.d.ts | 4 ++++ examples/with-mobx-state-tree-typescript/next-env.d.ts | 3 +++ examples/with-mysql/next-env.d.ts | 4 ++++ examples/with-next-sitemap/next-env.d.ts | 4 ++++ examples/with-paste-typescript/next-env.d.ts | 4 ++++ examples/with-react-intl/next-env.d.ts | 4 ++++ examples/with-react-md-typescript/next-env.d.ts | 4 ++++ examples/with-redux-toolkit-typescript/next-env.d.ts | 3 +++ examples/with-reflexjs/next-env.d.ts | 6 ++++++ examples/with-storybook-styled-jsx-scss/next-env.d.ts | 4 ++++ examples/with-stripe-typescript/next-env.d.ts | 8 ++++++-- examples/with-typescript-eslint-jest/next-env.d.ts | 4 ++++ examples/with-typescript-graphql/graphql.d.ts | 6 ++++++ examples/with-typescript-graphql/next-env.d.ts | 9 +++------ examples/with-typescript-graphql/tsconfig.json | 2 +- examples/with-typescript-styled-components/next-env.d.ts | 4 ++++ examples/with-typescript-types/next-env.d.ts | 4 ++++ examples/with-typescript/next-env.d.ts | 4 ++++ examples/with-unsplash/next-env.d.ts | 4 ++++ packages/create-next-app/create-app.ts | 9 +++++++++ .../create-next-app/templates/typescript/next-env.d.ts | 3 +++ scripts/check-examples.sh | 3 +++ 28 files changed, 115 insertions(+), 9 deletions(-) create mode 100644 examples/with-reflexjs/next-env.d.ts create mode 100644 examples/with-typescript-graphql/graphql.d.ts diff --git a/examples/blog-starter-typescript/next-env.d.ts b/examples/blog-starter-typescript/next-env.d.ts index 7b7aa2c7727d8..9bc3dd46b9d9b 100644 --- a/examples/blog-starter-typescript/next-env.d.ts +++ b/examples/blog-starter-typescript/next-env.d.ts @@ -1,2 +1,6 @@ /// /// +/// + +// NOTE: This file should not be edited +// see https://nextjs.org/docs/basic-features/typescript for more information. diff --git a/examples/custom-server-typescript/next-env.d.ts b/examples/custom-server-typescript/next-env.d.ts index 7b7aa2c7727d8..9bc3dd46b9d9b 100644 --- a/examples/custom-server-typescript/next-env.d.ts +++ b/examples/custom-server-typescript/next-env.d.ts @@ -1,2 +1,6 @@ /// /// +/// + +// NOTE: This file should not be edited +// see https://nextjs.org/docs/basic-features/typescript for more information. diff --git a/examples/with-aws-amplify-typescript/next-env.d.ts b/examples/with-aws-amplify-typescript/next-env.d.ts index 7b7aa2c7727d8..9bc3dd46b9d9b 100644 --- a/examples/with-aws-amplify-typescript/next-env.d.ts +++ b/examples/with-aws-amplify-typescript/next-env.d.ts @@ -1,2 +1,6 @@ /// /// +/// + +// NOTE: This file should not be edited +// see https://nextjs.org/docs/basic-features/typescript for more information. diff --git a/examples/with-chakra-ui-typescript/next-env.d.ts b/examples/with-chakra-ui-typescript/next-env.d.ts index 7b7aa2c7727d8..9bc3dd46b9d9b 100644 --- a/examples/with-chakra-ui-typescript/next-env.d.ts +++ b/examples/with-chakra-ui-typescript/next-env.d.ts @@ -1,2 +1,6 @@ /// /// +/// + +// NOTE: This file should not be edited +// see https://nextjs.org/docs/basic-features/typescript for more information. diff --git a/examples/with-electron-typescript/renderer/next-env.d.ts b/examples/with-electron-typescript/renderer/next-env.d.ts index 7b7aa2c7727d8..9bc3dd46b9d9b 100644 --- a/examples/with-electron-typescript/renderer/next-env.d.ts +++ b/examples/with-electron-typescript/renderer/next-env.d.ts @@ -1,2 +1,6 @@ /// /// +/// + +// NOTE: This file should not be edited +// see https://nextjs.org/docs/basic-features/typescript for more information. diff --git a/examples/with-expo-typescript/next-env.d.ts b/examples/with-expo-typescript/next-env.d.ts index 7b7aa2c7727d8..9bc3dd46b9d9b 100644 --- a/examples/with-expo-typescript/next-env.d.ts +++ b/examples/with-expo-typescript/next-env.d.ts @@ -1,2 +1,6 @@ /// /// +/// + +// NOTE: This file should not be edited +// see https://nextjs.org/docs/basic-features/typescript for more information. diff --git a/examples/with-ionic-typescript/next-env.d.ts b/examples/with-ionic-typescript/next-env.d.ts index 7b7aa2c7727d8..9bc3dd46b9d9b 100644 --- a/examples/with-ionic-typescript/next-env.d.ts +++ b/examples/with-ionic-typescript/next-env.d.ts @@ -1,2 +1,6 @@ /// /// +/// + +// NOTE: This file should not be edited +// see https://nextjs.org/docs/basic-features/typescript for more information. diff --git a/examples/with-mobx-state-tree-typescript/next-env.d.ts b/examples/with-mobx-state-tree-typescript/next-env.d.ts index c6643fda12ff6..9bc3dd46b9d9b 100644 --- a/examples/with-mobx-state-tree-typescript/next-env.d.ts +++ b/examples/with-mobx-state-tree-typescript/next-env.d.ts @@ -1,3 +1,6 @@ /// /// /// + +// NOTE: This file should not be edited +// see https://nextjs.org/docs/basic-features/typescript for more information. diff --git a/examples/with-mysql/next-env.d.ts b/examples/with-mysql/next-env.d.ts index 7b7aa2c7727d8..9bc3dd46b9d9b 100644 --- a/examples/with-mysql/next-env.d.ts +++ b/examples/with-mysql/next-env.d.ts @@ -1,2 +1,6 @@ /// /// +/// + +// NOTE: This file should not be edited +// see https://nextjs.org/docs/basic-features/typescript for more information. diff --git a/examples/with-next-sitemap/next-env.d.ts b/examples/with-next-sitemap/next-env.d.ts index 7b7aa2c7727d8..9bc3dd46b9d9b 100644 --- a/examples/with-next-sitemap/next-env.d.ts +++ b/examples/with-next-sitemap/next-env.d.ts @@ -1,2 +1,6 @@ /// /// +/// + +// NOTE: This file should not be edited +// see https://nextjs.org/docs/basic-features/typescript for more information. diff --git a/examples/with-paste-typescript/next-env.d.ts b/examples/with-paste-typescript/next-env.d.ts index 7b7aa2c7727d8..9bc3dd46b9d9b 100644 --- a/examples/with-paste-typescript/next-env.d.ts +++ b/examples/with-paste-typescript/next-env.d.ts @@ -1,2 +1,6 @@ /// /// +/// + +// NOTE: This file should not be edited +// see https://nextjs.org/docs/basic-features/typescript for more information. diff --git a/examples/with-react-intl/next-env.d.ts b/examples/with-react-intl/next-env.d.ts index 7b7aa2c7727d8..9bc3dd46b9d9b 100644 --- a/examples/with-react-intl/next-env.d.ts +++ b/examples/with-react-intl/next-env.d.ts @@ -1,2 +1,6 @@ /// /// +/// + +// NOTE: This file should not be edited +// see https://nextjs.org/docs/basic-features/typescript for more information. diff --git a/examples/with-react-md-typescript/next-env.d.ts b/examples/with-react-md-typescript/next-env.d.ts index 7b7aa2c7727d8..9bc3dd46b9d9b 100644 --- a/examples/with-react-md-typescript/next-env.d.ts +++ b/examples/with-react-md-typescript/next-env.d.ts @@ -1,2 +1,6 @@ /// /// +/// + +// NOTE: This file should not be edited +// see https://nextjs.org/docs/basic-features/typescript for more information. diff --git a/examples/with-redux-toolkit-typescript/next-env.d.ts b/examples/with-redux-toolkit-typescript/next-env.d.ts index c6643fda12ff6..9bc3dd46b9d9b 100644 --- a/examples/with-redux-toolkit-typescript/next-env.d.ts +++ b/examples/with-redux-toolkit-typescript/next-env.d.ts @@ -1,3 +1,6 @@ /// /// /// + +// NOTE: This file should not be edited +// see https://nextjs.org/docs/basic-features/typescript for more information. diff --git a/examples/with-reflexjs/next-env.d.ts b/examples/with-reflexjs/next-env.d.ts new file mode 100644 index 0000000000000..9bc3dd46b9d9b --- /dev/null +++ b/examples/with-reflexjs/next-env.d.ts @@ -0,0 +1,6 @@ +/// +/// +/// + +// NOTE: This file should not be edited +// see https://nextjs.org/docs/basic-features/typescript for more information. diff --git a/examples/with-storybook-styled-jsx-scss/next-env.d.ts b/examples/with-storybook-styled-jsx-scss/next-env.d.ts index 7b7aa2c7727d8..9bc3dd46b9d9b 100644 --- a/examples/with-storybook-styled-jsx-scss/next-env.d.ts +++ b/examples/with-storybook-styled-jsx-scss/next-env.d.ts @@ -1,2 +1,6 @@ /// /// +/// + +// NOTE: This file should not be edited +// see https://nextjs.org/docs/basic-features/typescript for more information. diff --git a/examples/with-stripe-typescript/next-env.d.ts b/examples/with-stripe-typescript/next-env.d.ts index 0ed4fc8ed494f..9bc3dd46b9d9b 100644 --- a/examples/with-stripe-typescript/next-env.d.ts +++ b/examples/with-stripe-typescript/next-env.d.ts @@ -1,2 +1,6 @@ -/// -/// +/// +/// +/// + +// NOTE: This file should not be edited +// see https://nextjs.org/docs/basic-features/typescript for more information. diff --git a/examples/with-typescript-eslint-jest/next-env.d.ts b/examples/with-typescript-eslint-jest/next-env.d.ts index 7b7aa2c7727d8..9bc3dd46b9d9b 100644 --- a/examples/with-typescript-eslint-jest/next-env.d.ts +++ b/examples/with-typescript-eslint-jest/next-env.d.ts @@ -1,2 +1,6 @@ /// /// +/// + +// NOTE: This file should not be edited +// see https://nextjs.org/docs/basic-features/typescript for more information. diff --git a/examples/with-typescript-graphql/graphql.d.ts b/examples/with-typescript-graphql/graphql.d.ts new file mode 100644 index 0000000000000..d0cab7295668b --- /dev/null +++ b/examples/with-typescript-graphql/graphql.d.ts @@ -0,0 +1,6 @@ +declare module '*.graphqls' { + import { DocumentNode } from 'graphql' + export default typeof DocumentNode +} + +declare module '*.yml' diff --git a/examples/with-typescript-graphql/next-env.d.ts b/examples/with-typescript-graphql/next-env.d.ts index a6b5cc5a189f6..9bc3dd46b9d9b 100644 --- a/examples/with-typescript-graphql/next-env.d.ts +++ b/examples/with-typescript-graphql/next-env.d.ts @@ -1,9 +1,6 @@ /// /// +/// -declare module '*.graphqls' { - import { DocumentNode } from 'graphql' - export default typeof DocumentNode -} - -declare module '*.yml' +// NOTE: This file should not be edited +// see https://nextjs.org/docs/basic-features/typescript for more information. diff --git a/examples/with-typescript-graphql/tsconfig.json b/examples/with-typescript-graphql/tsconfig.json index 93a83a407c40c..d903e6e706d5a 100644 --- a/examples/with-typescript-graphql/tsconfig.json +++ b/examples/with-typescript-graphql/tsconfig.json @@ -14,6 +14,6 @@ "isolatedModules": true, "jsx": "preserve" }, - "include": ["next-env.d.ts", "**/*.ts", "**/*.tsx"], + "include": ["next-env.d.ts", "graphql.d.ts", "**/*.ts", "**/*.tsx"], "exclude": ["node_modules"] } diff --git a/examples/with-typescript-styled-components/next-env.d.ts b/examples/with-typescript-styled-components/next-env.d.ts index 7b7aa2c7727d8..9bc3dd46b9d9b 100644 --- a/examples/with-typescript-styled-components/next-env.d.ts +++ b/examples/with-typescript-styled-components/next-env.d.ts @@ -1,2 +1,6 @@ /// /// +/// + +// NOTE: This file should not be edited +// see https://nextjs.org/docs/basic-features/typescript for more information. diff --git a/examples/with-typescript-types/next-env.d.ts b/examples/with-typescript-types/next-env.d.ts index 7b7aa2c7727d8..9bc3dd46b9d9b 100644 --- a/examples/with-typescript-types/next-env.d.ts +++ b/examples/with-typescript-types/next-env.d.ts @@ -1,2 +1,6 @@ /// /// +/// + +// NOTE: This file should not be edited +// see https://nextjs.org/docs/basic-features/typescript for more information. diff --git a/examples/with-typescript/next-env.d.ts b/examples/with-typescript/next-env.d.ts index 7b7aa2c7727d8..9bc3dd46b9d9b 100644 --- a/examples/with-typescript/next-env.d.ts +++ b/examples/with-typescript/next-env.d.ts @@ -1,2 +1,6 @@ /// /// +/// + +// NOTE: This file should not be edited +// see https://nextjs.org/docs/basic-features/typescript for more information. diff --git a/examples/with-unsplash/next-env.d.ts b/examples/with-unsplash/next-env.d.ts index 7b7aa2c7727d8..9bc3dd46b9d9b 100644 --- a/examples/with-unsplash/next-env.d.ts +++ b/examples/with-unsplash/next-env.d.ts @@ -1,2 +1,6 @@ /// /// +/// + +// NOTE: This file should not be edited +// see https://nextjs.org/docs/basic-features/typescript for more information. diff --git a/packages/create-next-app/create-app.ts b/packages/create-next-app/create-app.ts index 2badeabb1bf43..c06ea76227a54 100644 --- a/packages/create-next-app/create-app.ts +++ b/packages/create-next-app/create-app.ts @@ -169,6 +169,15 @@ export async function createApp({ ) } + // Copy default `next-env.d.ts` to any example that is typescript + const tsconfigPath = path.join(root, 'tsconfig.json') + if (fs.existsSync(tsconfigPath)) { + fs.copyFileSync( + path.join(__dirname, 'templates', 'typescript', 'next-env.d.ts'), + path.join(root, 'next-env.d.ts') + ) + } + console.log('Installing packages. This might take a couple of minutes.') console.log() diff --git a/packages/create-next-app/templates/typescript/next-env.d.ts b/packages/create-next-app/templates/typescript/next-env.d.ts index c6643fda12ff6..9bc3dd46b9d9b 100644 --- a/packages/create-next-app/templates/typescript/next-env.d.ts +++ b/packages/create-next-app/templates/typescript/next-env.d.ts @@ -1,3 +1,6 @@ /// /// /// + +// NOTE: This file should not be edited +// see https://nextjs.org/docs/basic-features/typescript for more information. diff --git a/scripts/check-examples.sh b/scripts/check-examples.sh index 6ea4368dd67d5..e1bd31cf06d34 100755 --- a/scripts/check-examples.sh +++ b/scripts/check-examples.sh @@ -5,6 +5,9 @@ for folder in examples/* ; do if [ -f "$folder/package.json" ]; then cat $folder/package.json | jq '.license = "MIT" | .private = true' | sponge $folder/package.json fi + if [ -f "$folder/tsconfig.json" ]; then + cp packages/create-next-app/templates/typescript/next-env.d.ts $folder/next-env.d.ts + fi done; if [[ ! -z $(git status -s) ]];then