@forsakringskassan/vite-lib-config 5.6.1 → 5.7.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 +2 -0
- package/api-extractor/api-extractor.json +41 -0
- package/dist/vite.config.cjs +19 -6
- package/dist/vite.config.mjs +19 -6
- package/dist/write-config.mjs +116 -20
- package/package.json +3 -1
package/README.md
CHANGED
|
@@ -14,6 +14,8 @@ Use `fk-write-config` to write boilerplate configuration files to the repository
|
|
|
14
14
|
|
|
15
15
|
fk-write-config
|
|
16
16
|
|
|
17
|
+
API Extractor is optiona and must be enabled with `--with-api-extractor`.
|
|
18
|
+
|
|
17
19
|
By default it assumes `vitest` is used as test runner, use `--with-jest` or `--with-vitest` to explicitly set a test runner.
|
|
18
20
|
|
|
19
21
|
### Bundled dependencies
|
|
@@ -0,0 +1,41 @@
|
|
|
1
|
+
{
|
|
2
|
+
"$schema": "https://developer.microsoft.com/json-schemas/api-extractor/v7/api-extractor.schema.json",
|
|
3
|
+
"mainEntryPointFilePath": "<projectFolder>/temp/types/index.d.ts",
|
|
4
|
+
"bundledPackages": [],
|
|
5
|
+
"apiReport": {
|
|
6
|
+
"enabled": true
|
|
7
|
+
},
|
|
8
|
+
"docModel": {
|
|
9
|
+
"enabled": false
|
|
10
|
+
},
|
|
11
|
+
"dtsRollup": {
|
|
12
|
+
"enabled": true,
|
|
13
|
+
"untrimmedFilePath": "",
|
|
14
|
+
"publicTrimmedFilePath": "<projectFolder>/dist/types/index.d.ts"
|
|
15
|
+
},
|
|
16
|
+
"tsdocMetadata": {
|
|
17
|
+
"enabled": false
|
|
18
|
+
},
|
|
19
|
+
"newlineKind": "lf",
|
|
20
|
+
"messages": {
|
|
21
|
+
"compilerMessageReporting": {
|
|
22
|
+
"default": {
|
|
23
|
+
"logLevel": "warning"
|
|
24
|
+
}
|
|
25
|
+
},
|
|
26
|
+
"extractorMessageReporting": {
|
|
27
|
+
"default": {
|
|
28
|
+
"logLevel": "warning"
|
|
29
|
+
},
|
|
30
|
+
"ae-internal-missing-underscore": {
|
|
31
|
+
"logLevel": "none",
|
|
32
|
+
"addToApiReportFile": false
|
|
33
|
+
}
|
|
34
|
+
},
|
|
35
|
+
"tsdocMessageReporting": {
|
|
36
|
+
"default": {
|
|
37
|
+
"logLevel": "warning"
|
|
38
|
+
}
|
|
39
|
+
}
|
|
40
|
+
}
|
|
41
|
+
}
|
package/dist/vite.config.cjs
CHANGED
|
@@ -11349,9 +11349,18 @@ function defineConfig(config = {}) {
|
|
|
11349
11349
|
return fkDefineConfig(mode, config);
|
|
11350
11350
|
});
|
|
11351
11351
|
}
|
|
11352
|
-
function
|
|
11353
|
-
const
|
|
11354
|
-
|
|
11352
|
+
function shouldUseCustomEntrypoint(options) {
|
|
11353
|
+
const { config, positional, mode } = options;
|
|
11354
|
+
if (mode !== "development") {
|
|
11355
|
+
return false;
|
|
11356
|
+
}
|
|
11357
|
+
if (process.env.CYPRESS) {
|
|
11358
|
+
return false;
|
|
11359
|
+
}
|
|
11360
|
+
if (positional.length === 0) {
|
|
11361
|
+
return false;
|
|
11362
|
+
}
|
|
11363
|
+
return !config.fk?.entrypoint;
|
|
11355
11364
|
}
|
|
11356
11365
|
async function fkDefineConfig(mode, config = {}) {
|
|
11357
11366
|
const argv = process.argv.slice(2);
|
|
@@ -11361,8 +11370,12 @@ async function fkDefineConfig(mode, config = {}) {
|
|
|
11361
11370
|
if (mocks.length > 0) {
|
|
11362
11371
|
defaultConfig.plugins.push((0, import_apimock_express.vitePlugin)(mocks));
|
|
11363
11372
|
}
|
|
11364
|
-
const
|
|
11365
|
-
|
|
11373
|
+
const useCustomEntrypoint = shouldUseCustomEntrypoint({
|
|
11374
|
+
config,
|
|
11375
|
+
positional,
|
|
11376
|
+
mode
|
|
11377
|
+
});
|
|
11378
|
+
if (useCustomEntrypoint) {
|
|
11366
11379
|
const entrypoint = await findEntrypoint(positional[0]);
|
|
11367
11380
|
config.fk.entrypoint = `/${entrypoint}`;
|
|
11368
11381
|
}
|
|
@@ -11392,7 +11405,7 @@ async function fkDefineConfig(mode, config = {}) {
|
|
|
11392
11405
|
"Bundled dependencies:",
|
|
11393
11406
|
prettyList(allDependencies, (it2) => isBundled(external2, it2))
|
|
11394
11407
|
);
|
|
11395
|
-
if (
|
|
11408
|
+
if (useCustomEntrypoint) {
|
|
11396
11409
|
console.log("Entrypoint:", config.fk.entrypoint);
|
|
11397
11410
|
}
|
|
11398
11411
|
console.groupEnd();
|
package/dist/vite.config.mjs
CHANGED
|
@@ -11343,9 +11343,18 @@ function defineConfig(config = {}) {
|
|
|
11343
11343
|
return fkDefineConfig(mode, config);
|
|
11344
11344
|
});
|
|
11345
11345
|
}
|
|
11346
|
-
function
|
|
11347
|
-
const
|
|
11348
|
-
|
|
11346
|
+
function shouldUseCustomEntrypoint(options) {
|
|
11347
|
+
const { config, positional, mode } = options;
|
|
11348
|
+
if (mode !== "development") {
|
|
11349
|
+
return false;
|
|
11350
|
+
}
|
|
11351
|
+
if (process.env.CYPRESS) {
|
|
11352
|
+
return false;
|
|
11353
|
+
}
|
|
11354
|
+
if (positional.length === 0) {
|
|
11355
|
+
return false;
|
|
11356
|
+
}
|
|
11357
|
+
return !config.fk?.entrypoint;
|
|
11349
11358
|
}
|
|
11350
11359
|
async function fkDefineConfig(mode, config = {}) {
|
|
11351
11360
|
const argv = process.argv.slice(2);
|
|
@@ -11355,8 +11364,12 @@ async function fkDefineConfig(mode, config = {}) {
|
|
|
11355
11364
|
if (mocks.length > 0) {
|
|
11356
11365
|
defaultConfig.plugins.push(apimockPlugin(mocks));
|
|
11357
11366
|
}
|
|
11358
|
-
const
|
|
11359
|
-
|
|
11367
|
+
const useCustomEntrypoint = shouldUseCustomEntrypoint({
|
|
11368
|
+
config,
|
|
11369
|
+
positional,
|
|
11370
|
+
mode
|
|
11371
|
+
});
|
|
11372
|
+
if (useCustomEntrypoint) {
|
|
11360
11373
|
const entrypoint = await findEntrypoint(positional[0]);
|
|
11361
11374
|
config.fk.entrypoint = `/${entrypoint}`;
|
|
11362
11375
|
}
|
|
@@ -11386,7 +11399,7 @@ async function fkDefineConfig(mode, config = {}) {
|
|
|
11386
11399
|
"Bundled dependencies:",
|
|
11387
11400
|
prettyList(allDependencies, (it2) => isBundled(external2, it2))
|
|
11388
11401
|
);
|
|
11389
|
-
if (
|
|
11402
|
+
if (useCustomEntrypoint) {
|
|
11390
11403
|
console.log("Entrypoint:", config.fk.entrypoint);
|
|
11391
11404
|
}
|
|
11392
11405
|
console.groupEnd();
|
package/dist/write-config.mjs
CHANGED
|
@@ -485,7 +485,6 @@ var init_find_up = __esm({
|
|
|
485
485
|
});
|
|
486
486
|
|
|
487
487
|
// src/write-config.ts
|
|
488
|
-
import { existsSync } from "node:fs";
|
|
489
488
|
import fs3 from "node:fs/promises";
|
|
490
489
|
import path3 from "node:path";
|
|
491
490
|
import { styleText } from "node:util";
|
|
@@ -601,11 +600,6 @@ function detectTestRunner(flags) {
|
|
|
601
600
|
}
|
|
602
601
|
return "vitest";
|
|
603
602
|
}
|
|
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
|
-
}
|
|
609
603
|
async function serializeJson(data) {
|
|
610
604
|
const { format, resolveConfig } = await import("prettier");
|
|
611
605
|
const content = JSON.stringify(data, null, 4);
|
|
@@ -614,6 +608,77 @@ async function serializeJson(data) {
|
|
|
614
608
|
const formatted = await format(content, { ...config, filepath });
|
|
615
609
|
return formatted;
|
|
616
610
|
}
|
|
611
|
+
async function generateApiExtractorLib(options) {
|
|
612
|
+
if (!options.enableApiExtractor) {
|
|
613
|
+
return null;
|
|
614
|
+
}
|
|
615
|
+
const config = {
|
|
616
|
+
$schema: "https://developer.microsoft.com/json-schemas/api-extractor/v7/api-extractor.schema.json",
|
|
617
|
+
extends: "@forsakringskassan/vite-lib-config/api-extractor/api-extractor.json",
|
|
618
|
+
compiler: {
|
|
619
|
+
tsconfigFilePath: "<projectFolder>/tsconfig.lib.json"
|
|
620
|
+
},
|
|
621
|
+
apiReport: {
|
|
622
|
+
reportFileName: "<unscopedPackageName>.api.md",
|
|
623
|
+
reportFolder: options.apiExtractorReportFolder ? `<projectFolder>/${options.apiExtractorReportFolder}` : void 0
|
|
624
|
+
},
|
|
625
|
+
docModel: {
|
|
626
|
+
enabled: true
|
|
627
|
+
},
|
|
628
|
+
dtsRollup: {
|
|
629
|
+
publicTrimmedFilePath: "<projectFolder>/dist/types/index.d.ts"
|
|
630
|
+
}
|
|
631
|
+
};
|
|
632
|
+
return [boilerplate, await serializeJson(config)].join("\n\n");
|
|
633
|
+
}
|
|
634
|
+
async function generateApiExtractorCypress(options) {
|
|
635
|
+
if (!options.enableApiExtractor) {
|
|
636
|
+
return null;
|
|
637
|
+
}
|
|
638
|
+
if (!options.enablePageobjects) {
|
|
639
|
+
return null;
|
|
640
|
+
}
|
|
641
|
+
const config = {
|
|
642
|
+
$schema: "https://developer.microsoft.com/json-schemas/api-extractor/v7/api-extractor.schema.json",
|
|
643
|
+
extends: "@forsakringskassan/vite-lib-config/api-extractor/api-extractor.json",
|
|
644
|
+
mainEntryPointFilePath: "<projectFolder>/temp/types/cypress/index.d.ts",
|
|
645
|
+
compiler: {
|
|
646
|
+
tsconfigFilePath: "<projectFolder>/tsconfig.pageobjects.json"
|
|
647
|
+
},
|
|
648
|
+
apiReport: {
|
|
649
|
+
reportFileName: "<unscopedPackageName>-cypress.api.md",
|
|
650
|
+
reportFolder: options.apiExtractorReportFolder ? `<projectFolder>/${options.apiExtractorReportFolder}` : void 0
|
|
651
|
+
},
|
|
652
|
+
dtsRollup: {
|
|
653
|
+
publicTrimmedFilePath: "<projectFolder>/dist/types/cypress.d.ts"
|
|
654
|
+
}
|
|
655
|
+
};
|
|
656
|
+
return [boilerplate, await serializeJson(config)].join("\n\n");
|
|
657
|
+
}
|
|
658
|
+
async function generateApiExtractorSelectors(options) {
|
|
659
|
+
if (!options.enableApiExtractor) {
|
|
660
|
+
return null;
|
|
661
|
+
}
|
|
662
|
+
if (!options.enableSelectors) {
|
|
663
|
+
return null;
|
|
664
|
+
}
|
|
665
|
+
const config = {
|
|
666
|
+
$schema: "https://developer.microsoft.com/json-schemas/api-extractor/v7/api-extractor.schema.json",
|
|
667
|
+
extends: "@forsakringskassan/vite-lib-config/api-extractor/api-extractor.json",
|
|
668
|
+
mainEntryPointFilePath: "<projectFolder>/temp/types/selectors/index.d.ts",
|
|
669
|
+
compiler: {
|
|
670
|
+
tsconfigFilePath: "<projectFolder>/tsconfig.selectors.json"
|
|
671
|
+
},
|
|
672
|
+
apiReport: {
|
|
673
|
+
reportFileName: "<unscopedPackageName>-selectors.api.md",
|
|
674
|
+
reportFolder: options.apiExtractorReportFolder ? `<projectFolder>/${options.apiExtractorReportFolder}` : void 0
|
|
675
|
+
},
|
|
676
|
+
dtsRollup: {
|
|
677
|
+
publicTrimmedFilePath: "<projectFolder>/dist/types/selectors.d.ts"
|
|
678
|
+
}
|
|
679
|
+
};
|
|
680
|
+
return [boilerplate, await serializeJson(config)].join("\n\n");
|
|
681
|
+
}
|
|
617
682
|
async function generateTsconfig(options) {
|
|
618
683
|
const { name, enablePageobjects, enableSelectors, testRunner } = options;
|
|
619
684
|
const config = {
|
|
@@ -742,6 +807,18 @@ async function writeBuildScripts(cwd, options) {
|
|
|
742
807
|
);
|
|
743
808
|
await writeJsonFile(cwd, "package.json", `${updated}${trailer}`);
|
|
744
809
|
}
|
|
810
|
+
async function findApiExtractorReportFolder(cwd) {
|
|
811
|
+
const { findUp: findUp2 } = await Promise.resolve().then(() => (init_find_up(), find_up_exports));
|
|
812
|
+
const absolutePath = await findUp2("package-lock.json", { cwd });
|
|
813
|
+
if (!absolutePath) {
|
|
814
|
+
return null;
|
|
815
|
+
}
|
|
816
|
+
const rootDir = path3.dirname(absolutePath);
|
|
817
|
+
if (path3.resolve(cwd) === rootDir) {
|
|
818
|
+
return null;
|
|
819
|
+
}
|
|
820
|
+
return path3.relative(cwd, path3.join(rootDir, "etc")).replaceAll("\\", "/");
|
|
821
|
+
}
|
|
745
822
|
async function findCypressConfigPath(cwd) {
|
|
746
823
|
const { findUp: findUp2 } = await Promise.resolve().then(() => (init_find_up(), find_up_exports));
|
|
747
824
|
const absolutePath = await findUp2("cypress/tsconfig.json", { cwd });
|
|
@@ -750,8 +827,14 @@ async function findCypressConfigPath(cwd) {
|
|
|
750
827
|
}
|
|
751
828
|
return "cypress/tsconfig.json";
|
|
752
829
|
}
|
|
753
|
-
function
|
|
754
|
-
|
|
830
|
+
function shouldPrune(filename) {
|
|
831
|
+
if (filename.startsWith("tsconfig.") && filename.endsWith(".json")) {
|
|
832
|
+
return true;
|
|
833
|
+
}
|
|
834
|
+
if (filename.startsWith("api-extractor.") && filename.endsWith(".json")) {
|
|
835
|
+
return true;
|
|
836
|
+
}
|
|
837
|
+
return false;
|
|
755
838
|
}
|
|
756
839
|
function flagEnabled(value) {
|
|
757
840
|
return value ? styleText("green", "enabled") : styleText("red", "disabled");
|
|
@@ -762,6 +845,7 @@ async function run(cwd, argv) {
|
|
|
762
845
|
console.log("usage: fk-write-config [OPTIONS..]");
|
|
763
846
|
console.log(`
|
|
764
847
|
--help Show this help.
|
|
848
|
+
--with-api-extractor Use @microsoft/api-extractor.
|
|
765
849
|
--with-jest Use Jest as test runner.
|
|
766
850
|
--with-vitest Use Vitest as test runner.
|
|
767
851
|
`);
|
|
@@ -775,54 +859,66 @@ async function run(cwd, argv) {
|
|
|
775
859
|
console.error(`Skipping writing configuration.`);
|
|
776
860
|
return;
|
|
777
861
|
}
|
|
862
|
+
const apiExtractorReportFolder = await findApiExtractorReportFolder(cwd);
|
|
778
863
|
const cypressConfigPath = await findCypressConfigPath(cwd);
|
|
779
864
|
const testRunner = detectTestRunner(flags);
|
|
780
|
-
const enableApiExtractor = detectApiExtractor(cwd);
|
|
781
865
|
const options = {
|
|
782
866
|
name: pkg.name,
|
|
867
|
+
apiExtractorReportFolder,
|
|
783
868
|
cypressConfigPath,
|
|
784
869
|
testRunner,
|
|
785
|
-
enableApiExtractor,
|
|
870
|
+
enableApiExtractor: flags.has("--with-api-extractor"),
|
|
786
871
|
enablePageobjects: Boolean(pkg.exports?.["./cypress"]),
|
|
787
872
|
enableSelectors: Boolean(pkg.exports?.["./selectors"])
|
|
788
873
|
};
|
|
789
874
|
const generated = /* @__PURE__ */ new Map([
|
|
875
|
+
["api-extractor.lib.json", generateApiExtractorLib(options)],
|
|
876
|
+
["api-extractor.cypress.json", generateApiExtractorCypress(options)],
|
|
877
|
+
[
|
|
878
|
+
"api-extractor.selectors.json",
|
|
879
|
+
generateApiExtractorSelectors(options)
|
|
880
|
+
],
|
|
790
881
|
["tsconfig.json", generateTsconfig(options)],
|
|
791
882
|
["tsconfig.lib.json", generateTsconfigLib(options)],
|
|
792
883
|
["tsconfig.cypress.json", generateTsconfigCypress(options)],
|
|
793
884
|
["tsconfig.selectors.json", generateTsconfigSelectors(options)],
|
|
794
885
|
["tsconfig.pageobjects.json", generateTsconfigPageobjects(options)]
|
|
795
886
|
]);
|
|
796
|
-
console.group("Writing
|
|
887
|
+
console.group("Writing configuration files");
|
|
888
|
+
console.log("API Extractor:", flagEnabled(options.enableApiExtractor));
|
|
889
|
+
console.log("Cypress pageobjects:", flagEnabled(options.enablePageobjects));
|
|
890
|
+
console.log("Selector objects:", flagEnabled(options.enableSelectors));
|
|
797
891
|
console.log("Test runner:", styleText("cyan", testRunner));
|
|
798
892
|
console.log();
|
|
799
893
|
const written = /* @__PURE__ */ new Set();
|
|
894
|
+
const omitted = /* @__PURE__ */ new Set();
|
|
800
895
|
for (const [filename, promise] of generated) {
|
|
801
896
|
const content = await promise;
|
|
802
897
|
if (content) {
|
|
803
898
|
await writeJsonFile(cwd, filename, content);
|
|
804
899
|
written.add(filename);
|
|
900
|
+
} else {
|
|
901
|
+
omitted.add(filename);
|
|
805
902
|
}
|
|
806
903
|
}
|
|
807
904
|
const entries = await fs3.readdir(cwd);
|
|
808
905
|
for (const entry of entries) {
|
|
809
|
-
if (
|
|
906
|
+
if (written.has(entry)) {
|
|
810
907
|
continue;
|
|
811
908
|
}
|
|
812
|
-
|
|
813
|
-
|
|
909
|
+
if (omitted.has(entry) || shouldPrune(entry)) {
|
|
910
|
+
await fs3.unlink(path3.join(cwd, entry));
|
|
911
|
+
console.log(entry, "removed");
|
|
912
|
+
}
|
|
814
913
|
}
|
|
815
|
-
console.groupEnd();
|
|
816
|
-
console.log();
|
|
817
|
-
console.group("Writing package.json scripts");
|
|
818
|
-
console.log("API Extractor:", flagEnabled(options.enableApiExtractor));
|
|
819
|
-
console.log("Selector objects:", flagEnabled(options.enableSelectors));
|
|
820
|
-
console.log();
|
|
821
914
|
await writeBuildScripts(cwd, options);
|
|
822
915
|
console.groupEnd();
|
|
823
916
|
console.log();
|
|
824
917
|
}
|
|
825
918
|
export {
|
|
919
|
+
generateApiExtractorCypress,
|
|
920
|
+
generateApiExtractorLib,
|
|
921
|
+
generateApiExtractorSelectors,
|
|
826
922
|
generateTsconfig,
|
|
827
923
|
generateTsconfigCypress,
|
|
828
924
|
generateTsconfigLib,
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@forsakringskassan/vite-lib-config",
|
|
3
|
-
"version": "5.
|
|
3
|
+
"version": "5.7.1",
|
|
4
4
|
"description": "Försäkringskassan toolchain to build libraries with Vite",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"vite"
|
|
@@ -18,6 +18,7 @@
|
|
|
18
18
|
"types": "./dist/index.d.ts",
|
|
19
19
|
"require": "./dist/index.js"
|
|
20
20
|
},
|
|
21
|
+
"./api-extractor/*.json": "./api-extractor/*.json",
|
|
21
22
|
"./assets/*": "./assets/*",
|
|
22
23
|
"./babel": {
|
|
23
24
|
"types": "./dist/babel.config.d.ts",
|
|
@@ -44,6 +45,7 @@
|
|
|
44
45
|
},
|
|
45
46
|
"files": [
|
|
46
47
|
"*.d.ts",
|
|
48
|
+
"api-extractor",
|
|
47
49
|
"assets",
|
|
48
50
|
"bin",
|
|
49
51
|
"dist",
|