python2ts 0.1.0 → 0.2.1

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.
Files changed (40) hide show
  1. package/LICENSE +21 -0
  2. package/README.md +22 -92
  3. package/dist/chunk-VYG6GDWU.js +4482 -0
  4. package/dist/chunk-VYG6GDWU.js.map +1 -0
  5. package/dist/cli/index.js +1 -2
  6. package/dist/cli/index.js.map +1 -1
  7. package/dist/index.d.ts +0 -1
  8. package/dist/index.js +1 -6
  9. package/dist/index.js.map +1 -1
  10. package/package.json +29 -14
  11. package/dist/acorn-CDFV7HXL.js +0 -3131
  12. package/dist/acorn-CDFV7HXL.js.map +0 -1
  13. package/dist/angular-PCJAXZFD.js +0 -3071
  14. package/dist/angular-PCJAXZFD.js.map +0 -1
  15. package/dist/babel-O6RKFHDQ.js +0 -7297
  16. package/dist/babel-O6RKFHDQ.js.map +0 -1
  17. package/dist/chunk-DTI6R2GT.js +0 -23942
  18. package/dist/chunk-DTI6R2GT.js.map +0 -1
  19. package/dist/chunk-PZ5AY32C.js +0 -10
  20. package/dist/chunk-PZ5AY32C.js.map +0 -1
  21. package/dist/estree-467CT4RF.js +0 -4613
  22. package/dist/estree-467CT4RF.js.map +0 -1
  23. package/dist/flow-FCFYGKSM.js +0 -27547
  24. package/dist/flow-FCFYGKSM.js.map +0 -1
  25. package/dist/glimmer-P46N72G3.js +0 -2895
  26. package/dist/glimmer-P46N72G3.js.map +0 -1
  27. package/dist/graphql-TFOZJU7B.js +0 -1267
  28. package/dist/graphql-TFOZJU7B.js.map +0 -1
  29. package/dist/html-KZKNLN3R.js +0 -2934
  30. package/dist/html-KZKNLN3R.js.map +0 -1
  31. package/dist/markdown-BS2B5AKD.js +0 -3554
  32. package/dist/markdown-BS2B5AKD.js.map +0 -1
  33. package/dist/meriyah-W6HUPGCY.js +0 -2685
  34. package/dist/meriyah-W6HUPGCY.js.map +0 -1
  35. package/dist/postcss-LMJBCD2Q.js +0 -5081
  36. package/dist/postcss-LMJBCD2Q.js.map +0 -1
  37. package/dist/typescript-Y5EPKFX5.js +0 -13204
  38. package/dist/typescript-Y5EPKFX5.js.map +0 -1
  39. package/dist/yaml-ZNP3H3BX.js +0 -4225
  40. package/dist/yaml-ZNP3H3BX.js.map +0 -1
package/dist/cli/index.js CHANGED
@@ -1,8 +1,7 @@
1
1
  #!/usr/bin/env node
2
2
  import {
3
3
  transpileAsync
4
- } from "../chunk-DTI6R2GT.js";
5
- import "../chunk-PZ5AY32C.js";
4
+ } from "../chunk-VYG6GDWU.js";
6
5
 
7
6
  // src/cli/index.ts
8
7
  import { parseArgs } from "util";
