@zthun/janitor-build-config 19.1.0 → 19.1.2

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/vite.js CHANGED
@@ -1,61 +1,18 @@
1
- import { cloneDeep, castArray, omitBy, isUndefined } from 'lodash-es';
2
- import swc from 'unplugin-swc';
3
- import { checker } from 'vite-plugin-checker';
4
- import dtsPlugin from 'vite-plugin-dts';
5
- import { externalizeDeps } from 'vite-plugin-externalize-deps';
6
- import tsConfigPaths from 'vite-tsconfig-paths';
7
-
8
- function _define_property$3(obj, key, value) {
9
- if (key in obj) {
10
- Object.defineProperty(obj, key, {
11
- value: value,
12
- enumerable: true,
13
- configurable: true,
14
- writable: true
15
- });
16
- } else {
17
- obj[key] = value;
18
- }
19
- return obj;
20
- }
21
- function _object_spread$2(target) {
22
- for(var i = 1; i < arguments.length; i++){
23
- var source = arguments[i] != null ? arguments[i] : {};
24
- var ownKeys = Object.keys(source);
25
- if (typeof Object.getOwnPropertySymbols === "function") {
26
- ownKeys = ownKeys.concat(Object.getOwnPropertySymbols(source).filter(function(sym) {
27
- return Object.getOwnPropertyDescriptor(source, sym).enumerable;
28
- }));
29
- }
30
- ownKeys.forEach(function(key) {
31
- _define_property$3(target, key, source[key]);
32
- });
33
- }
34
- return target;
35
- }
36
- function ownKeys$2(object, enumerableOnly) {
37
- var keys = Object.keys(object);
38
- if (Object.getOwnPropertySymbols) {
39
- var symbols = Object.getOwnPropertySymbols(object);
40
- keys.push.apply(keys, symbols);
41
- }
42
- return keys;
43
- }
44
- function _object_spread_props$2(target, source) {
45
- source = source != null ? source : {};
46
- if (Object.getOwnPropertyDescriptors) {
47
- Object.defineProperties(target, Object.getOwnPropertyDescriptors(source));
48
- } else {
49
- ownKeys$2(Object(source)).forEach(function(key) {
50
- Object.defineProperty(target, key, Object.getOwnPropertyDescriptor(source, key));
51
- });
52
- }
53
- return target;
54
- }
55
- /**
56
- * A builder for Vite library configurations.
57
- */ class ZViteLibraryBuilder {
58
- /**
1
+ import react from "@vitejs/plugin-react";
2
+ import { cloneDeep, castArray, omitBy, isUndefined } from "lodash-es";
3
+ import swc from "unplugin-swc";
4
+ import { checker } from "vite-plugin-checker";
5
+ import dtsPlugin from "vite-plugin-dts";
6
+ import { externalizeDeps } from "vite-plugin-externalize-deps";
7
+ import tsConfigPaths from "vite-tsconfig-paths";
8
+ class ZViteLibraryBuilder {
9
+ constructor() {
10
+ this.library = {
11
+ entry: {},
12
+ formats: ["es", "cjs"]
13
+ };
14
+ }
15
+ /**
59
16
  * Adds an entry point to the library.
60
17
  *
61
18
  * @param name -
@@ -65,91 +22,53 @@ function _object_spread_props$2(target, source) {
65
22
  *
66
23
  * @returns
67
24
  * This object.
68
- */ entry(name, path) {
69
- this.library.entry = _object_spread_props$2(_object_spread$2({}, this.library.entry), {
70
- [name]: path
71
- });
72
- return this;
73
- }
74
- /**
25
+ */
26
+ entry(name, path) {
27
+ this.library.entry = {
28
+ ...this.library.entry,
29
+ [name]: path
30
+ };
31
+ return this;
32
+ }
33
+ /**
75
34
  * A shorthand for adding an entry point
76
35
  * named "index" that points to "src/index.ts"
77
36
  *
78
37
  * @returns
79
38
  * This object.
80
- */ index() {
81
- return this.entry("index", "./src/index.ts");
82
- }
83
- /**
39
+ */
40
+ index() {
41
+ return this.entry("index", "./src/index.mts");
42
+ }
43
+ /**
84
44
  * Returns the built library configuration.
85
45
  *
86
46
  * @returns
87
47
  * A deep clone of the library configuration.
88
- */ build() {
89
- return cloneDeep(this.library);
90
- }
91
- constructor(){
92
- _define_property$3(this, "library", {
93
- entry: {},
94
- formats: [
95
- "es",
96
- "cjs"
97
- ]
98
- });
99
- }
100
- }
101
-
102
- function _define_property$2(obj, key, value) {
103
- if (key in obj) {
104
- Object.defineProperty(obj, key, {
105
- value: value,
106
- enumerable: true,
107
- configurable: true,
108
- writable: true
109
- });
110
- } else {
111
- obj[key] = value;
112
- }
113
- return obj;
114
- }
115
- function _object_spread$1(target) {
116
- for(var i = 1; i < arguments.length; i++){
117
- var source = arguments[i] != null ? arguments[i] : {};
118
- var ownKeys = Object.keys(source);
119
- if (typeof Object.getOwnPropertySymbols === "function") {
120
- ownKeys = ownKeys.concat(Object.getOwnPropertySymbols(source).filter(function(sym) {
121
- return Object.getOwnPropertyDescriptor(source, sym).enumerable;
122
- }));
123
- }
124
- ownKeys.forEach(function(key) {
125
- _define_property$2(target, key, source[key]);
126
- });
127
- }
128
- return target;
129
- }
130
- function ownKeys$1(object, enumerableOnly) {
131
- var keys = Object.keys(object);
132
- if (Object.getOwnPropertySymbols) {
133
- var symbols = Object.getOwnPropertySymbols(object);
134
- keys.push.apply(keys, symbols);
135
- }
136
- return keys;
137
- }
138
- function _object_spread_props$1(target, source) {
139
- source = source != null ? source : {};
140
- if (Object.getOwnPropertyDescriptors) {
141
- Object.defineProperties(target, Object.getOwnPropertyDescriptors(source));
142
- } else {
143
- ownKeys$1(Object(source)).forEach(function(key) {
144
- Object.defineProperty(target, key, Object.getOwnPropertyDescriptor(source, key));
145
- });
146
- }
147
- return target;
48
+ */
49
+ build() {
50
+ return cloneDeep(this.library);
51
+ }
148
52
  }
