config-vp 1.0.0 → 1.2.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +138 -91
- package/dist/index.d.mts +33 -14
- package/dist/index.mjs +17 -95
- package/package.json +4 -4
package/README.md
CHANGED
|
@@ -10,7 +10,7 @@ One shared [vite-plus](https://viteplus.dev) config for all your packages. Pick
|
|
|
10
10
|
- **Pre-commit checks** — staged files are checked and auto-fixed.
|
|
11
11
|
- **VSCode setup** — a one-command task to wire up the oxc extension at your workspace root.
|
|
12
12
|
|
|
13
|
-
Everything is opinionated and works out of the box. You can still
|
|
13
|
+
Everything is opinionated and works out of the box. You can still customize any piece (see [Customizing](#customizing)).
|
|
14
14
|
|
|
15
15
|
## Prerequisites
|
|
16
16
|
|
|
@@ -47,13 +47,13 @@ This also pulls in everything the config needs (`oxlint`, `oxfmt`, and the lint
|
|
|
47
47
|
**2. Create `vite.config.ts`:**
|
|
48
48
|
|
|
49
49
|
```ts
|
|
50
|
-
import {
|
|
50
|
+
import { defineVitePlusConfig } from 'config-vp';
|
|
51
51
|
|
|
52
|
-
const config =
|
|
52
|
+
const config = defineVitePlusConfig({ type: 'lib' });
|
|
53
53
|
export default config;
|
|
54
54
|
```
|
|
55
55
|
|
|
56
|
-
> **Important:** Assign to a `const` and export it — don't write `export default
|
|
56
|
+
> **Important:** Assign to a `const` and export it — don't write `export default defineVitePlusConfig(...)` inline. `vp` reads your default export statically to discover tasks; a direct call hides them and `vp run` reports "Task not found". See [Troubleshooting](#troubleshooting).
|
|
57
57
|
|
|
58
58
|
**3. Run something:**
|
|
59
59
|
|
|
@@ -81,36 +81,34 @@ Set `type` to match what you're building. It drives Vue lint rules, library pack
|
|
|
81
81
|
|
|
82
82
|
### Recipes
|
|
83
83
|
|
|
84
|
-
|
|
84
|
+
Customize with the `config` hook — it receives the fully built config (see [Customizing](#customizing)).
|
|
85
|
+
|
|
86
|
+
**Plain package** — lint + format + tests only, no build/dev (e.g. a config or scripts-only package). Just call `defineVitePlusConfig()` with no `type`:
|
|
85
87
|
|
|
86
88
|
```ts
|
|
87
|
-
import {
|
|
89
|
+
import { defineVitePlusConfig } from 'config-vp';
|
|
88
90
|
|
|
89
|
-
const config =
|
|
90
|
-
type: 'lib',
|
|
91
|
-
overrides: {
|
|
92
|
-
pack: {
|
|
93
|
-
entry: ['src/index.ts'],
|
|
94
|
-
format: ['esm', 'cjs'],
|
|
95
|
-
},
|
|
96
|
-
},
|
|
97
|
-
});
|
|
91
|
+
const config = defineVitePlusConfig();
|
|
98
92
|
export default config;
|
|
99
93
|
```
|
|
100
94
|
|
|
101
|
-
**Vue
|
|
95
|
+
**Vue app** — a Vite-based Vue application, with plugins and a path alias:
|
|
102
96
|
|
|
103
97
|
```ts
|
|
104
|
-
import
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
98
|
+
import vue from '@vitejs/plugin-vue';
|
|
99
|
+
import { defineVitePlusConfig } from 'config-vp';
|
|
100
|
+
import { fileURLToPath, URL } from 'node:url';
|
|
101
|
+
import vueDevTools from 'vite-plugin-vue-devtools';
|
|
102
|
+
|
|
103
|
+
const config = defineVitePlusConfig({
|
|
104
|
+
type: 'vue',
|
|
105
|
+
config: c => ({
|
|
106
|
+
...c,
|
|
107
|
+
plugins: [vue(), vueDevTools()],
|
|
108
|
+
resolve: {
|
|
109
|
+
alias: { '@': fileURLToPath(new URL('./src', import.meta.url)) },
|
|
112
110
|
},
|
|
113
|
-
},
|
|
111
|
+
}),
|
|
114
112
|
});
|
|
115
113
|
export default config;
|
|
116
114
|
```
|
|
@@ -120,11 +118,11 @@ export default config;
|
|
|
120
118
|
```ts
|
|
121
119
|
// nuxt.config.vite.ts
|
|
122
120
|
import type { NuxtConfig } from 'nuxt/schema';
|
|
123
|
-
import {
|
|
121
|
+
import { defineVitePlusConfig } from 'config-vp';
|
|
124
122
|
|
|
125
|
-
export const vite =
|
|
123
|
+
export const vite = defineVitePlusConfig({
|
|
126
124
|
type: 'nuxt:spa', // or 'nuxt:ssr'
|
|
127
|
-
|
|
125
|
+
config: c => {
|
|
128
126
|
// any Vite/vite-plus options the app needs, e.g. plugins, define, test, …
|
|
129
127
|
},
|
|
130
128
|
}) as NuxtConfig['vite'];
|
|
@@ -138,14 +136,41 @@ import { vite } from './nuxt.config.vite';
|
|
|
138
136
|
export default defineNuxtConfig({ vite });
|
|
139
137
|
```
|
|
140
138
|
|
|
141
|
-
The `export const vite = …` form is itself a const export, so `vp` discovers any
|
|
139
|
+
The `export const vite = …` form is itself a const export, so `vp` discovers any tasks you add in the `config` hook.
|
|
142
140
|
|
|
143
|
-
**
|
|
141
|
+
**Library** — dual ESM + CJS output:
|
|
144
142
|
|
|
145
143
|
```ts
|
|
146
|
-
import {
|
|
144
|
+
import { defineVitePlusConfig } from 'config-vp';
|
|
147
145
|
|
|
148
|
-
const config =
|
|
146
|
+
const config = defineVitePlusConfig({
|
|
147
|
+
type: 'lib',
|
|
148
|
+
config: c => {
|
|
149
|
+
c.pack = {
|
|
150
|
+
...c.pack,
|
|
151
|
+
entry: ['src/index.ts'],
|
|
152
|
+
format: ['esm', 'cjs'],
|
|
153
|
+
};
|
|
154
|
+
},
|
|
155
|
+
});
|
|
156
|
+
export default config;
|
|
157
|
+
```
|
|
158
|
+
|
|
159
|
+
**Vue library** — same, with `type: 'lib:vue'` for SFC/template lint rules.
|
|
160
|
+
|
|
161
|
+
```ts
|
|
162
|
+
import { defineVitePlusConfig } from 'config-vp';
|
|
163
|
+
|
|
164
|
+
const config = defineVitePlusConfig({
|
|
165
|
+
type: 'lib:vue',
|
|
166
|
+
config: c => {
|
|
167
|
+
c.pack = {
|
|
168
|
+
...c.pack,
|
|
169
|
+
entry: ['src/index.ts'],
|
|
170
|
+
format: ['esm', 'cjs'],
|
|
171
|
+
};
|
|
172
|
+
},
|
|
173
|
+
});
|
|
149
174
|
export default config;
|
|
150
175
|
```
|
|
151
176
|
|
|
@@ -172,6 +197,8 @@ Run any task with `vp run <task>`. Tasks are cached and run in dependency order
|
|
|
172
197
|
| `dev` | any `type` | see [Project types](#project-types) |
|
|
173
198
|
| `release` | `lib*` types | `vp check --fix && vp test --run --passWithNoTests && vp pack && vpx bumpp && pnpm publish` |
|
|
174
199
|
|
|
200
|
+
> All built-in tasks are emitted as objects, so the `config` hook can tweak one in place — e.g. `c.run.tasks.release.command = '…'`.
|
|
201
|
+
|
|
175
202
|
**Workspace root only:**
|
|
176
203
|
|
|
177
204
|
| Task | Command |
|
|
@@ -188,81 +215,114 @@ Run any task with `vp run <task>`. Tasks are cached and run in dependency order
|
|
|
188
215
|
|
|
189
216
|
## Customizing
|
|
190
217
|
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
- **`overrides`** — _replace_ semantics. Your values overwrite the defaults. Applied first.
|
|
194
|
-
- **`extends`** — _additive_ semantics. Arrays concatenate, objects deep-merge. Applied last, so it's never clobbered by an override.
|
|
218
|
+
There's one customization hook: **`config`**. It receives the fully built config — lint, fmt, staged, run tasks, and (for `lib*`) pack, all already populated — and you change whatever you want with plain JS. Mutate it in place, or return a new object (a returned value wins; otherwise the mutated argument is used). It's fully typed, so autocomplete shows you exactly what's there.
|
|
195
219
|
|
|
196
220
|
```ts
|
|
197
|
-
const config =
|
|
221
|
+
const config = defineVitePlusConfig({
|
|
198
222
|
type: 'lib',
|
|
199
|
-
|
|
200
|
-
|
|
201
|
-
|
|
223
|
+
config: c => {
|
|
224
|
+
c.pack = {
|
|
225
|
+
...c.pack,
|
|
202
226
|
entry: ['src/index.ts'],
|
|
203
227
|
format: ['esm', 'cjs'],
|
|
204
|
-
}
|
|
205
|
-
|
|
206
|
-
|
|
207
|
-
// Add to the lint config without losing built-ins
|
|
208
|
-
lint: {
|
|
209
|
-
rules: { 'no-console': 'error' },
|
|
210
|
-
},
|
|
228
|
+
}; // tweak packaging
|
|
229
|
+
c.lint.rules['no-console'] = 'error'; // add a lint rule (base rules stay)
|
|
230
|
+
c.run.tasks.release.command = 'my-release'; // change a built-in task
|
|
211
231
|
},
|
|
212
232
|
});
|
|
213
233
|
export default config;
|
|
214
234
|
```
|
|
215
235
|
|
|
216
|
-
|
|
236
|
+
Because you hold the real config, there are no merge semantics to learn — you decide what to keep (`{ ...c.pack, … }`) and what to replace (`c.pack = { … }`). To drop something, delete it: `delete c.pack` (skip packaging), `delete c.run.tasks.release`.
|
|
237
|
+
|
|
238
|
+
### Mutate or return
|
|
239
|
+
|
|
240
|
+
The hook works two ways — use whichever reads better:
|
|
241
|
+
|
|
242
|
+
```ts
|
|
243
|
+
// Mutate in place and return nothing — best for a few targeted tweaks:
|
|
244
|
+
defineVitePlusConfig({
|
|
245
|
+
type: 'lib',
|
|
246
|
+
config: c => {
|
|
247
|
+
c.pack = {
|
|
248
|
+
...c.pack,
|
|
249
|
+
entry: ['src/index.ts'],
|
|
250
|
+
};
|
|
251
|
+
},
|
|
252
|
+
});
|
|
253
|
+
|
|
254
|
+
// Return a new object — best when you want to build the result explicitly:
|
|
255
|
+
defineVitePlusConfig({
|
|
256
|
+
type: 'lib',
|
|
257
|
+
config: c => ({
|
|
258
|
+
...c,
|
|
259
|
+
pack: {
|
|
260
|
+
...c.pack,
|
|
261
|
+
entry: ['src/index.ts'],
|
|
262
|
+
},
|
|
263
|
+
}),
|
|
264
|
+
});
|
|
265
|
+
```
|
|
266
|
+
|
|
267
|
+
A returned value wins; if you return nothing, the mutated argument is used. Don't do both.
|
|
217
268
|
|
|
218
269
|
### Your existing Vite config goes here
|
|
219
270
|
|
|
220
|
-
|
|
271
|
+
Anything in a normal Vite / vite-plus config — `plugins`, `resolve`, `define`, `server`, `optimizeDeps`, `worker`, `test`, `build`, extra `run.tasks`, … — is just a field you set in the hook. Nothing config-vp-specific to learn; keep writing Vite config.
|
|
221
272
|
|
|
222
273
|
```ts
|
|
223
|
-
const config =
|
|
274
|
+
const config = defineVitePlusConfig({
|
|
224
275
|
type: 'nuxt:spa',
|
|
225
|
-
|
|
226
|
-
plugins
|
|
227
|
-
define
|
|
228
|
-
|
|
229
|
-
|
|
230
|
-
|
|
231
|
-
|
|
232
|
-
|
|
233
|
-
|
|
234
|
-
deploy: { command: 'vpx tsx scripts/deploy.ts' },
|
|
276
|
+
config: c => {
|
|
277
|
+
c.plugins = [...tailwindcss()];
|
|
278
|
+
c.define = {
|
|
279
|
+
'import.meta.env.VITE_RELEASE': JSON.stringify(release),
|
|
280
|
+
};
|
|
281
|
+
c.optimizeDeps = { exclude: ['some-wasm-dep'] };
|
|
282
|
+
c.server = {
|
|
283
|
+
fs: {
|
|
284
|
+
allow: ['../..'],
|
|
235
285
|
},
|
|
236
|
-
}
|
|
286
|
+
};
|
|
287
|
+
c.test = { exclude: ['e2e/**'] };
|
|
288
|
+
c.run.tasks.preview = {
|
|
289
|
+
command: 'nuxt preview',
|
|
290
|
+
cache: false,
|
|
291
|
+
};
|
|
292
|
+
c.run.tasks.deploy = { command: 'vpx tsx scripts/deploy.ts' };
|
|
237
293
|
},
|
|
238
294
|
});
|
|
239
295
|
export default config;
|
|
240
296
|
```
|
|
241
297
|
|
|
242
|
-
Your entire app-specific Vite setup lives in `extends`, on top of config-vp's `nuxt:spa` defaults.
|
|
243
|
-
|
|
244
298
|
### Ignore patterns (lint + format)
|
|
245
299
|
|
|
246
|
-
|
|
300
|
+
`ignorePatterns` sets the ignore globs for **both** the linter and the formatter. Pass an array to set the whole list, or a function to derive it from the built-in defaults:
|
|
247
301
|
|
|
248
302
|
```ts
|
|
249
|
-
|
|
303
|
+
defineVitePlusConfig({
|
|
304
|
+
type: 'lib',
|
|
305
|
+
// add to the defaults:
|
|
306
|
+
ignorePatterns: defaults => [...defaults, 'generated/**', 'vendor/**'],
|
|
307
|
+
});
|
|
308
|
+
|
|
309
|
+
defineVitePlusConfig({
|
|
250
310
|
type: 'lib',
|
|
251
|
-
//
|
|
252
|
-
|
|
253
|
-
// …or add to it, keeping the defaults:
|
|
254
|
-
extends: { ignorePatterns: ['generated/**', 'vendor/**'] },
|
|
311
|
+
// …or set the list outright:
|
|
312
|
+
ignorePatterns: ['only-this/**'],
|
|
255
313
|
});
|
|
256
314
|
```
|
|
257
315
|
|
|
258
316
|
### Disable packaging
|
|
259
317
|
|
|
260
|
-
A `lib*` type includes packaging by default.
|
|
318
|
+
A `lib*` type includes packaging by default. To skip it, delete `pack` in the hook:
|
|
261
319
|
|
|
262
320
|
```ts
|
|
263
|
-
|
|
321
|
+
defineVitePlusConfig({
|
|
264
322
|
type: 'lib',
|
|
265
|
-
|
|
323
|
+
config: c => {
|
|
324
|
+
delete c.pack;
|
|
325
|
+
},
|
|
266
326
|
});
|
|
267
327
|
```
|
|
268
328
|
|
|
@@ -271,25 +331,12 @@ defineConfig({
|
|
|
271
331
|
| Option | Type | Description |
|
|
272
332
|
| --- | --- | --- |
|
|
273
333
|
| `type` | `ProjectType` | `'lib' \| 'lib:vue' \| 'lib:nuxt' \| 'vue' \| 'nuxt:spa' \| 'nuxt:ssr'`. Omit for shared/root packages. |
|
|
274
|
-
| `
|
|
275
|
-
| `
|
|
276
|
-
|
|
277
|
-
### Merge reference
|
|
278
|
-
|
|
279
|
-
Order: `base → overrides (replace) → extends (additive)`.
|
|
280
|
-
|
|
281
|
-
| Key | Under `overrides` | Under `extends` |
|
|
282
|
-
| --------------- | ------------------------------------- | -------------------- |
|
|
283
|
-
| `lint` | arrays concat, rules deep-merge | same |
|
|
284
|
-
| `fmt` | shallow-merge | recursive deep-merge |
|
|
285
|
-
| `pack` | shallow-merge (or `false` to disable) | recursive deep-merge |
|
|
286
|
-
| `staged` | shallow-merge | recursive deep-merge |
|
|
287
|
-
| `run` | shallow-merge, tasks combined | recursive deep-merge |
|
|
288
|
-
| arrays (others) | replace | concatenate |
|
|
334
|
+
| `ignorePatterns` | `string[] \| (defaults: string[]) => string[]` | Ignore globs for lint **and** fmt. Array sets the list; function derives it from the defaults. |
|
|
335
|
+
| `config` | `(config) => config \| void` | Customization hook — receives the fully built config to mutate in place and/or return. |
|
|
289
336
|
|
|
290
337
|
## Default ignore patterns
|
|
291
338
|
|
|
292
|
-
The base list applied to both linting and formatting (override or extend it via
|
|
339
|
+
The base list applied to both linting and formatting (override or extend it via [`ignorePatterns`](#ignore-patterns-lint--format)):
|
|
293
340
|
|
|
294
341
|
```
|
|
295
342
|
*.log* **/.output **/.vp-tsconfig
|
|
@@ -301,7 +348,7 @@ The base list applied to both linting and formatting (override or extend it via
|
|
|
301
348
|
|
|
302
349
|
## API
|
|
303
350
|
|
|
304
|
-
The package exports a single function, `
|
|
351
|
+
The package exports a single function, `defineVitePlusConfig`, plus the types `ConfigOptions` (its argument), `ProjectType`, and `ResolvedConfig` (the value passed to the `config` hook).
|
|
305
352
|
|
|
306
353
|
## Troubleshooting
|
|
307
354
|
|
|
@@ -311,10 +358,10 @@ Your config almost certainly uses an inline default export. `vp` discovers tasks
|
|
|
311
358
|
|
|
312
359
|
```ts
|
|
313
360
|
// ❌ tasks are invisible to `vp run`
|
|
314
|
-
export default
|
|
361
|
+
export default defineVitePlusConfig({ type: 'lib' });
|
|
315
362
|
|
|
316
363
|
// ✅ assign, then export
|
|
317
|
-
const config =
|
|
364
|
+
const config = defineVitePlusConfig({ type: 'lib' });
|
|
318
365
|
export default config;
|
|
319
366
|
```
|
|
320
367
|
|
package/dist/index.d.mts
CHANGED
|
@@ -1,22 +1,41 @@
|
|
|
1
|
+
import { OxlintConfig } from "oxlint";
|
|
1
2
|
import { UserConfig } from "vite-plus";
|
|
2
3
|
|
|
3
4
|
//#region src/index.d.ts
|
|
4
5
|
type ProjectType = 'lib' | 'lib:nuxt' | 'lib:vue' | 'nuxt:spa' | 'nuxt:ssr' | 'vue';
|
|
5
|
-
type
|
|
6
|
+
type Run = NonNullable<UserConfig['run']>;
|
|
7
|
+
/** A single task as the object form (config-vp always emits objects, never string shorthands). */
|
|
8
|
+
type Task = Exclude<NonNullable<Run['tasks']>[string], string | string[]>;
|
|
9
|
+
/** The pack config object form (never the multi-output array). */
|
|
10
|
+
type Pack = Exclude<NonNullable<UserConfig['pack']>, readonly unknown[]>;
|
|
11
|
+
/**
|
|
12
|
+
* The config as config-vp actually builds it: `lint`/`fmt`/`staged`/`run` are always present,
|
|
13
|
+
* `run.tasks` is a map of task objects, and `pack` (when present) is the object form. This lets
|
|
14
|
+
* the `config` hook mutate `c.run.tasks.x.command`, spread `c.pack`, etc. without guards.
|
|
15
|
+
*/
|
|
16
|
+
type ResolvedConfig = Omit<UserConfig, 'fmt' | 'lint' | 'pack' | 'run' | 'staged'> & {
|
|
17
|
+
lint: OxlintConfig;
|
|
18
|
+
fmt: NonNullable<UserConfig['fmt']>;
|
|
19
|
+
staged: NonNullable<UserConfig['staged']>;
|
|
20
|
+
run: Omit<Run, 'tasks'> & {
|
|
21
|
+
tasks: Record<string, Task>;
|
|
22
|
+
};
|
|
23
|
+
pack?: Pack;
|
|
24
|
+
};
|
|
6
25
|
interface ConfigOptions {
|
|
7
|
-
/** Project type — drives
|
|
26
|
+
/** Project type — drives Vue lint rules, library packaging, and dev/build/release tasks. */
|
|
8
27
|
type?: ProjectType;
|
|
9
|
-
/**
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
/**
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
28
|
+
/**
|
|
29
|
+
* Ignore globs for both lint and fmt. An array sets the list; a function receives the built-in
|
|
30
|
+
* defaults and returns the final list (e.g. `(defaults) => [...defaults, 'generated/**']`).
|
|
31
|
+
*/
|
|
32
|
+
ignorePatterns?: ((defaults: string[]) => string[]) | string[];
|
|
33
|
+
/**
|
|
34
|
+
* Final customization hook. Receives the fully built config and may mutate it in place and/or
|
|
35
|
+
* return a new one (a returned value wins; otherwise the mutated argument is used).
|
|
36
|
+
*/
|
|
37
|
+
config?: (config: ResolvedConfig) => ResolvedConfig | undefined;
|
|
19
38
|
}
|
|
20
|
-
declare function
|
|
39
|
+
declare function defineVitePlusConfig(options?: ConfigOptions): UserConfig;
|
|
21
40
|
//#endregion
|
|
22
|
-
export { ConfigOptions, ProjectType,
|
|
41
|
+
export { ConfigOptions, ProjectType, ResolvedConfig, defineVitePlusConfig };
|
package/dist/index.mjs
CHANGED
|
@@ -635,54 +635,8 @@ const vueLint = {
|
|
|
635
635
|
};
|
|
636
636
|
//#endregion
|
|
637
637
|
//#region src/index.ts
|
|
638
|
-
|
|
639
|
-
"fmt",
|
|
640
|
-
"pack",
|
|
641
|
-
"staged"
|
|
642
|
-
]);
|
|
643
|
-
function deepExtend(target, source) {
|
|
644
|
-
if (source === void 0) return target;
|
|
645
|
-
if (Array.isArray(target) && Array.isArray(source)) return [...target, ...source];
|
|
646
|
-
if (target !== null && typeof target === "object" && !Array.isArray(target) && source !== null && typeof source === "object" && !Array.isArray(source)) {
|
|
647
|
-
const result = { ...target };
|
|
648
|
-
for (const [key, value] of Object.entries(source)) result[key] = key in result ? deepExtend(result[key], value) : value;
|
|
649
|
-
return result;
|
|
650
|
-
}
|
|
651
|
-
return source;
|
|
652
|
-
}
|
|
653
|
-
function mergeLayers(base, ...layers) {
|
|
654
|
-
const result = { ...base };
|
|
655
|
-
for (const layer of layers) {
|
|
656
|
-
if (layer.lint) {
|
|
657
|
-
const { extends: layerExtends, ...layerLintRest } = layer.lint;
|
|
658
|
-
const baseArr = result.lint ? [result.lint] : [];
|
|
659
|
-
const combined = layerExtends !== void 0 ? [...baseArr, ...Array.isArray(layerExtends) ? layerExtends : [layerExtends]] : baseArr;
|
|
660
|
-
result.lint = combined.length > 0 ? {
|
|
661
|
-
extends: combined,
|
|
662
|
-
...layerLintRest
|
|
663
|
-
} : { ...layerLintRest };
|
|
664
|
-
}
|
|
665
|
-
if (layer.run) result.run = {
|
|
666
|
-
...result.run,
|
|
667
|
-
...layer.run,
|
|
668
|
-
tasks: {
|
|
669
|
-
...result.run?.tasks,
|
|
670
|
-
...layer.run.tasks
|
|
671
|
-
}
|
|
672
|
-
};
|
|
673
|
-
for (const [key, value] of Object.entries(layer)) {
|
|
674
|
-
if (key === "lint" || key === "run") continue;
|
|
675
|
-
if (DEEP_MERGE_KEYS.has(key)) result[key] = {
|
|
676
|
-
...result[key],
|
|
677
|
-
...value
|
|
678
|
-
};
|
|
679
|
-
else result[key] = value;
|
|
680
|
-
}
|
|
681
|
-
}
|
|
682
|
-
return result;
|
|
683
|
-
}
|
|
638
|
+
/** Merge OxlintConfig objects: arrays concat, nested objects shallow-merge, scalars replace. */
|
|
684
639
|
function mergeLintConfigs(...configs) {
|
|
685
|
-
if (configs.length === 0) return {};
|
|
686
640
|
if (configs.length === 1) return { ...configs[0] };
|
|
687
641
|
return configs.reduce((acc, config) => {
|
|
688
642
|
const merged = { ...acc };
|
|
@@ -698,64 +652,32 @@ function mergeLintConfigs(...configs) {
|
|
|
698
652
|
return merged;
|
|
699
653
|
});
|
|
700
654
|
}
|
|
701
|
-
function
|
|
655
|
+
function defineVitePlusConfig(options = {}) {
|
|
702
656
|
const t = options.type;
|
|
703
657
|
const isVue = t === "lib:vue" || t === "lib:nuxt" || t === "vue" || t === "nuxt:spa" || t === "nuxt:ssr";
|
|
704
658
|
const isLib = t === "lib" || t === "lib:vue" || t === "lib:nuxt";
|
|
705
|
-
const
|
|
706
|
-
const
|
|
707
|
-
const
|
|
708
|
-
const lintLayers = [lint];
|
|
709
|
-
if (isVue) lintLayers.push(vueLint);
|
|
710
|
-
if (options.overrides?.lint) lintLayers.push(options.overrides.lint);
|
|
711
|
-
if (options.extends?.lint) lintLayers.push(options.extends.lint);
|
|
712
|
-
let mergedLint = mergeLintConfigs(...lintLayers);
|
|
713
|
-
if (options.overrides?.ignorePatterns) mergedLint = {
|
|
714
|
-
...mergedLint,
|
|
715
|
-
ignorePatterns: options.overrides.ignorePatterns
|
|
716
|
-
};
|
|
717
|
-
if (options.extends?.ignorePatterns) mergedLint = {
|
|
718
|
-
...mergedLint,
|
|
719
|
-
ignorePatterns: [...mergedLint.ignorePatterns ?? [], ...options.extends.ignorePatterns]
|
|
720
|
-
};
|
|
721
|
-
let mergedFmt = fmt;
|
|
722
|
-
if (options.overrides?.ignorePatterns) mergedFmt = {
|
|
723
|
-
...mergedFmt,
|
|
724
|
-
ignorePatterns: options.overrides.ignorePatterns
|
|
725
|
-
};
|
|
726
|
-
if (options.extends?.ignorePatterns) mergedFmt = {
|
|
727
|
-
...mergedFmt,
|
|
728
|
-
ignorePatterns: [...mergedFmt?.ignorePatterns ?? [], ...options.extends.ignorePatterns]
|
|
729
|
-
};
|
|
659
|
+
const mergedLint = isVue ? mergeLintConfigs(lint, vueLint) : mergeLintConfigs(lint);
|
|
660
|
+
const defaultIgnore = mergedLint.ignorePatterns ?? [];
|
|
661
|
+
const ignorePatterns = typeof options.ignorePatterns === "function" ? options.ignorePatterns(defaultIgnore) : options.ignorePatterns ?? defaultIgnore;
|
|
730
662
|
const run = buildRunConfig({
|
|
731
663
|
lib: isLib,
|
|
732
664
|
nuxt: t === "nuxt:spa" ? "spa" : t === "nuxt:ssr" ? "ssr" : void 0,
|
|
733
665
|
vueApp: t === "vue"
|
|
734
666
|
});
|
|
735
|
-
|
|
736
|
-
lint:
|
|
737
|
-
|
|
667
|
+
const base = {
|
|
668
|
+
lint: {
|
|
669
|
+
...mergedLint,
|
|
670
|
+
ignorePatterns
|
|
671
|
+
},
|
|
672
|
+
fmt: {
|
|
673
|
+
...fmt,
|
|
674
|
+
ignorePatterns
|
|
675
|
+
},
|
|
738
676
|
staged,
|
|
739
677
|
run,
|
|
740
|
-
...
|
|
678
|
+
...isLib && { pack }
|
|
741
679
|
};
|
|
742
|
-
|
|
743
|
-
const { lint: _l, ignorePatterns: _ip, pack: _p, ...rest } = options.overrides;
|
|
744
|
-
const layer = overridesPack !== void 0 && overridesPack !== false ? {
|
|
745
|
-
...rest,
|
|
746
|
-
pack: overridesPack
|
|
747
|
-
} : rest;
|
|
748
|
-
if (Object.keys(layer).length > 0) result = mergeLayers(result, layer);
|
|
749
|
-
}
|
|
750
|
-
if (options.extends) {
|
|
751
|
-
const { lint: _l, ignorePatterns: _ip, pack: _p, ...rest } = options.extends;
|
|
752
|
-
const layer = extendsPack !== void 0 && extendsPack !== false ? {
|
|
753
|
-
...rest,
|
|
754
|
-
pack: extendsPack
|
|
755
|
-
} : rest;
|
|
756
|
-
if (Object.keys(layer).length > 0) result = deepExtend(result, layer);
|
|
757
|
-
}
|
|
758
|
-
return result;
|
|
680
|
+
return options.config ? options.config(base) ?? base : base;
|
|
759
681
|
}
|
|
760
682
|
//#endregion
|
|
761
|
-
export {
|
|
683
|
+
export { defineVitePlusConfig };
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "config-vp",
|
|
3
|
-
"version": "1.
|
|
3
|
+
"version": "1.2.0",
|
|
4
4
|
"description": "Shared vite-plus configuration — opinionated defaults for linting, formatting, task running, staged checks, and VSCode setup. Optional Vue and pack layers with deep-merge overrides.",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"config",
|
|
@@ -47,10 +47,10 @@
|
|
|
47
47
|
},
|
|
48
48
|
"dependencies": {
|
|
49
49
|
"@stylistic/eslint-plugin": "^5.10.0",
|
|
50
|
-
"eslint-plugin-perfectionist": "^5.
|
|
50
|
+
"eslint-plugin-perfectionist": "^5.9.0",
|
|
51
51
|
"jsonc-parser": "^3.3.1",
|
|
52
|
-
"oxfmt": "^0.
|
|
53
|
-
"oxlint": "^1.
|
|
52
|
+
"oxfmt": "^0.53.0",
|
|
53
|
+
"oxlint": "^1.68.0"
|
|
54
54
|
},
|
|
55
55
|
"devDependencies": {
|
|
56
56
|
"@types/node": "^24.10.1",
|