@forsakringskassan/vite-lib-config 4.7.2 → 4.8.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/README.md CHANGED
@@ -6,9 +6,16 @@ Toolchain for building Vue framework libraries.
6
6
  - Transpiled with Babel.
7
7
  - Supports monorepo.
8
8
  - Optional: build pageobjects and selectors.
9
+ - Optional: shared typescript configuration.
9
10
 
10
11
  ## Configuration
11
12
 
13
+ Use `fk-write-config` to write boilerplate configuration files to the repository:
14
+
15
+ fk-write-config
16
+
17
+ By default it assumes `vitest` is used as test runner, use `--with-jest` or `--with-vitest` to explicitly set a test runner.
18
+
12
19
  ### Bundled dependencies
13
20
 
14
21
  By default all dependencies (`dependencies` and `peerDependencies`) are marked as external and not bundled in output files.
@@ -0,0 +1,13 @@
1
+ #!/usr/bin/env node
2
+
3
+ import { run } from "../dist/write-config.mjs";
4
+
5
+ const cwd = process.cwd();
6
+ const argv = process.argv.slice(2);
7
+
8
+ try {
9
+ await run(cwd, argv);
10
+ } catch (err) {
11
+ console.error(err);
12
+ process.exitCode = 1;
13
+ }
@@ -1314,6 +1314,47 @@ var require_coerce = __commonJS({
1314
1314
  }
1315
1315
  });
1316
1316
 
1317
+ // node_modules/semver/functions/truncate.js
1318
+ var require_truncate = __commonJS({
1319
+ "node_modules/semver/functions/truncate.js"(exports, module) {
1320
+ "use strict";
1321
+ var parse = require_parse();
1322
+ var constants = require_constants();
1323
+ var SemVer = require_semver();
1324
+ var truncate = (version2, truncation, options) => {
1325
+ if (!constants.RELEASE_TYPES.includes(truncation)) {
1326
+ return null;
1327
+ }
1328
+ const clonedVersion = cloneInputVersion(version2, options);
1329
+ return clonedVersion && doTruncation(clonedVersion, truncation);
1330
+ };
1331
+ var cloneInputVersion = (version2, options) => {
1332
+ const versionStringToParse = version2 instanceof SemVer ? version2.version : version2;
1333
+ return parse(versionStringToParse, options);
1334
+ };
1335
+ var doTruncation = (version2, truncation) => {
1336
+ if (isPrerelease(truncation)) {
1337
+ return version2.version;
1338
+ }
1339
+ version2.prerelease = [];
1340
+ switch (truncation) {
1341
+ case "major":
1342
+ version2.minor = 0;
1343
+ version2.patch = 0;
1344
+ break;
1345
+ case "minor":
1346
+ version2.patch = 0;
1347
+ break;
1348
+ }
1349
+ return version2.format();
1350
+ };
1351
+ var isPrerelease = (type) => {
1352
+ return type.startsWith("pre");
1353
+ };
1354
+ module.exports = truncate;
1355
+ }
1356
+ });
1357
+
1317
1358
  // node_modules/semver/internal/lrucache.js
