@dcloudio/uni-cli-shared 3.0.0-alpha-1000920260525813 → 3.0.0-alpha-5010220260529001

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 (71) hide show
  1. package/dist/hbx/alias.js +2 -21
  2. package/dist/hbx/index.d.ts +1 -1
  3. package/dist/i18n.js +17 -32
  4. package/dist/index.d.ts +1 -1
  5. package/dist/index.js +2 -1
  6. package/dist/json/app/pages/definePage.js +1 -1
  7. package/dist/logs/console.js +1 -15
  8. package/dist/messages/en.d.ts +1 -0
  9. package/dist/messages/en.js +1 -0
  10. package/dist/messages/index.d.ts +2 -0
  11. package/dist/messages/zh_CN.d.ts +1 -0
  12. package/dist/messages/zh_CN.js +1 -0
  13. package/dist/mp/imports.d.ts +1 -3
  14. package/dist/mp/template.d.ts +1 -2
  15. package/dist/mp/usingComponents.d.ts +1 -2
  16. package/dist/uni_modules.cloud.d.ts +4 -0
  17. package/dist/uni_modules.cloud.js +80 -1
  18. package/dist/vite/cloud.js +5 -2
  19. package/dist/vite/index.d.ts +3 -2
  20. package/dist/vite/plugins/console.js +27 -31
  21. package/dist/vite/plugins/copy.js +0 -1
  22. package/dist/vite/plugins/cssScoped.js +16 -25
  23. package/dist/vite/plugins/dynamicImportPolyfill.d.ts +1 -8
  24. package/dist/vite/plugins/easycom.js +43 -46
  25. package/dist/vite/plugins/inject.js +113 -132
  26. package/dist/vite/plugins/json.js +14 -17
  27. package/dist/vite/plugins/jsonJs.d.ts +2 -2
  28. package/dist/vite/plugins/jsonJs.js +0 -7
  29. package/dist/vite/plugins/mainJs.d.ts +1 -1
  30. package/dist/vite/plugins/mainJs.js +0 -7
  31. package/dist/vite/plugins/pre.js +30 -35
  32. package/dist/vite/plugins/sfc.js +2 -15
  33. package/dist/vite/plugins/sourceMap.js +1 -4
  34. package/dist/vite/plugins/stats.js +26 -0
  35. package/dist/vite/plugins/uts/ext-api.js +17 -23
  36. package/dist/vite/plugins/uts/uni_modules.js +44 -66
  37. package/dist/vite/plugins/uts/uvue.js +48 -55
  38. package/dist/vite/plugins/vitejs/plugins/asset.d.ts +4 -12
  39. package/dist/vite/plugins/vitejs/plugins/asset.js +2 -7
  40. package/dist/vite/plugins/vitejs/plugins/css.d.ts +1 -4
  41. package/dist/vite/plugins/vitejs/plugins/css.js +82 -102
  42. package/dist/vite/utils/utils.d.ts +2 -3
  43. package/dist/vue/transforms/x/transformDirection.js +33 -4
  44. package/dist/watcher.d.ts +0 -1
  45. package/dist/x.d.ts +0 -1
  46. package/dist/x.js +1 -5
  47. package/lib/@vue/compiler-core/dist/compiler-core.cjs.js +23 -16
  48. package/lib/@vue/compiler-core/dist/compiler-core.cjs.prod.js +23 -16
  49. package/lib/@vue/compiler-core/dist/compiler-core.esm-bundler.js +23 -16
  50. package/lib/@vue/compiler-sfc/dist/compiler-sfc.cjs.js +66 -23
  51. package/lib/@vue/compiler-sfc/dist/compiler-sfc.esm-browser.js +115 -67
  52. package/lib/dom2/app/@vue/compiler-core/dist/compiler-core.cjs.js +1 -1
  53. package/lib/dom2/app/@vue/compiler-core/dist/compiler-core.cjs.prod.js +1 -1
  54. package/lib/dom2/app/@vue/compiler-core/dist/compiler-core.esm-bundler.js +1 -1
  55. package/lib/dom2/app/@vue/compiler-dom/dist/compiler-dom.cjs.js +1 -1
  56. package/lib/dom2/app/@vue/compiler-dom/dist/compiler-dom.cjs.prod.js +1 -1
  57. package/lib/dom2/app/@vue/compiler-dom/dist/compiler-dom.esm-browser.js +1 -1
  58. package/lib/dom2/app/@vue/compiler-dom/dist/compiler-dom.esm-browser.prod.js +1 -1
  59. package/lib/dom2/app/@vue/compiler-dom/dist/compiler-dom.esm-bundler.js +1 -1
  60. package/lib/dom2/app/@vue/compiler-dom/dist/compiler-dom.global.js +1 -1
  61. package/lib/dom2/app/@vue/compiler-dom/dist/compiler-dom.global.prod.js +1 -1
  62. package/lib/dom2/app/@vue/compiler-sfc/dist/compiler-sfc.cjs.js +3 -3
  63. package/lib/dom2/app/@vue/compiler-sfc/dist/compiler-sfc.esm-browser.js +217 -45
  64. package/lib/dom2/app/@vue/compiler-vapor/dist/compiler-vapor.cjs.js +218 -43
  65. package/lib/dom2/app/@vue/compiler-vapor/dist/compiler-vapor.d.ts +62 -12
  66. package/lib/dom2/app/@vue/compiler-vapor/dist/compiler-vapor.esm-browser.js +228 -44
  67. package/lib/dom2/app/@vue/compiler-vapor-dom2/dist/compiler-vapor-dom2.cjs.js +1 -1
  68. package/lib/dom2/app/@vue/shared/dist/shared.cjs.js +1 -1
  69. package/lib/dom2/app/@vue/shared/dist/shared.cjs.prod.js +1 -1
  70. package/lib/dom2/app/@vue/shared/dist/shared.esm-bundler.js +1 -1
  71. package/package.json +8 -7
