From fdc469cdfca9c03a32641bff45ff19dafbfd386a Mon Sep 17 00:00:00 2001 From: Lexus Drumgold Date: Wed, 27 Jul 2022 22:07:49 -0400 Subject: [PATCH 1/4] feat(options): `sourcemap?` - https://github.com/Rich-Harris/magic-string#sgeneratemap-options- Signed-off-by: Lexus Drumgold --- src/options.ts | 13 +++++++++++++ 1 file changed, 13 insertions(+) diff --git a/src/options.ts b/src/options.ts index 467b9be..b09405b 100644 --- a/src/options.ts +++ b/src/options.ts @@ -3,6 +3,7 @@ * @module vite-plugin-react-docgen-typescript/Options */ +import type { SourceMapOptions } from 'magic-string' import type { ComponentDoc, ParserOptions } from 'react-docgen-typescript' import type { Plugin } from 'vite' @@ -87,6 +88,18 @@ interface Options extends ParserOptions { */ name?(doc: ComponentDoc, code: string, id: string): Promise | string + /** + * Include [version 3 sourcemap][1] in final transform result for successfully + * parsed modules. + * + * [1]: https://docs.google.com/document/d/1U1RGAehQwRypUTovF1KRlpiOFze0b-_2gc6fAH0KY0k/edit + * + * @see https://github.com/Rich-Harris/magic-string#sgeneratemap-options- + * + * @default true + */ + sourcemap?: Omit | boolean + /** * Name of tsconfig file or path to tsconfig file. * From 7103ad40e940ee37255bfc88357a31c0066094fa Mon Sep 17 00:00:00 2001 From: Lexus Drumgold Date: Wed, 27 Jul 2022 22:10:31 -0400 Subject: [PATCH 2/4] refactor(options): drop `name` - https://github.com/styleguidist/react-docgen-typescript/blob/v2.2.2/src/parser.ts#L350-L355 Signed-off-by: Lexus Drumgold --- src/options.ts | 16 ---------------- 1 file changed, 16 deletions(-) diff --git a/src/options.ts b/src/options.ts index b09405b..98429b7 100644 --- a/src/options.ts +++ b/src/options.ts @@ -72,22 +72,6 @@ interface Options extends ParserOptions { */ include?: string[] - /** - * Generate the name of the component to add a `__docgenInfo` property to. - * - * **Note**: `code` may have transforms from other plugins already applied. - * - * @see {@link ComponentDoc} - * - * @param {ComponentDoc} doc - Component docgen info object - * @param {string} code - Module code being transformed - * @param {string} id - Path to module being transformed - * @return {Promise | string} Component name - * - * @default doc=>doc.displayName - */ - name?(doc: ComponentDoc, code: string, id: string): Promise | string - /** * Include [version 3 sourcemap][1] in final transform result for successfully * parsed modules. From bb3b42a41605f273b7bbaa436057f89469544804 Mon Sep 17 00:00:00 2001 From: Lexus Drumgold Date: Wed, 27 Jul 2022 22:12:35 -0400 Subject: [PATCH 3/4] feat(ts): `PluginReactDocgenTypeScript` Signed-off-by: Lexus Drumgold --- src/constants.ts | 4 ++-- src/index.ts | 1 + src/plugin-type.ts | 49 ++++++++++++++++++++++++++++++++++++++++++++++ 3 files changed, 52 insertions(+), 2 deletions(-) create mode 100644 src/plugin-type.ts diff --git a/src/constants.ts b/src/constants.ts index 609811c..cecb8fd 100644 --- a/src/constants.ts +++ b/src/constants.ts @@ -3,5 +3,5 @@ * @module vite-plugin-react-docgen-typescript/constants */ -/** @const {string} PLUGIN_NAME - Plugin name */ -export const PLUGIN_NAME: string = 'vite:react-docgen-typescript' +/** @const {'vite:react-docgen-typescript'} PLUGIN_NAME - Plugin name */ +export const PLUGIN_NAME = 'vite:react-docgen-typescript' as const diff --git a/src/index.ts b/src/index.ts index 4cafdc6..7fdae98 100644 --- a/src/index.ts +++ b/src/index.ts @@ -6,3 +6,4 @@ export * from './constants' export type { default as Options } from './options' export * from './plugin' +export type { default as PluginReactDocgenTypeScript } from './plugin-type' diff --git a/src/plugin-type.ts b/src/plugin-type.ts new file mode 100644 index 0000000..dd0ff66 --- /dev/null +++ b/src/plugin-type.ts @@ -0,0 +1,49 @@ +/** + * @file RDT Plugin - PluginReactDocgenTypeScript + * @module vite-plugin-react-docgen-typescript/type + */ + +import type { TransformPluginContext, TransformResult } from 'rollup' +import type { Plugin } from 'vite' +import type { PLUGIN_NAME } from './constants' + +/** + * Vite `react-docgen-typescript` plugin type. + * + * @extends {Plugin} + */ +interface PluginReactDocgenTypeScript extends Plugin { + /** + * Plugin ordering. + * + * @see https://vitejs.dev/guide/api-plugin.html#plugin-ordering + */ + enforce: Required['enforce'] + + /** + * Plugin name. + */ + name: typeof PLUGIN_NAME + + /** + * Parses `id` for component docgen info. + * + * For a successfully parsed module, the final transform result will include + * a new source map and updated version of `code` that includes logic to + * attach a `__docgenInfo` property to all components in `id`. + * + * @async + * + * @param {TransformPluginContext} this - Plugin context + * @param {string} code - Module code being transformed + * @param {string} id - Path to module being transformed + * @return {Promise} Transform result + */ + transform( + this: TransformPluginContext, + code: string, + id: string + ): Promise +} + +export type { PluginReactDocgenTypeScript as default } From b3d524e484a215380e029be0a6fe310a09842690 Mon Sep 17 00:00:00 2001 From: Lexus Drumgold Date: Fri, 29 Jul 2022 17:06:34 -0400 Subject: [PATCH 4/4] feat(plugin): `transform` Signed-off-by: Lexus Drumgold --- .cspell.json | 1 + .dictionary.txt | 4 + .eslintignore | 1 + .eslintrc.base.cjs | 49 +- .eslintrc.cjs | 6 + .github/dependabot.yml | 4 +- .husky/pre-push | 2 +- .prettierignore | 1 + .vscode/settings.json | 17 + README.md | 12 +- __fixtures__/.gitkeep | 0 __fixtures__/Button.stories.tsx | 20 + __fixtures__/Button.tsx | 113 + __fixtures__/Counter.tsx | 61 + __fixtures__/List.tsx | 59 + __fixtures__/empty.tsx | 6 + __fixtures__/transform-plugin-context.ts | 54 + build.config.ts | 17 +- loader.mjs | 2 +- package.json | 22 +- src/__snapshots__/plugin.functional.snap | 126 + src/__tests__/plugin.functional.spec.ts | 106 + src/__tests__/plugin.spec.ts | 140 + src/options.ts | 21 +- src/plugin-type.ts | 14 +- src/plugin.ts | 117 +- tsconfig.json | 4 +- vitest.config.ts | 28 +- yarn.lock | 11918 ++++++++++++++++++--- 29 files changed, 11263 insertions(+), 1662 deletions(-) delete mode 100644 __fixtures__/.gitkeep create mode 100644 __fixtures__/Button.stories.tsx create mode 100644 __fixtures__/Button.tsx create mode 100644 __fixtures__/Counter.tsx create mode 100644 __fixtures__/List.tsx create mode 100644 __fixtures__/empty.tsx create mode 100644 __fixtures__/transform-plugin-context.ts create mode 100644 src/__snapshots__/plugin.functional.snap create mode 100644 src/__tests__/plugin.functional.spec.ts create mode 100644 src/__tests__/plugin.spec.ts diff --git a/.cspell.json b/.cspell.json index 2eaa43f..40f7ff2 100644 --- a/.cspell.json +++ b/.cspell.json @@ -13,6 +13,7 @@ "failFast": false, "flagWords": [], "ignorePaths": [ + "**/*.snap", "**/.gitignore", ".cspell.json", ".env*", diff --git a/.dictionary.txt b/.dictionary.txt index 74d0d47..a266780 100644 --- a/.dictionary.txt +++ b/.dictionary.txt @@ -17,9 +17,11 @@ esbenp esbuild fbca fpnv +frec gifv gpgsign iife +jsxdev lcov lintstagedrc micnncim @@ -32,9 +34,11 @@ nums nvmrc ohmyzsh pdel +picomatch rcmdnk safecrlf syncer +telejson tsnode tspaths vates diff --git a/.eslintignore b/.eslintignore index be3c9b5..30820c3 100644 --- a/.eslintignore +++ b/.eslintignore @@ -3,6 +3,7 @@ # DIRECTORIES & FILES **/.DS_Store +**/*.snap .eslintcache .yarn/* CHANGELOG.md diff --git a/.eslintrc.base.cjs b/.eslintrc.base.cjs index 3b48ab7..2184b52 100644 --- a/.eslintrc.base.cjs +++ b/.eslintrc.base.cjs @@ -53,11 +53,24 @@ const config = { node: true }, extends: ['eslint:recommended', 'plugin:@typescript-eslint/recommended'], - globals: {}, + globals: { + Chai: 'readonly', + Console: 'readonly', + JSX: 'readonly', + LoadHook: 'readonly', + LoadHookContext: 'readonly', + LoadHookResult: 'readonly', + LoaderHookFormat: 'readonly', + NodeJS: 'readonly', + ResolveFilename: 'readonly', + ResolveHook: 'readonly', + ResolveHookContext: 'readonly', + ResolveHookResult: 'readonly' + }, parser: require.resolve('@typescript-eslint/parser'), parserOptions: { ecmaFeatures: { - jsx: Boolean(tsconfig.compilerOptions.jsx ?? false), + jsx: Boolean(tsconfig.compilerOptions.jsx), impliedStrict: true }, emitDecoratorMetadata: tsconfig.compilerOptions.emitDecoratorMetadata, @@ -518,7 +531,7 @@ const config = { 'jsdoc/check-tag-names': [ 1, { - definedTags: ['fixme', 'link', 'maximum', 'minimum'], + definedTags: ['visibleName'], jsxTags: true } ], @@ -543,27 +556,7 @@ const config = { ], 'jsdoc/no-restricted-syntax': 0, 'jsdoc/no-types': 0, - 'jsdoc/no-undefined-types': [ - 1, - { - definedTypes: [ - 'Chai', - 'Console', - 'JSX', - 'LoadHook', - 'LoadHookContext', - 'LoadHookResult', - 'LoaderHookFormat', - 'NodeJS', - 'ResolveFilename', - 'ResolveHook', - 'ResolveHookContext', - 'ResolveHookResult', - 'never', - 'unknown' - ] - } - ], + 'jsdoc/no-undefined-types': [1, { definedTypes: ['never', 'unknown'] }], 'jsdoc/require-asterisk-prefix': [1, 'always'], 'jsdoc/require-description-complete-sentence': 0, 'jsdoc/require-description': [ @@ -908,6 +901,7 @@ const config = { '@typescript-eslint/no-base-to-string': 0, '@typescript-eslint/no-unused-expressions': 0, '@typescript-eslint/restrict-template-expressions': 0, + '@typescript-eslint/unbound-method': 0, 'chai-expect/missing-assertion': 2, 'chai-expect/no-inner-compare': 2, 'chai-expect/no-inner-literal': 2, @@ -1233,10 +1227,17 @@ const config = { name: 'namepath-defining', required: ['type'] }, + type: { + name: 'namepath-defining', + required: ['type'] + }, var: { name: 'namepath-defining', required: ['name'] }, + visibleName: { + required: ['name'] + }, yield: { name: 'namepath-defining', required: ['type'] diff --git a/.eslintrc.cjs b/.eslintrc.cjs index b59f458..bb327ca 100644 --- a/.eslintrc.cjs +++ b/.eslintrc.cjs @@ -15,6 +15,12 @@ const config = { extends: ['./.eslintrc.base.cjs', './.eslintrc.react.cjs'], overrides: [ ...base.overrides, + { + files: ['__fixtures__/**'], + rules: { + 'unicorn/filename-case': 0 + } + }, { files: ['build.config.ts'], rules: { diff --git a/.github/dependabot.yml b/.github/dependabot.yml index 1ea7bcf..b397e39 100644 --- a/.github/dependabot.yml +++ b/.github/dependabot.yml @@ -20,7 +20,6 @@ updates: separator: '-' rebase-strategy: auto target-branch: next - versioning-strategy: increase - package-ecosystem: npm directory: / schedule: @@ -29,7 +28,10 @@ updates: prefix: build include: scope ignore: + - dependency-name: '@storybook/react' - dependency-name: '@types/node' + - dependency-name: '@types/styled-components' + - dependency-name: styled-components labels: - type:build open-pull-requests-limit: 5 diff --git a/.husky/pre-push b/.husky/pre-push index f4dc472..e812c49 100755 --- a/.husky/pre-push +++ b/.husky/pre-push @@ -6,4 +6,4 @@ # # - https://vitest.dev/guide/cli.html#changed -yarn test --changed +yarn test --changed HEAD^ diff --git a/.prettierignore b/.prettierignore index 9cedb0a..2982beb 100644 --- a/.prettierignore +++ b/.prettierignore @@ -4,6 +4,7 @@ # DIRECTORIES & FILES **/.gitignore **/.gitkeep +**/*.snap .eslintcache .eslintignore .husky/_/* diff --git a/.vscode/settings.json b/.vscode/settings.json index 805d95d..9f7b503 100644 --- a/.vscode/settings.json +++ b/.vscode/settings.json @@ -5,6 +5,12 @@ "[javascript]": { "editor.defaultFormatter": "esbenp.prettier-vscode" }, + "[jest-snapshot]": { + "editor.rulers": [120], + "editor.wordWrap": "wordWrapColumn", + "editor.wordWrapColumn": 120, + "rewrap.wrappingColumn": 120 + }, "[json]": { "editor.defaultFormatter": "esbenp.prettier-vscode" }, @@ -39,6 +45,7 @@ "typescriptreact" ], "files.associations": { + "*.snap": "jest-snapshot", ".env.zsh": "shellscript", ".markdownlintignore": "ignore", "commit-msg": "shellscript", @@ -79,6 +86,11 @@ "format": "svg", "icon": "tsconfig" }, + { + "extensions": ["snap"], + "format": "svg", + "icon": "vitest" + }, { "extensions": ["yarnrc.yml"], "format": "svg", @@ -91,6 +103,11 @@ "format": "svg", "icon": "data" }, + { + "extensions": ["__snapshots__"], + "format": "svg", + "icon": "temp" + }, { "extensions": ["setup"], "format": "svg", diff --git a/README.md b/README.md index 18841e9..698976a 100644 --- a/README.md +++ b/README.md @@ -49,15 +49,15 @@ npmScopes: ## Built With -- [magic-string][1] -- [micromatch][2] +- [@rollup/pluginutils][1] +- [magic-string][2] - [react-docgen-typescript][3] -- [ts-dedent][4] +- [telejson][4] -[1]: https://github.com/Rich-Harris/magic-string -[2]: https://github.com/micromatch/micromatch +[1]: https://github.com/rollup/plugins/tree/master/packages/pluginutils +[2]: https://github.com/Rich-Harris/magic-string [3]: https://github.com/styleguidist/react-docgen-typescript -[4]: https://github.com/tamino-martinius/node-ts-dedent +[4]: https://github.com/storybookjs/telejson [5]: https://vitejs.dev [6]: https://docs.github.com/en/packages/learn-github-packages/about-permissions-for-github-packages#about-scopes-and-permissions-for-package-registries diff --git a/__fixtures__/.gitkeep b/__fixtures__/.gitkeep deleted file mode 100644 index e69de29..0000000 diff --git a/__fixtures__/Button.stories.tsx b/__fixtures__/Button.stories.tsx new file mode 100644 index 0000000..128fc1c --- /dev/null +++ b/__fixtures__/Button.stories.tsx @@ -0,0 +1,20 @@ +/** + * @file Fixtures - Button Stories + * @module fixtures/Button.stories + */ + +import type { Meta, Story } from '@storybook/react' +import Button, { CounterButton, type CounterButtonProps } from './Button' + +export default { + args: Button.defaultProps, + component: Button, + parameters: {}, + title: 'Button' +} as Meta + +export const Counter: Story = ( + args: CounterButtonProps +) => { + return +} diff --git a/__fixtures__/Button.tsx b/__fixtures__/Button.tsx new file mode 100644 index 0000000..1c9cc54 --- /dev/null +++ b/__fixtures__/Button.tsx @@ -0,0 +1,113 @@ +/** + * @file Fixtures - Button + * @module fixtures/Button + */ + +import { + forwardRef, + useState, + type ButtonHTMLAttributes, + type ForwardedRef +} from 'react' +import s, { css } from 'styled-components' + +interface ButtonProps extends ButtonHTMLAttributes { + /** + * Button background color. + * + * @default 'black' + */ + $bg?: ButtonHTMLAttributes['color'] + + /** + * Button text color. + * + * @default 'white' + */ + $color?: ButtonHTMLAttributes['color'] + + /** + * Button font size. + * + * @default '1.25rem' + */ + $fontsize?: number | string + + /** + * Mark button as disabled. + */ + disabled?: boolean +} + +interface CounterButtonProps extends ButtonProps { + /** + * Initial click count. + * + * @default 0 + */ + count?: number +} + +/** + * Renders an HTML ` + ) +}) + +CounterButton.displayName = 'CounterButton' +CounterButton.defaultProps = {} + +export { + Button as default, + CounterButton, + type ButtonProps, + type CounterButtonProps +} diff --git a/__fixtures__/Counter.tsx b/__fixtures__/Counter.tsx new file mode 100644 index 0000000..f8db99a --- /dev/null +++ b/__fixtures__/Counter.tsx @@ -0,0 +1,61 @@ +/** + * @file Fixtures - Counter + * @module fixtures/Counter + */ + +import { useState, type FC } from 'react' + +/** + * Renders a basic counter. + * + * @see https://dev.to/estheragbaje/how-to-use-react-hooks-to-create-a-counter-component-1bmp + * + * @return {JSX.Element} JSX element + */ +function Counter(): JSX.Element { + const [count, setcount] = useState(0) + + /** + * Decreases {@link count}. + * + * @return {void} Nothing when complete + */ + const decrement = (): void => setcount(prev => prev - 1) + + /** + * Increases {@link count}. + * + * @return {void} Nothing when complete + */ + const increment = (): void => setcount(prev => prev + 1) + + return ( +
+

