@openelement/ssg 0.41.0-alpha.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.
- package/LICENSE +21 -0
- package/README.md +21 -0
- package/package.json +30 -0
- package/src/build-postprocess.d.ts +24 -0
- package/src/build-postprocess.js +74 -0
- package/src/cem-compat.js +226 -0
- package/src/entry-generators.d.ts +3 -0
- package/src/entry-generators.js +126 -0
- package/src/entry-render-helpers.js +307 -0
- package/src/entry-render-runtime.js +94 -0
- package/src/entry-render-ssg.js +169 -0
- package/src/entry-renderer.d.ts +87 -0
- package/src/entry-renderer.js +555 -0
- package/src/external-resolver.d.ts +62 -0
- package/src/external-resolver.js +285 -0
- package/src/index.d.ts +31 -0
- package/src/index.js +28 -0
- package/src/island-manifest.d.ts +27 -0
- package/src/island-manifest.js +78 -0
- package/src/postprocess.d.ts +73 -0
- package/src/postprocess.js +376 -0
- package/src/route-scanner-fs.js +29 -0
- package/src/route-scanner.d.ts +132 -0
- package/src/route-scanner.js +497 -0
- package/src/route-type-generator.d.ts +29 -0
- package/src/route-type-generator.js +99 -0
- package/src/ssg-dynamic.js +66 -0
- package/src/ssg-helpers.d.ts +8 -0
- package/src/ssg-helpers.js +96 -0
- package/src/ssg-i18n.js +78 -0
- package/src/ssg-render.d.ts +3 -0
- package/src/ssg-render.js +162 -0
- package/src/ssg-report.js +172 -0
- package/src/ssr-polyfills.d.ts +15 -0
- package/src/ssr-polyfills.js +26 -0
|
@@ -0,0 +1,132 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @openelement/core - Route scanner
|
|
3
|
+
* Scans the routes directory and generates a route map.
|
|
4
|
+
* Produces the virtual:routes module.
|
|
5
|
+
*
|
|
6
|
+
* Phase 1 enhancement: support for _renderer.ts (layout) and
|
|
7
|
+
* _middleware.ts (Hono middleware) special files.
|
|
8
|
+
*
|
|
9
|
+
* Phase 2 enhancement: support for package islands auto-detection.
|
|
10
|
+
* Packages can export an `islands` array in their main entry.
|
|
11
|
+
*
|
|
12
|
+
* Convention (minimal augmentation):
|
|
13
|
+
* - _renderer.ts: exports a renderer that wraps route VNodes
|
|
14
|
+
* - _middleware.ts: exports a Hono middleware function applied before the route
|
|
15
|
+
* - Files starting with _ are not route handlers but are loaded by the framework
|
|
16
|
+
*
|
|
17
|
+
* ─── SSR Import Discovery Audit (Step1) ─────────────────────
|
|
18
|
+
*
|
|
19
|
+
* This file discovers islands but does NOT import them (static scan only):
|
|
20
|
+
*
|
|
21
|
+
* 1. Local island files:
|
|
22
|
+
* - Scanned by `scanIslands()`
|
|
23
|
+
* - Metadata read by `scanIslandMeta()` (static, no import)
|
|
24
|
+
* - SSR decision: `openElement.ssr` field (static read, no import)
|
|
25
|
+
*
|
|
26
|
+
* 2. Package manifest islands:
|
|
27
|
+
* - Discovered by `scanPackageManifests()`
|
|
28
|
+
* - Imports package module to read `manifest` export
|
|
29
|
+
* - Browser-only packages: caught by try/catch
|
|
30
|
+
* - SSR decision: `manifest.declarations[].openElement.ssr` field
|
|
31
|
+
*
|
|
32
|
+
* 3. CEM manifests (v0.18.0):
|
|
33
|
+
* - Discovered by `scanCemManifests()` - reads custom-elements.json from
|
|
34
|
+
* node_modules packages WITHOUT importing package code
|
|
35
|
+
* - Results fed into the compatibility classifier (parseCem + classifyCemManifest)
|
|
36
|
+
*
|
|
37
|
+
* 4. Nested custom elements (from the VNode tree):
|
|
38
|
+
* - NOT handled in this file
|
|
39
|
+
* - See: `packages/core/src/jsx-render-string.ts` and `renderDsdTree()`
|
|
40
|
+
*
|
|
41
|
+
* Audit completed: 2026-05-17
|
|
42
|
+
* Auditor: AI agent (openElement v0.17.4 SOP compliance check)
|
|
43
|
+
*
|
|
44
|
+
* ─── v0.41.0-alpha.1: AST removed ────────────────────────────
|
|
45
|
+
*
|
|
46
|
+
* Replaced TypeScript AST scanning with regex/glob-based extraction.
|
|
47
|
+
* Route and island modules are simple ESM files; parsing the whole source
|
|
48
|
+
* with the TypeScript compiler is overkill and adds a heavy dependency.
|
|
49
|
+
*/ import type { CompatibilityClassification, RouteEntry } from '@openelement/protocol/framework';
|
|
50
|
+
import type { OpenElementPackageManifest } from '@openelement/protocol/manifest';
|
|
51
|
+
/** Local island metadata indexed by tag name. */ export interface LocalIslandMeta {
|
|
52
|
+
tagName: string;
|
|
53
|
+
filePath: string;
|
|
54
|
+
ssr?: boolean;
|
|
55
|
+
dsd?: boolean;
|
|
56
|
+
hydrate?: 'load' | 'idle' | 'visible' | 'only';
|
|
57
|
+
reason?: string;
|
|
58
|
+
}
|
|
59
|
+
/**
|
|
60
|
+
* Recursively scan a directory for route files.
|
|
61
|
+
* Also collects _renderer.ts and _middleware.ts special files.
|
|
62
|
+
*/ export declare function scanRoutes(routesDir: string, baseDir?: string): Promise<RouteEntry[]>;
|
|
63
|
+
/**
|
|
64
|
+
* v0.25: AST-verified — converts file name to a valid Custom Element tag name.
|
|
65
|
+
* Uses regex for path manipulation since tag names are derived from file paths.
|
|
66
|
+
*
|
|
67
|
+
* Examples:
|
|
68
|
+
* 'my-counter.ts' -> 'my-counter'
|
|
69
|
+
* 'posts/index.ts' -> 'posts-index'
|
|
70
|
+
* 'admin\\dashboard.ts' -> 'admin-dashboard'
|
|
71
|
+
*/ export declare function fileToTagName(fileName: string): string;
|
|
72
|
+
/**
|
|
73
|
+
* Scan islands directory recursively for island files.
|
|
74
|
+
* Returns paths relative to islandsDir (e.g., ['my-counter.ts', 'posts/index.ts']).
|
|
75
|
+
*/ export declare function scanIslands(islandsDir: string, relativeDir?: string): Promise<string[]>;
|
|
76
|
+
/**
|
|
77
|
+
* v0.41.0-alpha.1: Regex-based — reads island metadata by statically scanning the module
|
|
78
|
+
* source for `export const openElement = defineIslandConfig({ ... })`.
|
|
79
|
+
*
|
|
80
|
+
* Supported form:
|
|
81
|
+
* export const openElement = defineIslandConfig({ ssr: false, dsd: false, hydrate: 'only' })
|
|
82
|
+
*
|
|
83
|
+
* This is more reliable than regex because it handles:
|
|
84
|
+
* - Comments inside the object literal
|
|
85
|
+
* - Computed properties
|
|
86
|
+
* - Destructured/re-exported values
|
|
87
|
+
* - Canonical defineIslandConfig(...) calls
|
|
88
|
+
*
|
|
89
|
+
* If a module cannot be read, its metadata is silently skipped.
|
|
90
|
+
*/ export declare function scanIslandMeta(islandsDir: string, islandFiles: string[]): Promise<Record<string, LocalIslandMeta>>;
|
|
91
|
+
/**
|
|
92
|
+
* Scan package exports for OpenElementPackageManifest.
|
|
93
|
+
* Packages should export a `manifest` OpenElementPackageManifest in their main entry.
|
|
94
|
+
*
|
|
95
|
+
* Example package export:
|
|
96
|
+
* ```ts
|
|
97
|
+
* // @openelement/ui/index.ts
|
|
98
|
+
* export { manifest } from './manifest.js';
|
|
99
|
+
* ```
|
|
100
|
+
*
|
|
101
|
+
* @param packageNames - List of package names to scan (e.g., ['@openelement/ui'])
|
|
102
|
+
* @returns Array of OpenElementPackageManifest
|
|
103
|
+
*/ export declare function scanPackageManifests(packageNames: string[]): Promise<OpenElementPackageManifest[]>;
|
|
104
|
+
/** Result of scanning node_modules for CEM manifests */ export interface CemScanResult {
|
|
105
|
+
/** Package name (e.g. '@openelement/ui') */ packageName: string;
|
|
106
|
+
/** Absolute path to custom-elements.json */ cemPath: string;
|
|
107
|
+
/** Raw JSON content */ json: string;
|
|
108
|
+
}
|
|
109
|
+
/**
|
|
110
|
+
* Scan node_modules for packages that ship a `custom-elements.json`.
|
|
111
|
+
*
|
|
112
|
+
* Strategy:
|
|
113
|
+
* 1. Read node_modules directory entries (top-level packages + scoped orgs)
|
|
114
|
+
* 2. For each package, check if `<pkg>/custom-elements.json` exists
|
|
115
|
+
* 3. Return the raw JSON - caller is responsible for parsing + classifying
|
|
116
|
+
*
|
|
117
|
+
* This function reads files only. It never imports or executes package code.
|
|
118
|
+
*
|
|
119
|
+
* @param nodeModulesDir - Absolute path to the node_modules directory
|
|
120
|
+
* @returns Array of found CEM manifests
|
|
121
|
+
*/ export declare function scanCemManifests(nodeModulesDir: string): Promise<CemScanResult[]>;
|
|
122
|
+
/**
|
|
123
|
+
* Run CEM auto-detection: scan node_modules, parse each manifest,
|
|
124
|
+
* and classify all discovered components.
|
|
125
|
+
*
|
|
126
|
+
* This is the high-level function called from the Vite plugin buildStart().
|
|
127
|
+
* It combines scanCemManifests() + parseCem() + classifyCemManifest()
|
|
128
|
+
* into a single pipeline.
|
|
129
|
+
*
|
|
130
|
+
* @param nodeModulesDir - Absolute path to node_modules
|
|
131
|
+
* @returns Array of compatibility classifications (may be empty if no CEM found)
|
|
132
|
+
*/ export declare function detectAndClassifyCemPackages(nodeModulesDir: string): Promise<CompatibilityClassification[]>;
|