@vercel/python-analysis 0.2.0 → 0.3.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 (41) hide show
  1. package/dist/index.cjs +1999 -0
  2. package/dist/index.d.ts +1 -0
  3. package/dist/index.js +1896 -71
  4. package/dist/semantic/entrypoints.d.ts +28 -0
  5. package/dist/semantic/load.d.ts +4 -0
  6. package/dist/wasm/interfaces/wasi-cli-environment.d.ts +2 -0
  7. package/dist/wasm/interfaces/wasi-cli-exit.d.ts +3 -0
  8. package/dist/wasm/interfaces/wasi-cli-stderr.d.ts +3 -0
  9. package/dist/wasm/interfaces/wasi-io-error.d.ts +9 -0
  10. package/dist/wasm/interfaces/wasi-io-streams.d.ts +18 -0
  11. package/dist/wasm/vercel_python_analysis.core.wasm +0 -0
  12. package/dist/wasm/vercel_python_analysis.core2.wasm +0 -0
  13. package/dist/wasm/vercel_python_analysis.core3.wasm +0 -0
  14. package/dist/wasm/vercel_python_analysis.d.ts +47 -0
  15. package/dist/wasm/vercel_python_analysis.js +1106 -0
  16. package/package.json +20 -4
  17. package/dist/manifest/package.js +0 -422
  18. package/dist/manifest/pep440.js +0 -63
  19. package/dist/manifest/pep508.js +0 -70
  20. package/dist/manifest/pipfile/schema.js +0 -44
  21. package/dist/manifest/pipfile/schema.zod.js +0 -97
  22. package/dist/manifest/pipfile/types.js +0 -16
  23. package/dist/manifest/pipfile-parser.js +0 -262
  24. package/dist/manifest/pyproject/schema.js +0 -56
  25. package/dist/manifest/pyproject/schema.zod.js +0 -94
  26. package/dist/manifest/pyproject/types.js +0 -16
  27. package/dist/manifest/python-selector.js +0 -185
  28. package/dist/manifest/python-specifiers.js +0 -156
  29. package/dist/manifest/requirement/schema.js +0 -35
  30. package/dist/manifest/requirement/schema.zod.js +0 -49
  31. package/dist/manifest/requirement/types.js +0 -16
  32. package/dist/manifest/requirements-txt-parser.js +0 -400
  33. package/dist/manifest/uv-config/schema.js +0 -35
  34. package/dist/manifest/uv-config/schema.zod.js +0 -48
  35. package/dist/manifest/uv-config/types.js +0 -16
  36. package/dist/manifest/uv-python-version-parser.js +0 -268
  37. package/dist/types.js +0 -16
  38. package/dist/util/config.js +0 -100
  39. package/dist/util/error.js +0 -54
  40. package/dist/util/fs.js +0 -75
  41. package/dist/util/type.js +0 -30
