@univa/core 0.0.7 → 0.0.9
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 +441 -435
- package/THIRD-PARTY-NOTICES +216 -0
- package/dist/global.d.ts +4 -0
- package/dist/index.cjs +175 -38
- package/dist/index.d.cts +33 -0
- package/dist/index.d.ts +33 -0
- package/dist/index.js +168 -31
- package/dist/use.cjs +46 -0
- package/dist/use.d.cts +9 -0
- package/dist/use.d.ts +9 -0
- package/dist/use.js +19 -0
- package/package.json +37 -22
package/dist/index.d.ts
CHANGED
|
@@ -2,6 +2,7 @@ import { PagesConfig } from '@uni-helper/uni-pages-types';
|
|
|
2
2
|
export { Condition, EasyCom, GlobalStyle, PageMetaDatum, PagesConfig, SubPackage, TabBar, TabBarItem } from '@uni-helper/uni-pages-types';
|
|
3
3
|
import { Options } from '@uni-helper/vite-plugin-uni-components';
|
|
4
4
|
export { ComponentInfo, ComponentResolver, Options as ComponentsOptions, ResolvedOptions as ComponentsResolvedOptions, ImportInfo, default as VitePluginUniComponents, camelCase, kebabCase, pascalCase } from '@uni-helper/vite-plugin-uni-components';
|
|
5
|
+
import { UserManifestConfig } from '@uni-helper/vite-plugin-uni-manifest';
|
|
5
6
|
import { UserOptions } from '@uni-helper/vite-plugin-uni-pages';
|
|
6
7
|
export { PageContext, PagePath, UserOptions as PagesPluginOptions, ResolvedOptions as PagesResolvedOptions, SubPageMetaDatum, VitePluginUniPages, definePage } from '@uni-helper/vite-plugin-uni-pages';
|
|
7
8
|
import { Options as Options$1 } from 'unplugin-auto-import/types';
|
|
@@ -12,6 +13,32 @@ export { VitePluginUniLayouts } from '@uni-helper/vite-plugin-uni-layouts';
|
|
|
12
13
|
export { default as UniKuRoot } from '@uni-ku/root';
|
|
13
14
|
export { default as AutoImport } from 'unplugin-auto-import/vite';
|
|
14
15
|
|
|
16
|
+
interface ManifestOptions {
|
|
17
|
+
/**
|
|
18
|
+
* minify the `manifest.json`
|
|
19
|
+
* @default false
|
|
20
|
+
*/
|
|
21
|
+
minify: boolean;
|
|
22
|
+
/**
|
|
23
|
+
* insert newline at the end of the `manifest.json`
|
|
24
|
+
* @default false
|
|
25
|
+
*/
|
|
26
|
+
insertFinalNewline: boolean;
|
|
27
|
+
/**
|
|
28
|
+
* Resolve configuration from this working directory.
|
|
29
|
+
* @default process.env.VITE_ROOT_DIR
|
|
30
|
+
*/
|
|
31
|
+
cwd?: string;
|
|
32
|
+
/**
|
|
33
|
+
* Merge the manifest config with the default config.
|
|
34
|
+
* @default false
|
|
35
|
+
*/
|
|
36
|
+
merge?: boolean;
|
|
37
|
+
}
|
|
38
|
+
/** User-facing options — all fields are optional. */
|
|
39
|
+
interface UserManifestOptions extends Partial<ManifestOptions> {
|
|
40
|
+
}
|
|
41
|
+
|
|
15
42
|
/**
|
|
16
43
|
* Univa 类型定义统一导出
|
|
17
44
|
*
|
|
@@ -115,6 +142,8 @@ interface UnivaOverrides {
|
|
|
115
142
|
autoImport?: Options$1;
|
|
116
143
|
/** unocss/vite 完整选项 */
|
|
117
144
|
unocss?: UnoCSSOptions;
|
|
145
|
+
/** @uni-helper/vite-plugin-uni-manifest 完整选项 */
|
|
146
|
+
manifest?: UserManifestOptions;
|
|
118
147
|
}
|
|
119
148
|
/**
|
|
120
149
|
* Univa 统一配置接口(工程级约定)
|
|
@@ -124,6 +153,8 @@ interface UnivaOverrides {
|
|
|
124
153
|
interface UnivaOptions {
|
|
125
154
|
/** 源码目录,相对 Vite root,默认 'src' */
|
|
126
155
|
srcDir?: string;
|
|
156
|
+
/** 开启调试日志,默认 false */
|
|
157
|
+
debug?: boolean;
|
|
127
158
|
/** 目录约定,相对 srcDir */
|
|
128
159
|
dirs?: UnivaDirs;
|
|
129
160
|
/** 自动导入配置 */
|
|
@@ -137,6 +168,8 @@ interface UnivaOptions {
|
|
|
137
168
|
* 注意:pages / subPackages 由目录扫描自动填充,请勿在此手写。
|
|
138
169
|
*/
|
|
139
170
|
pages?: Partial<PagesConfig>;
|
|
171
|
+
/** 应用级 manifest.json 配置 */
|
|
172
|
+
manifest?: Partial<UserManifestConfig>;
|
|
140
173
|
/** 底层插件逃生口(覆盖融合层默认,高级用户使用) */
|
|
141
174
|
overrides?: UnivaOverrides;
|
|
142
175
|
}
|
package/dist/index.js
CHANGED
|
@@ -14,6 +14,7 @@ import AutoImport from "unplugin-auto-import/vite";
|
|
|
14
14
|
// src/constant.ts
|
|
15
15
|
var ID = "univa";
|
|
16
16
|
var UNIVA_DIR_NAME = `.${ID}`;
|
|
17
|
+
var ROOT_NAME = `${ID}.root`;
|
|
17
18
|
|
|
18
19
|
// src/utils/fs.ts
|
|
19
20
|
import { existsSync, mkdirSync } from "fs";
|
|
@@ -32,9 +33,20 @@ function ensureUnivaDir(cwd) {
|
|
|
32
33
|
return dir;
|
|
33
34
|
}
|
|
34
35
|
|
|
36
|
+
// src/utils/logger.ts
|
|
37
|
+
var debugMode = false;
|
|
38
|
+
function setDebug(enabled) {
|
|
39
|
+
debugMode = enabled;
|
|
40
|
+
}
|
|
41
|
+
function log(message, ...args) {
|
|
42
|
+
if (debugMode) {
|
|
43
|
+
console.log(`[${ID}]`, message, ...args);
|
|
44
|
+
}
|
|
45
|
+
}
|
|
46
|
+
|
|
35
47
|
// src/plugins/context.ts
|
|
36
|
-
import { existsSync as
|
|
37
|
-
import { join as
|
|
48
|
+
import { existsSync as existsSync4, readFileSync as readFileSync3, writeFileSync as writeFileSync3 } from "fs";
|
|
49
|
+
import { join as join4 } from "path";
|
|
38
50
|
import { slash } from "@antfu/utils";
|
|
39
51
|
import { loadConfig } from "c12";
|
|
40
52
|
import { createJiti } from "jiti";
|
|
@@ -48,12 +60,115 @@ var mergeWithArrayOverride = createDefu((originObj, key, updates) => {
|
|
|
48
60
|
}
|
|
49
61
|
});
|
|
50
62
|
|
|
51
|
-
// src/plugins/
|
|
63
|
+
// src/plugins/manifest.ts
|
|
52
64
|
import { existsSync as existsSync2, readFileSync, writeFileSync } from "fs";
|
|
53
|
-
import { join as join2 } from "path";
|
|
65
|
+
import { join as join2, resolve } from "path";
|
|
66
|
+
import process2 from "process";
|
|
67
|
+
import { ensureManifestJsonExists } from "@uni-helper/vite-plugin-uni-manifest";
|
|
68
|
+
import { watchConfig } from "c12";
|
|
69
|
+
import { normalizePath } from "vite";
|
|
70
|
+
function resolveOptions(userOptions) {
|
|
71
|
+
return {
|
|
72
|
+
minify: false,
|
|
73
|
+
insertFinalNewline: false,
|
|
74
|
+
cwd: process2.env.VITE_ROOT_DIR,
|
|
75
|
+
merge: true,
|
|
76
|
+
...userOptions
|
|
77
|
+
};
|
|
78
|
+
}
|
|
79
|
+
function writeManifestJson(config = {}, opts) {
|
|
80
|
+
const path = resolveManifestJsonPath();
|
|
81
|
+
let mergeContent = {};
|
|
82
|
+
if (opts?.merge && existsSync2(path)) {
|
|
83
|
+
try {
|
|
84
|
+
const content2 = readFileSync(path, "utf-8");
|
|
85
|
+
mergeContent = JSON.parse(content2);
|
|
86
|
+
} catch (error) {
|
|
87
|
+
log(`manifest.json parse error: ${error}`);
|
|
88
|
+
}
|
|
89
|
+
}
|
|
90
|
+
const content = JSON.stringify(opts?.merge ? mergeWithArrayOverride(config, mergeContent) : config, null, opts?.minify ? 0 : 2) + (opts?.insertFinalNewline ? "\n" : "");
|
|
91
|
+
if (existsSync2(path) && readFileSync(path, "utf-8") === content) {
|
|
92
|
+
return;
|
|
93
|
+
}
|
|
94
|
+
writeFileSync(path, content);
|
|
95
|
+
}
|
|
96
|
+
function resolveManifestJsonPath() {
|
|
97
|
+
return normalizePath(
|
|
98
|
+
resolve(process2.env.UNI_INPUT_DIR || `${process2.cwd()}/src`, "manifest.json")
|
|
99
|
+
);
|
|
100
|
+
}
|
|
101
|
+
var ManifestContext = class {
|
|
102
|
+
options;
|
|
103
|
+
unwatch;
|
|
104
|
+
constructor(options) {
|
|
105
|
+
this.options = resolveOptions(options);
|
|
106
|
+
}
|
|
107
|
+
/**
|
|
108
|
+
* Start watching config sources and perform initial write.
|
|
109
|
+
* Must be called after construction.
|
|
110
|
+
*/
|
|
111
|
+
async setup() {
|
|
112
|
+
log(`manifest cwd: ${this.options.cwd}`);
|
|
113
|
+
const { config, unwatch } = await watchConfig({
|
|
114
|
+
cwd: this.options.cwd,
|
|
115
|
+
name: "manifest",
|
|
116
|
+
rcFile: false,
|
|
117
|
+
packageJson: false,
|
|
118
|
+
onUpdate: (config2) => {
|
|
119
|
+
writeManifestJson(config2.newConfig.config, this.options);
|
|
120
|
+
}
|
|
121
|
+
});
|
|
122
|
+
writeManifestJson(config, this.options);
|
|
123
|
+
this.unwatch = unwatch;
|
|
124
|
+
}
|
|
125
|
+
};
|
|
126
|
+
function VitePluginUniManifest(userOptions = {}) {
|
|
127
|
+
let ctx;
|
|
128
|
+
return {
|
|
129
|
+
name: "vite-plugin-uni-manifest",
|
|
130
|
+
// Run before other plugins to ensure manifest.json is ready
|
|
131
|
+
enforce: "pre",
|
|
132
|
+
async configResolved() {
|
|
133
|
+
ensureManifestJsonExists();
|
|
134
|
+
ctx = new ManifestContext(userOptions);
|
|
135
|
+
await ctx.setup();
|
|
136
|
+
},
|
|
137
|
+
buildEnd: () => ctx?.unwatch()
|
|
138
|
+
};
|
|
139
|
+
}
|
|
140
|
+
function generateManifestConfigContent(content = {}) {
|
|
141
|
+
return `// Auto-generated by @univa/core
|
|
142
|
+
export default ${JSON.stringify(content, null, 2)}
|
|
143
|
+
`;
|
|
144
|
+
}
|
|
145
|
+
function generateManifestConfigFile(content = {}, root) {
|
|
146
|
+
const configPath = getManifestConfigPath(root);
|
|
147
|
+
const newContent = generateManifestConfigContent(content);
|
|
148
|
+
if (existsSync2(configPath)) {
|
|
149
|
+
const existingContent = readFileSync(configPath, "utf-8");
|
|
150
|
+
if (existingContent === newContent) {
|
|
151
|
+
return;
|
|
152
|
+
}
|
|
153
|
+
}
|
|
154
|
+
writeFileSync(configPath, newContent, "utf-8");
|
|
155
|
+
}
|
|
156
|
+
function getManifestConfigPath(root) {
|
|
157
|
+
return join2(getUnivaDir(root), "manifest.config.ts");
|
|
158
|
+
}
|
|
159
|
+
function createManifestPlugin(userOptions = {}) {
|
|
160
|
+
return VitePluginUniManifest({
|
|
161
|
+
cwd: join2(process2.env.VITE_ROOT_DIR || "", UNIVA_DIR_NAME),
|
|
162
|
+
...userOptions
|
|
163
|
+
});
|
|
164
|
+
}
|
|
165
|
+
|
|
166
|
+
// src/plugins/pages.ts
|
|
167
|
+
import { existsSync as existsSync3, readFileSync as readFileSync2, writeFileSync as writeFileSync2 } from "fs";
|
|
168
|
+
import { join as join3 } from "path";
|
|
54
169
|
import { VitePluginUniPages } from "@uni-helper/vite-plugin-uni-pages";
|
|
55
170
|
function getPagesConfigPath(root) {
|
|
56
|
-
return
|
|
171
|
+
return join3(getUnivaDir(root), "pages-config.ts");
|
|
57
172
|
}
|
|
58
173
|
function generatePagesConfigContent(content) {
|
|
59
174
|
const { pages, subPackages, ...rest } = content;
|
|
@@ -67,13 +182,13 @@ export default ${JSON.stringify(rest, null, 2)}
|
|
|
67
182
|
function generatePagesConfigFile(content, root) {
|
|
68
183
|
const pagesConfigPath = getPagesConfigPath(root);
|
|
69
184
|
const newContent = generatePagesConfigContent(content);
|
|
70
|
-
if (
|
|
71
|
-
const existingContent =
|
|
185
|
+
if (existsSync3(pagesConfigPath)) {
|
|
186
|
+
const existingContent = readFileSync2(pagesConfigPath, "utf-8");
|
|
72
187
|
if (existingContent === newContent) {
|
|
73
188
|
return;
|
|
74
189
|
}
|
|
75
190
|
}
|
|
76
|
-
|
|
191
|
+
writeFileSync2(pagesConfigPath, newContent, "utf-8");
|
|
77
192
|
}
|
|
78
193
|
function createPagesPlugin(pluginOptions) {
|
|
79
194
|
const result = VitePluginUniPages({
|
|
@@ -86,23 +201,11 @@ function createPagesPlugin(pluginOptions) {
|
|
|
86
201
|
}
|
|
87
202
|
|
|
88
203
|
// src/plugins/context.ts
|
|
89
|
-
var DEFAULT_ROOT_FILE_NAME = "App.ku.vue";
|
|
90
204
|
var APP_KU_VUE_TEMPLATE = `<!-- Auto-generated by @univa/core -->
|
|
91
|
-
<!-- UniKuRoot \u865A\u62DF\u6839\u7EC4\u4EF6\uFF0C\u53EF\u5728\u6B64\u6DFB\u52A0\u5168\u5C40\u7EC4\u4EF6\uFF08\u5982 Toast\u3001ConfigProvider \u7B49\uFF09 -->
|
|
92
205
|
<template>
|
|
93
206
|
<KuRootView />
|
|
94
207
|
</template>
|
|
95
208
|
`;
|
|
96
|
-
function ensureRootComponent(config, root) {
|
|
97
|
-
const srcDir = config?.srcDir || "src";
|
|
98
|
-
const rootFileName = config?.overrides?.root?.rootFileName || DEFAULT_ROOT_FILE_NAME;
|
|
99
|
-
const rootComponentPath = join3(root, srcDir, rootFileName);
|
|
100
|
-
if (existsSync3(rootComponentPath)) {
|
|
101
|
-
return;
|
|
102
|
-
}
|
|
103
|
-
writeFileSync2(rootComponentPath, APP_KU_VUE_TEMPLATE, "utf-8");
|
|
104
|
-
console.log(`[univa] \u5DF2\u751F\u6210\u865A\u62DF\u6839\u7EC4\u4EF6\uFF1A${slash(rootComponentPath)}`);
|
|
105
|
-
}
|
|
106
209
|
var UnivaContext = class {
|
|
107
210
|
_server;
|
|
108
211
|
config;
|
|
@@ -111,12 +214,32 @@ var UnivaContext = class {
|
|
|
111
214
|
constructor(options) {
|
|
112
215
|
this.root = options.root;
|
|
113
216
|
}
|
|
217
|
+
/**
|
|
218
|
+
* 确保虚拟根组件文件存在
|
|
219
|
+
*
|
|
220
|
+
* UniKuRoot 插件依赖 src 下的虚拟根组件文件(默认 App.ku.vue)。
|
|
221
|
+
* 若不存在则生成最小模板,避免插件注入 import 时解析失败。
|
|
222
|
+
*
|
|
223
|
+
* 必须在 Vite 启动前调用(Univa() 初始化阶段),
|
|
224
|
+
* 否则在 configResolved 阶段创建 src 下新文件会触发 watcher add 事件,
|
|
225
|
+
* 导致 Vite 重编译与 VitePluginUniPages 的 pages.json 写入冲突(EPERM)。
|
|
226
|
+
*/
|
|
227
|
+
ensureRootComponent(fileName) {
|
|
228
|
+
const srcDir = this.config?.srcDir || "src";
|
|
229
|
+
const rootFileName = this.config?.overrides?.root?.rootFileName || fileName;
|
|
230
|
+
const rootComponentPath = join4(this.root, srcDir, rootFileName);
|
|
231
|
+
if (existsSync4(rootComponentPath)) {
|
|
232
|
+
return;
|
|
233
|
+
}
|
|
234
|
+
writeFileSync3(rootComponentPath, APP_KU_VUE_TEMPLATE, "utf-8");
|
|
235
|
+
log(`\u5DF2\u751F\u6210\u865A\u62DF\u6839\u7EC4\u4EF6\uFF1A${slash(rootComponentPath)}`);
|
|
236
|
+
}
|
|
114
237
|
/**
|
|
115
238
|
* 同步加载用户配置(univa.config.ts)
|
|
116
239
|
*/
|
|
117
240
|
loadUserConfigSync() {
|
|
118
241
|
const jiti = createJiti(this.root);
|
|
119
|
-
const configFile =
|
|
242
|
+
const configFile = join4(this.root, `${ID}.config`);
|
|
120
243
|
try {
|
|
121
244
|
const configModule = jiti(configFile);
|
|
122
245
|
const userConfig = configModule?.default || configModule;
|
|
@@ -175,26 +298,33 @@ var UnivaContext = class {
|
|
|
175
298
|
* 更新生成的文件
|
|
176
299
|
*
|
|
177
300
|
* 读取 univa.config.ts 的 pages 字段(应用级配置),
|
|
178
|
-
* 生成 .univa/pages.ts 供 VitePluginUniPages 消费。
|
|
179
|
-
*
|
|
301
|
+
* 生成 .univa/pages-config.ts 供 VitePluginUniPages 消费。
|
|
302
|
+
*
|
|
303
|
+
* 注意:不在此处生成 src/App.ku.vue,避免在 configResolved 阶段
|
|
304
|
+
* 创建 src 下新文件触发 watcher add 事件,导致 Vite 重编译
|
|
305
|
+
* 与 VitePluginUniPages 的 pages.json 写入冲突(EPERM)。
|
|
306
|
+
* App.ku.vue 的生成在 Univa() 初始化阶段完成。
|
|
180
307
|
*/
|
|
181
308
|
updateGeneratedFiles() {
|
|
182
309
|
const pagesConfig = this.config?.pages;
|
|
183
310
|
if (pagesConfig) {
|
|
184
311
|
generatePagesConfigFile(pagesConfig, this.root);
|
|
185
312
|
}
|
|
313
|
+
const manifestConfig = this.config?.manifest;
|
|
314
|
+
if (manifestConfig) {
|
|
315
|
+
generateManifestConfigFile(manifestConfig, this.root);
|
|
316
|
+
}
|
|
186
317
|
const pagesTsPath = getPagesConfigPath(this.root);
|
|
187
318
|
const emptyContent = `// Auto-generated by @univa/core
|
|
188
319
|
export default {}
|
|
189
320
|
`;
|
|
190
|
-
if (!
|
|
191
|
-
|
|
321
|
+
if (!existsSync4(pagesTsPath)) {
|
|
322
|
+
writeFileSync3(pagesTsPath, emptyContent, "utf-8");
|
|
192
323
|
} else if (!pagesConfig) {
|
|
193
|
-
if (
|
|
194
|
-
|
|
324
|
+
if (readFileSync3(pagesTsPath, "utf-8") !== emptyContent) {
|
|
325
|
+
writeFileSync3(pagesTsPath, emptyContent, "utf-8");
|
|
195
326
|
}
|
|
196
327
|
}
|
|
197
|
-
ensureRootComponent(this.config, this.root);
|
|
198
328
|
}
|
|
199
329
|
/**
|
|
200
330
|
* 更新回调
|
|
@@ -220,7 +350,7 @@ var DEFAULT_IMPORTS = {
|
|
|
220
350
|
apis: ["vue", "uni-app", "composables/**", "stores/**", "hooks/**", "constants/**"],
|
|
221
351
|
components: ["components/**", "components-biz/**"]
|
|
222
352
|
};
|
|
223
|
-
function
|
|
353
|
+
function resolveOptions2(userOptions) {
|
|
224
354
|
const srcDir = userOptions.srcDir || "src";
|
|
225
355
|
const dirs = {
|
|
226
356
|
pages: userOptions.dirs?.pages ?? DEFAULT_DIRS.pages,
|
|
@@ -293,7 +423,9 @@ function createUnivaPlugins(resolved) {
|
|
|
293
423
|
...resolved.overrides?.layouts
|
|
294
424
|
}));
|
|
295
425
|
plugins.push(UniKuRoot({
|
|
426
|
+
enabledVirtualHost: true,
|
|
296
427
|
enabledGlobalRef: true,
|
|
428
|
+
rootFileName: ROOT_NAME,
|
|
297
429
|
excludePages: [
|
|
298
430
|
"components-async/**/*.*"
|
|
299
431
|
],
|
|
@@ -306,6 +438,9 @@ function createUnivaPlugins(resolved) {
|
|
|
306
438
|
directoryAsNamespace: true,
|
|
307
439
|
...resolved.overrides?.components
|
|
308
440
|
}));
|
|
441
|
+
plugins.push(createManifestPlugin({
|
|
442
|
+
...resolved.overrides?.manifest
|
|
443
|
+
}));
|
|
309
444
|
plugins.push(...Uni());
|
|
310
445
|
plugins.push(...UnoCSS());
|
|
311
446
|
const { presets, dirs } = resolveApiSources(resolved.imports.apis, srcDir);
|
|
@@ -328,8 +463,10 @@ function Univa() {
|
|
|
328
463
|
});
|
|
329
464
|
ensureUnivaDir(context.root);
|
|
330
465
|
context.loadUserConfigSync();
|
|
331
|
-
|
|
332
|
-
|
|
466
|
+
setDebug(context.config?.debug ?? false);
|
|
467
|
+
context.ensureRootComponent(`${ROOT_NAME}.vue`);
|
|
468
|
+
const resolved = resolveOptions2(context.config || {});
|
|
469
|
+
log("\u5DF2\u52A0\u8F7D\u914D\u7F6E\uFF1A", context.configPath || "\u9ED8\u8BA4\u914D\u7F6E");
|
|
333
470
|
return createUnivaPlugins(resolved);
|
|
334
471
|
}
|
|
335
472
|
var plugins_default = Univa;
|
package/dist/use.cjs
ADDED
|
@@ -0,0 +1,46 @@
|
|
|
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
|
+
|
|
20
|
+
// src/use.ts
|
|
21
|
+
var use_exports = {};
|
|
22
|
+
__export(use_exports, {
|
|
23
|
+
usePageContext: () => usePageContext
|
|
24
|
+
});
|
|
25
|
+
module.exports = __toCommonJS(use_exports);
|
|
26
|
+
|
|
27
|
+
// src/hooks/usePageContext.ts
|
|
28
|
+
var import_vue = require("vue");
|
|
29
|
+
function usePageContext() {
|
|
30
|
+
const rootRef = (0, import_vue.shallowRef)(null);
|
|
31
|
+
(0, import_vue.onMounted)(() => {
|
|
32
|
+
const pagesStack = getCurrentPages();
|
|
33
|
+
const pageStack = pagesStack[pagesStack.length - 1];
|
|
34
|
+
if (!pageStack?.$vm?.$refs?.uniKuRoot) {
|
|
35
|
+
throw new Error("[usePageContext] Root not found.");
|
|
36
|
+
}
|
|
37
|
+
rootRef.value = pageStack.$vm.$refs.uniKuRoot;
|
|
38
|
+
});
|
|
39
|
+
return {
|
|
40
|
+
rootRef
|
|
41
|
+
};
|
|
42
|
+
}
|
|
43
|
+
// Annotate the CommonJS export names for ESM import in node:
|
|
44
|
+
0 && (module.exports = {
|
|
45
|
+
usePageContext
|
|
46
|
+
});
|
package/dist/use.d.cts
ADDED
package/dist/use.d.ts
ADDED
package/dist/use.js
ADDED
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
// src/hooks/usePageContext.ts
|
|
2
|
+
import { onMounted, shallowRef } from "vue";
|
|
3
|
+
function usePageContext() {
|
|
4
|
+
const rootRef = shallowRef(null);
|
|
5
|
+
onMounted(() => {
|
|
6
|
+
const pagesStack = getCurrentPages();
|
|
7
|
+
const pageStack = pagesStack[pagesStack.length - 1];
|
|
8
|
+
if (!pageStack?.$vm?.$refs?.uniKuRoot) {
|
|
9
|
+
throw new Error("[usePageContext] Root not found.");
|
|
10
|
+
}
|
|
11
|
+
rootRef.value = pageStack.$vm.$refs.uniKuRoot;
|
|
12
|
+
});
|
|
13
|
+
return {
|
|
14
|
+
rootRef
|
|
15
|
+
};
|
|
16
|
+
}
|
|
17
|
+
export {
|
|
18
|
+
usePageContext
|
|
19
|
+
};
|
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@univa/core",
|
|
3
3
|
"type": "module",
|
|
4
|
-
"version": "0.0.
|
|
4
|
+
"version": "0.0.9",
|
|
5
5
|
"description": "🚀 开箱即用的 uni-app Vite 插件集,提供完整的开发体验",
|
|
6
6
|
"author": "lianghang <libre1103@163.com>",
|
|
7
7
|
"license": "MIT",
|
|
@@ -29,8 +29,18 @@
|
|
|
29
29
|
"default": "./dist/index.cjs"
|
|
30
30
|
}
|
|
31
31
|
},
|
|
32
|
-
"./
|
|
33
|
-
"
|
|
32
|
+
"./use": {
|
|
33
|
+
"import": {
|
|
34
|
+
"types": "./dist/use.d.ts",
|
|
35
|
+
"default": "./dist/use.js"
|
|
36
|
+
},
|
|
37
|
+
"require": {
|
|
38
|
+
"types": "./dist/use.d.cts",
|
|
39
|
+
"default": "./dist/use.cjs"
|
|
40
|
+
}
|
|
41
|
+
},
|
|
42
|
+
"./global": {
|
|
43
|
+
"types": "./dist/global.d.ts"
|
|
34
44
|
}
|
|
35
45
|
},
|
|
36
46
|
"main": "./dist/index.cjs",
|
|
@@ -39,9 +49,8 @@
|
|
|
39
49
|
"files": [
|
|
40
50
|
"LICENSE",
|
|
41
51
|
"README.md",
|
|
42
|
-
"
|
|
43
|
-
"
|
|
44
|
-
"src/global.d.ts"
|
|
52
|
+
"THIRD-PARTY-NOTICES",
|
|
53
|
+
"dist"
|
|
45
54
|
],
|
|
46
55
|
"engines": {
|
|
47
56
|
"node": ">=20.0.0"
|
|
@@ -50,26 +59,27 @@
|
|
|
50
59
|
"access": "public",
|
|
51
60
|
"registry": "https://registry.npmjs.org/"
|
|
52
61
|
},
|
|
53
|
-
"
|
|
54
|
-
"
|
|
55
|
-
"dev": "tsup --watch"
|
|
62
|
+
"peerDependencies": {
|
|
63
|
+
"vite": "^5.2.8"
|
|
56
64
|
},
|
|
57
65
|
"dependencies": {
|
|
58
|
-
"@antfu/utils": "
|
|
59
|
-
"@
|
|
66
|
+
"@antfu/utils": "^9.3.0",
|
|
67
|
+
"@dcloudio/types": "3.4.28",
|
|
68
|
+
"@uni-helper/eslint-config": "0.7.4",
|
|
60
69
|
"@uni-helper/plugin-uni": "0.1.0",
|
|
61
|
-
"@uni-helper/uni-pages-types": "
|
|
62
|
-
"@uni-helper/uni-types": "1.
|
|
70
|
+
"@uni-helper/uni-pages-types": "0.4.6",
|
|
71
|
+
"@uni-helper/uni-types": "1.1.0",
|
|
63
72
|
"@uni-helper/unocss-preset-uni": "0.2.11",
|
|
64
|
-
"@uni-helper/vite-plugin-uni-components": "0.2
|
|
73
|
+
"@uni-helper/vite-plugin-uni-components": "0.3.2",
|
|
65
74
|
"@uni-helper/vite-plugin-uni-layouts": "0.1.11",
|
|
66
|
-
"@uni-helper/vite-plugin-uni-
|
|
75
|
+
"@uni-helper/vite-plugin-uni-manifest": "0.4.1",
|
|
76
|
+
"@uni-helper/vite-plugin-uni-pages": "0.4.6",
|
|
67
77
|
"@uni-ku/root": "1.4.1",
|
|
68
78
|
"@unocss/eslint-plugin": "66.6.7",
|
|
69
79
|
"@unocss/preset-legacy-compat": "66.0.0",
|
|
70
80
|
"c12": "3.3.4",
|
|
71
81
|
"defu": "6.1.7",
|
|
72
|
-
"eslint": "
|
|
82
|
+
"eslint": "^10.5.0",
|
|
73
83
|
"jiti": "2.7.0",
|
|
74
84
|
"sass": "1.99.0",
|
|
75
85
|
"unocss": "66.0.0",
|
|
@@ -77,10 +87,15 @@
|
|
|
77
87
|
"vite-plugin-uni-polyfill": "0.1.0"
|
|
78
88
|
},
|
|
79
89
|
"devDependencies": {
|
|
80
|
-
"@dcloudio/uni-app": "
|
|
81
|
-
"
|
|
82
|
-
"
|
|
83
|
-
"
|
|
84
|
-
"
|
|
90
|
+
"@dcloudio/uni-app": "3.0.0-5000720260410001",
|
|
91
|
+
"@types/node": "^24.13.2",
|
|
92
|
+
"tsup": "^8.5.1",
|
|
93
|
+
"typescript": "^5.9.3",
|
|
94
|
+
"vite": "^5.2.8",
|
|
95
|
+
"vue": "~3.4.38"
|
|
96
|
+
},
|
|
97
|
+
"scripts": {
|
|
98
|
+
"build": "node scripts/build.mjs",
|
|
99
|
+
"dev": "tsup --watch"
|
|
85
100
|
}
|
|
86
|
-
}
|
|
101
|
+
}
|