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

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,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,14 @@ 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}$`] = `${importDir}/${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}?${
192
+ // android 走 proxy
193
+ process.env.UNI_APP_X === 'true' &&
194
+ process.env.UNI_UTS_PLATFORM === 'app-android'
195
+ ? 'uts-proxy'
196
+ : 'uni_helpers'}`))
197
+ : `${importDir}/${name}${ext}`;
188
198
  break;
189
199
  }
190
200
  }
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" | "vue" | "weex" | "vite";
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";
@@ -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;
@@ -43,7 +43,16 @@ exports.isUniPageSfcFile = isUniPageSfcFile;
43
43
  * @returns
44
44
  */
45
45
  const parsePagesJson = (inputDir, platform, normalize = true) => {
46
- const jsonStr = fs_1.default.readFileSync(path_1.default.join(inputDir, 'pages.json'), 'utf8');
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
- componentsLibPath = path_1.default.join(resolveWithSymlinks('@dcloudio/uni-components/package.json', process.env.UNI_INPUT_DIR), dir);
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;
@@ -70,3 +70,42 @@ 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): Record<string, string[]>;
84
+ export declare function packUploadEncryptUniModules(uniModules: Record<string, EncryptPackageJson | undefined>, platform: typeof process.env.UNI_UTS_PLATFORM, inputDir: string, cacheDir: string): {
85
+ zipFile: string;
86
+ modules: string[];
87
+ };
88
+ interface EncryptPackageJson {
89
+ id: string;
90
+ version: string;
91
+ uni_modules: {
92
+ artifacts: {
93
+ env: {
94
+ compilerVersion: string;
95
+ } & Record<string, any>;
96
+ apis: string[];
97
+ components: string[];
98
+ };
99
+ };
100
+ }
101
+ export declare function initCheckEnv(): Record<string, string>;
102
+ export declare function resolveEncryptUniModule(id: string, platform: typeof process.env.UNI_UTS_PLATFORM, isX?: boolean): string | undefined;
103
+ export declare function checkEncryptUniModules(inputDir: string, params: {
104
+ mode: 'development' | 'production';
105
+ compilerVersion: string;
106
+ appid: string;
107
+ appname: string;
108
+ platform: typeof process.env.UNI_UTS_PLATFORM;
109
+ 'uni-app-x': boolean;
110
+ }): Promise<{} | undefined>;
111
+ export {};
@@ -3,10 +3,12 @@ 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.packUploadEncryptUniModules = 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");
11
+ const utils_1 = require("./utils");
10
12
  const extApiProviders = [];
11
13
  const extApiPlugins = new Set();
12
14
  function getUniExtApiProviders() {
@@ -26,11 +28,7 @@ function getUniExtApiProviderRegisters() {
26
28
  result.push({
27
29
  name: provider.name,
28
30
  service: provider.service,
29
- class: `uts.sdk.modules.${(0, exports.camelize)(provider.plugin)}.${(0, exports.capitalize)((0, exports.camelize)('uni-ext-api-' +
30
- provider.service +
31
- '-' +
32
- provider.name +
33
- '-provider'))}`,
31
+ class: `uts.sdk.modules.${(0, exports.camelize)(provider.plugin)}.${(0, exports.capitalize)((0, exports.camelize)('uni-' + provider.service + '-' + provider.name + '-provider'))}`,
34
32
  });
35
33
  }
36
34
  });
@@ -265,3 +263,272 @@ function parseUTSModuleDeps(deps, inputDir) {
265
263
  });
266
264
  }
267
265
  exports.parseUTSModuleDeps = parseUTSModuleDeps;
266
+ function genEncryptEasyComModuleIndex(components) {
267
+ const imports = [];
268
+ const ids = [];
269
+ components.forEach((component) => {
270
+ const id = (0, exports.capitalize)((0, exports.camelize)(component));
271
+ imports.push(`import ${id} from './components/${component}/${component}.vue'`);
272
+ ids.push(id);
273
+ });
274
+ return `
275
+ ${imports.join('\n')}
276
+ export { ${ids.join(',')} }
277
+ `;
278
+ }
279
+ exports.genEncryptEasyComModuleIndex = genEncryptEasyComModuleIndex;
280
+ // 目前该函数仅在云端使用(目前仅限iOS/web),云端编译时,提交上来的uni_modules是过滤好的
281
+ function parseUniModulesWithComponents(inputDir) {
282
+ const modulesDir = path_1.default.resolve(inputDir, 'uni_modules');
283
+ const uniModules = {};
284
+ if (fs_extra_1.default.existsSync(modulesDir)) {
285
+ fs_extra_1.default.readdirSync(modulesDir).forEach((uniModuleDir) => {
286
+ if (!fs_extra_1.default.existsSync(path_1.default.resolve(modulesDir, uniModuleDir, 'package.json'))) {
287
+ return;
288
+ }
289
+ // 解析加密的 easyCom 插件列表
290
+ const components = parseEasyComComponents(uniModuleDir, inputDir, false);
291
+ uniModules[uniModuleDir] = components;
292
+ });
293
+ }
294
+ return uniModules;
295
+ }
296
+ exports.parseUniModulesWithComponents = parseUniModulesWithComponents;
297
+ /**
298
+ * 解析 easyCom 组件列表
299
+ * @param pluginId
300
+ * @param inputDir
301
+ * @returns
302
+ */
303
+ function parseEasyComComponents(pluginId, inputDir, detectBinary = true) {
304
+ const componentsDir = path_1.default.resolve(inputDir, 'uni_modules', pluginId, 'components');
305
+ const components = [];
306
+ if (fs_extra_1.default.existsSync(componentsDir)) {
307
+ fs_extra_1.default.readdirSync(componentsDir).forEach((componentDir) => {
308
+ const componentFile = path_1.default.resolve(componentsDir, componentDir, componentDir);
309
+ if (['.vue', '.uvue'].some((extname) => {
310
+ const filename = componentFile + extname;
311
+ // 探测 filename 是否是二进制文件
312
+ if (fs_extra_1.default.existsSync(filename)) {
313
+ if (detectBinary) {
314
+ // 延迟require,这个是新增的依赖,无法及时同步到内部测试版本HBuilderX中,导致报错,所以延迟require吧
315
+ if (require('isbinaryfile').isBinaryFileSync(filename)) {
316
+ return true;
317
+ }
318
+ }
319
+ else {
320
+ return true;
321
+ }
322
+ }
323
+ })) {
324
+ components.push(componentDir);
325
+ }
326
+ });
327
+ }
328
+ return components;
329
+ }
330
+ exports.parseEasyComComponents = parseEasyComComponents;
331
+ // 查找所有普通加密插件 uni_modules
332
+ function findEncryptUniModules(inputDir, cacheDir = '') {
333
+ const modulesDir = path_1.default.resolve(inputDir, 'uni_modules');
334
+ const uniModules = {};
335
+ if (fs_extra_1.default.existsSync(modulesDir)) {
336
+ fs_extra_1.default.readdirSync(modulesDir).forEach((uniModuleDir) => {
337
+ const uniModuleRootDir = path_1.default.resolve(modulesDir, uniModuleDir);
338
+ if (!fs_extra_1.default.existsSync(path_1.default.resolve(uniModuleRootDir, 'encrypt'))) {
339
+ return;
340
+ }
341
+ // 仅扫描普通加密插件,无需依赖
342
+ if (fs_extra_1.default.existsSync(path_1.default.resolve(uniModuleRootDir, 'utssdk'))) {
343
+ return;
344
+ }
345
+ const pkg = require(path_1.default.resolve(uniModuleRootDir, 'package.json'));
346
+ uniModules[uniModuleDir] = findEncryptUniModuleCache(uniModuleDir, cacheDir, { version: pkg.version, env: initCheckEnv() });
347
+ });
348
+ }
349
+ return uniModules;
350
+ }
351
+ exports.findEncryptUniModules = findEncryptUniModules;
352
+ function findUploadEncryptUniModulesFiles(uniModules, platform, inputDir) {
353
+ const modules = {};
354
+ Object.keys(uniModules).forEach((uniModuleId) => {
355
+ if (!uniModules[uniModuleId]) {
356
+ modules[uniModuleId] = findUniModuleFiles(platform, uniModuleId, inputDir);
357
+ }
358
+ });
359
+ return modules;
360
+ }
361
+ exports.findUploadEncryptUniModulesFiles = findUploadEncryptUniModulesFiles;
362
+ function packUploadEncryptUniModules(uniModules, platform, inputDir, cacheDir) {
363
+ const modules = findUploadEncryptUniModulesFiles(uniModules, platform, inputDir);
364
+ const uploadModuleIds = Object.keys(modules);
365
+ if (uploadModuleIds.length) {
366
+ // 延迟 require,避免 vue2 编译器需要安装此依赖,目前该方法仅在 vite 编译器中使用
367
+ const AdmZip = require('adm-zip');
368
+ const zip = new AdmZip();
369
+ uploadModuleIds.forEach((moduleId) => {
370
+ modules[moduleId].forEach((file) => {
371
+ zip.addLocalFile(file, path_1.default.dirname(path_1.default.relative(inputDir, file)));
372
+ });
373
+ });
374
+ const zipFile = path_1.default.resolve(cacheDir, 'cloud-compile-plugins.zip');
375
+ zip.writeZip(zipFile);
376
+ return {
377
+ zipFile,
378
+ modules: uploadModuleIds,
379
+ };
380
+ }
381
+ return {
382
+ zipFile: '',
383
+ modules: [],
384
+ };
385
+ }
386
+ exports.packUploadEncryptUniModules = packUploadEncryptUniModules;
387
+ function isEnvExpired(value, other) {
388
+ const valueKeys = Object.keys(value);
389
+ const otherKeys = Object.keys(other);
390
+ if (valueKeys.length !== otherKeys.length) {
391
+ return true;
392
+ }
393
+ if (valueKeys.find((name) => value[name] !== other[name])) {
394
+ return true;
395
+ }
396
+ return false;
397
+ }
398
+ function findEncryptUniModuleCache(uniModuleId, cacheDir, options) {
399
+ if (!cacheDir) {
400
+ return;
401
+ }
402
+ const uniModuleCacheDir = path_1.default.resolve(cacheDir, 'uni_modules', uniModuleId);
403
+ if (fs_extra_1.default.existsSync(uniModuleCacheDir)) {
404
+ const pkg = require(path_1.default.resolve(uniModuleCacheDir, 'package.json'));
405
+ // 插件版本以及各种环境一致
406
+ if (pkg.version === options.version &&
407
+ !isEnvExpired(pkg.uni_modules?.artifacts?.env || {}, options.env)) {
408
+ return pkg;
409
+ }
410
+ // 已过期的插件,删除缓存
411
+ fs_extra_1.default.rmSync(uniModuleCacheDir, { recursive: true });
412
+ }
413
+ }
414
+ const KNOWN_ASSET_TYPES = [
415
+ // images
416
+ 'png',
417
+ 'jpe?g',
418
+ 'gif',
419
+ 'svg',
420
+ 'ico',
421
+ 'webp',
422
+ 'avif',
423
+ // media
424
+ 'mp4',
425
+ 'webm',
426
+ 'ogg',
427
+ 'mp3',
428
+ 'wav',
429
+ 'flac',
430
+ 'aac',
431
+ // fonts
432
+ 'woff2?',
433
+ 'eot',
434
+ 'ttf',
435
+ 'otf',
436
+ // other
437
+ 'pdf',
438
+ 'txt',
439
+ ];
440
+ function findUniModuleFiles(platform, id, inputDir) {
441
+ return (0, fast_glob_1.sync)(`uni_modules/${id}/**/*`, {
442
+ cwd: inputDir,
443
+ absolute: true,
444
+ ignore: [
445
+ '**/*.md',
446
+ ...(platform !== 'app-android' // 非 android 平台不需要扫描 assets
447
+ ? [`**/*.{${KNOWN_ASSET_TYPES.join(',')}}`]
448
+ : []),
449
+ ],
450
+ });
451
+ }
452
+ function initCheckEnv() {
453
+ return {
454
+ // 云端编译的版本号不带日期及小版本
455
+ compilerVersion: process.env.UNI_COMPILER_VERSION,
456
+ };
457
+ }
458
+ exports.initCheckEnv = initCheckEnv;
459
+ function findLastIndex(array, predicate) {
460
+ for (let i = array.length - 1; i >= 0; i--) {
461
+ if (predicate(array[i], i, array)) {
462
+ return i;
463
+ }
464
+ }
465
+ return -1;
466
+ }
467
+ let encryptUniModules = {};
468
+ function resolveEncryptUniModule(id, platform, isX = true) {
469
+ const parts = id.split('/');
470
+ const index = findLastIndex(parts, (part) => part === 'uni_modules');
471
+ if (index !== -1) {
472
+ const uniModuleId = parts[index + 1];
473
+ if (uniModuleId in encryptUniModules) {
474
+ // 原生平台走旧的uts-proxy
475
+ return (0, utils_1.normalizePath)(path_1.default.join(process.env.UNI_INPUT_DIR, `uni_modules/${uniModuleId}?${isX && platform === 'app-android' ? 'uts-proxy' : 'uni_helpers'}`));
476
+ }
477
+ }
478
+ }
479
+ exports.resolveEncryptUniModule = resolveEncryptUniModule;
480
+ async function checkEncryptUniModules(inputDir, params) {
481
+ // 扫描加密插件云编译
482
+ encryptUniModules = findEncryptUniModules(inputDir, process.env.UNI_MODULES_ENCRYPT_CACHE_DIR);
483
+ if (!Object.keys(encryptUniModules).length) {
484
+ return {};
485
+ }
486
+ if (!process.env.UNI_HBUILDERX_PLUGINS) {
487
+ return {};
488
+ }
489
+ const cacheDir = process.env.UNI_MODULES_ENCRYPT_CACHE_DIR;
490
+ const { zipFile, modules } = packUploadEncryptUniModules(encryptUniModules, process.env.UNI_UTS_PLATFORM, inputDir, cacheDir);
491
+ if (zipFile) {
492
+ const downloadFile = path_1.default.resolve(cacheDir, 'uni_modules.download.zip');
493
+ const { C, D, R, U } = require(path_1.default.join(process.env.UNI_HBUILDERX_PLUGINS, 'uni_helpers'));
494
+ try {
495
+ const isLogin = await C();
496
+ console.log(`正在云编译插件${isLogin ? '' : '(请先登录)'}:${modules.join(',')}...`);
497
+ const downloadUrl = await U({
498
+ params,
499
+ attachment: zipFile,
500
+ });
501
+ await D(downloadUrl, downloadFile);
502
+ // unzip
503
+ const AdmZip = require('adm-zip');
504
+ const zip = new AdmZip(downloadFile);
505
+ zip.extractAllTo(cacheDir, true);
506
+ fs_extra_1.default.unlinkSync(zipFile);
507
+ fs_extra_1.default.unlinkSync(downloadFile);
508
+ R({
509
+ dir: process.env.UNI_INPUT_DIR,
510
+ cacheDir: process.env.UNI_MODULES_ENCRYPT_CACHE_DIR,
511
+ });
512
+ console.log(`云编译已完成`);
513
+ console.log(`正在编译中...`);
514
+ }
515
+ catch (e) {
516
+ fs_extra_1.default.existsSync(zipFile) && fs_extra_1.default.unlinkSync(zipFile);
517
+ fs_extra_1.default.existsSync(downloadFile) && fs_extra_1.default.unlinkSync(downloadFile);
518
+ console.error(e);
519
+ process.exit(0);
520
+ }
521
+ }
522
+ else {
523
+ // android 平台需要在这里初始化
524
+ if (params.platform === 'app-android') {
525
+ const { R } = require(path_1.default.join(process.env.UNI_HBUILDERX_PLUGINS, 'uni_helpers'));
526
+ R({
527
+ dir: process.env.UNI_INPUT_DIR,
528
+ cacheDir: process.env.UNI_MODULES_ENCRYPT_CACHE_DIR,
529
+ });
530
+ }
531
+ }
532
+ encryptUniModules = findEncryptUniModules(inputDir, process.env.UNI_MODULES_ENCRYPT_CACHE_DIR);
533
+ }
534
+ 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
- export declare function normalizeIdentifier(str: string): Capitalize<string>;
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
- return (0, shared_1.capitalize)((0, shared_1.camelize)(str.replace(/\//g, '-')));
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
+ });
@@ -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;