react-lib-tools 0.0.5 → 0.0.7

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/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "react-lib-tools",
3
- "version": "0.0.5",
3
+ "version": "0.0.7",
4
4
  "type": "module",
5
5
  "author": "Brian Vaughn <brian.david.vaughn@gmail.com> (https://github.com/bvaughn/)",
6
6
  "contributors": [
@@ -1,9 +1,16 @@
1
1
  import { compileComponents } from "./utils/docs/compileComponents.ts";
2
2
  import { compileImperativeHandles } from "./utils/docs/compileImperativeHandles.ts";
3
3
  import type { CompilerOptions } from "typescript";
4
+ import {
5
+ JsxEmit,
6
+ ModuleDetectionKind,
7
+ ModuleKind,
8
+ ModuleResolutionKind,
9
+ ScriptTarget
10
+ } from "typescript";
4
11
 
5
12
  export async function compileDocs({
6
- compilerOptions = {},
13
+ compilerOptions: compilerOptionsParam,
7
14
  componentNames,
8
15
  imperativeHandleNames,
9
16
  outputDirName = "docs"
@@ -13,6 +20,11 @@ export async function compileDocs({
13
20
  imperativeHandleNames: string[];
14
21
  outputDirName?: string | undefined;
15
22
  }) {
23
+ const compilerOptions = {
24
+ ...defaultCompilerOptions,
25
+ ...compilerOptionsParam
26
+ };
27
+
16
28
  await compileComponents({
17
29
  compilerOptions,
18
30
  componentNames,
@@ -25,3 +37,25 @@ export async function compileDocs({
25
37
  outputDirName
26
38
  });
27
39
  }
40
+
41
+ const defaultCompilerOptions: CompilerOptions = {
42
+ tsBuildInfoFile: "./node_modules/.tmp/tsconfig.app.tsbuildinfo",
43
+ target: ScriptTarget.ES2022,
44
+ useDefineForClassFields: true,
45
+ lib: ["ES2022", "DOM", "DOM.Iterable"],
46
+ module: ModuleKind.ESNext,
47
+ skipLibCheck: true,
48
+ moduleResolution: ModuleResolutionKind.Bundler,
49
+ allowImportingTsExtensions: true,
50
+ verbatimModuleSyntax: true,
51
+ moduleDetection: ModuleDetectionKind.Force,
52
+ noEmit: true,
53
+ jsx: JsxEmit.ReactJSX,
54
+ strict: true,
55
+ noUnusedLocals: true,
56
+ noUnusedParameters: true,
57
+ erasableSyntaxOnly: true,
58
+ noFallthroughCasesInSwitch: true,
59
+ noUncheckedSideEffectImports: true,
60
+ exactOptionalPropertyTypes: true
61
+ };
@@ -6,7 +6,7 @@ import { trimExcludedText } from "./utils/examples/trimExcludedText.ts";
6
6
 
7
7
  export async function compileExamples({
8
8
  fileExtensions = [".html", ".ts", ".tsx"],
9
- inputPath = ["src", "routes"],
9
+ inputPath = ["src", "routes", "examples"],
10
10
  outputDirName = "examples"
11
11
  }: {
12
12
  fileExtensions?: string[] | undefined;
@@ -61,7 +61,7 @@ export async function compileExamples({
61
61
 
62
62
  const outputFile = join(
63
63
  outputDir,
64
- fileName.replace(/\.example\..+$/, ".json")
64
+ fileName.replace(/(\.example)?\.[\w]+$/, ".json")
65
65
  );
66
66
 
67
67
  console.debug("Writing to", outputFile);
@@ -58,10 +58,16 @@ export async function compileComponent({
58
58
  let textToFormat = getPropTypeText(prop);
59
59
 
60
60
  if (prop.defaultValue?.value) {
61
- const formattedValue =
62
- typeof prop.defaultValue.value === "string"
63
- ? `"${prop.defaultValue.value}"`
64
- : prop.defaultValue.value;
61
+ let formattedValue = prop.defaultValue.value;
62
+
63
+ // Wrap strings in quotes
64
+ if (typeof prop.defaultValue.value === "string") {
65
+ // But don't double quote, e.g.
66
+ // tagName?: keyof IntrinsicElements = ""div" as TagName"
67
+ if (!prop.defaultValue.value.includes('" as ')) {
68
+ formattedValue = `"${prop.defaultValue.value}"`;
69
+ }
70
+ }
65
71
 
66
72
  textToFormat = `${textToFormat} = ${formattedValue}`;
67
73
  }