149
- /**
150
- * A builder for test configurations found in vite's defineConfig test field.
151
- */ class ZViteTestBuilder {
152
- /**
53
+ class ZViteTestBuilder {
54
+ /**
55
+ * Initializes a new instance of this object.
56
+ */
57
+ constructor() {
58
+ this.node = this.environment.bind(this, "node");
59
+ this.browser = this.environment.bind(this, "happy-dom");
60
+ this.v8 = this.coverage.bind(this, "v8");
61
+ this.istanbul = this.coverage.bind(this, "istanbul");
62
+ this.test = {
63
+ environment: "node",
64
+ testTimeout: 3e4,
65
+ coverage: {
66
+ all: false,
67
+ provider: void 0
68
+ }
69
+ };
70
+ }
71
+ /**
153
72
  * Sets the test environment.
154
73
  *
155
74
  * @param environment -
@@ -157,11 +76,12 @@ function _object_spread_props$1(target, source) {
157
76
  *
158
77
  * @returns
159
78
  * This object.
160
- */ environment(environment) {
161
- this.test.environment = environment;
162
- return this;
163
- }
164
- /**
79
+ */
80
+ environment(environment) {
81
+ this.test.environment = environment;
82
+ return this;
83
+ }
84
+ /**
165
85
  * Sets the test coverage provider.
166
86
  *
167
87
  * @param provider -
@@ -169,13 +89,12 @@ function _object_spread_props$1(target, source) {
169
89
  *
170
90
  * @returns
171
91
  * This object.
172
- */ coverage(provider) {
173
- this.test.coverage = _object_spread_props$1(_object_spread$1({}, this.test.coverage), {
174
- provider
175
- });
176
- return this;
177
- }
178
- /**
92
+ */
93
+ coverage(provider) {
94
+ this.test.coverage = { ...this.test.coverage, provider };
95
+ return this;
96
+ }
97
+ /**
179
98
  * Adds to the list of projects.
180
99
  *
181
100
  * @param project -
@@ -183,12 +102,13 @@ function _object_spread_props$1(target, source) {
183
102
  *
184
103
  * @returns
185
104
  * This object.
186
- */ project(project = []) {
187
- const projects = this.test.projects || [];
188
- this.test.projects = projects.concat(project);
189
- return this;
190
- }
191
- /**
105
+ */
106
+ project(project = []) {
107
+ const projects = this.test.projects || [];
108
+ this.test.projects = projects.concat(project);
109
+ return this;
110
+ }
111
+ /**
192
112
  * Adds monorepo support to the test builder.
193
113
  *
194
114
  * @param packages -
@@ -196,144 +116,34 @@ function _object_spread_props$1(target, source) {
196
116
  *
197
117
  * @returns
198
118
  * This object.
199
- */ monorepo(packages = "packages") {
200
- return this.project(`${packages}/*/vitest.config.{js,cjs,mjs,ts,mts}`);
201
- }
202
- /**
119
+ */
120
+ monorepo(packages = "packages") {
121
+ return this.project(`${packages}/*/vitest.config.{js,cjs,mjs,ts,mts}`);
122
+ }
123
+ /**
203
124
  * Returns the built test configuration.
204
125
  *
205
126
  * @returns
206
127
  * A deep clone of the test configuration.
207
- */ build() {
208
- return cloneDeep(this.test);
209
- }
210
- /**
211
- * Initializes a new instance of this object.
212
- */ constructor(){
213
- _define_property$2(this, "test", void 0);
214
- /**
215
- * Sets the test environment to "node".
216
- *
217
- * @returns
218
- * This object.
219
- */ _define_property$2(this, "node", this.environment.bind(this, "node"));
220
- /**
221
- * Sets the test environment to "happy-dom".
222
- *
223
- * @returns
224
- * This object.
225
- */ _define_property$2(this, "browser", this.environment.bind(this, "happy-dom"));
226
- /**
227
- * Sets the test coverage provider to "v8".
228
- *
229
- * @returns
230
- * This object.
231
- */ _define_property$2(this, "v8", this.coverage.bind(this, "v8"));
232
- /**
233
- * Sets the test coverage provider to "istanbul".
234
- *
235
- * @returns
236
- * This object.
237
- */ _define_property$2(this, "istanbul", this.coverage.bind(this, "istanbul"));
238
- this.test = {
239
- environment: "node",
240
- testTimeout: 30000,
241
- coverage: {
242
- all: false,
243
- provider: undefined
244
- }
245
- };
246
- }
247
- }
248
-
249
- function _define_property$1(obj, key, value) {
250
- if (key in obj) {
251
- Object.defineProperty(obj, key, {
252
- value: value,
253
- enumerable: true,
254
- configurable: true,
255
- writable: true
256
- });
257
- } else {
258
- obj[key] = value;
259
- }
260
- return obj;
261
- }
262
- function _object_spread(target) {
263
- for(var i = 1; i < arguments.length; i++){
264
- var source = arguments[i] != null ? arguments[i] : {};
265
- var ownKeys = Object.keys(source);
266
- if (typeof Object.getOwnPropertySymbols === "function") {
267
- ownKeys = ownKeys.concat(Object.getOwnPropertySymbols(source).filter(function(sym) {
268
- return Object.getOwnPropertyDescriptor(source, sym).enumerable;
269
- }));
270
- }
271
- ownKeys.forEach(function(key) {
272
- _define_property$1(target, key, source[key]);
273
- });
274
- }
275
- return target;
128
+ */
129
+ build() {
130
+ return cloneDeep(this.test);
131
+ }
276
132
  }
