@sapphire/docusaurus-plugin-npm2yarn2pnpm 1.1.0-next.fadcdcf.0 → 1.1.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/CHANGELOG.md ADDED
@@ -0,0 +1,47 @@
1
+ # Changelog
2
+
3
+ All notable changes to this project will be documented in this file.
4
+
5
+ # [@sapphire/docusaurus-plugin-npm2yarn2pnpm@1.1.0](https://github.com/sapphiredev/documentation-plugins/compare/@sapphire/docusaurus-plugin-npm2yarn2pnpm@1.0.3...@sapphire/docusaurus-plugin-npm2yarn2pnpm@1.1.0) - (2022-05-15)
6
+
7
+ ## 🐛 Bug Fixes
8
+
9
+ - Restore tsup (reverts 7411ff7) ([7df536b](https://github.com/sapphiredev/documentation-plugins/commit/7df536bd871b45d0cfa65816684bc691b4735bc0))
10
+ - Remove tsup ([7411ff7](https://github.com/sapphiredev/documentation-plugins/commit/7411ff79624eec777519a2a049c8d3f026871cac))
11
+ - **npm2yarn2pnpm:** Ensure compatibility with docusaurus v2 beta 20 ([8aff911](https://github.com/sapphiredev/documentation-plugins/commit/8aff911be521423b465a547bb9bed9b24531533e))
12
+
13
+ ## 🚀 Features
14
+
15
+ - Allow module: NodeNext ([8221bc2](https://github.com/sapphiredev/documentation-plugins/commit/8221bc2668fd1ad9c2e80c3c6a1503ae27bfc632))
16
+
17
+ ## [1.0.3](https://github.com/sapphiredev/documentation-plugins/compare/@sapphire/docusaurus-plugin-npm2yarn2pnpm@1.0.2...@sapphire/docusaurus-plugin-npm2yarn2pnpm@1.0.3) (2022-01-13)
18
+
19
+ ### Bug Fixes
20
+
21
+ - **npm2yarn2pnpm:** cleanup dependencies ([fe52cac](https://github.com/sapphiredev/documentation-plugins/commit/fe52cacfc0fd28a0de49464aa63029eea35d7ddf))
22
+
23
+ ## [1.0.2](https://github.com/sapphiredev/documentation-plugins/compare/@sapphire/docusaurus-plugin-npm2yarn2pnpm@1.0.1...@sapphire/docusaurus-plugin-npm2yarn2pnpm@1.0.2) (2022-01-12)
24
+
25
+ ### Reverts
26
+
27
+ - Revert "ci: try adding extra dev deps for ci" ([de49260](https://github.com/sapphiredev/documentation-plugins/commit/de49260d4d8c4be4bb27d53f13472946e4cd3700))
28
+
29
+ ## [1.0.1](https://github.com/sapphiredev/documentation-plugins/compare/@sapphire/docusaurus-plugin-npm2yarn2pnpm@1.0.0...@sapphire/docusaurus-plugin-npm2yarn2pnpm@1.0.1) (2021-11-30)
30
+
31
+ **Note:** Version bump only for package @sapphire/docusaurus-plugin-npm2yarn2pnpm
32
+
33
+ # 1.0.0 (2021-11-26)
34
+
35
+ ### Bug Fixes
36
+
37
+ - **npm2yarn2pnpm:** also export npm2pnpm ([92711c8](https://github.com/sapphiredev/documentation-plugins/commit/92711c864f467b1834f63c3d9e1434c69f0305bb))
38
+ - **npm2yarn2pnpm:** removed esm exports to ensure cjs works fine with require syntax ([2e75537](https://github.com/sapphiredev/documentation-plugins/commit/2e75537a99d0614f55c4e3c8c963d0a37cf02768))
39
+ - **npm2yarn2pnpm:** removed exports field from package.json ([e2b11bc](https://github.com/sapphiredev/documentation-plugins/commit/e2b11bca172c85c415237de0a88dc095a61fbe39))
40
+
41
+ ### Features
42
+
43
+ - add npm2yarn2pnpm package ([a12527e](https://github.com/sapphiredev/documentation-plugins/commit/a12527eab37e7c0064174c3066939973ddce3740))
44
+
45
+ ### Reverts
46
+
47
+ - Revert "fix(typedoc-djs-links): removed esm exports to ensure cjs works fine with require syntax" ([7b4c6ab](https://github.com/sapphiredev/documentation-plugins/commit/7b4c6ab434265903213d7d965b0e927912b1aba1))
package/dist/index.js CHANGED
@@ -66,37 +66,40 @@ function npmToPnpm(str) {
66
66
 
67
67
  // src/npm2yarn2pnpm.ts
68
68
  var import_npm_to_yarn = __toESM(require("npm-to-yarn"));
69
+ var import_unist_util_visit = __toESM(require("unist-util-visit"));
69
70
  var transformNode = (node, options) => {
70
- const groupIdProp = options.sync ? 'groupId="npm2yarn2pnpm" ' : "";
71
+ const groupIdProp = options.sync ? ' groupId="npm2yarn2pnpm"' : "";
71
72
  const npmCode = node.value;
72
73
  const yarnCode = (0, import_npm_to_yarn.default)(node.value, "yarn");
73
74
  const pnpmCode = npmToPnpm(node.value);
74
- const [, highlight] = node.meta.split("|");
75
+ const [, highlight] = (node.meta ?? "").split("|");
75
76
  return [
76
77
  {
77
78
  type: "jsx",
78
- value: `<Tabs defaultValue="npm" ${groupIdProp}values={[
79
- { label: 'npm', value: 'npm', },
80
- { label: 'yarn', value: 'yarn', },
81
- { label: 'pnpm', value: 'pnpm', },
82
- ]}
83
- >
79
+ value: `<Tabs${groupIdProp}
80
+ defaultValue="npm"
81
+ values={[
82
+ { label: "npm", value: "npm" },
83
+ { label: "yarn", value: "yarn" },
84
+ { label: "pnpm", value: "pnpm" },
85
+ ]}
86
+ >
84
87
  <TabItem value="npm">`
85
88
  },
86
89
  {
87
90
  type: node.type,
88
91
  lang: node.lang,
89
- meta: highlight,
92
+ meta: `${highlight} showLineNumbers`,
90
93
  value: npmCode
91
94
  },
92
95
  {
93
96
  type: "jsx",
94
- value: '</TabItem>\n<TabItem value="yarn">'
97
+ value: '</TabItem>\n<TabItem value="yarn" label="Yarn">'
95
98
  },
96
99
  {
97
100
  type: node.type,
98
101
  lang: node.lang,
99
- meta: highlight,
102
+ meta: `${highlight} showLineNumbers`,
100
103
  value: yarnCode
101
104
  },
102
105
  {
@@ -106,7 +109,7 @@ var transformNode = (node, options) => {
106
109
  {
107
110
  type: node.type,
108
111
  lang: node.lang,
109
- meta: highlight,
112
+ meta: `${highlight} showLineNumbers`,
110
113
  value: pnpmCode
111
114
  },
112
115
  {
@@ -115,41 +118,39 @@ var transformNode = (node, options) => {
115
118
  }
116
119
  ];
117
120
  };
118
- var matchNode = (node) => node.type === "code" && typeof node.meta === "string" && node.meta.startsWith("npm2yarn2pnpm");
121
+ var isImport = (node) => node.type === "import";
122
+ var isParent = (node) => Array.isArray(node.children);
123
+ var matchNode = (node) => node.type === "code" && typeof node.meta === "string" && (node.meta ?? "").startsWith("npm2yarn2pnpm");
119
124
  var nodeForImport = {
120
125
  type: "import",
121
126
  value: "import Tabs from '@theme/Tabs';\nimport TabItem from '@theme/TabItem';"
122
127
  };
123
- function npm2yarn2pnpm({ sync = true } = { sync: true }) {
128
+ var npm2yarn2pnpm = ({ sync = true } = { sync: true }) => (root) => {
124
129
  let transformed = false;
125
130
  let alreadyImported = false;
126
- const transformer = (node) => {
127
- if (node.type === "import" && node.value.includes("@theme/Tabs")) {
131
+ (0, import_unist_util_visit.default)(root, (node) => {
132
+ if (isImport(node) && node.value.includes("@theme/Tabs")) {
128
133
  alreadyImported = true;
129
134
  }
130
- if (matchNode(node)) {
131
- transformed = true;
132
- return transformNode(node, { sync });
133
- }
134
- if (Array.isArray(node.children)) {
135
+ if (isParent(node)) {
135
136
  let index = 0;
136
137
  while (index < node.children.length) {
137
- const result = transformer(node.children[index]);
138
- if (result) {
138
+ const child = node.children[index];
139
+ if (matchNode(child)) {
140
+ const result = transformNode(child, { sync });
139
141
  node.children.splice(index, 1, ...result);
140
142
  index += result.length;
143
+ transformed = true;
141
144
  } else {
142
145
  index += 1;
143
146
  }
144
147
  }
145
148
  }
146
- if (node.type === "root" && transformed && !alreadyImported) {
147
- node.children.unshift(nodeForImport);
148
- }
149
- return null;
150
- };
151
- return transformer;
152
- }
149
+ });
150
+ if (transformed && !alreadyImported) {
151
+ root.children.unshift(nodeForImport);
152
+ }
153
+ };
153
154
  // Annotate the CommonJS export names for ESM import in node:
154
155
  0 && (module.exports = {
155
156
  npm2yarn2pnpm,
package/dist/index.js.map CHANGED
@@ -1 +1 @@
1
- {"version":3,"sources":["../src/index.ts","../src/npm2pnpm.ts","../src/npm2yarn2pnpm.ts"],"sourcesContent":["export { npmToPnpm } from './npm2pnpm';\nexport { npm2yarn2pnpm, PluginOptions } from './npm2yarn2pnpm';\n","/**\n * Copyright (c) 2019 Ben Gubler <nebrelbug@gmail.com>\n *\n * This source code is licensed under the MIT license found in the\n * LICENSE file in the root directory of this source tree.\n */\n\nconst unchangedCLICommands = ['init', 'run', 'test', 'login', 'logout', 'link', 'publish', 'cache'];\n\nconst npmToPnpmTable = {\n\tinstall(command: string) {\n\t\tif (/^install *$/.test(command)) {\n\t\t\treturn 'install';\n\t\t}\n\n\t\treturn command\n\t\t\t.replace('install', 'add')\n\t\t\t.replace(/\\s*--save/, '--save-prod')\n\t\t\t.replace('--no-package-lock', '');\n\t},\n\n\tuninstall(command: string) {\n\t\treturn command\n\t\t\t.replace('uninstall', 'remove')\n\t\t\t.replace(/\\s*--save/, '--save-prod')\n\t\t\t.replace('--no-package-lock', '');\n\t},\n\n\tversion(command: string) {\n\t\treturn command.replace(/(major|minor|patch)/, '--$1');\n\t},\n\n\trebuild(command: string) {\n\t\treturn command.replace('rebuild', 'add --force');\n\t}\n} as const;\n\nfunction convert(_: string, command: string) {\n\tcommand = (command ?? '').trim();\n\n\tconst firstCommand = (/\\w+/.exec(command) || [''])[0] as keyof typeof npmToPnpmTable;\n\n\tif (unchangedCLICommands.includes(firstCommand)) {\n\t\treturn `pnpm ${command}`;\n\t} else if (Object.prototype.hasOwnProperty.call(npmToPnpmTable, firstCommand) && npmToPnpmTable[firstCommand]) {\n\t\tif (typeof npmToPnpmTable[firstCommand] === 'function') {\n\t\t\treturn `pnpm ${npmToPnpmTable[firstCommand](command)}`;\n\t\t}\n\t\treturn `pnpm ${command.replace(firstCommand, npmToPnpmTable[firstCommand])}`;\n\t}\n\n\treturn `pnpm ${command}\\n# couldn't auto-convert command`;\n}\n\nexport function npmToPnpm(str: string) {\n\treturn str.replace(/npm(?: +([^&\\n\\r]*))?/gm, convert);\n}\n","import npmToYarn from 'npm-to-yarn';\nimport { npmToPnpm } from './npm2pnpm';\n\nconst transformNode = (node: any, options: PluginOptions) => {\n\tconst groupIdProp = options.sync ? 'groupId=\"npm2yarn2pnpm\" ' : '';\n\tconst npmCode = node.value;\n\n\tconst yarnCode = npmToYarn(node.value, 'yarn');\n\tconst pnpmCode = npmToPnpm(node.value);\n\n\tconst [, highlight] = node.meta.split('|');\n\n\treturn [\n\t\t{\n\t\t\ttype: 'jsx',\n\t\t\tvalue:\n\t\t\t\t`<Tabs defaultValue=\"npm\" ${groupIdProp}` +\n\t\t\t\t`values={[\n { label: 'npm', value: 'npm', },\n { label: 'yarn', value: 'yarn', },\n { label: 'pnpm', value: 'pnpm', },\n ]}\n>\n<TabItem value=\"npm\">`\n\t\t},\n\t\t{\n\t\t\ttype: node.type,\n\t\t\tlang: node.lang,\n\t\t\tmeta: highlight,\n\t\t\tvalue: npmCode\n\t\t},\n\t\t{\n\t\t\ttype: 'jsx',\n\t\t\tvalue: '</TabItem>\\n<TabItem value=\"yarn\">'\n\t\t},\n\t\t{\n\t\t\ttype: node.type,\n\t\t\tlang: node.lang,\n\t\t\tmeta: highlight,\n\t\t\tvalue: yarnCode\n\t\t},\n\t\t{\n\t\t\ttype: 'jsx',\n\t\t\tvalue: '</TabItem>\\n<TabItem value=\"pnpm\">'\n\t\t},\n\t\t{\n\t\t\ttype: node.type,\n\t\t\tlang: node.lang,\n\t\t\tmeta: highlight,\n\t\t\tvalue: pnpmCode\n\t\t},\n\t\t{\n\t\t\ttype: 'jsx',\n\t\t\tvalue: '</TabItem>\\n</Tabs>'\n\t\t}\n\t];\n};\n\nconst matchNode = (node: any) => node.type === 'code' && typeof node.meta === 'string' && node.meta.startsWith('npm2yarn2pnpm');\nconst nodeForImport = {\n\ttype: 'import',\n\tvalue: \"import Tabs from '@theme/Tabs';\\nimport TabItem from '@theme/TabItem';\"\n};\n\nexport interface PluginOptions {\n\tsync?: boolean;\n}\n\nexport function npm2yarn2pnpm({ sync = true }: PluginOptions = { sync: true }) {\n\tlet transformed = false;\n\tlet alreadyImported = false;\n\n\tconst transformer = (node: any) => {\n\t\tif (node.type === 'import' && node.value.includes('@theme/Tabs')) {\n\t\t\talreadyImported = true;\n\t\t}\n\n\t\tif (matchNode(node)) {\n\t\t\ttransformed = true;\n\t\t\treturn transformNode(node, { sync });\n\t\t}\n\n\t\tif (Array.isArray(node.children)) {\n\t\t\tlet index = 0;\n\t\t\twhile (index < node.children.length) {\n\t\t\t\tconst result = transformer(node.children[index]);\n\t\t\t\tif (result) {\n\t\t\t\t\tnode.children.splice(index, 1, ...result);\n\t\t\t\t\tindex += result.length;\n\t\t\t\t} else {\n\t\t\t\t\tindex += 1;\n\t\t\t\t}\n\t\t\t}\n\t\t}\n\n\t\tif (node.type === 'root' && transformed && !alreadyImported) {\n\t\t\tnode.children.unshift(nodeForImport);\n\t\t}\n\n\t\treturn null;\n\t};\n\n\treturn transformer;\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;;;ACOA,IAAM,uBAAuB,CAAC,QAAQ,OAAO,QAAQ,SAAS,UAAU,QAAQ,WAAW,OAAO;AAElG,IAAM,iBAAiB;AAAA,EACtB,QAAQ,SAAiB;AACxB,QAAI,cAAc,KAAK,OAAO,GAAG;AAChC,aAAO;AAAA,IACR;AAEA,WAAO,QACL,QAAQ,WAAW,KAAK,EACxB,QAAQ,aAAa,aAAa,EAClC,QAAQ,qBAAqB,EAAE;AAAA,EAClC;AAAA,EAEA,UAAU,SAAiB;AAC1B,WAAO,QACL,QAAQ,aAAa,QAAQ,EAC7B,QAAQ,aAAa,aAAa,EAClC,QAAQ,qBAAqB,EAAE;AAAA,EAClC;AAAA,EAEA,QAAQ,SAAiB;AACxB,WAAO,QAAQ,QAAQ,uBAAuB,MAAM;AAAA,EACrD;AAAA,EAEA,QAAQ,SAAiB;AACxB,WAAO,QAAQ,QAAQ,WAAW,aAAa;AAAA,EAChD;AACD;AAEA,iBAAiB,GAAW,SAAiB;AAC5C,YAAW,YAAW,IAAI,KAAK;AAE/B,QAAM,eAAgB,OAAM,KAAK,OAAO,KAAK,CAAC,EAAE,GAAG;AAEnD,MAAI,qBAAqB,SAAS,YAAY,GAAG;AAChD,WAAO,QAAQ;AAAA,E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AAK,SAAS,YAAY,KAAK,KAAK,WAAW,eAAe;AAC9H,IAAM,gBAAgB;AAAA,EACrB,MAAM;AAAA,EACN,OAAO;AACR;AAMO,uBAAuB,EAAE,OAAO,SAAwB,EAAE,MAAM,KAAK,GAAG;AAC9E,MAAI,cAAc;AAClB,MAAI,kBAAkB;AAEtB,QAAM,cAAc,CAAC,SAAc;AAClC,QAAI,KAAK,SAAS,YAAY,KAAK,MAAM,SAAS,aAAa,GAAG;AACjE,wBAAkB;AAAA,IACnB;AAEA,QAAI,UAAU,IAAI,GAAG;AACpB,oBAAc;AACd,aAAO,cAAc,MAAM,EAAE,KAAK,CAAC;AAAA,IACpC;AAEA,QAAI,MAAM,QAAQ,KAAK,QAAQ,GAAG;AACjC,UAAI,QAAQ;AACZ,aAAO,QAAQ,KAAK,SAAS,QAAQ;AACpC,cAAM,SAAS,YAAY,KAAK,SAAS,MAAM;AAC/C,YAAI,QAAQ;AACX,eAAK,SAAS,OAAO,OAAO,GAAG,GAAG,MAAM;AACxC,mBAAS,OAAO;AAAA,QACjB,OAAO;AACN,mBAAS;AAAA,QACV;AAAA,MACD;AAAA,IACD;AAEA,QAAI,KAAK,SAAS,UAAU,eAAe,CAAC,iBAAiB;AAC5D,WAAK,SAAS,QAAQ,aAAa;AAAA,IACpC;AAEA,WAAO;AAAA,EACR;AAEA,SAAO;AACR;","names":[]}
1
+ {"version":3,"sources":["../src/index.ts","../src/npm2pnpm.ts","../src/npm2yarn2pnpm.ts"],"sourcesContent":["export { npmToPnpm } from './npm2pnpm';\nexport { npm2yarn2pnpm, PluginOptions } from './npm2yarn2pnpm';\n","/**\n * Copyright (c) 2019 Ben Gubler <nebrelbug@gmail.com>\n *\n * This source code is licensed under the MIT license found in the\n * LICENSE file in the root directory of this source tree.\n */\n\nconst unchangedCLICommands = ['init', 'run', 'test', 'login', 'logout', 'link', 'publish', 'cache'];\n\nconst npmToPnpmTable = {\n\tinstall(command: string) {\n\t\tif (/^install *$/.test(command)) {\n\t\t\treturn 'install';\n\t\t}\n\n\t\treturn command\n\t\t\t.replace('install', 'add')\n\t\t\t.replace(/\\s*--save/, '--save-prod')\n\t\t\t.replace('--no-package-lock', '');\n\t},\n\n\tuninstall(command: string) {\n\t\treturn command\n\t\t\t.replace('uninstall', 'remove')\n\t\t\t.replace(/\\s*--save/, '--save-prod')\n\t\t\t.replace('--no-package-lock', '');\n\t},\n\n\tversion(command: string) {\n\t\treturn command.replace(/(major|minor|patch)/, '--$1');\n\t},\n\n\trebuild(command: string) {\n\t\treturn command.replace('rebuild', 'add --force');\n\t}\n} as const;\n\nfunction convert(_: string, command: string) {\n\tcommand = (command ?? '').trim();\n\n\tconst firstCommand = (/\\w+/.exec(command) || [''])[0] as keyof typeof npmToPnpmTable;\n\n\tif (unchangedCLICommands.includes(firstCommand)) {\n\t\treturn `pnpm ${command}`;\n\t} else if (Object.prototype.hasOwnProperty.call(npmToPnpmTable, firstCommand) && npmToPnpmTable[firstCommand]) {\n\t\tif (typeof npmToPnpmTable[firstCommand] === 'function') {\n\t\t\treturn `pnpm ${npmToPnpmTable[firstCommand](command)}`;\n\t\t}\n\t\treturn `pnpm ${command.replace(firstCommand, npmToPnpmTable[firstCommand])}`;\n\t}\n\n\treturn `pnpm ${command}\\n# couldn't auto-convert command`;\n}\n\nexport function npmToPnpm(str: string) {\n\treturn str.replace(/npm(?: +([^&\\n\\r]*))?/gm, convert);\n}\n","import type { Code, Content, Literal } from 'mdast';\nimport npmToYarn from 'npm-to-yarn';\nimport type { Plugin } from 'unified';\nimport type { Node, Parent } from 'unist';\nimport visit from 'unist-util-visit';\nimport { npmToPnpm } from './npm2pnpm';\n\n/**\n * Transforms a Docusaurus node from NPM to Yarn and Pnpm\n * @param node The Docusaurus node to transform\n * @param options The plugin options to pass to the transformer\n * @returns The transformed node in the form of Tabs.\n */\nconst transformNode = (node: Code, options: PluginOptions) => {\n\tconst groupIdProp = options.sync ? ' groupId=\"npm2yarn2pnpm\"' : '';\n\tconst npmCode = node.value;\n\n\tconst yarnCode = npmToYarn(node.value, 'yarn');\n\tconst pnpmCode = npmToPnpm(node.value);\n\n\tconst [, highlight] = (node.meta ?? '').split('|');\n\n\treturn [\n\t\t{\n\t\t\ttype: 'jsx',\n\t\t\tvalue: `<Tabs${groupIdProp}\n\t\t\t\t\t\tdefaultValue=\"npm\"\n\t\t\t\t\t\tvalues={[\n\t\t\t\t\t\t\t{ label: \"npm\", value: \"npm\" },\n\t\t\t\t\t\t\t{ label: \"yarn\", value: \"yarn\" },\n\t\t\t\t\t\t\t{ label: \"pnpm\", value: \"pnpm\" },\n\t\t\t\t\t\t]}\n\t\t\t>\\n<TabItem value=\"npm\">`\n\t\t},\n\t\t{\n\t\t\ttype: node.type,\n\t\t\tlang: node.lang,\n\t\t\tmeta: `${highlight} showLineNumbers`,\n\t\t\tvalue: npmCode\n\t\t},\n\t\t{\n\t\t\ttype: 'jsx',\n\t\t\tvalue: '</TabItem>\\n<TabItem value=\"yarn\" label=\"Yarn\">'\n\t\t},\n\t\t{\n\t\t\ttype: node.type,\n\t\t\tlang: node.lang,\n\t\t\tmeta: `${highlight} showLineNumbers`,\n\t\t\tvalue: yarnCode\n\t\t},\n\t\t{\n\t\t\ttype: 'jsx',\n\t\t\tvalue: '</TabItem>\\n<TabItem value=\"pnpm\">'\n\t\t},\n\t\t{\n\t\t\ttype: node.type,\n\t\t\tlang: node.lang,\n\t\t\tmeta: `${highlight} showLineNumbers`,\n\t\t\tvalue: pnpmCode\n\t\t},\n\t\t{\n\t\t\ttype: 'jsx',\n\t\t\tvalue: '</TabItem>\\n</Tabs>'\n\t\t}\n\t] as Content[];\n};\n\nconst isImport = (node: Node): node is Literal => node.type === 'import';\nconst isParent = (node: Node): node is Parent => Array.isArray((node as Parent).children);\nconst matchNode = (node: Node): node is Code =>\n\tnode.type === 'code' && typeof (node as Code).meta === 'string' && ((node as Code).meta ?? '').startsWith('npm2yarn2pnpm');\nconst nodeForImport: Literal = {\n\ttype: 'import',\n\tvalue: \"import Tabs from '@theme/Tabs';\\nimport TabItem from '@theme/TabItem';\"\n};\n\nexport interface PluginOptions {\n\tsync?: boolean;\n}\n\nexport const npm2yarn2pnpm: Plugin<[PluginOptions?]> =\n\t({ sync = true } = { sync: true }) =>\n\t(root) => {\n\t\tlet transformed = false;\n\t\tlet alreadyImported = false;\n\t\tvisit(root, (node: Node) => {\n\t\t\tif (isImport(node) && node.value.includes('@theme/Tabs')) {\n\t\t\t\talreadyImported = true;\n\t\t\t}\n\t\t\tif (isParent(node)) {\n\t\t\t\tlet index = 0;\n\t\t\t\twhile (index < node.children.length) {\n\t\t\t\t\tconst child = node.children[index]!;\n\t\t\t\t\tif (matchNode(child)) {\n\t\t\t\t\t\tconst result = transformNode(child, { sync });\n\t\t\t\t\t\tnode.children.splice(index, 1, ...result);\n\t\t\t\t\t\tindex += result.length;\n\t\t\t\t\t\ttransformed = true;\n\t\t\t\t\t} else {\n\t\t\t\t\t\tindex += 1;\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t}\n\t\t});\n\t\tif (transformed && !alreadyImported) {\n\t\t\t(root as Parent).children.unshift(nodeForImport);\n\t\t}\n\t};\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;;;ACOA,IAAM,uBAAuB,CAAC,QAAQ,OAAO,QAAQ,SAAS,UAAU,QAAQ,WAAW,OAAO;AAElG,IAAM,iBAAiB;AAAA,EACtB,QAAQ,SAAiB;AACxB,QAAI,cAAc,KAAK,OAAO,GAAG;AAChC,aAAO;AAAA,IACR;AAEA,WAAO,QACL,QAAQ,WAAW,KAAK,EACxB,QAAQ,aAAa,aAAa,EAClC,QAAQ,qBAAqB,EAAE;AAAA,EAClC;AAAA,EAEA,UAAU,SAAiB;AAC1B,WAAO,QACL,QAAQ,aAAa,QAAQ,EAC7B,QAAQ,aAAa,aAAa,EAClC,QAAQ,qBAAqB,EAAE;AAAA,EAClC;AAAA,EAEA,QAAQ,SAAiB;AACxB,W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AQ,aAAa;AAAA,EAChD;AACD;","names":[]}
package/dist/index.mjs CHANGED
@@ -37,37 +37,40 @@ function npmToPnpm(str) {
37
37
 
38
38
  // src/npm2yarn2pnpm.ts
39
39
  import npmToYarn from "npm-to-yarn";
40
+ import visit from "unist-util-visit";
40
41
  var transformNode = (node, options) => {
41
- const groupIdProp = options.sync ? 'groupId="npm2yarn2pnpm" ' : "";
42
+ const groupIdProp = options.sync ? ' groupId="npm2yarn2pnpm"' : "";
42
43
  const npmCode = node.value;
43
44
  const yarnCode = npmToYarn(node.value, "yarn");
44
45
  const pnpmCode = npmToPnpm(node.value);
45
- const [, highlight] = node.meta.split("|");
46
+ const [, highlight] = (node.meta ?? "").split("|");
46
47
  return [
47
48
  {
48
49
  type: "jsx",
49
- value: `<Tabs defaultValue="npm" ${groupIdProp}values={[
50
- { label: 'npm', value: 'npm', },
51
- { label: 'yarn', value: 'yarn', },
52
- { label: 'pnpm', value: 'pnpm', },
53
- ]}
54
- >
50
+ value: `<Tabs${groupIdProp}
51
+ defaultValue="npm"
52
+ values={[
53
+ { label: "npm", value: "npm" },
54
+ { label: "yarn", value: "yarn" },
55
+ { label: "pnpm", value: "pnpm" },
56
+ ]}
57
+ >
55
58
  <TabItem value="npm">`
56
59
  },
57
60
  {
58
61
  type: node.type,
59
62
  lang: node.lang,
60
- meta: highlight,
63
+ meta: `${highlight} showLineNumbers`,
61
64
  value: npmCode
62
65
  },
63
66
  {
64
67
  type: "jsx",
65
- value: '</TabItem>\n<TabItem value="yarn">'
68
+ value: '</TabItem>\n<TabItem value="yarn" label="Yarn">'
66
69
  },
67
70
  {
68
71
  type: node.type,
69
72
  lang: node.lang,
70
- meta: highlight,
73
+ meta: `${highlight} showLineNumbers`,
71
74
  value: yarnCode
72
75
  },
73
76
  {
@@ -77,7 +80,7 @@ var transformNode = (node, options) => {
77
80
  {
78
81
  type: node.type,
79
82
  lang: node.lang,
80
- meta: highlight,
83
+ meta: `${highlight} showLineNumbers`,
81
84
  value: pnpmCode
82
85
  },
83
86
  {
@@ -86,41 +89,39 @@ var transformNode = (node, options) => {
86
89
  }
87
90
  ];
88
91
  };
89
- var matchNode = (node) => node.type === "code" && typeof node.meta === "string" && node.meta.startsWith("npm2yarn2pnpm");
92
+ var isImport = (node) => node.type === "import";
93
+ var isParent = (node) => Array.isArray(node.children);
94
+ var matchNode = (node) => node.type === "code" && typeof node.meta === "string" && (node.meta ?? "").startsWith("npm2yarn2pnpm");
90
95
  var nodeForImport = {
91
96
  type: "import",
92
97
  value: "import Tabs from '@theme/Tabs';\nimport TabItem from '@theme/TabItem';"
93
98
  };
94
- function npm2yarn2pnpm({ sync = true } = { sync: true }) {
99
+ var npm2yarn2pnpm = ({ sync = true } = { sync: true }) => (root) => {
95
100
  let transformed = false;
96
101
  let alreadyImported = false;
97
- const transformer = (node) => {
98
- if (node.type === "import" && node.value.includes("@theme/Tabs")) {
102
+ visit(root, (node) => {
103
+ if (isImport(node) && node.value.includes("@theme/Tabs")) {
99
104
  alreadyImported = true;
100
105
  }
101
- if (matchNode(node)) {
102
- transformed = true;
103
- return transformNode(node, { sync });
104
- }
105
- if (Array.isArray(node.children)) {
106
+ if (isParent(node)) {
106
107
  let index = 0;
107
108
  while (index < node.children.length) {
108
- const result = transformer(node.children[index]);
109
- if (result) {
109
+ const child = node.children[index];
110
+ if (matchNode(child)) {
111
+ const result = transformNode(child, { sync });
110
112
  node.children.splice(index, 1, ...result);
111
113
  index += result.length;
114
+ transformed = true;
112
115
  } else {
113
116
  index += 1;
114
117
  }
115
118
  }
116
119
  }
117
- if (node.type === "root" && transformed && !alreadyImported) {
118
- node.children.unshift(nodeForImport);
119
- }
120
- return null;
121
- };
122
- return transformer;
123
- }
120
+ });
121
+ if (transformed && !alreadyImported) {
122
+ root.children.unshift(nodeForImport);
123
+ }
124
+ };
124
125
  export {
125
126
  npm2yarn2pnpm,
126
127
  npmToPnpm
@@ -1 +1 @@
1
- {"version":3,"sources":["../src/npm2pnpm.ts","../src/npm2yarn2pnpm.ts"],"sourcesContent":["/**\n * Copyright (c) 2019 Ben Gubler <nebrelbug@gmail.com>\n *\n * This source code is licensed under the MIT license found in the\n * LICENSE file in the root directory of this source tree.\n */\n\nconst unchangedCLICommands = ['init', 'run', 'test', 'login', 'logout', 'link', 'publish', 'cache'];\n\nconst npmToPnpmTable = {\n\tinstall(command: string) {\n\t\tif (/^install *$/.test(command)) {\n\t\t\treturn 'install';\n\t\t}\n\n\t\treturn command\n\t\t\t.replace('install', 'add')\n\t\t\t.replace(/\\s*--save/, '--save-prod')\n\t\t\t.replace('--no-package-lock', '');\n\t},\n\n\tuninstall(command: string) {\n\t\treturn command\n\t\t\t.replace('uninstall', 'remove')\n\t\t\t.replace(/\\s*--save/, '--save-prod')\n\t\t\t.replace('--no-package-lock', '');\n\t},\n\n\tversion(command: string) {\n\t\treturn command.replace(/(major|minor|patch)/, '--$1');\n\t},\n\n\trebuild(command: string) {\n\t\treturn command.replace('rebuild', 'add --force');\n\t}\n} as const;\n\nfunction convert(_: string, command: string) {\n\tcommand = (command ?? '').trim();\n\n\tconst firstCommand = (/\\w+/.exec(command) || [''])[0] as keyof typeof npmToPnpmTable;\n\n\tif (unchangedCLICommands.includes(firstCommand)) {\n\t\treturn `pnpm ${command}`;\n\t} else if (Object.prototype.hasOwnProperty.call(npmToPnpmTable, firstCommand) && npmToPnpmTable[firstCommand]) {\n\t\tif (typeof npmToPnpmTable[firstCommand] === 'function') {\n\t\t\treturn `pnpm ${npmToPnpmTable[firstCommand](command)}`;\n\t\t}\n\t\treturn `pnpm ${command.replace(firstCommand, npmToPnpmTable[firstCommand])}`;\n\t}\n\n\treturn `pnpm ${command}\\n# couldn't auto-convert command`;\n}\n\nexport function npmToPnpm(str: string) {\n\treturn str.replace(/npm(?: +([^&\\n\\r]*))?/gm, convert);\n}\n","import npmToYarn from 'npm-to-yarn';\nimport { npmToPnpm } from './npm2pnpm';\n\nconst transformNode = (node: any, options: PluginOptions) => {\n\tconst groupIdProp = options.sync ? 'groupId=\"npm2yarn2pnpm\" ' : '';\n\tconst npmCode = node.value;\n\n\tconst yarnCode = npmToYarn(node.value, 'yarn');\n\tconst pnpmCode = npmToPnpm(node.value);\n\n\tconst [, highlight] = node.meta.split('|');\n\n\treturn [\n\t\t{\n\t\t\ttype: 'jsx',\n\t\t\tvalue:\n\t\t\t\t`<Tabs defaultValue=\"npm\" ${groupIdProp}` +\n\t\t\t\t`values={[\n { label: 'npm', value: 'npm', },\n { label: 'yarn', value: 'yarn', },\n { label: 'pnpm', value: 'pnpm', },\n ]}\n>\n<TabItem value=\"npm\">`\n\t\t},\n\t\t{\n\t\t\ttype: node.type,\n\t\t\tlang: node.lang,\n\t\t\tmeta: highlight,\n\t\t\tvalue: npmCode\n\t\t},\n\t\t{\n\t\t\ttype: 'jsx',\n\t\t\tvalue: '</TabItem>\\n<TabItem value=\"yarn\">'\n\t\t},\n\t\t{\n\t\t\ttype: node.type,\n\t\t\tlang: node.lang,\n\t\t\tmeta: highlight,\n\t\t\tvalue: yarnCode\n\t\t},\n\t\t{\n\t\t\ttype: 'jsx',\n\t\t\tvalue: '</TabItem>\\n<TabItem value=\"pnpm\">'\n\t\t},\n\t\t{\n\t\t\ttype: node.type,\n\t\t\tlang: node.lang,\n\t\t\tmeta: highlight,\n\t\t\tvalue: pnpmCode\n\t\t},\n\t\t{\n\t\t\ttype: 'jsx',\n\t\t\tvalue: '</TabItem>\\n</Tabs>'\n\t\t}\n\t];\n};\n\nconst matchNode = (node: any) => node.type === 'code' && typeof node.meta === 'string' && node.meta.startsWith('npm2yarn2pnpm');\nconst nodeForImport = {\n\ttype: 'import',\n\tvalue: \"import Tabs from '@theme/Tabs';\\nimport TabItem from '@theme/TabItem';\"\n};\n\nexport interface PluginOptions {\n\tsync?: boolean;\n}\n\nexport function npm2yarn2pnpm({ sync = true }: PluginOptions = { sync: true }) {\n\tlet transformed = false;\n\tlet alreadyImported = false;\n\n\tconst transformer = (node: any) => {\n\t\tif (node.type === 'import' && node.value.includes('@theme/Tabs')) {\n\t\t\talreadyImported = true;\n\t\t}\n\n\t\tif (matchNode(node)) {\n\t\t\ttransformed = true;\n\t\t\treturn transformNode(node, { sync });\n\t\t}\n\n\t\tif (Array.isArray(node.children)) {\n\t\t\tlet index = 0;\n\t\t\twhile (index < node.children.length) {\n\t\t\t\tconst result = transformer(node.children[index]);\n\t\t\t\tif (result) {\n\t\t\t\t\tnode.children.splice(index, 1, ...result);\n\t\t\t\t\tindex += result.length;\n\t\t\t\t} else {\n\t\t\t\t\tindex += 1;\n\t\t\t\t}\n\t\t\t}\n\t\t}\n\n\t\tif (node.type === 'root' && transformed && !alreadyImported) {\n\t\t\tnode.children.unshift(nodeForImport);\n\t\t}\n\n\t\treturn null;\n\t};\n\n\treturn transformer;\n}\n"],"mappings":";AAOA,IAAM,uBAAuB,CAAC,QAAQ,OAAO,QAAQ,SAAS,UAAU,QAAQ,WAAW,OAAO;AAElG,IAAM,iBAAiB;AAAA,EACtB,QAAQ,SAAiB;AACxB,QAAI,cAAc,KAAK,OAAO,GAAG;AAChC,aAAO;AAAA,IACR;AAEA,WAAO,QACL,QAAQ,WAAW,KAAK,EACxB,QAAQ,aAAa,aAAa,EAClC,QAAQ,qBAAqB,EAAE;AAAA,EAClC;AAAA,EAEA,UAAU,SAAiB;AAC1B,WAAO,QACL,QAAQ,aAAa,QAAQ,EAC7B,QAAQ,aAAa,aAAa,EAClC,QAAQ,qBAAqB,EAAE;AAAA,EAClC;AAAA,EAEA,QAAQ,SAAiB;AACxB,WAAO,QAAQ,QAAQ,uBAAuB,MAAM;AAAA,EACrD;AAAA,EAEA,QAAQ,SAAiB;AACxB,WAAO,QAAQ,QAAQ,WAAW,aAAa;AAAA,EAChD;AACD;AAEA,iBAAiB,GAAW,SAAiB;AAC5C,YAAW,YAAW,IAAI,KAAK;AAE/B,QAAM,eAAgB,OAAM,KAAK,OAAO,KAAK,CAAC,EAAE,GAAG;AAEnD,MAAI,qBAAqB,SAAS,YAAY,GAAG;AAChD,WA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OAAO,KAAK,SAAS,YAAY,KAAK,KAAK,WAAW,eAAe;AAC9H,IAAM,gBAAgB;AAAA,EACrB,MAAM;AAAA,EACN,OAAO;AACR;AAMO,uBAAuB,EAAE,OAAO,SAAwB,EAAE,MAAM,KAAK,GAAG;AAC9E,MAAI,cAAc;AAClB,MAAI,kBAAkB;AAEtB,QAAM,cAAc,CAAC,SAAc;AAClC,QAAI,KAAK,SAAS,YAAY,KAAK,MAAM,SAAS,aAAa,GAAG;AACjE,wBAAkB;AAAA,IACnB;AAEA,QAAI,UAAU,IAAI,GAAG;AACpB,oBAAc;AACd,aAAO,cAAc,MAAM,EAAE,KAAK,CAAC;AAAA,IACpC;AAEA,QAAI,MAAM,QAAQ,KAAK,QAAQ,GAAG;AACjC,UAAI,QAAQ;AACZ,aAAO,QAAQ,KAAK,SAAS,QAAQ;AACpC,cAAM,SAAS,YAAY,KAAK,SAAS,MAAM;AAC/C,YAAI,QAAQ;AACX,eAAK,SAAS,OAAO,OAAO,GAAG,GAAG,MAAM;AACxC,mBAAS,OAAO;AAAA,QACjB,OAAO;AACN,mBAAS;AAAA,QACV;AAAA,MACD;AAAA,IACD;AAEA,QAAI,KAAK,SAAS,UAAU,eAAe,CAAC,iBAAiB;AAC5D,WAAK,SAAS,QAAQ,aAAa;AAAA,IACpC;AAEA,WAAO;AAAA,EACR;AAEA,SAAO;AACR;","names":[]}
1
+ {"version":3,"sources":["../src/npm2pnpm.ts","../src/npm2yarn2pnpm.ts"],"sourcesContent":["/**\n * Copyright (c) 2019 Ben Gubler <nebrelbug@gmail.com>\n *\n * This source code is licensed under the MIT license found in the\n * LICENSE file in the root directory of this source tree.\n */\n\nconst unchangedCLICommands = ['init', 'run', 'test', 'login', 'logout', 'link', 'publish', 'cache'];\n\nconst npmToPnpmTable = {\n\tinstall(command: string) {\n\t\tif (/^install *$/.test(command)) {\n\t\t\treturn 'install';\n\t\t}\n\n\t\treturn command\n\t\t\t.replace('install', 'add')\n\t\t\t.replace(/\\s*--save/, '--save-prod')\n\t\t\t.replace('--no-package-lock', '');\n\t},\n\n\tuninstall(command: string) {\n\t\treturn command\n\t\t\t.replace('uninstall', 'remove')\n\t\t\t.replace(/\\s*--save/, '--save-prod')\n\t\t\t.replace('--no-package-lock', '');\n\t},\n\n\tversion(command: string) {\n\t\treturn command.replace(/(major|minor|patch)/, '--$1');\n\t},\n\n\trebuild(command: string) {\n\t\treturn command.replace('rebuild', 'add --force');\n\t}\n} as const;\n\nfunction convert(_: string, command: string) {\n\tcommand = (command ?? '').trim();\n\n\tconst firstCommand = (/\\w+/.exec(command) || [''])[0] as keyof typeof npmToPnpmTable;\n\n\tif (unchangedCLICommands.includes(firstCommand)) {\n\t\treturn `pnpm ${command}`;\n\t} else if (Object.prototype.hasOwnProperty.call(npmToPnpmTable, firstCommand) && npmToPnpmTable[firstCommand]) {\n\t\tif (typeof npmToPnpmTable[firstCommand] === 'function') {\n\t\t\treturn `pnpm ${npmToPnpmTable[firstCommand](command)}`;\n\t\t}\n\t\treturn `pnpm ${command.replace(firstCommand, npmToPnpmTable[firstCommand])}`;\n\t}\n\n\treturn `pnpm ${command}\\n# couldn't auto-convert command`;\n}\n\nexport function npmToPnpm(str: string) {\n\treturn str.replace(/npm(?: +([^&\\n\\r]*))?/gm, convert);\n}\n","import type { Code, Content, Literal } from 'mdast';\nimport npmToYarn from 'npm-to-yarn';\nimport type { Plugin } from 'unified';\nimport type { Node, Parent } from 'unist';\nimport visit from 'unist-util-visit';\nimport { npmToPnpm } from './npm2pnpm';\n\n/**\n * Transforms a Docusaurus node from NPM to Yarn and Pnpm\n * @param node The Docusaurus node to transform\n * @param options The plugin options to pass to the transformer\n * @returns The transformed node in the form of Tabs.\n */\nconst transformNode = (node: Code, options: PluginOptions) => {\n\tconst groupIdProp = options.sync ? ' groupId=\"npm2yarn2pnpm\"' : '';\n\tconst npmCode = node.value;\n\n\tconst yarnCode = npmToYarn(node.value, 'yarn');\n\tconst pnpmCode = npmToPnpm(node.value);\n\n\tconst [, highlight] = (node.meta ?? '').split('|');\n\n\treturn [\n\t\t{\n\t\t\ttype: 'jsx',\n\t\t\tvalue: `<Tabs${groupIdProp}\n\t\t\t\t\t\tdefaultValue=\"npm\"\n\t\t\t\t\t\tvalues={[\n\t\t\t\t\t\t\t{ label: \"npm\", value: \"npm\" },\n\t\t\t\t\t\t\t{ label: \"yarn\", value: \"yarn\" },\n\t\t\t\t\t\t\t{ label: \"pnpm\", value: \"pnpm\" },\n\t\t\t\t\t\t]}\n\t\t\t>\\n<TabItem value=\"npm\">`\n\t\t},\n\t\t{\n\t\t\ttype: node.type,\n\t\t\tlang: node.lang,\n\t\t\tmeta: `${highlight} showLineNumbers`,\n\t\t\tvalue: npmCode\n\t\t},\n\t\t{\n\t\t\ttype: 'jsx',\n\t\t\tvalue: '</TabItem>\\n<TabItem value=\"yarn\" label=\"Yarn\">'\n\t\t},\n\t\t{\n\t\t\ttype: node.type,\n\t\t\tlang: node.lang,\n\t\t\tmeta: `${highlight} showLineNumbers`,\n\t\t\tvalue: yarnCode\n\t\t},\n\t\t{\n\t\t\ttype: 'jsx',\n\t\t\tvalue: '</TabItem>\\n<TabItem value=\"pnpm\">'\n\t\t},\n\t\t{\n\t\t\ttype: node.type,\n\t\t\tlang: node.lang,\n\t\t\tmeta: `${highlight} showLineNumbers`,\n\t\t\tvalue: pnpmCode\n\t\t},\n\t\t{\n\t\t\ttype: 'jsx',\n\t\t\tvalue: '</TabItem>\\n</Tabs>'\n\t\t}\n\t] as Content[];\n};\n\nconst isImport = (node: Node): node is Literal => node.type === 'import';\nconst isParent = (node: Node): node is Parent => Array.isArray((node as Parent).children);\nconst matchNode = (node: Node): node is Code =>\n\tnode.type === 'code' && typeof (node as Code).meta === 'string' && ((node as Code).meta ?? '').startsWith('npm2yarn2pnpm');\nconst nodeForImport: Literal = {\n\ttype: 'import',\n\tvalue: \"import Tabs from '@theme/Tabs';\\nimport TabItem from '@theme/TabItem';\"\n};\n\nexport interface PluginOptions {\n\tsync?: boolean;\n}\n\nexport const npm2yarn2pnpm: Plugin<[PluginOptions?]> =\n\t({ sync = true } = { sync: true }) =>\n\t(root) => {\n\t\tlet transformed = false;\n\t\tlet alreadyImported = false;\n\t\tvisit(root, (node: Node) => {\n\t\t\tif (isImport(node) && node.value.includes('@theme/Tabs')) {\n\t\t\t\talreadyImported = true;\n\t\t\t}\n\t\t\tif (isParent(node)) {\n\t\t\t\tlet index = 0;\n\t\t\t\twhile (index < node.children.length) {\n\t\t\t\t\tconst child = node.children[index]!;\n\t\t\t\t\tif (matchNode(child)) {\n\t\t\t\t\t\tconst result = transformNode(child, { sync });\n\t\t\t\t\t\tnode.children.splice(index, 1, ...result);\n\t\t\t\t\t\tindex += result.length;\n\t\t\t\t\t\ttransformed = true;\n\t\t\t\t\t} else {\n\t\t\t\t\t\tindex += 1;\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t}\n\t\t});\n\t\tif (transformed && !alreadyImported) {\n\t\t\t(root as Parent).children.unshift(nodeForImport);\n\t\t}\n\t};\n"],"mappings":";AAOA,IAAM,uBAAuB,CAAC,QAAQ,OAAO,QAAQ,SAAS,UAAU,QAAQ,WAAW,OAAO;AAElG,IAAM,iBAAiB;AAAA,EACtB,QAAQ,SAAiB;AACxB,QAAI,cAAc,KAAK,OAAO,GAAG;AAChC,aAAO;AAAA,IACR;AAEA,WAAO,QACL,QAAQ,WAAW,KAAK,EACxB,QAAQ,aAAa,aAAa,EAClC,QAAQ,qBAAqB,EAAE;AAAA,EAClC;AAAA,EAEA,UAAU,SAAiB;AAC1B,WAAO,QACL,QAAQ,aAAa,QAAQ,EAC7B,QAAQ,aAAa,aAAa,EAClC,QAAQ,qBAAqB,EAAE;AAAA,EAClC;AAAA,EAEA,QAAQ,SAAiB;AACxB,WAAO,QAAQ,QAAQ,uBAAuB,MAAM;AAAA,EACrD;AAAA,EAEA,QAAQ,SAAiB;AACxB,WAAO,QAAQ,QAAQ,WAAW,aAAa;AAAA,EAChD;AACD;AAEA,iBAAi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KAAK;AAAA,MACX,MAAM,KAAK;AAAA,MACX,MAAM,GAAG;AAAA,MACT,OAAO;AAAA,IACR;AAAA,IACA;AAAA,MACC,MAAM;AAAA,MACN,OAAO;AAAA,IACR;AAAA,EACD;AACD;AAEA,IAAM,WAAW,CAAC,SAAgC,KAAK,SAAS;AAChE,IAAM,WAAW,CAAC,SAA+B,MAAM,QAAS,KAAgB,QAAQ;AACxF,IAAM,YAAY,CAAC,SAClB,KAAK,SAAS,UAAU,OAAQ,KAAc,SAAS,YAAc,MAAc,QAAQ,IAAI,WAAW,eAAe;AAC1H,IAAM,gBAAyB;AAAA,EAC9B,MAAM;AAAA,EACN,OAAO;AACR;AAMO,IAAM,gBACZ,CAAC,EAAE,OAAO,SAAS,EAAE,MAAM,KAAK,MAChC,CAAC,SAAS;AACT,MAAI,cAAc;AAClB,MAAI,kBAAkB;AACtB,QAAM,MAAM,CAAC,SAAe;AAC3B,QAAI,SAAS,IAAI,KAAK,KAAK,MAAM,SAAS,aAAa,GAAG;AACzD,wBAAkB;AAAA,IACnB;AACA,QAAI,SAAS,IAAI,GAAG;AACnB,UAAI,QAAQ;AACZ,aAAO,QAAQ,KAAK,SAAS,QAAQ;AACpC,cAAM,QAAQ,KAAK,SAAS;AAC5B,YAAI,UAAU,KAAK,GAAG;AACrB,gBAAM,SAAS,cAAc,OAAO,EAAE,KAAK,CAAC;AAC5C,eAAK,SAAS,OAAO,OAAO,GAAG,GAAG,MAAM;AACxC,mBAAS,OAAO;AAChB,wBAAc;AAAA,QACf,OAAO;AACN,mBAAS;AAAA,QACV;AAAA,MACD;AAAA,IACD;AAAA,EACD,CAAC;AACD,MAAI,eAAe,CAAC,iBAAiB;AACpC,IAAC,KAAgB,SAAS,QAAQ,aAAa;AAAA,EAChD;AACD;","names":[]}
@@ -1,15 +1,6 @@
1
+ import type { Plugin } from 'unified';
1
2
  export interface PluginOptions {
2
3
  sync?: boolean;
3
4
  }
4
- export declare function npm2yarn2pnpm({ sync }?: PluginOptions): (node: any) => ({
5
- type: string;
6
- value: string;
7
- lang?: undefined;
8
- meta?: undefined;
9
- } | {
10
- type: any;
11
- lang: any;
12
- meta: any;
13
- value: any;
14
- })[] | null;
5
+ export declare const npm2yarn2pnpm: Plugin<[PluginOptions?]>;
15
6
  //# sourceMappingURL=npm2yarn2pnpm.d.ts.map
package/package.json CHANGED
@@ -1,57 +1,65 @@
1
1
  {
2
- "name": "@sapphire/docusaurus-plugin-npm2yarn2pnpm",
3
- "version": "1.1.0-next.fadcdcf.0",
4
- "description": "Docusaurus Remark plugin for converting NPM Commands to Yarn and Pnpm",
5
- "author": "@sapphire",
6
- "license": "MIT",
7
- "main": "dist/index.js",
8
- "module": "dist/index.mjs",
9
- "types": "dist/index.d.ts",
10
- "exports": {
11
- "import": "./dist/index.mjs",
12
- "require": "./dist/index.js",
13
- "types": "./dist/index.d.ts"
14
- },
15
- "scripts": {
16
- "lint": "eslint src --ext ts --fix",
17
- "build": "tsup && tsc -b src",
18
- "typecheck": "tsc -p tsconfig.eslint.json",
19
- "prepublishOnly": "yarn build"
20
- },
21
- "dependencies": {
22
- "npm-to-yarn": "^1.0.1"
23
- },
24
- "repository": {
25
- "type": "git",
26
- "url": "git+https://github.com/sapphiredev/documentation-plugins.git",
27
- "directory": "packages/ts2esm2cjs"
28
- },
29
- "files": [
30
- "dist",
31
- "!dist/*.tsbuildinfo"
32
- ],
33
- "engines": {
34
- "node": ">=v16.6.0",
35
- "npm": ">=7.0.0"
36
- },
37
- "keywords": [
38
- "docusaurus",
39
- "docusaurus-plugin",
40
- "@sapphire",
41
- "typescript",
42
- "ts",
43
- "esm",
44
- "cjs",
45
- "discord",
46
- "sapphire",
47
- "discordjs"
48
- ],
49
- "bugs": {
50
- "url": "https://github.com/sapphiredev/documentation-plugins/issues"
51
- },
52
- "homepage": "https://www.sapphirejs.dev",
53
- "publishConfig": {
54
- "access": "public"
55
- },
56
- "gitHead": "fadcdcf55888e1a82c04a626c9572fd228bdbfd8"
57
- }
2
+ "name": "@sapphire/docusaurus-plugin-npm2yarn2pnpm",
3
+ "version": "1.1.0",
4
+ "description": "Docusaurus Remark plugin for converting NPM Commands to Yarn and Pnpm",
5
+ "author": "@sapphire",
6
+ "license": "MIT",
7
+ "main": "dist/index.js",
8
+ "module": "dist/index.mjs",
9
+ "types": "dist/index.d.ts",
10
+ "exports": {
11
+ "import": "./dist/index.mjs",
12
+ "require": "./dist/index.js",
13
+ "types": "./dist/index.d.ts"
14
+ },
15
+ "sideEffects": false,
16
+ "scripts": {
17
+ "lint": "eslint src --ext ts --fix",
18
+ "build": "tsup && tsc -b src",
19
+ "typecheck": "tsc -p tsconfig.eslint.json",
20
+ "prepack": "yarn build",
21
+ "bump": "cliff-jumper",
22
+ "check-update": "cliff-jumper --dry-run"
23
+ },
24
+ "dependencies": {
25
+ "npm-to-yarn": "^1.0.1",
26
+ "unist-util-visit": "^2.0.3"
27
+ },
28
+ "repository": {
29
+ "type": "git",
30
+ "url": "git+https://github.com/sapphiredev/documentation-plugins.git",
31
+ "directory": "packages/ts2esm2cjs"
32
+ },
33
+ "files": [
34
+ "dist/**/*.js*",
35
+ "dist/**/*.mjs*",
36
+ "dist/**/*.d*"
37
+ ],
38
+ "engines": {
39
+ "node": ">=v16.6.0",
40
+ "npm": ">=7.0.0"
41
+ },
42
+ "keywords": [
43
+ "docusaurus",
44
+ "docusaurus-plugin",
45
+ "@sapphire",
46
+ "typescript",
47
+ "ts",
48
+ "esm",
49
+ "cjs",
50
+ "discord",
51
+ "sapphire",
52
+ "discordjs"
53
+ ],
54
+ "bugs": {
55
+ "url": "https://github.com/sapphiredev/documentation-plugins/issues"
56
+ },
57
+ "homepage": "https://www.sapphirejs.dev",
58
+ "publishConfig": {
59
+ "access": "public"
60
+ },
61
+ "devDependencies": {
62
+ "tsup": "^5.12.7",
63
+ "typescript": "^4.6.4"
64
+ }
65
+ }
package/LICENSE.md DELETED
@@ -1,24 +0,0 @@
1
- # The MIT License (MIT)
2
-
3
- Copyright © `2021` `The Sapphire Community and its contributors`
4
-
5
- Permission is hereby granted, free of charge, to any person
6
- obtaining a copy of this software and associated documentation
7
- files (the “Software”), to deal in the Software without
8
- restriction, including without limitation the rights to use,
9
- copy, modify, merge, publish, distribute, sublicense, and/or sell
10
- copies of the Software, and to permit persons to whom the
11
- Software is furnished to do so, subject to the following
12
- conditions:
13
-
14
- The above copyright notice and this permission notice shall be
15
- included in all copies or substantial portions of the Software.
16
-
17
- THE SOFTWARE IS PROVIDED “AS IS”, WITHOUT WARRANTY OF ANY KIND,
18
- EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES
19
- OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
20
- NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
21
- HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
22
- WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
23
- FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
24
- OTHER DEALINGS IN THE SOFTWARE.
@@ -1 +0,0 @@
1
- {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,SAAS,EAAE,MAAM,YAAY,CAAC;AACvC,OAAO,EAAE,aAAa,EAAE,aAAa,EAAE,MAAM,iBAAiB,CAAC"}
@@ -1 +0,0 @@
1
- {"version":3,"file":"npm2pnpm.d.ts","sourceRoot":"","sources":["../src/npm2pnpm.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AAiDH,wBAAgB,SAAS,CAAC,GAAG,EAAE,MAAM,UAEpC"}
@@ -1 +0,0 @@
1
- {"version":3,"file":"npm2yarn2pnpm.d.ts","sourceRoot":"","sources":["../src/npm2yarn2pnpm.ts"],"names":[],"mappings":"AAgEA,MAAM,WAAW,aAAa;IAC7B,IAAI,CAAC,EAAE,OAAO,CAAC;CACf;AAED,wBAAgB,aAAa,CAAC,EAAE,IAAW,EAAE,GAAE,aAA8B,UAIjD,GAAG;;;;;;;;;;YA+B9B"}