detype 2.0.3 → 2.0.4
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 +104 -230
- package/dist/index.cjs +199 -254
- package/dist/index.d.cts +34 -33
- package/dist/index.d.ts +34 -33
- package/dist/index.js +3 -12
- package/dist/transformFile-CkCVsmzB.js +193 -0
- package/package.json +11 -8
- package/dist/chunk-VYED23Y7.js +0 -250
package/detype.js
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
1
|
#!/usr/bin/env node
|
|
2
|
-
import "./dist/cli";
|
|
2
|
+
import "./dist/cli.js";
|
package/dist/cli.d.ts
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export { };
|
package/dist/cli.js
CHANGED
|
@@ -1,232 +1,102 @@
|
|
|
1
|
-
import {
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
} from "./chunk-VYED23Y7.js";
|
|
5
|
-
|
|
6
|
-
// src/cli-lib.ts
|
|
7
|
-
import fs from "fs";
|
|
8
|
-
import path from "path";
|
|
1
|
+
import { n as transformFile, t as removeMagicCommentsFromFile } from "./transformFile-CkCVsmzB.js";
|
|
2
|
+
import fs from "node:fs";
|
|
3
|
+
import path from "node:path";
|
|
9
4
|
import fastGlob from "fast-glob";
|
|
10
5
|
|
|
11
|
-
|
|
12
|
-
var
|
|
13
|
-
name: "detype",
|
|
14
|
-
version: "2.0.3",
|
|
15
|
-
description: "Removes TypeScript type annotations but keeps the formatting",
|
|
16
|
-
type: "module",
|
|
17
|
-
exports: {
|
|
18
|
-
".": {
|
|
19
|
-
import: {
|
|
20
|
-
types: "./dist/index.d.ts",
|
|
21
|
-
default: "./dist/index.js"
|
|
22
|
-
},
|
|
23
|
-
require: {
|
|
24
|
-
types: "./dist/index.d.cts",
|
|
25
|
-
default: "./dist/index.cjs"
|
|
26
|
-
}
|
|
27
|
-
}
|
|
28
|
-
},
|
|
29
|
-
bin: "detype.js",
|
|
30
|
-
scripts: {
|
|
31
|
-
prepack: "rimraf dist && pnpm build",
|
|
32
|
-
build: "tsup",
|
|
33
|
-
dev: "tsup --watch",
|
|
34
|
-
test: "pnpm run /^test:/",
|
|
35
|
-
"test:cq": "pnpm run /^cq:/",
|
|
36
|
-
"test:unit": "vitest run",
|
|
37
|
-
"cq:typecheck": "tsc -p tsconfig.json --noEmit",
|
|
38
|
-
"cq:lint": "eslint src --max-warnings 0",
|
|
39
|
-
"cq:prettier": "prettier --check test-files --ignore-unknown . '!pnpm-lock.yaml'",
|
|
40
|
-
format: "prettier . --write --ignore-path .gitignore --ignore-unknown . '!pnpm-lock.yaml'"
|
|
41
|
-
},
|
|
42
|
-
files: [
|
|
43
|
-
"dist/**/*",
|
|
44
|
-
"index.d.ts"
|
|
45
|
-
],
|
|
46
|
-
dependencies: {
|
|
47
|
-
"@babel/core": "^7.29.0",
|
|
48
|
-
"@babel/preset-typescript": "^7.28.5",
|
|
49
|
-
"@babel/traverse": "^7.29.0",
|
|
50
|
-
"@vue/compiler-dom": "^3.5.28",
|
|
51
|
-
"@vue/compiler-sfc": "^3.5.28",
|
|
52
|
-
"@vuedx/compiler-sfc": "0.7.1",
|
|
53
|
-
"@vuedx/template-ast-types": "0.7.1",
|
|
54
|
-
"fast-glob": "^3.3.3",
|
|
55
|
-
prettier: "^3.8.1"
|
|
56
|
-
},
|
|
57
|
-
devDependencies: {
|
|
58
|
-
"@cyco130/eslint-config": "^6.2.0",
|
|
59
|
-
"@types/babel__core": "^7.20.5",
|
|
60
|
-
"@types/babel__traverse": "^7.28.0",
|
|
61
|
-
"@types/node": "25.0.3",
|
|
62
|
-
eslint: "^10.0.0",
|
|
63
|
-
rimraf: "^6.1.3",
|
|
64
|
-
tsup: "^8.5.1",
|
|
65
|
-
typescript: "^5.9.3",
|
|
66
|
-
vitest: "4.0.18"
|
|
67
|
-
},
|
|
68
|
-
repository: {
|
|
69
|
-
type: "git",
|
|
70
|
-
url: "git+https://github.com/cyco130/detype.git"
|
|
71
|
-
},
|
|
72
|
-
keywords: [
|
|
73
|
-
"typescript",
|
|
74
|
-
"formatting",
|
|
75
|
-
"vue",
|
|
76
|
-
"sfc"
|
|
77
|
-
],
|
|
78
|
-
author: "Fatih Ayg\xFCn <cyco130@gmail.com>",
|
|
79
|
-
license: "MIT",
|
|
80
|
-
bugs: {
|
|
81
|
-
url: "https://github.com/cyco130/detype/issues"
|
|
82
|
-
},
|
|
83
|
-
homepage: "https://github.com/cyco130/detype#readme",
|
|
84
|
-
pnpm: {
|
|
85
|
-
overrides: {},
|
|
86
|
-
onlyBuiltDependencies: [
|
|
87
|
-
"esbuild",
|
|
88
|
-
"unrs-resolver"
|
|
89
|
-
]
|
|
90
|
-
}
|
|
91
|
-
};
|
|
6
|
+
//#region package.json
|
|
7
|
+
var version = "2.0.4";
|
|
92
8
|
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
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
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
output = inferName(input, output);
|
|
180
|
-
}
|
|
181
|
-
} else {
|
|
182
|
-
if (removeMagic) {
|
|
183
|
-
console.error(
|
|
184
|
-
"Output file name is required when removing magic comments"
|
|
185
|
-
);
|
|
186
|
-
return false;
|
|
187
|
-
}
|
|
188
|
-
if (input.endsWith(".vue")) {
|
|
189
|
-
console.error("Output file name is required for .vue files");
|
|
190
|
-
return false;
|
|
191
|
-
}
|
|
192
|
-
output = inferName(input);
|
|
193
|
-
}
|
|
194
|
-
const outputDir = path.dirname(output);
|
|
195
|
-
if (outputDir) {
|
|
196
|
-
await mkdir(path.normalize(outputDir), { recursive: true });
|
|
197
|
-
}
|
|
198
|
-
if (removeMagic) {
|
|
199
|
-
await removeMagicCommentsFromFile(
|
|
200
|
-
path.normalize(input),
|
|
201
|
-
path.normalize(output)
|
|
202
|
-
);
|
|
203
|
-
} else {
|
|
204
|
-
await transformFile(path.normalize(input), path.normalize(output), {
|
|
205
|
-
removeTsComments
|
|
206
|
-
});
|
|
207
|
-
}
|
|
208
|
-
return true;
|
|
209
|
-
function inferName(input2, outputDir2) {
|
|
210
|
-
let output2;
|
|
211
|
-
const { dir, name, ext } = path.parse(input2);
|
|
212
|
-
if (removeMagic) {
|
|
213
|
-
output2 = path.join(outputDir2 ?? dir, `${name}${ext}`);
|
|
214
|
-
} else if (ext === ".ts") {
|
|
215
|
-
output2 = path.join(outputDir2 ?? dir, name + ".js");
|
|
216
|
-
} else if (ext === ".tsx") {
|
|
217
|
-
output2 = path.join(outputDir2 ?? dir, name + ".jsx");
|
|
218
|
-
} else if (ext === ".vue") {
|
|
219
|
-
output2 = path.join(outputDir2 ?? dir, name + ".vue");
|
|
220
|
-
} else {
|
|
221
|
-
throw new Error(`Unknwon file extension ${input2}`);
|
|
222
|
-
}
|
|
223
|
-
return output2;
|
|
224
|
-
}
|
|
9
|
+
//#endregion
|
|
10
|
+
//#region src/cli-lib.ts
|
|
11
|
+
const { stat, mkdir } = fs.promises;
|
|
12
|
+
async function cli(...args) {
|
|
13
|
+
let dashDash = false;
|
|
14
|
+
const params = [];
|
|
15
|
+
const flags = [];
|
|
16
|
+
for (const arg of args) if (arg === "--") dashDash = true;
|
|
17
|
+
else if (dashDash || !arg.startsWith("-")) params.push(arg);
|
|
18
|
+
else flags.push(arg);
|
|
19
|
+
if (params.length > 2) {
|
|
20
|
+
console.error("Too many arguments");
|
|
21
|
+
return false;
|
|
22
|
+
}
|
|
23
|
+
let [input, output] = params;
|
|
24
|
+
if (params.length === 0 || flags.some((flag) => flag === "-h" || flag === "--help")) {
|
|
25
|
+
printUsage();
|
|
26
|
+
return params.length > 0;
|
|
27
|
+
}
|
|
28
|
+
if (flags.some((flag) => flag === "-v" || flag === "--version")) {
|
|
29
|
+
console.log(VERSION);
|
|
30
|
+
return true;
|
|
31
|
+
}
|
|
32
|
+
const removeMagic = flags.some((flag) => flag === "-m" || flag === "--remove-magic-comments");
|
|
33
|
+
const removeTsComments = flags.some((flag) => flag === "-t" || flag === "--remove-ts-comments");
|
|
34
|
+
if (removeMagic && removeTsComments) console.warn("--remove-ts-comments has no effect when --remove-magic-comments is used");
|
|
35
|
+
if (!removeMagic) [input, output] = args;
|
|
36
|
+
if (!input) {
|
|
37
|
+
console.error("No input file or directory given");
|
|
38
|
+
printUsage();
|
|
39
|
+
return false;
|
|
40
|
+
}
|
|
41
|
+
if ((await stat(input)).isDirectory()) {
|
|
42
|
+
if (!output) {
|
|
43
|
+
console.error("No output directory given");
|
|
44
|
+
printUsage();
|
|
45
|
+
return false;
|
|
46
|
+
}
|
|
47
|
+
const files = (await fastGlob(unixify(input + "/**/*.{ts,tsx,vue}"))).filter((file) => !file.endsWith(".d.ts"));
|
|
48
|
+
const dirs = [...new Set(files.map((file) => path.dirname(file)))].sort();
|
|
49
|
+
await mkdir(path.normalize(output), { recursive: true });
|
|
50
|
+
for (const dir of dirs) {
|
|
51
|
+
const outDir = path.join(output, path.relative(input, dir));
|
|
52
|
+
if (outDir === output) continue;
|
|
53
|
+
await mkdir(path.normalize(outDir), { recursive: true });
|
|
54
|
+
}
|
|
55
|
+
for (const file of files) {
|
|
56
|
+
const inputDir = path.dirname(path.relative(input, file));
|
|
57
|
+
const outputName = inferName(file, path.join(output, inputDir));
|
|
58
|
+
if (removeMagic) await removeMagicCommentsFromFile(path.normalize(file), path.normalize(outputName));
|
|
59
|
+
else await transformFile(path.normalize(file), path.normalize(outputName), { removeTsComments });
|
|
60
|
+
}
|
|
61
|
+
return true;
|
|
62
|
+
}
|
|
63
|
+
if (output) {
|
|
64
|
+
const outputStat = await stat(output).catch((error) => {
|
|
65
|
+
if (error && error.code === "ENOENT") return null;
|
|
66
|
+
throw error;
|
|
67
|
+
});
|
|
68
|
+
if (outputStat && outputStat.isDirectory()) output = inferName(input, output);
|
|
69
|
+
} else {
|
|
70
|
+
if (removeMagic) {
|
|
71
|
+
console.error("Output file name is required when removing magic comments");
|
|
72
|
+
return false;
|
|
73
|
+
}
|
|
74
|
+
if (input.endsWith(".vue")) {
|
|
75
|
+
console.error("Output file name is required for .vue files");
|
|
76
|
+
return false;
|
|
77
|
+
}
|
|
78
|
+
output = inferName(input);
|
|
79
|
+
}
|
|
80
|
+
const outputDir = path.dirname(output);
|
|
81
|
+
if (outputDir) await mkdir(path.normalize(outputDir), { recursive: true });
|
|
82
|
+
if (removeMagic) await removeMagicCommentsFromFile(path.normalize(input), path.normalize(output));
|
|
83
|
+
else await transformFile(path.normalize(input), path.normalize(output), { removeTsComments });
|
|
84
|
+
return true;
|
|
85
|
+
function inferName(input, outputDir) {
|
|
86
|
+
let output;
|
|
87
|
+
const { dir, name, ext } = path.parse(input);
|
|
88
|
+
if (removeMagic) output = path.join(outputDir ?? dir, `${name}${ext}`);
|
|
89
|
+
else if (ext === ".ts") output = path.join(outputDir ?? dir, name + ".js");
|
|
90
|
+
else if (ext === ".tsx") output = path.join(outputDir ?? dir, name + ".jsx");
|
|
91
|
+
else if (ext === ".vue") output = path.join(outputDir ?? dir, name + ".vue");
|
|
92
|
+
else throw new Error(`Unknwon file extension ${input}`);
|
|
93
|
+
return output;
|
|
94
|
+
}
|
|
225
95
|
}
|
|
226
96
|
function printUsage() {
|
|
227
|
-
|
|
97
|
+
console.error(USAGE);
|
|
228
98
|
}
|
|
229
|
-
|
|
99
|
+
const USAGE = `Usage:
|
|
230
100
|
|
|
231
101
|
detype [-m | --remove-magic-comments] <INPUT> [OUTPUT]
|
|
232
102
|
|
|
@@ -248,14 +118,18 @@ var USAGE = `Usage:
|
|
|
248
118
|
detype [-h | --help]
|
|
249
119
|
|
|
250
120
|
Print this help and exit`;
|
|
251
|
-
|
|
121
|
+
const VERSION = version;
|
|
122
|
+
/** Unixify path */
|
|
252
123
|
function unixify(name) {
|
|
253
|
-
|
|
124
|
+
return name.replaceAll(path.sep, "/");
|
|
254
125
|
}
|
|
255
126
|
|
|
256
|
-
|
|
257
|
-
|
|
258
|
-
cli(...
|
|
259
|
-
|
|
260
|
-
|
|
127
|
+
//#endregion
|
|
128
|
+
//#region src/cli.ts
|
|
129
|
+
cli(...process.argv.slice(2)).then((success) => process.exit(success ? 0 : 1)).catch((error) => {
|
|
130
|
+
console.error(error);
|
|
131
|
+
process.exit(1);
|
|
261
132
|
});
|
|
133
|
+
|
|
134
|
+
//#endregion
|
|
135
|
+
export { };
|