@univa/core 0.0.6 → 0.0.7

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.cjs CHANGED
@@ -30,346 +30,379 @@ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: tru
30
30
  // src/index.ts
31
31
  var index_exports = {};
32
32
  __export(index_exports, {
33
- Univa: () => Univa,
34
- definePagesConfig: () => definePagesConfig,
35
- presetUniva: () => presetUniva
33
+ AutoImport: () => import_vite3.default,
34
+ PageContext: () => import_vite_plugin_uni_pages2.PageContext,
35
+ UniKuRoot: () => import_root2.default,
36
+ Univa: () => plugins_default,
37
+ VitePluginUniComponents: () => import_vite_plugin_uni_components3.default,
38
+ VitePluginUniLayouts: () => import_vite_plugin_uni_layouts2.VitePluginUniLayouts,
39
+ VitePluginUniPages: () => import_vite_plugin_uni_pages2.VitePluginUniPages,
40
+ camelCase: () => import_vite_plugin_uni_components2.camelCase,
41
+ createUnivaPlugins: () => createUnivaPlugins,
42
+ defineConfig: () => defineConfig,
43
+ kebabCase: () => import_vite_plugin_uni_components2.kebabCase,
44
+ pascalCase: () => import_vite_plugin_uni_components2.pascalCase,
45
+ presetUni: () => import_unocss_preset_uni.presetUni
36
46
  });
37
47
  module.exports = __toCommonJS(index_exports);
38
48
 
49
+ // src/config/index.ts
50
+ function defineConfig(config) {
51
+ return config;
52
+ }
53
+
39
54
  // src/plugins/index.ts
40
55
  var import_plugin_uni = __toESM(require("@uni-helper/plugin-uni"), 1);
41
- var import_vite_plugin_uni_layouts = __toESM(require("@uni-helper/vite-plugin-uni-layouts"), 1);
42
- var import_bundle_optimizer = __toESM(require("@uni-ku/bundle-optimizer"), 1);
43
- var import_root = __toESM(require("@univa/root"), 1);
44
- var import_vite_plugin_uni_polyfill = __toESM(require("vite-plugin-uni-polyfill"), 1);
56
+ var import_vite_plugin_uni_components = __toESM(require("@uni-helper/vite-plugin-uni-components"), 1);
57
+ var import_vite_plugin_uni_layouts = require("@uni-helper/vite-plugin-uni-layouts");
58
+ var import_root = __toESM(require("@uni-ku/root"), 1);
59
+ var import_vite = __toESM(require("unocss/vite"), 1);
60
+ var import_vite2 = __toESM(require("unplugin-auto-import/vite"), 1);
45
61
 
46
62
  // src/constant.ts
47
- var DTS_DIR = "./.univa";
48
- var COMPONENT_ASYNC_ROOT = "components-async";
63
+ var ID = "univa";
64
+ var UNIVA_DIR_NAME = `.${ID}`;
49
65
 
