From 668237f5ad758219108fdeaad471149d28a146a6 Mon Sep 17 00:00:00 2001 From: rmenner Date: Tue, 2 Dec 2025 18:37:29 -0500 Subject: [PATCH 1/2] fix: enhance default value rendering and type normalization in documentation generation --- src/scripts/docs/docs-generator.ts | 48 +++++++++++++++++++++--------- 1 file changed, 34 insertions(+), 14 deletions(-) diff --git a/src/scripts/docs/docs-generator.ts b/src/scripts/docs/docs-generator.ts index 2a7ea57..5cd2b7a 100644 --- a/src/scripts/docs/docs-generator.ts +++ b/src/scripts/docs/docs-generator.ts @@ -258,14 +258,27 @@ export default class Docs { } const headers = ["Properties", "Attributes", "Modifiers", "Type", "Default", "Description"]; - const rows = mergedData.map((item: MergedTableData) => [ - escapeMarkdown(item.properties), - escapeMarkdown(item.attributes), - escapeMarkdown(item.modifiers), - escapeMarkdown(item.type), - escapeMarkdown(item.default), - escapeMarkdown(item.description), - ]); + const rows = mergedData.map((item: MergedTableData) => { + const defaultRaw = item.default || ""; + const defaultTrimmed = defaultRaw.trim(); + // Remove surrounding single quotes from default values like 'foo' + const defaultSanitized = defaultTrimmed.replace(/^'([^']+)'$/, "$1"); + // Remove surrounding double quotes from default values like "foo" + const defaultDoubleSanitized = defaultSanitized.replace(/^"([^"]+)"$/, "$1"); + const defaultWrapped = defaultDoubleSanitized + ? (defaultDoubleSanitized.startsWith('`') && defaultDoubleSanitized.endsWith('`') + ? defaultDoubleSanitized + : `\`${defaultDoubleSanitized}\``) + : ""; + return [ + escapeMarkdown(item.properties), + escapeMarkdown(item.attributes), + escapeMarkdown(item.modifiers), + escapeMarkdown(item.type), + escapeMarkdown(defaultWrapped), + escapeMarkdown(item.description), + ]; + }); const table = markdownTable([headers, ...rows]); @@ -364,14 +377,23 @@ ${table} const { type } = obj; + // Utility to normalize type text: fix union spacing and replace single quotes with backticks + const normalizeType = (text: string): string => { + return text + // Normalize union separators to have spaces around | + .replace(/\s*\|\s*/g, ' | ') + // Replace any single-quoted type segments with backticks + .replace(/'([^']+)'/g, '`$1`'); + }; + // Handle simple string type if (typeof type === 'string') { - return type.replace(/\s*\|\s*/g, ' | '); + return normalizeType(type); } // Handle type with text property if (type.text) { - return type.text.replace(/\s*\|\s*/g, ' | '); + return normalizeType(type.text); } // Handle union types or arrays of types @@ -387,7 +409,7 @@ ${table} // Handle complex type objects if (type.name) { - return type.name.replace(/\s*\|\s*/g, ' | '); + return normalizeType(type.name); } // Handle references @@ -398,9 +420,7 @@ ${table} // Fallback to string representation const result = String(type); - - // Normalize all | separators to have spaces - return result.replace(/\s*\|\s*/g, ' | '); + return normalizeType(result); } /** From dd2669df2c07139b67e22fba89f69ecce33572b3 Mon Sep 17 00:00:00 2001 From: rmenner Date: Tue, 2 Dec 2025 18:38:16 -0500 Subject: [PATCH 2/2] feat: upgrade dts generation to use cem instead --- package-lock.json | 39 ++++--------------- package.json | 4 +- .../custom-elements-manifest.config.mjs | 7 ++++ src/scripts/build/configUtils.js | 23 ----------- src/scripts/build/index.js | 6 --- src/scripts/build/watchModeHandlers.js | 24 +----------- 6 files changed, 18 insertions(+), 85 deletions(-) diff --git a/package-lock.json b/package-lock.json index baafb52..7b277ed 100644 --- a/package-lock.json +++ b/package-lock.json @@ -21,6 +21,7 @@ "@rollup/plugin-terser": "^0.4.4", "@rollup/plugin-typescript": "^12.1.4", "@wc-toolkit/cem-sorter": "^1.0.1", + "@wc-toolkit/jsx-types": "^1.4.3", "@web/dev-server": "^0.4.6", "@web/dev-server-rollup": "^0.6.4", "@web/test-runner": "^0.20.2", @@ -33,7 +34,6 @@ "inquirer": "^12.9.6", "markdown-table": "^3.0.4", "ora": "^8.2.0", - "rollup-plugin-dts": "^6.2.3", "rollup-plugin-scss-lit": "^2.1.0", "simple-git": "^3.28.0", "table": "^6.9.0", @@ -5228,6 +5228,12 @@ "integrity": "sha512-B7Ku0I1Gfy4dVRyjrbRl9UxROEIacLIFHPRBDs1Sh+yQLMc7xZhREju9msDsPDLhthqjiI0BAt/1OmEy00G1Dg==", "license": "MIT" }, + "node_modules/@wc-toolkit/jsx-types": { + "version": "1.4.3", + "resolved": "https://registry.npmjs.org/@wc-toolkit/jsx-types/-/jsx-types-1.4.3.tgz", + "integrity": "sha512-NbjzuOi1jBzllgYN1F8ycgmSY4nzt7wTISI4q5FSQt4JNZtTHdRoLPFq160U9rh7TcqKN6E2Zte4trM6eA+n1A==", + "license": "MIT" + }, "node_modules/@web/browser-logs": { "version": "0.4.1", "resolved": "https://registry.npmjs.org/@web/browser-logs/-/browser-logs-0.4.1.tgz", @@ -11948,15 +11954,6 @@ "node": ">=16.14" } }, - "node_modules/magic-string": { - "version": "0.30.17", - "resolved": "https://registry.npmjs.org/magic-string/-/magic-string-0.30.17.tgz", - "integrity": "sha512-sNPKHvyjVf7gyjwS4xGTaW/mCnF8wnjtifKBEhxfZ7E/S8tQ0rssrwGNn6q8JH/ohItJfSQp9mBtQYuTlH5QnA==", - "license": "MIT", - "dependencies": { - "@jridgewell/sourcemap-codec": "^1.5.0" - } - }, "node_modules/make-dir": { "version": "3.1.0", "resolved": "https://registry.npmjs.org/make-dir/-/make-dir-3.1.0.tgz", @@ -18161,28 +18158,6 @@ "url": "https://github.com/sponsors/jonschlinkert" } }, - "node_modules/rollup-plugin-dts": { - "version": "6.2.3", - "resolved": "https://registry.npmjs.org/rollup-plugin-dts/-/rollup-plugin-dts-6.2.3.tgz", - "integrity": "sha512-UgnEsfciXSPpASuOelix7m4DrmyQgiaWBnvI0TM4GxuDh5FkqW8E5hu57bCxXB90VvR1WNfLV80yEDN18UogSA==", - "license": "LGPL-3.0-only", - "dependencies": { - "magic-string": "^0.30.17" - }, - "engines": { - "node": ">=16" - }, - "funding": { - "url": "https://github.com/sponsors/Swatinem" - }, - "optionalDependencies": { - "@babel/code-frame": "^7.27.1" - }, - "peerDependencies": { - "rollup": "^3.29.4 || ^4", - "typescript": "^4.5 || ^5.0" - } - }, "node_modules/rollup-plugin-scss-lit": { "version": "2.1.0", "resolved": "https://registry.npmjs.org/rollup-plugin-scss-lit/-/rollup-plugin-scss-lit-2.1.0.tgz", diff --git a/package.json b/package.json index ffc8b47..a48ba51 100644 --- a/package.json +++ b/package.json @@ -77,11 +77,11 @@ "inquirer": "^12.9.6", "markdown-table": "^3.0.4", "ora": "^8.2.0", - "rollup-plugin-dts": "^6.2.3", "rollup-plugin-scss-lit": "^2.1.0", "simple-git": "^3.28.0", "table": "^6.9.0", - "typescript": "^5.9.2" + "typescript": "^5.9.2", + "@wc-toolkit/jsx-types": "^1.4.3" }, "devDependencies": { "@aurodesignsystem/auro-config": "^1.3.1", diff --git a/src/configs/custom-elements-manifest.config.mjs b/src/configs/custom-elements-manifest.config.mjs index aedde0e..933dcd3 100644 --- a/src/configs/custom-elements-manifest.config.mjs +++ b/src/configs/custom-elements-manifest.config.mjs @@ -1,4 +1,5 @@ import { cemSorterPlugin } from "@wc-toolkit/cem-sorter"; +import { jsxTypesPlugin } from "@wc-toolkit/jsx-types"; export default { globs: ["src/**/*.*js", "scripts/wca/**/*.*js"], @@ -10,5 +11,11 @@ export default { cemSorterPlugin({ deprecatedLast: true, }), + jsxTypesPlugin({ + fileName: "index.d.ts", + outdir: "dist", + defaultExport: true, + excludeCssCustomProperties: true, + }) ], }; \ No newline at end of file diff --git a/src/scripts/build/configUtils.js b/src/scripts/build/configUtils.js index 3b242e1..e27761e 100644 --- a/src/scripts/build/configUtils.js +++ b/src/scripts/build/configUtils.js @@ -1,7 +1,6 @@ import { basename, join } from "node:path"; import { nodeResolve } from "@rollup/plugin-node-resolve"; import { glob } from "glob"; -import { dts } from "rollup-plugin-dts"; import { litScss } from "rollup-plugin-scss-lit"; import { watchGlobs } from "./plugins.js"; @@ -108,28 +107,6 @@ export function getDemoConfig(options = {}) { }; } -/** - * Creates Rollup configuration for the d.ts files with output options. - * @param {object} options - Configuration options - * @returns {object} - Complete Rollup configuration object with input and output. - */ -export function getDtsConfig(options = {}) { - const { input = ["./dist/index.js"], outputDir = "./dist" } = options; - - return { - name: "DTS", - config: { - input, - output: { - format: "esm", - dir: outputDir, - entryFileNames: "[name].d.ts", - }, - plugins: [dts()], - }, - }; -} - /** * Creates Rollup configuration for watch mode. * @param {boolean|object} watchOptions - Whether to enable watch mode or watch options diff --git a/src/scripts/build/index.js b/src/scripts/build/index.js index e4354ae..7b75a2b 100644 --- a/src/scripts/build/index.js +++ b/src/scripts/build/index.js @@ -2,13 +2,11 @@ import terser from "@rollup/plugin-terser"; import { watch } from "rollup"; import { buildCombinedBundle, - buildTypeDefinitions, cleanupDist, generateDocs, } from "./bundleHandlers.js"; import { getDemoConfig, - getDtsConfig, getMainBundleConfig, } from "./configUtils.js"; import { startDevelopmentServer } from "./devServerUtils.js"; @@ -25,7 +23,6 @@ import { async function runProductionBuild(options) { const mainBundleConfig = getMainBundleConfig(options); const demoConfig = getDemoConfig(options); - const dtsConfig = getDtsConfig(); // Add terser for minification in production mainBundleConfig.config.plugins.push(terser()); @@ -35,9 +32,6 @@ async function runProductionBuild(options) { // Build main and demo bundles await buildCombinedBundle(mainBundleConfig.config, demoConfig.config); - - // Build TypeScript definitions - await buildTypeDefinitions(dtsConfig.config, dtsConfig.config.output); } /** diff --git a/src/scripts/build/watchModeHandlers.js b/src/scripts/build/watchModeHandlers.js index feeb396..e94d67d 100644 --- a/src/scripts/build/watchModeHandlers.js +++ b/src/scripts/build/watchModeHandlers.js @@ -3,14 +3,12 @@ import ora from "ora"; import { rollup } from "rollup"; import { analyzeComponents } from "#scripts/analyze.js"; import { generateDocs } from "./bundleHandlers.js"; -import { getDtsConfig } from "./configUtils.js"; // Track if any build is in progress to prevent overlapping operations let buildInProgress = false; // Track build states and times in a single object for cleaner management const builds = { - dts: { active: false, lastTime: 0 }, analyze: { active: false, lastTime: 0 }, docs: { active: false, lastTime: 0 }, }; @@ -52,7 +50,7 @@ function isOutputFile(filePath) { /** * Runs a build task with proper tracking of state - * @param {string} taskName - Type of task (dts, analyze, docs) + * @param {string} taskName - Type of task (analyze, docs) * @param {Function} taskFn - The actual task function to run * @returns {Promise} - Success status */ @@ -90,7 +88,7 @@ export async function handleWatcherEvents( // Track if this is the first build let isInitialBuild = true; // biome-ignore lint/style/useConst: This is an object that is mutated. - let buildTasksResults = { dts: false, analyze: false, docs: false }; + let buildTasksResults = {analyze: false, docs: false }; let scheduledTasksTimer = null; let bundleSpinner; @@ -99,22 +97,6 @@ export async function handleWatcherEvents( // The actual task functions const buildTasks = { - // Function to build d.ts files - dts: async () => { - const dtsSpinner = ora("Crafting type definitions...").start(); - try { - const create_dts = await rollup(getDtsConfig().config); - await create_dts.write(getDtsConfig().config.output); - await create_dts.close(); - dtsSpinner.succeed("Type files built."); - return true; - } catch (error) { - dtsSpinner.fail("Types trouble! Build failed."); - console.error("TypeScript definition build error:", error); - return false; - } - }, - // Function to analyze components analyze: async () => { const { wcaInput: sourceFiles, wcaOutput: outFile, skipDocs } = options; @@ -172,7 +154,6 @@ export async function handleWatcherEvents( const checkInitialBuildComplete = () => { if ( isInitialBuild && - buildTasksResults.dts && buildTasksResults.analyze && buildTasksResults.docs && typeof onInitialBuildComplete === "function" @@ -190,7 +171,6 @@ export async function handleWatcherEvents( scheduledTasksTimer = setTimeout(async () => { // Run tasks with delays between them to avoid race conditions - buildTasksResults.dts = await runBuildTask("dts", buildTasks.dts); setTimeout(async () => { buildTasksResults.analyze = await runBuildTask(