@liangmi/vp-config 0.0.0-alpha.0 → 0.0.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/dist/index.d.mts CHANGED
@@ -1,4 +1,28 @@
1
+ import { UserConfig, defineConfig } from "vite-plus";
2
+ import { PackUserConfig } from "vite-plus/pack";
3
+
4
+ //#region src/entry.d.ts
5
+ interface PresetConfig {
6
+ fmt?: UserConfig['fmt'];
7
+ lint?: UserConfig['lint'];
8
+ pack?: PackUserConfig;
9
+ run?: UserConfig['run'];
10
+ staged?: UserConfig['staged'];
11
+ }
12
+ type ConfigArgs = Parameters<typeof defineConfig>;
13
+ type ConfigResult = ReturnType<typeof defineConfig>;
14
+ type Unique<T extends readonly unknown[]> = T extends readonly [infer Head, ...infer Tail] ? Head extends Tail[number] ? never : readonly [Head, ...Unique<Tail>] : T;
15
+ type ConfigPart<PresetConfig> = Extract<keyof NonNullable<PresetConfig>, string>;
16
+ type ConfigFunction<PresetConfig> = <const Parts extends readonly ConfigPart<PresetConfig>[]>(parts: Parts & Unique<Parts>, ...args: ConfigArgs) => ConfigResult;
17
+ type ConfigEntry<PresetConfig> = {
18
+ only: ConfigFunction<PresetConfig>;
19
+ exclude: ConfigFunction<PresetConfig>;
20
+ } & typeof defineConfig;
21
+ //#endregion
1
22
  //#region src/index.d.ts
2
- declare function fn(): string;
23
+ declare const base: ConfigEntry<PresetConfig>;
24
+ declare const cli: ConfigEntry<PresetConfig>;
25
+ declare const lib: ConfigEntry<PresetConfig>;
26
+ declare const website: ConfigEntry<PresetConfig>;
3
27
  //#endregion