package/dist/hbx/alias.js CHANGED
@@ -78,27 +78,8 @@ function initModuleAlias() {
78
78
  if (process.env.UNI_APP_PLATFORM ||
79
79
  process.env.UNI_PLATFORM === 'app-harmony') {
80
80
  if (!process.env.UNI_APP_X_VAPOR_RENDER_TARGET) {
81
- // ios 和 harmony 平台默认使用 bytecode 目标,存在 .native 文件时使用 native 目标;其他平台如果存在 .dynamic 文件则使用 bytecode 目标,否则使用 native 目标
82
- if (process.env.UNI_APP_PLATFORM === 'ios' ||
83
- process.env.UNI_APP_PLATFORM === 'harmony' ||
84
- process.env.UNI_PLATFORM === 'app-harmony') {
85
- if (process.env.UNI_INPUT_DIR &&
86
- fs_1.default.existsSync(path_1.default.resolve(process.env.UNI_INPUT_DIR, '.native'))) {
87
- process.env.UNI_APP_X_VAPOR_RENDER_TARGET = 'nativecode';
88
- }
89
- else {
90
- process.env.UNI_APP_X_VAPOR_RENDER_TARGET = 'bytecode';
91
- }
92
- }
93
- else {
94
- if (process.env.UNI_INPUT_DIR &&
95
- fs_1.default.existsSync(path_1.default.resolve(process.env.UNI_INPUT_DIR, '.dynamic'))) {
96
- process.env.UNI_APP_X_VAPOR_RENDER_TARGET = 'bytecode';
97
- }
98
- else {
99
- process.env.UNI_APP_X_VAPOR_RENDER_TARGET = 'nativecode';
100
- }
101
- }
81
+ // 默认 app 平台使用 bytecode 目标
82
+ process.env.UNI_APP_X_VAPOR_RENDER_TARGET = 'bytecode';
102
83
  }
103
84
  if (process.env.UNI_APP_X_VAPOR_RENDER_TARGET?.includes('bytecode')) {
104
85
  process.env.UNI_APP_X_DOM2_DYNAMIC = 'true';
@@ -1,5 +1,5 @@
1
1
  export { formatAtFilename, createErrorWithBlockFlag } from './log';
2
2
  export * from './env';
3
3
  export { initModuleAlias, installHBuilderXPlugin, formatInstallHBuilderXPluginTips, } from './alias';
4
- export declare function uniHBuilderXConsolePlugin(method?: string): import("vite/dist/node").Plugin<any>;
4
+ export declare function uniHBuilderXConsolePlugin(method?: string): import("vite").Plugin<any>;
5
5
  export declare function isEnableConsole(): boolean;
package/dist/i18n.js CHANGED
@@ -47,51 +47,36 @@ function isUniAppLocaleFile(filepath) {
47
47
  return localeJsonRE.test(path_1.default.basename(filepath));
48
48
  }
49
49
  exports.isUniAppLocaleFile = isUniAppLocaleFile;
50
- const localeJsonCache = new Map();
51
50
  function parseLocaleJson(filepath) {
52
- const { mtimeMs, size } = fs_1.default.statSync(filepath);
53
- const cached = localeJsonCache.get(filepath);
54
- if (cached && cached.mtimeMs === mtimeMs && cached.size === size) {
55
- return cached.json;
56
- }
57
51
  let jsonObj = (0, json_1.parseJson)(fs_1.default.readFileSync(filepath, 'utf8'), false, filepath);
58
52
  if (isUniAppLocaleFile(filepath)) {
59
53
  jsonObj = jsonObj.common || {};
60
54
  }
61
- localeJsonCache.set(filepath, { mtimeMs, size, json: jsonObj });
62
55
  return jsonObj;
63
56
  }
64
- const localeFilesCache = new Map();
65
57
  function getLocaleFiles(cwd) {
66
- let mtimeMs;
67
- try {
68
- mtimeMs = fs_1.default.statSync(cwd).mtimeMs;
69
- }
70
- catch {
71
- return [];
72
- }
73
- const cached = localeFilesCache.get(cwd);
74
- if (cached && cached.mtimeMs === mtimeMs) {
75
- return cached.files;
76
- }
77
- const files = (0, fast_glob_1.sync)('*.json', { cwd, absolute: true });
78
- localeFilesCache.set(cwd, { mtimeMs, files });
79
- return files;
58
+ return (0, fast_glob_1.sync)('*.json', { cwd, absolute: true });
80
59
  }
81
60
  exports.getLocaleFiles = getLocaleFiles;
82
61
  function initLocales(dir, withMessages = true) {
83
- return getLocaleFiles(dir).reduce((res, filepath) => {
84
- const filename = path_1.default.basename(filepath);
85
- try {
86
- const locale = filename.replace(/(uni-app.)?(.*).json/, '$2');
87
- if (withMessages) {
88
- (0, shared_1.extend)(res[locale] || (res[locale] = {}), parseLocaleJson(filepath));
89
- }
90
- else {
91
- res[locale] = {};
62
+ if (!fs_1.default.existsSync(dir)) {
63
+ return {};
64
+ }
65
+ return fs_1.default.readdirSync(dir).reduce((res, filename) => {
66
+ if (path_1.default.extname(filename) === '.json') {
67
+ try {
68
+ const locale = path_1.default
69
+ .basename(filename)
70
+ .replace(/(uni-app.)?(.*).json/, '$2');
71
+ if (withMessages) {
72
+ (0, shared_1.extend)(res[locale] || (res[locale] = {}), parseLocaleJson(path_1.default.join(dir, filename)));
73
+ }
74
+ else {
75
+ res[locale] = {};
76
+ }
92
77
  }
78
+ catch (e) { }
93
79
  }
94
- catch { }
95
80
  return res;
96
81
  }, {});
97
82
  }
package/dist/index.d.ts CHANGED
@@ -26,7 +26,7 @@ export * from './platform';
26
26
  export * from './utsUtils';
27
27
  export * from './workers';
28
28
  export { parseUniExtApi, parseUniExtApis, parseInjects, Define, DefineOptions, Defines, getUniExtApiProviderRegisters, formatExtApiProviderName, } from './uni_modules';
29
- export { getUniModulesEncryptType, parseUniModulesArtifacts, resolveEncryptUniModule, } from './uni_modules.cloud';
29
+ export { copyEncryptUniModulesDom2Bytes, getUniModulesEncryptType, parseUniModulesArtifacts, resolveEncryptUniModule, } from './uni_modules.cloud';
30
30
  import type { EncryptPackageJson } from './uni_modules.cloud';
31
31
  export type EncryptArtifacts = EncryptPackageJson['uni_modules']['artifacts'];
32
32
  export { M } from './messages';
package/dist/index.js CHANGED
@@ -14,7 +14,7 @@ var __exportStar = (this && this.__exportStar) || function(m, exports) {
14
14
  for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
15
15
  };
16
16
  Object.defineProperty(exports, "__esModule", { value: true });
17
- exports.checkUpdate = exports.M = exports.resolveEncryptUniModule = exports.parseUniModulesArtifacts = exports.getUniModulesEncryptType = exports.formatExtApiProviderName = exports.getUniExtApiProviderRegisters = exports.parseInjects = exports.parseUniExtApis = exports.parseUniExtApi = void 0;
17
+ exports.checkUpdate = exports.M = exports.resolveEncryptUniModule = exports.parseUniModulesArtifacts = exports.getUniModulesEncryptType = exports.copyEncryptUniModulesDom2Bytes = exports.formatExtApiProviderName = exports.getUniExtApiProviderRegisters = exports.parseInjects = exports.parseUniExtApis = exports.parseUniExtApi = void 0;
18
18
  __exportStar(require("./fs"), exports);
19
19
  __exportStar(require("./mp"), exports);
20
20
  __exportStar(require("./url"), exports);
@@ -49,6 +49,7 @@ Object.defineProperty(exports, "parseInjects", { enumerable: true, get: function
49
49
  Object.defineProperty(exports, "getUniExtApiProviderRegisters", { enumerable: true, get: function () { return uni_modules_1.getUniExtApiProviderRegisters; } });
50
50
  Object.defineProperty(exports, "formatExtApiProviderName", { enumerable: true, get: function () { return uni_modules_1.formatExtApiProviderName; } });
51
51
  var uni_modules_cloud_1 = require("./uni_modules.cloud");
52
+ Object.defineProperty(exports, "copyEncryptUniModulesDom2Bytes", { enumerable: true, get: function () { return uni_modules_cloud_1.copyEncryptUniModulesDom2Bytes; } });
52
53
  Object.defineProperty(exports, "getUniModulesEncryptType", { enumerable: true, get: function () { return uni_modules_cloud_1.getUniModulesEncryptType; } });
53
54
  Object.defineProperty(exports, "parseUniModulesArtifacts", { enumerable: true, get: function () { return uni_modules_cloud_1.parseUniModulesArtifacts; } });
54
55
  Object.defineProperty(exports, "resolveEncryptUniModule", { enumerable: true, get: function () { return uni_modules_cloud_1.resolveEncryptUniModule; } });
@@ -46,7 +46,7 @@ function defineNVuePageCode(pagesJson) {
46
46
  }
47
47
  const pagePathWithExtname = (0, utils_1.normalizePagePath)(page.path, 'app');
48
48
  if (pagePathWithExtname) {
49
- importNVuePagesCode.push(`import('./${pagePathWithExtname}').then((res)=>res.default)`);
49
+ importNVuePagesCode.push(`import('./${pagePathWithExtname}').then((res)=>{res()})`);
50
50
  }
51
51
  });
52
52
  return importNVuePagesCode.join('\n');
@@ -6,7 +6,6 @@ Object.defineProperty(exports, "__esModule", { value: true });
6
6
  exports.appendConsoleExpr = exports.restoreConsoleExpr = exports.rewriteConsoleExpr = void 0;
7
7
  const magic_string_1 = __importDefault(require("magic-string"));
8
8
  const utils_1 = require("../utils");
9
- const x_1 = require("../x");
10
9
  function rewriteConsoleExpr(method, id, filename, code, sourceMap = false) {
11
10
  filename = (0, utils_1.normalizePath)(filename);
12
11
  const re = /(console\.(log|info|debug|warn|error))\s*\(([^)]+)\)/g;
@@ -20,25 +19,12 @@ function rewriteConsoleExpr(method, id, filename, code, sourceMap = false) {
20
19
  if (s.hasChanged()) {
21
20
  return {
22
21
  code: s.toString(),
23
- map: sourceMap
24
- ? normalizeSourceMap(s.generateMap({ hires: (0, x_1.shouldUseHighResolutionSourceMap)() }))
25
- : { mappings: '' },
22
+ map: sourceMap ? s.generateMap({ hires: true }) : { mappings: '' },
26
23
  };
27
24
  }
28
25
  return { code, map: null };
29
26
  }
30
27
  exports.rewriteConsoleExpr = rewriteConsoleExpr;
31
- function normalizeSourceMap(map) {
32
- return {
33
- ...map,
34
- file: map.file || '',
35
- names: map.names || [],
36
- sources: map.sources || [],
37
- sourcesContent: map.sourcesContent || [],
38
- toString: () => map.toString(),
39
- toUrl: () => map.toUrl(),
40
- };
41
- }
42
28
  function restoreConsoleExpr(code) {
43
29
  return code.replace(/(?:uni\.)?__f__\('([^']+)','at ([^:]+):(\d+)',/g, 'console.$1(');
44
30
  }
@@ -15,6 +15,7 @@ declare const _default: {
15
15
  readonly 'dev.watching.end.pages': "DONE Build complete. PAGES:{pages}";
16
16
  readonly 'dev.watching.end.files': "DONE Build complete. FILES:{files}";
17
17
  readonly 'dev.watching.restart.vapor': "DONE Restart required. Switching vapor mode requires restarting to take effect.";
18
+ readonly 'dev.watching.vapor.render.target': "vapor-render-target in manifest.json was changed to {manifestTarget}, but the running console is still {runtimeTarget}.";
18
19
  readonly 'build.failed': "DONE Build failed.";
19
20
  readonly 'compiler.build.failed': "Build failed with errors.";
20
21
  readonly 'stat.warn.appid': "The current application is not configured with Appid, and uni statistics cannot be used. For details, see https://ask.dcloud.net.cn/article/36303";
@@ -17,6 +17,7 @@ exports.default = {
17
17
  'dev.watching.end.pages': 'DONE Build complete. PAGES:{pages}',
18
18
  'dev.watching.end.files': 'DONE Build complete. FILES:{files}',
19
19
  'dev.watching.restart.vapor': 'DONE Restart required. Switching vapor mode requires restarting to take effect.',
20
+ 'dev.watching.vapor.render.target': 'vapor-render-target in manifest.json was changed to {manifestTarget}, but the running console is still {runtimeTarget}.',
20
21
  'build.failed': 'DONE Build failed.',
21
22
  'compiler.build.failed': 'Build failed with errors.',
22
23
  'stat.warn.appid': 'The current application is not configured with Appid, and uni statistics cannot be used. For details, see https://ask.dcloud.net.cn/article/36303',
@@ -15,6 +15,7 @@ export declare const M: {
15
15
  readonly 'dev.watching.end.pages': "DONE Build complete. PAGES:{pages}";
16
16
  readonly 'dev.watching.end.files': "DONE Build complete. FILES:{files}";
17
17
  readonly 'dev.watching.restart.vapor': "DONE Restart required. 切换蒸汽模式需要重新运行才能生效。";
18
+ readonly 'dev.watching.vapor.render.target': "manifest.json 中更改了视图层编译目标为{manifestTarget},但注意运行控制台还是{runtimeTarget}。";
18
19
  readonly 'build.failed': "DONE Build failed.";
19
20
  readonly 'compiler.build.failed': "编译失败";
20
21
  readonly 'stat.warn.appid': "当前应用未配置 appid,无法使用 uni 统计,详情参考:https://ask.dcloud.net.cn/article/36303";
@@ -71,6 +72,7 @@ export declare const M: {
71
72
  readonly 'dev.watching.end.pages': "DONE Build complete. PAGES:{pages}";
72
73
  readonly 'dev.watching.end.files': "DONE Build complete. FILES:{files}";
73
74
  readonly 'dev.watching.restart.vapor': "DONE Restart required. Switching vapor mode requires restarting to take effect.";
75
+ readonly 'dev.watching.vapor.render.target': "vapor-render-target in manifest.json was changed to {manifestTarget}, but the running console is still {runtimeTarget}.";
74
76
  readonly 'build.failed': "DONE Build failed.";
75
77
  readonly 'compiler.build.failed': "Build failed with errors.";
76
78
  readonly 'stat.warn.appid': "The current application is not configured with Appid, and uni statistics cannot be used. For details, see https://ask.dcloud.net.cn/article/36303";
@@ -15,6 +15,7 @@ declare const _default: {
15
15
  readonly 'dev.watching.end.pages': "DONE Build complete. PAGES:{pages}";
16
16
  readonly 'dev.watching.end.files': "DONE Build complete. FILES:{files}";
17
17
  readonly 'dev.watching.restart.vapor': "DONE Restart required. 切换蒸汽模式需要重新运行才能生效。";
18
+ readonly 'dev.watching.vapor.render.target': "manifest.json 中更改了视图层编译目标为{manifestTarget},但注意运行控制台还是{runtimeTarget}。";
18
19
  readonly 'build.failed': "DONE Build failed.";
19
20
  readonly 'compiler.build.failed': "编译失败";
20
21
  readonly 'stat.warn.appid': "当前应用未配置 appid,无法使用 uni 统计,详情参考:https://ask.dcloud.net.cn/article/36303";
@@ -17,6 +17,7 @@ exports.default = {
17
17
  'dev.watching.end.pages': 'DONE Build complete. PAGES:{pages}',
18
18
  'dev.watching.end.files': 'DONE Build complete. FILES:{files}',
19
19
  'dev.watching.restart.vapor': 'DONE Restart required. 切换蒸汽模式需要重新运行才能生效。',
20
+ 'dev.watching.vapor.render.target': 'manifest.json 中更改了视图层编译目标为{manifestTarget},但注意运行控制台还是{runtimeTarget}。',
20
21
  'build.failed': 'DONE Build failed.',
21
22
  'compiler.build.failed': '编译失败',
22
23
  'stat.warn.appid': '当前应用未配置 appid,无法使用 uni 统计,详情参考:https://ask.dcloud.net.cn/article/36303',
@@ -1,6 +1,5 @@
1
+ import type { PluginContext } from 'rollup';
1
2
  import { type ImportSpecifier } from 'es-module-lexer';
2
- import type { Rolldown } from 'vite';
3
- type PluginContext = Rolldown.PluginContext;
4
3
  /**
5
4
  * 暂时没用
6
5
  * @param source
@@ -11,4 +10,3 @@ type PluginContext = Rolldown.PluginContext;
11
10
  export declare function findVueComponentImports(source: string, importer: string, resolve: PluginContext['resolve']): Promise<(ImportSpecifier & {
12
11
  i: string;
13
12
  })[]>;
14
- export {};
@@ -1,7 +1,6 @@
1
- import type { Rolldown } from 'vite';
1
+ import type { EmittedAsset } from 'rollup';
2
2
  import type { AttributeNode, DirectiveNode, ElementNode } from '@vue/compiler-core';
3
3
  import type { MiniProgramComponentsType } from '../json/mp/types';
4
- type EmittedAsset = Rolldown.EmittedAsset;
5
4
  type LazyElementFn = (node: ElementNode, context: {
6
5
  isMiniProgramComponent(name: string): MiniProgramComponentsType | undefined;
7
6
  }) => {
@@ -1,6 +1,5 @@
1
1
  import { type ImportDeclaration, type Program } from '@babel/types';
2
- import type { Rolldown } from 'vite';
3
- type PluginContext = Rolldown.PluginContext;
2
+ import type { PluginContext } from 'rollup';
4
3
  type BindingComponents = Record<string, {
5
4
  tag: string;
6
5
  type: 'unknown' | 'setup' | 'self';
@@ -49,6 +49,7 @@ export interface EncryptPackageJson {
49
49
  export declare function initCheckEnv(): Record<string, unknown>;
50
50
  export declare function resolveEncryptUniModule(id: string, platform: typeof process.env.UNI_UTS_PLATFORM, isX?: boolean): string | undefined;
51
51
  type CloudCompileSdkType = 'utssdk' | 'easycom' | 'all';
52
+ type VaporRenderTarget = 'bytecode' | 'nativecode';
52
53
  export interface CloudCompileParams {
53
54
  mode: 'development' | 'production';
54
55
  packType: 'debug' | 'release';
@@ -57,6 +58,8 @@ export interface CloudCompileParams {
57
58
  appname: string;
58
59
  platform: typeof process.env.UNI_UTS_PLATFORM;
59
60
  'uni-app-x': boolean;
61
+ vapor: boolean;
62
+ vaporRenderTarget?: VaporRenderTarget;
60
63
  env: Record<string, string>;
61
64
  }
62
65
  export declare function checkEncryptUniModules(inputDir: string, params: CloudCompileParams, sdkType?: CloudCompileSdkType): Promise<{} | undefined>;
@@ -67,5 +70,6 @@ export declare function parseUniModulesArtifacts(): {
67
70
  scopedSlots: string[];
68
71
  declaration: string;
69
72
  }[];
73
+ export declare function copyEncryptUniModulesDom2Bytes(): boolean | Promise<boolean>;
70
74
  export declare function virtualComponentPath(filepath: string): string;
71
75
  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.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");
@@ -429,6 +429,7 @@ async function checkEncryptUniModules(inputDir, params, sdkType = 'all') {
429
429
  const AdmZip = require('adm-zip');
430
430
  const zip = new AdmZip(downloadFile);
431
431
  zip.extractAllTo(cacheDir, true);
432
+ await Promise.resolve(copyEncryptUniModulesDom2Bytes());
432
433
  fs_extra_1.default.unlinkSync(zipFile);
433
434
  fs_extra_1.default.unlinkSync(downloadFile);
434
435
  R({
@@ -446,6 +447,7 @@ async function checkEncryptUniModules(inputDir, params, sdkType = 'all') {
446
447
  }
447
448
  }
448
449
  else {
450
+ await Promise.resolve(copyEncryptUniModulesDom2Bytes());
449
451
  const useUniAppXAndroidNative = (0, x_1.isUniAppXAndroidNative)(params.platform);
450
452
  // 仅旧版 Android x 需要在缓存命中时额外初始化
451
453
  if (useUniAppXAndroidNative) {
@@ -480,6 +482,83 @@ function parseUniModulesArtifacts() {
480
482
  return res;
481
483
  }
482
484
  exports.parseUniModulesArtifacts = parseUniModulesArtifacts;
485
+ function copyEncryptUniModulesDom2Bytes() {
486
+ if (process.env.UNI_APP_X_DOM2 !== 'true') {
487
+ return false;
488
+ }
489
+ if (!['app-android', 'app-ios', 'app-harmony'].includes(process.env.UNI_UTS_PLATFORM)) {
490
+ return false;
491
+ }
492
+ const cacheDir = process.env.UNI_MODULES_ENCRYPT_CACHE_DIR;
493
+ const outputDir = process.env.UNI_OUTPUT_DIR;
494
+ if (!cacheDir || !outputDir) {
495
+ return false;
496
+ }
497
+ if (process.env.UNI_APP_X_VAPOR_RENDER_TARGET === 'bytecode') {
498
+ return copyEncryptUniModulesDom2BytesTarget(cacheDir, outputDir);
499
+ }
500
+ if (process.env.UNI_APP_X_VAPOR_RENDER_TARGET === 'nativecode') {
501
+ return copyEncryptUniModulesDom2CppTarget(cacheDir, outputDir);
502
+ }
503
+ return false;
504
+ }
505
+ exports.copyEncryptUniModulesDom2Bytes = copyEncryptUniModulesDom2Bytes;
506
+ function copyEncryptUniModulesDom2BytesTarget(cacheDir, outputDir) {
507
+ // 只依赖编译环境变量定位缓存目录和输出目录,避免拼接具体 unpackage/dist 路径。
508
+ const sourceBytesDir = path_1.default.resolve(cacheDir, 'bytes');
509
+ if (!fs_extra_1.default.existsSync(sourceBytesDir) ||
510
+ !fs_extra_1.default.statSync(sourceBytesDir).isDirectory()) {
511
+ return false;
512
+ }
513
+ const outputBytesDir = path_1.default.resolve(outputDir, 'bytes');
514
+ // 云编译产出的 bytecode 在缓存目录中,这里只合并复制到当前编译输出目录。
515
+ fs_extra_1.default.copySync(sourceBytesDir, outputBytesDir, { overwrite: true });
516
+ return true;
517
+ }
518
+ async function copyEncryptUniModulesDom2CppTarget(cacheDir, outputDir) {
519
+ const sourceCppDir = path_1.default.resolve(cacheDir, 'cpp');
520
+ if (!fs_extra_1.default.existsSync(sourceCppDir) ||
521
+ !fs_extra_1.default.statSync(sourceCppDir).isDirectory()) {
522
+ return false;
523
+ }
524
+ const outputCppDir = process.env.UNI_APP_X_DOM2_CPP_DIR || path_1.default.resolve(outputDir, 'cpp');
525
+ // nativecode 的 cpp/h 暂时不走 DUM 解密,直接复制云端产物。
526
+ // const cppFiles = sync('**/*.{cpp,h}', {
527
+ // absolute: false,
528
+ // cwd: sourceCppDir,
529
+ // onlyFiles: true,
530
+ // }).filter((file) => !isIgnoreDom2CppFile(file))
531
+ // if (cppFiles.length) {
532
+ // const files = cppFiles.reduce((files, file) => {
533
+ // files[path.resolve(sourceCppDir, file)] = path.resolve(outputCppDir, file)
534
+ // return files
535
+ // }, {} as Record<string, string>)
536
+ // const { DUM } = requireUniHelpers()
537
+ // const errMsg = await DUM(path.basename(sourceCppDir), files)
538
+ // if (errMsg) {
539
+ // console.error(errMsg)
540
+ // process.exit(0)
541
+ // }
542
+ // }
543
+ // cpp 目录保持原目录结构直接复制,shared_data_init.h 由当前编译流程生成,不复制云端缓存版本。
544
+ fs_extra_1.default.copySync(sourceCppDir, outputCppDir, {
545
+ filter(src) {
546
+ if (fs_extra_1.default.statSync(src).isDirectory()) {
547
+ return true;
548
+ }
549
+ // shared_data_init.h 由当前编译生成,不能复制云端缓存里的旧文件覆盖本地结果。
550
+ if (isIgnoreDom2CppFile(src)) {
551
+ return false;
552
+ }
553
+ return true;
554
+ },
555
+ overwrite: true,
556
+ });
557
+ return true;
558
+ }
559
+ function isIgnoreDom2CppFile(filename) {
560
+ return path_1.default.basename(filename) === 'shared_data_init.h';
561
+ }
483
562
  const uniComponentPrefix = 'uniComponent://';
484
563
  function virtualComponentPath(filepath) {
485
564
  return uniComponentPrefix + (0, url_1.encodeBase64Url)(filepath);
@@ -131,13 +131,16 @@ function uniEncryptUniModulesPlugin() {
131
131
  }
132
132
  delete bundle[fileName];
133
133
  const pkg = `uni_modules/${uniModuleId}/package.json`;
134
- this.emitFile({
134
+ bundle[pkg] = {
135
135
  type: 'asset',
136
136
  fileName: pkg,
137
+ name: pkg,
138
+ originalFileName: null,
139
+ needsCodeReference: false,
137
140
  source: genUniModulesPackageJson(uniModuleId, process.env.UNI_INPUT_DIR, {
138
141
  env: (0, uni_modules_cloud_1.initCheckEnv)(),
139
142
  }),
140
- });
143
+ };
141
144
  }
142
145
  else if (fileName.endsWith('.js')) {
143
146
  if (isMp) {
@@ -1,4 +1,5 @@
1
- import type { Plugin, Rolldown } from 'vite';
1
+ import type { Plugin } from 'vite';
2
+ import type { EmittedAsset } from 'rollup';
2
3
  import type { ParserOptions } from '@vue/compiler-core';
3
4
  import type { CompilerOptions, SFCStyleCompileOptions, TemplateCompiler } from '@vue/compiler-sfc';
4
5
  import type { UniViteCopyPluginOptions } from './plugins/copy';
@@ -16,7 +17,7 @@ interface UniVitePluginUniOptions {
16
17
  styleOptions?: Pick<SFCStyleCompileOptions, 'postcssPlugins'>;
17
18
  compilerOptions?: {
18
19
  miniProgram?: {
19
- emitFile?: (emittedFile: Rolldown.EmittedAsset) => string;
20
+ emitFile?: (emittedFile: EmittedAsset) => string;
20
21
  };
21
22
  isNativeTag?: ParserOptions['isNativeTag'];
22
23
  isVoidTag?: ParserOptions['isVoidTag'];
@@ -22,42 +22,38 @@ function uniConsolePlugin(options) {
22
22
  resolvedConfig = config;
23
23
  // 理论上发行模式就不应该有这个逻辑了,只不过为了尽量不引发兼容性问题,目前严谨一些判断是否配置了 drop_console
24
24
  if (process.env.NODE_ENV !== 'development') {
25
- const compressOptions = resolvedConfig.build.terserOptions
26
- ?.compress;
25
+ const compressOptions = resolvedConfig.build.terserOptions?.compress;
27
26
  if (compressOptions && typeof compressOptions === 'object') {
28
27
  dropConsole = !!compressOptions.drop_console;
29
28
  }
30
29
  }
31
30
  },
32
- transform: {
33
- filter: { code: /console\.|__f__/ },
34
- handler(code, id) {
35
- if (dropConsole) {
36
- return;
37
- }
38
- if ((0, filter_1.isRenderjs)(id) || (0, filter_1.isWxs)(id)) {
39
- return {
40
- code: (0, console_1.restoreConsoleExpr)(code),
41
- map: null,
42
- };
43
- }
44
- if (!filter(id))
45
- return null;
46
- if (!(0, utils_1.isJsFile)(id))
47
- return null;
48
- let { filename } = (0, utils_1.parseVueRequest)(id);
49
- if (options.filename) {
50
- filename = options.filename(filename);
51
- }
52
- if (!filename) {
53
- return null;
54
- }
55
- if (!code.includes('console.')) {
56
- return null;
57
- }
58
- debugConsole(id);
59
- return (0, console_1.rewriteConsoleExpr)(options.method, id, filename, code, (0, utils_2.withSourcemap)(resolvedConfig));
60
- },
31
+ transform(code, id) {
32
+ if (dropConsole) {
33
+ return;
34
+ }
35
+ if ((0, filter_1.isRenderjs)(id) || (0, filter_1.isWxs)(id)) {
36
+ return {
37
+ code: (0, console_1.restoreConsoleExpr)(code),
38
+ map: null,
39
+ };
40
+ }
41
+ if (!filter(id))
42
+ return null;
43
+ if (!(0, utils_1.isJsFile)(id))
44
+ return null;
45
+ let { filename } = (0, utils_1.parseVueRequest)(id);
46
+ if (options.filename) {
47
+ filename = options.filename(filename);
48
+ }
49
+ if (!filename) {
50
+ return null;
51
+ }
52
+ if (!code.includes('console.')) {
53
+ return null;
54
+ }
55
+ debugConsole(id);
56
+ return (0, console_1.rewriteConsoleExpr)(options.method, id, filename, code, (0, utils_2.withSourcemap)(resolvedConfig));
61
57
  },
62
58
  };
63
59
  }
@@ -11,7 +11,6 @@ function uniViteCopyPlugin({ targets, }) {
11
11
  let isFirstBuild = true;
12
12
  return {
13
13
  name: 'uni:copy',
14
- enforce: 'pre',
15
14
  apply: 'build',
16
15
  configResolved(config) {
17
16
  resolvedConfig = config;
@@ -13,7 +13,6 @@ const utils_1 = require("../../utils");
13
13
  const utils_2 = require("../../vue/utils");
14
14
  const debugScoped = (0, debug_1.default)('uni:scoped');
15
15
  const SCOPED_RE = /<style\s[^>]*scoped[^>]*>/i;
16
- const VUE_SFC_ID_RE = /\.(?:vue|nvue|uvue)(?:$|\?(?!vue(?:&|=|$)))/;
17
16
  function addScoped(code) {
18
17
  return code.replace(/(<style\b[^><]*)>/gi, (str, $1) => {
19
18
  if ($1.includes('scoped')) {
@@ -33,18 +32,14 @@ function uniRemoveCssScopedPlugin(_ = { filter: () => false }) {
33
32
  return {
34
33
  name: 'uni:css-remove-scoped',
35
34
  enforce: 'pre',
36
- transform: {
37
- // 仅 SFC 主模块需要移除 scoped,跳过 script/style/template 等子模块。
38
- filter: { id: VUE_SFC_ID_RE },
39
- handler(code, id) {
40
- if (!(0, utils_2.isVueSfcFile)(id))
41
- return null;
42
- debugScoped(id);
43
- return {
44
- code: removeScoped(code),
45
- map: null,
46
- };
47
- },
35
+ transform(code, id) {
36
+ if (!(0, utils_2.isVueSfcFile)(id))
37
+ return null;
38
+ debugScoped(id);
39
+ return {
40
+ code: removeScoped(code),
41
+ map: null,
42
+ };
48
43
  },
49
44
  };
50
45
  }
@@ -54,18 +49,14 @@ function uniCssScopedPlugin({ filter } = { filter: () => false }) {
54
49
  return {
55
50
  name: 'uni:css-scoped',
56
51
  enforce: 'pre',
57
- transform: {
58
- // 仅 SFC 主模块需要补 scoped,跳过 script/style/template 等子模块。
59
- filter: { id: VUE_SFC_ID_RE },
60
- handler(code, id) {
61
- if (!filter(id))
62
- return null;
63
- debugScoped(id);
64
- return {
65
- code: addScoped(code),
66
- map: null,
67
- };
68
- },
52
+ transform(code, id) {
53
+ if (!filter(id))
54
+ return null;
55
+ debugScoped(id);
56
+ return {
57
+ code: addScoped(code),
58
+ map: null,
59
+ };
69
60
  },
70
61
  // 仅 h5
71
62
  handleHotUpdate(ctx) {
@@ -1,9 +1,2 @@
1
1
  import type { Plugin } from 'vite';
2
- interface DynamicImportPolyfillPlugin extends Plugin {
3
- renderDynamicImport(): {
4
- left: string;
5
- right: string;
6
- };
7
- }
8
- export declare function dynamicImportPolyfill(promise?: boolean): DynamicImportPolyfillPlugin;
9
- export {};
2
+ export declare function dynamicImportPolyfill(promise?: boolean): Plugin;