@dcloudio/uni-cli-shared 3.0.0-3090920231225001 → 3.0.0-4000720240327001

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.
Files changed (60) hide show
  1. package/dist/constants.d.ts +1 -1
  2. package/dist/constants.js +4 -6
  3. package/dist/easycom.d.ts +5 -0
  4. package/dist/easycom.js +54 -3
  5. package/dist/env/define.d.ts +1 -0
  6. package/dist/env/define.js +1 -0
  7. package/dist/hbx/alias.js +33 -9
  8. package/dist/json/json.js +5 -1
  9. package/dist/json/manifest.js +4 -0
  10. package/dist/json/mp/jsonFile.d.ts +1 -1
  11. package/dist/json/mp/jsonFile.js +6 -0
  12. package/dist/json/mp/pages.js +1 -1
  13. package/dist/json/pages.d.ts +1 -0
  14. package/dist/json/pages.js +70 -4
  15. package/dist/json/uni-x/index.js +20 -4
  16. package/dist/logs/format.js +6 -0
  17. package/dist/messages/en.d.ts +1 -0
  18. package/dist/messages/en.js +1 -0
  19. package/dist/messages/index.d.ts +2 -0
  20. package/dist/messages/zh_CN.d.ts +1 -0
  21. package/dist/messages/zh_CN.js +1 -0
  22. package/dist/mp/template.d.ts +1 -1
  23. package/dist/postcss/plugins/uniapp.js +1 -1
  24. package/dist/preprocess/context.js +1 -1
  25. package/dist/preprocess/index.js +6 -0
  26. package/dist/uni_modules.d.ts +7 -2
  27. package/dist/uni_modules.js +26 -3
  28. package/dist/utils.d.ts +2 -2
  29. package/dist/utils.js +7 -0
  30. package/dist/uts.d.ts +3 -1
  31. package/dist/uts.js +43 -5
  32. package/dist/vite/autoImport.js +55 -2
  33. package/dist/vite/index.d.ts +1 -0
  34. package/dist/vite/index.js +21 -1
  35. package/dist/vite/plugins/easycom.d.ts +8 -0
  36. package/dist/vite/plugins/easycom.js +52 -0
  37. package/dist/vite/plugins/index.d.ts +3 -1
  38. package/dist/vite/plugins/index.js +4 -1
  39. package/dist/vite/plugins/inject.d.ts +1 -0
  40. package/dist/vite/plugins/inject.js +1 -1
  41. package/dist/vite/plugins/uts/ext-api.d.ts +12 -0
  42. package/dist/vite/plugins/uts/ext-api.js +81 -0
  43. package/dist/vite/plugins/uts/uni_modules.d.ts +7 -0
  44. package/dist/vite/plugins/uts/uni_modules.js +59 -9
  45. package/dist/vite/plugins/uts/uvue.js +11 -8
  46. package/dist/vite/plugins/vitejs/plugins/asset.d.ts +1 -1
  47. package/dist/vite/plugins/vitejs/plugins/asset.js +2 -2
  48. package/dist/vite/plugins/vitejs/plugins/css.d.ts +6 -1
  49. package/dist/vite/plugins/vitejs/plugins/css.js +34 -3
  50. package/dist/vite/plugins/vitejs/utils.d.ts +3 -1
  51. package/dist/vite/plugins/vitejs/utils.js +17 -24
  52. package/dist/vite/utils/plugin.d.ts +1 -1
  53. package/dist/vite/utils/utils.d.ts +2 -0
  54. package/dist/vite/utils/utils.js +6 -5
  55. package/dist/vue/transforms/index.d.ts +1 -0
  56. package/dist/vue/transforms/index.js +1 -0
  57. package/dist/vue/transforms/transformUTSComponent.d.ts +8 -0
  58. package/dist/vue/transforms/transformUTSComponent.js +22 -0
  59. package/lib/preprocess/lib/preprocess.js +92 -91
  60. package/package.json +17 -12
@@ -1,6 +1,5 @@
1
1
  export declare const PUBLIC_DIR = "static";
2
2
  export declare const EXTNAME_JS: string[];
3
- export declare const X_EXTNAME_JS: string[];
4
3
  export declare const EXTNAME_TS: string[];
5
4
  export declare const EXTNAME_VUE: string[];
6
5
  export declare const X_EXTNAME_VUE: string[];
@@ -31,6 +30,7 @@ export declare const H5_API_STYLE_PATH = "@dcloudio/uni-h5/style/api/";
31
30
  export declare const H5_FRAMEWORK_STYLE_PATH = "@dcloudio/uni-h5/style/framework/";
32
31
  export declare const H5_COMPONENTS_STYLE_PATH = "@dcloudio/uni-h5/style/";
33
32
  export declare const BASE_COMPONENTS_STYLE_PATH = "@dcloudio/uni-components/style/";
33
+ export declare const X_BASE_COMPONENTS_STYLE_PATH = "@dcloudio/uni-components/style-x/";
34
34
  export declare const COMMON_EXCLUDE: RegExp[];
35
35
  export declare const KNOWN_ASSET_TYPES: string[];
36
36
  export declare const DEFAULT_ASSETS_RE: RegExp;