1318
1359
  var require_lrucache = __commonJS({
1319
1360
  "node_modules/semver/internal/lrucache.js"(exports, module) {
@@ -2348,6 +2389,7 @@ var require_semver2 = __commonJS({
2348
2389
  var lte = require_lte();
2349
2390
  var cmp = require_cmp();
2350
2391
  var coerce = require_coerce();
2392
+ var truncate = require_truncate();
2351
2393
  var Comparator = require_comparator();
2352
2394
  var Range = require_range();
2353
2395
  var satisfies = require_satisfies();
@@ -2386,6 +2428,7 @@ var require_semver2 = __commonJS({
2386
2428
  lte,
2387
2429
  cmp,
2388
2430
  coerce,
2431
+ truncate,
2389
2432
  Comparator,
2390
2433
  Range,
2391
2434
  satisfies,
@@ -10,6 +10,7 @@ var extension = {
10
10
  async function build2(entrypoint, options) {
11
11
  const { external, formats } = options;
12
12
  if (!existsSync(entrypoint)) {
13
+ console.log(entrypoint, "does not exist, skipping");
13
14
  return;
14
15
  }
15
16
  const basename = path.basename(path.dirname(entrypoint));
@@ -3505,6 +3505,47 @@ var require_coerce = __commonJS({
3505
3505
  }
3506
3506
  });
3507
3507
 
3508
+ // node_modules/semver/functions/truncate.js
3509
+ var require_truncate = __commonJS({
3510
+ "node_modules/semver/functions/truncate.js"(exports2, module2) {
3511
+ "use strict";
3512
+ var parse3 = require_parse2();
3513
+ var constants = require_constants2();
3514
+ var SemVer = require_semver();
3515
+ var truncate = (version3, truncation, options) => {
3516
+ if (!constants.RELEASE_TYPES.includes(truncation)) {
3517
+ return null;
3518
+ }
3519
+ const clonedVersion = cloneInputVersion(version3, options);
3520
+ return clonedVersion && doTruncation(clonedVersion, truncation);
3521
+ };
3522
+ var cloneInputVersion = (version3, options) => {
3523
+ const versionStringToParse = version3 instanceof SemVer ? version3.version : version3;
3524
+ return parse3(versionStringToParse, options);
3525
+ };
3526
+ var doTruncation = (version3, truncation) => {
3527
+ if (isPrerelease(truncation)) {
3528
+ return version3.version;
3529
+ }
3530
+ version3.prerelease = [];
3531
+ switch (truncation) {
3532
+ case "major":
3533
+ version3.minor = 0;
3534
+ version3.patch = 0;
3535
+ break;
3536
+ case "minor":
3537
+ version3.patch = 0;
3538
+ break;
3539
+ }
3540
+ return version3.format();
3541
+ };
3542
+ var isPrerelease = (type) => {
3543
+ return type.startsWith("pre");
3544
+ };
3545
+ module2.exports = truncate;
3546
+ }
3547
+ });
3548
+
3508
3549
  // node_modules/semver/internal/lrucache.js
3509
3550
  var require_lrucache = __commonJS({
3510
3551
  "node_modules/semver/internal/lrucache.js"(exports2, module2) {
@@ -4539,6 +4580,7 @@ var require_semver2 = __commonJS({
4539
4580
  var lte = require_lte();
4540
4581
  var cmp = require_cmp();
4541
4582
  var coerce2 = require_coerce();
4583
+ var truncate = require_truncate();
4542
4584
  var Comparator = require_comparator();
4543
4585
  var Range = require_range();
4544
4586
  var satisfies = require_satisfies();
@@ -4577,6 +4619,7 @@ var require_semver2 = __commonJS({
4577
4619
  lte,
4578
4620
  cmp,
4579
4621
  coerce: coerce2,
4622
+ truncate,
4580
4623
  Comparator,
4581
4624
  Range,
4582
4625
  satisfies,
@@ -3503,6 +3503,47 @@ var require_coerce = __commonJS({
3503
3503
  }
3504
3504
  });
3505
3505
 
3506
+ // node_modules/semver/functions/truncate.js
3507
+ var require_truncate = __commonJS({
3508
+ "node_modules/semver/functions/truncate.js"(exports, module) {
3509
+ "use strict";
3510
+ var parse3 = require_parse2();
3511
+ var constants = require_constants2();
3512
+ var SemVer = require_semver();
3513
+ var truncate = (version3, truncation, options) => {
3514
+ if (!constants.RELEASE_TYPES.includes(truncation)) {
3515
+ return null;
3516
+ }
3517
+ const clonedVersion = cloneInputVersion(version3, options);
3518
+ return clonedVersion && doTruncation(clonedVersion, truncation);
3519
+ };
3520
+ var cloneInputVersion = (version3, options) => {
3521
+ const versionStringToParse = version3 instanceof SemVer ? version3.version : version3;
3522
+ return parse3(versionStringToParse, options);
3523
+ };
3524
+ var doTruncation = (version3, truncation) => {
3525
+ if (isPrerelease(truncation)) {
3526
+ return version3.version;
3527
+ }
3528
+ version3.prerelease = [];
3529
+ switch (truncation) {
3530
+ case "major":
3531
+ version3.minor = 0;
3532
+ version3.patch = 0;
3533
+ break;
3534
+ case "minor":
3535
+ version3.patch = 0;
3536
+ break;
3537
+ }
3538
+ return version3.format();
3539
+ };
3540
+ var isPrerelease = (type) => {
3541
+ return type.startsWith("pre");
3542
+ };
3543
+ module.exports = truncate;
3544
+ }
3545
+ });
3546
+
3506
3547
  // node_modules/semver/internal/lrucache.js
3507
3548
  var require_lrucache = __commonJS({
3508
3549
  "node_modules/semver/internal/lrucache.js"(exports, module) {
@@ -4537,6 +4578,7 @@ var require_semver2 = __commonJS({
4537
4578
  var lte = require_lte();
4538
4579
  var cmp = require_cmp();
4539
4580
  var coerce2 = require_coerce();
4581
+ var truncate = require_truncate();
4540
4582
  var Comparator = require_comparator();
4541
4583
  var Range = require_range();
4542
4584
  var satisfies = require_satisfies();
@@ -4575,6 +4617,7 @@ var require_semver2 = __commonJS({
4575
4617
  lte,
4576
4618
  cmp,
4577
4619
  coerce: coerce2,
4620
+ truncate,
4578
4621
  Comparator,
4579
4622
  Range,
4580
4623
  satisfies,
@@ -0,0 +1,663 @@
1
+ var __defProp = Object.defineProperty;
2
+ var __getOwnPropNames = Object.getOwnPropertyNames;
3
+ var __esm = (fn, res) => function __init() {
4
+ return fn && (res = (0, fn[__getOwnPropNames(fn)[0]])(fn = 0)), res;
5
+ };
6
+ var __export = (target, all) => {
7
+ for (var name in all)
8
+ __defProp(target, name, { get: all[name], enumerable: true });
9
+ };
10
+
11
+ // node_modules/p-locate/node_modules/yocto-queue/index.js
12
+ var Node, Queue;
13
+ var init_yocto_queue = __esm({
14
+ "node_modules/p-locate/node_modules/yocto-queue/index.js"() {
15
+ Node = class {
16
+ value;
17
+ next;
18
+ constructor(value) {
19
+ this.value = value;
20
+ }
21
+ };
22
+ Queue = class {
23
+ #head;
24
+ #tail;
25
+ #size;
26
+ constructor() {
27
+ this.clear();
28
+ }
29
+ enqueue(value) {
30
+ const node = new Node(value);
31
+ if (this.#head) {
32
+ this.#tail.next = node;
33
+ this.#tail = node;
34
+ } else {
35
+ this.#head = node;
36
+ this.#tail = node;
37
+ }
38
+ this.#size++;
39
+ }
40
+ dequeue() {
41
+ const current = this.#head;
42
+ if (!current) {
43
+ return;
44
+ }
45
+ this.#head = this.#head.next;
46
+ this.#size--;
47
+ if (!this.#head) {
48
+ this.#tail = void 0;
49
+ }
50
+ return current.value;
51
+ }
52
+ peek() {
53
+ if (!this.#head) {
54
+ return;
55
+ }
56
+ return this.#head.value;
57
+ }
58
+ clear() {
59
+ this.#head = void 0;
60
+ this.#tail = void 0;
61
+ this.#size = 0;
62
+ }
63
+ get size() {
64
+ return this.#size;
65
+ }
66
+ *[Symbol.iterator]() {
67
+ let current = this.#head;
68
+ while (current) {
69
+ yield current.value;
70
+ current = current.next;
71
+ }
72
+ }
73
+ *drain() {
74
+ while (this.#head) {
75
+ yield this.dequeue();
76
+ }
77
+ }
78
+ };
79
+ }
80
+ });
81
+
82
+ // node_modules/p-locate/node_modules/p-limit/index.js
83
+ function pLimit(concurrency) {
84
+ if (!((Number.isInteger(concurrency) || concurrency === Number.POSITIVE_INFINITY) && concurrency > 0)) {
85
+ throw new TypeError("Expected `concurrency` to be a number from 1 and up");
86
+ }
87
+ const queue = new Queue();
88
+ let activeCount = 0;
89
+ const next = () => {
90
+ activeCount--;
91
+ if (queue.size > 0) {
92
+ queue.dequeue()();
93
+ }
94
+ };
95
+ const run2 = async (fn, resolve, args) => {
96
+ activeCount++;
97
+ const result = (async () => fn(...args))();
98
+ resolve(result);
99
+ try {
100
+ await result;
101
+ } catch {
102
+ }
103
+ next();
104
+ };
105
+ const enqueue = (fn, resolve, args) => {
106
+ queue.enqueue(run2.bind(void 0, fn, resolve, args));
107
+ (async () => {
108
+ await Promise.resolve();
109
+ if (activeCount < concurrency && queue.size > 0) {
110
+ queue.dequeue()();
111
+ }
112
+ })();
113
+ };
114
+ const generator = (fn, ...args) => new Promise((resolve) => {
115
+ enqueue(fn, resolve, args);
116
+ });
117
+ Object.defineProperties(generator, {
118
+ activeCount: {
119
+ get: () => activeCount
120
+ },
121
+ pendingCount: {
122
+ get: () => queue.size
123
+ },
124
+ clearQueue: {
125
+ value: () => {
126
+ queue.clear();
127
+ }
128
+ }
129
+ });
130
+ return generator;
131
+ }
132
+ var init_p_limit = __esm({
133
+ "node_modules/p-locate/node_modules/p-limit/index.js"() {
134
+ init_yocto_queue();
135
+ }
136
+ });
137
+
138
+ // node_modules/p-locate/index.js
139
+ async function pLocate(iterable, tester, {
140
+ concurrency = Number.POSITIVE_INFINITY,
141
+ preserveOrder = true
142
+ } = {}) {
143
+ const limit = pLimit(concurrency);
144
+ const items = [...iterable].map((element) => [element, limit(testElement, element, tester)]);
145
+ const checkLimit = pLimit(preserveOrder ? 1 : Number.POSITIVE_INFINITY);
146
+ try {
147
+ await Promise.all(items.map((element) => checkLimit(finder, element)));
148
+ } catch (error) {
149
+ if (error instanceof EndError) {
150
+ return error.value;
151
+ }
152
+ throw error;
153
+ }
154
+ }
155
+ var EndError, testElement, finder;
156
+ var init_p_locate = __esm({
157
+ "node_modules/p-locate/index.js"() {
158
+ init_p_limit();
159
+ EndError = class extends Error {
160
+ constructor(value) {
161
+ super();
162
+ this.value = value;
163
+ }
164
+ };
165
+ testElement = async (element, tester) => tester(await element);
166
+ finder = async (element) => {
167
+ const values = await Promise.all(element);
168
+ if (values[1] === true) {
169
+ throw new EndError(values[0]);
170
+ }
171
+ return false;
172
+ };
173
+ }
174
+ });
175
+
176
+ // node_modules/locate-path/index.js
177
+ import process from "node:process";
178
+ import path from "node:path";
179
+ import fs, { promises as fsPromises } from "node:fs";
180
+ import { fileURLToPath } from "node:url";
181
+ function checkType(type) {
182
+ if (type === "both" || Object.hasOwn(typeMappings, type)) {
183
+ return;
184
+ }
185
+ throw new Error(`Invalid type specified: ${type}`);
186
+ }
187
+ async function locatePath(paths, {
188
+ cwd = process.cwd(),
189
+ type = "file",
190
+ allowSymlinks = true,
191
+ concurrency,
192
+ preserveOrder
193
+ } = {}) {
194
+ checkType(type);
195
+ cwd = toPath(cwd);
196
+ const statFunction = allowSymlinks ? fsPromises.stat : fsPromises.lstat;
197
+ return pLocate(paths, async (path_) => {
198
+ try {
199
+ const stat = await statFunction(path.resolve(cwd, path_));
200
+ return matchType(type, stat);
201
+ } catch {
202
+ return false;
203
+ }
204
+ }, { concurrency, preserveOrder });
205
+ }
206
+ function locatePathSync(paths, {
207
+ cwd = process.cwd(),
208
+ type = "file",
209
+ allowSymlinks = true
210
+ } = {}) {
211
+ checkType(type);
212
+ cwd = toPath(cwd);
213
+ const statFunction = allowSymlinks ? fs.statSync : fs.lstatSync;
214
+ for (const path_ of paths) {
215
+ try {
216
+ const stat = statFunction(path.resolve(cwd, path_), {
217
+ throwIfNoEntry: false
218
+ });
219
+ if (!stat) {
220
+ continue;
221
+ }
222
+ if (matchType(type, stat)) {
223
+ return path_;
224
+ }
225
+ } catch {
226
+ }
227
+ }
228
+ }
229
+ var typeMappings, matchType, toPath;
230
+ var init_locate_path = __esm({
231
+ "node_modules/locate-path/index.js"() {
232
+ init_p_locate();
233
+ typeMappings = {
234
+ directory: "isDirectory",
235
+ file: "isFile"
236
+ };
237
+ matchType = (type, stat) => type === "both" ? stat.isFile() || stat.isDirectory() : stat[typeMappings[type]]();
238
+ toPath = (urlOrPath) => urlOrPath instanceof URL ? fileURLToPath(urlOrPath) : urlOrPath;
239
+ }
240
+ });
241
+
242
+ // node_modules/unicorn-magic/default.js
243
+ var init_default = __esm({
244
+ "node_modules/unicorn-magic/default.js"() {
245
+ }
246
+ });
247
+
248
+ // node_modules/unicorn-magic/node.js
249
+ import { promisify } from "node:util";
250
+ import { execFile as execFileCallback, execFileSync as execFileSyncOriginal } from "node:child_process";
251
+ import { fileURLToPath as fileURLToPath2 } from "node:url";
252
+ function toPath2(urlOrPath) {
253
+ return urlOrPath instanceof URL ? fileURLToPath2(urlOrPath) : urlOrPath;
254
+ }
255
+ var execFileOriginal, TEN_MEGABYTES_IN_BYTES;
256
+ var init_node = __esm({
257
+ "node_modules/unicorn-magic/node.js"() {
258
+ init_default();
259
+ execFileOriginal = promisify(execFileCallback);
260
+ TEN_MEGABYTES_IN_BYTES = 10 * 1024 * 1024;
261
+ }
262
+ });
263
+
264
+ // node_modules/find-up/index.js
265
+ var find_up_exports = {};
266
+ __export(find_up_exports, {
267
+ findDown: () => findDown,
268
+ findDownSync: () => findDownSync,
269
+ findUp: () => findUp,
270
+ findUpMultiple: () => findUpMultiple,
271
+ findUpMultipleSync: () => findUpMultipleSync,
272
+ findUpStop: () => findUpStop,
273
+ findUpSync: () => findUpSync
274
+ });
275
+ import path2 from "node:path";
276
+ import fs2 from "node:fs";
277
+ async function findUpMultiple(name, options = {}) {
278
+ let directory = path2.resolve(toPath2(options.cwd) ?? "");
279
+ const { root } = path2.parse(directory);
280
+ const stopAt = path2.resolve(directory, toPath2(options.stopAt) ?? root);
281
+ const limit = options.limit ?? Number.POSITIVE_INFINITY;
282
+ const paths = [name].flat();
283
+ const runMatcher = async (locateOptions) => {
284
+ if (typeof name !== "function") {
285
+ return locatePath(paths, locateOptions);
286
+ }
287
+ const foundPath = await name(locateOptions.cwd);
288
+ if (typeof foundPath === "string") {
289
+ return locatePath([foundPath], locateOptions);
290
+ }
291
+ return foundPath;
292
+ };
293
+ const matches = [];
294
+ while (true) {
295
+ const foundPath = await runMatcher({ ...options, cwd: directory });
296
+ if (foundPath === findUpStop) {
297
+ break;
298
+ }
299
+ if (foundPath) {
300
+ matches.push(path2.resolve(directory, foundPath));
301
+ }
302
+ if (directory === stopAt || matches.length >= limit) {
303
+ break;
304
+ }
305
+ directory = path2.dirname(directory);
306
+ }
307
+ return matches;
308
+ }
309
+ function findUpMultipleSync(name, options = {}) {
310
+ let directory = path2.resolve(toPath2(options.cwd) ?? "");
311
+ const { root } = path2.parse(directory);
312
+ const stopAt = path2.resolve(directory, toPath2(options.stopAt) ?? root);
313
+ const limit = options.limit ?? Number.POSITIVE_INFINITY;
314
+ const paths = [name].flat();
315
+ const runMatcher = (locateOptions) => {
316
+ if (typeof name !== "function") {
317
+ return locatePathSync(paths, locateOptions);
318
+ }
319
+ const foundPath = name(locateOptions.cwd);
320
+ if (typeof foundPath === "string") {
321
+ return locatePathSync([foundPath], locateOptions);
322
+ }
323
+ return foundPath;
324
+ };
325
+ const matches = [];
326
+ while (true) {
327
+ const foundPath = runMatcher({ ...options, cwd: directory });
328
+ if (foundPath === findUpStop) {
329
+ break;
330
+ }
331
+ if (foundPath) {
332
+ matches.push(path2.resolve(directory, foundPath));
333
+ }
334
+ if (directory === stopAt || matches.length >= limit) {
335
+ break;
336
+ }
337
+ directory = path2.dirname(directory);
338
+ }
339
+ return matches;
340
+ }
341
+ async function findUp(name, options = {}) {
342
+ const matches = await findUpMultiple(name, { ...options, limit: 1 });
343
+ return matches[0];
344
+ }
345
+ function findUpSync(name, options = {}) {
346
+ const matches = findUpMultipleSync(name, { ...options, limit: 1 });
347
+ return matches[0];
348
+ }
349
+ async function findDownDepthFirst(directory, paths, maxDepth, locateOptions, currentDepth = 0) {
350
+ const found = await locatePath(paths, { cwd: directory, ...locateOptions });
351
+ if (found) {
352
+ return path2.resolve(directory, found);
353
+ }
354
+ if (currentDepth >= maxDepth) {
355
+ return void 0;
356
+ }
357
+ try {
358
+ const entries = await fs2.promises.readdir(directory, { withFileTypes: true });
359
+ for (const entry of entries) {
360
+ if (entry.isDirectory()) {
361
+ const result = await findDownDepthFirst(
362
+ path2.join(directory, entry.name),
363
+ paths,
364
+ maxDepth,
365
+ locateOptions,
366
+ currentDepth + 1
367
+ );
368
+ if (result) {
369
+ return result;
370
+ }
371
+ }
372
+ }
373
+ } catch {
374
+ }
375
+ return void 0;
376
+ }
377
+ function findDownDepthFirstSync(directory, paths, maxDepth, locateOptions, currentDepth = 0) {
378
+ const found = locatePathSync(paths, { cwd: directory, ...locateOptions });
379
+ if (found) {
380
+ return path2.resolve(directory, found);
381
+ }
382
+ if (currentDepth >= maxDepth) {
383
+ return void 0;
384
+ }
385
+ try {
386
+ const entries = fs2.readdirSync(directory, { withFileTypes: true });
387
+ for (const entry of entries) {
388
+ if (entry.isDirectory()) {
389
+ const result = findDownDepthFirstSync(
390
+ path2.join(directory, entry.name),
391
+ paths,
392
+ maxDepth,
393
+ locateOptions,
394
+ currentDepth + 1
395
+ );
396
+ if (result) {
397
+ return result;
398
+ }
399
+ }
400
+ }
401
+ } catch {
402
+ }
403
+ return void 0;
404
+ }
405
+ function prepareFindDownOptions(name, options) {
406
+ const startDirectory = path2.resolve(toPath2(options.cwd) ?? "");
407
+ const maxDepth = Math.max(0, options.depth ?? 1);
408
+ const paths = [name].flat();
409
+ const { type = "file", allowSymlinks = true, strategy = "breadth" } = options;
410
+ const locateOptions = { type, allowSymlinks };
411
+ return {
412
+ startDirectory,
413
+ maxDepth,
414
+ paths,
415
+ locateOptions,
416
+ strategy
417
+ };
418
+ }
419
+ async function findDownBreadthFirst(startDirectory, paths, maxDepth, locateOptions) {
420
+ const queue = [{ directory: startDirectory, depth: 0 }];
421
+ while (queue.length > 0) {
422
+ const { directory, depth } = queue.shift();
423
+ const found = await locatePath(paths, { cwd: directory, ...locateOptions });
424
+ if (found) {
425
+ return path2.resolve(directory, found);
426
+ }
427
+ if (depth >= maxDepth) {
428
+ continue;
429
+ }
430
+ try {
431
+ const entries = await fs2.promises.readdir(directory, { withFileTypes: true });
432
+ for (const entry of entries) {
433
+ if (entry.isDirectory()) {
434
+ queue.push({ directory: path2.join(directory, entry.name), depth: depth + 1 });
435
+ }
436
+ }
437
+ } catch {
438
+ }
439
+ }
440
+ return void 0;
441
+ }
442
+ function findDownBreadthFirstSync(startDirectory, paths, maxDepth, locateOptions) {
443
+ const queue = [{ directory: startDirectory, depth: 0 }];
444
+ while (queue.length > 0) {
445
+ const { directory, depth } = queue.shift();
446
+ const found = locatePathSync(paths, { cwd: directory, ...locateOptions });
447
+ if (found) {
448
+ return path2.resolve(directory, found);
449
+ }
450
+ if (depth >= maxDepth) {
451
+ continue;
452
+ }
453
+ try {
454
+ const entries = fs2.readdirSync(directory, { withFileTypes: true });
455
+ for (const entry of entries) {
456
+ if (entry.isDirectory()) {
457
+ queue.push({ directory: path2.join(directory, entry.name), depth: depth + 1 });
458
+ }
459
+ }
460
+ } catch {
461
+ }
462
+ }
463
+ return void 0;
464
+ }
465
+ async function findDown(name, options = {}) {
466
+ const { startDirectory, maxDepth, paths, locateOptions, strategy } = prepareFindDownOptions(name, options);
467
+ return strategy === "depth" ? findDownDepthFirst(startDirectory, paths, maxDepth, locateOptions) : findDownBreadthFirst(startDirectory, paths, maxDepth, locateOptions);
468
+ }
469
+ function findDownSync(name, options = {}) {
470
+ const { startDirectory, maxDepth, paths, locateOptions, strategy } = prepareFindDownOptions(name, options);
471
+ return strategy === "depth" ? findDownDepthFirstSync(startDirectory, paths, maxDepth, locateOptions) : findDownBreadthFirstSync(startDirectory, paths, maxDepth, locateOptions);
472
+ }
473
+ var findUpStop;
474
+ var init_find_up = __esm({
475
+ "node_modules/find-up/index.js"() {
476
+ init_locate_path();
477
+ init_node();
478
+ findUpStop = /* @__PURE__ */ Symbol("findUpStop");
479
+ }
480
+ });
481
+
482
+ // src/write-config.ts
483
+ import fs3 from "node:fs/promises";
484
+ import path3 from "node:path";
485
+ var boilerplate = `/* This file was generated by @forsakringskassan/vite-lib-config. Changes may be overwritten! */`;
486
+ function detectTestRunner(flags) {
487
+ if (flags.has("--with-jest")) {
488
+ return "jest";
489
+ } else if (flags.has("--with-vitest")) {
490
+ return "vitest";
491
+ } else {
492
+ return "vitest";
493
+ }
494
+ }
495
+ async function serializeJson(data) {
496
+ const { format, resolveConfig } = await import("prettier");
497
+ const content = JSON.stringify(data, null, 4);
498
+ const filepath = "tsconfig.json";
499
+ const config = await resolveConfig(filepath, { editorconfig: true });
500
+ const formatted = await format(content, { ...config, filepath });
501
+ return formatted;
502
+ }
503
+ async function generateTsconfig(options) {
504
+ const { name, enablePageobjects, enableSelectors, testRunner } = options;
505
+ const config = {
506
+ extends: "@forsakringskassan/vite-lib-config/tsconfig.root.json",
507
+ compilerOptions: void 0,
508
+ include: void 0,
509
+ exclude: void 0,
510
+ references: [
511
+ { path: "./tsconfig.lib.json" },
512
+ { path: "./tsconfig.cypress.json" }
513
+ ]
514
+ };
515
+ if (testRunner === "jest") {
516
+ config.extends = [
517
+ "@forsakringskassan/vite-lib-config/tsconfig.root.json",
518
+ "@fkui/tsconfig/recommended",
519
+ "@fkui/tsconfig/vue"
520
+ ];
521
+ config.compilerOptions = {
522
+ declarationDir: "temp/jest",
523
+ paths: {
524
+ [name]: ["./src/index.ts"]
525
+ }
526
+ };
527
+ config.include = ["src/@types/*.ts"];
528
+ config.exclude = ["src/@types/cypress.d.ts"];
529
+ }
530
+ if (enablePageobjects) {
531
+ config.references?.push({ path: "./tsconfig.pageobjects.json" });
532
+ }
533
+ if (enableSelectors) {
534
+ config.references?.push({ path: "./tsconfig.selectors.json" });
535
+ }
536
+ return [boilerplate, await serializeJson(config)].join("\n\n");
537
+ }
538
+ async function generateTsconfigLib(options) {
539
+ const { name, testRunner } = options;
540
+ const config = {
541
+ extends: "@forsakringskassan/vite-lib-config/tsconfig.lib.json",
542
+ compilerOptions: {
543
+ types: testRunner === "jest" ? ["node", "jest", "vite/client"] : void 0,
544
+ paths: {
545
+ [`${name}/cypress`]: ["./src/cypress/index.ts"],
546
+ [`${name}/selectors`]: ["./src/selectors/index.ts"],
547
+ [name]: ["./src/index.ts"]
548
+ }
549
+ }
550
+ };
551
+ return [boilerplate, await serializeJson(config)].join("\n\n");
552
+ }
553
+ async function generateTsconfigCypress(options) {
554
+ const { name, cypressConfigPath } = options;
555
+ const config = {
556
+ extends: [
557
+ cypressConfigPath,
558
+ "@forsakringskassan/vite-lib-config/tsconfig.cypress.json"
559
+ ],
560
+ compilerOptions: {
561
+ paths: {
562
+ [`${name}/cypress`]: ["./src/cypress/index.ts"],
563
+ [`${name}/selectors`]: ["./src/selectors/index.ts"],
564
+ [name]: ["./src/index.ts"]
565
+ }
566
+ }
567
+ };
568
+ return [boilerplate, await serializeJson(config)].join("\n\n");
569
+ }
570
+ async function generateTsconfigSelectors(options) {
571
+ if (!options.enableSelectors) {
572
+ return null;
573
+ }
574
+ const config = {
575
+ extends: "@forsakringskassan/vite-lib-config/tsconfig.selectors.json"
576
+ };
577
+ return [boilerplate, await serializeJson(config)].join("\n\n");
578
+ }
579
+ async function generateTsconfigPageobjects(options) {
580
+ if (!options.enablePageobjects) {
581
+ return null;
582
+ }
583
+ const config = {
584
+ extends: "@forsakringskassan/vite-lib-config/tsconfig.pageobjects.json"
585
+ };
586
+ return [boilerplate, await serializeJson(config)].join("\n\n");
587
+ }
588
+ async function readJsonFile(filePath) {
589
+ const content = await fs3.readFile(filePath, "utf8");
590
+ return JSON.parse(content);
591
+ }
592
+ async function writeJsonFile(cwd, filename, content) {
593
+ const filePath = path3.join(cwd, filename);
594
+ await fs3.writeFile(filePath, content, "utf8");
595
+ console.log(filename, "written");
596
+ }
597
+ async function findCypressConfigPath(cwd) {
598
+ const { findUp: findUp2 } = await Promise.resolve().then(() => (init_find_up(), find_up_exports));
599
+ const absolutePath = await findUp2("cypress/tsconfig.json", { cwd });
600
+ if (absolutePath) {
601
+ return path3.relative(cwd, absolutePath).replaceAll("\\", "/");
602
+ }
603
+ return "cypress/tsconfig.json";
604
+ }
605
+ function isTSConfigFile(filename) {
606
+ return filename.startsWith("tsconfig.") && filename.endsWith(".json");
607
+ }
608
+ async function run(cwd, argv) {
609
+ const flags = new Set(argv.filter((it) => it.startsWith("--")));
610
+ if (flags.has("--help")) {
611
+ console.log("usage: fk-write-config [OPTIONS..]");
612
+ console.log(`
613
+ --help Show this help.
614
+ --with-jest Use Jest as test runner.
615
+ --with-vitest Use Vitest as test runner.
616
+ `);
617
+ return;
618
+ }
619
+ const pkg = await readJsonFile(path3.join(cwd, "package.json"));
620
+ const cypressConfigPath = await findCypressConfigPath(cwd);
621
+ const testRunner = detectTestRunner(flags);
622
+ const options = {
623
+ name: pkg.name,
624
+ cypressConfigPath,
625
+ testRunner,
626
+ enablePageobjects: Boolean(pkg.exports?.["./cypress"]),
627
+ enableSelectors: Boolean(pkg.exports?.["./selectors"])
628
+ };
629
+ const generated = /* @__PURE__ */ new Map([
630
+ ["tsconfig.json", generateTsconfig(options)],
631
+ ["tsconfig.lib.json", generateTsconfigLib(options)],
632
+ ["tsconfig.cypress.json", generateTsconfigCypress(options)],
633
+ ["tsconfig.selectors.json", generateTsconfigSelectors(options)],
634
+ ["tsconfig.pageobjects.json", generateTsconfigPageobjects(options)]
635
+ ]);
636
+ console.group("Writing TypeScript configuration");
637
+ console.log("Test runner:", testRunner);
638
+ console.log();
639
+ const written = /* @__PURE__ */ new Set();
640
+ for (const [filename, promise] of generated.entries()) {
641
+ const content = await promise;
642
+ if (content) {
643
+ await writeJsonFile(cwd, filename, content);
644
+ written.add(filename);
645
+ }
646
+ }
647
+ const entries = await fs3.readdir(cwd);
648
+ for (const entry of entries) {
649
+ if (isTSConfigFile(entry) && !written.has(entry)) {
650
+ await fs3.unlink(path3.join(cwd, entry));
651
+ console.log(entry, "removed");
652
+ }
653
+ }
654
+ console.groupEnd();
655
+ }
656
+ export {
657
+ generateTsconfig,
658
+ generateTsconfigCypress,
659
+ generateTsconfigLib,
660
+ generateTsconfigPageobjects,
661
+ generateTsconfigSelectors,
662
+ run
663
+ };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@forsakringskassan/vite-lib-config",
3
- "version": "4.7.2",
3
+ "version": "4.8.1",
4
4
  "description": "Försäkringskassan toolchain to build libraries with Vite",
5
5
  "keywords": [
6
6
  "vite"
@@ -18,29 +18,36 @@
18
18
  "types": "./dist/index.d.ts",
19
19
  "require": "./dist/index.js"
20
20
  },
21
+ "./assets/*": "./assets/*",
21
22
  "./babel": {
22
23
  "types": "./dist/babel.config.d.ts",
23
24
  "require": "./dist/babel.config.js"
24
25
  },
26
+ "./tsconfig.root.json": "./tsconfig/tsconfig.root.json",
27
+ "./tsconfig.cypress.json": "./tsconfig/tsconfig.cypress.json",
28
+ "./tsconfig.lib.json": "./tsconfig/tsconfig.lib.json",
29
+ "./tsconfig.pageobjects.json": "./tsconfig/tsconfig.pageobjects.json",
30
+ "./tsconfig.selectors.json": "./tsconfig/tsconfig.selectors.json",
25
31
  "./vite": {
26
32
  "types": "./dist/vite.config.d.ts",
27
33
  "import": "./dist/vite.config.mjs",
28
34
  "require": "./dist/vite.config.cjs"
29
- },
30
- "./assets/*": "./assets/*"
35
+ }
31
36
  },
32
37
  "main": "./dist/index.js",
33
38
  "types": "./dist/index.d.ts",
34
39
  "bin": {
35
40
  "fk-api-extractor": "bin/api-extractor.mjs",
36
41
  "fk-build-vue-lib": "bin/build-vue-lib.mjs",
37
- "fk-build-selectors": "bin/build-selectors.mjs"
42
+ "fk-build-selectors": "bin/build-selectors.mjs",
43
+ "fk-write-config": "bin/write-config.mjs"
38
44
  },
39
45
  "files": [
40
46
  "*.d.ts",
41
47
  "assets",
42
48
  "bin",
43
- "dist"
49
+ "dist",
50
+ "tsconfig"
44
51
  ],
45
52
  "dependencies": {
46
53
  "@microsoft/api-extractor": "7.58.7",
@@ -50,7 +57,9 @@
50
57
  "peerDependencies": {
51
58
  "@babel/core": "^7.22.0",
52
59
  "@babel/plugin-transform-nullish-coalescing-operator": "^7.22.0",
60
+ "@fkui/tsconfig": ">= 6.3.0",
53
61
  "@forsakringskassan/apimock-express": "^1.1.0 || ^2.0.0",
62
+ "prettier": "^3.0.0",
54
63
  "typescript": "^5.0.2 || ^6.0.2",
55
64
  "vite": "^5.0.0 || ^6.0.0 || ^7.0.0 || ^8.0.0",
56
65
  "vue": "^3.0.0"
@@ -0,0 +1 @@
1
+ `tsconfig.json` files for usage in the consumer library.
@@ -0,0 +1,18 @@
1
+ {
2
+ "$schema": "https://www.schemastore.org/tsconfig",
3
+ "compilerOptions": {
4
+ "composite": true,
5
+ "tsBuildInfoFile": "${configDir}/temp/tsconfig.cypress.tsbuildinfo",
6
+ "outDir": "${configDir}/temp",
7
+ "rootDir": "${configDir}/src",
8
+ "emitDeclarationOnly": true,
9
+ "declarationDir": "temp/cypress",
10
+ "skipLibCheck": true
11
+ },
12
+ "include": [
13
+ "${configDir}/src/**/*.ts",
14
+ "${configDir}/src/**/*.vue",
15
+ "${configDir}/src/**/*.cy.ts"
16
+ ],
17
+ "exclude": ["${configDir}/src/**/*.spec.ts"]
18
+ }
@@ -0,0 +1,16 @@
1
+ {
2
+ "$schema": "https://www.schemastore.org/tsconfig",
3
+ "extends": ["@fkui/tsconfig/recommended", "@fkui/tsconfig/vue"],
4
+ "compilerOptions": {
5
+ "composite": true,
6
+ "tsBuildInfoFile": "${configDir}/temp/tsconfig.lib.tsbuildinfo",
7
+ "types": ["node", "vite/client"]
8
+ },
9
+ "include": ["${configDir}/src/**/*.ts", "${configDir}/src/**/*.vue"],
10
+ "exclude": [
11
+ "${configDir}/src/@types/cypress.d.ts",
12
+ "${configDir}/src/cypress/**/*.ts",
13
+ "${configDir}/src/**/*.cy.ts",
14
+ "${configDir}/src/**/*.pageobject.ts"
15
+ ]
16
+ }
@@ -0,0 +1,16 @@
1
+ {
2
+ "extends": "@fkui/tsconfig/recommended",
3
+ "compilerOptions": {
4
+ "composite": true,
5
+ "tsBuildInfoFile": "${configDir}/temp/tsconfig.pageobjects.tsbuildinfo",
6
+ "types": ["cypress"],
7
+ "emitDeclarationOnly": true,
8
+ "skipLibCheck": true
9
+ },
10
+ "include": [
11
+ "${configDir}/src/cypress/**/*.ts",
12
+ "${configDir}/src/selectors/**/*.ts",
13
+ "${configDir}/src/**/*.pageobject.ts"
14
+ ],
15
+ "exclude": ["${configDir}/src/**/*.cy.ts", "${configDir}/src/**/*.spec.ts"]
16
+ }
@@ -0,0 +1,20 @@
1
+ {
2
+ "compilerOptions": {
3
+ "tsBuildInfoFile": "${configDir}/temp/tsconfig.tsbuildinfo"
4
+ },
5
+ "files": [],
6
+ "references": [
7
+ {
8
+ "path": "${configDir}/tsconfig.lib.json"
9
+ },
10
+ {
11
+ "path": "${configDir}/tsconfig.pageobjects.json"
12
+ },
13
+ {
14
+ "path": "${configDir}/tsconfig.cypress.json"
15
+ },
16
+ {
17
+ "path": "${configDir}/tsconfig.selectors.json"
18
+ }
19
+ ]
20
+ }
@@ -0,0 +1,11 @@
1
+ {
2
+ "extends": "@fkui/tsconfig/recommended",
3
+ "compilerOptions": {
4
+ "composite": true,
5
+ "tsBuildInfoFile": "${configDir}/temp/tsconfig.selectors.tsbuildinfo",
6
+ "types": [],
7
+ "emitDeclarationOnly": true
8
+ },
9
+ "include": ["${configDir}/src/selectors/**/*.ts"],
10
+ "exclude": ["${configDir}/src/**/*.spec.ts"]
11
+ }