@dcloudio/uni-cli-shared 3.0.0-4010420240430002 → 3.0.0-4020320240708001
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/easycom.js +35 -3
- package/dist/fs.js +8 -5
- package/dist/hbx/log.js +9 -0
- package/dist/index.d.ts +1 -1
- package/dist/index.js +5 -1
- package/dist/json/app/manifest/nvue.d.ts +1 -1
- package/dist/json/app/pages/definePage.d.ts +1 -1
- package/dist/json/app/pages/definePage.js +3 -3
- package/dist/json/app/pages/index.d.ts +1 -1
- package/dist/json/app/pages/index.js +2 -2
- package/dist/json/manifest.d.ts +1 -0
- package/dist/json/manifest.js +13 -2
- package/dist/json/pages.js +20 -2
- package/dist/json/theme.d.ts +19 -0
- package/dist/json/theme.js +240 -2
- package/dist/json/uni-x/uniConfig.js +5 -0
- package/dist/messages/en.d.ts +1 -0
- package/dist/messages/en.js +1 -0
- package/dist/messages/index.d.ts +2 -0
- package/dist/messages/zh_CN.d.ts +1 -0
- package/dist/messages/zh_CN.js +1 -0
- package/dist/postcss/plugins/uniapp.js +1 -0
- package/dist/preprocess/context.js +10 -2
- package/dist/resolve.js +6 -1
- package/dist/uni_modules.d.ts +51 -0
- package/dist/uni_modules.js +357 -23
- package/dist/utils.d.ts +14 -1
- package/dist/utils.js +39 -3
- package/dist/uts.d.ts +1 -1
- package/dist/uts.js +10 -3
- package/dist/vite/autoImport.js +16 -2
- package/dist/vite/cloud.d.ts +6 -0
- package/dist/vite/cloud.js +305 -0
- package/dist/vite/index.d.ts +2 -0
- package/dist/vite/index.js +4 -1
- package/dist/vite/plugins/easycom.js +3 -1
- package/dist/vite/plugins/uts/uni_modules.d.ts +3 -2
- package/dist/vite/plugins/uts/uni_modules.js +76 -14
- package/dist/vite/plugins/vitejs/plugins/asset.d.ts +3 -3
- package/dist/vite/plugins/vitejs/plugins/asset.js +11 -9
- package/dist/vite/plugins/vitejs/plugins/css.d.ts +6 -1
- package/dist/vite/plugins/vitejs/plugins/css.js +27 -25
- package/dist/vite/plugins/vitejs/plugins/static.d.ts +2 -0
- package/dist/vite/plugins/vitejs/plugins/static.js +40 -0
- package/dist/vite/utils/index.js +3 -0
- package/dist/vite/utils/plugin.d.ts +5 -2
- package/dist/vite/utils/plugin.js +7 -2
- package/dist/vite/utils/utils.js +3 -0
- package/dist/vue/transforms/transformPageHead.js +7 -3
- package/package.json +7 -4
|
@@ -16,6 +16,7 @@ const DEFAULT_KEYS = [
|
|
|
16
16
|
'APP_VUE',
|
|
17
17
|
'APP_ANDROID',
|
|
18
18
|
'APP_IOS',
|
|
19
|
+
'APP_HARMONY',
|
|
19
20
|
'H5',
|
|
20
21
|
'MP',
|
|
21
22
|
'MP_360',
|
|
@@ -68,9 +69,16 @@ function initPreContext(platform, userPreContext, utsPlatform, isX) {
|
|
|
68
69
|
nvueContext.UNI_APP_X = true;
|
|
69
70
|
uvueContext.UNI_APP_X = true;
|
|
70
71
|
}
|
|
71
|
-
if (platform === 'app' ||
|
|
72
|
+
if (platform === 'app' ||
|
|
73
|
+
platform === 'app-plus' ||
|
|
74
|
+
platform === 'app-harmony') {
|
|
72
75
|
defaultContext.APP = true;
|
|
73
|
-
|
|
76
|
+
if (platform === 'app-harmony') {
|
|
77
|
+
defaultContext.APP_HARMONY = true;
|
|
78
|
+
}
|
|
79
|
+
else {
|
|
80
|
+
defaultContext.APP_PLUS = isX ? false : true;
|
|
81
|
+
}
|
|
74
82
|
vueContext.APP_VUE = true;
|
|
75
83
|
nvueContext.APP_NVUE = true;
|
|
76
84
|
nvueContext.APP_PLUS_NVUE = true;
|
package/dist/resolve.js
CHANGED
|
@@ -107,7 +107,12 @@ function resolveComponentsLibPath() {
|
|
|
107
107
|
componentsLibPath = path_1.default.join(resolveBuiltIn('@dcloudio/uni-components/package.json'), dir);
|
|
108
108
|
}
|
|
109
109
|
else {
|
|
110
|
-
|
|
110
|
+
try {
|
|
111
|
+
componentsLibPath = path_1.default.join(resolveWithSymlinks('@dcloudio/uni-components/package.json', process.env.UNI_INPUT_DIR), dir);
|
|
112
|
+
}
|
|
113
|
+
catch (e) {
|
|
114
|
+
componentsLibPath = path_1.default.join(resolveWithSymlinks('@dcloudio/uni-components/package.json', process.cwd()), dir);
|
|
115
|
+
}
|
|
111
116
|
}
|
|
112
117
|
}
|
|
113
118
|
return componentsLibPath;
|
package/dist/uni_modules.d.ts
CHANGED
|
@@ -24,12 +24,15 @@ export declare function getUniExtApiProviders(): {
|
|
|
24
24
|
export declare function getUniExtApiPlugins(): {
|
|
25
25
|
plugin: string;
|
|
26
26
|
}[];
|
|
27
|
+
export declare function formatExtApiProviderName(service: string, name: string): string;
|
|
27
28
|
export declare function getUniExtApiProviderRegisters(): {
|
|
28
29
|
name: string;
|
|
30
|
+
plugin: string;
|
|
29
31
|
service: string;
|
|
30
32
|
class: string;
|
|
31
33
|
}[];
|
|
32
34
|
export declare function parseUniExtApis(vite: boolean | undefined, platform: typeof process.env.UNI_UTS_PLATFORM, language?: UTSTargetLanguage): Injects;
|
|
35
|
+
export declare function parseUniExtApi(pluginDir: string, pluginId: string, vite: boolean | undefined, platform: typeof process.env.UNI_UTS_PLATFORM, language?: UTSTargetLanguage): Injects | undefined;
|
|
33
36
|
export type Injects = {
|
|
34
37
|
[name: string]: string | [string, string] | [string, string, DefineOptions['app']] | false;
|
|
35
38
|
};
|
|
@@ -70,3 +73,51 @@ export declare const capitalize: (str: string) => string;
|
|
|
70
73
|
* @returns
|
|
71
74
|
*/
|
|
72
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
|
+
artifacts: {
|
|
96
|
+
env: {
|
|
97
|
+
compilerVersion: string;
|
|
98
|
+
} & Record<string, any>;
|
|
99
|
+
apis: string[];
|
|
100
|
+
components: string[];
|
|
101
|
+
scopedSlots: string[];
|
|
102
|
+
declaration: string;
|
|
103
|
+
};
|
|
104
|
+
};
|
|
105
|
+
}
|
|
106
|
+
export declare function initCheckEnv(): Record<string, string>;
|
|
107
|
+
export declare function resolveEncryptUniModule(id: string, platform: typeof process.env.UNI_UTS_PLATFORM, isX?: boolean): string | undefined;
|
|
108
|
+
export declare function checkEncryptUniModules(inputDir: string, params: {
|
|
109
|
+
mode: 'development' | 'production';
|
|
110
|
+
packType: 'debug' | 'release';
|
|
111
|
+
compilerVersion: string;
|
|
112
|
+
appid: string;
|
|
113
|
+
appname: string;
|
|
114
|
+
platform: typeof process.env.UNI_UTS_PLATFORM;
|
|
115
|
+
'uni-app-x': boolean;
|
|
116
|
+
}): Promise<{} | undefined>;
|
|
117
|
+
export declare function parseUniModulesArtifacts(): {
|
|
118
|
+
name: string;
|
|
119
|
+
package: string;
|
|
120
|
+
scopedSlots: string[];
|
|
121
|
+
declaration: string;
|
|
122
|
+
}[];
|
|
123
|
+
export {};
|
package/dist/uni_modules.js
CHANGED
|
@@ -3,10 +3,14 @@ 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.parseUTSModuleDeps = exports.capitalize = exports.camelize = exports.parseInjects = exports.parseUniExtApis = exports.getUniExtApiProviderRegisters = exports.getUniExtApiPlugins = exports.getUniExtApiProviders = void 0;
|
|
6
|
+
exports.parseUniModulesArtifacts = exports.checkEncryptUniModules = exports.resolveEncryptUniModule = exports.initCheckEnv = exports.packUploadEncryptUniModules = exports.findUploadEncryptUniModulesFiles = exports.findEncryptUniModules = exports.parseEasyComComponents = exports.parseUniModulesWithComponents = exports.genEncryptEasyComModuleIndex = exports.parseUTSModuleDeps = exports.capitalize = exports.camelize = exports.parseInjects = exports.parseUniExtApi = exports.parseUniExtApis = exports.getUniExtApiProviderRegisters = exports.formatExtApiProviderName = exports.getUniExtApiPlugins = exports.getUniExtApiProviders = void 0;
|
|
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 fast_glob_1 = require("fast-glob");
|
|
11
|
+
const utils_1 = require("./utils");
|
|
12
|
+
const easycom_1 = require("./easycom");
|
|
13
|
+
const messages_1 = require("./messages");
|
|
10
14
|
const extApiProviders = [];
|
|
11
15
|
const extApiPlugins = new Set();
|
|
12
16
|
function getUniExtApiProviders() {
|
|
@@ -19,18 +23,22 @@ function getUniExtApiPlugins() {
|
|
|
19
23
|
});
|
|
20
24
|
}
|
|
21
25
|
exports.getUniExtApiPlugins = getUniExtApiPlugins;
|
|
26
|
+
function formatExtApiProviderName(service, name) {
|
|
27
|
+
if (service === 'oauth') {
|
|
28
|
+
service = 'OAuth';
|
|
29
|
+
}
|
|
30
|
+
return `Uni${(0, exports.capitalize)((0, exports.camelize)(service))}${(0, exports.capitalize)((0, exports.camelize)(name))}Provider`;
|
|
31
|
+
}
|
|
32
|
+
exports.formatExtApiProviderName = formatExtApiProviderName;
|
|
22
33
|
function getUniExtApiProviderRegisters() {
|
|
23
34
|
const result = [];
|
|
24
35
|
extApiProviders.forEach((provider) => {
|
|
25
36
|
if (provider.name && provider.service) {
|
|
26
37
|
result.push({
|
|
27
38
|
name: provider.name,
|
|
39
|
+
plugin: provider.plugin,
|
|
28
40
|
service: provider.service,
|
|
29
|
-
class: `uts.sdk.modules.${(0, exports.camelize)(provider.plugin)}.${(
|
|
30
|
-
provider.service +
|
|
31
|
-
'-' +
|
|
32
|
-
provider.name +
|
|
33
|
-
'-provider'))}`,
|
|
41
|
+
class: `uts.sdk.modules.${(0, exports.camelize)(provider.plugin)}.${formatExtApiProviderName(provider.service, provider.name)}`,
|
|
34
42
|
});
|
|
35
43
|
}
|
|
36
44
|
});
|
|
@@ -80,6 +88,21 @@ function parseUniExtApis(vite = true, platform, language = 'javascript') {
|
|
|
80
88
|
return injects;
|
|
81
89
|
}
|
|
82
90
|
exports.parseUniExtApis = parseUniExtApis;
|
|
91
|
+
function parseUniExtApi(pluginDir, pluginId, vite = true, platform, language = 'javascript') {
|
|
92
|
+
const pkgPath = path_1.default.resolve(pluginDir, 'package.json');
|
|
93
|
+
if (!fs_extra_1.default.existsSync(pkgPath)) {
|
|
94
|
+
return;
|
|
95
|
+
}
|
|
96
|
+
let exports;
|
|
97
|
+
const pkg = JSON.parse(fs_extra_1.default.readFileSync(pkgPath, 'utf8'));
|
|
98
|
+
if (pkg && pkg.uni_modules && pkg.uni_modules['uni-ext-api']) {
|
|
99
|
+
exports = pkg.uni_modules['uni-ext-api'];
|
|
100
|
+
}
|
|
101
|
+
if (exports) {
|
|
102
|
+
return parseInjects(vite, platform, language, `@/uni_modules/${pluginId}`, pluginDir, exports);
|
|
103
|
+
}
|
|
104
|
+
}
|
|
105
|
+
exports.parseUniExtApi = parseUniExtApi;
|
|
83
106
|
/**
|
|
84
107
|
* uni:'getBatteryInfo'
|
|
85
108
|
* import getBatteryInfo from '..'
|
|
@@ -122,13 +145,15 @@ function parseInjects(vite = true, platform, language, source, uniModuleRootDir,
|
|
|
122
145
|
if (platform === 'app') {
|
|
123
146
|
hasPlatformFile =
|
|
124
147
|
fs_extra_1.default.existsSync(path_1.default.resolve(uniModuleRootDir, 'utssdk', 'app-android')) ||
|
|
125
|
-
fs_extra_1.default.existsSync(path_1.default.resolve(uniModuleRootDir, 'utssdk', 'app-ios'))
|
|
148
|
+
fs_extra_1.default.existsSync(path_1.default.resolve(uniModuleRootDir, 'utssdk', 'app-ios')) ||
|
|
149
|
+
fs_extra_1.default.existsSync(path_1.default.resolve(uniModuleRootDir, 'utssdk', 'app-harmony'));
|
|
126
150
|
}
|
|
127
151
|
}
|
|
128
152
|
// 其他平台修改source,直接指向目标文件,否则 uts2js 找不到类型信息
|
|
129
153
|
if (platform !== 'app' &&
|
|
130
154
|
platform !== 'app-android' &&
|
|
131
|
-
platform !== 'app-ios'
|
|
155
|
+
platform !== 'app-ios' &&
|
|
156
|
+
platform !== 'app-harmony') {
|
|
132
157
|
if (fs_extra_1.default.existsSync(platformIndexFileName)) {
|
|
133
158
|
source = `${source}/utssdk/${platform}/index.uts`;
|
|
134
159
|
}
|
|
@@ -176,7 +201,9 @@ function parseInject(vite = true, platform, language, source, globalObject, defi
|
|
|
176
201
|
}
|
|
177
202
|
else {
|
|
178
203
|
const defineOptions = define[d];
|
|
179
|
-
const p = platform === 'app-android' ||
|
|
204
|
+
const p = platform === 'app-android' ||
|
|
205
|
+
platform === 'app-ios' ||
|
|
206
|
+
platform === 'app-harmony'
|
|
180
207
|
? 'app'
|
|
181
208
|
: platform;
|
|
182
209
|
if (!(p in defineOptions)) {
|
|
@@ -193,20 +220,9 @@ function parseInject(vite = true, platform, language, source, globalObject, defi
|
|
|
193
220
|
const skipCheck = process.env.UNI_APP_X_UVUE_SCRIPT_ENGINE === 'js' &&
|
|
194
221
|
source.includes('app-js');
|
|
195
222
|
if (!skipCheck) {
|
|
196
|
-
|
|
197
|
-
|
|
198
|
-
|
|
199
|
-
}
|
|
200
|
-
}
|
|
201
|
-
else if (language === 'kotlin') {
|
|
202
|
-
if (appOptions.kotlin === false) {
|
|
203
|
-
return;
|
|
204
|
-
}
|
|
205
|
-
}
|
|
206
|
-
else if (language === 'swift') {
|
|
207
|
-
if (appOptions.swift === false) {
|
|
208
|
-
return;
|
|
209
|
-
}
|
|
223
|
+
const targetLanguage = language === 'javascript' ? 'js' : language;
|
|
224
|
+
if (targetLanguage && appOptions[targetLanguage] === false) {
|
|
225
|
+
return;
|
|
210
226
|
}
|
|
211
227
|
}
|
|
212
228
|
}
|
|
@@ -265,3 +281,321 @@ function parseUTSModuleDeps(deps, inputDir) {
|
|
|
265
281
|
});
|
|
266
282
|
}
|
|
267
283
|
exports.parseUTSModuleDeps = parseUTSModuleDeps;
|
|
284
|
+
function genEncryptEasyComModuleIndex(platform, components) {
|
|
285
|
+
const imports = [];
|
|
286
|
+
const ids = [];
|
|
287
|
+
Object.keys(components).forEach((component) => {
|
|
288
|
+
const id = (0, exports.capitalize)((0, exports.camelize)(component));
|
|
289
|
+
ids.push(id);
|
|
290
|
+
if (platform === 'app-android') {
|
|
291
|
+
// 类型
|
|
292
|
+
ids.push((0, easycom_1.genUTSComponentPublicInstanceIdent)(component));
|
|
293
|
+
}
|
|
294
|
+
imports.push(`import ${id} from './components/${component}/${component}${components[component]}'`);
|
|
295
|
+
});
|
|
296
|
+
return `
|
|
297
|
+
${imports.join('\n')}
|
|
298
|
+
export {
|
|
299
|
+
${ids.join(',\n ')}
|
|
300
|
+
}
|
|
301
|
+
`;
|
|
302
|
+
}
|
|
303
|
+
exports.genEncryptEasyComModuleIndex = genEncryptEasyComModuleIndex;
|
|
304
|
+
// 目前该函数仅在云端使用(目前仅限iOS/web),云端编译时,提交上来的uni_modules是过滤好的
|
|
305
|
+
function parseUniModulesWithComponents(inputDir) {
|
|
306
|
+
const modulesDir = path_1.default.resolve(inputDir, 'uni_modules');
|
|
307
|
+
const uniModules = {};
|
|
308
|
+
if (fs_extra_1.default.existsSync(modulesDir)) {
|
|
309
|
+
fs_extra_1.default.readdirSync(modulesDir).forEach((uniModuleDir) => {
|
|
310
|
+
if (!fs_extra_1.default.existsSync(path_1.default.resolve(modulesDir, uniModuleDir, 'package.json'))) {
|
|
311
|
+
return;
|
|
312
|
+
}
|
|
313
|
+
// 解析加密的 easyCom 插件列表
|
|
314
|
+
const components = parseEasyComComponents(uniModuleDir, inputDir, false);
|
|
315
|
+
uniModules[uniModuleDir] = components;
|
|
316
|
+
});
|
|
317
|
+
}
|
|
318
|
+
return uniModules;
|
|
319
|
+
}
|
|
320
|
+
exports.parseUniModulesWithComponents = parseUniModulesWithComponents;
|
|
321
|
+
/**
|
|
322
|
+
* 解析 easyCom 组件列表
|
|
323
|
+
* @param pluginId
|
|
324
|
+
* @param inputDir
|
|
325
|
+
* @returns
|
|
326
|
+
*/
|
|
327
|
+
function parseEasyComComponents(pluginId, inputDir, detectBinary = true) {
|
|
328
|
+
const componentsDir = path_1.default.resolve(inputDir, 'uni_modules', pluginId, 'components');
|
|
329
|
+
const components = {};
|
|
330
|
+
if (fs_extra_1.default.existsSync(componentsDir)) {
|
|
331
|
+
fs_extra_1.default.readdirSync(componentsDir).forEach((componentDir) => {
|
|
332
|
+
const componentFile = path_1.default.resolve(componentsDir, componentDir, componentDir);
|
|
333
|
+
const extname = ['.vue', '.uvue'].find((extname) => {
|
|
334
|
+
const filename = componentFile + extname;
|
|
335
|
+
// 探测 filename 是否是二进制文件
|
|
336
|
+
if (fs_extra_1.default.existsSync(filename)) {
|
|
337
|
+
if (detectBinary) {
|
|
338
|
+
// 延迟require,这个是新增的依赖,无法及时同步到内部测试版本HBuilderX中,导致报错,所以延迟require吧
|
|
339
|
+
if (require('isbinaryfile').isBinaryFileSync(filename)) {
|
|
340
|
+
return true;
|
|
341
|
+
}
|
|
342
|
+
}
|
|
343
|
+
else {
|
|
344
|
+
return true;
|
|
345
|
+
}
|
|
346
|
+
}
|
|
347
|
+
});
|
|
348
|
+
if (extname) {
|
|
349
|
+
components[componentDir] = extname;
|
|
350
|
+
}
|
|
351
|
+
});
|
|
352
|
+
}
|
|
353
|
+
return components;
|
|
354
|
+
}
|
|
355
|
+
exports.parseEasyComComponents = parseEasyComComponents;
|
|
356
|
+
// 查找所有普通加密插件 uni_modules
|
|
357
|
+
function findEncryptUniModules(inputDir, cacheDir = '') {
|
|
358
|
+
const modulesDir = path_1.default.resolve(inputDir, 'uni_modules');
|
|
359
|
+
const uniModules = {};
|
|
360
|
+
if (fs_extra_1.default.existsSync(modulesDir)) {
|
|
361
|
+
fs_extra_1.default.readdirSync(modulesDir).forEach((uniModuleDir) => {
|
|
362
|
+
const uniModuleRootDir = path_1.default.resolve(modulesDir, uniModuleDir);
|
|
363
|
+
if (!fs_extra_1.default.existsSync(path_1.default.resolve(uniModuleRootDir, 'encrypt'))) {
|
|
364
|
+
return;
|
|
365
|
+
}
|
|
366
|
+
// 仅扫描普通加密插件,无需依赖
|
|
367
|
+
if (fs_extra_1.default.existsSync(path_1.default.resolve(uniModuleRootDir, 'utssdk'))) {
|
|
368
|
+
return;
|
|
369
|
+
}
|
|
370
|
+
const pkg = require(path_1.default.resolve(uniModuleRootDir, 'package.json'));
|
|
371
|
+
uniModules[uniModuleDir] = findEncryptUniModuleCache(uniModuleDir, cacheDir, { version: pkg.version, env: initCheckEnv() });
|
|
372
|
+
});
|
|
373
|
+
}
|
|
374
|
+
return uniModules;
|
|
375
|
+
}
|
|
376
|
+
exports.findEncryptUniModules = findEncryptUniModules;
|
|
377
|
+
function findUploadEncryptUniModulesFiles(uniModules, platform, inputDir) {
|
|
378
|
+
const modules = {};
|
|
379
|
+
Object.keys(uniModules).forEach((uniModuleId) => {
|
|
380
|
+
if (!uniModules[uniModuleId]) {
|
|
381
|
+
modules[uniModuleId] = findUniModuleFiles(platform, uniModuleId, inputDir);
|
|
382
|
+
}
|
|
383
|
+
});
|
|
384
|
+
return modules;
|
|
385
|
+
}
|
|
386
|
+
exports.findUploadEncryptUniModulesFiles = findUploadEncryptUniModulesFiles;
|
|
387
|
+
function packUploadEncryptUniModules(uniModules, platform, inputDir, cacheDir) {
|
|
388
|
+
const modules = findUploadEncryptUniModulesFiles(uniModules, platform, inputDir);
|
|
389
|
+
const uploadModuleIds = Object.keys(modules);
|
|
390
|
+
if (uploadModuleIds.length) {
|
|
391
|
+
// 延迟 require,避免 vue2 编译器需要安装此依赖,目前该方法仅在 vite 编译器中使用
|
|
392
|
+
const AdmZip = require('adm-zip');
|
|
393
|
+
const zip = new AdmZip();
|
|
394
|
+
uploadModuleIds.forEach((moduleId) => {
|
|
395
|
+
modules[moduleId].forEach((file) => {
|
|
396
|
+
zip.addLocalFile(file, path_1.default.dirname(path_1.default.relative(inputDir, file)));
|
|
397
|
+
});
|
|
398
|
+
});
|
|
399
|
+
const zipFile = path_1.default.resolve(cacheDir, 'cloud-compile-plugins.zip');
|
|
400
|
+
zip.writeZip(zipFile);
|
|
401
|
+
return {
|
|
402
|
+
zipFile,
|
|
403
|
+
modules: uploadModuleIds,
|
|
404
|
+
};
|
|
405
|
+
}
|
|
406
|
+
return {
|
|
407
|
+
zipFile: '',
|
|
408
|
+
modules: [],
|
|
409
|
+
};
|
|
410
|
+
}
|
|
411
|
+
exports.packUploadEncryptUniModules = packUploadEncryptUniModules;
|
|
412
|
+
function isEnvExpired(value, other) {
|
|
413
|
+
const valueKeys = Object.keys(value);
|
|
414
|
+
const otherKeys = Object.keys(other);
|
|
415
|
+
if (valueKeys.length !== otherKeys.length) {
|
|
416
|
+
return true;
|
|
417
|
+
}
|
|
418
|
+
if (valueKeys.find((name) => value[name] !== other[name])) {
|
|
419
|
+
return true;
|
|
420
|
+
}
|
|
421
|
+
return false;
|
|
422
|
+
}
|
|
423
|
+
function findEncryptUniModuleCache(uniModuleId, cacheDir, options) {
|
|
424
|
+
if (!cacheDir) {
|
|
425
|
+
return;
|
|
426
|
+
}
|
|
427
|
+
const uniModuleCacheDir = path_1.default.resolve(cacheDir, 'uni_modules', uniModuleId);
|
|
428
|
+
if (fs_extra_1.default.existsSync(uniModuleCacheDir)) {
|
|
429
|
+
const pkg = require(path_1.default.resolve(uniModuleCacheDir, 'package.json'));
|
|
430
|
+
// 插件版本以及各种环境一致
|
|
431
|
+
if (pkg.version === options.version &&
|
|
432
|
+
!isEnvExpired(pkg.uni_modules?.artifacts?.env || {}, options.env)) {
|
|
433
|
+
const declaration = path_1.default.resolve(uniModuleCacheDir, 'utssdk/app-android/index.d.uts');
|
|
434
|
+
pkg.uni_modules.artifacts.declaration = fs_extra_1.default.existsSync(declaration)
|
|
435
|
+
? declaration
|
|
436
|
+
: '';
|
|
437
|
+
return pkg;
|
|
438
|
+
}
|
|
439
|
+
console.log(`插件${uniModuleId} 缓存已过期,需要重新云编译。`);
|
|
440
|
+
// 已过期的插件,删除缓存
|
|
441
|
+
fs_extra_1.default.rmSync(uniModuleCacheDir, { recursive: true });
|
|
442
|
+
}
|
|
443
|
+
}
|
|
444
|
+
const KNOWN_ASSET_TYPES = [
|
|
445
|
+
// images
|
|
446
|
+
'png',
|
|
447
|
+
'jpe?g',
|
|
448
|
+
'gif',
|
|
449
|
+
'svg',
|
|
450
|
+
'ico',
|
|
451
|
+
'webp',
|
|
452
|
+
'avif',
|
|
453
|
+
// media
|
|
454
|
+
'mp4',
|
|
455
|
+
'webm',
|
|
456
|
+
'ogg',
|
|
457
|
+
'mp3',
|
|
458
|
+
'wav',
|
|
459
|
+
'flac',
|
|
460
|
+
'aac',
|
|
461
|
+
// fonts
|
|
462
|
+
'woff2?',
|
|
463
|
+
'eot',
|
|
464
|
+
'ttf',
|
|
465
|
+
'otf',
|
|
466
|
+
// other
|
|
467
|
+
'pdf',
|
|
468
|
+
'txt',
|
|
469
|
+
];
|
|
470
|
+
function findUniModuleFiles(platform, id, inputDir) {
|
|
471
|
+
return (0, fast_glob_1.sync)(`uni_modules/${id}/**/*`, {
|
|
472
|
+
cwd: inputDir,
|
|
473
|
+
absolute: true,
|
|
474
|
+
ignore: [
|
|
475
|
+
'**/*.md',
|
|
476
|
+
...(platform !== 'app-android' // 非 android 平台不需要扫描 assets
|
|
477
|
+
? [`**/*.{${KNOWN_ASSET_TYPES.join(',')}}`]
|
|
478
|
+
: []),
|
|
479
|
+
],
|
|
480
|
+
});
|
|
481
|
+
}
|
|
482
|
+
function initCheckEnv() {
|
|
483
|
+
return {
|
|
484
|
+
// 云端编译的版本号不带日期及小版本
|
|
485
|
+
compilerVersion: process.env.UNI_COMPILER_VERSION,
|
|
486
|
+
};
|
|
487
|
+
}
|
|
488
|
+
exports.initCheckEnv = initCheckEnv;
|
|
489
|
+
function findLastIndex(array, predicate) {
|
|
490
|
+
for (let i = array.length - 1; i >= 0; i--) {
|
|
491
|
+
if (predicate(array[i], i, array)) {
|
|
492
|
+
return i;
|
|
493
|
+
}
|
|
494
|
+
}
|
|
495
|
+
return -1;
|
|
496
|
+
}
|
|
497
|
+
let encryptUniModules = {};
|
|
498
|
+
function resolveEncryptUniModule(id, platform, isX = true) {
|
|
499
|
+
const parts = id.split('/');
|
|
500
|
+
const index = findLastIndex(parts, (part) => part === 'uni_modules');
|
|
501
|
+
if (index !== -1) {
|
|
502
|
+
const uniModuleId = parts[index + 1];
|
|
503
|
+
if (uniModuleId in encryptUniModules) {
|
|
504
|
+
if (parts[index + 2]) {
|
|
505
|
+
console.warn(messages_1.M['uni_modules.import']
|
|
506
|
+
.replace('{0}', uniModuleId)
|
|
507
|
+
.replace('{1}', uniModuleId)
|
|
508
|
+
.replace('{2}', parts.slice(index + 2).join('/')));
|
|
509
|
+
}
|
|
510
|
+
// 原生平台走旧的uts-proxy
|
|
511
|
+
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'}`));
|
|
512
|
+
}
|
|
513
|
+
}
|
|
514
|
+
}
|
|
515
|
+
exports.resolveEncryptUniModule = resolveEncryptUniModule;
|
|
516
|
+
async function checkEncryptUniModules(inputDir, params) {
|
|
517
|
+
// 扫描加密插件云编译
|
|
518
|
+
encryptUniModules = findEncryptUniModules(inputDir, process.env.UNI_MODULES_ENCRYPT_CACHE_DIR);
|
|
519
|
+
if (!Object.keys(encryptUniModules).length) {
|
|
520
|
+
return {};
|
|
521
|
+
}
|
|
522
|
+
if (!process.env.UNI_HBUILDERX_PLUGINS) {
|
|
523
|
+
return {};
|
|
524
|
+
}
|
|
525
|
+
const cacheDir = process.env.UNI_MODULES_ENCRYPT_CACHE_DIR;
|
|
526
|
+
const { zipFile, modules } = packUploadEncryptUniModules(encryptUniModules, process.env.UNI_UTS_PLATFORM, inputDir, cacheDir);
|
|
527
|
+
if (zipFile) {
|
|
528
|
+
const downloadFile = path_1.default.resolve(cacheDir, 'uni_modules.download.zip');
|
|
529
|
+
const { C, D, R, U } = (0, utils_1.requireUniHelpers)();
|
|
530
|
+
try {
|
|
531
|
+
const isLogin = await C();
|
|
532
|
+
const tips = process.env.UNI_UTS_PLATFORM !== 'app-android'
|
|
533
|
+
? '(此过程耗时较长)'
|
|
534
|
+
: '';
|
|
535
|
+
console.log(`正在云编译插件${isLogin ? '' : '(请先登录)'}${tips}:${modules.join(',')}...`);
|
|
536
|
+
let downloadUrl = '';
|
|
537
|
+
try {
|
|
538
|
+
downloadUrl = await U({
|
|
539
|
+
params,
|
|
540
|
+
attachment: zipFile,
|
|
541
|
+
});
|
|
542
|
+
}
|
|
543
|
+
catch (e) {
|
|
544
|
+
if (e.message && e.message === '{"error":"UserNotLogin"}') {
|
|
545
|
+
console.log('当前项目包含需要云编译的付费插件,需要您先登录HBuilderX账号。');
|
|
546
|
+
}
|
|
547
|
+
else {
|
|
548
|
+
console.error(e);
|
|
549
|
+
}
|
|
550
|
+
process.exit(0);
|
|
551
|
+
}
|
|
552
|
+
await D(downloadUrl, downloadFile);
|
|
553
|
+
// unzip
|
|
554
|
+
const AdmZip = require('adm-zip');
|
|
555
|
+
const zip = new AdmZip(downloadFile);
|
|
556
|
+
zip.extractAllTo(cacheDir, true);
|
|
557
|
+
fs_extra_1.default.unlinkSync(zipFile);
|
|
558
|
+
fs_extra_1.default.unlinkSync(downloadFile);
|
|
559
|
+
R({
|
|
560
|
+
dir: process.env.UNI_INPUT_DIR,
|
|
561
|
+
cacheDir: process.env.UNI_MODULES_ENCRYPT_CACHE_DIR,
|
|
562
|
+
});
|
|
563
|
+
console.log(`云编译已完成`);
|
|
564
|
+
console.log(`正在编译中...`);
|
|
565
|
+
}
|
|
566
|
+
catch (e) {
|
|
567
|
+
fs_extra_1.default.existsSync(zipFile) && fs_extra_1.default.unlinkSync(zipFile);
|
|
568
|
+
fs_extra_1.default.existsSync(downloadFile) && fs_extra_1.default.unlinkSync(downloadFile);
|
|
569
|
+
console.error(e);
|
|
570
|
+
process.exit(0);
|
|
571
|
+
}
|
|
572
|
+
}
|
|
573
|
+
else {
|
|
574
|
+
// android 平台需要在这里初始化
|
|
575
|
+
if (params.platform === 'app-android') {
|
|
576
|
+
const { R } = (0, utils_1.requireUniHelpers)();
|
|
577
|
+
R({
|
|
578
|
+
dir: process.env.UNI_INPUT_DIR,
|
|
579
|
+
cacheDir: process.env.UNI_MODULES_ENCRYPT_CACHE_DIR,
|
|
580
|
+
});
|
|
581
|
+
}
|
|
582
|
+
}
|
|
583
|
+
encryptUniModules = findEncryptUniModules(inputDir, process.env.UNI_MODULES_ENCRYPT_CACHE_DIR);
|
|
584
|
+
}
|
|
585
|
+
exports.checkEncryptUniModules = checkEncryptUniModules;
|
|
586
|
+
function parseUniModulesArtifacts() {
|
|
587
|
+
const res = [];
|
|
588
|
+
Object.keys(encryptUniModules).forEach((uniModuleId) => {
|
|
589
|
+
const pkg = encryptUniModules[uniModuleId];
|
|
590
|
+
if (pkg?.uni_modules?.artifacts) {
|
|
591
|
+
res.push({
|
|
592
|
+
name: uniModuleId,
|
|
593
|
+
package: `uts.sdk.modules.${(0, exports.camelize)(uniModuleId)}`,
|
|
594
|
+
scopedSlots: pkg.uni_modules.artifacts.scopedSlots || [],
|
|
595
|
+
declaration: pkg.uni_modules.artifacts.declaration,
|
|
596
|
+
});
|
|
597
|
+
}
|
|
598
|
+
});
|
|
599
|
+
return res;
|
|
600
|
+
}
|
|
601
|
+
exports.parseUniModulesArtifacts = parseUniModulesArtifacts;
|
package/dist/utils.d.ts
CHANGED
|
@@ -5,7 +5,12 @@ export { camelize, capitalize, isArray } from '@vue/shared';
|
|
|
5
5
|
export declare const isWindows: boolean;
|
|
6
6
|
export declare function normalizePath(id: string): string;
|
|
7
7
|
export declare function checkElementNodeTag(node: RootNode | TemplateChildNode | null | undefined, tag: string): node is ElementNode;
|
|
8
|
-
|
|
8
|
+
/**
|
|
9
|
+
* 根据 path 返回合法 js 变量
|
|
10
|
+
* @param str pages.json.page.path
|
|
11
|
+
* @returns
|
|
12
|
+
*/
|
|
13
|
+
export declare function normalizeIdentifier(str: string): string;
|
|
9
14
|
export declare function normalizePagePath(pagePath: string, platform: UniApp.PLATFORM): string | undefined;
|
|
10
15
|
export declare function removeExt(str: string): string;
|
|
11
16
|
export declare function normalizeNodeModules(str: string): string;
|
|
@@ -17,7 +22,15 @@ export declare function pathToGlob(pathString: string, glob: string, options?: {
|
|
|
17
22
|
}): string;
|
|
18
23
|
export declare function resolveSourceMapPath(outputDir?: string, platform?: UniApp.PLATFORM): string;
|
|
19
24
|
export declare function installDepTips(type: 'dependencies' | 'devDependencies', module: string, version?: string): string;
|
|
25
|
+
/**
|
|
26
|
+
* 根据路径判断是否为 App.(u?)vue
|
|
27
|
+
* @param {string} filename 相对、绝对路径
|
|
28
|
+
* @returns
|
|
29
|
+
*/
|
|
20
30
|
export declare function isAppVue(filename: string): boolean;
|
|
21
31
|
export declare function resolveAppVue(inputDir: string): string;
|
|
22
32
|
export declare function parseImporter(importer: string): string;
|
|
23
33
|
export declare function createResolveErrorMsg(source: string, importer: string): string;
|
|
34
|
+
export declare function enableSourceMap(): boolean;
|
|
35
|
+
export declare function requireUniHelpers(): any;
|
|
36
|
+
export declare function normalizeEmitAssetFileName(fileName: string): string;
|
package/dist/utils.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.createResolveErrorMsg = exports.parseImporter = exports.resolveAppVue = exports.isAppVue = exports.installDepTips = exports.resolveSourceMapPath = exports.pathToGlob = exports.normalizeParsePlugins = exports.normalizeMiniProgramFilename = exports.normalizeNodeModules = exports.removeExt = exports.normalizePagePath = exports.normalizeIdentifier = exports.checkElementNodeTag = exports.normalizePath = exports.isWindows = exports.isArray = exports.capitalize = exports.camelize = exports.hash = void 0;
|
|
6
|
+
exports.normalizeEmitAssetFileName = exports.requireUniHelpers = exports.enableSourceMap = exports.createResolveErrorMsg = exports.parseImporter = exports.resolveAppVue = exports.isAppVue = exports.installDepTips = exports.resolveSourceMapPath = exports.pathToGlob = exports.normalizeParsePlugins = exports.normalizeMiniProgramFilename = exports.normalizeNodeModules = exports.removeExt = exports.normalizePagePath = exports.normalizeIdentifier = exports.checkElementNodeTag = exports.normalizePath = exports.isWindows = exports.isArray = exports.capitalize = exports.camelize = exports.hash = void 0;
|
|
7
7
|
const fs_1 = __importDefault(require("fs"));
|
|
8
8
|
const os_1 = __importDefault(require("os"));
|
|
9
9
|
const path_1 = __importDefault(require("path"));
|
|
@@ -33,8 +33,19 @@ function checkElementNodeTag(node, tag) {
|
|
|
33
33
|
return !!node && node.type === compiler_core_1.NodeTypes.ELEMENT && node.tag === tag;
|
|
34
34
|
}
|
|
35
35
|
exports.checkElementNodeTag = checkElementNodeTag;
|
|
36
|
+
/**
|
|
37
|
+
* 根据 path 返回合法 js 变量
|
|
38
|
+
* @param str pages.json.page.path
|
|
39
|
+
* @returns
|
|
40
|
+
*/
|
|
36
41
|
function normalizeIdentifier(str) {
|
|
37
|
-
|
|
42
|
+
let _str = str.replace(/[^a-zA-Z0-9]+/g, '-');
|
|
43
|
+
_str = (0, shared_1.capitalize)((0, shared_1.camelize)(_str));
|
|
44
|
+
// 不允许数字开头,补充 _
|
|
45
|
+
if (/^\d/.test(_str)) {
|
|
46
|
+
_str = '_' + _str;
|
|
47
|
+
}
|
|
48
|
+
return _str;
|
|
38
49
|
}
|
|
39
50
|
exports.normalizeIdentifier = normalizeIdentifier;
|
|
40
51
|
function normalizePagePath(pagePath, platform) {
|
|
@@ -124,8 +135,14 @@ function installDepTips(type, module, version) {
|
|
|
124
135
|
Please run \`${picocolors_1.default.cyan(`${getInstallCommand(process.cwd())} ${module + (version ? '@' + version : '')}${type === 'devDependencies' ? ' -D' : ''}`)}\` and try again.`;
|
|
125
136
|
}
|
|
126
137
|
exports.installDepTips = installDepTips;
|
|
138
|
+
/**
|
|
139
|
+
* 根据路径判断是否为 App.(u?)vue
|
|
140
|
+
* @param {string} filename 相对、绝对路径
|
|
141
|
+
* @returns
|
|
142
|
+
*/
|
|
127
143
|
function isAppVue(filename) {
|
|
128
|
-
|
|
144
|
+
const _filePath = normalizePath(filename);
|
|
145
|
+
return /(\/|\\)app\.(u?)vue$/.test(_filePath.toLowerCase());
|
|
129
146
|
}
|
|
130
147
|
exports.isAppVue = isAppVue;
|
|
131
148
|
function resolveAppVue(inputDir) {
|
|
@@ -148,3 +165,22 @@ function createResolveErrorMsg(source, importer) {
|
|
|
148
165
|
return `Could not resolve "${source}" from "${parseImporter(importer)}"`;
|
|
149
166
|
}
|
|
150
167
|
exports.createResolveErrorMsg = createResolveErrorMsg;
|
|
168
|
+
function enableSourceMap() {
|
|
169
|
+
return (process.env.NODE_ENV === 'development' &&
|
|
170
|
+
process.env.UNI_COMPILE_TARGET !== 'uni_modules');
|
|
171
|
+
}
|
|
172
|
+
exports.enableSourceMap = enableSourceMap;
|
|
173
|
+
function requireUniHelpers() {
|
|
174
|
+
require(path_1.default.resolve(process.env.UNI_HBUILDERX_PLUGINS, 'uni_helpers/lib/bytenode'));
|
|
175
|
+
return require(path_1.default.join(process.env.UNI_HBUILDERX_PLUGINS, 'uni_helpers'));
|
|
176
|
+
}
|
|
177
|
+
exports.requireUniHelpers = requireUniHelpers;
|
|
178
|
+
function normalizeEmitAssetFileName(fileName) {
|
|
179
|
+
if (process.env.UNI_APP_X_TSC === 'true') {
|
|
180
|
+
if (path_1.default.extname(fileName) !== '.ts') {
|
|
181
|
+
return fileName + '.ts';
|
|
182
|
+
}
|
|
183
|
+
}
|
|
184
|
+
return fileName;
|
|
185
|
+
}
|
|
186
|
+
exports.normalizeEmitAssetFileName = normalizeEmitAssetFileName;
|
package/dist/uts.d.ts
CHANGED
|
@@ -8,7 +8,7 @@ import type { EasycomMatcher } from './easycom';
|
|
|
8
8
|
* @param importer
|
|
9
9
|
* @returns
|
|
10
10
|
*/
|
|
11
|
-
export declare function resolveUTSAppModule(id: string, importer: string, includeUTSSDK?: boolean): string | undefined;
|
|
11
|
+
export declare function resolveUTSAppModule(platform: typeof process.env.UNI_UTS_PLATFORM, id: string, importer: string, includeUTSSDK?: boolean): string | undefined;
|
|
12
12
|
export declare function resolveUTSModule(id: string, importer: string, includeUTSSDK?: boolean): string | undefined;
|
|
13
13
|
export declare function resolveUTSCompiler(): typeof UTSCompiler;
|
|
14
14
|
export declare function isUTSComponent(name: string): boolean;
|