@dcloudio/uni-cli-shared 3.0.0-5000720260410001 → 3.0.0-5010420260703001

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 (90) hide show
  1. package/dist/constants.d.ts +1 -3
  2. package/dist/constants.js +2 -6
  3. package/dist/deps.d.ts +1 -0
  4. package/dist/deps.js +22 -13
  5. package/dist/dom2/fontFamily.d.ts +4 -0
  6. package/dist/dom2/fontFamily.js +21 -0
  7. package/dist/dom2/index.d.ts +3 -0
  8. package/dist/dom2/index.js +3 -0
  9. package/dist/dom2/rootScrollView.d.ts +47 -0
  10. package/dist/dom2/rootScrollView.js +283 -0
  11. package/dist/dom2/sharedData.d.ts +4 -0
  12. package/dist/dom2/sharedData.js +40 -5
  13. package/dist/dom2/vue.d.ts +17 -0
  14. package/dist/dom2/vue.js +50 -0
  15. package/dist/easycom.d.ts +1 -0
  16. package/dist/easycom.js +23 -9
  17. package/dist/env/define.d.ts +0 -1
  18. package/dist/env/define.js +3 -11
  19. package/dist/hbx/alias.js +66 -10
  20. package/dist/hbx/log.js +9 -2
  21. package/dist/index.d.ts +2 -1
  22. package/dist/index.js +3 -1
  23. package/dist/json/app/manifest/plus.js +9 -1
  24. package/dist/json/index.d.ts +1 -1
  25. package/dist/json/index.js +2 -1
  26. package/dist/json/uni-x/index.d.ts +6 -0
  27. package/dist/json/uni-x/index.js +54 -1
  28. package/dist/json/uni-x/manifest.d.ts +1 -1
  29. package/dist/json/uni-x/manifest.js +2 -1
  30. package/dist/json/utils.js +24 -0
  31. package/dist/messages/en.d.ts +10 -2
  32. package/dist/messages/en.js +10 -2
  33. package/dist/messages/index.d.ts +20 -4
  34. package/dist/messages/zh_CN.d.ts +10 -2
  35. package/dist/messages/zh_CN.js +10 -2
  36. package/dist/mp/style.js +6 -2
  37. package/dist/postcss/plugins/stylePluginExternal.d.ts +9 -10
  38. package/dist/postcss/plugins/stylePluginExternal.js +51 -45
  39. package/dist/uni_modules.cloud.d.ts +7 -1
  40. package/dist/uni_modules.cloud.js +131 -14
  41. package/dist/uni_modules.js +3 -2
  42. package/dist/utils.js +5 -0
  43. package/dist/uts.d.ts +1 -0
  44. package/dist/uts.js +90 -6
  45. package/dist/vite/autoImport.js +7 -4
  46. package/dist/vite/cloud.js +13 -6
  47. package/dist/vite/extApi.js +4 -1
  48. package/dist/vite/plugins/inject.js +4 -1
  49. package/dist/vite/plugins/json.js +2 -69
  50. package/dist/vite/plugins/pre.js +2 -0
  51. package/dist/vite/plugins/stats.d.ts +5 -1
  52. package/dist/vite/plugins/stats.js +74 -3
  53. package/dist/vite/plugins/uts/uni_modules.d.ts +1 -1
  54. package/dist/vite/plugins/uts/uni_modules.js +30 -12
  55. package/dist/vite/plugins/vitejs/plugins/css.d.ts +2 -2
  56. package/dist/vite/plugins/vitejs/plugins/css.js +10 -5
  57. package/dist/vue/transforms/index.d.ts +1 -0
  58. package/dist/vue/transforms/index.js +1 -0
  59. package/dist/vue/transforms/transformTeleport.d.ts +2 -0
  60. package/dist/vue/transforms/transformTeleport.js +68 -0
  61. package/dist/vue/transforms/x/transformDirection.js +33 -4
  62. package/dist/workers.d.ts +1 -0
  63. package/dist/workers.js +12 -5
  64. package/dist/x.d.ts +10 -0
  65. package/dist/x.js +39 -0
  66. package/lib/dom2/app/@vitejs/plugin-vue/dist/index.cjs +0 -7
  67. package/lib/dom2/app/@vitejs/plugin-vue/dist/index.mjs +0 -7
  68. package/lib/dom2/app/@vue/compiler-core/dist/compiler-core.cjs.js +58 -63
  69. package/lib/dom2/app/@vue/compiler-core/dist/compiler-core.cjs.prod.js +58 -63
  70. package/lib/dom2/app/@vue/compiler-core/dist/compiler-core.d.ts +7 -1
  71. package/lib/dom2/app/@vue/compiler-core/dist/compiler-core.esm-bundler.js +22 -47
  72. package/lib/dom2/app/@vue/compiler-dom/dist/compiler-dom.cjs.js +12 -23
  73. package/lib/dom2/app/@vue/compiler-dom/dist/compiler-dom.cjs.prod.js +12 -22
  74. package/lib/dom2/app/@vue/compiler-dom/dist/compiler-dom.esm-browser.js +23 -74
  75. package/lib/dom2/app/@vue/compiler-dom/dist/compiler-dom.esm-browser.prod.js +5 -5
  76. package/lib/dom2/app/@vue/compiler-dom/dist/compiler-dom.esm-bundler.js +3 -20
  77. package/lib/dom2/app/@vue/compiler-dom/dist/compiler-dom.global.js +310 -363
  78. package/lib/dom2/app/@vue/compiler-dom/dist/compiler-dom.global.prod.js +5 -5
  79. package/lib/dom2/app/@vue/compiler-sfc/dist/compiler-sfc.cjs.js +810 -579
  80. package/lib/dom2/app/@vue/compiler-sfc/dist/compiler-sfc.d.ts +33 -11114
  81. package/lib/dom2/app/@vue/compiler-sfc/dist/compiler-sfc.esm-browser.js +1638 -1250
  82. package/lib/dom2/app/@vue/compiler-vapor/dist/compiler-vapor.cjs.js +1031 -599
  83. package/lib/dom2/app/@vue/compiler-vapor/dist/compiler-vapor.d.ts +470 -328
  84. package/lib/dom2/app/@vue/compiler-vapor/dist/compiler-vapor.esm-browser.js +1154 -709
  85. package/lib/dom2/app/@vue/compiler-vapor-dom2/dist/compiler-vapor-dom2.cjs.js +1 -1
  86. package/lib/dom2/app/@vue/shared/dist/shared.cjs.js +16 -25
  87. package/lib/dom2/app/@vue/shared/dist/shared.cjs.prod.js +16 -25
  88. package/lib/dom2/app/@vue/shared/dist/shared.d.ts +5 -0
  89. package/lib/dom2/app/@vue/shared/dist/shared.esm-bundler.js +11 -23
  90. package/package.json +6 -6
