@sapphire/docusaurus-plugin-ts2esm2cjs 0.1.0-next.35ec87d.0 → 0.1.0-next.92711c8.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/README.md +19 -0
- package/dist/index.d.ts +3 -1
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +15 -10
- package/dist/index.js.map +1 -1
- package/package.json +2 -2
package/README.md
CHANGED
|
@@ -124,6 +124,25 @@ The output JS and ESM code is formatted using Prettier. The default configuratio
|
|
|
124
124
|
|
|
125
125
|
You can customize this by passing `prettierConfig` to the plugin options.
|
|
126
126
|
|
|
127
|
+
### TypeScript compiler options
|
|
128
|
+
|
|
129
|
+
The ESM code is transpiled from TypeScript using the TypeScript compiler with the following base configuration:
|
|
130
|
+
|
|
131
|
+
```json
|
|
132
|
+
{
|
|
133
|
+
"newLine": "lf",
|
|
134
|
+
"removeComments": false,
|
|
135
|
+
"esModuleInterop": true,
|
|
136
|
+
"pretty": true,
|
|
137
|
+
"module": "ESNext",
|
|
138
|
+
"moduleResolution": "Node",
|
|
139
|
+
"target": "ESNext"
|
|
140
|
+
}
|
|
141
|
+
```
|
|
142
|
+
|
|
143
|
+
You can customize this by passing `typescriptCompilerOptions` to the plugin options. However, you cannot customize the
|
|
144
|
+
`module`, `moduleResolution`, or `target` options.
|
|
145
|
+
|
|
127
146
|
## Buy us some doughnuts
|
|
128
147
|
|
|
129
148
|
Sapphire Community is and always will be open source, even if we don't get donations. That being said, we know there are
|
package/dist/index.d.ts
CHANGED
|
@@ -1,9 +1,11 @@
|
|
|
1
1
|
import { Options } from 'prettier';
|
|
2
|
+
import { CompilerOptions } from 'typescript';
|
|
2
3
|
export interface PluginOptions {
|
|
3
4
|
sync?: boolean;
|
|
4
5
|
prettierOptions?: Options;
|
|
6
|
+
typescriptCompilerOptions?: CompilerOptions;
|
|
5
7
|
}
|
|
6
|
-
declare const _default: ({ sync, prettierOptions }?: PluginOptions) => (node: any) => ({
|
|
8
|
+
declare const _default: ({ sync, prettierOptions, typescriptCompilerOptions }?: PluginOptions) => (node: any) => ({
|
|
7
9
|
type: string;
|
|
8
10
|
value: string;
|
|
9
11
|
lang?: undefined;
|
package/dist/index.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAEA,OAAiB,EAAE,OAAO,EAAE,MAAM,UAAU,CAAC;
|
|
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;gFAGuE,aAAa,YASzD,GAAG;;;;;;;;;;;AAV/B,wBAyCE"}
|
package/dist/index.js
CHANGED
|
@@ -12,21 +12,22 @@ const documentationPrettierConfig = {
|
|
|
12
12
|
printWidth: 120,
|
|
13
13
|
parser: 'babel'
|
|
14
14
|
};
|
|
15
|
-
const
|
|
16
|
-
module: typescript_1.default.ModuleKind.ESNext,
|
|
15
|
+
const makeTsCompilerOptions = (overrideOptions) => ({
|
|
17
16
|
newLine: typescript_1.default.NewLineKind.LineFeed,
|
|
18
|
-
moduleResolution: typescript_1.default.ModuleResolutionKind.NodeJs,
|
|
19
|
-
target: typescript_1.default.ScriptTarget.ESNext,
|
|
20
17
|
removeComments: false,
|
|
21
18
|
esModuleInterop: true,
|
|
22
|
-
pretty: true
|
|
23
|
-
|
|
19
|
+
pretty: true,
|
|
20
|
+
...overrideOptions,
|
|
21
|
+
module: typescript_1.default.ModuleKind.ESNext,
|
|
22
|
+
moduleResolution: typescript_1.default.ModuleResolutionKind.NodeJs,
|
|
23
|
+
target: typescript_1.default.ScriptTarget.ESNext
|
|
24
|
+
});
|
|
24
25
|
/**
|
|
25
26
|
* Transpiles input TypeScript code to ESM code.
|
|
26
27
|
* @param code The code to transpile
|
|
27
28
|
* @returns Input code transpiled to ESM
|
|
28
29
|
*/
|
|
29
|
-
const tsToEsm = (code) => typescript_1.default.transpileModule(code, { reportDiagnostics: false, compilerOptions:
|
|
30
|
+
const tsToEsm = (code, options) => typescript_1.default.transpileModule(code, { reportDiagnostics: false, compilerOptions: makeTsCompilerOptions(options.typescriptCompilerOptions) });
|
|
30
31
|
/**
|
|
31
32
|
* Transforms input ESM code to CJS code.
|
|
32
33
|
* @param code The code to transform
|
|
@@ -61,7 +62,7 @@ const prettierFormatCode = (code, prettierConfig) => prettier_1.default.format(c
|
|
|
61
62
|
const transformNode = (node, options) => {
|
|
62
63
|
const groupIdProp = options.sync ? 'groupId="ts2esm2cjs" ' : '';
|
|
63
64
|
const tsCode = escapeNewLines(node.value);
|
|
64
|
-
const esmCode = tsToEsm(tsCode).outputText;
|
|
65
|
+
const esmCode = tsToEsm(tsCode, { typescriptCompilerOptions: options.typescriptCompilerOptions }).outputText;
|
|
65
66
|
const cjsCode = esmToCjs(esmCode);
|
|
66
67
|
const [, jsHighlight, tsHighlight] = node.meta.split('|');
|
|
67
68
|
return [
|
|
@@ -113,7 +114,11 @@ const nodeForImport = {
|
|
|
113
114
|
type: 'import',
|
|
114
115
|
value: "import Tabs from '@theme/Tabs';\nimport TabItem from '@theme/TabItem';"
|
|
115
116
|
};
|
|
116
|
-
exports.default = ({ sync = true, prettierOptions = {}
|
|
117
|
+
exports.default = ({ sync = true, prettierOptions = {}, typescriptCompilerOptions = {} } = {
|
|
118
|
+
sync: true,
|
|
119
|
+
prettierOptions: {},
|
|
120
|
+
typescriptCompilerOptions: {}
|
|
121
|
+
}) => {
|
|
117
122
|
let transformed = false;
|
|
118
123
|
let alreadyImported = false;
|
|
119
124
|
const transformer = (node) => {
|
|
@@ -122,7 +127,7 @@ exports.default = ({ sync = true, prettierOptions = {} } = { sync: true, prettie
|
|
|
122
127
|
}
|
|
123
128
|
if (matchNode(node)) {
|
|
124
129
|
transformed = true;
|
|
125
|
-
return transformNode(node, { sync, prettierOptions });
|
|
130
|
+
return transformNode(node, { sync, prettierOptions, typescriptCompilerOptions });
|
|
126
131
|
}
|
|
127
132
|
if (Array.isArray(node.children)) {
|
|
128
133
|
let index = 0;
|
package/dist/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":";;;AAAA,6FAA+D;AAC/D,2CAA0C;AAC1C,qEAA6C;AAC7C,yEAAiD;AAEjD,MAAM,2BAA2B,GAAY;IAC5C,GAAG,yBAAsB;IACzB,QAAQ,EAAE,CAAC;IACX,OAAO,EAAE,KAAK;IACd,UAAU,EAAE,GAAG;IACf,MAAM,EAAE,OAAO;CACf,CAAC;AAEF,MAAM,
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":";;;AAAA,6FAA+D;AAC/D,2CAA0C;AAC1C,qEAA6C;AAC7C,yEAAiD;AAEjD,MAAM,2BAA2B,GAAY;IAC5C,GAAG,yBAAsB;IACzB,QAAQ,EAAE,CAAC;IACX,OAAO,EAAE,KAAK;IACd,UAAU,EAAE,GAAG;IACf,MAAM,EAAE,OAAO;CACf,CAAC;AAEF,MAAM,qBAAqB,GAAG,CAAC,eAAiC,EAAmB,EAAE,CAAC,CAAC;IACtF,OAAO,EAAE,oBAAE,CAAC,WAAW,CAAC,QAAQ;IAChC,cAAc,EAAE,KAAK;IACrB,eAAe,EAAE,IAAI;IACrB,MAAM,EAAE,IAAI;IACZ,GAAG,eAAe;IAClB,MAAM,EAAE,oBAAE,CAAC,UAAU,CAAC,MAAM;IAC5B,gBAAgB,EAAE,oBAAE,CAAC,oBAAoB,CAAC,MAAM;IAChD,MAAM,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W,IAAI,CAAC,eAAe,EAAE;YAC5D,IAAI,CAAC,QAAQ,CAAC,OAAO,CAAC,aAAa,CAAC,CAAC;SACrC;QAED,OAAO,IAAI,CAAC;IACb,CAAC,CAAC;IAEF,OAAO,WAAW,CAAC;AACpB,CAAC,CAAC"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@sapphire/docusaurus-plugin-ts2esm2cjs",
|
|
3
|
-
"version": "0.1.0-next.
|
|
3
|
+
"version": "0.1.0-next.92711c8.0",
|
|
4
4
|
"description": "Docusaurus Remark plugin for converting TypeScript code to ESM and CJS code",
|
|
5
5
|
"author": "@sapphire",
|
|
6
6
|
"license": "MIT",
|
|
@@ -60,5 +60,5 @@
|
|
|
60
60
|
"devDependencies": {
|
|
61
61
|
"@types/prettier": "^2"
|
|
62
62
|
},
|
|
63
|
-
"gitHead": "
|
|
63
|
+
"gitHead": "92711c864f467b1834f63c3d9e1434c69f0305bb"
|
|
64
64
|
}
|