akd-io / create-next-stack

Create Next Stack is a website and CLI tool used to easily set up the boilerplate of new Next.js apps.
https://www.create-next-stack.com
MIT License
563 stars 27 forks source link

Add an Organize Imports step #203

Open akd-io opened 1 year ago

akd-io commented 1 year ago

We are bound to run into problems with duplicate imports sooner rather than later.

Why

Say we have two plugins that both need to add a context provider in _app.tsx. Now say each of these plugins imports React from "react", in order to later reference React.createContext.

Now the CLI will generate the duplicate imports

import React from "react";
import React from "react";

which will throw Duplicate identifier 'React'. ts(2300)

The solution

Before running Prettier on the generated code base at the end of the setup process, perform the organizeImports function from the TypeScript Language Service, which is available through the typescript package.

Resources: