From c17b71ddad02a54a7121f67d1f2149989640b36c Mon Sep 17 00:00:00 2001 From: Remco Haszing Date: Fri, 28 Jun 2024 14:23:21 +0200 Subject: [PATCH 1/3] Leverage TypeScript project references --- .gitignore | 3 ++- index.js | 9 --------- lib/exports.ts | 9 +++++++++ lib/index.js | 2 +- package.json | 8 +++++--- tsconfig.base.json | 10 ++++++++++ tsconfig.build.json | 14 ++++++++++++++ tsconfig.json | 17 ++++++----------- 8 files changed, 47 insertions(+), 25 deletions(-) delete mode 100644 index.js create mode 100644 lib/exports.ts create mode 100644 tsconfig.base.json create mode 100644 tsconfig.build.json diff --git a/.gitignore b/.gitignore index fdbc06a8..fc13b3d5 100644 --- a/.gitignore +++ b/.gitignore @@ -1,6 +1,7 @@ coverage/ node_modules/ -*.d.ts +types/ +*.tsbuildinfo *.log .DS_Store react-markdown.min.js diff --git a/index.js b/index.js deleted file mode 100644 index ff903ce0..00000000 --- a/index.js +++ /dev/null @@ -1,9 +0,0 @@ -/** - * @typedef {import('hast-util-to-jsx-runtime').ExtraProps} ExtraProps - * @typedef {import('./lib/index.js').AllowElement} AllowElement - * @typedef {import('./lib/index.js').Components} Components - * @typedef {import('./lib/index.js').Options} Options - * @typedef {import('./lib/index.js').UrlTransform} UrlTransform - */ - -export {Markdown as default, defaultUrlTransform} from './lib/index.js' diff --git a/lib/exports.ts b/lib/exports.ts new file mode 100644 index 00000000..c31eb91b --- /dev/null +++ b/lib/exports.ts @@ -0,0 +1,9 @@ +export type {ExtraProps} from 'hast-util-to-jsx-runtime' +export { + type AllowElement, + type Components, + type Options, + type UrlTransform, + defaultUrlTransform, + default +} from './index.js' diff --git a/lib/index.js b/lib/index.js index 98a62e29..188d36f2 100644 --- a/lib/index.js +++ b/lib/index.js @@ -138,7 +138,7 @@ const deprecations = [ * @returns {ReactElement} * React element. */ -export function Markdown(options) { +export default function Markdown(options) { const allowedElements = options.allowedElements const allowElement = options.allowElement const children = options.children || '' diff --git a/package.json b/package.json index dc1b8b9f..4e29f52f 100644 --- a/package.json +++ b/package.json @@ -69,11 +69,13 @@ ], "sideEffects": false, "type": "module", - "exports": "./index.js", + "exports": { + "types": "./types/exports.d.ts", + "default": "./lib/index.js" + }, "files": [ "lib/", - "index.d.ts", - "index.js" + "types/" ], "dependencies": { "@types/hast": "^3.0.0", diff --git a/tsconfig.base.json b/tsconfig.base.json new file mode 100644 index 00000000..f10b87c8 --- /dev/null +++ b/tsconfig.base.json @@ -0,0 +1,10 @@ +{ + "compilerOptions": { + "checkJs": true, + "customConditions": ["development"], + "exactOptionalPropertyTypes": true, + "module": "node16", + "strict": true, + "target": "es2022" + } +} diff --git a/tsconfig.build.json b/tsconfig.build.json new file mode 100644 index 00000000..78a5cc57 --- /dev/null +++ b/tsconfig.build.json @@ -0,0 +1,14 @@ +{ + "extends": "./tsconfig.base.json", + "compilerOptions": { + "composite": true, + "declaration": true, + "emitDeclarationOnly": true, + "lib": ["dom", "es2022"], + "outDir": "types/", + "rootDir": "lib/", + "target": "es2022", + "types": [] + }, + "include": ["lib/"] +} diff --git a/tsconfig.json b/tsconfig.json index 0fe0d02d..921b271e 100644 --- a/tsconfig.json +++ b/tsconfig.json @@ -1,16 +1,11 @@ { + "extends": "./tsconfig.base.json", "compilerOptions": { - "checkJs": true, - "customConditions": ["development"], - "declaration": true, - "emitDeclarationOnly": true, - "exactOptionalPropertyTypes": true, "jsx": "preserve", - "lib": ["dom", "es2022"], - "module": "node16", - "strict": true, - "target": "es2022" + "lib": ["es2022"], + "noEmit": true, + "types": ["node"] }, - "exclude": ["coverage/", "node_modules/"], - "include": ["**/*.js", "**/*.jsx", "lib/complex-types.d.ts"] + "exclude": ["coverage/", "lib/", "node_modules/"], + "references": [{"path": "./tsconfig.build.json"}] } From f8004c0a591caf99f1fb94e34f820a0dddee7934 Mon Sep 17 00:00:00 2001 From: Remco Haszing Date: Fri, 20 Dec 2024 15:36:58 +0100 Subject: [PATCH 2/3] Update .gitignore Co-authored-by: Titus Signed-off-by: Remco Haszing --- .gitignore | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.gitignore b/.gitignore index fc13b3d5..3fedeead 100644 --- a/.gitignore +++ b/.gitignore @@ -1,8 +1,8 @@ coverage/ node_modules/ types/ -*.tsbuildinfo *.log +*.tsbuildinfo .DS_Store react-markdown.min.js yarn.lock From d7c69237d53ea75f664e42f5d2ba52d273befda3 Mon Sep 17 00:00:00 2001 From: Remco Haszing Date: Fri, 20 Dec 2024 15:37:22 +0100 Subject: [PATCH 3/3] Re-enable declaration maps --- tsconfig.build.json | 1 + 1 file changed, 1 insertion(+) diff --git a/tsconfig.build.json b/tsconfig.build.json index 78a5cc57..05d9bb54 100644 --- a/tsconfig.build.json +++ b/tsconfig.build.json @@ -3,6 +3,7 @@ "compilerOptions": { "composite": true, "declaration": true, + "declarationMap": true, "emitDeclarationOnly": true, "lib": ["dom", "es2022"], "outDir": "types/",