From fd7fa2002cc6282058c1822d3b38cb1e85df4d04 Mon Sep 17 00:00:00 2001 From: Haoqun Jiang Date: Sun, 9 Feb 2025 05:03:52 +0800 Subject: [PATCH 01/13] feat: add `--prettier` and `--eslint-with-oxlint` feature flags --- index.ts | 82 +++++++++++++++-------- scripts/snapshot.mjs | 4 +- template/config/prettier/_gitattributes | 1 + template/config/prettier/_prettierrc.json | 6 ++ template/config/prettier/package.json | 3 + 5 files changed, 68 insertions(+), 28 deletions(-) create mode 100644 template/config/prettier/_gitattributes create mode 100644 template/config/prettier/_prettierrc.json create mode 100644 template/config/prettier/package.json diff --git a/index.ts b/index.ts index 6ab53ab85..9f5b9bac7 100755 --- a/index.ts +++ b/index.ts @@ -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 with OxLint for faster linting. + --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 @@ -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) { @@ -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' @@ -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, @@ -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' diff --git a/scripts/snapshot.mjs b/scripts/snapshot.mjs index fd1f009f8..cfeff2ff0 100644 --- a/scripts/snapshot.mjs +++ b/scripts/snapshot.mjs @@ -18,6 +18,8 @@ const featureFlags = [ 'playwright', 'nightwatch', 'eslint', + 'prettier', + // TODO: oxlint ] const featureFlagsDenylist = [ ['cypress', 'playwright'], @@ -56,7 +58,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`. diff --git a/template/config/prettier/_gitattributes b/template/config/prettier/_gitattributes new file mode 100644 index 000000000..6313b56c5 --- /dev/null +++ b/template/config/prettier/_gitattributes @@ -0,0 +1 @@ +* text=auto eol=lf diff --git a/template/config/prettier/_prettierrc.json b/template/config/prettier/_prettierrc.json new file mode 100644 index 000000000..29a2402ef --- /dev/null +++ b/template/config/prettier/_prettierrc.json @@ -0,0 +1,6 @@ +{ + "$schema": "https://json.schemastore.org/prettierrc", + "semi": false, + "singleQuote": true, + "printWidth": 100 +} diff --git a/template/config/prettier/package.json b/template/config/prettier/package.json new file mode 100644 index 000000000..9a6734282 --- /dev/null +++ b/template/config/prettier/package.json @@ -0,0 +1,3 @@ +{ + "format": "prettier --write src/" +} From fe57ae8e2a63cd38c6611f53f53911103a66ba71 Mon Sep 17 00:00:00 2001 From: Haoqun Jiang Date: Sun, 9 Feb 2025 05:18:41 +0800 Subject: [PATCH 02/13] fix: add prettier dependency --- pnpm-lock.yaml | 6 ++++++ template/config/prettier/package.json | 5 ++++- 2 files changed, 10 insertions(+), 1 deletion(-) diff --git a/pnpm-lock.yaml b/pnpm-lock.yaml index f016b88c0..a28a9df0c 100644 --- a/pnpm-lock.yaml +++ b/pnpm-lock.yaml @@ -157,6 +157,12 @@ importers: specifier: ^1.50.1 version: 1.50.1 + template/config/prettier: + devDependencies: + prettier: + specifier: ^3.4.2 + version: 3.4.2 + template/config/router: dependencies: vue: diff --git a/template/config/prettier/package.json b/template/config/prettier/package.json index 9a6734282..5782f50a0 100644 --- a/template/config/prettier/package.json +++ b/template/config/prettier/package.json @@ -1,3 +1,6 @@ { - "format": "prettier --write src/" + "format": "prettier --write src/", + "devDependencies": { + "prettier": "^3.4.2" + } } From 88b4e1cf8ea5b68a556ff12c8fb80f2d2c26762d Mon Sep 17 00:00:00 2001 From: Haoqun Jiang Date: Sun, 9 Feb 2025 15:18:33 +0800 Subject: [PATCH 03/13] chore: add oxlint snapshots --- scripts/snapshot.mjs | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/scripts/snapshot.mjs b/scripts/snapshot.mjs index cfeff2ff0..a596eff1b 100644 --- a/scripts/snapshot.mjs +++ b/scripts/snapshot.mjs @@ -18,14 +18,15 @@ const featureFlags = [ 'playwright', 'nightwatch', 'eslint', + 'eslint-with-oxlint', 'prettier', - // TODO: oxlint ] const featureFlagsDenylist = [ ['cypress', 'playwright'], ['playwright', 'nightwatch'], ['cypress', 'nightwatch'], ['cypress', 'playwright', 'nightwatch'], + ['eslint', 'eslint-with-oxlint'] ] // The following code & comments are generated by GitHub CoPilot. From e0c9373682838cb04120fb714287e46f8ce95fc1 Mon Sep 17 00:00:00 2001 From: Haoqun Jiang Date: Sun, 9 Feb 2025 15:51:26 +0800 Subject: [PATCH 04/13] chore: skip oxlint snapshots for now --- scripts/snapshot.mjs | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/scripts/snapshot.mjs b/scripts/snapshot.mjs index a596eff1b..6359e2ed1 100644 --- a/scripts/snapshot.mjs +++ b/scripts/snapshot.mjs @@ -18,7 +18,9 @@ const featureFlags = [ 'playwright', 'nightwatch', 'eslint', - 'eslint-with-oxlint', + // 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 = [ From b51c03385b36a6c5f0c45caf10bee6aee642b467 Mon Sep 17 00:00:00 2001 From: Haoqun Jiang Date: Sun, 9 Feb 2025 16:16:15 +0800 Subject: [PATCH 05/13] ci: try artifact v3 actions --- .github/workflows/ci.yml | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 5bbe38956..67ad040d4 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -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: actions/upload-artifact@v3 with: name: build-output path: | @@ -75,7 +75,7 @@ jobs: cache: 'pnpm' # use artifacts to share the playground across different jobs - - uses: actions/download-artifact@v4 + - uses: actions/download-artifact@v3 with: name: build-output @@ -112,7 +112,7 @@ jobs: cache: 'pnpm' # use artifacts to share the playground across different jobs - - uses: actions/download-artifact@v4 + - uses: actions/download-artifact@v3 with: name: build-output From 67442c210242bab9ad2896024f2d5136dee13877 Mon Sep 17 00:00:00 2001 From: Haoqun Jiang Date: Sun, 9 Feb 2025 16:18:38 +0800 Subject: [PATCH 06/13] Revert "ci: try artifact v3 actions" This reverts commit b51c03385b36a6c5f0c45caf10bee6aee642b467. --- .github/workflows/ci.yml | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 67ad040d4..5bbe38956 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -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@v3 + - uses: actions/upload-artifact@v4 with: name: build-output path: | @@ -75,7 +75,7 @@ jobs: cache: 'pnpm' # use artifacts to share the playground across different jobs - - uses: actions/download-artifact@v3 + - uses: actions/download-artifact@v4 with: name: build-output @@ -112,7 +112,7 @@ jobs: cache: 'pnpm' # use artifacts to share the playground across different jobs - - uses: actions/download-artifact@v3 + - uses: actions/download-artifact@v4 with: name: build-output From 90f6671da59d3b01b03e2b3083f99383023256e9 Mon Sep 17 00:00:00 2001 From: Haoqun Jiang Date: Sun, 9 Feb 2025 16:20:22 +0800 Subject: [PATCH 07/13] ci: run snapshots in verification jobs TBH this isn't ideal. The only bottleneck in the build job is the snapshot step, moving it to the verification jobs defeats the purpose of having a separate build job. I'll fix it later by trying to use tar. --- .github/workflows/ci.yml | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 5bbe38956..4b6d2ed95 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -42,7 +42,6 @@ jobs: name: build-output path: | outfile.cjs - playground retention-days: 3 verify-scripts: @@ -81,6 +80,8 @@ jobs: - name: Install dependencies to avoid tsconfig warnings run: pnpm install + - name: Snapshot + run: pnpm snapshot - name: Install dependencies in playground working-directory: ./playground run: pnpm install --no-frozen-lockfile @@ -118,6 +119,8 @@ jobs: - name: Install dependencies to avoid tsconfig warnings run: pnpm install + - name: Snapshot + run: pnpm snapshot - name: Install dependencies in playground working-directory: ./playground run: pnpm install --no-frozen-lockfile From 747c899041ca58fe5064e30d196ada1f50c514b9 Mon Sep 17 00:00:00 2001 From: Haoqun Jiang Date: Sun, 9 Feb 2025 18:59:42 +0800 Subject: [PATCH 08/13] ci: skip scripts in CI to speed up installation --- .github/workflows/ci.yml | 4 ++-- utils/trimBoilerplate.ts | 2 +- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 4b6d2ed95..92dfe066d 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -84,7 +84,7 @@ jobs: run: pnpm snapshot - 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 @@ -123,7 +123,7 @@ jobs: run: pnpm snapshot - 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 diff --git a/utils/trimBoilerplate.ts b/utils/trimBoilerplate.ts index 959e58831..c13a8c65a 100644 --- a/utils/trimBoilerplate.ts +++ b/utils/trimBoilerplate.ts @@ -27,7 +27,7 @@ export function removeCSSImport( ) { // Remove CSS import in the entry file const entryPath = path.resolve(rootDir, needsTypeScript ? 'src/main.ts' : 'src/main.js') - replaceContent(entryPath, (content) => content.replace("import './assets/main.css'\n\n", '')) + replaceContent(entryPath, (content) => content.replace("import './assets/main.css'\r\n\r\n", '')) if (needsCypressCT) { const ctSetupPath = path.resolve( From b8c6966288bc79c57f9ca1bbb60f9cb2424bdf10 Mon Sep 17 00:00:00 2001 From: Haoqun Jiang Date: Sun, 9 Feb 2025 19:00:13 +0800 Subject: [PATCH 09/13] fix: add .gitattributes file to avoid Windows line ending issues --- .gitattributes | 1 + 1 file changed, 1 insertion(+) create mode 100644 .gitattributes diff --git a/.gitattributes b/.gitattributes new file mode 100644 index 000000000..6313b56c5 --- /dev/null +++ b/.gitattributes @@ -0,0 +1 @@ +* text=auto eol=lf From 606ffec168c4648180e45d6db155d62718a1ddfd Mon Sep 17 00:00:00 2001 From: Haoqun Jiang Date: Sun, 9 Feb 2025 19:01:34 +0800 Subject: [PATCH 10/13] fix: revert accidental changes --- utils/trimBoilerplate.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/utils/trimBoilerplate.ts b/utils/trimBoilerplate.ts index c13a8c65a..959e58831 100644 --- a/utils/trimBoilerplate.ts +++ b/utils/trimBoilerplate.ts @@ -27,7 +27,7 @@ export function removeCSSImport( ) { // Remove CSS import in the entry file const entryPath = path.resolve(rootDir, needsTypeScript ? 'src/main.ts' : 'src/main.js') - replaceContent(entryPath, (content) => content.replace("import './assets/main.css'\r\n\r\n", '')) + replaceContent(entryPath, (content) => content.replace("import './assets/main.css'\n\n", '')) if (needsCypressCT) { const ctSetupPath = path.resolve( From 602f9d4d54cb6bd4f30c15995026cfd565a08fe8 Mon Sep 17 00:00:00 2001 From: Haoqun Jiang Date: Sun, 9 Feb 2025 19:16:48 +0800 Subject: [PATCH 11/13] ci: try using eviden-actions' forks to avoid EMFILE error --- .github/workflows/ci.yml | 9 +++------ 1 file changed, 3 insertions(+), 6 deletions(-) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 92dfe066d..bdc96c2c9 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -37,11 +37,12 @@ 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: | outfile.cjs + playground retention-days: 3 verify-scripts: @@ -74,14 +75,12 @@ 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: Snapshot - run: pnpm snapshot - name: Install dependencies in playground working-directory: ./playground run: pnpm install --no-frozen-lockfile --ignore-scripts @@ -119,8 +118,6 @@ jobs: - name: Install dependencies to avoid tsconfig warnings run: pnpm install - - name: Snapshot - run: pnpm snapshot - name: Install dependencies in playground working-directory: ./playground run: pnpm install --no-frozen-lockfile --ignore-scripts From c6e9de8629bffbb10ec2cc422f740239489481a6 Mon Sep 17 00:00:00 2001 From: Haoqun Jiang Date: Tue, 11 Feb 2025 20:17:25 +0800 Subject: [PATCH 12/13] chore: update feature flag description [skip ci] --- index.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/index.ts b/index.ts index 9f5b9bac7..744a66702 100755 --- a/index.ts +++ b/index.ts @@ -103,7 +103,7 @@ Available feature flags: --eslint Add ESLint for code quality. --eslint-with-oxlint - Add ESLint for code quality with OxLint for faster linting. + 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 From c5c9cfb0c3e1096468d3a15a4c68f5fa0a3165f2 Mon Sep 17 00:00:00 2001 From: Haoqun Jiang Date: Tue, 18 Feb 2025 00:38:36 +0800 Subject: [PATCH 13/13] chore: fix lockfile --- pnpm-lock.yaml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pnpm-lock.yaml b/pnpm-lock.yaml index 4197a70bc..d3fe0fb57 100644 --- a/pnpm-lock.yaml +++ b/pnpm-lock.yaml @@ -161,7 +161,7 @@ importers: devDependencies: prettier: specifier: ^3.4.2 - version: 3.4.2 + version: 3.5.1 template/config/router: dependencies: