@oiyo/core 0.0.4 → 0.1.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.cts CHANGED
@@ -1,29 +1,16 @@
1
1
  /**
2
- * @oiyo/core v0.0.4
2
+ * @oiyo/core v0.1.0
3
3
  * Copyright (c) 2026 skiyee. All rights reserved.
4
4
  * Commercial software. See LICENSE for terms.
5
- * Official site: https://oiyo.pages.dev
5
+ * Official site: https://oiyo.js.org
6
6
  */
7
- import { n as PageFile, r as ResolvedPageMeta } from "./types-CO6ioKnp.cjs";
8
- import { OiyoConfig, PagesConfig } from "@oiyo/config";
7
+ import { GlobRule, GlobalStyle, OiyoConfig, Page, PagesConfig, PagesJson } from "@oiyo/config";
8
+ import * as _$vue from "vue";
9
9
  import * as _$magic_string0 from "magic-string";
10
- import { ConfigWatcher } from "c12";
11
10
  import { SFCDescriptor } from "@vue/compiler-sfc";
11
+ import { ConfigWatcher } from "c12";
12
12
  import { Plugin } from "vite";
13
13
 
14
- //#region src/layout/types.d.ts
15
- /**
16
- * 布局信息
17
- */
18
- interface LayoutFile {
19
- /** 布局应用名称 */
20
- useName: string;
21
- /** 布局组件名称 */
22
- componentName: string;
23
- /** 布局文件的绝对路径 */
24
- filePath: string;
25
- }
26
- //#endregion
27
14
  //#region src/logger.d.ts
28
15
  type LogType = 'error' | 'warn' | 'info' | 'debug';
29
16
  type LogLevel = 'silent' | LogType | 'verbose';
@@ -56,19 +43,268 @@ interface LoggerOptions {
56
43
  }
57
44
  declare function createLogger(level?: LogLevel, options?: LoggerOptions): Logger;
58
45
  //#endregion