package/dist/constants.js CHANGED
@@ -1,15 +1,14 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.TEXT_STYLE = exports.DEFAULT_ASSETS_RE = exports.KNOWN_ASSET_TYPES = exports.COMMON_EXCLUDE = exports.BASE_COMPONENTS_STYLE_PATH = exports.H5_COMPONENTS_STYLE_PATH = exports.H5_FRAMEWORK_STYLE_PATH = exports.H5_API_STYLE_PATH = exports.X_PAGE_EXTNAME_APP = exports.X_PAGE_EXTNAME = exports.PAGE_EXTNAME = exports.PAGE_EXTNAME_APP = exports.BINDING_COMPONENTS = exports.APP_CONFIG_SERVICE = exports.APP_CONFIG = exports.APP_SERVICE_FILENAME = exports.ASSETS_INLINE_LIMIT = exports.JSON_JS_MAP = exports.MANIFEST_JSON_UTS = exports.MANIFEST_JSON_JS = exports.PAGES_JSON_UTS = exports.PAGES_JSON_JS = exports.uni_app_x_extensions = exports.extensions = exports.EXTNAME_TS_RE = exports.EXTNAME_JS_RE = exports.EXTNAME_VUE_RE = exports.EXTNAME_VUE_TEMPLATE = exports.X_EXTNAME_VUE = exports.EXTNAME_VUE = exports.EXTNAME_TS = exports.X_EXTNAME_JS = exports.EXTNAME_JS = exports.PUBLIC_DIR = void 0;
3
+ exports.TEXT_STYLE = exports.DEFAULT_ASSETS_RE = exports.KNOWN_ASSET_TYPES = exports.COMMON_EXCLUDE = exports.X_BASE_COMPONENTS_STYLE_PATH = exports.BASE_COMPONENTS_STYLE_PATH = exports.H5_COMPONENTS_STYLE_PATH = exports.H5_FRAMEWORK_STYLE_PATH = exports.H5_API_STYLE_PATH = exports.X_PAGE_EXTNAME_APP = exports.X_PAGE_EXTNAME = exports.PAGE_EXTNAME = exports.PAGE_EXTNAME_APP = exports.BINDING_COMPONENTS = exports.APP_CONFIG_SERVICE = exports.APP_CONFIG = exports.APP_SERVICE_FILENAME = exports.ASSETS_INLINE_LIMIT = exports.JSON_JS_MAP = exports.MANIFEST_JSON_UTS = exports.MANIFEST_JSON_JS = exports.PAGES_JSON_UTS = exports.PAGES_JSON_JS = exports.uni_app_x_extensions = exports.extensions = exports.EXTNAME_TS_RE = exports.EXTNAME_JS_RE = exports.EXTNAME_VUE_RE = exports.EXTNAME_VUE_TEMPLATE = exports.X_EXTNAME_VUE = exports.EXTNAME_VUE = exports.EXTNAME_TS = exports.EXTNAME_JS = exports.PUBLIC_DIR = void 0;
4
4
  exports.PUBLIC_DIR = 'static';
5
- exports.EXTNAME_JS = ['.js', '.ts', '.jsx', '.tsx'];
6
- exports.X_EXTNAME_JS = ['.uts', ...exports.EXTNAME_JS];
5
+ exports.EXTNAME_JS = ['.js', '.ts', '.jsx', '.tsx', '.uts'];
7
6
  exports.EXTNAME_TS = ['.ts', '.tsx'];
8
7
  exports.EXTNAME_VUE = ['.vue', '.nvue', '.uvue'];
9
8
  exports.X_EXTNAME_VUE = ['.uvue', '.vue'];
10
9
  exports.EXTNAME_VUE_TEMPLATE = ['.vue', '.nvue', '.uvue', '.jsx', '.tsx'];
11
10
  exports.EXTNAME_VUE_RE = /\.(vue|nvue|uvue)$/;
12
- exports.EXTNAME_JS_RE = /\.(js|jsx|ts|tsx|mjs)$/;
11
+ exports.EXTNAME_JS_RE = /\.(js|jsx|ts|uts|tsx|mjs)$/;
13
12
  exports.EXTNAME_TS_RE = /\.tsx?$/;
