@dcloudio/uni-cli-shared 3.0.0-alpha-4020820240920001 → 3.0.0-alpha-4030120240925001

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/index.d.ts CHANGED
@@ -22,7 +22,8 @@ export * from './resolve';
22
22
  export * from './scripts';
23
23
  export * from './platform';
24
24
  export * from './utsUtils';
25
- export { parseUniExtApi, parseUniExtApis, parseInjects, parseUniModulesArtifacts, Define, DefineOptions, Defines, getUniExtApiProviderRegisters, resolveEncryptUniModule, formatExtApiProviderName, } from './uni_modules';
25
+ export { parseUniExtApi, parseUniExtApis, parseInjects, Define, DefineOptions, Defines, getUniExtApiProviderRegisters, formatExtApiProviderName, } from './uni_modules';
26
+ export { parseUniModulesArtifacts, resolveEncryptUniModule, } from './uni_modules.cloud';
26
27
  export { M } from './messages';
27
28
  export * from './exports';
28
29
  export { checkUpdate } from './checkUpdate';
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.formatExtApiProviderName = exports.resolveEncryptUniModule = exports.getUniExtApiProviderRegisters = exports.parseUniModulesArtifacts = exports.parseInjects = exports.parseUniExtApis = exports.parseUniExtApi = void 0;
17
+ exports.checkUpdate = exports.M = exports.resolveEncryptUniModule = exports.parseUniModulesArtifacts = 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);
@@ -43,10 +43,11 @@ var uni_modules_1 = require("./uni_modules");
43
43
  Object.defineProperty(exports, "parseUniExtApi", { enumerable: true, get: function () { return uni_modules_1.parseUniExtApi; } });
44
44
  Object.defineProperty(exports, "parseUniExtApis", { enumerable: true, get: function () { return uni_modules_1.parseUniExtApis; } });
45
45
  Object.defineProperty(exports, "parseInjects", { enumerable: true, get: function () { return uni_modules_1.parseInjects; } });
46
- Object.defineProperty(exports, "parseUniModulesArtifacts", { enumerable: true, get: function () { return uni_modules_1.parseUniModulesArtifacts; } });
47
46
  Object.defineProperty(exports, "getUniExtApiProviderRegisters", { enumerable: true, get: function () { return uni_modules_1.getUniExtApiProviderRegisters; } });
48
- Object.defineProperty(exports, "resolveEncryptUniModule", { enumerable: true, get: function () { return uni_modules_1.resolveEncryptUniModule; } });
49
47
  Object.defineProperty(exports, "formatExtApiProviderName", { enumerable: true, get: function () { return uni_modules_1.formatExtApiProviderName; } });
48
+ var uni_modules_cloud_1 = require("./uni_modules.cloud");
49
+ Object.defineProperty(exports, "parseUniModulesArtifacts", { enumerable: true, get: function () { return uni_modules_cloud_1.parseUniModulesArtifacts; } });
50
+ Object.defineProperty(exports, "resolveEncryptUniModule", { enumerable: true, get: function () { return uni_modules_cloud_1.resolveEncryptUniModule; } });
50
51
  var messages_1 = require("./messages");
51
52
  Object.defineProperty(exports, "M", { enumerable: true, get: function () { return messages_1.M; } });
52
53
  __exportStar(require("./exports"), exports);