59
- //#region src/layout/index.d.ts
60
- declare class OiyoLayout {
46
+ //#region src/modules/auto-api/types.d.ts
47
+ /** 自动 API 条目,描述一个可被自动导入的模块导出项 */
48
+ interface AutoApiItem {
49
+ /** 导出名称,如 'default' 或具名导出 */
50
+ exportName: string;
51
+ /** 源文件在磁盘上的绝对路径 */
52
+ filePath: string;
53
+ /** 对外暴露的导入路径(可能经过 importBase 规范化) */
54
+ importPath?: string;
55
+ /** 在消费端使用的本地标识符名称 */
56
+ name: string;
57
+ }
58
+ /** 手动注册的 API 条目,由用户在配置中通过 scan.apis.only 显式声明 */
59
+ interface IncludedApi {
60
+ /** 源导出名称,默认与 name 相同 */
61
+ export?: string;
62
+ /** 模块来源路径 */
63
+ from: string;
64
+ /** 本地注册名称 */
65
+ name: string;
66
+ }
67
+ /** 批量扫描 API 的源配置,描述一个目录/包的扫描规则 */
68
+ interface IncludedApisSource {
69
+ /** 需要排除的导出名称列表 */
70
+ exclude?: string[];
71
+ /** 忽略文件/目录的 glob 规则 */
72
+ ignore?: GlobRule;
73
+ /** 包导入基准路径(bare specifier),用于生成对外导入语句 */
74
+ importBase?: string;
75
+ /** 匹配文件的 glob 规则,默认匹配 TS/JS 模块文件 */
76
+ pattern?: GlobRule;
77
+ /** 扫描源目录/包的绝对路径 */
78
+ path: string;
79
+ /** 是否同时扫描并注册类型导出 */
80
+ types?: boolean;
81
+ }
82
+ //#endregion
83
+ //#region src/state/index.d.ts
84
+ declare class OiyoState {
85
+ private readonly config;
86
+ constructor(config: OiyoConfig);
87
+ get stateDir(): string;
88
+ get typesDir(): string;
89
+ get srcDir(): string;
90
+ get declarationEntryPath(): string;
91
+ get appTsconfigPath(): string;
92
+ get nodeTsconfigPath(): string;
93
+ private relativeToState;
94
+ private stringifyJson;
95
+ generateDeclarationEntry(): string;
96
+ generateAppTsconfig(): string;
97
+ generateNodeTsconfig(): string;
98
+ writeAppTsconfig(): string;
99
+ writeNodeTsconfig(): string;
100
+ writeDeclarationEntry(): string;
101
+ ensureDeclarationEntry(): string;
102
+ }
103
+ //#endregion
104
+ //#region src/modules/auto-api/index.d.ts
105
+ /**
106
+ * 自动 API 管理模块
107
+ *
108
+ * 负责扫描指定目录/包中的模块导出,生成自动导入语句和全局类型声明。
109
+ * 核心流程:
110
+ * 1. 构造时注册配置中的扫描器(registerConfigScanners)
111
+ * 2. collectApis() 扫描所有源文件并收集导出项
112
+ * 3. resolveImports() 分析代码引用并生成 import 语句
113
+ * 4. generateDeclaration() / writeDeclaration() 生成并写入全局类型声明文件
114
+ */
115
+ declare class OiyoModAutoApi {
116
+ private readonly _config;
117
+ /** 已扫描收集的值导出列表 */
118
+ autoApis: AutoApiItem[];
119
+ /** 已扫描收集的类型导出列表 */
120
+ autoApiTypes: AutoApiItem[];
121
+ /** 值导出注册表,按 name 索引,用于去重和快速查找 */
122
+ private readonly autoApiMap;
123
+ /** 类型导出注册表,按 name 索引 */
124
+ private readonly autoApiTypeMap;
125
+ /** 手动注册的值 API(来自配置中的 only 声明) */
126
+ private readonly includedApis;
127
+ /** 手动注册的类型 API */
128
+ private readonly includedApiTypes;
129
+ /** 待扫描的 API 源列表 */
130
+ private readonly apiSources;
131
+ private readonly logger;
132
+ private readonly oiyoState;
133
+ constructor(_config: OiyoConfig, deps: {
134
+ logger: Logger;
135
+ oiyoState: OiyoState;
136
+ });
137
+ /** oiyo 状态目录路径 */
138
+ get stateDir(): string;
139
+ /** 类型声明文件存放目录 */
140
+ get typesDir(): string;
141
+ /** API 全局类型声明文件的完整路径(apis.d.ts) */
142
+ get declarationPath(): string;
143
+ /** 判断给定文件路径是否属于已注册的 API 扫描源 */
144
+ isAutoApiPath(absPath: string): boolean;
145
+ /** 手动注册值 API 项(来自显式声明,非扫描所得) */
146
+ includeApi(input: IncludedApi | IncludedApi[]): void;
147
+ /** 手动注册类型 API 项 */
148
+ includeApiType(input: IncludedApi | IncludedApi[]): void;
149
+ /**
150
+ * 批量注册 API 扫描源(自动去重)
151
+ * 支持字符串路径或完整的 IncludedApisSource 配置对象
152
+ */
153
+ includeApis(input: string | string[] | IncludedApisSource | IncludedApisSource[]): void;
154
+ /** 解析配置文件中的 scan.apis,分别注册到扫描源或手动注册列表 */
155
+ private registerConfigScanners;
156
+ /** 重置所有已收集的状态(在重新扫描前调用) */
157
+ private resetCollectedState;
158
+ /**
159
+ * 注册一个值导出项,处理同名冲突检测
160
+ * - 同文件同导出名:跳过(重复)
161
+ * - 同文件但已有具名导出时遇到 default:跳过(具名优先)
162
+ * - 不同文件同名:冲突警告并跳过
163
+ * @returns 是否注册成功
164
+ */
165
+ private registerValue;
166
+ /**
167
+ * 注册一个类型导出项,处理同名冲突检测
168
+ * 同文件同导出名视为重复跳过,不同文件同名则冲突警告
169
+ */
170
+ private registerType;
171
+ /** 将手动注册的 API 项预先注入注册表(确保优先级高于扫描结果) */
172
+ private seedIncludedRegistrations;
173
+ /** 批量注册扫描到的值导出项,跳过 exclude 列表中的名称 */
174
+ private registerScannedValueItems;
175
+ /** 批量注册扫描到的类型导出项,跳过 exclude 列表中的名称 */
176
+ private registerScannedTypeItems;
177
+ /**
178
+ * 扫描一组文件,提取导出项并注册到全局注册表
179
+ * @param source 所属的扫描源配置
180
+ * @param filePaths 待扫描的文件路径列表
181
+ * @param scanPath 扫描基准路径(用于计算相对导入路径)
182
+ * @param options.includeTypes 是否解析类型导出
183
+ * @param options.registerValues/registerTypes 分别控制是否注册值/类型导出
184
+ */
185
+ private scanSourceFiles;
186
+ /**
187
+ * 执行完整的 API 收集流程
188
+ * 1. 重置状态并注入手动注册项
189
+ * 2. 遍历所有扫描源,分别处理值文件和类型文件
190
+ * 3. 返回收集到的值 API 列表
191
+ */
192
+ collectApis(): Promise<AutoApiItem[]>;
193
+ /** 代理调用 collectBoundNames,收集代码中已绑定的标识符 */
194
+ collectBoundNames(code: string): Set<string>;
195
+ /**
196
+ * 分析代码中引用了哪些已注册的自动 API,生成对应的 import 语句列表
197
+ *
198
+ * @param code
199
+ * @param options 配置
200
+ * @param options.boundNames 额外已绑定的标识符(不会被当作需要导入的引用)
201
+ */
202
+ resolveImports(code: string, options?: {
203
+ boundNames?: Iterable<string>;
204
+ }): string[];
205
+ resolveImport(name: string): string | undefined;
206
+ /**
207
+ * 生成全局类型声明文件内容(apis.d.ts)
208
+ * 包含两部分:
209
+ * - 值导出的全局 const 声明(typeof import(...) 形式)
210
+ * - 类型导出的 re-export 声明
211
+ */
212
+ generateDeclaration(): string;
213
+ /** 生成类型声明内容并写入文件,同时确保 tsconfig 中包含该声明文件 */
214
+ writeDeclaration(): string;
215
+ }
216
+ //#endregion
217
+ //#region src/modules/auto-component/index.d.ts
218
+ interface AutoComponentFile {
219
+ componentName: string;
220
+ exportName: string;
221
+ filePath: string;
222
+ importPath?: string;
223
+ }
224
+ interface RegisteredComponent {
225
+ export?: string;
226
+ from: string;
227
+ name: string;
228
+ }
229
+ interface RegisteredComponentsSource {
230
+ chain?: boolean;
231
+ ignore?: GlobRule;
232
+ importBase?: string;
233
+ pattern?: GlobRule;
234
+ path: string;
235
+ prefix?: string;
236
+ }
237
+ declare function resolveScannedComponentSources(config: OiyoConfig): RegisteredComponentsSource[];
238
+ declare function isScannedComponentPath(config: OiyoConfig, absPath: string): boolean;
239
+ declare function resolveComponentName(filePath: string, baseDir: string, options?: {
240
+ chain?: boolean;
241
+ prefix?: string;
242
+ }): string;
243
+ declare class OiyoModAutoComponent {
244
+ private readonly _config;
245
+ autoComponents: AutoComponentFile[];
246
+ private readonly registeredComponents;
247
+ private readonly componentSources;
248
+ private readonly autoComponentMap;
249
+ private readonly logger;
250
+ private readonly oiyoState;
251
+ constructor(_config: OiyoConfig, deps: {
252
+ logger: Logger;
253
+ oiyoState: OiyoState;
254
+ });
255
+ get stateDir(): string;
256
+ get typesDir(): string;
257
+ get declarationPath(): string;
258
+ isAutoComponentPath(absPath: string): boolean;
259
+ registerComponent(component: RegisteredComponent): void;
260
+ registerComponents(input: string | string[] | RegisteredComponentsSource | RegisteredComponentsSource[]): void;
261
+ private registerConfigScanners;
262
+ private setResolvedComponent;
263
+ collectComponents(): Promise<AutoComponentFile[]>;
264
+ resolveComponentImports(template: string, importerPath?: string): string[];
265
+ resolveComponentImport(componentName: string, importerPath?: string): string | undefined;
266
+ generateDeclaration(): string;
267
+ writeDeclaration(): string;
268
+ }
269
+ //#endregion
270
+ //#region src/modules/layout/types.d.ts
271
+ /**
272
+ * 布局信息
273
+ */
274
+ interface LayoutFile {
275
+ /** 布局应用名称 */
276
+ useName: string;
277
+ /** 布局组件名称 */
278
+ componentName: string;
279
+ /** 布局文件的绝对路径 */
280
+ filePath: string;
281
+ }
282
+ //#endregion
283
+ //#region src/modules/layout/placeholder.d.ts
284
+ declare const OiyoLayout: _$vue.DefineComponent<{}, () => _$vue.VNode<_$vue.RendererNode, _$vue.RendererElement, {
285
+ [key: string]: any;
286
+ }>[] | undefined, {}, {}, {}, _$vue.ComponentOptionsMixin, _$vue.ComponentOptionsMixin, {}, string, _$vue.PublicProps, Readonly<_$vue.ExtractPropTypes<{}>>, {}, {}>;
287
+ //#endregion
288
+ //#region src/modules/layout/index.d.ts
289
+ declare class OiyoModLayout {
61
290
  private readonly config;
62
291
  layoutFiles: LayoutFile[];
63
- logger: Logger;
292
+ private readonly logger;
293
+ private readonly oiyoState;
64
294
  constructor(config: OiyoConfig, deps: {
65
295
  logger: Logger;
296
+ oiyoState: OiyoState;
66
297
  });
67
298
  get srcDir(): string;
68
299
  get layoutDir(): string;
300
+ get stateDir(): string;
301
+ get typesDir(): string;
302
+ get declarationPath(): string;
69
303
  isLayoutPath(absPath: string): boolean;
70
304
  setLayout(absPath: string): boolean;
71
305
  registerLayouts(): Promise<LayoutFile[]>;
306
+ generateDeclaration(): string;
307
+ writeDeclaration(): string;
72
308
  applyLayout(useName: string | false | undefined, template: string): {
73
309
  template: string;
74
310
  script: string;
@@ -76,7 +312,7 @@ declare class OiyoLayout {
76
312
  };
77
313
  }
78
314
  //#endregion
79
- //#region src/root/parse.d.ts
315
+ //#region src/modules/root/parse.d.ts
80
316
  interface ParsedRootMarco {
81
317
  /** 宏引用模块 */
82
318
  imports?: string[];
@@ -91,34 +327,50 @@ interface ParsedRootMarco {
91
327
  }[];
92
328
  }
93
329
  //#endregion
94
- //#region src/root/virtual-module.d.ts
330
+ //#region src/modules/root/macro.d.ts
331
+ /**
332
+ * 根上下文工厂函数
333
+ */
334
+ type RootContextFactory<T extends object> = () => T;
335
+ /**
336
+ * 定义根上下文
337
+ * @param factory 返回上下文对象的工厂函数
338
+ * @returns 上下文对象
339
+ */
340
+ declare const defineRootContext: <T extends object>(factory: RootContextFactory<T>) => T;
341
+ //#endregion
342
+ //#region src/modules/root/virtual-module.d.ts
95
343
  declare const VIRTUAL_ROOT_CONTEXT_ID = "virtual:oiyo-root-context";
96
344
  declare const RESOLVED_VIRTUAL_ROOT_CONTEXT_ID = "\0virtual:oiyo-root-context";
97
345
  //#endregion
98
- //#region src/root/index.d.ts
99
- interface RootView {
100
- imports: string[];
101
- template: string;
102
- script: string;
103
- }
104
- declare class OiyoRoot {
346
+ //#region src/modules/root/index.d.ts
347
+ declare class OiyoModRoot {
105
348
  readonly config: OiyoConfig;
106
349
  /** 根视图模块 */
107
- rootView: RootView;
350
+ rootView: {
351
+ imports: string[];
352
+ template: string;
353
+ script: string;
354
+ };
108
355
  /** 根虚拟模块 */
109
356
  rootVM?: string;
110
357
  /** 根宏命令结构 */
111
358
  rootMarco?: ParsedRootMarco;
112
- /** 日志 */
113
- logger: Logger;
359
+ private readonly logger;
360
+ private readonly oiyoAutoApi?;
114
361
  constructor(config: OiyoConfig, deps: {
115
362
  logger: Logger;
363
+ oiyoAutoApi?: OiyoModAutoApi;
116
364
  });
117
365
  get srcDir(): string;
118
366
  get rootPath(): string;
119
367
  isRootPath(absPath: string): boolean;
120
368
  parseRoot(source: string): {
121
- view: RootView;
369
+ view: {
370
+ imports: string[];
371
+ template: string;
372
+ script: string;
373
+ };
122
374
  marco: ParsedRootMarco | undefined;
123
375
  };
124
376
  transformRoot(source: string): {
@@ -134,27 +386,104 @@ declare class OiyoRoot {
134
386
  };
135
387
  }
136
388
  //#endregion
137
- //#region src/page/index.d.ts
138
- declare class OiyoPage {
389
+ //#region src/modules/route/types.d.ts
390
+ /**
391
+ * 可序列化的页面元信息值类型
392
+ * 用于静态提取和 pages.json 生成
393
+ */
394
+ type PageMetaValue = string | number | boolean | null | PageMetaObject | PageMetaValue[];
395
+ /**
396
+ * 可序列化的页面元信息对象
397
+ */
398
+ interface PageMetaObject {
399
+ [key: string]: PageMetaValue | undefined;
400
+ }
401
+ /**
402
+ * 页面元信息基础字段
403
+ */
404
+ interface BasePageMeta {
405
+ /** 页面类型 */
406
+ type?: 'page' | 'home';
407
+ /** 使用的布局名称,false 表示不使用布局 */
408
+ layout?: string | false;
409
+ /** uni-app 页面样式配置 */
410
+ style?: GlobalStyle;
411
+ }
412
+ /**
413
+ * 已解析的页面元信息
414
+ * 用于编译期静态提取和 pages.json 生成
415
+ */
416
+ interface ResolvedPageMeta extends BasePageMeta, PageMetaObject {}
417
+ /**
418
+ * 页面文件信息
419
+ */
420
+ interface PageFile {
421
+ /** 页面路径(相对于 srcDir,不含扩展名) */
422
+ pagePath: string;
423
+ /** 页面文件的绝对路径 */
424
+ filePath: string;
425
+ /** 页面元信息 */
426
+ pageMeta: ResolvedPageMeta;
427
+ /** 所属包(main 或子包名称) */
428
+ pageBelong: string;
429
+ }
430
+ /**
431
+ * 已解析的页面配置
432
+ */
433
+ interface ResolvedPagesJson extends PagesJson {
434
+ /**
435
+ * 设置页面路径及窗口表现
436
+ */
437
+ pages: Page[];
438
+ }
439
+ //#endregion
440
+ //#region src/modules/route/macro.d.ts
441
+ /**
442
+ * 页面元信息
443
+ * 用户在 definePageMeta() 中使用的类型
444
+ * 支持通过 declare module '@skiyee/oiyo' 进行扩展
445
+ */
446
+ interface PageMeta extends BasePageMeta {
447
+ /** 其他自定义字段 */
448
+ [key: string]: unknown;
449
+ }
450
+ /**
451
+ * 定义页面元信息
452
+ * @param meta 页面元信息配置
453
+ */
454
+ declare const definePageMeta: (meta: PageMeta) => void;
455
+ //#endregion
456
+ //#region src/modules/route/placeholder.d.ts
457
+ declare const OiyoPage: _$vue.DefineComponent<{}, {}, {}, {}, {}, _$vue.ComponentOptionsMixin, _$vue.ComponentOptionsMixin, {}, string, _$vue.PublicProps, Readonly<_$vue.ExtractPropTypes<{}>>, {}, {}>;
458
+ //#endregion
459
+ //#region src/modules/route/index.d.ts
460
+ declare class OiyoModRoute {
139
461
  pageFiles: PageFile[];
140
462
  pagesConfig: PagesConfig;
141
463
  pagesConfigWatcher?: ConfigWatcher<PagesConfig>;
142
- config: OiyoConfig;
143
- oiyoRoot?: OiyoRoot;
144
- oiyoLayout?: OiyoLayout;
145
- logger: Logger;
464
+ private readonly config;
465
+ private readonly logger;
466
+ private readonly oiyoState;
467
+ private readonly oiyoRoot?;
468
+ private readonly oiyoLayout?;
146
469
  constructor(config: OiyoConfig, deps: {
147
470
  logger: Logger;
471
+ oiyoState: OiyoState;
148
472
  });
149
473
  constructor(config: OiyoConfig, deps: {
150
474
  logger: Logger;
151
- oiyoRoot: OiyoRoot;
152
- oiyoLayout: OiyoLayout;
475
+ oiyoState: OiyoState;
476
+ oiyoRoot: OiyoModRoot;
477
+ oiyoLayout: OiyoModLayout;
153
478
  });
154
479
  get srcDir(): string;
155
480
  get mainPageDir(): string;
156
481
  get subPageDirs(): string[];
157
482
  get pagesJsonPath(): string;
483
+ get stateDir(): string;
484
+ get typesDir(): string;
485
+ get declarationPath(): string;
486
+ resolvePagesJson(userPageJson?: PagesConfig): ResolvedPagesJson;
158
487
  loadPagesConfig(): Promise<PagesConfig>;
159
488
  watchPagesConfig(onUpdateCallback?: () => void | Promise<void>): Promise<void>;
160
489
  unwatchPagesConfig(): Promise<void>;
@@ -177,6 +506,8 @@ declare class OiyoPage {
177
506
  * 生成并写入 pages.json
178
507
  */
179
508
  writePagesJson(userPageJson?: PagesConfig): void;
509
+ generateDeclaration(userPageJson?: PagesConfig): string;
510
+ writeDeclaration(userPageJson?: PagesConfig): string;
180
511
  /**
181
512
  * 注册所有页面
182
513
  * - 扫描页面
@@ -191,7 +522,24 @@ declare class OiyoPage {
191
522
  }>;
192
523
  }
193
524
  //#endregion
525
+ //#region src/plugin/context.d.ts
526
+ interface OiyoContext {
527
+ config: OiyoConfig;
528
+ autoApi: OiyoModAutoApi;
529
+ autoComponent: OiyoModAutoComponent;
530
+ logger: Logger;
531
+ layout: OiyoModLayout;
532
+ state: OiyoState;
533
+ route: OiyoModRoute;
534
+ root: OiyoModRoot;
535
+ }
536
+ //#endregion
194
537
  //#region src/plugin/index.d.ts
538
+ declare module 'vite' {
539
+ interface UserConfig {
540
+ oiyo: OiyoContext;
541
+ }
542
+ }
195
543
  declare function OiyoCorePlugin(options?: OiyoConfig): Plugin[];
196
544
  //#endregion
197
- export { LogErrorOptions, LogLevel, LogLevels, LogOptions, LogType, Logger, LoggerOptions, OiyoCorePlugin, OiyoLayout, OiyoPage, OiyoRoot, RESOLVED_VIRTUAL_ROOT_CONTEXT_ID, RootView, VIRTUAL_ROOT_CONTEXT_ID, createLogger };
545
+ export { type AutoApiItem, AutoComponentFile, type IncludedApi, type IncludedApisSource, LogErrorOptions, LogLevel, LogLevels, LogOptions, LogType, Logger, LoggerOptions, OiyoCorePlugin, OiyoLayout, OiyoModAutoApi, OiyoModAutoComponent, OiyoModLayout, OiyoModRoot, OiyoModRoute, OiyoPage, OiyoState, type PageMeta, RESOLVED_VIRTUAL_ROOT_CONTEXT_ID, RegisteredComponent, RegisteredComponentsSource, VIRTUAL_ROOT_CONTEXT_ID, createLogger, definePageMeta, defineRootContext, isScannedComponentPath, resolveComponentName, resolveScannedComponentSources };