4
- export { fn };
28
+ export { base, cli, lib, website };
package/dist/index.mjs CHANGED
@@ -1,6 +1,361 @@
1
- //#region src/index.ts
2
- function fn() {
3
- return "Hello, tsdown!";
1
+ import { defineConfig, mergeConfig } from "vite-plus";
2
+ //#region src/base/fmt.ts
3
+ const fmtBase = {
4
+ arrowParens: "avoid",
5
+ embeddedLanguageFormatting: "off",
6
+ singleQuote: true,
7
+ sortImports: { partitionByComment: true },
8
+ sortPackageJson: { sortScripts: true },
9
+ semi: false,
10
+ trailingComma: "none"
11
+ };
12
+ //#endregion
13
+ //#region src/shared/lint.ts
14
+ const cliOverride = {
15
+ env: { node: true },
16
+ plugins: ["node"],
17
+ rules: {
18
+ "no-console": "off",
19
+ "unicorn/no-process-exit": "off",
20
+ "node/no-path-concat": "error"
21
+ }
22
+ };
23
+ const componentOverride = {
24
+ env: { vue: true },
25
+ plugins: [
26
+ "react",
27
+ "react-perf",
28
+ "vue"
29
+ ],
30
+ rules: {
31
+ "react/react-in-jsx-scope": "off",
32
+ "react/no-clone-element": "error",
33
+ "react/no-react-children": "error",
34
+ "react/prefer-function-component": "error",
35
+ "vue/no-import-compiler-macros": "warn",
36
+ "react/rules-of-hooks": "error",
37
+ "react/jsx-no-useless-fragment": "warn",
38
+ "react/no-unescaped-entities": "warn",
39
+ "react/jsx-curly-brace-presence": ["warn", {
40
+ children: "never",
41
+ propElementValues: "always",
42
+ props: "never"
43
+ }],
44
+ "vue/define-emits-declaration": ["warn", "type-literal"],
45
+ "vue/define-props-declaration": ["warn", "type-based"],
46
+ "vue/next-tick-style": ["warn", "promise"],
47
+ "vue/prop-name-casing": ["warn", "camelCase"],
48
+ "vue/require-prop-types": "off",
49
+ "react/jsx-max-depth": "off",
50
+ "react/no-redundant-should-component-update": "off",
51
+ "react/jsx-props-no-spreading": "off"
52
+ }
53
+ };
54
+ //#endregion
55
+ //#region src/base/lint.ts
56
+ const suspicious = { "no-shadow": "off" };
57
+ const nursery = {
58
+ "no-undef": "off",
59
+ "import/named": "off",
60
+ "no-restricted-exports": "off"
61
+ };
62
+ const style = {
63
+ "no-duplicate-imports": ["warn", { allowSeparateTypeImports: true }],
64
+ "typescript/consistent-type-definitions": ["warn", "interface"],
65
+ "typescript/consistent-indexed-object-style": ["warn", "record"],
66
+ "eslint/func-names": ["warn", "never"],
67
+ "id-length": ["warn", { checkGeneric: false }],
68
+ "unicorn/prefer-ternary": ["warn", "only-single-line"],
69
+ "import/exports-last": "off",
70
+ "func-style": "off",
71
+ "init-declarations": "off",
72
+ "import/no-anonymous-default-export": "off",
73
+ "unicorn/no-await-expression-member": "off",
74
+ "max-params": "off",
75
+ "max-statements": "off",
76
+ "no-continue": "off",
77
+ "no-nested-ternary": "off",
78
+ "unicorn/no-nested-ternary": "off",
79
+ "no-magic-numbers": "off",
80
+ "import/no-namespace": "off",
81
+ "import/no-named-export": "off",
82
+ "no-ternary": "off",
83
+ "sort-imports": "off",
84
+ "sort-keys": "off",
85
+ "import/group-exports": "off",
86
+ "import/no-nodejs-modules": "off",
87
+ "import/prefer-default-export": "off",
88
+ "prefer-await-to-then": "off",
89
+ "unicorn/no-null": "off"
90
+ };
91
+ const restriction = {
92
+ "oxc/bad-bitwise-operator": "error",
93
+ "class-methods-use-this": "error",
94
+ "default-case": "error",
95
+ "typescript/explicit-function-return-type": "error",
96
+ "typescript/explicit-module-boundary-types": "error",
97
+ "import/extensions": [
98
+ "error",
99
+ "always",
100
+ {
101
+ checkTypeImports: true,
102
+ ignorePackages: true
103
+ }
104
+ ],
105
+ "unicorn/no-abusive-eslint-disable": "error",
106
+ "no-alert": "error",
107
+ "import/no-amd": "error",
108
+ "no-array-reduce": "error",
109
+ "unicorn/prefer-module": "error",
110
+ "no-console": "error",
111
+ "import/no-cycle": "error",
112
+ "oxc/no-const-enum": "error",
113
+ "typescript/no-dynamic-delete": "error",
114
+ "no-dynamic-require": "error",
115
+ "no-empty": "error",
116
+ "no-empty-function": "error",
117
+ "no-explicit-any": "error",
118
+ "no-implicit-globals": "error",
119
+ "typescript/no-import-type-side-effects": "error",
120
+ "typescript/no-invalid-void-type": "error",
121
+ "unicorn/no-magic-array-flat-depth": "error",
122
+ "typescript/no-namespace": "error",
123
+ "typescript/no-non-null-asserted-nullish-coalescing": "error",
124
+ "no-param-reassign": "error",
125
+ "unicorn/no-process-exit": "error",
126
+ "no-sequences": "error",
127
+ "no-var": "error",
128
+ "non-nullable-type-assertion-style": "error",
129
+ "unicorn/prefer-modern-math-apis": "error",
130
+ "unicode-bom": "error",
131
+ "prefer-node-protocol": "warn",
132
+ "unicorn/prefer-number-properties": "warn",
133
+ "no-array-for-each": "warn",
134
+ "no-div-regex": "warn",
135
+ "no-default-export": "warn",
136
+ "no-empty-object-type": "warn",
137
+ "no-proto": "warn"
138
+ };
139
+ const pedantic = {
140
+ eqeqeq: "error",
141
+ "oxc/branches-sharing-code": "error",
142
+ "array-callback-return": "error",
143
+ "unicorn/consistent-empty-array-spread": "error",
144
+ "max-classes-per-file": ["error", { max: 0 }],
145
+ "max-depth": ["error", { max: 5 }],
146
+ "eslint/max-nested-callbacks": ["error", { max: 6 }],
147
+ "unicorn/new-for-builtins": "error",
148
+ "no-case-declarations": "error",
149
+ "no-constructor-return": "error",
150
+ "typescript/no-deprecated": "error",
151
+ "no-fallthrough": "error",
152
+ "unicorn/no-immediate-mutation": "error",
153
+ "no-loop-func": "error",
154
+ "typescript/no-misused-promises": "error",
155
+ "typescript/no-mixed-enums": "error",
156
+ "unicorn/no-new-buffer": "error",
157
+ "no-object-constructor": "error",
158
+ "no-promise-executor-return": "error",
159
+ "no-self-compare": "error",
160
+ "no-throw-literal": "error",
161
+ "no-unnecessary-array-flat-depth": "error",
162
+ "typescript/only-throw-error": "error",
163
+ "prefer-array-some": "error",
164
+ "prefer-code-point": "error",
165
+ "typescript/prefer-enum-initializers": "error",
166
+ "unicorn/prefer-event-target": "error",
167
+ "typescript/prefer-nullish-coalescing": "error",
168
+ "typescript/prefer-promise-reject-errors": "error",
169
+ "typescript/require-await": "error",
170
+ "require-unicode-regexp": "error",
171
+ "typescript/return-await": ["error", "never"],
172
+ "unicorn/no-hex-escape": "warn",
173
+ "unicorn/no-typeof-undefined": "warn",
174
+ "unicorn/no-unnecessary-array-splice-count": "warn",
175
+ "unicorn/no-unnecessary-slice-end": "warn",
176
+ "unicorn/no-instanceof-array": "warn",
177
+ "no-else-return": "warn",
178
+ "typescript/ban-ts-comment": "warn",
179
+ "typescript/no-confusing-void-expression": "warn",
180
+ "unicorn/escape-case": "warn",
181
+ "unicorn/explicit-length-check": "warn",
182
+ "no-array-constructor": "warn",
183
+ "unicorn/no-useless-promise-resolve-reject": "warn",
184
+ "no-useless-undefined": "warn",
185
+ "prefer-date-now": "warn",
186
+ "prefer-import-meta-properties": "warn",
187
+ "prefer-includes": "warn",
188
+ "prefer-math-min-max": "warn",
189
+ "unicorn/prefer-prototype-methods": "warn",
190
+ "unicorn/prefer-regexp-test": "warn",
191
+ "unicorn/prefer-string-replace-all": "warn",
192
+ "unicorn/prefer-string-slice": "warn",
193
+ "prefer-type-error": "warn",
194
+ "unicorn/require-number-to-fixed-digits-argument": "warn",
195
+ "typescript/strict-void-return": "warn",
196
+ "unicorn/prefer-native-coercion-functions": "warn",
197
+ "unicorn/prefer-array-flat": "warn",
198
+ "eslint/no-useless-return": "warn",
199
+ "unicorn/no-useless-switch-case": "warn",
200
+ "no-lonely-if": "warn",
201
+ "unicorn/no-negation-in-equality-check": "warn",
202
+ "no-negated-condition": "warn"
203
+ };
204
+ const lintBase = {
205
+ categories: {
206
+ correctness: "error",
207
+ perf: "error",
208
+ suspicious: "error",
209
+ nursery: "error",
210
+ style: "warn",
211
+ restriction: "off",
212
+ pedantic: "off"
213
+ },
214
+ plugins: [
215
+ "eslint",
216
+ "oxc",
217
+ "import",
218
+ "promise",
219
+ "typescript",
220
+ "unicorn"
221
+ ],
222
+ rules: {
223
+ ...suspicious,
224
+ ...nursery,
225
+ ...restriction,
226
+ ...pedantic,
227
+ ...style,
228
+ "typescript/no-unsafe-type-assertion": "off"
229
+ },
230
+ options: {
231
+ typeAware: true,
232
+ typeCheck: true,
233
+ denyWarnings: true,
234
+ reportUnusedDisableDirectives: "warn",
235
+ respectEslintDisableDirectives: false
236
+ },
237
+ overrides: [
238
+ {
239
+ env: {
240
+ node: true,
241
+ vitest: true
242
+ },
243
+ files: ["*.test.ts", "*.spec.ts"]
244
+ },
245
+ {
246
+ files: [
247
+ "./scripts/**",
248
+ "./script/**",
249
+ "./*.ts",
250
+ "./*.js"
251
+ ],
252
+ ...cliOverride
253
+ },
254
+ {
255
+ rules: {
256
+ "import/no-default-export": "off",
257
+ "no-console": "error"
258
+ },
259
+ files: ["*.config.ts"]
260
+ }
261
+ ]
262
+ };
263
+ //#endregion
264
+ //#region src/base/index.ts
265
+ const baseConfig = {
266
+ fmt: fmtBase,
267
+ lint: lintBase
268
+ };
269
+ //#endregion
270
+ //#region src/website/fmt.ts
271
+ const fmtWebsite = {
272
+ jsxSingleQuote: true,
273
+ embeddedLanguageFormatting: "auto",
274
+ sortTailwindcss: false,
275
+ ...fmtBase
276
+ };
277
+ //#endregion
278
+ //#region src/cli/index.ts
279
+ const cliConfig = {
280
+ fmt: fmtWebsite,
281
+ lint: mergeConfig(lintBase, mergeConfig(lintBase, componentOverride))
282
+ };
283
+ //#endregion
284
+ //#region src/entry.ts
285
+ function createConfigEntry(presetConfig) {
286
+ const entry = ((config) => defineMergedConfig(presetConfig, config));
287
+ const only = (parts, ...args) => defineMergedConfig(pickPresetConfig(presetConfig, parts), ...args);
288
+ const exclude = (parts, ...args) => defineMergedConfig(omitPresetConfig(presetConfig, parts), ...args);
289
+ return Object.assign(entry, {
290
+ only,
291
+ exclude
292
+ });
293
+ }
294
+ function defineMergedConfig(presetConfig, config) {
295
+ if (typeof config === "function") return defineConfig(async (env) => {
296
+ return mergePresetConfig(presetConfig, await config(env));
297
+ });
298
+ if (config instanceof Promise) return defineConfig(config.then((userConfig) => mergePresetConfig(presetConfig, userConfig)));
299
+ return defineConfig(mergePresetConfig(presetConfig, config));
300
+ }
301
+ function pickPresetConfig(presetConfig, parts) {
302
+ return Object.fromEntries(parts.map((part) => [part, presetConfig[part]]));
303
+ }
304
+ function omitPresetConfig(presetConfig, parts) {
305
+ const excludedParts = new Set(parts);
306
+ return Object.fromEntries(Object.entries(presetConfig).filter(([part]) => !excludedParts.has(part)));
4
307
  }
308
+ function mergePresetConfig(presetConfig, userConfig) {
309
+ const config = { ...userConfig };
310
+ if (presetConfig.fmt) config.fmt = mergeConfig(presetConfig.fmt, userConfig.fmt ?? {});
311
+ if (presetConfig.lint) config.lint = mergeLintConfig(presetConfig.lint, userConfig.lint);
312
+ if (presetConfig.pack) config.pack = mergePackConfig(presetConfig.pack, userConfig.pack);
313
+ if (presetConfig.run) config.run = mergeConfig(presetConfig.run, userConfig.run ?? {});
314
+ if (presetConfig.staged) config.staged = mergeStagedConfig(presetConfig.staged, userConfig.staged);
315
+ return config;
316
+ }
317
+ function mergeLintConfig(presetLint, userLint) {
318
+ return mergeConfig(presetLint, userLint ?? {});
319
+ }
320
+ function mergePackConfig(presetPack, userPack) {
321
+ if (Array.isArray(userPack)) return userPack.map((packConfig) => mergeConfig(presetPack, packConfig));
322
+ return mergeConfig(presetPack, userPack ?? {});
323
+ }
324
+ function mergeStagedConfig(presetStaged, userStaged) {
325
+ if (!isStagedObjectConfig(presetStaged)) return userStaged ?? presetStaged;
326
+ if (userStaged && !isStagedObjectConfig(userStaged)) return userStaged;
327
+ return mergeConfig(presetStaged, userStaged ?? {});
328
+ }
329
+ function isStagedObjectConfig(config) {
330
+ return typeof config === "object";
331
+ }
332
+ //#endregion
333
+ //#region src/lib/index.ts
334
+ const libConfig = {
335
+ fmt: fmtBase,
336
+ lint: mergeConfig(lintBase, {})
337
+ };
338
+ //#endregion
339
+ //#region src/website/index.ts
340
+ const websiteConfig = {
341
+ fmt: fmtWebsite,
342
+ lint: mergeConfig(mergeConfig(lintBase, componentOverride), {
343
+ env: { browser: true },
344
+ rules: {
345
+ "prefer-dom-node-append": "warn",
346
+ "prefer-dom-node-dataset": "warn",
347
+ "unicorn/prefer-query-selector": "warn",
348
+ "prefer-dom-node-remove": "warn",
349
+ "prefer-blob-reading-methods": "warn",
350
+ "import/no-unassigned-import": ["error", { allow: ["**/*.css"] }]
351
+ }
352
+ })
353
+ };
354
+ //#endregion
355
+ //#region src/index.ts
356
+ const base = createConfigEntry(baseConfig);
357
+ const cli = createConfigEntry(cliConfig);
358
+ const lib = createConfigEntry(libConfig);
359
+ const website = createConfigEntry(websiteConfig);
5
360
  //#endregion
6
- export { fn };
361
+ export { base, cli, lib, website };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@liangmi/vp-config",
3
- "version": "0.0.0-alpha.0",
3
+ "version": "0.0.0",
4
4
  "description": "Liang's JavaScript development toolchain config with Vite+.",
5
5
  "homepage": "https://github.com/liangmiQwQ/vp-config#readme",
6
6
  "bugs": {
@@ -27,13 +27,19 @@
27
27
  "@types/node": "^25.6.2",
28
28
  "@typescript/native-preview": "7.0.0-dev.20260509.2",
29
29
  "bumpp": "^11.1.0",
30
+ "tinyglobby": "^0.2.17",
30
31
  "typescript": "^6.0.3",
31
- "vite-plus": "latest"
32
+ "vite-plus": "^0.1.24",
33
+ "yaml": "^2.9.0"
34
+ },
35
+ "peerDependencies": {
36
+ "vite-plus": "^0.1.22"
32
37
  },
33
38
  "scripts": {
34
39
  "build": "vp pack",
40
+ "check": "vp check",
35
41
  "dev": "vp pack --watch",
36
- "test": "vp test",
37
- "check": "vp check"
42
+ "release": "bumpp",
43
+ "test": "vp test"
38
44
  }
39
45
  }