277
- function ownKeys(object, enumerableOnly) {
278
- var keys = Object.keys(object);
279
- if (Object.getOwnPropertySymbols) {
280
- var symbols = Object.getOwnPropertySymbols(object);
281
- keys.push.apply(keys, symbols);
282
- }
283
- return keys;
284
- }
285
- function _object_spread_props(target, source) {
286
- source = source != null ? source : {};
287
- if (Object.getOwnPropertyDescriptors) {
288
- Object.defineProperties(target, Object.getOwnPropertyDescriptors(source));
289
- } else {
290
- ownKeys(Object(source)).forEach(function(key) {
291
- Object.defineProperty(target, key, Object.getOwnPropertyDescriptor(source, key));
292
- });
293
- }
294
- return target;
295
- }
296
- /**
297
- * A config builder for the vite build system.
298
- *
299
- * This is helpful when building different types
300
- * of projects and keeping a standard.
301
- *
302
- * @example vite.config.ts
303
- *
304
- * ```ts
305
- * // Before Config Builder
306
- * export default defineConfig({
307
- * build: {
308
- * lib: {
309
- * entry: {
310
- * index: "./src/index.ts",
311
- * },
312
- * formats: ["cjs", "es"],
313
- * },
314
- * },
315
- * minify: false,
316
- * sourceMap: true,
317
- * plugins: [
318
- * swc.vite(),
319
- * tsConfigPaths(),
320
- * externalizeDeps(),
321
- * dtsPlugin({
322
- * compilerOptions: {
323
- * paths: {},
324
- * },
325
- * }),
326
- * ],
327
- * });
328
- * ```
329
- *
330
- * ```ts
331
- * // After config builder
332
- * const config = new ZViteConfigBuilder().library().build();
333
- * export default defineConfig(config);
334
- * ```
335
- */ class ZViteConfigBuilder {
336
- /**
133
+ class ZViteConfigBuilder {
134
+ /**
135
+ * Initializes a new instance of this object.
136
+ */
137
+ constructor() {
138
+ this.config = {
139
+ build: {
140
+ minify: true,
141
+ sourcemap: false
142
+ },
143
+ plugins: [tsConfigPaths()]
144
+ };
145
+ }
146
+ /**
337
147
  * Sets whether to minify the build output.
338
148
  *
339
149
  * @param minify -
@@ -341,13 +151,12 @@ function _object_spread_props(target, source) {
341
151
  *
342
152
  * @returns
343
153
  * This object.
344
- */ minify(minify = true) {
345
- this.config.build = _object_spread_props(_object_spread({}, this.config.build), {
346
- minify
347
- });
348
- return this;
349
- }
350
- /**
154
+ */
155
+ minify(minify = true) {
156
+ this.config.build = { ...this.config.build, minify };
157
+ return this;
158
+ }
159
+ /**
351
160
  * Adds a list of plugins.
352
161
  *
353
162
  * @param option -
@@ -355,14 +164,22 @@ function _object_spread_props(target, source) {
355
164
  *
356
165
  * @returns
357
166
  * This object.
358
- */ plugin(option = []) {
359
- // See constructor - the config plugins are guaranteed to
360
- // be set. The swc and paths plugins are automatically added.
361
- const plugins = this.config.plugins;
362
- this.config.plugins = plugins.concat(castArray(option));
363
- return this;
364
- }
365
- /**
167
+ */
168
+ plugin(option = []) {
169
+ const plugins = this.config.plugins;
170
+ this.config.plugins = plugins.concat(castArray(option));
171
+ return this;
172
+ }
173
+ /**
174
+ * Adds the swc plugin.
175
+ *
176
+ * This is mostly for nest projects as nest requires
177
+ * swc to support decorators.
178
+ */
179
+ swc() {
180
+ return this.plugin(swc.vite());
181
+ }
182
+ /**
366
183
  * Sets whether to generate source maps.
367
184
  *
368
185
  * @param sourcemap -
@@ -370,13 +187,12 @@ function _object_spread_props(target, source) {
370
187
  *
371
188
  * @returns
372
189
  * This object.
373
- */ sourceMap(sourcemap = true) {
374
- this.config.build = _object_spread_props(_object_spread({}, this.config.build), {
375
- sourcemap
376
- });
377
- return this;
378
- }
379
- /**
190
+ */
191
+ sourceMap(sourcemap = true) {
192
+ this.config.build = { ...this.config.build, sourcemap };
193
+ return this;
194
+ }
195
+ /**
380
196
  * Assigns the server options.
381
197
  *
382
198
  * @param options -
@@ -384,11 +200,12 @@ function _object_spread_props(target, source) {
384
200
  *
385
201
  * @returns
386
202
  * This object.
387
- */ server(options) {
388
- this.config.server = cloneDeep(options);
389
- return this;
390
- }
391
- /**
203
+ */
204
+ server(options) {
205
+ this.config.server = cloneDeep(options);
206
+ return this;
207
+ }
208
+ /**
392
209
  * Sets vite into library mode.
393
210
  *
394
211
  * @param lib -
@@ -400,22 +217,21 @@ function _object_spread_props(target, source) {
400
217
  *
401
218
  * @returns
402
219
  * This object.
403
- */ library(lib = new ZViteLibraryBuilder().index().build()) {
404
- this.config.build = _object_spread_props(_object_spread({}, this.config.build), {
405
- lib
406
- });
407
- const dts = dtsPlugin({
408
- compilerOptions: {
409
- // Always turn off paths when building for production. You want to make
410
- // sure that your build is building in the correct order and that your
411
- // actual paths are correct.
412
- paths: {}
413
- }
414
- });
415
- const external = externalizeDeps();
416
- return this.minify(false).sourceMap().plugin(external).plugin(dts);
417
- }
418
- /**
220
+ */
221
+ library(lib = new ZViteLibraryBuilder().index().build()) {
222
+ this.config.build = { ...this.config.build, lib };
223
+ const dts = dtsPlugin({
224
+ compilerOptions: {
225
+ // Always turn off paths when building for production. You want to make
226
+ // sure that your build is building in the correct order and that your
227
+ // actual paths are correct.
228
+ paths: {}
229
+ }
230
+ });
231
+ const external = externalizeDeps();
232
+ return this.minify(false).sourceMap().plugin(external).plugin(dts);
233
+ }
234
+ /**
419
235
  * Constructs the config to act as if it's compiling a node application.
420
236
  *
421
237
  * This is just an alias to {@link ZViteConfigBuilder.library} with two
@@ -426,12 +242,12 @@ function _object_spread_props(target, source) {
426
242
  *
427
243
  * @returns
428
244
  * This object.
429
- */ cli() {
430
- // A cli works similar to a library.
431
- const library = new ZViteLibraryBuilder().entry("index", "src/index.ts").entry("cli", "src/cli.ts").build();
432
- return this.library(library);
433
- }
434
- /**
245
+ */
246
+ cli() {
247
+ const library = new ZViteLibraryBuilder().entry("index", "src/index.mts").entry("cli", "src/cli.mts").build();
248
+ return this.library(library);
249
+ }
250
+ /**
435
251
  * Constructs the config to act as if it's compiling a nest application.
436
252
  *
437
253
  * This is just an alias to {@link ZViteConfigBuilder.library} with a single
@@ -441,113 +257,93 @@ function _object_spread_props(target, source) {
441
257
  *
442
258
  * @returns
443
259
  * This object.
444
- */ nest() {
445
- const library = new ZViteLibraryBuilder().entry("main", "src/main.mts").build();
446
- return this.library(library);
447
- }
448
- /**
260
+ */
261
+ nest() {
262
+ const library = new ZViteLibraryBuilder().entry("main", "src/main.mts").build();
263
+ return this.library(library).swc();
264
+ }
265
+ /**
449
266
  * Constructs the config to act as if it's compiling a web application.
450
267
  *
451
268
  * @returns
452
269
  * This object.
453
- */ web() {
454
- return this.minify().sourceMap(false).plugin(checker({
455
- typescript: true
456
- }));
457
- }
458
- /**
270
+ */
271
+ web() {
272
+ return this.minify().sourceMap(false).plugin(checker({ typescript: true }));
273
+ }
274
+ /**
275
+ * Constructs the config to compile a react application.
276
+ *
277
+ * @returns
278
+ * This object.
279
+ */
280
+ react() {
281
+ return this.web().plugin(react());
282
+ }
283
+ /**
459
284
  * Constructs the config to be for testing.
460
285
  *
461
286
  * @param options -
462
287
  * The test config to use. If this is falsy,
463
288
  * then a test setup using a monorepo with an
464
289
  * istanbul provider in node is used.
465
- */ test(options = new ZViteTestBuilder().node().istanbul().monorepo().build()) {
466
- this.config.test = options;
467
- return this;
468
- }
469
- /**
290
+ */
291
+ test(options = new ZViteTestBuilder().node().istanbul().monorepo().build()) {
292
+ this.config.test = options;
293
+ return this;
294
+ }
295
+ /**
470
296
  * Returns the currently built config.
471
297
  *
472
298
  * @returns
473
299
  * The currently built config.
474
- */ build() {
475
- return cloneDeep(this.config);
476
- }
477
- /**
478
- * Initializes a new instance of this object.
479
- */ constructor(){
480
- _define_property$1(this, "config", void 0);
481
- /**
482
- * An alias to {@link web}
483
- *
484
- * @returns
485
- * This object.
486
- */ _define_property$1(this, "react", this.web);
487
- this.config = {
488
- build: {
489
- minify: true,
490
- sourcemap: false
491
- },
492
- plugins: [
493
- swc.vite(),
494
- tsConfigPaths()
495
- ]
496
- };
497
- }
498
- }
499
-
500
- function _define_property(obj, key, value) {
501
- if (key in obj) {
502
- Object.defineProperty(obj, key, {
503
- value: value,
504
- enumerable: true,
505
- configurable: true,
506
- writable: true
507
- });
508
- } else {
509
- obj[key] = value;
510
- }
511
- return obj;
300
+ */
301
+ build() {
302
+ return cloneDeep(this.config);
303
+ }
512
304
  }
