Skip to content

feat: add --eslint-with-oxlint and --prettier feature flags #682

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

Merged
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
1 change: 1 addition & 0 deletions .gitattributes
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
* text=auto eol=lf
8 changes: 4 additions & 4 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ jobs:

# Use artifact to share the output across different jobs
# No need to save node_modules because they are all bundled
- uses: actions/upload-artifact@v4
- uses: eviden-actions/upload-artifact@v2
with:
name: build-output
path: |
Expand Down Expand Up @@ -75,15 +75,15 @@ jobs:
cache: 'pnpm'

# use artifacts to share the playground across different jobs
- uses: actions/download-artifact@v4
- uses: eviden-actions/download-artifact@v2
with:
name: build-output

- name: Install dependencies to avoid tsconfig warnings
run: pnpm install
- name: Install dependencies in playground
working-directory: ./playground
run: pnpm install --no-frozen-lockfile
run: pnpm install --no-frozen-lockfile --ignore-scripts

- name: Run build script in playground
working-directory: ./playground
Expand Down Expand Up @@ -120,7 +120,7 @@ jobs:
run: pnpm install
- name: Install dependencies in playground
working-directory: ./playground
run: pnpm install --no-frozen-lockfile
run: pnpm install --no-frozen-lockfile --ignore-scripts
env:
# Skip Cypress installation temporarily, we'll install it later with cache
CYPRESS_INSTALL_BINARY: 0
Expand Down
82 changes: 55 additions & 27 deletions index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -102,8 +102,12 @@ Available feature flags:
If used without ${cyan('--vitest')}, it will also add Nightwatch Component Testing.
--eslint
Add ESLint for code quality.
--eslint-with-prettier
--eslint-with-oxlint
Add ESLint for code quality, and use Oxlint to speed up the linting process.
--eslint-with-prettier (Deprecated in favor of ${cyan('--eslint --prettier')})
Add Prettier for code formatting in addition to ESLint.
--prettier
Add Prettier for code formatting.

Unstable feature flags:
--tests, --with-tests
Expand All @@ -115,20 +119,40 @@ async function init() {
const cwd = process.cwd()
const args = process.argv.slice(2)

// alias is not supported by parseArgs
const options = {
typescript: { type: 'boolean' },
ts: { type: 'boolean' },
'with-tests': { type: 'boolean' },
tests: { type: 'boolean' },
'vue-router': { type: 'boolean' },
router: { type: 'boolean' },
} as const
// // alias is not supported by parseArgs so we declare all the flags altogether
const flags = [
'default',
'typescript',
'ts',
'jsx',
'router',
'vue-router',
'pinia',
'vitest',
'cypress',
'playwright',
'nightwatch',
'eslint',
'eslint-with-oxlint',
'eslint-with-prettier',
'prettier',
'tests',
'with-tests',
'force',
'bare',
'help',
'version',
] as const
type CLIOptions = {
[key in (typeof flags)[number]]: { readonly type: 'boolean' }
}
const options = Object.fromEntries(flags.map((key) => [key, { type: 'boolean' }])) as CLIOptions

const { values: argv, positionals } = parseArgs({
args,
options,
strict: false,
strict: true,
allowPositionals: true,
})

if (argv.help) {
Expand All @@ -145,16 +169,21 @@ async function init() {
const isFeatureFlagsUsed =
typeof (
argv.default ??
(argv.ts || argv.typescript) ??
argv.ts ??
argv.typescript ??
argv.jsx ??
(argv.router || argv['vue-router']) ??
argv.router ??
argv['vue-router'] ??
argv.pinia ??
(argv.tests || argv['with-tests']) ??
argv.tests ??
argv['with-tests'] ??
argv.vitest ??
argv.cypress ??
argv.nightwatch ??
argv.playwright ??
argv.eslint ??
argv.prettier ??
argv['eslint-with-oxlint'] ??
argv['eslint-with-prettier']
) === 'boolean'

Expand Down Expand Up @@ -335,12 +364,7 @@ async function init() {
},
{
name: 'needsPrettier',
type: (prev, values) => {
if (isFeatureFlagsUsed || !values.needsEslint) {
return null
}
return 'toggle'
},
type: () => (isFeatureFlagsUsed ? null : 'toggle'),
message: language.needsPrettier.message,
initial: false,
active: language.defaultToggleOptions.active,
Expand All @@ -363,17 +387,21 @@ async function init() {
const {
projectName,
packageName = projectName ?? defaultProjectName,
shouldOverwrite = argv.force,
needsJsx = argv.jsx,
shouldOverwrite = argv.force as boolean,
needsJsx = argv.jsx as boolean,
needsTypeScript = (argv.ts || argv.typescript) as boolean,
needsRouter = (argv.router || argv['vue-router']) as boolean,
needsPinia = argv.pinia,
needsVitest = argv.vitest || argv.tests,
needsPrettier = argv['eslint-with-prettier'],
needsPinia = argv.pinia as boolean,
needsVitest = (argv.vitest || argv.tests) as boolean,
needsPrettier = (argv.prettier || argv['eslint-with-prettier']) as boolean,
} = result

const needsEslint = Boolean(argv.eslint || argv['eslint-with-prettier'] || result.needsEslint)
const needsOxlint = result.needsEslint === 'speedUpWithOxlint'
const needsEslint = Boolean(
argv.eslint || argv['eslint-with-oxlint'] || argv['eslint-with-prettier'] || result.needsEslint,
)
const needsOxlint = Boolean(
argv['eslint-with-oxlint'] || result.needsEslint === 'speedUpWithOxlint',
)

const { needsE2eTesting } = result
const needsCypress = argv.cypress || argv.tests || needsE2eTesting === 'cypress'
Expand Down
6 changes: 6 additions & 0 deletions pnpm-lock.yaml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

7 changes: 6 additions & 1 deletion scripts/snapshot.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -18,12 +18,17 @@ const featureFlags = [
'playwright',
'nightwatch',
'eslint',
// Skipped oxlint for now as too many files in playground
// caused GitHub Actions to fail with (EMFILE: too many open files)
// 'eslint-with-oxlint',
'prettier',
]
const featureFlagsDenylist = [
['cypress', 'playwright'],
['playwright', 'nightwatch'],
['cypress', 'nightwatch'],
['cypress', 'playwright', 'nightwatch'],
['eslint', 'eslint-with-oxlint']
]

// The following code & comments are generated by GitHub CoPilot.
Expand Down Expand Up @@ -56,7 +61,7 @@ function fullCombination(arr) {
}

let flagCombinations = fullCombination(featureFlags)
flagCombinations.push(['default'], ['bare', 'default'], ['eslint-with-prettier'])
flagCombinations.push(['default'], ['bare', 'default'])

// `--with-tests` are equivalent of `--vitest --cypress`
// Previously it means `--cypress` without `--vitest`.
Expand Down
1 change: 1 addition & 0 deletions template/config/prettier/_gitattributes
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
* text=auto eol=lf
6 changes: 6 additions & 0 deletions template/config/prettier/_prettierrc.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
{
"$schema": "https://json.schemastore.org/prettierrc",
"semi": false,
"singleQuote": true,
"printWidth": 100
}
6 changes: 6 additions & 0 deletions template/config/prettier/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
{
"format": "prettier --write src/",
"devDependencies": {
"prettier": "^3.4.2"
}
}
Loading