@sapphire/docusaurus-plugin-npm2yarn2pnpm 1.0.1 → 1.0.2-next.10cd117.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/dist/index.js +164 -7
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +127 -4
- package/dist/index.mjs.map +1 -0
- package/package.json +11 -12
- package/dist/index.d.ts.map +0 -1
- package/dist/npm2pnpm.d.ts.map +0 -1
- package/dist/npm2pnpm.js +0 -52
- package/dist/npm2pnpm.js.map +0 -1
- package/dist/npm2yarn2pnpm.d.ts.map +0 -1
- package/dist/npm2yarn2pnpm.js +0 -94
- package/dist/npm2yarn2pnpm.js.map +0 -1
package/dist/index.js
CHANGED
|
@@ -1,8 +1,165 @@
|
|
|
1
|
-
|
|
2
|
-
Object.defineProperty
|
|
3
|
-
|
|
4
|
-
var
|
|
5
|
-
|
|
6
|
-
var
|
|
7
|
-
|
|
1
|
+
var __create = Object.create;
|
|
2
|
+
var __defProp = Object.defineProperty;
|
|
3
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
4
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
5
|
+
var __getProtoOf = Object.getPrototypeOf;
|
|
6
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
7
|
+
var __markAsModule = (target) => __defProp(target, "__esModule", { value: true });
|
|
8
|
+
var __export = (target, all) => {
|
|
9
|
+
for (var name in all)
|
|
10
|
+
__defProp(target, name, { get: all[name], enumerable: true });
|
|
11
|
+
};
|
|
12
|
+
var __reExport = (target, module2, copyDefault, desc) => {
|
|
13
|
+
if (module2 && typeof module2 === "object" || typeof module2 === "function") {
|
|
14
|
+
for (let key of __getOwnPropNames(module2))
|
|
15
|
+
if (!__hasOwnProp.call(target, key) && (copyDefault || key !== "default"))
|
|
16
|
+
__defProp(target, key, { get: () => module2[key], enumerable: !(desc = __getOwnPropDesc(module2, key)) || desc.enumerable });
|
|
17
|
+
}
|
|
18
|
+
return target;
|
|
19
|
+
};
|
|
20
|
+
var __toESM = (module2, isNodeMode) => {
|
|
21
|
+
return __reExport(__markAsModule(__defProp(module2 != null ? __create(__getProtoOf(module2)) : {}, "default", !isNodeMode && module2 && module2.__esModule ? { get: () => module2.default, enumerable: true } : { value: module2, enumerable: true })), module2);
|
|
22
|
+
};
|
|
23
|
+
var __toCommonJS = /* @__PURE__ */ ((cache) => {
|
|
24
|
+
return (module2, temp) => {
|
|
25
|
+
return cache && cache.get(module2) || (temp = __reExport(__markAsModule({}), module2, 1), cache && cache.set(module2, temp), temp);
|
|
26
|
+
};
|
|
27
|
+
})(typeof WeakMap !== "undefined" ? /* @__PURE__ */ new WeakMap() : 0);
|
|
28
|
+
|
|
29
|
+
// src/index.ts
|
|
30
|
+
var src_exports = {};
|
|
31
|
+
__export(src_exports, {
|
|
32
|
+
npm2yarn2pnpm: () => npm2yarn2pnpm,
|
|
33
|
+
npmToPnpm: () => npmToPnpm
|
|
34
|
+
});
|
|
35
|
+
|
|
36
|
+
// src/npm2pnpm.ts
|
|
37
|
+
var unchangedCLICommands = ["init", "run", "test", "login", "logout", "link", "publish", "cache"];
|
|
38
|
+
var npmToPnpmTable = {
|
|
39
|
+
install(command) {
|
|
40
|
+
if (/^install *$/.test(command)) {
|
|
41
|
+
return "install";
|
|
42
|
+
}
|
|
43
|
+
return command.replace("install", "add").replace(/\s*--save/, "--save-prod").replace("--no-package-lock", "");
|
|
44
|
+
},
|
|
45
|
+
uninstall(command) {
|
|
46
|
+
return command.replace("uninstall", "remove").replace(/\s*--save/, "--save-prod").replace("--no-package-lock", "");
|
|
47
|
+
},
|
|
48
|
+
version(command) {
|
|
49
|
+
return command.replace(/(major|minor|patch)/, "--$1");
|
|
50
|
+
},
|
|
51
|
+
rebuild(command) {
|
|
52
|
+
return command.replace("rebuild", "add --force");
|
|
53
|
+
}
|
|
54
|
+
};
|
|
55
|
+
function convert(_, command) {
|
|
56
|
+
command = (command ?? "").trim();
|
|
57
|
+
const firstCommand = (/\w+/.exec(command) || [""])[0];
|
|
58
|
+
if (unchangedCLICommands.includes(firstCommand)) {
|
|
59
|
+
return `pnpm ${command}`;
|
|
60
|
+
} else if (Object.prototype.hasOwnProperty.call(npmToPnpmTable, firstCommand) && npmToPnpmTable[firstCommand]) {
|
|
61
|
+
if (typeof npmToPnpmTable[firstCommand] === "function") {
|
|
62
|
+
return `pnpm ${npmToPnpmTable[firstCommand](command)}`;
|
|
63
|
+
}
|
|
64
|
+
return `pnpm ${command.replace(firstCommand, npmToPnpmTable[firstCommand])}`;
|
|
65
|
+
}
|
|
66
|
+
return `pnpm ${command}
|
|
67
|
+
# couldn't auto-convert command`;
|
|
68
|
+
}
|
|
69
|
+
function npmToPnpm(str) {
|
|
70
|
+
return str.replace(/npm(?: +([^&\n\r]*))?/gm, convert);
|
|
71
|
+
}
|
|
72
|
+
|
|
73
|
+
// src/npm2yarn2pnpm.ts
|
|
74
|
+
var import_npm_to_yarn = __toESM(require("npm-to-yarn"));
|
|
75
|
+
var transformNode = (node, options) => {
|
|
76
|
+
const groupIdProp = options.sync ? 'groupId="npm2yarn2pnpm" ' : "";
|
|
77
|
+
const npmCode = node.value;
|
|
78
|
+
const yarnCode = (0, import_npm_to_yarn.default)(node.value, "yarn");
|
|
79
|
+
const pnpmCode = npmToPnpm(node.value);
|
|
80
|
+
const [, highlight] = node.meta.split("|");
|
|
81
|
+
return [
|
|
82
|
+
{
|
|
83
|
+
type: "jsx",
|
|
84
|
+
value: `<Tabs defaultValue="npm" ${groupIdProp}values={[
|
|
85
|
+
{ label: 'npm', value: 'npm', },
|
|
86
|
+
{ label: 'yarn', value: 'yarn', },
|
|
87
|
+
{ label: 'pnpm', value: 'pnpm', },
|
|
88
|
+
]}
|
|
89
|
+
>
|
|
90
|
+
<TabItem value="npm">`
|
|
91
|
+
},
|
|
92
|
+
{
|
|
93
|
+
type: node.type,
|
|
94
|
+
lang: node.lang,
|
|
95
|
+
meta: highlight,
|
|
96
|
+
value: npmCode
|
|
97
|
+
},
|
|
98
|
+
{
|
|
99
|
+
type: "jsx",
|
|
100
|
+
value: '</TabItem>\n<TabItem value="yarn">'
|
|
101
|
+
},
|
|
102
|
+
{
|
|
103
|
+
type: node.type,
|
|
104
|
+
lang: node.lang,
|
|
105
|
+
meta: highlight,
|
|
106
|
+
value: yarnCode
|
|
107
|
+
},
|
|
108
|
+
{
|
|
109
|
+
type: "jsx",
|
|
110
|
+
value: '</TabItem>\n<TabItem value="pnpm">'
|
|
111
|
+
},
|
|
112
|
+
{
|
|
113
|
+
type: node.type,
|
|
114
|
+
lang: node.lang,
|
|
115
|
+
meta: highlight,
|
|
116
|
+
value: pnpmCode
|
|
117
|
+
},
|
|
118
|
+
{
|
|
119
|
+
type: "jsx",
|
|
120
|
+
value: "</TabItem>\n</Tabs>"
|
|
121
|
+
}
|
|
122
|
+
];
|
|
123
|
+
};
|
|
124
|
+
var matchNode = (node) => node.type === "code" && typeof node.meta === "string" && node.meta.startsWith("npm2yarn2pnpm");
|
|
125
|
+
var nodeForImport = {
|
|
126
|
+
type: "import",
|
|
127
|
+
value: "import Tabs from '@theme/Tabs';\nimport TabItem from '@theme/TabItem';"
|
|
128
|
+
};
|
|
129
|
+
function npm2yarn2pnpm({ sync = true } = { sync: true }) {
|
|
130
|
+
let transformed = false;
|
|
131
|
+
let alreadyImported = false;
|
|
132
|
+
const transformer = (node) => {
|
|
133
|
+
if (node.type === "import" && node.value.includes("@theme/Tabs")) {
|
|
134
|
+
alreadyImported = true;
|
|
135
|
+
}
|
|
136
|
+
if (matchNode(node)) {
|
|
137
|
+
transformed = true;
|
|
138
|
+
return transformNode(node, { sync });
|
|
139
|
+
}
|
|
140
|
+
if (Array.isArray(node.children)) {
|
|
141
|
+
let index = 0;
|
|
142
|
+
while (index < node.children.length) {
|
|
143
|
+
const result = transformer(node.children[index]);
|
|
144
|
+
if (result) {
|
|
145
|
+
node.children.splice(index, 1, ...result);
|
|
146
|
+
index += result.length;
|
|
147
|
+
} else {
|
|
148
|
+
index += 1;
|
|
149
|
+
}
|
|
150
|
+
}
|
|
151
|
+
}
|
|
152
|
+
if (node.type === "root" && transformed && !alreadyImported) {
|
|
153
|
+
node.children.unshift(nodeForImport);
|
|
154
|
+
}
|
|
155
|
+
return null;
|
|
156
|
+
};
|
|
157
|
+
return transformer;
|
|
158
|
+
}
|
|
159
|
+
module.exports = __toCommonJS(src_exports);
|
|
160
|
+
// Annotate the CommonJS export names for ESM import in node:
|
|
161
|
+
0 && (module.exports = {
|
|
162
|
+
npm2yarn2pnpm,
|
|
163
|
+
npmToPnpm
|
|
164
|
+
});
|
|
8
165
|
//# sourceMappingURL=index.js.map
|
package/dist/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"
|
|
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;;;ACOA,IAAM,uBAAuB,CAAC,QAAQ,OAAO,QAAQ,SAAS,UA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A;AAGR,SAAO;AAAA;","names":[]}
|
package/dist/index.mjs
CHANGED
|
@@ -1,5 +1,128 @@
|
|
|
1
|
-
|
|
1
|
+
// src/npm2pnpm.ts
|
|
2
|
+
var unchangedCLICommands = ["init", "run", "test", "login", "logout", "link", "publish", "cache"];
|
|
3
|
+
var npmToPnpmTable = {
|
|
4
|
+
install(command) {
|
|
5
|
+
if (/^install *$/.test(command)) {
|
|
6
|
+
return "install";
|
|
7
|
+
}
|
|
8
|
+
return command.replace("install", "add").replace(/\s*--save/, "--save-prod").replace("--no-package-lock", "");
|
|
9
|
+
},
|
|
10
|
+
uninstall(command) {
|
|
11
|
+
return command.replace("uninstall", "remove").replace(/\s*--save/, "--save-prod").replace("--no-package-lock", "");
|
|
12
|
+
},
|
|
13
|
+
version(command) {
|
|
14
|
+
return command.replace(/(major|minor|patch)/, "--$1");
|
|
15
|
+
},
|
|
16
|
+
rebuild(command) {
|
|
17
|
+
return command.replace("rebuild", "add --force");
|
|
18
|
+
}
|
|
19
|
+
};
|
|
20
|
+
function convert(_, command) {
|
|
21
|
+
command = (command ?? "").trim();
|
|
22
|
+
const firstCommand = (/\w+/.exec(command) || [""])[0];
|
|
23
|
+
if (unchangedCLICommands.includes(firstCommand)) {
|
|
24
|
+
return `pnpm ${command}`;
|
|
25
|
+
} else if (Object.prototype.hasOwnProperty.call(npmToPnpmTable, firstCommand) && npmToPnpmTable[firstCommand]) {
|
|
26
|
+
if (typeof npmToPnpmTable[firstCommand] === "function") {
|
|
27
|
+
return `pnpm ${npmToPnpmTable[firstCommand](command)}`;
|
|
28
|
+
}
|
|
29
|
+
return `pnpm ${command.replace(firstCommand, npmToPnpmTable[firstCommand])}`;
|
|
30
|
+
}
|
|
31
|
+
return `pnpm ${command}
|
|
32
|
+
# couldn't auto-convert command`;
|
|
33
|
+
}
|
|
34
|
+
function npmToPnpm(str) {
|
|
35
|
+
return str.replace(/npm(?: +([^&\n\r]*))?/gm, convert);
|
|
36
|
+
}
|
|
2
37
|
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
38
|
+
// src/npm2yarn2pnpm.ts
|
|
39
|
+
import npmToYarn from "npm-to-yarn";
|
|
40
|
+
var transformNode = (node, options) => {
|
|
41
|
+
const groupIdProp = options.sync ? 'groupId="npm2yarn2pnpm" ' : "";
|
|
42
|
+
const npmCode = node.value;
|
|
43
|
+
const yarnCode = npmToYarn(node.value, "yarn");
|
|
44
|
+
const pnpmCode = npmToPnpm(node.value);
|
|
45
|
+
const [, highlight] = node.meta.split("|");
|
|
46
|
+
return [
|
|
47
|
+
{
|
|
48
|
+
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
|
+
>
|
|
55
|
+
<TabItem value="npm">`
|
|
56
|
+
},
|
|
57
|
+
{
|
|
58
|
+
type: node.type,
|
|
59
|
+
lang: node.lang,
|
|
60
|
+
meta: highlight,
|
|
61
|
+
value: npmCode
|
|
62
|
+
},
|
|
63
|
+
{
|
|
64
|
+
type: "jsx",
|
|
65
|
+
value: '</TabItem>\n<TabItem value="yarn">'
|
|
66
|
+
},
|
|
67
|
+
{
|
|
68
|
+
type: node.type,
|
|
69
|
+
lang: node.lang,
|
|
70
|
+
meta: highlight,
|
|
71
|
+
value: yarnCode
|
|
72
|
+
},
|
|
73
|
+
{
|
|
74
|
+
type: "jsx",
|
|
75
|
+
value: '</TabItem>\n<TabItem value="pnpm">'
|
|
76
|
+
},
|
|
77
|
+
{
|
|
78
|
+
type: node.type,
|
|
79
|
+
lang: node.lang,
|
|
80
|
+
meta: highlight,
|
|
81
|
+
value: pnpmCode
|
|
82
|
+
},
|
|
83
|
+
{
|
|
84
|
+
type: "jsx",
|
|
85
|
+
value: "</TabItem>\n</Tabs>"
|
|
86
|
+
}
|
|
87
|
+
];
|
|
88
|
+
};
|
|
89
|
+
var matchNode = (node) => node.type === "code" && typeof node.meta === "string" && node.meta.startsWith("npm2yarn2pnpm");
|
|
90
|
+
var nodeForImport = {
|
|
91
|
+
type: "import",
|
|
92
|
+
value: "import Tabs from '@theme/Tabs';\nimport TabItem from '@theme/TabItem';"
|
|
93
|
+
};
|
|
94
|
+
function npm2yarn2pnpm({ sync = true } = { sync: true }) {
|
|
95
|
+
let transformed = false;
|
|
96
|
+
let alreadyImported = false;
|
|
97
|
+
const transformer = (node) => {
|
|
98
|
+
if (node.type === "import" && node.value.includes("@theme/Tabs")) {
|
|
99
|
+
alreadyImported = true;
|
|
100
|
+
}
|
|
101
|
+
if (matchNode(node)) {
|
|
102
|
+
transformed = true;
|
|
103
|
+
return transformNode(node, { sync });
|
|
104
|
+
}
|
|
105
|
+
if (Array.isArray(node.children)) {
|
|
106
|
+
let index = 0;
|
|
107
|
+
while (index < node.children.length) {
|
|
108
|
+
const result = transformer(node.children[index]);
|
|
109
|
+
if (result) {
|
|
110
|
+
node.children.splice(index, 1, ...result);
|
|
111
|
+
index += result.length;
|
|
112
|
+
} else {
|
|
113
|
+
index += 1;
|
|
114
|
+
}
|
|
115
|
+
}
|
|
116
|
+
}
|
|
117
|
+
if (node.type === "root" && transformed && !alreadyImported) {
|
|
118
|
+
node.children.unshift(nodeForImport);
|
|
119
|
+
}
|
|
120
|
+
return null;
|
|
121
|
+
};
|
|
122
|
+
return transformer;
|
|
123
|
+
}
|
|
124
|
+
export {
|
|
125
|
+
npm2yarn2pnpm,
|
|
126
|
+
npmToPnpm
|
|
127
|
+
};
|
|
128
|
+
//# sourceMappingURL=index.mjs.map
|
|
@@ -0,0 +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;AAE3F,IAAM,iBAAiB;AAAA,EACtB,QAAQ,SAAiB;AACxB,QAAI,cAAc,KAAK,UAAU;AAChC,aAAO;AAAA;AAGR,WAAO,QACL,QAAQ,WAAW,OACnB,QAAQ,aAAa,eACrB,QAAQ,qBAAqB;AAAA;AAAA,EAGhC,UAAU,SAAiB;AAC1B,WAAO,QACL,QAAQ,aAAa,UACrB,QAAQ,aAAa,eACrB,QAAQ,qBAAqB;AAAA;AAAA,EAGhC,QAAQ,SAAiB;AACxB,WAAO,QAAQ,QAAQ,uBAAuB;AAAA;AAAA,EAG/C,QAAQ,SAAiB;AACxB,WAAO,QAAQ,QAAQ,WAAW;AAAA;AAAA;AAIpC,iBAAiB,GAAW,SAAiB;AAC5C,YAAW,YAAW,IAAI;AAE1B,QAAM,eAAgB,OAAM,KAAK,YAAY,CAAC,KAAK;AAEnD,MAAI,qBAAqB,SAAS,eAAe;AAChD,WAAO,QAAQ;AAAA,aACL,OAAO,UAAU,eAAe,KAAK,gBAAgB,iBAAiB,eAAe,eAAe;AAC9G,QAAI,OAAO,eAAe,kBAAkB,YAAY;AACvD,aAAO,QAAQ,eAAe,cAAc;AAAA;AAE7C,WAAO,QAAQ,QAAQ,QAAQ,cAAc,eAAe;AAAA;AAG7D,SAAO,QAAQ;AAA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U,OAAO;AACpB,oBAAc;AACd,aAAO,cAAc,MAAM,EAAE;AAAA;AAG9B,QAAI,MAAM,QAAQ,KAAK,WAAW;AACjC,UAAI,QAAQ;AACZ,aAAO,QAAQ,KAAK,SAAS,QAAQ;AACpC,cAAM,SAAS,YAAY,KAAK,SAAS;AACzC,YAAI,QAAQ;AACX,eAAK,SAAS,OAAO,OAAO,GAAG,GAAG;AAClC,mBAAS,OAAO;AAAA,eACV;AACN,mBAAS;AAAA;AAAA;AAAA;AAKZ,QAAI,KAAK,SAAS,UAAU,eAAe,CAAC,iBAAiB;AAC5D,WAAK,SAAS,QAAQ;AAAA;AAGvB,WAAO;AAAA;AAGR,SAAO;AAAA;","names":[]}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@sapphire/docusaurus-plugin-npm2yarn2pnpm",
|
|
3
|
-
"version": "1.0.
|
|
3
|
+
"version": "1.0.2-next.10cd117.0",
|
|
4
4
|
"description": "Docusaurus Remark plugin for converting NPM Commands to Yarn and Pnpm",
|
|
5
5
|
"author": "@sapphire",
|
|
6
6
|
"license": "MIT",
|
|
@@ -13,18 +13,20 @@
|
|
|
13
13
|
},
|
|
14
14
|
"scripts": {
|
|
15
15
|
"lint": "eslint src --ext ts --fix",
|
|
16
|
-
"build": "tsc -b src
|
|
17
|
-
"
|
|
18
|
-
"watch": "tsc -b src -w",
|
|
16
|
+
"build": "tsup && tsc -b src",
|
|
17
|
+
"typecheck": "tsc -p tsconfig.eslint.json",
|
|
19
18
|
"prepublishOnly": "yarn build"
|
|
20
19
|
},
|
|
21
20
|
"dependencies": {
|
|
22
|
-
"@sapphire/prettier-config": "^1.2.
|
|
21
|
+
"@sapphire/prettier-config": "^1.2.7",
|
|
23
22
|
"esm-to-cjs": "^1.2.0",
|
|
24
23
|
"npm-to-yarn": "^1.0.1",
|
|
25
|
-
"prettier": "^2.5.
|
|
26
|
-
"
|
|
27
|
-
|
|
24
|
+
"prettier": "^2.5.1",
|
|
25
|
+
"typescript": "^4.5.4"
|
|
26
|
+
},
|
|
27
|
+
"devDependencies": {
|
|
28
|
+
"eslint": "^8.5.0",
|
|
29
|
+
"tsup": "^5.11.6"
|
|
28
30
|
},
|
|
29
31
|
"repository": {
|
|
30
32
|
"type": "git",
|
|
@@ -58,8 +60,5 @@
|
|
|
58
60
|
"publishConfig": {
|
|
59
61
|
"access": "public"
|
|
60
62
|
},
|
|
61
|
-
"
|
|
62
|
-
"@types/prettier": "^2"
|
|
63
|
-
},
|
|
64
|
-
"gitHead": "bf8adb9091117077e24371f84fc5f0b2f064bc1f"
|
|
63
|
+
"gitHead": "10cd11787f5d219a61bb51754a6d36d6a8924624"
|
|
65
64
|
}
|
package/dist/index.d.ts.map
DELETED
|
@@ -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"}
|
package/dist/npm2pnpm.d.ts.map
DELETED
|
@@ -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"}
|
package/dist/npm2pnpm.js
DELETED
|
@@ -1,52 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
/**
|
|
3
|
-
* Copyright (c) 2019 Ben Gubler <nebrelbug@gmail.com>
|
|
4
|
-
*
|
|
5
|
-
* This source code is licensed under the MIT license found in the
|
|
6
|
-
* LICENSE file in the root directory of this source tree.
|
|
7
|
-
*/
|
|
8
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
9
|
-
exports.npmToPnpm = void 0;
|
|
10
|
-
const unchangedCLICommands = ['init', 'run', 'test', 'login', 'logout', 'link', 'publish', 'cache'];
|
|
11
|
-
const npmToPnpmTable = {
|
|
12
|
-
install(command) {
|
|
13
|
-
if (/^install *$/.test(command)) {
|
|
14
|
-
return 'install';
|
|
15
|
-
}
|
|
16
|
-
return command
|
|
17
|
-
.replace('install', 'add')
|
|
18
|
-
.replace(/\s*--save/, '--save-prod')
|
|
19
|
-
.replace('--no-package-lock', '');
|
|
20
|
-
},
|
|
21
|
-
uninstall(command) {
|
|
22
|
-
return command
|
|
23
|
-
.replace('uninstall', 'remove')
|
|
24
|
-
.replace(/\s*--save/, '--save-prod')
|
|
25
|
-
.replace('--no-package-lock', '');
|
|
26
|
-
},
|
|
27
|
-
version(command) {
|
|
28
|
-
return command.replace(/(major|minor|patch)/, '--$1');
|
|
29
|
-
},
|
|
30
|
-
rebuild(command) {
|
|
31
|
-
return command.replace('rebuild', 'add --force');
|
|
32
|
-
}
|
|
33
|
-
};
|
|
34
|
-
function convert(_, command) {
|
|
35
|
-
command = (command ?? '').trim();
|
|
36
|
-
const firstCommand = (/\w+/.exec(command) || [''])[0];
|
|
37
|
-
if (unchangedCLICommands.includes(firstCommand)) {
|
|
38
|
-
return `pnpm ${command}`;
|
|
39
|
-
}
|
|
40
|
-
else if (Object.prototype.hasOwnProperty.call(npmToPnpmTable, firstCommand) && npmToPnpmTable[firstCommand]) {
|
|
41
|
-
if (typeof npmToPnpmTable[firstCommand] === 'function') {
|
|
42
|
-
return `pnpm ${npmToPnpmTable[firstCommand](command)}`;
|
|
43
|
-
}
|
|
44
|
-
return `pnpm ${command.replace(firstCommand, npmToPnpmTable[firstCommand])}`;
|
|
45
|
-
}
|
|
46
|
-
return `pnpm ${command}\n# couldn't auto-convert command`;
|
|
47
|
-
}
|
|
48
|
-
function npmToPnpm(str) {
|
|
49
|
-
return str.replace(/npm(?: +([^&\n\r]*))?/gm, convert);
|
|
50
|
-
}
|
|
51
|
-
exports.npmToPnpm = npmToPnpm;
|
|
52
|
-
//# s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AC,CAAC,CAAgC,CAAC;IAErF,IAAI,oBAAoB,CAAC,QAAQ,CAAC,YAAY,CAAC,EAAE;QAChD,OAAO,QAAQ,OAAO,EAAE,CAAC;KACzB;SAAM,IAAI,MAAM,CAAC,SAAS,CAAC,cAAc,CAAC,IAAI,CAAC,cAAc,EAAE,YAAY,CAAC,IAAI,cAAc,CAAC,YAAY,CAAC,EAAE;QAC9G,IAAI,OAAO,cAAc,CAAC,YAAY,CAAC,KAAK,UAAU,EAAE;YACvD,OAAO,QAAQ,cAAc,CAAC,YAAY,CAAC,CAAC,OAAO,CAAC,EAAE,CAAC;SACvD;QACD,OAAO,QAAQ,OAAO,CAAC,OAAO,CAAC,YAAY,EAAE,cAAc,CAAC,YAAY,CAAC,CAAC,EAAE,CAAC;KAC7E;IAED,OAAO,QAAQ,OAAO,mCAAmC,CAAC;AAC3D,CAAC;AAED,SAAgB,SAAS,CAAC,GAAW;IACpC,OAAO,GAAG,CAAC,OAAO,CAAC,yBAAyB,EAAE,OAAO,CAAC,CAAC;AACxD,CAAC;AAFD,8BAEC"}
|
|
@@ -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"}
|
package/dist/npm2yarn2pnpm.js
DELETED
|
@@ -1,94 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.npm2yarn2pnpm = void 0;
|
|
4
|
-
const tslib_1 = require("tslib");
|
|
5
|
-
const npm_to_yarn_1 = (0, tslib_1.__importDefault)(require("npm-to-yarn"));
|
|
6
|
-
const npm2pnpm_1 = require("./npm2pnpm");
|
|
7
|
-
const transformNode = (node, options) => {
|
|
8
|
-
const groupIdProp = options.sync ? 'groupId="npm2yarn2pnpm" ' : '';
|
|
9
|
-
const npmCode = node.value;
|
|
10
|
-
const yarnCode = (0, npm_to_yarn_1.default)(node.value, 'yarn');
|
|
11
|
-
const pnpmCode = (0, npm2pnpm_1.npmToPnpm)(node.value);
|
|
12
|
-
const [, highlight] = node.meta.split('|');
|
|
13
|
-
return [
|
|
14
|
-
{
|
|
15
|
-
type: 'jsx',
|
|
16
|
-
value: `<Tabs defaultValue="npm" ${groupIdProp}` +
|
|
17
|
-
`values={[
|
|
18
|
-
{ label: 'npm', value: 'npm', },
|
|
19
|
-
{ label: 'yarn', value: 'yarn', },
|
|
20
|
-
{ label: 'pnpm', value: 'pnpm', },
|
|
21
|
-
]}
|
|
22
|
-
>
|
|
23
|
-
<TabItem value="npm">`
|
|
24
|
-
},
|
|
25
|
-
{
|
|
26
|
-
type: node.type,
|
|
27
|
-
lang: node.lang,
|
|
28
|
-
meta: highlight,
|
|
29
|
-
value: npmCode
|
|
30
|
-
},
|
|
31
|
-
{
|
|
32
|
-
type: 'jsx',
|
|
33
|
-
value: '</TabItem>\n<TabItem value="yarn">'
|
|
34
|
-
},
|
|
35
|
-
{
|
|
36
|
-
type: node.type,
|
|
37
|
-
lang: node.lang,
|
|
38
|
-
meta: highlight,
|
|
39
|
-
value: yarnCode
|
|
40
|
-
},
|
|
41
|
-
{
|
|
42
|
-
type: 'jsx',
|
|
43
|
-
value: '</TabItem>\n<TabItem value="pnpm">'
|
|
44
|
-
},
|
|
45
|
-
{
|
|
46
|
-
type: node.type,
|
|
47
|
-
lang: node.lang,
|
|
48
|
-
meta: highlight,
|
|
49
|
-
value: pnpmCode
|
|
50
|
-
},
|
|
51
|
-
{
|
|
52
|
-
type: 'jsx',
|
|
53
|
-
value: '</TabItem>\n</Tabs>'
|
|
54
|
-
}
|
|
55
|
-
];
|
|
56
|
-
};
|
|
57
|
-
const matchNode = (node) => node.type === 'code' && typeof node.meta === 'string' && node.meta.startsWith('npm2yarn2pnpm');
|
|
58
|
-
const nodeForImport = {
|
|
59
|
-
type: 'import',
|
|
60
|
-
value: "import Tabs from '@theme/Tabs';\nimport TabItem from '@theme/TabItem';"
|
|
61
|
-
};
|
|
62
|
-
function npm2yarn2pnpm({ sync = true } = { sync: true }) {
|
|
63
|
-
let transformed = false;
|
|
64
|
-
let alreadyImported = false;
|
|
65
|
-
const transformer = (node) => {
|
|
66
|
-
if (node.type === 'import' && node.value.includes('@theme/Tabs')) {
|
|
67
|
-
alreadyImported = true;
|
|
68
|
-
}
|
|
69
|
-
if (matchNode(node)) {
|
|
70
|
-
transformed = true;
|
|
71
|
-
return transformNode(node, { sync });
|
|
72
|
-
}
|
|
73
|
-
if (Array.isArray(node.children)) {
|
|
74
|
-
let index = 0;
|
|
75
|
-
while (index < node.children.length) {
|
|
76
|
-
const result = transformer(node.children[index]);
|
|
77
|
-
if (result) {
|
|
78
|
-
node.children.splice(index, 1, ...result);
|
|
79
|
-
index += result.length;
|
|
80
|
-
}
|
|
81
|
-
else {
|
|
82
|
-
index += 1;
|
|
83
|
-
}
|
|
84
|
-
}
|
|
85
|
-
}
|
|
86
|
-
if (node.type === 'root' && transformed && !alreadyImported) {
|
|
87
|
-
node.children.unshift(nodeForImport);
|
|
88
|
-
}
|
|
89
|
-
return null;
|
|
90
|
-
};
|
|
91
|
-
return transformer;
|
|
92
|
-
}
|
|
93
|
-
exports.npm2yarn2pnpm = npm2yarn2pnpm;
|
|
94
|
-
//# sourceMappingURL=npm2yarn2pnpm.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"npm2yarn2pnpm.js","sourceRoot":"","sources":["../src/npm2yarn2pnpm.ts"],"names":[],"mappings":";;;;AAAA,2EAAoC;AACpC,yCAAuC;AAEvC,MAAM,aAAa,GAAG,CAAC,IAAS,EAAE,OAAsB,EAAE,EAAE;IAC3D,MAAM,WAAW,GAAG,OAAO,CAAC,IAAI,CA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