From 45df6a3981dc151bd6c5e2cc7d17bf32cef1caa6 Mon Sep 17 00:00:00 2001 From: fanny Date: Sun, 20 Sep 2020 20:05:40 -0300 Subject: [PATCH 1/4] chore(v2): add dependency --- packages/docusaurus-mdx-loader/package.json | 1 + packages/docusaurus-mdx-loader/src/index.js | 3 +- .../src/remark/npm2yarn/index.js | 81 +++++++++++++++++++ 3 files changed, 84 insertions(+), 1 deletion(-) create mode 100644 packages/docusaurus-mdx-loader/src/remark/npm2yarn/index.js diff --git a/packages/docusaurus-mdx-loader/package.json b/packages/docusaurus-mdx-loader/package.json index 6a805e9a3d12..e2f22458f390 100644 --- a/packages/docusaurus-mdx-loader/package.json +++ b/packages/docusaurus-mdx-loader/package.json @@ -17,6 +17,7 @@ "@docusaurus/utils": "2.0.0-alpha.64", "@mdx-js/mdx": "^1.5.8", "@mdx-js/react": "^1.5.8", + "npm-to-yarn": "^1.0.0-2", "escape-html": "^1.0.3", "file-loader": "^6.0.0", "fs-extra": "^8.1.0", diff --git a/packages/docusaurus-mdx-loader/src/index.js b/packages/docusaurus-mdx-loader/src/index.js index 64a666bbd102..95a4da1b0a45 100644 --- a/packages/docusaurus-mdx-loader/src/index.js +++ b/packages/docusaurus-mdx-loader/src/index.js @@ -15,10 +15,11 @@ const slug = require('./remark/slug'); const rightToc = require('./remark/rightToc'); const transformImage = require('./remark/transformImage'); const transformLinks = require('./remark/transformLinks'); +const npm2yarn = require('./remark/npm2yarn'); const DEFAULT_OPTIONS = { rehypePlugins: [], - remarkPlugins: [emoji, slug, rightToc], + remarkPlugins: [emoji, slug, rightToc, npm2yarn], }; module.exports = async function docusaurusMdxLoader(fileString) { diff --git a/packages/docusaurus-mdx-loader/src/remark/npm2yarn/index.js b/packages/docusaurus-mdx-loader/src/remark/npm2yarn/index.js new file mode 100644 index 000000000000..3fb7dc662752 --- /dev/null +++ b/packages/docusaurus-mdx-loader/src/remark/npm2yarn/index.js @@ -0,0 +1,81 @@ +/** + * Copyright (c) Facebook, Inc. and its affiliates. + * + * This source code is licensed under the MIT license found in the + * LICENSE file in the root directory of this source tree. + */ + +const npmToYarn = require('npm-to-yarn'); + +// E.g. global install: 'npm i' -> 'yarn' +const convertNpmToYarn = (npmCode) => npmToYarn(npmCode, 'yarn'); + +const transformNode = (node) => { + const npmCode = node.value; + const yarnCode = convertNpmToYarn(node.value); + return [ + { + type: 'jsx', + value: + ` +`, + }, + { + type: node.type, + lang: node.lang, + value: npmCode, + }, + { + type: 'jsx', + value: '\n', + }, + { + type: node.type, + lang: node.lang, + value: yarnCode, + }, + { + type: 'jsx', + value: '\n', + }, + ]; +}; + +const matchNode = (node) => node.type === 'code' && node.meta === 'npm2yarn'; +const nodeForImport = { + type: 'import', + value: + "import Tabs from '@theme/Tabs';\nimport TabItem from '@theme/TabItem';", +}; + +module.exports = () => { + let transformed = false; + const transformer = (node) => { + if (matchNode(node)) { + transformed = true; + return transformNode(node); + } + if (Array.isArray(node.children)) { + let index = 0; + while (index < node.children.length) { + const result = transformer(node.children[index]); + if (result) { + node.children.splice(index, 1, ...result); + index += result.length; + } else { + index += 1; + } + } + } + if (node.type === 'root' && transformed) { + node.children.unshift(nodeForImport); + } + return null; + }; + return transformer; +}; From a8077a8f17b854b2c9f83f01c42d1e7b0fcbb0d3 Mon Sep 17 00:00:00 2001 From: fanny Date: Mon, 21 Sep 2020 08:22:10 -0300 Subject: [PATCH 2/4] test(v2): Add npm2yarn tests --- .../__snapshots__/index.test.js.snap | 74 +++++++++++++++++++ .../__tests__/fixtures/installation.md | 3 + .../npm2yarn/__tests__/fixtures/plugin.md | 7 ++ .../fixtures/syntax-not-properly-set.md | 11 +++ .../remark/npm2yarn/__tests__/index.test.js | 55 ++++++++++++++ 5 files changed, 150 insertions(+) create mode 100644 packages/docusaurus-mdx-loader/src/remark/npm2yarn/__tests__/__snapshots__/index.test.js.snap create mode 100644 packages/docusaurus-mdx-loader/src/remark/npm2yarn/__tests__/fixtures/installation.md create mode 100644 packages/docusaurus-mdx-loader/src/remark/npm2yarn/__tests__/fixtures/plugin.md create mode 100644 packages/docusaurus-mdx-loader/src/remark/npm2yarn/__tests__/fixtures/syntax-not-properly-set.md create mode 100644 packages/docusaurus-mdx-loader/src/remark/npm2yarn/__tests__/index.test.js diff --git a/packages/docusaurus-mdx-loader/src/remark/npm2yarn/__tests__/__snapshots__/index.test.js.snap b/packages/docusaurus-mdx-loader/src/remark/npm2yarn/__tests__/__snapshots__/index.test.js.snap new file mode 100644 index 000000000000..735aeb451f74 --- /dev/null +++ b/packages/docusaurus-mdx-loader/src/remark/npm2yarn/__tests__/__snapshots__/index.test.js.snap @@ -0,0 +1,74 @@ +// Jest Snapshot v1, https://goo.gl/fbAQLP + +exports[`npm2yarn plugin test: installation file 1`] = ` +"import Tabs from '@theme/Tabs'; +import TabItem from '@theme/TabItem'; + + + + +\`\`\`bash + $ npm install --global docusaurus +\`\`\` + + + + +\`\`\`bash + $ yarn add --global docusaurus +\`\`\` + + + +" +`; + +exports[`npm2yarn plugin test: language was not setted 1`] = ` +"\`\`\`npm2yarn +npm install --save docusaurus-plugin-name +\`\`\` + +\`\`\`bash +npm install --save docusaurus-plugin-name +\`\`\` + +\`\`\`shell +npm install --save docusaurus-plugin-name +\`\`\` +" +`; + +exports[`npm2yarn plugin test: plugin file 1`] = ` +"import Tabs from '@theme/Tabs'; +import TabItem from '@theme/TabItem'; + +## Installing a plugin + +A plugin is usually a npm package, so you install them like other npm packages using npm. + + + + +\`\`\`bash +npm install --save docusaurus-plugin-name +\`\`\` + + + + +\`\`\`bash +yarn add docusaurus-plugin-name +\`\`\` + + + +" +`; diff --git a/packages/docusaurus-mdx-loader/src/remark/npm2yarn/__tests__/fixtures/installation.md b/packages/docusaurus-mdx-loader/src/remark/npm2yarn/__tests__/fixtures/installation.md new file mode 100644 index 000000000000..68ce57629e69 --- /dev/null +++ b/packages/docusaurus-mdx-loader/src/remark/npm2yarn/__tests__/fixtures/installation.md @@ -0,0 +1,3 @@ +```bash npm2yarn + $ npm install --global docusaurus +``` diff --git a/packages/docusaurus-mdx-loader/src/remark/npm2yarn/__tests__/fixtures/plugin.md b/packages/docusaurus-mdx-loader/src/remark/npm2yarn/__tests__/fixtures/plugin.md new file mode 100644 index 000000000000..903c335d2941 --- /dev/null +++ b/packages/docusaurus-mdx-loader/src/remark/npm2yarn/__tests__/fixtures/plugin.md @@ -0,0 +1,7 @@ +## Installing a plugin + +A plugin is usually a npm package, so you install them like other npm packages using npm. + +```bash npm2yarn +npm install --save docusaurus-plugin-name +``` diff --git a/packages/docusaurus-mdx-loader/src/remark/npm2yarn/__tests__/fixtures/syntax-not-properly-set.md b/packages/docusaurus-mdx-loader/src/remark/npm2yarn/__tests__/fixtures/syntax-not-properly-set.md new file mode 100644 index 000000000000..c4bebceed9cc --- /dev/null +++ b/packages/docusaurus-mdx-loader/src/remark/npm2yarn/__tests__/fixtures/syntax-not-properly-set.md @@ -0,0 +1,11 @@ +```npm2yarn +npm install --save docusaurus-plugin-name +``` + +```bash +npm install --save docusaurus-plugin-name +``` + +```shell +npm install --save docusaurus-plugin-name +``` diff --git a/packages/docusaurus-mdx-loader/src/remark/npm2yarn/__tests__/index.test.js b/packages/docusaurus-mdx-loader/src/remark/npm2yarn/__tests__/index.test.js new file mode 100644 index 000000000000..8cec8b7be926 --- /dev/null +++ b/packages/docusaurus-mdx-loader/src/remark/npm2yarn/__tests__/index.test.js @@ -0,0 +1,55 @@ +/** + * Copyright (c) Facebook, Inc. and its affiliates. + * + * This source code is licensed under the MIT license found in the + * LICENSE file in the root directory of this source tree. + */ + +/* eslint-disable no-param-reassign */ + +import remark from 'remark'; +import npm2yarn from '../index'; +import vfile from 'to-vfile'; +import {join, relative} from 'path'; +import mdx from 'remark-mdx'; +import slug from '../../slug/index'; + +const staticDir = `./${relative(process.cwd(), join(__dirname, 'fixtures'))}`; + +const processFixture = async (name, options) => { + const path = join(__dirname, 'fixtures', `${name}.md`); + const file = await vfile.read(path); + const result = await remark() + .use(slug) + .use(mdx) + .use(npm2yarn, {...options, filePath: path}) + .process(file); + + return result.toString(); +}; + +describe('npm2yarn plugin', () => { + test('test: installation file', async () => { + const result = await processFixture('installation', { + staticDir, + }); + + expect(result).toMatchSnapshot(); + }); + + test('test: plugin file', async () => { + const result = await processFixture('plugin', { + staticDir, + }); + + expect(result).toMatchSnapshot(); + }); + + test('test: language was not setted', async () => { + const result = await processFixture('syntax-not-properly-set', { + staticDir, + }); + + expect(result).toMatchSnapshot(); + }); +}); From 46c6c637634833c39cd78b73b93984206b1c4fb6 Mon Sep 17 00:00:00 2001 From: fanny Date: Tue, 13 Oct 2020 08:57:03 -0300 Subject: [PATCH 3/4] feat(v2): Move npm2yarn to a new remark plugin --- packages/docusaurus-mdx-loader/src/index.js | 3 +- .../package.json | 26 ++++ .../src/index.js | 17 +++ .../__snapshots__/index.test.js.snap | 0 .../__tests__/fixtures/installation.md | 0 .../npm2yarn/__tests__/fixtures/plugin.md | 0 .../fixtures/syntax-not-properly-set.md | 0 .../src}/npm2yarn/__tests__/index.test.js | 2 - .../src}/npm2yarn/index.js | 0 yarn.lock | 133 ++++++++++++++++++ 10 files changed, 177 insertions(+), 4 deletions(-) create mode 100644 packages/docusaurus-remark-plugin-npm2yarn/package.json create mode 100644 packages/docusaurus-remark-plugin-npm2yarn/src/index.js rename packages/{docusaurus-mdx-loader/src/remark => docusaurus-remark-plugin-npm2yarn/src}/npm2yarn/__tests__/__snapshots__/index.test.js.snap (100%) rename packages/{docusaurus-mdx-loader/src/remark => docusaurus-remark-plugin-npm2yarn/src}/npm2yarn/__tests__/fixtures/installation.md (100%) rename packages/{docusaurus-mdx-loader/src/remark => docusaurus-remark-plugin-npm2yarn/src}/npm2yarn/__tests__/fixtures/plugin.md (100%) rename packages/{docusaurus-mdx-loader/src/remark => docusaurus-remark-plugin-npm2yarn/src}/npm2yarn/__tests__/fixtures/syntax-not-properly-set.md (100%) rename packages/{docusaurus-mdx-loader/src/remark => docusaurus-remark-plugin-npm2yarn/src}/npm2yarn/__tests__/index.test.js (96%) rename packages/{docusaurus-mdx-loader/src/remark => docusaurus-remark-plugin-npm2yarn/src}/npm2yarn/index.js (100%) diff --git a/packages/docusaurus-mdx-loader/src/index.js b/packages/docusaurus-mdx-loader/src/index.js index 95a4da1b0a45..64a666bbd102 100644 --- a/packages/docusaurus-mdx-loader/src/index.js +++ b/packages/docusaurus-mdx-loader/src/index.js @@ -15,11 +15,10 @@ const slug = require('./remark/slug'); const rightToc = require('./remark/rightToc'); const transformImage = require('./remark/transformImage'); const transformLinks = require('./remark/transformLinks'); -const npm2yarn = require('./remark/npm2yarn'); const DEFAULT_OPTIONS = { rehypePlugins: [], - remarkPlugins: [emoji, slug, rightToc, npm2yarn], + remarkPlugins: [emoji, slug, rightToc], }; module.exports = async function docusaurusMdxLoader(fileString) { diff --git a/packages/docusaurus-remark-plugin-npm2yarn/package.json b/packages/docusaurus-remark-plugin-npm2yarn/package.json new file mode 100644 index 000000000000..6e12ca1dacb6 --- /dev/null +++ b/packages/docusaurus-remark-plugin-npm2yarn/package.json @@ -0,0 +1,26 @@ +{ + "name": "@docusaurus/remark-plugin-npm2yarn", + "version": "2.0.0-alpha.65", + "description": "Remark plugin for convert npm commands to yarn as tabs", + "main": "src/index.js", + "publishConfig": { + "access": "public" + }, + "license": "MIT", + "dependencies": { + "npm-to-yarn": "^1.0.0-2", + "@docusaurus/mdx-loader": "2.0.0-alpha.65" + }, + "devDependencies": { + "remark": "^12.0.0", + "remark-mdx": "^1.5.8", + "to-vfile": "^6.0.0" + }, + "peerDependencies": { + "react": "^16.8.4", + "react-dom": "^16.8.4" + }, + "engines": { + "node": ">=10.15.1" + } + } diff --git a/packages/docusaurus-remark-plugin-npm2yarn/src/index.js b/packages/docusaurus-remark-plugin-npm2yarn/src/index.js new file mode 100644 index 000000000000..fa4d24baa38b --- /dev/null +++ b/packages/docusaurus-remark-plugin-npm2yarn/src/index.js @@ -0,0 +1,17 @@ +/** + * Copyright (c) Facebook, Inc. and its affiliates. + * + * This source code is licensed under the MIT license found in the + * LICENSE file in the root directory of this source tree. + */ + +const path = require('path'); + +module.exports = function (_context, _options) { + return { + name: 'docusaurus-remark-plugin-npm2yarn', + getClientModules() { + return [path.resolve(__dirname, './npm2yarn/index.js')]; + }, + }; +}; diff --git a/packages/docusaurus-mdx-loader/src/remark/npm2yarn/__tests__/__snapshots__/index.test.js.snap b/packages/docusaurus-remark-plugin-npm2yarn/src/npm2yarn/__tests__/__snapshots__/index.test.js.snap similarity index 100% rename from packages/docusaurus-mdx-loader/src/remark/npm2yarn/__tests__/__snapshots__/index.test.js.snap rename to packages/docusaurus-remark-plugin-npm2yarn/src/npm2yarn/__tests__/__snapshots__/index.test.js.snap diff --git a/packages/docusaurus-mdx-loader/src/remark/npm2yarn/__tests__/fixtures/installation.md b/packages/docusaurus-remark-plugin-npm2yarn/src/npm2yarn/__tests__/fixtures/installation.md similarity index 100% rename from packages/docusaurus-mdx-loader/src/remark/npm2yarn/__tests__/fixtures/installation.md rename to packages/docusaurus-remark-plugin-npm2yarn/src/npm2yarn/__tests__/fixtures/installation.md diff --git a/packages/docusaurus-mdx-loader/src/remark/npm2yarn/__tests__/fixtures/plugin.md b/packages/docusaurus-remark-plugin-npm2yarn/src/npm2yarn/__tests__/fixtures/plugin.md similarity index 100% rename from packages/docusaurus-mdx-loader/src/remark/npm2yarn/__tests__/fixtures/plugin.md rename to packages/docusaurus-remark-plugin-npm2yarn/src/npm2yarn/__tests__/fixtures/plugin.md diff --git a/packages/docusaurus-mdx-loader/src/remark/npm2yarn/__tests__/fixtures/syntax-not-properly-set.md b/packages/docusaurus-remark-plugin-npm2yarn/src/npm2yarn/__tests__/fixtures/syntax-not-properly-set.md similarity index 100% rename from packages/docusaurus-mdx-loader/src/remark/npm2yarn/__tests__/fixtures/syntax-not-properly-set.md rename to packages/docusaurus-remark-plugin-npm2yarn/src/npm2yarn/__tests__/fixtures/syntax-not-properly-set.md diff --git a/packages/docusaurus-mdx-loader/src/remark/npm2yarn/__tests__/index.test.js b/packages/docusaurus-remark-plugin-npm2yarn/src/npm2yarn/__tests__/index.test.js similarity index 96% rename from packages/docusaurus-mdx-loader/src/remark/npm2yarn/__tests__/index.test.js rename to packages/docusaurus-remark-plugin-npm2yarn/src/npm2yarn/__tests__/index.test.js index 8cec8b7be926..d504331c52e4 100644 --- a/packages/docusaurus-mdx-loader/src/remark/npm2yarn/__tests__/index.test.js +++ b/packages/docusaurus-remark-plugin-npm2yarn/src/npm2yarn/__tests__/index.test.js @@ -12,7 +12,6 @@ import npm2yarn from '../index'; import vfile from 'to-vfile'; import {join, relative} from 'path'; import mdx from 'remark-mdx'; -import slug from '../../slug/index'; const staticDir = `./${relative(process.cwd(), join(__dirname, 'fixtures'))}`; @@ -20,7 +19,6 @@ const processFixture = async (name, options) => { const path = join(__dirname, 'fixtures', `${name}.md`); const file = await vfile.read(path); const result = await remark() - .use(slug) .use(mdx) .use(npm2yarn, {...options, filePath: path}) .process(file); diff --git a/packages/docusaurus-mdx-loader/src/remark/npm2yarn/index.js b/packages/docusaurus-remark-plugin-npm2yarn/src/npm2yarn/index.js similarity index 100% rename from packages/docusaurus-mdx-loader/src/remark/npm2yarn/index.js rename to packages/docusaurus-remark-plugin-npm2yarn/src/npm2yarn/index.js diff --git a/yarn.lock b/yarn.lock index 833ec75087b1..1166f18e5ce6 100644 --- a/yarn.lock +++ b/yarn.lock @@ -1786,6 +1786,139 @@ "@francoischalifour/autocomplete-preset-algolia" "^1.0.0-alpha.27" algoliasearch "^4.0.0" +"@docusaurus/core@2.0.0-alpha.65": + version "2.0.0-alpha.65" + resolved "https://registry.yarnpkg.com/@docusaurus/core/-/core-2.0.0-alpha.65.tgz#e99f19d602c6505febe3de68029fb7ca1225df4d" + integrity sha512-9kfgPugosRq5byuBC/tz3ZShPFT8xh8t08r5tsx8QujfH2ZpDXSQpLF0x/isbCY1O2NQsRZZCKGXQf5dE6NZfQ== + dependencies: + "@babel/core" "^7.9.0" + "@babel/plugin-proposal-nullish-coalescing-operator" "^7.10.1" + "@babel/plugin-proposal-optional-chaining" "^7.10.3" + "@babel/plugin-syntax-dynamic-import" "^7.8.3" + "@babel/plugin-transform-runtime" "^7.9.0" + "@babel/preset-env" "^7.9.0" + "@babel/preset-react" "^7.9.4" + "@babel/preset-typescript" "^7.9.0" + "@babel/runtime" "^7.9.2" + "@babel/runtime-corejs3" "^7.10.4" + "@docusaurus/types" "2.0.0-alpha.65" + "@docusaurus/utils" "2.0.0-alpha.65" + "@docusaurus/utils-validation" "2.0.0-alpha.65" + "@endiliey/static-site-generator-webpack-plugin" "^4.0.0" + "@hapi/joi" "^17.1.1" + "@svgr/webpack" "^5.4.0" + babel-loader "^8.1.0" + babel-plugin-dynamic-import-node "^2.3.0" + boxen "^4.2.0" + cache-loader "^4.1.0" + chalk "^3.0.0" + chokidar "^3.3.0" + commander "^4.0.1" + copy-webpack-plugin "^6.0.3" + core-js "^2.6.5" + css-loader "^3.4.2" + del "^5.1.0" + detect-port "^1.3.0" + eta "^1.1.1" + express "^4.17.1" + file-loader "^6.0.0" + fs-extra "^8.1.0" + globby "^10.0.1" + html-minifier-terser "^5.0.5" + html-tags "^3.1.0" + html-webpack-plugin "^4.0.4" + import-fresh "^3.2.1" + inquirer "^7.2.0" + is-root "^2.1.0" + leven "^3.1.0" + lodash "^4.5.2" + lodash.flatmap "^4.5.0" + lodash.has "^4.5.2" + lodash.isplainobject "^4.0.6" + lodash.isstring "^4.0.1" + mini-css-extract-plugin "^0.8.0" + nprogress "^0.2.0" + null-loader "^3.0.0" + optimize-css-assets-webpack-plugin "^5.0.3" + pnp-webpack-plugin "^1.6.4" + postcss-loader "^3.0.0" + postcss-preset-env "^6.7.0" + react-dev-utils "^10.2.1" + react-helmet "^6.0.0-beta" + react-loadable "^5.5.0" + react-loadable-ssr-addon "^0.3.0" + react-router "^5.1.2" + react-router-config "^5.1.1" + react-router-dom "^5.1.2" + resolve-pathname "^3.0.0" + semver "^6.3.0" + serve-handler "^6.1.3" + shelljs "^0.8.4" + std-env "^2.2.1" + terser-webpack-plugin "^4.1.0" + update-notifier "^4.1.0" + url-loader "^4.1.0" + wait-file "^1.0.5" + webpack "^4.44.1" + webpack-bundle-analyzer "^3.6.1" + webpack-dev-server "^3.11.0" + webpack-merge "^4.2.2" + webpackbar "^4.0.0" + +"@docusaurus/mdx-loader@2.0.0-alpha.65": + version "2.0.0-alpha.65" + resolved "https://registry.yarnpkg.com/@docusaurus/mdx-loader/-/mdx-loader-2.0.0-alpha.65.tgz#389133ea0bc937be935b01e0002cde7ad16429db" + integrity sha512-E+8f9dNML4CMDeLVcJi7qfJisPGJY45iGGkjGTdaxPPzP6xEnqA/Y/ghnKMiBY/GYCxKqteQFg52ZDAGNm4Bkg== + dependencies: + "@babel/parser" "^7.9.4" + "@babel/traverse" "^7.9.0" + "@docusaurus/core" "2.0.0-alpha.65" + "@docusaurus/utils" "2.0.0-alpha.65" + "@mdx-js/mdx" "^1.5.8" + "@mdx-js/react" "^1.5.8" + escape-html "^1.0.3" + file-loader "^6.0.0" + fs-extra "^8.1.0" + github-slugger "^1.3.0" + gray-matter "^4.0.2" + loader-utils "^1.2.3" + mdast-util-to-string "^1.1.0" + remark-emoji "^2.1.0" + stringify-object "^3.3.0" + unist-util-visit "^2.0.2" + url-loader "^4.1.0" + +"@docusaurus/types@2.0.0-alpha.65": + version "2.0.0-alpha.65" + resolved "https://registry.yarnpkg.com/@docusaurus/types/-/types-2.0.0-alpha.65.tgz#e47104e7198ee3708d4f0d82c9fcb1aa2c118ab5" + integrity sha512-a4pcWUfS4I4B6O9zi2yJ7JJvjo8lHqwC6+EdwW/XiJ9B40CkD9LGKYGR2EKIUFM2qrRCgSBrDukIK1oAROrkSQ== + dependencies: + "@types/webpack" "^4.41.0" + commander "^4.0.1" + querystring "0.2.0" + webpack-merge "^4.2.2" + +"@docusaurus/utils-validation@2.0.0-alpha.65": + version "2.0.0-alpha.65" + resolved "https://registry.yarnpkg.com/@docusaurus/utils-validation/-/utils-validation-2.0.0-alpha.65.tgz#3d2b5b365938cacd35c224f4a661802978b5d6ff" + integrity sha512-BcWQx8zb+bbQEDzzUerl31Lehuv4axdoty2vSDqt4rhKiAn1lh/XyWYxxPN98r+roailHsl3WRYK0L+KJjTcKA== + dependencies: + "@docusaurus/utils" "2.0.0-alpha.65" + "@hapi/joi" "17.1.1" + chalk "^3.0.0" + +"@docusaurus/utils@2.0.0-alpha.65": + version "2.0.0-alpha.65" + resolved "https://registry.yarnpkg.com/@docusaurus/utils/-/utils-2.0.0-alpha.65.tgz#2dfc82da1be31d9632cca85d3b70628ef17dc149" + integrity sha512-Fz0rF/eMuzgMOJITF3R62H7fC2fDfTNtJ9wq5DBR050647OMEJnimKSilS1Rsckd7c72mfBdhg3Hdb9rrSrk8Q== + dependencies: + escape-string-regexp "^2.0.0" + fs-extra "^8.1.0" + gray-matter "^4.0.2" + lodash.camelcase "^4.3.0" + lodash.kebabcase "^4.1.1" + resolve-pathname "^3.0.0" + "@endiliey/react-ideal-image@^0.0.11": version "0.0.11" resolved "https://registry.yarnpkg.com/@endiliey/react-ideal-image/-/react-ideal-image-0.0.11.tgz#dc3803d04e1409cf88efa4bba0f67667807bdf27" From 0a98a6e908e881b6d0a2a47e835028d9ee37d7ee Mon Sep 17 00:00:00 2001 From: slorber Date: Thu, 15 Oct 2020 19:17:53 +0200 Subject: [PATCH 4/4] remark npm2yarn plugin => ready to release --- .../README.md | 53 +++++++ .../example.png | Bin 0 -> 18970 bytes .../package.json | 3 +- .../__snapshots__/index.test.js.snap | 0 .../__tests__/fixtures/installation.md | 0 .../__tests__/fixtures/plugin.md | 0 .../fixtures/syntax-not-properly-set.md | 0 .../{npm2yarn => }/__tests__/index.test.js | 0 .../src/index.js | 76 +++++++++- .../src/npm2yarn/index.js | 81 ----------- website/docusaurus.config.js | 4 +- website/package.json | 1 + website/src/plugins/remark-npm2yarn.js | 81 ----------- yarn.lock | 135 +----------------- 14 files changed, 128 insertions(+), 306 deletions(-) create mode 100644 packages/docusaurus-remark-plugin-npm2yarn/README.md create mode 100644 packages/docusaurus-remark-plugin-npm2yarn/example.png rename packages/docusaurus-remark-plugin-npm2yarn/src/{npm2yarn => }/__tests__/__snapshots__/index.test.js.snap (100%) rename packages/docusaurus-remark-plugin-npm2yarn/src/{npm2yarn => }/__tests__/fixtures/installation.md (100%) rename packages/docusaurus-remark-plugin-npm2yarn/src/{npm2yarn => }/__tests__/fixtures/plugin.md (100%) rename packages/docusaurus-remark-plugin-npm2yarn/src/{npm2yarn => }/__tests__/fixtures/syntax-not-properly-set.md (100%) rename packages/docusaurus-remark-plugin-npm2yarn/src/{npm2yarn => }/__tests__/index.test.js (100%) delete mode 100644 packages/docusaurus-remark-plugin-npm2yarn/src/npm2yarn/index.js delete mode 100644 website/src/plugins/remark-npm2yarn.js diff --git a/packages/docusaurus-remark-plugin-npm2yarn/README.md b/packages/docusaurus-remark-plugin-npm2yarn/README.md new file mode 100644 index 000000000000..b93d73da218d --- /dev/null +++ b/packages/docusaurus-remark-plugin-npm2yarn/README.md @@ -0,0 +1,53 @@ +# Remark plugin npm2yarn + +## Motivation: + +Transforms npm bash command code blocks to Docusaurus tabs: + +The following (remove the `//`): + +````bash +// ```bash npm2yarn +// npm run build +// ``` +```` + +Becomes: + +![npm2yarn tabs example](./example.png) + +**Note**: it only works when used with Docusaurus themes that have the `Tabs` and `TabItems` components. + +## Install + +```bash +npm install @docusaurus/remark-plugin-npm2yarn` +``` + +It is a Remark plugin, **not a Docusaurus plugin**, so you have to install it as a Remark plugin in the config of your Docusaurus plugins. + +```js +module.exports = { + presets: [ + [ + '@docusaurus/preset-classic', + { + docs: { + // ... + remarkPlugins: [require('@docusaurus/remark-plugin-npm2yarn')], + }, + blog: { + // ... + remarkPlugins: [require('@docusaurus/remark-plugin-npm2yarn')], + }, + pages: { + // ... + remarkPlugins: [require('@docusaurus/remark-plugin-npm2yarn')], + }, + // ... + }, + ], + ], + // ... +}; +``` diff --git a/packages/docusaurus-remark-plugin-npm2yarn/example.png b/packages/docusaurus-remark-plugin-npm2yarn/example.png new file mode 100644 index 0000000000000000000000000000000000000000..a007c1ddd76130d2bea8fedc1d71d65c4c1df7ef GIT binary patch literal 18970 zcmeHucT`jBwr>CniU<}&0U?TX0qGs0NEeU}QUw7i0jZ&dfNn(TB7$_JN*C!}kt!w9 zkrH|dE%eX=Z^ga$IcL0`?0et)=Z-tZ&KO}W*81w4^ZU)3*ALYcD9_TJ1%W`6N{aV2 zL7-C+AP~t#@>9T*{ln-4;2${~S=on5va;ZZ&W=_#_Ld+J`x^^0vx`c%*;^k!HZyDO zc?FLYq#@BMYb0OgU&pfSpU8?q( zXsYO%E9`oo+6_jpzs_bn`79&-3L6<(29gkM^iaFu%a`}0Pq<=YF8d8#hml5TfemW`IB6pqwY_3^!pa6 z5khuD_nh|Qeu~StA+MT(?%c6&Gc%h|k$;t~YHmh7V`V1FpcA1VMGgZ^i$qTeS}>Ex zdrOd!EtMP}%LEGC`DDj`=dkwZ_!zTte0*%&{N;;Ju>a&25zx^ElUr)ccSZra23hJW zS*famIDva|&0DSt@=l3gF zybkGXX{fDDP(`%li=Th?rO;@DFIh43ujA92bZUguDAMJ7=Q<7o+%o* zfIwGR@Lv)o&0A~0_=7gu`mXw_55z4Tp*)YDIGS7XctD@w#{o%thy%A!OV`I>52(F^ zi@1l>&0j6VfqVR8-kacGO?Hg#CdsPFc=R^fXC6zjt*e_xR1>p-CU(^-o#Jzug~x6wDhp~_e>5he{2ibATRz6FCWhx-hYh^ zbd|(E6@O^sVQH^_-v$cM446ZjPgwMhS&Q<4|I_5UEn?{xn46d<(pSxMf1F-`hx#0#4<03R7_ z?yGA9S3t^seO?29*?}+q3VfN2)ynIETP6;r`**cHNS4PuqjZ`QPp_Ghje%Qp*n_X> zos*w-IMK*$%PQZUa5ZM;fuOuxz*Rn{*I^dFJ&ByS#lt7x{obWHbmIFQd)#Y^id5FP zR`b;7^g(xiEW65LYer^_Q5n^D)zmf%);tkwIg10;I=JlpU`(YOR~e?eSlWl28VvCR zk&vDsaC0b|a?kGx@87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*VAl!_ literal 0 HcmV?d00001 diff --git a/packages/docusaurus-remark-plugin-npm2yarn/package.json b/packages/docusaurus-remark-plugin-npm2yarn/package.json index 6e12ca1dacb6..65860934dd97 100644 --- a/packages/docusaurus-remark-plugin-npm2yarn/package.json +++ b/packages/docusaurus-remark-plugin-npm2yarn/package.json @@ -8,8 +8,7 @@ }, "license": "MIT", "dependencies": { - "npm-to-yarn": "^1.0.0-2", - "@docusaurus/mdx-loader": "2.0.0-alpha.65" + "npm-to-yarn": "^1.0.1" }, "devDependencies": { "remark": "^12.0.0", diff --git a/packages/docusaurus-remark-plugin-npm2yarn/src/npm2yarn/__tests__/__snapshots__/index.test.js.snap b/packages/docusaurus-remark-plugin-npm2yarn/src/__tests__/__snapshots__/index.test.js.snap similarity index 100% rename from packages/docusaurus-remark-plugin-npm2yarn/src/npm2yarn/__tests__/__snapshots__/index.test.js.snap rename to packages/docusaurus-remark-plugin-npm2yarn/src/__tests__/__snapshots__/index.test.js.snap diff --git a/packages/docusaurus-remark-plugin-npm2yarn/src/npm2yarn/__tests__/fixtures/installation.md b/packages/docusaurus-remark-plugin-npm2yarn/src/__tests__/fixtures/installation.md similarity index 100% rename from packages/docusaurus-remark-plugin-npm2yarn/src/npm2yarn/__tests__/fixtures/installation.md rename to packages/docusaurus-remark-plugin-npm2yarn/src/__tests__/fixtures/installation.md diff --git a/packages/docusaurus-remark-plugin-npm2yarn/src/npm2yarn/__tests__/fixtures/plugin.md b/packages/docusaurus-remark-plugin-npm2yarn/src/__tests__/fixtures/plugin.md similarity index 100% rename from packages/docusaurus-remark-plugin-npm2yarn/src/npm2yarn/__tests__/fixtures/plugin.md rename to packages/docusaurus-remark-plugin-npm2yarn/src/__tests__/fixtures/plugin.md diff --git a/packages/docusaurus-remark-plugin-npm2yarn/src/npm2yarn/__tests__/fixtures/syntax-not-properly-set.md b/packages/docusaurus-remark-plugin-npm2yarn/src/__tests__/fixtures/syntax-not-properly-set.md similarity index 100% rename from packages/docusaurus-remark-plugin-npm2yarn/src/npm2yarn/__tests__/fixtures/syntax-not-properly-set.md rename to packages/docusaurus-remark-plugin-npm2yarn/src/__tests__/fixtures/syntax-not-properly-set.md diff --git a/packages/docusaurus-remark-plugin-npm2yarn/src/npm2yarn/__tests__/index.test.js b/packages/docusaurus-remark-plugin-npm2yarn/src/__tests__/index.test.js similarity index 100% rename from packages/docusaurus-remark-plugin-npm2yarn/src/npm2yarn/__tests__/index.test.js rename to packages/docusaurus-remark-plugin-npm2yarn/src/__tests__/index.test.js diff --git a/packages/docusaurus-remark-plugin-npm2yarn/src/index.js b/packages/docusaurus-remark-plugin-npm2yarn/src/index.js index fa4d24baa38b..3fb7dc662752 100644 --- a/packages/docusaurus-remark-plugin-npm2yarn/src/index.js +++ b/packages/docusaurus-remark-plugin-npm2yarn/src/index.js @@ -5,13 +5,77 @@ * LICENSE file in the root directory of this source tree. */ -const path = require('path'); +const npmToYarn = require('npm-to-yarn'); -module.exports = function (_context, _options) { - return { - name: 'docusaurus-remark-plugin-npm2yarn', - getClientModules() { - return [path.resolve(__dirname, './npm2yarn/index.js')]; +// E.g. global install: 'npm i' -> 'yarn' +const convertNpmToYarn = (npmCode) => npmToYarn(npmCode, 'yarn'); + +const transformNode = (node) => { + const npmCode = node.value; + const yarnCode = convertNpmToYarn(node.value); + return [ + { + type: 'jsx', + value: + ` +`, + }, + { + type: node.type, + lang: node.lang, + value: npmCode, + }, + { + type: 'jsx', + value: '\n', + }, + { + type: node.type, + lang: node.lang, + value: yarnCode, + }, + { + type: 'jsx', + value: '\n', }, + ]; +}; + +const matchNode = (node) => node.type === 'code' && node.meta === 'npm2yarn'; +const nodeForImport = { + type: 'import', + value: + "import Tabs from '@theme/Tabs';\nimport TabItem from '@theme/TabItem';", +}; + +module.exports = () => { + let transformed = false; + const transformer = (node) => { + if (matchNode(node)) { + transformed = true; + return transformNode(node); + } + if (Array.isArray(node.children)) { + let index = 0; + while (index < node.children.length) { + const result = transformer(node.children[index]); + if (result) { + node.children.splice(index, 1, ...result); + index += result.length; + } else { + index += 1; + } + } + } + if (node.type === 'root' && transformed) { + node.children.unshift(nodeForImport); + } + return null; }; + return transformer; }; diff --git a/packages/docusaurus-remark-plugin-npm2yarn/src/npm2yarn/index.js b/packages/docusaurus-remark-plugin-npm2yarn/src/npm2yarn/index.js deleted file mode 100644 index 3fb7dc662752..000000000000 --- a/packages/docusaurus-remark-plugin-npm2yarn/src/npm2yarn/index.js +++ /dev/null @@ -1,81 +0,0 @@ -/** - * Copyright (c) Facebook, Inc. and its affiliates. - * - * This source code is licensed under the MIT license found in the - * LICENSE file in the root directory of this source tree. - */ - -const npmToYarn = require('npm-to-yarn'); - -// E.g. global install: 'npm i' -> 'yarn' -const convertNpmToYarn = (npmCode) => npmToYarn(npmCode, 'yarn'); - -const transformNode = (node) => { - const npmCode = node.value; - const yarnCode = convertNpmToYarn(node.value); - return [ - { - type: 'jsx', - value: - ` -`, - }, - { - type: node.type, - lang: node.lang, - value: npmCode, - }, - { - type: 'jsx', - value: '\n', - }, - { - type: node.type, - lang: node.lang, - value: yarnCode, - }, - { - type: 'jsx', - value: '\n', - }, - ]; -}; - -const matchNode = (node) => node.type === 'code' && node.meta === 'npm2yarn'; -const nodeForImport = { - type: 'import', - value: - "import Tabs from '@theme/Tabs';\nimport TabItem from '@theme/TabItem';", -}; - -module.exports = () => { - let transformed = false; - const transformer = (node) => { - if (matchNode(node)) { - transformed = true; - return transformNode(node); - } - if (Array.isArray(node.children)) { - let index = 0; - while (index < node.children.length) { - const result = transformer(node.children[index]); - if (result) { - node.children.splice(index, 1, ...result); - index += result.length; - } else { - index += 1; - } - } - } - if (node.type === 'root' && transformed) { - node.children.unshift(nodeForImport); - } - return null; - }; - return transformer; -}; diff --git a/website/docusaurus.config.js b/website/docusaurus.config.js index f746566750af..56fa70ca7fff 100644 --- a/website/docusaurus.config.js +++ b/website/docusaurus.config.js @@ -193,7 +193,7 @@ module.exports = { 'https://github.com/facebook/docusaurus/edit/master/website/', showLastUpdateAuthor: true, showLastUpdateTime: true, - remarkPlugins: [require('./src/plugins/remark-npm2yarn')], + remarkPlugins: [require('@docusaurus/remark-plugin-npm2yarn')], disableVersioning: isVersioningDisabled, lastVersion: 'current', onlyIncludeVersions: @@ -218,7 +218,7 @@ module.exports = { }, }, pages: { - remarkPlugins: [require('./src/plugins/remark-npm2yarn')], + remarkPlugins: [require('@docusaurus/remark-plugin-npm2yarn')], }, theme: { customCss: [require.resolve('./src/css/custom.css')], diff --git a/website/package.json b/website/package.json index 402ae986922b..0d19ae335f36 100644 --- a/website/package.json +++ b/website/package.json @@ -30,6 +30,7 @@ "@docusaurus/plugin-ideal-image": "2.0.0-alpha.65", "@docusaurus/plugin-pwa": "2.0.0-alpha.65", "@docusaurus/preset-classic": "2.0.0-alpha.65", + "@docusaurus/remark-plugin-npm2yarn": "2.0.0-alpha.65", "@docusaurus/theme-live-codeblock": "2.0.0-alpha.65", "clsx": "^1.1.1", "color": "^3.1.2", diff --git a/website/src/plugins/remark-npm2yarn.js b/website/src/plugins/remark-npm2yarn.js deleted file mode 100644 index 02118ec6d4ab..000000000000 --- a/website/src/plugins/remark-npm2yarn.js +++ /dev/null @@ -1,81 +0,0 @@ -/** - * Copyright (c) Facebook, Inc. and its affiliates. - * - * This source code is licensed under the MIT license found in the - * LICENSE file in the root directory of this source tree. - */ - -const npmToYarn = require('npm-to-yarn'); - -// E.g. global install: 'npm i' -> 'yarn' -const convertNpmToYarn = (npmCode) => npmToYarn(npmCode, 'yarn'); - -const transformNode = (node) => { - const npmCode = node.value; - const yarnCode = convertNpmToYarn(node.value); - return [ - { - type: 'jsx', - value: - ` -`, - }, - { - type: node.type, - lang: node.lang, - value: npmCode, - }, - { - type: 'jsx', - value: '\n', - }, - { - type: node.type, - lang: node.lang, - value: yarnCode, - }, - { - type: 'jsx', - value: '\n', - }, - ]; -}; - -const matchNode = (node) => node.type === 'code' && node.meta === 'npm2yarn'; -const nodeForImport = { - type: 'import', - value: - "import Tabs from '@theme/Tabs';\nimport TabItem from '@theme/TabItem';", -}; - -module.exports = () => { - let transformed = false; - const transformer = (node) => { - if (matchNode(node)) { - transformed = true; - return transformNode(node); - } - if (Array.isArray(node.children)) { - let index = 0; - while (index < node.children.length) { - const result = transformer(node.children[index]); - if (result) { - node.children.splice(index, 1, ...result); - index += result.length; - } else { - index += 1; - } - } - } - if (node.type === 'root' && transformed) { - node.children.unshift(nodeForImport); - } - return null; - }; - return transformer; -}; diff --git a/yarn.lock b/yarn.lock index 7151b1dff10a..1efd9fa3746c 100644 --- a/yarn.lock +++ b/yarn.lock @@ -1786,139 +1786,6 @@ "@francoischalifour/autocomplete-preset-algolia" "^1.0.0-alpha.27" algoliasearch "^4.0.0" -"@docusaurus/core@2.0.0-alpha.65": - version "2.0.0-alpha.65" - resolved "https://registry.yarnpkg.com/@docusaurus/core/-/core-2.0.0-alpha.65.tgz#e99f19d602c6505febe3de68029fb7ca1225df4d" - integrity sha512-9kfgPugosRq5byuBC/tz3ZShPFT8xh8t08r5tsx8QujfH2ZpDXSQpLF0x/isbCY1O2NQsRZZCKGXQf5dE6NZfQ== - dependencies: - "@babel/core" "^7.9.0" - "@babel/plugin-proposal-nullish-coalescing-operator" "^7.10.1" - "@babel/plugin-proposal-optional-chaining" "^7.10.3" - "@babel/plugin-syntax-dynamic-import" "^7.8.3" - "@babel/plugin-transform-runtime" "^7.9.0" - "@babel/preset-env" "^7.9.0" - "@babel/preset-react" "^7.9.4" - "@babel/preset-typescript" "^7.9.0" - "@babel/runtime" "^7.9.2" - "@babel/runtime-corejs3" "^7.10.4" - "@docusaurus/types" "2.0.0-alpha.65" - "@docusaurus/utils" "2.0.0-alpha.65" - "@docusaurus/utils-validation" "2.0.0-alpha.65" - "@endiliey/static-site-generator-webpack-plugin" "^4.0.0" - "@hapi/joi" "^17.1.1" - "@svgr/webpack" "^5.4.0" - babel-loader "^8.1.0" - babel-plugin-dynamic-import-node "^2.3.0" - boxen "^4.2.0" - cache-loader "^4.1.0" - chalk "^3.0.0" - chokidar "^3.3.0" - commander "^4.0.1" - copy-webpack-plugin "^6.0.3" - core-js "^2.6.5" - css-loader "^3.4.2" - del "^5.1.0" - detect-port "^1.3.0" - eta "^1.1.1" - express "^4.17.1" - file-loader "^6.0.0" - fs-extra "^8.1.0" - globby "^10.0.1" - html-minifier-terser "^5.0.5" - html-tags "^3.1.0" - html-webpack-plugin "^4.0.4" - import-fresh "^3.2.1" - inquirer "^7.2.0" - is-root "^2.1.0" - leven "^3.1.0" - lodash "^4.5.2" - lodash.flatmap "^4.5.0" - lodash.has "^4.5.2" - lodash.isplainobject "^4.0.6" - lodash.isstring "^4.0.1" - mini-css-extract-plugin "^0.8.0" - nprogress "^0.2.0" - null-loader "^3.0.0" - optimize-css-assets-webpack-plugin "^5.0.3" - pnp-webpack-plugin "^1.6.4" - postcss-loader "^3.0.0" - postcss-preset-env "^6.7.0" - react-dev-utils "^10.2.1" - react-helmet "^6.0.0-beta" - react-loadable "^5.5.0" - react-loadable-ssr-addon "^0.3.0" - react-router "^5.1.2" - react-router-config "^5.1.1" - react-router-dom "^5.1.2" - resolve-pathname "^3.0.0" - semver "^6.3.0" - serve-handler "^6.1.3" - shelljs "^0.8.4" - std-env "^2.2.1" - terser-webpack-plugin "^4.1.0" - update-notifier "^4.1.0" - url-loader "^4.1.0" - wait-file "^1.0.5" - webpack "^4.44.1" - webpack-bundle-analyzer "^3.6.1" - webpack-dev-server "^3.11.0" - webpack-merge "^4.2.2" - webpackbar "^4.0.0" - -"@docusaurus/mdx-loader@2.0.0-alpha.65": - version "2.0.0-alpha.65" - resolved "https://registry.yarnpkg.com/@docusaurus/mdx-loader/-/mdx-loader-2.0.0-alpha.65.tgz#389133ea0bc937be935b01e0002cde7ad16429db" - integrity sha512-E+8f9dNML4CMDeLVcJi7qfJisPGJY45iGGkjGTdaxPPzP6xEnqA/Y/ghnKMiBY/GYCxKqteQFg52ZDAGNm4Bkg== - dependencies: - "@babel/parser" "^7.9.4" - "@babel/traverse" "^7.9.0" - "@docusaurus/core" "2.0.0-alpha.65" - "@docusaurus/utils" "2.0.0-alpha.65" - "@mdx-js/mdx" "^1.5.8" - "@mdx-js/react" "^1.5.8" - escape-html "^1.0.3" - file-loader "^6.0.0" - fs-extra "^8.1.0" - github-slugger "^1.3.0" - gray-matter "^4.0.2" - loader-utils "^1.2.3" - mdast-util-to-string "^1.1.0" - remark-emoji "^2.1.0" - stringify-object "^3.3.0" - unist-util-visit "^2.0.2" - url-loader "^4.1.0" - -"@docusaurus/types@2.0.0-alpha.65": - version "2.0.0-alpha.65" - resolved "https://registry.yarnpkg.com/@docusaurus/types/-/types-2.0.0-alpha.65.tgz#e47104e7198ee3708d4f0d82c9fcb1aa2c118ab5" - integrity sha512-a4pcWUfS4I4B6O9zi2yJ7JJvjo8lHqwC6+EdwW/XiJ9B40CkD9LGKYGR2EKIUFM2qrRCgSBrDukIK1oAROrkSQ== - dependencies: - "@types/webpack" "^4.41.0" - commander "^4.0.1" - querystring "0.2.0" - webpack-merge "^4.2.2" - -"@docusaurus/utils-validation@2.0.0-alpha.65": - version "2.0.0-alpha.65" - resolved "https://registry.yarnpkg.com/@docusaurus/utils-validation/-/utils-validation-2.0.0-alpha.65.tgz#3d2b5b365938cacd35c224f4a661802978b5d6ff" - integrity sha512-BcWQx8zb+bbQEDzzUerl31Lehuv4axdoty2vSDqt4rhKiAn1lh/XyWYxxPN98r+roailHsl3WRYK0L+KJjTcKA== - dependencies: - "@docusaurus/utils" "2.0.0-alpha.65" - "@hapi/joi" "17.1.1" - chalk "^3.0.0" - -"@docusaurus/utils@2.0.0-alpha.65": - version "2.0.0-alpha.65" - resolved "https://registry.yarnpkg.com/@docusaurus/utils/-/utils-2.0.0-alpha.65.tgz#2dfc82da1be31d9632cca85d3b70628ef17dc149" - integrity sha512-Fz0rF/eMuzgMOJITF3R62H7fC2fDfTNtJ9wq5DBR050647OMEJnimKSilS1Rsckd7c72mfBdhg3Hdb9rrSrk8Q== - dependencies: - escape-string-regexp "^2.0.0" - fs-extra "^8.1.0" - gray-matter "^4.0.2" - lodash.camelcase "^4.3.0" - lodash.kebabcase "^4.1.1" - resolve-pathname "^3.0.0" - "@endiliey/react-ideal-image@^0.0.11": version "0.0.11" resolved "https://registry.yarnpkg.com/@endiliey/react-ideal-image/-/react-ideal-image-0.0.11.tgz#dc3803d04e1409cf88efa4bba0f67667807bdf27" @@ -15490,7 +15357,7 @@ npm-run-path@^4.0.0: dependencies: path-key "^3.0.0" -npm-to-yarn@^1.0.0-2: +npm-to-yarn@^1.0.0-2, npm-to-yarn@^1.0.1: version "1.0.1" resolved "https://registry.yarnpkg.com/npm-to-yarn/-/npm-to-yarn-1.0.1.tgz#6cdb95114c4ff0be50a7a2381d4d16131a5f52df" integrity sha512-bp8T8oNMfLW+N/fE0itFfSu7RReytwhqNd9skbkfHfzGYC+5CCdzS2HnaXz6JiG4AlK2eA0qlT6NJN1SoFvcWQ==