50
- // src/plugins/autoImport.ts
51
- var import_vite = __toESM(require("unplugin-auto-import/vite"), 1);
52
- function createAutoImportPlugin(options) {
53
- const defaultAutoImportOptions = {
54
- imports: [
55
- "vue",
56
- "pinia",
57
- "uni-app",
58
- {
59
- from: "@univa/core/hooks",
60
- imports: ["usePageContext"]
61
- }
62
- ],
63
- dirs: [
64
- "src/hooks/**",
65
- "!src/hooks/**/_*/**",
66
- "src/store/**",
67
- "!src/store/**/_*/**",
68
- "src/constants/**"
69
- ],
70
- vueTemplate: true,
71
- dts: `${DTS_DIR}/auto-imports.d.ts`
72
- };
73
- const userAutoImportOptions = typeof options.autoImport === "object" ? options.autoImport : {};
74
- const mergedOptions = {
75
- ...defaultAutoImportOptions,
76
- ...userAutoImportOptions
77
- };
78
- if (userAutoImportOptions.imports) {
79
- const userImports = Array.isArray(userAutoImportOptions.imports) ? userAutoImportOptions.imports : [userAutoImportOptions.imports];
80
- mergedOptions.imports = [...defaultAutoImportOptions.imports, ...userImports];
81
- }
82
- if (userAutoImportOptions.dirs) {
83
- const userDirs = Array.isArray(userAutoImportOptions.dirs) ? userAutoImportOptions.dirs : [userAutoImportOptions.dirs];
84
- mergedOptions.dirs = [...defaultAutoImportOptions.dirs, ...userDirs];
66
+ // src/utils/fs.ts
67
+ var import_node_fs = require("fs");
68
+ var import_node_path = require("path");
69
+ function ensureDir(dir) {
70
+ if (!(0, import_node_fs.existsSync)(dir)) {
71
+ (0, import_node_fs.mkdirSync)(dir, { recursive: true });
85
72
  }
86
- return (0, import_vite.default)(mergedOptions);
73
+ }
74
+ function getUnivaDir(cwd) {
75
+ return (0, import_node_path.join)(cwd, UNIVA_DIR_NAME);
76
+ }
77
+ function ensureUnivaDir(cwd) {
78
+ const dir = getUnivaDir(cwd);
79
+ ensureDir(dir);
80
+ return dir;
87
81
  }
88
82
 
89
- // src/plugins/components.ts
90
- var import_vite_plugin_uni_components = __toESM(require("@uni-helper/vite-plugin-uni-components"), 1);
91
- function createComponentsPlugin(options) {
92
- const defaultComponentsOptions = {
93
- dirs: ["src/components", "src/components-biz"],
94
- exclude: ["**/components/**/*.*"],
95
- directoryAsNamespace: true,
96
- globalNamespaces: ["components", "common"],
97
- dts: `${DTS_DIR}/components.d.ts`
98
- };
99
- const userComponentsOptions = typeof options.components === "object" ? options.components : {};
100
- const mergedOptions = {
101
- ...defaultComponentsOptions,
102
- ...userComponentsOptions
103
- };
104
- if (userComponentsOptions.dirs) {
105
- const userDirs = Array.isArray(userComponentsOptions.dirs) ? userComponentsOptions.dirs : [userComponentsOptions.dirs];
106
- mergedOptions.dirs = [...defaultComponentsOptions.dirs, ...userDirs];
107
- }
108
- if (userComponentsOptions.exclude) {
109
- const userExclude = Array.isArray(userComponentsOptions.exclude) ? userComponentsOptions.exclude : [userComponentsOptions.exclude];
110
- mergedOptions.exclude = [...defaultComponentsOptions.exclude, ...userExclude];
111
- }
112
- if (userComponentsOptions.globalNamespaces) {
113
- const userGlobalNamespaces = Array.isArray(userComponentsOptions.globalNamespaces) ? userComponentsOptions.globalNamespaces : [userComponentsOptions.globalNamespaces];
114
- mergedOptions.globalNamespaces = [...defaultComponentsOptions.globalNamespaces, ...userGlobalNamespaces];
83
+ // src/plugins/context.ts
84
+ var import_node_fs3 = require("fs");
85
+ var import_node_path3 = require("path");
86
+ var import_utils = require("@antfu/utils");
87
+ var import_c12 = require("c12");
88
+ var import_jiti = require("jiti");
89
+
90
+ // src/utils/merge.ts
91
+ var import_defu = require("defu");
92
+ var mergeWithArrayOverride = (0, import_defu.createDefu)((originObj, key, updates) => {
93
+ if (Array.isArray(originObj[key]) && Array.isArray(updates)) {
94
+ originObj[key] = updates;
95
+ return true;
115
96
  }
116
- return (0, import_vite_plugin_uni_components.default)(mergedOptions);
117
- }
97
+ });
118
98
 
119
- // src/plugins/manifest.ts
120
- var import_manifest = require("@univa/manifest");
121
- function createManifestPlugin(options) {
122
- return (0, import_manifest.VitePluginUniManifest)({
123
- rewrite: (config) => {
124
- return options?.manifest || config;
99
+ // src/plugins/pages.ts
100
+ var import_node_fs2 = require("fs");
101
+ var import_node_path2 = require("path");
102
+ var import_vite_plugin_uni_pages = require("@uni-helper/vite-plugin-uni-pages");
103
+ function getPagesConfigPath(root) {
104
+ return (0, import_node_path2.join)(getUnivaDir(root), "pages-config.ts");
105
+ }
106
+ function generatePagesConfigContent(content) {
107
+ const { pages, subPackages, ...rest } = content;
108
+ void pages;
109
+ void subPackages;
110
+ return `// Auto-generated by @univa/core
111
+ // \u6765\u6E90\uFF1Auniva.config.ts \u7684 pages \u5B57\u6BB5
112
+ export default ${JSON.stringify(rest, null, 2)}
113
+ `;
114
+ }
115
+ function generatePagesConfigFile(content, root) {
116
+ const pagesConfigPath = getPagesConfigPath(root);
117
+ const newContent = generatePagesConfigContent(content);
118
+ if ((0, import_node_fs2.existsSync)(pagesConfigPath)) {
119
+ const existingContent = (0, import_node_fs2.readFileSync)(pagesConfigPath, "utf-8");
120
+ if (existingContent === newContent) {
121
+ return;
125
122
  }
123
+ }
124
+ (0, import_node_fs2.writeFileSync)(pagesConfigPath, newContent, "utf-8");
125
+ }
126
+ function createPagesPlugin(pluginOptions) {
127
+ const result = (0, import_vite_plugin_uni_pages.VitePluginUniPages)({
128
+ dts: `${UNIVA_DIR_NAME}/uni-pages.d.ts`,
129
+ exclude: ["**/components/**/*.*"],
130
+ configSource: `${UNIVA_DIR_NAME}/pages-config.ts`,
131
+ ...pluginOptions
126
132
  });
133
+ return Array.isArray(result) ? result : [result];
127
134
  }
128
135
 
129
- // src/plugins/pages.ts
130
- var import_vite_plugin_uni_pages = __toESM(require("@uni-helper/vite-plugin-uni-pages"), 1);
131
- function _pathToName(path, partToReplace = "", prefix = "") {
132
- const parts = path.replace(/\.\w+$/, "").split("/").filter(Boolean);
133
- const toPascalCase = (parts2) => {
134
- return parts2.map(
135
- (part) => part.split("-").map((subPart) => subPart.charAt(0).toUpperCase() + subPart.slice(1)).join("")
136
- ).join("");
137
- };
138
- if (!partToReplace) {
139
- return toPascalCase(parts);
140
- }
141
- const indexToReplace = parts.findIndex((part) => part.toLowerCase() === partToReplace.toLowerCase());
142
- if (indexToReplace === -1) {
143
- return prefix + toPascalCase(parts);
136
+ // src/plugins/context.ts
137
+ var DEFAULT_ROOT_FILE_NAME = "App.ku.vue";
138
+ var APP_KU_VUE_TEMPLATE = `<!-- Auto-generated by @univa/core -->
139
+ <!-- UniKuRoot \u865A\u62DF\u6839\u7EC4\u4EF6\uFF0C\u53EF\u5728\u6B64\u6DFB\u52A0\u5168\u5C40\u7EC4\u4EF6\uFF08\u5982 Toast\u3001ConfigProvider \u7B49\uFF09 -->
140
+ <template>
141
+ <KuRootView />
142
+ </template>
143
+ `;
144
+ function ensureRootComponent(config, root) {
145
+ const srcDir = config?.srcDir || "src";
146
+ const rootFileName = config?.overrides?.root?.rootFileName || DEFAULT_ROOT_FILE_NAME;
147
+ const rootComponentPath = (0, import_node_path3.join)(root, srcDir, rootFileName);
148
+ if ((0, import_node_fs3.existsSync)(rootComponentPath)) {
149
+ return;
144
150
  }
145
- parts[indexToReplace] = prefix;
146
- return toPascalCase(parts);
151
+ (0, import_node_fs3.writeFileSync)(rootComponentPath, APP_KU_VUE_TEMPLATE, "utf-8");
152
+ console.log(`[univa] \u5DF2\u751F\u6210\u865A\u62DF\u6839\u7EC4\u4EF6\uFF1A${(0, import_utils.slash)(rootComponentPath)}`);
147
153
  }
148
- function processPageName(ctx) {
149
- ctx.pageMetaData.forEach((page) => {
150
- if (page.name) {
154
+ var UnivaContext = class {
155
+ _server;
156
+ config;
157
+ configPath;
158
+ root;
159
+ constructor(options) {
160
+ this.root = options.root;
161
+ }
162
+ /**
163
+ * 同步加载用户配置(univa.config.ts)
164
+ */
165
+ loadUserConfigSync() {
166
+ const jiti = (0, import_jiti.createJiti)(this.root);
167
+ const configFile = (0, import_node_path3.join)(this.root, `${ID}.config`);
168
+ try {
169
+ const configModule = jiti(configFile);
170
+ const userConfig = configModule?.default || configModule;
171
+ this.config = mergeWithArrayOverride({}, userConfig);
172
+ this.configPath = jiti.resolve(configFile);
173
+ } catch {
174
+ }
175
+ }
176
+ /**
177
+ * 异步加载用户配置(c12 支持更多格式与合并能力)
178
+ */
179
+ async loadUserConfigAsync() {
180
+ const { config: userConfig, configFile } = await (0, import_c12.loadConfig)({
181
+ name: ID,
182
+ cwd: this.root,
183
+ defaults: this.config || {},
184
+ merger: mergeWithArrayOverride
185
+ });
186
+ this.config = userConfig;
187
+ this.configPath = configFile || "";
188
+ }
189
+ /**
190
+ * 设置 Vite 开发服务器
191
+ */
192
+ setupViteServer(server) {
193
+ if (this._server === server)
194
+ return;
195
+ this._server = server;
196
+ this.setupWatcher(server.watcher);
197
+ }
198
+ /**
199
+ * 设置文件监听器
200
+ *
201
+ * 监听 univa.config.ts 变化,重新生成 .univa/pages.ts
202
+ */
203
+ setupWatcher(watcher) {
204
+ if (!this.configPath) {
151
205
  return;
152
206
  }
153
- page.name = _pathToName(page.path, "pages");
154
- });
155
- ctx.subPageMetaData.forEach((subPackage) => {
156
- const root = subPackage.root;
157
- const isAsyncComponent = root.startsWith(COMPONENT_ASYNC_ROOT);
158
- subPackage.pages.forEach((page) => {
159
- if (page.name) {
207
+ watcher.add(this.configPath);
208
+ watcher.on("change", async (filePath) => {
209
+ filePath = (0, import_utils.slash)(filePath);
210
+ const configPath = (0, import_utils.slash)(this.configPath || "");
211
+ if (filePath !== configPath) {
160
212
  return;
161
213
  }
162
- if (!page.path) {
163
- console.warn(`[vite-plugin-uni-pages] Page path is missing in subPackage: ${root}`);
164
- return;
165
- }
166
- if (isAsyncComponent) {
167
- page.layout = false;
168
- }
169
- page.name = _pathToName(`${root}/${page.path}`, "pages-sub", "Sub");
214
+ await this.updateConfig();
215
+ this.onUpdate();
170
216
  });
171
- });
172
- }
173
- function processTabBar(ctx) {
174
- const tabBar = ctx.pagesGlobConfig?.tabBar;
175
- if (!tabBar) {
176
- return;
177
217
  }
178
- const tabBarMode = ctx.pagesGlobConfig?.tabBarMode || "NATIVE";
179
- if (tabBarMode === "CUSTOM") {
180
- tabBar.custom = true;
218
+ async updateConfig() {
219
+ await this.loadUserConfigAsync();
220
+ this.updateGeneratedFiles();
181
221
  }
182
- const rawTabBarList = [];
183
- if (tabBar.list && tabBar.list.length > 0) {
184
- tabBar.list = tabBar.list.map((item) => {
185
- rawTabBarList.push({ ...item });
186
- const filtered = { ...item };
187
- if (!filtered.iconPath?.startsWith("static/")) {
188
- delete filtered.iconPath;
189
- }
190
- if (!filtered.selectedIconPath?.startsWith("static/")) {
191
- delete filtered.selectedIconPath;
222
+ /**
223
+ * 更新生成的文件
224
+ *
225
+ * 读取 univa.config.ts pages 字段(应用级配置),
226
+ * 生成 .univa/pages.ts VitePluginUniPages 消费。
227
+ * 同时确保 UniKuRoot 虚拟根组件文件存在。
228
+ */
229
+ updateGeneratedFiles() {
230
+ const pagesConfig = this.config?.pages;
231
+ if (pagesConfig) {
232
+ generatePagesConfigFile(pagesConfig, this.root);
233
+ }
234
+ const pagesTsPath = getPagesConfigPath(this.root);
235
+ const emptyContent = `// Auto-generated by @univa/core
236
+ export default {}
237
+ `;
238
+ if (!(0, import_node_fs3.existsSync)(pagesTsPath)) {
239
+ (0, import_node_fs3.writeFileSync)(pagesTsPath, emptyContent, "utf-8");
240
+ } else if (!pagesConfig) {
241
+ if ((0, import_node_fs3.readFileSync)(pagesTsPath, "utf-8") !== emptyContent) {
242
+ (0, import_node_fs3.writeFileSync)(pagesTsPath, emptyContent, "utf-8");
192
243
  }
193
- return filtered;
194
- });
195
- }
196
- const clonedTabBar = { ...tabBar };
197
- if (clonedTabBar.list) {
198
- clonedTabBar.list = rawTabBarList;
244
+ }
245
+ ensureRootComponent(this.config, this.root);
199
246
  }
200
- return clonedTabBar;
201
- }
202
- function resolveUserPagesConfig(config) {
203
- if (!config.tabBar) {
204
- return config;
247
+ /**
248
+ * 更新回调
249
+ * 触发 HMR
250
+ */
251
+ onUpdate() {
252
+ if (!this._server) {
253
+ return;
254
+ }
255
+ this._server.ws.send({
256
+ type: "full-reload"
257
+ });
205
258
  }
206
- return config;
207
- }
208
- function createPagesPlugin(options) {
209
- const pages = options.pages || {};
210
- const MODULE_ID_VIRTUAL = "virtual:univa-pages";
211
- const RESOLVED_MODULE_ID_VIRTUAL = `\0${MODULE_ID_VIRTUAL}`;
212
- const virtualData = {
213
- pages: [],
214
- subPackages: [],
215
- tabBar: null
216
- };
217
- const virtualModule = () => {
218
- const pages2 = `export const pages = ${virtualData.pages};`;
219
- const subPackages = `export const subPackages = ${virtualData.subPackages};`;
220
- const tabBar = `export const tabBar = ${JSON.stringify(virtualData.tabBar)};`;
221
- return [pages2, subPackages, tabBar].join("\n");
259
+ };
260
+
261
+ // src/plugins/options.ts
262
+ var DEFAULT_DIRS = {
263
+ pages: "pages",
264
+ subPackages: ["pages-sub/*"],
265
+ layouts: "layouts"
266
+ };
267
+ var DEFAULT_IMPORTS = {
268
+ apis: ["vue", "uni-app", "composables/**", "stores/**", "hooks/**", "constants/**"],
269
+ components: ["components/**", "components-biz/**"]
270
+ };
271
+ function resolveOptions(userOptions) {
272
+ const srcDir = userOptions.srcDir || "src";
273
+ const dirs = {
274
+ pages: userOptions.dirs?.pages ?? DEFAULT_DIRS.pages,
275
+ subPackages: userOptions.dirs?.subPackages ?? DEFAULT_DIRS.subPackages,
276
+ layouts: userOptions.dirs?.layouts ?? DEFAULT_DIRS.layouts
222
277
  };
223
- const tabbarPlugin = {
224
- name: "vite-plugin-univa-pages",
225
- enforce: "pre",
226
- resolveId(id) {
227
- if (id === MODULE_ID_VIRTUAL) {
228
- return RESOLVED_MODULE_ID_VIRTUAL;
229
- }
230
- },
231
- load(id) {
232
- if (id === RESOLVED_MODULE_ID_VIRTUAL) {
233
- return virtualModule();
234
- }
235
- }
278
+ const imports = {
279
+ apis: userOptions.imports?.apis ?? DEFAULT_IMPORTS.apis,
280
+ components: userOptions.imports?.components ?? DEFAULT_IMPORTS.components
236
281
  };
237
- return [
238
- tabbarPlugin,
239
- (0, import_vite_plugin_uni_pages.default)({
240
- configSource: pages.config ? {
241
- files: "vite.config",
242
- rewrite: () => resolveUserPagesConfig(pages.config)
243
- } : {
244
- files: "pages.config"
245
- },
246
- subPackages: [
247
- ...pages.subPackages || []
248
- ],
249
- exclude: [
250
- ...pages?.exclude || [],
251
- "**/components/**/*.*"
252
- ],
253
- onAfterMergePageMetaData(ctx) {
254
- processPageName(ctx);
255
- virtualData.tabBar = processTabBar(ctx);
256
- },
257
- onAfterWriteFile(ctx) {
258
- virtualData.pages = ctx.resolveRoutes();
259
- virtualData.subPackages = ctx.resolveSubRoutes();
260
- },
261
- dts: `${DTS_DIR}/pages.d.ts`
262
- })
263
- ];
264
- }
265
- function definePagesConfig(config) {
266
- return config;
267
- }
268
-
269
- // src/plugins/unocss.ts
270
- var import_unocss_preset_uni = require("@uni-helper/unocss-preset-uni");
271
- var import_preset_legacy_compat = __toESM(require("@unocss/preset-legacy-compat"), 1);
272
- var import_unocss = require("unocss");
273
- var import_vite2 = __toESM(require("unocss/vite"), 1);
274
- function createUnocssPlugin() {
275
- return (0, import_vite2.default)({
276
- presets: [
277
- presetUniva()
278
- ]
279
- });
280
- }
281
- function presetUniva() {
282
282
  return {
283
- name: "univa-preset",
284
- presets: [
285
- (0, import_unocss_preset_uni.presetUni)({
286
- attributify: false
287
- }),
288
- (0, import_unocss.presetIcons)({
289
- scale: 1.2,
290
- warn: true,
291
- extraProperties: {
292
- "display": "inline-block",
293
- "vertical-align": "middle"
294
- }
295
- }),
296
- // 处理低端安卓机的样式问题,eg: `rgb(255 0 0)` -> `rgb(255, 0, 0)`
297
- (0, import_preset_legacy_compat.default)({
298
- commaStyleColorFunction: true,
299
- legacyColorSpace: true
300
- })
301
- ],
302
- shortcuts: [
303
- ["border-s", "border border-solid"],
304
- ["wh-full", "w-full h-full"],
305
- ["f-c-c", "flex justify-center items-center"],
306
- ["f-col-c", "flex-col justify-center items-center"],
307
- ["flex-items", "flex items-center"],
308
- ["flex-justify", "flex justify-center"],
309
- ["flex-col", "flex flex-col"]
310
- ],
311
- transformers: [
312
- (0, import_unocss.transformerDirectives)(),
313
- (0, import_unocss.transformerVariantGroup)()
314
- ],
315
- rules: [
316
- [
317
- "p-safe",
318
- {
319
- padding: "env(safe-area-inset-top) env(safe-area-inset-right) env(safe-area-inset-bottom) env(safe-area-inset-left)"
320
- }
321
- ],
322
- ["pt-safe", { "padding-top": "env(safe-area-inset-top)" }],
323
- ["pb-safe", { "padding-bottom": "env(safe-area-inset-bottom)" }]
324
- ]
283
+ srcDir,
284
+ dirs,
285
+ imports,
286
+ overrides: userOptions.overrides
325
287
  };
326
288
  }
327
289
 
328
290
  // src/plugins/index.ts
329
- function createUnivaPlugins(options) {
330
- const pluginFactory = {
331
- plugins: [
332
- ...createPagesPlugin(options),
333
- (0, import_vite_plugin_uni_layouts.default)()
334
- ],
335
- register(condition, plugin) {
336
- if (condition) {
337
- this.plugins.push(plugin);
338
- }
291
+ var context;
292
+ function createCorePlugin() {
293
+ return {
294
+ name: "vite-plugin-univa",
295
+ enforce: "pre",
296
+ async configResolved() {
297
+ await context.loadUserConfigAsync();
298
+ context.updateGeneratedFiles();
299
+ },
300
+ configureServer(server) {
301
+ context.setupViteServer(server);
339
302
  }
340
303
  };
341
- pluginFactory.register(options.appRoot !== false, (0, import_root.default)({
342
- enabledVirtualHost: true,
343
- rootFileName: "App.univa",
304
+ }
305
+ function isPresetName(from) {
306
+ if (/[*?[\]{}]/.test(from))
307
+ return false;
308
+ if (/^@[\w.-]+\/[\w.-]+$/.test(from))
309
+ return true;
310
+ if (/[/\\]/.test(from))
311
+ return false;
312
+ return true;
313
+ }
314
+ function resolveApiSources(sources, srcDir) {
315
+ const presets = [];
316
+ const dirs = [];
317
+ for (const source of sources) {
318
+ if (typeof source !== "string") {
319
+ presets.push(source);
320
+ } else if (source.startsWith("!")) {
321
+ dirs.push(`!${srcDir}/${source.slice(1)}`);
322
+ } else if (isPresetName(source)) {
323
+ presets.push(source);
324
+ } else {
325
+ dirs.push(`${srcDir}/${source}`);
326
+ }
327
+ }
328
+ return { presets, dirs };
329
+ }
330
+ function createUnivaPlugins(resolved) {
331
+ const plugins = [];
332
+ const { srcDir } = resolved;
333
+ plugins.push(createCorePlugin());
334
+ plugins.push(...createPagesPlugin({
335
+ dir: `${srcDir}/${resolved.dirs.pages}`,
336
+ subPackages: resolved.dirs.subPackages.map((p) => `${srcDir}/${p}`),
337
+ ...resolved.overrides?.pages
338
+ }));
339
+ plugins.push((0, import_vite_plugin_uni_layouts.VitePluginUniLayouts)({
340
+ layoutDir: `${srcDir}/${resolved.dirs.layouts}`,
341
+ ...resolved.overrides?.layouts
342
+ }));
343
+ plugins.push((0, import_root.default)({
344
344
  enabledGlobalRef: true,
345
- autoCreateRoot: true,
346
345
  excludePages: [
347
- `${COMPONENT_ASYNC_ROOT}/**/*.*`
348
- ]
346
+ "components-async/**/*.*"
347
+ ],
348
+ ...resolved.overrides?.root
349
+ }));
350
+ plugins.push((0, import_vite_plugin_uni_components.default)({
351
+ dirs: resolved.imports.components.map((c) => `${srcDir}/${c}`),
352
+ dts: `${UNIVA_DIR_NAME}/components.d.ts`,
353
+ globalNamespaces: ["components", "common"],
354
+ directoryAsNamespace: true,
355
+ ...resolved.overrides?.components
349
356
  }));
350
- pluginFactory.register(true, createManifestPlugin(options));
351
- pluginFactory.register(options.components !== false, createComponentsPlugin(options));
352
- pluginFactory.register(true, (0, import_bundle_optimizer.default)());
353
- pluginFactory.register(true, (0, import_plugin_uni.default)());
354
- pluginFactory.register(true, createUnocssPlugin());
355
- pluginFactory.register(options.autoImport !== false, createAutoImportPlugin(options));
356
- pluginFactory.register(true, (0, import_vite_plugin_uni_polyfill.default)());
357
- return pluginFactory.plugins;
357
+ plugins.push(...(0, import_plugin_uni.default)());
358
+ plugins.push(...(0, import_vite.default)());
359
+ const { presets, dirs } = resolveApiSources(resolved.imports.apis, srcDir);
360
+ const autoImportPlugin = (0, import_vite2.default)({
361
+ imports: presets,
362
+ dirs,
363
+ dts: `${UNIVA_DIR_NAME}/auto-imports.d.ts`,
364
+ ...resolved.overrides?.autoImport
365
+ });
366
+ if (Array.isArray(autoImportPlugin)) {
367
+ plugins.push(...autoImportPlugin);
368
+ } else {
369
+ plugins.push(autoImportPlugin);
370
+ }
371
+ return plugins;
358
372
  }
359
-
360
- // src/index.ts
361
- function Univa(config) {
362
- return createUnivaPlugins({
363
- components: config?.components ?? true,
364
- autoImport: config?.autoImport ?? true,
365
- appRoot: config?.appRoot ?? true,
366
- pages: config?.pages,
367
- manifest: config?.manifest
373
+ function Univa() {
374
+ context = new UnivaContext({
375
+ root: process.cwd()
368
376
  });
377
+ ensureUnivaDir(context.root);
378
+ context.loadUserConfigSync();
379
+ const resolved = resolveOptions(context.config || {});
380
+ console.log("[univa] \u5DF2\u52A0\u8F7D\u914D\u7F6E\uFF1A", context.configPath || "\u9ED8\u8BA4\u914D\u7F6E");
381
+ return createUnivaPlugins(resolved);
369
382
  }
383
+ var plugins_default = Univa;
384
+
385
+ // src/index.ts
386
+ var import_unocss_preset_uni = require("@uni-helper/unocss-preset-uni");
387
+ var import_vite_plugin_uni_components2 = require("@uni-helper/vite-plugin-uni-components");
388
+ var import_vite_plugin_uni_components3 = __toESM(require("@uni-helper/vite-plugin-uni-components"), 1);
389
+ var import_vite_plugin_uni_layouts2 = require("@uni-helper/vite-plugin-uni-layouts");
390
+ var import_vite_plugin_uni_pages2 = require("@uni-helper/vite-plugin-uni-pages");
391
+ var import_root2 = __toESM(require("@uni-ku/root"), 1);
392
+ var import_vite3 = __toESM(require("unplugin-auto-import/vite"), 1);
370
393
  // Annotate the CommonJS export names for ESM import in node:
371
394
  0 && (module.exports = {
395
+ AutoImport,
396
+ PageContext,
397
+ UniKuRoot,
372
398
  Univa,
373
- definePagesConfig,
374
- presetUniva
399
+ VitePluginUniComponents,
400
+ VitePluginUniLayouts,
401
+ VitePluginUniPages,
402
+ camelCase,
403
+ createUnivaPlugins,
404
+ defineConfig,
405
+ kebabCase,
406
+ pascalCase,
407
+ presetUni
375
408
  });