detype 0.4.2 → 0.5.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 +33 -22
- package/dist/cli.js +37 -38
- package/dist/index.d.ts +32 -0
- package/index.d.ts +1 -47
- package/package.json +22 -28
package/README.md
CHANGED
|
@@ -22,13 +22,13 @@ let x: string;
|
|
|
22
22
|
// This comment should be deleted
|
|
23
23
|
// Ditto for this
|
|
24
24
|
interface Foo {
|
|
25
|
-
|
|
26
|
-
|
|
25
|
+
// This should go too
|
|
26
|
+
bar: number;
|
|
27
27
|
}
|
|
28
28
|
|
|
29
29
|
// This comment should also be kept
|
|
30
30
|
export function bar(foo: Foo): Date {
|
|
31
|
-
|
|
31
|
+
return new Date();
|
|
32
32
|
}
|
|
33
33
|
```
|
|
34
34
|
|
|
@@ -41,7 +41,7 @@ let x;
|
|
|
41
41
|
|
|
42
42
|
// This comment should also be kept
|
|
43
43
|
export function bar(foo) {
|
|
44
|
-
|
|
44
|
+
return new Date();
|
|
45
45
|
}
|
|
46
46
|
```
|
|
47
47
|
|
|
@@ -85,7 +85,7 @@ console.log("Hello from TypeScript");
|
|
|
85
85
|
|
|
86
86
|
## System requirements
|
|
87
87
|
|
|
88
|
-
`detype` requires Node version
|
|
88
|
+
`detype` requires Node version 14.19.3 or later.
|
|
89
89
|
|
|
90
90
|
## CLI Usage
|
|
91
91
|
|
|
@@ -114,52 +114,63 @@ detype [-h | --help]
|
|
|
114
114
|
```ts
|
|
115
115
|
// Transform TypeScript code into vanilla JavaScript without affecting the formatting
|
|
116
116
|
function transform(
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
117
|
+
// Source code
|
|
118
|
+
code: string,
|
|
119
|
+
// File name for the source
|
|
120
|
+
fileName: string,
|
|
121
|
+
// Options to pass to prettier
|
|
122
|
+
prettierOptions?: PrettierOptions | null,
|
|
123
123
|
): Promise<string>;
|
|
124
124
|
|
|
125
125
|
// Transform the input file and write the output to another file
|
|
126
126
|
function transformFile(
|
|
127
|
-
|
|
128
|
-
|
|
127
|
+
inputFileName: string,
|
|
128
|
+
outputFileName: string,
|
|
129
129
|
): Promise<void>;
|
|
130
130
|
|
|
131
131
|
// Remove magic comments without performing the TS to JS transform
|
|
132
132
|
export function removeMagicComments(
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
133
|
+
// Source code
|
|
134
|
+
code: string,
|
|
135
|
+
// File name for the source
|
|
136
|
+
fileName: string,
|
|
137
|
+
// Options to pass to prettier
|
|
138
|
+
prettierOptions?: PrettierOptions | null,
|
|
139
139
|
): string;
|
|
140
140
|
|
|
141
141
|
// Remove magic comments from the input file and write the output to another file
|
|
142
142
|
export function removeMagicCommentsFromFile(
|
|
143
|
-
|
|
144
|
-
|
|
143
|
+
inputFileName: string,
|
|
144
|
+
outputFileName: string,
|
|
145
145
|
): Promise<void>;
|
|
146
146
|
```
|
|
147
147
|
|
|
148
148
|
## Change log
|
|
149
|
+
|
|
150
|
+
### 0.5
|
|
151
|
+
|
|
152
|
+
- BREAKING CHANGE: Drop support for Node 12
|
|
153
|
+
- chore: Set up CI workflows
|
|
154
|
+
|
|
149
155
|
### 0.4
|
|
156
|
+
|
|
150
157
|
- feature: CLI support for removing magic comments
|
|
151
158
|
- chore: Improve documentation
|
|
152
159
|
|
|
153
160
|
### 0.3
|
|
161
|
+
|
|
154
162
|
- feature: Magic comments
|
|
155
163
|
- feature: Expose type declarations
|
|
156
164
|
- fix: Better empty line handling
|
|
157
165
|
|
|
158
166
|
### 0.2
|
|
167
|
+
|
|
159
168
|
- feature: for Vue single file components
|
|
160
169
|
|
|
161
170
|
### 0.1
|
|
171
|
+
|
|
162
172
|
- Initial release
|
|
163
173
|
|
|
164
174
|
## Credits
|
|
165
|
-
|
|
175
|
+
|
|
176
|
+
Fatih Aygün, under MIT License
|
package/dist/cli.js
CHANGED
|
@@ -212,56 +212,51 @@ var import_fast_glob = __toESM(require("fast-glob"));
|
|
|
212
212
|
|
|
213
213
|
// package.json
|
|
214
214
|
var name = "detype";
|
|
215
|
-
var version = "0.
|
|
215
|
+
var version = "0.5.0";
|
|
216
216
|
var description = "Removes TypeScript type annotations but keeps the formatting";
|
|
217
217
|
var main = "dist/index.js";
|
|
218
218
|
var bin = "detype.js";
|
|
219
219
|
var engines = {
|
|
220
|
-
node: ">=
|
|
220
|
+
node: ">=14.19.3"
|
|
221
221
|
};
|
|
222
222
|
var scripts = {
|
|
223
|
-
|
|
224
|
-
build: "
|
|
225
|
-
|
|
223
|
+
prepack: "rimraf dist && pnpm build",
|
|
224
|
+
build: "tsup",
|
|
225
|
+
dev: "tsup --watch",
|
|
226
|
+
cq: "pnpm run test:typecheck && pnpm run test:lint && pnpm run test:prettier",
|
|
226
227
|
test: "run-p 'test:*'",
|
|
227
|
-
"test:unit": "
|
|
228
|
+
"test:unit": "vitest run",
|
|
228
229
|
"test:typecheck": "tsc -p tsconfig.json --noEmit",
|
|
229
230
|
"test:lint": "eslint src --max-warnings 0",
|
|
230
|
-
|
|
231
|
+
"test:prettier": "prettier --check --ignore-path .gitignore --ignore-unknown . '!pnpm-lock.yaml'",
|
|
232
|
+
format: "prettier . --write --ignore-path .gitignore --ignore-unknown . '!pnpm-lock.yaml'"
|
|
231
233
|
};
|
|
232
234
|
var files = [
|
|
233
235
|
"dist/**/*",
|
|
234
236
|
"index.d.ts"
|
|
235
237
|
];
|
|
236
238
|
var dependencies = {
|
|
237
|
-
"@babel/core": "^7.
|
|
238
|
-
"@babel/preset-typescript": "^7.
|
|
239
|
+
"@babel/core": "^7.18.2",
|
|
240
|
+
"@babel/preset-typescript": "^7.17.12",
|
|
239
241
|
"@vuedx/compiler-sfc": "^0.7.1",
|
|
240
|
-
"@vuedx/template-ast-types": "^0.7.
|
|
242
|
+
"@vuedx/template-ast-types": "^0.7.3",
|
|
241
243
|
"fast-glob": "^3.2.11",
|
|
242
244
|
prettier: "^2.6.2",
|
|
243
245
|
"string.prototype.replaceall": "^1.0.6"
|
|
244
246
|
};
|
|
245
247
|
var devDependencies = {
|
|
246
|
-
"@babel/traverse": "^7.
|
|
247
|
-
"@
|
|
248
|
-
"@types/
|
|
249
|
-
"@
|
|
250
|
-
"@
|
|
251
|
-
|
|
252
|
-
|
|
253
|
-
"esbuild-node-externals": "^1.4.1",
|
|
254
|
-
eslint: "^8.12.0",
|
|
255
|
-
"eslint-config-prettier": "^8.5.0",
|
|
256
|
-
"eslint-import-resolver-typescript": "^2.7.1",
|
|
257
|
-
"eslint-plugin-import": "^2.25.4",
|
|
258
|
-
"eslint-plugin-no-only-tests": "^2.6.0",
|
|
259
|
-
"eslint-plugin-only-warn": "^1.0.3",
|
|
260
|
-
"eslint-plugin-ssr-friendly": "^1.0.6",
|
|
261
|
-
jest: "^27.5.1",
|
|
248
|
+
"@babel/traverse": "^7.18.2",
|
|
249
|
+
"@cyco130/eslint-config": "^1.1.0",
|
|
250
|
+
"@types/babel__core": "^7.1.19",
|
|
251
|
+
"@types/babel__traverse": "^7.17.1",
|
|
252
|
+
"@types/node": "17.0.36",
|
|
253
|
+
"@types/prettier": "^2.6.3",
|
|
254
|
+
eslint: "^8.16.0",
|
|
262
255
|
"npm-run-all": "^4.1.5",
|
|
263
256
|
rimraf: "^3.0.2",
|
|
264
|
-
|
|
257
|
+
tsup: "^6.0.1",
|
|
258
|
+
typescript: "^4.7.2",
|
|
259
|
+
vitest: "^0.13.0"
|
|
265
260
|
};
|
|
266
261
|
var repository = {
|
|
267
262
|
type: "git",
|
|
@@ -301,7 +296,8 @@ var package_default = {
|
|
|
301
296
|
// src/cli-lib.ts
|
|
302
297
|
var { stat, mkdir } = import_fs2.default.promises;
|
|
303
298
|
async function cli(...args2) {
|
|
304
|
-
|
|
299
|
+
const [flag] = args2;
|
|
300
|
+
let [, input, output] = args2;
|
|
305
301
|
if (!flag || flag === "-h" || flag === "--help") {
|
|
306
302
|
printUsage();
|
|
307
303
|
return !!flag;
|
|
@@ -321,19 +317,19 @@ async function cli(...args2) {
|
|
|
321
317
|
printUsage();
|
|
322
318
|
return false;
|
|
323
319
|
}
|
|
324
|
-
const files2 = (await (0, import_fast_glob.default)(
|
|
320
|
+
const files2 = (await (0, import_fast_glob.default)(unixify(input + "/**/*.{ts,tsx,vue}"))).filter((file) => !file.endsWith(".d.ts"));
|
|
325
321
|
const dirs = [...new Set(files2.map((file) => import_path.default.dirname(file)))].sort();
|
|
326
|
-
await mkdir(output, { recursive: true });
|
|
322
|
+
await mkdir(import_path.default.normalize(output), { recursive: true });
|
|
327
323
|
for (const dir of dirs) {
|
|
328
324
|
const outDir = import_path.default.join(output, import_path.default.relative(input, dir));
|
|
329
325
|
if (outDir === output)
|
|
330
326
|
continue;
|
|
331
|
-
await mkdir(outDir, { recursive: true });
|
|
327
|
+
await mkdir(import_path.default.normalize(outDir), { recursive: true });
|
|
332
328
|
}
|
|
333
329
|
for (const file of files2) {
|
|
334
330
|
const inputDir = import_path.default.dirname(import_path.default.relative(input, file));
|
|
335
331
|
const outputName = inferName(file, import_path.default.join(output, inputDir));
|
|
336
|
-
removeMagic ? await removeMagicCommentsFromFile(file, outputName) : await transformFile(file, outputName);
|
|
332
|
+
removeMagic ? await removeMagicCommentsFromFile(import_path.default.normalize(file), import_path.default.normalize(outputName)) : await transformFile(import_path.default.normalize(file), import_path.default.normalize(outputName));
|
|
337
333
|
}
|
|
338
334
|
return true;
|
|
339
335
|
}
|
|
@@ -360,21 +356,21 @@ async function cli(...args2) {
|
|
|
360
356
|
}
|
|
361
357
|
const outputDir = import_path.default.dirname(output);
|
|
362
358
|
if (outputDir) {
|
|
363
|
-
await mkdir(outputDir, { recursive: true });
|
|
359
|
+
await mkdir(import_path.default.normalize(outputDir), { recursive: true });
|
|
364
360
|
}
|
|
365
|
-
removeMagic ? await removeMagicCommentsFromFile(input, output) : await transformFile(input, output);
|
|
361
|
+
removeMagic ? await removeMagicCommentsFromFile(import_path.default.normalize(input), import_path.default.normalize(output)) : await transformFile(import_path.default.normalize(input), import_path.default.normalize(output));
|
|
366
362
|
return true;
|
|
367
363
|
function inferName(input2, outputDir2) {
|
|
368
364
|
let output2;
|
|
369
365
|
const { dir, name: name2, ext } = import_path.default.parse(input2);
|
|
370
366
|
if (removeMagic) {
|
|
371
|
-
output2 = import_path.default.join(outputDir2
|
|
367
|
+
output2 = import_path.default.join(outputDir2 ?? dir, `${name2}${ext}`);
|
|
372
368
|
} else if (ext === ".ts") {
|
|
373
|
-
output2 = import_path.default.join(outputDir2
|
|
369
|
+
output2 = import_path.default.join(outputDir2 ?? dir, name2 + ".js");
|
|
374
370
|
} else if (ext === ".tsx") {
|
|
375
|
-
output2 = import_path.default.join(outputDir2
|
|
371
|
+
output2 = import_path.default.join(outputDir2 ?? dir, name2 + ".jsx");
|
|
376
372
|
} else if (ext === ".vue") {
|
|
377
|
-
output2 = import_path.default.join(outputDir2
|
|
373
|
+
output2 = import_path.default.join(outputDir2 ?? dir, name2 + ".vue");
|
|
378
374
|
} else {
|
|
379
375
|
throw new Error(`Unknwon file extension ${input2}`);
|
|
380
376
|
}
|
|
@@ -404,6 +400,9 @@ var USAGE = `Usage:
|
|
|
404
400
|
|
|
405
401
|
Print this help and exit`;
|
|
406
402
|
var VERSION = package_default.version;
|
|
403
|
+
function unixify(name2) {
|
|
404
|
+
return name2.replaceAll(import_path.default.sep, "/");
|
|
405
|
+
}
|
|
407
406
|
|
|
408
407
|
// src/cli.ts
|
|
409
408
|
var args = process.argv.slice(2);
|
package/dist/index.d.ts
ADDED
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
import { Options } from 'prettier';
|
|
2
|
+
export { Options as PrettierOptions } from 'prettier';
|
|
3
|
+
|
|
4
|
+
/**
|
|
5
|
+
* Transform TypeScript code into vanilla JavaScript without affecting the formatting
|
|
6
|
+
* @param code Source coude
|
|
7
|
+
* @param fileName File name for the source
|
|
8
|
+
* @param prettierOptions Options to pass to prettier
|
|
9
|
+
*/
|
|
10
|
+
declare function transform(code: string, fileName: string, prettierOptions?: Options | null): Promise<string>;
|
|
11
|
+
/**
|
|
12
|
+
* Removes magic comments without performing the TS to JS transform
|
|
13
|
+
* @param code Source coude
|
|
14
|
+
* @param fileName File name for the source
|
|
15
|
+
* @param prettierOptions Options to pass to prettier
|
|
16
|
+
*/
|
|
17
|
+
declare function removeMagicComments(code: string, fileName: string, prettierOptions?: Options | null): string;
|
|
18
|
+
|
|
19
|
+
/**
|
|
20
|
+
* Transform the input file and write the output to another file
|
|
21
|
+
* @param inputFileName
|
|
22
|
+
* @param outputFileName
|
|
23
|
+
*/
|
|
24
|
+
declare function transformFile(inputFileName: string, outputFileName: string): Promise<void>;
|
|
25
|
+
/**
|
|
26
|
+
* Remove magic comments from the input file and write the output to another file
|
|
27
|
+
* @param inputFileName
|
|
28
|
+
* @param outputFileName
|
|
29
|
+
*/
|
|
30
|
+
declare function removeMagicCommentsFromFile(inputFileName: string, outputFileName: string): Promise<void>;
|
|
31
|
+
|
|
32
|
+
export { removeMagicComments, removeMagicCommentsFromFile, transform, transformFile };
|
package/index.d.ts
CHANGED
|
@@ -1,47 +1 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
export { PrettierOptions };
|
|
4
|
-
|
|
5
|
-
/**
|
|
6
|
-
* Transform TypeScript code into vanilla JavaScript without affecting the formatting
|
|
7
|
-
* @param code Source coude
|
|
8
|
-
* @param fileName File name for the source
|
|
9
|
-
* @param prettierOptions Options to pass to prettier
|
|
10
|
-
*/
|
|
11
|
-
export function transform(
|
|
12
|
-
code: string,
|
|
13
|
-
fileName: string,
|
|
14
|
-
prettierOptions?: PrettierOptions | null | undefined,
|
|
15
|
-
): Promise<string>;
|
|
16
|
-
|
|
17
|
-
/**
|
|
18
|
-
* Transform the input file and write the output to another file
|
|
19
|
-
* @param inputFileName
|
|
20
|
-
* @param outputFileName
|
|
21
|
-
*/
|
|
22
|
-
export function transformFile(
|
|
23
|
-
inputFileName: string,
|
|
24
|
-
outputFileName: string,
|
|
25
|
-
): Promise<void>;
|
|
26
|
-
|
|
27
|
-
/**
|
|
28
|
-
* Removes magic comments without performing the TS to JS transform
|
|
29
|
-
* @param code Source coude
|
|
30
|
-
* @param fileName File name for the source
|
|
31
|
-
* @param prettierOptions Options to pass to prettier
|
|
32
|
-
*/
|
|
33
|
-
export function removeMagicComments(
|
|
34
|
-
code: string,
|
|
35
|
-
fileName: string,
|
|
36
|
-
prettierOptions?: PrettierOptions | null,
|
|
37
|
-
): string;
|
|
38
|
-
|
|
39
|
-
/**
|
|
40
|
-
* Remove magic comments from the input file and write the output to another file
|
|
41
|
-
* @param inputFileName
|
|
42
|
-
* @param outputFileName
|
|
43
|
-
*/
|
|
44
|
-
export function removeMagicCommentsFromFile(
|
|
45
|
-
inputFileName: string,
|
|
46
|
-
outputFileName: string,
|
|
47
|
-
): Promise<void>;
|
|
1
|
+
export * from "./dist";
|
package/package.json
CHANGED
|
@@ -1,45 +1,38 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "detype",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.5.0",
|
|
4
4
|
"description": "Removes TypeScript type annotations but keeps the formatting",
|
|
5
5
|
"main": "dist/index.js",
|
|
6
6
|
"bin": "detype.js",
|
|
7
7
|
"engines": {
|
|
8
|
-
"node": ">=
|
|
8
|
+
"node": ">=14.19.3"
|
|
9
9
|
},
|
|
10
10
|
"files": [
|
|
11
11
|
"dist/**/*",
|
|
12
12
|
"index.d.ts"
|
|
13
13
|
],
|
|
14
14
|
"dependencies": {
|
|
15
|
-
"@babel/core": "^7.
|
|
16
|
-
"@babel/preset-typescript": "^7.
|
|
15
|
+
"@babel/core": "^7.18.2",
|
|
16
|
+
"@babel/preset-typescript": "^7.17.12",
|
|
17
17
|
"@vuedx/compiler-sfc": "^0.7.1",
|
|
18
|
-
"@vuedx/template-ast-types": "^0.7.
|
|
18
|
+
"@vuedx/template-ast-types": "^0.7.3",
|
|
19
19
|
"fast-glob": "^3.2.11",
|
|
20
20
|
"prettier": "^2.6.2",
|
|
21
21
|
"string.prototype.replaceall": "^1.0.6"
|
|
22
22
|
},
|
|
23
23
|
"devDependencies": {
|
|
24
|
-
"@babel/traverse": "^7.
|
|
25
|
-
"@
|
|
26
|
-
"@types/
|
|
27
|
-
"@
|
|
28
|
-
"@
|
|
29
|
-
"
|
|
30
|
-
"
|
|
31
|
-
"esbuild-node-externals": "^1.4.1",
|
|
32
|
-
"eslint": "^8.12.0",
|
|
33
|
-
"eslint-config-prettier": "^8.5.0",
|
|
34
|
-
"eslint-import-resolver-typescript": "^2.7.1",
|
|
35
|
-
"eslint-plugin-import": "^2.25.4",
|
|
36
|
-
"eslint-plugin-no-only-tests": "^2.6.0",
|
|
37
|
-
"eslint-plugin-only-warn": "^1.0.3",
|
|
38
|
-
"eslint-plugin-ssr-friendly": "^1.0.6",
|
|
39
|
-
"jest": "^27.5.1",
|
|
24
|
+
"@babel/traverse": "^7.18.2",
|
|
25
|
+
"@cyco130/eslint-config": "^1.1.0",
|
|
26
|
+
"@types/babel__core": "^7.1.19",
|
|
27
|
+
"@types/babel__traverse": "^7.17.1",
|
|
28
|
+
"@types/node": "17.0.36",
|
|
29
|
+
"@types/prettier": "^2.6.3",
|
|
30
|
+
"eslint": "^8.16.0",
|
|
40
31
|
"npm-run-all": "^4.1.5",
|
|
41
32
|
"rimraf": "^3.0.2",
|
|
42
|
-
"
|
|
33
|
+
"tsup": "^6.0.1",
|
|
34
|
+
"typescript": "^4.7.2",
|
|
35
|
+
"vitest": "^0.13.0"
|
|
43
36
|
},
|
|
44
37
|
"repository": {
|
|
45
38
|
"type": "git",
|
|
@@ -58,13 +51,14 @@
|
|
|
58
51
|
},
|
|
59
52
|
"homepage": "https://github.com/cyco130/detype#readme",
|
|
60
53
|
"scripts": {
|
|
61
|
-
"build": "
|
|
62
|
-
"
|
|
54
|
+
"build": "tsup",
|
|
55
|
+
"dev": "tsup --watch",
|
|
56
|
+
"cq": "pnpm run test:typecheck && pnpm run test:lint && pnpm run test:prettier",
|
|
63
57
|
"test": "run-p 'test:*'",
|
|
64
|
-
"test:unit": "
|
|
58
|
+
"test:unit": "vitest run",
|
|
65
59
|
"test:typecheck": "tsc -p tsconfig.json --noEmit",
|
|
66
60
|
"test:lint": "eslint src --max-warnings 0",
|
|
67
|
-
"
|
|
68
|
-
|
|
69
|
-
|
|
61
|
+
"test:prettier": "prettier --check --ignore-path .gitignore --ignore-unknown . '!pnpm-lock.yaml'",
|
|
62
|
+
"format": "prettier . --write --ignore-path .gitignore --ignore-unknown . '!pnpm-lock.yaml'"
|
|
63
|
+
}
|
|
70
64
|
}
|