@forsakringskassan/vite-lib-config 5.6.0 → 5.7.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/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
+ }
@@ -10968,7 +10968,8 @@ function lookupFile(nameWithoutExtension) {
10968
10968
  }
10969
10969
 
10970
10970
  // src/plugins/index-html-plugin.ts
10971
- var templateFile = import_node_path3.default.resolve(__dirname, "../assets/index.html");
10971
+ var rootDir = import_node_path3.default.resolve(__dirname, "..");
10972
+ var templateFile = import_node_path3.default.join(rootDir, "assets/index.html");
10972
10973
  var VIRTUAL_ENTRYPOINT = "index.html";
10973
10974
  function isHtmlPage(url) {
10974
10975
  if (!url) {
@@ -10981,6 +10982,7 @@ function middleware(server) {
10981
10982
  const { url } = req;
10982
10983
  if (isHtmlPage(url)) {
10983
10984
  try {
10985
+ res.setHeader("content-type", "text/html; charset=utf-8");
10984
10986
  res.end(await server.transformIndexHtml(url, ""));
10985
10987
  } catch (err) {
10986
10988
  console.error(err);
@@ -10960,7 +10960,8 @@ function lookupFile(nameWithoutExtension) {
10960
10960
  }
10961
10961
 
10962
10962
  // src/plugins/index-html-plugin.ts
10963
- var templateFile = path2.resolve(__dirname, "../assets/index.html");
10963
+ var rootDir = path2.resolve(__dirname, "..");
10964
+ var templateFile = path2.join(rootDir, "assets/index.html");
10964
10965
  var VIRTUAL_ENTRYPOINT = "index.html";
10965
10966
  function isHtmlPage(url) {
10966
10967
  if (!url) {
@@ -10973,6 +10974,7 @@ function middleware(server) {
10973
10974
  const { url } = req;
10974
10975
  if (isHtmlPage(url)) {
10975
10976
  try {
10977
+ res.setHeader("content-type", "text/html; charset=utf-8");
10976
10978
  res.end(await server.transformIndexHtml(url, ""));
10977
10979
  } catch (err) {
10978
10980
  console.error(err);
@@ -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 isTSConfigFile(filename) {
754
- return filename.startsWith("tsconfig.") && filename.endsWith(".json");
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 TypeScript configuration");
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 (!isTSConfigFile(entry) || written.has(entry)) {
906
+ if (written.has(entry)) {
810
907
  continue;
811
908
  }
812
- await fs3.unlink(path3.join(cwd, entry));
813
- console.log(entry, "removed");
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.6.0",
3
+ "version": "5.7.0",
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",