From e41af1795b8c67f277e96775d9a95e834af43c6d Mon Sep 17 00:00:00 2001 From: Benny Powers Date: Mon, 14 Oct 2024 13:13:38 +0300 Subject: [PATCH] chore: typescript configs --- .gitignore | 13 +-- .stylelintrc.yml | 2 +- docs/11ty-types.d.ts | 62 ++++++++++++-- docs/_includes/layouts/pages/element.11ty.ts | 26 +++--- docs/_includes/layouts/pages/has-toc.njk | 2 +- docs/_includes/layouts/pages/tokens.11ty.ts | 6 +- .../partials/component/feedback.11ty.ts | 23 ++--- docs/_includes/partials/component/header.njk | 2 +- docs/_plugins/alphabetize-tags.ts | 4 +- docs/_plugins/element-demos.ts | 3 +- docs/_plugins/element-docs.ts | 53 +++++++----- docs/_plugins/importMap.ts | 14 ++-- docs/_plugins/lit-ssr/lit.ts | 6 +- docs/_plugins/markdown-it.ts | 11 ++- docs/_plugins/rhds.ts | 14 ++-- docs/_plugins/table-of-contents.ts | 20 ++--- docs/styles/lightdom.css | 8 +- docs/tsconfig.json | 14 ++++ elements/tsconfig.json | 17 ++++ eleventy.config.ts | 84 ++++++++++--------- lib/tsconfig.json | 12 +++ package-lock.json | 37 ++++++-- package.json | 35 ++++---- scripts/environment.d.ts | 9 ++ tsconfig.docs.json | 25 ------ tsconfig.json | 38 ++++----- tsconfig.settings.json | 46 +++++----- uxdot/repoStatus.ts | 10 +++ uxdot/tsconfig.json | 14 ++++ .../uxdot-best-practice.css | 0 .../elements => uxdot}/uxdot-best-practice.ts | 0 .../elements => uxdot}/uxdot-copy-button.css | 0 .../elements => uxdot}/uxdot-copy-button.ts | 0 .../uxdot-copy-permalink-lightdom.css | 0 .../uxdot-copy-permalink.css | 0 .../uxdot-copy-permalink.ts | 0 .../elements => uxdot}/uxdot-example.css | 0 .../elements => uxdot}/uxdot-example.ts | 0 .../elements => uxdot}/uxdot-feedback.css | 0 .../elements => uxdot}/uxdot-feedback.ts | 0 .../elements => uxdot}/uxdot-header.css | 0 .../elements => uxdot}/uxdot-header.ts | 0 .../elements => uxdot}/uxdot-hero.css | 0 .../elements => uxdot}/uxdot-hero.ts | 0 .../uxdot-installation-tabs.ts | 0 .../uxdot-masthead-lightdom.css | 0 .../elements => uxdot}/uxdot-masthead.css | 0 .../elements => uxdot}/uxdot-masthead.ts | 0 .../uxdot-pattern-ssr-controller-client.ts | 0 .../uxdot-pattern-ssr-controller-server.ts | 5 +- .../uxdot-pattern-ssr-controller.ts | 0 .../elements => uxdot}/uxdot-pattern.css | 0 .../elements => uxdot}/uxdot-pattern.ts | 0 .../uxdot-repo-status-checklist.ts | 0 .../uxdot-repo-status-list.css | 0 .../uxdot-repo-status-list.ts | 0 .../uxdot-repo-status-table.css | 0 .../uxdot-repo-status-table.ts | 0 .../elements => uxdot}/uxdot-repo.ts | 10 +-- .../elements => uxdot}/uxdot-search.css | 0 .../elements => uxdot}/uxdot-search.ts | 0 .../uxdot-sidenav-dropdown-menu-item.css | 0 .../uxdot-sidenav-dropdown-menu.css | 0 .../uxdot-sidenav-dropdown.css | 0 .../elements => uxdot}/uxdot-sidenav-item.css | 0 .../uxdot-sidenav-lightdom.css | 0 .../elements => uxdot}/uxdot-sidenav.css | 0 .../elements => uxdot}/uxdot-sidenav.ts | 0 .../uxdot-spacer-tokens-table.css | 0 .../uxdot-spacer-tokens-table.ts | 0 .../elements => uxdot}/uxdot-toc-lightdom.css | 0 .../elements => uxdot}/uxdot-toc.css | 0 .../elements => uxdot}/uxdot-toc.ts | 0 73 files changed, 380 insertions(+), 245 deletions(-) create mode 100644 docs/tsconfig.json create mode 100644 elements/tsconfig.json create mode 100644 lib/tsconfig.json create mode 100644 scripts/environment.d.ts delete mode 100644 tsconfig.docs.json create mode 100644 uxdot/repoStatus.ts create mode 100644 uxdot/tsconfig.json rename {docs/assets/javascript/elements => uxdot}/uxdot-best-practice.css (100%) rename {docs/assets/javascript/elements => uxdot}/uxdot-best-practice.ts (100%) rename {docs/assets/javascript/elements => uxdot}/uxdot-copy-button.css (100%) rename {docs/assets/javascript/elements => uxdot}/uxdot-copy-button.ts (100%) rename {docs/assets/javascript/elements => uxdot}/uxdot-copy-permalink-lightdom.css (100%) rename {docs/assets/javascript/elements => uxdot}/uxdot-copy-permalink.css (100%) rename {docs/assets/javascript/elements => uxdot}/uxdot-copy-permalink.ts (100%) rename {docs/assets/javascript/elements => uxdot}/uxdot-example.css (100%) rename {docs/assets/javascript/elements => uxdot}/uxdot-example.ts (100%) rename {docs/assets/javascript/elements => uxdot}/uxdot-feedback.css (100%) rename {docs/assets/javascript/elements => uxdot}/uxdot-feedback.ts (100%) rename {docs/assets/javascript/elements => uxdot}/uxdot-header.css (100%) rename {docs/assets/javascript/elements => uxdot}/uxdot-header.ts (100%) rename {docs/assets/javascript/elements => uxdot}/uxdot-hero.css (100%) rename {docs/assets/javascript/elements => uxdot}/uxdot-hero.ts (100%) rename {docs/assets/javascript/elements => uxdot}/uxdot-installation-tabs.ts (100%) rename {docs/assets/javascript/elements => uxdot}/uxdot-masthead-lightdom.css (100%) rename {docs/assets/javascript/elements => uxdot}/uxdot-masthead.css (100%) rename {docs/assets/javascript/elements => uxdot}/uxdot-masthead.ts (100%) rename {docs/assets/javascript/elements => uxdot}/uxdot-pattern-ssr-controller-client.ts (100%) rename {docs/assets/javascript/elements => uxdot}/uxdot-pattern-ssr-controller-server.ts (96%) rename {docs/assets/javascript/elements => uxdot}/uxdot-pattern-ssr-controller.ts (100%) rename {docs/assets/javascript/elements => uxdot}/uxdot-pattern.css (100%) rename {docs/assets/javascript/elements => uxdot}/uxdot-pattern.ts (100%) rename {docs/assets/javascript/elements => uxdot}/uxdot-repo-status-checklist.ts (100%) rename {docs/assets/javascript/elements => uxdot}/uxdot-repo-status-list.css (100%) rename {docs/assets/javascript/elements => uxdot}/uxdot-repo-status-list.ts (100%) rename {docs/assets/javascript/elements => uxdot}/uxdot-repo-status-table.css (100%) rename {docs/assets/javascript/elements => uxdot}/uxdot-repo-status-table.ts (100%) rename {docs/assets/javascript/elements => uxdot}/uxdot-repo.ts (93%) rename {docs/assets/javascript/elements => uxdot}/uxdot-search.css (100%) rename {docs/assets/javascript/elements => uxdot}/uxdot-search.ts (100%) rename {docs/assets/javascript/elements => uxdot}/uxdot-sidenav-dropdown-menu-item.css (100%) rename {docs/assets/javascript/elements => uxdot}/uxdot-sidenav-dropdown-menu.css (100%) rename {docs/assets/javascript/elements => uxdot}/uxdot-sidenav-dropdown.css (100%) rename {docs/assets/javascript/elements => uxdot}/uxdot-sidenav-item.css (100%) rename {docs/assets/javascript/elements => uxdot}/uxdot-sidenav-lightdom.css (100%) rename {docs/assets/javascript/elements => uxdot}/uxdot-sidenav.css (100%) rename {docs/assets/javascript/elements => uxdot}/uxdot-sidenav.ts (100%) rename {docs/assets/javascript/elements => uxdot}/uxdot-spacer-tokens-table.css (100%) rename {docs/assets/javascript/elements => uxdot}/uxdot-spacer-tokens-table.ts (100%) rename {docs/assets/javascript/elements => uxdot}/uxdot-toc-lightdom.css (100%) rename {docs/assets/javascript/elements => uxdot}/uxdot-toc.css (100%) rename {docs/assets/javascript/elements => uxdot}/uxdot-toc.ts (100%) diff --git a/.gitignore b/.gitignore index 8ad4e8e662..fed260cc38 100644 --- a/.gitignore +++ b/.gitignore @@ -8,16 +8,15 @@ node_modules _site docs/pfe.min* docs/assets/playgrounds/ -docs/assets/javascript/elements/*.js.map -docs/assets/javascript/elements/*.d.ts -docs/assets/javascript/elements/*.js +docs/assets/javascript/elements/**/*.js.map +docs/assets/javascript/elements/**/*.d.ts +docs/assets/javascript/elements/**/*.js docs/_plugins/**/*.js docs/_includes/**/*.js docs/_data/playgrounds.json docs/assets/javascript/elements/playground-elements.js docs/assets/javascript/elements/assets/playground-typescript-worker-*.js docs/assets/javascript/environment.js -!docs/11ty-types.d.ts # Build artifacts elements.js @@ -26,10 +25,13 @@ elements/*/test/*.js react lib/**/*.js !elements/**/demo/*.css +*.tsbuildinfo *.map *.d.ts !declaration.d.ts -*.tsbuildinfo +!docs/11ty-types.d.ts +!./docs/11ty-types.d.ts +!*/11ty-types.d.ts custom-elements.json test-results.xml rhds.min.js @@ -109,4 +111,3 @@ $RECYCLE.BIN/ # Windows shortcuts *.lnk -!declaration.d.ts diff --git a/.stylelintrc.yml b/.stylelintrc.yml index d7c764e0b1..3927d8c48e 100644 --- a/.stylelintrc.yml +++ b/.stylelintrc.yml @@ -40,8 +40,8 @@ rules: ignoreTypes: - heading - actions - - rendered - pending + - --rendered selector-pseudo-element-no-unknown: - true diff --git a/docs/11ty-types.d.ts b/docs/11ty-types.d.ts index bcb2d670dd..e15f30385d 100644 --- a/docs/11ty-types.d.ts +++ b/docs/11ty-types.d.ts @@ -1,7 +1,3 @@ -declare module '@11ty/eleventy-plugin-syntaxhighlight/src/HighlightPairedShortcode.js' { - export default function HighlightPairedShortcode(content: string, language: string, highlightLines: string, options: object): any -} - declare module '@11ty/eleventy-plugin-syntaxhighlight/src/getAttributes.js' { export default function getAttributes(...args: any[]): string } @@ -80,12 +76,15 @@ declare module '@11ty/eleventy/src/UserConfig.js' { compile(inputContent: string): (this: CompileContext, data: unknown) => string | Promise; } - interface EleventyEventHandlerOptions { + interface EleventyBeforeEventHandlerOptions { directories: EleventyData['directories'], /** @deprecated */ dir: {input: string; output: string; includes: string, data: string; layouts: string;}; outputMode: 'js'|'json'|'ndjson'; runMode: 'build'|'serve'|'watch'; + } + + interface EleventyAfterEventHandlerOptions extends EleventyBeforeEventHandlerOptions { results?: {inputPath:string;outputPath:string; url:string;content:string}[]; } @@ -93,19 +92,30 @@ declare module '@11ty/eleventy/src/UserConfig.js' { type AddCollectionCallback = (api: CollectionApi) => CollectionItem[] | Promise; - type OnCallback = (opts: EleventyEventHandlerOptions) => void | Promise; + type OnCallback = (opts: O) => void | Promise; export type PluginFunction = (config: UserConfig, opts?: Opts) => void | Promise - type FilterFunction = (this: FilterContext, data: T, ...args: unknown[]) => R | Promise; + type FilterFunction = (this: FilterContext, data: T) => R | Promise; + type FilterFunctionWithArgs = (this: FilterContext, data: T, ...args: any[]) => R | Promise; + + type DataEntry = + | string + | number + | object + | Promise + | (() => unknown) + | (() => Promise); export default class UserConfig { addCollection(name: string, callback: AddCollectionCallback): void; addDataExtension(names: string, processor: (content: string) => unknown | Promise): void; addExtension(extension: string, options: AddExtensionOptions): void; addFilter(name: string, filter: FilterFunction): void; + addFilter(name: string, filter: FilterFunctionWithArgs): void; addGlobalData(name: string, data: unknown | (() => unknown)): void; addJavaScriptFunction(name: string, filter: FilterFunction): void; + addJavaScriptFunction(name: string, filter: FilterFunctionWithArgs): void; addPassthroughCopy(items: string | Record, copyOptions?: PassthroughCopyOptions): void; addPlugin(Plugin: PluginFunction | { initֵArguments?: Opts; @@ -115,9 +125,15 @@ declare module '@11ty/eleventy/src/UserConfig.js' { addWatchTarget(name: string, opts?: { resetConfig: boolean }): void; amendLibrary(md: 'md', callback: ((md: MarkdownIt) => MarkdownIt)): void; getFilter(name: string): FilterFunction; - globalData: Record unknown) | ((() => Promise))>; - on(event: 'eleventy.before'| 'eleventy.beforeWatch' | 'eleventy.after', callback: OnCallback): void; + getFilter(name: string): FilterFunctionWithArgs; + globalData: { [key: string]: DataEntry }; + on(event: 'eleventy.before', callback: OnCallback): void; + on(event: 'eleventy.after', callback: OnCallback): void; + on(event: 'eleventy.beforeWatch', callback: (changedFiles: string[]) => void | Promise): void; + on(event: 'eleventy.contentMap', callback: (opts: ({ inputPathToUrl: Record, urlToInputPath: Record })) => void | Promise): void; + on(event: 'eleventy.beforeConfig', callback: (config: UserConfig) => void | Promise): void; setQuietMode(quiet: boolean): void; + javascriptFunctions: Record any>; watchIgnores: Set; } } @@ -162,7 +178,9 @@ declare module '@11ty/eleventy-plugin-syntaxhighlight' { errorOnInvalidLanguage: boolean; }>; export default Plugin; + export function pairedShortcode(content: string, language: string, highlightLines: string, options: object): string; } + declare module '@11ty/eleventy-plugin-directory-output' { import { PluginFunction } from "@11ty/eleventy/src/UserConfig.js"; const Plugin: PluginFunction<{ @@ -173,6 +191,30 @@ declare module '@11ty/eleventy-plugin-directory-output' { }>; export default Plugin; } + +declare module '@11ty/eleventy-fetch' { + import { PluginFunction } from "@11ty/eleventy/src/UserConfig.js"; + type Duration = `${number}${'d'|'m'|'h'}`; + type CacheType = 'json' | 'buffer' | 'text'; + function EleventyFetch(url: string, options: { + directory: string; + removeUrlQueryParams: boolean; + type: CacheType; + duration: Duration; + fetchOptions: { headers: Record }; + }): Promise; + export default EleventyFetch; + export class AssetCache { + constructor(tag: string); + isCacheValid(time: Duration): boolean; + save(data:T, type: CacheType): Promise; + getCachedValue(): Promise + cache: { + destroy(): void; + } + } +} + declare module '@patternfly/pfe-tools/11ty/plugins/anchors.cjs' { import type { Cheerio } from 'cheerio'; import type { AnyNode } from 'domhandler'; @@ -183,12 +225,14 @@ declare module '@patternfly/pfe-tools/11ty/plugins/anchors.cjs' { }>; export default AnchorsPlugin; } + declare module '@patternfly/pfe-tools/11ty/plugins/custom-elements-manifest.cjs' { import type { PluginOptions } from '@patternfly/pfe-tools/11ty/plugins/types'; import { PluginFunction } from "@11ty/eleventy/src/UserConfig.js"; const Plugin: PluginFunction; export default Plugin; } + declare module 'eleventy-plugin-helmet' { import { PluginFunction } from "@11ty/eleventy/src/UserConfig.js"; const Plugin: PluginFunction; diff --git a/docs/_includes/layouts/pages/element.11ty.ts b/docs/_includes/layouts/pages/element.11ty.ts index 6af2e9b4b7..60bc2a46ec 100644 --- a/docs/_includes/layouts/pages/element.11ty.ts +++ b/docs/_includes/layouts/pages/element.11ty.ts @@ -1,4 +1,4 @@ -import type { ElementDocsPageData } from '../../../_plugins/element-docs.js'; +import type { ElementDocsPageData } from '#11ty-plugins/element-docs.js'; import type { ClassMethod } from 'custom-elements-manifest'; import type { FileOptions, ProjectManifest } from 'playground-elements/shared/worker-api.js'; @@ -6,10 +6,11 @@ import { tokens } from '@rhds/tokens/meta.js'; import { join } from 'node:path'; import { fileURLToPath } from 'node:url'; import { readFile } from 'node:fs/promises'; -import { copyCell, dedent, getTokenHref } from '../../../_plugins/tokensHelpers.js'; +import { copyCell, dedent, getTokenHref } from '#11ty-plugins/tokensHelpers.js'; import { Generator } from '@jspm/generator'; import { AssetCache } from '@11ty/eleventy-fetch'; -import { Renderer } from '#uxdot/eleventy.config.js'; +import { Renderer } from '#eleventy.config'; +import type { ImportMap } from '#11ty-plugins/importMap.js'; type FileEntry = [string, FileOptions & { inline: string }]; @@ -43,16 +44,16 @@ interface Context extends EleventyPageRenderData { playgrounds: Record<`rh-${string}`, ProjectManifest>; } -export default class ElementsPage extends Renderer { - static assetCache = new AssetCache('rhds-ux-dot-import-map-jspmio'); +export default class ElementsPage extends Renderer { + static assetCache = new AssetCache('rhds-ux-dot-import-map-jspmio'); data() { return { layout: 'layouts/pages/has-toc.njk', - permalink: ({ doc }) => doc.permalink, + permalink: ({ doc }: Context) => doc.permalink, eleventyComputed: { - title: ({ doc }) => doc.pageTitle, - tagName: ({ doc }) => doc.tagName, + title: ({ doc }: Context) => doc.pageTitle, + tagName: ({ doc }: Context) => doc.tagName, }, }; } @@ -138,9 +139,9 @@ export default class ElementsPage extends Renderer { await assetCache.save(generator.getMap(), 'json'); } const map = structuredClone(await assetCache.getCachedValue()); - map.imports[`@rhds/elements/${tagName}/${tagName}.js`] = - map.imports['@rhds/elements'].replace('elements.js', `${tagName}/${tagName}.js`); - delete map.imports['@rhds/elements']; + map.imports![`@rhds/elements/${tagName}/${tagName}.js`] = + map.imports!['@rhds/elements'].replace('elements.js', `${tagName}/${tagName}.js`); + delete map.imports!['@rhds/elements']; return JSON.stringify(map, null, 2); } @@ -776,7 +777,8 @@ export default class ElementsPage extends Renderer { } async #renderDemos(ctx: Context) { - const entries: FileEntry[] = Object.entries(ctx.playgrounds[ctx.tagName]?.files ?? {}); + const tagName = ctx.tagName as `rh-${string}`; + const entries = Object.entries(ctx.playgrounds[tagName]?.files ?? {}) as FileEntry[]; return [ await this.#renderDemoHead(), ...await this.#renderPlaygrounds(ctx, entries), diff --git a/docs/_includes/layouts/pages/has-toc.njk b/docs/_includes/layouts/pages/has-toc.njk index ba37b580d7..6a4fc74d1a 100755 --- a/docs/_includes/layouts/pages/has-toc.njk +++ b/docs/_includes/layouts/pages/has-toc.njk @@ -8,7 +8,7 @@ layout: layouts/base.njk data-helmet>