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