Skip to content

Commit ba17f66

Browse files
authored
chore: remove cjs exports and improve typescript performance (#472)
* add explicit return types for public apis * remove ifDefined * remove cjs exports * remove redundant files
1 parent f2efbfa commit ba17f66

File tree

244 files changed

+1275
-975
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

244 files changed

+1275
-975
lines changed

.changeset/chatty-actors-repair.md

+11
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
---
2+
"@tapsioss/react-components": minor
3+
"@tapsioss/web-components": minor
4+
"@tapsioss/react-icons": minor
5+
"@tapsioss/web-icons": minor
6+
"@tapsioss/icons": minor
7+
"@tapsioss/theme": minor
8+
---
9+
10+
Remove cjs exports
11+

.changeset/hot-eggs-brake.md

-6
This file was deleted.

docs/.vitepress/theme/index.ts

+5-3
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
1+
import type { Theme } from "vitepress";
12
import defaultTheme from "vitepress/theme";
3+
24
import "./custom.css";
35

4-
export default {
5-
extends: defaultTheme,
6-
};
6+
const theme: Theme = { extends: defaultTheme };
7+
8+
export default theme;

docs/components/[component].paths.ts

+6-1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
import fs from "node:fs";
22
import path from "node:path";
3+
import { type ResolvedRouteConfig } from "vitepress";
34
import { getFileMeta } from "../../scripts/utils.ts";
45
import {
56
type ComponentMetadata,
@@ -26,7 +27,9 @@ const metadata = JSON.parse(
2627

2728
packagesMetadata = metadata.package;
2829

29-
export default {
30+
const routeConfig: {
31+
paths(): Pick<ResolvedRouteConfig, "content" | "params">[];
32+
} = {
3033
paths() {
3134
return Object.values(metadata.components).map(c => {
3235
let content = "";
@@ -43,6 +46,8 @@ export default {
4346
},
4447
};
4548

49+
export default routeConfig;
50+
4651
const getPageMarkdown = (component: ComponentMetadata) => {
4752
let res = "\n";
4853

docs/internals/components/DocIconGrid.ts

+13-6
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,14 @@
11
import icons from "@tapsioss/icons";
22
import * as scrollLock from "body-scroll-lock";
33
import { createFocusTrap, type FocusTrap } from "focus-trap";
4-
import { html, LitElement, nothing, svg, type PropertyValues } from "lit";
4+
import {
5+
html,
6+
LitElement,
7+
nothing,
8+
svg,
9+
type PropertyValues,
10+
type TemplateResult,
11+
} from "lit";
512
import { customElement, query, state } from "lit/decorators.js";
613
import { classMap } from "lit/directives/class-map.js";
714
import { unsafeHTML } from "lit/directives/unsafe-html.js";
@@ -28,7 +35,7 @@ type SVGIconInfo = {
2835

2936
@customElement("doc-icon-grid")
3037
export class DocIconGrid extends LitElement {
31-
protected override createRenderRoot() {
38+
protected override createRenderRoot(): HTMLElement | DocumentFragment {
3239
return this;
3340
}
3441

@@ -54,7 +61,7 @@ export class DocIconGrid extends LitElement {
5461
return inputString.toLowerCase().replace(/-/g, "").replace(/_/g, "");
5562
}
5663

57-
public override disconnectedCallback() {
64+
public override disconnectedCallback(): void {
5865
super.disconnectedCallback();
5966

6067
scrollLock.enableBodyScroll(this._iconModal);
@@ -65,8 +72,8 @@ export class DocIconGrid extends LitElement {
6572
window.removeEventListener("keydown", this._handleEscapeKey);
6673
}
6774

68-
protected override firstUpdated(_changedProperties: PropertyValues) {
69-
super.firstUpdated(_changedProperties);
75+
protected override firstUpdated(changed: PropertyValues): void {
76+
super.firstUpdated(changed);
7077

7178
this._focusTrapper = createFocusTrap(this._iconModal, {
7279
clickOutsideDeactivates: true,
@@ -275,7 +282,7 @@ export class DocIconGrid extends LitElement {
275282
return html`<div>No icon was found for "${this._searchString}"!</div>`;
276283
}
277284

278-
protected override render() {
285+
protected override render(): TemplateResult {
279286
return html`
280287
${this._renderModal()}${this._renderSearchbar()}
281288
<div id="icons-grid">${this._renderIcons()}</div>

docs/sidebar.ts

+47-49
Original file line numberDiff line numberDiff line change
@@ -12,54 +12,52 @@ const metadataFile = path.join(
1212
"packages/web-components/metadata.json",
1313
);
1414

15-
const getSidebarItems = (): DefaultTheme.Sidebar => {
16-
const metadata = JSON.parse(
17-
fs.readFileSync(metadataFile).toString("utf-8"),
18-
) as Metadata;
19-
20-
const components = Object.values(metadata.components)
21-
.sort((a, b) => a.name.localeCompare(b.name))
22-
.map(c => ({
23-
text: c.titleCaseName,
24-
link: `/components/${c.relativePath}`,
25-
}));
26-
27-
const componentsSidebar = [
28-
{
29-
text: "Introduction",
30-
link: "/components",
31-
items: components,
32-
},
33-
];
34-
35-
const themeSidebar = [
36-
{
37-
text: "Introduction",
38-
link: "/theme",
39-
items: [
40-
{ text: "Color", link: "/theme/color" },
41-
{ text: "Palette", link: "/theme/palette" },
42-
{ text: "Radius", link: "/theme/radius" },
43-
{ text: "Spacing", link: "/theme/spacing" },
44-
{ text: "Stroke", link: "/theme/stroke" },
45-
{ text: "Typography", link: "/theme/typography" },
46-
],
47-
},
48-
];
49-
50-
const iconsSidebar = [
51-
{
52-
text: "Introduction",
53-
link: "/icons",
54-
items: [{ text: "Explore Icons", link: "/icons/explore" }],
55-
},
56-
];
57-
58-
return {
59-
"/components": componentsSidebar,
60-
"/theme": themeSidebar,
61-
"/icons": iconsSidebar,
62-
};
15+
const metadata = JSON.parse(
16+
fs.readFileSync(metadataFile).toString("utf-8"),
17+
) as Metadata;
18+
19+
const components = Object.values(metadata.components)
20+
.sort((a, b) => a.name.localeCompare(b.name))
21+
.map(c => ({
22+
text: c.titleCaseName,
23+
link: `/components/${c.relativePath}`,
24+
}));
25+
26+
const componentsSidebar = [
27+
{
28+
text: "Introduction",
29+
link: "/components",
30+
items: components,
31+
},
32+
];
33+
34+
const themeSidebar = [
35+
{
36+
text: "Introduction",
37+
link: "/theme",
38+
items: [
39+
{ text: "Color", link: "/theme/color" },
40+
{ text: "Palette", link: "/theme/palette" },
41+
{ text: "Radius", link: "/theme/radius" },
42+
{ text: "Spacing", link: "/theme/spacing" },
43+
{ text: "Stroke", link: "/theme/stroke" },
44+
{ text: "Typography", link: "/theme/typography" },
45+
],
46+
},
47+
];
48+
49+
const iconsSidebar = [
50+
{
51+
text: "Introduction",
52+
link: "/icons",
53+
items: [{ text: "Explore Icons", link: "/icons/explore" }],
54+
},
55+
];
56+
57+
const items: DefaultTheme.Sidebar = {
58+
"/components": componentsSidebar,
59+
"/theme": themeSidebar,
60+
"/icons": iconsSidebar,
6361
};
6462

65-
export default getSidebarItems();
63+
export default items;

docs/utils/markdown.ts

+5-3
Original file line numberDiff line numberDiff line change
@@ -12,17 +12,19 @@ export const tabulateData = (headers: string[], data: string[][]): string => {
1212

1313
export const codify = (inputString: string) => `\`${inputString}\``;
1414

15-
export const getFormattedTagUsageString = (tagName?: string) => {
15+
export const getFormattedTagUsageString = (tagName?: string): string => {
1616
if (!tagName) return "";
1717
return `<pre>&lt;<span style="--shiki-light:#22863A;--shiki-dark:#85E89D;">${tagName}</span>&gt;&lt;/<span style="--shiki-light:#22863A;--shiki-dark:#85E89D;">${tagName}</span>&gt;</pre>`;
1818
};
1919

20-
export const getFormattedImportUsageString = (path?: string) => {
20+
export const getFormattedImportUsageString = (path?: string): string => {
2121
if (!path) return "";
2222
return `<pre><span style="--shiki-light:#D73A49;--shiki-dark:#F97583;">import</span> <span style="--shiki-light:#032F62;--shiki-dark:#9ECBFF;">"${path}"</span>;</pre>`;
2323
};
2424

25-
export const getUsageSectionMarkdown = (sections: [string, string?][]) => {
25+
export const getUsageSectionMarkdown = (
26+
sections: [string, string?][],
27+
): string => {
2628
let res = "";
2729

2830
if (sections.length === 0) return res;

docs/vitepress.config.ts

+4-2
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
1-
import { defineConfig } from "vitepress";
1+
import { defineConfig, type DefaultTheme, type UserConfig } from "vitepress";
22
import nav from "./nav.ts";
33
import sidebar from "./sidebar.ts";
44
import socialLinks from "./social-links.ts";
55

6-
export default defineConfig({
6+
const config: UserConfig<DefaultTheme.Config> = defineConfig({
77
title: "Tapsi Design System",
88
description: "A set of components based on Tapsi design system.",
99
base: "/web-components/",
@@ -41,3 +41,5 @@ export default defineConfig({
4141
"components/index.md": "components.md",
4242
},
4343
});
44+
45+
export default config;

internals/danger/package.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "@internals/danger",
3-
"main": "index.ts",
3+
"main": "src/index.ts",
44
"version": "0.0.0",
55
"private": true,
66
"type": "module"

internals/danger/DangerClient.ts renamed to internals/danger/src/DangerClient.ts

+4-4
Original file line numberDiff line numberDiff line change
@@ -59,28 +59,28 @@ class DangerClient {
5959
return `[^${++this.footnoteString}]`;
6060
}
6161

62-
public failWithFootnote(content: string, footnote: string) {
62+
public failWithFootnote(content: string, footnote: string): void {
6363
const footnoteString = this.getFootnoteString();
6464

6565
this.fail(`${content} ${footnoteString}`);
6666
this.markdown(`${footnoteString}: ${footnote}`);
6767
}
6868

69-
public warnWithFootnote(content: string, footnote: string) {
69+
public warnWithFootnote(content: string, footnote: string): void {
7070
const footnoteString = this.getFootnoteString();
7171

7272
this.warn(`${content} ${footnoteString}`);
7373
this.markdown(`${footnoteString}: ${footnote}`);
7474
}
7575

76-
public markdownWithFootnote(content: string, footnote: string) {
76+
public markdownWithFootnote(content: string, footnote: string): void {
7777
const footnoteString = this.getFootnoteString();
7878

7979
this.markdown(`${content} ${footnoteString}`);
8080
this.markdown(`${footnoteString}: ${footnote}`);
8181
}
8282

83-
public messageWithFootnote(content: string, footnote: string) {
83+
public messageWithFootnote(content: string, footnote: string): void {
8484
const footnoteString = this.getFootnoteString();
8585

8686
this.message(`${content} ${footnoteString}`);
File renamed without changes.

internals/danger/tsconfig.json

+9
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
{
2+
"extends": "../../tsconfig.json",
3+
"compilerOptions": {
4+
"moduleResolution": "node",
5+
"module": "ES2020",
6+
"resolvePackageJsonExports": false
7+
},
8+
"include": ["src"]
9+
}

internals/test-helpers/handles.ts

-9
This file was deleted.

internals/test-helpers/package.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "@internals/test-helpers",
3-
"main": "index.ts",
3+
"main": "src/index.ts",
44
"version": "0.0.0",
55
"private": true,
66
"type": "module"

internals/test-helpers/create-promise-resolvers.ts renamed to internals/test-helpers/src/create-promise-resolvers.ts

+10-5
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,9 @@
1-
const createPromiseResolvers = <T = void>() => {
1+
const createPromiseResolvers = <T = void>(): {
2+
readonly promise: Promise<T>;
3+
readonly resolve: (value: T | PromiseLike<T>) => void;
4+
readonly reject: (reason?: unknown) => void;
5+
renew: () => void;
6+
} => {
27
const noop = () => void 0;
38

49
let _resolve: (value: T | PromiseLike<T>) => void = noop;
@@ -12,18 +17,18 @@ const createPromiseResolvers = <T = void>() => {
1217

1318
let _promise = createPromise();
1419

15-
const renew = () => {
20+
const renew = (): void => {
1621
_promise = createPromise();
1722
};
1823

1924
return {
20-
get promise() {
25+
get promise(): Promise<T> {
2126
return _promise;
2227
},
23-
get resolve() {
28+
get resolve(): (value: T | PromiseLike<T>) => void {
2429
return _resolve;
2530
},
26-
get reject() {
31+
get reject(): (reason?: unknown) => void {
2732
return _reject;
2833
},
2934
renew,

internals/test-helpers/forEachLocator.ts renamed to internals/test-helpers/src/forEachLocator.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ import { type Locator } from "@playwright/test";
33
export const forEachLocator = async (
44
locators: Locator[],
55
callback: (locator: Locator, index: number) => void | Promise<void>,
6-
) => {
6+
): Promise<void> => {
77
for (const [index, locator] of locators.entries()) {
88
await callback(locator, index);
99
}

internals/test-helpers/src/handles.ts

+12
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
import type { ElementHandle, JSHandle, Page } from "@playwright/test";
2+
3+
export const windowHandle = (
4+
page: Page,
5+
): Promise<JSHandle<Window & typeof globalThis>> =>
6+
page.evaluateHandle(() => window);
7+
8+
export const documentHandle = (page: Page): Promise<ElementHandle<Document>> =>
9+
page.evaluateHandle(() => document);
10+
11+
export const bodyHandle = (page: Page): Promise<ElementHandle<HTMLElement>> =>
12+
page.evaluateHandle(() => document.body);

0 commit comments

Comments
 (0)