From 407bced824d1af1b8c6268e91939bad6180005bc Mon Sep 17 00:00:00 2001 From: Tom Mrazauskas Date: Sun, 12 Nov 2023 20:23:55 +0200 Subject: [PATCH 1/4] feat: add type definitions files --- .github/workflows/checks.yml | 12 ++++++++++++ index.d.ts | 24 ++++++++++++++++++++++++ package.json | 11 ++++++++--- tsconfig.json | 26 ++++++++++++++++++++++++++ typetests/index.tst.ts | 20 ++++++++++++++++++++ yarn.lock | 36 ++++++++++++++++++++++++++++++++++++ 6 files changed, 126 insertions(+), 3 deletions(-) create mode 100644 index.d.ts create mode 100644 tsconfig.json create mode 100644 typetests/index.tst.ts diff --git a/.github/workflows/checks.yml b/.github/workflows/checks.yml index 3575404..e4ea1bb 100644 --- a/.github/workflows/checks.yml +++ b/.github/workflows/checks.yml @@ -23,6 +23,18 @@ jobs: - run: yarn lint:eslint - run: yarn lint:prettier --no-write --check + test-types: + name: Test Types + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@b4ffde65f46336ab88eb53be808477a3936bae11 # v4 + - uses: actions/setup-node@8f152de45cc393bb48ce5d89d36b731f54556e65 # v4 + with: + node-version: lts/* + - run: corepack enable + - run: yarn install + - run: yarn test:types + test-node: name: Test on Node.js v${{ matrix.node-version }} strategy: diff --git a/index.d.ts b/index.d.ts new file mode 100644 index 0000000..54e3254 --- /dev/null +++ b/index.d.ts @@ -0,0 +1,24 @@ +export interface Options { + /** + * The {@link https://docusaurus.io/docs/markdown-features/tabs#syncing-tab-choices | `groupId`} + * property for all instances of `Tabs` component created by this plugin. + */ + groupId?: string; + /** + * List with tuples with code block language attribute and tab label text. + */ + labels?: Array<[string, string]>; + /** + * Whether tab choices should be {@link https://docusaurus.io/docs/markdown-features/tabs#syncing-tab-choices | synced} + * between all tabs created by this plugin. + */ + sync?: boolean; +} + +/** + * Turns Docusaurus {@link https://docusaurus.io/docs/next/markdown-features/code-blocks | code blocks} + * into {@link https://docusaurus.io/docs/next/markdown-features/tabs | tabs}. + */ +declare function tabBlocks(options?: Options): void; + +export default tabBlocks; diff --git a/package.json b/package.json index 316ac43..d717018 100644 --- a/package.json +++ b/package.json @@ -20,7 +20,9 @@ }, "license": "MIT", "type": "module", - "main": "index.js", + "exports": { + ".": "./index.js" + }, "files": [ "index.js" ], @@ -28,7 +30,8 @@ "lint": "yarn lint:eslint && yarn lint:prettier", "lint:eslint": "eslint . --ext js", "lint:prettier": "prettier . --no-config --write", - "test": "NODE_OPTIONS='--experimental-vm-modules --no-warnings' jest" + "test": "NODE_OPTIONS='--experimental-vm-modules --no-warnings' jest", + "test:types": "tstyche" }, "dependencies": { "unist-util-is": "^6.0.0", @@ -41,7 +44,9 @@ "jest": "29.7.0", "prettier": "3.0.3", "remark": "15.0.1", - "remark-mdx": "3.0.0" + "remark-mdx": "3.0.0", + "tstyche": "1.0.0-beta.2", + "typescript": "5.2.2" }, "packageManager": "yarn@4.0.1", "engines": { diff --git a/tsconfig.json b/tsconfig.json new file mode 100644 index 0000000..d36e5ae --- /dev/null +++ b/tsconfig.json @@ -0,0 +1,26 @@ +{ + "compilerOptions": { + "target": "es2022", + "module": "node16", + "moduleResolution": "node16", + + "allowJs": true, + "checkJs": true, + + "noEmit": true, + + "esModuleInterop": true, + "forceConsistentCasingInFileNames": true, + + "strict": true, + "allowUnreachableCode": false, + "exactOptionalPropertyTypes": true, + "noImplicitReturns": true, + "noPropertyAccessFromIndexSignature": true, + "noUncheckedIndexedAccess": true, + "noUnusedLocals": true, + "noUnusedParameters": true, + + "skipLibCheck": true + } +} diff --git a/typetests/index.tst.ts b/typetests/index.tst.ts new file mode 100644 index 0000000..9412666 --- /dev/null +++ b/typetests/index.tst.ts @@ -0,0 +1,20 @@ +import { expect, test } from "tstyche"; +import tabBlocks, { type Options } from "docusaurus-remark-plugin-tab-blocks"; + +const options: Options = {}; + +test("tabBlocks()", () => { + expect(tabBlocks()).type.toBeVoid(); + expect(tabBlocks(options)).type.toBeVoid(); +}); + +test("Options", () => { + expect(options).type.toBeAssignable({ groupId: "code-examples" }); + expect(options).type.toBeAssignable({ + labels: [ + ["js", "JavaScript"] as [string, string], + ["ts", "TypeScript"] as [string, string], + ], + }); + expect(options).type.toBeAssignable({ sync: true }); +}); diff --git a/yarn.lock b/yarn.lock index 766cb7a..4a6c152 100644 --- a/yarn.lock +++ b/yarn.lock @@ -1769,6 +1769,8 @@ __metadata: prettier: "npm:3.0.3" remark: "npm:15.0.1" remark-mdx: "npm:3.0.0" + tstyche: "npm:1.0.0-beta.2" + typescript: "npm:5.2.2" unist-util-is: "npm:^6.0.0" unist-util-visit: "npm:^5.0.0" languageName: unknown @@ -4812,6 +4814,20 @@ __metadata: languageName: node linkType: hard +"tstyche@npm:1.0.0-beta.2": + version: 1.0.0-beta.2 + resolution: "tstyche@npm:1.0.0-beta.2" + peerDependencies: + typescript: 4.x || 5.x + peerDependenciesMeta: + typescript: + optional: true + bin: + tstyche: build/bin.js + checksum: 3921b0fd009470fb32f07c8502f1a9fd12ef87edc514f295a40fe9c734d0a69c84e90568efac3a9f02da4f5441c2507ef1773b147702e1c527275c4a10f31efa + languageName: node + linkType: hard + "tsutils@npm:^3.21.0": version: 3.21.0 resolution: "tsutils@npm:3.21.0" @@ -4853,6 +4869,26 @@ __metadata: languageName: node linkType: hard +"typescript@npm:5.2.2": + version: 5.2.2 + resolution: "typescript@npm:5.2.2" + bin: + tsc: bin/tsc + tsserver: bin/tsserver + checksum: 91ae3e6193d0ddb8656d4c418a033f0f75dec5e077ebbc2bd6d76439b93f35683936ee1bdc0e9cf94ec76863aa49f27159b5788219b50e1cd0cd6d110aa34b07 + languageName: node + linkType: hard + +"typescript@patch:typescript@npm%3A5.2.2#optional!builtin": + version: 5.2.2 + resolution: "typescript@patch:typescript@npm%3A5.2.2#optional!builtin::version=5.2.2&hash=f3b441" + bin: + tsc: bin/tsc + tsserver: bin/tsserver + checksum: 062c1cee1990e6b9419ce8a55162b8dc917eb87f807e4de0327dbc1c2fa4e5f61bc0dd4e034d38ff541d1ed0479b53bcee8e4de3a4075c51a1724eb6216cb6f5 + languageName: node + linkType: hard + "undici-types@npm:~5.26.4": version: 5.26.5 resolution: "undici-types@npm:5.26.5" From 1eca3320b97153c2212ca406540a4792c17dc2a3 Mon Sep 17 00:00:00 2001 From: Tom Mrazauskas Date: Sun, 12 Nov 2023 20:31:40 +0200 Subject: [PATCH 2/4] target TS 4.8 and 5.0 --- .github/workflows/checks.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/checks.yml b/.github/workflows/checks.yml index e4ea1bb..569303f 100644 --- a/.github/workflows/checks.yml +++ b/.github/workflows/checks.yml @@ -33,7 +33,7 @@ jobs: node-version: lts/* - run: corepack enable - run: yarn install - - run: yarn test:types + - run: yarn test:types --target 4.8,5.0,latest test-node: name: Test on Node.js v${{ matrix.node-version }} From 09ed60c3fecdfaf758f652be931ec8154dba635e Mon Sep 17 00:00:00 2001 From: Tom Mrazauskas Date: Sun, 12 Nov 2023 20:33:45 +0200 Subject: [PATCH 3/4] do not check JS for now --- tsconfig.json | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/tsconfig.json b/tsconfig.json index d36e5ae..d519b76 100644 --- a/tsconfig.json +++ b/tsconfig.json @@ -4,8 +4,8 @@ "module": "node16", "moduleResolution": "node16", - "allowJs": true, - "checkJs": true, + // "allowJs": true, + // "checkJs": true, "noEmit": true, From 7ebc52ea3c2ac4d3047af334262a35320b8b67c2 Mon Sep 17 00:00:00 2001 From: Tom Mrazauskas Date: Mon, 13 Nov 2023 20:13:16 +0200 Subject: [PATCH 4/4] bump 'tstyche' --- package.json | 2 +- yarn.lock | 10 +++++----- 2 files changed, 6 insertions(+), 6 deletions(-) diff --git a/package.json b/package.json index d717018..1efbf6d 100644 --- a/package.json +++ b/package.json @@ -45,7 +45,7 @@ "prettier": "3.0.3", "remark": "15.0.1", "remark-mdx": "3.0.0", - "tstyche": "1.0.0-beta.2", + "tstyche": "1.0.0-beta.3", "typescript": "5.2.2" }, "packageManager": "yarn@4.0.1", diff --git a/yarn.lock b/yarn.lock index 4a6c152..7c81c58 100644 --- a/yarn.lock +++ b/yarn.lock @@ -1769,7 +1769,7 @@ __metadata: prettier: "npm:3.0.3" remark: "npm:15.0.1" remark-mdx: "npm:3.0.0" - tstyche: "npm:1.0.0-beta.2" + tstyche: "npm:1.0.0-beta.3" typescript: "npm:5.2.2" unist-util-is: "npm:^6.0.0" unist-util-visit: "npm:^5.0.0" @@ -4814,9 +4814,9 @@ __metadata: languageName: node linkType: hard -"tstyche@npm:1.0.0-beta.2": - version: 1.0.0-beta.2 - resolution: "tstyche@npm:1.0.0-beta.2" +"tstyche@npm:1.0.0-beta.3": + version: 1.0.0-beta.3 + resolution: "tstyche@npm:1.0.0-beta.3" peerDependencies: typescript: 4.x || 5.x peerDependenciesMeta: @@ -4824,7 +4824,7 @@ __metadata: optional: true bin: tstyche: build/bin.js - checksum: 3921b0fd009470fb32f07c8502f1a9fd12ef87edc514f295a40fe9c734d0a69c84e90568efac3a9f02da4f5441c2507ef1773b147702e1c527275c4a10f31efa + checksum: 8db6acde30b8905c891c3854837340e7bbfee20e79e6eae2e674e1e966737f8c79079325c330b51b922f3157a3fcb26da0005032a45ade302f20b1d3e3ccfd37 languageName: node linkType: hard