@dcloudio/uni-cli-shared 3.0.0-alpha-5000520260323001 → 3.0.0-alpha-5000720260416001

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.
@@ -64,30 +64,6 @@ function checkPagesJson(jsonStr, inputDir) {
64
64
  });
65
65
  }
66
66
  });
67
- const tabBarNode = root.children?.find((child) => child.type === 'property' &&
68
- child.children?.length === 2 &&
69
- child.children[0].value === 'tabBar');
70
- if (process.env.UNI_APP_X_DOM2 !== 'true' && tabBarNode) {
71
- // dom2下不支持tabBar配置项,这里先不校验
72
- let allPages = []; // 收集全部页面,包含分包页面
73
- let tabBarPages = []; // 收集 tabBar 页面
74
- allPages.push(...pagePathNodes.map((node) => node.value));
75
- findRootNode(tabBarNode.children[1], ['list']).forEach((node) => {
76
- const pagePathNode = node.type === 'object' &&
77
- node.children?.find((child) => child.type === 'property' &&
78
- child.children?.length === 2 &&
79
- child.children[0].value === 'pagePath');
80
- if (pagePathNode) {
81
- const pagePathValueNode = pagePathNode.children[1];
82
- const pagePath = pagePathValueNode.value;
83
- tabBarPages.push(pagePath);
84
- if (!allPages.includes(pagePath) &&
85
- !allPages.includes(pagePath.substring(1))) {
86
- throwCompilerError(jsonStr, pagePathValueNode, messages_1.M['pages.json.tabbar.page.notfound'].replace('{pagePath}', pagePath));
87
- }
88
- }
89
- });
90
- }
91
67
  for (const node of pagePathNodes) {
92
68
  const pagePath = node.value ?? '';
93
69
  if (!pageExistsWithCaseSync(path_1.default.join(inputDir, pagePath))) {
@@ -48,6 +48,5 @@ declare const _default: {
48
48
  readonly 'uni_modules.import': "Plug-in [{0}] only supports @/uni_modules/{1}.";
49
49
  readonly 'pages.json.page.notfound': "The page \"{pagePath}\" does not exist.";
50
50
  readonly 'pages.json.page.slash': "The Path \"{pagePath}\" cannot start with \"/\"";
51
- readonly 'pages.json.tabbar.page.notfound': "The tabBar page \"{pagePath}\" is not declared in \"pages.json\".";
52
51
  };
53
52
  export default _default;
@@ -50,5 +50,4 @@ exports.default = {
50
50
  'uni_modules.import': 'Plug-in [{0}] only supports @/uni_modules/{1}.',
51
51
  'pages.json.page.notfound': 'The page "{pagePath}" does not exist.',
52
52
  'pages.json.page.slash': 'The Path "{pagePath}" cannot start with "/"',
53
- 'pages.json.tabbar.page.notfound': 'The tabBar page "{pagePath}" is not declared in "pages.json".',
54
53
  };
@@ -48,7 +48,6 @@ export declare const M: {
48
48
  readonly 'uni_modules.import': "插件[{0}]仅支持 @/uni_modules/{1} 方式引入,不支持直接导入内部文件 {2}。";
49
49
  readonly 'pages.json.page.notfound': "页面\"{pagePath}\"不存在,请确保填写的页面路径不包含文件后缀,且必须与真实的文件路径大小写保持一致。";
50
50
  readonly 'pages.json.page.slash': "路径 \"{pagePath}\" 不能以 \"/\" 开头";
51
- readonly 'pages.json.tabbar.page.notfound': "tabBar 中配置的页面 \"{pagePath}\" 未在 pages.json 中注册。";
52
51
  } | {
53
52
  readonly 'app.compiler.version': "Compiler version: {version}";
54
53
  readonly compiling: "Compiling...";
@@ -99,5 +98,4 @@ export declare const M: {
99
98
  readonly 'uni_modules.import': "Plug-in [{0}] only supports @/uni_modules/{1}.";
100
99
  readonly 'pages.json.page.notfound': "The page \"{pagePath}\" does not exist.";
101
100
  readonly 'pages.json.page.slash': "The Path \"{pagePath}\" cannot start with \"/\"";
102
- readonly 'pages.json.tabbar.page.notfound': "The tabBar page \"{pagePath}\" is not declared in \"pages.json\".";
103
101
  };
@@ -48,6 +48,5 @@ declare const _default: {
48
48
  readonly 'uni_modules.import': "插件[{0}]仅支持 @/uni_modules/{1} 方式引入,不支持直接导入内部文件 {2}。";
49
49
  readonly 'pages.json.page.notfound': "页面\"{pagePath}\"不存在,请确保填写的页面路径不包含文件后缀,且必须与真实的文件路径大小写保持一致。";
50
50
  readonly 'pages.json.page.slash': "路径 \"{pagePath}\" 不能以 \"/\" 开头";
51
- readonly 'pages.json.tabbar.page.notfound': "tabBar 中配置的页面 \"{pagePath}\" 未在 pages.json 中注册。";
52
51
  };
53
52
  export default _default;
@@ -51,5 +51,4 @@ exports.default = {
51
51
  'uni_modules.import': '插件[{0}]仅支持 @/uni_modules/{1} 方式引入,不支持直接导入内部文件 {2}。',
52
52
  'pages.json.page.notfound': '页面"{pagePath}"不存在,请确保填写的页面路径不包含文件后缀,且必须与真实的文件路径大小写保持一致。',
53
53
  'pages.json.page.slash': '路径 "{pagePath}" 不能以 "/" 开头',
54
- 'pages.json.tabbar.page.notfound': 'tabBar 中配置的页面 "{pagePath}" 未在 pages.json 中注册。',
55
54
  };
@@ -9,19 +9,86 @@ const json_1 = require("../../json");
9
9
  const preprocess_1 = require("../../preprocess");
10
10
  const utils_1 = require("../utils");
11
11
  function uniJsonPlugin() {
12
+ const UTS_CAST_ARRAY_MARKER = '/*__UTS_CAST_UTSJSON_ARRAY__*/';
13
+ const UTS_CAST_OBJECT_MARKER = '/*__UTS_CAST_UTSJSON_OBJECT__*/';
14
+ const IS_UNI_X_ANDROID = process.env.UNI_APP_X === 'true' &&
15
+ process.env.UNI_UTS_PLATFORM === 'app-android';
12
16
  return {
13
17
  name: 'uni:json',
14
18
  enforce: 'pre',
19
+ generateBundle(options, bundle) {
20
+ if (IS_UNI_X_ANDROID) {
21
+ for (const [fileName, file] of Object.entries(bundle)) {
22
+ if (fileName.endsWith('.json.ts')) {
23
+ if (file.type === 'asset' && file.source) {
24
+ const source = file.source.toString();
25
+ if (source.includes(UTS_CAST_ARRAY_MARKER) ||
26
+ source.includes(UTS_CAST_OBJECT_MARKER)) {
27
+ file.source = source
28
+ .replace(new RegExp(UTS_CAST_ARRAY_MARKER.replace(/[.*+?^${}()|[\]\\]/g, '\\$&'), 'g'), ' as UTSJSONObject[]')
29
+ .replace(new RegExp(UTS_CAST_OBJECT_MARKER.replace(/[.*+?^${}()|[\]\\]/g, '\\$&'), 'g'), ' as UTSJSONObject');
30
+ }
31
+ }
32
+ }
33
+ }
34
+ }
35
+ },
15
36
  transform(code, id) {
16
37
  // 如果已经被其他插件处理过了,就不再处理,比如 commonjs 插件,ICAPRegistrar.json?commonjs-external
17
38
  if (id.startsWith('\0')) {
18
39
  return;
19
40
  }
20
- if (path_1.default.extname((0, utils_1.parseVueRequest)(id).filename) !== '.json') {
41
+ const { filename } = (0, utils_1.parseVueRequest)(id);
42
+ if (path_1.default.extname(filename) !== '.json') {
21
43
  return;
22
44
  }
45
+ let codeObj = (0, json_1.parseJson)((0, preprocess_1.preJson)(code, id), false, id);
46
+ let codeJson = '';
47
+ if (IS_UNI_X_ANDROID) {
48
+ if (Array.isArray(codeObj)) {
49
+ codeJson +=
50
+ 'export default JSON.parseArray(`' +
51
+ JSON.stringify(codeObj, null, 2) +
52
+ '`)' +
53
+ UTS_CAST_ARRAY_MARKER +
54
+ ';\n';
55
+ }
56
+ else {
57
+ codeJson +=
58
+ 'let __jsonObj = JSON.parseObject(`' +
59
+ JSON.stringify(codeObj, null, 2) +
60
+ '`);\n';
61
+ for (const key in codeObj) {
62
+ if (!Object.hasOwn(codeObj, key))
63
+ continue;
64
+ const element = codeObj[key];
65
+ if (Array.isArray(element)) {
66
+ codeJson += `export const ${key} = __jsonObj?.getArray("${key}")${UTS_CAST_ARRAY_MARKER};\n`;
67
+ }
68
+ else if (typeof element === 'object' && element !== null) {
69
+ codeJson += `export const ${key} = __jsonObj?.get("${key}")${UTS_CAST_OBJECT_MARKER};\n`;
70
+ }
71
+ else if (typeof element === 'string') {
72
+ codeJson += `export const ${key} = __jsonObj?.getString("${key}") ?? '';\n`;
73
+ }
74
+ else if (typeof element === 'number') {
75
+ codeJson += `export const ${key} = __jsonObj?.getNumber("${key}") ?? 0;\n`;
76
+ }
77
+ else if (typeof element === 'boolean') {
78
+ codeJson += `export const ${key} = __jsonObj?.getBoolean("${key}") ?? false;\n`;
79
+ }
80
+ else {
81
+ codeJson += `export const ${key} = __jsonObj?.get("${key}")${UTS_CAST_OBJECT_MARKER};\n`;
82
+ }
83
+ }
84
+ codeJson += `export default __jsonObj;`;
85
+ }
86
+ }
87
+ else {
88
+ codeJson = JSON.stringify(codeObj, null, 2);
89
+ }
23
90
  return {
24
- code: JSON.stringify((0, json_1.parseJson)((0, preprocess_1.preJson)(code, id), false, id), null, 2),
91
+ code: codeJson,
25
92
  map: {
26
93
  mappings: '',
27
94
  },
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@dcloudio/uni-cli-shared",
3
- "version": "3.0.0-alpha-5000520260323001",
3
+ "version": "3.0.0-alpha-5000720260416001",
4
4
  "description": "@dcloudio/uni-cli-shared",
5
5
  "main": "dist/index.js",
6
6
  "types": "dist/index.d.ts",
@@ -69,9 +69,9 @@
69
69
  "unimport": "4.1.1",
70
70
  "unplugin-auto-import": "19.1.0",
71
71
  "xregexp": "5.1.2",
72
- "@dcloudio/uni-nvue-styler": "3.0.0-alpha-5000520260323001",
73
- "@dcloudio/uni-i18n": "3.0.0-alpha-5000520260323001",
74
- "@dcloudio/uni-shared": "3.0.0-alpha-5000520260323001"
72
+ "@dcloudio/uni-nvue-styler": "3.0.0-alpha-5000720260416001",
73
+ "@dcloudio/uni-shared": "3.0.0-alpha-5000720260416001",
74
+ "@dcloudio/uni-i18n": "3.0.0-alpha-5000720260416001"
75
75
  },
76
76
  "gitHead": "33e807d66e1fe47e2ee08ad9c59247e37b8884da",
77
77
  "devDependencies": {
@@ -91,6 +91,6 @@
91
91
  "code-frame": "link:@types/@babel/code-frame",
92
92
  "postcss": "8.4.45",
93
93
  "vue": "3.4.21",
94
- "@dcloudio/uni-uts-v1": "3.0.0-alpha-5000520260323001"
94
+ "@dcloudio/uni-uts-v1": "3.0.0-alpha-5000720260416001"
95
95
  }
96
96
  }