@subf/config 0.2.1 → 0.4.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 CHANGED
@@ -12,18 +12,15 @@ bun i -D @subf/config
12
12
 
13
13
  ### `tsconfig`
14
14
 
15
- ```json
16
- {
17
- "extends": "@subf/config/tsc-lib"
18
- }
19
- ```
15
+ Run `subf` to create or update `tsconfig.json` (the default type is `lib`):
20
16
 
21
- Available configs:
17
+ ```sh
18
+ subf
19
+ subf --type node # Node.js apps
20
+ subf --type web # SolidJS apps
21
+ ```
22
22
 
23
- - `tsc-lib`: for libraries.
24
- - `tsc-node`: for Node.js apps.
25
- - `tsc-web`: for SolidJS apps.
26
- - `tsc-base`: base config for custom setups.
23
+ When `tsconfig.json` already exists, missing settings are added while existing settings are preserved. Use `--force` to overwrite generated settings. Legacy `@subf/config` entries in `extends` are removed automatically.
27
24
 
28
25
  ### `tsdown`
29
26
 
@@ -148,6 +145,8 @@ bun subf # or just `subf` if on PATH
148
145
  bun subf -f # force overwrite existing files
149
146
  ```
150
147
 
148
+ When `oxlint` or `oxfmt` is missing, `subf` resolves the latest version from the registry and adds it to `devDependencies` (fallback chain: `$npm_config_registry` -> `$NPM_CONFIG_REGISTRY` -> the public npm registry). Registry failures are reported as warnings and do not prevent config generation.
149
+
151
150
  ## License
152
151
 
153
- MIT
152
+ MIT
package/bin/subf.js CHANGED
@@ -1,171 +1,3 @@
1
1
  #!/usr/bin/env node
2
- import { existsSync, readFileSync, writeFileSync } from 'node:fs'
3
- import path from 'node:path'
4
- import { fileURLToPath } from 'node:url'
5
-
6
- function createConfigs({ cwd = process.cwd(), force = false } = {}) {
7
- const files = [
8
- {
9
- name: 'oxfmt.config.ts',
10
- content: "import { subfFmt } from '@subf/config/oxfmt'\n\nexport default subfFmt()\n",
11
- },
12
- {
13
- name: 'oxlint.config.ts',
14
- content: "import { subfLint } from '@subf/config/oxlint'\n\nexport default subfLint()\n",
15
- },
16
- {
17
- name: 'tsconfig.json',
18
- content: `${JSON.stringify({ extends: '@subf/config/tsconfig-lib' }, null, 2)}\n`,
19
- },
20
- ]
21
-
22
- const created = []
23
-
24
- for (const file of files) {
25
- const full = path.join(cwd, file.name)
26
- if (existsSync(full) && !force) {
27
- console.log(`Skipped ${file.name} (exists). Use --force to overwrite.`)
28
- continue
29
- }
30
-
31
- writeFileSync(full, file.content, 'utf8')
32
- created.push(file.name)
33
- console.log(`Wrote ${file.name}`)
34
- }
35
-
36
- if (created.length === 0) {
37
- console.log('No files created.')
38
- } else {
39
- console.log('Created:', created.join(', '))
40
- }
41
-
42
- return created
43
- }
44
-
45
- function getSelfVersionRange() {
46
- try {
47
- const currentDir = path.dirname(fileURLToPath(import.meta.url))
48
- const selfPkgPath = path.resolve(currentDir, '..', 'package.json')
49
- const selfPkg = JSON.parse(readFileSync(selfPkgPath, 'utf8'))
50
-
51
- if (selfPkg && typeof selfPkg.version === 'string' && selfPkg.version.length > 0) {
52
- return `^${selfPkg.version}`
53
- }
54
- } catch {}
55
-
56
- return 'latest'
57
- }
58
-
59
- function sortObjectKeys(obj) {
60
- return Object.fromEntries(Object.entries(obj).sort(([a], [b]) => a.localeCompare(b)))
61
- }
62
-
63
- function ensureDevDependency(pkg, name, versionRange) {
64
- const existingDev = pkg.devDependencies && pkg.devDependencies[name]
65
- if (existingDev) {
66
- return { changed: false, location: 'devDependencies', version: existingDev }
67
- }
68
-
69
- const existingDep = pkg.dependencies && pkg.dependencies[name]
70
- if (existingDep) {
71
- return { changed: false, location: 'dependencies', version: existingDep }
72
- }
73
-
74
- if (!pkg.devDependencies || typeof pkg.devDependencies !== 'object') {
75
- pkg.devDependencies = {}
76
- }
77
-
78
- pkg.devDependencies[name] = versionRange
79
- pkg.devDependencies = sortObjectKeys(pkg.devDependencies)
80
-
81
- return { changed: true, location: 'devDependencies', version: versionRange }
82
- }
83
-
84
- const projectRoot = process.env.INIT_CWD || process.cwd()
85
- const args = new Set(process.argv.slice(2))
86
- const force = args.has('--force') || args.has('-f')
87
- const help = args.has('--help') || args.has('-h')
88
-
89
- if (help) {
90
- console.log('Usage: subf [-f|--force]')
91
- console.log('Create helper config files in the current project:')
92
- console.log(' oxfmt.config.ts, oxlint.config.ts, tsconfig.json')
93
- console.log('Use -f or --force to overwrite existing files.')
94
- process.exit(0)
95
- }
96
-
97
- try {
98
- createConfigs({ cwd: projectRoot, force })
99
- } catch (err) {
100
- console.error('Failed to create config files:', err)
101
- process.exit(1)
102
- }
103
-
104
- // If project has package.json, suggest installing @subf/config when it's not listed
105
- const projectPkgPath = path.join(projectRoot, 'package.json')
106
- if (!existsSync(projectPkgPath)) {
107
- console.log('No package.json found in project root.')
108
- console.log('Skipping dependency injection because package.json is missing.')
109
- process.exit(0)
110
- }
111
-
112
- let projectPkg
113
- try {
114
- projectPkg = JSON.parse(readFileSync(projectPkgPath, 'utf8'))
115
- } catch (err) {
116
- console.log(
117
- 'Created helper configs. Could not read package.json to add @subf/config.',
118
- err && (err.message || err),
119
- )
120
- process.exit(0)
121
- }
122
-
123
- const depName = '@subf/config'
124
- const depVersion = getSelfVersionRange()
125
- const depResult = ensureDevDependency(projectPkg, depName, depVersion)
126
-
127
- if (depResult.changed) {
128
- try {
129
- writeFileSync(projectPkgPath, `${JSON.stringify(projectPkg, null, 2)}\n`, 'utf8')
130
- console.log(`Added ${depName}@${depResult.version} to devDependencies in package.json.`)
131
- } catch (err) {
132
- console.log(
133
- `Created helper configs, but failed to write ${depName} into package.json.`,
134
- err && (err.message || err),
135
- )
136
- process.exit(0)
137
- }
138
- } else {
139
- console.log(
140
- `${depName} already exists in ${depResult.location} (${depResult.version}). No dependency changes needed.`,
141
- )
142
- }
143
-
144
- // If either oxfmt or oxlint aren't listed, hint how to install them
145
- try {
146
- const missingTools = []
147
- const hasOxfmt = projectPkg.devDependencies?.oxfmt || projectPkg.dependencies?.oxfmt
148
- const hasOxlint = projectPkg.devDependencies?.oxlint || projectPkg.dependencies?.oxlint
149
- const hasTypescript =
150
- projectPkg.devDependencies?.typescript || projectPkg.dependencies?.typescript
151
-
152
- if (!hasOxfmt) {
153
- missingTools.push('oxfmt')
154
- }
155
- if (!hasOxlint) {
156
- missingTools.push('oxlint')
157
- }
158
- if (!hasTypescript) {
159
- missingTools.push('typescript')
160
- }
161
-
162
- if (missingTools.length > 0) {
163
- console.log(
164
- `Hint: Install ${missingTools.join(' and ')} to use the generated configs. Example: npm install -D ${missingTools.join(
165
- ' ',
166
- )}`,
167
- )
168
- }
169
- } catch {}
170
-
171
- process.exit(0)
2
+ import { main } from '../dist/cli.js'
3
+ main(process.argv.slice(2))
package/dist/cli.d.ts ADDED
@@ -0,0 +1,9 @@
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/cli.js ADDED
@@ -0,0 +1,285 @@
1
+ import { existsSync, readFileSync, writeFileSync } from "node:fs";
2
+ import path from "node:path";
3
+ import { createDefu } from "defu";
4
+ import { fileURLToPath } from "node:url";
5
+ //#region src/utils/tsconfig.ts
6
+ const TSCONFIG_TYPE = [
7
+ "node",
8
+ "lib",
9
+ "solid",
10
+ "solid-lib"
11
+ ];
12
+ const BASE_COMPILER_OPTIONS = {
13
+ target: "esnext",
14
+ module: "esnext",
15
+ moduleResolution: "Bundler",
16
+ moduleDetection: "force",
17
+ strict: true,
18
+ strictNullChecks: true,
19
+ noUnusedLocals: true,
20
+ noImplicitOverride: true,
21
+ esModuleInterop: true,
22
+ isolatedModules: true,
23
+ skipLibCheck: true,
24
+ verbatimModuleSyntax: true,
25
+ resolveJsonModule: true,
26
+ noEmit: true,
27
+ allowImportingTsExtensions: true
28
+ };
29
+ function solidConfigs(options) {
30
+ options.jsx = "preserve";
31
+ options.jsxImportSource = "solid-js";
32
+ options.lib = [
33
+ "ES2022",
34
+ "DOM",
35
+ "DOM.Iterable"
36
+ ];
37
+ options.types = ["vite/client"];
38
+ }
39
+ function getCompilerOptions(type) {
40
+ const options = { ...BASE_COMPILER_OPTIONS };
41
+ switch (type) {
42
+ case "solid":
43
+ solidConfigs(options);
44
+ break;
45
+ case "solid-lib":
46
+ solidConfigs(options);
47
+ options.noUncheckedIndexedAccess = true;
48
+ break;
49
+ case "node":
50
+ options.target = "ES2023";
51
+ options.lib = ["ES2023"];
52
+ options.module = "NodeNext";
53
+ options.moduleResolution = "NodeNext";
54
+ options.types = ["node"];
55
+ options.erasableSyntaxOnly = true;
56
+ break;
57
+ case "lib":
58
+ options.target = "ES2023";
59
+ options.lib = ["ES2023"];
60
+ options.noUncheckedIndexedAccess = true;
61
+ }
62
+ return options;
63
+ }
64
+ //#endregion
65
+ //#region src/utils/config-files.ts
66
+ function isRecord(value) {
67
+ return typeof value === "object" && value !== null && !Array.isArray(value);
68
+ }
69
+ function mergeConfig(existing, generated, overwrite) {
70
+ const merge = createDefu((object, key, value) => {
71
+ if (overwrite) {
72
+ if (isRecord(object[key]) && isRecord(value)) return false;
73
+ object[key] = value;
74
+ return true;
75
+ }
76
+ if (Array.isArray(object[key]) && Array.isArray(value)) {
77
+ object[key] = value;
78
+ return true;
79
+ }
80
+ return false;
81
+ });
82
+ const result = overwrite ? merge(generated, existing) : merge(existing, generated);
83
+ if (!overwrite) restoreNullValues(result, existing);
84
+ return result;
85
+ }
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
+ function getTsconfigContent(fullPath, force, type) {
91
+ const generated = { compilerOptions: getCompilerOptions(type) };
92
+ if (!existsSync(fullPath)) return `${JSON.stringify(generated, null, 2)}\n`;
93
+ let existing;
94
+ try {
95
+ existing = JSON.parse(readFileSync(fullPath, "utf8"));
96
+ } catch (error) {
97
+ if (!force) throw new Error(`Failed to parse ${path.basename(fullPath)}: ${String(error)}`);
98
+ return `${JSON.stringify(generated, null, 2)}\n`;
99
+ }
100
+ if (!isRecord(existing)) {
101
+ if (!force) throw new Error(`${path.basename(fullPath)} must contain a JSON object`);
102
+ return `${JSON.stringify(generated, null, 2)}\n`;
103
+ }
104
+ const merged = mergeConfig(existing, generated, force);
105
+ if (typeof merged.extends === "string" && merged.extends.includes("@subf/config")) delete merged.extends;
106
+ const content = `${JSON.stringify(merged, null, 2)}\n`;
107
+ return content === readFileSync(fullPath, "utf8") ? void 0 : content;
108
+ }
109
+ function createConfigs({ cwd, force, type }) {
110
+ const files = [{
111
+ name: "oxfmt.config.ts",
112
+ content: "import { subfFmt } from '@subf/config/oxfmt'\n\nexport default subfFmt()\n"
113
+ }, {
114
+ name: "oxlint.config.ts",
115
+ content: "import { subfLint } from '@subf/config/oxlint'\n\nexport default subfLint()\n"
116
+ }];
117
+ const created = [];
118
+ for (const file of files) {
119
+ const fullPath = path.join(cwd, file.name);
120
+ if (existsSync(fullPath)) {
121
+ if (!force) {
122
+ console.log(`Skipped ${file.name} (exists). Use --force to overwrite.`);
123
+ continue;
124
+ }
125
+ } else created.push(file.name);
126
+ writeFileSync(fullPath, file.content, "utf8");
127
+ console.log(`Wrote ${file.name}`);
128
+ }
129
+ const tsconfigPath = path.join(cwd, "tsconfig.json");
130
+ const tsconfigContent = getTsconfigContent(tsconfigPath, force, type);
131
+ if (tsconfigContent === void 0) console.log("Skipped tsconfig.json (up to date).");
132
+ else {
133
+ writeFileSync(tsconfigPath, tsconfigContent, "utf8");
134
+ created.push("tsconfig.json");
135
+ console.log("Wrote tsconfig.json");
136
+ }
137
+ if (created.length === 0) console.log("No files created.");
138
+ else console.log("Created:", created.join(", "));
139
+ }
140
+ //#endregion
141
+ //#region src/utils/registry.ts
142
+ function getRegistry(env = process.env) {
143
+ return (env.npm_config_registry || env.NPM_CONFIG_REGISTRY || "https://registry.npmjs.org").replace(/\/+$/, "");
144
+ }
145
+ async function getLatestVersion(name, registry) {
146
+ const controller = new AbortController();
147
+ const timeout = setTimeout(() => controller.abort(), 1e4);
148
+ try {
149
+ const response = await fetch(`${registry}/${encodeURIComponent(name)}`, { signal: controller.signal });
150
+ if (!response.ok) throw new Error(`HTTP ${response.status}`);
151
+ const version = (await response.json())["dist-tags"]?.latest;
152
+ if (typeof version !== "string" || !version.trim()) throw new Error("missing dist-tags.latest");
153
+ return version.trim();
154
+ } finally {
155
+ clearTimeout(timeout);
156
+ }
157
+ }
158
+ //#endregion
159
+ //#region src/utils/package-json.ts
160
+ function sortObjectKeys(obj) {
161
+ return Object.fromEntries(Object.entries(obj).sort(([a], [b]) => a.localeCompare(b)));
162
+ }
163
+ function ensureDevDependency(pkg, name, versionRange) {
164
+ const existingDev = pkg.devDependencies?.[name];
165
+ if (existingDev) return {
166
+ changed: false,
167
+ location: "devDependencies",
168
+ version: existingDev
169
+ };
170
+ const existingDep = pkg.dependencies?.[name];
171
+ if (existingDep) return {
172
+ changed: false,
173
+ location: "dependencies",
174
+ version: existingDep
175
+ };
176
+ if (!pkg.devDependencies || typeof pkg.devDependencies !== "object") pkg.devDependencies = {};
177
+ pkg.devDependencies[name] = versionRange;
178
+ pkg.devDependencies = sortObjectKeys(pkg.devDependencies);
179
+ return {
180
+ changed: true,
181
+ location: "devDependencies",
182
+ version: versionRange
183
+ };
184
+ }
185
+ function getSelfVersionRange() {
186
+ try {
187
+ const moduleDirectory = path.dirname(fileURLToPath(import.meta.url));
188
+ const packagePath = [path.resolve(moduleDirectory, "..", "package.json"), path.resolve(moduleDirectory, "..", "..", "package.json")].find((candidate) => existsSync(candidate));
189
+ if (!packagePath) return "latest";
190
+ const pkg = JSON.parse(readFileSync(packagePath, "utf8"));
191
+ if (typeof pkg?.version === "string" && pkg.version.length > 0) return `^${pkg.version}`;
192
+ } catch {}
193
+ return "latest";
194
+ }
195
+ function hasDependency(pkg, name) {
196
+ return Boolean(pkg.devDependencies?.[name] || pkg.dependencies?.[name]);
197
+ }
198
+ async function updateProjectPackage({ projectRoot, registry }) {
199
+ const packagePath = path.join(projectRoot, "package.json");
200
+ if (!existsSync(packagePath)) {
201
+ console.log("No package.json found in project root.");
202
+ console.log("Skipping dependency injection because package.json is missing.");
203
+ return;
204
+ }
205
+ let projectPackage;
206
+ try {
207
+ projectPackage = JSON.parse(readFileSync(packagePath, "utf8"));
208
+ } catch (error) {
209
+ console.log("Created helper configs. Could not read package.json.", error);
210
+ return;
211
+ }
212
+ let changed = false;
213
+ if (projectPackage.name !== "@subf/config") {
214
+ const result = ensureDevDependency(projectPackage, "@subf/config", getSelfVersionRange());
215
+ changed ||= result.changed;
216
+ if (result.changed) console.log(`Added @subf/config@${result.version} to devDependencies.`);
217
+ else console.log(`@subf/config already exists in ${result.location} (${result.version}). No dependency changes needed.`);
218
+ }
219
+ for (const name of ["oxfmt", "oxlint"]) {
220
+ const existing = projectPackage.devDependencies?.[name] || projectPackage.dependencies?.[name];
221
+ if (existing) {
222
+ console.log(`${name} already exists (${existing}). No dependency changes needed.`);
223
+ continue;
224
+ }
225
+ try {
226
+ const version = await getLatestVersion(name, registry);
227
+ changed ||= ensureDevDependency(projectPackage, name, `^${version}`).changed;
228
+ console.log(`Added ${name}@^${version} to devDependencies.`);
229
+ } catch (error) {
230
+ console.warn(`Warning: could not resolve latest ${name} from ${registry}:`, error);
231
+ }
232
+ }
233
+ if (changed) try {
234
+ writeFileSync(packagePath, `${JSON.stringify(projectPackage, null, 2)}\n`, "utf8");
235
+ } catch (error) {
236
+ console.log("Created helper configs, but failed to write package.json.", error);
237
+ }
238
+ const missingTools = [
239
+ "oxfmt",
240
+ "oxlint",
241
+ "typescript"
242
+ ].filter((name) => !hasDependency(projectPackage, name));
243
+ if (missingTools.length > 0) console.log(`Hint: Install ${missingTools.join(" and ")} to use the generated configs.`);
244
+ }
245
+ //#endregion
246
+ //#region src/cli.ts
247
+ function parseType(argv) {
248
+ const index = argv.findIndex((arg) => arg === "--type" || arg.startsWith("--type="));
249
+ if (index < 0) return "lib";
250
+ const option = argv[index] ?? "";
251
+ const value = option.startsWith("--type=") ? option.slice(7) : argv[index + 1];
252
+ if (!TSCONFIG_TYPE.some((item) => item === value)) throw new Error(`Invalid type: ${value}. Must be one of ${TSCONFIG_TYPE.join(",")}.`);
253
+ return value;
254
+ }
255
+ async function main(argv = process.argv.slice(2)) {
256
+ const args = new Set(argv);
257
+ const force = args.has("--force") || args.has("-f");
258
+ const help = args.has("--help") || args.has("-h");
259
+ const type = parseType(argv);
260
+ const projectRoot = process.env.INIT_CWD || process.cwd();
261
+ if (help) {
262
+ console.log("Usage: subf [--type lib|node|web] [-f|--force]");
263
+ console.log("");
264
+ console.log("Create oxfmt.config.ts, oxlint.config.ts, and tsconfig.json.");
265
+ console.log("The tsconfig type defaults to lib. Existing tsconfig.json is merged automatically; use --force to overwrite existing config keys.");
266
+ return 0;
267
+ }
268
+ try {
269
+ createConfigs({
270
+ cwd: projectRoot,
271
+ force,
272
+ type
273
+ });
274
+ } catch (error) {
275
+ console.error("Failed to create config files:", error);
276
+ return 1;
277
+ }
278
+ await updateProjectPackage({
279
+ projectRoot,
280
+ registry: getRegistry()
281
+ });
282
+ return 0;
283
+ }
284
+ //#endregion
285
+ export { main, parseType };
package/dist/oxfmt.d.ts CHANGED
@@ -1,5 +1,4 @@
1
1
  import { OxfmtConfig } from "oxfmt";
2
-
3
2
  //#region src/oxfmt.d.ts
4
3
  declare const CONFIG: OxfmtConfig;
5
4
  declare function subfFmt(config?: OxfmtConfig): OxfmtConfig;
package/dist/oxlint.d.ts CHANGED
@@ -1,6 +1,5 @@
1
1
  import { FILES_TS_TSX, solidConfig as solid } from "@subf/oxlint-plugin/config";
2
2
  import { OxlintConfig, OxlintOverride } from "oxlint";
3
-
4
3
  //#region src/oxlint.d.ts
5
4
  declare const baseConfig: OxlintConfig;
6
5
  declare const baseRules: OxlintConfig;
@@ -12,8 +11,8 @@ declare const CONFIG: OxlintConfig;
12
11
  declare const unocss: OxlintOverride;
13
12
  interface SubfOptions extends OxlintConfig {
14
13
  /**
15
- * Used for lib, force to explicit function return type
16
- */
14
+ * Used for lib, force to explicit function return type
15
+ */
17
16
  lib?: boolean;
18
17
  solid?: boolean;
19
18
  unocss?: boolean;
package/dist/oxlint.js CHANGED
@@ -90,8 +90,15 @@ const baseRules = {
90
90
  "typescript",
91
91
  "eslint"
92
92
  ],
93
+ jsPlugins: [{
94
+ name: "subf",
95
+ specifier: "@subf/oxlint-plugin"
96
+ }],
93
97
  categories: { correctness: "error" },
94
98
  rules: {
99
+ "subf/method-signature-style": "error",
100
+ "subf/no-negated-conjunction": "error",
101
+ "subf/no-negated-disjunction": "error",
95
102
  "array-callback-return": "error",
96
103
  "block-scoped-var": "error",
97
104
  "class-methods-use-this": "error",
@@ -105,6 +112,7 @@ const baseRules = {
105
112
  newIsCap: true,
106
113
  properties: true
107
114
  }],
115
+ "logical-assignment-operators": ["error", "always"],
108
116
  "no-alert": "error",
109
117
  "no-array-constructor": "error",
110
118
  "no-async-promise-executor": "error",
@@ -133,10 +141,14 @@ const baseRules = {
133
141
  "no-func-assign": "error",
134
142
  "no-global-assign": "error",
135
143
  "no-import-assign": "error",
144
+ "no-implied-eval": "error",
136
145
  "no-inner-declarations": [
137
146
  "error",
138
147
  "functions",
139
- "disallow"
148
+ {
149
+ blockScopedFunctions: "disallow",
150
+ namespaces: "disallow"
151
+ }
140
152
  ],
141
153
  "no-irregular-whitespace": "error",
142
154
  "no-iterator": "error",
@@ -191,6 +203,7 @@ const baseRules = {
191
203
  functions: false,
192
204
  variables: true
193
205
  }],
206
+ "no-useless-assignment": "error",
194
207
  "no-useless-call": "error",
195
208
  "no-useless-catch": "error",
196
209
  "no-useless-computed-key": "error",
@@ -213,6 +226,7 @@ const baseRules = {
213
226
  "object-shorthand": ["error", "always"],
214
227
  "prefer-exponentiation-operator": "error",
215
228
  "prefer-rest-params": "error",
229
+ "prefer-regex-literals": "error",
216
230
  "prefer-spread": "error",
217
231
  "prefer-template": "error",
218
232
  "symbol-description": "error",
@@ -246,7 +260,7 @@ const baseRules = {
246
260
  "unicorn/no-instanceof-array": "error",
247
261
  "unicorn/no-new-array": "off",
248
262
  "unicorn/no-new-buffer": "error",
249
- "unicorn/number-literal-case": "error",
263
+ "unicorn/no-array-fill-with-reference-type": "error",
250
264
  "unicorn/prefer-array-find": "error",
251
265
  "unicorn/prefer-array-flat-map": "error",
252
266
  "unicorn/prefer-array-some": "error",
@@ -263,6 +277,7 @@ const baseRules = {
263
277
  "unicorn/throw-new-error": "error",
264
278
  "import/consistent-type-specifier-style": "error",
265
279
  "import/no-absolute-path": "error",
280
+ "import/no-cycle": "error",
266
281
  "import/no-duplicates": "error",
267
282
  "import/no-self-import": "error",
268
283
  "import/no-named-export": "allow",
@@ -275,12 +290,7 @@ const baseRules = {
275
290
  const ts = {
276
291
  files: FILES_TS_TSX$1,
277
292
  plugins: ["typescript"],
278
- jsPlugins: [{
279
- name: "subf",
280
- specifier: "@subf/oxlint-plugin"
281
- }],
282
293
  rules: {
283
- "subf/method-signature-style": ["error", "property"],
284
294
  "constructor-super": "off",
285
295
  "no-class-assign": "off",
286
296
  "no-const-assign": "off",
@@ -307,6 +317,7 @@ const ts = {
307
317
  }],
308
318
  "typescript/ban-ts-comment": ["error", { "ts-expect-error": "allow-with-description" }],
309
319
  "typescript/dot-notation": "error",
320
+ "typescript/method-signature-style": ["error", "property"],
310
321
  "typescript/no-duplicate-enum-values": "error",
311
322
  "typescript/no-extra-non-null-assertion": "error",
312
323
  "typescript/no-misused-new": "error",
@@ -351,6 +362,7 @@ const vitest = {
351
362
  "vitest/no-import-node-test": "error",
352
363
  "vitest/prefer-hooks-in-order": "error",
353
364
  "vitest/prefer-lowercase-title": "error",
365
+ "vitest/prefer-called-exactly-once-with": "warn",
354
366
  "no-unused-expressions": "off"
355
367
  }
356
368
  };
package/dist/tsdown.d.ts CHANGED
@@ -1,46 +1,52 @@
1
- import { DepsConfig, ExportsOptions, TsdownInputOption, UserConfig } from "tsdown";
2
-
1
+ import { DepsConfig, DtsOptions, ExportsOptions, TsdownInputOption, UserConfig } from "tsdown";
3
2
  //#region src/tsdown.d.ts
4
- interface LibOptions {
3
+ interface DepsOptions {
5
4
  /**
6
- * The entry point for the library.
7
- * - 'index' (default): Only include `src/index.ts`.
8
- * - 'shallow': Include all `.ts` files directly under `src/`.
9
- * - 'all': Include all `.ts` files under `src/` recursively.
10
- * - Custom glob pattern or array of file paths.
11
- *
12
- * @default 'index'
13
- */
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
+ */
14
23
  entry?: "index" | "shallow" | "all" | Exclude<TsdownInputOption, string>;
15
24
  /**
16
- * tsdown's `customExports` option, which controls how the exports field is generated in package.json.
17
- *
18
- * @default true
19
- */
25
+ * tsdown's `customExports` option, which controls how the exports field is generated in package.json.
26
+ *
27
+ * @default true
28
+ */
20
29
  extraExports?: ExportsOptions["customExports"];
21
- /**
22
- * tsdown's deps option, which controls how dependencies are bundled / excluded.
23
- */
24
- bundled?: DepsConfig["alwaysBundle"];
25
- unbundled?: DepsConfig["neverBundle"];
30
+ dts?: DtsOptions & DepsOptions;
31
+ plugins?: UserConfig["plugins"];
26
32
  overrides?: UserConfig;
27
33
  }
28
34
  declare function lib(options?: LibOptions): UserConfig;
29
35
  declare function nodeLib(options?: LibOptions): UserConfig;
30
36
  interface SolidLibOptions extends LibOptions {
31
37
  /**
32
- * 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.
33
- */
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
+ */
34
40
  solid?: Record<string, any>;
35
41
  /**
36
- * 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.
37
- */
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
+ */
38
44
  jsOverride?: UserConfig;
39
45
  /**
40
- * 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.
41
- */
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
+ */
42
48
  jsxOverride?: UserConfig;
43
49
  }
44
50
  declare function solidLib(options: SolidLibOptions): Promise<UserConfig[]>;
45
51
  //#endregion
46
- export { SolidLibOptions, lib, nodeLib, solidLib };
52
+ export { LibOptions, SolidLibOptions, lib, nodeLib, solidLib };
package/dist/tsdown.js CHANGED
@@ -1,14 +1,19 @@
1
1
  import { mergeConfig } from "tsdown/config";
2
2
  //#region src/tsdown.ts
3
3
  function lib(options = {}) {
4
- const { entry = "index", extraExports, bundled, unbundled, overrides = {} } = options;
4
+ const { entry = "index", extraExports, bundled, unbundled, plugins, dts = { oxc: true }, overrides = {} } = options;
5
5
  return mergeConfig({
6
6
  entry: entry === "index" ? "src/index.ts" : entry === "shallow" ? "src/*.ts" : entry === "all" ? "src/**/*.ts" : entry,
7
- dts: { oxc: true },
7
+ dts,
8
8
  platform: "neutral",
9
+ plugins,
9
10
  deps: {
10
11
  alwaysBundle: bundled,
11
- neverBundle: unbundled
12
+ neverBundle: unbundled,
13
+ dts: {
14
+ alwaysBundle: dts.bundled,
15
+ neverBundle: dts.unbundled
16
+ }
12
17
  },
13
18
  exports: { customExports: extraExports }
14
19
  }, overrides);
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@subf/config",
3
- "version": "0.2.1",
3
+ "version": "0.4.0",
4
4
  "description": "Universal configuration for TypeScript, oxlint (+unocss, +solid), oxfmt, and tsdown.",
5
5
  "keywords": [
6
6
  "config",
@@ -30,7 +30,6 @@
30
30
  },
31
31
  "files": [
32
32
  "dist",
33
- "tsconfig.*.json",
34
33
  "bin"
35
34
  ],
36
35
  "type": "module",
@@ -38,11 +37,7 @@
38
37
  "./oxfmt": "./dist/oxfmt.js",
39
38
  "./oxlint": "./dist/oxlint.js",
40
39
  "./tsdown": "./dist/tsdown.js",
41
- "./package.json": "./package.json",
42
- "./tsconfig-base": "./tsconfig.base.json",
43
- "./tsconfig-node": "./tsconfig.node.json",
44
- "./tsconfig-web": "./tsconfig.web.json",
45
- "./tsconfig-lib": "./tsconfig.lib.json"
40
+ "./package.json": "./package.json"
46
41
  },
47
42
  "publishConfig": {
48
43
  "access": "public"
@@ -51,23 +46,26 @@
51
46
  "build": "tsdown",
52
47
  "dev": "tsdown --watch",
53
48
  "typecheck": "tsc --noEmit",
49
+ "lint": "oxlint --fix",
50
+ "format": "oxfmt",
54
51
  "release": "bumpp --all",
55
- "qa": "bun run typecheck && oxlint --fix && oxfmt",
56
- "prepublishOnly": "bun run build"
52
+ "qa": "nub run lint && nub run format && nub run typecheck",
53
+ "prepublishOnly": "nub run build"
57
54
  },
58
55
  "dependencies": {
59
- "@subf/oxlint-plugin": "^0.2.2"
56
+ "@subf/oxlint-plugin": "^0.3.0"
60
57
  },
61
58
  "devDependencies": {
62
- "@oxlint/plugins": "^1.59.0",
63
- "@types/bun": "^1.3.11",
64
- "bumpp": "^11.0.1",
65
- "oxfmt": "^0.44.0",
66
- "oxlint": "^1.59.0",
67
- "tsdown": "^0.21.7",
68
- "typescript": "^5.9.3"
59
+ "@types/node": "^24",
60
+ "bumpp": "^11.1.0",
61
+ "oxfmt": "^0.65.0",
62
+ "oxlint": "^1.80.0",
63
+ "tsdown": "^0.22.14",
64
+ "typescript": "^7.0.2"
69
65
  },
70
66
  "peerDependencies": {
71
- "defu": "*"
67
+ "defu": "6.1.7",
68
+ "oxfmt": "^0",
69
+ "oxlint": "^1"
72
70
  }
73
71
  }
@@ -1,19 +0,0 @@
1
- {
2
- "compilerOptions": {
3
- "target": "esnext",
4
- "module": "esnext",
5
- "lib": ["ESNext"],
6
- "resolveJsonModule": true,
7
- "strict": true,
8
- "strictNullChecks": true,
9
- "noUnusedLocals": true,
10
- "noImplicitOverride": true,
11
- "esModuleInterop": true,
12
- "isolatedModules": true,
13
- "verbatimModuleSyntax": true,
14
- "skipLibCheck": true,
15
- "declaration": true,
16
- "sourceMap": true,
17
- "noEmit": true
18
- }
19
- }
package/tsconfig.lib.json DELETED
@@ -1,7 +0,0 @@
1
- {
2
- "extends": "./tsconfig.base.json",
3
- "compilerOptions": {
4
- "moduleResolution": "bundler",
5
- "noUncheckedIndexedAccess": true
6
- }
7
- }
@@ -1,9 +0,0 @@
1
- {
2
- "extends": "./tsconfig.base.json",
3
- "compilerOptions": {
4
- "lib": ["ESNext"],
5
- "module": "nodenext",
6
- "moduleResolution": "nodenext",
7
- "allowImportingTsExtensions": true
8
- }
9
- }
package/tsconfig.web.json DELETED
@@ -1,10 +0,0 @@
1
- {
2
- "extends": "./tsconfig.base.json",
3
- "compilerOptions": {
4
- "moduleResolution": "bundler",
5
- "jsx": "preserve",
6
- "jsxImportSource": "solid-js",
7
- "lib": ["DOM", "ESNext", "DOM.Iterable"],
8
- "types": ["vite/client"]
9
- }
10
- }