@zthun/janitor-build-config 19.0.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/LICENSE.md +20 -0
- package/README.md +13 -0
- package/dist/typedoc/index.d.ts +1 -0
- package/dist/typedoc/typedoc-config-builder.d.mts +142 -0
- package/dist/typedoc/typedoc-config-builder.spec.d.ts +1 -0
- package/dist/typedoc.cjs +181 -0
- package/dist/typedoc.cjs.map +1 -0
- package/dist/typedoc.js +177 -0
- package/dist/typedoc.js.map +1 -0
- package/dist/vite/index.d.ts +3 -0
- package/dist/vite/vite-config-builder.d.mts +92 -0
- package/dist/vite/vite-config-builder.spec.d.ts +1 -0
- package/dist/vite/vite-library-builder.d.mts +34 -0
- package/dist/vite/vite-library-builder.spec.d.ts +1 -0
- package/dist/vite/vite-test-builder.d.mts +66 -0
- package/dist/vite/vite-test-builder.spec.d.ts +1 -0
- package/dist/vite.cjs +341 -0
- package/dist/vite.cjs.map +1 -0
- package/dist/vite.js +335 -0
- package/dist/vite.js.map +1 -0
- package/package.json +64 -0
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
import { LibraryOptions } from 'vite';
|
|
2
|
+
/**
|
|
3
|
+
* A builder for Vite library configurations.
|
|
4
|
+
*/
|
|
5
|
+
export declare class ZViteLibraryBuilder {
|
|
6
|
+
private library;
|
|
7
|
+
/**
|
|
8
|
+
* Adds an entry point to the library.
|
|
9
|
+
*
|
|
10
|
+
* @param name -
|
|
11
|
+
* The name of the entry point.
|
|
12
|
+
* @param path -
|
|
13
|
+
* The path to the entry point file.
|
|
14
|
+
*
|
|
15
|
+
* @returns
|
|
16
|
+
* This object.
|
|
17
|
+
*/
|
|
18
|
+
entry(name: string, path: string): this;
|
|
19
|
+
/**
|
|
20
|
+
* A shorthand for adding an entry point
|
|
21
|
+
* named "index" that points to "src/index.ts"
|
|
22
|
+
*
|
|
23
|
+
* @returns
|
|
24
|
+
* This object.
|
|
25
|
+
*/
|
|
26
|
+
index(): this;
|
|
27
|
+
/**
|
|
28
|
+
* Returns the built library configuration.
|
|
29
|
+
*
|
|
30
|
+
* @returns
|
|
31
|
+
* A deep clone of the library configuration.
|
|
32
|
+
*/
|
|
33
|
+
build(): LibraryOptions;
|
|
34
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -0,0 +1,66 @@
|
|
|
1
|
+
import { InlineConfig, VitestEnvironment } from 'vitest/node';
|
|
2
|
+
/**
|
|
3
|
+
* A builder for test configurations found in vite's defineConfig test field.
|
|
4
|
+
*/
|
|
5
|
+
export declare class ZViteTestBuilder {
|
|
6
|
+
private test;
|
|
7
|
+
/**
|
|
8
|
+
* Initializes a new instance of this object.
|
|
9
|
+
*/
|
|
10
|
+
constructor();
|
|
11
|
+
/**
|
|
12
|
+
* Sets the test environment.
|
|
13
|
+
*
|
|
14
|
+
* @param environment -
|
|
15
|
+
* The test environment to use.
|
|
16
|
+
*
|
|
17
|
+
* @returns
|
|
18
|
+
* This object.
|
|
19
|
+
*/
|
|
20
|
+
environment(environment: VitestEnvironment): this;
|
|
21
|
+
/**
|
|
22
|
+
* Sets the test environment to "node".
|
|
23
|
+
*
|
|
24
|
+
* @returns
|
|
25
|
+
* This object.
|
|
26
|
+
*/
|
|
27
|
+
node: () => this;
|
|
28
|
+
/**
|
|
29
|
+
* Sets the test environment to "happy-dom".
|
|
30
|
+
*
|
|
31
|
+
* @returns
|
|
32
|
+
* This object.
|
|
33
|
+
*/
|
|
34
|
+
browser: () => this;
|
|
35
|
+
/**
|
|
36
|
+
* Sets the test coverage provider.
|
|
37
|
+
*
|
|
38
|
+
* @param provider -
|
|
39
|
+
* The test coverage provider to use.
|
|
40
|
+
*
|
|
41
|
+
* @returns
|
|
42
|
+
* This object.
|
|
43
|
+
*/
|
|
44
|
+
coverage(provider: "v8" | "istanbul"): this;
|
|
45
|
+
/**
|
|
46
|
+
* Sets the test coverage provider to "v8".
|
|
47
|
+
*
|
|
48
|
+
* @returns
|
|
49
|
+
* This object.
|
|
50
|
+
*/
|
|
51
|
+
v8: () => this;
|
|
52
|
+
/**
|
|
53
|
+
* Sets the test coverage provider to "istanbul".
|
|
54
|
+
*
|
|
55
|
+
* @returns
|
|
56
|
+
* This object.
|
|
57
|
+
*/
|
|
58
|
+
istanbul: () => this;
|
|
59
|
+
/**
|
|
60
|
+
* Returns the built test configuration.
|
|
61
|
+
*
|
|
62
|
+
* @returns
|
|
63
|
+
* A deep clone of the test configuration.
|
|
64
|
+
*/
|
|
65
|
+
build(): InlineConfig;
|
|
66
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
package/dist/vite.cjs
ADDED
|
@@ -0,0 +1,341 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, Symbol.toStringTag, { value: 'Module' });
|
|
4
|
+
|
|
5
|
+
const lodashEs = require('lodash-es');
|
|
6
|
+
const swc = require('unplugin-swc');
|
|
7
|
+
const dtsPlugin = require('vite-plugin-dts');
|
|
8
|
+
const vitePluginExternalizeDeps = require('vite-plugin-externalize-deps');
|
|
9
|
+
const tsConfigPaths = require('vite-tsconfig-paths');
|
|
10
|
+
|
|
11
|
+
function _define_property$2(obj, key, value) {
|
|
12
|
+
if (key in obj) {
|
|
13
|
+
Object.defineProperty(obj, key, {
|
|
14
|
+
value: value,
|
|
15
|
+
enumerable: true,
|
|
16
|
+
configurable: true,
|
|
17
|
+
writable: true
|
|
18
|
+
});
|
|
19
|
+
} else {
|
|
20
|
+
obj[key] = value;
|
|
21
|
+
}
|
|
22
|
+
return obj;
|
|
23
|
+
}
|
|
24
|
+
function _object_spread(target) {
|
|
25
|
+
for(var i = 1; i < arguments.length; i++){
|
|
26
|
+
var source = arguments[i] != null ? arguments[i] : {};
|
|
27
|
+
var ownKeys = Object.keys(source);
|
|
28
|
+
if (typeof Object.getOwnPropertySymbols === "function") {
|
|
29
|
+
ownKeys = ownKeys.concat(Object.getOwnPropertySymbols(source).filter(function(sym) {
|
|
30
|
+
return Object.getOwnPropertyDescriptor(source, sym).enumerable;
|
|
31
|
+
}));
|
|
32
|
+
}
|
|
33
|
+
ownKeys.forEach(function(key) {
|
|
34
|
+
_define_property$2(target, key, source[key]);
|
|
35
|
+
});
|
|
36
|
+
}
|
|
37
|
+
return target;
|
|
38
|
+
}
|
|
39
|
+
function ownKeys(object, enumerableOnly) {
|
|
40
|
+
var keys = Object.keys(object);
|
|
41
|
+
if (Object.getOwnPropertySymbols) {
|
|
42
|
+
var symbols = Object.getOwnPropertySymbols(object);
|
|
43
|
+
keys.push.apply(keys, symbols);
|
|
44
|
+
}
|
|
45
|
+
return keys;
|
|
46
|
+
}
|
|
47
|
+
function _object_spread_props(target, source) {
|
|
48
|
+
source = source != null ? source : {};
|
|
49
|
+
if (Object.getOwnPropertyDescriptors) {
|
|
50
|
+
Object.defineProperties(target, Object.getOwnPropertyDescriptors(source));
|
|
51
|
+
} else {
|
|
52
|
+
ownKeys(Object(source)).forEach(function(key) {
|
|
53
|
+
Object.defineProperty(target, key, Object.getOwnPropertyDescriptor(source, key));
|
|
54
|
+
});
|
|
55
|
+
}
|
|
56
|
+
return target;
|
|
57
|
+
}
|
|
58
|
+
/**
|
|
59
|
+
* A builder for Vite library configurations.
|
|
60
|
+
*/ class ZViteLibraryBuilder {
|
|
61
|
+
/**
|
|
62
|
+
* Adds an entry point to the library.
|
|
63
|
+
*
|
|
64
|
+
* @param name -
|
|
65
|
+
* The name of the entry point.
|
|
66
|
+
* @param path -
|
|
67
|
+
* The path to the entry point file.
|
|
68
|
+
*
|
|
69
|
+
* @returns
|
|
70
|
+
* This object.
|
|
71
|
+
*/ entry(name, path) {
|
|
72
|
+
this.library.entry = _object_spread_props(_object_spread({}, this.library.entry), {
|
|
73
|
+
[name]: path
|
|
74
|
+
});
|
|
75
|
+
return this;
|
|
76
|
+
}
|
|
77
|
+
/**
|
|
78
|
+
* A shorthand for adding an entry point
|
|
79
|
+
* named "index" that points to "src/index.ts"
|
|
80
|
+
*
|
|
81
|
+
* @returns
|
|
82
|
+
* This object.
|
|
83
|
+
*/ index() {
|
|
84
|
+
return this.entry("index", "./src/index.ts");
|
|
85
|
+
}
|
|
86
|
+
/**
|
|
87
|
+
* Returns the built library configuration.
|
|
88
|
+
*
|
|
89
|
+
* @returns
|
|
90
|
+
* A deep clone of the library configuration.
|
|
91
|
+
*/ build() {
|
|
92
|
+
return lodashEs.cloneDeep(this.library);
|
|
93
|
+
}
|
|
94
|
+
constructor(){
|
|
95
|
+
_define_property$2(this, "library", {
|
|
96
|
+
entry: {},
|
|
97
|
+
formats: [
|
|
98
|
+
"es",
|
|
99
|
+
"cjs"
|
|
100
|
+
]
|
|
101
|
+
});
|
|
102
|
+
}
|
|
103
|
+
}
|
|
104
|
+
|
|
105
|
+
function _define_property$1(obj, key, value) {
|
|
106
|
+
if (key in obj) {
|
|
107
|
+
Object.defineProperty(obj, key, {
|
|
108
|
+
value: value,
|
|
109
|
+
enumerable: true,
|
|
110
|
+
configurable: true,
|
|
111
|
+
writable: true
|
|
112
|
+
});
|
|
113
|
+
} else {
|
|
114
|
+
obj[key] = value;
|
|
115
|
+
}
|
|
116
|
+
return obj;
|
|
117
|
+
}
|
|
118
|
+
/**
|
|
119
|
+
* A builder for test configurations found in vite's defineConfig test field.
|
|
120
|
+
*/ class ZViteTestBuilder {
|
|
121
|
+
/**
|
|
122
|
+
* Sets the test environment.
|
|
123
|
+
*
|
|
124
|
+
* @param environment -
|
|
125
|
+
* The test environment to use.
|
|
126
|
+
*
|
|
127
|
+
* @returns
|
|
128
|
+
* This object.
|
|
129
|
+
*/ environment(environment) {
|
|
130
|
+
this.test.environment = environment;
|
|
131
|
+
return this;
|
|
132
|
+
}
|
|
133
|
+
/**
|
|
134
|
+
* Sets the test coverage provider.
|
|
135
|
+
*
|
|
136
|
+
* @param provider -
|
|
137
|
+
* The test coverage provider to use.
|
|
138
|
+
*
|
|
139
|
+
* @returns
|
|
140
|
+
* This object.
|
|
141
|
+
*/ coverage(provider) {
|
|
142
|
+
this.test.coverage.provider = provider;
|
|
143
|
+
return this;
|
|
144
|
+
}
|
|
145
|
+
/**
|
|
146
|
+
* Returns the built test configuration.
|
|
147
|
+
*
|
|
148
|
+
* @returns
|
|
149
|
+
* A deep clone of the test configuration.
|
|
150
|
+
*/ build() {
|
|
151
|
+
return lodashEs.cloneDeep(this.test);
|
|
152
|
+
}
|
|
153
|
+
/**
|
|
154
|
+
* Initializes a new instance of this object.
|
|
155
|
+
*/ constructor(){
|
|
156
|
+
_define_property$1(this, "test", void 0);
|
|
157
|
+
/**
|
|
158
|
+
* Sets the test environment to "node".
|
|
159
|
+
*
|
|
160
|
+
* @returns
|
|
161
|
+
* This object.
|
|
162
|
+
*/ _define_property$1(this, "node", this.environment.bind(this, "node"));
|
|
163
|
+
/**
|
|
164
|
+
* Sets the test environment to "happy-dom".
|
|
165
|
+
*
|
|
166
|
+
* @returns
|
|
167
|
+
* This object.
|
|
168
|
+
*/ _define_property$1(this, "browser", this.environment.bind(this, "happy-dom"));
|
|
169
|
+
/**
|
|
170
|
+
* Sets the test coverage provider to "v8".
|
|
171
|
+
*
|
|
172
|
+
* @returns
|
|
173
|
+
* This object.
|
|
174
|
+
*/ _define_property$1(this, "v8", this.coverage.bind(this, "v8"));
|
|
175
|
+
/**
|
|
176
|
+
* Sets the test coverage provider to "istanbul".
|
|
177
|
+
*
|
|
178
|
+
* @returns
|
|
179
|
+
* This object.
|
|
180
|
+
*/ _define_property$1(this, "istanbul", this.coverage.bind(this, "istanbul"));
|
|
181
|
+
this.test = {
|
|
182
|
+
environment: "node",
|
|
183
|
+
testTimeout: 30000,
|
|
184
|
+
coverage: {
|
|
185
|
+
all: false,
|
|
186
|
+
provider: undefined
|
|
187
|
+
}
|
|
188
|
+
};
|
|
189
|
+
}
|
|
190
|
+
}
|
|
191
|
+
|
|
192
|
+
function _define_property(obj, key, value) {
|
|
193
|
+
if (key in obj) {
|
|
194
|
+
Object.defineProperty(obj, key, {
|
|
195
|
+
value: value,
|
|
196
|
+
enumerable: true,
|
|
197
|
+
configurable: true,
|
|
198
|
+
writable: true
|
|
199
|
+
});
|
|
200
|
+
} else {
|
|
201
|
+
obj[key] = value;
|
|
202
|
+
}
|
|
203
|
+
return obj;
|
|
204
|
+
}
|
|
205
|
+
/**
|
|
206
|
+
* A config builder for the vite build system.
|
|
207
|
+
*
|
|
208
|
+
* This is helpful when building different types
|
|
209
|
+
* of projects and keeping a standard.
|
|
210
|
+
*
|
|
211
|
+
* @example vite.config.ts
|
|
212
|
+
*
|
|
213
|
+
* ```ts
|
|
214
|
+
* // Before Config Builder
|
|
215
|
+
* export default defineConfig({
|
|
216
|
+
* build: {
|
|
217
|
+
* lib: {
|
|
218
|
+
* entry: {
|
|
219
|
+
* index: "./src/index.ts",
|
|
220
|
+
* },
|
|
221
|
+
* formats: ["cjs", "es"],
|
|
222
|
+
* },
|
|
223
|
+
* },
|
|
224
|
+
* minify: false,
|
|
225
|
+
* sourceMap: true,
|
|
226
|
+
* plugins: [
|
|
227
|
+
* swc.vite(),
|
|
228
|
+
* tsConfigPaths(),
|
|
229
|
+
* externalizeDeps(),
|
|
230
|
+
* dtsPlugin({
|
|
231
|
+
* compilerOptions: {
|
|
232
|
+
* paths: {},
|
|
233
|
+
* },
|
|
234
|
+
* }),
|
|
235
|
+
* ],
|
|
236
|
+
* });
|
|
237
|
+
* ```
|
|
238
|
+
*
|
|
239
|
+
* ```ts
|
|
240
|
+
* // After config builder
|
|
241
|
+
* const config = new ZViteConfigBuilder().library().build();
|
|
242
|
+
* export default defineConfig(config);
|
|
243
|
+
* ```
|
|
244
|
+
*/ class ZViteConfigBuilder {
|
|
245
|
+
/**
|
|
246
|
+
* Sets vite into library mode.
|
|
247
|
+
*
|
|
248
|
+
* @param options -
|
|
249
|
+
* The options for the library. You can set this to
|
|
250
|
+
* nothing to use the default library which looks for
|
|
251
|
+
* an entry point at the source directory called index.ts
|
|
252
|
+
*
|
|
253
|
+
* @see {@link ZViteLibraryBuilder} for more information.
|
|
254
|
+
*
|
|
255
|
+
* @returns
|
|
256
|
+
* This object.
|
|
257
|
+
*/ library(options = new ZViteLibraryBuilder().index().build()) {
|
|
258
|
+
this.config.build.lib = options;
|
|
259
|
+
// There is almost no value to minifying a library unless you
|
|
260
|
+
// are bundling it for importing via html.
|
|
261
|
+
// Thus, just turn off the minify and enable the source map
|
|
262
|
+
// This makes it much easier for other devs to debug problems
|
|
263
|
+
this.config.build.minify = false;
|
|
264
|
+
this.config.build.sourcemap = true;
|
|
265
|
+
// When using a library, we also want to make sure we externalize the
|
|
266
|
+
// dependencies automatically -> it blows my mind why vite doesn't
|
|
267
|
+
// do this out of the box. I guess there's some reason or some
|
|
268
|
+
// use case to bundle all the dependencies; I just don't see it.
|
|
269
|
+
this.config.plugins = [
|
|
270
|
+
...this.config.plugins,
|
|
271
|
+
vitePluginExternalizeDeps.externalizeDeps(),
|
|
272
|
+
dtsPlugin({
|
|
273
|
+
compilerOptions: {
|
|
274
|
+
// Always turn off paths when building for production. You want to make
|
|
275
|
+
// sure that your build is building in the correct order and that your
|
|
276
|
+
// actual paths are correct.
|
|
277
|
+
paths: {}
|
|
278
|
+
}
|
|
279
|
+
})
|
|
280
|
+
];
|
|
281
|
+
return this;
|
|
282
|
+
}
|
|
283
|
+
/**
|
|
284
|
+
* Constructs the config to act as if it's compiling a node application.
|
|
285
|
+
*
|
|
286
|
+
* This is just an alias to {@link ZViteConfigBuilder.library} with two
|
|
287
|
+
* entry points.
|
|
288
|
+
*
|
|
289
|
+
* 1. The file src/cli.ts is the main entry point of the application.
|
|
290
|
+
* 1. The file, src/index.ts, is the api for importing
|
|
291
|
+
*
|
|
292
|
+
* @returns
|
|
293
|
+
* This object.
|
|
294
|
+
*/ cli() {
|
|
295
|
+
// A cli works similar to a library. Vite isn't the best when it comes
|
|
296
|
+
// to building complex node apps, but for simple cli tools and non
|
|
297
|
+
// framework based servers, you can do it.
|
|
298
|
+
const library = new ZViteLibraryBuilder().entry("index", "src/index.ts").entry("cli", "src/cli.ts").build();
|
|
299
|
+
return this.library(library);
|
|
300
|
+
}
|
|
301
|
+
/**
|
|
302
|
+
* Constructs the config to be for testing.
|
|
303
|
+
*/ test(options = new ZViteTestBuilder().node().istanbul().build()) {
|
|
304
|
+
this.config.test = options;
|
|
305
|
+
return this;
|
|
306
|
+
}
|
|
307
|
+
/**
|
|
308
|
+
* Returns the currently built config.
|
|
309
|
+
*
|
|
310
|
+
* @returns
|
|
311
|
+
* The currently built config.
|
|
312
|
+
*/ build() {
|
|
313
|
+
return lodashEs.cloneDeep(this.config);
|
|
314
|
+
}
|
|
315
|
+
/**
|
|
316
|
+
* Initializes a new instance of this object.
|
|
317
|
+
*
|
|
318
|
+
* @param _dirname -
|
|
319
|
+
* The directory that is housing the vite.config
|
|
320
|
+
* file. Pass __dirname to this.
|
|
321
|
+
*/ constructor(_dirname){
|
|
322
|
+
_define_property(this, "_dirname", void 0);
|
|
323
|
+
_define_property(this, "config", void 0);
|
|
324
|
+
this._dirname = _dirname;
|
|
325
|
+
this.config = {
|
|
326
|
+
build: {
|
|
327
|
+
minify: true,
|
|
328
|
+
sourcemap: false
|
|
329
|
+
},
|
|
330
|
+
plugins: [
|
|
331
|
+
swc.vite(),
|
|
332
|
+
tsConfigPaths()
|
|
333
|
+
]
|
|
334
|
+
};
|
|
335
|
+
}
|
|
336
|
+
}
|
|
337
|
+
|
|
338
|
+
exports.ZViteConfigBuilder = ZViteConfigBuilder;
|
|
339
|
+
exports.ZViteLibraryBuilder = ZViteLibraryBuilder;
|
|
340
|
+
exports.ZViteTestBuilder = ZViteTestBuilder;
|
|
341
|
+
//# sourceMappingURL=vite.cjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"vite.cjs","sources":["../src/vite/vite-library-builder.mts","../src/vite/vite-test-builder.mts","../src/vite/vite-config-builder.mts"],"sourcesContent":["import { cloneDeep } from \"lodash-es\";\nimport { LibraryOptions } from \"vite\";\n\n/**\n * A builder for Vite library configurations.\n */\nexport class ZViteLibraryBuilder {\n private library: LibraryOptions = {\n entry: {},\n formats: [\"es\", \"cjs\"],\n };\n\n /**\n * Adds an entry point to the library.\n *\n * @param name -\n * The name of the entry point.\n * @param path -\n * The path to the entry point file.\n *\n * @returns\n * This object.\n */\n public entry(name: string, path: string) {\n this.library.entry = {\n ...(this.library.entry as Record<string, string>),\n [name]: path,\n };\n return this;\n }\n\n /**\n * A shorthand for adding an entry point\n * named \"index\" that points to \"src/index.ts\"\n *\n * @returns\n * This object.\n */\n public index() {\n return this.entry(\"index\", \"./src/index.ts\");\n }\n\n /**\n * Returns the built library configuration.\n *\n * @returns\n * A deep clone of the library configuration.\n */\n public build() {\n return cloneDeep(this.library);\n }\n}\n","import { cloneDeep } from \"lodash-es\";\nimport { InlineConfig, VitestEnvironment } from \"vitest/node\";\n\n/**\n * A builder for test configurations found in vite's defineConfig test field.\n */\nexport class ZViteTestBuilder {\n private test: InlineConfig;\n\n /**\n * Initializes a new instance of this object.\n */\n public constructor() {\n this.test = {\n environment: \"node\",\n testTimeout: 30000,\n coverage: {\n all: false,\n provider: undefined,\n },\n };\n }\n\n /**\n * Sets the test environment.\n *\n * @param environment -\n * The test environment to use.\n *\n * @returns\n * This object.\n */\n public environment(environment: VitestEnvironment) {\n this.test.environment = environment;\n return this;\n }\n\n /**\n * Sets the test environment to \"node\".\n *\n * @returns\n * This object.\n */\n public node = this.environment.bind(this, \"node\");\n\n /**\n * Sets the test environment to \"happy-dom\".\n *\n * @returns\n * This object.\n */\n public browser = this.environment.bind(this, \"happy-dom\");\n\n /**\n * Sets the test coverage provider.\n *\n * @param provider -\n * The test coverage provider to use.\n *\n * @returns\n * This object.\n */\n public coverage(provider: \"v8\" | \"istanbul\") {\n this.test.coverage.provider = provider;\n return this;\n }\n\n /**\n * Sets the test coverage provider to \"v8\".\n *\n * @returns\n * This object.\n */\n public v8 = this.coverage.bind(this, \"v8\");\n\n /**\n * Sets the test coverage provider to \"istanbul\".\n *\n * @returns\n * This object.\n */\n public istanbul = this.coverage.bind(this, \"istanbul\");\n\n /**\n * Returns the built test configuration.\n *\n * @returns\n * A deep clone of the test configuration.\n */\n public build() {\n return cloneDeep(this.test);\n }\n}\n","import { cloneDeep } from \"lodash-es\";\nimport swc from \"unplugin-swc\";\nimport { LibraryOptions, UserConfig } from \"vite\";\nimport dtsPlugin from \"vite-plugin-dts\";\nimport { externalizeDeps } from \"vite-plugin-externalize-deps\";\nimport tsConfigPaths from \"vite-tsconfig-paths\";\nimport { InlineConfig as TestConfig } from \"vitest/node.js\";\nimport { ZViteLibraryBuilder } from \"./vite-library-builder.mjs\";\nimport { ZViteTestBuilder } from \"./vite-test-builder.mjs\";\n\n/**\n * A config builder for the vite build system.\n *\n * This is helpful when building different types\n * of projects and keeping a standard.\n *\n * @example vite.config.ts\n *\n * ```ts\n * // Before Config Builder\n * export default defineConfig({\n * build: {\n * lib: {\n * entry: {\n * index: \"./src/index.ts\",\n * },\n * formats: [\"cjs\", \"es\"],\n * },\n * },\n * minify: false,\n * sourceMap: true,\n * plugins: [\n * swc.vite(),\n * tsConfigPaths(),\n * externalizeDeps(),\n * dtsPlugin({\n * compilerOptions: {\n * paths: {},\n * },\n * }),\n * ],\n * });\n * ```\n *\n * ```ts\n * // After config builder\n * const config = new ZViteConfigBuilder().library().build();\n * export default defineConfig(config);\n * ```\n */\nexport class ZViteConfigBuilder {\n private config: UserConfig;\n\n /**\n * Initializes a new instance of this object.\n *\n * @param _dirname -\n * The directory that is housing the vite.config\n * file. Pass __dirname to this.\n */\n public constructor(private _dirname: string) {\n this.config = {\n build: {\n minify: true,\n sourcemap: false,\n },\n plugins: [swc.vite(), tsConfigPaths()],\n };\n }\n\n /**\n * Sets vite into library mode.\n *\n * @param options -\n * The options for the library. You can set this to\n * nothing to use the default library which looks for\n * an entry point at the source directory called index.ts\n *\n * @see {@link ZViteLibraryBuilder} for more information.\n *\n * @returns\n * This object.\n */\n public library(\n options: LibraryOptions = new ZViteLibraryBuilder().index().build(),\n ) {\n this.config.build.lib = options;\n\n // There is almost no value to minifying a library unless you\n // are bundling it for importing via html.\n // Thus, just turn off the minify and enable the source map\n // This makes it much easier for other devs to debug problems\n this.config.build.minify = false;\n this.config.build.sourcemap = true;\n\n // When using a library, we also want to make sure we externalize the\n // dependencies automatically -> it blows my mind why vite doesn't\n // do this out of the box. I guess there's some reason or some\n // use case to bundle all the dependencies; I just don't see it.\n this.config.plugins = [\n ...this.config.plugins,\n externalizeDeps(),\n dtsPlugin({\n compilerOptions: {\n // Always turn off paths when building for production. You want to make\n // sure that your build is building in the correct order and that your\n // actual paths are correct.\n paths: {},\n },\n }),\n ];\n\n return this;\n }\n\n /**\n * Constructs the config to act as if it's compiling a node application.\n *\n * This is just an alias to {@link ZViteConfigBuilder.library} with two\n * entry points.\n *\n * 1. The file src/cli.ts is the main entry point of the application.\n * 1. The file, src/index.ts, is the api for importing\n *\n * @returns\n * This object.\n */\n public cli() {\n // A cli works similar to a library. Vite isn't the best when it comes\n // to building complex node apps, but for simple cli tools and non\n // framework based servers, you can do it.\n const library = new ZViteLibraryBuilder()\n .entry(\"index\", \"src/index.ts\")\n .entry(\"cli\", \"src/cli.ts\")\n .build();\n return this.library(library);\n }\n\n /**\n * Constructs the config to be for testing.\n */\n public test(\n options: TestConfig = new ZViteTestBuilder().node().istanbul().build(),\n ) {\n this.config.test = options;\n return this;\n }\n\n /**\n * Returns the currently built config.\n *\n * @returns\n * The currently built config.\n */\n public build() {\n return cloneDeep(this.config);\n }\n}\n"],"names":["ZViteLibraryBuilder","entry","name","path","library","cloneDeep","_define_property","formats","ZViteTestBuilder","environment","test","coverage","provider","node","bind","browser","v8","istanbul","testTimeout","all","undefined","ZViteConfigBuilder","options","index","build","config","lib","minify","sourcemap","plugins","externalizeDeps","dtsPlugin","compilerOptions","paths","_dirname","swc","vite","tsConfigPaths"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;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