@@ -1,5 +1,9 @@
1
1
  declare const _default: {
2
2
  readonly 'app.compiler.version': "编译器版本:{version}";
3
+ readonly 'view.render.compiler.target': "当前视图层编译目标:{target}";
4
+ readonly 'view.render.compiler.target.bytecode': "字节码";
5
+ readonly 'view.render.compiler.target.nativecode': "机器码";
6
+ readonly 'style.isolation.version': "当前样式隔离策略:{version}。详见:https://doc.dcloud.net.cn/uni-app-x/css/common/style-isolation.html";
3
7
  readonly compiling: "正在编译中...";
4
8
  readonly 'dev.performance': "请注意运行模式下,因日志输出、sourcemap 以及未压缩源码等原因,性能和包体积,均不及发行模式。";
5
9
  readonly 'dev.performance.nvue': "尤其是 app-nvue 的 sourcemap 影响较大";
@@ -11,14 +15,17 @@ declare const _default: {
11
15
  readonly 'dev.watching.end.pages': "DONE Build complete. PAGES:{pages}";
12
16
  readonly 'dev.watching.end.files': "DONE Build complete. FILES:{files}";
13
17
  readonly 'dev.watching.restart.vapor': "DONE Restart required. 切换蒸汽模式需要重新运行才能生效。";
18
+ readonly 'dev.watching.vapor.render.target': "manifest.json 中更改了视图层编译目标为{manifestTarget},但注意运行控制台还是{runtimeTarget}。";
14
19
  readonly 'build.failed': "DONE Build failed.";
15
20
  readonly 'compiler.build.failed': "编译失败";
16
21
  readonly 'stat.warn.appid': "当前应用未配置 appid,无法使用 uni 统计,详情参考:https://ask.dcloud.net.cn/article/36303";
17
- readonly 'stat.warn.version': "当前应用未配置uni统计版本,默认使用1.0版本;建议使用uni统计2.0版本 ,私有部署数据更安全,代码开源可定制。详情:https://uniapp.dcloud.io/uni-stat";
18
- readonly 'stat.warn.tip': "已开启 uni统计{version} 版本";
22
+ readonly 'stat.warn.version': "当前应用未配置 uni 统计版本,默认使用公有版;可配置为公有版或私有版。详情:https://uniapp.dcloud.io/uni-stat";
23
+ readonly 'stat.warn.tip': "已开启uni 统计 2.0{type}";
19
24
  readonly 'i18n.fallbackLocale.default': "当前应用未在 manifest.json 配置 fallbackLocale,默认使用:{locale}";
20
25
  readonly 'i18n.fallbackLocale.missing': "当前应用配置的 fallbackLocale 或 locale 为:{locale},但 locale 目录缺少该语言文件";
21
26
  readonly 'easycom.conflict': "easycom组件冲突:";
27
+ readonly 'dom2.compatible.component': "蒸汽模式不支持 uni-app 兼容模式组件 {name},检测到其实现文件为 {file}。请改用标准模式的UTS组件实现来实现。";
28
+ readonly 'dom2.root.scroll.view': "蒸汽模式下页面可滚动,建议移除根节点 scroll-view,以避免嵌套滚动。详情: https://doc.dcloud.net.cn/uni-app-x/page.html#disablescroll";
22
29
  readonly 'mp.component.args[0]': "{0}的第一个参数必须为静态字符串";
23
30
  readonly 'mp.component.args[1]': "{0}需要两个参数";
24
31
  readonly 'mp.360.unsupported': "vue3暂不支持360小程序";
@@ -48,5 +55,6 @@ declare const _default: {
48
55
  readonly 'uni_modules.import': "插件[{0}]仅支持 @/uni_modules/{1} 方式引入,不支持直接导入内部文件 {2}。";
49
56
  readonly 'pages.json.page.notfound': "页面\"{pagePath}\"不存在,请确保填写的页面路径不包含文件后缀,且必须与真实的文件路径大小写保持一致。";
50
57
  readonly 'pages.json.page.slash': "路径 \"{pagePath}\" 不能以 \"/\" 开头";
58
+ readonly 'pages.json.tabbar.page.notfound': "tabBar 中配置的页面 \"{pagePath}\" 未在 pages.json 中注册。";
51
59
  };
52
60
  export default _default;
@@ -2,6 +2,10 @@
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.default = {
4
4
  'app.compiler.version': '编译器版本:{version}',
5
+ 'view.render.compiler.target': '当前视图层编译目标:{target}',
6
+ 'view.render.compiler.target.bytecode': '字节码',
7
+ 'view.render.compiler.target.nativecode': '机器码',
8
+ 'style.isolation.version': '当前样式隔离策略:{version}。详见:https://doc.dcloud.net.cn/uni-app-x/css/common/style-isolation.html',
5
9
  compiling: '正在编译中...',
6
10
  'dev.performance': '请注意运行模式下,因日志输出、sourcemap 以及未压缩源码等原因,性能和包体积,均不及发行模式。',
7
11
  'dev.performance.nvue': '尤其是 app-nvue 的 sourcemap 影响较大',
@@ -13,14 +17,17 @@ exports.default = {
13
17
  'dev.watching.end.pages': 'DONE Build complete. PAGES:{pages}',
14
18
  'dev.watching.end.files': 'DONE Build complete. FILES:{files}',
15
19
  'dev.watching.restart.vapor': 'DONE Restart required. 切换蒸汽模式需要重新运行才能生效。',
20
+ 'dev.watching.vapor.render.target': 'manifest.json 中更改了视图层编译目标为{manifestTarget},但注意运行控制台还是{runtimeTarget}。',
16
21
  'build.failed': 'DONE Build failed.',
17
22
  'compiler.build.failed': '编译失败',
18
23
  'stat.warn.appid': '当前应用未配置 appid,无法使用 uni 统计,详情参考:https://ask.dcloud.net.cn/article/36303',
19
- 'stat.warn.version': '当前应用未配置uni统计版本,默认使用1.0版本;建议使用uni统计2.0版本 ,私有部署数据更安全,代码开源可定制。详情:https://uniapp.dcloud.io/uni-stat',
20
- 'stat.warn.tip': '已开启 uni统计{version} 版本',
24
+ 'stat.warn.version': '当前应用未配置 uni 统计版本,默认使用公有版;可配置为公有版或私有版。详情:https://uniapp.dcloud.io/uni-stat',
25
+ 'stat.warn.tip': '已开启uni 统计 2.0{type}',
21
26
  'i18n.fallbackLocale.default': '当前应用未在 manifest.json 配置 fallbackLocale,默认使用:{locale}',
22
27
  'i18n.fallbackLocale.missing': '当前应用配置的 fallbackLocale 或 locale 为:{locale},但 locale 目录缺少该语言文件',
23
28
  'easycom.conflict': 'easycom组件冲突:',
29
+ 'dom2.compatible.component': '蒸汽模式不支持 uni-app 兼容模式组件 {name},检测到其实现文件为 {file}。请改用标准模式的UTS组件实现来实现。',
30
+ 'dom2.root.scroll.view': '蒸汽模式下页面可滚动,建议移除根节点 scroll-view,以避免嵌套滚动。详情: https://doc.dcloud.net.cn/uni-app-x/page.html#disablescroll',
24
31
  'mp.component.args[0]': '{0}的第一个参数必须为静态字符串',
25
32
  'mp.component.args[1]': '{0}需要两个参数',
26
33
  'mp.360.unsupported': 'vue3暂不支持360小程序',
@@ -51,4 +58,5 @@ exports.default = {
51
58
  'uni_modules.import': '插件[{0}]仅支持 @/uni_modules/{1} 方式引入,不支持直接导入内部文件 {2}。',
52
59
  'pages.json.page.notfound': '页面"{pagePath}"不存在,请确保填写的页面路径不包含文件后缀,且必须与真实的文件路径大小写保持一致。',
53
60
  'pages.json.page.slash': '路径 "{pagePath}" 不能以 "/" 开头',
61
+ 'pages.json.tabbar.page.notfound': 'tabBar 中配置的页面 "{pagePath}" 未在 pages.json 中注册。',
54
62
  };
package/dist/mp/style.js CHANGED
@@ -4,6 +4,7 @@ exports.transformPartSelector = exports.transformScopedCss = void 0;
4
4
  const tags_1 = require("./tags");
5
5
  const logs_1 = require("../logs");
6
6
  const uni_shared_1 = require("@dcloudio/uni-shared");
7
+ const HTML_TAG_SELECTOR_RE = new RegExp(`/\\*[\\s\\S]*?(?:\\*/|$)|[\\s,}](${Object.keys(tags_1.HTML_TO_MINI_PROGRAM_TAGS).join('|')})\\s*(?=,|\\{)`, 'g');
7
8
  function transformScopedCss(cssCode) {
8
9
  checkHtmlTagSelector(cssCode);
9
10
  return cssCode.replace(/\[(data-v-[a-f0-9]{8})\]/gi, (_, scopedId) => {
@@ -18,8 +19,11 @@ function transformPartSelector(cssCode) {
18
19
  }
19
20
  exports.transformPartSelector = transformPartSelector;
20
21
  function checkHtmlTagSelector(cssCode) {
21
- for (const tag in tags_1.HTML_TO_MINI_PROGRAM_TAGS) {
22
- if (new RegExp(`( |\n|\t|,|})${tag}( *)(,|{)`, 'g').test(cssCode)) {
22
+ HTML_TAG_SELECTOR_RE.lastIndex = 0;
23
+ let match;
24
+ while ((match = HTML_TAG_SELECTOR_RE.exec(cssCode))) {
25
+ const tag = match[1];
26
+ if (tag) {
23
27
  (0, logs_1.output)('warn', `小程序端 style 暂不支持 ${tag} 标签选择器,推荐使用 class 选择器,详情参考:https://uniapp.dcloud.net.cn/tutorial/migration-to-vue3.html#style`);
24
28
  break;
25
29
  }
@@ -1,17 +1,16 @@
1
1
  import type { PluginCreator } from 'postcss';
2
2
  /**
3
- * PostCSS plugin to boost specificity for page CSS based on externalClasses usage
3
+ * 基于页面 externalClasses 使用情况提升页面样式优先级
4
4
  *
5
- * For mini-program platforms (mp-*):
6
- * - If page has no externalClasses usage: no transformation
7
- * - If page has dynamic externalClasses: all selectors get page prefix
8
- * .a -> page .a
9
- * - If page has only static externalClasses: only matching selectors get page prefix
10
- * .foo -> page .foo (if "foo" is in staticClasses)
11
- * .bar -> .bar (unchanged, if "bar" is not in staticClasses)
5
+ * 小程序平台(mp-*):
6
+ * - 页面没有使用 externalClasses:不做转换
7
+ * - 页面存在动态 externalClasses:选择器最后一个 class 追加 [class]
8
+ * .a -> .a[class]
9
+ * - 页面只有静态 externalClasses:仅命中静态 class 的选择器追加 [class]
10
+ * .foo -> .foo[class](foo 在 staticClasses 中)
11
+ * .bar -> .bar(bar 不在 staticClasses 中)
12
12
  *
13
- * This ensures page styles have higher specificity than component styles
14
- * while minimizing unnecessary transformations for performance
13
+ * 追加 [class] 可以提升 class 选择器优先级,同时避免原先插入 page 带来的结构影响。
15
14
  */
16
15
  declare const externalPlugin: PluginCreator<void>;
17
16
  export default externalPlugin;
@@ -7,18 +7,17 @@ const postcss_selector_parser_1 = __importDefault(require("postcss-selector-pars
7
7
  const pages_1 = require("../../json/pages");
8
8
  const externalClasses_1 = require("../../mp/externalClasses");
9
9
  /**
10
- * PostCSS plugin to boost specificity for page CSS based on externalClasses usage
10
+ * 基于页面 externalClasses 使用情况提升页面样式优先级
11
11
  *
12
- * For mini-program platforms (mp-*):
13
- * - If page has no externalClasses usage: no transformation
14
- * - If page has dynamic externalClasses: all selectors get page prefix
15
- * .a -> page .a
16
- * - If page has only static externalClasses: only matching selectors get page prefix
17
- * .foo -> page .foo (if "foo" is in staticClasses)
18
- * .bar -> .bar (unchanged, if "bar" is not in staticClasses)
12
+ * 小程序平台(mp-*):
13
+ * - 页面没有使用 externalClasses:不做转换
14
+ * - 页面存在动态 externalClasses:选择器最后一个 class 追加 [class]
15
+ * .a -> .a[class]
16
+ * - 页面只有静态 externalClasses:仅命中静态 class 的选择器追加 [class]
17
+ * .foo -> .foo[class](foo 在 staticClasses 中)
18
+ * .bar -> .bar(bar 不在 staticClasses 中)
19
19
  *
20
- * This ensures page styles have higher specificity than component styles
21
- * while minimizing unnecessary transformations for performance
20
+ * 追加 [class] 可以提升 class 选择器优先级,同时避免原先插入 page 带来的结构影响。
22
21
  */
23
22
  const externalPlugin = () => {
24
23
  return {
@@ -27,21 +26,21 @@ const externalPlugin = () => {
27
26
  const processedRules = new WeakSet();
28
27
  return {
29
28
  OnceExit(root) {
30
- // Only mini-program platforms need page selector prepend
29
+ // 只有小程序平台需要处理 externalClasses 的样式优先级
31
30
  const platform = process.env.UNI_PLATFORM || '';
32
31
  if (!platform.startsWith('mp-')) {
33
32
  return;
34
33
  }
35
- // Get file path from postcss source
34
+ // 从 postcss source 中获取当前样式所属文件
36
35
  const filePath = root.source?.input?.file;
37
36
  if (!filePath) {
38
37
  return;
39
38
  }
40
- // Only process page files
39
+ // 只处理页面文件,组件文件保持原样
41
40
  if (!(0, pages_1.isUniPageFile)(filePath)) {
42
41
  return;
43
42
  }
44
- // Get page's externalClasses info
43
+ // 获取页面中收集到的 externalClasses 使用信息
45
44
  const externalClassesInfo = (0, externalClasses_1.findPageExternalClasses)(filePath);
46
45
  let staticClasses = new Set();
47
46
  let hasDynamic = false;
@@ -55,7 +54,7 @@ const externalPlugin = () => {
55
54
  hasDynamic = true;
56
55
  }
57
56
  }
58
- // If no static classes and no dynamic, skip processing
57
+ // 没有静态 class,也没有动态绑定时,直接跳过,避免无意义遍历
59
58
  if (staticClasses.size === 0 && !hasDynamic) {
60
59
  return;
61
60
  }
@@ -68,60 +67,67 @@ const externalPlugin = () => {
68
67
  };
69
68
  };
70
69
  function processRule(rule, processedRules, staticClasses, hasDynamic) {
71
- // Skip already processed rules
70
+ // 同一个 Rule 只处理一次,避免被重复追加 [class]
72
71
  if (processedRules.has(rule)) {
73
72
  return;
74
73
  }
75
- // Skip keyframes rules
74
+ // keyframes 内部的 from/to 不是普通选择器,不能处理
76
75
  if (rule.parent &&
77
76
  rule.parent.type === 'atrule' &&
78
77
  /-?keyframes$/.test(rule.parent.name)) {
79
78
  return;
80
79
  }
81
80
  processedRules.add(rule);
82
- // Process selector based on externalClasses info
81
+ // 根据 externalClasses 情况处理选择器
83
82
  rule.selector = (0, postcss_selector_parser_1.default)((selectorRoot) => {
84
83
  selectorRoot.each((selector) => {
84
+ let classNode;
85
85
  if (hasDynamic) {
86
- // Dynamic externalClasses: prepend page to all selectors
87
- prependPageSelector(selector);
86
+ // 动态绑定无法提前知道具体 class,所有包含 class 的选择器都提升优先级
87
+ classNode = findLastClassNode(selector);
88
88
  }
89
89
  else {
90
- // Static only: only prepend page if selector contains any staticClasses
91
- if (selectorContainsClasses(selector, staticClasses)) {
92
- prependPageSelector(selector);
93
- }
90
+ // 静态绑定只处理命中 staticClasses 的选择器,减少无关 CSS 变更
91
+ classNode = findLastClassNode(selector, staticClasses);
92
+ }
93
+ if (classNode) {
94
+ appendClassAttribute(selector, classNode);
94
95
  }
95
96
  });
96
97
  }).processSync(rule.selector);
97
98
  }
98
99
  /**
99
- * Check if selector contains any of the specified classes
100
+ * 找到选择器最右侧的 class 节点。
101
+ * 传入 classes 时,仅在选择器包含目标 class 后才返回最右侧 class,
102
+ * 这样 .a .b 在命中 .a 时也能输出 .a .b[class],符合整体提权预期。
100
103
  */
101
- function selectorContainsClasses(selector, classes) {
102
- let found = false;
103
- selector.walk((node) => {
104
- if (node.type === 'class' && classes.has(node.value)) {
105
- found = true;
106
- return false; // stop walking
104
+ function findLastClassNode(selector, classes) {
105
+ let lastClassNode;
106
+ for (let i = selector.nodes.length - 1; i >= 0; i--) {
107
+ const node = selector.nodes[i];
108
+ if (node.type !== 'class') {
109
+ continue;
110
+ }
111
+ if (!lastClassNode) {
112
+ lastClassNode = node;
113
+ }
114
+ if (!classes || classes.has(node.value)) {
115
+ return lastClassNode;
107
116
  }
108
- });
109
- return found;
117
+ }
110
118
  }
111
119
  /**
112
- * Prepend 'page' selector for mini-program platforms
113
- * .a -> page .a
114
- * .b .c -> page .b .c
120
+ * 在 class 后追加 [class] 提升优先级。
121
+ * .a -> .a[class]
122
+ * .a[class] -> .a[class][class]
123
+ * .a .b -> .a .b[class]
115
124
  */
116
- function prependPageSelector(selector) {
117
- // Skip if selector already starts with 'page'
118
- const firstNode = selector.first;
119
- if (firstNode && firstNode.type === 'tag' && firstNode.value === 'page') {
120
- return;
121
- }
122
- // Insert 'page' tag and a combinator (space) at the beginning
123
- selector.prepend(postcss_selector_parser_1.default.combinator({ value: ' ' }));
124
- selector.prepend(postcss_selector_parser_1.default.tag({ value: 'page' }));
125
+ function appendClassAttribute(selector, classNode) {
126
+ selector.insertAfter(classNode, postcss_selector_parser_1.default.attribute({
127
+ attribute: 'class',
128
+ value: undefined,
129
+ raws: {},
130
+ }));
125
131
  }
126
132
  externalPlugin.postcss = true;
127
133
  exports.default = externalPlugin;
@@ -32,6 +32,7 @@ export interface EncryptPackageJson {
32
32
  dependencies: string[];
33
33
  artifacts: {
34
34
  env: {
35
+ vapor: boolean;
35
36
  compilerVersion: string;
36
37
  } & Record<string, any>;
37
38
  apis: string[];
@@ -45,9 +46,10 @@ export interface EncryptPackageJson {
45
46
  };
46
47
  };
47
48
  }
48
- export declare function initCheckEnv(): Record<string, string>;
49
+ export declare function initCheckEnv(): Record<string, unknown>;
49
50
  export declare function resolveEncryptUniModule(id: string, platform: typeof process.env.UNI_UTS_PLATFORM, isX?: boolean): string | undefined;
50
51
  type CloudCompileSdkType = 'utssdk' | 'easycom' | 'all';
52
+ type VaporRenderTarget = 'bytecode' | 'nativecode';
51
53
  export interface CloudCompileParams {
52
54
  mode: 'development' | 'production';
53
55
  packType: 'debug' | 'release';
@@ -56,8 +58,11 @@ export interface CloudCompileParams {
56
58
  appname: string;
57
59
  platform: typeof process.env.UNI_UTS_PLATFORM;
58
60
  'uni-app-x': boolean;
61
+ vapor: boolean;
62
+ vaporRenderTarget?: VaporRenderTarget;
59
63
  env: Record<string, string>;
60
64
  }
65
+ export declare function validateCloudCompileAppInfo(params: Pick<CloudCompileParams, 'appid' | 'appname'>): string;
61
66
  export declare function checkEncryptUniModules(inputDir: string, params: CloudCompileParams, sdkType?: CloudCompileSdkType): Promise<{} | undefined>;
62
67
  export declare function getUniModulesEncryptType(pluginId: string): "" | "utssdk" | "easycom" | undefined;
63
68
  export declare function parseUniModulesArtifacts(): {
@@ -66,5 +71,6 @@ export declare function parseUniModulesArtifacts(): {
66
71
  scopedSlots: string[];
67
72
  declaration: string;
68
73
  }[];
74
+ export declare function copyEncryptUniModulesDom2Bytes(): boolean | Promise<boolean>;
69
75
  export declare function virtualComponentPath(filepath: string): string;
70
76
  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.virtualComponentPath = exports.parseUniModulesArtifacts = exports.getUniModulesEncryptType = exports.checkEncryptUniModules = exports.resolveEncryptUniModule = exports.initCheckEnv = exports.packUploadEncryptUniModules = exports.findUploadEncryptUniModulesFiles = exports.findCloudEncryptUniModules = exports.parseEasyComComponents = exports.parseUniModulesWithComponents = exports.genEncryptUTSModuleCode = exports.genEncryptEasyComModuleCode = void 0;
6
+ exports.virtualComponentPath = exports.copyEncryptUniModulesDom2Bytes = exports.parseUniModulesArtifacts = exports.getUniModulesEncryptType = exports.checkEncryptUniModules = exports.validateCloudCompileAppInfo = exports.resolveEncryptUniModule = exports.initCheckEnv = exports.packUploadEncryptUniModules = exports.findUploadEncryptUniModulesFiles = exports.findCloudEncryptUniModules = exports.parseEasyComComponents = exports.parseUniModulesWithComponents = exports.genEncryptUTSModuleCode = exports.genEncryptEasyComModuleCode = void 0;
7
7
  const path_1 = __importDefault(require("path"));
8
8
  const fs_extra_1 = __importDefault(require("fs-extra"));
9
9
  const fast_glob_1 = require("fast-glob");
@@ -12,6 +12,7 @@ const easycom_1 = require("./easycom");
12
12
  const messages_1 = require("./messages");
13
13
  const constants_1 = require("./constants");
14
14
  const url_1 = require("./url");
15
+ const x_1 = require("./x");
15
16
  function genEncryptEasyComModuleIndex(pluginId, platform, components) {
16
17
  const isMp = platform.startsWith('mp-');
17
18
  const imports = [];
@@ -23,7 +24,7 @@ function genEncryptEasyComModuleIndex(pluginId, platform, components) {
23
24
  ids.push(id);
24
25
  }
25
26
  let instance = '';
26
- if (platform === 'app-android') {
27
+ if ((0, x_1.isUniAppXAndroidNative)(platform)) {
27
28
  instance = (0, easycom_1.genUTSComponentPublicInstanceIdent)(component);
28
29
  // 类型
29
30
  ids.push(instance);
@@ -307,20 +308,22 @@ const KNOWN_ASSET_TYPES = [
307
308
  'txt',
308
309
  ];
309
310
  function findUniModuleFiles(platform, id, inputDir) {
311
+ const useUniAppXAndroidNative = (0, x_1.isUniAppXAndroidNative)(platform);
310
312
  return (0, fast_glob_1.sync)(`uni_modules/${id}/**/*`, {
311
313
  cwd: inputDir,
312
314
  absolute: true,
313
315
  ignore: [
314
316
  '**/*.md',
315
- ...(platform !== 'app-android' // 非 android 平台不需要扫描 assets
316
- ? [`**/*.{${KNOWN_ASSET_TYPES.join(',')}}`]
317
- : []),
317
+ ...(useUniAppXAndroidNative // 仅旧版 Android x 需要扫描 assets
318
+ ? []
319
+ : [`**/*.{${KNOWN_ASSET_TYPES.join(',')}}`]),
318
320
  ],
319
321
  });
320
322
  }
321
323
  function initCheckEnv() {
322
324
  return {
323
325
  // 云端编译的版本号不带日期及小版本
326
+ vapor: process.env.UNI_APP_X_DOM2 === 'true',
324
327
  compilerVersion: process.env.UNI_COMPILER_VERSION,
325
328
  };
326
329
  }
@@ -334,6 +337,9 @@ function findLastIndex(array, predicate) {
334
337
  return -1;
335
338
  }
336
339
  let encryptUniModules = {};
340
+ function refreshEncryptUniModules(platform, inputDir) {
341
+ encryptUniModules = findCloudEncryptUniModules(platform, inputDir, process.env.UNI_MODULES_ENCRYPT_CACHE_DIR, 'all');
342
+ }
337
343
  function resolveEncryptUniModule(id, platform, isX = true) {
338
344
  id = id.split('?', 2)[0];
339
345
  const parts = id.split('/');
@@ -367,31 +373,62 @@ function resolveEncryptUniModule(id, platform, isX = true) {
367
373
  }
368
374
  }
369
375
  }
370
- // 原生平台走旧的uts-proxy
371
- return (0, utils_1.normalizePath)(path_1.default.join(process.env.UNI_INPUT_DIR, `uni_modules/${uniModuleId}?${isX && platform === 'app-android' ? 'uts-proxy' : 'uni_helpers'}`));
376
+ // 仅旧版 Android x 原生引擎走 uts-proxy,JS 引擎与其他平台统一走 uni_helpers
377
+ return (0, utils_1.normalizePath)(path_1.default.join(process.env.UNI_INPUT_DIR, `uni_modules/${uniModuleId}?${isX && (0, x_1.isUniAppXAndroidNative)(platform)
378
+ ? 'uts-proxy'
379
+ : 'uni_helpers'}`));
372
380
  }
373
381
  }
374
382
  }
375
383
  exports.resolveEncryptUniModule = resolveEncryptUniModule;
384
+ function validateCloudCompileAppInfo(params) {
385
+ const missingFields = [];
386
+ if (!String(params.appid || '').trim()) {
387
+ missingFields.push('appid');
388
+ }
389
+ if (!String(params.appname || '').trim()) {
390
+ missingFields.push('name');
391
+ }
392
+ if (missingFields.length) {
393
+ return `云编译插件失败:manifest.json 缺少 ${missingFields.join('、')},请先配置后重新编译。`;
394
+ }
395
+ return '';
396
+ }
397
+ exports.validateCloudCompileAppInfo = validateCloudCompileAppInfo;
376
398
  async function checkEncryptUniModules(inputDir, params, sdkType = 'all') {
399
+ const isHarmonySplitCompile = params.platform === 'app-harmony' && sdkType !== 'all';
377
400
  // 初始化指定 sdk 类型的加密插件
378
401
  const curEncryptUniModules = findCloudEncryptUniModules(params.platform, inputDir, process.env.UNI_MODULES_ENCRYPT_CACHE_DIR, sdkType);
379
402
  if (!Object.keys(curEncryptUniModules).length) {
403
+ // 鸿蒙会按 utssdk/easycom 分两次扫描,这里回填一次全量状态,避免子集扫描把插件类型覆盖掉
404
+ if (isHarmonySplitCompile) {
405
+ refreshEncryptUniModules(params.platform, inputDir);
406
+ }
380
407
  return {};
381
408
  }
382
409
  if (!process.env.UNI_HBUILDERX_PLUGINS) {
410
+ if (isHarmonySplitCompile) {
411
+ refreshEncryptUniModules(params.platform, inputDir);
412
+ }
383
413
  return {};
384
414
  }
385
415
  const cacheDir = process.env.UNI_MODULES_ENCRYPT_CACHE_DIR;
386
- const { zipFile, modules } = packUploadEncryptUniModules(curEncryptUniModules, process.env.UNI_UTS_PLATFORM, inputDir, cacheDir);
416
+ const needsCloudCompile = Object.keys(curEncryptUniModules).some((uniModuleId) => !curEncryptUniModules[uniModuleId]);
417
+ if (params.vapor && needsCloudCompile) {
418
+ const validateAppInfoError = validateCloudCompileAppInfo(params);
419
+ if (validateAppInfoError) {
420
+ console.error(validateAppInfoError);
421
+ return process.exit(0);
422
+ }
423
+ }
424
+ const { zipFile, modules } = packUploadEncryptUniModules(curEncryptUniModules, params.platform, inputDir, cacheDir);
387
425
  if (zipFile) {
388
426
  const downloadFile = path_1.default.resolve(cacheDir, 'uni_modules.download.zip');
389
427
  const { C, D, R, U } = (0, utils_1.requireUniHelpers)();
390
428
  try {
391
429
  const isLogin = await C();
392
- const tips = process.env.UNI_UTS_PLATFORM !== 'app-android'
393
- ? '(此过程耗时较长)'
394
- : '';
430
+ const useUniAppXAndroidNative = (0, x_1.isUniAppXAndroidNative)(params.platform);
431
+ const tips = !useUniAppXAndroidNative ? '(此过程耗时较长)' : '';
395
432
  console.log(`正在云编译插件${isLogin ? '' : '(请先登录)'}${tips}:${modules.join(',')}...`);
396
433
  let downloadUrl = '';
397
434
  try {
@@ -414,6 +451,7 @@ async function checkEncryptUniModules(inputDir, params, sdkType = 'all') {
414
451
  const AdmZip = require('adm-zip');
415
452
  const zip = new AdmZip(downloadFile);
416
453
  zip.extractAllTo(cacheDir, true);
454
+ await Promise.resolve(copyEncryptUniModulesDom2Bytes());
417
455
  fs_extra_1.default.unlinkSync(zipFile);
418
456
  fs_extra_1.default.unlinkSync(downloadFile);
419
457
  R({
@@ -431,8 +469,10 @@ async function checkEncryptUniModules(inputDir, params, sdkType = 'all') {
431
469
  }
432
470
  }
433
471
  else {
434
- // android 平台需要在这里初始化
435
- if (params.platform === 'app-android') {
472
+ await Promise.resolve(copyEncryptUniModulesDom2Bytes());
473
+ const useUniAppXAndroidNative = (0, x_1.isUniAppXAndroidNative)(params.platform);
474
+ // 仅旧版 Android x 需要在缓存命中时额外初始化
475
+ if (useUniAppXAndroidNative) {
436
476
  const { R } = (0, utils_1.requireUniHelpers)();
437
477
  R({
438
478
  dir: process.env.UNI_INPUT_DIR,
@@ -441,7 +481,7 @@ async function checkEncryptUniModules(inputDir, params, sdkType = 'all') {
441
481
  }
442
482
  }
443
483
  // 初始化所有
444
- encryptUniModules = findCloudEncryptUniModules(params.platform, inputDir, process.env.UNI_MODULES_ENCRYPT_CACHE_DIR, 'all');
484
+ refreshEncryptUniModules(params.platform, inputDir);
445
485
  }
446
486
  exports.checkEncryptUniModules = checkEncryptUniModules;
447
487
  function getUniModulesEncryptType(pluginId) {
@@ -464,6 +504,83 @@ function parseUniModulesArtifacts() {
464
504
  return res;
465
505
  }
466
506
  exports.parseUniModulesArtifacts = parseUniModulesArtifacts;
507
+ function copyEncryptUniModulesDom2Bytes() {
508
+ if (process.env.UNI_APP_X_DOM2 !== 'true') {
509
+ return false;
510
+ }
511
+ if (!['app-android', 'app-ios', 'app-harmony'].includes(process.env.UNI_UTS_PLATFORM)) {
512
+ return false;
513
+ }
514
+ const cacheDir = process.env.UNI_MODULES_ENCRYPT_CACHE_DIR;
515
+ const outputDir = process.env.UNI_OUTPUT_DIR;
516
+ if (!cacheDir || !outputDir) {
517
+ return false;
518
+ }
519
+ if (process.env.UNI_APP_X_VAPOR_RENDER_TARGET === 'bytecode') {
520
+ return copyEncryptUniModulesDom2BytesTarget(cacheDir, outputDir);
521
+ }
522
+ if (process.env.UNI_APP_X_VAPOR_RENDER_TARGET === 'nativecode') {
523
+ return copyEncryptUniModulesDom2CppTarget(cacheDir, outputDir);
524
+ }
525
+ return false;
526
+ }
527
+ exports.copyEncryptUniModulesDom2Bytes = copyEncryptUniModulesDom2Bytes;
528
+ function copyEncryptUniModulesDom2BytesTarget(cacheDir, outputDir) {
529
+ // 只依赖编译环境变量定位缓存目录和输出目录,避免拼接具体 unpackage/dist 路径。
530
+ const sourceBytesDir = path_1.default.resolve(cacheDir, 'bytes');
531
+ if (!fs_extra_1.default.existsSync(sourceBytesDir) ||
532
+ !fs_extra_1.default.statSync(sourceBytesDir).isDirectory()) {
533
+ return false;
534
+ }
535
+ const outputBytesDir = path_1.default.resolve(outputDir, 'bytes');
536
+ // 云编译产出的 bytecode 在缓存目录中,这里只合并复制到当前编译输出目录。
537
+ fs_extra_1.default.copySync(sourceBytesDir, outputBytesDir, { overwrite: true });
538
+ return true;
539
+ }
540
+ async function copyEncryptUniModulesDom2CppTarget(cacheDir, outputDir) {
541
+ const sourceCppDir = path_1.default.resolve(cacheDir, 'cpp');
542
+ if (!fs_extra_1.default.existsSync(sourceCppDir) ||
543
+ !fs_extra_1.default.statSync(sourceCppDir).isDirectory()) {
544
+ return false;
545
+ }
546
+ const outputCppDir = process.env.UNI_APP_X_DOM2_CPP_DIR || path_1.default.resolve(outputDir, 'cpp');
547
+ // nativecode 的 cpp/h 暂时不走 DUM 解密,直接复制云端产物。
548
+ // const cppFiles = sync('**/*.{cpp,h}', {
549
+ // absolute: false,
550
+ // cwd: sourceCppDir,
551
+ // onlyFiles: true,
552
+ // }).filter((file) => !isIgnoreDom2CppFile(file))
553
+ // if (cppFiles.length) {
554
+ // const files = cppFiles.reduce((files, file) => {
555
+ // files[path.resolve(sourceCppDir, file)] = path.resolve(outputCppDir, file)
556
+ // return files
557
+ // }, {} as Record<string, string>)
558
+ // const { DUM } = requireUniHelpers()
559
+ // const errMsg = await DUM(path.basename(sourceCppDir), files)
560
+ // if (errMsg) {
561
+ // console.error(errMsg)
562
+ // process.exit(0)
563
+ // }
564
+ // }
565
+ // cpp 目录保持原目录结构直接复制,shared_data_init.h 由当前编译流程生成,不复制云端缓存版本。
566
+ fs_extra_1.default.copySync(sourceCppDir, outputCppDir, {
567
+ filter(src) {
568
+ if (fs_extra_1.default.statSync(src).isDirectory()) {
569
+ return true;
570
+ }
571
+ // shared_data_init.h 由当前编译生成,不能复制云端缓存里的旧文件覆盖本地结果。
572
+ if (isIgnoreDom2CppFile(src)) {
573
+ return false;
574
+ }
575
+ return true;
576
+ },
577
+ overwrite: true,
578
+ });
579
+ return true;
580
+ }
581
+ function isIgnoreDom2CppFile(filename) {
582
+ return path_1.default.basename(filename) === 'shared_data_init.h';
583
+ }
467
584
  const uniComponentPrefix = 'uniComponent://';
468
585
  function virtualComponentPath(filepath) {
469
586
  return uniComponentPrefix + (0, url_1.encodeBase64Url)(filepath);
@@ -7,6 +7,7 @@ exports.parseUTSModuleDeps = exports.capitalize = exports.camelize = exports.par
7
7
  // 重要:此文件编译后的js,需同步至 vue2 编译器中 uni-cli-shared/lib/uts/uni_modules.js
8
8
  const path_1 = __importDefault(require("path"));
9
9
  const fs_extra_1 = __importDefault(require("fs-extra"));
10
+ const x_1 = require("./x");
10
11
  const extApiProviders = [];
11
12
  const extApiPlugins = new Set();
12
13
  function getNonTreeShakingPlugins() {
@@ -228,7 +229,7 @@ function parseInjects(vite = true, platform, language, source, uniModuleRootDir,
228
229
  // source = `${source}/utssdk/index.uts`
229
230
  // }
230
231
  }
231
- else if (process.env.UNI_APP_X_UVUE_SCRIPT_ENGINE === 'js') {
232
+ else if ((0, x_1.isUniAppXJsEngine)()) {
232
233
  if (fs_extra_1.default.existsSync(path_1.default.resolve(uniModuleRootDir, 'utssdk', 'app-js', 'index.uts'))) {
233
234
  source = `${source}/utssdk/app-js/index.uts`;
234
235
  }
@@ -291,7 +292,7 @@ function parseInject(vite = true, platform, language, source, globalObject, defi
291
292
  const appOptions = defineOptions.app;
292
293
  if (isPlainObject(appOptions)) {
293
294
  // js engine 下且存在 app-js,不检查
294
- const skipCheck = (process.env.UNI_APP_X_UVUE_SCRIPT_ENGINE === 'js' ||
295
+ const skipCheck = ((0, x_1.isUniAppXJsEngine)() ||
295
296
  process.env.UNI_UTS_PLATFORM === 'app-harmony') &&
296
297
  source.includes('app-js');
297
298
  if (!skipCheck) {
package/dist/utils.js CHANGED
@@ -175,6 +175,11 @@ function enableSourceMap() {
175
175
  if (process.env.UNI_APP_SOURCEMAP === 'false') {
176
176
  return false;
177
177
  }
178
+ if (process.env.NODE_ENV === 'development' &&
179
+ process.env.UNI_PLATFORM === 'app' &&
180
+ process.env.UNI_APP_X !== 'true') {
181
+ return false;
182
+ }
178
183
  return process.env.NODE_ENV === 'development' && isNormalCompileTarget();
179
184
  }
180
185
  exports.enableSourceMap = enableSourceMap;
package/dist/uts.d.ts CHANGED
@@ -11,6 +11,7 @@ import type { EasycomMatcher } from './easycom';
11
11
  */
12
12
  export declare function resolveUTSAppModule(platform: typeof process.env.UNI_UTS_PLATFORM, id: string, importer: string, includeUTSSDK?: boolean): string | undefined;
13
13
  export declare function resolveUTSModule(id: string, importer: string, includeUTSSDK?: boolean): string | undefined;
14
+ export declare function hasUTSModulePlatformFile(pluginDir: string, platform: typeof process.env.UNI_UTS_PLATFORM): boolean;
14
15
  export declare function resolveUTSCompiler(throwError?: boolean): typeof UTSCompiler;
15
16
  export declare function resolveUTSCompilerVersion(): string;
16
17
  interface UTSComponentMeta {