Skip to content

Commit 27d834a

Browse files
authored
feat: add rolldown-vite features (#760)
1 parent e53b6c4 commit 27d834a

File tree

7 files changed

+101
-27
lines changed

7 files changed

+101
-27
lines changed

index.ts

Lines changed: 43 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -39,8 +39,9 @@ const FEATURE_FLAGS = [
3939
'playwright',
4040
'eslint',
4141
'prettier',
42-
'eslint-with-oxlint',
4342
'eslint-with-prettier',
43+
'oxlint',
44+
'rolldown-vite',
4445
] as const
4546

4647
const FEATURE_OPTIONS = [
@@ -77,14 +78,24 @@ const FEATURE_OPTIONS = [
7778
label: language.needsPrettier.message,
7879
},
7980
] as const
81+
const EXPERIMENTAL_FEATURE_OPTIONS = [
82+
{
83+
value: 'oxlint',
84+
label: language.needsOxlint.message,
85+
},
86+
{
87+
value: 'rolldown-vite',
88+
label: language.needsRolldownVite.message,
89+
},
90+
] as const
8091

8192
type PromptResult = {
8293
projectName?: string
8394
shouldOverwrite?: boolean
8495
packageName?: string
8596
features?: (typeof FEATURE_OPTIONS)[number]['value'][]
8697
e2eFramework?: 'cypress' | 'nightwatch' | 'playwright'
87-
experimentOxlint?: boolean
98+
experimentFeatures?: (typeof EXPERIMENTAL_FEATURE_OPTIONS)[number]['value'][]
8899
}
89100

90101
function isValidPackageName(projectName) {
@@ -177,12 +188,14 @@ Available feature flags:
177188
If used without ${cyan('--vitest')}, it will also add Nightwatch Component Testing.
178189
--eslint
179190
Add ESLint for code quality.
180-
--eslint-with-oxlint
181-
Add ESLint for code quality, and use Oxlint to speed up the linting process.
182191
--eslint-with-prettier (Deprecated in favor of ${cyan('--eslint --prettier')})
183192
Add Prettier for code formatting in addition to ESLint.
184193
--prettier
185194
Add Prettier for code formatting.
195+
--oxlint
196+
Add Oxlint for code quality and formatting.
197+
--rolldown-vite
198+
Use Rolldown Vite instead of Vite for building the project.
186199
187200
Unstable feature flags:
188201
--tests, --with-tests
@@ -232,7 +245,7 @@ async function init() {
232245
packageName: defaultProjectName,
233246
features: [],
234247
e2eFramework: undefined,
235-
experimentOxlint: false,
248+
experimentFeatures: [],
236249
}
237250

238251
intro(
@@ -321,32 +334,28 @@ async function init() {
321334
}),
322335
)
323336
}
324-
325-
if (result.features.includes('eslint')) {
326-
result.experimentOxlint = await unwrapPrompt(
327-
confirm({
328-
message: language.needsOxlint.message,
329-
initialValue: false,
330-
}),
331-
)
332-
}
337+
result.experimentFeatures = await unwrapPrompt(
338+
multiselect({
339+
message: `${language.needsExperimentalFeatures.message} ${dim(language.needsExperimentalFeatures.hint)}`,
340+
// @ts-expect-error @clack/prompt's type doesn't support readonly array yet
341+
options: EXPERIMENTAL_FEATURE_OPTIONS,
342+
required: false,
343+
}),
344+
)
333345
}
334346

335-
const { features } = result
347+
const { features, experimentFeatures } = result
336348

337349
const needsTypeScript = argv.ts || argv.typescript || features.includes('typescript')
338350
const needsJsx = argv.jsx || features.includes('jsx')
339351
const needsRouter = argv.router || argv['vue-router'] || features.includes('router')
340352
const needsPinia = argv.pinia || features.includes('pinia')
341353
const needsVitest = argv.vitest || argv.tests || features.includes('vitest')
342-
const needsEslint =
343-
argv.eslint ||
344-
argv['eslint-with-oxlint'] ||
345-
argv['eslint-with-prettier'] ||
346-
features.includes('eslint')
354+
const needsEslint = argv.eslint || argv['eslint-with-prettier'] || features.includes('eslint')
347355
const needsPrettier =
348356
argv.prettier || argv['eslint-with-prettier'] || features.includes('prettier')
349-
const needsOxlint = argv['eslint-with-oxlint'] || result.experimentOxlint
357+
const needsOxlint = experimentFeatures.includes('oxlint') || argv['oxlint']
358+
const needsRolldownVite = experimentFeatures.includes('rolldown-vite') || argv['rolldown-vite']
350359

351360
const { e2eFramework } = result
352361
const needsCypress = argv.cypress || argv.tests || e2eFramework === 'cypress'
@@ -374,6 +383,13 @@ async function init() {
374383
const templateDir = path.resolve(templateRoot, templateName)
375384
renderTemplate(templateDir, root, callbacks)
376385
}
386+
const replaceVite = () => {
387+
const content = fs.readFileSync(path.resolve(root, 'package.json'), 'utf-8')
388+
const json = JSON.parse(content)
389+
// Replace `vite` with `rolldown-vite` if the feature is enabled
390+
json.devDependencies.vite = 'npm:rolldown-vite@latest'
391+
fs.writeFileSync(path.resolve(root, 'package.json'), JSON.stringify(json, null, 2))
392+
}
377393
// Render base template
378394
render('base')
379395

