@sapphire/docusaurus-plugin-ts2esm2cjs 2.0.2-next.fafceb7.0 → 2.0.3-next.c24a7a0.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 CHANGED
@@ -2,6 +2,20 @@
2
2
 
3
3
  All notable changes to this project will be documented in this file.
4
4
 
5
+ # [@sapphire/docusaurus-plugin-ts2esm2cjs@2.0.2](https://github.com/sapphiredev/documentation-plugins/compare/@sapphire/docusaurus-plugin-ts2esm2cjs@2.0.2...@sapphire/docusaurus-plugin-ts2esm2cjs@2.0.2) - (2024-01-19)
6
+
7
+ ## 🐛 Bug Fixes
8
+
9
+ - Properly split CJS and ESM (#228) ([ea4951c](https://github.com/sapphiredev/documentation-plugins/commit/ea4951cb04eea5f6c5d1882b68e1ae42ed73e3ea))
10
+
11
+ ## 📝 Documentation
12
+
13
+ - Incorrect syntax in readme of ts2esm2cjs & npm2yarn2pnpm (#203) ([621df18](https://github.com/sapphiredev/documentation-plugins/commit/621df18aaa89d8f82887c5124ebc681cfec8986c))
14
+
15
+ ## 🧪 Testing
16
+
17
+ - Fix test config ([7b4a6ab](https://github.com/sapphiredev/documentation-plugins/commit/7b4a6ab7732e5e886a40f31d5adb27874a04e43b))
18
+
5
19
  # [@sapphire/docusaurus-plugin-ts2esm2cjs@2.0.1](https://github.com/sapphiredev/documentation-plugins/compare/@sapphire/docusaurus-plugin-ts2esm2cjs@2.0.1...@sapphire/docusaurus-plugin-ts2esm2cjs@2.0.1) - (2023-11-05)
6
20
 
7
21
  ## 🐛 Bug Fixes
@@ -1,55 +1,25 @@
1
- "use strict";
2
- var __create = Object.create;
3
- var __defProp = Object.defineProperty;
4
- var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
5
- var __getOwnPropNames = Object.getOwnPropertyNames;
6
- var __getProtoOf = Object.getPrototypeOf;
7
- var __hasOwnProp = Object.prototype.hasOwnProperty;
8
- var __export = (target, all) => {
9
- for (var name in all)
10
- __defProp(target, name, { get: all[name], enumerable: true });
11
- };
12
- var __copyProps = (to, from, except, desc) => {
13
- if (from && typeof from === "object" || typeof from === "function") {
14
- for (let key of __getOwnPropNames(from))
15
- if (!__hasOwnProp.call(to, key) && key !== except)
16
- __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
17
- }
18
- return to;
19
- };
20
- var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
21
- // If the importer is in node compatibility mode or this is not an ESM
22
- // file that has been converted to a CommonJS file using a Babel-
23
- // compatible transform (i.e. "__esModule" has not been set), then set
24
- // "default" to the CommonJS "module.exports" for node compatibility.
25
- isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
26
- mod
27
- ));
28
- var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
1
+ 'use strict';
29
2
 
30
- // src/index.ts
31
- var src_exports = {};
32
- __export(src_exports, {
33
- esm2cjs: () => esm2cjs,
34
- ts2esm: () => ts2esm,
35
- ts2esm2cjs: () => ts2esm2cjs
36
- });
37
- module.exports = __toCommonJS(src_exports);
3
+ var sync = require('@prettier/sync');
4
+ var esmToCjs$1 = require('esm-to-cjs');
5
+ var ts = require('typescript');
6
+
7
+ function _interopDefault (e) { return e && e.__esModule ? e : { default: e }; }
38
8
 
39
- // src/ts2esm2cjs.ts
40
- var import_sync = require("@prettier/sync");
41
- var import_esm_to_cjs = require("esm-to-cjs");
42
- var import_typescript = __toESM(require("typescript"));
43
- var makeTsCompilerOptions = (overrideOptions) => ({
44
- newLine: import_typescript.default.NewLineKind.LineFeed,
9
+ var ts__default = /*#__PURE__*/_interopDefault(ts);
10
+
11
+ var __defProp = Object.defineProperty;
12
+ var __name = (target, value) => __defProp(target, "name", { value, configurable: true });
13
+ var makeTsCompilerOptions = /* @__PURE__ */ __name((overrideOptions) => ({
14
+ newLine: ts__default.default.NewLineKind.LineFeed,
45
15
  removeComments: false,
46
16
  esModuleInterop: true,
47
17
  pretty: true,
48
18
  ...overrideOptions,
49
- module: import_typescript.default.ModuleKind.ESNext,
50
- moduleResolution: import_typescript.default.ModuleResolutionKind.NodeJs,
51
- target: import_typescript.default.ScriptTarget.ESNext
52
- });
19
+ module: ts__default.default.ModuleKind.ESNext,
20
+ moduleResolution: ts__default.default.ModuleResolutionKind.NodeJs,
21
+ target: ts__default.default.ScriptTarget.ESNext
22
+ }), "makeTsCompilerOptions");
53
23
  var documentationPrettierConfig = {
54
24
  endOfLine: "lf",
55
25
  quoteProps: "as-needed",
@@ -61,20 +31,22 @@ var documentationPrettierConfig = {
61
31
  printWidth: 120,
62
32
  parser: "babel"
63
33
  };
64
- var esmToCjs = (code) => (0, import_esm_to_cjs.runTransform)(code, { quote: "single", lenDestructure: 128, lenModuleName: 128, lenIdentifier: 128 });
65
- var escapeNewLines = (code) => code.replace(/\n\n/g, "\n/* :newline: */");
66
- var restoreNewLines = (code) => code.replace(/\/\* :newline: \*\//g, "\n");
67
- var prettierFormatCode = (code, prettierConfig) => (0, import_sync.format)(code, { ...documentationPrettierConfig, ...prettierConfig }).slice(0, -1);
68
- var tsToEsm = (code, options) => import_typescript.default.transpileModule(code, { reportDiagnostics: false, compilerOptions: makeTsCompilerOptions(options.typescriptCompilerOptions) });
34
+ var esmToCjs = /* @__PURE__ */ __name((code) => esmToCjs$1.runTransform(code, { quote: "single", lenDestructure: 128, lenModuleName: 128, lenIdentifier: 128 }), "esmToCjs");
35
+ var escapeNewLines = /* @__PURE__ */ __name((code) => code.replace(/\n\n/g, "\n/* :newline: */"), "escapeNewLines");
36
+ var restoreNewLines = /* @__PURE__ */ __name((code) => code.replace(/\/\* :newline: \*\//g, "\n"), "restoreNewLines");
37
+ var prettierFormatCode = /* @__PURE__ */ __name((code, prettierConfig) => sync.format(code, { ...documentationPrettierConfig, ...prettierConfig }).slice(0, -1), "prettierFormatCode");
38
+ var tsToEsm = /* @__PURE__ */ __name((code, options) => ts__default.default.transpileModule(code, { reportDiagnostics: false, compilerOptions: makeTsCompilerOptions(options.typescriptCompilerOptions) }), "tsToEsm");
69
39
  function ts2esm(input, options) {
70
40
  const tsCode = escapeNewLines(input);
71
41
  const esmCode = tsToEsm(tsCode, { typescriptCompilerOptions: options.typescriptCompilerOptions }).outputText;
72
42
  return prettierFormatCode(restoreNewLines(esmCode), options.prettierOptions);
73
43
  }
44
+ __name(ts2esm, "ts2esm");
74
45
  function esm2cjs(input, options) {
75
46
  const cjsCode = esmToCjs(input);
76
47
  return prettierFormatCode(restoreNewLines(cjsCode), options.prettierOptions);
77
48
  }
49
+ __name(esm2cjs, "esm2cjs");
78
50
 
79
51
  // src/index.ts
80
52
  function createAttribute(attributeName, attributeValue) {
@@ -84,6 +56,7 @@ function createAttribute(attributeName, attributeValue) {
84
56
  value: attributeValue
85
57
  };
86
58
  }
59
+ __name(createAttribute, "createAttribute");
87
60
  function createTabItem({ code, node, value, label }) {
88
61
  let [, jsHighlight, tsHighlight] = (node.meta ?? "").split("|");
89
62
  if (!tsHighlight && jsHighlight) {
@@ -103,7 +76,8 @@ function createTabItem({ code, node, value, label }) {
103
76
  ]
104
77
  };
105
78
  }
106
- var transformNode = (node, options) => {
79
+ __name(createTabItem, "createTabItem");
80
+ var transformNode = /* @__PURE__ */ __name((node, options) => {
107
81
  const groupIdProp = {
108
82
  type: "mdxJsxAttribute",
109
83
  name: "groupId",
@@ -140,11 +114,11 @@ var transformNode = (node, options) => {
140
114
  ]
141
115
  }
142
116
  ];
143
- };
144
- var isMdxEsmLiteral = (node) => node.type === "mdxjsEsm";
145
- var isTabsImport = (node) => isMdxEsmLiteral(node) && node.value.includes("@theme/Tabs");
146
- var isParent = (node) => Array.isArray(node.children);
147
- var matchNode = (node) => node.type === "code" && typeof node.meta === "string" && (node.meta ?? "").startsWith("ts2esm2cjs");
117
+ }, "transformNode");
118
+ var isMdxEsmLiteral = /* @__PURE__ */ __name((node) => node.type === "mdxjsEsm", "isMdxEsmLiteral");
119
+ var isTabsImport = /* @__PURE__ */ __name((node) => isMdxEsmLiteral(node) && node.value.includes("@theme/Tabs"), "isTabsImport");
120
+ var isParent = /* @__PURE__ */ __name((node) => Array.isArray(node.children), "isParent");
121
+ var matchNode = /* @__PURE__ */ __name((node) => node.type === "code" && typeof node.meta === "string" && (node.meta ?? "").startsWith("ts2esm2cjs"), "matchNode");
148
122
  function createImportNode() {
149
123
  return {
150
124
  type: "mdxjsEsm",
@@ -187,8 +161,9 @@ function createImportNode() {
187
161
  }
188
162
  };
189
163
  }
190
- var ts2esm2cjs = ({ sync = true, prettierOptions = {}, typescriptCompilerOptions = {} } = { sync: true, prettierOptions: {}, typescriptCompilerOptions: {} }) => async (root) => {
191
- const { visit } = await import("unist-util-visit");
164
+ __name(createImportNode, "createImportNode");
165
+ var ts2esm2cjs = /* @__PURE__ */ __name(({ sync = true, prettierOptions = {}, typescriptCompilerOptions = {} } = { sync: true, prettierOptions: {}, typescriptCompilerOptions: {} }) => async (root) => {
166
+ const { visit } = await import('unist-util-visit');
192
167
  let transformed = false;
193
168
  let alreadyImported = false;
194
169
  visit(root, (node) => {
@@ -213,11 +188,10 @@ var ts2esm2cjs = ({ sync = true, prettierOptions = {}, typescriptCompilerOptions
213
188
  if (transformed && !alreadyImported) {
214
189
  root.children.unshift(createImportNode());
215
190
  }
216
- };
217
- // Annotate the CommonJS export names for ESM import in node:
218
- 0 && (module.exports = {
219
- esm2cjs,
220
- ts2esm,
221
- ts2esm2cjs
222
- });
223
- //# sourceMappingURL=index.js.map
191
+ }, "ts2esm2cjs");
192
+
193
+ exports.esm2cjs = esm2cjs;
194
+ exports.ts2esm = ts2esm;
195
+ exports.ts2esm2cjs = ts2esm2cjs;
196
+ //# sourceMappingURL=out.js.map
197
+ //# sourceMappingURL=index.cjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../../src/ts2esm2cjs.ts","../../src/index.ts"],"names":[],"mappings":";;;;AAAA,S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AAM,kBAAkB,CAAC,GAAG,4BAA4B,CAAC,EAAE,IAAI,EAAE,MAAM,MAAM,iBAAiB,CAAC,GAAG,2BAA2B,CAAC,EAAE,MAE1I,OAAO,SAAS;AACf,QAAM,EAAE,MAAM,IAAI,MAAM,OAAO,kBAAkB;AAEjD,MAAI,cAAc;AAClB,MAAI,kBAAkB;AAEtB,QAAM,MAAM,CAAC,SAAe;AAC3B,QAAI,aAAa,IAAI,GAAG;AACvB,wBAAkB;AAAA,IACnB;AAEA,QAAI,SAAS,IAAI,GAAG;AACnB,UAAI,QAAQ;AACZ,aAAO,QAAQ,KAAK,SAAS,QAAQ;AACpC,cAAM,QAAQ,KAAK,SAAS,KAAK;AACjC,YAAI,UAAU,KAAK,GAAG;AACrB,gBAAM,SAAS,cAAc,OAAO,EAAE,MAAM,iBAAiB,0BAA0B,CAAC;AACxF,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;AAED,MAAI,eAAe,CAAC,iBAAiB;AACpC,IAAC,KAAgB,SAAS,QAAQ,iBAAiB,CAAC;AAAA,EACrD;AACD,GAjCA","sourcesContent":["import { format } from '@prettier/sync';\nimport { runTransform } from 'esm-to-cjs';\nimport type { Options } from 'prettier';\nimport ts, { type CompilerOptions } from 'typescript';\nimport type { PluginOptions } from './types';\n\nconst makeTsCompilerOptions = (overrideOptions?: CompilerOptions): CompilerOptions => ({\n\tnewLine: ts.NewLineKind.LineFeed,\n\tremoveComments: false,\n\tesModuleInterop: true,\n\tpretty: true,\n\t...overrideOptions,\n\tmodule: ts.ModuleKind.ESNext,\n\tmoduleResolution: ts.ModuleResolutionKind.NodeJs,\n\ttarget: ts.ScriptTarget.ESNext\n});\n\nconst documentationPrettierConfig: Options = {\n\tendOfLine: 'lf',\n\tquoteProps: 'as-needed',\n\tsemi: true,\n\tsingleQuote: true,\n\ttrailingComma: 'none',\n\ttabWidth: 2,\n\tuseTabs: false,\n\tprintWidth: 120,\n\tparser: 'babel'\n};\n\n/**\n * Transforms input ESM code to CJS code.\n * @param code The code to transform\n * @returns Input code transformed to CommonJS\n */\nconst esmToCjs = (code: string): string => runTransform(code, { quote: 'single', lenDestructure: 128, lenModuleName: 128, lenIdentifier: 128 });\n\n/**\n * Escaped new lines in code with block comments so they can be restored by {@link restoreNewLines}\n * @param code The code to escape new lines in\n * @returns The same code but with new lines escaped using block comments\n */\nconst escapeNewLines = (code: string) => code.replace(/\\n\\n/g, '\\n/* :newline: */');\n\n/**\n * Reverses {@link escapeNewLines} and restores new lines\n * @param code The code with escaped new lines\n * @returns The same code with new lines restored\n */\nconst restoreNewLines = (code: string): string => code.replace(/\\/\\* :newline: \\*\\//g, '\\n');\n\n/**\n * Formats the code using Prettier\n * @param code The code to prettier format\n * @param prettierConfig Additional prettier options to use for formatting\n * @returns Prettier formatted code\n */\nconst prettierFormatCode = (code: string, prettierConfig?: Options) =>\n\tformat(code, { ...documentationPrettierConfig, ...prettierConfig }).slice(0, -1);\n\n/**\n * Transpiles input TypeScript code to ESM code.\n * @param code The code to transpile\n * @returns Input code transpiled to ESM\n */\nconst tsToEsm = (code: string, options: Pick<PluginOptions, 'typescriptCompilerOptions'>): ts.TranspileOutput =>\n\tts.transpileModule(code, { reportDiagnostics: false, compilerOptions: makeTsCompilerOptions(options.typescriptCompilerOptions) });\n\n/**\n * Transforms input TypeScript code to ESM code.\n * @param input The TypeScript code to transform\n * @param options The plugin options\n * @returns The transformed code (ESM)\n */\nexport function ts2esm(input: string, options: PluginOptions) {\n\tconst tsCode = escapeNewLines(input);\n\tconst esmCode = tsToEsm(tsCode, { typescriptCompilerOptions: options.typescriptCompilerOptions }).outputText;\n\n\treturn prettierFormatCode(restoreNewLines(esmCode), options.prettierOptions);\n}\n\nexport function esm2cjs(input: string, options: PluginOptions) {\n\tconst cjsCode = esmToCjs(input);\n\n\treturn prettierFormatCode(restoreNewLines(cjsCode), options.prettierOptions);\n}\n","import type { Code, Literal, RootContent } from 'mdast';\nimport type { MdxJsxAttribute, MdxJsxFlowElement } from 'mdast-util-mdx';\nimport type { Plugin, Transformer } from 'unified';\nimport type { Node, Parent } from 'unist';\nimport { esm2cjs, ts2esm } from './ts2esm2cjs';\nimport type { PluginOptions } from './types';\n\nexport { esm2cjs, ts2esm } from './ts2esm2cjs';\nexport type { PluginOptions } from './types';\n\nfunction createAttribute(attributeName: string, attributeValue: MdxJsxAttribute['value']): MdxJsxAttribute {\n\treturn {\n\t\ttype: 'mdxJsxAttribute',\n\t\tname: attributeName,\n\t\tvalue: attributeValue\n\t};\n}\n\ninterface CreateTabItemOptions {\n\tcode: string;\n\tnode: Code;\n\tvalue: 'cjs' | 'esm' | 'typescript';\n\tlabel: string;\n}\n\nfunction createTabItem({ code, node, value, label }: CreateTabItemOptions): MdxJsxFlowElement {\n\tlet [, jsHighlight, tsHighlight] = (node.meta ?? '').split('|');\n\n\tif (!tsHighlight && jsHighlight) {\n\t\ttsHighlight = jsHighlight;\n\t}\n\n\treturn {\n\t\ttype: 'mdxJsxFlowElement',\n\t\tname: 'TabItem',\n\t\tattributes: [createAttribute('value', value), createAttribute('label', label)],\n\t\tchildren: [\n\t\t\t{\n\t\t\t\ttype: node.type,\n\t\t\t\tlang: node.lang,\n\t\t\t\tvalue: code,\n\t\t\t\tmeta: value === 'typescript' ? `${tsHighlight} showLineNumbers` : `${jsHighlight} showLineNumbers`\n\t\t\t}\n\t\t]\n\t};\n}\n\n/**\n * Transforms a Docusaurus node from TypeScript to ESM and CJS\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 = {\n\t\ttype: 'mdxJsxAttribute',\n\t\tname: 'groupId',\n\t\tvalue: 'ts2esm2cjs'\n\t};\n\n\tconst esmCode = ts2esm(node.value, options);\n\tconst cjsCode = esm2cjs(esmCode, options);\n\n\treturn [\n\t\t{\n\t\t\ttype: 'mdxJsxFlowElement',\n\t\t\tname: 'Tabs',\n\t\t\t...(options.sync && {\n\t\t\t\tattributes: [groupIdProp]\n\t\t\t}),\n\t\t\tchildren: [\n\t\t\t\tcreateTabItem({\n\t\t\t\t\tcode: cjsCode,\n\t\t\t\t\tnode,\n\t\t\t\t\tvalue: 'cjs',\n\t\t\t\t\tlabel: 'CommonJS'\n\t\t\t\t}),\n\t\t\t\tcreateTabItem({\n\t\t\t\t\tcode: esmCode,\n\t\t\t\t\tnode,\n\t\t\t\t\tvalue: 'esm',\n\t\t\t\t\tlabel: 'ESM'\n\t\t\t\t}),\n\t\t\t\tcreateTabItem({\n\t\t\t\t\tcode: node.value,\n\t\t\t\t\tnode,\n\t\t\t\t\tvalue: 'typescript',\n\t\t\t\t\tlabel: 'TypeScript'\n\t\t\t\t})\n\t\t\t]\n\t\t}\n\t] as RootContent[];\n};\n\nconst isMdxEsmLiteral = (node: Node): node is Literal => node.type === 'mdxjsEsm';\nconst isTabsImport = (node: Node): boolean => isMdxEsmLiteral(node) && node.value.includes('@theme/Tabs');\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('ts2esm2cjs');\n\nfunction createImportNode() {\n\treturn {\n\t\ttype: 'mdxjsEsm',\n\t\tvalue: \"import Tabs from '@theme/Tabs'\\nimport TabItem from '@theme/TabItem'\",\n\t\tdata: {\n\t\t\testree: {\n\t\t\t\ttype: 'Program',\n\t\t\t\tbody: [\n\t\t\t\t\t{\n\t\t\t\t\t\ttype: 'ImportDeclaration',\n\t\t\t\t\t\tspecifiers: [\n\t\t\t\t\t\t\t{\n\t\t\t\t\t\t\t\ttype: 'ImportDefaultSpecifier',\n\t\t\t\t\t\t\t\tlocal: { type: 'Identifier', name: 'Tabs' }\n\t\t\t\t\t\t\t}\n\t\t\t\t\t\t],\n\t\t\t\t\t\tsource: {\n\t\t\t\t\t\t\ttype: 'Literal',\n\t\t\t\t\t\t\tvalue: '@theme/Tabs',\n\t\t\t\t\t\t\traw: \"'@theme/Tabs'\"\n\t\t\t\t\t\t}\n\t\t\t\t\t},\n\t\t\t\t\t{\n\t\t\t\t\t\ttype: 'ImportDeclaration',\n\t\t\t\t\t\tspecifiers: [\n\t\t\t\t\t\t\t{\n\t\t\t\t\t\t\t\ttype: 'ImportDefaultSpecifier',\n\t\t\t\t\t\t\t\tlocal: { type: 'Identifier', name: 'TabItem' }\n\t\t\t\t\t\t\t}\n\t\t\t\t\t\t],\n\t\t\t\t\t\tsource: {\n\t\t\t\t\t\t\ttype: 'Literal',\n\t\t\t\t\t\t\tvalue: '@theme/TabItem',\n\t\t\t\t\t\t\traw: \"'@theme/TabItem'\"\n\t\t\t\t\t\t}\n\t\t\t\t\t}\n\t\t\t\t],\n\t\t\t\tsourceType: 'module'\n\t\t\t}\n\t\t}\n\t};\n}\n\nexport const ts2esm2cjs: Plugin<[PluginOptions?]> =\n\t(\n\t\t{ sync = true, prettierOptions = {}, typescriptCompilerOptions = {} } = { sync: true, prettierOptions: {}, typescriptCompilerOptions: {} }\n\t): Transformer =>\n\tasync (root) => {\n\t\tconst { visit } = await import('unist-util-visit');\n\n\t\tlet transformed = false;\n\t\tlet alreadyImported = false;\n\n\t\tvisit(root, (node: Node) => {\n\t\t\tif (isTabsImport(node)) {\n\t\t\t\talreadyImported = true;\n\t\t\t}\n\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, prettierOptions, typescriptCompilerOptions });\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\n\t\tif (transformed && !alreadyImported) {\n\t\t\t(root as Parent).children.unshift(createImportNode());\n\t\t}\n\t};\n"]}
@@ -1,8 +1,10 @@
1
- // src/ts2esm2cjs.ts
2
- import { format } from "@prettier/sync";
3
- import { runTransform } from "esm-to-cjs";
4
- import ts from "typescript";
5
- var makeTsCompilerOptions = (overrideOptions) => ({
1
+ import { format } from '@prettier/sync';
2
+ import { runTransform } from 'esm-to-cjs';
3
+ import ts from 'typescript';
4
+
5
+ var __defProp = Object.defineProperty;
6
+ var __name = (target, value) => __defProp(target, "name", { value, configurable: true });
7
+ var makeTsCompilerOptions = /* @__PURE__ */ __name((overrideOptions) => ({
6
8
  newLine: ts.NewLineKind.LineFeed,
7
9
  removeComments: false,
8
10
  esModuleInterop: true,
@@ -11,7 +13,7 @@ var makeTsCompilerOptions = (overrideOptions) => ({
11
13
  module: ts.ModuleKind.ESNext,
12
14
  moduleResolution: ts.ModuleResolutionKind.NodeJs,
13
15
  target: ts.ScriptTarget.ESNext
14
- });
16
+ }), "makeTsCompilerOptions");
15
17
  var documentationPrettierConfig = {
16
18
  endOfLine: "lf",
17
19
  quoteProps: "as-needed",
@@ -23,20 +25,22 @@ var documentationPrettierConfig = {
23
25
  printWidth: 120,
24
26
  parser: "babel"
25
27
  };
26
- var esmToCjs = (code) => runTransform(code, { quote: "single", lenDestructure: 128, lenModuleName: 128, lenIdentifier: 128 });
27
- var escapeNewLines = (code) => code.replace(/\n\n/g, "\n/* :newline: */");
28
- var restoreNewLines = (code) => code.replace(/\/\* :newline: \*\//g, "\n");
29
- var prettierFormatCode = (code, prettierConfig) => format(code, { ...documentationPrettierConfig, ...prettierConfig }).slice(0, -1);
30
- var tsToEsm = (code, options) => ts.transpileModule(code, { reportDiagnostics: false, compilerOptions: makeTsCompilerOptions(options.typescriptCompilerOptions) });
28
+ var esmToCjs = /* @__PURE__ */ __name((code) => runTransform(code, { quote: "single", lenDestructure: 128, lenModuleName: 128, lenIdentifier: 128 }), "esmToCjs");
29
+ var escapeNewLines = /* @__PURE__ */ __name((code) => code.replace(/\n\n/g, "\n/* :newline: */"), "escapeNewLines");
30
+ var restoreNewLines = /* @__PURE__ */ __name((code) => code.replace(/\/\* :newline: \*\//g, "\n"), "restoreNewLines");
31
+ var prettierFormatCode = /* @__PURE__ */ __name((code, prettierConfig) => format(code, { ...documentationPrettierConfig, ...prettierConfig }).slice(0, -1), "prettierFormatCode");
32
+ var tsToEsm = /* @__PURE__ */ __name((code, options) => ts.transpileModule(code, { reportDiagnostics: false, compilerOptions: makeTsCompilerOptions(options.typescriptCompilerOptions) }), "tsToEsm");
31
33
  function ts2esm(input, options) {
32
34
  const tsCode = escapeNewLines(input);
33
35
  const esmCode = tsToEsm(tsCode, { typescriptCompilerOptions: options.typescriptCompilerOptions }).outputText;
34
36
  return prettierFormatCode(restoreNewLines(esmCode), options.prettierOptions);
35
37
  }
38
+ __name(ts2esm, "ts2esm");
36
39
  function esm2cjs(input, options) {
37
40
  const cjsCode = esmToCjs(input);
38
41
  return prettierFormatCode(restoreNewLines(cjsCode), options.prettierOptions);
39
42
  }
43
+ __name(esm2cjs, "esm2cjs");
40
44
 
41
45
  // src/index.ts
42
46
  function createAttribute(attributeName, attributeValue) {
@@ -46,6 +50,7 @@ function createAttribute(attributeName, attributeValue) {
46
50
  value: attributeValue
47
51
  };
48
52
  }
53
+ __name(createAttribute, "createAttribute");
49
54
  function createTabItem({ code, node, value, label }) {
50
55
  let [, jsHighlight, tsHighlight] = (node.meta ?? "").split("|");
51
56
  if (!tsHighlight && jsHighlight) {
@@ -65,7 +70,8 @@ function createTabItem({ code, node, value, label }) {
65
70
  ]
66
71
  };
67
72
  }
68
- var transformNode = (node, options) => {
73
+ __name(createTabItem, "createTabItem");
74
+ var transformNode = /* @__PURE__ */ __name((node, options) => {
69
75
  const groupIdProp = {
70
76
  type: "mdxJsxAttribute",
71
77
  name: "groupId",
@@ -102,11 +108,11 @@ var transformNode = (node, options) => {
102
108
  ]
103
109
  }
104
110
  ];
105
- };
106
- var isMdxEsmLiteral = (node) => node.type === "mdxjsEsm";
107
- var isTabsImport = (node) => isMdxEsmLiteral(node) && node.value.includes("@theme/Tabs");
108
- var isParent = (node) => Array.isArray(node.children);
109
- var matchNode = (node) => node.type === "code" && typeof node.meta === "string" && (node.meta ?? "").startsWith("ts2esm2cjs");
111
+ }, "transformNode");
112
+ var isMdxEsmLiteral = /* @__PURE__ */ __name((node) => node.type === "mdxjsEsm", "isMdxEsmLiteral");
113
+ var isTabsImport = /* @__PURE__ */ __name((node) => isMdxEsmLiteral(node) && node.value.includes("@theme/Tabs"), "isTabsImport");
114
+ var isParent = /* @__PURE__ */ __name((node) => Array.isArray(node.children), "isParent");
115
+ var matchNode = /* @__PURE__ */ __name((node) => node.type === "code" && typeof node.meta === "string" && (node.meta ?? "").startsWith("ts2esm2cjs"), "matchNode");
110
116
  function createImportNode() {
111
117
  return {
112
118
  type: "mdxjsEsm",
@@ -149,8 +155,9 @@ function createImportNode() {
149
155
  }
150
156
  };
151
157
  }
152
- var ts2esm2cjs = ({ sync = true, prettierOptions = {}, typescriptCompilerOptions = {} } = { sync: true, prettierOptions: {}, typescriptCompilerOptions: {} }) => async (root) => {
153
- const { visit } = await import("unist-util-visit");
158
+ __name(createImportNode, "createImportNode");
159
+ var ts2esm2cjs = /* @__PURE__ */ __name(({ sync = true, prettierOptions = {}, typescriptCompilerOptions = {} } = { sync: true, prettierOptions: {}, typescriptCompilerOptions: {} }) => async (root) => {
160
+ const { visit } = await import('unist-util-visit');
154
161
  let transformed = false;
155
162
  let alreadyImported = false;
156
163
  visit(root, (node) => {
@@ -175,10 +182,8 @@ var ts2esm2cjs = ({ sync = true, prettierOptions = {}, typescriptCompilerOptions
175
182
  if (transformed && !alreadyImported) {
176
183
  root.children.unshift(createImportNode());
177
184
  }
178
- };
179
- export {
180
- esm2cjs,
181
- ts2esm,
182
- ts2esm2cjs
183
- };
185
+ }, "ts2esm2cjs");
186
+
187
+ export { esm2cjs, ts2esm, ts2esm2cjs };
188
+ //# sourceMappingURL=out.js.map
184
189
  //# sourceMappingURL=index.mjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../../src/ts2esm2cjs.ts","../../src/index.ts"],"names":[],"mappings":";;;;AAAA,SAAS,cAAc;AACvB,SAAS,oBAAoB;AAE7B,OAAO,QAAkC;AAGzC,IAAM,wBAAwB,wBAAC,qBAAwD;AAAA,EACtF,SAAS,GAAG,YAAY;AAAA,EACxB,gBAAgB;AAAA,EAChB,iBAAiB;AAAA,EACjB,QAAQ;AAAA,EACR,GAAG;AAAA,EACH,QAAQ,GAAG,WAAW;AAAA,EACtB,kBAAkB,GAAG,qBAAqB;AAAA,EAC1C,QAAQ,GAAG,aAAa;AACzB,IAT8B;AAW9B,IAAM,8BAAuC;AAAA,EAC5C,WAAW;AAAA,EACX,YAAY;AAAA,EACZ,MAAM;AAAA,EACN,aAAa;AAAA,EACb,eAAe;AAAA,EACf,UAAU;AAAA,EACV,SAAS;AAAA,EACT,YAAY;AAAA,EACZ,QAAQ;AACT;AAOA,IAAM,WAAW,wBAAC,SAAyB,aAAa,MAAM,EAAE,OAAO,UAAU,gBAAgB,KAAK,eAAe,KAAK,eAAe,IAAI,CAAC,GAA7H;AAOjB,IAAM,iBAAiB,wBAAC,SAAiB,KAAK,QAAQ,SAAS,mBAAmB,GAA3D;AAOvB,IAAM,kBAAkB,wBAAC,SAAyB,KAAK,QAAQ,wBAAwB,IAAI,GAAnE;AAQxB,IAAM,qBAAqB,wBAAC,MAAc,mBACzC,OAAO,MAAM,EAAE,GAAG,6BAA6B,GAAG,eAAe,CAAC,EAAE,MAAM,GAAG,EAAE,GADrD;AAQ3B,IAAM,UAAU,wBAAC,MAAc,YAC9B,GAAG,gBAAgB,MAAM,EAAE,mBAAmB,OAAO,iBAAiB,sBAAsB,QAAQ,yBAAyB,EAAE,CAAC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MAAM,UAAU;AAAA,cAC9C;AAAA,YACD;AAAA,YACA,QAAQ;AAAA,cACP,MAAM;AAAA,cACN,OAAO;AAAA,cACP,KAAK;AAAA,YACN;AAAA,UACD;AAAA,QACD;AAAA,QACA,YAAY;AAAA,MACb;AAAA,IACD;AAAA,EACD;AACD;AAzCS;AA2CF,IAAM,aACZ,wBACC,EAAE,OAAO,MAAM,kBAAkB,CAAC,GAAG,4BAA4B,CAAC,EAAE,IAAI,EAAE,MAAM,MAAM,iBAAiB,CAAC,GAAG,2BAA2B,CAAC,EAAE,MAE1I,OAAO,SAAS;AACf,QAAM,EAAE,MAAM,IAAI,MAAM,OAAO,kBAAkB;AAEjD,MAAI,cAAc;AAClB,MAAI,kBAAkB;AAEtB,QAAM,MAAM,CAAC,SAAe;AAC3B,QAAI,aAAa,IAAI,GAAG;AACvB,wBAAkB;AAAA,IACnB;AAEA,QAAI,SAAS,IAAI,GAAG;AACnB,UAAI,QAAQ;AACZ,aAAO,QAAQ,KAAK,SAAS,QAAQ;AACpC,cAAM,QAAQ,KAAK,SAAS,KAAK;AACjC,YAAI,UAAU,KAAK,GAAG;AACrB,gBAAM,SAAS,cAAc,OAAO,EAAE,MAAM,iBAAiB,0BAA0B,CAAC;AACxF,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;AAED,MAAI,eAAe,CAAC,iBAAiB;AACpC,IAAC,KAAgB,SAAS,QAAQ,iBAAiB,CAAC;AAAA,EACrD;AACD,GAjCA","sourcesContent":["import { format } from '@prettier/sync';\nimport { runTransform } from 'esm-to-cjs';\nimport type { Options } from 'prettier';\nimport ts, { type CompilerOptions } from 'typescript';\nimport type { PluginOptions } from './types';\n\nconst makeTsCompilerOptions = (overrideOptions?: CompilerOptions): CompilerOptions => ({\n\tnewLine: ts.NewLineKind.LineFeed,\n\tremoveComments: false,\n\tesModuleInterop: true,\n\tpretty: true,\n\t...overrideOptions,\n\tmodule: ts.ModuleKind.ESNext,\n\tmoduleResolution: ts.ModuleResolutionKind.NodeJs,\n\ttarget: ts.ScriptTarget.ESNext\n});\n\nconst documentationPrettierConfig: Options = {\n\tendOfLine: 'lf',\n\tquoteProps: 'as-needed',\n\tsemi: true,\n\tsingleQuote: true,\n\ttrailingComma: 'none',\n\ttabWidth: 2,\n\tuseTabs: false,\n\tprintWidth: 120,\n\tparser: 'babel'\n};\n\n/**\n * Transforms input ESM code to CJS code.\n * @param code The code to transform\n * @returns Input code transformed to CommonJS\n */\nconst esmToCjs = (code: string): string => runTransform(code, { quote: 'single', lenDestructure: 128, lenModuleName: 128, lenIdentifier: 128 });\n\n/**\n * Escaped new lines in code with block comments so they can be restored by {@link restoreNewLines}\n * @param code The code to escape new lines in\n * @returns The same code but with new lines escaped using block comments\n */\nconst escapeNewLines = (code: string) => code.replace(/\\n\\n/g, '\\n/* :newline: */');\n\n/**\n * Reverses {@link escapeNewLines} and restores new lines\n * @param code The code with escaped new lines\n * @returns The same code with new lines restored\n */\nconst restoreNewLines = (code: string): string => code.replace(/\\/\\* :newline: \\*\\//g, '\\n');\n\n/**\n * Formats the code using Prettier\n * @param code The code to prettier format\n * @param prettierConfig Additional prettier options to use for formatting\n * @returns Prettier formatted code\n */\nconst prettierFormatCode = (code: string, prettierConfig?: Options) =>\n\tformat(code, { ...documentationPrettierConfig, ...prettierConfig }).slice(0, -1);\n\n/**\n * Transpiles input TypeScript code to ESM code.\n * @param code The code to transpile\n * @returns Input code transpiled to ESM\n */\nconst tsToEsm = (code: string, options: Pick<PluginOptions, 'typescriptCompilerOptions'>): ts.TranspileOutput =>\n\tts.transpileModule(code, { reportDiagnostics: false, compilerOptions: makeTsCompilerOptions(options.typescriptCompilerOptions) });\n\n/**\n * Transforms input TypeScript code to ESM code.\n * @param input The TypeScript code to transform\n * @param options The plugin options\n * @returns The transformed code (ESM)\n */\nexport function ts2esm(input: string, options: PluginOptions) {\n\tconst tsCode = escapeNewLines(input);\n\tconst esmCode = tsToEsm(tsCode, { typescriptCompilerOptions: options.typescriptCompilerOptions }).outputText;\n\n\treturn prettierFormatCode(restoreNewLines(esmCode), options.prettierOptions);\n}\n\nexport function esm2cjs(input: string, options: PluginOptions) {\n\tconst cjsCode = esmToCjs(input);\n\n\treturn prettierFormatCode(restoreNewLines(cjsCode), options.prettierOptions);\n}\n","import type { Code, Literal, RootContent } from 'mdast';\nimport type { MdxJsxAttribute, MdxJsxFlowElement } from 'mdast-util-mdx';\nimport type { Plugin, Transformer } from 'unified';\nimport type { Node, Parent } from 'unist';\nimport { esm2cjs, ts2esm } from './ts2esm2cjs';\nimport type { PluginOptions } from './types';\n\nexport { esm2cjs, ts2esm } from './ts2esm2cjs';\nexport type { PluginOptions } from './types';\n\nfunction createAttribute(attributeName: string, attributeValue: MdxJsxAttribute['value']): MdxJsxAttribute {\n\treturn {\n\t\ttype: 'mdxJsxAttribute',\n\t\tname: attributeName,\n\t\tvalue: attributeValue\n\t};\n}\n\ninterface CreateTabItemOptions {\n\tcode: string;\n\tnode: Code;\n\tvalue: 'cjs' | 'esm' | 'typescript';\n\tlabel: string;\n}\n\nfunction createTabItem({ code, node, value, label }: CreateTabItemOptions): MdxJsxFlowElement {\n\tlet [, jsHighlight, tsHighlight] = (node.meta ?? '').split('|');\n\n\tif (!tsHighlight && jsHighlight) {\n\t\ttsHighlight = jsHighlight;\n\t}\n\n\treturn {\n\t\ttype: 'mdxJsxFlowElement',\n\t\tname: 'TabItem',\n\t\tattributes: [createAttribute('value', value), createAttribute('label', label)],\n\t\tchildren: [\n\t\t\t{\n\t\t\t\ttype: node.type,\n\t\t\t\tlang: node.lang,\n\t\t\t\tvalue: code,\n\t\t\t\tmeta: value === 'typescript' ? `${tsHighlight} showLineNumbers` : `${jsHighlight} showLineNumbers`\n\t\t\t}\n\t\t]\n\t};\n}\n\n/**\n * Transforms a Docusaurus node from TypeScript to ESM and CJS\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 = {\n\t\ttype: 'mdxJsxAttribute',\n\t\tname: 'groupId',\n\t\tvalue: 'ts2esm2cjs'\n\t};\n\n\tconst esmCode = ts2esm(node.value, options);\n\tconst cjsCode = esm2cjs(esmCode, options);\n\n\treturn [\n\t\t{\n\t\t\ttype: 'mdxJsxFlowElement',\n\t\t\tname: 'Tabs',\n\t\t\t...(options.sync && {\n\t\t\t\tattributes: [groupIdProp]\n\t\t\t}),\n\t\t\tchildren: [\n\t\t\t\tcreateTabItem({\n\t\t\t\t\tcode: cjsCode,\n\t\t\t\t\tnode,\n\t\t\t\t\tvalue: 'cjs',\n\t\t\t\t\tlabel: 'CommonJS'\n\t\t\t\t}),\n\t\t\t\tcreateTabItem({\n\t\t\t\t\tcode: esmCode,\n\t\t\t\t\tnode,\n\t\t\t\t\tvalue: 'esm',\n\t\t\t\t\tlabel: 'ESM'\n\t\t\t\t}),\n\t\t\t\tcreateTabItem({\n\t\t\t\t\tcode: node.value,\n\t\t\t\t\tnode,\n\t\t\t\t\tvalue: 'typescript',\n\t\t\t\t\tlabel: 'TypeScript'\n\t\t\t\t})\n\t\t\t]\n\t\t}\n\t] as RootContent[];\n};\n\nconst isMdxEsmLiteral = (node: Node): node is Literal => node.type === 'mdxjsEsm';\nconst isTabsImport = (node: Node): boolean => isMdxEsmLiteral(node) && node.value.includes('@theme/Tabs');\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('ts2esm2cjs');\n\nfunction createImportNode() {\n\treturn {\n\t\ttype: 'mdxjsEsm',\n\t\tvalue: \"import Tabs from '@theme/Tabs'\\nimport TabItem from '@theme/TabItem'\",\n\t\tdata: {\n\t\t\testree: {\n\t\t\t\ttype: 'Program',\n\t\t\t\tbody: [\n\t\t\t\t\t{\n\t\t\t\t\t\ttype: 'ImportDeclaration',\n\t\t\t\t\t\tspecifiers: [\n\t\t\t\t\t\t\t{\n\t\t\t\t\t\t\t\ttype: 'ImportDefaultSpecifier',\n\t\t\t\t\t\t\t\tlocal: { type: 'Identifier', name: 'Tabs' }\n\t\t\t\t\t\t\t}\n\t\t\t\t\t\t],\n\t\t\t\t\t\tsource: {\n\t\t\t\t\t\t\ttype: 'Literal',\n\t\t\t\t\t\t\tvalue: '@theme/Tabs',\n\t\t\t\t\t\t\traw: \"'@theme/Tabs'\"\n\t\t\t\t\t\t}\n\t\t\t\t\t},\n\t\t\t\t\t{\n\t\t\t\t\t\ttype: 'ImportDeclaration',\n\t\t\t\t\t\tspecifiers: [\n\t\t\t\t\t\t\t{\n\t\t\t\t\t\t\t\ttype: 'ImportDefaultSpecifier',\n\t\t\t\t\t\t\t\tlocal: { type: 'Identifier', name: 'TabItem' }\n\t\t\t\t\t\t\t}\n\t\t\t\t\t\t],\n\t\t\t\t\t\tsource: {\n\t\t\t\t\t\t\ttype: 'Literal',\n\t\t\t\t\t\t\tvalue: '@theme/TabItem',\n\t\t\t\t\t\t\traw: \"'@theme/TabItem'\"\n\t\t\t\t\t\t}\n\t\t\t\t\t}\n\t\t\t\t],\n\t\t\t\tsourceType: 'module'\n\t\t\t}\n\t\t}\n\t};\n}\n\nexport const ts2esm2cjs: Plugin<[PluginOptions?]> =\n\t(\n\t\t{ sync = true, prettierOptions = {}, typescriptCompilerOptions = {} } = { sync: true, prettierOptions: {}, typescriptCompilerOptions: {} }\n\t): Transformer =>\n\tasync (root) => {\n\t\tconst { visit } = await import('unist-util-visit');\n\n\t\tlet transformed = false;\n\t\tlet alreadyImported = false;\n\n\t\tvisit(root, (node: Node) => {\n\t\t\tif (isTabsImport(node)) {\n\t\t\t\talreadyImported = true;\n\t\t\t}\n\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, prettierOptions, typescriptCompilerOptions });\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\n\t\tif (transformed && !alreadyImported) {\n\t\t\t(root as Parent).children.unshift(createImportNode());\n\t\t}\n\t};\n"]}
package/package.json CHANGED
@@ -1,26 +1,27 @@
1
1
  {
2
2
  "name": "@sapphire/docusaurus-plugin-ts2esm2cjs",
3
- "version": "2.0.2-next.fafceb7.0",
3
+ "version": "2.0.3-next.c24a7a0.0",
4
4
  "description": "Docusaurus Remark plugin for converting TypeScript code to ESM and CJS code",
5
5
  "author": "@sapphire",
6
6
  "license": "MIT",
7
- "main": "dist/index.js",
8
- "module": "dist/index.mjs",
9
- "types": "dist/index.d.ts",
7
+ "main": "dist/cjs/index.cjs",
8
+ "module": "dist/esm/index.mjs",
9
+ "types": "dist/cjs/index.d.cts",
10
10
  "exports": {
11
11
  "import": {
12
- "types": "./dist/index.d.mts",
13
- "default": "./dist/index.mjs"
12
+ "types": "./dist/esm/index.d.mts",
13
+ "default": "./dist/esm/index.mjs"
14
14
  },
15
15
  "require": {
16
- "types": "./dist/index.d.ts",
17
- "default": "./dist/index.js"
16
+ "types": "./dist/cjs/index.d.cts",
17
+ "default": "./dist/cjs/index.cjs"
18
18
  }
19
19
  },
20
20
  "sideEffects": false,
21
21
  "scripts": {
22
22
  "lint": "eslint src --ext ts --fix",
23
- "build": "tsup",
23
+ "build": "tsup && yarn build:rename-cjs-index",
24
+ "build:rename-cjs-index": "node ../../scripts/rename-cjs-index.mjs",
24
25
  "typecheck": "tsc -p tsconfig.eslint.json",
25
26
  "prepack": "yarn build",
26
27
  "bump": "cliff-jumper",
@@ -31,7 +32,7 @@
31
32
  "@prettier/sync": "^0.3.0",
32
33
  "esm-to-cjs": "^1.2.1",
33
34
  "mdast-util-mdx": "^3.0.0",
34
- "typescript": "^5.2.2",
35
+ "typescript": "^5.3.3",
35
36
  "unified": "^11.0.4",
36
37
  "unist-util-visit": "^5.0.0"
37
38
  },
@@ -68,8 +69,8 @@
68
69
  },
69
70
  "devDependencies": {
70
71
  "@favware/cliff-jumper": "^2.2.3",
71
- "@sapphire/framework": "^4.8.2",
72
- "tsup": "^7.3.0",
73
- "vitest": "^0.34.6"
72
+ "@sapphire/framework": "^5.0.7",
73
+ "tsup": "^8.0.1",
74
+ "vitest": "^1.2.1"
74
75
  }
75
76
  }
package/dist/index.js.map DELETED
@@ -1 +0,0 @@
1
- {"version":3,"sources":["../src/index.ts","../src/ts2esm2cjs.ts"],"sourcesContent":["import type { Code, Literal, RootContent } from 'mdast';\nimport type { MdxJsxAttribute, MdxJsxFlowElement } from 'mdast-util-mdx';\nimport type { Plugin, Transformer } from 'unified';\nimport type { Node, Parent } from 'unist';\nimport { esm2cjs, ts2esm } from './ts2esm2cjs';\nimport type { PluginOptions } from './types';\n\nexport { esm2cjs, ts2esm } from './ts2esm2cjs';\nexport type { PluginOptions } from './types';\n\nfunction createAttribute(attributeName: string, attributeValue: MdxJsxAttribute['value']): MdxJsxAttribute {\n\treturn {\n\t\ttype: 'mdxJsxAttribute',\n\t\tname: attributeName,\n\t\tvalue: attributeValue\n\t};\n}\n\ninterface CreateTabItemOptions {\n\tcode: string;\n\tnode: Code;\n\tvalue: 'cjs' | 'esm' | 'typescript';\n\tlabel: string;\n}\n\nfunction createTabItem({ code, node, value, label }: CreateTabItemOptions): MdxJsxFlowElement {\n\tlet [, jsHighlight, tsHighlight] = (node.meta ?? '').split('|');\n\n\tif (!tsHighlight && jsHighlight) {\n\t\ttsHighlight = jsHighlight;\n\t}\n\n\treturn {\n\t\ttype: 'mdxJsxFlowElement',\n\t\tname: 'TabItem',\n\t\tattributes: [createAttribute('value', value), createAttribute('label', label)],\n\t\tchildren: [\n\t\t\t{\n\t\t\t\ttype: node.type,\n\t\t\t\tlang: node.lang,\n\t\t\t\tvalue: code,\n\t\t\t\tmeta: value === 'typescript' ? `${tsHighlight} showLineNumbers` : `${jsHighlight} showLineNumbers`\n\t\t\t}\n\t\t]\n\t};\n}\n\n/**\n * Transforms a Docusaurus node from TypeScript to ESM and CJS\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 = {\n\t\ttype: 'mdxJsxAttribute',\n\t\tname: 'groupId',\n\t\tvalue: 'ts2esm2cjs'\n\t};\n\n\tconst esmCode = ts2esm(node.value, options);\n\tconst cjsCode = esm2cjs(esmCode, options);\n\n\treturn [\n\t\t{\n\t\t\ttype: 'mdxJsxFlowElement',\n\t\t\tname: 'Tabs',\n\t\t\t...(options.sync && {\n\t\t\t\tattributes: [groupIdProp]\n\t\t\t}),\n\t\t\tchildren: [\n\t\t\t\tcreateTabItem({\n\t\t\t\t\tcode: cjsCode,\n\t\t\t\t\tnode,\n\t\t\t\t\tvalue: 'cjs',\n\t\t\t\t\tlabel: 'CommonJS'\n\t\t\t\t}),\n\t\t\t\tcreateTabItem({\n\t\t\t\t\tcode: esmCode,\n\t\t\t\t\tnode,\n\t\t\t\t\tvalue: 'esm',\n\t\t\t\t\tlabel: 'ESM'\n\t\t\t\t}),\n\t\t\t\tcreateTabItem({\n\t\t\t\t\tcode: node.value,\n\t\t\t\t\tnode,\n\t\t\t\t\tvalue: 'typescript',\n\t\t\t\t\tlabel: 'TypeScript'\n\t\t\t\t})\n\t\t\t]\n\t\t}\n\t] as RootContent[];\n};\n\nconst isMdxEsmLiteral = (node: Node): node is Literal => node.type === 'mdxjsEsm';\nconst isTabsImport = (node: Node): boolean => isMdxEsmLiteral(node) && node.value.includes('@theme/Tabs');\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('ts2esm2cjs');\n\nfunction createImportNode() {\n\treturn {\n\t\ttype: 'mdxjsEsm',\n\t\tvalue: \"import Tabs from '@theme/Tabs'\\nimport TabItem from '@theme/TabItem'\",\n\t\tdata: {\n\t\t\testree: {\n\t\t\t\ttype: 'Program',\n\t\t\t\tbody: [\n\t\t\t\t\t{\n\t\t\t\t\t\ttype: 'ImportDeclaration',\n\t\t\t\t\t\tspecifiers: [\n\t\t\t\t\t\t\t{\n\t\t\t\t\t\t\t\ttype: 'ImportDefaultSpecifier',\n\t\t\t\t\t\t\t\tlocal: { type: 'Identifier', name: 'Tabs' }\n\t\t\t\t\t\t\t}\n\t\t\t\t\t\t],\n\t\t\t\t\t\tsource: {\n\t\t\t\t\t\t\ttype: 'Literal',\n\t\t\t\t\t\t\tvalue: '@theme/Tabs',\n\t\t\t\t\t\t\traw: \"'@theme/Tabs'\"\n\t\t\t\t\t\t}\n\t\t\t\t\t},\n\t\t\t\t\t{\n\t\t\t\t\t\ttype: 'ImportDeclaration',\n\t\t\t\t\t\tspecifiers: [\n\t\t\t\t\t\t\t{\n\t\t\t\t\t\t\t\ttype: 'ImportDefaultSpecifier',\n\t\t\t\t\t\t\t\tlocal: { type: 'Identifier', name: 'TabItem' }\n\t\t\t\t\t\t\t}\n\t\t\t\t\t\t],\n\t\t\t\t\t\tsource: {\n\t\t\t\t\t\t\ttype: 'Literal',\n\t\t\t\t\t\t\tvalue: '@theme/TabItem',\n\t\t\t\t\t\t\traw: \"'@theme/TabItem'\"\n\t\t\t\t\t\t}\n\t\t\t\t\t}\n\t\t\t\t],\n\t\t\t\tsourceType: 'module'\n\t\t\t}\n\t\t}\n\t};\n}\n\nexport const ts2esm2cjs: Plugin<[PluginOptions?]> =\n\t(\n\t\t{ sync = true, prettierOptions = {}, typescriptCompilerOptions = {} } = { sync: true, prettierOptions: {}, typescriptCompilerOptions: {} }\n\t): Transformer =>\n\tasync (root) => {\n\t\tconst { visit } = await import('unist-util-visit');\n\n\t\tlet transformed = false;\n\t\tlet alreadyImported = false;\n\n\t\tvisit(root, (node: Node) => {\n\t\t\tif (isTabsImport(node)) {\n\t\t\t\talreadyImported = true;\n\t\t\t}\n\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, prettierOptions, typescriptCompilerOptions });\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\n\t\tif (transformed && !alreadyImported) {\n\t\t\t(root as Parent).children.unshift(createImportNode());\n\t\t}\n\t};\n","import { format } from '@prettier/sync';\nimport { runTransform } from 'esm-to-cjs';\nimport type { Options } from 'prettier';\nimport ts, { type CompilerOptions } from 'typescript';\nimport type { PluginOptions } from './types';\n\nconst makeTsCompilerOptions = (overrideOptions?: CompilerOptions): CompilerOptions => ({\n\tnewLine: ts.NewLineKind.LineFeed,\n\tremoveComments: false,\n\tesModuleInterop: true,\n\tpretty: true,\n\t...overrideOptions,\n\tmodule: ts.ModuleKind.ESNext,\n\tmoduleResolution: ts.ModuleResolutionKind.NodeJs,\n\ttarget: ts.ScriptTarget.ESNext\n});\n\nconst documentationPrettierConfig: Options = {\n\tendOfLine: 'lf',\n\tquoteProps: 'as-needed',\n\tsemi: true,\n\tsingleQuote: true,\n\ttrailingComma: 'none',\n\ttabWidth: 2,\n\tuseTabs: false,\n\tprintWidth: 120,\n\tparser: 'babel'\n};\n\n/**\n * Transforms input ESM code to CJS code.\n * @param code The code to transform\n * @returns Input code transformed to CommonJS\n */\nconst esmToCjs = (code: string): string => runTransform(code, { quote: 'single', lenDestructure: 128, lenModuleName: 128, lenIdentifier: 128 });\n\n/**\n * Escaped new lines in code with block comments so they can be restored by {@link restoreNewLines}\n * @param code The code to escape new lines in\n * @returns The same code but with new lines escaped using block comments\n */\nconst escapeNewLines = (code: string) => code.replace(/\\n\\n/g, '\\n/* :newline: */');\n\n/**\n * Reverses {@link escapeNewLines} and restores new lines\n * @param code The code with escaped new lines\n * @returns The same code with new lines restored\n */\nconst restoreNewLines = (code: string): string => code.replace(/\\/\\* :newline: \\*\\//g, '\\n');\n\n/**\n * Formats the code using Prettier\n * @param code The code to prettier format\n * @param prettierConfig Additional prettier options to use for formatting\n * @returns Prettier formatted code\n */\nconst prettierFormatCode = (code: string, prettierConfig?: Options) =>\n\tformat(code, { ...documentationPrettierConfig, ...prettierConfig }).slice(0, -1);\n\n/**\n * Transpiles input TypeScript code to ESM code.\n * @param code The code to transpile\n * @returns Input code transpiled to ESM\n */\nconst tsToEsm = (code: string, options: Pick<PluginOptions, 'typescriptCompilerOptions'>): ts.TranspileOutput =>\n\tts.transpileModule(code, { reportDiagnostics: false, compilerOptions: makeTsCompilerOptions(options.typescriptCompilerOptions) });\n\n/**\n * Transforms input TypeScript code to ESM code.\n * @param input The TypeScript code to transform\n * @param options The plugin options\n * @returns The transformed code (ESM)\n */\nexport function ts2esm(input: string, options: PluginOptions) {\n\tconst tsCode = escapeNewLines(input);\n\tconst esmCode = tsToEsm(tsCode, { typescriptCompilerOptions: options.typescriptCompilerOptions }).outputText;\n\n\treturn prettierFormatCode(restoreNewLines(esmCode), options.prettierOptions);\n}\n\nexport function esm2cjs(input: string, options: PluginOptions) {\n\tconst cjsCode = esmToCjs(input);\n\n\treturn prettierFormatCode(restoreNewLines(cjsCode), options.prettierOptions);\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAA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AAC,GAAG,2BAA2B,CAAC,EAAE,MAE1I,OAAO,SAAS;AACf,QAAM,EAAE,MAAM,IAAI,MAAM,OAAO,kBAAkB;AAEjD,MAAI,cAAc;AAClB,MAAI,kBAAkB;AAEtB,QAAM,MAAM,CAAC,SAAe;AAC3B,QAAI,aAAa,IAAI,GAAG;AACvB,wBAAkB;AAAA,IACnB;AAEA,QAAI,SAAS,IAAI,GAAG;AACnB,UAAI,QAAQ;AACZ,aAAO,QAAQ,KAAK,SAAS,QAAQ;AACpC,cAAM,QAAQ,KAAK,SAAS,KAAK;AACjC,YAAI,UAAU,KAAK,GAAG;AACrB,gBAAM,SAAS,cAAc,OAAO,EAAE,MAAM,iBAAiB,0BAA0B,CAAC;AACxF,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;AAED,MAAI,eAAe,CAAC,iBAAiB;AACpC,IAAC,KAAgB,SAAS,QAAQ,iBAAiB,CAAC;AAAA,EACrD;AACD;","names":["ts"]}
@@ -1 +0,0 @@
1
- {"version":3,"sources":["../src/ts2esm2cjs.ts","../src/index.ts"],"sourcesContent":["import { format } from '@prettier/sync';\nimport { runTransform } from 'esm-to-cjs';\nimport type { Options } from 'prettier';\nimport ts, { type CompilerOptions } from 'typescript';\nimport type { PluginOptions } from './types';\n\nconst makeTsCompilerOptions = (overrideOptions?: CompilerOptions): CompilerOptions => ({\n\tnewLine: ts.NewLineKind.LineFeed,\n\tremoveComments: false,\n\tesModuleInterop: true,\n\tpretty: true,\n\t...overrideOptions,\n\tmodule: ts.ModuleKind.ESNext,\n\tmoduleResolution: ts.ModuleResolutionKind.NodeJs,\n\ttarget: ts.ScriptTarget.ESNext\n});\n\nconst documentationPrettierConfig: Options = {\n\tendOfLine: 'lf',\n\tquoteProps: 'as-needed',\n\tsemi: true,\n\tsingleQuote: true,\n\ttrailingComma: 'none',\n\ttabWidth: 2,\n\tuseTabs: false,\n\tprintWidth: 120,\n\tparser: 'babel'\n};\n\n/**\n * Transforms input ESM code to CJS code.\n * @param code The code to transform\n * @returns Input code transformed to CommonJS\n */\nconst esmToCjs = (code: string): string => runTransform(code, { quote: 'single', lenDestructure: 128, lenModuleName: 128, lenIdentifier: 128 });\n\n/**\n * Escaped new lines in code with block comments so they can be restored by {@link restoreNewLines}\n * @param code The code to escape new lines in\n * @returns The same code but with new lines escaped using block comments\n */\nconst escapeNewLines = (code: string) => code.replace(/\\n\\n/g, '\\n/* :newline: */');\n\n/**\n * Reverses {@link escapeNewLines} and restores new lines\n * @param code The code with escaped new lines\n * @returns The same code with new lines restored\n */\nconst restoreNewLines = (code: string): string => code.replace(/\\/\\* :newline: \\*\\//g, '\\n');\n\n/**\n * Formats the code using Prettier\n * @param code The code to prettier format\n * @param prettierConfig Additional prettier options to use for formatting\n * @returns Prettier formatted code\n */\nconst prettierFormatCode = (code: string, prettierConfig?: Options) =>\n\tformat(code, { ...documentationPrettierConfig, ...prettierConfig }).slice(0, -1);\n\n/**\n * Transpiles input TypeScript code to ESM code.\n * @param code The code to transpile\n * @returns Input code transpiled to ESM\n */\nconst tsToEsm = (code: string, options: Pick<PluginOptions, 'typescriptCompilerOptions'>): ts.TranspileOutput =>\n\tts.transpileModule(code, { reportDiagnostics: false, compilerOptions: makeTsCompilerOptions(options.typescriptCompilerOptions) });\n\n/**\n * Transforms input TypeScript code to ESM code.\n * @param input The TypeScript code to transform\n * @param options The plugin options\n * @returns The transformed code (ESM)\n */\nexport function ts2esm(input: string, options: PluginOptions) {\n\tconst tsCode = escapeNewLines(input);\n\tconst esmCode = tsToEsm(tsCode, { typescriptCompilerOptions: options.typescriptCompilerOptions }).outputText;\n\n\treturn prettierFormatCode(restoreNewLines(esmCode), options.prettierOptions);\n}\n\nexport function esm2cjs(input: string, options: PluginOptions) {\n\tconst cjsCode = esmToCjs(input);\n\n\treturn prettierFormatCode(restoreNewLines(cjsCode), options.prettierOptions);\n}\n","import type { Code, Literal, RootContent } from 'mdast';\nimport type { MdxJsxAttribute, MdxJsxFlowElement } from 'mdast-util-mdx';\nimport type { Plugin, Transformer } from 'unified';\nimport type { Node, Parent } from 'unist';\nimport { esm2cjs, ts2esm } from './ts2esm2cjs';\nimport type { PluginOptions } from './types';\n\nexport { esm2cjs, ts2esm } from './ts2esm2cjs';\nexport type { PluginOptions } from './types';\n\nfunction createAttribute(attributeName: string, attributeValue: MdxJsxAttribute['value']): MdxJsxAttribute {\n\treturn {\n\t\ttype: 'mdxJsxAttribute',\n\t\tname: attributeName,\n\t\tvalue: attributeValue\n\t};\n}\n\ninterface CreateTabItemOptions {\n\tcode: string;\n\tnode: Code;\n\tvalue: 'cjs' | 'esm' | 'typescript';\n\tlabel: string;\n}\n\nfunction createTabItem({ code, node, value, label }: CreateTabItemOptions): MdxJsxFlowElement {\n\tlet [, jsHighlight, tsHighlight] = (node.meta ?? '').split('|');\n\n\tif (!tsHighlight && jsHighlight) {\n\t\ttsHighlight = jsHighlight;\n\t}\n\n\treturn {\n\t\ttype: 'mdxJsxFlowElement',\n\t\tname: 'TabItem',\n\t\tattributes: [createAttribute('value', value), createAttribute('label', label)],\n\t\tchildren: [\n\t\t\t{\n\t\t\t\ttype: node.type,\n\t\t\t\tlang: node.lang,\n\t\t\t\tvalue: code,\n\t\t\t\tmeta: value === 'typescript' ? `${tsHighlight} showLineNumbers` : `${jsHighlight} showLineNumbers`\n\t\t\t}\n\t\t]\n\t};\n}\n\n/**\n * Transforms a Docusaurus node from TypeScript to ESM and CJS\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 = {\n\t\ttype: 'mdxJsxAttribute',\n\t\tname: 'groupId',\n\t\tvalue: 'ts2esm2cjs'\n\t};\n\n\tconst esmCode = ts2esm(node.value, options);\n\tconst cjsCode = esm2cjs(esmCode, options);\n\n\treturn [\n\t\t{\n\t\t\ttype: 'mdxJsxFlowElement',\n\t\t\tname: 'Tabs',\n\t\t\t...(options.sync && {\n\t\t\t\tattributes: [groupIdProp]\n\t\t\t}),\n\t\t\tchildren: [\n\t\t\t\tcreateTabItem({\n\t\t\t\t\tcode: cjsCode,\n\t\t\t\t\tnode,\n\t\t\t\t\tvalue: 'cjs',\n\t\t\t\t\tlabel: 'CommonJS'\n\t\t\t\t}),\n\t\t\t\tcreateTabItem({\n\t\t\t\t\tcode: esmCode,\n\t\t\t\t\tnode,\n\t\t\t\t\tvalue: 'esm',\n\t\t\t\t\tlabel: 'ESM'\n\t\t\t\t}),\n\t\t\t\tcreateTabItem({\n\t\t\t\t\tcode: node.value,\n\t\t\t\t\tnode,\n\t\t\t\t\tvalue: 'typescript',\n\t\t\t\t\tlabel: 'TypeScript'\n\t\t\t\t})\n\t\t\t]\n\t\t}\n\t] as RootContent[];\n};\n\nconst isMdxEsmLiteral = (node: Node): node is Literal => node.type === 'mdxjsEsm';\nconst isTabsImport = (node: Node): boolean => isMdxEsmLiteral(node) && node.value.includes('@theme/Tabs');\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('ts2esm2cjs');\n\nfunction createImportNode() {\n\treturn {\n\t\ttype: 'mdxjsEsm',\n\t\tvalue: \"import Tabs from '@theme/Tabs'\\nimport TabItem from '@theme/TabItem'\",\n\t\tdata: {\n\t\t\testree: {\n\t\t\t\ttype: 'Program',\n\t\t\t\tbody: [\n\t\t\t\t\t{\n\t\t\t\t\t\ttype: 'ImportDeclaration',\n\t\t\t\t\t\tspecifiers: [\n\t\t\t\t\t\t\t{\n\t\t\t\t\t\t\t\ttype: 'ImportDefaultSpecifier',\n\t\t\t\t\t\t\t\tlocal: { type: 'Identifier', name: 'Tabs' }\n\t\t\t\t\t\t\t}\n\t\t\t\t\t\t],\n\t\t\t\t\t\tsource: {\n\t\t\t\t\t\t\ttype: 'Literal',\n\t\t\t\t\t\t\tvalue: '@theme/Tabs',\n\t\t\t\t\t\t\traw: \"'@theme/Tabs'\"\n\t\t\t\t\t\t}\n\t\t\t\t\t},\n\t\t\t\t\t{\n\t\t\t\t\t\ttype: 'ImportDeclaration',\n\t\t\t\t\t\tspecifiers: [\n\t\t\t\t\t\t\t{\n\t\t\t\t\t\t\t\ttype: 'ImportDefaultSpecifier',\n\t\t\t\t\t\t\t\tlocal: { type: 'Identifier', name: 'TabItem' }\n\t\t\t\t\t\t\t}\n\t\t\t\t\t\t],\n\t\t\t\t\t\tsource: {\n\t\t\t\t\t\t\ttype: 'Literal',\n\t\t\t\t\t\t\tvalue: '@theme/TabItem',\n\t\t\t\t\t\t\traw: \"'@theme/TabItem'\"\n\t\t\t\t\t\t}\n\t\t\t\t\t}\n\t\t\t\t],\n\t\t\t\tsourceType: 'module'\n\t\t\t}\n\t\t}\n\t};\n}\n\nexport const ts2esm2cjs: Plugin<[PluginOptions?]> =\n\t(\n\t\t{ sync = true, prettierOptions = {}, typescriptCompilerOptions = {} } = { sync: true, prettierOptions: {}, typescriptCompilerOptions: {} }\n\t): Transformer =>\n\tasync (root) => {\n\t\tconst { visit } = await import('unist-util-visit');\n\n\t\tlet transformed = false;\n\t\tlet alreadyImported = false;\n\n\t\tvisit(root, (node: Node) => {\n\t\t\tif (isTabsImport(node)) {\n\t\t\t\talreadyImported = true;\n\t\t\t}\n\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, prettierOptions, typescriptCompilerOptions });\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 {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