@celsian/vura-compiler 0.2.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 +15 -0
- package/dist/index.d.ts +33 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +79 -0
- package/dist/index.js.map +1 -0
- package/package.json +45 -0
package/README.md
ADDED
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
# @celsian/vura-compiler
|
|
2
|
+
|
|
3
|
+
Compiler for Vura — transforms routes, pages, and API endpoints into optimized build output.
|
|
4
|
+
|
|
5
|
+
## Install
|
|
6
|
+
|
|
7
|
+
```bash
|
|
8
|
+
npm install @celsian/vura-compiler
|
|
9
|
+
```
|
|
10
|
+
|
|
11
|
+
This package is typically used internally by `@celsian/vura-cli` and `@celsian/vura-vite-plugin`. You don't need to install it directly unless building custom tooling.
|
|
12
|
+
|
|
13
|
+
## License
|
|
14
|
+
|
|
15
|
+
MIT
|
package/dist/index.d.ts
ADDED
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @celsian/vura-compiler — Pure JS fallback compiler for Vura
|
|
3
|
+
*
|
|
4
|
+
* Same API surface as @celsian/vura-compiler-native but uses regex-based
|
|
5
|
+
* static analysis instead of AST parsing. Good enough for most
|
|
6
|
+
* projects, but the native compiler is 10-50x faster for large ones.
|
|
7
|
+
*/
|
|
8
|
+
export interface ScanResult {
|
|
9
|
+
methods: string[];
|
|
10
|
+
kind: string;
|
|
11
|
+
hasDefaultExport: boolean;
|
|
12
|
+
hasGetServerData: boolean;
|
|
13
|
+
pageMode: string | null;
|
|
14
|
+
config: Record<string, string | number | boolean>;
|
|
15
|
+
}
|
|
16
|
+
export interface TransformResult {
|
|
17
|
+
code: string;
|
|
18
|
+
map: string | null;
|
|
19
|
+
}
|
|
20
|
+
/**
|
|
21
|
+
* Scan a route or page file using regex-based static analysis.
|
|
22
|
+
* Extracted from @celsian/vura-core's manifest.ts for standalone use.
|
|
23
|
+
*/
|
|
24
|
+
export declare function scanRoute(source: string, _fileType: string): ScanResult;
|
|
25
|
+
/**
|
|
26
|
+
* Transform JSX source — delegates to esbuild in practice.
|
|
27
|
+
* This is a passthrough that adds the import pragma.
|
|
28
|
+
*/
|
|
29
|
+
export declare function transformJsx(source: string, options?: {
|
|
30
|
+
jsxImportSource?: string;
|
|
31
|
+
production?: boolean;
|
|
32
|
+
}): TransformResult;
|
|
33
|
+
//# sourceMappingURL=index.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA;;;;;;GAMG;AAIH,MAAM,WAAW,UAAU;IACzB,OAAO,EAAE,MAAM,EAAE,CAAC;IAClB,IAAI,EAAE,MAAM,CAAC;IACb,gBAAgB,EAAE,OAAO,CAAC;IAC1B,gBAAgB,EAAE,OAAO,CAAC;IAC1B,QAAQ,EAAE,MAAM,GAAG,IAAI,CAAC;IACxB,MAAM,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,GAAG,MAAM,GAAG,OAAO,CAAC,CAAC;CACnD;AAED,MAAM,WAAW,eAAe;IAC9B,IAAI,EAAE,MAAM,CAAC;IACb,GAAG,EAAE,MAAM,GAAG,IAAI,CAAC;CACpB;AAMD;;;GAGG;AACH,wBAAgB,SAAS,CAAC,MAAM,EAAE,MAAM,EAAE,SAAS,EAAE,MAAM,GAAG,UAAU,CAsDvE;AAED;;;GAGG;AACH,wBAAgB,YAAY,CAC1B,MAAM,EAAE,MAAM,EACd,OAAO,GAAE;IAAE,eAAe,CAAC,EAAE,MAAM,CAAC;IAAC,UAAU,CAAC,EAAE,OAAO,CAAA;CAAO,GAC/D,eAAe,CAUjB"}
|
package/dist/index.js
ADDED
|
@@ -0,0 +1,79 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @celsian/vura-compiler — Pure JS fallback compiler for Vura
|
|
3
|
+
*
|
|
4
|
+
* Same API surface as @celsian/vura-compiler-native but uses regex-based
|
|
5
|
+
* static analysis instead of AST parsing. Good enough for most
|
|
6
|
+
* projects, but the native compiler is 10-50x faster for large ones.
|
|
7
|
+
*/
|
|
8
|
+
// ─── Route Scanner (regex-based) ───
|
|
9
|
+
const HTTP_METHODS = ['GET', 'POST', 'PUT', 'DELETE', 'PATCH', 'HEAD', 'OPTIONS'];
|
|
10
|
+
/**
|
|
11
|
+
* Scan a route or page file using regex-based static analysis.
|
|
12
|
+
* Extracted from @celsian/vura-core's manifest.ts for standalone use.
|
|
13
|
+
*/
|
|
14
|
+
export function scanRoute(source, _fileType) {
|
|
15
|
+
const methods = [];
|
|
16
|
+
// Detect HTTP method exports
|
|
17
|
+
for (const method of HTTP_METHODS) {
|
|
18
|
+
const pattern = new RegExp(`export\\s+(?:async\\s+)?(?:function\\s+${method}|const\\s+${method}\\s*=)`);
|
|
19
|
+
if (pattern.test(source)) {
|
|
20
|
+
methods.push(method);
|
|
21
|
+
}
|
|
22
|
+
}
|
|
23
|
+
// Extract route config
|
|
24
|
+
let kind = 'serverless';
|
|
25
|
+
const config = {};
|
|
26
|
+
const routeMatch = source.match(/export\s+const\s+route\s*=\s*\{([^}]+)\}/);
|
|
27
|
+
if (routeMatch) {
|
|
28
|
+
extractKVPairs(routeMatch[1], config);
|
|
29
|
+
if (typeof config.kind === 'string') {
|
|
30
|
+
kind = config.kind;
|
|
31
|
+
}
|
|
32
|
+
}
|
|
33
|
+
// Extract page config
|
|
34
|
+
let pageMode = null;
|
|
35
|
+
const pageMatch = source.match(/export\s+const\s+page\s*=\s*\{([^}]+)\}/);
|
|
36
|
+
if (pageMatch) {
|
|
37
|
+
extractKVPairs(pageMatch[1], config);
|
|
38
|
+
if (typeof config.mode === 'string') {
|
|
39
|
+
pageMode = config.mode;
|
|
40
|
+
}
|
|
41
|
+
}
|
|
42
|
+
// Detect default export
|
|
43
|
+
const hasDefaultExport = /export\s+default\s+/.test(source);
|
|
44
|
+
// Detect getServerData
|
|
45
|
+
const hasGetServerData = /export\s+(?:async\s+)?function\s+getServerData|export\s+(?:const|let)\s+getServerData/.test(source);
|
|
46
|
+
// Auto-detect server mode
|
|
47
|
+
if (!pageMode && hasGetServerData) {
|
|
48
|
+
pageMode = 'server';
|
|
49
|
+
}
|
|
50
|
+
if (!pageMode && (/import\s+.*from\s+['"]then\/server['"]/.test(source) || /useSWR|useQuery|useServerData/.test(source))) {
|
|
51
|
+
pageMode = 'server';
|
|
52
|
+
}
|
|
53
|
+
return { methods, kind, hasDefaultExport, hasGetServerData, pageMode, config };
|
|
54
|
+
}
|
|
55
|
+
/**
|
|
56
|
+
* Transform JSX source — delegates to esbuild in practice.
|
|
57
|
+
* This is a passthrough that adds the import pragma.
|
|
58
|
+
*/
|
|
59
|
+
export function transformJsx(source, options = {}) {
|
|
60
|
+
const importSource = options.jsxImportSource ?? 'what-framework';
|
|
61
|
+
const importLine = options.production
|
|
62
|
+
? `import { template, insert, createComponent } from '${importSource}/server';\n`
|
|
63
|
+
: `import { jsx as _jsx, jsxs as _jsxs, Fragment as _Fragment } from '${importSource}/jsx-runtime';\n`;
|
|
64
|
+
return {
|
|
65
|
+
code: importLine + source,
|
|
66
|
+
map: null,
|
|
67
|
+
};
|
|
68
|
+
}
|
|
69
|
+
// ─── Helpers ───
|
|
70
|
+
function extractKVPairs(body, config) {
|
|
71
|
+
const kvPattern = /(\w+)\s*:\s*(?:'([^']*)'|"([^"]*)"|(\d+(?:\.\d+)?)|(\btrue\b|\bfalse\b))/g;
|
|
72
|
+
let match;
|
|
73
|
+
while ((match = kvPattern.exec(body)) !== null) {
|
|
74
|
+
const key = match[1];
|
|
75
|
+
const value = match[2] ?? match[3] ?? (match[4] ? Number(match[4]) : match[5] === 'true');
|
|
76
|
+
config[key] = value;
|
|
77
|
+
}
|
|
78
|
+
}
|
|
79
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"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C,CAAC,CAAC;QACrB,MAAM,KAAK,GAAG,KAAK,CAAC,CAAC,CAAC,IAAI,KAAK,CAAC,CAAC,CAAC,IAAI,CAAC,KAAK,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,MAAM,CAAC,KAAK,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,KAAK,CAAC,CAAC,CAAC,KAAK,MAAM,CAAC,CAAC;QAC1F,MAAM,CAAC,GAAG,CAAC,GAAG,KAAK,CAAC;IACtB,CAAC;AACH,CAAC"}
|
package/package.json
ADDED
|
@@ -0,0 +1,45 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@celsian/vura-compiler",
|
|
3
|
+
"version": "0.2.0",
|
|
4
|
+
"description": "Pure JS compiler fallback for Vura — route scanning and JSX transforms",
|
|
5
|
+
"type": "module",
|
|
6
|
+
"main": "dist/index.js",
|
|
7
|
+
"types": "dist/index.d.ts",
|
|
8
|
+
"exports": {
|
|
9
|
+
".": {
|
|
10
|
+
"types": "./dist/index.d.ts",
|
|
11
|
+
"import": "./dist/index.js",
|
|
12
|
+
"default": "./dist/index.js"
|
|
13
|
+
}
|
|
14
|
+
},
|
|
15
|
+
"files": [
|
|
16
|
+
"dist"
|
|
17
|
+
],
|
|
18
|
+
"scripts": {
|
|
19
|
+
"test": "vitest run",
|
|
20
|
+
"build": "tsc -b",
|
|
21
|
+
"prepack": "pnpm run build"
|
|
22
|
+
},
|
|
23
|
+
"license": "MIT",
|
|
24
|
+
"publishConfig": {
|
|
25
|
+
"access": "public"
|
|
26
|
+
},
|
|
27
|
+
"repository": {
|
|
28
|
+
"type": "git",
|
|
29
|
+
"url": "git+https://github.com/CelsianJs/vura.git"
|
|
30
|
+
},
|
|
31
|
+
"homepage": "https://github.com/CelsianJs/vura#readme",
|
|
32
|
+
"bugs": {
|
|
33
|
+
"url": "https://github.com/CelsianJs/vura/issues"
|
|
34
|
+
},
|
|
35
|
+
"keywords": [
|
|
36
|
+
"vura",
|
|
37
|
+
"compiler",
|
|
38
|
+
"jsx",
|
|
39
|
+
"routes",
|
|
40
|
+
"typescript"
|
|
41
|
+
],
|
|
42
|
+
"engines": {
|
|
43
|
+
"node": ">=20 <23"
|
|
44
|
+
}
|
|
45
|
+
}
|