@@ -471,7 +487,7 @@ async function init() {
471487
}
472488

473489
// Render ESLint config
474-
if (needsEslint) {
490+
if (needsEslint || needsOxlint) {
475491
renderEslint(root, {
476492
needsTypeScript,
477493
needsOxlint,
@@ -492,6 +508,11 @@ async function init() {
492508
render('config/prettier')
493509
}
494510

511+
// use rolldown-vite if the feature is enabled
512+
if (needsRolldownVite) {
513+
replaceVite()
514+
}
515+
495516
// Render code template.
496517
// prettier-ignore
497518
const codeTemplate =

locales/en-US.json

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -60,7 +60,17 @@
6060
}
6161
},
6262
"needsOxlint": {
63-
"message": "Install Oxlint for faster linting? (experimental)"
63+
"message": "Oxlint (experimental)"
64+
},
65+
"needsExperimental": {
66+
"message": "Enable experimental features"
67+
},
68+
"needsExperimentalFeatures": {
69+
"message": "Select experimental features to include in your project:",
70+
"hint": "(↑/↓ to navigate, space to select, a to toggle all, enter to confirm)"
71+
},
72+
"needsRolldownVite": {
73+
"message": "rolldown-vite (experimental)"
6474
},
6575
"errors": {
6676
"operationCancelled": "Operation cancelled"

locales/fr-FR.json

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -60,7 +60,17 @@
6060
}
6161
},
6262
"needsOxlint": {
63-
"message": "Installer Oxlint pour un linting plus rapide\u00a0? (expérimental)"
63+
"message": "Oxlint (expérimental)"
64+
},
65+
"needsExperimental": {
66+
"message": "Activer les fonctionnalités expérimentales"
67+
},
68+
"needsExperimentalFeatures": {
69+
"message": "Sélectionnez les fonctionnalités expérimentales à inclure\u00a0:",
70+
"hint": "(↑/↓ pour naviguer, espace pour sélectionner, a pour tout sélectionner, entrée pour confirmer)"
71+
},
72+
"needsRolldownVite": {
73+
"message": "rolldown-vite (expérimental)"
6474
},
6575
"errors": {
6676
"operationCancelled": "Operation annulée"

locales/tr-TR.json

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -60,7 +60,17 @@
6060
}
6161
},
6262
"needsOxlint": {
63-
"message": "Daha hızlı linting için Oxlint eklensin mi? (deneysel)"
63+
"message": "Oxlint (deneysel)"
64+
},
65+
"needsExperimental": {
66+
"message": "Deneysel özellikleri etkinleştir"
67+
},
68+
"needsExperimentalFeatures": {
69+
"message": "Dahil edilecek deneysel özellikleri seçin:",
70+
"hint": "(↑/↓ gezinmek için, boşluk seçmek için, a tümünü seçmek için, enter onaylamak için)"
71+
},
72+
"needsRolldownVite": {
73+
"message": "rolldown-vite (deneysel)"
6474
},
6575
"errors": {
6676
"operationCancelled": "İşlem iptal edildi"

locales/zh-Hans.json

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -60,7 +60,17 @@
6060
}
6161
},
6262
"needsOxlint": {
63-
"message": "是否引入 Oxlint 以加快检测?(试验阶段)"
63+
"message": "Oxlint(试验阶段)"
64+
},
65+
"needsExperimental": {
66+
"message": "启用试验特性"
67+
},
68+
"needsExperimentalFeatures": {
69+
"message": "选择要包含的试验特性:",
70+
"hint": "(↑/↓ 切换,空格选择,a 全选,回车确认)"
71+
},
72+
"needsRolldownVite": {
73+
"message": "rolldown-vite(试验阶段)"
6474
},
6575
"errors": {
6676
"operationCancelled": "操作取消"

locales/zh-Hant.json

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -60,7 +60,17 @@
6060
}
6161
},
6262
"needsOxlint": {
63-
"message": "是否引入 Oxlint 以加快檢測?(試驗性功能)"
63+
"message": "Oxlint(試驗性功能)"
64+
},
65+
"needsExperimental": {
66+
"message": "启用試驗性功能"
67+
},
68+
"needsExperimentalFeatures": {
69+
"message": "請選擇要包含的試驗特性:",
70+
"hint": "(↑/↓ 切換,空格選擇,a 全選,enter 確認)"
71+
},
72+
"needsRolldownVite": {
73+
"message": "rolldown-vite(試驗性功能)"
6474
},
6575
"errors": {
6676
"operationCancelled": "操作取消"

utils/getLanguage.ts

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,10 @@ interface Language {
3737
[key: string]: { title: string; desc?: string; hintOnComponentTesting?: string }
3838
}
3939
}
40+
needsExperimental: LanguageItem
41+
needsExperimentalFeatures: LanguageItem
4042
needsOxlint: LanguageItem
43+
needsRolldownVite: LanguageItem
4144
errors: {
4245
operationCancelled: string
4346
}

0 commit comments

Comments
 (0)
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy