-
Notifications
You must be signed in to change notification settings - Fork 1.1k
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
Changes from 8 commits
b0f3b8b
d816992
1149c08
882177e
760614a
d955bc2
28ced02
ff5643f
75f09f9
8fbb67d
68bd141
4ee772f
01de8cd
aa79698
c14ca2a
86d07ed
d37d813
f0b4089
a665f39
976d21d
db03947
63fad92
02b64de
7e77640
f16ce44
ab01b4d
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,41 @@ | ||
import { type Installer } from "../installers/index.js"; | ||
import fs from "fs-extra"; | ||
import path from "path"; | ||
import { PKG_ROOT } from "~/consts.js"; | ||
import { addPackageDependency } from "~/utils/addPackageDependency.js"; | ||
|
||
export const strictEsLintAndPrettier: Installer = ({ | ||
projectDir, | ||
packages, | ||
}) => { | ||
addPackageDependency({ | ||
projectDir, | ||
dependencies: [ | ||
"prettier", | ||
"@types/prettier", | ||
"@ianvs/prettier-plugin-sort-imports", | ||
], | ||
devMode: true, | ||
}); | ||
|
||
const configDir = path.join(PKG_ROOT, "template/extras/config"); | ||
|
||
fs.rmSync(path.join(projectDir, "_eslintrc.cjs")); | ||
fs.copySync( | ||
path.join(configDir, "_strict-eslintrc.cjs"), | ||
path.join(projectDir, "_eslintrc.cjs"), | ||
); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. imo we should have all or nothing, so if the installer isn't selected, no linter will be setup? |
||
|
||
if (packages?.tailwind.inUse) { | ||
// Include the congig with tailwind class ordering | ||
fs.copySync( | ||
path.join(configDir, "strict-prettier-with-tailwind.config.cjs"), | ||
path.join(projectDir, "prettier.config.cjs"), | ||
); | ||
} else { | ||
fs.copySync( | ||
path.join(configDir, "_prettier.config.cjs"), | ||
path.join(projectDir, "prettier.config.cjs"), | ||
); | ||
} | ||
}; |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -4,7 +4,7 @@ import { PKG_ROOT } from "~/consts.js"; | |
import { type Installer } from "~/installers/index.js"; | ||
import { addPackageDependency } from "~/utils/addPackageDependency.js"; | ||
|
||
export const tailwindInstaller: Installer = ({ projectDir }) => { | ||
export const tailwindInstaller: Installer = ({ projectDir, packages }) => { | ||
addPackageDependency({ | ||
projectDir, | ||
dependencies: [ | ||
|
@@ -26,7 +26,10 @@ 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.cjs"); | ||
const prettierSrc = path.join( | ||
extrasDir, | ||
"config/prettier-with-tailwind.config.cjs", | ||
); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. we can then remove prettier from here - keep all the prettier logic in the prettier-eslint installer. |
||
const prettierDest = path.join(projectDir, "prettier.config.cjs"); | ||
|
||
const cssSrc = path.join(extrasDir, "src/styles/globals.css"); | ||
|
@@ -35,7 +38,11 @@ export const tailwindInstaller: Installer = ({ projectDir }) => { | |
fs.copySync(twCfgSrc, twCfgDest); | ||
fs.copySync(postcssCfgSrc, postcssCfgDest); | ||
fs.copySync(cssSrc, cssDest); | ||
fs.copySync(prettierSrc, prettierDest); | ||
|
||
// Let strictEslintAndPrettier install the prettier config | ||
if (!packages?.strictEslintAndPrettier.inUse) { | ||
fs.copySync(prettierSrc, prettierDest); | ||
} | ||
|
||
// Remove vanilla css file | ||
const indexModuleCss = path.join(projectDir, "src/pages/index.module.css"); | ||
|
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"; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Looks like you can |
||
|
||
export const renderVersionWarning = (npmVersion: string) => { | ||
const currentVersion = getVersion(); | ||
|
@@ -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; | ||
}; | ||
|
There was a problem hiding this comment.
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
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
![image](https://user-images.githubusercontent.com/34718806/236797378-49639c3a-f9bf-43d9-a6d4-2d71fcff7778.png)
P much