@@ -26,7 +26,7 @@ const defaultManifestJson = `{
26
26
  "permissions": {},
27
27
  "plus": {
28
28
  "useragent": {
29
- "value": "uni-app appservice",
29
+ "value": "",
30
30
  "concatenate": true
31
31
  },
32
32
  "splashscreen": {
@@ -14,7 +14,17 @@ function initLaunchwebview(manifestJson, pagesJson) {
14
14
  }
15
15
  catch (e) { }
16
16
  }
17
- manifestJson.plus.useragent.value = 'uni-app';
17
+ if (manifestJson.plus.useragent.concatenate) {
18
+ if (manifestJson.plus.useragent.value) {
19
+ manifestJson.plus.useragent.value = [
20
+ 'uni-app',
21
+ manifestJson.plus.useragent.value,
22
+ ].join(' ');
23
+ }
24
+ else {
25
+ manifestJson.plus.useragent.value = 'uni-app';
26
+ }
27
+ }
18
28
  (0, shared_1.extend)(manifestJson.plus.launchwebview, {
19
29
  id: '1',
20
30
  kernel: 'WKWebview',
@@ -36,6 +36,8 @@ function normalizeAppUniConfig(pagesJson, manifestJson) {
36
36
  locales: (0, i18n_1.initLocales)(path_1.default.join(process.env.UNI_INPUT_DIR, 'locale')),
37
37
  darkmode: platformConfig.darkmode || false,
38
38
  themeConfig: (0, theme_1.normalizeThemeConfigOnce)(platformConfig),
39
+ // @ts-expect-error
40
+ qqMapKey: platformConfig?.distribute?.sdkConfigs?.maps?.qqmap?.key,
39
41
  };
40
42
  // TODO 待支持分包
41
43
  return JSON.stringify(config);
@@ -9,10 +9,11 @@ const path_1 = __importDefault(require("path"));
9
9
  const shared_1 = require("@vue/shared");
10
10
  const uni_shared_1 = require("@dcloudio/uni-shared");
11
11
  const json_1 = require("./json");
12
+ const utils_1 = require("../utils");
12
13
  const parseManifestJson = (inputDir) => {
13
14
  const manifestFilename = path_1.default.join(inputDir, 'manifest.json');
14
15
  if (!fs_1.default.existsSync(manifestFilename)) {
15
- if (process.env.UNI_COMPILE_TARGET === 'uni_modules') {
16
+ if (!(0, utils_1.isNormalCompileTarget)()) {
16
17
  return {};
17
18
  }
18
19
  }
@@ -45,7 +45,7 @@ exports.isUniPageSfcFile = isUniPageSfcFile;
45
45
  const parsePagesJson = (inputDir, platform, normalize = true) => {
46
46
  const pagesFilename = path_1.default.join(inputDir, 'pages.json');
47
47
  if (!fs_1.default.existsSync(pagesFilename)) {
48
- if (process.env.UNI_COMPILE_TARGET === 'uni_modules') {
48
+ if (!(0, utils_1.isNormalCompileTarget)()) {
49
49
  return {
50
50
  pages: [],
51
51
  globalStyle: { navigationBar: {} },
@@ -1,5 +1,5 @@
1
1
  import type { EmittedAsset } from 'rollup';
2
- import type { ElementNode } from '@vue/compiler-core';
2
+ import type { AttributeNode, DirectiveNode, ElementNode } from '@vue/compiler-core';
3
3
  import type { MiniProgramComponentsType } from '../json/mp/types';
4
4
  type LazyElementFn = (node: ElementNode, context: {
5
5
  isMiniProgramComponent(name: string): MiniProgramComponentsType | undefined;
@@ -10,6 +10,10 @@ type LazyElementFn = (node: ElementNode, context: {
10
10
  }[] | true;
11
11
  } | boolean;
12
12
  export interface MiniProgramCompilerOptions {
13
+ /**
14
+ * 检查属性名称是否符合平台要求,比如华为快应用不允许使用 key 属性等
15
+ */
16
+ checkPropName?: (name: string, prop: AttributeNode | DirectiveNode, node: ElementNode) => boolean;
13
17
  /**
14
18
  * 需要延迟渲染的组件,通常是某个组件的某个事件会立刻触发,需要延迟到首次 render 之后,比如微信 editor 的 ready 事件,快手 switch 的 change
15
19
  */
package/dist/platform.js CHANGED
@@ -18,6 +18,7 @@ const BUILT_IN_PLATFORMS = [
18
18
  'mp-qq',
19
19
  'mp-toutiao',
20
20
  'mp-weixin',
21
+ 'mp-xhs',
21
22
  'quickapp-webview',
22
23
  'quickapp-webview-huawei',
23
24
  'quickapp-webview-union',
@@ -1,4 +1,9 @@
1
1
  export declare function getPreVueContext(): any;
2
2
  export declare function getPreNVueContext(): any;
3
3
  export declare function getPreUVueContext(): any;
4
+ export declare function initScopedPreContext(platform: UniApp.PLATFORM, userPreContext?: Record<string, boolean> | string, utsPlatform?: typeof process.env.UNI_UTS_PLATFORM, isX?: boolean): {
5
+ preVueContext: any;
6
+ preNVueContext: any;
7
+ preUVueContext: any;
8
+ };
4
9
  export declare function initPreContext(platform: UniApp.PLATFORM, userPreContext?: Record<string, boolean> | string, utsPlatform?: typeof process.env.UNI_UTS_PLATFORM, isX?: boolean): void;
@@ -1,6 +1,6 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.initPreContext = exports.getPreUVueContext = exports.getPreNVueContext = exports.getPreVueContext = void 0;
3
+ exports.initPreContext = exports.initScopedPreContext = exports.getPreUVueContext = exports.getPreNVueContext = exports.getPreVueContext = void 0;
4
4
  const extend = Object.assign;
5
5
  const isString = (val) => typeof val === 'string';
6
6
  const objectToString = Object.prototype.toString;
@@ -51,7 +51,7 @@ function getPreUVueContext() {
51
51
  return preUVueContext;
52
52
  }
53
53
  exports.getPreUVueContext = getPreUVueContext;
54
- function initPreContext(platform, userPreContext, utsPlatform, isX) {
54
+ function initScopedPreContext(platform, userPreContext, utsPlatform, isX) {
55
55
  const vueContext = Object.create(null);
56
56
  const nvueContext = Object.create(null);
57
57
  const uvueContext = Object.create(null);
@@ -112,9 +112,18 @@ function initPreContext(platform, userPreContext, utsPlatform, isX) {
112
112
  });
113
113
  }
114
114
  }
115
- extend(preVueContext, defaultContext, vueContext);
116
- extend(preNVueContext, defaultContext, nvueContext);
117
- extend(preUVueContext, defaultContext, uvueContext);
115
+ return {
116
+ preVueContext: extend({}, defaultContext, vueContext),
117
+ preNVueContext: extend({}, defaultContext, nvueContext),
118
+ preUVueContext: extend({}, defaultContext, uvueContext),
119
+ };
120
+ }
121
+ exports.initScopedPreContext = initScopedPreContext;
122
+ function initPreContext(platform, userPreContext, utsPlatform, isX) {
123
+ const { preVueContext: scopedPreVueContext, preNVueContext: scopedPreNVueContext, preUVueContext: scopedPreUVueContext, } = initScopedPreContext(platform, userPreContext, utsPlatform, isX);
124
+ extend(preVueContext, scopedPreVueContext);
125
+ extend(preNVueContext, scopedPreNVueContext);
126
+ extend(preUVueContext, scopedPreUVueContext);
118
127
  }
119
128
  exports.initPreContext = initPreContext;
120
129
  function normalizeKey(name) {
package/dist/resolve.d.ts CHANGED
@@ -2,6 +2,7 @@ export declare function requireResolve(filename: string, basedir: string): strin
2
2
  export declare function relativeFile(from: string, to: string): string;
3
3
  export declare const resolveMainPathOnce: (inputDir: string) => string;
4
4
  export declare function getBuiltInPaths(): string[];
5
- export declare function resolveBuiltIn(path: string): string;
5
+ export declare function resolveBuiltIn(module: string): string;
6
6
  export declare function resolveVueI18nRuntime(): string;
7
7
  export declare function resolveComponentsLibPath(): string;
8
+ export declare function resolveComponentsLibDirs(): string[];
package/dist/resolve.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.resolveComponentsLibPath = exports.resolveVueI18nRuntime = exports.resolveBuiltIn = exports.getBuiltInPaths = exports.resolveMainPathOnce = exports.relativeFile = exports.requireResolve = void 0;
6
+ exports.resolveComponentsLibDirs = exports.resolveComponentsLibPath = exports.resolveVueI18nRuntime = exports.resolveBuiltIn = exports.getBuiltInPaths = exports.resolveMainPathOnce = exports.relativeFile = exports.requireResolve = 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"));
@@ -93,8 +93,13 @@ function getBuiltInPaths() {
93
93
  return paths;
94
94
  }
95
95
  exports.getBuiltInPaths = getBuiltInPaths;
96
- function resolveBuiltIn(path) {
97
- return require.resolve(path, { paths: getBuiltInPaths() });
96
+ function resolveBuiltIn(module) {
97
+ if (process.env.UNI_COMPILE_TARGET === 'ext-api' &&
98
+ process.env.UNI_APP_NEXT_WORKSPACE &&
99
+ module.startsWith('@dcloudio/')) {
100
+ return path_1.default.resolve(process.env.UNI_APP_NEXT_WORKSPACE, 'packages', module);
101
+ }
102
+ return require.resolve(module, { paths: getBuiltInPaths() });
98
103
  }
99
104
  exports.resolveBuiltIn = resolveBuiltIn;
100
105
  function resolveVueI18nRuntime() {
@@ -125,3 +130,9 @@ function resolveComponentsLibPath() {
125
130
  return componentsLibPath;
126
131
  }
127
132
  exports.resolveComponentsLibPath = resolveComponentsLibPath;
133
+ function resolveComponentsLibDirs() {
134
+ return process.env.UNI_COMPILE_TARGET === 'ext-api'
135
+ ? []
136
+ : [resolveComponentsLibPath()];
137
+ }
138
+ exports.resolveComponentsLibDirs = resolveComponentsLibDirs;
@@ -0,0 +1,49 @@
1
+ export declare function genEncryptEasyComModuleIndex(platform: typeof process.env.UNI_UTS_PLATFORM, components: Record<string, '.vue' | '.uvue'>): string;
2
+ export declare function parseUniModulesWithComponents(inputDir: string): Record<string, Record<string, ".vue" | ".uvue">>;
3
+ /**
4
+ * 解析 easyCom 组件列表
5
+ * @param pluginId
6
+ * @param inputDir
7
+ * @returns
8
+ */
9
+ export declare function parseEasyComComponents(pluginId: string, inputDir: string, detectBinary?: boolean): Record<string, ".vue" | ".uvue">;
10
+ export declare function findEncryptUniModules(inputDir: string, cacheDir?: string): Record<string, EncryptPackageJson | undefined>;
11
+ export declare function findUploadEncryptUniModulesFiles(uniModules: Record<string, EncryptPackageJson | undefined>, platform: typeof process.env.UNI_UTS_PLATFORM, inputDir: string): Record<string, string[]>;
12
+ export declare function packUploadEncryptUniModules(uniModules: Record<string, EncryptPackageJson | undefined>, platform: typeof process.env.UNI_UTS_PLATFORM, inputDir: string, cacheDir: string): {
13
+ zipFile: string;
14
+ modules: string[];
15
+ };
16
+ interface EncryptPackageJson {
17
+ id: string;
18
+ version: string;
19
+ uni_modules: {
20
+ dependencies: string[];
21
+ artifacts: {
22
+ env: {
23
+ compilerVersion: string;
24
+ } & Record<string, any>;
25
+ apis: string[];
26
+ components: string[];
27
+ scopedSlots: string[];
28
+ declaration: string;
29
+ };
30
+ };
31
+ }
32
+ export declare function initCheckEnv(): Record<string, string>;
33
+ export declare function resolveEncryptUniModule(id: string, platform: typeof process.env.UNI_UTS_PLATFORM, isX?: boolean): string | undefined;
34
+ export declare function checkEncryptUniModules(inputDir: string, params: {
35
+ mode: 'development' | 'production';
36
+ packType: 'debug' | 'release';
37
+ compilerVersion: string;
38
+ appid: string;
39
+ appname: string;
40
+ platform: typeof process.env.UNI_UTS_PLATFORM;
41
+ 'uni-app-x': boolean;
42
+ }): Promise<{} | undefined>;
43
+ export declare function parseUniModulesArtifacts(): {
44
+ name: string;
45
+ package: string;
46
+ scopedSlots: string[];
47
+ declaration: string;
48
+ }[];
49
+ export {};
@@ -0,0 +1,332 @@
1
+ "use strict";
2
+ var __importDefault = (this && this.__importDefault) || function (mod) {
3
+ return (mod && mod.__esModule) ? mod : { "default": mod };
4
+ };
5
+ Object.defineProperty(exports, "__esModule", { value: true });
6
+ exports.parseUniModulesArtifacts = exports.checkEncryptUniModules = exports.resolveEncryptUniModule = exports.initCheckEnv = exports.packUploadEncryptUniModules = exports.findUploadEncryptUniModulesFiles = exports.findEncryptUniModules = exports.parseEasyComComponents = exports.parseUniModulesWithComponents = exports.genEncryptEasyComModuleIndex = void 0;
7
+ const path_1 = __importDefault(require("path"));
8
+ const fs_extra_1 = __importDefault(require("fs-extra"));
9
+ const fast_glob_1 = require("fast-glob");
10
+ const utils_1 = require("./utils");
11
+ const easycom_1 = require("./easycom");
12
+ const messages_1 = require("./messages");
13
+ function genEncryptEasyComModuleIndex(platform, components) {
14
+ const imports = [];
15
+ const ids = [];
16
+ Object.keys(components).forEach((component) => {
17
+ const id = (0, utils_1.capitalize)((0, utils_1.camelize)(component));
18
+ ids.push(id);
19
+ let instance = '';
20
+ if (platform === 'app-android') {
21
+ instance = (0, easycom_1.genUTSComponentPublicInstanceIdent)(component);
22
+ // 类型
23
+ ids.push(instance);
24
+ }
25
+ imports.push(`import ${id}${instance ? `, { ${instance} }` : ''} from './components/${component}/${component}${components[component]}'`);
26
+ });
27
+ return `
28
+ ${imports.join('\n')}
29
+ export {
30
+ ${ids.join(',\n ')}
31
+ }
32
+ `;
33
+ }
34
+ exports.genEncryptEasyComModuleIndex = genEncryptEasyComModuleIndex;
35
+ // 目前该函数仅在云端使用(目前仅限iOS/web),云端编译时,提交上来的uni_modules是过滤好的
36
+ function parseUniModulesWithComponents(inputDir) {
37
+ const modulesDir = path_1.default.resolve(inputDir, 'uni_modules');
38
+ const uniModules = {};
39
+ if (fs_extra_1.default.existsSync(modulesDir)) {
40
+ fs_extra_1.default.readdirSync(modulesDir).forEach((uniModuleDir) => {
41
+ if (!fs_extra_1.default.existsSync(path_1.default.resolve(modulesDir, uniModuleDir, 'package.json'))) {
42
+ return;
43
+ }
44
+ // 解析加密的 easyCom 插件列表
45
+ const components = parseEasyComComponents(uniModuleDir, inputDir, false);
46
+ uniModules[uniModuleDir] = components;
47
+ });
48
+ }
49
+ return uniModules;
50
+ }
51
+ exports.parseUniModulesWithComponents = parseUniModulesWithComponents;
52
+ /**
53
+ * 解析 easyCom 组件列表
54
+ * @param pluginId
55
+ * @param inputDir
56
+ * @returns
57
+ */
58
+ function parseEasyComComponents(pluginId, inputDir, detectBinary = true) {
59
+ const componentsDir = path_1.default.resolve(inputDir, 'uni_modules', pluginId, 'components');
60
+ const components = {};
61
+ if (fs_extra_1.default.existsSync(componentsDir)) {
62
+ fs_extra_1.default.readdirSync(componentsDir).forEach((componentDir) => {
63
+ const componentFile = path_1.default.resolve(componentsDir, componentDir, componentDir);
64
+ const extname = ['.vue', '.uvue'].find((extname) => {
65
+ const filename = componentFile + extname;
66
+ // 探测 filename 是否是二进制文件
67
+ if (fs_extra_1.default.existsSync(filename)) {
68
+ if (detectBinary) {
69
+ // 延迟require,这个是新增的依赖,无法及时同步到内部测试版本HBuilderX中,导致报错,所以延迟require吧
70
+ if (require('isbinaryfile').isBinaryFileSync(filename)) {
71
+ return true;
72
+ }
73
+ }
74
+ else {
75
+ return true;
76
+ }
77
+ }
78
+ });
79
+ if (extname) {
80
+ components[componentDir] = extname;
81
+ }
82
+ });
83
+ }
84
+ return components;
85
+ }
86
+ exports.parseEasyComComponents = parseEasyComComponents;
87
+ // 查找所有普通加密插件 uni_modules
88
+ function findEncryptUniModules(inputDir, cacheDir = '') {
89
+ const modulesDir = path_1.default.resolve(inputDir, 'uni_modules');
90
+ const uniModules = {};
91
+ if (fs_extra_1.default.existsSync(modulesDir)) {
92
+ fs_extra_1.default.readdirSync(modulesDir).forEach((uniModuleDir) => {
93
+ const uniModuleRootDir = path_1.default.resolve(modulesDir, uniModuleDir);
94
+ if (!fs_extra_1.default.existsSync(path_1.default.resolve(uniModuleRootDir, 'encrypt'))) {
95
+ return;
96
+ }
97
+ // 仅扫描普通加密插件,无需依赖
98
+ if (fs_extra_1.default.existsSync(path_1.default.resolve(uniModuleRootDir, 'utssdk'))) {
99
+ return;
100
+ }
101
+ const pkg = require(path_1.default.resolve(uniModuleRootDir, 'package.json'));
102
+ uniModules[uniModuleDir] = findEncryptUniModuleCache(uniModuleDir, cacheDir, { version: pkg.version, env: initCheckEnv() });
103
+ });
104
+ }
105
+ return uniModules;
106
+ }
107
+ exports.findEncryptUniModules = findEncryptUniModules;
108
+ function findUploadEncryptUniModulesFiles(uniModules, platform, inputDir) {
109
+ const modules = {};
110
+ Object.keys(uniModules).forEach((uniModuleId) => {
111
+ if (!uniModules[uniModuleId]) {
112
+ modules[uniModuleId] = findUniModuleFiles(platform, uniModuleId, inputDir);
113
+ }
114
+ });
115
+ return modules;
116
+ }
117
+ exports.findUploadEncryptUniModulesFiles = findUploadEncryptUniModulesFiles;
118
+ function packUploadEncryptUniModules(uniModules, platform, inputDir, cacheDir) {
119
+ const modules = findUploadEncryptUniModulesFiles(uniModules, platform, inputDir);
120
+ const uploadModuleIds = Object.keys(modules);
121
+ if (uploadModuleIds.length) {
122
+ // 延迟 require,避免 vue2 编译器需要安装此依赖,目前该方法仅在 vite 编译器中使用
123
+ const AdmZip = require('adm-zip');
124
+ const zip = new AdmZip();
125
+ uploadModuleIds.forEach((moduleId) => {
126
+ modules[moduleId].forEach((file) => {
127
+ zip.addLocalFile(file, path_1.default.dirname(path_1.default.relative(inputDir, file)));
128
+ });
129
+ });
130
+ const zipFile = path_1.default.resolve(cacheDir, 'cloud-compile-plugins.zip');
131
+ zip.writeZip(zipFile);
132
+ return {
133
+ zipFile,
134
+ modules: uploadModuleIds,
135
+ };
136
+ }
137
+ return {
138
+ zipFile: '',
139
+ modules: [],
140
+ };
141
+ }
142
+ exports.packUploadEncryptUniModules = packUploadEncryptUniModules;
143
+ function isEnvExpired(value, other) {
144
+ const valueKeys = Object.keys(value);
145
+ const otherKeys = Object.keys(other);
146
+ if (valueKeys.length !== otherKeys.length) {
147
+ return true;
148
+ }
149
+ if (valueKeys.find((name) => value[name] !== other[name])) {
150
+ return true;
151
+ }
152
+ return false;
153
+ }
154
+ function findEncryptUniModuleCache(uniModuleId, cacheDir, options) {
155
+ if (!cacheDir) {
156
+ return;
157
+ }
158
+ const uniModuleCacheDir = path_1.default.resolve(cacheDir, 'uni_modules', uniModuleId);
159
+ if (fs_extra_1.default.existsSync(uniModuleCacheDir)) {
160
+ const pkg = require(path_1.default.resolve(uniModuleCacheDir, 'package.json'));
161
+ // 插件版本以及各种环境一致
162
+ if (pkg.version === options.version &&
163
+ !isEnvExpired(pkg.uni_modules?.artifacts?.env || {}, options.env)) {
164
+ const declaration = path_1.default.resolve(uniModuleCacheDir, 'utssdk/app-android/index.d.uts');
165
+ pkg.uni_modules.artifacts.declaration = fs_extra_1.default.existsSync(declaration)
166
+ ? declaration
167
+ : '';
168
+ return pkg;
169
+ }
170
+ console.log(`插件${uniModuleId} 缓存已过期,需要重新云编译。`);
171
+ // 已过期的插件,删除缓存
172
+ fs_extra_1.default.rmSync(uniModuleCacheDir, { recursive: true });
173
+ }
174
+ }
175
+ const KNOWN_ASSET_TYPES = [
176
+ // images
177
+ 'png',
178
+ 'jpe?g',
179
+ 'gif',
180
+ 'svg',
181
+ 'ico',
182
+ 'webp',
183
+ 'avif',
184
+ // media
185
+ 'mp4',
186
+ 'webm',
187
+ 'ogg',
188
+ 'mp3',
189
+ 'wav',
190
+ 'flac',
191
+ 'aac',
192
+ // fonts
193
+ 'woff2?',
194
+ 'eot',
195
+ 'ttf',
196
+ 'otf',
197
+ // other
198
+ 'pdf',
199
+ 'txt',
200
+ ];
201
+ function findUniModuleFiles(platform, id, inputDir) {
202
+ return (0, fast_glob_1.sync)(`uni_modules/${id}/**/*`, {
203
+ cwd: inputDir,
204
+ absolute: true,
205
+ ignore: [
206
+ '**/*.md',
207
+ ...(platform !== 'app-android' // 非 android 平台不需要扫描 assets
208
+ ? [`**/*.{${KNOWN_ASSET_TYPES.join(',')}}`]
209
+ : []),
210
+ ],
211
+ });
212
+ }
213
+ function initCheckEnv() {
214
+ return {
215
+ // 云端编译的版本号不带日期及小版本
216
+ compilerVersion: process.env.UNI_COMPILER_VERSION,
217
+ };
218
+ }
219
+ exports.initCheckEnv = initCheckEnv;
220
+ function findLastIndex(array, predicate) {
221
+ for (let i = array.length - 1; i >= 0; i--) {
222
+ if (predicate(array[i], i, array)) {
223
+ return i;
224
+ }
225
+ }
226
+ return -1;
227
+ }
228
+ let encryptUniModules = {};
229
+ function resolveEncryptUniModule(id, platform, isX = true) {
230
+ const parts = id.split('?', 2)[0].split('/');
231
+ const index = findLastIndex(parts, (part) => part === 'uni_modules');
232
+ if (index !== -1) {
233
+ const uniModuleId = parts[index + 1];
234
+ if (uniModuleId in encryptUniModules) {
235
+ if (parts[index + 2]) {
236
+ console.warn(messages_1.M['uni_modules.import']
237
+ .replace('{0}', uniModuleId)
238
+ .replace('{1}', uniModuleId)
239
+ .replace('{2}', parts.slice(index + 2).join('/')));
240
+ }
241
+ // 原生平台走旧的uts-proxy
242
+ 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'}`));
243
+ }
244
+ }
245
+ }
246
+ exports.resolveEncryptUniModule = resolveEncryptUniModule;
247
+ async function checkEncryptUniModules(inputDir, params) {
248
+ // 扫描加密插件云编译
249
+ encryptUniModules = findEncryptUniModules(inputDir, process.env.UNI_MODULES_ENCRYPT_CACHE_DIR);
250
+ if (!Object.keys(encryptUniModules).length) {
251
+ return {};
252
+ }
253
+ if (!process.env.UNI_HBUILDERX_PLUGINS) {
254
+ return {};
255
+ }
256
+ const cacheDir = process.env.UNI_MODULES_ENCRYPT_CACHE_DIR;
257
+ const { zipFile, modules } = packUploadEncryptUniModules(encryptUniModules, process.env.UNI_UTS_PLATFORM, inputDir, cacheDir);
258
+ if (zipFile) {
259
+ const downloadFile = path_1.default.resolve(cacheDir, 'uni_modules.download.zip');
260
+ const { C, D, R, U } = (0, utils_1.requireUniHelpers)();
261
+ try {
262
+ const isLogin = await C();
263
+ const tips = process.env.UNI_UTS_PLATFORM !== 'app-android'
264
+ ? '(此过程耗时较长)'
265
+ : '';
266
+ console.log(`正在云编译插件${isLogin ? '' : '(请先登录)'}${tips}:${modules.join(',')}...`);
267
+ let downloadUrl = '';
268
+ try {
269
+ downloadUrl = await U({
270
+ params,
271
+ attachment: zipFile,
272
+ });
273
+ }
274
+ catch (e) {
275
+ if (e.message && e.message === '{"error":"UserNotLogin"}') {
276
+ console.log('当前项目包含需要云编译的付费插件,需要您先登录HBuilderX账号。');
277
+ }
278
+ else {
279
+ console.error(e);
280
+ }
281
+ process.exit(0);
282
+ }
283
+ await D(downloadUrl, downloadFile);
284
+ // unzip
285
+ const AdmZip = require('adm-zip');
286
+ const zip = new AdmZip(downloadFile);
287
+ zip.extractAllTo(cacheDir, true);
288
+ fs_extra_1.default.unlinkSync(zipFile);
289
+ fs_extra_1.default.unlinkSync(downloadFile);
290
+ R({
291
+ dir: process.env.UNI_INPUT_DIR,
292
+ cacheDir: process.env.UNI_MODULES_ENCRYPT_CACHE_DIR,
293
+ });
294
+ console.log(`云编译已完成`);
295
+ console.log(`正在编译中...`);
296
+ }
297
+ catch (e) {
298
+ fs_extra_1.default.existsSync(zipFile) && fs_extra_1.default.unlinkSync(zipFile);
299
+ fs_extra_1.default.existsSync(downloadFile) && fs_extra_1.default.unlinkSync(downloadFile);
300
+ console.error(e);
301
+ process.exit(0);
302
+ }
303
+ }
304
+ else {
305
+ // android 平台需要在这里初始化
306
+ if (params.platform === 'app-android') {
307
+ const { R } = (0, utils_1.requireUniHelpers)();
308
+ R({
309
+ dir: process.env.UNI_INPUT_DIR,
310
+ cacheDir: process.env.UNI_MODULES_ENCRYPT_CACHE_DIR,
311
+ });
312
+ }
313
+ }
314
+ encryptUniModules = findEncryptUniModules(inputDir, process.env.UNI_MODULES_ENCRYPT_CACHE_DIR);
315
+ }
316
+ exports.checkEncryptUniModules = checkEncryptUniModules;
317
+ function parseUniModulesArtifacts() {
318
+ const res = [];
319
+ Object.keys(encryptUniModules).forEach((uniModuleId) => {
320
+ const pkg = encryptUniModules[uniModuleId];
321
+ if (pkg?.uni_modules?.artifacts) {
322
+ res.push({
323
+ name: uniModuleId,
324
+ package: `uts.sdk.modules.${(0, utils_1.camelize)(uniModuleId)}`,
325
+ scopedSlots: pkg.uni_modules.artifacts.scopedSlots || [],
326
+ declaration: pkg.uni_modules.artifacts.declaration,
327
+ });
328
+ }
329
+ });
330
+ return res;
331
+ }
332
+ exports.parseUniModulesArtifacts = parseUniModulesArtifacts;
@@ -73,52 +73,3 @@ export declare const capitalize: (str: string) => string;
73
73
  * @returns
74
74
  */
