@vercel/python-analysis 0.2.0 → 0.3.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/dist/index.d.ts +1 -0
- package/dist/index.js +3 -0
- package/dist/semantic/entrypoints.d.ts +28 -0
- package/dist/semantic/entrypoints.js +32 -0
- package/dist/semantic/load.d.ts +4 -0
- package/dist/semantic/load.js +66 -0
- package/dist/wasm/interfaces/wasi-cli-environment.d.ts +2 -0
- package/dist/wasm/interfaces/wasi-cli-exit.d.ts +3 -0
- package/dist/wasm/interfaces/wasi-cli-stderr.d.ts +3 -0
- package/dist/wasm/interfaces/wasi-io-error.d.ts +9 -0
- package/dist/wasm/interfaces/wasi-io-streams.d.ts +18 -0
- package/dist/wasm/vercel_python_analysis.core.wasm +0 -0
- package/dist/wasm/vercel_python_analysis.core2.wasm +0 -0
- package/dist/wasm/vercel_python_analysis.core3.wasm +0 -0
- package/dist/wasm/vercel_python_analysis.d.ts +47 -0
- package/dist/wasm/vercel_python_analysis.js +1106 -0
- package/package.json +9 -3
package/dist/index.d.ts
CHANGED
|
@@ -6,6 +6,7 @@
|
|
|
6
6
|
*
|
|
7
7
|
* @module @vercel/python-analysis
|
|
8
8
|
*/
|
|
9
|
+
export { containsAppOrHandler } from './semantic/entrypoints';
|
|
9
10
|
export type { PythonConfig, PythonConfigs, PythonManifest, PythonManifestOrigin, PythonPackage, PythonVersionConfig, } from './manifest/package';
|
|
10
11
|
export { discoverPythonPackage, PythonConfigKind, PythonManifestConvertedKind, PythonManifestKind, } from './manifest/package';
|
|
11
12
|
export type { PythonSelectionResult } from './manifest/python-selector';
|
package/dist/index.js
CHANGED
|
@@ -53,10 +53,12 @@ __export(src_exports, {
|
|
|
53
53
|
UvConfigSchema: () => import_schema2.UvConfigSchema,
|
|
54
54
|
UvConfigWorkspaceSchema: () => import_schema2.UvConfigWorkspaceSchema,
|
|
55
55
|
UvIndexEntrySchema: () => import_schema2.UvIndexEntrySchema,
|
|
56
|
+
containsAppOrHandler: () => import_entrypoints.containsAppOrHandler,
|
|
56
57
|
discoverPythonPackage: () => import_package.discoverPythonPackage,
|
|
57
58
|
selectPython: () => import_python_selector.selectPython
|
|
58
59
|
});
|
|
59
60
|
module.exports = __toCommonJS(src_exports);
|
|
61
|
+
var import_entrypoints = require("./semantic/entrypoints");
|
|
60
62
|
var import_package = require("./manifest/package");
|
|
61
63
|
var import_python_selector = require("./manifest/python-selector");
|
|
62
64
|
var import_error = require("./util/error");
|
|
@@ -102,6 +104,7 @@ var import_python_specifiers = require("./manifest/python-specifiers");
|
|
|
102
104
|
UvConfigSchema,
|
|
103
105
|
UvConfigWorkspaceSchema,
|
|
104
106
|
UvIndexEntrySchema,
|
|
107
|
+
containsAppOrHandler,
|
|
105
108
|
discoverPythonPackage,
|
|
106
109
|
selectPython
|
|
107
110
|
});
|
|
@@ -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,32 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __defProp = Object.defineProperty;
|
|
3
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
4
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
5
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
6
|
+
var __export = (target, all) => {
|
|
7
|
+
for (var name in all)
|
|
8
|
+
__defProp(target, name, { get: all[name], enumerable: true });
|
|
9
|
+
};
|
|
10
|
+
var __copyProps = (to, from, except, desc) => {
|
|
11
|
+
if (from && typeof from === "object" || typeof from === "function") {
|
|
12
|
+
for (let key of __getOwnPropNames(from))
|
|
13
|
+
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
14
|
+
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
15
|
+
}
|
|
16
|
+
return to;
|
|
17
|
+
};
|
|
18
|
+
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
19
|
+
var entrypoints_exports = {};
|
|
20
|
+
__export(entrypoints_exports, {
|
|
21
|
+
containsAppOrHandler: () => containsAppOrHandler
|
|
22
|
+
});
|
|
23
|
+
module.exports = __toCommonJS(entrypoints_exports);
|
|
24
|
+
var import_load = require("./load");
|
|
25
|
+
async function containsAppOrHandler(source) {
|
|
26
|
+
const mod = await (0, import_load.importWasmModule)();
|
|
27
|
+
return mod.containsAppOrHandler(source);
|
|
28
|
+
}
|
|
29
|
+
// Annotate the CommonJS export names for ESM import in node:
|
|
30
|
+
0 && (module.exports = {
|
|
31
|
+
containsAppOrHandler
|
|
32
|
+
});
|
|
@@ -0,0 +1,66 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __create = Object.create;
|
|
3
|
+
var __defProp = Object.defineProperty;
|
|
4
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
5
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
6
|
+
var __getProtoOf = Object.getPrototypeOf;
|
|
7
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
8
|
+
var __export = (target, all) => {
|
|
9
|
+
for (var name in all)
|
|
10
|
+
__defProp(target, name, { get: all[name], enumerable: true });
|
|
11
|
+
};
|
|
12
|
+
var __copyProps = (to, from, except, desc) => {
|
|
13
|
+
if (from && typeof from === "object" || typeof from === "function") {
|
|
14
|
+
for (let key of __getOwnPropNames(from))
|
|
15
|
+
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
16
|
+
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
17
|
+
}
|
|
18
|
+
return to;
|
|
19
|
+
};
|
|
20
|
+
var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
|
|
21
|
+
// If the importer is in node compatibility mode or this is not an ESM
|
|
22
|
+
// file that has been converted to a CommonJS file using a Babel-
|
|
23
|
+
// compatible transform (i.e. "__esModule" has not been set), then set
|
|
24
|
+
// "default" to the CommonJS "module.exports" for node compatibility.
|
|
25
|
+
isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
|
|
26
|
+
mod
|
|
27
|
+
));
|
|
28
|
+
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
29
|
+
var load_exports = {};
|
|
30
|
+
__export(load_exports, {
|
|
31
|
+
importWasmModule: () => importWasmModule
|
|
32
|
+
});
|
|
33
|
+
module.exports = __toCommonJS(load_exports);
|
|
34
|
+
var import_promises = require("node:fs/promises");
|
|
35
|
+
var import_node_path = require("node:path");
|
|
36
|
+
let wasmInstance = null;
|
|
37
|
+
let wasmLoadPromise = null;
|
|
38
|
+
const wasmModulePath = require.resolve("#wasm/vercel_python_analysis.js");
|
|
39
|
+
const wasmDir = (0, import_node_path.dirname)(wasmModulePath);
|
|
40
|
+
async function getCoreModule(path) {
|
|
41
|
+
const wasmPath = (0, import_node_path.join)(wasmDir, path);
|
|
42
|
+
const wasmBytes = await (0, import_promises.readFile)(wasmPath);
|
|
43
|
+
return WebAssembly.compile(wasmBytes);
|
|
44
|
+
}
|
|
45
|
+
async function importWasmModule() {
|
|
46
|
+
if (wasmInstance) {
|
|
47
|
+
return wasmInstance;
|
|
48
|
+
}
|
|
49
|
+
if (!wasmLoadPromise) {
|
|
50
|
+
wasmLoadPromise = (async () => {
|
|
51
|
+
const {
|
|
52
|
+
WASIShim
|
|
53
|
+
} = require("@bytecodealliance/preview2-shim/instantiation");
|
|
54
|
+
const wasmModule = require("#wasm/vercel_python_analysis.js");
|
|
55
|
+
const imports = new WASIShim().getImportObject();
|
|
56
|
+
const instance = await wasmModule.instantiate(getCoreModule, imports);
|
|
57
|
+
wasmInstance = instance;
|
|
58
|
+
return instance;
|
|
59
|
+
})();
|
|
60
|
+
}
|
|
61
|
+
return wasmLoadPromise;
|
|
62
|
+
}
|
|
63
|
+
// Annotate the CommonJS export names for ESM import in node:
|
|
64
|
+
0 && (module.exports = {
|
|
65
|
+
importWasmModule
|
|
66
|
+
});
|
|
@@ -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
|
+
}
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
@@ -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
|
+
|