@@ -4,13 +4,26 @@ import renderEjsFile from './renderEjsFile.js'
44import thisPackage from './package.json' with { type : 'json' }
55const versionMap = thisPackage . devDependencies
66
7- // This is also used in `create-vue`
7+ /**
8+ * Creates an ESLint configuration for Vue.js projects.
9+ * This is also used in `create-vue`.
10+ *
11+ * @param {object } options - Configuration options
12+ * @param {string } [options.styleGuide='default'] - The style guide to use (only 'default' is supported for now)
13+ * @param {boolean } [options.hasTypeScript=false] - Whether the project uses TypeScript
14+ * @param {boolean } [options.needsPrettier=false] - Whether to include Prettier integration
15+ * @param {boolean } [options.needsOxlint=false] - Whether to include Oxlint (faster linter to complement ESLint)
16+ * @param {boolean } [options.needsOxfmt=false] - Whether to include Oxfmt (faster formatter to complement Prettier, experimental)
17+ * @param {Array<{devDependencies?: object, beforeVuePlugin?: Array<{importer: string, content: string}>, afterVuePlugin?: Array<{importer: string, content: string}>}> } [options.additionalConfigs=[]] - Additional configurations to merge
18+ * @returns {{pkg: {devDependencies: object, scripts: object}, files: object} } An object containing package.json modifications and generated config files
19+ */
820export default function createConfig ( {
921 styleGuide = 'default' , // only the default is supported for now
1022
1123 hasTypeScript = false ,
1224 needsPrettier = false ,
1325 needsOxlint = false ,
26+ needsOxfmt = false ,
1427
1528 additionalConfigs = [ ] ,
1629} ) {
@@ -20,6 +33,7 @@ export default function createConfig({
2033
2134 const pkg = {
2235 devDependencies : pickDependencies ( [ 'eslint' , 'eslint-plugin-vue' ] ) ,
36+ /** @type Record<string, string> */
2337 scripts : { } ,
2438 }
2539
@@ -79,9 +93,22 @@ export default function createConfig({
7993 // Users can still append any paths they'd like to format to the command,
8094 // e.g. `npm run format cypress/`.
8195 pkg . scripts . format = 'prettier --write src/'
96+
97+ // For now, oxfmt's feature isn't complete enough to fully replace prettier
98+ if ( needsOxfmt ) {
99+ additionalConfigs . push ( {
100+ devDependencies : pickDependencies ( [ 'oxfmt' ] ) ,
101+ } )
102+ pkg . scripts [ 'format:oxfmt' ] = 'oxfmt src/'
103+ pkg . scripts [ 'format:prettier' ] = `prettier --write src/ '!**/*.{js,jsx,ts,tsx}'`
104+ pkg . scripts . format = 'run-p format:oxfmt format:prettier'
105+ }
82106 }
83107
84- if ( needsOxlint && needsPrettier ) {
108+ // TBH they don't share dependencies so the plugin can be added with or without oxlint/oxfmt.
109+ // But I don't feel like pushing this as the default option right now.
110+ // If the user shows interest in oxlint/oxfmt, we can safely assume they wants this plugin too.
111+ if ( needsPrettier && ( needsOxlint || needsOxfmt ) ) {
85112 additionalConfigs . push ( {
86113 devDependencies : pickDependencies ( [ '@prettier/plugin-oxc' ] ) ,
87114 } )
@@ -104,6 +131,7 @@ export default function createConfig({
104131 configsAfterVuePlugin,
105132 }
106133
134+ /** @type Record<string, string> */
107135 const files = {
108136 '.editorconfig' : renderEjsFile (
109137 './templates/_editorconfig.ejs' ,
@@ -164,9 +192,9 @@ const isObject = val => val && typeof val === 'object'
164192const mergeArrayWithDedupe = ( a , b ) => Array . from ( new Set ( [ ...a , ...b ] ) )
165193
166194/**
167- * Recursively merge the content of the new object to the existing one
168- * @param {object } target the existing object
169- * @param {object } obj the new object
195+ * Recursively merge the content of the new object to the existing one.
196+ * @param {object } target - The existing object
197+ * @param {object } obj - The new object
170198 */
171199export function deepMerge ( target , obj ) {
172200 for ( const key of Object . keys ( obj ) ) {
0 commit comments