@@ -1 +1 @@
1
- {"version":3,"sources":["../../src/cli/index.ts"],"sourcesContent":["#!/usr/bin/env node\nimport { parseArgs } from \"node:util\"\nimport { readFile, writeFile } from \"node:fs/promises\"\nimport { createInterface } from \"node:readline\"\nimport { transpileAsync, type GeneratorOptions } from \"../generator/index.js\"\n\nconst VERSION = \"0.1.0\"\n\nconst HELP = `\npython2ts - Transpile Python code to TypeScript\n\nUsage:\n python2ts [options] [file]\n\nArguments:\n file Input Python file (reads from stdin if omitted)\n\nOptions:\n -o, --output <file> Write output to file (prints to stdout if omitted)\n --no-runtime Don't include runtime import statement\n --runtime-path <path> Custom runtime import path (default: pythonlib)\n -h, --help Show this help message\n -v, --version Show version number\n\nExamples:\n python2ts input.py Transpile and print to stdout\n python2ts input.py -o output.ts Transpile to file\n cat input.py | python2ts Read from stdin\n python2ts input.py --no-runtime Transpile without runtime import\n`.trim()\n\nasync function readStdin(): Promise<string> {\n const lines: string[] = []\n const rl = createInterface({\n input: process.stdin,\n crlfDelay: Infinity\n })\n\n for await (const line of rl) {\n lines.push(line)\n }\n\n return lines.join(\"\\n\")\n}\n\nasync function main(): Promise<void> {\n const { values, positionals } = parseArgs({\n options: {\n output: { type: \"string\", short: \"o\" },\n \"no-runtime\": { type: \"boolean\", default: false },\n \"runtime-path\": { type: \"string\" },\n help: { type: \"boolean\", short: \"h\", default: false },\n version: { type: \"boolean\", short: \"v\", default: false }\n },\n allowPositionals: true\n })\n\n if (values.help) {\n console.log(HELP)\n process.exit(0)\n }\n\n if (values.version) {\n console.log(VERSION)\n process.exit(0)\n }\n\n // Read input\n let pythonCode: string\n const inputFile = positionals[0]\n\n if (inputFile) {\n try {\n pythonCode = await readFile(inputFile, \"utf-8\")\n } catch (error) {\n const err = error as NodeJS.ErrnoException\n if (err.code === \"ENOENT\") {\n console.error(`Error: File not found: ${inputFile}`)\n } else {\n console.error(`Error reading file: ${err.message}`)\n }\n process.exit(1)\n }\n } else {\n // Read from stdin\n if (process.stdin.isTTY) {\n console.error(\"Error: No input file specified and stdin is a terminal.\")\n console.error(\"Usage: python2ts <file> or cat file.py | python2ts\")\n process.exit(1)\n }\n pythonCode = await readStdin()\n }\n\n // Transpile (with Prettier formatting)\n let tsCode: string\n try {\n const options: GeneratorOptions = {\n includeRuntime: !values[\"no-runtime\"]\n }\n if (values[\"runtime-path\"]) {\n options.runtimeImportPath = values[\"runtime-path\"]\n }\n tsCode = await transpileAsync(pythonCode, options)\n } catch (error) {\n const err = error as Error\n console.error(`Transpilation error: ${err.message}`)\n process.exit(1)\n }\n\n // Write output\n const outputFile = values.output\n if (outputFile) {\n try {\n await writeFile(outputFile, tsCode, \"utf-8\")\n } catch (error) {\n const err = error as Error\n console.error(`Error writing file: ${err.message}`)\n process.exit(1)\n }\n } else {\n console.log(tsCode)\n }\n}\n\nmain().catch((error: unknown) => {\n console.error(`Unexpected error: ${String(error)}`)\n process.exit(1)\n})\n"],"mappings":";;;;;;;AACA,SAAS,iBAAiB;AAC1B,SAAS,UAAU,iBAAiB;AACpC,SAAS,uBAAuB;AAGhC,IAAM,UAAU;AAEhB,IAAM,OAAO;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,EAqBX,KAAK;AAEP,eAA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CAAC;AAAA,IAChB;AACA,iBAAa,MAAM,UAAU;AAAA,EAC/B;AAGA,MAAI;AACJ,MAAI;AACF,UAAM,UAA4B;AAAA,MAChC,gBAAgB,CAAC,OAAO,YAAY;AAAA,IACtC;AACA,QAAI,OAAO,cAAc,GAAG;AAC1B,cAAQ,oBAAoB,OAAO,cAAc;AAAA,IACnD;AACA,aAAS,MAAM,eAAe,YAAY,OAAO;AAAA,EACnD,SAAS,OAAO;AACd,UAAM,MAAM;AACZ,YAAQ,MAAM,wBAAwB,IAAI,OAAO,EAAE;AACnD,YAAQ,KAAK,CAAC;AAAA,EAChB;AAGA,QAAM,aAAa,OAAO;AAC1B,MAAI,YAAY;AACd,QAAI;AACF,YAAM,UAAU,YAAY,QAAQ,OAAO;AAAA,IAC7C,SAAS,OAAO;AACd,YAAM,MAAM;AACZ,cAAQ,MAAM,uBAAuB,IAAI,OAAO,EAAE;AAClD,cAAQ,KAAK,CAAC;AAAA,IAChB;AAAA,EACF,OAAO;AACL,YAAQ,IAAI,MAAM;AAAA,EACpB;AACF;AAEA,KAAK,EAAE,MAAM,CAAC,UAAmB;AAC/B,UAAQ,MAAM,qBAAqB,OAAO,KAAK,CAAC,EAAE;AAClD,UAAQ,KAAK,CAAC;AAChB,CAAC;","names":[]}
1
+ {"version":3,"sources":["../../src/cli/index.ts"],"sourcesContent":["#!/usr/bin/env node\nimport { parseArgs } from \"node:util\"\nimport { readFile, writeFile } from \"node:fs/promises\"\nimport { createInterface } from \"node:readline\"\nimport { transpileAsync, type GeneratorOptions } from \"../generator/index.js\"\n\nconst VERSION = \"0.1.0\"\n\nconst HELP = `\npython2ts - Transpile Python code to TypeScript\n\nUsage:\n python2ts [options] [file]\n\nArguments:\n file Input Python file (reads from stdin if omitted)\n\nOptions:\n -o, --output <file> Write output to file (prints to stdout if omitted)\n --no-runtime Don't include runtime import statement\n --runtime-path <path> Custom runtime import path (default: pythonlib)\n -h, --help Show this help message\n -v, --version Show version number\n\nExamples:\n python2ts input.py Transpile and print to stdout\n python2ts input.py -o output.ts Transpile to file\n cat input.py | python2ts Read from stdin\n python2ts input.py --no-runtime Transpile without runtime import\n`.trim()\n\nasync function readStdin(): Promise<string> {\n const lines: string[] = []\n const rl = createInterface({\n input: process.stdin,\n crlfDelay: Infinity\n })\n\n for await (const line of rl) {\n lines.push(line)\n }\n\n return lines.join(\"\\n\")\n}\n\nasync function main(): Promise<void> {\n const { values, positionals } = parseArgs({\n options: {\n output: { type: \"string\", short: \"o\" },\n \"no-runtime\": { type: \"boolean\", default: false },\n \"runtime-path\": { type: \"string\" },\n help: { type: \"boolean\", short: \"h\", default: false },\n version: { type: \"boolean\", short: \"v\", default: false }\n },\n allowPositionals: true\n })\n\n if (values.help) {\n console.log(HELP)\n process.exit(0)\n }\n\n if (values.version) {\n console.log(VERSION)\n process.exit(0)\n }\n\n // Read input\n let pythonCode: string\n const inputFile = positionals[0]\n\n if (inputFile) {\n try {\n pythonCode = await readFile(inputFile, \"utf-8\")\n } catch (error) {\n const err = error as NodeJS.ErrnoException\n if (err.code === \"ENOENT\") {\n console.error(`Error: File not found: ${inputFile}`)\n } else {\n console.error(`Error reading file: ${err.message}`)\n }\n process.exit(1)\n }\n } else {\n // Read from stdin\n if (process.stdin.isTTY) {\n console.error(\"Error: No input file specified and stdin is a terminal.\")\n console.error(\"Usage: python2ts <file> or cat file.py | python2ts\")\n process.exit(1)\n }\n pythonCode = await readStdin()\n }\n\n // Transpile (with Prettier formatting)\n let tsCode: string\n try {\n const options: GeneratorOptions = {\n includeRuntime: !values[\"no-runtime\"]\n }\n if (values[\"runtime-path\"]) {\n options.runtimeImportPath = values[\"runtime-path\"]\n }\n tsCode = await transpileAsync(pythonCode, options)\n } catch (error) {\n const err = error as Error\n console.error(`Transpilation error: ${err.message}`)\n process.exit(1)\n }\n\n // Write output\n const outputFile = values.output\n if (outputFile) {\n try {\n await writeFile(outputFile, tsCode, \"utf-8\")\n } catch (error) {\n const err = error as Error\n console.error(`Error writing file: ${err.message}`)\n process.exit(1)\n }\n } else {\n console.log(tsCode)\n }\n}\n\nmain().catch((error: unknown) => {\n console.error(`Unexpected error: ${String(error)}`)\n process.exit(1)\n})\n"],"mappings":";;;;;;AACA,SAAS,iBAAiB;AAC1B,SAAS,UAAU,iBAAiB;AACpC,SAAS,uBAAuB;AAGhC,IAAM,UAAU;AAEhB,IAAM,OAAO;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,EAqBX,KAAK;AAEP,eAAe,YAA6B;AAC1C,QAAM,QAAkB,CAAC;AACzB,QAAM,KAAK,gBAAgB;AAAA,IACzB,OAAO,QAAQ;AAAA,IACf,WAAW;AAAA,EACb,CAAC;AAED,mBAAiB,QAAQ,IAAI;AAC3B,UAAM,KAAK,IAAI;AAAA,EACjB;AAEA,SAAO,MAAM,KAAK,IAAI;AACxB;AAEA,eAAe,OAAsB;AACnC,QAAM,EAAE,QAAQ,YAAY,IAAI,UAAU;AAAA,IACxC,SAAS;AAAA,MACP,QAAQ,EAAE,MAAM,UAAU,OAAO,IAAI;AAAA,MACrC,cAAc,EAAE,MAAM,WAAW,SAAS,MAAM;AAAA,MAChD,gBAAgB,EAAE,MAAM,SAAS;AAAA,MACjC,MAAM,EAAE,MAAM,WAAW,OAAO,KAAK,SAAS,MAAM;AAAA,MACpD,SAAS,EAAE,MAAM,WAAW,OAAO,KAAK,SAAS,MAAM;AAAA,IACzD;AAAA,IACA,kBAAkB;AAAA,EACpB,CAAC;AAED,MAAI,OAAO,MAAM;AACf,YAAQ,IAAI,IAAI;AAChB,YAAQ,KAAK,CAAC;AAAA,EAChB;AAEA,MAAI,OAAO,SAAS;AAClB,YAAQ,IAAI,OAAO;AACnB,YAAQ,KAAK,CAAC;AAAA,EAChB;AAGA,MAAI;AACJ,QAAM,YAAY,YAAY,CAAC;AAE/B,MAAI,WAAW;AACb,QAAI;AACF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} from '@lezer/common';
2
- export { py } from 'pythonlib';
3
2
 
4
3
  interface ParseResult {
5
4
  tree: Tree;
package/dist/index.js CHANGED
@@ -12,11 +12,7 @@ import {
12
12
  transpile,
13
13
  transpileAsync,
14
14
  walkTree
15
- } from "./chunk-DTI6R2GT.js";
16
- import "./chunk-PZ5AY32C.js";
17
-
18
- // src/index.ts
19
- import { py } from "pythonlib";
15
+ } from "./chunk-VYG6GDWU.js";
20
16
  export {
21
17
  debugTree,
22
18
  formatCode,
@@ -27,7 +23,6 @@ export {
27
23
  getChildrenByType,
28
24
  getNodeText,
29
25
  parse,
30
- py,
31
26
  transform,
32
27
  transpile,
33
28
  transpileAsync,
package/dist/index.js.map CHANGED
@@ -1 +1 @@
1
- {"version":3,"sources":["../src/index.ts"],"sourcesContent":["export {\n parse,\n debugTree,\n getNodeText,\n getChildren,\n getChildByType,\n getChildrenByType,\n walkTree\n} from \"./parser/index.js\"\nexport type { ParseResult, NodeVisitor, NodeType } from \"./parser/index.js\"\n\nexport { transform, type TransformResult, type TransformContext } from \"./transformer/index.js\"\n\nexport {\n generate,\n generateAsync,\n transpile,\n transpileAsync,\n formatCode,\n type GeneratorOptions,\n type GeneratedCode\n} from \"./generator/index.js\"\n\n// Re-export pythonlib runtime for convenience\nexport { py } from \"pythonlib\"\n"],"mappings":";;;;;;;;;;;;;;;;;;AAwBA,SAAS,UAAU;","names":[]}
1
+ {"version":3,"sources":[],"sourcesContent":[],"mappings":"","names":[]}
package/package.json CHANGED
@@ -1,12 +1,20 @@
1
1
  {
2
2
  "name": "python2ts",
3
- "version": "0.1.0",
4
- "description": "AST-based Python to TypeScript transpiler",
3
+ "version": "0.2.1",
4
+ "description": "AST-based Python to TypeScript transpiler. Convert Python code to clean, idiomatic TypeScript with full type preservation.",
5
+ "homepage": "https://sebastian-software.github.io/python2ts/",
5
6
  "repository": {
6
7
  "type": "git",
7
8
  "url": "https://github.com/sebastian-software/python2ts.git",
8
9
  "directory": "packages/python2ts"
9
10
  },
11
+ "bugs": {
12
+ "url": "https://github.com/sebastian-software/python2ts/issues"
13
+ },
14
+ "funding": {
15
+ "type": "github",
16
+ "url": "https://github.com/sponsors/sebastian-software"
17
+ },
10
18
  "type": "module",
11
19
  "main": "dist/index.js",
12
20
  "types": "dist/index.d.ts",
@@ -23,30 +31,37 @@
23
31
  "dist",
24
32
  "README.md"
25
33
  ],
26
- "scripts": {
27
- "build": "tsup",
28
- "dev": "tsup --watch",
29
- "typecheck": "tsc --noEmit"
30
- },
31
34
  "keywords": [
32
35
  "python",
33
36
  "typescript",
34
37
  "transpiler",
38
+ "compiler",
35
39
  "ast",
36
- "converter"
40
+ "converter",
41
+ "code-generation",
42
+ "type-inference",
43
+ "migration",
44
+ "ai",
45
+ "machine-learning"
37
46
  ],
38
47
  "author": "Sebastian Software GmbH",
39
48
  "license": "MIT",
40
49
  "dependencies": {
41
- "@lezer/common": "^1.2.0",
42
- "@lezer/python": "^1.1.0",
43
- "pythonlib": "workspace:*"
50
+ "@lezer/common": "^1.5.0",
51
+ "@lezer/python": "^1.1.18",
52
+ "prettier": "^3.8.0",
53
+ "pythonlib": "0.2.1"
44
54
  },
45
55
  "devDependencies": {
46
- "tsup": "^8.3.0",
47
- "typescript": "^5.6.0"
56
+ "tsup": "^8.5.1",
57
+ "typescript": "^5.9.3"
48
58
  },
49
59
  "engines": {
50
60
  "node": ">=22.0.0"
61
+ },
62
+ "scripts": {
63
+ "build": "tsup",
64
+ "dev": "tsup --watch",
65
+ "typecheck": "tsc --noEmit"
51
66
  }
52
- }
67
+ }