@f-o-t/config 0.1.0 → 1.0.3
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 +64 -16
- package/dist/index.d.ts +21 -1
- package/dist/index.js +8 -4
- package/package.json +6 -6
- package/src/factory.ts +24 -0
- package/src/generators/biome.ts +84 -0
- package/src/generators/index.ts +3 -0
- package/src/generators/package-json.ts +95 -0
- package/src/generators/tsconfig.ts +68 -0
- package/src/index.ts +4 -0
- package/src/schemas.ts +82 -0
- package/src/types.ts +112 -0
package/README.md
CHANGED
|
@@ -33,6 +33,8 @@ const config = defineFotConfig({
|
|
|
33
33
|
external: ["react", "react-dom"],
|
|
34
34
|
typescript: {
|
|
35
35
|
declaration: true,
|
|
36
|
+
isolatedDeclarations: false,
|
|
37
|
+
maxMemory: 4096,
|
|
36
38
|
},
|
|
37
39
|
biome: {
|
|
38
40
|
enabled: true,
|
|
@@ -61,23 +63,31 @@ The library provides generators to create standard configuration files for your
|
|
|
61
63
|
|
|
62
64
|
```typescript
|
|
63
65
|
import {
|
|
66
|
+
defineFotConfig,
|
|
64
67
|
generatePackageJson,
|
|
65
|
-
|
|
68
|
+
generateTSConfig,
|
|
66
69
|
generateBiomeConfig
|
|
67
70
|
} from "@f-o-t/config";
|
|
68
71
|
|
|
69
|
-
//
|
|
70
|
-
const
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
description: "My FOT library",
|
|
72
|
+
// First, define your configuration
|
|
73
|
+
const config = defineFotConfig({
|
|
74
|
+
external: ["zod"],
|
|
75
|
+
plugins: ["operators"],
|
|
74
76
|
});
|
|
75
77
|
|
|
78
|
+
// Generate package.json
|
|
79
|
+
const packageJson = generatePackageJson(
|
|
80
|
+
"my-library", // library name (without @f-o-t/ prefix)
|
|
81
|
+
"1.0.0", // version
|
|
82
|
+
config, // resolved config
|
|
83
|
+
{ "zod": "^4.3.6" } // optional custom dependencies
|
|
84
|
+
);
|
|
85
|
+
|
|
76
86
|
// Generate tsconfig.json
|
|
77
|
-
const tsconfig =
|
|
87
|
+
const tsconfig = generateTSConfig(config);
|
|
78
88
|
|
|
79
89
|
// Generate biome.json
|
|
80
|
-
const biomeConfig = generateBiomeConfig();
|
|
90
|
+
const biomeConfig = generateBiomeConfig(config);
|
|
81
91
|
```
|
|
82
92
|
|
|
83
93
|
## API Reference
|
|
@@ -117,7 +127,11 @@ Fully resolved configuration with all defaults applied:
|
|
|
117
127
|
interface ResolvedFotConfig {
|
|
118
128
|
formats: BuildFormat[];
|
|
119
129
|
external: string[];
|
|
120
|
-
typescript:
|
|
130
|
+
typescript: {
|
|
131
|
+
declaration: boolean;
|
|
132
|
+
isolatedDeclarations: boolean;
|
|
133
|
+
maxMemory?: number;
|
|
134
|
+
};
|
|
121
135
|
biome: Required<BiomeOptions>;
|
|
122
136
|
plugins: PluginConfig[];
|
|
123
137
|
}
|
|
@@ -133,7 +147,9 @@ type BuildFormat = "esm" | "cjs";
|
|
|
133
147
|
|
|
134
148
|
```typescript
|
|
135
149
|
interface TypeScriptOptions {
|
|
136
|
-
declaration?: boolean;
|
|
150
|
+
declaration?: boolean; // Generate .d.ts files (default: true)
|
|
151
|
+
isolatedDeclarations?: boolean; // Use isolated declarations mode for faster, more memory-efficient declaration generation (default: false)
|
|
152
|
+
maxMemory?: number; // Maximum memory (in MB) to allocate for TypeScript declaration generation (default: undefined)
|
|
137
153
|
}
|
|
138
154
|
```
|
|
139
155
|
|
|
@@ -156,24 +172,56 @@ interface PluginConfig {
|
|
|
156
172
|
|
|
157
173
|
## Generators
|
|
158
174
|
|
|
159
|
-
### `generatePackageJson(
|
|
175
|
+
### `generatePackageJson(libraryName, version, config, customDependencies?)`
|
|
160
176
|
|
|
161
177
|
Generates a standard package.json configuration for FOT libraries.
|
|
162
178
|
|
|
163
179
|
**Parameters:**
|
|
164
|
-
- `
|
|
180
|
+
- `libraryName`: Library name (without `@f-o-t/` prefix)
|
|
165
181
|
- `version`: Package version
|
|
166
|
-
- `
|
|
167
|
-
-
|
|
182
|
+
- `config`: Resolved FOT configuration (`ResolvedFotConfig`)
|
|
183
|
+
- `customDependencies` (optional): Custom dependencies to include in the package.json
|
|
168
184
|
|
|
169
|
-
|
|
185
|
+
**Returns:** `PackageJson` object
|
|
186
|
+
|
|
187
|
+
**Example:**
|
|
188
|
+
```typescript
|
|
189
|
+
const pkg = generatePackageJson(
|
|
190
|
+
"my-library",
|
|
191
|
+
"1.0.0",
|
|
192
|
+
config,
|
|
193
|
+
{ "zod": "^4.3.6" }
|
|
194
|
+
);
|
|
195
|
+
```
|
|
196
|
+
|
|
197
|
+
### `generateTSConfig(config)`
|
|
170
198
|
|
|
171
199
|
Generates a standard TypeScript configuration optimized for FOT libraries.
|
|
172
200
|
|
|
173
|
-
|
|
201
|
+
**Parameters:**
|
|
202
|
+
- `config`: Resolved FOT configuration (`ResolvedFotConfig`)
|
|
203
|
+
|
|
204
|
+
**Returns:** `TSConfig` object
|
|
205
|
+
|
|
206
|
+
**Example:**
|
|
207
|
+
```typescript
|
|
208
|
+
const tsconfig = generateTSConfig(config);
|
|
209
|
+
```
|
|
210
|
+
|
|
211
|
+
### `generateBiomeConfig(config)`
|
|
174
212
|
|
|
175
213
|
Generates a standard Biome configuration for linting and formatting.
|
|
176
214
|
|
|
215
|
+
**Parameters:**
|
|
216
|
+
- `config`: Resolved FOT configuration (`ResolvedFotConfig`)
|
|
217
|
+
|
|
218
|
+
**Returns:** `BiomeConfig` object
|
|
219
|
+
|
|
220
|
+
**Example:**
|
|
221
|
+
```typescript
|
|
222
|
+
const biomeConfig = generateBiomeConfig(config);
|
|
223
|
+
```
|
|
224
|
+
|
|
177
225
|
## License
|
|
178
226
|
|
|
179
227
|
MIT
|
package/dist/index.d.ts
CHANGED
|
@@ -11,6 +11,18 @@ interface TypeScriptOptions {
|
|
|
11
11
|
* @default true
|
|
12
12
|
*/
|
|
13
13
|
declaration?: boolean;
|
|
14
|
+
/**
|
|
15
|
+
* Use isolated declarations mode for faster, more memory-efficient declaration generation
|
|
16
|
+
* Requires TypeScript 5.5+
|
|
17
|
+
* @default false
|
|
18
|
+
*/
|
|
19
|
+
isolatedDeclarations?: boolean;
|
|
20
|
+
/**
|
|
21
|
+
* Maximum memory (in MB) to allocate for TypeScript declaration generation
|
|
22
|
+
* Useful for large libraries with complex types
|
|
23
|
+
* @default undefined (uses Node.js default ~2GB)
|
|
24
|
+
*/
|
|
25
|
+
maxMemory?: number;
|
|
14
26
|
}
|
|
15
27
|
/**
|
|
16
28
|
* Biome configuration options
|
|
@@ -79,7 +91,11 @@ interface ResolvedFotConfig {
|
|
|
79
91
|
/**
|
|
80
92
|
* TypeScript options
|
|
81
93
|
*/
|
|
82
|
-
typescript:
|
|
94
|
+
typescript: {
|
|
95
|
+
declaration: boolean;
|
|
96
|
+
isolatedDeclarations: boolean;
|
|
97
|
+
maxMemory?: number;
|
|
98
|
+
};
|
|
83
99
|
/**
|
|
84
100
|
* Biome options
|
|
85
101
|
*/
|
|
@@ -239,6 +255,8 @@ declare const pluginConfigSchema: z.ZodPipe<z.ZodUnion<readonly [z.ZodString, z.
|
|
|
239
255
|
*/
|
|
240
256
|
declare const typeScriptOptionsSchema: z.ZodDefault<z.ZodObject<{
|
|
241
257
|
declaration: z.ZodDefault<z.ZodBoolean>;
|
|
258
|
+
isolatedDeclarations: z.ZodDefault<z.ZodBoolean>;
|
|
259
|
+
maxMemory: z.ZodOptional<z.ZodNumber>;
|
|
242
260
|
}, z.core.$strip>>;
|
|
243
261
|
/**
|
|
244
262
|
* Schema for Biome configuration options
|
|
@@ -257,6 +275,8 @@ declare const fotConfigSchema: z.ZodObject<{
|
|
|
257
275
|
external: z.ZodDefault<z.ZodArray<z.ZodString>>;
|
|
258
276
|
typescript: z.ZodDefault<z.ZodObject<{
|
|
259
277
|
declaration: z.ZodDefault<z.ZodBoolean>;
|
|
278
|
+
isolatedDeclarations: z.ZodDefault<z.ZodBoolean>;
|
|
279
|
+
maxMemory: z.ZodOptional<z.ZodNumber>;
|
|
260
280
|
}, z.core.$strip>>;
|
|
261
281
|
biome: z.ZodDefault<z.ZodObject<{
|
|
262
282
|
enabled: z.ZodDefault<z.ZodBoolean>;
|
package/dist/index.js
CHANGED
|
@@ -15,8 +15,10 @@ var pluginConfigSchema = z.union([
|
|
|
15
15
|
return { name: val.name, enabled: val.enabled ?? true };
|
|
16
16
|
});
|
|
17
17
|
var typeScriptOptionsSchema = z.object({
|
|
18
|
-
declaration: z.boolean().default(true)
|
|
19
|
-
|
|
18
|
+
declaration: z.boolean().default(true),
|
|
19
|
+
isolatedDeclarations: z.boolean().default(false),
|
|
20
|
+
maxMemory: z.number().int().positive().optional()
|
|
21
|
+
}).default({ declaration: true, isolatedDeclarations: false });
|
|
20
22
|
var biomeOptionsSchema = z.object({
|
|
21
23
|
enabled: z.boolean().default(true)
|
|
22
24
|
}).default({ enabled: true });
|
|
@@ -123,11 +125,13 @@ function generatePackageJson(libraryName, version, config, customDependencies) {
|
|
|
123
125
|
}
|
|
124
126
|
// src/generators/tsconfig.ts
|
|
125
127
|
function generateTSConfig(config) {
|
|
128
|
+
const enabledPlugins = config.plugins.filter((p) => p.enabled !== false);
|
|
129
|
+
const pluginExcludes = enabledPlugins.map((p) => `src/plugins/${p.name}`);
|
|
126
130
|
return {
|
|
127
131
|
compilerOptions: {
|
|
128
132
|
allowImportingTsExtensions: true,
|
|
129
133
|
declaration: config.typescript.declaration,
|
|
130
|
-
isolatedDeclarations:
|
|
134
|
+
isolatedDeclarations: config.typescript.isolatedDeclarations,
|
|
131
135
|
module: "Preserve",
|
|
132
136
|
moduleDetection: "force",
|
|
133
137
|
moduleResolution: "bundler",
|
|
@@ -143,7 +147,7 @@ function generateTSConfig(config) {
|
|
|
143
147
|
target: "ES2023",
|
|
144
148
|
verbatimModuleSyntax: true
|
|
145
149
|
},
|
|
146
|
-
exclude: ["node_modules", "dist", "bunup.config.ts"],
|
|
150
|
+
exclude: ["node_modules", "dist", "bunup.config.ts", ...pluginExcludes],
|
|
147
151
|
include: ["src/**/*"]
|
|
148
152
|
};
|
|
149
153
|
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@f-o-t/config",
|
|
3
|
-
"version": "
|
|
3
|
+
"version": "1.0.3",
|
|
4
4
|
"description": "Standardized configuration for F-O-T libraries",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"module": "./dist/index.js",
|
|
@@ -11,13 +11,13 @@
|
|
|
11
11
|
"import": {
|
|
12
12
|
"default": "./dist/index.js",
|
|
13
13
|
"types": "./dist/index.d.ts"
|
|
14
|
-
}
|
|
15
|
-
"types": "./src/index.ts"
|
|
14
|
+
}
|
|
16
15
|
},
|
|
17
16
|
"./package.json": "./package.json"
|
|
18
17
|
},
|
|
19
18
|
"files": [
|
|
20
|
-
"dist"
|
|
19
|
+
"dist",
|
|
20
|
+
"src"
|
|
21
21
|
],
|
|
22
22
|
"scripts": {
|
|
23
23
|
"build": "bunup",
|
|
@@ -27,10 +27,10 @@
|
|
|
27
27
|
"test": "bun test",
|
|
28
28
|
"test:coverage": "bun test --coverage",
|
|
29
29
|
"test:watch": "bun test --watch",
|
|
30
|
-
"typecheck": "tsc"
|
|
30
|
+
"typecheck": "tsc --noEmit"
|
|
31
31
|
},
|
|
32
32
|
"dependencies": {
|
|
33
|
-
"zod": "4.3.6"
|
|
33
|
+
"zod": "^4.3.6"
|
|
34
34
|
},
|
|
35
35
|
"devDependencies": {
|
|
36
36
|
"@biomejs/biome": "2.3.12",
|
package/src/factory.ts
ADDED
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
import { fotConfigSchema } from "./schemas";
|
|
2
|
+
import type { FotConfig, ResolvedFotConfig } from "./types";
|
|
3
|
+
|
|
4
|
+
/**
|
|
5
|
+
* Factory function to define a FOT library configuration
|
|
6
|
+
* Validates the config against the schema and applies defaults
|
|
7
|
+
*
|
|
8
|
+
* @param config - The library configuration
|
|
9
|
+
* @returns The validated and normalized configuration with defaults applied
|
|
10
|
+
* @throws {Error} If the configuration is invalid
|
|
11
|
+
*/
|
|
12
|
+
export function defineFotConfig(config: FotConfig = {}): ResolvedFotConfig {
|
|
13
|
+
// Validate against schema (schema handles defaults and normalization)
|
|
14
|
+
const result = fotConfigSchema.safeParse(config);
|
|
15
|
+
|
|
16
|
+
if (!result.success) {
|
|
17
|
+
const errors = result.error.issues
|
|
18
|
+
.map((err) => `${err.path.join(".")}: ${err.message}`)
|
|
19
|
+
.join(", ");
|
|
20
|
+
throw new Error(`Invalid FOT configuration: ${errors}`);
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
return result.data;
|
|
24
|
+
}
|
|
@@ -0,0 +1,84 @@
|
|
|
1
|
+
import type { ResolvedFotConfig } from "../types";
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* Biome configuration structure
|
|
5
|
+
*/
|
|
6
|
+
export interface BiomeConfig {
|
|
7
|
+
$schema: string;
|
|
8
|
+
vcs: {
|
|
9
|
+
enabled: boolean;
|
|
10
|
+
clientKind: string;
|
|
11
|
+
useIgnoreFile: boolean;
|
|
12
|
+
defaultBranch: string;
|
|
13
|
+
};
|
|
14
|
+
files: {
|
|
15
|
+
ignoreUnknown: boolean;
|
|
16
|
+
ignore: string[];
|
|
17
|
+
};
|
|
18
|
+
formatter: {
|
|
19
|
+
enabled: boolean;
|
|
20
|
+
indentStyle: string;
|
|
21
|
+
indentWidth: number;
|
|
22
|
+
lineWidth: number;
|
|
23
|
+
};
|
|
24
|
+
organizeImports: {
|
|
25
|
+
enabled: boolean;
|
|
26
|
+
};
|
|
27
|
+
linter: {
|
|
28
|
+
enabled: boolean;
|
|
29
|
+
rules: {
|
|
30
|
+
recommended: boolean;
|
|
31
|
+
};
|
|
32
|
+
};
|
|
33
|
+
javascript: {
|
|
34
|
+
formatter: {
|
|
35
|
+
quoteStyle: string;
|
|
36
|
+
semicolons: string;
|
|
37
|
+
trailingCommas: string;
|
|
38
|
+
};
|
|
39
|
+
};
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
/**
|
|
43
|
+
* Generate a biome.json file from a resolved FOT configuration
|
|
44
|
+
*
|
|
45
|
+
* @param config - The resolved FOT configuration
|
|
46
|
+
* @returns The generated biome.json object
|
|
47
|
+
*/
|
|
48
|
+
export function generateBiomeConfig(config: ResolvedFotConfig): BiomeConfig {
|
|
49
|
+
return {
|
|
50
|
+
$schema: "https://biomejs.dev/schemas/1.9.4/schema.json",
|
|
51
|
+
vcs: {
|
|
52
|
+
enabled: true,
|
|
53
|
+
clientKind: "git",
|
|
54
|
+
useIgnoreFile: true,
|
|
55
|
+
defaultBranch: "main",
|
|
56
|
+
},
|
|
57
|
+
files: {
|
|
58
|
+
ignoreUnknown: false,
|
|
59
|
+
ignore: ["node_modules", "dist", "*.config.ts"],
|
|
60
|
+
},
|
|
61
|
+
formatter: {
|
|
62
|
+
enabled: config.biome.enabled,
|
|
63
|
+
indentStyle: "tab",
|
|
64
|
+
indentWidth: 2,
|
|
65
|
+
lineWidth: 80,
|
|
66
|
+
},
|
|
67
|
+
organizeImports: {
|
|
68
|
+
enabled: true,
|
|
69
|
+
},
|
|
70
|
+
linter: {
|
|
71
|
+
enabled: config.biome.enabled,
|
|
72
|
+
rules: {
|
|
73
|
+
recommended: true,
|
|
74
|
+
},
|
|
75
|
+
},
|
|
76
|
+
javascript: {
|
|
77
|
+
formatter: {
|
|
78
|
+
quoteStyle: "double",
|
|
79
|
+
semicolons: "always",
|
|
80
|
+
trailingCommas: "all",
|
|
81
|
+
},
|
|
82
|
+
},
|
|
83
|
+
};
|
|
84
|
+
}
|
|
@@ -0,0 +1,95 @@
|
|
|
1
|
+
import type { ResolvedFotConfig } from "../types";
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* Package.json export configuration
|
|
5
|
+
*/
|
|
6
|
+
export interface PackageExport {
|
|
7
|
+
types: string;
|
|
8
|
+
default: string;
|
|
9
|
+
}
|
|
10
|
+
|
|
11
|
+
/**
|
|
12
|
+
* Package.json structure
|
|
13
|
+
*/
|
|
14
|
+
export interface PackageJson {
|
|
15
|
+
name: string;
|
|
16
|
+
version: string;
|
|
17
|
+
type: "module";
|
|
18
|
+
main: string;
|
|
19
|
+
types: string;
|
|
20
|
+
exports: Record<string, PackageExport>;
|
|
21
|
+
scripts: Record<string, string>;
|
|
22
|
+
dependencies?: Record<string, string>;
|
|
23
|
+
devDependencies: Record<string, string>;
|
|
24
|
+
repository: {
|
|
25
|
+
type: "git";
|
|
26
|
+
url: string;
|
|
27
|
+
directory: string;
|
|
28
|
+
};
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
/**
|
|
32
|
+
* Generate a package.json file from a resolved FOT configuration
|
|
33
|
+
*
|
|
34
|
+
* @param libraryName - The name of the library (without @f-o-t/ prefix)
|
|
35
|
+
* @param version - The version of the library
|
|
36
|
+
* @param config - The resolved FOT configuration
|
|
37
|
+
* @param customDependencies - Optional custom dependencies to include
|
|
38
|
+
* @returns The generated package.json object
|
|
39
|
+
*/
|
|
40
|
+
export function generatePackageJson(
|
|
41
|
+
libraryName: string,
|
|
42
|
+
version: string,
|
|
43
|
+
config: ResolvedFotConfig,
|
|
44
|
+
customDependencies?: Record<string, string>,
|
|
45
|
+
): PackageJson {
|
|
46
|
+
// Generate exports for main entry point
|
|
47
|
+
const exports: Record<string, PackageExport> = {
|
|
48
|
+
".": {
|
|
49
|
+
types: "./dist/index.d.ts",
|
|
50
|
+
default: "./dist/index.js",
|
|
51
|
+
},
|
|
52
|
+
};
|
|
53
|
+
|
|
54
|
+
// Generate exports for each plugin
|
|
55
|
+
for (const plugin of config.plugins) {
|
|
56
|
+
if (plugin.enabled !== false) {
|
|
57
|
+
exports[`./plugins/${plugin.name}`] = {
|
|
58
|
+
types: `./dist/plugins/${plugin.name}/index.d.ts`,
|
|
59
|
+
default: `./dist/plugins/${plugin.name}/index.js`,
|
|
60
|
+
};
|
|
61
|
+
}
|
|
62
|
+
}
|
|
63
|
+
|
|
64
|
+
// Build package.json structure
|
|
65
|
+
const pkg: PackageJson = {
|
|
66
|
+
name: `@f-o-t/${libraryName}`,
|
|
67
|
+
version,
|
|
68
|
+
type: "module",
|
|
69
|
+
main: "./dist/index.js",
|
|
70
|
+
types: "./dist/index.d.ts",
|
|
71
|
+
exports,
|
|
72
|
+
scripts: {
|
|
73
|
+
build: "fot build",
|
|
74
|
+
test: "fot test",
|
|
75
|
+
lint: "fot lint",
|
|
76
|
+
format: "fot format",
|
|
77
|
+
},
|
|
78
|
+
devDependencies: {
|
|
79
|
+
"@f-o-t/cli": "workspace:*",
|
|
80
|
+
"@f-o-t/config": "workspace:*",
|
|
81
|
+
},
|
|
82
|
+
repository: {
|
|
83
|
+
type: "git",
|
|
84
|
+
url: "https://github.com/F-O-T/libraries.git",
|
|
85
|
+
directory: `libraries/${libraryName}`,
|
|
86
|
+
},
|
|
87
|
+
};
|
|
88
|
+
|
|
89
|
+
// Add custom dependencies if provided
|
|
90
|
+
if (customDependencies && Object.keys(customDependencies).length > 0) {
|
|
91
|
+
pkg.dependencies = customDependencies;
|
|
92
|
+
}
|
|
93
|
+
|
|
94
|
+
return pkg;
|
|
95
|
+
}
|
|
@@ -0,0 +1,68 @@
|
|
|
1
|
+
import type { ResolvedFotConfig } from "../types";
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* TypeScript configuration structure
|
|
5
|
+
*/
|
|
6
|
+
export interface TSConfig {
|
|
7
|
+
compilerOptions: {
|
|
8
|
+
allowImportingTsExtensions: boolean;
|
|
9
|
+
declaration: boolean;
|
|
10
|
+
isolatedDeclarations: boolean;
|
|
11
|
+
module: string;
|
|
12
|
+
moduleDetection: string;
|
|
13
|
+
moduleResolution: string;
|
|
14
|
+
noEmit: boolean;
|
|
15
|
+
noFallthroughCasesInSwitch: boolean;
|
|
16
|
+
noImplicitOverride: boolean;
|
|
17
|
+
noPropertyAccessFromIndexSignature: boolean;
|
|
18
|
+
noUncheckedIndexedAccess: boolean;
|
|
19
|
+
noUnusedLocals: boolean;
|
|
20
|
+
noUnusedParameters: boolean;
|
|
21
|
+
skipLibCheck: boolean;
|
|
22
|
+
strict: boolean;
|
|
23
|
+
target: string;
|
|
24
|
+
verbatimModuleSyntax: boolean;
|
|
25
|
+
};
|
|
26
|
+
exclude: string[];
|
|
27
|
+
include: string[];
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
/**
|
|
31
|
+
* Generate a tsconfig.json file from a resolved FOT configuration
|
|
32
|
+
*
|
|
33
|
+
* @param config - The resolved FOT configuration
|
|
34
|
+
* @returns The generated tsconfig.json object
|
|
35
|
+
*/
|
|
36
|
+
export function generateTSConfig(config: ResolvedFotConfig): TSConfig {
|
|
37
|
+
// Exclude plugin directories from main tsconfig so their dependencies
|
|
38
|
+
// (e.g., @f-o-t/condition-evaluator) don't get type-checked in the main pass.
|
|
39
|
+
// Plugin declarations are handled separately by the build system.
|
|
40
|
+
const enabledPlugins = config.plugins.filter((p) => p.enabled !== false);
|
|
41
|
+
const pluginExcludes = enabledPlugins.map(
|
|
42
|
+
(p) => `src/plugins/${p.name}`,
|
|
43
|
+
);
|
|
44
|
+
|
|
45
|
+
return {
|
|
46
|
+
compilerOptions: {
|
|
47
|
+
allowImportingTsExtensions: true,
|
|
48
|
+
declaration: config.typescript.declaration,
|
|
49
|
+
isolatedDeclarations: config.typescript.isolatedDeclarations,
|
|
50
|
+
module: "Preserve",
|
|
51
|
+
moduleDetection: "force",
|
|
52
|
+
moduleResolution: "bundler",
|
|
53
|
+
noEmit: true,
|
|
54
|
+
noFallthroughCasesInSwitch: true,
|
|
55
|
+
noImplicitOverride: true,
|
|
56
|
+
noPropertyAccessFromIndexSignature: false,
|
|
57
|
+
noUncheckedIndexedAccess: true,
|
|
58
|
+
noUnusedLocals: false,
|
|
59
|
+
noUnusedParameters: false,
|
|
60
|
+
skipLibCheck: true,
|
|
61
|
+
strict: true,
|
|
62
|
+
target: "ES2023",
|
|
63
|
+
verbatimModuleSyntax: true,
|
|
64
|
+
},
|
|
65
|
+
exclude: ["node_modules", "dist", "bunup.config.ts", ...pluginExcludes],
|
|
66
|
+
include: ["src/**/*"],
|
|
67
|
+
};
|
|
68
|
+
}
|
package/src/index.ts
ADDED
package/src/schemas.ts
ADDED
|
@@ -0,0 +1,82 @@
|
|
|
1
|
+
import { z } from "zod";
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* Regex for validating npm package names (scoped and unscoped)
|
|
5
|
+
* - Must be lowercase
|
|
6
|
+
* - Can contain hyphens, dots, underscores
|
|
7
|
+
* - Scoped packages: @scope/name
|
|
8
|
+
* - Cannot start with dot or underscore
|
|
9
|
+
*/
|
|
10
|
+
const packageNameRegex =
|
|
11
|
+
/^(@[a-z0-9-~][a-z0-9-._~]*\/)?[a-z0-9-~][a-z0-9-._~]*$/;
|
|
12
|
+
|
|
13
|
+
/**
|
|
14
|
+
* Schema for build output formats
|
|
15
|
+
*/
|
|
16
|
+
export const buildFormatSchema = z.enum(["esm", "cjs"]);
|
|
17
|
+
|
|
18
|
+
/**
|
|
19
|
+
* Schema for plugin configuration
|
|
20
|
+
* Accepts either a string (plugin name) or a config object
|
|
21
|
+
*/
|
|
22
|
+
export const pluginConfigSchema = z
|
|
23
|
+
.union([
|
|
24
|
+
z.string(),
|
|
25
|
+
z.object({
|
|
26
|
+
name: z.string(),
|
|
27
|
+
enabled: z.boolean().default(true),
|
|
28
|
+
}),
|
|
29
|
+
])
|
|
30
|
+
.transform((val) => {
|
|
31
|
+
if (typeof val === "string") {
|
|
32
|
+
return { name: val, enabled: true };
|
|
33
|
+
}
|
|
34
|
+
return { name: val.name, enabled: val.enabled ?? true };
|
|
35
|
+
});
|
|
36
|
+
|
|
37
|
+
/**
|
|
38
|
+
* Schema for TypeScript compiler options
|
|
39
|
+
*/
|
|
40
|
+
export const typeScriptOptionsSchema = z
|
|
41
|
+
.object({
|
|
42
|
+
declaration: z.boolean().default(true),
|
|
43
|
+
isolatedDeclarations: z.boolean().default(false),
|
|
44
|
+
maxMemory: z.number().int().positive().optional(),
|
|
45
|
+
})
|
|
46
|
+
.default({ declaration: true, isolatedDeclarations: false });
|
|
47
|
+
|
|
48
|
+
/**
|
|
49
|
+
* Schema for Biome configuration options
|
|
50
|
+
*/
|
|
51
|
+
export const biomeOptionsSchema = z
|
|
52
|
+
.object({
|
|
53
|
+
enabled: z.boolean().default(true),
|
|
54
|
+
})
|
|
55
|
+
.default({ enabled: true });
|
|
56
|
+
|
|
57
|
+
/**
|
|
58
|
+
* Schema for FOT configuration
|
|
59
|
+
*/
|
|
60
|
+
export const fotConfigSchema = z.object({
|
|
61
|
+
formats: z.array(buildFormatSchema).default(["esm"]),
|
|
62
|
+
external: z
|
|
63
|
+
.array(
|
|
64
|
+
z.string().regex(packageNameRegex, {
|
|
65
|
+
message: "Invalid package name format",
|
|
66
|
+
}),
|
|
67
|
+
)
|
|
68
|
+
.default([]),
|
|
69
|
+
typescript: typeScriptOptionsSchema,
|
|
70
|
+
biome: biomeOptionsSchema,
|
|
71
|
+
plugins: z.array(pluginConfigSchema).default([]),
|
|
72
|
+
});
|
|
73
|
+
|
|
74
|
+
/**
|
|
75
|
+
* Type for input configuration (before validation and defaults)
|
|
76
|
+
*/
|
|
77
|
+
export type FotConfigInput = z.input<typeof fotConfigSchema>;
|
|
78
|
+
|
|
79
|
+
/**
|
|
80
|
+
* Type for output configuration (after validation and defaults)
|
|
81
|
+
*/
|
|
82
|
+
export type FotConfigOutput = z.output<typeof fotConfigSchema>;
|
package/src/types.ts
ADDED
|
@@ -0,0 +1,112 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Build output formats
|
|
3
|
+
*/
|
|
4
|
+
export type BuildFormat = "esm" | "cjs";
|
|
5
|
+
|
|
6
|
+
/**
|
|
7
|
+
* TypeScript compiler options for the build
|
|
8
|
+
*/
|
|
9
|
+
export interface TypeScriptOptions {
|
|
10
|
+
/**
|
|
11
|
+
* Generate .d.ts declaration files
|
|
12
|
+
* @default true
|
|
13
|
+
*/
|
|
14
|
+
declaration?: boolean;
|
|
15
|
+
/**
|
|
16
|
+
* Use isolated declarations mode for faster, more memory-efficient declaration generation
|
|
17
|
+
* Requires TypeScript 5.5+
|
|
18
|
+
* @default false
|
|
19
|
+
*/
|
|
20
|
+
isolatedDeclarations?: boolean;
|
|
21
|
+
/**
|
|
22
|
+
* Maximum memory (in MB) to allocate for TypeScript declaration generation
|
|
23
|
+
* Useful for large libraries with complex types
|
|
24
|
+
* @default undefined (uses Node.js default ~2GB)
|
|
25
|
+
*/
|
|
26
|
+
maxMemory?: number;
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
/**
|
|
30
|
+
* Biome configuration options
|
|
31
|
+
*/
|
|
32
|
+
export interface BiomeOptions {
|
|
33
|
+
/**
|
|
34
|
+
* Enable Biome for linting/formatting
|
|
35
|
+
* @default true
|
|
36
|
+
*/
|
|
37
|
+
enabled?: boolean;
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
/**
|
|
41
|
+
* Plugin configuration
|
|
42
|
+
*/
|
|
43
|
+
export interface PluginConfig {
|
|
44
|
+
/**
|
|
45
|
+
* Name of the plugin
|
|
46
|
+
*/
|
|
47
|
+
name: string;
|
|
48
|
+
/**
|
|
49
|
+
* Whether the plugin is enabled
|
|
50
|
+
* @default true
|
|
51
|
+
*/
|
|
52
|
+
enabled?: boolean;
|
|
53
|
+
}
|
|
54
|
+
|
|
55
|
+
/**
|
|
56
|
+
* User-provided configuration for FOT libraries
|
|
57
|
+
*/
|
|
58
|
+
export interface FotConfig {
|
|
59
|
+
/**
|
|
60
|
+
* Build output formats
|
|
61
|
+
* @default ["esm"]
|
|
62
|
+
*/
|
|
63
|
+
formats?: BuildFormat[];
|
|
64
|
+
/**
|
|
65
|
+
* External dependencies that should not be bundled
|
|
66
|
+
* @default []
|
|
67
|
+
*/
|
|
68
|
+
external?: string[];
|
|
69
|
+
/**
|
|
70
|
+
* TypeScript options
|
|
71
|
+
*/
|
|
72
|
+
typescript?: TypeScriptOptions;
|
|
73
|
+
/**
|
|
74
|
+
* Biome options
|
|
75
|
+
*/
|
|
76
|
+
biome?: BiomeOptions;
|
|
77
|
+
/**
|
|
78
|
+
* Plugins to load - can be plugin names as strings or config objects
|
|
79
|
+
* @default []
|
|
80
|
+
*/
|
|
81
|
+
plugins?: (string | PluginConfig)[];
|
|
82
|
+
}
|
|
83
|
+
|
|
84
|
+
/**
|
|
85
|
+
* Resolved configuration with all defaults applied
|
|
86
|
+
*/
|
|
87
|
+
export interface ResolvedFotConfig {
|
|
88
|
+
/**
|
|
89
|
+
* Build output formats
|
|
90
|
+
*/
|
|
91
|
+
formats: BuildFormat[];
|
|
92
|
+
/**
|
|
93
|
+
* External dependencies that should not be bundled
|
|
94
|
+
*/
|
|
95
|
+
external: string[];
|
|
96
|
+
/**
|
|
97
|
+
* TypeScript options
|
|
98
|
+
*/
|
|
99
|
+
typescript: {
|
|
100
|
+
declaration: boolean;
|
|
101
|
+
isolatedDeclarations: boolean;
|
|
102
|
+
maxMemory?: number;
|
|
103
|
+
};
|
|
104
|
+
/**
|
|
105
|
+
* Biome options
|
|
106
|
+
*/
|
|
107
|
+
biome: Required<BiomeOptions>;
|
|
108
|
+
/**
|
|
109
|
+
* Plugins to load (normalized to config objects)
|
|
110
|
+
*/
|
|
111
|
+
plugins: PluginConfig[];
|
|
112
|
+
}
|