@f-o-t/config 0.1.0 → 1.0.4
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/LICENSE +21 -0
- package/README.md +64 -16
- package/dist/index.d.ts +25 -2
- package/dist/index.js +10 -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 +100 -0
- package/src/generators/tsconfig.ts +66 -0
- package/src/index.ts +4 -0
- package/src/schemas.ts +82 -0
- package/src/types.ts +112 -0
package/LICENSE
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2026 FOT (F-O-T)
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
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
|
*/
|
|
@@ -144,10 +160,13 @@ interface BiomeConfig {
|
|
|
144
160
|
*/
|
|
145
161
|
declare function generateBiomeConfig(config: ResolvedFotConfig): BiomeConfig;
|
|
146
162
|
/**
|
|
147
|
-
* Package.json configuration
|
|
163
|
+
* Package.json configuration.
|
|
164
|
+
* Includes "import" condition so bundlers/Vite can resolve ESM entries
|
|
165
|
+
* under conditions like ["module", "browser", "import"].
|
|
148
166
|
*/
|
|
149
167
|
interface PackageExport {
|
|
150
168
|
types: string;
|
|
169
|
+
import: string;
|
|
151
170
|
default: string;
|
|
152
171
|
}
|
|
153
172
|
/**
|
|
@@ -239,6 +258,8 @@ declare const pluginConfigSchema: z.ZodPipe<z.ZodUnion<readonly [z.ZodString, z.
|
|
|
239
258
|
*/
|
|
240
259
|
declare const typeScriptOptionsSchema: z.ZodDefault<z.ZodObject<{
|
|
241
260
|
declaration: z.ZodDefault<z.ZodBoolean>;
|
|
261
|
+
isolatedDeclarations: z.ZodDefault<z.ZodBoolean>;
|
|
262
|
+
maxMemory: z.ZodOptional<z.ZodNumber>;
|
|
242
263
|
}, z.core.$strip>>;
|
|
243
264
|
/**
|
|
244
265
|
* Schema for Biome configuration options
|
|
@@ -257,6 +278,8 @@ declare const fotConfigSchema: z.ZodObject<{
|
|
|
257
278
|
external: z.ZodDefault<z.ZodArray<z.ZodString>>;
|
|
258
279
|
typescript: z.ZodDefault<z.ZodObject<{
|
|
259
280
|
declaration: z.ZodDefault<z.ZodBoolean>;
|
|
281
|
+
isolatedDeclarations: z.ZodDefault<z.ZodBoolean>;
|
|
282
|
+
maxMemory: z.ZodOptional<z.ZodNumber>;
|
|
260
283
|
}, z.core.$strip>>;
|
|
261
284
|
biome: z.ZodDefault<z.ZodObject<{
|
|
262
285
|
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 });
|
|
@@ -82,6 +84,7 @@ function generatePackageJson(libraryName, version, config, customDependencies) {
|
|
|
82
84
|
const exports = {
|
|
83
85
|
".": {
|
|
84
86
|
types: "./dist/index.d.ts",
|
|
87
|
+
import: "./dist/index.js",
|
|
85
88
|
default: "./dist/index.js"
|
|
86
89
|
}
|
|
87
90
|
};
|
|
@@ -89,6 +92,7 @@ function generatePackageJson(libraryName, version, config, customDependencies) {
|
|
|
89
92
|
if (plugin.enabled !== false) {
|
|
90
93
|
exports[`./plugins/${plugin.name}`] = {
|
|
91
94
|
types: `./dist/plugins/${plugin.name}/index.d.ts`,
|
|
95
|
+
import: `./dist/plugins/${plugin.name}/index.js`,
|
|
92
96
|
default: `./dist/plugins/${plugin.name}/index.js`
|
|
93
97
|
};
|
|
94
98
|
}
|
|
@@ -123,11 +127,13 @@ function generatePackageJson(libraryName, version, config, customDependencies) {
|
|
|
123
127
|
}
|
|
124
128
|
// src/generators/tsconfig.ts
|
|
125
129
|
function generateTSConfig(config) {
|
|
130
|
+
const enabledPlugins = config.plugins.filter((p) => p.enabled !== false);
|
|
131
|
+
const pluginExcludes = enabledPlugins.map((p) => `src/plugins/${p.name}`);
|
|
126
132
|
return {
|
|
127
133
|
compilerOptions: {
|
|
128
134
|
allowImportingTsExtensions: true,
|
|
129
135
|
declaration: config.typescript.declaration,
|
|
130
|
-
isolatedDeclarations:
|
|
136
|
+
isolatedDeclarations: config.typescript.isolatedDeclarations,
|
|
131
137
|
module: "Preserve",
|
|
132
138
|
moduleDetection: "force",
|
|
133
139
|
moduleResolution: "bundler",
|
|
@@ -143,7 +149,7 @@ function generateTSConfig(config) {
|
|
|
143
149
|
target: "ES2023",
|
|
144
150
|
verbatimModuleSyntax: true
|
|
145
151
|
},
|
|
146
|
-
exclude: ["node_modules", "dist", "bunup.config.ts"],
|
|
152
|
+
exclude: ["node_modules", "dist", "bunup.config.ts", ...pluginExcludes],
|
|
147
153
|
include: ["src/**/*"]
|
|
148
154
|
};
|
|
149
155
|
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@f-o-t/config",
|
|
3
|
-
"version": "
|
|
3
|
+
"version": "1.0.4",
|
|
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,100 @@
|
|
|
1
|
+
import type { ResolvedFotConfig } from "../types";
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* Package.json export configuration.
|
|
5
|
+
* Includes "import" condition so bundlers/Vite can resolve ESM entries
|
|
6
|
+
* under conditions like ["module", "browser", "import"].
|
|
7
|
+
*/
|
|
8
|
+
export interface PackageExport {
|
|
9
|
+
types: string;
|
|
10
|
+
import: string;
|
|
11
|
+
default: string;
|
|
12
|
+
}
|
|
13
|
+
|
|
14
|
+
/**
|
|
15
|
+
* Package.json structure
|
|
16
|
+
*/
|
|
17
|
+
export interface PackageJson {
|
|
18
|
+
name: string;
|
|
19
|
+
version: string;
|
|
20
|
+
type: "module";
|
|
21
|
+
main: string;
|
|
22
|
+
types: string;
|
|
23
|
+
exports: Record<string, PackageExport>;
|
|
24
|
+
scripts: Record<string, string>;
|
|
25
|
+
dependencies?: Record<string, string>;
|
|
26
|
+
devDependencies: Record<string, string>;
|
|
27
|
+
repository: {
|
|
28
|
+
type: "git";
|
|
29
|
+
url: string;
|
|
30
|
+
directory: string;
|
|
31
|
+
};
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
/**
|
|
35
|
+
* Generate a package.json file from a resolved FOT configuration
|
|
36
|
+
*
|
|
37
|
+
* @param libraryName - The name of the library (without @f-o-t/ prefix)
|
|
38
|
+
* @param version - The version of the library
|
|
39
|
+
* @param config - The resolved FOT configuration
|
|
40
|
+
* @param customDependencies - Optional custom dependencies to include
|
|
41
|
+
* @returns The generated package.json object
|
|
42
|
+
*/
|
|
43
|
+
export function generatePackageJson(
|
|
44
|
+
libraryName: string,
|
|
45
|
+
version: string,
|
|
46
|
+
config: ResolvedFotConfig,
|
|
47
|
+
customDependencies?: Record<string, string>,
|
|
48
|
+
): PackageJson {
|
|
49
|
+
// Generate exports for main entry point
|
|
50
|
+
const exports: Record<string, PackageExport> = {
|
|
51
|
+
".": {
|
|
52
|
+
types: "./dist/index.d.ts",
|
|
53
|
+
import: "./dist/index.js",
|
|
54
|
+
default: "./dist/index.js",
|
|
55
|
+
},
|
|
56
|
+
};
|
|
57
|
+
|
|
58
|
+
// Generate exports for each plugin
|
|
59
|
+
for (const plugin of config.plugins) {
|
|
60
|
+
if (plugin.enabled !== false) {
|
|
61
|
+
exports[`./plugins/${plugin.name}`] = {
|
|
62
|
+
types: `./dist/plugins/${plugin.name}/index.d.ts`,
|
|
63
|
+
import: `./dist/plugins/${plugin.name}/index.js`,
|
|
64
|
+
default: `./dist/plugins/${plugin.name}/index.js`,
|
|
65
|
+
};
|
|
66
|
+
}
|
|
67
|
+
}
|
|
68
|
+
|
|
69
|
+
// Build package.json structure
|
|
70
|
+
const pkg: PackageJson = {
|
|
71
|
+
name: `@f-o-t/${libraryName}`,
|
|
72
|
+
version,
|
|
73
|
+
type: "module",
|
|
74
|
+
main: "./dist/index.js",
|
|
75
|
+
types: "./dist/index.d.ts",
|
|
76
|
+
exports,
|
|
77
|
+
scripts: {
|
|
78
|
+
build: "fot build",
|
|
79
|
+
test: "fot test",
|
|
80
|
+
lint: "fot lint",
|
|
81
|
+
format: "fot format",
|
|
82
|
+
},
|
|
83
|
+
devDependencies: {
|
|
84
|
+
"@f-o-t/cli": "workspace:*",
|
|
85
|
+
"@f-o-t/config": "workspace:*",
|
|
86
|
+
},
|
|
87
|
+
repository: {
|
|
88
|
+
type: "git",
|
|
89
|
+
url: "https://github.com/F-O-T/libraries.git",
|
|
90
|
+
directory: `libraries/${libraryName}`,
|
|
91
|
+
},
|
|
92
|
+
};
|
|
93
|
+
|
|
94
|
+
// Add custom dependencies if provided
|
|
95
|
+
if (customDependencies && Object.keys(customDependencies).length > 0) {
|
|
96
|
+
pkg.dependencies = customDependencies;
|
|
97
|
+
}
|
|
98
|
+
|
|
99
|
+
return pkg;
|
|
100
|
+
}
|
|
@@ -0,0 +1,66 @@
|
|
|
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((p) => `src/plugins/${p.name}`);
|
|
42
|
+
|
|
43
|
+
return {
|
|
44
|
+
compilerOptions: {
|
|
45
|
+
allowImportingTsExtensions: true,
|
|
46
|
+
declaration: config.typescript.declaration,
|
|
47
|
+
isolatedDeclarations: config.typescript.isolatedDeclarations,
|
|
48
|
+
module: "Preserve",
|
|
49
|
+
moduleDetection: "force",
|
|
50
|
+
moduleResolution: "bundler",
|
|
51
|
+
noEmit: true,
|
|
52
|
+
noFallthroughCasesInSwitch: true,
|
|
53
|
+
noImplicitOverride: true,
|
|
54
|
+
noPropertyAccessFromIndexSignature: false,
|
|
55
|
+
noUncheckedIndexedAccess: true,
|
|
56
|
+
noUnusedLocals: false,
|
|
57
|
+
noUnusedParameters: false,
|
|
58
|
+
skipLibCheck: true,
|
|
59
|
+
strict: true,
|
|
60
|
+
target: "ES2023",
|
|
61
|
+
verbatimModuleSyntax: true,
|
|
62
|
+
},
|
|
63
|
+
exclude: ["node_modules", "dist", "bunup.config.ts", ...pluginExcludes],
|
|
64
|
+
include: ["src/**/*"],
|
|
65
|
+
};
|
|
66
|
+
}
|
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
|
+
}
|