@sapphire/docusaurus-plugin-ts2esm2cjs 1.0.2-next.dfbe36e.0 → 1.0.2
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/README.md +3 -1
- package/dist/index.d.ts +35 -2
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +471 -139
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +465 -3
- package/dist/index.mjs.map +1 -0
- package/package.json +7 -13
package/dist/index.js
CHANGED
|
@@ -1,154 +1,486 @@
|
|
|
1
|
-
|
|
2
|
-
Object.defineProperty
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
...prettier_config_1.default,
|
|
11
|
-
tabWidth: 2,
|
|
12
|
-
useTabs: false,
|
|
13
|
-
printWidth: 120,
|
|
14
|
-
parser: 'babel'
|
|
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 __esm = (fn, res) => function __init() {
|
|
9
|
+
return fn && (res = (0, fn[__getOwnPropNames(fn)[0]])(fn = 0)), res;
|
|
15
10
|
};
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
11
|
+
var __commonJS = (cb, mod) => function __require() {
|
|
12
|
+
return mod || (0, cb[__getOwnPropNames(cb)[0]])((mod = { exports: {} }).exports, mod), mod.exports;
|
|
13
|
+
};
|
|
14
|
+
var __export = (target, all) => {
|
|
15
|
+
for (var name in all)
|
|
16
|
+
__defProp(target, name, { get: all[name], enumerable: true });
|
|
17
|
+
};
|
|
18
|
+
var __reExport = (target, module2, copyDefault, desc) => {
|
|
19
|
+
if (module2 && typeof module2 === "object" || typeof module2 === "function") {
|
|
20
|
+
for (let key of __getOwnPropNames(module2))
|
|
21
|
+
if (!__hasOwnProp.call(target, key) && (copyDefault || key !== "default"))
|
|
22
|
+
__defProp(target, key, { get: () => module2[key], enumerable: !(desc = __getOwnPropDesc(module2, key)) || desc.enumerable });
|
|
23
|
+
}
|
|
24
|
+
return target;
|
|
25
|
+
};
|
|
26
|
+
var __toESM = (module2, isNodeMode) => {
|
|
27
|
+
return __reExport(__markAsModule(__defProp(module2 != null ? __create(__getProtoOf(module2)) : {}, "default", !isNodeMode && module2 && module2.__esModule ? { get: () => module2.default, enumerable: true } : { value: module2, enumerable: true })), module2);
|
|
28
|
+
};
|
|
29
|
+
var __toCommonJS = /* @__PURE__ */ ((cache) => {
|
|
30
|
+
return (module2, temp) => {
|
|
31
|
+
return cache && cache.get(module2) || (temp = __reExport(__markAsModule({}), module2, 1), cache && cache.set(module2, temp), temp);
|
|
32
|
+
};
|
|
33
|
+
})(typeof WeakMap !== "undefined" ? /* @__PURE__ */ new WeakMap() : 0);
|
|
34
|
+
|
|
35
|
+
// ../../node_modules/tsup/assets/cjs_shims.js
|
|
36
|
+
var init_cjs_shims = __esm({
|
|
37
|
+
"../../node_modules/tsup/assets/cjs_shims.js"() {
|
|
38
|
+
}
|
|
25
39
|
});
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
const
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
40
|
+
|
|
41
|
+
// src/esmToCjs.js
|
|
42
|
+
var require_esmToCjs = __commonJS({
|
|
43
|
+
"src/esmToCjs.js"(exports, module2) {
|
|
44
|
+
init_cjs_shims();
|
|
45
|
+
module2.exports.runTransform = runTransform2;
|
|
46
|
+
var LOOKING_FOR;
|
|
47
|
+
var DISTANCE = 6;
|
|
48
|
+
var defaultOptions = {
|
|
49
|
+
quote: "double",
|
|
50
|
+
lenDestructure: 60,
|
|
51
|
+
lenModuleName: 20,
|
|
52
|
+
lenIdentifier: 20,
|
|
53
|
+
indent: 2
|
|
54
|
+
};
|
|
55
|
+
function runTransform2(str, options = {}) {
|
|
56
|
+
options = { ...defaultOptions, ...options };
|
|
57
|
+
options.quote = options.quote === "single" ? "'" : '"';
|
|
58
|
+
const buffer = [];
|
|
59
|
+
const exportBuffer = {
|
|
60
|
+
items: [],
|
|
61
|
+
requires: []
|
|
62
|
+
};
|
|
63
|
+
let pos = 0;
|
|
64
|
+
for (const token of tokenize(str, options)) {
|
|
65
|
+
buffer.push(str.slice(pos, token.start));
|
|
66
|
+
buffer.push(transform(token, str, exportBuffer, options));
|
|
67
|
+
pos = token.end + 1;
|
|
68
|
+
}
|
|
69
|
+
pos = skipNewLines(str, pos);
|
|
70
|
+
buffer.push(str.slice(pos, str.length));
|
|
71
|
+
if (exportBuffer.items.length) {
|
|
72
|
+
const indent = " ".repeat(options.indent);
|
|
73
|
+
for (const item of exportBuffer.requires) {
|
|
74
|
+
buffer.push(item);
|
|
75
|
+
}
|
|
76
|
+
buffer.push("\nmodule.exports = {\n");
|
|
77
|
+
const exportNames = exportBuffer.items.map((item) => `${indent}${item[0]}${item[1] ? `: ${item[1]}` : ""}`);
|
|
78
|
+
buffer.push(exportNames.join(",\n"));
|
|
79
|
+
buffer.push("\n}");
|
|
80
|
+
}
|
|
81
|
+
buffer.push("\n");
|
|
82
|
+
return buffer.join("");
|
|
83
|
+
}
|
|
84
|
+
function transform(token, str, exportBuffer, { indent }) {
|
|
85
|
+
indent = " ".repeat(indent);
|
|
86
|
+
const { type } = token;
|
|
87
|
+
switch (type) {
|
|
88
|
+
case "import": {
|
|
89
|
+
const identifiers = token.modules.map((s) => s.join(": ")).join(", ");
|
|
90
|
+
return `const { ${identifiers} } = require(${token.moduleName})`;
|
|
91
|
+
}
|
|
92
|
+
case "import*":
|
|
93
|
+
case "importDefault": {
|
|
94
|
+
const { identifier, moduleName } = token;
|
|
95
|
+
return `const ${identifier} = require(${moduleName})${token.isDefaultImport ? ".default" : ""}`;
|
|
96
|
+
}
|
|
97
|
+
case "awaitImport": {
|
|
98
|
+
return `require(${token.moduleName})`;
|
|
99
|
+
}
|
|
100
|
+
case "export": {
|
|
101
|
+
exportBuffer.items.push(token.modules);
|
|
102
|
+
return "";
|
|
103
|
+
}
|
|
104
|
+
case "reExport": {
|
|
105
|
+
const { moduleName } = token;
|
|
106
|
+
if (token.modules.length === 1) {
|
|
107
|
+
const [original, alias] = token.modules[0];
|
|
108
|
+
exportBuffer.items.push([alias ? alias : original, `require(${moduleName}).${original}`]);
|
|
109
|
+
return;
|
|
110
|
+
}
|
|
111
|
+
exportBuffer.requires.push("const {\n");
|
|
112
|
+
const names = token.modules.map(([original]) => `${indent}${original}: __${original}__`).join(",\n");
|
|
113
|
+
exportBuffer.requires.push(names);
|
|
114
|
+
exportBuffer.requires.push(`
|
|
115
|
+
} = require(${moduleName});`);
|
|
116
|
+
for (const [original, alias] of token.modules) {
|
|
117
|
+
exportBuffer.items.push([alias ? alias : original, `__${original}__`]);
|
|
118
|
+
}
|
|
119
|
+
return "";
|
|
120
|
+
}
|
|
121
|
+
case "reExportImported": {
|
|
122
|
+
exportBuffer.items.push(...token.modules);
|
|
123
|
+
return "";
|
|
124
|
+
}
|
|
125
|
+
default:
|
|
126
|
+
throw new Error("should not reach here");
|
|
127
|
+
}
|
|
128
|
+
}
|
|
129
|
+
String.prototype.indexWithin = indexWithin;
|
|
130
|
+
function* tokenize(str, options) {
|
|
131
|
+
const { quote, lenDestructure, lenModuleName, lenIdentifier } = options;
|
|
132
|
+
let start = 0;
|
|
133
|
+
let pos;
|
|
134
|
+
const types = /* @__PURE__ */ new Map([
|
|
135
|
+
["import", "import "],
|
|
136
|
+
["export", "export "],
|
|
137
|
+
["awaitImport", "await import("]
|
|
138
|
+
]);
|
|
139
|
+
while (types.size !== 0) {
|
|
140
|
+
pos = Number.POSITIVE_INFINITY;
|
|
141
|
+
let type;
|
|
142
|
+
for (const t of types.keys()) {
|
|
143
|
+
const idx = str.indexOf(types.get(t), start);
|
|
144
|
+
if (idx === -1) {
|
|
145
|
+
types.delete(t);
|
|
146
|
+
} else if (idx < pos) {
|
|
147
|
+
pos = idx;
|
|
148
|
+
type = t;
|
|
149
|
+
}
|
|
150
|
+
}
|
|
151
|
+
switch (type) {
|
|
152
|
+
case "import":
|
|
153
|
+
yield handleImport();
|
|
154
|
+
break;
|
|
155
|
+
case "export":
|
|
156
|
+
yield handleExport();
|
|
157
|
+
break;
|
|
158
|
+
case "awaitImport":
|
|
159
|
+
yield handleAwaitImport();
|
|
160
|
+
break;
|
|
161
|
+
}
|
|
162
|
+
}
|
|
163
|
+
function handleImport() {
|
|
164
|
+
LOOKING_FOR = "import names";
|
|
165
|
+
const braceStart = str.indexWithin("{", pos + 7, DISTANCE, false);
|
|
166
|
+
if (braceStart === -1) {
|
|
167
|
+
return handleImportStar();
|
|
168
|
+
}
|
|
169
|
+
const braceEnd = str.indexWithin("}", braceStart + 1, lenDestructure);
|
|
170
|
+
LOOKING_FOR = "name of imported module";
|
|
171
|
+
let moduleStart = str.indexWithin("from ", braceEnd + 1, DISTANCE);
|
|
172
|
+
moduleStart = str.indexWithin(quote, moduleStart + 1, 5);
|
|
173
|
+
const moduleEnd = str.indexWithin(quote, moduleStart + 1, lenModuleName);
|
|
174
|
+
start = moduleEnd + 1;
|
|
175
|
+
return {
|
|
176
|
+
type: "import",
|
|
177
|
+
start: pos,
|
|
178
|
+
end: moduleEnd,
|
|
179
|
+
modules: destructureModules(str.slice(braceStart, braceEnd + 1)),
|
|
180
|
+
moduleName: str.slice(moduleStart, moduleEnd + 1)
|
|
181
|
+
};
|
|
182
|
+
}
|
|
183
|
+
function handleAwaitImport() {
|
|
184
|
+
LOOKING_FOR = "name of imported module for await import()";
|
|
185
|
+
const moduleStart = str.indexWithin("(", pos + 12, 10) + 1;
|
|
186
|
+
const moduleEnd = str.indexWithin(")", moduleStart + 1, lenIdentifier) - 1;
|
|
187
|
+
start = moduleEnd + 2;
|
|
188
|
+
return {
|
|
189
|
+
type: "awaitImport",
|
|
190
|
+
start: pos,
|
|
191
|
+
end: moduleEnd + 1,
|
|
192
|
+
moduleName: str.slice(moduleStart, moduleEnd + 1)
|
|
193
|
+
};
|
|
194
|
+
}
|
|
195
|
+
function handleExport() {
|
|
196
|
+
LOOKING_FOR = "export pattern";
|
|
197
|
+
let skipStart = pos + "export ".length;
|
|
198
|
+
if (str.indexWithin("{", skipStart, 5, false) !== -1) {
|
|
199
|
+
return handleReExport();
|
|
200
|
+
} else if (str.indexWithin("*", skipStart, 5, false) !== -1) {
|
|
201
|
+
return handleExportStar();
|
|
202
|
+
}
|
|
203
|
+
LOOKING_FOR = "identifier type (function|class|const) for export";
|
|
204
|
+
if (str.indexWithin("async ", skipStart, DISTANCE, false) !== -1) {
|
|
205
|
+
skipStart += 6;
|
|
206
|
+
}
|
|
207
|
+
let isDefaultExport = false;
|
|
208
|
+
if (str.indexWithin("default ", skipStart, DISTANCE, false) !== -1) {
|
|
209
|
+
skipStart += 8;
|
|
210
|
+
isDefaultExport = true;
|
|
211
|
+
}
|
|
212
|
+
const typeEnd = str.indexWithin(" ", skipStart, 9);
|
|
213
|
+
const exportType = str.slice(skipStart, typeEnd);
|
|
214
|
+
LOOKING_FOR = "export identifiers";
|
|
215
|
+
const identifierStart = str.indexWithin(" ", skipStart + exportType.length, 5) + 1;
|
|
216
|
+
const identifierEnd = str.indexWithin(exportType === "function" ? "(" : " ", identifierStart, lenIdentifier) - 1;
|
|
217
|
+
const end = pos + 6 + (isDefaultExport ? 8 : 0);
|
|
218
|
+
const modules = isDefaultExport ? ["default", str.slice(identifierStart, identifierEnd + 1)] : [str.slice(identifierStart, identifierEnd + 1)];
|
|
219
|
+
start = end + 1;
|
|
220
|
+
return {
|
|
221
|
+
type: "export",
|
|
222
|
+
start: pos,
|
|
223
|
+
end,
|
|
224
|
+
modules
|
|
225
|
+
};
|
|
226
|
+
}
|
|
227
|
+
function handleImportStar() {
|
|
228
|
+
LOOKING_FOR = "import name for import*";
|
|
229
|
+
let identifierStart = str.indexWithin("* as ", pos + 7, DISTANCE, false);
|
|
230
|
+
if (identifierStart === -1) {
|
|
231
|
+
return handleDefaultImport();
|
|
232
|
+
}
|
|
233
|
+
identifierStart += 5;
|
|
234
|
+
const identifierEnd = str.indexWithin(" ", identifierStart + 1, lenIdentifier);
|
|
235
|
+
LOOKING_FOR = "name of imported module for import*";
|
|
236
|
+
let moduleStart = str.indexWithin("from ", identifierEnd + 1) + "from".length;
|
|
237
|
+
moduleStart = str.indexWithin(quote, moduleStart + 1);
|
|
238
|
+
const moduleEnd = str.indexWithin(quote, moduleStart + 1, lenModuleName);
|
|
239
|
+
start = moduleEnd + 1;
|
|
240
|
+
return {
|
|
241
|
+
type: "import*",
|
|
242
|
+
start: pos,
|
|
243
|
+
end: moduleEnd,
|
|
244
|
+
identifier: str.slice(identifierStart, identifierEnd),
|
|
245
|
+
moduleName: str.slice(moduleStart, moduleEnd + 1)
|
|
246
|
+
};
|
|
247
|
+
}
|
|
248
|
+
function handleDefaultImport() {
|
|
249
|
+
LOOKING_FOR = "import name for default import";
|
|
250
|
+
const identifierStart = pos + 7;
|
|
251
|
+
const identifierEnd = str.indexWithin(" ", identifierStart, DISTANCE);
|
|
252
|
+
LOOKING_FOR = "name of imported module for import*";
|
|
253
|
+
let moduleStart = str.indexWithin("from ", identifierEnd + 1) + "from".length;
|
|
254
|
+
moduleStart = str.indexWithin(quote, moduleStart + 1);
|
|
255
|
+
const moduleEnd = str.indexWithin(quote, moduleStart + 1, lenModuleName);
|
|
256
|
+
start = moduleEnd + 1;
|
|
257
|
+
return {
|
|
258
|
+
type: "importDefault",
|
|
259
|
+
start: pos,
|
|
260
|
+
end: moduleEnd,
|
|
261
|
+
isDefaultImport: true,
|
|
262
|
+
identifier: str.slice(identifierStart, identifierEnd),
|
|
263
|
+
moduleName: str.slice(moduleStart, moduleEnd + 1)
|
|
264
|
+
};
|
|
265
|
+
}
|
|
266
|
+
function handleReExport() {
|
|
267
|
+
LOOKING_FOR = "export pattern for re-export";
|
|
268
|
+
const braceStart = str.indexWithin("{", pos + "export ".length, 5);
|
|
269
|
+
const braceEnd = str.indexWithin("}", braceStart + 1, lenDestructure);
|
|
270
|
+
LOOKING_FOR = "name of re-exported module";
|
|
271
|
+
let moduleStart = str.indexWithin("from ", braceEnd + 1, 10, false);
|
|
272
|
+
if (moduleStart === -1) {
|
|
273
|
+
const end2 = skipNewLines(str, braceEnd);
|
|
274
|
+
start = end2 + 1;
|
|
275
|
+
return {
|
|
276
|
+
type: "reExportImported",
|
|
277
|
+
start: pos,
|
|
278
|
+
end: end2,
|
|
279
|
+
modules: destructureModules(str.slice(braceStart, braceEnd + 1))
|
|
280
|
+
};
|
|
281
|
+
}
|
|
282
|
+
moduleStart = str.indexWithin(quote, moduleStart, "from ".length + 4);
|
|
283
|
+
const moduleEnd = str.indexWithin(quote, moduleStart + 1, lenModuleName);
|
|
284
|
+
const end = skipNewLines(str, moduleEnd);
|
|
285
|
+
start = end + 1;
|
|
286
|
+
return {
|
|
287
|
+
type: "reExport",
|
|
288
|
+
start: pos,
|
|
289
|
+
end,
|
|
290
|
+
modules: destructureModules(str.slice(braceStart, braceEnd + 1)),
|
|
291
|
+
moduleName: str.slice(moduleStart, moduleEnd + 1)
|
|
292
|
+
};
|
|
293
|
+
}
|
|
294
|
+
function handleExportStar() {
|
|
295
|
+
throw new Error("not implemented");
|
|
296
|
+
}
|
|
297
|
+
function destructureModules(objLiteral) {
|
|
298
|
+
return objLiteral.trim().slice(1, -1).split(/,\s*/).map((i) => i.trim()).filter((i) => i).map((i) => i.split(/\s*\bas\b\s*/));
|
|
299
|
+
}
|
|
300
|
+
}
|
|
301
|
+
function indexWithin(needle, from, within = 99, throws = true) {
|
|
302
|
+
for (let i = from, L = from + within, j = 0; i < L; ++i) {
|
|
303
|
+
if (this.charCodeAt(i) === needle.charCodeAt(j)) {
|
|
304
|
+
while (j < needle.length) {
|
|
305
|
+
if (this.charCodeAt(i + j) === needle.charCodeAt(j)) {
|
|
306
|
+
++j;
|
|
307
|
+
} else {
|
|
308
|
+
j = 0;
|
|
309
|
+
break;
|
|
310
|
+
}
|
|
311
|
+
}
|
|
312
|
+
if (j === needle.length) {
|
|
313
|
+
return i;
|
|
314
|
+
}
|
|
315
|
+
}
|
|
316
|
+
}
|
|
317
|
+
if (throws) {
|
|
318
|
+
throw new Error(`ParseError: Failed to find \`${needle}\` within ${within} characters from position ${from}${LOOKING_FOR ? ` while looking for ${LOOKING_FOR}` : ""}
|
|
319
|
+
|
|
320
|
+
INPUT STRING:
|
|
321
|
+
${"*".repeat(20)}
|
|
322
|
+
${this}
|
|
323
|
+
${"*".repeat(20)}
|
|
324
|
+
`);
|
|
325
|
+
} else {
|
|
326
|
+
return -1;
|
|
327
|
+
}
|
|
328
|
+
}
|
|
329
|
+
function skipNewLines(str, i) {
|
|
330
|
+
if (str.charAt(i + 1) === ";")
|
|
331
|
+
++i;
|
|
332
|
+
while (i < str.length && /\s/.test(str.charAt(i))) {
|
|
333
|
+
++i;
|
|
334
|
+
}
|
|
335
|
+
return i;
|
|
336
|
+
}
|
|
337
|
+
}
|
|
338
|
+
});
|
|
339
|
+
|
|
340
|
+
// src/index.ts
|
|
341
|
+
var src_exports = {};
|
|
342
|
+
__export(src_exports, {
|
|
343
|
+
documentationPrettierConfig: () => documentationPrettierConfig,
|
|
344
|
+
escapeNewLines: () => escapeNewLines,
|
|
345
|
+
esmToCjs: () => esmToCjs,
|
|
346
|
+
makeTsCompilerOptions: () => makeTsCompilerOptions,
|
|
347
|
+
prettierFormatCode: () => prettierFormatCode,
|
|
348
|
+
restoreNewLines: () => restoreNewLines,
|
|
349
|
+
ts2esm2cjs: () => ts2esm2cjs,
|
|
350
|
+
tsToEsm: () => tsToEsm
|
|
351
|
+
});
|
|
352
|
+
init_cjs_shims();
|
|
353
|
+
var import_prettier_config = __toESM(require("@sapphire/prettier-config"));
|
|
354
|
+
var import_esmToCjs = __toESM(require_esmToCjs());
|
|
355
|
+
var import_prettier = __toESM(require("prettier"));
|
|
356
|
+
var import_typescript = __toESM(require("typescript"));
|
|
357
|
+
var documentationPrettierConfig = {
|
|
358
|
+
...import_prettier_config.default,
|
|
359
|
+
tabWidth: 2,
|
|
360
|
+
useTabs: false,
|
|
361
|
+
printWidth: 120,
|
|
362
|
+
parser: "babel"
|
|
363
|
+
};
|
|
364
|
+
var makeTsCompilerOptions = (overrideOptions) => ({
|
|
365
|
+
newLine: import_typescript.default.NewLineKind.LineFeed,
|
|
366
|
+
removeComments: false,
|
|
367
|
+
esModuleInterop: true,
|
|
368
|
+
pretty: true,
|
|
369
|
+
...overrideOptions,
|
|
370
|
+
module: import_typescript.default.ModuleKind.ESNext,
|
|
371
|
+
moduleResolution: import_typescript.default.ModuleResolutionKind.NodeJs,
|
|
372
|
+
target: import_typescript.default.ScriptTarget.ESNext
|
|
373
|
+
});
|
|
374
|
+
var tsToEsm = (code, options) => import_typescript.default.transpileModule(code, { reportDiagnostics: false, compilerOptions: makeTsCompilerOptions(options.typescriptCompilerOptions) });
|
|
375
|
+
var esmToCjs = (code) => (0, import_esmToCjs.runTransform)(code, { quote: "single", lenDestructure: 512, lenModuleName: 512, lenIdentifier: 512 });
|
|
376
|
+
var escapeNewLines = (code) => code.replace(/\n\n/g, "\n/* :newline: */");
|
|
377
|
+
var restoreNewLines = (code) => code.replace(/\/\* :newline: \*\//g, "\n");
|
|
378
|
+
var prettierFormatCode = (code, prettierConfig) => import_prettier.default.format(code, { ...documentationPrettierConfig, ...prettierConfig }).slice(0, -1);
|
|
379
|
+
var transformNode = (node, options) => {
|
|
380
|
+
const groupIdProp = options.sync ? 'groupId="ts2esm2cjs" ' : "";
|
|
381
|
+
const tsCode = escapeNewLines(node.value);
|
|
382
|
+
const esmCode = tsToEsm(tsCode, { typescriptCompilerOptions: options.typescriptCompilerOptions }).outputText;
|
|
383
|
+
const cjsCode = esmToCjs(esmCode);
|
|
384
|
+
const [, jsHighlight, tsHighlight] = node.meta.split("|");
|
|
385
|
+
return [
|
|
386
|
+
{
|
|
387
|
+
type: "jsx",
|
|
388
|
+
value: `<Tabs defaultValue="typescript" ${groupIdProp}values={[
|
|
74
389
|
{ label: 'JavaScript', value: 'javascript', },
|
|
75
390
|
{ label: 'ESM', value: 'esm', },
|
|
76
391
|
{ label: 'TypeScript', value: 'typescript', },
|
|
77
392
|
]}
|
|
78
393
|
>
|
|
79
394
|
<TabItem value="javascript">`
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
395
|
+
},
|
|
396
|
+
{
|
|
397
|
+
type: node.type,
|
|
398
|
+
lang: node.lang,
|
|
399
|
+
meta: jsHighlight,
|
|
400
|
+
value: prettierFormatCode(restoreNewLines(cjsCode), options.prettierOptions)
|
|
401
|
+
},
|
|
402
|
+
{
|
|
403
|
+
type: "jsx",
|
|
404
|
+
value: '</TabItem>\n<TabItem value="esm">'
|
|
405
|
+
},
|
|
406
|
+
{
|
|
407
|
+
type: node.type,
|
|
408
|
+
lang: node.lang,
|
|
409
|
+
meta: jsHighlight,
|
|
410
|
+
value: prettierFormatCode(restoreNewLines(esmCode), options.prettierOptions)
|
|
411
|
+
},
|
|
412
|
+
{
|
|
413
|
+
type: "jsx",
|
|
414
|
+
value: '</TabItem>\n<TabItem value="typescript">'
|
|
415
|
+
},
|
|
416
|
+
{
|
|
417
|
+
type: node.type,
|
|
418
|
+
lang: node.lang,
|
|
419
|
+
meta: tsHighlight,
|
|
420
|
+
value: node.value
|
|
421
|
+
},
|
|
422
|
+
{
|
|
423
|
+
type: "jsx",
|
|
424
|
+
value: "</TabItem>\n</Tabs>"
|
|
425
|
+
}
|
|
426
|
+
];
|
|
112
427
|
};
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
428
|
+
var matchNode = (node) => node.type === "code" && typeof node.meta === "string" && node.meta.startsWith("ts2esm2cjs");
|
|
429
|
+
var nodeForImport = {
|
|
430
|
+
type: "import",
|
|
431
|
+
value: "import Tabs from '@theme/Tabs';\nimport TabItem from '@theme/TabItem';"
|
|
117
432
|
};
|
|
118
433
|
function ts2esm2cjs({ sync = true, prettierOptions = {}, typescriptCompilerOptions = {} } = {
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
434
|
+
sync: true,
|
|
435
|
+
prettierOptions: {},
|
|
436
|
+
typescriptCompilerOptions: {}
|
|
122
437
|
}) {
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
index += 1;
|
|
143
|
-
}
|
|
144
|
-
}
|
|
438
|
+
let transformed = false;
|
|
439
|
+
let alreadyImported = false;
|
|
440
|
+
const transformer = (node) => {
|
|
441
|
+
if (node.type === "import" && node.value.includes("@theme/Tabs")) {
|
|
442
|
+
alreadyImported = true;
|
|
443
|
+
}
|
|
444
|
+
if (matchNode(node)) {
|
|
445
|
+
transformed = true;
|
|
446
|
+
return transformNode(node, { sync, prettierOptions, typescriptCompilerOptions });
|
|
447
|
+
}
|
|
448
|
+
if (Array.isArray(node.children)) {
|
|
449
|
+
let index = 0;
|
|
450
|
+
while (index < node.children.length) {
|
|
451
|
+
const result = transformer(node.children[index]);
|
|
452
|
+
if (result) {
|
|
453
|
+
node.children.splice(index, 1, ...result);
|
|
454
|
+
index += result.length;
|
|
455
|
+
} else {
|
|
456
|
+
index += 1;
|
|
145
457
|
}
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
}
|
|
151
|
-
return
|
|
458
|
+
}
|
|
459
|
+
}
|
|
460
|
+
if (node.type === "root" && transformed && !alreadyImported) {
|
|
461
|
+
node.children.unshift(nodeForImport);
|
|
462
|
+
}
|
|
463
|
+
return null;
|
|
464
|
+
};
|
|
465
|
+
return transformer;
|
|
152
466
|
}
|
|
153
|
-
exports
|
|
467
|
+
module.exports = __toCommonJS(src_exports);
|
|
468
|
+
// Annotate the CommonJS export names for ESM import in node:
|
|
469
|
+
0 && (module.exports = {
|
|
470
|
+
documentationPrettierConfig,
|
|
471
|
+
escapeNewLines,
|
|
472
|
+
esmToCjs,
|
|
473
|
+
makeTsCompilerOptions,
|
|
474
|
+
prettierFormatCode,
|
|
475
|
+
restoreNewLines,
|
|
476
|
+
ts2esm2cjs,
|
|
477
|
+
tsToEsm
|
|
478
|
+
});
|
|
479
|
+
/**
|
|
480
|
+
* @license MIT
|
|
481
|
+
* @copyright 2018 Sid Vishnoi <sidvishnoi8@gmail.com>
|
|
482
|
+
* @see https://github.com/sidvishnoi/esm-to-cjs/blob/d032518da994b6d28cff5fd38ac2d0b45a13f0d9/src/core.js
|
|
483
|
+
*
|
|
484
|
+
* Modified code is line 340
|
|
485
|
+
*/
|
|
154
486
|
//# sourceMappingURL=index.js.map
|