75
75
  export declare function parseUTSModuleDeps(deps: string[], inputDir: string): string[];
76
- export declare function genEncryptEasyComModuleIndex(platform: typeof process.env.UNI_UTS_PLATFORM, components: Record<string, '.vue' | '.uvue'>): string;
77
- export declare function parseUniModulesWithComponents(inputDir: string): Record<string, Record<string, ".vue" | ".uvue">>;
78
- /**
79
- * 解析 easyCom 组件列表
80
- * @param pluginId
81
- * @param inputDir
82
- * @returns
83
- */
84
- export declare function parseEasyComComponents(pluginId: string, inputDir: string, detectBinary?: boolean): Record<string, ".vue" | ".uvue">;
85
- export declare function findEncryptUniModules(inputDir: string, cacheDir?: string): Record<string, EncryptPackageJson | undefined>;
86
- export declare function findUploadEncryptUniModulesFiles(uniModules: Record<string, EncryptPackageJson | undefined>, platform: typeof process.env.UNI_UTS_PLATFORM, inputDir: string): Record<string, string[]>;
87
- export declare function packUploadEncryptUniModules(uniModules: Record<string, EncryptPackageJson | undefined>, platform: typeof process.env.UNI_UTS_PLATFORM, inputDir: string, cacheDir: string): {
88
- zipFile: string;
89
- modules: string[];
90
- };
91
- interface EncryptPackageJson {
92
- id: string;
93
- version: string;
94
- uni_modules: {
95
- dependencies: string[];
96
- artifacts: {
97
- env: {
98
- compilerVersion: string;
99
- } & Record<string, any>;
100
- apis: string[];
101
- components: string[];
102
- scopedSlots: string[];
103
- declaration: string;
104
- };
105
- };
106
- }
107
- export declare function initCheckEnv(): Record<string, string>;
108
- export declare function resolveEncryptUniModule(id: string, platform: typeof process.env.UNI_UTS_PLATFORM, isX?: boolean): string | undefined;
109
- export declare function checkEncryptUniModules(inputDir: string, params: {
110
- mode: 'development' | 'production';
111
- packType: 'debug' | 'release';
112
- compilerVersion: string;
113
- appid: string;
114
- appname: string;
115
- platform: typeof process.env.UNI_UTS_PLATFORM;
116
- 'uni-app-x': boolean;
117
- }): Promise<{} | undefined>;
118
- export declare function parseUniModulesArtifacts(): {
119
- name: string;
120
- package: string;
121
- scopedSlots: string[];
122
- declaration: string;
123
- }[];
124
- export {};