513
305
  class ZViteServerBuilder {
514
- allowedHost(name) {
515
- if (name === true) {
516
- this.options.allowedHosts = true;
517
- } else if (this.options.allowedHosts !== true) {
518
- const hosts = this.options.allowedHosts || [];
519
- this.options.allowedHosts = hosts.concat(name);
520
- }
521
- return this;
522
- }
523
- denyAllHosts() {
524
- delete this.options.allowedHosts;
525
- return this;
526
- }
527
- port(port) {
528
- this.options.port = port;
529
- return this;
530
- }
531
- strictPort() {
532
- this.options.strictPort = true;
533
- return this;
534
- }
535
- host(ip) {
536
- this.options.host = ip;
537
- return this;
538
- }
539
- dev() {
540
- return this.strictPort().host("0.0.0.0").allowedHost(true);
541
- }
542
- build() {
543
- const clone = cloneDeep(this.options);
544
- return omitBy(clone, isUndefined);
545
- }
546
- constructor(){
547
- _define_property(this, "options", {});
548
- _define_property(this, "localhost", this.host.bind(this, "127.0.0.1"));
549
- }
306
+ constructor() {
307
+ this.options = {};
308
+ this.localhost = this.host.bind(this, "127.0.0.1");
309
+ }
310
+ allowedHost(name) {
311
+ if (name === true) {
312
+ this.options.allowedHosts = true;
313
+ } else if (this.options.allowedHosts !== true) {
314
+ const hosts = this.options.allowedHosts || [];
315
+ this.options.allowedHosts = hosts.concat(name);
316
+ }
317
+ return this;
318
+ }
319
+ denyAllHosts() {
320
+ delete this.options.allowedHosts;
321
+ return this;
322
+ }
323
+ port(port) {
324
+ this.options.port = port;
325
+ return this;
326
+ }
327
+ strictPort() {
328
+ this.options.strictPort = true;
329
+ return this;
330
+ }
331
+ host(ip) {
332
+ this.options.host = ip;
333
+ return this;
334
+ }
335
+ dev() {
336
+ return this.strictPort().host("0.0.0.0").allowedHost(true);
337
+ }
338
+ build() {
339
+ const clone = cloneDeep(this.options);
340
+ return omitBy(clone, isUndefined);
341
+ }
550
342
  }
551
-
552
- export { ZViteConfigBuilder, ZViteLibraryBuilder, ZViteServerBuilder, ZViteTestBuilder };
343
+ export {
344
+ ZViteConfigBuilder,
345
+ ZViteLibraryBuilder,
346
+ ZViteServerBuilder,
347
+ ZViteTestBuilder
348
+ };
553
349
  //# sourceMappingURL=vite.js.map