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 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
- removeMagicCommentsFromFile,
3
- transformFile
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
- // package.json
12
- var package_default = {
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
- // src/cli-lib.ts
94
- var { stat, mkdir } = fs.promises;
95
- async function cli(...args2) {
96
- let dashDash = false;
97
- const params = [];
98
- const flags = [];
99
- for (const arg of args2) {
100
- if (arg === "--") {
101
- dashDash = true;
102
- } else if (dashDash || !arg.startsWith("-")) {
103
- params.push(arg);
104
- } else {
105
- flags.push(arg);
106
- }
107
- }
108
- if (params.length > 2) {
109
- console.error("Too many arguments");
110
- return false;
111
- }
112
- let [input, output] = params;
113
- if (params.length === 0 || flags.some((flag) => flag === "-h" || flag === "--help")) {
114
- printUsage();
115
- return params.length > 0;
116
- }
117
- if (flags.some((flag) => flag === "-v" || flag === "--version")) {
118
- console.log(VERSION);
119
- return true;
120
- }
121
- const removeMagic = flags.some(
122
- (flag) => flag === "-m" || flag === "--remove-magic-comments"
123
- );
124
- const removeTsComments = flags.some(
125
- (flag) => flag === "-t" || flag === "--remove-ts-comments"
126
- );
127
- if (removeMagic && removeTsComments) {
128
- console.warn(
129
- "--remove-ts-comments has no effect when --remove-magic-comments is used"
130
- );
131
- }
132
- if (!removeMagic) {
133
- [input, output] = args2;
134
- }
135
- if (!input) {
136
- console.error("No input file or directory given");
137
- printUsage();
138
- return false;
139
- }
140
- const inputStat = await stat(input);
141
- if (inputStat.isDirectory()) {
142
- if (!output) {
143
- console.error("No output directory given");
144
- printUsage();
145
- return false;
146
- }
147
- const files = (await fastGlob(unixify(input + "/**/*.{ts,tsx,vue}"))).filter((file) => !file.endsWith(".d.ts"));
148
- const dirs = [...new Set(files.map((file) => path.dirname(file)))].sort();
149
- await mkdir(path.normalize(output), { recursive: true });
150
- for (const dir of dirs) {
151
- const outDir = path.join(output, path.relative(input, dir));
152
- if (outDir === output) continue;
153
- await mkdir(path.normalize(outDir), { recursive: true });
154
- }
155
- for (const file of files) {
156
- const inputDir = path.dirname(path.relative(input, file));
157
- const outputName = inferName(file, path.join(output, inputDir));
158
- if (removeMagic) {
159
- await removeMagicCommentsFromFile(
160
- path.normalize(file),
161
- path.normalize(outputName)
162
- );
163
- } else {
164
- await transformFile(path.normalize(file), path.normalize(outputName), {
165
- removeTsComments
166
- });
167
- }
168
- }
169
- return true;
170
- }
171
- if (output) {
172
- const outputStat = await stat(output).catch((error) => {
173
- if (error && error.code === "ENOENT") {
174
- return null;
175
- }
176
- throw error;
177
- });
178
- if (outputStat && outputStat.isDirectory()) {
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
- console.error(USAGE);
97
+ console.error(USAGE);
228
98
  }
229
- var USAGE = `Usage:
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
- var VERSION = package_default.version;
121
+ const VERSION = version;
122
+ /** Unixify path */
252
123
  function unixify(name) {
253
- return name.replaceAll(path.sep, "/");
124
+ return name.replaceAll(path.sep, "/");
254
125
  }
255
126
 
256
- // src/cli.ts
257
- var args = process.argv.slice(2);
258
- cli(...args).then((success) => process.exit(success ? 0 : 1)).catch((error) => {
259
- console.error(error);
260
- process.exit(1);
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 { };