detype 2.0.3 → 2.0.5
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/detype.js +1 -1
- package/dist/cli.d.ts +1 -0
- package/dist/cli.js +103 -233
- package/dist/index.cjs +194 -257
- package/dist/index.d.cts +34 -33
- package/dist/index.d.ts +34 -33
- package/dist/index.js +2 -12
- package/dist/transformFile-qmpi6_2q.js +190 -0
- package/package.json +11 -8
- package/dist/chunk-VYED23Y7.js +0 -250
package/dist/index.cjs
CHANGED
|
@@ -1,281 +1,218 @@
|
|
|
1
|
-
"
|
|
1
|
+
Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
|
|
2
|
+
//#region \0rolldown/runtime.js
|
|
2
3
|
var __create = Object.create;
|
|
3
4
|
var __defProp = Object.defineProperty;
|
|
4
5
|
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
5
6
|
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
6
7
|
var __getProtoOf = Object.getPrototypeOf;
|
|
7
8
|
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
9
|
var __copyProps = (to, from, except, desc) => {
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
10
|
+
if (from && typeof from === "object" || typeof from === "function") for (var keys = __getOwnPropNames(from), i = 0, n = keys.length, key; i < n; i++) {
|
|
11
|
+
key = keys[i];
|
|
12
|
+
if (!__hasOwnProp.call(to, key) && key !== except) __defProp(to, key, {
|
|
13
|
+
get: ((k) => from[k]).bind(null, key),
|
|
14
|
+
enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable
|
|
15
|
+
});
|
|
16
|
+
}
|
|
17
|
+
return to;
|
|
19
18
|
};
|
|
20
|
-
var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
)
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
transform: () => transform,
|
|
36
|
-
transformFile: () => transformFile
|
|
37
|
-
});
|
|
38
|
-
module.exports = __toCommonJS(index_exports);
|
|
39
|
-
|
|
40
|
-
// src/transform.ts
|
|
41
|
-
var import_core = require("@babel/core");
|
|
42
|
-
var import_prettier = require("prettier");
|
|
43
|
-
var import_compiler_sfc = require("@vuedx/compiler-sfc");
|
|
44
|
-
var import_compiler_sfc2 = require("@vue/compiler-sfc");
|
|
45
|
-
var import_template_ast_types = require("@vuedx/template-ast-types");
|
|
46
|
-
var import_preset_typescript = __toESM(require("@babel/preset-typescript"), 1);
|
|
19
|
+
var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", {
|
|
20
|
+
value: mod,
|
|
21
|
+
enumerable: true
|
|
22
|
+
}) : target, mod));
|
|
23
|
+
//#endregion
|
|
24
|
+
let _babel_core = require("@babel/core");
|
|
25
|
+
let prettier = require("prettier");
|
|
26
|
+
let _vuedx_compiler_sfc = require("@vuedx/compiler-sfc");
|
|
27
|
+
let _vue_compiler_sfc = require("@vue/compiler-sfc");
|
|
28
|
+
let _vuedx_template_ast_types = require("@vuedx/template-ast-types");
|
|
29
|
+
let _babel_preset_typescript = require("@babel/preset-typescript");
|
|
30
|
+
_babel_preset_typescript = __toESM(_babel_preset_typescript);
|
|
31
|
+
let node_fs = require("node:fs");
|
|
32
|
+
node_fs = __toESM(node_fs);
|
|
33
|
+
//#region src/transform.ts
|
|
47
34
|
function getDefinePropsObject(content) {
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
return content.substring(startContentIndex, endContentIndex);
|
|
62
|
-
}
|
|
63
|
-
return "";
|
|
35
|
+
const matched = /\sprops:\s*\{/m.exec(content);
|
|
36
|
+
if (matched) {
|
|
37
|
+
const startContentIndex = matched.index + matched[0].length - 1;
|
|
38
|
+
let leftBracketCount = 1;
|
|
39
|
+
let endContentIndex = startContentIndex + 1;
|
|
40
|
+
while (leftBracketCount) {
|
|
41
|
+
if (content.charAt(endContentIndex) === "{") leftBracketCount++;
|
|
42
|
+
else if (content.charAt(endContentIndex) === "}") leftBracketCount--;
|
|
43
|
+
endContentIndex++;
|
|
44
|
+
}
|
|
45
|
+
return content.substring(startContentIndex, endContentIndex);
|
|
46
|
+
}
|
|
47
|
+
return "";
|
|
64
48
|
}
|
|
49
|
+
/**
|
|
50
|
+
* Transform TypeScript code into vanilla JavaScript without affecting the formatting
|
|
51
|
+
* @param code Source coude
|
|
52
|
+
* @param fileName File name for the source
|
|
53
|
+
* @param options Options
|
|
54
|
+
*/
|
|
65
55
|
async function transform(code, fileName, options = {}) {
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
code = await removeTypesFromVueSfcScript(
|
|
95
|
-
code,
|
|
96
|
-
fileName,
|
|
97
|
-
script1,
|
|
98
|
-
parsedVue.descriptor.template?.ast,
|
|
99
|
-
removeTypeOptions
|
|
100
|
-
);
|
|
101
|
-
code = await removeTypesFromVueSfcScript(
|
|
102
|
-
code,
|
|
103
|
-
fileName,
|
|
104
|
-
script2,
|
|
105
|
-
parsedVue.descriptor.template?.ast,
|
|
106
|
-
removeTypeOptions
|
|
107
|
-
);
|
|
108
|
-
} else {
|
|
109
|
-
code = await removeTypes(code, fileName, removeTypeOptions);
|
|
110
|
-
}
|
|
111
|
-
if (propsContent) {
|
|
112
|
-
code = code.replace("defineProps(", (str) => `${str}${propsContent}`);
|
|
113
|
-
}
|
|
114
|
-
if (emitsContent) {
|
|
115
|
-
code = code.replace("defineEmits(", (str) => `${str}${emitsContent}`);
|
|
116
|
-
}
|
|
117
|
-
code = await (0, import_prettier.format)(code, {
|
|
118
|
-
...prettierOptions,
|
|
119
|
-
filepath: originalFileName
|
|
120
|
-
});
|
|
121
|
-
return code;
|
|
56
|
+
const { prettierOptions, ...removeTypeOptions } = options;
|
|
57
|
+
const originalCode = code;
|
|
58
|
+
const originalFileName = fileName;
|
|
59
|
+
let propsContent = "";
|
|
60
|
+
let emitsContent = "";
|
|
61
|
+
code = code.replaceAll("\r\n", "\n");
|
|
62
|
+
if (fileName.endsWith(".vue")) {
|
|
63
|
+
const parsedVue = (0, _vuedx_compiler_sfc.parse)(code);
|
|
64
|
+
if (parsedVue.descriptor.script?.lang !== "ts" && parsedVue.descriptor.scriptSetup?.lang !== "ts") return originalCode;
|
|
65
|
+
let { script: script1, scriptSetup: script2 } = parsedVue.descriptor;
|
|
66
|
+
const isContainsDefinePropsType = script2?.content.match(/defineProps\s*</m);
|
|
67
|
+
const isContainsDefineEmitType = script2?.content.match(/defineEmits\s*</m);
|
|
68
|
+
if (isContainsDefinePropsType || isContainsDefineEmitType) {
|
|
69
|
+
const { content } = (0, _vue_compiler_sfc.compileScript)(parsedVue.descriptor, { id: "xxxxxxx" });
|
|
70
|
+
if (isContainsDefinePropsType) propsContent = getDefinePropsObject(content);
|
|
71
|
+
if (isContainsDefineEmitType) emitsContent = content.match(/\semits:\s(\[.*\]?)/m)?.[1] || "";
|
|
72
|
+
}
|
|
73
|
+
if (script1 && script2 && script1.loc.start.offset < script2.loc.start.offset) [script2, script1] = [script1, script2];
|
|
74
|
+
code = await removeTypesFromVueSfcScript(code, fileName, script1, parsedVue.descriptor.template?.ast, removeTypeOptions);
|
|
75
|
+
code = await removeTypesFromVueSfcScript(code, fileName, script2, parsedVue.descriptor.template?.ast, removeTypeOptions);
|
|
76
|
+
} else code = await removeTypes(code, fileName, removeTypeOptions);
|
|
77
|
+
if (propsContent) code = code.replace("defineProps(", (str) => `${str}${propsContent}`);
|
|
78
|
+
if (emitsContent) code = code.replace("defineEmits(", (str) => `${str}${emitsContent}`);
|
|
79
|
+
code = await (0, prettier.format)(code, {
|
|
80
|
+
...prettierOptions,
|
|
81
|
+
filepath: originalFileName
|
|
82
|
+
});
|
|
83
|
+
return code;
|
|
122
84
|
}
|
|
123
85
|
async function removeTypes(code, fileName, options) {
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
TSDeclareMethod: removeComments,
|
|
155
|
-
TSImportType: removeComments
|
|
156
|
-
}
|
|
157
|
-
}
|
|
158
|
-
].filter(Boolean),
|
|
159
|
-
presets: [import_preset_typescript.default],
|
|
160
|
-
generatorOpts: {
|
|
161
|
-
shouldPrintComment: (comment) => comment !== "@detype: remove-me" && (!options.removeTsComments || !comment.match(/^\s*(@ts-ignore|@ts-expect-error)/))
|
|
162
|
-
}
|
|
163
|
-
};
|
|
164
|
-
if (options.customizeBabelConfig) {
|
|
165
|
-
options.customizeBabelConfig(babelConfig);
|
|
166
|
-
}
|
|
167
|
-
const babelOutput = await (0, import_core.transformAsync)(code, babelConfig);
|
|
168
|
-
if (!babelOutput || babelOutput.code === void 0 || babelOutput.code === null) {
|
|
169
|
-
throw new Error("Babel error");
|
|
170
|
-
}
|
|
171
|
-
return babelOutput.code.replaceAll(/\n\n*/g, "\n").replace(
|
|
172
|
-
/\/\* @detype: empty-line=([0-9]+) \*\//g,
|
|
173
|
-
(_match, p1) => `
|
|
174
|
-
`.repeat(p1 - 2)
|
|
175
|
-
);
|
|
86
|
+
code = code.replace(/\n\n+/g, (match) => `\n/* @detype: empty-line=${match.length} */\n`);
|
|
87
|
+
code = processMagicComments(code);
|
|
88
|
+
const removeComments = { enter(p) {
|
|
89
|
+
if (!p.node.leadingComments) return;
|
|
90
|
+
for (let i = p.node.leadingComments.length - 1; i >= 0; i--) {
|
|
91
|
+
const comment = p.node.leadingComments[i];
|
|
92
|
+
if (code.slice(comment.end).match(/^\s*\n\s*\n/) || comment.value.includes("@detype: empty-line")) break;
|
|
93
|
+
comment.value = "@detype: remove-me";
|
|
94
|
+
}
|
|
95
|
+
} };
|
|
96
|
+
const babelConfig = {
|
|
97
|
+
filename: fileName,
|
|
98
|
+
retainLines: true,
|
|
99
|
+
plugins: [{
|
|
100
|
+
name: "detype-comment-remover",
|
|
101
|
+
visitor: {
|
|
102
|
+
TSTypeAliasDeclaration: removeComments,
|
|
103
|
+
TSInterfaceDeclaration: removeComments,
|
|
104
|
+
TSDeclareFunction: removeComments,
|
|
105
|
+
TSDeclareMethod: removeComments,
|
|
106
|
+
TSImportType: removeComments
|
|
107
|
+
}
|
|
108
|
+
}].filter(Boolean),
|
|
109
|
+
presets: [_babel_preset_typescript.default],
|
|
110
|
+
generatorOpts: { shouldPrintComment: (comment) => comment !== "@detype: remove-me" && (!options.removeTsComments || !comment.match(/^\s*(@ts-ignore|@ts-expect-error)/)) }
|
|
111
|
+
};
|
|
112
|
+
if (options.customizeBabelConfig) options.customizeBabelConfig(babelConfig);
|
|
113
|
+
const babelOutput = await (0, _babel_core.transformAsync)(code, babelConfig);
|
|
114
|
+
if (!babelOutput || babelOutput.code === void 0 || babelOutput.code === null) throw new Error("Babel error");
|
|
115
|
+
return babelOutput.code.replaceAll(/\n\n*/g, "\n").replace(/\/\* @detype: empty-line=([0-9]+) \*\//g, (_match, p1) => `\n`.repeat(p1 - 2));
|
|
176
116
|
}
|
|
177
117
|
async function removeTypesFromVueSfcScript(code, fileName, script, templateAst, options) {
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
|
|
189
|
-
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
|
|
196
|
-
|
|
197
|
-
|
|
198
|
-
|
|
199
|
-
let before = code.slice(0, script.loc.start.offset);
|
|
200
|
-
const after = code.slice(script.loc.end.offset);
|
|
201
|
-
const matches = before.match(/\blang\s*=\s*["']ts["']/);
|
|
202
|
-
if (matches) {
|
|
203
|
-
const lastMatch = matches[matches.length - 1];
|
|
204
|
-
const lastMatchIndex = before.lastIndexOf(lastMatch);
|
|
205
|
-
before = before.slice(0, lastMatchIndex) + before.slice(lastMatchIndex + lastMatch.length);
|
|
206
|
-
}
|
|
207
|
-
return before + scriptCode + after;
|
|
118
|
+
if (script === null || script.lang !== "ts") return code;
|
|
119
|
+
if (script.setup && templateAst) {
|
|
120
|
+
const expressions = /* @__PURE__ */ new Set();
|
|
121
|
+
(0, _vuedx_template_ast_types.traverse)(templateAst, { enter(node) {
|
|
122
|
+
if ((0, _vuedx_template_ast_types.isSimpleExpressionNode)(node) && !node.isStatic) expressions.add(`[${node.content}]`);
|
|
123
|
+
else if ((0, _vuedx_template_ast_types.isComponentNode)(node)) expressions.add(`[${node.tag}]`);
|
|
124
|
+
} });
|
|
125
|
+
script.content += "/* @detype: remove-after-this */" + [...expressions].join(";");
|
|
126
|
+
}
|
|
127
|
+
let scriptCode = await removeTypes(script.content, fileName + ".ts", options);
|
|
128
|
+
const removeAfterIndex = scriptCode.indexOf("/* @detype: remove-after-this */");
|
|
129
|
+
if (removeAfterIndex >= 0) scriptCode = scriptCode.slice(0, removeAfterIndex);
|
|
130
|
+
let before = code.slice(0, script.loc.start.offset);
|
|
131
|
+
const after = code.slice(script.loc.end.offset);
|
|
132
|
+
const matches = before.match(/\blang\s*=\s*["']ts["']/);
|
|
133
|
+
if (matches) {
|
|
134
|
+
const lastMatch = matches[matches.length - 1];
|
|
135
|
+
const lastMatchIndex = before.lastIndexOf(lastMatch);
|
|
136
|
+
before = before.slice(0, lastMatchIndex) + before.slice(lastMatchIndex + lastMatch.length);
|
|
137
|
+
}
|
|
138
|
+
return before + scriptCode + after;
|
|
208
139
|
}
|
|
209
140
|
function processMagicComments(input) {
|
|
210
|
-
|
|
211
|
-
|
|
212
|
-
|
|
213
|
-
|
|
214
|
-
|
|
215
|
-
|
|
216
|
-
|
|
217
|
-
|
|
218
|
-
|
|
219
|
-
|
|
220
|
-
|
|
221
|
-
|
|
222
|
-
|
|
223
|
-
|
|
224
|
-
|
|
225
|
-
|
|
226
|
-
|
|
227
|
-
|
|
141
|
+
const REPLACE_COMMENT = "// @detype: replace\n";
|
|
142
|
+
const WITH_COMMENT = "// @detype: with\n";
|
|
143
|
+
const END_COMMENT = "// @detype: end\n";
|
|
144
|
+
let start = input.indexOf(REPLACE_COMMENT);
|
|
145
|
+
while (start >= 0) {
|
|
146
|
+
const middle = input.indexOf(WITH_COMMENT, start);
|
|
147
|
+
if (middle < 0) return input;
|
|
148
|
+
const middleEnd = middle + 17;
|
|
149
|
+
const end = input.indexOf(END_COMMENT, middleEnd);
|
|
150
|
+
if (end < 0) return input;
|
|
151
|
+
const endEnd = end + 16;
|
|
152
|
+
const before = input.slice(0, start);
|
|
153
|
+
const newText = input.slice(middleEnd, end).replaceAll(/^\s*\/\//gm, "");
|
|
154
|
+
const after = input.slice(endEnd);
|
|
155
|
+
input = before + newText + after;
|
|
156
|
+
start = input.indexOf(REPLACE_COMMENT, before.length + newText.length);
|
|
157
|
+
}
|
|
158
|
+
return input;
|
|
228
159
|
}
|
|
160
|
+
/**
|
|
161
|
+
* Removes magic comments without performing the TS to JS transform
|
|
162
|
+
* @param code Source coude
|
|
163
|
+
* @param fileName File name for the source
|
|
164
|
+
* @param prettierOptions Options to pass to prettier
|
|
165
|
+
*/
|
|
229
166
|
async function removeMagicComments(code, fileName, prettierOptions) {
|
|
230
|
-
|
|
231
|
-
|
|
232
|
-
|
|
233
|
-
|
|
234
|
-
|
|
235
|
-
|
|
236
|
-
|
|
237
|
-
|
|
238
|
-
|
|
239
|
-
|
|
240
|
-
|
|
241
|
-
|
|
242
|
-
|
|
243
|
-
|
|
244
|
-
|
|
245
|
-
|
|
246
|
-
|
|
247
|
-
|
|
248
|
-
|
|
249
|
-
|
|
250
|
-
|
|
251
|
-
|
|
252
|
-
|
|
253
|
-
|
|
167
|
+
const REPLACE_COMMENT = "// @detype: replace\n";
|
|
168
|
+
const WITH_COMMENT = "// @detype: with\n";
|
|
169
|
+
const END_COMMENT = "// @detype: end\n";
|
|
170
|
+
let start = code.indexOf(REPLACE_COMMENT);
|
|
171
|
+
let startEnd = start + 20;
|
|
172
|
+
while (start >= 0) {
|
|
173
|
+
const middle = code.indexOf(WITH_COMMENT, start);
|
|
174
|
+
if (middle < 0) return code;
|
|
175
|
+
const middleEnd = middle + 17;
|
|
176
|
+
const end = code.indexOf(END_COMMENT, middleEnd);
|
|
177
|
+
if (end < 0) return code;
|
|
178
|
+
const endEnd = end + 16;
|
|
179
|
+
const before = code.slice(0, start);
|
|
180
|
+
const keptText = code.slice(startEnd, middle);
|
|
181
|
+
const after = code.slice(endEnd);
|
|
182
|
+
code = before + keptText + after;
|
|
183
|
+
start = code.indexOf(REPLACE_COMMENT, before.length + keptText.length);
|
|
184
|
+
startEnd = start + 20;
|
|
185
|
+
}
|
|
186
|
+
code = await (0, prettier.format)(code, {
|
|
187
|
+
...prettierOptions,
|
|
188
|
+
filepath: fileName
|
|
189
|
+
});
|
|
190
|
+
return code;
|
|
254
191
|
}
|
|
255
|
-
|
|
256
|
-
|
|
257
|
-
|
|
258
|
-
|
|
259
|
-
|
|
192
|
+
//#endregion
|
|
193
|
+
//#region src/transformFile.ts
|
|
194
|
+
const { readFile, writeFile } = node_fs.default.promises;
|
|
195
|
+
/**
|
|
196
|
+
* Transform the input file and write the output to another file
|
|
197
|
+
* @param inputFileName
|
|
198
|
+
* @param outputFileName
|
|
199
|
+
*/
|
|
260
200
|
async function transformFile(inputFileName, outputFileName, options = {}) {
|
|
261
|
-
|
|
262
|
-
|
|
263
|
-
|
|
264
|
-
|
|
265
|
-
...options
|
|
266
|
-
});
|
|
267
|
-
await writeFile(outputFileName, output, "utf-8");
|
|
201
|
+
await writeFile(outputFileName, await transform(await readFile(inputFileName, "utf-8"), inputFileName, {
|
|
202
|
+
prettierOptions: await (0, prettier.resolveConfig)(inputFileName),
|
|
203
|
+
...options
|
|
204
|
+
}), "utf-8");
|
|
268
205
|
}
|
|
206
|
+
/**
|
|
207
|
+
* Remove magic comments from the input file and write the output to another file
|
|
208
|
+
* @param inputFileName
|
|
209
|
+
* @param outputFileName
|
|
210
|
+
*/
|
|
269
211
|
async function removeMagicCommentsFromFile(inputFileName, outputFileName) {
|
|
270
|
-
|
|
271
|
-
const prettierConfig = await (0, import_prettier2.resolveConfig)(inputFileName);
|
|
272
|
-
const output = await removeMagicComments(code, inputFileName, prettierConfig);
|
|
273
|
-
await writeFile(outputFileName, output, "utf-8");
|
|
212
|
+
await writeFile(outputFileName, await removeMagicComments(await readFile(inputFileName, "utf-8"), inputFileName, await (0, prettier.resolveConfig)(inputFileName)), "utf-8");
|
|
274
213
|
}
|
|
275
|
-
|
|
276
|
-
|
|
277
|
-
|
|
278
|
-
|
|
279
|
-
|
|
280
|
-
transformFile
|
|
281
|
-
});
|
|
214
|
+
//#endregion
|
|
215
|
+
exports.removeMagicComments = removeMagicComments;
|
|
216
|
+
exports.removeMagicCommentsFromFile = removeMagicCommentsFromFile;
|
|
217
|
+
exports.transform = transform;
|
|
218
|
+
exports.transformFile = transformFile;
|
package/dist/index.d.cts
CHANGED
|
@@ -1,43 +1,44 @@
|
|
|
1
|
-
import { Options } from
|
|
2
|
-
|
|
3
|
-
import { TransformOptions as TransformOptions$1 } from '@babel/core';
|
|
1
|
+
import { Options as PrettierOptions } from "prettier";
|
|
2
|
+
import { TransformOptions } from "@babel/core";
|
|
4
3
|
|
|
4
|
+
//#region src/transform.d.ts
|
|
5
5
|
interface RemoveTypeOptions {
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
6
|
+
/** Whether to remove ts-ignore and ts-expect-error comments */
|
|
7
|
+
removeTsComments?: boolean;
|
|
8
|
+
/** Escape hatch for customizing Babel configuration */
|
|
9
|
+
customizeBabelConfig?(config: TransformOptions): void;
|
|
10
10
|
}
|
|
11
|
-
interface TransformOptions extends RemoveTypeOptions {
|
|
12
|
-
|
|
13
|
-
|
|
11
|
+
interface TransformOptions$1 extends RemoveTypeOptions {
|
|
12
|
+
/** Prettier options */
|
|
13
|
+
prettierOptions?: PrettierOptions | null;
|
|
14
14
|
}
|
|
15
15
|
/**
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
declare function transform(code: string, fileName: string, options?: TransformOptions): Promise<string>;
|
|
16
|
+
* Transform TypeScript code into vanilla JavaScript without affecting the formatting
|
|
17
|
+
* @param code Source coude
|
|
18
|
+
* @param fileName File name for the source
|
|
19
|
+
* @param options Options
|
|
20
|
+
*/
|
|
21
|
+
declare function transform(code: string, fileName: string, options?: TransformOptions$1): Promise<string>;
|
|
22
22
|
/**
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
declare function removeMagicComments(code: string, fileName: string, prettierOptions?:
|
|
29
|
-
|
|
23
|
+
* Removes magic comments without performing the TS to JS transform
|
|
24
|
+
* @param code Source coude
|
|
25
|
+
* @param fileName File name for the source
|
|
26
|
+
* @param prettierOptions Options to pass to prettier
|
|
27
|
+
*/
|
|
28
|
+
declare function removeMagicComments(code: string, fileName: string, prettierOptions?: PrettierOptions | null): Promise<string>;
|
|
29
|
+
//#endregion
|
|
30
|
+
//#region src/transformFile.d.ts
|
|
30
31
|
/**
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
32
|
+
* Transform the input file and write the output to another file
|
|
33
|
+
* @param inputFileName
|
|
34
|
+
* @param outputFileName
|
|
35
|
+
*/
|
|
35
36
|
declare function transformFile(inputFileName: string, outputFileName: string, options?: RemoveTypeOptions): Promise<void>;
|
|
36
37
|
/**
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
38
|
+
* Remove magic comments from the input file and write the output to another file
|
|
39
|
+
* @param inputFileName
|
|
40
|
+
* @param outputFileName
|
|
41
|
+
*/
|
|
41
42
|
declare function removeMagicCommentsFromFile(inputFileName: string, outputFileName: string): Promise<void>;
|
|
42
|
-
|
|
43
|
-
export { removeMagicComments, removeMagicCommentsFromFile, transform, transformFile };
|
|
43
|
+
//#endregion
|
|
44
|
+
export { type PrettierOptions, removeMagicComments, removeMagicCommentsFromFile, transform, transformFile };
|
package/dist/index.d.ts
CHANGED
|
@@ -1,43 +1,44 @@
|
|
|
1
|
-
import {
|
|
2
|
-
|
|
3
|
-
import { TransformOptions as TransformOptions$1 } from '@babel/core';
|
|
1
|
+
import { TransformOptions } from "@babel/core";
|
|
2
|
+
import { Options as PrettierOptions } from "prettier";
|
|
4
3
|
|
|
4
|
+
//#region src/transform.d.ts
|
|
5
5
|
interface RemoveTypeOptions {
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
6
|
+
/** Whether to remove ts-ignore and ts-expect-error comments */
|
|
7
|
+
removeTsComments?: boolean;
|
|
8
|
+
/** Escape hatch for customizing Babel configuration */
|
|
9
|
+
customizeBabelConfig?(config: TransformOptions): void;
|
|
10
10
|
}
|
|
11
|
-
interface TransformOptions extends RemoveTypeOptions {
|
|
12
|
-
|
|
13
|
-
|
|
11
|
+
interface TransformOptions$1 extends RemoveTypeOptions {
|
|
12
|
+
/** Prettier options */
|
|
13
|
+
prettierOptions?: PrettierOptions | null;
|
|
14
14
|
}
|
|
15
15
|
/**
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
declare function transform(code: string, fileName: string, options?: TransformOptions): Promise<string>;
|
|
16
|
+
* Transform TypeScript code into vanilla JavaScript without affecting the formatting
|
|
17
|
+
* @param code Source coude
|
|
18
|
+
* @param fileName File name for the source
|
|
19
|
+
* @param options Options
|
|
20
|
+
*/
|
|
21
|
+
declare function transform(code: string, fileName: string, options?: TransformOptions$1): Promise<string>;
|
|
22
22
|
/**
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
declare function removeMagicComments(code: string, fileName: string, prettierOptions?:
|
|
29
|
-
|
|
23
|
+
* Removes magic comments without performing the TS to JS transform
|
|
24
|
+
* @param code Source coude
|
|
25
|
+
* @param fileName File name for the source
|
|
26
|
+
* @param prettierOptions Options to pass to prettier
|
|
27
|
+
*/
|
|
28
|
+
declare function removeMagicComments(code: string, fileName: string, prettierOptions?: PrettierOptions | null): Promise<string>;
|
|
29
|
+
//#endregion
|
|
30
|
+
//#region src/transformFile.d.ts
|
|
30
31
|
/**
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
32
|
+
* Transform the input file and write the output to another file
|
|
33
|
+
* @param inputFileName
|
|
34
|
+
* @param outputFileName
|
|
35
|
+
*/
|
|
35
36
|
declare function transformFile(inputFileName: string, outputFileName: string, options?: RemoveTypeOptions): Promise<void>;
|
|
36
37
|
/**
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
38
|
+
* Remove magic comments from the input file and write the output to another file
|
|
39
|
+
* @param inputFileName
|
|
40
|
+
* @param outputFileName
|
|
41
|
+
*/
|
|
41
42
|
declare function removeMagicCommentsFromFile(inputFileName: string, outputFileName: string): Promise<void>;
|
|
42
|
-
|
|
43
|
-
export { removeMagicComments, removeMagicCommentsFromFile, transform, transformFile };
|
|
43
|
+
//#endregion
|
|
44
|
+
export { type PrettierOptions, removeMagicComments, removeMagicCommentsFromFile, transform, transformFile };
|