@@ -0,0 +1,28 @@
1
+ /**
2
+ * Semantic analyzer for detecting application entrypoint patterns in Python
3
+ * source code.
4
+ */
5
+ /**
6
+ * Check if Python source code contains or exports:
7
+ * - A top-level 'app' callable (e.g., Flask, FastAPI, Sanic apps)
8
+ * - A top-level 'handler' class (e.g., BaseHTTPRequestHandler subclass)
9
+ *
10
+ * This function uses a WASM-based Python parser (ruff_python_ast) for
11
+ * accurate AST analysis without requiring a Python runtime.
12
+ *
13
+ * @param source - The Python source code to analyze
14
+ * @returns Promise that resolves to true if an app or handler is found, false otherwise.
15
+ * Returns false for invalid Python syntax.
16
+ *
17
+ * @example
18
+ * ```typescript
19
+ * import { containsAppOrHandler } from '@vercel/python-analysis';
20
+ *
21
+ * const hasApp = await containsAppOrHandler(`
22
+ * from flask import Flask
23
+ * app = Flask(__name__)
24
+ * `);
25
+ * console.log(hasApp); // true
26
+ * ```
27
+ */
28
+ export declare function containsAppOrHandler(source: string): Promise<boolean>;
@@ -0,0 +1,4 @@
1
+ type ModuleType = typeof import('#wasm/vercel_python_analysis.js');
2
+ type RootType = Awaited<ReturnType<ModuleType['instantiate']>>;
3
+ export declare function importWasmModule(): Promise<RootType>;
4
+ export {};
@@ -0,0 +1,2 @@
1
+ /** @module Interface wasi:cli/environment@0.2.6 **/
2
+ export function getEnvironment(): Array<[string, string]>;
@@ -0,0 +1,3 @@
1
+ /** @module Interface wasi:cli/exit@0.2.6 **/
2
+ export function exit(status: Result<void, void>): void;
3
+ export type Result<T, E> = { tag: 'ok', val: T } | { tag: 'err', val: E };
@@ -0,0 +1,3 @@
1
+ /** @module Interface wasi:cli/stderr@0.2.6 **/
2
+ export function getStderr(): OutputStream;
3
+ export type OutputStream = import('./wasi-io-streams.js').OutputStream;
@@ -0,0 +1,9 @@
1
+ /** @module Interface wasi:io/error@0.2.6 **/
2
+
3
+ export class Error {
4
+ /**
5
+ * This type does not have a public constructor.
6
+ */
7
+ private constructor();
8
+ toDebugString(): string;
9
+ }
@@ -0,0 +1,18 @@
1
+ /** @module Interface wasi:io/streams@0.2.6 **/
2
+ export type Error = import('./wasi-io-error.js').Error;
3
+ export type StreamError = StreamErrorLastOperationFailed | StreamErrorClosed;
4
+ export interface StreamErrorLastOperationFailed {
5
+ tag: 'last-operation-failed',
6
+ val: Error,
7
+ }
8
+ export interface StreamErrorClosed {
9
+ tag: 'closed',
10
+ }
11
+
12
+ export class OutputStream {
13
+ /**
14
+ * This type does not have a public constructor.
15
+ */
16
+ private constructor();
17
+ blockingWriteAndFlush(contents: Uint8Array): void;
18
+ }
@@ -0,0 +1,47 @@
1
+ // world root:component/root
2
+ import type * as WasiCliEnvironment from './interfaces/wasi-cli-environment.js'; // wasi:cli/environment@0.2.6
3
+ import type * as WasiCliExit from './interfaces/wasi-cli-exit.js'; // wasi:cli/exit@0.2.6
4
+ import type * as WasiCliStderr from './interfaces/wasi-cli-stderr.js'; // wasi:cli/stderr@0.2.6
5
+ import type * as WasiIoError from './interfaces/wasi-io-error.js'; // wasi:io/error@0.2.6
6
+ import type * as WasiIoStreams from './interfaces/wasi-io-streams.js'; // wasi:io/streams@0.2.6
7
+ export interface ImportObject {
8
+ 'wasi:cli/environment@0.2.6': typeof WasiCliEnvironment,
9
+ 'wasi:cli/exit@0.2.6': typeof WasiCliExit,
10
+ 'wasi:cli/stderr@0.2.6': typeof WasiCliStderr,
11
+ 'wasi:io/error@0.2.6': typeof WasiIoError,
12
+ 'wasi:io/streams@0.2.6': typeof WasiIoStreams,
13
+ }
14
+ export interface Root {
15
+ containsAppOrHandler(source: string): boolean,
16
+ }
17
+
18
+ /**
19
+ * Instantiates this component with the provided imports and
20
+ * returns a map of all the exports of the component.
21
+ *
22
+ * This function is intended to be similar to the
23
+ * `WebAssembly.instantiate` function. The second `imports`
24
+ * argument is the "import object" for wasm, except here it
25
+ * uses component-model-layer types instead of core wasm
26
+ * integers/numbers/etc.
27
+ *
28
+ * The first argument to this function, `getCoreModule`, is
29
+ * used to compile core wasm modules within the component.
30
+ * Components are composed of core wasm modules and this callback
31
+ * will be invoked per core wasm module. The caller of this
32
+ * function is responsible for reading the core wasm module
33
+ * identified by `path` and returning its compiled
34
+ * `WebAssembly.Module` object. This would use `compileStreaming`
35
+ * on the web, for example.
36
+ */
37
+ export function instantiate(
38
+ getCoreModule: (path: string) => WebAssembly.Module,
39
+ imports: ImportObject,
40
+ instantiateCore?: (module: WebAssembly.Module, imports: Record<string, any>) => WebAssembly.Instance
41
+ ): Root;
42
+ export function instantiate(
43
+ getCoreModule: (path: string) => WebAssembly.Module | Promise<WebAssembly.Module>,
44
+ imports: ImportObject,
45
+ instantiateCore?: (module: WebAssembly.Module, imports: Record<string, any>) => WebAssembly.Instance | Promise<WebAssembly.Instance>
46
+ ): Root | Promise<Root>;
47
+