@uni-helper/vite-plugin-uni-pages 0.4.9 → 0.5.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 +388 -50
- package/client.d.ts +2 -4
- package/dist/index.d.mts +708 -357
- package/dist/index.mjs +1737 -870
- package/package.json +27 -35
- package/dist/index.cjs +0 -1401
- package/dist/index.d.cts +0 -569
- package/index.d.ts +0 -4
package/dist/index.d.cts
DELETED
|
@@ -1,569 +0,0 @@
|
|
|
1
|
-
import { Logger, Plugin, ViteDevServer } from "vite";
|
|
2
|
-
import { LoadConfigSource } from "unconfig";
|
|
3
|
-
import { DefinePage, ExcludeIndexSignature, MaybeCallable, MaybePromise, MaybePromiseCallable, PageMetaDatum, SubPageMetaDatum, UserPageMeta, UserPagesConfig, UserTabBarItem, definePage } from "@uni-helper/uni-pages-types";
|
|
4
|
-
import { FSWatcher } from "chokidar";
|
|
5
|
-
import { SFCDescriptor, SFCParseOptions } from "@vue/compiler-sfc";
|
|
6
|
-
import * as t from "@babel/types";
|
|
7
|
-
import babelGenerator from "@babel/generator";
|
|
8
|
-
import Debug from "debug";
|
|
9
|
-
import fs from "node:fs";
|
|
10
|
-
export * from "@uni-helper/uni-pages-types";
|
|
11
|
-
|
|
12
|
-
//#region \0rolldown/runtime.js
|
|
13
|
-
declare namespace index_d_exports$1 {
|
|
14
|
-
export { defineUniPages };
|
|
15
|
-
}
|
|
16
|
-
import * as import__uni_helper_uni_pages_types from "@uni-helper/uni-pages-types";
|
|
17
|
-
/**
|
|
18
|
-
* Define uni-pages configuration
|
|
19
|
-
* Used in pages.config.ts configuration file to provide type hints and validation
|
|
20
|
-
*
|
|
21
|
-
* @param config - Page configuration object
|
|
22
|
-
* @returns Configuration object
|
|
23
|
-
*/
|
|
24
|
-
declare function defineUniPages(config: UserPagesConfig): UserPagesConfig;
|
|
25
|
-
//#endregion
|
|
26
|
-
//#region src/page.d.ts
|
|
27
|
-
/**
|
|
28
|
-
* Page class representing a Vue page file
|
|
29
|
-
*
|
|
30
|
-
* Responsibilities:
|
|
31
|
-
* 1. Read page file content
|
|
32
|
-
* 2. Parse page metadata defined by definePage macro
|
|
33
|
-
* 3. Provide tabBar configuration information
|
|
34
|
-
* 4. Track page file change status
|
|
35
|
-
*/
|
|
36
|
-
declare class Page {
|
|
37
|
-
/** Page context instance */
|
|
38
|
-
ctx: PageContext;
|
|
39
|
-
/** Page path information containing relative and absolute paths */
|
|
40
|
-
path: PagePath;
|
|
41
|
-
/** Page URI used for pages.json path field */
|
|
42
|
-
uri: string;
|
|
43
|
-
/** Whether the page has changed, used for incremental update judgment */
|
|
44
|
-
changed: boolean;
|
|
45
|
-
/** Raw JSON string of page metadata for change detection */
|
|
46
|
-
private raw;
|
|
47
|
-
/** Parsed page metadata */
|
|
48
|
-
private meta;
|
|
49
|
-
/**
|
|
50
|
-
* Create a page instance
|
|
51
|
-
* @param ctx - Page context instance
|
|
52
|
-
* @param path - Page path information
|
|
53
|
-
*/
|
|
54
|
-
constructor(ctx: PageContext, path: PagePath);
|
|
55
|
-
/**
|
|
56
|
-
* Get page metadata
|
|
57
|
-
* Parse configuration defined by definePage macro and return metadata for pages.json
|
|
58
|
-
*
|
|
59
|
-
* @param forceUpdate - Whether to force update, ignoring cache
|
|
60
|
-
* @returns Page metadata object
|
|
61
|
-
*/
|
|
62
|
-
getPageMeta(forceUpdate?: boolean): Promise<PageMetaDatum>;
|
|
63
|
-
/**
|
|
64
|
-
* Get page tabBar configuration
|
|
65
|
-
* Extract tabBar related configuration from definePage macro
|
|
66
|
-
*
|
|
67
|
-
* @param forceUpdate - Whether to force update, ignoring cache
|
|
68
|
-
* @returns tabBar configuration object, or undefined if page doesn't define tabBar
|
|
69
|
-
*/
|
|
70
|
-
getTabBar(forceUpdate?: boolean): Promise<index_d_exports$1.TabBarItem & {
|
|
71
|
-
index: number;
|
|
72
|
-
} | undefined>;
|
|
73
|
-
/**
|
|
74
|
-
* Check if the page has changed
|
|
75
|
-
* @returns Whether the page has changed
|
|
76
|
-
*/
|
|
77
|
-
hasChanged(): boolean;
|
|
78
|
-
/**
|
|
79
|
-
* Read page file and parse metadata
|
|
80
|
-
* Extract configuration defined by definePage macro from Vue SFC
|
|
81
|
-
*/
|
|
82
|
-
read(): Promise<void>;
|
|
83
|
-
private readPageMetaFromFile;
|
|
84
|
-
}
|
|
85
|
-
/**
|
|
86
|
-
* Parse Vue Single File Component (SFC)
|
|
87
|
-
* Compatible with different versions of @vue/compiler-sfc
|
|
88
|
-
*
|
|
89
|
-
* @param code - Vue SFC source code
|
|
90
|
-
* @param options - Parse options
|
|
91
|
-
* @returns SFC descriptor object
|
|
92
|
-
*/
|
|
93
|
-
declare function parseSFC(code: string, options?: SFCParseOptions): SFCDescriptor;
|
|
94
|
-
/**
|
|
95
|
-
* Try to extract page metadata defined by definePage macro from SFC
|
|
96
|
-
* Support using definePage in script setup or regular script
|
|
97
|
-
*
|
|
98
|
-
* @param sfc - Vue SFC descriptor
|
|
99
|
-
* @returns Page metadata object, or undefined if definePage is not found
|
|
100
|
-
*/
|
|
101
|
-
declare function tryPageMetaFromMacro(sfc: SFCDescriptor): Promise<UserPageMeta | undefined>;
|
|
102
|
-
/**
|
|
103
|
-
* Find definePage macro call in AST
|
|
104
|
-
* Support function expressions, arrow functions and object expressions as arguments
|
|
105
|
-
*
|
|
106
|
-
* @param stmts - AST statement array
|
|
107
|
-
* @param filename - Filename for error reporting
|
|
108
|
-
* @returns definePage call expression, or undefined if not found
|
|
109
|
-
*/
|
|
110
|
-
declare function findMacro(stmts: t.Statement[], filename: string): t.CallExpression | undefined;
|
|
111
|
-
/**
|
|
112
|
-
* Extract all import declarations from AST
|
|
113
|
-
* Used to provide necessary imports when executing definePage arguments
|
|
114
|
-
*
|
|
115
|
-
* @param stmts - AST statement array
|
|
116
|
-
* @returns Import declaration array
|
|
117
|
-
*/
|
|
118
|
-
declare function findImports(stmts: t.Statement[]): t.ImportDeclaration[];
|
|
119
|
-
//#endregion
|
|
120
|
-
//#region src/context.d.ts
|
|
121
|
-
/**
|
|
122
|
-
* Page context class responsible for page scanning, config loading, page metadata merging and pages.json generation
|
|
123
|
-
*
|
|
124
|
-
* Core responsibilities:
|
|
125
|
-
* 1. Scan page directories and collect page files
|
|
126
|
-
* 2. Load user configuration files (pages.config.ts, etc.)
|
|
127
|
-
* 3. Parse page metadata (definePage macro)
|
|
128
|
-
* 4. Merge page configurations and generate pages.json
|
|
129
|
-
* 5. Provide virtual module and HMR support
|
|
130
|
-
*/
|
|
131
|
-
declare class PageContext {
|
|
132
|
-
private _server;
|
|
133
|
-
/** Parsed configuration object from user config file (pages.config.ts) */
|
|
134
|
-
pagesGlobConfig: index_d_exports$1.PagesConfig | undefined;
|
|
135
|
-
/** Source path list of user configuration files */
|
|
136
|
-
pagesConfigSourcePaths: string[];
|
|
137
|
-
/** Main package page map, key is the absolute path of the page file */
|
|
138
|
-
pages: Map<string, Page>;
|
|
139
|
-
/** Sub-package page map, key is the sub-package root directory, value is the page map under that sub-package */
|
|
140
|
-
subPages: Map<string, Map<string, Page>>;
|
|
141
|
-
/** Main package page metadata array for generating pages.json pages field */
|
|
142
|
-
pageMetaData: PageMetaDatum[];
|
|
143
|
-
/** Sub-package page metadata array for generating pages.json subPackages field */
|
|
144
|
-
subPageMetaData: SubPageMetaDatum[];
|
|
145
|
-
/** Generated pages.json file path */
|
|
146
|
-
resolvedPagesJSONPath: string;
|
|
147
|
-
private resolvedPagesJSONIndent?;
|
|
148
|
-
private resolvedPagesJSONNewline?;
|
|
149
|
-
private resolvedPagesJSONEofNewline?;
|
|
150
|
-
/** Original options passed by the user */
|
|
151
|
-
rawOptions: UserOptions;
|
|
152
|
-
/** Project root directory */
|
|
153
|
-
root: string;
|
|
154
|
-
/** Resolved configuration options */
|
|
155
|
-
options: ResolvedOptions;
|
|
156
|
-
logger?: Logger;
|
|
157
|
-
/** Whether to work with vite-plugin-uni-platform plugin */
|
|
158
|
-
withUniPlatform: boolean;
|
|
159
|
-
/** Cached previous pages.json content to avoid redundant writes */
|
|
160
|
-
private lastPagesJson;
|
|
161
|
-
/**
|
|
162
|
-
* Create a PageContext instance
|
|
163
|
-
* @param userOptions - User configuration options
|
|
164
|
-
* @param viteRoot - Vite project root directory, defaults to current working directory
|
|
165
|
-
*/
|
|
166
|
-
constructor(userOptions: UserOptions, viteRoot?: string);
|
|
167
|
-
/**
|
|
168
|
-
* Set the Vite logger
|
|
169
|
-
* @param logger - Vite logger instance
|
|
170
|
-
*/
|
|
171
|
-
setLogger(logger: Logger): void;
|
|
172
|
-
/**
|
|
173
|
-
* Load user page configuration file (e.g. pages.config.ts)
|
|
174
|
-
* Uses unconfig to load configuration, supporting multiple config file formats
|
|
175
|
-
*/
|
|
176
|
-
loadUserPagesConfig(): Promise<void>;
|
|
177
|
-
/**
|
|
178
|
-
* Scan main package page directories and collect all page file paths
|
|
179
|
-
* Scan corresponding directories based on the configured dirs option
|
|
180
|
-
*/
|
|
181
|
-
scanPages(): Promise<void>;
|
|
182
|
-
/**
|
|
183
|
-
* Scan sub-package page directories and collect all sub-package page file paths
|
|
184
|
-
* Scan corresponding directories based on the configured subPackages option
|
|
185
|
-
*/
|
|
186
|
-
scanSubPages(): Promise<void>;
|
|
187
|
-
/**
|
|
188
|
-
* Set up Vite dev server for HMR and file watching
|
|
189
|
-
* @param server - Vite dev server instance
|
|
190
|
-
*/
|
|
191
|
-
setupViteServer(server: ViteDevServer): void;
|
|
192
|
-
/**
|
|
193
|
-
* Set up file watcher to monitor page file and config file changes
|
|
194
|
-
* Automatically update pages.json when page files or config files change
|
|
195
|
-
* @param watcher - chokidar file watcher instance
|
|
196
|
-
*/
|
|
197
|
-
setupWatcher(watcher: FSWatcher): Promise<void>;
|
|
198
|
-
/**
|
|
199
|
-
* Page update callback, triggered when page files or configuration changes
|
|
200
|
-
* Responsible for invalidating virtual modules and notifying the browser to do a full reload
|
|
201
|
-
*/
|
|
202
|
-
onUpdate(): void;
|
|
203
|
-
/**
|
|
204
|
-
* parse pages rules && set page type
|
|
205
|
-
* @param pages page path array
|
|
206
|
-
* @param type page type
|
|
207
|
-
* @param overrides custom page config
|
|
208
|
-
* @returns pages rules
|
|
209
|
-
*/
|
|
210
|
-
parsePages(pages: Map<string, Page>, type: 'main' | 'sub', overrides?: PageMetaDatum[]): Promise<PageMetaDatum[]>;
|
|
211
|
-
/**
|
|
212
|
-
* set home page
|
|
213
|
-
* @param result pages rules array
|
|
214
|
-
* @returns pages rules
|
|
215
|
-
*/
|
|
216
|
-
setHomePage(result: PageMetaDatum[]): PageMetaDatum[];
|
|
217
|
-
/**
|
|
218
|
-
* Merge main package page metadata
|
|
219
|
-
* Filter out pages belonging to sub-packages, then parse page metadata and merge user configuration
|
|
220
|
-
*/
|
|
221
|
-
mergePageMetaData(): Promise<void>;
|
|
222
|
-
/**
|
|
223
|
-
* Merge sub-package page metadata
|
|
224
|
-
* Parse page metadata for each sub-package and handle sub-package configuration inheritance
|
|
225
|
-
* Preserves sub-package level properties like plugins from user config
|
|
226
|
-
*/
|
|
227
|
-
mergeSubPageMetaData(): Promise<void>;
|
|
228
|
-
/**
|
|
229
|
-
* Update pages.json file
|
|
230
|
-
* This is the core method responsible for coordinating the entire page configuration generation flow:
|
|
231
|
-
* 1. Check file changes (if filepath is specified)
|
|
232
|
-
* 2. Load user configuration
|
|
233
|
-
* 3. Scan page files
|
|
234
|
-
* 4. Merge page metadata
|
|
235
|
-
* 5. Generate and write pages.json
|
|
236
|
-
* @param filepath - Changed file path for incremental update judgment
|
|
237
|
-
* @returns Whether pages.json was successfully updated
|
|
238
|
-
*/
|
|
239
|
-
updatePagesJSON(filepath?: string): Promise<boolean>;
|
|
240
|
-
/**
|
|
241
|
-
* Generate virtual module content
|
|
242
|
-
* Returns JavaScript code containing pages and subPackages exports
|
|
243
|
-
* @returns Virtual module code string
|
|
244
|
-
*/
|
|
245
|
-
virtualModule(): string;
|
|
246
|
-
/**
|
|
247
|
-
* Resolve main package route data to JSON string
|
|
248
|
-
* @returns JSON string of main package page metadata
|
|
249
|
-
*/
|
|
250
|
-
resolveRoutes(): string;
|
|
251
|
-
/**
|
|
252
|
-
* Resolve sub-package route data to JSON string
|
|
253
|
-
* @returns JSON string of sub-package page metadata
|
|
254
|
-
*/
|
|
255
|
-
resolveSubRoutes(): string;
|
|
256
|
-
/**
|
|
257
|
-
* Resolve tabBar configuration
|
|
258
|
-
* Merges page-defined tabBar items with config-defined tabBar
|
|
259
|
-
* @returns Merged tabBar configuration object, or undefined if no tabBar exists
|
|
260
|
-
*/
|
|
261
|
-
resolveTabBar(): Promise<index_d_exports$1.TabBar | undefined>;
|
|
262
|
-
/**
|
|
263
|
-
* Generate TypeScript declaration file
|
|
264
|
-
* Generate type definitions for page paths to provide type hints during navigation
|
|
265
|
-
*/
|
|
266
|
-
generateDeclaration(): Promise<void> | undefined;
|
|
267
|
-
private genratePagesJSON;
|
|
268
|
-
private readInfoFromPagesJSON;
|
|
269
|
-
private getIndent;
|
|
270
|
-
private getNewline;
|
|
271
|
-
private getEndOfLine;
|
|
272
|
-
}
|
|
273
|
-
//#endregion
|
|
274
|
-
//#region src/utils.d.ts
|
|
275
|
-
/**
|
|
276
|
-
* Invalidate virtual module to trigger HMR update
|
|
277
|
-
* When page configuration changes, the virtual module needs to be invalidated to regenerate content
|
|
278
|
-
*
|
|
279
|
-
* @param server - Vite dev server instance
|
|
280
|
-
*/
|
|
281
|
-
declare function invalidatePagesModule(server: ViteDevServer): void;
|
|
282
|
-
/**
|
|
283
|
-
* Debug logging utility
|
|
284
|
-
* Uses debug package for leveled log output
|
|
285
|
-
* Enable via environment variable DEBUG=vite-plugin-uni-pages:*
|
|
286
|
-
*/
|
|
287
|
-
declare const debug: {
|
|
288
|
-
/** HMR related logs */hmr: Debug.Debugger; /** Configuration options related logs */
|
|
289
|
-
options: Debug.Debugger; /** Main package page scanning logs */
|
|
290
|
-
pages: Debug.Debugger; /** Sub-package page scanning logs */
|
|
291
|
-
subPages: Debug.Debugger; /** Error logs */
|
|
292
|
-
error: Debug.Debugger; /** Cache related logs */
|
|
293
|
-
cache: Debug.Debugger; /** Declaration file generation logs */
|
|
294
|
-
declaration: Debug.Debugger; /** definePage macro parsing logs */
|
|
295
|
-
definePage: Debug.Debugger;
|
|
296
|
-
};
|
|
297
|
-
/**
|
|
298
|
-
* Convert file extensions array to glob pattern
|
|
299
|
-
* @param extensions - File extensions array
|
|
300
|
-
* @returns Glob pattern string
|
|
301
|
-
*/
|
|
302
|
-
declare function extsToGlob(extensions: string[]): string;
|
|
303
|
-
/**
|
|
304
|
-
* Check if file is a target page file
|
|
305
|
-
* Determine if the file extension is in the supported page file types list
|
|
306
|
-
*
|
|
307
|
-
* @param path - File path
|
|
308
|
-
* @returns Whether it's a target file
|
|
309
|
-
*/
|
|
310
|
-
declare function isTargetFile(path: string): boolean;
|
|
311
|
-
/**
|
|
312
|
-
* merge page meta data array by path and assign style
|
|
313
|
-
* @param pageMetaData page meta data array
|
|
314
|
-
* TODO: support merge middleware
|
|
315
|
-
*/
|
|
316
|
-
declare function mergePageMetaDataArray(pageMetaData: PageMetaDatum[]): PageMetaDatum[];
|
|
317
|
-
/**
|
|
318
|
-
* Convert TypeScript / JavaScript script code to object/function
|
|
319
|
-
*
|
|
320
|
-
* @param options - Configuration required for script execution
|
|
321
|
-
* @param options.imports - List of module import statements to include
|
|
322
|
-
* @param options.code - TypeScript code content to execute
|
|
323
|
-
* @param options.filename - Script filename for error location and context
|
|
324
|
-
* @returns Script execution result, if export is a function then execute and return its return value
|
|
325
|
-
*/
|
|
326
|
-
declare function parseCode(options: {
|
|
327
|
-
imports: string[];
|
|
328
|
-
code: string;
|
|
329
|
-
filename: string;
|
|
330
|
-
}): Promise<any>;
|
|
331
|
-
/**
|
|
332
|
-
* Async sleep function
|
|
333
|
-
* @param ms - Sleep duration in milliseconds
|
|
334
|
-
* @returns Promise object
|
|
335
|
-
*/
|
|
336
|
-
declare function sleep(ms: number): Promise<unknown>;
|
|
337
|
-
/** Babel code generator for converting AST back to code */
|
|
338
|
-
declare const babelGenerate: typeof babelGenerator;
|
|
339
|
-
//#endregion
|
|
340
|
-
//#region src/types.d.ts
|
|
341
|
-
/** Debug log type, corresponding to methods in the debug object */
|
|
342
|
-
type debugType = keyof typeof debug;
|
|
343
|
-
/** Configuration source type, supports string path or unconfig LoadConfigSource object */
|
|
344
|
-
type ConfigSource = string | LoadConfigSource<index_d_exports$1.PagesConfig> | LoadConfigSource<index_d_exports$1.PagesConfig>[];
|
|
345
|
-
/**
|
|
346
|
-
* Plugin configuration options interface
|
|
347
|
-
* Defines all configuration options that users can pass in
|
|
348
|
-
*/
|
|
349
|
-
interface Options {
|
|
350
|
-
/**
|
|
351
|
-
* Generate TypeScript declaration for pages path
|
|
352
|
-
*
|
|
353
|
-
* Accept boolean or a path related to project root
|
|
354
|
-
*
|
|
355
|
-
* @default true
|
|
356
|
-
*/
|
|
357
|
-
dts?: boolean | string;
|
|
358
|
-
/**
|
|
359
|
-
* Load from configs files
|
|
360
|
-
*
|
|
361
|
-
* @default 'pages.config.(ts|mts|cts|js|cjs|mjs|json)',
|
|
362
|
-
*/
|
|
363
|
-
configSource: ConfigSource;
|
|
364
|
-
/**
|
|
365
|
-
* The default application entry page is the home page
|
|
366
|
-
* @default 'pages/index' or 'pages/index/index'
|
|
367
|
-
*/
|
|
368
|
-
homePage: string;
|
|
369
|
-
/**
|
|
370
|
-
* Whether to merge pages in pages.json
|
|
371
|
-
* @default true
|
|
372
|
-
*/
|
|
373
|
-
mergePages: boolean;
|
|
374
|
-
/**
|
|
375
|
-
* Paths to the directory to search for page components.
|
|
376
|
-
* @default 'src/pages'
|
|
377
|
-
*/
|
|
378
|
-
dir: string;
|
|
379
|
-
/**
|
|
380
|
-
* Sub-package page directories for uni-app sub-package loading
|
|
381
|
-
*
|
|
382
|
-
* Supports string format (directory path) or object format (custom root in pages.json)
|
|
383
|
-
*
|
|
384
|
-
* In monorepo projects, pages may be located outside the project root.
|
|
385
|
-
* Use object format to specify a custom root that appears in pages.json,
|
|
386
|
-
* avoiding '..' in the generated root path.
|
|
387
|
-
*
|
|
388
|
-
* @see https://github.com/uni-helper/vite-plugin-uni-pages/issues/271
|
|
389
|
-
* @default []
|
|
390
|
-
*/
|
|
391
|
-
subPackages: (string | SubPackageConfig)[];
|
|
392
|
-
/**
|
|
393
|
-
* pages.json dir
|
|
394
|
-
* @default "src"
|
|
395
|
-
*/
|
|
396
|
-
outDir: string;
|
|
397
|
-
/**
|
|
398
|
-
* pages to be excluded, based on [tinyglobby ignore option](https://superchupu.dev/tinyglobby/documentation#ignore)
|
|
399
|
-
* @default []
|
|
400
|
-
*/
|
|
401
|
-
exclude: string[];
|
|
402
|
-
/**
|
|
403
|
-
* minify the `pages.json`
|
|
404
|
-
* @default false
|
|
405
|
-
*/
|
|
406
|
-
minify: boolean;
|
|
407
|
-
/**
|
|
408
|
-
* enable debug log
|
|
409
|
-
*/
|
|
410
|
-
debug: boolean | debugType;
|
|
411
|
-
onBeforeLoadUserConfig: (ctx: PageContext) => void;
|
|
412
|
-
onAfterLoadUserConfig: (ctx: PageContext) => void;
|
|
413
|
-
onBeforeScanPages: (ctx: PageContext) => void;
|
|
414
|
-
onAfterScanPages: (ctx: PageContext) => void;
|
|
415
|
-
onBeforeMergePageMetaData: (ctx: PageContext) => void;
|
|
416
|
-
onAfterMergePageMetaData: (ctx: PageContext) => void;
|
|
417
|
-
onBeforeWriteFile: (ctx: PageContext) => void;
|
|
418
|
-
onAfterWriteFile: (ctx: PageContext) => void;
|
|
419
|
-
}
|
|
420
|
-
/** User configuration options type, all options are optional */
|
|
421
|
-
type UserOptions = Partial<Options>;
|
|
422
|
-
/**
|
|
423
|
-
* Resolved configuration options interface
|
|
424
|
-
* Configuration processed by resolveOptions, all paths resolved to absolute paths
|
|
425
|
-
*/
|
|
426
|
-
interface ResolvedOptions extends Omit<Options, 'dir' | 'homePage' | 'configSource' | 'dts' | 'subPackages'> {
|
|
427
|
-
/**
|
|
428
|
-
* Resolves to the `root` value from Vite config.
|
|
429
|
-
* @default config.root
|
|
430
|
-
*/
|
|
431
|
-
root: string;
|
|
432
|
-
dts: string | false;
|
|
433
|
-
/**
|
|
434
|
-
* Resolved page dirs
|
|
435
|
-
*/
|
|
436
|
-
dirs: string[];
|
|
437
|
-
/**
|
|
438
|
-
* Resolved entry page
|
|
439
|
-
*/
|
|
440
|
-
homePage: string[];
|
|
441
|
-
configSource: LoadConfigSource<index_d_exports$1.PagesConfig>[];
|
|
442
|
-
/**
|
|
443
|
-
* Resolved sub-package directories
|
|
444
|
-
*/
|
|
445
|
-
subPackages: string[];
|
|
446
|
-
/**
|
|
447
|
-
* Custom root mapping for sub-packages (dir -> root)
|
|
448
|
-
* Used for monorepo support to specify custom root paths in pages.json
|
|
449
|
-
*/
|
|
450
|
-
subPackageRootMap: Map<string, string>;
|
|
451
|
-
}
|
|
452
|
-
/**
|
|
453
|
-
* Sub-package configuration interface
|
|
454
|
-
* Allows customizing the root path in pages.json for monorepo support
|
|
455
|
-
*
|
|
456
|
-
* In monorepo projects, pages may be located outside the project root (e.g., ../../packages/login/src/pages).
|
|
457
|
-
* By default, the plugin generates root paths with '..', which uni-app does not support.
|
|
458
|
-
* Use this config to specify a custom root that appears in pages.json instead.
|
|
459
|
-
*
|
|
460
|
-
* @example
|
|
461
|
-
* ```ts
|
|
462
|
-
* subPackages: [
|
|
463
|
-
* {
|
|
464
|
-
* dir: '../../packages/login/src/pages', // Physical directory to scan
|
|
465
|
-
* root: 'packages/login/src/pages', // Custom root in pages.json
|
|
466
|
-
* }
|
|
467
|
-
* ]
|
|
468
|
-
* ```
|
|
469
|
-
*/
|
|
470
|
-
interface SubPackageConfig {
|
|
471
|
-
/** Physical directory path to scan for page files */
|
|
472
|
-
dir: string;
|
|
473
|
-
/** Custom root path that appears in pages.json subPackages.root */
|
|
474
|
-
root: string;
|
|
475
|
-
}
|
|
476
|
-
/**
|
|
477
|
-
* Page path information interface
|
|
478
|
-
* Contains relative and absolute paths of page files
|
|
479
|
-
*/
|
|
480
|
-
interface PagePath {
|
|
481
|
-
/** Path relative to the output directory */
|
|
482
|
-
relativePath: string;
|
|
483
|
-
/** Absolute path of the page file */
|
|
484
|
-
absolutePath: string;
|
|
485
|
-
}
|
|
486
|
-
//#endregion
|
|
487
|
-
//#region src/constant.d.ts
|
|
488
|
-
/** Virtual module identifier for Vite module resolution */
|
|
489
|
-
declare const MODULE_ID_VIRTUAL = "virtual:uni-pages";
|
|
490
|
-
/** Resolved virtual module identifier with \0 prefix to avoid conflicts with other modules */
|
|
491
|
-
declare const RESOLVED_MODULE_ID_VIRTUAL = "\0virtual:uni-pages";
|
|
492
|
-
/** Output filename, the uni-app page configuration file */
|
|
493
|
-
declare const OUTPUT_NAME = "pages.json";
|
|
494
|
-
/** Supported page file extensions */
|
|
495
|
-
declare const FILE_EXTENSIONS: string[];
|
|
496
|
-
//#endregion
|
|
497
|
-
//#region src/files.d.ts
|
|
498
|
-
/**
|
|
499
|
-
* Resolves the files that are valid pages for the given context.
|
|
500
|
-
*/
|
|
501
|
-
declare function getPageFiles(path: string, options: ResolvedOptions): string[];
|
|
502
|
-
/**
|
|
503
|
-
* Check the pages.json file at the specified path, create an empty pages.json file if it doesn't exist or is not a valid file
|
|
504
|
-
* @param path - File path to check
|
|
505
|
-
* @returns boolean - Whether the operation was successful
|
|
506
|
-
*/
|
|
507
|
-
declare function checkPagesJsonFileSync(path: fs.PathLike): boolean;
|
|
508
|
-
/**
|
|
509
|
-
* Run a task while holding an exclusive file lock.
|
|
510
|
-
*
|
|
511
|
-
* Unlike {@link writeFileWithLock}, this protects the whole read-modify-write
|
|
512
|
-
* critical section. The lock is held from the moment `task` starts until it
|
|
513
|
-
* resolves, so concurrent processes cannot observe or overwrite a half-written
|
|
514
|
-
* state. This is required by pages.json generation, where the new content
|
|
515
|
-
* depends on the current content (other platforms' `#ifdef` blocks).
|
|
516
|
-
*
|
|
517
|
-
* @param path - File path used as the lock target
|
|
518
|
-
* @param task - Async work to run inside the lock; return value is forwarded
|
|
519
|
-
* @param retry - Number of retries when lock acquisition fails, defaults to 3
|
|
520
|
-
* @returns The value resolved by `task`, or `undefined` if the lock could not be acquired
|
|
521
|
-
*/
|
|
522
|
-
declare function withFileLock<T>(path: string, task: () => Promise<T>, retry?: number): Promise<T | undefined>;
|
|
523
|
-
/**
|
|
524
|
-
* Safely write file using file lock
|
|
525
|
-
* Avoid data corruption caused by concurrent writes through file lock
|
|
526
|
-
* Use atomic write to ensure file write integrity
|
|
527
|
-
*
|
|
528
|
-
* Note: this only makes the *write* atomic. Callers that need to read the
|
|
529
|
-
* current content before computing the new one must use {@link withFileLock}
|
|
530
|
-
* so the read and write belong to the same critical section.
|
|
531
|
-
*
|
|
532
|
-
* @param path - File path
|
|
533
|
-
* @param content - File content
|
|
534
|
-
* @param retry - Number of retries when lock acquisition fails, defaults to 3
|
|
535
|
-
*/
|
|
536
|
-
declare function writeFileWithLock(path: string, content: string, retry?: number): Promise<void | undefined>;
|
|
537
|
-
//#endregion
|
|
538
|
-
//#region src/options.d.ts
|
|
539
|
-
/**
|
|
540
|
-
* Resolve user configuration options
|
|
541
|
-
* Merge user-provided configuration with default values and handle path resolution
|
|
542
|
-
*
|
|
543
|
-
* @param userOptions - User configuration options
|
|
544
|
-
* @param viteRoot - Vite project root directory
|
|
545
|
-
* @returns Resolved configuration options
|
|
546
|
-
*/
|
|
547
|
-
declare function resolveOptions(userOptions: UserOptions, viteRoot?: string): ResolvedOptions;
|
|
548
|
-
/**
|
|
549
|
-
* Resolves the page dirs for its for its given globs
|
|
550
|
-
*/
|
|
551
|
-
declare function resolvePageDirs(dir: string, root: string, exclude: string[]): string[];
|
|
552
|
-
declare namespace index_d_exports {
|
|
553
|
-
export { ConfigSource, DefinePage, ExcludeIndexSignature, FILE_EXTENSIONS, MODULE_ID_VIRTUAL, MaybeCallable, MaybePromise, MaybePromiseCallable, OUTPUT_NAME, Options, Page, PageContext, PageMetaDatum, PagePath, RESOLVED_MODULE_ID_VIRTUAL, ResolvedOptions, SubPackageConfig, SubPageMetaDatum, UserOptions, UserPageMeta, UserTabBarItem, VitePluginUniPages, babelGenerate, checkPagesJsonFileSync, debug, debugType, VitePluginUniPages as default, definePage, defineUniPages, extsToGlob, findImports, findMacro, getPageFiles, invalidatePagesModule, isTargetFile, mergePageMetaDataArray, parseCode, parseSFC, resolveOptions, resolvePageDirs, sleep, tryPageMetaFromMacro, withFileLock, writeFileWithLock };
|
|
554
|
-
}
|
|
555
|
-
/**
|
|
556
|
-
* vite-plugin-uni-pages plugin main entry
|
|
557
|
-
*
|
|
558
|
-
* Automatically scan page directories and generate pages.json configuration file
|
|
559
|
-
* Support definePage macro for defining page metadata
|
|
560
|
-
* Support multi-platform conditional compilation
|
|
561
|
-
* Support sub-package configuration
|
|
562
|
-
* Support TypeScript declaration file generation
|
|
563
|
-
*
|
|
564
|
-
* @param userOptions - User configuration options
|
|
565
|
-
* @returns Vite plugin instance
|
|
566
|
-
*/
|
|
567
|
-
declare function VitePluginUniPages(userOptions?: UserOptions): Plugin;
|
|
568
|
-
//#endregion
|
|
569
|
-
export { ConfigSource, type DefinePage, type ExcludeIndexSignature, FILE_EXTENSIONS, MODULE_ID_VIRTUAL, type MaybeCallable, type MaybePromise, type MaybePromiseCallable, OUTPUT_NAME, Options, Page, PageContext, type PageMetaDatum, PagePath, RESOLVED_MODULE_ID_VIRTUAL, ResolvedOptions, SubPackageConfig, type SubPageMetaDatum, UserOptions, type UserPageMeta, type UserTabBarItem, VitePluginUniPages, VitePluginUniPages as default, babelGenerate, checkPagesJsonFileSync, debug, debugType, type definePage, defineUniPages, extsToGlob, findImports, findMacro, getPageFiles, invalidatePagesModule, isTargetFile, mergePageMetaDataArray, parseCode, parseSFC, resolveOptions, resolvePageDirs, sleep, tryPageMetaFromMacro, withFileLock, writeFileWithLock };
|
package/index.d.ts
DELETED