@zthun/janitor-build-config 19.0.0 → 19.1.1
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/dist/typedoc.cjs +80 -107
- package/dist/typedoc.cjs.map +1 -1
- package/dist/typedoc.js +81 -104
- package/dist/typedoc.js.map +1 -1
- package/dist/vite/index.d.ts +1 -0
- package/dist/vite/vite-config-builder.d.mts +81 -8
- package/dist/vite/vite-server-builder.d.mts +12 -0
- package/dist/vite/vite-server-builder.spec.d.ts +1 -0
- package/dist/vite/vite-test-builder.d.mts +20 -0
- package/dist/vite.cjs +268 -260
- package/dist/vite.cjs.map +1 -1
- package/dist/vite.js +271 -257
- package/dist/vite.js.map +1 -1
- package/package.json +15 -10
package/dist/vite.cjs
CHANGED
|
@@ -1,64 +1,20 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
const
|
|
6
|
-
const
|
|
7
|
-
const dtsPlugin = require(
|
|
8
|
-
const vitePluginExternalizeDeps = require(
|
|
9
|
-
const tsConfigPaths = require(
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
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
|
-
/**
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
|
|
3
|
+
const react = require("@vitejs/plugin-react");
|
|
4
|
+
const lodashEs = require("lodash-es");
|
|
5
|
+
const swc = require("unplugin-swc");
|
|
6
|
+
const vitePluginChecker = require("vite-plugin-checker");
|
|
7
|
+
const dtsPlugin = require("vite-plugin-dts");
|
|
8
|
+
const vitePluginExternalizeDeps = require("vite-plugin-externalize-deps");
|
|
9
|
+
const tsConfigPaths = require("vite-tsconfig-paths");
|
|
10
|
+
class ZViteLibraryBuilder {
|
|
11
|
+
constructor() {
|
|
12
|
+
this.library = {
|
|
13
|
+
entry: {},
|
|
14
|
+
formats: ["es", "cjs"]
|
|
15
|
+
};
|
|
16
|
+
}
|
|
17
|
+
/**
|
|
62
18
|
* Adds an entry point to the library.
|
|
63
19
|
*
|
|
64
20
|
* @param name -
|
|
@@ -68,57 +24,53 @@ function _object_spread_props(target, source) {
|
|
|
68
24
|
*
|
|
69
25
|
* @returns
|
|
70
26
|
* This object.
|
|
71
|
-
*/
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
}
|
|
77
|
-
|
|
27
|
+
*/
|
|
28
|
+
entry(name, path) {
|
|
29
|
+
this.library.entry = {
|
|
30
|
+
...this.library.entry,
|
|
31
|
+
[name]: path
|
|
32
|
+
};
|
|
33
|
+
return this;
|
|
34
|
+
}
|
|
35
|
+
/**
|
|
78
36
|
* A shorthand for adding an entry point
|
|
79
37
|
* named "index" that points to "src/index.ts"
|
|
80
38
|
*
|
|
81
39
|
* @returns
|
|
82
40
|
* This object.
|
|
83
|
-
*/
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
41
|
+
*/
|
|
42
|
+
index() {
|
|
43
|
+
return this.entry("index", "./src/index.ts");
|
|
44
|
+
}
|
|
45
|
+
/**
|
|
87
46
|
* Returns the built library configuration.
|
|
88
47
|
*
|
|
89
48
|
* @returns
|
|
90
49
|
* A deep clone of the library configuration.
|
|
91
|
-
*/
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
_define_property$2(this, "library", {
|
|
96
|
-
entry: {},
|
|
97
|
-
formats: [
|
|
98
|
-
"es",
|
|
99
|
-
"cjs"
|
|
100
|
-
]
|
|
101
|
-
});
|
|
102
|
-
}
|
|
50
|
+
*/
|
|
51
|
+
build() {
|
|
52
|
+
return lodashEs.cloneDeep(this.library);
|
|
53
|
+
}
|
|
103
54
|
}
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
55
|
+
class ZViteTestBuilder {
|
|
56
|
+
/**
|
|
57
|
+
* Initializes a new instance of this object.
|
|
58
|
+
*/
|
|
59
|
+
constructor() {
|
|
60
|
+
this.node = this.environment.bind(this, "node");
|
|
61
|
+
this.browser = this.environment.bind(this, "happy-dom");
|
|
62
|
+
this.v8 = this.coverage.bind(this, "v8");
|
|
63
|
+
this.istanbul = this.coverage.bind(this, "istanbul");
|
|
64
|
+
this.test = {
|
|
65
|
+
environment: "node",
|
|
66
|
+
testTimeout: 3e4,
|
|
67
|
+
coverage: {
|
|
68
|
+
all: false,
|
|
69
|
+
provider: void 0
|
|
70
|
+
}
|
|
71
|
+
};
|
|
72
|
+
}
|
|
73
|
+
/**
|
|
122
74
|
* Sets the test environment.
|
|
123
75
|
*
|
|
124
76
|
* @param environment -
|
|
@@ -126,11 +78,12 @@ function _define_property$1(obj, key, value) {
|
|
|
126
78
|
*
|
|
127
79
|
* @returns
|
|
128
80
|
* This object.
|
|
129
|
-
*/
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
81
|
+
*/
|
|
82
|
+
environment(environment) {
|
|
83
|
+
this.test.environment = environment;
|
|
84
|
+
return this;
|
|
85
|
+
}
|
|
86
|
+
/**
|
|
134
87
|
* Sets the test coverage provider.
|
|
135
88
|
*
|
|
136
89
|
* @param provider -
|
|
@@ -138,114 +91,126 @@ function _define_property$1(obj, key, value) {
|
|
|
138
91
|
*
|
|
139
92
|
* @returns
|
|
140
93
|
* This object.
|
|
141
|
-
*/
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
94
|
+
*/
|
|
95
|
+
coverage(provider) {
|
|
96
|
+
this.test.coverage = { ...this.test.coverage, provider };
|
|
97
|
+
return this;
|
|
98
|
+
}
|
|
99
|
+
/**
|
|
100
|
+
* Adds to the list of projects.
|
|
101
|
+
*
|
|
102
|
+
* @param project -
|
|
103
|
+
* The list of projects.
|
|
104
|
+
*
|
|
105
|
+
* @returns
|
|
106
|
+
* This object.
|
|
107
|
+
*/
|
|
108
|
+
project(project = []) {
|
|
109
|
+
const projects = this.test.projects || [];
|
|
110
|
+
this.test.projects = projects.concat(project);
|
|
111
|
+
return this;
|
|
112
|
+
}
|
|
113
|
+
/**
|
|
114
|
+
* Adds monorepo support to the test builder.
|
|
115
|
+
*
|
|
116
|
+
* @param packages -
|
|
117
|
+
* The path to the package directory.
|
|
118
|
+
*
|
|
119
|
+
* @returns
|
|
120
|
+
* This object.
|
|
121
|
+
*/
|
|
122
|
+
monorepo(packages = "packages") {
|
|
123
|
+
return this.project(`${packages}/*/vitest.config.{js,cjs,mjs,ts,mts}`);
|
|
124
|
+
}
|
|
125
|
+
/**
|
|
146
126
|
* Returns the built test configuration.
|
|
147
127
|
*
|
|
148
128
|
* @returns
|
|
149
129
|
* A deep clone of the test configuration.
|
|
150
|
-
*/
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
130
|
+
*/
|
|
131
|
+
build() {
|
|
132
|
+
return lodashEs.cloneDeep(this.test);
|
|
133
|
+
}
|
|
134
|
+
}
|
|
135
|
+
class ZViteConfigBuilder {
|
|
136
|
+
/**
|
|
154
137
|
* Initializes a new instance of this object.
|
|
155
|
-
*/
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
138
|
+
*/
|
|
139
|
+
constructor() {
|
|
140
|
+
this.config = {
|
|
141
|
+
build: {
|
|
142
|
+
minify: true,
|
|
143
|
+
sourcemap: false
|
|
144
|
+
},
|
|
145
|
+
plugins: [tsConfigPaths()]
|
|
146
|
+
};
|
|
147
|
+
}
|
|
148
|
+
/**
|
|
149
|
+
* Sets whether to minify the build output.
|
|
150
|
+
*
|
|
151
|
+
* @param minify -
|
|
152
|
+
* The flag as to minify the output.
|
|
159
153
|
*
|
|
160
154
|
* @returns
|
|
161
155
|
* This object.
|
|
162
|
-
*/
|
|
163
|
-
|
|
164
|
-
|
|
156
|
+
*/
|
|
157
|
+
minify(minify = true) {
|
|
158
|
+
this.config.build = { ...this.config.build, minify };
|
|
159
|
+
return this;
|
|
160
|
+
}
|
|
161
|
+
/**
|
|
162
|
+
* Adds a list of plugins.
|
|
163
|
+
*
|
|
164
|
+
* @param option -
|
|
165
|
+
* The plugins to add.
|
|
165
166
|
*
|
|
166
167
|
* @returns
|
|
167
168
|
* This object.
|
|
168
|
-
*/
|
|
169
|
-
|
|
170
|
-
|
|
169
|
+
*/
|
|
170
|
+
plugin(option = []) {
|
|
171
|
+
const plugins = this.config.plugins;
|
|
172
|
+
this.config.plugins = plugins.concat(lodashEs.castArray(option));
|
|
173
|
+
return this;
|
|
174
|
+
}
|
|
175
|
+
/**
|
|
176
|
+
* Adds the swc plugin.
|
|
177
|
+
*
|
|
178
|
+
* This is mostly for nest projects as nest requires
|
|
179
|
+
* swc to support decorators.
|
|
180
|
+
*/
|
|
181
|
+
swc() {
|
|
182
|
+
return this.plugin(swc.vite());
|
|
183
|
+
}
|
|
184
|
+
/**
|
|
185
|
+
* Sets whether to generate source maps.
|
|
186
|
+
*
|
|
187
|
+
* @param sourcemap -
|
|
188
|
+
* True to generate a sourcemap, false for faster build.
|
|
171
189
|
*
|
|
172
190
|
* @returns
|
|
173
191
|
* This object.
|
|
174
|
-
*/
|
|
175
|
-
|
|
176
|
-
|
|
192
|
+
*/
|
|
193
|
+
sourceMap(sourcemap = true) {
|
|
194
|
+
this.config.build = { ...this.config.build, sourcemap };
|
|
195
|
+
return this;
|
|
196
|
+
}
|
|
197
|
+
/**
|
|
198
|
+
* Assigns the server options.
|
|
199
|
+
*
|
|
200
|
+
* @param options -
|
|
201
|
+
* The server options to assign.
|
|
177
202
|
*
|
|
178
203
|
* @returns
|
|
179
204
|
* This object.
|
|
180
|
-
*/
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
|
|
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
|
-
/**
|
|
205
|
+
*/
|
|
206
|
+
server(options) {
|
|
207
|
+
this.config.server = lodashEs.cloneDeep(options);
|
|
208
|
+
return this;
|
|
209
|
+
}
|
|
210
|
+
/**
|
|
246
211
|
* Sets vite into library mode.
|
|
247
212
|
*
|
|
248
|
-
* @param
|
|
213
|
+
* @param lib -
|
|
249
214
|
* The options for the library. You can set this to
|
|
250
215
|
* nothing to use the default library which looks for
|
|
251
216
|
* an entry point at the source directory called index.ts
|
|
@@ -254,33 +219,21 @@ function _define_property(obj, key, value) {
|
|
|
254
219
|
*
|
|
255
220
|
* @returns
|
|
256
221
|
* This object.
|
|
257
|
-
*/
|
|
258
|
-
|
|
259
|
-
|
|
260
|
-
|
|
261
|
-
|
|
262
|
-
//
|
|
263
|
-
|
|
264
|
-
|
|
265
|
-
|
|
266
|
-
|
|
267
|
-
|
|
268
|
-
|
|
269
|
-
|
|
270
|
-
|
|
271
|
-
|
|
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
|
-
/**
|
|
222
|
+
*/
|
|
223
|
+
library(lib = new ZViteLibraryBuilder().index().build()) {
|
|
224
|
+
this.config.build = { ...this.config.build, lib };
|
|
225
|
+
const dts = dtsPlugin({
|
|
226
|
+
compilerOptions: {
|
|
227
|
+
// Always turn off paths when building for production. You want to make
|
|
228
|
+
// sure that your build is building in the correct order and that your
|
|
229
|
+
// actual paths are correct.
|
|
230
|
+
paths: {}
|
|
231
|
+
}
|
|
232
|
+
});
|
|
233
|
+
const external = vitePluginExternalizeDeps.externalizeDeps();
|
|
234
|
+
return this.minify(false).sourceMap().plugin(external).plugin(dts);
|
|
235
|
+
}
|
|
236
|
+
/**
|
|
284
237
|
* Constructs the config to act as if it's compiling a node application.
|
|
285
238
|
*
|
|
286
239
|
* This is just an alias to {@link ZViteConfigBuilder.library} with two
|
|
@@ -291,51 +244,106 @@ function _define_property(obj, key, value) {
|
|
|
291
244
|
*
|
|
292
245
|
* @returns
|
|
293
246
|
* This object.
|
|
294
|
-
*/
|
|
295
|
-
|
|
296
|
-
|
|
297
|
-
|
|
298
|
-
|
|
299
|
-
|
|
300
|
-
|
|
301
|
-
|
|
247
|
+
*/
|
|
248
|
+
cli() {
|
|
249
|
+
const library = new ZViteLibraryBuilder().entry("index", "src/index.ts").entry("cli", "src/cli.ts").build();
|
|
250
|
+
return this.library(library);
|
|
251
|
+
}
|
|
252
|
+
/**
|
|
253
|
+
* Constructs the config to act as if it's compiling a nest application.
|
|
254
|
+
*
|
|
255
|
+
* This is just an alias to {@link ZViteConfigBuilder.library} with a single
|
|
256
|
+
* entry point.
|
|
257
|
+
*
|
|
258
|
+
* 1. The file, src/main.mts
|
|
259
|
+
*
|
|
260
|
+
* @returns
|
|
261
|
+
* This object.
|
|
262
|
+
*/
|
|
263
|
+
nest() {
|
|
264
|
+
const library = new ZViteLibraryBuilder().entry("main", "src/main.mts").build();
|
|
265
|
+
return this.library(library).swc();
|
|
266
|
+
}
|
|
267
|
+
/**
|
|
268
|
+
* Constructs the config to act as if it's compiling a web application.
|
|
269
|
+
*
|
|
270
|
+
* @returns
|
|
271
|
+
* This object.
|
|
272
|
+
*/
|
|
273
|
+
web() {
|
|
274
|
+
return this.minify().sourceMap(false).plugin(vitePluginChecker.checker({ typescript: true }));
|
|
275
|
+
}
|
|
276
|
+
/**
|
|
277
|
+
* Constructs the config to compile a react application.
|
|
278
|
+
*
|
|
279
|
+
* @returns
|
|
280
|
+
* This object.
|
|
281
|
+
*/
|
|
282
|
+
react() {
|
|
283
|
+
return this.web().plugin(react());
|
|
284
|
+
}
|
|
285
|
+
/**
|
|
302
286
|
* Constructs the config to be for testing.
|
|
303
|
-
|
|
304
|
-
|
|
305
|
-
|
|
306
|
-
|
|
307
|
-
|
|
287
|
+
*
|
|
288
|
+
* @param options -
|
|
289
|
+
* The test config to use. If this is falsy,
|
|
290
|
+
* then a test setup using a monorepo with an
|
|
291
|
+
* istanbul provider in node is used.
|
|
292
|
+
*/
|
|
293
|
+
test(options = new ZViteTestBuilder().node().istanbul().monorepo().build()) {
|
|
294
|
+
this.config.test = options;
|
|
295
|
+
return this;
|
|
296
|
+
}
|
|
297
|
+
/**
|
|
308
298
|
* Returns the currently built config.
|
|
309
299
|
*
|
|
310
300
|
* @returns
|
|
311
301
|
* The currently built config.
|
|
312
|
-
*/
|
|
313
|
-
|
|
314
|
-
|
|
315
|
-
|
|
316
|
-
|
|
317
|
-
|
|
318
|
-
|
|
319
|
-
|
|
320
|
-
|
|
321
|
-
|
|
322
|
-
|
|
323
|
-
|
|
324
|
-
|
|
325
|
-
|
|
326
|
-
|
|
327
|
-
|
|
328
|
-
sourcemap: false
|
|
329
|
-
},
|
|
330
|
-
plugins: [
|
|
331
|
-
swc.vite(),
|
|
332
|
-
tsConfigPaths()
|
|
333
|
-
]
|
|
334
|
-
};
|
|
302
|
+
*/
|
|
303
|
+
build() {
|
|
304
|
+
return lodashEs.cloneDeep(this.config);
|
|
305
|
+
}
|
|
306
|
+
}
|
|
307
|
+
class ZViteServerBuilder {
|
|
308
|
+
constructor() {
|
|
309
|
+
this.options = {};
|
|
310
|
+
this.localhost = this.host.bind(this, "127.0.0.1");
|
|
311
|
+
}
|
|
312
|
+
allowedHost(name) {
|
|
313
|
+
if (name === true) {
|
|
314
|
+
this.options.allowedHosts = true;
|
|
315
|
+
} else if (this.options.allowedHosts !== true) {
|
|
316
|
+
const hosts = this.options.allowedHosts || [];
|
|
317
|
+
this.options.allowedHosts = hosts.concat(name);
|
|
335
318
|
}
|
|
319
|
+
return this;
|
|
320
|
+
}
|
|
321
|
+
denyAllHosts() {
|
|
322
|
+
delete this.options.allowedHosts;
|
|
323
|
+
return this;
|
|
324
|
+
}
|
|
325
|
+
port(port) {
|
|
326
|
+
this.options.port = port;
|
|
327
|
+
return this;
|
|
328
|
+
}
|
|
329
|
+
strictPort() {
|
|
330
|
+
this.options.strictPort = true;
|
|
331
|
+
return this;
|
|
332
|
+
}
|
|
333
|
+
host(ip) {
|
|
334
|
+
this.options.host = ip;
|
|
335
|
+
return this;
|
|
336
|
+
}
|
|
337
|
+
dev() {
|
|
338
|
+
return this.strictPort().host("0.0.0.0").allowedHost(true);
|
|
339
|
+
}
|
|
340
|
+
build() {
|
|
341
|
+
const clone = lodashEs.cloneDeep(this.options);
|
|
342
|
+
return lodashEs.omitBy(clone, lodashEs.isUndefined);
|
|
343
|
+
}
|
|
336
344
|
}
|
|
337
|
-
|
|
338
345
|
exports.ZViteConfigBuilder = ZViteConfigBuilder;
|
|
339
346
|
exports.ZViteLibraryBuilder = ZViteLibraryBuilder;
|
|
347
|
+
exports.ZViteServerBuilder = ZViteServerBuilder;
|
|
340
348
|
exports.ZViteTestBuilder = ZViteTestBuilder;
|
|
341
349
|
//# sourceMappingURL=vite.cjs.map
|
package/dist/vite.cjs.map
CHANGED
|
@@ -1 +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":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAGA;;AAEC,IACM,MAAMA,mBAAAA,CAAAA;AAMX;;;;;;;;;;AAUC,MACD,KAAOC,CAAMC,IAAY,EAAEC,IAAY,EAAE;QACvC,IAAI,CAACC,OAAO,CAACH,KAAK,GAAG,wCACf,IAAI,CAACG,OAAO,CAACH,KAAK,CAAA,EAAA;AACtB,YAAA,CAACC,OAAOC;;AAEV,QAAA,OAAO,IAAI;AACb;AAEA;;;;;;AAMC,MACD,KAAe,GAAA;AACb,QAAA,OAAO,IAAI,CAACF,KAAK,CAAC,OAAS,EAAA,gBAAA,CAAA;AAC7B;AAEA;;;;;AAKC,MACD,KAAe,GAAA;QACb,OAAOI,kBAAAA,CAAU,IAAI,CAACD,OAAO,CAAA;AAC/B;;AA3CA,QAAAE,kBAA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b;AAEA;;;;;AAKC,MACD,KAAe,GAAA;QACb,OAAOjB,kBAAAA,CAAU,IAAI,CAACoB,MAAM,CAAA;AAC9B;AAvGA;;;;;;MAOA,WAAA,CAAmB,QAAwB,CAAE;;AAT7C,QAAA,gBAAA,CAAA,IAAA,EAAQA,UAAR,MAAA,CAAA;aAS2BS,QAAAA,GAAAA,QAAAA;QACzB,IAAI,CAACT,MAAM,GAAG;YACZD,KAAO,EAAA;gBACLG,MAAQ,EAAA,IAAA;gBACRC,SAAW,EAAA;AACb,aAAA;YACAC,OAAS,EAAA;AAACM,gBAAAA,GAAAA,CAAIC,IAAI,EAAA;AAAIC,gBAAAA,aAAAA;AAAgB;AACxC,SAAA;AACF;AAyFF;;;;;;"}
|
|
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","../src/vite/vite-server-builder.mts"],"sourcesContent":["import { cloneDeep } from \"lodash-es\";\nimport type { 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 type { 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 = { ...this.test.coverage, 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 * Adds to the list of projects.\n *\n * @param project -\n * The list of projects.\n *\n * @returns\n * This object.\n */\n public project(project: string | string[] = []) {\n const projects = this.test.projects || [];\n this.test.projects = projects.concat(project);\n return this;\n }\n\n /**\n * Adds monorepo support to the test builder.\n *\n * @param packages -\n * The path to the package directory.\n *\n * @returns\n * This object.\n */\n public monorepo(packages = \"packages\") {\n return this.project(`${packages}/*/vitest.config.{js,cjs,mjs,ts,mts}`);\n }\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 react from \"@vitejs/plugin-react\";\nimport { castArray, cloneDeep } from \"lodash-es\";\nimport swc from \"unplugin-swc\";\nimport type {\n LibraryOptions,\n PluginOption,\n ServerOptions,\n UserConfig,\n} from \"vite\";\nimport { checker } from \"vite-plugin-checker\";\nimport dtsPlugin from \"vite-plugin-dts\";\nimport { externalizeDeps } from \"vite-plugin-externalize-deps\";\nimport tsConfigPaths from \"vite-tsconfig-paths\";\nimport type { 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 public constructor() {\n this.config = {\n build: {\n minify: true,\n sourcemap: false,\n },\n plugins: [tsConfigPaths()],\n };\n }\n\n /**\n * Sets whether to minify the build output.\n *\n * @param minify -\n * The flag as to minify the output.\n *\n * @returns\n * This object.\n */\n public minify(minify = true) {\n this.config.build = { ...this.config.build, minify };\n return this;\n }\n\n /**\n * Adds a list of plugins.\n *\n * @param option -\n * The plugins to add.\n *\n * @returns\n * This object.\n */\n public plugin(option: PluginOption | PluginOption[] = []) {\n // See constructor - the config plugins are guaranteed to\n // be set. The swc and paths plugins are automatically added.\n const plugins = this.config.plugins!;\n this.config.plugins = plugins.concat(castArray(option));\n return this;\n }\n\n /**\n * Adds the swc plugin.\n *\n * This is mostly for nest projects as nest requires\n * swc to support decorators.\n */\n public swc() {\n return this.plugin(swc.vite());\n }\n\n /**\n * Sets whether to generate source maps.\n *\n * @param sourcemap -\n * True to generate a sourcemap, false for faster build.\n *\n * @returns\n * This object.\n */\n public sourceMap(sourcemap = true) {\n this.config.build = { ...this.config.build, sourcemap };\n return this;\n }\n\n /**\n * Assigns the server options.\n *\n * @param options -\n * The server options to assign.\n *\n * @returns\n * This object.\n */\n public server(options: ServerOptions) {\n this.config.server = cloneDeep(options);\n return this;\n }\n\n /**\n * Sets vite into library mode.\n *\n * @param lib -\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 lib: LibraryOptions = new ZViteLibraryBuilder().index().build(),\n ) {\n this.config.build = { ...this.config.build, lib };\n\n const dts = 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 const external = externalizeDeps();\n\n return this.minify(false).sourceMap().plugin(external).plugin(dts);\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.\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 act as if it's compiling a nest application.\n *\n * This is just an alias to {@link ZViteConfigBuilder.library} with a single\n * entry point.\n *\n * 1. The file, src/main.mts\n *\n * @returns\n * This object.\n */\n public nest() {\n const library = new ZViteLibraryBuilder()\n .entry(\"main\", \"src/main.mts\")\n .build();\n return this.library(library).swc();\n }\n\n /**\n * Constructs the config to act as if it's compiling a web application.\n *\n * @returns\n * This object.\n */\n public web() {\n return this.minify()\n .sourceMap(false)\n .plugin(checker({ typescript: true }));\n }\n\n /**\n * Constructs the config to compile a react application.\n *\n * @returns\n * This object.\n */\n public react() {\n return this.web().plugin(react());\n }\n\n /**\n * Constructs the config to be for testing.\n *\n * @param options -\n * The test config to use. If this is falsy,\n * then a test setup using a monorepo with an\n * istanbul provider in node is used.\n */\n public test(\n options: TestConfig = new ZViteTestBuilder()\n .node()\n .istanbul()\n .monorepo()\n .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","import { cloneDeep, isUndefined, omitBy } from \"lodash-es\";\nimport type { ServerOptions } from \"vite\";\n\nexport class ZViteServerBuilder {\n private options: ServerOptions = {};\n\n public allowedHost(name: string | string[] | true) {\n if (name === true) {\n this.options.allowedHosts = true;\n } else if (this.options.allowedHosts !== true) {\n const hosts = this.options.allowedHosts || [];\n this.options.allowedHosts = hosts.concat(name);\n }\n\n return this;\n }\n\n public denyAllHosts() {\n delete this.options.allowedHosts;\n return this;\n }\n\n public port(port?: number) {\n this.options.port = port;\n return this;\n }\n\n public strictPort() {\n this.options.strictPort = true;\n return this;\n }\n\n public host(ip: string) {\n this.options.host = ip;\n return this;\n }\n\n public localhost = this.host.bind(this, \"127.0.0.1\");\n\n public dev() {\n return this.strictPort().host(\"0.0.0.0\").allowedHost(true);\n }\n\n public build() {\n const clone = cloneDeep(this.options);\n return omitBy<ServerOptions>(clone, isUndefined) as ServerOptions;\n }\n}\n"],"names":["cloneDeep","castArray","externalizeDeps","checker","omitBy","isUndefined"],"mappings":";;;;;;;;;AAMO,MAAM,oBAAoB;AAAA,EAA1B,cAAA;AACL,SAAQ,UAA0B;AAAA,MAChC,OAAO,CAAC;AAAA,MACR,SAAS,CAAC,MAAM,KAAK;AAAA,IACvB;AAAA,EAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,EAaO,MAAM,MAAc,MAAc;AACvC,SAAK,QAAQ,QAAQ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