+ Count is {count} +

+
+ + + +
+
+ ) +} + +export default Counter as FC diff --git a/__fixtures__/List.tsx b/__fixtures__/List.tsx new file mode 100644 index 0000000..b25319d --- /dev/null +++ b/__fixtures__/List.tsx @@ -0,0 +1,59 @@ +/** + * @file Fixtures - List + * @module fixtures/List + */ + +import type { LiHTMLAttributes, OlHTMLAttributes, Ref } from 'react' +import s, { css } from 'styled-components' + +interface ListProps< + T extends HTMLOListElement | HTMLUListElement = + | HTMLOListElement + | HTMLUListElement +> extends OlHTMLAttributes { + /** + * List items to render. + * + * @default [] + */ + $items?: LiHTMLAttributes[] + + /** + * Type of list to render. + * + * @default 'ul' + */ + as?: 'ol' | 'ul' + + /** + * Reference to inner list element. + */ + ref?: Ref +} + +/** + * Renders an HTML `
    ` or `
      ` element. + * + * Pass `props.as` to change the list type. + * + * @see https://developer.mozilla.org/docs/Web/HTML/Element/ol + * @see https://developer.mozilla.org/docs/Web/HTML/Element/ul + * @see https://developer.mozilla.org/docs/Web/API/HTMLOListElement + * @see https://developer.mozilla.org/docs/Web/API/HTMLUListElement + */ +const List = s.ul.attrs(p => ({ + 'aria-hidden': p.hidden ?? undefined, + children: (() => { + if (!p.$items || p.$items.length === 0) return p.children + return p.$items.map((item, i) =>
    • ) + })() +}))(() => css``) + +List.displayName = 'List' +List.defaultProps = { + $items: [], + as: 'ul' +} + +export default List +export { type ListProps } diff --git a/__fixtures__/empty.tsx b/__fixtures__/empty.tsx new file mode 100644 index 0000000..189cf90 --- /dev/null +++ b/__fixtures__/empty.tsx @@ -0,0 +1,6 @@ +/** + * @file Fixtures - Empty File + * @module fixtures/empty + */ + +export {} diff --git a/__fixtures__/transform-plugin-context.ts b/__fixtures__/transform-plugin-context.ts new file mode 100644 index 0000000..bb36d61 --- /dev/null +++ b/__fixtures__/transform-plugin-context.ts @@ -0,0 +1,54 @@ +/** + * @file Fixtures - TransformPluginContext + * @module fixtures/TransformPluginContext + */ + +import type { TransformPluginContext } from 'rollup' +import { VERSION as rollupVersion } from 'rollup' + +/** + * Mock transform plugin context. + * + * @const {TransformPluginContext} context + */ +const context: TransformPluginContext = { + addWatchFile: vi.fn(), + cache: { + delete: vi.fn().mockReturnValue(true), + get: vi.fn(), + has: vi.fn().mockReturnValue([false, true][Math.floor(Math.random() * 2)]), + set: vi.fn() + }, + emitAsset: vi.fn(), + emitChunk: vi.fn(), + emitFile: vi.fn(), + error: vi.fn(), + getAssetFileName: vi.fn(), + getChunkFileName: vi.fn(), + getCombinedSourcemap: vi.fn(), + getFileName: vi.fn(), + getModuleIds: vi.fn().mockReturnValue( + (function* ids(): IterableIterator { + yield faker.datatype.uuid() + yield faker.datatype.uuid() + yield faker.datatype.uuid() + })() + ), + getModuleInfo: vi.fn(), + getWatchFiles: vi.fn().mockReturnValue([]), + isExternal: vi.fn(), + load: vi.fn(), + meta: { rollupVersion, watchMode: false }, + moduleIds: (function* ids(): IterableIterator { + yield faker.datatype.uuid() + yield faker.datatype.uuid() + yield faker.datatype.uuid() + })(), + parse: vi.fn(), + resolve: vi.fn().mockResolvedValue(null), + resolveId: vi.fn().mockResolvedValue(null), + setAssetSource: vi.fn(), + warn: vi.fn() +} + +export default context diff --git a/build.config.ts b/build.config.ts index 9b3a27a..ffa1a13 100644 --- a/build.config.ts +++ b/build.config.ts @@ -4,6 +4,7 @@ * @see https://github.com/unjs/unbuild#configuration */ +import type { MkdistOptions } from 'mkdist' import path from 'node:path' import { applyChanges } from 'resolve-tspaths/dist/steps/applyChanges' import { computeAliases } from 'resolve-tspaths/dist/steps/computeAliases' @@ -15,7 +16,8 @@ import { defineBuildConfig, type BuildConfig, type BuildContext, - type BuildOptions + type BuildOptions, + type MkdistBuildEntry } from 'unbuild' /** @const {BuildConfig} config - Build config */ @@ -71,6 +73,19 @@ const config: BuildConfig = defineBuildConfig({ } catch (e: unknown) { console.error(e instanceof Error ? e.message : e) } + }, + /** + * Updates `mkdist` build options. + * + * @see https://github.com/unjs/mkdist#-usage + * + * @param {BuildContext} _ - Build context + * @param {MkdistBuildEntry} __ - `mkdist` build entry + * @param {MkdistOptions} options - `mkdist` build options + * @return {void} Nothing when complete + */ + 'mkdist:entry:options'(_, __, options: MkdistOptions): void { + options.pattern = '*' } } }) diff --git a/loader.mjs b/loader.mjs index bc8b0b8..a458b55 100644 --- a/loader.mjs +++ b/loader.mjs @@ -26,7 +26,7 @@ const hooks = createEsmHooks(register()) * * @param {string} url - `file:` url of module * @param {LoadHookContext} context - Hook context - * @param {(LoaderHookFormat | null)?} [context.format] - Module format + * @param {?LoaderHookFormat} [context.format] - Module format * @param {ImportAssertions} context.importAssertions - Import assertions map * @param {LoadHook} defaultLoad - Default Node.js `load` function * @return {Promise} Hook result diff --git a/package.json b/package.json index b39af27..dbd4bbc 100644 --- a/package.json +++ b/package.json @@ -29,7 +29,7 @@ "type": "module", "files": [ "dist", - "src", + "src/*", "CHANGELOG.md" ], "exports": { @@ -60,7 +60,7 @@ "types": "./dist/index.d.ts", "scripts": { "build": "unbuild", - "check:ci": "yarn fix:cg && yarn check:spelling && yarn check:types && yarn test && NODE_ENV=production yarn pack -o %s-%v.tgz", + "check:ci": "yarn fix:cg && yarn check:spelling && yarn check:types && yarn test && NODE_ENV=production yarn pack -o %s-%v.tgz && yarn clean:pack", "check:dedupe": "yarn dedupe --check", "check:format": "prettier --check .", "check:lint": "eslint --cache --exit-on-fatal-error --ext cjs,json,md,mjs,ts,tsx,yml --max-warnings 0 .", @@ -69,6 +69,7 @@ "check:upgrades": "yarn upgrade-interactive", "clean:build": "trash ./{dist,*.tgz}", "clean:modules": "trash ./.yarn/{cache,*.gz} ./node_modules", + "clean:pack": "trash ./*.tgz", "clean:test": "trash ./coverage", "fix:cg": "yarn fix:format && yarn fix:lint", "fix:dedupe": "yarn dedupe --strategy=highest", @@ -85,11 +86,10 @@ "test:watch": "vitest" }, "dependencies": { - "@types/micromatch": "4.0.2", + "@rollup/pluginutils": "4.2.1", "magic-string": "0.26.2", - "micromatch": "4.0.5", "react-docgen-typescript": "2.2.2", - "ts-dedent": "2.2.0" + "telejson": "6.0.8" }, "devDependencies": { "@commitlint/cli": "17.0.3", @@ -97,19 +97,21 @@ "@commitlint/types": "17.0.0", "@faker-js/faker": "7.3.0", "@flex-development/tutils": "4.8.0", + "@storybook/react": "6.5.9", "@types/chai": "4.3.1", "@types/eslint": "8.4.5", "@types/is-ci": "3.0.0", - "@types/micromatch": "4.0.2", "@types/mvdan-sh": "0.5.1", "@types/node": "16.11.45", "@types/node-notifier": "8.0.2", "@types/prettier": "2.6.3", "@types/react": "18.0.15", + "@types/styled-components": "5.1.25", "@typescript-eslint/eslint-plugin": "5.31.0", "@typescript-eslint/parser": "5.31.0", "@vates/toggle-scripts": "1.0.0", "@vitest/ui": "0.19.1", + "c8": "7.12.0", "chai": "4.3.6", "cspell": "6.4.1", "eslint": "8.20.0", @@ -137,7 +139,9 @@ "pretty-format": "28.1.3", "react": "18.2.0", "resolve-tspaths": "0.7.1", + "styled-components": "5.3.5", "trash-cli": "5.0.0", + "ts-dedent": "2.2.0", "ts-node": "10.9.1", "tsconfig": "7.0.0", "tsconfig-paths": "4.0.0", @@ -145,7 +149,6 @@ "vite": "3.0.3", "vite-plugin-inspect": "0.6.0", "vite-tsconfig-paths": "3.5.0", - "viteshot": "0.3.1", "vitest": "0.19.1", "vitest-github-actions-reporter": "0.8.1", "yaml-eslint-parser": "1.0.1" @@ -154,10 +157,9 @@ "vite": ">=2.0.0" }, "resolutions": { - "c8": "7.12.0", - "consola": "2.15.3", + "@types/picomatch": "2.3.0", "mkdist": "patch:mkdist@npm:0.3.13#.yarn/patches/mkdist-npm-0.3.13-c41cf41c68.patch", - "simple-git": "3.10.0", + "picomatch": "2.3.1", "typescript": "4.8.0-beta" }, "engines": { diff --git a/src/__snapshots__/plugin.functional.snap b/src/__snapshots__/plugin.functional.snap new file mode 100644 index 0000000..dca5978 --- /dev/null +++ b/src/__snapshots__/plugin.functional.snap @@ -0,0 +1,126 @@ +// Vitest Snapshot v1 + +exports[`functional:plugin > should not transform module if docgen info is missing 1`] = `null`; + +exports[`functional:plugin > should not transform module if id does not match include pattern 1`] = `undefined`; + +exports[`functional:plugin > should not transform module if id matches exclude pattern 1`] = `undefined`; + +exports[`functional:plugin > should transform module if id matches include pattern 1`] = ` +"/** + * @file Fixtures - Button + * @module fixtures/Button + */ + +import { + forwardRef, + useState, + type ButtonHTMLAttributes, + type ForwardedRef +} from 'react' +import s, { css } from 'styled-components' + +interface ButtonProps extends ButtonHTMLAttributes { + /** + * Button background color. + * + * @default 'black' + */ + $bg?: ButtonHTMLAttributes['color'] + + /** + * Button text color. + * + * @default 'white' + */ + $color?: ButtonHTMLAttributes['color'] + + /** + * Button font size. + * + * @default '1.25rem' + */ + $fontsize?: number | string + + /** + * Mark button as disabled. + */ + disabled?: boolean +} + +interface CounterButtonProps extends ButtonProps { + /** + * Initial click count. + * + * @default 0 + */ + count?: number +} + +/** + * Renders an HTML \` + ) +}) + +CounterButton.displayName = 'CounterButton' +CounterButton.defaultProps = {} + +export { + Button as default, + CounterButton, + type ButtonProps, + type CounterButtonProps +} + +;Button.__docgenInfo={\\"tags\\":{\\"see\\":\\"https://developer.mozilla.org/docs/Web/HTML/Element/button\\\\nhttps://developer.mozilla.org/docs/Web/API/HTMLButtonElement\\",\\"visibleName\\":\\"Button\\"},\\"filePath\\":\\"\\",\\"description\\":\\"Renders an HTML \`