@forsakringskassan/vite-lib-config 5.2.0 → 5.3.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/vite.config.cjs +33 -14
- package/dist/vite.config.mjs +33 -14
- package/dist/write-config.mjs +157 -5
- package/package.json +1 -1
package/dist/vite.config.cjs
CHANGED
|
@@ -4732,7 +4732,7 @@ var import_node_path = __toESM(require("node:path"), 1);
|
|
|
4732
4732
|
var import_node_crypto = __toESM(require("node:crypto"), 1);
|
|
4733
4733
|
var import_node_tty = require("node:tty");
|
|
4734
4734
|
var import_node_util = require("node:util");
|
|
4735
|
-
var version = "6.0.
|
|
4735
|
+
var version = "6.0.8";
|
|
4736
4736
|
function resolveCompiler(root) {
|
|
4737
4737
|
const compiler = tryResolveCompiler(root) || tryResolveCompiler();
|
|
4738
4738
|
if (!compiler) throw new Error("Failed to resolve vue/compiler-sfc.\n@vitejs/plugin-vue requires vue (>=3.2.25) to be present in the dependency tree.");
|
|
@@ -4849,6 +4849,18 @@ function createRollupError(id2, error) {
|
|
|
4849
4849
|
};
|
|
4850
4850
|
return rollupError;
|
|
4851
4851
|
}
|
|
4852
|
+
function isVaporMode(descriptor, options) {
|
|
4853
|
+
if (descriptor.vapor) return true;
|
|
4854
|
+
if (options.features?.vapor) return canForceVaporMode(descriptor);
|
|
4855
|
+
return false;
|
|
4856
|
+
}
|
|
4857
|
+
function canForceVaporMode(descriptor) {
|
|
4858
|
+
if (descriptor.filename.endsWith(".vue")) {
|
|
4859
|
+
if (descriptor.scriptSetup) return true;
|
|
4860
|
+
if (descriptor.script) return false;
|
|
4861
|
+
}
|
|
4862
|
+
return true;
|
|
4863
|
+
}
|
|
4852
4864
|
async function transformTemplateAsModule(code2, filename, descriptor, options, pluginContext, ssr, customElement) {
|
|
4853
4865
|
const result = compile(code2, filename, descriptor, options, pluginContext, ssr, customElement);
|
|
4854
4866
|
let returnCode = result.code;
|
|
@@ -4923,7 +4935,7 @@ function resolveTemplateCompilerOptions(descriptor, options, filename, ssr) {
|
|
|
4923
4935
|
if (lang && /tsx?$/.test(lang) && !expressionPlugins.includes("typescript")) expressionPlugins.push("typescript");
|
|
4924
4936
|
return {
|
|
4925
4937
|
...options.template,
|
|
4926
|
-
vapor: descriptor
|
|
4938
|
+
vapor: isVaporMode(descriptor, options),
|
|
4927
4939
|
id: id2,
|
|
4928
4940
|
ast: canReuseAST(options.compiler.version) ? descriptor.template?.ast : void 0,
|
|
4929
4941
|
filename,
|
|
@@ -4989,6 +5001,7 @@ function resolveScript(descriptor, options, ssr, customElement) {
|
|
|
4989
5001
|
sourceMap: options.sourceMap,
|
|
4990
5002
|
genDefaultAs: canInlineMain(descriptor, options) ? scriptIdentifier : void 0,
|
|
4991
5003
|
customElement,
|
|
5004
|
+
vapor: isVaporMode(descriptor, options),
|
|
4992
5005
|
propsDestructure: options.features?.propsDestructure ?? options.script?.propsDestructure
|
|
4993
5006
|
});
|
|
4994
5007
|
if (!options.isProduction && resolved?.deps) {
|
|
@@ -5012,8 +5025,8 @@ function canInlineMain(descriptor, options) {
|
|
|
5012
5025
|
var comma = ",".charCodeAt(0);
|
|
5013
5026
|
var semicolon = ";".charCodeAt(0);
|
|
5014
5027
|
var chars = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/";
|
|
5015
|
-
var intToChar = new Uint8Array(64);
|
|
5016
|
-
var charToInt = new Uint8Array(128);
|
|
5028
|
+
var intToChar = /* @__PURE__ */ new Uint8Array(64);
|
|
5029
|
+
var charToInt = /* @__PURE__ */ new Uint8Array(128);
|
|
5017
5030
|
for (let i = 0; i < chars.length; i++) {
|
|
5018
5031
|
const c = chars.charCodeAt(i);
|
|
5019
5032
|
intToChar[i] = c;
|
|
@@ -5624,8 +5637,8 @@ function createDebug$1(namespace, options) {
|
|
|
5624
5637
|
options.formatArgs.call(debug2, diff, args);
|
|
5625
5638
|
debug2.log(...args);
|
|
5626
5639
|
};
|
|
5627
|
-
debug2.extend = function(
|
|
5628
|
-
return createDebug$1(this.namespace + delimiter +
|
|
5640
|
+
debug2.extend = function(namespace2, delimiter = ":") {
|
|
5641
|
+
return createDebug$1(this.namespace + delimiter + namespace2, {
|
|
5629
5642
|
useColors: this.useColors,
|
|
5630
5643
|
color: this.color,
|
|
5631
5644
|
formatArgs: this.formatArgs,
|
|
@@ -5656,8 +5669,8 @@ function createDebug$1(namespace, options) {
|
|
|
5656
5669
|
}
|
|
5657
5670
|
var names = [];
|
|
5658
5671
|
var skips = [];
|
|
5659
|
-
function enable(namespaces
|
|
5660
|
-
globalNamespaces = namespaces
|
|
5672
|
+
function enable(namespaces) {
|
|
5673
|
+
globalNamespaces = namespaces;
|
|
5661
5674
|
names = [];
|
|
5662
5675
|
skips = [];
|
|
5663
5676
|
const split = globalNamespaces.trim().replace(/\s+/g, ",").split(",").filter(Boolean);
|
|
@@ -5764,7 +5777,7 @@ var inspectOpts = Object.keys(process.env).filter((key) => /^debug_/i.test(key))
|
|
|
5764
5777
|
else value = Number(value);
|
|
5765
5778
|
obj[prop] = value;
|
|
5766
5779
|
return obj;
|
|
5767
|
-
},
|
|
5780
|
+
}, /* @__PURE__ */ Object.create(null));
|
|
5768
5781
|
function useColors() {
|
|
5769
5782
|
return "colors" in inspectOpts ? Boolean(inspectOpts.colors) : (0, import_node_tty.isatty)(process.stderr.fd);
|
|
5770
5783
|
}
|
|
@@ -5773,8 +5786,8 @@ function getDate() {
|
|
|
5773
5786
|
return `${(/* @__PURE__ */ new Date()).toISOString()} `;
|
|
5774
5787
|
}
|
|
5775
5788
|
function formatArgs(diff, args) {
|
|
5776
|
-
const { namespace: name, useColors:
|
|
5777
|
-
if (
|
|
5789
|
+
const { namespace: name, useColors: useColors2 } = this;
|
|
5790
|
+
if (useColors2) {
|
|
5778
5791
|
const c = this.color;
|
|
5779
5792
|
const colorCode = `\x1B[3${c < 8 ? c : `8;5;${c}`}`;
|
|
5780
5793
|
const prefix = ` ${colorCode};1m${name} \x1B[0m`;
|
|
@@ -5791,10 +5804,16 @@ var defaultOptions = {
|
|
|
5791
5804
|
useColors: useColors(),
|
|
5792
5805
|
formatArgs,
|
|
5793
5806
|
formatters: {
|
|
5807
|
+
/**
|
|
5808
|
+
* Map %o to `util.inspect()`, all on a single line.
|
|
5809
|
+
*/
|
|
5794
5810
|
o(v2) {
|
|
5795
5811
|
this.inspectOpts.colors = this.useColors;
|
|
5796
5812
|
return (0, import_node_util.inspect)(v2, this.inspectOpts).split("\n").map((str) => str.trim()).join(" ");
|
|
5797
5813
|
},
|
|
5814
|
+
/**
|
|
5815
|
+
* Map %O to `util.inspect()`, allowing multiple lines if needed.
|
|
5816
|
+
*/
|
|
5798
5817
|
O(v2) {
|
|
5799
5818
|
this.inspectOpts.colors = this.useColors;
|
|
5800
5819
|
return (0, import_node_util.inspect)(v2, this.inspectOpts);
|
|
@@ -5973,7 +5992,7 @@ async function transformMain(code2, filename, options, pluginContext, ssr, custo
|
|
|
5973
5992
|
}
|
|
5974
5993
|
const attachedProps = [];
|
|
5975
5994
|
const hasScoped = descriptor.styles.some((s) => s.scoped);
|
|
5976
|
-
const isTemplateOnlyVapor = !descriptor.script && !descriptor.scriptSetup && descriptor
|
|
5995
|
+
const isTemplateOnlyVapor = !descriptor.script && !descriptor.scriptSetup && isVaporMode(descriptor, options);
|
|
5977
5996
|
const { code: scriptCode, map: scriptMap } = await genScriptCode(descriptor, options, pluginContext, ssr, customElement);
|
|
5978
5997
|
const hasTemplateImport = descriptor.template && !isUseInlineTemplate(descriptor, options);
|
|
5979
5998
|
const isTemplateInlined = !!descriptor.template && (!descriptor.template.lang || descriptor.template.lang === "html") && !descriptor.template.src;
|
|
@@ -6070,7 +6089,7 @@ async function transformMain(code2, filename, options, pluginContext, ssr, custo
|
|
|
6070
6089
|
async function genTemplateCode(descriptor, options, pluginContext, ssr, customElement) {
|
|
6071
6090
|
const template = descriptor.template;
|
|
6072
6091
|
const hasScoped = descriptor.styles.some((style) => style.scoped);
|
|
6073
|
-
const needsMultiRoot = !descriptor.script && !descriptor.scriptSetup && descriptor
|
|
6092
|
+
const needsMultiRoot = !descriptor.script && !descriptor.scriptSetup && isVaporMode(descriptor, options);
|
|
6074
6093
|
if ((!template.lang || template.lang === "html") && !template.src) {
|
|
6075
6094
|
const result = transformTemplateInMain(template.content, descriptor, options, pluginContext, ssr, customElement);
|
|
6076
6095
|
return {
|
|
@@ -6090,7 +6109,7 @@ async function genTemplateCode(descriptor, options, pluginContext, ssr, customEl
|
|
|
6090
6109
|
}
|
|
6091
6110
|
}
|
|
6092
6111
|
async function genScriptCode(descriptor, options, pluginContext, ssr, customElement) {
|
|
6093
|
-
let scriptCode = `const ${scriptIdentifier} = { ${descriptor
|
|
6112
|
+
let scriptCode = `const ${scriptIdentifier} = { ${isVaporMode(descriptor, options) ? "__vapor: true" : ""} }`;
|
|
6094
6113
|
let map;
|
|
6095
6114
|
const script = resolveScript(descriptor, options, ssr, customElement);
|
|
6096
6115
|
if (script) if (canInlineMain(descriptor, options)) {
|
package/dist/vite.config.mjs
CHANGED
|
@@ -4724,7 +4724,7 @@ import path from "node:path";
|
|
|
4724
4724
|
import crypto from "node:crypto";
|
|
4725
4725
|
import { isatty } from "node:tty";
|
|
4726
4726
|
import { formatWithOptions, inspect } from "node:util";
|
|
4727
|
-
var version = "6.0.
|
|
4727
|
+
var version = "6.0.8";
|
|
4728
4728
|
function resolveCompiler(root) {
|
|
4729
4729
|
const compiler = tryResolveCompiler(root) || tryResolveCompiler();
|
|
4730
4730
|
if (!compiler) throw new Error("Failed to resolve vue/compiler-sfc.\n@vitejs/plugin-vue requires vue (>=3.2.25) to be present in the dependency tree.");
|
|
@@ -4841,6 +4841,18 @@ function createRollupError(id2, error) {
|
|
|
4841
4841
|
};
|
|
4842
4842
|
return rollupError;
|
|
4843
4843
|
}
|
|
4844
|
+
function isVaporMode(descriptor, options) {
|
|
4845
|
+
if (descriptor.vapor) return true;
|
|
4846
|
+
if (options.features?.vapor) return canForceVaporMode(descriptor);
|
|
4847
|
+
return false;
|
|
4848
|
+
}
|
|
4849
|
+
function canForceVaporMode(descriptor) {
|
|
4850
|
+
if (descriptor.filename.endsWith(".vue")) {
|
|
4851
|
+
if (descriptor.scriptSetup) return true;
|
|
4852
|
+
if (descriptor.script) return false;
|
|
4853
|
+
}
|
|
4854
|
+
return true;
|
|
4855
|
+
}
|
|
4844
4856
|
async function transformTemplateAsModule(code2, filename, descriptor, options, pluginContext, ssr, customElement) {
|
|
4845
4857
|
const result = compile(code2, filename, descriptor, options, pluginContext, ssr, customElement);
|
|
4846
4858
|
let returnCode = result.code;
|
|
@@ -4915,7 +4927,7 @@ function resolveTemplateCompilerOptions(descriptor, options, filename, ssr) {
|
|
|
4915
4927
|
if (lang && /tsx?$/.test(lang) && !expressionPlugins.includes("typescript")) expressionPlugins.push("typescript");
|
|
4916
4928
|
return {
|
|
4917
4929
|
...options.template,
|
|
4918
|
-
vapor: descriptor
|
|
4930
|
+
vapor: isVaporMode(descriptor, options),
|
|
4919
4931
|
id: id2,
|
|
4920
4932
|
ast: canReuseAST(options.compiler.version) ? descriptor.template?.ast : void 0,
|
|
4921
4933
|
filename,
|
|
@@ -4981,6 +4993,7 @@ function resolveScript(descriptor, options, ssr, customElement) {
|
|
|
4981
4993
|
sourceMap: options.sourceMap,
|
|
4982
4994
|
genDefaultAs: canInlineMain(descriptor, options) ? scriptIdentifier : void 0,
|
|
4983
4995
|
customElement,
|
|
4996
|
+
vapor: isVaporMode(descriptor, options),
|
|
4984
4997
|
propsDestructure: options.features?.propsDestructure ?? options.script?.propsDestructure
|
|
4985
4998
|
});
|
|
4986
4999
|
if (!options.isProduction && resolved?.deps) {
|
|
@@ -5004,8 +5017,8 @@ function canInlineMain(descriptor, options) {
|
|
|
5004
5017
|
var comma = ",".charCodeAt(0);
|
|
5005
5018
|
var semicolon = ";".charCodeAt(0);
|
|
5006
5019
|
var chars = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/";
|
|
5007
|
-
var intToChar = new Uint8Array(64);
|
|
5008
|
-
var charToInt = new Uint8Array(128);
|
|
5020
|
+
var intToChar = /* @__PURE__ */ new Uint8Array(64);
|
|
5021
|
+
var charToInt = /* @__PURE__ */ new Uint8Array(128);
|
|
5009
5022
|
for (let i = 0; i < chars.length; i++) {
|
|
5010
5023
|
const c = chars.charCodeAt(i);
|
|
5011
5024
|
intToChar[i] = c;
|
|
@@ -5616,8 +5629,8 @@ function createDebug$1(namespace, options) {
|
|
|
5616
5629
|
options.formatArgs.call(debug2, diff, args);
|
|
5617
5630
|
debug2.log(...args);
|
|
5618
5631
|
};
|
|
5619
|
-
debug2.extend = function(
|
|
5620
|
-
return createDebug$1(this.namespace + delimiter +
|
|
5632
|
+
debug2.extend = function(namespace2, delimiter = ":") {
|
|
5633
|
+
return createDebug$1(this.namespace + delimiter + namespace2, {
|
|
5621
5634
|
useColors: this.useColors,
|
|
5622
5635
|
color: this.color,
|
|
5623
5636
|
formatArgs: this.formatArgs,
|
|
@@ -5648,8 +5661,8 @@ function createDebug$1(namespace, options) {
|
|
|
5648
5661
|
}
|
|
5649
5662
|
var names = [];
|
|
5650
5663
|
var skips = [];
|
|
5651
|
-
function enable(namespaces
|
|
5652
|
-
globalNamespaces = namespaces
|
|
5664
|
+
function enable(namespaces) {
|
|
5665
|
+
globalNamespaces = namespaces;
|
|
5653
5666
|
names = [];
|
|
5654
5667
|
skips = [];
|
|
5655
5668
|
const split = globalNamespaces.trim().replace(/\s+/g, ",").split(",").filter(Boolean);
|
|
@@ -5756,7 +5769,7 @@ var inspectOpts = Object.keys(process.env).filter((key) => /^debug_/i.test(key))
|
|
|
5756
5769
|
else value = Number(value);
|
|
5757
5770
|
obj[prop] = value;
|
|
5758
5771
|
return obj;
|
|
5759
|
-
},
|
|
5772
|
+
}, /* @__PURE__ */ Object.create(null));
|
|
5760
5773
|
function useColors() {
|
|
5761
5774
|
return "colors" in inspectOpts ? Boolean(inspectOpts.colors) : isatty(process.stderr.fd);
|
|
5762
5775
|
}
|
|
@@ -5765,8 +5778,8 @@ function getDate() {
|
|
|
5765
5778
|
return `${(/* @__PURE__ */ new Date()).toISOString()} `;
|
|
5766
5779
|
}
|
|
5767
5780
|
function formatArgs(diff, args) {
|
|
5768
|
-
const { namespace: name, useColors:
|
|
5769
|
-
if (
|
|
5781
|
+
const { namespace: name, useColors: useColors2 } = this;
|
|
5782
|
+
if (useColors2) {
|
|
5770
5783
|
const c = this.color;
|
|
5771
5784
|
const colorCode = `\x1B[3${c < 8 ? c : `8;5;${c}`}`;
|
|
5772
5785
|
const prefix = ` ${colorCode};1m${name} \x1B[0m`;
|
|
@@ -5783,10 +5796,16 @@ var defaultOptions = {
|
|
|
5783
5796
|
useColors: useColors(),
|
|
5784
5797
|
formatArgs,
|
|
5785
5798
|
formatters: {
|
|
5799
|
+
/**
|
|
5800
|
+
* Map %o to `util.inspect()`, all on a single line.
|
|
5801
|
+
*/
|
|
5786
5802
|
o(v2) {
|
|
5787
5803
|
this.inspectOpts.colors = this.useColors;
|
|
5788
5804
|
return inspect(v2, this.inspectOpts).split("\n").map((str) => str.trim()).join(" ");
|
|
5789
5805
|
},
|
|
5806
|
+
/**
|
|
5807
|
+
* Map %O to `util.inspect()`, allowing multiple lines if needed.
|
|
5808
|
+
*/
|
|
5790
5809
|
O(v2) {
|
|
5791
5810
|
this.inspectOpts.colors = this.useColors;
|
|
5792
5811
|
return inspect(v2, this.inspectOpts);
|
|
@@ -5965,7 +5984,7 @@ async function transformMain(code2, filename, options, pluginContext, ssr, custo
|
|
|
5965
5984
|
}
|
|
5966
5985
|
const attachedProps = [];
|
|
5967
5986
|
const hasScoped = descriptor.styles.some((s) => s.scoped);
|
|
5968
|
-
const isTemplateOnlyVapor = !descriptor.script && !descriptor.scriptSetup && descriptor
|
|
5987
|
+
const isTemplateOnlyVapor = !descriptor.script && !descriptor.scriptSetup && isVaporMode(descriptor, options);
|
|
5969
5988
|
const { code: scriptCode, map: scriptMap } = await genScriptCode(descriptor, options, pluginContext, ssr, customElement);
|
|
5970
5989
|
const hasTemplateImport = descriptor.template && !isUseInlineTemplate(descriptor, options);
|
|
5971
5990
|
const isTemplateInlined = !!descriptor.template && (!descriptor.template.lang || descriptor.template.lang === "html") && !descriptor.template.src;
|
|
@@ -6062,7 +6081,7 @@ async function transformMain(code2, filename, options, pluginContext, ssr, custo
|
|
|
6062
6081
|
async function genTemplateCode(descriptor, options, pluginContext, ssr, customElement) {
|
|
6063
6082
|
const template = descriptor.template;
|
|
6064
6083
|
const hasScoped = descriptor.styles.some((style) => style.scoped);
|
|
6065
|
-
const needsMultiRoot = !descriptor.script && !descriptor.scriptSetup && descriptor
|
|
6084
|
+
const needsMultiRoot = !descriptor.script && !descriptor.scriptSetup && isVaporMode(descriptor, options);
|
|
6066
6085
|
if ((!template.lang || template.lang === "html") && !template.src) {
|
|
6067
6086
|
const result = transformTemplateInMain(template.content, descriptor, options, pluginContext, ssr, customElement);
|
|
6068
6087
|
return {
|
|
@@ -6082,7 +6101,7 @@ async function genTemplateCode(descriptor, options, pluginContext, ssr, customEl
|
|
|
6082
6101
|
}
|
|
6083
6102
|
}
|
|
6084
6103
|
async function genScriptCode(descriptor, options, pluginContext, ssr, customElement) {
|
|
6085
|
-
let scriptCode = `const ${scriptIdentifier} = { ${descriptor
|
|
6104
|
+
let scriptCode = `const ${scriptIdentifier} = { ${isVaporMode(descriptor, options) ? "__vapor: true" : ""} }`;
|
|
6086
6105
|
let map;
|
|
6087
6106
|
const script = resolveScript(descriptor, options, ssr, customElement);
|
|
6088
6107
|
if (script) if (canInlineMain(descriptor, options)) {
|
package/dist/write-config.mjs
CHANGED
|
@@ -485,8 +485,112 @@ var init_find_up = __esm({
|
|
|
485
485
|
});
|
|
486
486
|
|
|
487
487
|
// src/write-config.ts
|
|
488
|
+
import { existsSync } from "node:fs";
|
|
488
489
|
import fs3 from "node:fs/promises";
|
|
489
490
|
import path3 from "node:path";
|
|
491
|
+
import { styleText } from "node:util";
|
|
492
|
+
|
|
493
|
+
// node_modules/detect-indent/index.js
|
|
494
|
+
var INDENT_REGEX = /^(?:( )+|\t+)/;
|
|
495
|
+
var INDENT_TYPE_SPACE = "space";
|
|
496
|
+
var INDENT_TYPE_TAB = "tab";
|
|
497
|
+
function shouldIgnoreSingleSpace(ignoreSingleSpaces, indentType, value) {
|
|
498
|
+
return ignoreSingleSpaces && indentType === INDENT_TYPE_SPACE && value === 1;
|
|
499
|
+
}
|
|
500
|
+
function makeIndentsMap(string, ignoreSingleSpaces) {
|
|
501
|
+
const indents = /* @__PURE__ */ new Map();
|
|
502
|
+
let previousSize = 0;
|
|
503
|
+
let previousIndentType;
|
|
504
|
+
let key;
|
|
505
|
+
for (const line of string.split(/\n/g)) {
|
|
506
|
+
if (!line) {
|
|
507
|
+
continue;
|
|
508
|
+
}
|
|
509
|
+
const matches = line.match(INDENT_REGEX);
|
|
510
|
+
if (matches === null) {
|
|
511
|
+
previousSize = 0;
|
|
512
|
+
previousIndentType = "";
|
|
513
|
+
} else {
|
|
514
|
+
const indent = matches[0].length;
|
|
515
|
+
const indentType = matches[1] ? INDENT_TYPE_SPACE : INDENT_TYPE_TAB;
|
|
516
|
+
if (shouldIgnoreSingleSpace(ignoreSingleSpaces, indentType, indent)) {
|
|
517
|
+
continue;
|
|
518
|
+
}
|
|
519
|
+
if (indentType !== previousIndentType) {
|
|
520
|
+
previousSize = 0;
|
|
521
|
+
}
|
|
522
|
+
previousIndentType = indentType;
|
|
523
|
+
let use = 1;
|
|
524
|
+
let weight = 0;
|
|
525
|
+
const indentDifference = indent - previousSize;
|
|
526
|
+
previousSize = indent;
|
|
527
|
+
if (indentDifference === 0) {
|
|
528
|
+
use = 0;
|
|
529
|
+
weight = 1;
|
|
530
|
+
} else {
|
|
531
|
+
const absoluteIndentDifference = Math.abs(indentDifference);
|
|
532
|
+
if (shouldIgnoreSingleSpace(ignoreSingleSpaces, indentType, absoluteIndentDifference)) {
|
|
533
|
+
continue;
|
|
534
|
+
}
|
|
535
|
+
key = encodeIndentsKey(indentType, absoluteIndentDifference);
|
|
536
|
+
}
|
|
537
|
+
const entry = indents.get(key);
|
|
538
|
+
indents.set(key, entry === void 0 ? [1, 0] : [entry[0] + use, entry[1] + weight]);
|
|
539
|
+
}
|
|
540
|
+
}
|
|
541
|
+
return indents;
|
|
542
|
+
}
|
|
543
|
+
function encodeIndentsKey(indentType, indentAmount) {
|
|
544
|
+
const typeCharacter = indentType === INDENT_TYPE_SPACE ? "s" : "t";
|
|
545
|
+
return typeCharacter + String(indentAmount);
|
|
546
|
+
}
|
|
547
|
+
function decodeIndentsKey(indentsKey) {
|
|
548
|
+
const keyHasTypeSpace = indentsKey[0] === "s";
|
|
549
|
+
const type = keyHasTypeSpace ? INDENT_TYPE_SPACE : INDENT_TYPE_TAB;
|
|
550
|
+
const amount = Number(indentsKey.slice(1));
|
|
551
|
+
return { type, amount };
|
|
552
|
+
}
|
|
553
|
+
function getMostUsedKey(indents) {
|
|
554
|
+
let result;
|
|
555
|
+
let maxUsed = 0;
|
|
556
|
+
let maxWeight = 0;
|
|
557
|
+
for (const [key, [usedCount, weight]] of indents) {
|
|
558
|
+
if (usedCount > maxUsed || usedCount === maxUsed && weight > maxWeight) {
|
|
559
|
+
maxUsed = usedCount;
|
|
560
|
+
maxWeight = weight;
|
|
561
|
+
result = key;
|
|
562
|
+
}
|
|
563
|
+
}
|
|
564
|
+
return result;
|
|
565
|
+
}
|
|
566
|
+
function makeIndentString(type, amount) {
|
|
567
|
+
const indentCharacter = type === INDENT_TYPE_SPACE ? " " : " ";
|
|
568
|
+
return indentCharacter.repeat(amount);
|
|
569
|
+
}
|
|
570
|
+
function detectIndent(string) {
|
|
571
|
+
if (typeof string !== "string") {
|
|
572
|
+
throw new TypeError("Expected a string");
|
|
573
|
+
}
|
|
574
|
+
let indents = makeIndentsMap(string, true);
|
|
575
|
+
if (indents.size === 0) {
|
|
576
|
+
indents = makeIndentsMap(string, false);
|
|
577
|
+
}
|
|
578
|
+
const keyOfMostUsedIndent = getMostUsedKey(indents);
|
|
579
|
+
let type;
|
|
580
|
+
let amount = 0;
|
|
581
|
+
let indent = "";
|
|
582
|
+
if (keyOfMostUsedIndent !== void 0) {
|
|
583
|
+
({ type, amount } = decodeIndentsKey(keyOfMostUsedIndent));
|
|
584
|
+
indent = makeIndentString(type, amount);
|
|
585
|
+
}
|
|
586
|
+
return {
|
|
587
|
+
amount,
|
|
588
|
+
type,
|
|
589
|
+
indent
|
|
590
|
+
};
|
|
591
|
+
}
|
|
592
|
+
|
|
593
|
+
// src/write-config.ts
|
|
490
594
|
var boilerplate = `/* This file was generated by @forsakringskassan/vite-lib-config. Changes may be overwritten! */`;
|
|
491
595
|
function detectTestRunner(flags) {
|
|
492
596
|
if (flags.has("--with-jest")) {
|
|
@@ -497,6 +601,11 @@ function detectTestRunner(flags) {
|
|
|
497
601
|
}
|
|
498
602
|
return "vitest";
|
|
499
603
|
}
|
|
604
|
+
function detectApiExtractor(cwd) {
|
|
605
|
+
const haveBaseConfig = existsSync(path3.join(cwd, "api-extractor.json"));
|
|
606
|
+
const haveLibConfig = existsSync(path3.join(cwd, "api-extractor.lib.json"));
|
|
607
|
+
return haveBaseConfig || haveLibConfig;
|
|
608
|
+
}
|
|
500
609
|
async function serializeJson(data) {
|
|
501
610
|
const { format, resolveConfig } = await import("prettier");
|
|
502
611
|
const content = JSON.stringify(data, null, 4);
|
|
@@ -590,15 +699,44 @@ async function generateTsconfigPageobjects(options) {
|
|
|
590
699
|
};
|
|
591
700
|
return [boilerplate, await serializeJson(config)].join("\n\n");
|
|
592
701
|
}
|
|
593
|
-
async function readJsonFile(
|
|
702
|
+
async function readJsonFile(cwd, filename) {
|
|
703
|
+
const filePath = path3.join(cwd, filename);
|
|
594
704
|
const content = await fs3.readFile(filePath, "utf8");
|
|
595
|
-
|
|
705
|
+
const data = JSON.parse(content);
|
|
706
|
+
const { indent } = detectIndent(content);
|
|
707
|
+
return { data, indent };
|
|
596
708
|
}
|
|
597
709
|
async function writeJsonFile(cwd, filename, content) {
|
|
598
710
|
const filePath = path3.join(cwd, filename);
|
|
599
711
|
await fs3.writeFile(filePath, content, "utf8");
|
|
600
712
|
console.log(filename, "written");
|
|
601
713
|
}
|
|
714
|
+
function updateBuildScripts(pkg, options) {
|
|
715
|
+
const result = { ...pkg, scripts: { ...pkg.scripts } };
|
|
716
|
+
result.scripts.build = [
|
|
717
|
+
"run-s",
|
|
718
|
+
"build:lib",
|
|
719
|
+
options.enableSelectors ? "build:selectors" : null,
|
|
720
|
+
"build:dts",
|
|
721
|
+
options.enableApiExtractor ? "build:api" : null
|
|
722
|
+
].filter(Boolean).join(" ");
|
|
723
|
+
result.scripts["build:api"] = options.enableApiExtractor ? "fk-api-extractor api-extractor.*.json" : void 0;
|
|
724
|
+
result.scripts["build:dts"] = "vue-tsc -b";
|
|
725
|
+
result.scripts["build:lib"] = "fk-build-vue-lib";
|
|
726
|
+
result.scripts["build:selectors"] = options.enableSelectors ? "fk-build-selectors" : void 0;
|
|
727
|
+
delete result.scripts["build:pageobject"];
|
|
728
|
+
return result;
|
|
729
|
+
}
|
|
730
|
+
async function writeBuildScripts(cwd, options) {
|
|
731
|
+
const result = await readJsonFile(cwd, "package.json");
|
|
732
|
+
const { data: pkg, indent } = result;
|
|
733
|
+
const updated = JSON.stringify(
|
|
734
|
+
updateBuildScripts(pkg, options),
|
|
735
|
+
void 0,
|
|
736
|
+
indent
|
|
737
|
+
);
|
|
738
|
+
await writeJsonFile(cwd, "package.json", updated);
|
|
739
|
+
}
|
|
602
740
|
async function findCypressConfigPath(cwd) {
|
|
603
741
|
const { findUp: findUp2 } = await Promise.resolve().then(() => (init_find_up(), find_up_exports));
|
|
604
742
|
const absolutePath = await findUp2("cypress/tsconfig.json", { cwd });
|
|
@@ -610,6 +748,9 @@ async function findCypressConfigPath(cwd) {
|
|
|
610
748
|
function isTSConfigFile(filename) {
|
|
611
749
|
return filename.startsWith("tsconfig.") && filename.endsWith(".json");
|
|
612
750
|
}
|
|
751
|
+
function flagEnabled(value) {
|
|
752
|
+
return value ? styleText("green", "enabled") : styleText("red", "disabled");
|
|
753
|
+
}
|
|
613
754
|
async function run(cwd, argv) {
|
|
614
755
|
const flags = new Set(argv.filter((it) => it.startsWith("--")));
|
|
615
756
|
if (flags.has("--help")) {
|
|
@@ -621,7 +762,7 @@ async function run(cwd, argv) {
|
|
|
621
762
|
`);
|
|
622
763
|
return;
|
|
623
764
|
}
|
|
624
|
-
const pkg = await readJsonFile(
|
|
765
|
+
const { data: pkg } = await readJsonFile(cwd, "package.json");
|
|
625
766
|
if (!pkg.devDependencies?.["@forsakringskassan/vite-lib-config"]) {
|
|
626
767
|
console.error(
|
|
627
768
|
`The "${pkg.name}" does not use "@forsakringskassan/vite-lib-config".`
|
|
@@ -631,10 +772,12 @@ async function run(cwd, argv) {
|
|
|
631
772
|
}
|
|
632
773
|
const cypressConfigPath = await findCypressConfigPath(cwd);
|
|
633
774
|
const testRunner = detectTestRunner(flags);
|
|
775
|
+
const enableApiExtractor = detectApiExtractor(cwd);
|
|
634
776
|
const options = {
|
|
635
777
|
name: pkg.name,
|
|
636
778
|
cypressConfigPath,
|
|
637
779
|
testRunner,
|
|
780
|
+
enableApiExtractor,
|
|
638
781
|
enablePageobjects: Boolean(pkg.exports?.["./cypress"]),
|
|
639
782
|
enableSelectors: Boolean(pkg.exports?.["./selectors"])
|
|
640
783
|
};
|
|
@@ -646,7 +789,7 @@ async function run(cwd, argv) {
|
|
|
646
789
|
["tsconfig.pageobjects.json", generateTsconfigPageobjects(options)]
|
|
647
790
|
]);
|
|
648
791
|
console.group("Writing TypeScript configuration");
|
|
649
|
-
console.log("Test runner:", testRunner);
|
|
792
|
+
console.log("Test runner:", styleText("cyan", testRunner));
|
|
650
793
|
console.log();
|
|
651
794
|
const written = /* @__PURE__ */ new Set();
|
|
652
795
|
for (const [filename, promise] of generated) {
|
|
@@ -665,6 +808,14 @@ async function run(cwd, argv) {
|
|
|
665
808
|
console.log(entry, "removed");
|
|
666
809
|
}
|
|
667
810
|
console.groupEnd();
|
|
811
|
+
console.log();
|
|
812
|
+
console.group("Writing package.json scripts");
|
|
813
|
+
console.log("API Extractor:", flagEnabled(options.enableApiExtractor));
|
|
814
|
+
console.log("Selector objects:", flagEnabled(options.enableSelectors));
|
|
815
|
+
console.log();
|
|
816
|
+
await writeBuildScripts(cwd, options);
|
|
817
|
+
console.groupEnd();
|
|
818
|
+
console.log();
|
|
668
819
|
}
|
|
669
820
|
export {
|
|
670
821
|
generateTsconfig,
|
|
@@ -672,5 +823,6 @@ export {
|
|
|
672
823
|
generateTsconfigLib,
|
|
673
824
|
generateTsconfigPageobjects,
|
|
674
825
|
generateTsconfigSelectors,
|
|
675
|
-
run
|
|
826
|
+
run,
|
|
827
|
+
updateBuildScripts
|
|
676
828
|
};
|