@dcloudio/uni-cli-shared 3.0.0-alpha-4010620240509002 → 3.0.0-alpha-4010720240511002
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 +6 -1
- package/dist/hbx/log.js +9 -0
- package/dist/json/app/manifest/nvue.d.ts +1 -1
- package/dist/json/manifest.js +6 -0
- package/dist/json/pages.js +10 -1
- package/dist/resolve.js +6 -1
- package/dist/uni_modules.d.ts +35 -0
- package/dist/uni_modules.js +241 -1
- package/dist/utils.d.ts +7 -1
- package/dist/utils.js +18 -2
- package/dist/utils.spec.d.ts +1 -0
- package/dist/utils.spec.js +17 -0
- package/dist/vite/autoImport.js +9 -1
- package/dist/vite/cloud.d.ts +5 -0
- package/dist/vite/cloud.js +240 -0
- package/dist/vite/index.d.ts +1 -0
- package/dist/vite/index.js +1 -0
- package/dist/vite/plugins/easycom.js +3 -1
- package/dist/vite/plugins/uts/uni_modules.js +36 -7
- package/dist/vite/plugins/vitejs/plugins/css.d.ts +6 -1
- package/dist/vite/plugins/vitejs/plugins/css.js +26 -25
- 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/package.json +7 -4
package/dist/easycom.js
CHANGED
|
@@ -173,6 +173,9 @@ function initAutoScanEasycom(dir, rootDir, extensions) {
|
|
|
173
173
|
if (!fs_1.default.existsSync(dir)) {
|
|
174
174
|
return easycoms;
|
|
175
175
|
}
|
|
176
|
+
const is_uni_modules = path_1.default.basename(path_1.default.resolve(dir, '../..')) === 'uni_modules';
|
|
177
|
+
const is_encrypt_uni_modules = is_uni_modules && fs_1.default.existsSync(path_1.default.resolve(dir, '../encrypt'));
|
|
178
|
+
const uni_modules_plugin_id = is_encrypt_uni_modules && path_1.default.basename(path_1.default.resolve(dir, '..'));
|
|
176
179
|
fs_1.default.readdirSync(dir).forEach((name) => {
|
|
177
180
|
const folder = path_1.default.resolve(dir, name);
|
|
178
181
|
if (!isDir(folder)) {
|
|
@@ -184,7 +187,9 @@ function initAutoScanEasycom(dir, rootDir, extensions) {
|
|
|
184
187
|
for (let i = 0; i < extensions.length; i++) {
|
|
185
188
|
const ext = extensions[i];
|
|
186
189
|
if (files.includes(name + ext)) {
|
|
187
|
-
easycoms[`^${name}$`] =
|
|
190
|
+
easycoms[`^${name}$`] = is_encrypt_uni_modules
|
|
191
|
+
? (0, utils_1.normalizePath)(path_1.default.join(rootDir, `uni_modules/${uni_modules_plugin_id}?uni_helpers`))
|
|
192
|
+
: `${importDir}/${name}${ext}`;
|
|
188
193
|
break;
|
|
189
194
|
}
|
|
190
195
|
}
|
package/dist/hbx/log.js
CHANGED
|
@@ -110,7 +110,16 @@ exports.errorFormatter = {
|
|
|
110
110
|
};
|
|
111
111
|
function buildErrorMessage(err, args = [], includeStack = true) {
|
|
112
112
|
if (err.plugin) {
|
|
113
|
+
const otherMsgs = [];
|
|
114
|
+
if (err.message.includes(': [plugin ')) {
|
|
115
|
+
const messages = err.message.split(': [plugin ');
|
|
116
|
+
err.message = messages[0];
|
|
117
|
+
messages.slice(1).forEach((msg) => {
|
|
118
|
+
otherMsgs.push(`[plugin:${msg}`);
|
|
119
|
+
});
|
|
120
|
+
}
|
|
113
121
|
args.push(`${picocolors_1.default.magenta('[plugin:' + err.plugin + ']')} ${picocolors_1.default.red(err.message)}`);
|
|
122
|
+
args.push(...otherMsgs);
|
|
114
123
|
if (err.loc &&
|
|
115
124
|
err.hook === 'transform' &&
|
|
116
125
|
err.plugin === 'rollup-plugin-dynamic-import-variables' &&
|
|
@@ -1,4 +1,4 @@
|
|
|
1
1
|
export declare function initNVue(manifestJson: Record<string, any>, pagesJson: UniApp.PagesJson): void;
|
|
2
|
-
export declare function getNVueCompiler(manifestJson: Record<string, any>): "uni-app" | "
|
|
2
|
+
export declare function getNVueCompiler(manifestJson: Record<string, any>): "uni-app" | "weex" | "vue" | "vite";
|
|
3
3
|
export declare function getNVueStyleCompiler(manifestJson: Record<string, any>): "uni-app" | "weex";
|
|
4
4
|
export declare function getNVueFlexDirection(manifestJson: Record<string, any>): "column" | "row" | "row-reverse" | "column-reverse";
|
package/dist/json/manifest.js
CHANGED
|
@@ -10,6 +10,12 @@ const shared_1 = require("@vue/shared");
|
|
|
10
10
|
const uni_shared_1 = require("@dcloudio/uni-shared");
|
|
11
11
|
const json_1 = require("./json");
|
|
12
12
|
const parseManifestJson = (inputDir) => {
|
|
13
|
+
const manifestFilename = path_1.default.join(inputDir, 'manifest.json');
|
|
14
|
+
if (!fs_1.default.existsSync(manifestFilename)) {
|
|
15
|
+
if (process.env.UNI_COMPILE_TARGET === 'uni_modules') {
|
|
16
|
+
return {};
|
|
17
|
+
}
|
|
18
|
+
}
|
|
13
19
|
return (0, json_1.parseJson)(fs_1.default.readFileSync(path_1.default.join(inputDir, 'manifest.json'), 'utf8'));
|
|
14
20
|
};
|
|
15
21
|
exports.parseManifestJson = parseManifestJson;
|
package/dist/json/pages.js
CHANGED
|
@@ -43,7 +43,16 @@ exports.isUniPageSfcFile = isUniPageSfcFile;
|
|
|
43
43
|
* @returns
|
|
44
44
|
*/
|
|
45
45
|
const parsePagesJson = (inputDir, platform, normalize = true) => {
|
|
46
|
-
const
|
|
46
|
+
const pagesFilename = path_1.default.join(inputDir, 'pages.json');
|
|
47
|
+
if (!fs_1.default.existsSync(pagesFilename)) {
|
|
48
|
+
if (process.env.UNI_COMPILE_TARGET === 'uni_modules') {
|
|
49
|
+
return {
|
|
50
|
+
pages: [],
|
|
51
|
+
globalStyle: { navigationBar: {} },
|
|
52
|
+
};
|
|
53
|
+
}
|
|
54
|
+
}
|
|
55
|
+
const jsonStr = fs_1.default.readFileSync(pagesFilename, 'utf8');
|
|
47
56
|
if (normalize) {
|
|
48
57
|
return normalizePagesJson(jsonStr, platform);
|
|
49
58
|
}
|
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
|
@@ -70,3 +70,38 @@ export declare const capitalize: (str: string) => string;
|
|
|
70
70
|
* @returns
|
|
71
71
|
*/
|
|
72
72
|
export declare function parseUTSModuleDeps(deps: string[], inputDir: string): string[];
|
|
73
|
+
export declare function genEncryptEasyComModuleIndex(components: string[]): string;
|
|
74
|
+
export declare function parseUniModulesWithComponents(inputDir: string): Record<string, string[]>;
|
|
75
|
+
/**
|
|
76
|
+
* 解析 easyCom 组件列表
|
|
77
|
+
* @param pluginId
|
|
78
|
+
* @param inputDir
|
|
79
|
+
* @returns
|
|
80
|
+
*/
|
|
81
|
+
export declare function parseEasyComComponents(pluginId: string, inputDir: string, detectBinary?: boolean): string[];
|
|
82
|
+
export declare function findEncryptUniModules(inputDir: string, cacheDir?: string): Record<string, EncryptPackageJson | undefined>;
|
|
83
|
+
export declare function findUploadEncryptUniModulesFiles(uniModules: Record<string, EncryptPackageJson | undefined>, platform: typeof process.env.UNI_UTS_PLATFORM, inputDir: string): string[];
|
|
84
|
+
interface EncryptPackageJson {
|
|
85
|
+
id: string;
|
|
86
|
+
version: string;
|
|
87
|
+
uni_modules: {
|
|
88
|
+
artifacts: {
|
|
89
|
+
env: {
|
|
90
|
+
compilerVersion: string;
|
|
91
|
+
} & Record<string, any>;
|
|
92
|
+
apis: string[];
|
|
93
|
+
components: string[];
|
|
94
|
+
};
|
|
95
|
+
};
|
|
96
|
+
}
|
|
97
|
+
export declare function initCheckEnv(): Record<string, string>;
|
|
98
|
+
export declare function resolveEncryptUniModule(id: string, platform: typeof process.env.UNI_UTS_PLATFORM, isX?: boolean): string | undefined;
|
|
99
|
+
export declare function checkEncryptUniModules(inputDir: string, params: {
|
|
100
|
+
mode: 'development' | 'production';
|
|
101
|
+
compilerVersion: string;
|
|
102
|
+
appid: string;
|
|
103
|
+
appname: string;
|
|
104
|
+
platform: typeof process.env.UNI_UTS_PLATFORM;
|
|
105
|
+
'uni-app-x': boolean;
|
|
106
|
+
}): Promise<{} | undefined>;
|
|
107
|
+
export {};
|
package/dist/uni_modules.js
CHANGED
|
@@ -3,10 +3,11 @@ 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.checkEncryptUniModules = exports.resolveEncryptUniModule = exports.initCheckEnv = exports.findUploadEncryptUniModulesFiles = exports.findEncryptUniModules = exports.parseEasyComComponents = exports.parseUniModulesWithComponents = exports.genEncryptEasyComModuleIndex = exports.parseUTSModuleDeps = exports.capitalize = exports.camelize = exports.parseInjects = exports.parseUniExtApis = exports.getUniExtApiProviderRegisters = 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");
|
|
10
11
|
const extApiProviders = [];
|
|
11
12
|
const extApiPlugins = new Set();
|
|
12
13
|
function getUniExtApiProviders() {
|
|
@@ -265,3 +266,242 @@ function parseUTSModuleDeps(deps, inputDir) {
|
|
|
265
266
|
});
|
|
266
267
|
}
|
|
267
268
|
exports.parseUTSModuleDeps = parseUTSModuleDeps;
|
|
269
|
+
function genEncryptEasyComModuleIndex(components) {
|
|
270
|
+
const imports = [];
|
|
271
|
+
const ids = [];
|
|
272
|
+
components.forEach((component) => {
|
|
273
|
+
const id = (0, exports.capitalize)((0, exports.camelize)(component));
|
|
274
|
+
imports.push(`import ${id} from './components/${component}/${component}.vue'`);
|
|
275
|
+
ids.push(id);
|
|
276
|
+
});
|
|
277
|
+
return `
|
|
278
|
+
${imports.join('\n')}
|
|
279
|
+
export { ${ids.join(',')} }
|
|
280
|
+
`;
|
|
281
|
+
}
|
|
282
|
+
exports.genEncryptEasyComModuleIndex = genEncryptEasyComModuleIndex;
|
|
283
|
+
// 目前该函数仅在云端使用(目前仅限iOS/web),云端编译时,提交上来的uni_modules是过滤好的
|
|
284
|
+
function parseUniModulesWithComponents(inputDir) {
|
|
285
|
+
const modulesDir = path_1.default.resolve(inputDir, 'uni_modules');
|
|
286
|
+
const uniModules = {};
|
|
287
|
+
if (fs_extra_1.default.existsSync(modulesDir)) {
|
|
288
|
+
fs_extra_1.default.readdirSync(modulesDir).forEach((uniModuleDir) => {
|
|
289
|
+
if (!fs_extra_1.default.existsSync(path_1.default.resolve(modulesDir, uniModuleDir, 'package.json'))) {
|
|
290
|
+
return;
|
|
291
|
+
}
|
|
292
|
+
// 解析加密的 easyCom 插件列表
|
|
293
|
+
const components = parseEasyComComponents(uniModuleDir, inputDir, false);
|
|
294
|
+
uniModules[uniModuleDir] = components;
|
|
295
|
+
});
|
|
296
|
+
}
|
|
297
|
+
return uniModules;
|
|
298
|
+
}
|
|
299
|
+
exports.parseUniModulesWithComponents = parseUniModulesWithComponents;
|
|
300
|
+
/**
|
|
301
|
+
* 解析 easyCom 组件列表
|
|
302
|
+
* @param pluginId
|
|
303
|
+
* @param inputDir
|
|
304
|
+
* @returns
|
|
305
|
+
*/
|
|
306
|
+
function parseEasyComComponents(pluginId, inputDir, detectBinary = true) {
|
|
307
|
+
const componentsDir = path_1.default.resolve(inputDir, 'uni_modules', pluginId, 'components');
|
|
308
|
+
const components = [];
|
|
309
|
+
if (fs_extra_1.default.existsSync(componentsDir)) {
|
|
310
|
+
fs_extra_1.default.readdirSync(componentsDir).forEach((componentDir) => {
|
|
311
|
+
const componentFile = path_1.default.resolve(componentsDir, componentDir, componentDir);
|
|
312
|
+
if (['.vue', '.uvue'].some((extname) => {
|
|
313
|
+
const filename = componentFile + extname;
|
|
314
|
+
// 探测 filename 是否是二进制文件
|
|
315
|
+
if (fs_extra_1.default.existsSync(filename)) {
|
|
316
|
+
if (detectBinary) {
|
|
317
|
+
// 延迟require,这个是新增的依赖,无法及时同步到内部测试版本HBuilderX中,导致报错,所以延迟require吧
|
|
318
|
+
if (require('isbinaryfile').isBinaryFileSync(filename)) {
|
|
319
|
+
return true;
|
|
320
|
+
}
|
|
321
|
+
}
|
|
322
|
+
else {
|
|
323
|
+
return true;
|
|
324
|
+
}
|
|
325
|
+
}
|
|
326
|
+
})) {
|
|
327
|
+
components.push(componentDir);
|
|
328
|
+
}
|
|
329
|
+
});
|
|
330
|
+
}
|
|
331
|
+
return components;
|
|
332
|
+
}
|
|
333
|
+
exports.parseEasyComComponents = parseEasyComComponents;
|
|
334
|
+
// 查找所有普通加密插件 uni_modules
|
|
335
|
+
function findEncryptUniModules(inputDir, cacheDir = '') {
|
|
336
|
+
const modulesDir = path_1.default.resolve(inputDir, 'uni_modules');
|
|
337
|
+
const uniModules = {};
|
|
338
|
+
if (fs_extra_1.default.existsSync(modulesDir)) {
|
|
339
|
+
fs_extra_1.default.readdirSync(modulesDir).forEach((uniModuleDir) => {
|
|
340
|
+
const uniModuleRootDir = path_1.default.resolve(modulesDir, uniModuleDir);
|
|
341
|
+
if (!fs_extra_1.default.existsSync(path_1.default.resolve(uniModuleRootDir, 'encrypt'))) {
|
|
342
|
+
return;
|
|
343
|
+
}
|
|
344
|
+
// 仅扫描普通加密插件,无需依赖
|
|
345
|
+
if (fs_extra_1.default.existsSync(path_1.default.resolve(uniModuleRootDir, 'utssdk'))) {
|
|
346
|
+
return;
|
|
347
|
+
}
|
|
348
|
+
const pkg = require(path_1.default.resolve(uniModuleRootDir, 'package.json'));
|
|
349
|
+
uniModules[uniModuleDir] = findEncryptUniModuleCache(uniModuleDir, cacheDir, { version: pkg.version, env: initCheckEnv() });
|
|
350
|
+
});
|
|
351
|
+
}
|
|
352
|
+
return uniModules;
|
|
353
|
+
}
|
|
354
|
+
exports.findEncryptUniModules = findEncryptUniModules;
|
|
355
|
+
function findUploadEncryptUniModulesFiles(uniModules, platform, inputDir) {
|
|
356
|
+
const files = [];
|
|
357
|
+
Object.keys(uniModules).forEach((uniModuleId) => {
|
|
358
|
+
if (!uniModules[uniModuleId]) {
|
|
359
|
+
files.push(...findUniModuleFiles(platform, uniModuleId, inputDir));
|
|
360
|
+
}
|
|
361
|
+
});
|
|
362
|
+
return files;
|
|
363
|
+
}
|
|
364
|
+
exports.findUploadEncryptUniModulesFiles = findUploadEncryptUniModulesFiles;
|
|
365
|
+
function packUploadEncryptUniModules(uniModules, platform, inputDir, cacheDir) {
|
|
366
|
+
const files = findUploadEncryptUniModulesFiles(uniModules, platform, inputDir);
|
|
367
|
+
if (files.length) {
|
|
368
|
+
// 延迟 require,避免 vue2 编译器需要安装此依赖,目前该方法仅在 vite 编译器中使用
|
|
369
|
+
const AdmZip = require('adm-zip');
|
|
370
|
+
const zip = new AdmZip();
|
|
371
|
+
files.forEach((file) => {
|
|
372
|
+
zip.addLocalFile(file);
|
|
373
|
+
});
|
|
374
|
+
const zipFile = path_1.default.resolve(cacheDir, 'uni_modules.upload.zip');
|
|
375
|
+
zip.writeZip(zipFile);
|
|
376
|
+
return zipFile;
|
|
377
|
+
}
|
|
378
|
+
}
|
|
379
|
+
function isEnvExpired(value, other) {
|
|
380
|
+
const valueKeys = Object.keys(value);
|
|
381
|
+
const otherKeys = Object.keys(other);
|
|
382
|
+
if (valueKeys.length !== otherKeys.length) {
|
|
383
|
+
return true;
|
|
384
|
+
}
|
|
385
|
+
if (valueKeys.find((name) => value[name] !== other[name])) {
|
|
386
|
+
return true;
|
|
387
|
+
}
|
|
388
|
+
return false;
|
|
389
|
+
}
|
|
390
|
+
function findEncryptUniModuleCache(uniModuleId, cacheDir, options) {
|
|
391
|
+
if (!cacheDir) {
|
|
392
|
+
return;
|
|
393
|
+
}
|
|
394
|
+
const uniModuleCacheDir = path_1.default.resolve(cacheDir, 'uni_modules', uniModuleId);
|
|
395
|
+
if (fs_extra_1.default.existsSync(uniModuleCacheDir)) {
|
|
396
|
+
const pkg = require(path_1.default.resolve(uniModuleCacheDir, 'package.json'));
|
|
397
|
+
// 插件版本以及各种环境一致
|
|
398
|
+
if (pkg.version === options.version &&
|
|
399
|
+
!isEnvExpired(pkg.env, options.env)) {
|
|
400
|
+
return pkg;
|
|
401
|
+
}
|
|
402
|
+
// 已过期的插件,删除缓存
|
|
403
|
+
fs_extra_1.default.rmSync(uniModuleCacheDir, { recursive: true });
|
|
404
|
+
}
|
|
405
|
+
}
|
|
406
|
+
const KNOWN_ASSET_TYPES = [
|
|
407
|
+
// images
|
|
408
|
+
'png',
|
|
409
|
+
'jpe?g',
|
|
410
|
+
'gif',
|
|
411
|
+
'svg',
|
|
412
|
+
'ico',
|
|
413
|
+
'webp',
|
|
414
|
+
'avif',
|
|
415
|
+
// media
|
|
416
|
+
'mp4',
|
|
417
|
+
'webm',
|
|
418
|
+
'ogg',
|
|
419
|
+
'mp3',
|
|
420
|
+
'wav',
|
|
421
|
+
'flac',
|
|
422
|
+
'aac',
|
|
423
|
+
// fonts
|
|
424
|
+
'woff2?',
|
|
425
|
+
'eot',
|
|
426
|
+
'ttf',
|
|
427
|
+
'otf',
|
|
428
|
+
// other
|
|
429
|
+
'pdf',
|
|
430
|
+
'txt',
|
|
431
|
+
];
|
|
432
|
+
function findUniModuleFiles(platform, id, inputDir) {
|
|
433
|
+
return (0, fast_glob_1.sync)(`uni_modules/${id}/**/*`, {
|
|
434
|
+
cwd: inputDir,
|
|
435
|
+
ignore: [
|
|
436
|
+
'**/*.md',
|
|
437
|
+
...(platform !== 'app-android' // 非 android 平台不需要扫描 assets
|
|
438
|
+
? [`**/*.{${KNOWN_ASSET_TYPES.join(',')}}`]
|
|
439
|
+
: []),
|
|
440
|
+
],
|
|
441
|
+
});
|
|
442
|
+
}
|
|
443
|
+
function initCheckEnv() {
|
|
444
|
+
return {
|
|
445
|
+
// 云端编译的版本号不带日期及小版本
|
|
446
|
+
compilerVersion: process.env.UNI_COMPILER_VERSION,
|
|
447
|
+
};
|
|
448
|
+
}
|
|
449
|
+
exports.initCheckEnv = initCheckEnv;
|
|
450
|
+
function findLastIndex(array, predicate) {
|
|
451
|
+
for (let i = array.length - 1; i >= 0; i--) {
|
|
452
|
+
if (predicate(array[i], i, array)) {
|
|
453
|
+
return i;
|
|
454
|
+
}
|
|
455
|
+
}
|
|
456
|
+
return -1;
|
|
457
|
+
}
|
|
458
|
+
let encryptUniModules = {};
|
|
459
|
+
function resolveEncryptUniModule(id, platform, isX = true) {
|
|
460
|
+
const parts = id.split('/');
|
|
461
|
+
const index = findLastIndex(parts, (part) => part === 'uni_modules');
|
|
462
|
+
if (index !== -1) {
|
|
463
|
+
const uniModuleId = parts[index + 1];
|
|
464
|
+
if (uniModuleId in encryptUniModules) {
|
|
465
|
+
// 原生平台走旧的uts-proxy
|
|
466
|
+
return `@/uni_modules/${uniModuleId}?${isX && platform === 'app-android' ? 'uts-proxy' : 'uni_helpers'}`;
|
|
467
|
+
}
|
|
468
|
+
}
|
|
469
|
+
}
|
|
470
|
+
exports.resolveEncryptUniModule = resolveEncryptUniModule;
|
|
471
|
+
async function checkEncryptUniModules(inputDir, params) {
|
|
472
|
+
// 扫描加密插件云编译
|
|
473
|
+
encryptUniModules = findEncryptUniModules(inputDir, process.env.UNI_MODULES_ENCRYPT_CACHE_DIR);
|
|
474
|
+
if (!Object.keys(encryptUniModules).length) {
|
|
475
|
+
return {};
|
|
476
|
+
}
|
|
477
|
+
if (!process.env.UNI_HBUILDERX_PLUGINS) {
|
|
478
|
+
return {};
|
|
479
|
+
}
|
|
480
|
+
const cacheDir = process.env.UNI_MODULES_ENCRYPT_CACHE_DIR;
|
|
481
|
+
const zipFile = packUploadEncryptUniModules(encryptUniModules, process.env.UNI_UTS_PLATFORM, inputDir, cacheDir);
|
|
482
|
+
if (zipFile) {
|
|
483
|
+
const downloadFile = path_1.default.resolve(cacheDir, 'uni_modules.download.zip');
|
|
484
|
+
const { U, D } = require(path_1.default.join(process.env.UNI_HBUILDERX_PLUGINS, 'uni_helpers'));
|
|
485
|
+
try {
|
|
486
|
+
console.log(await U({
|
|
487
|
+
...params,
|
|
488
|
+
}));
|
|
489
|
+
const downloadUrl = '';
|
|
490
|
+
await D(downloadUrl, downloadFile);
|
|
491
|
+
// unzip
|
|
492
|
+
const AdmZip = require('adm-zip');
|
|
493
|
+
const zip = new AdmZip(downloadFile);
|
|
494
|
+
zip.extractAllTo(cacheDir, true);
|
|
495
|
+
fs_extra_1.default.unlinkSync(zipFile);
|
|
496
|
+
fs_extra_1.default.unlinkSync(downloadFile);
|
|
497
|
+
}
|
|
498
|
+
catch (e) {
|
|
499
|
+
fs_extra_1.default.existsSync(zipFile) && fs_extra_1.default.unlinkSync(zipFile);
|
|
500
|
+
fs_extra_1.default.existsSync(downloadFile) && fs_extra_1.default.unlinkSync(downloadFile);
|
|
501
|
+
console.error(e);
|
|
502
|
+
process.exit(0);
|
|
503
|
+
}
|
|
504
|
+
}
|
|
505
|
+
encryptUniModules = findEncryptUniModules(inputDir, process.env.UNI_MODULES_ENCRYPT_CACHE_DIR);
|
|
506
|
+
}
|
|
507
|
+
exports.checkEncryptUniModules = checkEncryptUniModules;
|
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;
|
|
@@ -21,3 +26,4 @@ export declare function isAppVue(filename: string): boolean;
|
|
|
21
26
|
export declare function resolveAppVue(inputDir: string): string;
|
|
22
27
|
export declare function parseImporter(importer: string): string;
|
|
23
28
|
export declare function createResolveErrorMsg(source: string, importer: string): string;
|
|
29
|
+
export declare function enableSourceMap(): boolean;
|
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.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) {
|
|
@@ -148,3 +159,8 @@ function createResolveErrorMsg(source, importer) {
|
|
|
148
159
|
return `Could not resolve "${source}" from "${parseImporter(importer)}"`;
|
|
149
160
|
}
|
|
150
161
|
exports.createResolveErrorMsg = createResolveErrorMsg;
|
|
162
|
+
function enableSourceMap() {
|
|
163
|
+
return (process.env.NODE_ENV === 'development' &&
|
|
164
|
+
process.env.UNI_COMPILE_TARGET !== 'uni_modules');
|
|
165
|
+
}
|
|
166
|
+
exports.enableSourceMap = enableSourceMap;
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
const utils_1 = require("./utils");
|
|
4
|
+
describe('test: packages/uni-cli-shared/src/utils.ts', () => {
|
|
5
|
+
test('test:normalizeIdentifier', () => {
|
|
6
|
+
// 根据 path 返回合法 js 变量
|
|
7
|
+
expect((0, utils_1.normalizeIdentifier)('pages/index/index')).toBe('PagesIndexIndex');
|
|
8
|
+
expect((0, utils_1.normalizeIdentifier)('pages/index0.0/index')).toBe('PagesIndex00Index');
|
|
9
|
+
// note: filter `-`
|
|
10
|
+
expect((0, utils_1.normalizeIdentifier)('pages/index1-0/index')).toBe('PagesIndex10Index');
|
|
11
|
+
expect((0, utils_1.normalizeIdentifier)('pages/index2-0///index')).toBe('PagesIndex20Index');
|
|
12
|
+
expect((0, utils_1.normalizeIdentifier)('pages/index3--0/index')).toBe('PagesIndex30Index');
|
|
13
|
+
expect((0, utils_1.normalizeIdentifier)('pages/index4---0/index')).toBe('PagesIndex40Index');
|
|
14
|
+
expect((0, utils_1.normalizeIdentifier)('pages/index5 0/index')).toBe('PagesIndex50Index');
|
|
15
|
+
expect((0, utils_1.normalizeIdentifier)('2pages/index6/index')).toBe('_2pagesIndex6Index');
|
|
16
|
+
});
|
|
17
|
+
});
|
package/dist/vite/autoImport.js
CHANGED
|
@@ -126,13 +126,21 @@ const vuePreset = {
|
|
|
126
126
|
'defineComponent',
|
|
127
127
|
'defineAsyncComponent',
|
|
128
128
|
'getCurrentInstance',
|
|
129
|
-
'h',
|
|
130
129
|
'inject',
|
|
131
130
|
'nextTick',
|
|
132
131
|
'provide',
|
|
133
132
|
'useCssModule',
|
|
134
133
|
'createApp',
|
|
135
134
|
'hasInjectionContext',
|
|
135
|
+
// render
|
|
136
|
+
'h',
|
|
137
|
+
'mergeProps',
|
|
138
|
+
'cloneVNode',
|
|
139
|
+
'isVNode',
|
|
140
|
+
'resolveComponent',
|
|
141
|
+
'resolveDirective',
|
|
142
|
+
'withDirectives',
|
|
143
|
+
'withModifiers',
|
|
136
144
|
// effect scope
|
|
137
145
|
'effectScope',
|
|
138
146
|
'EffectScope',
|
|
@@ -0,0 +1,5 @@
|
|
|
1
|
+
import type { Plugin, ResolveFn } from 'vite';
|
|
2
|
+
import type { CssUrlReplacer } from './plugins/vitejs/plugins/css';
|
|
3
|
+
export declare function createEncryptCssUrlReplacer(resolve: ResolveFn): CssUrlReplacer;
|
|
4
|
+
export declare function uniEncryptUniModulesPlugin(): Plugin;
|
|
5
|
+
export declare function addUniModulesExtApiComponents(relativeFilename: string, components: string[]): void;
|
|
@@ -0,0 +1,240 @@
|
|
|
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.addUniModulesExtApiComponents = exports.uniEncryptUniModulesPlugin = exports.createEncryptCssUrlReplacer = void 0;
|
|
7
|
+
const path_1 = __importDefault(require("path"));
|
|
8
|
+
const fs_extra_1 = __importDefault(require("fs-extra"));
|
|
9
|
+
const uni_modules_1 = require("../uni_modules");
|
|
10
|
+
const utils_1 = require("./plugins/vitejs/utils");
|
|
11
|
+
const uts_1 = require("../uts");
|
|
12
|
+
function createEncryptCssUrlReplacer(resolve) {
|
|
13
|
+
return async (url, importer) => {
|
|
14
|
+
if (url.startsWith('/') && !url.startsWith('//')) {
|
|
15
|
+
// /static/logo.png => @/static/logo.png
|
|
16
|
+
url = '@' + url;
|
|
17
|
+
}
|
|
18
|
+
const resolved = await resolve(url, importer);
|
|
19
|
+
if (resolved) {
|
|
20
|
+
return ('@/' + (0, utils_1.normalizePath)(path_1.default.relative(process.env.UNI_INPUT_DIR, resolved)));
|
|
21
|
+
}
|
|
22
|
+
return url;
|
|
23
|
+
};
|
|
24
|
+
}
|
|
25
|
+
exports.createEncryptCssUrlReplacer = createEncryptCssUrlReplacer;
|
|
26
|
+
function uniEncryptUniModulesPlugin() {
|
|
27
|
+
let resolvedConfig;
|
|
28
|
+
return {
|
|
29
|
+
name: 'uni:encrypt-uni-modules',
|
|
30
|
+
apply: 'build',
|
|
31
|
+
config() {
|
|
32
|
+
return {
|
|
33
|
+
resolve: {
|
|
34
|
+
alias: initEncryptUniModulesAlias(),
|
|
35
|
+
},
|
|
36
|
+
build: initEncryptUniModulesBuildOptions(process.env.UNI_INPUT_DIR),
|
|
37
|
+
};
|
|
38
|
+
},
|
|
39
|
+
configResolved(config) {
|
|
40
|
+
// 编译组件时,禁用内联资源
|
|
41
|
+
config.build.assetsInlineLimit = 0;
|
|
42
|
+
config.build.rollupOptions.external = createExternal(config);
|
|
43
|
+
resolvedConfig = config;
|
|
44
|
+
},
|
|
45
|
+
resolveId(id) {
|
|
46
|
+
if (resolvedConfig.assetsInclude((0, utils_1.cleanUrl)(id))) {
|
|
47
|
+
return `\0${id}`;
|
|
48
|
+
}
|
|
49
|
+
},
|
|
50
|
+
generateBundle(_, bundle) {
|
|
51
|
+
Object.keys(bundle).forEach((fileName) => {
|
|
52
|
+
if (fileName.endsWith('.module.js')) {
|
|
53
|
+
const uniModuleId = path_1.default.basename(fileName).replace('.module.js', '');
|
|
54
|
+
// app-android 不需要 js
|
|
55
|
+
if (process.env.UNI_UTS_PLATFORM !== 'app-android') {
|
|
56
|
+
const newFileName = 'uni_modules/' +
|
|
57
|
+
fileName.replace('.module.js', '/index.module.js');
|
|
58
|
+
bundle[newFileName] = bundle[fileName];
|
|
59
|
+
bundle[newFileName].fileName = newFileName;
|
|
60
|
+
}
|
|
61
|
+
delete bundle[fileName];
|
|
62
|
+
const pkg = `uni_modules/${uniModuleId}/package.json`;
|
|
63
|
+
bundle[pkg] = {
|
|
64
|
+
type: 'asset',
|
|
65
|
+
fileName: pkg,
|
|
66
|
+
name: pkg,
|
|
67
|
+
needsCodeReference: false,
|
|
68
|
+
source: genUniModulesPackageJson(uniModuleId, process.env.UNI_INPUT_DIR, {
|
|
69
|
+
env: (0, uni_modules_1.initCheckEnv)(),
|
|
70
|
+
}),
|
|
71
|
+
};
|
|
72
|
+
}
|
|
73
|
+
});
|
|
74
|
+
},
|
|
75
|
+
async writeBundle() {
|
|
76
|
+
if (process.env.UNI_UTS_PLATFORM !== 'app-android') {
|
|
77
|
+
return;
|
|
78
|
+
}
|
|
79
|
+
// 编译所有 uni_modules 插件
|
|
80
|
+
const tempOutputDir = uvueOutDir();
|
|
81
|
+
const tempUniModulesDir = path_1.default.join(tempOutputDir, 'uni_modules');
|
|
82
|
+
const tempUniModules = [];
|
|
83
|
+
if (fs_extra_1.default.existsSync(tempUniModulesDir)) {
|
|
84
|
+
fs_extra_1.default.readdirSync(tempUniModulesDir).forEach((uniModuleDir) => {
|
|
85
|
+
if (fs_extra_1.default.existsSync(path_1.default.join(tempUniModulesDir, uniModuleDir, 'index.module.uts'))) {
|
|
86
|
+
tempUniModules.push(uniModuleDir);
|
|
87
|
+
}
|
|
88
|
+
});
|
|
89
|
+
}
|
|
90
|
+
const compiler = (0, uts_1.resolveUTSCompiler)();
|
|
91
|
+
for (const uniModule of tempUniModules) {
|
|
92
|
+
const pluginDir = path_1.default.resolve(tempUniModulesDir, uniModule);
|
|
93
|
+
const result = await compiler.compile(pluginDir, {
|
|
94
|
+
isX: process.env.UNI_APP_X === 'true',
|
|
95
|
+
isSingleThread: true,
|
|
96
|
+
isPlugin: false,
|
|
97
|
+
sourceMap: false,
|
|
98
|
+
uni_modules: [],
|
|
99
|
+
});
|
|
100
|
+
if (result) {
|
|
101
|
+
const apis = result.inject_apis;
|
|
102
|
+
const components = getUniModulesExtApiComponents(uniModule);
|
|
103
|
+
const modules = (0, uts_1.resolveUTSCompiler)().parseInjectModules(apis, {}, components);
|
|
104
|
+
fs_extra_1.default.writeFileSync(path_1.default.resolve(process.env.UNI_OUTPUT_DIR, 'uni_modules', uniModule, 'package.json'), genUniModulesPackageJson(uniModule, tempOutputDir, {
|
|
105
|
+
env: (0, uni_modules_1.initCheckEnv)(),
|
|
106
|
+
apis,
|
|
107
|
+
components,
|
|
108
|
+
modules,
|
|
109
|
+
}));
|
|
110
|
+
}
|
|
111
|
+
}
|
|
112
|
+
},
|
|
113
|
+
};
|
|
114
|
+
}
|
|
115
|
+
exports.uniEncryptUniModulesPlugin = uniEncryptUniModulesPlugin;
|
|
116
|
+
function uvueOutDir() {
|
|
117
|
+
return path_1.default.join(process.env.UNI_OUTPUT_DIR, '../.uvue');
|
|
118
|
+
}
|
|
119
|
+
function createExternal(config) {
|
|
120
|
+
return function external(source) {
|
|
121
|
+
if (
|
|
122
|
+
// android 平台需要编译 assets 资源
|
|
123
|
+
process.env.UNI_UTS_PLATFORM !== 'app-android' &&
|
|
124
|
+
config.assetsInclude((0, utils_1.cleanUrl)(source))) {
|
|
125
|
+
return true;
|
|
126
|
+
}
|
|
127
|
+
if ([
|
|
128
|
+
'vue',
|
|
129
|
+
'plugin-vue:export-helper',
|
|
130
|
+
'vue-router',
|
|
131
|
+
'pinia',
|
|
132
|
+
'vuex',
|
|
133
|
+
'vue-i18n',
|
|
134
|
+
].includes(source)) {
|
|
135
|
+
return true;
|
|
136
|
+
}
|
|
137
|
+
if (source.startsWith('@vue/')) {
|
|
138
|
+
return true;
|
|
139
|
+
}
|
|
140
|
+
if (source.startsWith('@dcloudio/')) {
|
|
141
|
+
return true;
|
|
142
|
+
}
|
|
143
|
+
if (source.startsWith('@/uni_modules/')) {
|
|
144
|
+
return true;
|
|
145
|
+
}
|
|
146
|
+
return false;
|
|
147
|
+
};
|
|
148
|
+
}
|
|
149
|
+
function initEncryptUniModulesAlias() {
|
|
150
|
+
return [
|
|
151
|
+
{
|
|
152
|
+
find: '\0plugin-vue:export-helper',
|
|
153
|
+
replacement: 'plugin-vue:export-helper',
|
|
154
|
+
},
|
|
155
|
+
];
|
|
156
|
+
}
|
|
157
|
+
const indexFiles = ['index.uts', 'index.ts', 'index.js'];
|
|
158
|
+
function hasIndexFile(uniModuleDir) {
|
|
159
|
+
return fs_extra_1.default.readdirSync(uniModuleDir).some((file) => indexFiles.includes(file));
|
|
160
|
+
}
|
|
161
|
+
function initEncryptUniModulesBuildOptions(inputDir) {
|
|
162
|
+
const modules = (0, uni_modules_1.parseUniModulesWithComponents)(inputDir);
|
|
163
|
+
const moduleNames = Object.keys(modules);
|
|
164
|
+
if (!moduleNames.length) {
|
|
165
|
+
throw new Error('No encrypt uni_modules found');
|
|
166
|
+
}
|
|
167
|
+
// 生成入口文件
|
|
168
|
+
const input = {};
|
|
169
|
+
moduleNames.forEach((module) => {
|
|
170
|
+
const indexEncryptFile = path_1.default.resolve(inputDir, 'uni_modules', module, 'index.module.uts');
|
|
171
|
+
const codes = [];
|
|
172
|
+
if (hasIndexFile(path_1.default.resolve(inputDir, 'uni_modules', module))) {
|
|
173
|
+
codes.push(`export * from './index'`);
|
|
174
|
+
}
|
|
175
|
+
// easyCom
|
|
176
|
+
if (modules[module].length) {
|
|
177
|
+
codes.push((0, uni_modules_1.genEncryptEasyComModuleIndex)(modules[module]));
|
|
178
|
+
}
|
|
179
|
+
if (codes.length) {
|
|
180
|
+
fs_extra_1.default.writeFileSync(indexEncryptFile, codes.join(`\n`));
|
|
181
|
+
// 输出 xxx.module ,确保相对路径的准确性,因为真正引用的时候,是从 @/uni_modules/xxx 引入的
|
|
182
|
+
input[module + '.module'] = indexEncryptFile;
|
|
183
|
+
}
|
|
184
|
+
});
|
|
185
|
+
return {
|
|
186
|
+
lib: false, // 不使用 lib 模式,lib模式会直接内联资源
|
|
187
|
+
cssCodeSplit: false,
|
|
188
|
+
// outDir: process.env.UNI_OUTPUT_DIR,
|
|
189
|
+
rollupOptions: {
|
|
190
|
+
preserveEntrySignatures: 'strict',
|
|
191
|
+
input,
|
|
192
|
+
output: {
|
|
193
|
+
format: 'es',
|
|
194
|
+
banner: ``,
|
|
195
|
+
entryFileNames: '[name].js',
|
|
196
|
+
assetFileNames(asset) {
|
|
197
|
+
if (asset.name && path_1.default.isAbsolute(asset.name)) {
|
|
198
|
+
const uniModuleId = parseUniModuleId(path_1.default.relative(inputDir, asset.name));
|
|
199
|
+
if (uniModuleId) {
|
|
200
|
+
return `uni_modules/${uniModuleId}/assets/[name]-[hash][extname]`;
|
|
201
|
+
}
|
|
202
|
+
}
|
|
203
|
+
return 'assets/[name]-[hash][extname]';
|
|
204
|
+
},
|
|
205
|
+
},
|
|
206
|
+
},
|
|
207
|
+
};
|
|
208
|
+
}
|
|
209
|
+
function genUniModulesPackageJson(uniModuleId, inputDir, artifacts) {
|
|
210
|
+
const pkg = require(path_1.default.resolve(inputDir, path_1.default.join('uni_modules', uniModuleId, 'package.json')));
|
|
211
|
+
return JSON.stringify({
|
|
212
|
+
id: pkg.id,
|
|
213
|
+
version: pkg.version,
|
|
214
|
+
uni_modules: {
|
|
215
|
+
artifacts,
|
|
216
|
+
},
|
|
217
|
+
}, null, 2);
|
|
218
|
+
}
|
|
219
|
+
function parseUniModuleId(relativeFilename) {
|
|
220
|
+
const parts = (0, utils_1.normalizePath)(relativeFilename).split('/', 2);
|
|
221
|
+
if (parts[0] === 'uni_modules') {
|
|
222
|
+
return parts[1];
|
|
223
|
+
}
|
|
224
|
+
}
|
|
225
|
+
const uniModulesExtApiComponents = new Map();
|
|
226
|
+
function addUniModulesExtApiComponents(relativeFilename, components) {
|
|
227
|
+
const uniModuleId = parseUniModuleId(relativeFilename);
|
|
228
|
+
if (uniModuleId) {
|
|
229
|
+
let extApiComponents = uniModulesExtApiComponents.get(uniModuleId);
|
|
230
|
+
if (!extApiComponents) {
|
|
231
|
+
extApiComponents = new Set();
|
|
232
|
+
uniModulesExtApiComponents.set(uniModuleId, extApiComponents);
|
|
233
|
+
}
|
|
234
|
+
components.forEach((component) => extApiComponents.add(component));
|
|
235
|
+
}
|
|
236
|
+
}
|
|
237
|
+
exports.addUniModulesExtApiComponents = addUniModulesExtApiComponents;
|
|
238
|
+
function getUniModulesExtApiComponents(uniModuleId) {
|
|
239
|
+
return [...(uniModulesExtApiComponents.get(uniModuleId) || [])];
|
|
240
|
+
}
|
package/dist/vite/index.d.ts
CHANGED
package/dist/vite/index.js
CHANGED
|
@@ -25,6 +25,7 @@ __exportStar(require("./utils"), exports);
|
|
|
25
25
|
__exportStar(require("./plugins"), exports);
|
|
26
26
|
__exportStar(require("./features"), exports);
|
|
27
27
|
__exportStar(require("./autoImport"), exports);
|
|
28
|
+
__exportStar(require("./cloud"), exports);
|
|
28
29
|
// https://github.com/vitejs/vite/blob/aac2ef77521f66ddd908f9d97020b8df532148cf/packages/vite/src/node/server/searchRoot.ts#L38
|
|
29
30
|
// vite 在初始化阶段会执行 initTSConfck,此时会 searchForWorkspaceRoot,如果找到了 pnpm-workspace.yaml 文件,会将其作为 root
|
|
30
31
|
// HBuilderX 项目,root 一定是 UNI_INPUT_DIR,所以需要重写 fs.existsSync,不重写的话,可能会找错,
|
|
@@ -34,7 +34,9 @@ function uniEasycomPlugin(options) {
|
|
|
34
34
|
// 处理easycom组件优先级
|
|
35
35
|
return (0, easycom_1.genResolveEasycomCode)(importDeclarations, str, (0, easycom_1.addImportDeclaration)(importDeclarations, `__easycom_${i++}`, source, source.includes('uts-proxy')
|
|
36
36
|
? (0, shared_1.capitalize)((0, shared_1.camelize)(name)) + 'Component'
|
|
37
|
-
: '')
|
|
37
|
+
: source.includes('uni_helpers')
|
|
38
|
+
? (0, shared_1.capitalize)((0, shared_1.camelize)(name))
|
|
39
|
+
: ''));
|
|
38
40
|
}
|
|
39
41
|
}
|
|
40
42
|
return str;
|
|
@@ -10,14 +10,21 @@ const uni_shared_1 = require("@dcloudio/uni-shared");
|
|
|
10
10
|
const uts_1 = require("../../../uts");
|
|
11
11
|
const utils_1 = require("../../utils");
|
|
12
12
|
const uni_modules_1 = require("../../../uni_modules");
|
|
13
|
+
const utils_2 = require("../../../utils");
|
|
14
|
+
const json_1 = require("../../../json");
|
|
13
15
|
const UTSProxyRE = /\?uts-proxy$/;
|
|
16
|
+
const UniHelpersRE = /\?uni_helpers$/;
|
|
14
17
|
function isUTSProxy(id) {
|
|
15
18
|
return UTSProxyRE.test(id);
|
|
16
19
|
}
|
|
20
|
+
function isUniHelpers(id) {
|
|
21
|
+
return UniHelpersRE.test(id);
|
|
22
|
+
}
|
|
17
23
|
const utsModuleCaches = new Map();
|
|
18
24
|
exports.utsPlugins = new Set();
|
|
19
25
|
let uniExtApiCompiler = async () => { };
|
|
20
26
|
function uniUTSUniModulesPlugin(options = {}) {
|
|
27
|
+
const inputDir = process.env.UNI_INPUT_DIR;
|
|
21
28
|
process.env.UNI_UTS_USING_ROLLUP = 'true';
|
|
22
29
|
const compilePlugin = async (pluginDir) => {
|
|
23
30
|
exports.utsPlugins.add(path_1.default.basename(pluginDir));
|
|
@@ -26,16 +33,16 @@ function uniUTSUniModulesPlugin(options = {}) {
|
|
|
26
33
|
// 如果是 provider 扩展,需要判断 provider 的宿主插件是否在本地,在的话,自动导入该宿主插件包名
|
|
27
34
|
let uniExtApiProviderServicePlugin = '';
|
|
28
35
|
if (extApiProvider?.servicePlugin) {
|
|
29
|
-
if (fs_1.default.existsSync(path_1.default.resolve(
|
|
36
|
+
if (fs_1.default.existsSync(path_1.default.resolve(inputDir, 'uni_modules', extApiProvider.servicePlugin))) {
|
|
30
37
|
uniExtApiProviderServicePlugin = extApiProvider.servicePlugin;
|
|
31
38
|
}
|
|
32
39
|
}
|
|
33
40
|
const compiler = (0, uts_1.resolveUTSCompiler)();
|
|
34
41
|
// 处理依赖的 uts 插件
|
|
35
|
-
const deps = (0, uni_modules_1.parseUTSModuleDeps)(pkgJson.uni_modules?.dependencies || [],
|
|
42
|
+
const deps = (0, uni_modules_1.parseUTSModuleDeps)(pkgJson.uni_modules?.dependencies || [], inputDir);
|
|
36
43
|
if (deps.length) {
|
|
37
44
|
for (const dep of deps) {
|
|
38
|
-
await compilePlugin(path_1.default.resolve(
|
|
45
|
+
await compilePlugin(path_1.default.resolve(inputDir, 'uni_modules', dep));
|
|
39
46
|
}
|
|
40
47
|
}
|
|
41
48
|
return compiler.compile(pluginDir, {
|
|
@@ -43,7 +50,7 @@ function uniUTSUniModulesPlugin(options = {}) {
|
|
|
43
50
|
isSingleThread: !!options.isSingleThread,
|
|
44
51
|
isPlugin: true,
|
|
45
52
|
extApis: options.extApis,
|
|
46
|
-
sourceMap:
|
|
53
|
+
sourceMap: (0, utils_2.enableSourceMap)(),
|
|
47
54
|
uni_modules: deps,
|
|
48
55
|
transform: {
|
|
49
56
|
uniExtApiProviderName: extApiProvider?.name,
|
|
@@ -56,7 +63,7 @@ function uniUTSUniModulesPlugin(options = {}) {
|
|
|
56
63
|
// 获取 provider 扩展(编译所有uni)
|
|
57
64
|
const plugins = (0, uni_modules_1.getUniExtApiPlugins)().filter((provider) => !exports.utsPlugins.has(provider.plugin));
|
|
58
65
|
for (const plugin of plugins) {
|
|
59
|
-
const result = await compilePlugin(path_1.default.resolve(
|
|
66
|
+
const result = await compilePlugin(path_1.default.resolve(inputDir, 'uni_modules', plugin.plugin));
|
|
60
67
|
if (result) {
|
|
61
68
|
// 时机不对,不能addWatch
|
|
62
69
|
// result.deps.forEach((dep) => {
|
|
@@ -65,15 +72,37 @@ function uniUTSUniModulesPlugin(options = {}) {
|
|
|
65
72
|
}
|
|
66
73
|
}
|
|
67
74
|
};
|
|
75
|
+
const isX = process.env.UNI_APP_X === 'true';
|
|
68
76
|
return {
|
|
69
77
|
name: 'uni:uts-uni_modules',
|
|
70
78
|
apply: 'build',
|
|
71
79
|
enforce: 'pre',
|
|
80
|
+
async configResolved() {
|
|
81
|
+
if (isX) {
|
|
82
|
+
const manifest = (0, json_1.parseManifestJsonOnce)(inputDir);
|
|
83
|
+
await (0, uni_modules_1.checkEncryptUniModules)(inputDir, {
|
|
84
|
+
mode: process.env.NODE_ENV !== 'development'
|
|
85
|
+
? 'production'
|
|
86
|
+
: 'development',
|
|
87
|
+
compilerVersion: process.env.UNI_COMPILER_VERSION,
|
|
88
|
+
appid: manifest.appid,
|
|
89
|
+
appname: manifest.name,
|
|
90
|
+
platform: process.env.UNI_UTS_PLATFORM,
|
|
91
|
+
'uni-app-x': isX,
|
|
92
|
+
});
|
|
93
|
+
}
|
|
94
|
+
},
|
|
72
95
|
resolveId(id, importer) {
|
|
73
|
-
if (isUTSProxy(id)) {
|
|
96
|
+
if (isUTSProxy(id) || isUniHelpers(id)) {
|
|
74
97
|
return id;
|
|
75
98
|
}
|
|
76
|
-
|
|
99
|
+
if (isX && process.env.UNI_COMPILE_TARGET !== 'uni_modules') {
|
|
100
|
+
const resolvedId = (0, uni_modules_1.resolveEncryptUniModule)(id, process.env.UNI_UTS_PLATFORM, process.env.UNI_APP_X === 'true');
|
|
101
|
+
if (resolvedId) {
|
|
102
|
+
return resolvedId;
|
|
103
|
+
}
|
|
104
|
+
}
|
|
105
|
+
const module = (0, uts_1.resolveUTSAppModule)(id, importer ? path_1.default.dirname(importer) : inputDir, options.x !== true);
|
|
77
106
|
if (module) {
|
|
78
107
|
// app-js 会直接返回 index.uts 路径,不需要 uts-proxy
|
|
79
108
|
if (module.endsWith('.uts')) {
|
|
@@ -1,7 +1,9 @@
|
|
|
1
1
|
import type { SFCDescriptor } from '@vue/compiler-sfc';
|
|
2
2
|
import type { ExistingRawSourceMap, RollupError } from 'rollup';
|
|
3
|
+
import type * as PostCSS from 'postcss';
|
|
3
4
|
import type { Plugin } from '../plugin';
|
|
4
5
|
import type { ResolvedConfig } from '../config';
|
|
6
|
+
import type { ResolveFn } from '../';
|
|
5
7
|
import * as Postcss from 'postcss';
|
|
6
8
|
export interface CSSOptions {
|
|
7
9
|
/**
|
|
@@ -34,18 +36,21 @@ export declare const isDirectCSSRequest: (request: string) => boolean;
|
|
|
34
36
|
export declare function cssPlugin(config: ResolvedConfig, options?: {
|
|
35
37
|
isAndroidX: boolean;
|
|
36
38
|
getDescriptor?(filename: string): SFCDescriptor | undefined;
|
|
39
|
+
createUrlReplacer?: (resolve: ResolveFn) => CssUrlReplacer;
|
|
37
40
|
}): Plugin;
|
|
38
41
|
/**
|
|
39
42
|
* Plugin applied after user plugins
|
|
40
43
|
*/
|
|
41
|
-
export declare function cssPostPlugin(config: ResolvedConfig, { platform, isJsCode, chunkCssFilename, chunkCssCode, includeComponentCss, }: {
|
|
44
|
+
export declare function cssPostPlugin(config: ResolvedConfig, { platform, isJsCode, preserveModules, chunkCssFilename, chunkCssCode, includeComponentCss, }: {
|
|
42
45
|
platform: UniApp.PLATFORM;
|
|
43
46
|
isJsCode?: boolean;
|
|
47
|
+
preserveModules?: boolean;
|
|
44
48
|
chunkCssFilename: (id: string) => string | void;
|
|
45
49
|
chunkCssCode: (filename: string, cssCode: string) => Promise<string> | string;
|
|
46
50
|
includeComponentCss?: boolean;
|
|
47
51
|
}): Plugin;
|
|
48
52
|
export declare function formatPostcssSourceMap(rawMap: ExistingRawSourceMap, file: string): ExistingRawSourceMap;
|
|
53
|
+
export type CssUrlReplacer = (url: string, importer?: string, source?: PostCSS.Source) => string | Promise<string>;
|
|
49
54
|
export declare const cssUrlRE: RegExp;
|
|
50
55
|
export declare const cssDataUriRE: RegExp;
|
|
51
56
|
export declare const importCssRE: RegExp;
|
|
@@ -121,29 +121,30 @@ function cssPlugin(config, options = { isAndroidX: false }) {
|
|
|
121
121
|
if (!exports.cssLangRE.test(id) || exports.commonjsProxyRE.test(id)) {
|
|
122
122
|
return;
|
|
123
123
|
}
|
|
124
|
-
const urlReplacer =
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
124
|
+
const urlReplacer = (options.createUrlReplacer && options.createUrlReplacer(resolveUrl)) ||
|
|
125
|
+
(async (url, importer, source) => {
|
|
126
|
+
if (url.startsWith('/') && !url.startsWith('//')) {
|
|
127
|
+
// /static/logo.png => @/static/logo.png
|
|
128
|
+
url = '@' + url;
|
|
129
|
+
}
|
|
130
|
+
const resolved = await wrapResolve(resolveUrl, source?.input.css || raw, source, options.getDescriptor)(url, importer);
|
|
131
|
+
if (resolved) {
|
|
132
|
+
return (0, asset_1.fileToUrl)(resolved, config, options?.isAndroidX
|
|
133
|
+
? {
|
|
134
|
+
emitFile(emittedFile) {
|
|
135
|
+
const fileName = path_1.default.resolve(process.env.UNI_OUTPUT_DIR, emittedFile.fileName);
|
|
136
|
+
// 忽略static(可能有只读文件,写入覆盖只读会报错权限)
|
|
137
|
+
if ((0, utils_1.normalizePath)(fileName).includes('/static/')) {
|
|
138
|
+
return;
|
|
139
|
+
}
|
|
140
|
+
// 直接写入目标目录
|
|
141
|
+
fs_extra_1.default.outputFileSync(fileName, emittedFile.source);
|
|
142
|
+
},
|
|
143
|
+
}
|
|
144
|
+
: this, true);
|
|
145
|
+
}
|
|
146
|
+
return url;
|
|
147
|
+
});
|
|
147
148
|
const { code: css, modules, deps, } = await compileCSS(id, raw, config, urlReplacer, atImportResolvers, server);
|
|
148
149
|
if (modules) {
|
|
149
150
|
moduleCache.set(id, modules);
|
|
@@ -199,7 +200,7 @@ function findCssModuleIds(moduleId, includeComponentCss = true, cssModuleIds, se
|
|
|
199
200
|
/**
|
|
200
201
|
* Plugin applied after user plugins
|
|
201
202
|
*/
|
|
202
|
-
function cssPostPlugin(config, { platform, isJsCode, chunkCssFilename, chunkCssCode, includeComponentCss, }) {
|
|
203
|
+
function cssPostPlugin(config, { platform, isJsCode, preserveModules, chunkCssFilename, chunkCssCode, includeComponentCss, }) {
|
|
203
204
|
// styles initialization in buildStart causes a styling loss in watch
|
|
204
205
|
const styles = new Map();
|
|
205
206
|
let cssChunks;
|
|
@@ -251,7 +252,7 @@ function cssPostPlugin(config, { platform, isJsCode, chunkCssFilename, chunkCssC
|
|
|
251
252
|
},
|
|
252
253
|
async generateBundle() {
|
|
253
254
|
// app 平台页面并未 chunk,所以 renderChunk 并不会处理页面的 css,需要这里再补充查找
|
|
254
|
-
if (platform === 'app') {
|
|
255
|
+
if (platform === 'app' || preserveModules) {
|
|
255
256
|
const moduleIds = Array.from(this.getModuleIds());
|
|
256
257
|
moduleIds.forEach((id) => {
|
|
257
258
|
const filename = chunkCssFilename(id);
|
package/dist/vite/utils/index.js
CHANGED
|
@@ -22,6 +22,9 @@ __exportStar(require("./utils"), exports);
|
|
|
22
22
|
// 内置组件css列表,h5平台需要合并进去首页css中
|
|
23
23
|
exports.buildInCssSet = new Set();
|
|
24
24
|
function isCombineBuiltInCss(config) {
|
|
25
|
+
if (process.env.UNI_COMPILE_TARGET === 'uni_modules') {
|
|
26
|
+
return false;
|
|
27
|
+
}
|
|
25
28
|
return config.command === 'build' && config.build.cssCodeSplit;
|
|
26
29
|
}
|
|
27
30
|
exports.isCombineBuiltInCss = isCombineBuiltInCss;
|
|
@@ -1,4 +1,5 @@
|
|
|
1
|
-
import type { Plugin, ResolvedConfig } from 'vite';
|
|
1
|
+
import type { Plugin, ResolveFn, ResolvedConfig } from 'vite';
|
|
2
|
+
import { type CssUrlReplacer } from '../plugins/vitejs/plugins/css';
|
|
2
3
|
export type CreateUniViteFilterPlugin = (opts: UniViteFilterPluginOptions) => Plugin;
|
|
3
4
|
export interface UniViteFilterPluginOptions {
|
|
4
5
|
resolvedConfig: ResolvedConfig;
|
|
@@ -7,7 +8,9 @@ export interface UniViteFilterPluginOptions {
|
|
|
7
8
|
export declare function injectAssetPlugin(config: ResolvedConfig, options?: {
|
|
8
9
|
isAndroidX: boolean;
|
|
9
10
|
}): void;
|
|
10
|
-
export declare function injectCssPlugin(config: ResolvedConfig
|
|
11
|
+
export declare function injectCssPlugin(config: ResolvedConfig, options?: {
|
|
12
|
+
createUrlReplacer?: (resolve: ResolveFn) => CssUrlReplacer;
|
|
13
|
+
}): void;
|
|
11
14
|
export declare function injectCssPostPlugin(config: ResolvedConfig, newCssPostPlugin: Plugin): void;
|
|
12
15
|
export declare function replacePlugins(plugins: Plugin[], config: ResolvedConfig): void;
|
|
13
16
|
export declare function removePlugins(plugins: string | string[], config: ResolvedConfig): void;
|
|
@@ -8,8 +8,13 @@ function injectAssetPlugin(config, options) {
|
|
|
8
8
|
replacePlugins([(0, asset_1.assetPlugin)(config, options)], config);
|
|
9
9
|
}
|
|
10
10
|
exports.injectAssetPlugin = injectAssetPlugin;
|
|
11
|
-
function injectCssPlugin(config) {
|
|
12
|
-
replacePlugins([
|
|
11
|
+
function injectCssPlugin(config, options) {
|
|
12
|
+
replacePlugins([
|
|
13
|
+
(0, css_1.cssPlugin)(config, {
|
|
14
|
+
isAndroidX: false,
|
|
15
|
+
...options,
|
|
16
|
+
}),
|
|
17
|
+
], config);
|
|
13
18
|
}
|
|
14
19
|
exports.injectCssPlugin = injectCssPlugin;
|
|
15
20
|
function injectCssPostPlugin(config, newCssPostPlugin) {
|
package/dist/vite/utils/utils.js
CHANGED
|
@@ -5,6 +5,9 @@ const shared_1 = require("@vue/shared");
|
|
|
5
5
|
const code_frame_1 = require("@babel/code-frame");
|
|
6
6
|
const utils_1 = require("../plugins/vitejs/utils");
|
|
7
7
|
function withSourcemap(config) {
|
|
8
|
+
if (process.env.UNI_COMPILE_TARGET === 'uni_modules') {
|
|
9
|
+
return false;
|
|
10
|
+
}
|
|
8
11
|
if (config.command === 'serve') {
|
|
9
12
|
return true;
|
|
10
13
|
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@dcloudio/uni-cli-shared",
|
|
3
|
-
"version": "3.0.0-alpha-
|
|
3
|
+
"version": "3.0.0-alpha-4010720240511002",
|
|
4
4
|
"description": "@dcloudio/uni-cli-shared",
|
|
5
5
|
"main": "dist/index.js",
|
|
6
6
|
"types": "dist/index.d.ts",
|
|
@@ -26,8 +26,8 @@
|
|
|
26
26
|
"@babel/core": "^7.23.3",
|
|
27
27
|
"@babel/parser": "^7.23.9",
|
|
28
28
|
"@babel/types": "^7.20.7",
|
|
29
|
-
"@dcloudio/uni-i18n": "3.0.0-alpha-
|
|
30
|
-
"@dcloudio/uni-shared": "3.0.0-alpha-
|
|
29
|
+
"@dcloudio/uni-i18n": "3.0.0-alpha-4010720240511002",
|
|
30
|
+
"@dcloudio/uni-shared": "3.0.0-alpha-4010720240511002",
|
|
31
31
|
"@intlify/core-base": "9.1.9",
|
|
32
32
|
"@intlify/shared": "9.1.9",
|
|
33
33
|
"@intlify/vue-devtools": "9.1.9",
|
|
@@ -38,6 +38,7 @@
|
|
|
38
38
|
"@vue/compiler-ssr": "3.4.21",
|
|
39
39
|
"@vue/server-renderer": "3.4.21",
|
|
40
40
|
"@vue/shared": "3.4.21",
|
|
41
|
+
"adm-zip": "^0.5.12",
|
|
41
42
|
"autoprefixer": "^10.4.19",
|
|
42
43
|
"base64url": "^3.0.1",
|
|
43
44
|
"chokidar": "^3.5.3",
|
|
@@ -49,6 +50,7 @@
|
|
|
49
50
|
"fast-glob": "^3.2.11",
|
|
50
51
|
"fs-extra": "^10.0.0",
|
|
51
52
|
"hash-sum": "^2.0.0",
|
|
53
|
+
"isbinaryfile": "^5.0.2",
|
|
52
54
|
"jsonc-parser": "^3.2.0",
|
|
53
55
|
"lines-and-columns": "^2.0.4",
|
|
54
56
|
"magic-string": "^0.30.7",
|
|
@@ -69,7 +71,8 @@
|
|
|
69
71
|
},
|
|
70
72
|
"gitHead": "33e807d66e1fe47e2ee08ad9c59247e37b8884da",
|
|
71
73
|
"devDependencies": {
|
|
72
|
-
"@dcloudio/uni-uts-v1": "3.0.0-alpha-
|
|
74
|
+
"@dcloudio/uni-uts-v1": "3.0.0-alpha-4010720240511002",
|
|
75
|
+
"@types/adm-zip": "^0.5.5",
|
|
73
76
|
"@types/babel__code-frame": "^7.0.6",
|
|
74
77
|
"@types/babel__core": "^7.1.19",
|
|
75
78
|
"@types/debug": "^4.1.7",
|