14
13
  const COMMON_EXTENSIONS = [
15
14
  '.uts',
@@ -45,6 +44,7 @@ exports.H5_API_STYLE_PATH = '@dcloudio/uni-h5/style/api/';
45
44
  exports.H5_FRAMEWORK_STYLE_PATH = '@dcloudio/uni-h5/style/framework/';
46
45
  exports.H5_COMPONENTS_STYLE_PATH = '@dcloudio/uni-h5/style/';
47
46
  exports.BASE_COMPONENTS_STYLE_PATH = '@dcloudio/uni-components/style/';
47
+ exports.X_BASE_COMPONENTS_STYLE_PATH = '@dcloudio/uni-components/style-x/';
48
48
  exports.COMMON_EXCLUDE = [
49
49
  /\/pages\.json\.js$/,
50
50
  /\/manifest\.json\.js$/,
@@ -55,8 +55,6 @@ exports.COMMON_EXCLUDE = [
55
55
  /\/vue-i18n\//,
56
56
  /\/@dcloudio\/uni-h5-vue/,
57
57
  /\/@dcloudio\/uni-shared/,
58
- /\/@dcloudio\/uni-h5\/style/,
59
- /\/@dcloudio\/uni-components\/style/,
60
58
  ];
61
59
  exports.KNOWN_ASSET_TYPES = [
62
60
  // images
package/dist/easycom.d.ts CHANGED
@@ -1,4 +1,5 @@
1
1
  interface EasycomOption {
2
+ isX?: boolean;
2
3
  dirs?: string[];
3
4
  rootDir: string;
4
5
  extensions: string[];
@@ -28,4 +29,8 @@ export declare function matchEasycom(tag: string): string | false | undefined;
28
29
  export declare function addImportDeclaration(importDeclarations: string[], local: string, source: string, imported?: string): string;
29
30
  export declare function genResolveEasycomCode(importDeclarations: string[], code: string, name: string): string;
30
31
  export declare const UNI_EASYCOM_EXCLUDE: RegExp[];
32
+ export declare function getUTSEasyComAutoImports(): Record<string, [[string, string]]>;
33
+ export declare function addUTSEasyComAutoImports(source: string, imports: [string, string]): void;
34
+ export declare function genUTSComponentPublicInstanceIdent(tagName: string): string;
35
+ export declare function genUTSComponentPublicInstanceImported(root: string, fileName: string): string;
31
36
  export {};
package/dist/easycom.js CHANGED
@@ -3,7 +3,7 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
3
3
  return (mod && mod.__esModule) ? mod : { "default": mod };
4
4
  };
5
5
  Object.defineProperty(exports, "__esModule", { value: true });
6
- exports.UNI_EASYCOM_EXCLUDE = exports.genResolveEasycomCode = exports.addImportDeclaration = exports.matchEasycom = exports.initEasycomsOnce = exports.initEasycoms = void 0;
6
+ exports.genUTSComponentPublicInstanceImported = exports.genUTSComponentPublicInstanceIdent = exports.addUTSEasyComAutoImports = exports.getUTSEasyComAutoImports = exports.UNI_EASYCOM_EXCLUDE = exports.genResolveEasycomCode = exports.addImportDeclaration = exports.matchEasycom = exports.initEasycomsOnce = exports.initEasycoms = void 0;
7
7
  const fs_1 = __importDefault(require("fs"));
8
8
  const path_1 = __importDefault(require("path"));
9
9
  const debug_1 = __importDefault(require("debug"));
@@ -31,6 +31,7 @@ function initEasycoms(inputDir, { dirs, platform, isX, }) {
31
31
  // 初始化时,从once中读取缓存,refresh时,实时读取
32
32
  const { easycom } = pagesJson || (0, pages_1.parsePagesJson)(inputDir, platform, false);
33
33
  const easycomOptions = {
34
+ isX,
34
35
  dirs: easycom && easycom.autoscan === false
35
36
  ? [...dirs] // 禁止自动扫描
36
37
  : [
@@ -57,6 +58,10 @@ function initEasycoms(inputDir, { dirs, platform, isX, }) {
57
58
  easycoms.push(item);
58
59
  }
59
60
  });
61
+ if (isX && globalThis.uts2jsSourceCodeMap) {
62
+ ;
63
+ globalThis.uts2jsSourceCodeMap.initUts2jsEasycom(easycoms);
64
+ }
60
65
  };
61
66
  initEasycom(options);
62
67
  initUTSEasycom();
@@ -96,11 +101,26 @@ function initUniModulesEasycomDirs(uniModulesDir) {
96
101
  })
97
102
  .filter(Boolean);
98
103
  }
99
- function initEasycom({ dirs, rootDir, custom, extensions }) {
104
+ function initEasycom({ isX, dirs, rootDir, custom, extensions, }) {
100
105
  clearEasycom();
106
+ rootDir = (0, utils_1.normalizePath)(rootDir);
101
107
  const easycomsObj = Object.create(null);
102
108
  if (dirs && dirs.length && rootDir) {
103
- (0, shared_1.extend)(easycomsObj, initAutoScanEasycoms(dirs, rootDir, extensions));
109
+ const autoEasyComObj = initAutoScanEasycoms(dirs, rootDir, extensions);
110
+ if (isX) {
111
+ Object.keys(autoEasyComObj).forEach((tagName) => {
112
+ let source = autoEasyComObj[tagName];
113
+ tagName = tagName.slice(1, -1);
114
+ if (path_1.default.isAbsolute(source) && source.startsWith(rootDir)) {
115
+ source = '@/' + (0, utils_1.normalizePath)(path_1.default.relative(rootDir, source));
116
+ }
117
+ addUTSEasyComAutoImports(source, [
118
+ genUTSComponentPublicInstanceImported(rootDir, source),
119
+ genUTSComponentPublicInstanceIdent(tagName),
120
+ ]);
121
+ });
122
+ }
123
+ (0, shared_1.extend)(easycomsObj, autoEasyComObj);
104
124
  }
105
125
  if (custom) {
106
126
  Object.keys(custom).forEach((name) => {
@@ -219,3 +239,34 @@ function genResolveEasycomCode(importDeclarations, code, name) {
219
239
  }
220
240
  exports.genResolveEasycomCode = genResolveEasycomCode;
221
241
  exports.UNI_EASYCOM_EXCLUDE = [/App.vue$/, /@dcloudio\/uni-h5/];
242
+ const utsEasyComAutoImports = {};
243
+ function getUTSEasyComAutoImports() {
244
+ return utsEasyComAutoImports;
245
+ }
246
+ exports.getUTSEasyComAutoImports = getUTSEasyComAutoImports;
247
+ function addUTSEasyComAutoImports(source, imports) {
248
+ if (!utsEasyComAutoImports[source]) {
249
+ utsEasyComAutoImports[source] = [imports];
250
+ }
251
+ else {
252
+ if (!utsEasyComAutoImports[source].find((item) => item[0] === imports[0])) {
253
+ utsEasyComAutoImports[source].push(imports);
254
+ }
255
+ }
256
+ }
257
+ exports.addUTSEasyComAutoImports = addUTSEasyComAutoImports;
258
+ function genUTSComponentPublicInstanceIdent(tagName) {
259
+ return (0, shared_1.capitalize)((0, shared_1.camelize)(tagName)) + 'ComponentPublicInstance';
260
+ }
261
+ exports.genUTSComponentPublicInstanceIdent = genUTSComponentPublicInstanceIdent;
262
+ function genUTSComponentPublicInstanceImported(root, fileName) {
263
+ root = (0, utils_1.normalizePath)(root);
264
+ if (path_1.default.isAbsolute(fileName) && fileName.startsWith(root)) {
265
+ fileName = (0, utils_1.normalizePath)(path_1.default.relative(root, fileName));
266
+ }
267
+ if (fileName.startsWith('@/')) {
268
+ return ((0, uts_1.genUTSClassName)(fileName.replace('@/', '')) + 'ComponentPublicInstance');
269
+ }
270
+ return (0, uts_1.genUTSClassName)(fileName) + 'ComponentPublicInstance';
271
+ }
272
+ exports.genUTSComponentPublicInstanceImported = genUTSComponentPublicInstanceImported;
@@ -12,6 +12,7 @@ export declare function initDefine(stringifyBoolean?: boolean): {
12
12
  'process.env.UNI_COMPILER_VERSION': string;
13
13
  'process.env.RUN_BY_HBUILDERX': string | boolean;
14
14
  'process.env.UNI_AUTOMATOR_WS_ENDPOINT': string;
15
+ 'process.env.UNI_AUTOMATOR_APP_WEBVIEW_SRC': string;
15
16
  'process.env.UNI_CLOUD_PROVIDER': string;
16
17
  'process.env.UNICLOUD_DEBUG': string;
17
18
  'process.env.VUE_APP_PLATFORM': string;
@@ -27,6 +27,7 @@ function initDefine(stringifyBoolean = false) {
27
27
  ? JSON.stringify(isRunByHBuilderX)
28
28
  : isRunByHBuilderX,
29
29
  'process.env.UNI_AUTOMATOR_WS_ENDPOINT': JSON.stringify(process.env.UNI_AUTOMATOR_WS_ENDPOINT || ''),
30
+ 'process.env.UNI_AUTOMATOR_APP_WEBVIEW_SRC': JSON.stringify(process.env.UNI_AUTOMATOR_APP_WEBVIEW_SRC || ''),
30
31
  'process.env.UNI_CLOUD_PROVIDER': JSON.stringify(process.env.UNI_CLOUD_PROVIDER || ''),
31
32
  'process.env.UNICLOUD_DEBUG': JSON.stringify(process.env.UNICLOUD_DEBUG || ''),
32
33
  // 兼容旧版本
package/dist/hbx/alias.js CHANGED
@@ -6,7 +6,6 @@ Object.defineProperty(exports, "__esModule", { value: true });
6
6
  exports.formatInstallHBuilderXPluginTips = exports.moduleAliasFormatter = exports.installHBuilderXPlugin = exports.initModuleAlias = void 0;
7
7
  const path_1 = __importDefault(require("path"));
8
8
  const module_alias_1 = __importDefault(require("module-alias"));
9
- const resolve_1 = __importDefault(require("resolve"));
10
9
  const env_1 = require("./env");
11
10
  const hbxPlugins = {
12
11
  // typescript: 'compile-typescript/node_modules/typescript',
@@ -38,14 +37,39 @@ function initModuleAlias() {
38
37
  Object.keys(hbxPlugins).forEach((name) => {
39
38
  module_alias_1.default.addAlias(name, path_1.default.resolve(process.env.UNI_HBUILDERX_PLUGINS, hbxPlugins[name]));
40
39
  });
41
- // https://github.com/vitejs/vite/blob/892916d040a035edde1add93c192e0b0c5c9dd86/packages/vite/src/node/plugins/css.ts#L1481
42
- const oldSync = resolve_1.default.sync;
43
- resolve_1.default.sync = (id, opts) => {
44
- if (hbxPlugins[id]) {
45
- return path_1.default.resolve(process.env.UNI_HBUILDERX_PLUGINS, hbxPlugins[id]);
46
- }
47
- return oldSync(id, opts);
48
- };
40
+ // web 平台用了 vite 内置 css 插件,该插件会加载预编译器如scss、less等,需要转向到 HBuilderX 的对应编译器插件
41
+ if (process.env.UNI_PLATFORM === 'h5' ||
42
+ process.env.UNI_PLATFORM === 'web') {
43
+ // https://github.com/vitejs/vite/blob/main/packages/vite/src/node/packages.ts#L92
44
+ // 拦截预编译器
45
+ const join = path_1.default.join;
46
+ path_1.default.join = function (...paths) {
47
+ if (paths.length === 4) {
48
+ // path.join(basedir, 'node_modules', pkgName, 'package.json')
49
+ // const basedir = paths[0]
50
+ const nodeModules = paths[1]; // = node_modules
51
+ const pkgName = paths[2];
52
+ const packageJson = paths[3]; // = package.json
53
+ if (nodeModules === 'node_modules' &&
54
+ packageJson === 'package.json' &&
55
+ hbxPlugins[pkgName]) {
56
+ return path_1.default.resolve(process.env.UNI_HBUILDERX_PLUGINS, hbxPlugins[pkgName], packageJson);
57
+ }
58
+ }
59
+ return join(...paths);
60
+ };
61
+ // https://github.com/vitejs/vite/blob/892916d040a035edde1add93c192e0b0c5c9dd86/packages/vite/src/node/plugins/css.ts#L1481
62
+ // const oldSync = resovle.sync
63
+ // resovle.sync = (id: string, opts?: SyncOpts) => {
64
+ // if ((hbxPlugins as any)[id]) {
65
+ // return path.resolve(
66
+ // process.env.UNI_HBUILDERX_PLUGINS,
67
+ // hbxPlugins[id as keyof typeof hbxPlugins]
68
+ // )
69
+ // }
70
+ // return oldSync(id, opts)
71
+ // }
72
+ }
49
73
  }
50
74
  }
51
75
  exports.initModuleAlias = initModuleAlias;
package/dist/json/json.js CHANGED
@@ -4,6 +4,10 @@ exports.parseJson = void 0;
4
4
  const jsonc_parser_1 = require("jsonc-parser");
5
5
  const preprocess_1 = require("../preprocess");
6
6
  function parseJson(jsonStr, shouldPre = false) {
7
- return (0, jsonc_parser_1.parse)(shouldPre ? (0, preprocess_1.preJson)(jsonStr) : jsonStr);
7
+ return (0, jsonc_parser_1.parse)(shouldPre
8
+ ? process.env.UNI_APP_X === 'true'
9
+ ? (0, preprocess_1.preUVueJson)(jsonStr)
10
+ : (0, preprocess_1.preJson)(jsonStr)
11
+ : jsonStr);
8
12
  }
9
13
  exports.parseJson = parseJson;
@@ -97,6 +97,10 @@ function getRouterOptions(manifestJson) {
97
97
  }
98
98
  exports.getRouterOptions = getRouterOptions;
99
99
  function isEnableTreeShaking(manifestJson) {
100
+ // 自动化测试时,一定不摇树
101
+ if (process.env.UNI_AUTOMATOR_WS_ENDPOINT) {
102
+ return false;
103
+ }
100
104
  return manifestJson.h5?.optimization?.treeShaking?.enable !== false;
101
105
  }
102
106
  exports.isEnableTreeShaking = isEnableTreeShaking;
@@ -17,7 +17,7 @@ export declare function isMiniProgramUsingComponent(name: string, options: {
17
17
  componentsDir?: string;
18
18
  }): boolean;
19
19
  interface MiniProgramComponents {
20
- [name: string]: 'plugin' | 'component' | 'dynamicLib';
20
+ [name: string]: 'plugin' | 'component' | 'dynamicLib' | 'ext';
21
21
  }
22
22
  export declare function findMiniProgramUsingComponents({ filename, inputDir, componentsDir, }: {
23
23
  filename: string;
@@ -141,11 +141,17 @@ function findMiniProgramUsingComponent(usingComponents, componentsDir) {
141
141
  return Object.keys(usingComponents).reduce((res, name) => {
142
142
  const path = usingComponents[name];
143
143
  if (path.includes('plugin://')) {
144
+ // mp-weixin & mp-alipay
144
145
  res[name] = 'plugin';
145
146
  }
146
147
  else if (path.includes('dynamicLib://')) {
148
+ // mp-baidu
147
149
  res[name] = 'dynamicLib';
148
150
  }
151
+ else if (path.includes('ext://')) {
152
+ // mp-toutiao
153
+ res[name] = 'ext';
154
+ }
149
155
  else if (componentsDir && path.includes(componentsDir + '/')) {
150
156
  res[name] = 'component';
151
157
  }
@@ -114,7 +114,7 @@ function parsePagesJson(jsonStr, platform, { debug, darkmode, networkTimeout, su
114
114
  appJson.tabBar = tabBar;
115
115
  }
116
116
  }
117
- ;
117
+ (0, pages_1.filterPlatformPages)(platform, pagesJson);
118
118
  ['preloadRule', 'workers', 'plugins', 'entryPagePath'].forEach((name) => {
119
119
  if ((0, shared_1.hasOwn)(pagesJson, name)) {
120
120
  appJson[name] = pagesJson[name];
@@ -28,4 +28,5 @@ export declare function removePlatformStyle(pageStyle: Record<string, any>): Rec
28
28
  export declare function normalizePagesRoute(pagesJson: UniApp.PagesJson): UniApp.UniRoute[];
29
29
  declare function parseSubpackagesRoot(inputDir: string, platform: UniApp.PLATFORM): string[];
30
30
  export declare const parseSubpackagesRootOnce: typeof parseSubpackagesRoot;
31
+ export declare function filterPlatformPages(platform: UniApp.PLATFORM, pagesJson: UniApp.PagesJson): void;
31
32
  export {};
@@ -3,7 +3,7 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
3
3
  return (mod && mod.__esModule) ? mod : { "default": mod };
4
4
  };
5
5
  Object.defineProperty(exports, "__esModule", { value: true });
6
- exports.parseSubpackagesRootOnce = exports.normalizePagesRoute = exports.removePlatformStyle = exports.validatePages = exports.normalizePagesJson = exports.parsePagesJsonOnce = exports.parsePagesJson = exports.isUniPageSfcFile = exports.isUniPageSetupAndTs = exports.isUniPageFile = void 0;
6
+ exports.filterPlatformPages = exports.parseSubpackagesRootOnce = exports.normalizePagesRoute = exports.removePlatformStyle = exports.validatePages = exports.normalizePagesJson = exports.parsePagesJsonOnce = exports.parsePagesJson = exports.isUniPageSfcFile = exports.isUniPageSetupAndTs = exports.isUniPageFile = void 0;
7
7
  const fs_1 = __importDefault(require("fs"));
8
8
  const path_1 = __importDefault(require("path"));
9
9
  const shared_1 = require("@vue/shared");
@@ -108,6 +108,8 @@ function normalizePagesJson(jsonStr, platform, { subpackages, } = { subpackages:
108
108
  delete pagesJson.tabBar;
109
109
  }
110
110
  }
111
+ // 过滤平台page
112
+ filterPlatformPages(platform, pagesJson);
111
113
  // 缓存页面列表
112
114
  pagesCacheSet.clear();
113
115
  pagesJson.pages.forEach((page) => pagesCacheSet.add(page.path));
@@ -122,16 +124,19 @@ exports.normalizePagesJson = normalizePagesJson;
122
124
  function validatePages(pagesJson, jsonStr) {
123
125
  if (!(0, shared_1.isArray)(pagesJson.pages)) {
124
126
  pagesJson.pages = [];
125
- throw new Error(`[uni-app] Error: pages.json->pages parse failed.`);
127
+ console.error(`[uni-app] Error: pages.json->pages parse failed.`);
128
+ process.exit(0);
126
129
  }
127
130
  else if (!pagesJson.pages.length) {
128
- throw new Error(`[uni-app] Error: pages.json->pages must contain at least 1 page.`);
131
+ console.error(`[uni-app] Error: pages.json->pages must contain at least 1 page.`);
132
+ process.exit(0);
129
133
  }
130
134
  else {
131
135
  const pages = [];
132
136
  pagesJson.pages.forEach((page) => {
133
137
  if (pages.indexOf(page.path) !== -1) {
134
- throw new Error(`[uni-app] Error: pages.json->${page.path} duplication.`);
138
+ console.error(`[uni-app] Error: pages.json->${page.path} duplication.`);
139
+ process.exit(0);
135
140
  }
136
141
  pages.push(page.path);
137
142
  });
@@ -441,3 +446,64 @@ function parseSubpackagesRoot(inputDir, platform) {
441
446
  return roots;
442
447
  }
443
448
  exports.parseSubpackagesRootOnce = (0, uni_shared_1.once)(parseSubpackagesRoot);
449
+ let isInvalidPagesWarned = false;
450
+ function filterPlatformPages(platform, pagesJson) {
451
+ const invalidPages = [];
452
+ pagesJson.pages = pagesJson.pages.filter(({ path }) => {
453
+ if (isPlatformPage(platform, path)) {
454
+ return true;
455
+ }
456
+ invalidPages.push(path);
457
+ return false;
458
+ });
459
+ if (pagesJson.subPackages) {
460
+ pagesJson.subPackages.forEach((subPackage) => {
461
+ if (subPackage.pages) {
462
+ subPackage.pages = subPackage.pages.filter(({ path }) => {
463
+ const pagePath = subPackage.root + '/' + path;
464
+ if (isPlatformPage(platform, pagePath)) {
465
+ return true;
466
+ }
467
+ invalidPages.push(pagePath);
468
+ return false;
469
+ });
470
+ }
471
+ });
472
+ }
473
+ if (pagesJson.subpackages) {
474
+ pagesJson.subpackages.forEach((subPackage) => {
475
+ if (subPackage.pages) {
476
+ subPackage.pages = subPackage.pages.filter(({ path }) => {
477
+ const pagePath = subPackage.root + '/' + path;
478
+ if (isPlatformPage(platform, pagePath)) {
479
+ return true;
480
+ }
481
+ invalidPages.push(pagePath);
482
+ return false;
483
+ });
484
+ }
485
+ });
486
+ }
487
+ // 目前仅启动的时候警告一次,该方法可能会被调用很多次
488
+ if (invalidPages.length) {
489
+ if (!isInvalidPagesWarned) {
490
+ isInvalidPagesWarned = true;
491
+ console.log(`已忽略页面:${invalidPages.join('、')}。详见:https://uniapp.dcloud.net.cn/tutorial/platform.html#platforms`);
492
+ }
493
+ }
494
+ }
495
+ exports.filterPlatformPages = filterPlatformPages;
496
+ function isPlatformPage(platform, pagePath) {
497
+ if (pagePath.startsWith('platforms/')) {
498
+ if (platform === 'app' || platform === 'app-plus') {
499
+ return (pagePath.startsWith('platforms/app/') ||
500
+ pagePath.startsWith('platforms/app-plus/'));
501
+ }
502
+ else if (platform === 'h5' || platform === 'web') {
503
+ return (pagePath.startsWith('platforms/h5/') ||
504
+ pagePath.startsWith('platforms/web/'));
505
+ }
506
+ return pagePath.startsWith('platforms/' + platform + '/');
507
+ }
508
+ return true;
509
+ }
@@ -14,6 +14,7 @@ const utils_1 = require("../../utils");
14
14
  const uniRoutes_1 = require("../app/pages/uniRoutes");
15
15
  const uniConfig_1 = require("./uniConfig");
16
16
  const utils_2 = require("../../vite/plugins/vitejs/utils");
17
+ const preprocess_1 = require("../../preprocess");
17
18
  var manifest_1 = require("./manifest");
18
19
  Object.defineProperty(exports, "parseUniXFlexDirection", { enumerable: true, get: function () { return manifest_1.parseUniXFlexDirection; } });
19
20
  Object.defineProperty(exports, "parseUniXSplashScreen", { enumerable: true, get: function () { return manifest_1.parseUniXSplashScreen; } });
@@ -58,8 +59,7 @@ function checkPagesJson(jsonStr, inputDir) {
58
59
  if (pagePathNodes.length) {
59
60
  for (const node of pagePathNodes) {
60
61
  const pagePath = node.value ?? '';
61
- if (fs_1.default.existsSync(path_1.default.join(inputDir, pagePath + '.uvue')) ||
62
- fs_1.default.existsSync(path_1.default.join(inputDir, pagePath + '.vue'))) {
62
+ if (pageExistsWithCaseSync(path_1.default.join(inputDir, pagePath))) {
63
63
  continue;
64
64
  }
65
65
  const { line, column } = (0, utils_2.offsetToLineColumn)(jsonStr, node.offset);
@@ -78,6 +78,18 @@ function checkPagesJson(jsonStr, inputDir) {
78
78
  return true;
79
79
  }
80
80
  exports.checkPagesJson = checkPagesJson;
81
+ function pageExistsWithCaseSync(pagePath) {
82
+ try {
83
+ const files = fs_1.default.readdirSync(path_1.default.dirname(pagePath));
84
+ const basename = path_1.default.basename(pagePath);
85
+ const uvuePage = basename + '.uvue';
86
+ const vuePage = basename + '.vue';
87
+ return files.some((file) => file === uvuePage || file === vuePage);
88
+ }
89
+ catch (e) {
90
+ return false;
91
+ }
92
+ }
81
93
  function findSubPackageRoot(node) {
82
94
  const child = node.children?.find((child) => child.type === 'property' &&
83
95
  child.children &&
@@ -122,6 +134,8 @@ function walkNode(node, pagePathNodes) {
122
134
  }
123
135
  }
124
136
  function normalizeUniAppXAppPagesJson(jsonStr) {
137
+ // 先条件编译
138
+ jsonStr = (0, preprocess_1.preUVueJson)(jsonStr);
125
139
  checkPagesJson(jsonStr, process.env.UNI_INPUT_DIR);
126
140
  const pagesJson = {
127
141
  pages: [],
@@ -131,9 +145,9 @@ function normalizeUniAppXAppPagesJson(jsonStr) {
131
145
  pages: [],
132
146
  globalStyle: {},
133
147
  };
134
- // preprocess
135
148
  try {
136
- userPagesJson = (0, json_1.parseJson)(jsonStr, true);
149
+ // 此处不需要条件编译了
150
+ userPagesJson = (0, json_1.parseJson)(jsonStr, false);
137
151
  }
138
152
  catch (e) {
139
153
  console.error(`[vite] Error: pages.json parse failed.\n`, jsonStr, e);
@@ -163,6 +177,8 @@ function normalizeUniAppXAppPagesJson(jsonStr) {
163
177
  if (userPagesJson.uniIdRouter) {
164
178
  pagesJson.uniIdRouter = userPagesJson.uniIdRouter;
165
179
  }
180
+ // 是否应该用 process.env.UNI_UTS_PLATFORM
181
+ (0, pages_1.filterPlatformPages)(process.env.UNI_PLATFORM, pagesJson);
166
182
  return pagesJson;
167
183
  }
168
184
  exports.normalizeUniAppXAppPagesJson = normalizeUniAppXAppPagesJson;
@@ -30,6 +30,9 @@ const initWarnFormattersOnce = (0, uni_shared_1.once)(() => {
30
30
  warnFormatters.push(log_1.removeWarnFormatter);
31
31
  });
32
32
  function formatErrMsg(msg, options) {
33
+ if (options && (0, env_1.isInHBuilderX)()) {
34
+ options.timestamp = false;
35
+ }
33
36
  initErrFormattersOnce();
34
37
  const formatter = errFormatters.find(({ test }) => test(msg, options));
35
38
  if (formatter) {
@@ -76,6 +79,9 @@ function formatInfoMsg(msg, options) {
76
79
  }
77
80
  exports.formatInfoMsg = formatInfoMsg;
78
81
  function formatWarnMsg(msg, options) {
82
+ if (options && (0, env_1.isInHBuilderX)()) {
83
+ options.timestamp = false;
84
+ }
79
85
  initWarnFormattersOnce();
80
86
  const formatter = warnFormatters.find(({ test }) => test(msg, options));
81
87
  if (formatter) {
@@ -5,6 +5,7 @@ declare const _default: {
5
5
  readonly 'dev.exclusion': "Please configure the antivirus software to set up an exclusion list for scanning, reducing system resource consumption. [详情](https://uniapp.dcloud.net.cn/uni-app-x/compiler/#tips)";
6
6
  readonly 'dev.performance.nvue': "Especially the sourcemap of app-nvue has a greater impact";
7
7
  readonly 'dev.performance.mp': "To officially release, please click the release menu or use the cli release command to release";
8
+ readonly 'dev.performance.web': "\nVite is compiled on demand, and clicking on an uncompiled page at runtime will compile first and then load, resulting in a slower display, and there is no such problem after release.";
8
9
  readonly 'build.done': "DONE Build complete.";
9
10
  readonly 'dev.watching.start': "Compiling...";
10
11
  readonly 'dev.watching.end': "DONE Build complete. Watching for changes...";
@@ -7,6 +7,7 @@ exports.default = {
7
7
  'dev.exclusion': 'Please configure the antivirus software to set up an exclusion list for scanning, reducing system resource consumption. [详情](https://uniapp.dcloud.net.cn/uni-app-x/compiler/#tips)',
8
8
  'dev.performance.nvue': 'Especially the sourcemap of app-nvue has a greater impact',
9
9
  'dev.performance.mp': 'To officially release, please click the release menu or use the cli release command to release',
10
+ 'dev.performance.web': '\nVite is compiled on demand, and clicking on an uncompiled page at runtime will compile first and then load, resulting in a slower display, and there is no such problem after release.',
10
11
  'build.done': 'DONE Build complete.',
11
12
  'dev.watching.start': 'Compiling...',
12
13
  'dev.watching.end': 'DONE Build complete. Watching for changes...',
@@ -5,6 +5,7 @@ export declare const M: {
5
5
  readonly 'dev.exclusion': "请在杀毒软件中设置扫描排除名单,减少系统资源消耗。[详情](https://uniapp.dcloud.net.cn/uni-app-x/compiler/#tips)";
6
6
  readonly 'dev.performance.nvue': "尤其是 app-nvue 的 sourcemap 影响较大";
7
7
  readonly 'dev.performance.mp': "若要正式发布,请点击发行菜单或使用 cli 发布命令进行发布";
8
+ readonly 'dev.performance.web': "\nvite是按需编译,运行时点击某个未编译页面会先编译后加载,导致显示较慢,发行后无此问题。";
8
9
  readonly 'build.done': "DONE Build complete.";
9
10
  readonly 'dev.watching.start': "开始差量编译...";
10
11
  readonly 'dev.watching.end': "DONE Build complete. Watching for changes...";
@@ -49,6 +50,7 @@ export declare const M: {
49
50
  readonly 'dev.exclusion': "Please configure the antivirus software to set up an exclusion list for scanning, reducing system resource consumption. [详情](https://uniapp.dcloud.net.cn/uni-app-x/compiler/#tips)";
50
51
  readonly 'dev.performance.nvue': "Especially the sourcemap of app-nvue has a greater impact";
51
52
  readonly 'dev.performance.mp': "To officially release, please click the release menu or use the cli release command to release";
53
+ readonly 'dev.performance.web': "\nVite is compiled on demand, and clicking on an uncompiled page at runtime will compile first and then load, resulting in a slower display, and there is no such problem after release.";
52
54
  readonly 'build.done': "DONE Build complete.";
53
55
  readonly 'dev.watching.start': "Compiling...";
54
56
  readonly 'dev.watching.end': "DONE Build complete. Watching for changes...";
@@ -5,6 +5,7 @@ declare const _default: {
5
5
  readonly 'dev.exclusion': "请在杀毒软件中设置扫描排除名单,减少系统资源消耗。[详情](https://uniapp.dcloud.net.cn/uni-app-x/compiler/#tips)";
6
6
  readonly 'dev.performance.nvue': "尤其是 app-nvue 的 sourcemap 影响较大";
7
7
  readonly 'dev.performance.mp': "若要正式发布,请点击发行菜单或使用 cli 发布命令进行发布";
8
+ readonly 'dev.performance.web': "\nvite是按需编译,运行时点击某个未编译页面会先编译后加载,导致显示较慢,发行后无此问题。";
8
9
  readonly 'build.done': "DONE Build complete.";
9
10
  readonly 'dev.watching.start': "开始差量编译...";
10
11
  readonly 'dev.watching.end': "DONE Build complete. Watching for changes...";
@@ -7,6 +7,7 @@ exports.default = {
7
7
  'dev.exclusion': '请在杀毒软件中设置扫描排除名单,减少系统资源消耗。[详情](https://uniapp.dcloud.net.cn/uni-app-x/compiler/#tips)',
8
8
  'dev.performance.nvue': '尤其是 app-nvue 的 sourcemap 影响较大',
9
9
  'dev.performance.mp': '若要正式发布,请点击发行菜单或使用 cli 发布命令进行发布',
10
+ 'dev.performance.web': '\nvite是按需编译,运行时点击某个未编译页面会先编译后加载,导致显示较慢,发行后无此问题。',
10
11
  'build.done': 'DONE Build complete.',
11
12
  'dev.watching.start': '开始差量编译...',
12
13
  'dev.watching.end': 'DONE Build complete. Watching for changes...',
@@ -1,7 +1,7 @@
1
1
  import type { EmittedAsset } from 'rollup';
2
2
  import type { ElementNode } from '@vue/compiler-core';
3
3
  type LazyElementFn = (node: ElementNode, context: {
4
- isMiniProgramComponent(name: string): 'plugin' | 'component' | 'dynamicLib' | undefined;
4
+ isMiniProgramComponent(name: string): 'plugin' | 'component' | 'dynamicLib' | 'ext' | undefined;
5
5
  }) => {
6
6
  [name: string]: {
7
7
  name: 'on' | 'bind';
@@ -62,7 +62,7 @@ function filterPrefersColorScheme(root, force = false) {
62
62
  const filePath = root.source?.input.file;
63
63
  if (force || (filePath && filePath.includes('@dcloudio'))) {
64
64
  root.walkAtRules((rule) => {
65
- if (rule.params.includes('prefers-color-scheme')) {
65
+ if (/prefers-color-scheme\s*:\s*dark/.test(rule.params)) {
66
66
  rule.remove();
67
67
  }
68
68
  });
@@ -70,7 +70,7 @@ function initPreContext(platform, userPreContext, utsPlatform, isX) {
70
70
  }
71
71
  if (platform === 'app' || platform === 'app-plus') {
72
72
  defaultContext.APP = true;
73
- defaultContext.APP_PLUS = true;
73
+ defaultContext.APP_PLUS = isX ? false : true;
74
74
  vueContext.APP_VUE = true;
75
75
  nvueContext.APP_NVUE = true;
76
76
  nvueContext.APP_PLUS_NVUE = true;
@@ -7,10 +7,16 @@ const { preprocess } = require('../../lib/preprocess');
7
7
  var context_2 = require("./context");
8
8
  Object.defineProperty(exports, "initPreContext", { enumerable: true, get: function () { return context_2.initPreContext; } });
9
9
  function preJs(jsCode) {
10
+ if (process.env.UNI_APP_X === 'true') {
11
+ return preUVueJs(jsCode);
12
+ }
10
13
  return preprocess(jsCode, (0, context_1.getPreVueContext)(), { type: 'js' });
11
14
  }
12
15
  exports.preJs = preJs;
13
16
  function preHtml(htmlCode) {
17
+ if (process.env.UNI_APP_X === 'true') {
18
+ return preUVueHtml(htmlCode);
19
+ }
14
20
  return preprocess(htmlCode, (0, context_1.getPreVueContext)(), { type: 'html' });
15
21
  }
16
22
  exports.preHtml = preHtml;
@@ -15,8 +15,14 @@ export type Defines = {
15
15
  export interface Exports {
16
16
  [name: string]: Define | Defines | false;
17
17
  }
18
+ export declare function getUniExtApiProviders(): {
19
+ plugin: string;
20
+ service: string;
21
+ name?: string | undefined;
22
+ servicePlugin?: string | undefined;
23
+ }[];
18
24
  export declare function parseUniExtApis(vite: boolean | undefined, platform: typeof process.env.UNI_UTS_PLATFORM, language?: UTSTargetLanguage): Injects;
19
- type Injects = {
25
+ export type Injects = {
20
26
  [name: string]: string | [string, string] | [string, string, DefineOptions['app']] | false;
21
27
  };
22
28
  /**
@@ -41,4 +47,3 @@ type Injects = {
41
47
  * @returns
42
48
  */
43
49
  export declare function parseInjects(vite: boolean | undefined, platform: typeof process.env.UNI_UTS_PLATFORM, language: UTSTargetLanguage, source: string, uniModuleRootDir: string, exports?: Exports): Injects;
44
- export {};