@sapphire/docusaurus-plugin-ts2esm2cjs 1.1.0-next.fadcdcf.0 → 1.1.1-next.eb82505.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/CHANGELOG.md ADDED
@@ -0,0 +1,57 @@
1
+ # Changelog
2
+
3
+ All notable changes to this project will be documented in this file.
4
+
5
+ # [@sapphire/docusaurus-plugin-ts2esm2cjs@1.1.0](https://github.com/sapphiredev/documentation-plugins/compare/@sapphire/docusaurus-plugin-ts2esm2cjs@1.0.3...@sapphire/docusaurus-plugin-ts2esm2cjs@1.1.0) - (2022-05-15)
6
+
7
+ ## 🐛 Bug Fixes
8
+
9
+ - Restore tsup (reverts 7411ff7) ([7df536b](https://github.com/sapphiredev/documentation-plugins/commit/7df536bd871b45d0cfa65816684bc691b4735bc0))
10
+ - Remove tsup ([7411ff7](https://github.com/sapphiredev/documentation-plugins/commit/7411ff79624eec777519a2a049c8d3f026871cac))
11
+ - **ts2esm2cjs:** Ensure compatibility with docusaurus v2 beta 20 ([c1c4716](https://github.com/sapphiredev/documentation-plugins/commit/c1c4716ac51f3ad28099dd9bf13dabe064b014bb))
12
+
13
+ ## 🚀 Features
14
+
15
+ - Allow module: NodeNext ([8221bc2](https://github.com/sapphiredev/documentation-plugins/commit/8221bc2668fd1ad9c2e80c3c6a1503ae27bfc632))
16
+
17
+ ## [1.0.3](https://github.com/sapphiredev/documentation-plugins/compare/@sapphire/docusaurus-plugin-ts2esm2cjs@1.0.2...@sapphire/docusaurus-plugin-ts2esm2cjs@1.0.3) (2022-01-13)
18
+
19
+ ### Bug Fixes
20
+
21
+ - **ts2esm2cjs:** switch back to published package of esm-to-cjs ([0ca3884](https://github.com/sapphiredev/documentation-plugins/commit/0ca388495cf91a7c4ab19c24bd48e0d992e0f821))
22
+
23
+ ### Reverts
24
+
25
+ - Revert "fix(ts2esm2cjs): fixed imports that have `as` in their name" ([684b297](https://github.com/sapphiredev/documentation-plugins/commit/684b2975f08df8a00ed2a6f5576770e6c7168383))
26
+
27
+ ## [1.0.2](https://github.com/sapphiredev/documentation-plugins/compare/@sapphire/docusaurus-plugin-ts2esm2cjs@1.0.1...@sapphire/docusaurus-plugin-ts2esm2cjs@1.0.2) (2022-01-12)
28
+
29
+ ### Bug Fixes
30
+
31
+ - **ts2esm2cjs:** fixed imports that have `as` in their name ([147c85d](https://github.com/sapphiredev/documentation-plugins/commit/147c85db866ac0544b4bcc62aa5e54a9f3009903))
32
+
33
+ ### Reverts
34
+
35
+ - Revert "ci: try adding extra dev deps for ci" ([de49260](https://github.com/sapphiredev/documentation-plugins/commit/de49260d4d8c4be4bb27d53f13472946e4cd3700))
36
+
37
+ ## [1.0.1](https://github.com/sapphiredev/documentation-plugins/compare/@sapphire/docusaurus-plugin-ts2esm2cjs@1.0.0...@sapphire/docusaurus-plugin-ts2esm2cjs@1.0.1) (2021-11-30)
38
+
39
+ ### Bug Fixes
40
+
41
+ - **ts2esm2cjs:** allow longer lengths for esm to cjs ([280746c](https://github.com/sapphiredev/documentation-plugins/commit/280746cbf7120c9baddf8deac436ea0a9ba1835e))
42
+
43
+ # 1.0.0 (2021-11-26)
44
+
45
+ ### Bug Fixes
46
+
47
+ - **ts2esm2cjs:** removed esm exports to ensure cjs works fine with require syntax ([73b6898](https://github.com/sapphiredev/documentation-plugins/commit/73b6898881374259f9a38b74fe741cf46a468e06))
48
+ - **ts2esm2cjs:** removed exports field from package.json ([7dfac94](https://github.com/sapphiredev/documentation-plugins/commit/7dfac9464b28caa8e2d0dc03040a1b38f6b02d68))
49
+
50
+ ### Features
51
+
52
+ - add ts2esm2cjs package ([35ec87d](https://github.com/sapphiredev/documentation-plugins/commit/35ec87dd8743aecc57c344b1d2d4ae88038fcd7b))
53
+ - **ts2esm2cjs:** add option to customize tsc options ([af19a1d](https://github.com/sapphiredev/documentation-plugins/commit/af19a1d8473b8a3723933f87f8a0c6f79e98ebc7))
54
+
55
+ ### Reverts
56
+
57
+ - Revert "fix(typedoc-djs-links): removed esm exports to ensure cjs works fine with require syntax" ([7b4c6ab](https://github.com/sapphiredev/documentation-plugins/commit/7b4c6ab434265903213d7d965b0e927912b1aba1))
package/dist/index.d.ts CHANGED
@@ -1,19 +1,10 @@
1
1
  import { Options } from 'prettier';
2
2
  import { CompilerOptions } from 'typescript';
3
+ import type { Plugin } from 'unified';
3
4
  export interface PluginOptions {
4
5
  sync?: boolean;
5
6
  prettierOptions?: Options;
6
7
  typescriptCompilerOptions?: CompilerOptions;
7
8
  }
8
- export declare function ts2esm2cjs({ sync, prettierOptions, typescriptCompilerOptions }?: PluginOptions): (node: any) => ({
9
- type: string;
10
- value: string;
11
- lang?: undefined;
12
- meta?: undefined;
13
- } | {
14
- type: any;
15
- lang: any;
16
- meta: any;
17
- value: any;
18
- })[] | null;
9
+ export declare const ts2esm2cjs: Plugin<[PluginOptions?]>;
19
10
  //# sourceMappingURL=index.d.ts.map
package/dist/index.js CHANGED
@@ -29,6 +29,7 @@ var import_prettier_config = __toESM(require("@sapphire/prettier-config"));
29
29
  var import_esm_to_cjs = require("esm-to-cjs");
30
30
  var import_prettier = __toESM(require("prettier"));
31
31
  var import_typescript = __toESM(require("typescript"));
32
+ var import_unist_util_visit = __toESM(require("unist-util-visit"));
32
33
  var documentationPrettierConfig = {
33
34
  ...import_prettier_config.default,
34
35
  tabWidth: 2,
@@ -52,26 +53,28 @@ var escapeNewLines = (code) => code.replace(/\n\n/g, "\n/* :newline: */");
52
53
  var restoreNewLines = (code) => code.replace(/\/\* :newline: \*\//g, "\n");
53
54
  var prettierFormatCode = (code, prettierConfig) => import_prettier.default.format(code, { ...documentationPrettierConfig, ...prettierConfig }).slice(0, -1);
54
55
  var transformNode = (node, options) => {
55
- const groupIdProp = options.sync ? 'groupId="ts2esm2cjs" ' : "";
56
+ const groupIdProp = options.sync ? ' groupId="ts2esm2cjs"' : "";
56
57
  const tsCode = escapeNewLines(node.value);
57
58
  const esmCode = tsToEsm(tsCode, { typescriptCompilerOptions: options.typescriptCompilerOptions }).outputText;
58
59
  const cjsCode = esmToCjs(esmCode);
59
- const [, jsHighlight, tsHighlight] = node.meta.split("|");
60
+ const [, jsHighlight, tsHighlight] = (node.meta ?? "").split("|");
60
61
  return [
61
62
  {
62
63
  type: "jsx",
63
- value: `<Tabs defaultValue="typescript" ${groupIdProp}values={[
64
- { label: 'JavaScript', value: 'javascript', },
65
- { label: 'ESM', value: 'esm', },
66
- { label: 'TypeScript', value: 'typescript', },
67
- ]}
68
- >
64
+ value: `<Tabs${groupIdProp}
65
+ defaultValue="typescript"
66
+ values={[
67
+ { label: "JavaScript", value: "javascript" },
68
+ { label: "ESM", value: "esm" },
69
+ { label: "TypeScript", value: "typescript" },
70
+ ]}
71
+ >
69
72
  <TabItem value="javascript">`
70
73
  },
71
74
  {
72
75
  type: node.type,
73
76
  lang: node.lang,
74
- meta: jsHighlight,
77
+ meta: `${jsHighlight} showLineNumbers`,
75
78
  value: prettierFormatCode(restoreNewLines(cjsCode), options.prettierOptions)
76
79
  },
77
80
  {
@@ -81,7 +84,7 @@ var transformNode = (node, options) => {
81
84
  {
82
85
  type: node.type,
83
86
  lang: node.lang,
84
- meta: jsHighlight,
87
+ meta: `${jsHighlight} showLineNumbers`,
85
88
  value: prettierFormatCode(restoreNewLines(esmCode), options.prettierOptions)
86
89
  },
87
90
  {
@@ -91,7 +94,7 @@ var transformNode = (node, options) => {
91
94
  {
92
95
  type: node.type,
93
96
  lang: node.lang,
94
- meta: tsHighlight,
97
+ meta: `${tsHighlight} showLineNumbers`,
95
98
  value: node.value
96
99
  },
97
100
  {
@@ -100,45 +103,41 @@ var transformNode = (node, options) => {
100
103
  }
101
104
  ];
102
105
  };
103
- var matchNode = (node) => node.type === "code" && typeof node.meta === "string" && node.meta.startsWith("ts2esm2cjs");
106
+ var isImport = (node) => node.type === "import";
107
+ var isParent = (node) => Array.isArray(node.children);
108
+ var matchNode = (node) => node.type === "code" && typeof node.meta === "string" && (node.meta ?? "").startsWith("ts2esm2cjs");
104
109
  var nodeForImport = {
105
110
  type: "import",
106
111
  value: "import Tabs from '@theme/Tabs';\nimport TabItem from '@theme/TabItem';"
107
112
  };
108
- function ts2esm2cjs({ sync = true, prettierOptions = {}, typescriptCompilerOptions = {} } = {
109
- sync: true,
110
- prettierOptions: {},
111
- typescriptCompilerOptions: {}
112
- }) {
113
- let transformed = false;
114
- let alreadyImported = false;
115
- const transformer = (node) => {
116
- if (node.type === "import" && node.value.includes("@theme/Tabs")) {
117
- alreadyImported = true;
118
- }
119
- if (matchNode(node)) {
120
- transformed = true;
121
- return transformNode(node, { sync, prettierOptions, typescriptCompilerOptions });
122
- }
123
- if (Array.isArray(node.children)) {
124
- let index = 0;
125
- while (index < node.children.length) {
126
- const result = transformer(node.children[index]);
127
- if (result) {
128
- node.children.splice(index, 1, ...result);
129
- index += result.length;
130
- } else {
131
- index += 1;
113
+ var ts2esm2cjs = ({ sync = true, prettierOptions = {}, typescriptCompilerOptions = {} } = { sync: true, prettierOptions: {}, typescriptCompilerOptions: {} }) => {
114
+ return (root) => {
115
+ let transformed = false;
116
+ let alreadyImported = false;
117
+ (0, import_unist_util_visit.default)(root, (node) => {
118
+ if (isImport(node) && node.value.includes("@theme/Tabs")) {
119
+ alreadyImported = true;
120
+ }
121
+ if (isParent(node)) {
122
+ let index = 0;
123
+ while (index < node.children.length) {
124
+ const child = node.children[index];
125
+ if (matchNode(child)) {
126
+ const result = transformNode(child, { sync, prettierOptions, typescriptCompilerOptions });
127
+ node.children.splice(index, 1, ...result);
128
+ index += result.length;
129
+ transformed = true;
130
+ } else {
131
+ index += 1;
132
+ }
132
133
  }
133
134
  }
135
+ });
136
+ if (transformed && !alreadyImported) {
137
+ root.children.unshift(nodeForImport);
134
138
  }
135
- if (node.type === "root" && transformed && !alreadyImported) {
136
- node.children.unshift(nodeForImport);
137
- }
138
- return null;
139
139
  };
140
- return transformer;
141
- }
140
+ };
142
141
  // Annotate the CommonJS export names for ESM import in node:
143
142
  0 && (module.exports = {
144
143
  ts2esm2cjs
package/dist/index.js.map CHANGED
@@ -1 +1 @@
1
- {"version":3,"sources":["../src/index.ts"],"sourcesContent":["import sapphirePrettierConfig from '@sapphire/prettier-config';\nimport { runTransform } from 'esm-to-cjs';\nimport prettier, { Options } from 'prettier';\nimport ts, { CompilerOptions } from 'typescript';\n\nconst documentationPrettierConfig: Options = {\n\t...sapphirePrettierConfig,\n\ttabWidth: 2,\n\tuseTabs: false,\n\tprintWidth: 120,\n\tparser: 'babel'\n};\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\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 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\tprettier.format(code, { ...documentationPrettierConfig, ...prettierConfig }).slice(0, -1);\n\n/**\n * Transforms a Docusaurus node from TypeScript to ESM and CJS\n * @param node The Docusaurus node to transform\n * @param isSync Whether the transform should synchronize between all entries of this type\n * @returns The transformed node in the form of Tabs.\n */\nconst transformNode = (node: any, options: PluginOptions) => {\n\tconst groupIdProp = options.sync ? 'groupId=\"ts2esm2cjs\" ' : '';\n\n\tconst tsCode = escapeNewLines(node.value);\n\tconst esmCode = tsToEsm(tsCode, { typescriptCompilerOptions: options.typescriptCompilerOptions }).outputText;\n\tconst cjsCode = esmToCjs(esmCode);\n\n\tconst [, jsHighlight, tsHighlight] = 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=\"typescript\" ${groupIdProp}` +\n\t\t\t\t`values={[\n { label: 'JavaScript', value: 'javascript', },\n { label: 'ESM', value: 'esm', },\n { label: 'TypeScript', value: 'typescript', },\n ]}\n>\n<TabItem value=\"javascript\">`\n\t\t},\n\t\t{\n\t\t\ttype: node.type,\n\t\t\tlang: node.lang,\n\t\t\tmeta: jsHighlight,\n\t\t\tvalue: prettierFormatCode(restoreNewLines(cjsCode), options.prettierOptions)\n\t\t},\n\t\t{\n\t\t\ttype: 'jsx',\n\t\t\tvalue: '</TabItem>\\n<TabItem value=\"esm\">'\n\t\t},\n\t\t{\n\t\t\ttype: node.type,\n\t\t\tlang: node.lang,\n\t\t\tmeta: jsHighlight,\n\t\t\tvalue: prettierFormatCode(restoreNewLines(esmCode), options.prettierOptions)\n\t\t},\n\t\t{\n\t\t\ttype: 'jsx',\n\t\t\tvalue: '</TabItem>\\n<TabItem value=\"typescript\">'\n\t\t},\n\t\t{\n\t\t\ttype: node.type,\n\t\t\tlang: node.lang,\n\t\t\tmeta: tsHighlight,\n\t\t\tvalue: node.value\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('ts2esm2cjs');\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\tprettierOptions?: Options;\n\ttypescriptCompilerOptions?: CompilerOptions;\n}\n\nexport function ts2esm2cjs(\n\t{ sync = true, prettierOptions = {}, typescriptCompilerOptions = {} }: PluginOptions = {\n\t\tsync: true,\n\t\tprettierOptions: {},\n\t\ttypescriptCompilerOptions: {}\n\t}\n) {\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, prettierOptions, typescriptCompilerOptions });\n\t\t}\n\n\t\tif (Array.isArray(node.children)) {\n\t\t\tlet index = 0;\n\t\t\twhile (index < node.children.length) {\n\t\t\t\tconst result = transformer(node.children[index]);\n\t\t\t\tif (result) {\n\t\t\t\t\tnode.children.splice(index, 1, ...result);\n\t\t\t\t\tindex += result.length;\n\t\t\t\t} else {\n\t\t\t\t\tindex += 1;\n\t\t\t\t}\n\t\t\t}\n\t\t}\n\n\t\tif (node.type === 'root' && transformed && !alreadyImported) {\n\t\t\tnode.children.unshift(nodeForImport);\n\t\t}\n\n\t\treturn null;\n\t};\n\n\treturn transformer;\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,6BAAmC;AACnC,wBAA6B;AAC7B,sBAAkC;AAClC,wBAAoC;AAEpC,IAAM,8BAAuC;AAAA,KAC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SAAS,YAAY,KAAK,SAAS,MAAM;AAC/C,YAAI,QAAQ;AACX,eAAK,SAAS,OAAO,OAAO,GAAG,GAAG,MAAM;AACxC,mBAAS,OAAO;AAAA,QACjB,OAAO;AACN,mBAAS;AAAA,QACV;AAAA,MACD;AAAA,IACD;AAEA,QAAI,KAAK,SAAS,UAAU,eAAe,CAAC,iBAAiB;AAC5D,WAAK,SAAS,QAAQ,aAAa;AAAA,IACpC;AAEA,WAAO;AAAA,EACR;AAEA,SAAO;AACR;","names":[]}
1
+ {"version":3,"sources":["../src/index.ts"],"sourcesContent":["import sapphirePrettierConfig from '@sapphire/prettier-config';\nimport { runTransform } from 'esm-to-cjs';\nimport type { Code, Content, Literal } from 'mdast';\nimport prettier, { Options } from 'prettier';\nimport ts, { CompilerOptions } from 'typescript';\nimport type { Plugin } from 'unified';\nimport type { Node, Parent } from 'unist';\nimport visit from 'unist-util-visit';\n\nconst documentationPrettierConfig: Options = {\n\t...sapphirePrettierConfig,\n\ttabWidth: 2,\n\tuseTabs: false,\n\tprintWidth: 120,\n\tparser: 'babel'\n};\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\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 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\tprettier.format(code, { ...documentationPrettierConfig, ...prettierConfig }).slice(0, -1);\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 = options.sync ? ' groupId=\"ts2esm2cjs\"' : '';\n\n\tconst tsCode = escapeNewLines(node.value);\n\tconst esmCode = tsToEsm(tsCode, { typescriptCompilerOptions: options.typescriptCompilerOptions }).outputText;\n\tconst cjsCode = esmToCjs(esmCode);\n\n\tconst [, jsHighlight, tsHighlight] = (node.meta ?? '').split('|');\n\n\treturn [\n\t\t{\n\t\t\ttype: 'jsx',\n\t\t\tvalue: `<Tabs${groupIdProp}\n\t\t\t\t\t\tdefaultValue=\"typescript\"\n\t\t\t\t\t\tvalues={[\n\t\t\t\t\t\t\t{ label: \"JavaScript\", value: \"javascript\" },\n\t\t\t\t\t\t\t{ label: \"ESM\", value: \"esm\" },\n\t\t\t\t\t\t\t{ label: \"TypeScript\", value: \"typescript\" },\n\t\t\t\t\t\t]}\n\t\t\t>\\n<TabItem value=\"javascript\">`\n\t\t},\n\t\t{\n\t\t\ttype: node.type,\n\t\t\tlang: node.lang,\n\t\t\tmeta: `${jsHighlight} showLineNumbers`,\n\t\t\tvalue: prettierFormatCode(restoreNewLines(cjsCode), options.prettierOptions)\n\t\t},\n\t\t{\n\t\t\ttype: 'jsx',\n\t\t\tvalue: '</TabItem>\\n<TabItem value=\"esm\">'\n\t\t},\n\t\t{\n\t\t\ttype: node.type,\n\t\t\tlang: node.lang,\n\t\t\tmeta: `${jsHighlight} showLineNumbers`,\n\t\t\tvalue: prettierFormatCode(restoreNewLines(esmCode), options.prettierOptions)\n\t\t},\n\t\t{\n\t\t\ttype: 'jsx',\n\t\t\tvalue: '</TabItem>\\n<TabItem value=\"typescript\">'\n\t\t},\n\t\t{\n\t\t\ttype: node.type,\n\t\t\tlang: node.lang,\n\t\t\tmeta: `${tsHighlight} showLineNumbers`,\n\t\t\tvalue: node.value\n\t\t},\n\t\t{\n\t\t\ttype: 'jsx',\n\t\t\tvalue: '</TabItem>\\n</Tabs>'\n\t\t}\n\t] as Content[];\n};\n\nconst isImport = (node: Node): node is Literal => node.type === 'import';\nconst isParent = (node: Node): node is Parent => Array.isArray((node as Parent).children);\nconst matchNode = (node: Node): node is Code =>\n\tnode.type === 'code' && typeof (node as Code).meta === 'string' && ((node as Code).meta ?? '').startsWith('ts2esm2cjs');\nconst nodeForImport: Literal = {\n\ttype: 'import',\n\tvalue: \"import Tabs from '@theme/Tabs';\\nimport TabItem from '@theme/TabItem';\"\n};\n\nexport interface PluginOptions {\n\tsync?: boolean;\n\tprettierOptions?: Options;\n\ttypescriptCompilerOptions?: CompilerOptions;\n}\n\nexport const ts2esm2cjs: Plugin<[PluginOptions?]> = (\n\t{ sync = true, prettierOptions = {}, typescriptCompilerOptions = {} } = { sync: true, prettierOptions: {}, typescriptCompilerOptions: {} }\n) => {\n\treturn (root) => {\n\t\tlet transformed = false;\n\t\tlet alreadyImported = false;\n\t\tvisit(root, (node: Node) => {\n\t\t\tif (isImport(node) && node.value.includes('@theme/Tabs')) {\n\t\t\t\talreadyImported = true;\n\t\t\t}\n\t\t\tif (isParent(node)) {\n\t\t\t\tlet index = 0;\n\t\t\t\twhile (index < node.children.length) {\n\t\t\t\t\tconst child = node.children[index]!;\n\t\t\t\t\tif (matchNode(child)) {\n\t\t\t\t\t\tconst result = transformNode(child, { sync, 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\t\tif (transformed && !alreadyImported) {\n\t\t\t(root as Parent).children.unshift(nodeForImport);\n\t\t}\n\t};\n};\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,6BAAmC;AACnC,wBAA6B;AAE7B,sBAAkC;AAClC,wBAAoC;AAGpC,8BAAkB;AAElB,IAAM,8BAAuC;AAAA,KACzC;AAAA,EACH,UAAU;AAAA,EACV,SAAS;AAAA,EACT,YAAY;AAAA,EACZ,QAAQ;AACT;AAEA,IAAM,wBAAwB,CAAC,oBAAwD;AAAA,EACtF,SAAS,0BAAG,YAAY;AAAA,EACxB,gBAAgB;AAAA,EAChB,iBAAiB;AAAA,EACjB,QAAQ;AAAA,KACL;AAAA,EACH,QAAQ,0BAAG,WAAW;AAAA,EACtB,kBAAkB,0BAAG,qBAAqB;AAAA,EAC1C,QAAQ,0BAAG,aAAa;AACzB;AAOA,IAAM,UAAU,CAAC,MAAc,YAC9B,0BAAG,gBAAgB,MAAM,EAAE,mBAAmB,OAAO,iBAAiB,sBAAsB,QAAQ,yBAAyB,EAAE,CAAC;AAOjI,IAAM,WAAW,CAAC,SAAyB,oCAAa,MAAM,EAAE,OAAO,UAAU,gBAAgB,KAAK,eAAe,KAAK,eAAe,IAAI,CAAC;AAO9I,IAAM,iBAAiB,CAAC,SAAiB,KAAK,QAAQ,SAAS,mBAAmB;AAOl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AChE,IAAM,WAAW,CAAC,SAA+B,MAAM,QAAS,KAAgB,QAAQ;AACxF,IAAM,YAAY,CAAC,SAClB,KAAK,SAAS,UAAU,OAAQ,KAAc,SAAS,YAAc,MAAc,QAAQ,IAAI,WAAW,YAAY;AACvH,IAAM,gBAAyB;AAAA,EAC9B,MAAM;AAAA,EACN,OAAO;AACR;AAQO,IAAM,aAAuC,CACnD,EAAE,OAAO,MAAM,kBAAkB,CAAC,GAAG,4BAA4B,CAAC,MAAM,EAAE,MAAM,MAAM,iBAAiB,CAAC,GAAG,2BAA2B,CAAC,EAAE,MACrI;AACJ,SAAO,CAAC,SAAS;AAChB,QAAI,cAAc;AAClB,QAAI,kBAAkB;AACtB,yCAAM,MAAM,CAAC,SAAe;AAC3B,UAAI,SAAS,IAAI,KAAK,KAAK,MAAM,SAAS,aAAa,GAAG;AACzD,0BAAkB;AAAA,MACnB;AACA,UAAI,SAAS,IAAI,GAAG;AACnB,YAAI,QAAQ;AACZ,eAAO,QAAQ,KAAK,SAAS,QAAQ;AACpC,gBAAM,QAAQ,KAAK,SAAS;AAC5B,cAAI,UAAU,KAAK,GAAG;AACrB,kBAAM,SAAS,cAAc,OAAO,EAAE,MAAM,iBAAiB,0BAA0B,CAAC;AACxF,iBAAK,SAAS,OAAO,OAAO,GAAG,GAAG,MAAM;AACxC,qBAAS,OAAO;AAChB,0BAAc;AAAA,UACf,OAAO;AACN,qBAAS;AAAA,UACV;AAAA,QACD;AAAA,MACD;AAAA,IACD,CAAC;AACD,QAAI,eAAe,CAAC,iBAAiB;AACpC,MAAC,KAAgB,SAAS,QAAQ,aAAa;AAAA,IAChD;AAAA,EACD;AACD;","names":[]}
package/dist/index.mjs CHANGED
@@ -3,6 +3,7 @@ import sapphirePrettierConfig from "@sapphire/prettier-config";
3
3
  import { runTransform } from "esm-to-cjs";
4
4
  import prettier from "prettier";
5
5
  import ts from "typescript";
6
+ import visit from "unist-util-visit";
6
7
  var documentationPrettierConfig = {
7
8
  ...sapphirePrettierConfig,
8
9
  tabWidth: 2,
@@ -26,26 +27,28 @@ var escapeNewLines = (code) => code.replace(/\n\n/g, "\n/* :newline: */");
26
27
  var restoreNewLines = (code) => code.replace(/\/\* :newline: \*\//g, "\n");
27
28
  var prettierFormatCode = (code, prettierConfig) => prettier.format(code, { ...documentationPrettierConfig, ...prettierConfig }).slice(0, -1);
28
29
  var transformNode = (node, options) => {
29
- const groupIdProp = options.sync ? 'groupId="ts2esm2cjs" ' : "";
30
+ const groupIdProp = options.sync ? ' groupId="ts2esm2cjs"' : "";
30
31
  const tsCode = escapeNewLines(node.value);
31
32
  const esmCode = tsToEsm(tsCode, { typescriptCompilerOptions: options.typescriptCompilerOptions }).outputText;
32
33
  const cjsCode = esmToCjs(esmCode);
33
- const [, jsHighlight, tsHighlight] = node.meta.split("|");
34
+ const [, jsHighlight, tsHighlight] = (node.meta ?? "").split("|");
34
35
  return [
35
36
  {
36
37
  type: "jsx",
37
- value: `<Tabs defaultValue="typescript" ${groupIdProp}values={[
38
- { label: 'JavaScript', value: 'javascript', },
39
- { label: 'ESM', value: 'esm', },
40
- { label: 'TypeScript', value: 'typescript', },
41
- ]}
42
- >
38
+ value: `<Tabs${groupIdProp}
39
+ defaultValue="typescript"
40
+ values={[
41
+ { label: "JavaScript", value: "javascript" },
42
+ { label: "ESM", value: "esm" },
43
+ { label: "TypeScript", value: "typescript" },
44
+ ]}
45
+ >
43
46
  <TabItem value="javascript">`
44
47
  },
45
48
  {
46
49
  type: node.type,
47
50
  lang: node.lang,
48
- meta: jsHighlight,
51
+ meta: `${jsHighlight} showLineNumbers`,
49
52
  value: prettierFormatCode(restoreNewLines(cjsCode), options.prettierOptions)
50
53
  },
51
54
  {
@@ -55,7 +58,7 @@ var transformNode = (node, options) => {
55
58
  {
56
59
  type: node.type,
57
60
  lang: node.lang,
58
- meta: jsHighlight,
61
+ meta: `${jsHighlight} showLineNumbers`,
59
62
  value: prettierFormatCode(restoreNewLines(esmCode), options.prettierOptions)
60
63
  },
61
64
  {
@@ -65,7 +68,7 @@ var transformNode = (node, options) => {
65
68
  {
66
69
  type: node.type,
67
70
  lang: node.lang,
68
- meta: tsHighlight,
71
+ meta: `${tsHighlight} showLineNumbers`,
69
72
  value: node.value
70
73
  },
71
74
  {
@@ -74,45 +77,41 @@ var transformNode = (node, options) => {
74
77
  }
75
78
  ];
76
79
  };
77
- var matchNode = (node) => node.type === "code" && typeof node.meta === "string" && node.meta.startsWith("ts2esm2cjs");
80
+ var isImport = (node) => node.type === "import";
81
+ var isParent = (node) => Array.isArray(node.children);
82
+ var matchNode = (node) => node.type === "code" && typeof node.meta === "string" && (node.meta ?? "").startsWith("ts2esm2cjs");
78
83
  var nodeForImport = {
79
84
  type: "import",
80
85
  value: "import Tabs from '@theme/Tabs';\nimport TabItem from '@theme/TabItem';"
81
86
  };
82
- function ts2esm2cjs({ sync = true, prettierOptions = {}, typescriptCompilerOptions = {} } = {
83
- sync: true,
84
- prettierOptions: {},
85
- typescriptCompilerOptions: {}
86
- }) {
87
- let transformed = false;
88
- let alreadyImported = false;
89
- const transformer = (node) => {
90
- if (node.type === "import" && node.value.includes("@theme/Tabs")) {
91
- alreadyImported = true;
92
- }
93
- if (matchNode(node)) {
94
- transformed = true;
95
- return transformNode(node, { sync, prettierOptions, typescriptCompilerOptions });
96
- }
97
- if (Array.isArray(node.children)) {
98
- let index = 0;
99
- while (index < node.children.length) {
100
- const result = transformer(node.children[index]);
101
- if (result) {
102
- node.children.splice(index, 1, ...result);
103
- index += result.length;
104
- } else {
105
- index += 1;
87
+ var ts2esm2cjs = ({ sync = true, prettierOptions = {}, typescriptCompilerOptions = {} } = { sync: true, prettierOptions: {}, typescriptCompilerOptions: {} }) => {
88
+ return (root) => {
89
+ let transformed = false;
90
+ let alreadyImported = false;
91
+ visit(root, (node) => {
92
+ if (isImport(node) && node.value.includes("@theme/Tabs")) {
93
+ alreadyImported = true;
94
+ }
95
+ if (isParent(node)) {
96
+ let index = 0;
97
+ while (index < node.children.length) {
98
+ const child = node.children[index];
99
+ if (matchNode(child)) {
100
+ const result = transformNode(child, { sync, prettierOptions, typescriptCompilerOptions });
101
+ node.children.splice(index, 1, ...result);
102
+ index += result.length;
103
+ transformed = true;
104
+ } else {
105
+ index += 1;
106
+ }
106
107
  }
107
108
  }
109
+ });
110
+ if (transformed && !alreadyImported) {
111
+ root.children.unshift(nodeForImport);
108
112
  }
109
- if (node.type === "root" && transformed && !alreadyImported) {
110
- node.children.unshift(nodeForImport);
111
- }
112
- return null;
113
113
  };
114
- return transformer;
115
- }
114
+ };
116
115
  export {
117
116
  ts2esm2cjs
118
117
  };
@@ -1 +1 @@
1
- {"version":3,"sources":["../src/index.ts"],"sourcesContent":["import sapphirePrettierConfig from '@sapphire/prettier-config';\nimport { runTransform } from 'esm-to-cjs';\nimport prettier, { Options } from 'prettier';\nimport ts, { CompilerOptions } from 'typescript';\n\nconst documentationPrettierConfig: Options = {\n\t...sapphirePrettierConfig,\n\ttabWidth: 2,\n\tuseTabs: false,\n\tprintWidth: 120,\n\tparser: 'babel'\n};\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\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 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\tprettier.format(code, { ...documentationPrettierConfig, ...prettierConfig }).slice(0, -1);\n\n/**\n * Transforms a Docusaurus node from TypeScript to ESM and CJS\n * @param node The Docusaurus node to transform\n * @param isSync Whether the transform should synchronize between all entries of this type\n * @returns The transformed node in the form of Tabs.\n */\nconst transformNode = (node: any, options: PluginOptions) => {\n\tconst groupIdProp = options.sync ? 'groupId=\"ts2esm2cjs\" ' : '';\n\n\tconst tsCode = escapeNewLines(node.value);\n\tconst esmCode = tsToEsm(tsCode, { typescriptCompilerOptions: options.typescriptCompilerOptions }).outputText;\n\tconst cjsCode = esmToCjs(esmCode);\n\n\tconst [, jsHighlight, tsHighlight] = 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=\"typescript\" ${groupIdProp}` +\n\t\t\t\t`values={[\n { label: 'JavaScript', value: 'javascript', },\n { label: 'ESM', value: 'esm', },\n { label: 'TypeScript', value: 'typescript', },\n ]}\n>\n<TabItem value=\"javascript\">`\n\t\t},\n\t\t{\n\t\t\ttype: node.type,\n\t\t\tlang: node.lang,\n\t\t\tmeta: jsHighlight,\n\t\t\tvalue: prettierFormatCode(restoreNewLines(cjsCode), options.prettierOptions)\n\t\t},\n\t\t{\n\t\t\ttype: 'jsx',\n\t\t\tvalue: '</TabItem>\\n<TabItem value=\"esm\">'\n\t\t},\n\t\t{\n\t\t\ttype: node.type,\n\t\t\tlang: node.lang,\n\t\t\tmeta: jsHighlight,\n\t\t\tvalue: prettierFormatCode(restoreNewLines(esmCode), options.prettierOptions)\n\t\t},\n\t\t{\n\t\t\ttype: 'jsx',\n\t\t\tvalue: '</TabItem>\\n<TabItem value=\"typescript\">'\n\t\t},\n\t\t{\n\t\t\ttype: node.type,\n\t\t\tlang: node.lang,\n\t\t\tmeta: tsHighlight,\n\t\t\tvalue: node.value\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('ts2esm2cjs');\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\tprettierOptions?: Options;\n\ttypescriptCompilerOptions?: CompilerOptions;\n}\n\nexport function ts2esm2cjs(\n\t{ sync = true, prettierOptions = {}, typescriptCompilerOptions = {} }: PluginOptions = {\n\t\tsync: true,\n\t\tprettierOptions: {},\n\t\ttypescriptCompilerOptions: {}\n\t}\n) {\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, prettierOptions, typescriptCompilerOptions });\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;AACA;AACA;AACA;AAEA,IAAM,8BAAuC;AAAA,KACzC;AAAA,EACH,UAAU;AAAA,EACV,SAAS;AAAA,EACT,YAAY;AAAA,EACZ,QAAQ;AACT;AAEA,IAAM,wBAAwB,CAAC,oBAAwD;AAAA,EACtF,SAAS,GAAG,YAAY;AAAA,EACxB,gBAAgB;AAAA,EAChB,iBAAiB;AAAA,EACjB,QAAQ;AAAA,KACL;AAAA,EACH,QAAQ,GAAG,WAAW;AAAA,EACtB,kBAAkB,GAAG,qBAAqB;AAAA,EAC1C,QAAQ,GAAG,aAAa;AACzB;AAOA,IAAM,UAAU,CAAC,MAAc,YAC9B,GAAG,gBAAgB,MAAM,EAAE,mBAAmB,OAAO,iBAAiB,sBAAsB,QAAQ,yBAAyB,EAAE,CAAC;AAOjI,IAAM,WAAW,CAAC,SAAyB,aAAa,MAAM,EAAE,OAAO,UAAU,gBAAgB,KAAK,eAAe,KAAK,eAAe,IAAI,CAAC;AAO9I,IAAM,iBAAiB,CAAC,SAAiB,KAAK,QAAQ,SAAS,mBAAmB;AAOlF,IAAM,kBAAkB,CAAC,SAAyB,KAAK,QAAQ,wBAAwB,IAAI;AAQ3F,IAAM,qBAAqB,CAAC,MAAc,mBACzC,SAAS,OAAO,MAAM,KAAK,gCAAgC,eAAe,CAAC,EAAE,MAAM,GAAG,EAAE;AAQzF,IAAM,gBAAgB,CAAC,MAAW,YAA2B;AAC5D,QAAM,cAAc,QAAQ,OAAO,0BAA0B;AAE7D,QAAM,SAAS,eAAe,KAAK,KAAK;AACxC,QAAM,UAAU,QAAQ,QAAQ,EAAE,2BAA2B,QAAQ,0BAA0B,CAAC,EAAE;AAClG,QAAM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A,IACnB;AAEA,QAAI,UAAU,IAAI,GAAG;AACpB,oBAAc;AACd,aAAO,cAAc,MAAM,EAAE,MAAM,iBAAiB,0BAA0B,CAAC;AAAA,IAChF;AAEA,QAAI,MAAM,QAAQ,KAAK,QAAQ,GAAG;AACjC,UAAI,QAAQ;AACZ,aAAO,QAAQ,KAAK,SAAS,QAAQ;AACpC,cAAM,SAAS,YAAY,KAAK,SAAS,MAAM;AAC/C,YAAI,QAAQ;AACX,eAAK,SAAS,OAAO,OAAO,GAAG,GAAG,MAAM;AACxC,mBAAS,OAAO;AAAA,QACjB,OAAO;AACN,mBAAS;AAAA,QACV;AAAA,MACD;AAAA,IACD;AAEA,QAAI,KAAK,SAAS,UAAU,eAAe,CAAC,iBAAiB;AAC5D,WAAK,SAAS,QAAQ,aAAa;AAAA,IACpC;AAEA,WAAO;AAAA,EACR;AAEA,SAAO;AACR;","names":[]}
1
+ {"version":3,"sources":["../src/index.ts"],"sourcesContent":["import sapphirePrettierConfig from '@sapphire/prettier-config';\nimport { runTransform } from 'esm-to-cjs';\nimport type { Code, Content, Literal } from 'mdast';\nimport prettier, { Options } from 'prettier';\nimport ts, { CompilerOptions } from 'typescript';\nimport type { Plugin } from 'unified';\nimport type { Node, Parent } from 'unist';\nimport visit from 'unist-util-visit';\n\nconst documentationPrettierConfig: Options = {\n\t...sapphirePrettierConfig,\n\ttabWidth: 2,\n\tuseTabs: false,\n\tprintWidth: 120,\n\tparser: 'babel'\n};\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\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 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\tprettier.format(code, { ...documentationPrettierConfig, ...prettierConfig }).slice(0, -1);\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 = options.sync ? ' groupId=\"ts2esm2cjs\"' : '';\n\n\tconst tsCode = escapeNewLines(node.value);\n\tconst esmCode = tsToEsm(tsCode, { typescriptCompilerOptions: options.typescriptCompilerOptions }).outputText;\n\tconst cjsCode = esmToCjs(esmCode);\n\n\tconst [, jsHighlight, tsHighlight] = (node.meta ?? '').split('|');\n\n\treturn [\n\t\t{\n\t\t\ttype: 'jsx',\n\t\t\tvalue: `<Tabs${groupIdProp}\n\t\t\t\t\t\tdefaultValue=\"typescript\"\n\t\t\t\t\t\tvalues={[\n\t\t\t\t\t\t\t{ label: \"JavaScript\", value: \"javascript\" },\n\t\t\t\t\t\t\t{ label: \"ESM\", value: \"esm\" },\n\t\t\t\t\t\t\t{ label: \"TypeScript\", value: \"typescript\" },\n\t\t\t\t\t\t]}\n\t\t\t>\\n<TabItem value=\"javascript\">`\n\t\t},\n\t\t{\n\t\t\ttype: node.type,\n\t\t\tlang: node.lang,\n\t\t\tmeta: `${jsHighlight} showLineNumbers`,\n\t\t\tvalue: prettierFormatCode(restoreNewLines(cjsCode), options.prettierOptions)\n\t\t},\n\t\t{\n\t\t\ttype: 'jsx',\n\t\t\tvalue: '</TabItem>\\n<TabItem value=\"esm\">'\n\t\t},\n\t\t{\n\t\t\ttype: node.type,\n\t\t\tlang: node.lang,\n\t\t\tmeta: `${jsHighlight} showLineNumbers`,\n\t\t\tvalue: prettierFormatCode(restoreNewLines(esmCode), options.prettierOptions)\n\t\t},\n\t\t{\n\t\t\ttype: 'jsx',\n\t\t\tvalue: '</TabItem>\\n<TabItem value=\"typescript\">'\n\t\t},\n\t\t{\n\t\t\ttype: node.type,\n\t\t\tlang: node.lang,\n\t\t\tmeta: `${tsHighlight} showLineNumbers`,\n\t\t\tvalue: node.value\n\t\t},\n\t\t{\n\t\t\ttype: 'jsx',\n\t\t\tvalue: '</TabItem>\\n</Tabs>'\n\t\t}\n\t] as Content[];\n};\n\nconst isImport = (node: Node): node is Literal => node.type === 'import';\nconst isParent = (node: Node): node is Parent => Array.isArray((node as Parent).children);\nconst matchNode = (node: Node): node is Code =>\n\tnode.type === 'code' && typeof (node as Code).meta === 'string' && ((node as Code).meta ?? '').startsWith('ts2esm2cjs');\nconst nodeForImport: Literal = {\n\ttype: 'import',\n\tvalue: \"import Tabs from '@theme/Tabs';\\nimport TabItem from '@theme/TabItem';\"\n};\n\nexport interface PluginOptions {\n\tsync?: boolean;\n\tprettierOptions?: Options;\n\ttypescriptCompilerOptions?: CompilerOptions;\n}\n\nexport const ts2esm2cjs: Plugin<[PluginOptions?]> = (\n\t{ sync = true, prettierOptions = {}, typescriptCompilerOptions = {} } = { sync: true, prettierOptions: {}, typescriptCompilerOptions: {} }\n) => {\n\treturn (root) => {\n\t\tlet transformed = false;\n\t\tlet alreadyImported = false;\n\t\tvisit(root, (node: Node) => {\n\t\t\tif (isImport(node) && node.value.includes('@theme/Tabs')) {\n\t\t\t\talreadyImported = true;\n\t\t\t}\n\t\t\tif (isParent(node)) {\n\t\t\t\tlet index = 0;\n\t\t\t\twhile (index < node.children.length) {\n\t\t\t\t\tconst child = node.children[index]!;\n\t\t\t\t\tif (matchNode(child)) {\n\t\t\t\t\t\tconst result = transformNode(child, { sync, 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\t\tif (transformed && !alreadyImported) {\n\t\t\t(root as Parent).children.unshift(nodeForImport);\n\t\t}\n\t};\n};\n"],"mappings":";AAAA;AACA;AAEA;AACA;AAGA;AAEA,IAAM,8BAAuC;AAAA,KACzC;AAAA,EACH,UAAU;AAAA,EACV,SAAS;AAAA,EACT,YAAY;AAAA,EACZ,QAAQ;AACT;AAEA,IAAM,wBAAwB,CAAC,oBAAwD;AAAA,EACtF,SAAS,GAAG,YAAY;AAAA,EACxB,gBAAgB;AAAA,EAChB,iBAAiB;AAAA,EACjB,QAAQ;AAAA,KACL;AAAA,EACH,QAAQ,GAAG,WAAW;AAAA,EACtB,kBAAkB,GAAG,qBAAqB;AAAA,EAC1C,QAAQ,GAAG,aAAa;AACzB;AAOA,IAAM,UAAU,CAAC,MAAc,YAC9B,GAAG,gBAAgB,MAAM,EAAE,mBAAmB,OAAO,iBAAiB,sBAAsB,QAAQ,yBAAyB,EAAE,CAAC;AAOjI,IAAM,WAAW,CAAC,SAAyB,aAAa,MAAM,EAA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esm2cjs",
3
- "version": "1.1.0-next.fadcdcf.0",
4
- "description": "Docusaurus Remark plugin for converting TypeScript code to ESM and CJS code",
5
- "author": "@sapphire",
6
- "license": "MIT",
7
- "main": "dist/index.js",
8
- "module": "dist/index.mjs",
9
- "types": "dist/index.d.ts",
10
- "exports": {
11
- "import": "./dist/index.mjs",
12
- "require": "./dist/index.js",
13
- "types": "./dist/index.d.ts"
14
- },
15
- "scripts": {
16
- "lint": "eslint src --ext ts --fix",
17
- "build": "tsup && tsc -b src",
18
- "typecheck": "tsc -p tsconfig.eslint.json",
19
- "prepublishOnly": "yarn build"
20
- },
21
- "dependencies": {
22
- "@sapphire/prettier-config": "^1.4.3",
23
- "esm-to-cjs": "^1.2.1",
24
- "prettier": "^2.6.2",
25
- "typescript": "^4.6.4"
26
- },
27
- "repository": {
28
- "type": "git",
29
- "url": "git+https://github.com/sapphiredev/documentation-plugins.git",
30
- "directory": "packages/ts2esm2cjs"
31
- },
32
- "files": [
33
- "dist",
34
- "!dist/*.tsbuildinfo"
35
- ],
36
- "engines": {
37
- "node": ">=v16.6.0",
38
- "npm": ">=7.0.0"
39
- },
40
- "keywords": [
41
- "docusaurus",
42
- "docusaurus-plugin",
43
- "@sapphire",
44
- "typescript",
45
- "ts",
46
- "esm",
47
- "cjs",
48
- "discord",
49
- "sapphire",
50
- "discordjs"
51
- ],
52
- "bugs": {
53
- "url": "https://github.com/sapphiredev/documentation-plugins/issues"
54
- },
55
- "homepage": "https://www.sapphirejs.dev",
56
- "publishConfig": {
57
- "access": "public"
58
- },
59
- "gitHead": "fadcdcf55888e1a82c04a626c9572fd228bdbfd8"
60
- }
2
+ "name": "@sapphire/docusaurus-plugin-ts2esm2cjs",
3
+ "version": "1.1.1-next.eb82505.0",
4
+ "description": "Docusaurus Remark plugin for converting TypeScript code to ESM and CJS code",
5
+ "author": "@sapphire",
6
+ "license": "MIT",
7
+ "main": "dist/index.js",
8
+ "module": "dist/index.mjs",
9
+ "types": "dist/index.d.ts",
10
+ "exports": {
11
+ "import": "./dist/index.mjs",
12
+ "require": "./dist/index.js",
13
+ "types": "./dist/index.d.ts"
14
+ },
15
+ "sideEffects": false,
16
+ "scripts": {
17
+ "lint": "eslint src --ext ts --fix",
18
+ "build": "tsup && tsc -b src",
19
+ "typecheck": "tsc -p tsconfig.eslint.json",
20
+ "prepack": "yarn build",
21
+ "bump": "cliff-jumper",
22
+ "check-update": "cliff-jumper --dry-run"
23
+ },
24
+ "dependencies": {
25
+ "@sapphire/prettier-config": "^1.4.3",
26
+ "esm-to-cjs": "^1.2.1",
27
+ "prettier": "^2.6.2",
28
+ "typescript": "^4.6.4",
29
+ "unist-util-visit": "^2.0.3"
30
+ },
31
+ "repository": {
32
+ "type": "git",
33
+ "url": "git+https://github.com/sapphiredev/documentation-plugins.git",
34
+ "directory": "packages/ts2esm2cjs"
35
+ },
36
+ "files": [
37
+ "dist/**/*.js*",
38
+ "dist/**/*.mjs*",
39
+ "dist/**/*.d*"
40
+ ],
41
+ "engines": {
42
+ "node": ">=v16.6.0",
43
+ "npm": ">=7.0.0"
44
+ },
45
+ "keywords": [
46
+ "docusaurus",
47
+ "docusaurus-plugin",
48
+ "@sapphire",
49
+ "typescript",
50
+ "ts",
51
+ "esm",
52
+ "cjs",
53
+ "discord",
54
+ "sapphire",
55
+ "discordjs"
56
+ ],
57
+ "bugs": {
58
+ "url": "https://github.com/sapphiredev/documentation-plugins/issues"
59
+ },
60
+ "homepage": "https://www.sapphirejs.dev",
61
+ "publishConfig": {
62
+ "access": "public"
63
+ },
64
+ "devDependencies": {
65
+ "tsup": "^5.12.8",
66
+ "typescript": "^4.6.4"
67
+ }
68
+ }
package/LICENSE.md DELETED
@@ -1,24 +0,0 @@
1
- # The MIT License (MIT)
2
-
3
- Copyright © `2021` `The Sapphire Community and its contributors`
4
-
5
- Permission is hereby granted, free of charge, to any person
6
- obtaining a copy of this software and associated documentation
7
- files (the “Software”), to deal in the Software without
8
- restriction, including without limitation the rights to use,
9
- copy, modify, merge, publish, distribute, sublicense, and/or sell
10
- copies of the Software, and to permit persons to whom the
11
- Software is furnished to do so, subject to the following
12
- conditions:
13
-
14
- The above copyright notice and this permission notice shall be
15
- included in all copies or substantial portions of the Software.
16
-
17
- THE SOFTWARE IS PROVIDED “AS IS”, WITHOUT WARRANTY OF ANY KIND,
18
- EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES
19
- OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
20
- NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
21
- HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
22
- WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
23
- FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
24
- OTHER DEALINGS IN THE SOFTWARE.
@@ -1 +0,0 @@
1
- {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAEA,OAAiB,EAAE,OAAO,EAAE,MAAM,UAAU,CAAC;AAC7C,OAAW,EAAE,eAAe,EAAE,MAAM,YAAY,CAAC;AA8HjD,MAAM,WAAW,aAAa;IAC7B,IAAI,CAAC,EAAE,OAAO,CAAC;IACf,eAAe,CAAC,EAAE,OAAO,CAAC;IAC1B,yBAAyB,CAAC,EAAE,eAAe,CAAC;CAC5C;AAED,wBAAgB,UAAU,CACzB,EAAE,IAAW,EAAE,eAAoB,EAAE,yBAA8B,EAAE,GAAE,aAItE,UAK0B,GAAG;;;;;;;;;;YA+B9B"}