@dcloudio/uni-cli-shared 3.0.0-alpha-4010720240511002 → 3.0.0-alpha-4010720240511003

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 CHANGED
@@ -173,9 +173,6 @@ 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, '..'));
179
176
  fs_1.default.readdirSync(dir).forEach((name) => {
180
177
  const folder = path_1.default.resolve(dir, name);
181
178
  if (!isDir(folder)) {
@@ -187,9 +184,7 @@ function initAutoScanEasycom(dir, rootDir, extensions) {
187
184
  for (let i = 0; i < extensions.length; i++) {
188
185
  const ext = extensions[i];
189
186
  if (files.includes(name + ext)) {
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}`;
187
+ easycoms[`^${name}$`] = `${importDir}/${name}${ext}`;
193
188
  break;
194
189
  }
195
190
  }
package/dist/hbx/log.js CHANGED
@@ -110,16 +110,7 @@ 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
- }
121
113
  args.push(`${picocolors_1.default.magenta('[plugin:' + err.plugin + ']')} ${picocolors_1.default.red(err.message)}`);
122
- args.push(...otherMsgs);
123
114
  if (err.loc &&
124
115
  err.hook === 'transform' &&
125
116
  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" | "weex" | "vue" | "vite";
2
+ export declare function getNVueCompiler(manifestJson: Record<string, any>): "uni-app" | "vue" | "weex" | "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";
@@ -10,12 +10,6 @@ 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
- }
19
13
  return (0, json_1.parseJson)(fs_1.default.readFileSync(path_1.default.join(inputDir, 'manifest.json'), 'utf8'));
20
14
  };
21
15
  exports.parseManifestJson = parseManifestJson;
@@ -43,16 +43,7 @@ exports.isUniPageSfcFile = isUniPageSfcFile;
43
43
  * @returns
44
44
  */
45
45
  const parsePagesJson = (inputDir, platform, normalize = true) => {
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');
46
+ const jsonStr = fs_1.default.readFileSync(path_1.default.join(inputDir, 'pages.json'), 'utf8');
56
47
  if (normalize) {
57
48
  return normalizePagesJson(jsonStr, platform);
58
49
  }
package/dist/resolve.js CHANGED
@@ -107,12 +107,7 @@ function resolveComponentsLibPath() {
107
107
  componentsLibPath = path_1.default.join(resolveBuiltIn('@dcloudio/uni-components/package.json'), dir);
108
108
  }
109
109
  else {
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
- }
110
+ componentsLibPath = path_1.default.join(resolveWithSymlinks('@dcloudio/uni-components/package.json', process.env.UNI_INPUT_DIR), dir);
116
111
  }
117
112
  }
118
113
  return componentsLibPath;
@@ -70,38 +70,3 @@ 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 {};
@@ -3,11 +3,10 @@ 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.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;
6
+ 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");
11
10
  const extApiProviders = [];
12
11
  const extApiPlugins = new Set();
13
12
  function getUniExtApiProviders() {
@@ -266,242 +265,3 @@ function parseUTSModuleDeps(deps, inputDir) {
266
265
  });
267
266
  }
268
267
  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,12 +5,7 @@ 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
- /**
9
- * 根据 path 返回合法 js 变量
10
- * @param str pages.json.page.path
11
- * @returns
12
- */
13
- export declare function normalizeIdentifier(str: string): string;
8
+ export declare function normalizeIdentifier(str: string): Capitalize<string>;
14
9
  export declare function normalizePagePath(pagePath: string, platform: UniApp.PLATFORM): string | undefined;
15
10
  export declare function removeExt(str: string): string;
16
11
  export declare function normalizeNodeModules(str: string): string;
@@ -26,4 +21,3 @@ export declare function isAppVue(filename: string): boolean;
26
21
  export declare function resolveAppVue(inputDir: string): string;
27
22
  export declare function parseImporter(importer: string): string;
28
23
  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.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;
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;
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,19 +33,8 @@ 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
- */
41
36
  function normalizeIdentifier(str) {
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;
37
+ return (0, shared_1.capitalize)((0, shared_1.camelize)(str.replace(/\//g, '-')));
49
38
  }
50
39
  exports.normalizeIdentifier = normalizeIdentifier;
51
40
  function normalizePagePath(pagePath, platform) {
@@ -159,8 +148,3 @@ function createResolveErrorMsg(source, importer) {
159
148
  return `Could not resolve "${source}" from "${parseImporter(importer)}"`;
160
149
  }
161
150
  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;
@@ -126,21 +126,13 @@ const vuePreset = {
126
126
  'defineComponent',
127
127
  'defineAsyncComponent',
128
128
  'getCurrentInstance',
129
+ 'h',
129
130
  'inject',
130
131
  'nextTick',
131
132
  'provide',
132
133
  'useCssModule',
133
134
  'createApp',
134
135
  'hasInjectionContext',
135
- // render
136
- 'h',
137
- 'mergeProps',
138
- 'cloneVNode',
139
- 'isVNode',
140
- 'resolveComponent',
141
- 'resolveDirective',
142
- 'withDirectives',
143
- 'withModifiers',
144
136
  // effect scope
145
137
  'effectScope',
146
138
  'EffectScope',
@@ -36,5 +36,4 @@ export * from './utils';
36
36
  export * from './plugins';
37
37
  export * from './features';
38
38
  export * from './autoImport';
39
- export * from './cloud';
40
39
  export declare function rewriteExistsSyncHasRootFile(): void;
@@ -25,7 +25,6 @@ __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);
29
28
  // https://github.com/vitejs/vite/blob/aac2ef77521f66ddd908f9d97020b8df532148cf/packages/vite/src/node/server/searchRoot.ts#L38
30
29
  // vite 在初始化阶段会执行 initTSConfck,此时会 searchForWorkspaceRoot,如果找到了 pnpm-workspace.yaml 文件,会将其作为 root
31
30
  // HBuilderX 项目,root 一定是 UNI_INPUT_DIR,所以需要重写 fs.existsSync,不重写的话,可能会找错,
@@ -34,9 +34,7 @@ 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
- : source.includes('uni_helpers')
38
- ? (0, shared_1.capitalize)((0, shared_1.camelize)(name))
39
- : ''));
37
+ : ''));
40
38
  }
41
39
  }
42
40
  return str;
@@ -10,21 +10,14 @@ 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");
15
13
  const UTSProxyRE = /\?uts-proxy$/;
16
- const UniHelpersRE = /\?uni_helpers$/;
17
14
  function isUTSProxy(id) {
18
15
  return UTSProxyRE.test(id);
19
16
  }
20
- function isUniHelpers(id) {
21
- return UniHelpersRE.test(id);
22
- }
23
17
  const utsModuleCaches = new Map();
24
18
  exports.utsPlugins = new Set();
25
19
  let uniExtApiCompiler = async () => { };
26
20
  function uniUTSUniModulesPlugin(options = {}) {
27
- const inputDir = process.env.UNI_INPUT_DIR;
28
21
  process.env.UNI_UTS_USING_ROLLUP = 'true';
29
22
  const compilePlugin = async (pluginDir) => {
30
23
  exports.utsPlugins.add(path_1.default.basename(pluginDir));
@@ -33,16 +26,16 @@ function uniUTSUniModulesPlugin(options = {}) {
33
26
  // 如果是 provider 扩展,需要判断 provider 的宿主插件是否在本地,在的话,自动导入该宿主插件包名
34
27
  let uniExtApiProviderServicePlugin = '';
35
28
  if (extApiProvider?.servicePlugin) {
36
- if (fs_1.default.existsSync(path_1.default.resolve(inputDir, 'uni_modules', extApiProvider.servicePlugin))) {
29
+ if (fs_1.default.existsSync(path_1.default.resolve(process.env.UNI_INPUT_DIR, 'uni_modules', extApiProvider.servicePlugin))) {
37
30
  uniExtApiProviderServicePlugin = extApiProvider.servicePlugin;
38
31
  }
39
32
  }
40
33
  const compiler = (0, uts_1.resolveUTSCompiler)();
41
34
  // 处理依赖的 uts 插件
42
- const deps = (0, uni_modules_1.parseUTSModuleDeps)(pkgJson.uni_modules?.dependencies || [], inputDir);
35
+ const deps = (0, uni_modules_1.parseUTSModuleDeps)(pkgJson.uni_modules?.dependencies || [], process.env.UNI_INPUT_DIR);
43
36
  if (deps.length) {
44
37
  for (const dep of deps) {
45
- await compilePlugin(path_1.default.resolve(inputDir, 'uni_modules', dep));
38
+ await compilePlugin(path_1.default.resolve(process.env.UNI_INPUT_DIR, 'uni_modules', dep));
46
39
  }
47
40
  }
48
41
  return compiler.compile(pluginDir, {
@@ -50,7 +43,7 @@ function uniUTSUniModulesPlugin(options = {}) {
50
43
  isSingleThread: !!options.isSingleThread,
51
44
  isPlugin: true,
52
45
  extApis: options.extApis,
53
- sourceMap: (0, utils_2.enableSourceMap)(),
46
+ sourceMap: process.env.NODE_ENV === 'development',
54
47
  uni_modules: deps,
55
48
  transform: {
56
49
  uniExtApiProviderName: extApiProvider?.name,
@@ -63,7 +56,7 @@ function uniUTSUniModulesPlugin(options = {}) {
63
56
  // 获取 provider 扩展(编译所有uni)
64
57
  const plugins = (0, uni_modules_1.getUniExtApiPlugins)().filter((provider) => !exports.utsPlugins.has(provider.plugin));
65
58
  for (const plugin of plugins) {
66
- const result = await compilePlugin(path_1.default.resolve(inputDir, 'uni_modules', plugin.plugin));
59
+ const result = await compilePlugin(path_1.default.resolve(process.env.UNI_INPUT_DIR, 'uni_modules', plugin.plugin));
67
60
  if (result) {
68
61
  // 时机不对,不能addWatch
69
62
  // result.deps.forEach((dep) => {
@@ -72,37 +65,15 @@ function uniUTSUniModulesPlugin(options = {}) {
72
65
  }
73
66
  }
74
67
  };
75
- const isX = process.env.UNI_APP_X === 'true';
76
68
  return {
77
69
  name: 'uni:uts-uni_modules',
78
70
  apply: 'build',
79
71
  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
- },
95
72
  resolveId(id, importer) {
96
- if (isUTSProxy(id) || isUniHelpers(id)) {
73
+ if (isUTSProxy(id)) {
97
74
  return id;
98
75
  }
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);
76
+ const module = (0, uts_1.resolveUTSAppModule)(id, importer ? path_1.default.dirname(importer) : process.env.UNI_INPUT_DIR, options.x !== true);
106
77
  if (module) {
107
78
  // app-js 会直接返回 index.uts 路径,不需要 uts-proxy
108
79
  if (module.endsWith('.uts')) {
@@ -1,9 +1,7 @@
1
1
  import type { SFCDescriptor } from '@vue/compiler-sfc';
2
2
  import type { ExistingRawSourceMap, RollupError } from 'rollup';
3
- import type * as PostCSS from 'postcss';
4
3
  import type { Plugin } from '../plugin';
5
4
  import type { ResolvedConfig } from '../config';
6
- import type { ResolveFn } from '../';
7
5
  import * as Postcss from 'postcss';
8
6
  export interface CSSOptions {
9
7
  /**
@@ -36,21 +34,18 @@ export declare const isDirectCSSRequest: (request: string) => boolean;
36
34
  export declare function cssPlugin(config: ResolvedConfig, options?: {
37
35
  isAndroidX: boolean;
38
36
  getDescriptor?(filename: string): SFCDescriptor | undefined;
39
- createUrlReplacer?: (resolve: ResolveFn) => CssUrlReplacer;
40
37
  }): Plugin;
41
38
  /**
42
39
  * Plugin applied after user plugins
43
40
  */
44
- export declare function cssPostPlugin(config: ResolvedConfig, { platform, isJsCode, preserveModules, chunkCssFilename, chunkCssCode, includeComponentCss, }: {
41
+ export declare function cssPostPlugin(config: ResolvedConfig, { platform, isJsCode, chunkCssFilename, chunkCssCode, includeComponentCss, }: {
45
42
  platform: UniApp.PLATFORM;
46
43
  isJsCode?: boolean;
47
- preserveModules?: boolean;
48
44
  chunkCssFilename: (id: string) => string | void;
49
45
  chunkCssCode: (filename: string, cssCode: string) => Promise<string> | string;
50
46
  includeComponentCss?: boolean;
51
47
  }): Plugin;
52
48
  export declare function formatPostcssSourceMap(rawMap: ExistingRawSourceMap, file: string): ExistingRawSourceMap;
53
- export type CssUrlReplacer = (url: string, importer?: string, source?: PostCSS.Source) => string | Promise<string>;
54
49
  export declare const cssUrlRE: RegExp;
55
50
  export declare const cssDataUriRE: RegExp;
56
51
  export declare const importCssRE: RegExp;
@@ -121,30 +121,29 @@ 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 = (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
- });
124
+ const urlReplacer = async (url, importer, source) => {
125
+ if (url.startsWith('/') && !url.startsWith('//')) {
126
+ // /static/logo.png => @/static/logo.png
127
+ url = '@' + url;
128
+ }
129
+ const resolved = await wrapResolve(resolveUrl, source?.input.css || raw, source, options.getDescriptor)(url, importer);
130
+ if (resolved) {
131
+ return (0, asset_1.fileToUrl)(resolved, config, options?.isAndroidX
132
+ ? {
133
+ emitFile(emittedFile) {
134
+ const fileName = path_1.default.resolve(process.env.UNI_OUTPUT_DIR, emittedFile.fileName);
135
+ // 忽略static(可能有只读文件,写入覆盖只读会报错权限)
136
+ if ((0, utils_1.normalizePath)(fileName).includes('/static/')) {
137
+ return;
138
+ }
139
+ // 直接写入目标目录
140
+ fs_extra_1.default.outputFileSync(fileName, emittedFile.source);
141
+ },
142
+ }
143
+ : this, true);
144
+ }
145
+ return url;
146
+ };
148
147
  const { code: css, modules, deps, } = await compileCSS(id, raw, config, urlReplacer, atImportResolvers, server);
149
148
  if (modules) {
150
149
  moduleCache.set(id, modules);
@@ -200,7 +199,7 @@ function findCssModuleIds(moduleId, includeComponentCss = true, cssModuleIds, se
200
199
  /**
201
200
  * Plugin applied after user plugins
202
201
  */
203
- function cssPostPlugin(config, { platform, isJsCode, preserveModules, chunkCssFilename, chunkCssCode, includeComponentCss, }) {
202
+ function cssPostPlugin(config, { platform, isJsCode, chunkCssFilename, chunkCssCode, includeComponentCss, }) {
204
203
  // styles initialization in buildStart causes a styling loss in watch
205
204
  const styles = new Map();
206
205
  let cssChunks;
@@ -252,7 +251,7 @@ function cssPostPlugin(config, { platform, isJsCode, preserveModules, chunkCssFi
252
251
  },
253
252
  async generateBundle() {
254
253
  // app 平台页面并未 chunk,所以 renderChunk 并不会处理页面的 css,需要这里再补充查找
255
- if (platform === 'app' || preserveModules) {
254
+ if (platform === 'app') {
256
255
  const moduleIds = Array.from(this.getModuleIds());
257
256
  moduleIds.forEach((id) => {
258
257
  const filename = chunkCssFilename(id);
@@ -22,9 +22,6 @@ __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
- }
28
25
  return config.command === 'build' && config.build.cssCodeSplit;
29
26
  }
30
27
  exports.isCombineBuiltInCss = isCombineBuiltInCss;
@@ -1,5 +1,4 @@
1
- import type { Plugin, ResolveFn, ResolvedConfig } from 'vite';
2
- import { type CssUrlReplacer } from '../plugins/vitejs/plugins/css';
1
+ import type { Plugin, ResolvedConfig } from 'vite';
3
2
  export type CreateUniViteFilterPlugin = (opts: UniViteFilterPluginOptions) => Plugin;
4
3
  export interface UniViteFilterPluginOptions {
5
4
  resolvedConfig: ResolvedConfig;
@@ -8,9 +7,7 @@ export interface UniViteFilterPluginOptions {
8
7
  export declare function injectAssetPlugin(config: ResolvedConfig, options?: {
9
8
  isAndroidX: boolean;
10
9
  }): void;
11
- export declare function injectCssPlugin(config: ResolvedConfig, options?: {
12
- createUrlReplacer?: (resolve: ResolveFn) => CssUrlReplacer;
13
- }): void;
10
+ export declare function injectCssPlugin(config: ResolvedConfig): void;
14
11
  export declare function injectCssPostPlugin(config: ResolvedConfig, newCssPostPlugin: Plugin): void;
15
12
  export declare function replacePlugins(plugins: Plugin[], config: ResolvedConfig): void;
16
13
  export declare function removePlugins(plugins: string | string[], config: ResolvedConfig): void;
@@ -8,13 +8,8 @@ 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, options) {
12
- replacePlugins([
13
- (0, css_1.cssPlugin)(config, {
14
- isAndroidX: false,
15
- ...options,
16
- }),
17
- ], config);
11
+ function injectCssPlugin(config) {
12
+ replacePlugins([(0, css_1.cssPlugin)(config)], config);
18
13
  }
19
14
  exports.injectCssPlugin = injectCssPlugin;
20
15
  function injectCssPostPlugin(config, newCssPostPlugin) {
@@ -5,9 +5,6 @@ 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
- }
11
8
  if (config.command === 'serve') {
12
9
  return true;
13
10
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@dcloudio/uni-cli-shared",
3
- "version": "3.0.0-alpha-4010720240511002",
3
+ "version": "3.0.0-alpha-4010720240511003",
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-4010720240511002",
30
- "@dcloudio/uni-shared": "3.0.0-alpha-4010720240511002",
29
+ "@dcloudio/uni-i18n": "3.0.0-alpha-4010720240511003",
30
+ "@dcloudio/uni-shared": "3.0.0-alpha-4010720240511003",
31
31
  "@intlify/core-base": "9.1.9",
32
32
  "@intlify/shared": "9.1.9",
33
33
  "@intlify/vue-devtools": "9.1.9",
@@ -38,7 +38,6 @@
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",
42
41
  "autoprefixer": "^10.4.19",
43
42
  "base64url": "^3.0.1",
44
43
  "chokidar": "^3.5.3",
@@ -50,7 +49,6 @@
50
49
  "fast-glob": "^3.2.11",
51
50
  "fs-extra": "^10.0.0",
52
51
  "hash-sum": "^2.0.0",
53
- "isbinaryfile": "^5.0.2",
54
52
  "jsonc-parser": "^3.2.0",
55
53
  "lines-and-columns": "^2.0.4",
56
54
  "magic-string": "^0.30.7",
@@ -71,8 +69,7 @@
71
69
  },
72
70
  "gitHead": "33e807d66e1fe47e2ee08ad9c59247e37b8884da",
73
71
  "devDependencies": {
74
- "@dcloudio/uni-uts-v1": "3.0.0-alpha-4010720240511002",
75
- "@types/adm-zip": "^0.5.5",
72
+ "@dcloudio/uni-uts-v1": "3.0.0-alpha-4010720240511003",
76
73
  "@types/babel__code-frame": "^7.0.6",
77
74
  "@types/babel__core": "^7.1.19",
78
75
  "@types/debug": "^4.1.7",
@@ -1 +0,0 @@
1
- export {};
@@ -1,17 +0,0 @@
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
- });
@@ -1,5 +0,0 @@
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;
@@ -1,240 +0,0 @@
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
- }