From b2dd0467f1ab4fa4b99949ef72f0ea5258de232e Mon Sep 17 00:00:00 2001 From: Titus Wormer Date: Fri, 13 Aug 2021 08:20:34 +0200 Subject: [PATCH] Reorganize files --- index.js | 8 ++++++++ {src => lib}/ast-to-react.js | 0 {src => lib}/react-markdown.js | 0 {src => lib}/rehype-filter.js | 0 {src => lib}/uri-transformer.js | 0 package.json | 17 ++++++++++------- readme.md | 2 +- test/test.jsx | 15 ++++++++------- tsconfig.json | 2 +- 9 files changed, 28 insertions(+), 16 deletions(-) create mode 100644 index.js rename {src => lib}/ast-to-react.js (100%) rename {src => lib}/react-markdown.js (100%) rename {src => lib}/rehype-filter.js (100%) rename {src => lib}/uri-transformer.js (100%) diff --git a/index.js b/index.js new file mode 100644 index 00000000..fffdeccb --- /dev/null +++ b/index.js @@ -0,0 +1,8 @@ +'use strict' + +/** + * @typedef {import('./lib/react-markdown.js').ReactMarkdownOptions} Options + * @typedef {import('./lib/ast-to-react.js').Components} Components + */ + +module.exports = require('./lib/react-markdown.js') diff --git a/src/ast-to-react.js b/lib/ast-to-react.js similarity index 100% rename from src/ast-to-react.js rename to lib/ast-to-react.js diff --git a/src/react-markdown.js b/lib/react-markdown.js similarity index 100% rename from src/react-markdown.js rename to lib/react-markdown.js diff --git a/src/rehype-filter.js b/lib/rehype-filter.js similarity index 100% rename from src/rehype-filter.js rename to lib/rehype-filter.js diff --git a/src/uri-transformer.js b/lib/uri-transformer.js similarity index 100% rename from src/uri-transformer.js rename to lib/uri-transformer.js diff --git a/package.json b/package.json index 7088dd12..e0d16d47 100644 --- a/package.json +++ b/package.json @@ -67,11 +67,13 @@ "Dennis S ", "Evan Hensleigh " ], - "types": "src/react-markdown.d.ts", - "main": "src/react-markdown.js", + "types": "index.d.ts", + "main": "index.js", "unpkg": "react-markdown.min.js", "files": [ - "src/", + "lib/", + "index.d.ts", + "index.js", "react-markdown.min.js" ], "dependencies": { @@ -123,8 +125,8 @@ }, "scripts": { "prepack": "npm run build && npm run format", - "build:ts": "rimraf \"{src/**,test/**,}.d.ts\" && tsc && type-coverage", - "build:umd": "esbuild src/react-markdown.js --bundle --minify --target=es2015 --outfile=react-markdown.min.js --global-name=ReactMarkdown --banner:js=\"(function (g, f) {typeof exports === 'object' && typeof module !== 'undefined' ? module.exports = f() : typeof define === 'function' && define.amd ? define([], f) : (g = typeof globalThis !== 'undefined' ? globalThis : g || self, g.ReactMarkdown = f()); }(this, (function () { 'use strict';\" --footer:js=\"return ReactMarkdown;})));\"", + "build:ts": "rimraf \"{lib/**,test/**,*}.d.ts\" && tsc && type-coverage", + "build:umd": "esbuild index.js --bundle --minify --target=es2015 --outfile=react-markdown.min.js --global-name=ReactMarkdown --banner:js=\"(function (g, f) {typeof exports === 'object' && typeof module !== 'undefined' ? module.exports = f() : typeof define === 'function' && define.amd ? define([], f) : (g = typeof globalThis !== 'undefined' ? globalThis : g || self, g.ReactMarkdown = f()); }(this, (function () { 'use strict';\" --footer:js=\"return ReactMarkdown;})));\"", "build": "run-s build:*", "format": "remark . -qfo --ignore-pattern test/ && prettier . -w --loglevel warn && xo --fix", "test": "run-s build format test:coverage", @@ -158,7 +160,8 @@ "ignoreCatch": true, "#": "below is ignored because some proptypes will `any`", "ignoreFiles": [ - "src/react-markdown.d.ts" + "lib/react-markdown.d.ts", + "index.d.ts" ] }, "prettier": { @@ -179,7 +182,7 @@ "overrides": [ { "files": [ - "src/**/*.js" + "lib/**/*.js" ], "extends": [ "plugin:es/restrict-to-es2015", diff --git a/readme.md b/readme.md index 5f0edcbb..bf5d10d6 100644 --- a/readme.md +++ b/readme.md @@ -590,7 +590,7 @@ abide by its terms. [cm-html]: https://spec.commonmark.org/0.29/#html-blocks -[uri]: https://github.com/remarkjs/react-markdown/blob/main/src/uri-transformer.js +[uri]: https://github.com/remarkjs/react-markdown/blob/main/lib/uri-transformer.js [security]: #security diff --git a/test/test.jsx b/test/test.jsx index a3baa986..5a0124ae 100644 --- a/test/test.jsx +++ b/test/test.jsx @@ -7,7 +7,7 @@ const gfm = require('remark-gfm') const visit = require('unist-util-visit') const ReactDom = require('react-dom/server') const raw = require('rehype-raw') -const Markdown = require('../src/react-markdown.js') +const Markdown = require('../index.js') const toc = require('remark-toc') const own = {}.hasOwnProperty @@ -19,7 +19,7 @@ const own = {}.hasOwnProperty * @typedef {import('hast').Element} Element * @typedef {import('hast').Text} Text * @typedef {import('react').ReactNode} ReactNode - * @typedef {import('../src/ast-to-react').Components} Components + * @typedef {import('../index.js').Components} Components */ /** @@ -39,7 +39,7 @@ test('should warn when passed `source`', () => { /** @type {unknown} */ let message - console.warn = (d) => { + console.warn = (/** @type {unknown} */ d) => { message = d } @@ -59,7 +59,7 @@ test('should warn when passed non-string children (number)', () => { let message console.error = () => {} - console.warn = (d) => { + console.warn = (/** @type {unknown} */ d) => { message = d } @@ -80,7 +80,7 @@ test('should warn when passed non-string children (boolean)', () => { let message console.error = () => {} - console.warn = (d) => { + console.warn = (/** @type {unknown} */ d) => { message = d } @@ -110,7 +110,7 @@ test('should warn when passed `allowDangerousHtml`', () => { /** @type {unknown} */ let message - console.warn = (d) => { + console.warn = (/** @type {unknown} */ d) => { message = d } @@ -1067,6 +1067,7 @@ test('should pass index of a node under its parent to components if `includeElem * @param {object} props * @param {Element} props.node * @param {ReactNode[]} props.children + * @param {number} [props.index] */ const p = ({node, ...otherProps}) => { assert.equal(typeof otherProps.index === 'number', true) @@ -1082,7 +1083,7 @@ test('should pass index of a node under its parent to components if `includeElem test('should be able to render components with forwardRef in HOC', () => { /** * @typedef {import('react').Ref} Ref - * @typedef {JSX.IntrinsicElements['a'] & import('../src/ast-to-react').ReactMarkdownProps} Props + * @typedef {JSX.IntrinsicElements['a'] & import('../lib/ast-to-react').ReactMarkdownProps} Props */ /** diff --git a/tsconfig.json b/tsconfig.json index 8d08f2c3..ca4aa3e2 100644 --- a/tsconfig.json +++ b/tsconfig.json @@ -1,5 +1,5 @@ { - "include": ["*.js", "src/**.js", "test/**.js"], + "include": ["lib/**.js", "test/**.jsx", "index.js"], "exclude": ["**/*.min.js"], "compilerOptions": { "target": "ES2015",