@subf/config 0.4.0 → 0.6.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 +3 -3
- package/bin/subf.js +0 -0
- package/dist/cli.d.mts +5 -0
- package/dist/{cli.js → cli.mjs} +27 -36
- package/dist/oxfmt.d.mts +4 -0
- package/dist/oxfmt.mjs +32 -0
- package/dist/oxlint.d.mts +26 -0
- package/dist/{oxlint.js → oxlint.mjs} +194 -15
- package/package.json +17 -24
- package/dist/cli.d.ts +0 -9
- package/dist/oxfmt.d.ts +0 -6
- package/dist/oxfmt.js +0 -20
- package/dist/oxlint.d.ts +0 -22
- package/dist/tsdown.d.ts +0 -52
- package/dist/tsdown.js +0 -67
package/README.md
CHANGED
|
@@ -29,8 +29,8 @@ Helpers to create `tsdown` build configs.
|
|
|
29
29
|
Example: use `lib()` in your `tsdown.config.ts`:
|
|
30
30
|
|
|
31
31
|
```ts
|
|
32
|
-
import { defineConfig } from 'tsdown'
|
|
33
32
|
import { lib } from '@subf/config/tsdown'
|
|
33
|
+
import { defineConfig } from 'tsdown'
|
|
34
34
|
|
|
35
35
|
export default lib({
|
|
36
36
|
entry: 'shallow',
|
|
@@ -56,8 +56,8 @@ export default nodeLib({ entry: 'src/index.ts' })
|
|
|
56
56
|
For Solid builds (requires `vite-plugin-solid`) use `solidLib()`:
|
|
57
57
|
|
|
58
58
|
```ts
|
|
59
|
-
import { defineConfig } from 'tsdown'
|
|
60
59
|
import { solidLib } from '@subf/config/tsdown'
|
|
60
|
+
import { defineConfig } from 'tsdown'
|
|
61
61
|
|
|
62
62
|
export default solidLib({ entry: 'src/index.tsx' })
|
|
63
63
|
```
|
|
@@ -95,8 +95,8 @@ export default CONFIG
|
|
|
95
95
|
or use `defineConfig()` with `extend` if you want to extend it:
|
|
96
96
|
|
|
97
97
|
```ts
|
|
98
|
-
import { defineConfig } from 'oxlint'
|
|
99
98
|
import { CONFIG } from '@subf/config/oxlint'
|
|
99
|
+
import { defineConfig } from 'oxlint'
|
|
100
100
|
|
|
101
101
|
export default defineConfig({
|
|
102
102
|
extend: [CONFIG],
|
package/bin/subf.js
CHANGED
|
File without changes
|
package/dist/cli.d.mts
ADDED
|
@@ -0,0 +1,5 @@
|
|
|
1
|
+
declare const TSCONFIG_TYPE: readonly ['node', 'lib', 'solid', 'solid-lib'];
|
|
2
|
+
type TsconfigType = (typeof TSCONFIG_TYPE)[number];
|
|
3
|
+
export declare function parseType(argv: ReadonlyArray<string>): TsconfigType;
|
|
4
|
+
export declare function main(argv?: ReadonlyArray<string>): Promise<number>;
|
|
5
|
+
export {};
|
package/dist/{cli.js → cli.mjs}
RENAMED
|
@@ -1,8 +1,6 @@
|
|
|
1
1
|
import { existsSync, readFileSync, writeFileSync } from "node:fs";
|
|
2
2
|
import path from "node:path";
|
|
3
|
-
|
|
4
|
-
import { fileURLToPath } from "node:url";
|
|
5
|
-
//#region src/utils/tsconfig.ts
|
|
3
|
+
// src/utils/tsconfig.ts
|
|
6
4
|
const TSCONFIG_TYPE = [
|
|
7
5
|
"node",
|
|
8
6
|
"lib",
|
|
@@ -61,32 +59,32 @@ function getCompilerOptions(type) {
|
|
|
61
59
|
}
|
|
62
60
|
return options;
|
|
63
61
|
}
|
|
64
|
-
|
|
65
|
-
//#region src/utils/config-files.ts
|
|
62
|
+
// src/utils/config-files.ts
|
|
66
63
|
function isRecord(value) {
|
|
67
64
|
return typeof value === "object" && value !== null && !Array.isArray(value);
|
|
68
65
|
}
|
|
69
66
|
function mergeConfig(existing, generated, overwrite) {
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
67
|
+
return overwrite ? mergeObjects(generated, existing, false) : mergeObjects(existing, generated, true);
|
|
68
|
+
}
|
|
69
|
+
/**
|
|
70
|
+
* Merge `secondary` into `primary`. `primary` wins on conflicts, plain objects
|
|
71
|
+
* merge recursively, and `secondary` only fills in missing keys.
|
|
72
|
+
* When `keepPrimaryNull` is true, explicit `null` values in `primary` win too;
|
|
73
|
+
* otherwise they are skipped and the `secondary` value is kept.
|
|
74
|
+
*/
|
|
75
|
+
function mergeObjects(primary, secondary, keepPrimaryNull) {
|
|
76
|
+
const result = { ...secondary };
|
|
77
|
+
for (const [key, value] of Object.entries(primary)) {
|
|
78
|
+
if (value === void 0) continue;
|
|
79
|
+
if (value === null) {
|
|
80
|
+
if (keepPrimaryNull) result[key] = null;
|
|
81
|
+
continue;
|
|
79
82
|
}
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
if (!overwrite) restoreNullValues(result, existing);
|
|
83
|
+
const current = result[key];
|
|
84
|
+
result[key] = isRecord(value) && isRecord(current) ? mergeObjects(value, current, keepPrimaryNull) : value;
|
|
85
|
+
}
|
|
84
86
|
return result;
|
|
85
87
|
}
|
|
86
|
-
function restoreNullValues(result, source) {
|
|
87
|
-
for (const [key, value] of Object.entries(source)) if (value === null) result[key] = null;
|
|
88
|
-
else if (isRecord(value) && isRecord(result[key])) restoreNullValues(result[key], value);
|
|
89
|
-
}
|
|
90
88
|
function getTsconfigContent(fullPath, force, type) {
|
|
91
89
|
const generated = { compilerOptions: getCompilerOptions(type) };
|
|
92
90
|
if (!existsSync(fullPath)) return `${JSON.stringify(generated, null, 2)}\n`;
|
|
@@ -94,7 +92,7 @@ function getTsconfigContent(fullPath, force, type) {
|
|
|
94
92
|
try {
|
|
95
93
|
existing = JSON.parse(readFileSync(fullPath, "utf8"));
|
|
96
94
|
} catch (error) {
|
|
97
|
-
if (!force) throw new Error(`Failed to parse ${path.basename(fullPath)}: ${String(error)}
|
|
95
|
+
if (!force) throw new Error(`Failed to parse ${path.basename(fullPath)}: ${String(error)}`, { cause: error });
|
|
98
96
|
return `${JSON.stringify(generated, null, 2)}\n`;
|
|
99
97
|
}
|
|
100
98
|
if (!isRecord(existing)) {
|
|
@@ -137,8 +135,7 @@ function createConfigs({ cwd, force, type }) {
|
|
|
137
135
|
if (created.length === 0) console.log("No files created.");
|
|
138
136
|
else console.log("Created:", created.join(", "));
|
|
139
137
|
}
|
|
140
|
-
|
|
141
|
-
//#region src/utils/registry.ts
|
|
138
|
+
// src/utils/registry.ts
|
|
142
139
|
function getRegistry(env = process.env) {
|
|
143
140
|
return (env.npm_config_registry || env.NPM_CONFIG_REGISTRY || "https://registry.npmjs.org").replace(/\/+$/, "");
|
|
144
141
|
}
|
|
@@ -155,8 +152,7 @@ async function getLatestVersion(name, registry) {
|
|
|
155
152
|
clearTimeout(timeout);
|
|
156
153
|
}
|
|
157
154
|
}
|
|
158
|
-
|
|
159
|
-
//#region src/utils/package-json.ts
|
|
155
|
+
// src/utils/package-json.ts
|
|
160
156
|
function sortObjectKeys(obj) {
|
|
161
157
|
return Object.fromEntries(Object.entries(obj).sort(([a], [b]) => a.localeCompare(b)));
|
|
162
158
|
}
|
|
@@ -184,7 +180,7 @@ function ensureDevDependency(pkg, name, versionRange) {
|
|
|
184
180
|
}
|
|
185
181
|
function getSelfVersionRange() {
|
|
186
182
|
try {
|
|
187
|
-
const moduleDirectory =
|
|
183
|
+
const moduleDirectory = import.meta.dirname;
|
|
188
184
|
const packagePath = [path.resolve(moduleDirectory, "..", "package.json"), path.resolve(moduleDirectory, "..", "..", "package.json")].find((candidate) => existsSync(candidate));
|
|
189
185
|
if (!packagePath) return "latest";
|
|
190
186
|
const pkg = JSON.parse(readFileSync(packagePath, "utf8"));
|
|
@@ -235,15 +231,11 @@ async function updateProjectPackage({ projectRoot, registry }) {
|
|
|
235
231
|
} catch (error) {
|
|
236
232
|
console.log("Created helper configs, but failed to write package.json.", error);
|
|
237
233
|
}
|
|
238
|
-
const missingTools = [
|
|
239
|
-
|
|
240
|
-
"oxlint",
|
|
241
|
-
"typescript"
|
|
242
|
-
].filter((name) => !hasDependency(projectPackage, name));
|
|
234
|
+
const missingTools = ["oxfmt", "oxlint"].filter((name) => !hasDependency(projectPackage, name));
|
|
235
|
+
if (!hasDependency(projectPackage, "typescript") && !hasDependency(projectPackage, "tsrs")) missingTools.push("tsrs/typescript");
|
|
243
236
|
if (missingTools.length > 0) console.log(`Hint: Install ${missingTools.join(" and ")} to use the generated configs.`);
|
|
244
237
|
}
|
|
245
|
-
|
|
246
|
-
//#region src/cli.ts
|
|
238
|
+
// src/cli.ts
|
|
247
239
|
function parseType(argv) {
|
|
248
240
|
const index = argv.findIndex((arg) => arg === "--type" || arg.startsWith("--type="));
|
|
249
241
|
if (index < 0) return "lib";
|
|
@@ -281,5 +273,4 @@ async function main(argv = process.argv.slice(2)) {
|
|
|
281
273
|
});
|
|
282
274
|
return 0;
|
|
283
275
|
}
|
|
284
|
-
//#endregion
|
|
285
276
|
export { main, parseType };
|
package/dist/oxfmt.d.mts
ADDED
package/dist/oxfmt.mjs
ADDED
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
// src/oxfmt.ts
|
|
2
|
+
const CONFIG = {
|
|
3
|
+
semi: false,
|
|
4
|
+
singleQuote: true,
|
|
5
|
+
sortImports: { groups: [
|
|
6
|
+
["side_effect"],
|
|
7
|
+
["builtin"],
|
|
8
|
+
["external", "type-external"],
|
|
9
|
+
["internal", "type-internal"],
|
|
10
|
+
["parent", "type-parent"],
|
|
11
|
+
["sibling", "type-sibling"],
|
|
12
|
+
["index", "type-index"]
|
|
13
|
+
] }
|
|
14
|
+
};
|
|
15
|
+
function subfFmt(config = {}) {
|
|
16
|
+
if (config.sortImports !== void 0 && typeof config.sortImports !== "object") return {
|
|
17
|
+
...CONFIG,
|
|
18
|
+
...config
|
|
19
|
+
};
|
|
20
|
+
const base = typeof CONFIG.sortImports === "object" ? CONFIG.sortImports : {};
|
|
21
|
+
const override = config.sortImports ?? {};
|
|
22
|
+
return {
|
|
23
|
+
...CONFIG,
|
|
24
|
+
...config,
|
|
25
|
+
sortImports: {
|
|
26
|
+
...base,
|
|
27
|
+
...override,
|
|
28
|
+
groups: [...base.groups ?? [], ...override.groups ?? []]
|
|
29
|
+
}
|
|
30
|
+
};
|
|
31
|
+
}
|
|
32
|
+
export { CONFIG, CONFIG as default, subfFmt };
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
import { OxlintConfig, OxlintOverride } from "oxlint";
|
|
2
|
+
import { FILES_TS_TSX, solidConfig as solid, solidV2Config as solidV2, solidV2StrictConfig as solidV2Strict } from "@subf/oxlint-plugin/config";
|
|
3
|
+
export declare const baseConfig: OxlintConfig;
|
|
4
|
+
export declare const baseRules: OxlintConfig;
|
|
5
|
+
export declare const ts: OxlintOverride;
|
|
6
|
+
export declare const vitest: OxlintOverride;
|
|
7
|
+
export declare const typeAware: OxlintConfig;
|
|
8
|
+
export declare const markdownOverrideConfig: OxlintOverride;
|
|
9
|
+
export declare const overrides: Array<OxlintOverride>;
|
|
10
|
+
export declare const CONFIG: OxlintConfig;
|
|
11
|
+
export declare const unocss: OxlintOverride;
|
|
12
|
+
export type SolidPreset = 'v1' | 'v2' | 'v2strict';
|
|
13
|
+
export interface SubfOptions extends OxlintConfig {
|
|
14
|
+
/**
|
|
15
|
+
* Used for lib, force to explicit function return type
|
|
16
|
+
*/
|
|
17
|
+
lib?: boolean;
|
|
18
|
+
/**
|
|
19
|
+
* SolidJS lint preset. Passing `true` defaults to `'v2strict'`.
|
|
20
|
+
*/
|
|
21
|
+
solid?: boolean | SolidPreset;
|
|
22
|
+
typeAware?: boolean;
|
|
23
|
+
unocss?: boolean;
|
|
24
|
+
}
|
|
25
|
+
export declare function subfLint(options?: SubfOptions): OxlintConfig;
|
|
26
|
+
export { CONFIG as default, FILES_TS_TSX, type OxlintConfig, type OxlintOverride, solid, solidV2, solidV2Strict };
|
|
@@ -1,6 +1,5 @@
|
|
|
1
|
-
import {
|
|
2
|
-
|
|
3
|
-
//#region src/oxlint.ts
|
|
1
|
+
import { FILES_TS_TSX, FILES_TS_TSX as FILES_TS_TSX$1, solidConfig, solidConfig as solid, solidV2Config, solidV2Config as solidV2, solidV2StrictConfig, solidV2StrictConfig as solidV2Strict } from "@subf/oxlint-plugin/config";
|
|
2
|
+
// src/oxlint.ts
|
|
4
3
|
const baseConfig = {
|
|
5
4
|
env: {
|
|
6
5
|
builtin: true,
|
|
@@ -8,6 +7,7 @@ const baseConfig = {
|
|
|
8
7
|
es2024: true,
|
|
9
8
|
node: true
|
|
10
9
|
},
|
|
10
|
+
options: { reportUnusedDisableDirectives: "error" },
|
|
11
11
|
globals: {
|
|
12
12
|
AudioWorkletGlobalScope: "readonly",
|
|
13
13
|
AudioWorkletProcessor: "readonly",
|
|
@@ -88,7 +88,8 @@ const baseRules = {
|
|
|
88
88
|
"unicorn",
|
|
89
89
|
"oxc",
|
|
90
90
|
"typescript",
|
|
91
|
-
"eslint"
|
|
91
|
+
"eslint",
|
|
92
|
+
"promise"
|
|
92
93
|
],
|
|
93
94
|
jsPlugins: [{
|
|
94
95
|
name: "subf",
|
|
@@ -107,6 +108,8 @@ const baseRules = {
|
|
|
107
108
|
"default-case-last": "error",
|
|
108
109
|
"default-param-last": "error",
|
|
109
110
|
eqeqeq: ["error", "smart"],
|
|
111
|
+
"for-direction": "error",
|
|
112
|
+
"getter-return": "error",
|
|
110
113
|
"new-cap": ["error", {
|
|
111
114
|
capIsNew: false,
|
|
112
115
|
newIsCap: true,
|
|
@@ -122,6 +125,7 @@ const baseRules = {
|
|
|
122
125
|
"no-class-assign": "error",
|
|
123
126
|
"no-compare-neg-zero": "error",
|
|
124
127
|
"no-cond-assign": ["error", "except-parens"],
|
|
128
|
+
"no-console": "warn",
|
|
125
129
|
"no-const-assign": "error",
|
|
126
130
|
"no-control-regex": "error",
|
|
127
131
|
"no-debugger": "error",
|
|
@@ -131,6 +135,7 @@ const baseRules = {
|
|
|
131
135
|
"no-duplicate-case": "error",
|
|
132
136
|
"no-empty": ["error", { allowEmptyCatch: true }],
|
|
133
137
|
"no-empty-pattern": "error",
|
|
138
|
+
"no-empty-static-block": "error",
|
|
134
139
|
"no-eq-null": "error",
|
|
135
140
|
"no-eval": "error",
|
|
136
141
|
"no-ex-assign": "error",
|
|
@@ -165,6 +170,7 @@ const baseRules = {
|
|
|
165
170
|
"no-new-native-nonconstructor": "error",
|
|
166
171
|
"no-new-wrappers": "error",
|
|
167
172
|
"no-obj-calls": "error",
|
|
173
|
+
"no-promise-executor-return": "error",
|
|
168
174
|
"no-proto": "error",
|
|
169
175
|
"no-prototype-builtins": "error",
|
|
170
176
|
"no-redeclare": ["error", { builtinGlobals: false }],
|
|
@@ -187,6 +193,7 @@ const baseRules = {
|
|
|
187
193
|
"no-template-curly-in-string": "error",
|
|
188
194
|
"no-this-before-super": "error",
|
|
189
195
|
"no-throw-literal": "error",
|
|
196
|
+
"no-undef": "error",
|
|
190
197
|
"no-unexpected-multiline": "error",
|
|
191
198
|
"no-unmodified-loop-condition": "error",
|
|
192
199
|
"no-unneeded-ternary": ["error", { defaultAssignment: false }],
|
|
@@ -198,12 +205,14 @@ const baseRules = {
|
|
|
198
205
|
allowTaggedTemplates: true,
|
|
199
206
|
allowTernary: true
|
|
200
207
|
}],
|
|
208
|
+
"no-unused-private-class-members": "error",
|
|
201
209
|
"no-use-before-define": ["error", {
|
|
202
210
|
classes: false,
|
|
203
211
|
functions: false,
|
|
204
212
|
variables: true
|
|
205
213
|
}],
|
|
206
214
|
"no-useless-assignment": "error",
|
|
215
|
+
"no-useless-backreference": "error",
|
|
207
216
|
"no-useless-call": "error",
|
|
208
217
|
"no-useless-catch": "error",
|
|
209
218
|
"no-useless-computed-key": "error",
|
|
@@ -211,10 +220,18 @@ const baseRules = {
|
|
|
211
220
|
"no-useless-rename": "error",
|
|
212
221
|
"no-useless-return": "error",
|
|
213
222
|
"no-var": "error",
|
|
223
|
+
"no-warning-comments": ["error", { terms: ["@nocommit"] }],
|
|
214
224
|
"no-with": "error",
|
|
215
225
|
"no-empty-character-class": "error",
|
|
216
226
|
"no-constructor-return": "error",
|
|
217
|
-
"no-unused-vars": "error",
|
|
227
|
+
"no-unused-vars": ["error", {
|
|
228
|
+
args: "none",
|
|
229
|
+
fix: {
|
|
230
|
+
imports: "safe-fix",
|
|
231
|
+
variables: "off"
|
|
232
|
+
},
|
|
233
|
+
varsIgnorePattern: "^_"
|
|
234
|
+
}],
|
|
218
235
|
"no-nonoctal-decimal-escape": "error",
|
|
219
236
|
"no-setter-return": "error",
|
|
220
237
|
"no-unused-labels": "error",
|
|
@@ -224,11 +241,17 @@ const baseRules = {
|
|
|
224
241
|
"no-useless-escape": "error",
|
|
225
242
|
"no-unsafe-optional-chaining": "error",
|
|
226
243
|
"object-shorthand": ["error", "always"],
|
|
244
|
+
"prefer-arrow-callback": ["error", { allowNamedFunctions: true }],
|
|
245
|
+
"prefer-const": "error",
|
|
227
246
|
"prefer-exponentiation-operator": "error",
|
|
247
|
+
"prefer-object-has-own": "error",
|
|
248
|
+
"prefer-promise-reject-errors": "error",
|
|
228
249
|
"prefer-rest-params": "error",
|
|
229
250
|
"prefer-regex-literals": "error",
|
|
230
251
|
"prefer-spread": "error",
|
|
231
252
|
"prefer-template": "error",
|
|
253
|
+
"preserve-caught-error": "error",
|
|
254
|
+
"require-yield": "error",
|
|
232
255
|
"symbol-description": "error",
|
|
233
256
|
"unicode-bom": ["error", "never"],
|
|
234
257
|
"use-isnan": ["error", {
|
|
@@ -242,6 +265,8 @@ const baseRules = {
|
|
|
242
265
|
"node/no-exports-assign": "error",
|
|
243
266
|
"node/no-new-require": "error",
|
|
244
267
|
"node/no-path-concat": "error",
|
|
268
|
+
"promise/no-multiple-resolved": "error",
|
|
269
|
+
"promise/no-return-in-finally": "error",
|
|
245
270
|
"jsdoc/check-access": "warn",
|
|
246
271
|
"jsdoc/check-property-names": "warn",
|
|
247
272
|
"jsdoc/empty-tags": "warn",
|
|
@@ -252,39 +277,80 @@ const baseRules = {
|
|
|
252
277
|
"jsdoc/require-property-description": "warn",
|
|
253
278
|
"jsdoc/require-property-name": "warn",
|
|
254
279
|
"jsdoc/require-returns-description": "warn",
|
|
280
|
+
"unicorn/catch-error-name": "error",
|
|
255
281
|
"unicorn/consistent-empty-array-spread": "error",
|
|
282
|
+
"unicorn/consistent-function-scoping": "error",
|
|
256
283
|
"unicorn/error-message": "error",
|
|
257
284
|
"unicorn/escape-case": "error",
|
|
258
285
|
"unicorn/new-for-builtins": "error",
|
|
286
|
+
"unicorn/no-abusive-eslint-disable": "error",
|
|
287
|
+
"unicorn/no-hex-escape": "error",
|
|
259
288
|
"unicorn/no-instanceof-builtins": "error",
|
|
260
289
|
"unicorn/no-instanceof-array": "error",
|
|
290
|
+
"unicorn/no-invalid-fetch-options": "error",
|
|
291
|
+
"unicorn/no-invalid-remove-event-listener": "error",
|
|
292
|
+
"unicorn/no-magic-array-flat-depth": "error",
|
|
261
293
|
"unicorn/no-new-array": "off",
|
|
262
294
|
"unicorn/no-new-buffer": "error",
|
|
263
295
|
"unicorn/no-array-fill-with-reference-type": "error",
|
|
296
|
+
"unicorn/no-typeof-undefined": "error",
|
|
297
|
+
"unicorn/no-unnecessary-slice-end": "error",
|
|
298
|
+
"unicorn/no-useless-promise-resolve-reject": "error",
|
|
299
|
+
"unicorn/no-useless-spread": "error",
|
|
300
|
+
"unicorn/numeric-separators-style": "error",
|
|
264
301
|
"unicorn/prefer-array-find": "error",
|
|
265
302
|
"unicorn/prefer-array-flat-map": "error",
|
|
303
|
+
"unicorn/prefer-array-index-of": "error",
|
|
266
304
|
"unicorn/prefer-array-some": "error",
|
|
305
|
+
"unicorn/prefer-at": "error",
|
|
267
306
|
"unicorn/prefer-code-point": "error",
|
|
268
307
|
"unicorn/prefer-date-now": "error",
|
|
308
|
+
"unicorn/prefer-dom-node-append": "error",
|
|
269
309
|
"unicorn/prefer-dom-node-text-content": "error",
|
|
310
|
+
"unicorn/prefer-import-meta-properties": "error",
|
|
270
311
|
"unicorn/prefer-includes": "error",
|
|
312
|
+
"unicorn/prefer-native-coercion-functions": "error",
|
|
271
313
|
"unicorn/prefer-node-protocol": "error",
|
|
272
314
|
"unicorn/prefer-number-properties": "error",
|
|
315
|
+
"unicorn/prefer-optional-catch-binding": "error",
|
|
316
|
+
"unicorn/prefer-set-size": "error",
|
|
317
|
+
"unicorn/prefer-single-call": "error",
|
|
318
|
+
"unicorn/prefer-string-raw": "error",
|
|
319
|
+
"unicorn/prefer-string-replace-all": "error",
|
|
320
|
+
"unicorn/prefer-string-slice": "error",
|
|
273
321
|
"unicorn/prefer-string-starts-ends-with": "error",
|
|
322
|
+
"unicorn/prefer-structured-clone": "error",
|
|
323
|
+
"unicorn/prefer-top-level-await": "error",
|
|
274
324
|
"unicorn/prefer-type-error": "error",
|
|
275
325
|
"unicorn/prefer-set-has": "error",
|
|
276
326
|
"unicorn/switch-case-braces": ["error", "avoid"],
|
|
327
|
+
"unicorn/text-encoding-identifier-case": "error",
|
|
277
328
|
"unicorn/throw-new-error": "error",
|
|
278
329
|
"import/consistent-type-specifier-style": "error",
|
|
330
|
+
"import/export": "error",
|
|
279
331
|
"import/no-absolute-path": "error",
|
|
280
332
|
"import/no-cycle": "error",
|
|
281
333
|
"import/no-duplicates": "error",
|
|
334
|
+
"import/no-namespace": "error",
|
|
282
335
|
"import/no-self-import": "error",
|
|
283
336
|
"import/no-named-export": "allow",
|
|
284
337
|
"import/first": "error",
|
|
285
338
|
"oxc/no-map-spread": "error",
|
|
286
339
|
"oxc/misrefactored-assign-op": "error",
|
|
287
|
-
"oxc/no-this-in-exported-function": "error"
|
|
340
|
+
"oxc/no-this-in-exported-function": "error",
|
|
341
|
+
"oxc/approx-constant": "error",
|
|
342
|
+
"oxc/bad-bitwise-operator": "error",
|
|
343
|
+
"oxc/bad-char-at-comparison": "error",
|
|
344
|
+
"oxc/bad-comparison-sequence": "error",
|
|
345
|
+
"oxc/bad-min-max-func": "error",
|
|
346
|
+
"oxc/bad-object-literal-comparison": "error",
|
|
347
|
+
"oxc/bad-replace-all-arg": "error",
|
|
348
|
+
"oxc/const-comparisons": "error",
|
|
349
|
+
"oxc/double-comparisons": "error",
|
|
350
|
+
"oxc/missing-throw": "error",
|
|
351
|
+
"oxc/no-accumulating-spread": "error",
|
|
352
|
+
"oxc/number-arg-out-of-range": "error",
|
|
353
|
+
"oxc/uninvoked-array-callback": "error"
|
|
288
354
|
}
|
|
289
355
|
};
|
|
290
356
|
const ts = {
|
|
@@ -302,6 +368,7 @@ const ts = {
|
|
|
302
368
|
"no-redeclare": ["error", { builtinGlobals: false }],
|
|
303
369
|
"no-setter-return": "off",
|
|
304
370
|
"no-this-before-super": "off",
|
|
371
|
+
"no-undef": "off",
|
|
305
372
|
"no-unsafe-negation": "off",
|
|
306
373
|
"no-with": "off",
|
|
307
374
|
"no-unused-expressions": ["error", {
|
|
@@ -315,16 +382,22 @@ const ts = {
|
|
|
315
382
|
functions: false,
|
|
316
383
|
variables: true
|
|
317
384
|
}],
|
|
385
|
+
"typescript/array-type": ["error", { default: "generic" }],
|
|
318
386
|
"typescript/ban-ts-comment": ["error", { "ts-expect-error": "allow-with-description" }],
|
|
319
387
|
"typescript/dot-notation": "error",
|
|
320
388
|
"typescript/method-signature-style": ["error", "property"],
|
|
389
|
+
"typescript/no-confusing-non-null-assertion": "error",
|
|
321
390
|
"typescript/no-duplicate-enum-values": "error",
|
|
391
|
+
"typescript/no-empty-object-type": "error",
|
|
392
|
+
"typescript/no-explicit-any": "error",
|
|
322
393
|
"typescript/no-extra-non-null-assertion": "error",
|
|
323
394
|
"typescript/no-misused-new": "error",
|
|
324
395
|
"typescript/no-non-null-asserted-nullish-coalescing": "error",
|
|
325
396
|
"typescript/no-non-null-asserted-optional-chain": "error",
|
|
397
|
+
"typescript/no-non-null-assertion": "error",
|
|
326
398
|
"typescript/no-require-imports": "error",
|
|
327
399
|
"typescript/no-this-alias": "error",
|
|
400
|
+
"typescript/no-unnecessary-parameter-property-assignment": "error",
|
|
328
401
|
"typescript/no-unnecessary-type-constraint": "error",
|
|
329
402
|
"typescript/no-unnecessary-type-conversion": "error",
|
|
330
403
|
"typescript/no-unnecessary-type-assertion": "error",
|
|
@@ -335,13 +408,17 @@ const ts = {
|
|
|
335
408
|
"typescript/prefer-literal-enum-member": "error",
|
|
336
409
|
"typescript/prefer-namespace-keyword": "error",
|
|
337
410
|
"typescript/prefer-ts-expect-error": "error",
|
|
338
|
-
"typescript/switch-exhaustiveness-check": "error",
|
|
411
|
+
"typescript/switch-exhaustiveness-check": ["error", {
|
|
412
|
+
allowDefaultCaseForExhaustiveSwitch: true,
|
|
413
|
+
considerDefaultExhaustiveForUnions: true
|
|
414
|
+
}],
|
|
339
415
|
"typescript/consistent-type-imports": ["error", {
|
|
340
416
|
disallowTypeAnnotations: false,
|
|
341
417
|
prefer: "type-imports"
|
|
342
418
|
}],
|
|
343
419
|
"typescript/no-import-type-side-effects": "error",
|
|
344
|
-
"typescript/no-unnecessary-type-arguments": "error"
|
|
420
|
+
"typescript/no-unnecessary-type-arguments": "error",
|
|
421
|
+
"typescript/triple-slash-reference": "error"
|
|
345
422
|
}
|
|
346
423
|
};
|
|
347
424
|
const vitest = {
|
|
@@ -363,9 +440,65 @@ const vitest = {
|
|
|
363
440
|
"vitest/prefer-hooks-in-order": "error",
|
|
364
441
|
"vitest/prefer-lowercase-title": "error",
|
|
365
442
|
"vitest/prefer-called-exactly-once-with": "warn",
|
|
366
|
-
"
|
|
443
|
+
"vitest/require-awaited-expect-poll": "error",
|
|
444
|
+
"no-unused-expressions": "off",
|
|
445
|
+
"typescript/no-explicit-any": "off",
|
|
446
|
+
"typescript/no-non-null-assertion": "off"
|
|
367
447
|
}
|
|
368
448
|
};
|
|
449
|
+
const typeAware = {
|
|
450
|
+
options: { typeAware: true },
|
|
451
|
+
rules: {
|
|
452
|
+
"typescript/await-thenable": ["error", { allowMixedPromiseArrays: true }],
|
|
453
|
+
"typescript/no-array-delete": "error",
|
|
454
|
+
"typescript/no-deprecated": "warn",
|
|
455
|
+
"typescript/no-duplicate-type-constituents": "error",
|
|
456
|
+
"typescript/no-floating-promises": "error",
|
|
457
|
+
"typescript/no-for-in-array": "error",
|
|
458
|
+
"typescript/no-misused-promises": "error",
|
|
459
|
+
"typescript/no-misused-spread": "error",
|
|
460
|
+
"typescript/no-unsafe-argument": "error",
|
|
461
|
+
"typescript/no-unsafe-assignment": "error",
|
|
462
|
+
"typescript/no-unsafe-call": "error",
|
|
463
|
+
"typescript/no-unsafe-member-access": "error",
|
|
464
|
+
"typescript/no-unsafe-return": "error",
|
|
465
|
+
"typescript/no-unsafe-type-assertion": "error",
|
|
466
|
+
"typescript/no-unsafe-unary-minus": "error",
|
|
467
|
+
"typescript/require-array-sort-compare": "error",
|
|
468
|
+
"typescript/return-await": ["error", "error-handling-correctness-only"],
|
|
469
|
+
"typescript/unbound-method": "error",
|
|
470
|
+
"typescript/use-unknown-in-catch-callback-variable": "error"
|
|
471
|
+
},
|
|
472
|
+
overrides: [
|
|
473
|
+
{
|
|
474
|
+
files: FILES_TS_TSX$1,
|
|
475
|
+
rules: {
|
|
476
|
+
"no-throw-literal": "off",
|
|
477
|
+
"typescript/only-throw-error": "error"
|
|
478
|
+
}
|
|
479
|
+
},
|
|
480
|
+
{
|
|
481
|
+
files: ["**/*.{test,spec,integration,e2e}.{ts,tsx,mts,cts}", "**/__tests__/**/*.{ts,tsx,mts,cts}"],
|
|
482
|
+
rules: {
|
|
483
|
+
"typescript/no-unsafe-argument": "off",
|
|
484
|
+
"typescript/no-unsafe-assignment": "off",
|
|
485
|
+
"typescript/no-unsafe-member-access": "off",
|
|
486
|
+
"typescript/only-throw-error": "off",
|
|
487
|
+
"typescript/unbound-method": "off"
|
|
488
|
+
}
|
|
489
|
+
},
|
|
490
|
+
{
|
|
491
|
+
files: ["**/*.{js,jsx,mjs,cjs}"],
|
|
492
|
+
rules: {
|
|
493
|
+
"typescript/no-unsafe-argument": "off",
|
|
494
|
+
"typescript/no-unsafe-assignment": "off",
|
|
495
|
+
"typescript/no-unsafe-call": "off",
|
|
496
|
+
"typescript/no-unsafe-member-access": "off",
|
|
497
|
+
"typescript/no-unsafe-return": "off"
|
|
498
|
+
}
|
|
499
|
+
}
|
|
500
|
+
]
|
|
501
|
+
};
|
|
369
502
|
const markdownOverrideConfig = {
|
|
370
503
|
files: ["**/*.md/**/*.?([cm])[jt]s?(x)"],
|
|
371
504
|
rules: {
|
|
@@ -399,8 +532,9 @@ const unocss = {
|
|
|
399
532
|
}
|
|
400
533
|
};
|
|
401
534
|
function subfLint(options = {}) {
|
|
402
|
-
const { lib, unocss: enableUnocss, solid: enableSolid, ...oxlint } = options;
|
|
403
|
-
const ovr = [
|
|
535
|
+
const { lib, unocss: enableUnocss, solid: enableSolid, typeAware: enableTypeAware, overrides, extends: userExtends, ...oxlint } = options;
|
|
536
|
+
const ovr = [];
|
|
537
|
+
let solidSettings;
|
|
404
538
|
if (lib) ovr.push({
|
|
405
539
|
...ts,
|
|
406
540
|
rules: {
|
|
@@ -413,9 +547,54 @@ function subfLint(options = {}) {
|
|
|
413
547
|
}
|
|
414
548
|
});
|
|
415
549
|
else ovr.push(ts);
|
|
550
|
+
ovr.push(vitest, markdownOverrideConfig);
|
|
416
551
|
if (enableUnocss) ovr.push(unocss);
|
|
417
|
-
if (enableSolid)
|
|
418
|
-
|
|
552
|
+
if (enableSolid) {
|
|
553
|
+
const solidPreset = enableSolid === true ? "v2strict" : enableSolid;
|
|
554
|
+
if (solidPreset === "v1") ovr.push(solidConfig);
|
|
555
|
+
else {
|
|
556
|
+
const preset = solidPreset === "v2" ? solidV2Config : solidV2StrictConfig;
|
|
557
|
+
if (preset.overrides) ovr.push(...preset.overrides);
|
|
558
|
+
solidSettings = preset.settings;
|
|
559
|
+
}
|
|
560
|
+
}
|
|
561
|
+
if (enableTypeAware && typeAware.overrides) ovr.push(...typeAware.overrides);
|
|
562
|
+
if (overrides) ovr.push(...overrides);
|
|
563
|
+
return {
|
|
564
|
+
...oxlint,
|
|
565
|
+
env: {
|
|
566
|
+
...baseConfig.env,
|
|
567
|
+
...oxlint.env
|
|
568
|
+
},
|
|
569
|
+
globals: {
|
|
570
|
+
...baseConfig.globals,
|
|
571
|
+
...oxlint.globals
|
|
572
|
+
},
|
|
573
|
+
settings: {
|
|
574
|
+
...solidSettings,
|
|
575
|
+
...oxlint.settings
|
|
576
|
+
},
|
|
577
|
+
options: {
|
|
578
|
+
...baseConfig.options,
|
|
579
|
+
...enableTypeAware ? typeAware.options : {},
|
|
580
|
+
...oxlint.options
|
|
581
|
+
},
|
|
582
|
+
plugins: [
|
|
583
|
+
...baseRules.plugins ?? [],
|
|
584
|
+
...(userExtends ?? []).flatMap((config) => config.plugins ?? []),
|
|
585
|
+
...oxlint.plugins ?? []
|
|
586
|
+
],
|
|
587
|
+
ignorePatterns: [
|
|
588
|
+
...baseConfig.ignorePatterns ?? [],
|
|
589
|
+
...(userExtends ?? []).flatMap((config) => config.ignorePatterns ?? []),
|
|
590
|
+
...oxlint.ignorePatterns ?? []
|
|
591
|
+
],
|
|
592
|
+
extends: [
|
|
593
|
+
baseRules,
|
|
594
|
+
...enableTypeAware ? [{ rules: typeAware.rules }] : [],
|
|
595
|
+
...userExtends ?? []
|
|
596
|
+
],
|
|
597
|
+
overrides: ovr
|
|
598
|
+
};
|
|
419
599
|
}
|
|
420
|
-
|
|
421
|
-
export { CONFIG, CONFIG as default, FILES_TS_TSX, baseConfig, baseRules, markdownOverrideConfig, overrides, solid, subfLint, ts, unocss, vitest };
|
|
600
|
+
export { CONFIG, CONFIG as default, FILES_TS_TSX, baseConfig, baseRules, markdownOverrideConfig, overrides, solid, solidV2, solidV2Strict, subfLint, ts, typeAware, unocss, vitest };
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@subf/config",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.6.0",
|
|
4
4
|
"description": "Universal configuration for TypeScript, oxlint (+unocss, +solid), oxfmt, and tsdown.",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"config",
|
|
@@ -34,38 +34,31 @@
|
|
|
34
34
|
],
|
|
35
35
|
"type": "module",
|
|
36
36
|
"exports": {
|
|
37
|
-
"./oxfmt": "./dist/oxfmt.
|
|
38
|
-
"./oxlint": "./dist/oxlint.
|
|
39
|
-
"./tsdown": "./dist/tsdown.js",
|
|
37
|
+
"./oxfmt": "./dist/oxfmt.mjs",
|
|
38
|
+
"./oxlint": "./dist/oxlint.mjs",
|
|
40
39
|
"./package.json": "./package.json"
|
|
41
40
|
},
|
|
42
41
|
"publishConfig": {
|
|
43
42
|
"access": "public"
|
|
44
43
|
},
|
|
45
|
-
"scripts": {
|
|
46
|
-
"build": "tsdown",
|
|
47
|
-
"dev": "tsdown --watch",
|
|
48
|
-
"typecheck": "tsc --noEmit",
|
|
49
|
-
"lint": "oxlint --fix",
|
|
50
|
-
"format": "oxfmt",
|
|
51
|
-
"release": "bumpp --all",
|
|
52
|
-
"qa": "nub run lint && nub run format && nub run typecheck",
|
|
53
|
-
"prepublishOnly": "nub run build"
|
|
54
|
-
},
|
|
55
44
|
"dependencies": {
|
|
56
|
-
"@subf/oxlint-plugin": "^0.
|
|
45
|
+
"@subf/oxlint-plugin": "^0.4.0"
|
|
57
46
|
},
|
|
58
47
|
"devDependencies": {
|
|
59
48
|
"@types/node": "^24",
|
|
60
49
|
"bumpp": "^11.1.0",
|
|
61
|
-
"oxfmt": "^0.
|
|
62
|
-
"oxlint": "^1.
|
|
63
|
-
"tsdown": "^0.
|
|
64
|
-
"
|
|
50
|
+
"oxfmt": "^0.79.0",
|
|
51
|
+
"oxlint": "^1.94.0",
|
|
52
|
+
"tsdown": "^0.23.7",
|
|
53
|
+
"tsrs": "0.25.0-ts7.1.0-beta"
|
|
65
54
|
},
|
|
66
|
-
"
|
|
67
|
-
"
|
|
68
|
-
"
|
|
69
|
-
"
|
|
55
|
+
"scripts": {
|
|
56
|
+
"build": "tsdown",
|
|
57
|
+
"dev": "tsdown --watch",
|
|
58
|
+
"typecheck": "tsrs --noEmit --fast",
|
|
59
|
+
"lint": "oxlint --fix",
|
|
60
|
+
"format": "oxfmt",
|
|
61
|
+
"release": "bumpp --all",
|
|
62
|
+
"qa": "pnpm run lint && pnpm run format && pnpm run typecheck"
|
|
70
63
|
}
|
|
71
|
-
}
|
|
64
|
+
}
|
package/dist/cli.d.ts
DELETED
|
@@ -1,9 +0,0 @@
|
|
|
1
|
-
//#region src/utils/tsconfig.d.ts
|
|
2
|
-
declare const TSCONFIG_TYPE: readonly ["node", "lib", "solid", "solid-lib"];
|
|
3
|
-
type TsconfigType = (typeof TSCONFIG_TYPE)[number];
|
|
4
|
-
//#endregion
|
|
5
|
-
//#region src/cli.d.ts
|
|
6
|
-
declare function parseType(argv: readonly string[]): TsconfigType;
|
|
7
|
-
declare function main(argv?: readonly string[]): Promise<number>;
|
|
8
|
-
//#endregion
|
|
9
|
-
export { main, parseType };
|
package/dist/oxfmt.d.ts
DELETED
package/dist/oxfmt.js
DELETED
|
@@ -1,20 +0,0 @@
|
|
|
1
|
-
import { defu } from "defu";
|
|
2
|
-
//#region src/oxfmt.ts
|
|
3
|
-
const CONFIG = {
|
|
4
|
-
semi: false,
|
|
5
|
-
singleQuote: true,
|
|
6
|
-
sortImports: { groups: [
|
|
7
|
-
["side_effect"],
|
|
8
|
-
["builtin"],
|
|
9
|
-
["external", "type-external"],
|
|
10
|
-
["internal", "type-internal"],
|
|
11
|
-
["parent", "type-parent"],
|
|
12
|
-
["sibling", "type-sibling"],
|
|
13
|
-
["index", "type-index"]
|
|
14
|
-
] }
|
|
15
|
-
};
|
|
16
|
-
function subfFmt(config) {
|
|
17
|
-
return defu(CONFIG, config);
|
|
18
|
-
}
|
|
19
|
-
//#endregion
|
|
20
|
-
export { CONFIG, CONFIG as default, subfFmt };
|
package/dist/oxlint.d.ts
DELETED
|
@@ -1,22 +0,0 @@
|
|
|
1
|
-
import { FILES_TS_TSX, solidConfig as solid } from "@subf/oxlint-plugin/config";
|
|
2
|
-
import { OxlintConfig, OxlintOverride } from "oxlint";
|
|
3
|
-
//#region src/oxlint.d.ts
|
|
4
|
-
declare const baseConfig: OxlintConfig;
|
|
5
|
-
declare const baseRules: OxlintConfig;
|
|
6
|
-
declare const ts: OxlintOverride;
|
|
7
|
-
declare const vitest: OxlintOverride;
|
|
8
|
-
declare const markdownOverrideConfig: OxlintOverride;
|
|
9
|
-
declare const overrides: OxlintOverride[];
|
|
10
|
-
declare const CONFIG: OxlintConfig;
|
|
11
|
-
declare const unocss: OxlintOverride;
|
|
12
|
-
interface SubfOptions extends OxlintConfig {
|
|
13
|
-
/**
|
|
14
|
-
* Used for lib, force to explicit function return type
|
|
15
|
-
*/
|
|
16
|
-
lib?: boolean;
|
|
17
|
-
solid?: boolean;
|
|
18
|
-
unocss?: boolean;
|
|
19
|
-
}
|
|
20
|
-
declare function subfLint(options?: SubfOptions): OxlintConfig;
|
|
21
|
-
//#endregion
|
|
22
|
-
export { CONFIG, CONFIG as default, FILES_TS_TSX, type OxlintConfig, type OxlintOverride, SubfOptions, baseConfig, baseRules, markdownOverrideConfig, overrides, solid, subfLint, ts, unocss, vitest };
|
package/dist/tsdown.d.ts
DELETED
|
@@ -1,52 +0,0 @@
|
|
|
1
|
-
import { DepsConfig, DtsOptions, ExportsOptions, TsdownInputOption, UserConfig } from "tsdown";
|
|
2
|
-
//#region src/tsdown.d.ts
|
|
3
|
-
interface DepsOptions {
|
|
4
|
-
/**
|
|
5
|
-
* tsdown's deps option, which controls which dependency to bundle.
|
|
6
|
-
*/
|
|
7
|
-
bundled?: DepsConfig["alwaysBundle"];
|
|
8
|
-
/**
|
|
9
|
-
* tsdown's deps option, which controls which dependency to exclude.
|
|
10
|
-
*/
|
|
11
|
-
unbundled?: DepsConfig["neverBundle"];
|
|
12
|
-
}
|
|
13
|
-
interface LibOptions extends DepsOptions {
|
|
14
|
-
/**
|
|
15
|
-
* The entry point for the library.
|
|
16
|
-
* - 'index' (default): Only include `src/index.ts`.
|
|
17
|
-
* - 'shallow': Include all `.ts` files directly under `src/`.
|
|
18
|
-
* - 'all': Include all `.ts` files under `src/` recursively.
|
|
19
|
-
* - Custom glob pattern or array of file paths.
|
|
20
|
-
*
|
|
21
|
-
* @default 'index'
|
|
22
|
-
*/
|
|
23
|
-
entry?: "index" | "shallow" | "all" | Exclude<TsdownInputOption, string>;
|
|
24
|
-
/**
|
|
25
|
-
* tsdown's `customExports` option, which controls how the exports field is generated in package.json.
|
|
26
|
-
*
|
|
27
|
-
* @default true
|
|
28
|
-
*/
|
|
29
|
-
extraExports?: ExportsOptions["customExports"];
|
|
30
|
-
dts?: DtsOptions & DepsOptions;
|
|
31
|
-
plugins?: UserConfig["plugins"];
|
|
32
|
-
overrides?: UserConfig;
|
|
33
|
-
}
|
|
34
|
-
declare function lib(options?: LibOptions): UserConfig;
|
|
35
|
-
declare function nodeLib(options?: LibOptions): UserConfig;
|
|
36
|
-
interface SolidLibOptions extends LibOptions {
|
|
37
|
-
/**
|
|
38
|
-
* Options to pass to the `vite-plugin-solid` plugin. This is useful if you want to customize the solid plugin options, such as enabling hot module replacement (HMR) or configuring the Solid compiler.
|
|
39
|
-
*/
|
|
40
|
-
solid?: Record<string, any>;
|
|
41
|
-
/**
|
|
42
|
-
* Overrides for the js output config. This is useful if you want to customize the js output config, such as adding additional plugins or changing the output format.
|
|
43
|
-
*/
|
|
44
|
-
jsOverride?: UserConfig;
|
|
45
|
-
/**
|
|
46
|
-
* Overrides for the jsx output config. This is useful if you want to customize the jsx output config, such as adding additional plugins or changing the output format.
|
|
47
|
-
*/
|
|
48
|
-
jsxOverride?: UserConfig;
|
|
49
|
-
}
|
|
50
|
-
declare function solidLib(options: SolidLibOptions): Promise<UserConfig[]>;
|
|
51
|
-
//#endregion
|
|
52
|
-
export { LibOptions, SolidLibOptions, lib, nodeLib, solidLib };
|
package/dist/tsdown.js
DELETED
|
@@ -1,67 +0,0 @@
|
|
|
1
|
-
import { mergeConfig } from "tsdown/config";
|
|
2
|
-
//#region src/tsdown.ts
|
|
3
|
-
function lib(options = {}) {
|
|
4
|
-
const { entry = "index", extraExports, bundled, unbundled, plugins, dts = { oxc: true }, overrides = {} } = options;
|
|
5
|
-
return mergeConfig({
|
|
6
|
-
entry: entry === "index" ? "src/index.ts" : entry === "shallow" ? "src/*.ts" : entry === "all" ? "src/**/*.ts" : entry,
|
|
7
|
-
dts,
|
|
8
|
-
platform: "neutral",
|
|
9
|
-
plugins,
|
|
10
|
-
deps: {
|
|
11
|
-
alwaysBundle: bundled,
|
|
12
|
-
neverBundle: unbundled,
|
|
13
|
-
dts: {
|
|
14
|
-
alwaysBundle: dts.bundled,
|
|
15
|
-
neverBundle: dts.unbundled
|
|
16
|
-
}
|
|
17
|
-
},
|
|
18
|
-
exports: { customExports: extraExports }
|
|
19
|
-
}, overrides);
|
|
20
|
-
}
|
|
21
|
-
function nodeLib(options = {}) {
|
|
22
|
-
return lib({
|
|
23
|
-
...options,
|
|
24
|
-
overrides: {
|
|
25
|
-
platform: "node",
|
|
26
|
-
...options.overrides
|
|
27
|
-
}
|
|
28
|
-
});
|
|
29
|
-
}
|
|
30
|
-
async function loadSolidPlugin(options) {
|
|
31
|
-
let solid;
|
|
32
|
-
try {
|
|
33
|
-
solid = await import("vite-plugin-solid").then((m) => m.default || m);
|
|
34
|
-
} catch {
|
|
35
|
-
throw new Error("`vite-plugin-solid` is required for solidLib.");
|
|
36
|
-
}
|
|
37
|
-
return solid(options);
|
|
38
|
-
}
|
|
39
|
-
async function solidLib(options) {
|
|
40
|
-
const { entry, solid: solidOptions, extraExports, overrides = {}, jsOverride = {}, jsxOverride = {} } = options;
|
|
41
|
-
return [mergeConfig({
|
|
42
|
-
entry,
|
|
43
|
-
platform: "browser",
|
|
44
|
-
plugins: [loadSolidPlugin(solidOptions)],
|
|
45
|
-
dts: true
|
|
46
|
-
}, overrides, jsOverride), mergeConfig({
|
|
47
|
-
entry,
|
|
48
|
-
platform: "neutral",
|
|
49
|
-
outExtensions: () => ({ js: ".jsx" }),
|
|
50
|
-
dts: false,
|
|
51
|
-
exports: { customExports(exports, context) {
|
|
52
|
-
for (const [key, val] of Object.entries(exports)) if (val.endsWith(".jsx")) exports[key] = {
|
|
53
|
-
solid: val,
|
|
54
|
-
default: val.replace(".jsx", ".mjs"),
|
|
55
|
-
type: val.replace(".jsx", ".d.mts")
|
|
56
|
-
};
|
|
57
|
-
if (!extraExports) return exports;
|
|
58
|
-
else if (typeof extraExports === "function") return extraExports(exports, context);
|
|
59
|
-
else return {
|
|
60
|
-
...exports,
|
|
61
|
-
...extraExports
|
|
62
|
-
};
|
|
63
|
-
} }
|
|
64
|
-
}, overrides, jsxOverride)];
|
|
65
|
-
}
|
|
66
|
-
//#endregion
|
|
67
|
-
export { lib, nodeLib, solidLib };
|