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 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,100 @@
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-qmpi6_2q.js";
2
+ import fs from "node:fs";
3
+ import path from "node:path";
9
4
  import fastGlob from "fast-glob";
10
-
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
- };
92
-
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
- }
5
+ //#region package.json
6
+ var version = "2.0.5";
7
+ //#endregion
8
+ //#region src/cli-lib.ts
9
+ const { stat, mkdir } = fs.promises;
10
+ async function cli(...args) {
11
+ let dashDash = false;
12
+ const params = [];
13
+ const flags = [];
14
+ for (const arg of args) if (arg === "--") dashDash = true;
15
+ else if (dashDash || !arg.startsWith("-")) params.push(arg);
16
+ else flags.push(arg);
17
+ if (params.length > 2) {
18
+ console.error("Too many arguments");
19
+ return false;
20
+ }
21
+ let [input, output] = params;
22
+ if (params.length === 0 || flags.some((flag) => flag === "-h" || flag === "--help")) {
23
+ printUsage();
24
+ return params.length > 0;
25
+ }
26
+ if (flags.some((flag) => flag === "-v" || flag === "--version")) {
27
+ console.log(VERSION);
28
+ return true;
29
+ }
30
+ const removeMagic = flags.some((flag) => flag === "-m" || flag === "--remove-magic-comments");
31
+ const removeTsComments = flags.some((flag) => flag === "-t" || flag === "--remove-ts-comments");
32
+ if (removeMagic && removeTsComments) console.warn("--remove-ts-comments has no effect when --remove-magic-comments is used");
33
+ if (!removeMagic) [input, output] = args;
34
+ if (!input) {
35
+ console.error("No input file or directory given");
36
+ printUsage();
37
+ return false;
38
+ }
39
+ if ((await stat(input)).isDirectory()) {
40
+ if (!output) {
41
+ console.error("No output directory given");
42
+ printUsage();
43
+ return false;
44
+ }
45
+ const files = (await fastGlob(unixify(input + "/**/*.{ts,tsx,vue}"))).filter((file) => !file.endsWith(".d.ts"));
46
+ const dirs = [...new Set(files.map((file) => path.dirname(file)))].sort();
47
+ await mkdir(path.normalize(output), { recursive: true });
48
+ for (const dir of dirs) {
49
+ const outDir = path.join(output, path.relative(input, dir));
50
+ if (outDir === output) continue;
51
+ await mkdir(path.normalize(outDir), { recursive: true });
52
+ }
53
+ for (const file of files) {
54
+ const inputDir = path.dirname(path.relative(input, file));
55
+ const outputName = inferName(file, path.join(output, inputDir));
56
+ if (removeMagic) await removeMagicCommentsFromFile(path.normalize(file), path.normalize(outputName));
57
+ else await transformFile(path.normalize(file), path.normalize(outputName), { removeTsComments });
58
+ }
59
+ return true;
60
+ }
61
+ if (output) {
62
+ const outputStat = await stat(output).catch((error) => {
63
+ if (error && error.code === "ENOENT") return null;
64
+ throw error;
65
+ });
66
+ if (outputStat && outputStat.isDirectory()) output = inferName(input, output);
67
+ } else {
68
+ if (removeMagic) {
69
+ console.error("Output file name is required when removing magic comments");
70
+ return false;
71
+ }
72
+ if (input.endsWith(".vue")) {
73
+ console.error("Output file name is required for .vue files");
74
+ return false;
75
+ }
76
+ output = inferName(input);
77
+ }
78
+ const outputDir = path.dirname(output);
79
+ if (outputDir) await mkdir(path.normalize(outputDir), { recursive: true });
80
+ if (removeMagic) await removeMagicCommentsFromFile(path.normalize(input), path.normalize(output));
81
+ else await transformFile(path.normalize(input), path.normalize(output), { removeTsComments });
82
+ return true;
83
+ function inferName(input, outputDir) {
84
+ let output;
85
+ const { dir, name, ext } = path.parse(input);
86
+ if (removeMagic) output = path.join(outputDir ?? dir, `${name}${ext}`);
87
+ else if (ext === ".ts") output = path.join(outputDir ?? dir, name + ".js");
88
+ else if (ext === ".tsx") output = path.join(outputDir ?? dir, name + ".jsx");
89
+ else if (ext === ".vue") output = path.join(outputDir ?? dir, name + ".vue");
90
+ else throw new Error(`Unknwon file extension ${input}`);
91
+ return output;
92
+ }
225
93
  }
226
94
  function printUsage() {
227
- console.error(USAGE);
95
+ console.error(USAGE);
228
96
  }
229
- var USAGE = `Usage:
97
+ const USAGE = `Usage:
230
98
 
231
99
  detype [-m | --remove-magic-comments] <INPUT> [OUTPUT]
232
100
 
@@ -248,14 +116,16 @@ var USAGE = `Usage:
248
116
  detype [-h | --help]
249
117
 
250
118
  Print this help and exit`;
251
- var VERSION = package_default.version;
119
+ const VERSION = version;
120
+ /** Unixify path */
252
121
  function unixify(name) {
253
- return name.replaceAll(path.sep, "/");
122
+ return name.replaceAll(path.sep, "/");
254
123
  }
255
-
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);
124
+ //#endregion
125
+ //#region src/cli.ts
126
+ cli(...process.argv.slice(2)).then((success) => process.exit(success ? 0 : 1)).catch((error) => {
127
+ console.error(error);
128
+ process.exit(1);
261
129
  });
130
+ //#endregion
131
+ export {};