@dcloudio/uni-cli-shared 3.0.0-4020420240722003 → 3.0.0-4020920240930001

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/LICENSE ADDED
@@ -0,0 +1,202 @@
1
+
2
+ Apache License
3
+ Version 2.0, January 2004
4
+ http://www.apache.org/licenses/
5
+
6
+ TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
7
+
8
+ 1. Definitions.
9
+
10
+ "License" shall mean the terms and conditions for use, reproduction,
11
+ and distribution as defined by Sections 1 through 9 of this document.
12
+
13
+ "Licensor" shall mean the copyright owner or entity authorized by
14
+ the copyright owner that is granting the License.
15
+
16
+ "Legal Entity" shall mean the union of the acting entity and all
17
+ other entities that control, are controlled by, or are under common
18
+ control with that entity. For the purposes of this definition,
19
+ "control" means (i) the power, direct or indirect, to cause the
20
+ direction or management of such entity, whether by contract or
21
+ otherwise, or (ii) ownership of fifty percent (50%) or more of the
22
+ outstanding shares, or (iii) beneficial ownership of such entity.
23
+
24
+ "You" (or "Your") shall mean an individual or Legal Entity
25
+ exercising permissions granted by this License.
26
+
27
+ "Source" form shall mean the preferred form for making modifications,
28
+ including but not limited to software source code, documentation
29
+ source, and configuration files.
30
+
31
+ "Object" form shall mean any form resulting from mechanical
32
+ transformation or translation of a Source form, including but
33
+ not limited to compiled object code, generated documentation,
34
+ and conversions to other media types.
35
+
36
+ "Work" shall mean the work of authorship, whether in Source or
37
+ Object form, made available under the License, as indicated by a
38
+ copyright notice that is included in or attached to the work
39
+ (an example is provided in the Appendix below).
40
+
41
+ "Derivative Works" shall mean any work, whether in Source or Object
42
+ form, that is based on (or derived from) the Work and for which the
43
+ editorial revisions, annotations, elaborations, or other modifications
44
+ represent, as a whole, an original work of authorship. For the purposes
45
+ of this License, Derivative Works shall not include works that remain
46
+ separable from, or merely link (or bind by name) to the interfaces of,
47
+ the Work and Derivative Works thereof.
48
+
49
+ "Contribution" shall mean any work of authorship, including
50
+ the original version of the Work and any modifications or additions
51
+ to that Work or Derivative Works thereof, that is intentionally
52
+ submitted to Licensor for inclusion in the Work by the copyright owner
53
+ or by an individual or Legal Entity authorized to submit on behalf of
54
+ the copyright owner. For the purposes of this definition, "submitted"
55
+ means any form of electronic, verbal, or written communication sent
56
+ to the Licensor or its representatives, including but not limited to
57
+ communication on electronic mailing lists, source code control systems,
58
+ and issue tracking systems that are managed by, or on behalf of, the
59
+ Licensor for the purpose of discussing and improving the Work, but
60
+ excluding communication that is conspicuously marked or otherwise
61
+ designated in writing by the copyright owner as "Not a Contribution."
62
+
63
+ "Contributor" shall mean Licensor and any individual or Legal Entity
64
+ on behalf of whom a Contribution has been received by Licensor and
65
+ subsequently incorporated within the Work.
66
+
67
+ 2. Grant of Copyright License. Subject to the terms and conditions of
68
+ this License, each Contributor hereby grants to You a perpetual,
69
+ worldwide, non-exclusive, no-charge, royalty-free, irrevocable
70
+ copyright license to reproduce, prepare Derivative Works of,
71
+ publicly display, publicly perform, sublicense, and distribute the
72
+ Work and such Derivative Works in Source or Object form.
73
+
74
+ 3. Grant of Patent License. Subject to the terms and conditions of
75
+ this License, each Contributor hereby grants to You a perpetual,
76
+ worldwide, non-exclusive, no-charge, royalty-free, irrevocable
77
+ (except as stated in this section) patent license to make, have made,
78
+ use, offer to sell, sell, import, and otherwise transfer the Work,
79
+ where such license applies only to those patent claims licensable
80
+ by such Contributor that are necessarily infringed by their
81
+ Contribution(s) alone or by combination of their Contribution(s)
82
+ with the Work to which such Contribution(s) was submitted. If You
83
+ institute patent litigation against any entity (including a
84
+ cross-claim or counterclaim in a lawsuit) alleging that the Work
85
+ or a Contribution incorporated within the Work constitutes direct
86
+ or contributory patent infringement, then any patent licenses
87
+ granted to You under this License for that Work shall terminate
88
+ as of the date such litigation is filed.
89
+
90
+ 4. Redistribution. You may reproduce and distribute copies of the
91
+ Work or Derivative Works thereof in any medium, with or without
92
+ modifications, and in Source or Object form, provided that You
93
+ meet the following conditions:
94
+
95
+ (a) You must give any other recipients of the Work or
96
+ Derivative Works a copy of this License; and
97
+
98
+ (b) You must cause any modified files to carry prominent notices
99
+ stating that You changed the files; and
100
+
101
+ (c) You must retain, in the Source form of any Derivative Works
102
+ that You distribute, all copyright, patent, trademark, and
103
+ attribution notices from the Source form of the Work,
104
+ excluding those notices that do not pertain to any part of
105
+ the Derivative Works; and
106
+
107
+ (d) If the Work includes a "NOTICE" text file as part of its
108
+ distribution, then any Derivative Works that You distribute must
109
+ include a readable copy of the attribution notices contained
110
+ within such NOTICE file, excluding those notices that do not
111
+ pertain to any part of the Derivative Works, in at least one
112
+ of the following places: within a NOTICE text file distributed
113
+ as part of the Derivative Works; within the Source form or
114
+ documentation, if provided along with the Derivative Works; or,
115
+ within a display generated by the Derivative Works, if and
116
+ wherever such third-party notices normally appear. The contents
117
+ of the NOTICE file are for informational purposes only and
118
+ do not modify the License. You may add Your own attribution
119
+ notices within Derivative Works that You distribute, alongside
120
+ or as an addendum to the NOTICE text from the Work, provided
121
+ that such additional attribution notices cannot be construed
122
+ as modifying the License.
123
+
124
+ You may add Your own copyright statement to Your modifications and
125
+ may provide additional or different license terms and conditions
126
+ for use, reproduction, or distribution of Your modifications, or
127
+ for any such Derivative Works as a whole, provided Your use,
128
+ reproduction, and distribution of the Work otherwise complies with
129
+ the conditions stated in this License.
130
+
131
+ 5. Submission of Contributions. Unless You explicitly state otherwise,
132
+ any Contribution intentionally submitted for inclusion in the Work
133
+ by You to the Licensor shall be under the terms and conditions of
134
+ this License, without any additional terms or conditions.
135
+ Notwithstanding the above, nothing herein shall supersede or modify
136
+ the terms of any separate license agreement you may have executed
137
+ with Licensor regarding such Contributions.
138
+
139
+ 6. Trademarks. This License does not grant permission to use the trade
140
+ names, trademarks, service marks, or product names of the Licensor,
141
+ except as required for reasonable and customary use in describing the
142
+ origin of the Work and reproducing the content of the NOTICE file.
143
+
144
+ 7. Disclaimer of Warranty. Unless required by applicable law or
145
+ agreed to in writing, Licensor provides the Work (and each
146
+ Contributor provides its Contributions) on an "AS IS" BASIS,
147
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
148
+ implied, including, without limitation, any warranties or conditions
149
+ of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
150
+ PARTICULAR PURPOSE. You are solely responsible for determining the
151
+ appropriateness of using or redistributing the Work and assume any
152
+ risks associated with Your exercise of permissions under this License.
153
+
154
+ 8. Limitation of Liability. In no event and under no legal theory,
155
+ whether in tort (including negligence), contract, or otherwise,
156
+ unless required by applicable law (such as deliberate and grossly
157
+ negligent acts) or agreed to in writing, shall any Contributor be
158
+ liable to You for damages, including any direct, indirect, special,
159
+ incidental, or consequential damages of any character arising as a
160
+ result of this License or out of the use or inability to use the
161
+ Work (including but not limited to damages for loss of goodwill,
162
+ work stoppage, computer failure or malfunction, or any and all
163
+ other commercial damages or losses), even if such Contributor
164
+ has been advised of the possibility of such damages.
165
+
166
+ 9. Accepting Warranty or Additional Liability. While redistributing
167
+ the Work or Derivative Works thereof, You may choose to offer,
168
+ and charge a fee for, acceptance of support, warranty, indemnity,
169
+ or other liability obligations and/or rights consistent with this
170
+ License. However, in accepting such obligations, You may act only
171
+ on Your own behalf and on Your sole responsibility, not on behalf
172
+ of any other Contributor, and only if You agree to indemnify,
173
+ defend, and hold each Contributor harmless for any liability
174
+ incurred by, or claims asserted against, such Contributor by reason
175
+ of your accepting any such warranty or additional liability.
176
+
177
+ END OF TERMS AND CONDITIONS
178
+
179
+ APPENDIX: How to apply the Apache License to your work.
180
+
181
+ To apply the Apache License to your work, attach the following
182
+ boilerplate notice, with the fields enclosed by brackets "[]"
183
+ replaced with your own identifying information. (Don't include
184
+ the brackets!) The text should be enclosed in the appropriate
185
+ comment syntax for the file format. We also recommend that a
186
+ file or class name and description of purpose be included on the
187
+ same "printed page" as the copyright notice for easier
188
+ identification within third-party archives.
189
+
190
+ Copyright [yyyy] [name of copyright owner]
191
+
192
+ Licensed under the Apache License, Version 2.0 (the "License");
193
+ you may not use this file except in compliance with the License.
194
+ You may obtain a copy of the License at
195
+
196
+ http://www.apache.org/licenses/LICENSE-2.0
197
+
198
+ Unless required by applicable law or agreed to in writing, software
199
+ distributed under the License is distributed on an "AS IS" BASIS,
200
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
201
+ See the License for the specific language governing permissions and
202
+ limitations under the License.
package/dist/easycom.js CHANGED
@@ -115,20 +115,13 @@ function initEasycom({ isX, dirs, rootDir, custom, extensions, }) {
115
115
  if (path_1.default.isAbsolute(source) && source.startsWith(rootDir)) {
116
116
  source = '@/' + (0, utils_1.normalizePath)(path_1.default.relative(rootDir, source));
117
117
  }
118
- let imported = '';
119
118
  // 加密插件easycom类型导入
120
119
  if (source.includes('?uts-proxy')) {
121
120
  const moduleId = path_1.default.basename(source.split('?uts-proxy')[0]);
122
121
  source = `uts.sdk.modules.${(0, shared_1.camelize)(moduleId)}`;
123
- imported = genUTSComponentPublicInstanceImported(rootDir, `@/uni_modules/${moduleId}/components/${tagName}/${tagName}`);
124
122
  }
125
- else {
126
- imported = genUTSComponentPublicInstanceImported(rootDir, source);
127
- }
128
- addUTSEasyComAutoImports(source, [
129
- imported,
130
- genUTSComponentPublicInstanceIdent(tagName),
131
- ]);
123
+ const ident = genUTSComponentPublicInstanceIdent(tagName);
124
+ addUTSEasyComAutoImports(source, [ident, ident]);
132
125
  });
133
126
  }
134
127
  (0, shared_1.extend)(easycomsObj, autoEasyComObj);
@@ -30,6 +30,7 @@ export declare function getRouterOptions(manifestJson: Record<string, any>): {
30
30
  };
31
31
  export declare function isEnableTreeShaking(manifestJson: Record<string, any>): boolean;
32
32
  export declare function getDevServerOptions(manifestJson: Record<string, any>): any;
33
+ export declare function getPlatformManifestJson(manifestJson: any, platform?: UniApp.PLATFORM): any;
33
34
  export declare function getPlatformManifestJsonOnce(): any;
34
35
  export declare function validateThemeValue(value: string): boolean;
35
36
  export {};
@@ -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.validateThemeValue = exports.getPlatformManifestJsonOnce = exports.getDevServerOptions = exports.isEnableTreeShaking = exports.getRouterOptions = exports.isUniPushOffline = exports.hasPushModule = exports.isEnableSecureNetwork = exports.isEnableUniPushV2 = exports.isEnableUniPushV1 = exports.getUniStatistics = exports.normalizeNetworkTimeout = exports.parseCompatConfigOnce = exports.parseRpx2UnitOnce = exports.parseManifestJsonOnce = exports.parseManifestJson = void 0;
6
+ exports.validateThemeValue = exports.getPlatformManifestJsonOnce = exports.getPlatformManifestJson = exports.getDevServerOptions = exports.isEnableTreeShaking = exports.getRouterOptions = exports.isUniPushOffline = exports.hasPushModule = exports.isEnableSecureNetwork = exports.isEnableUniPushV2 = exports.isEnableUniPushV1 = exports.getUniStatistics = exports.normalizeNetworkTimeout = exports.parseCompatConfigOnce = exports.parseRpx2UnitOnce = exports.parseManifestJsonOnce = exports.parseManifestJson = void 0;
7
7
  const fs_1 = __importDefault(require("fs"));
8
8
  const path_1 = __importDefault(require("path"));
9
9
  const shared_1 = require("@vue/shared");
@@ -24,7 +24,8 @@ exports.parseRpx2UnitOnce = (0, uni_shared_1.once)((inputDir, platform = 'h5') =
24
24
  const rpx2unit = platform === 'h5' || platform === 'app' || platform === 'app-harmony'
25
25
  ? uni_shared_1.defaultRpx2Unit
26
26
  : uni_shared_1.defaultMiniProgramRpx2Unit;
27
- const platformOptions = (0, exports.parseManifestJsonOnce)(inputDir)[platform];
27
+ const manifestJson = (0, exports.parseManifestJsonOnce)(inputDir);
28
+ let platformOptions = getPlatformManifestJson(manifestJson, platform);
28
29
  if (platformOptions && platformOptions.rpx) {
29
30
  return (0, shared_1.extend)({}, rpx2unit, platformOptions);
30
31
  }
@@ -50,10 +51,8 @@ function normalizeNetworkTimeout(networkTimeout) {
50
51
  exports.normalizeNetworkTimeout = normalizeNetworkTimeout;
51
52
  function getUniStatistics(inputDir, platform) {
52
53
  const manifest = (0, exports.parseManifestJsonOnce)(inputDir);
53
- if (platform === 'app') {
54
- platform = 'app-plus';
55
- }
56
- return (0, shared_1.extend)({}, manifest.uniStatistics, manifest[platform] && manifest[platform].uniStatistics);
54
+ let platformManifest = getPlatformManifestJson(manifest, platform);
55
+ return (0, shared_1.extend)({}, manifest.uniStatistics, platformManifest && platformManifest.uniStatistics);
57
56
  }
58
57
  exports.getUniStatistics = getUniStatistics;
59
58
  function isEnableUniPushV1(inputDir, platform) {
@@ -72,19 +71,20 @@ function isEnableUniPushV1(inputDir, platform) {
72
71
  exports.isEnableUniPushV1 = isEnableUniPushV1;
73
72
  function isEnableUniPushV2(inputDir, platform) {
74
73
  const manifest = (0, exports.parseManifestJsonOnce)(inputDir);
74
+ const platformManifest = getPlatformManifestJson(manifest, platform);
75
75
  if (platform === 'app') {
76
- return (manifest['app-plus']?.distribute?.sdkConfigs?.push?.unipush?.version ==
77
- '2');
76
+ return (platformManifest?.distribute?.sdkConfigs?.push?.unipush?.version == '2');
78
77
  }
79
- return manifest[platform]?.unipush?.enable === true;
78
+ return platformManifest?.unipush?.enable === true;
80
79
  }
81
80
  exports.isEnableUniPushV2 = isEnableUniPushV2;
82
81
  function isEnableSecureNetwork(inputDir, platform) {
83
82
  const manifest = (0, exports.parseManifestJsonOnce)(inputDir);
83
+ const platformManifest = getPlatformManifestJson(manifest, platform);
84
84
  if (platform === 'app') {
85
- return !!manifest['app-plus']?.modules?.SecureNetwork;
85
+ return !!platformManifest?.modules?.SecureNetwork;
86
86
  }
87
- return manifest[platform]?.secureNetwork?.enable === true;
87
+ return platformManifest?.secureNetwork?.enable === true;
88
88
  }
89
89
  exports.isEnableSecureNetwork = isEnableSecureNetwork;
90
90
  function hasPushModule(inputDir) {
@@ -99,7 +99,7 @@ function isUniPushOffline(inputDir) {
99
99
  }
100
100
  exports.isUniPushOffline = isUniPushOffline;
101
101
  function getRouterOptions(manifestJson) {
102
- return (0, shared_1.extend)({}, manifestJson.h5?.router);
102
+ return (0, shared_1.extend)({}, getPlatformManifestJson(manifestJson, 'h5')?.router);
103
103
  }
104
104
  exports.getRouterOptions = getRouterOptions;
105
105
  function isEnableTreeShaking(manifestJson) {
@@ -107,18 +107,33 @@ function isEnableTreeShaking(manifestJson) {
107
107
  if (process.env.UNI_AUTOMATOR_WS_ENDPOINT) {
108
108
  return false;
109
109
  }
110
- return manifestJson.h5?.optimization?.treeShaking?.enable !== false;
110
+ const platformManifest = getPlatformManifestJson(manifestJson, 'h5');
111
+ return platformManifest?.optimization?.treeShaking?.enable !== false;
111
112
  }
112
113
  exports.isEnableTreeShaking = isEnableTreeShaking;
113
114
  function getDevServerOptions(manifestJson) {
114
- return (0, shared_1.extend)({}, manifestJson.h5?.devServer);
115
+ const platformManifest = getPlatformManifestJson(manifestJson, 'h5');
116
+ return (0, shared_1.extend)({}, platformManifest?.devServer);
115
117
  }
116
118
  exports.getDevServerOptions = getDevServerOptions;
119
+ function getPlatformManifestJson(manifestJson, platform) {
120
+ if (!platform) {
121
+ platform = process.env.UNI_PLATFORM;
122
+ }
123
+ if (platform === 'app') {
124
+ return manifestJson['app-plus'] || manifestJson['plus'] || {};
125
+ }
126
+ if (platform === 'h5') {
127
+ return manifestJson.web || manifestJson.h5 || {};
128
+ }
129
+ return manifestJson[platform] || {};
130
+ }
131
+ exports.getPlatformManifestJson = getPlatformManifestJson;
117
132
  function getPlatformManifestJsonOnce() {
118
- const platform = process.env.UNI_PLATFORM === 'app' ? 'app-plus' : process.env.UNI_PLATFORM;
119
- return !process.env.UNI_INPUT_DIR
133
+ const manifestJson = !process.env.UNI_INPUT_DIR
120
134
  ? {}
121
- : (0, exports.parseManifestJsonOnce)(process.env.UNI_INPUT_DIR)[platform] || {};
135
+ : (0, exports.parseManifestJsonOnce)(process.env.UNI_INPUT_DIR);
136
+ return getPlatformManifestJson(manifestJson);
122
137
  }
123
138
  exports.getPlatformManifestJsonOnce = getPlatformManifestJsonOnce;
124
139
  const themeValues = ['dark', 'light', 'auto'];
@@ -1,4 +1,4 @@
1
1
  export * from './jsonFile';
2
- export { AppJson, ComponentJson } from './types';
2
+ export { AppJson, ComponentJson, MiniProgramComponentsType } from './types';
3
3
  export { mergeMiniProgramAppJson, parseMiniProgramPagesJson } from './pages';
4
4
  export { parseMiniProgramProjectJson } from './project';
@@ -1,4 +1,4 @@
1
- import type { ComponentJson, PageWindowOptions, UsingComponents } from './types';
1
+ import type { ComponentJson, MiniProgramComponentsType, PageWindowOptions, UsingComponents } from './types';
2
2
  export declare function isMiniProgramPageFile(file: string, inputDir?: string): boolean;
3
3
  export declare function isMiniProgramPageSfcFile(file: string, inputDir?: string): boolean;
4
4
  export declare function hasJsonFile(filename: string): boolean;
@@ -17,11 +17,12 @@ export declare function isMiniProgramUsingComponent(name: string, options: {
17
17
  componentsDir?: string;
18
18
  }): boolean;
19
19
  interface MiniProgramComponents {
20
- [name: string]: 'plugin' | 'component' | 'dynamicLib' | 'ext';
20
+ [name: string]: MiniProgramComponentsType;
21
21
  }
22
22
  export declare function findMiniProgramUsingComponents({ filename, inputDir, componentsDir, }: {
23
23
  filename: string;
24
24
  inputDir: string;
25
25
  componentsDir?: string;
26
26
  }): MiniProgramComponents;
27
+ export declare function findUsingComponentsJson(pathInpages: string, componentsDir: string): Record<any, any>;
27
28
  export {};
@@ -3,8 +3,9 @@ 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.findMiniProgramUsingComponents = exports.isMiniProgramUsingComponent = exports.addMiniProgramUsingComponents = exports.addMiniProgramComponentJson = exports.addMiniProgramPageJson = exports.addMiniProgramAppJson = exports.findChangedJsonFiles = exports.normalizeJsonFilename = exports.findUsingComponents = exports.findJsonFile = exports.getComponentJsonFilenames = exports.hasJsonFile = exports.isMiniProgramPageSfcFile = exports.isMiniProgramPageFile = void 0;
6
+ exports.findUsingComponentsJson = exports.findMiniProgramUsingComponents = exports.isMiniProgramUsingComponent = exports.addMiniProgramUsingComponents = exports.addMiniProgramComponentJson = exports.addMiniProgramPageJson = exports.addMiniProgramAppJson = exports.findChangedJsonFiles = exports.normalizeJsonFilename = exports.findUsingComponents = exports.findJsonFile = exports.getComponentJsonFilenames = exports.hasJsonFile = exports.isMiniProgramPageSfcFile = exports.isMiniProgramPageFile = void 0;
7
7
  const path_1 = __importDefault(require("path"));
8
+ const fs_1 = __importDefault(require("fs"));
8
9
  const shared_1 = require("@vue/shared");
9
10
  const utils_1 = require("../../utils");
10
11
  const resolve_1 = require("../../resolve");
@@ -152,9 +153,39 @@ function findMiniProgramUsingComponent(usingComponents, componentsDir) {
152
153
  // mp-toutiao
153
154
  res[name] = 'ext';
154
155
  }
156
+ else if (componentsDir &&
157
+ path.includes(componentsDir + '/') &&
158
+ findUsingComponentsJson(path, componentsDir).renderer === 'xr-frame') {
159
+ // mp-weixin & x-frame
160
+ res[name] = 'xr-frame';
161
+ }
155
162
  else if (componentsDir && path.includes(componentsDir + '/')) {
156
163
  res[name] = 'component';
157
164
  }
158
165
  return res;
159
166
  }, {});
160
167
  }
168
+ function findUsingComponentsJson(pathInpages, componentsDir) {
169
+ // 兼容test case
170
+ if (!process.env.UNI_INPUT_DIR)
171
+ return {};
172
+ let [, dir] = pathInpages.split(componentsDir);
173
+ if (dir === '') {
174
+ console.warn(`${pathInpages} 路径里没有找到对应的 ${componentsDir} 目录`);
175
+ return {};
176
+ }
177
+ dir = '.' + dir;
178
+ const fulldir = path_1.default.resolve(process.env.UNI_INPUT_DIR, componentsDir, dir);
179
+ let filename = path_1.default.parse(pathInpages).name + '.json';
180
+ let jsonPath = path_1.default.resolve(fulldir, filename);
181
+ if (fs_1.default.existsSync(jsonPath)) {
182
+ return require(jsonPath);
183
+ }
184
+ jsonPath = path_1.default.resolve(fulldir, 'index.json');
185
+ if (fs_1.default.existsSync(jsonPath)) {
186
+ return require(jsonPath);
187
+ }
188
+ console.warn(`${pathInpages} 路径下没有找到对应的json文件`);
189
+ return {};
190
+ }
191
+ exports.findUsingComponentsJson = findUsingComponentsJson;
@@ -119,4 +119,5 @@ export interface AppJson {
119
119
  restartStrategy?: RestartStrategy;
120
120
  [name: string]: unknown;
121
121
  }
122
+ export type MiniProgramComponentsType = 'plugin' | 'component' | 'dynamicLib' | 'ext' | 'xr-frame';
122
123
  export {};
@@ -377,14 +377,12 @@ const DEFAULT_TAB_BAR = {
377
377
  iconWidth: '24px',
378
378
  spacing: '3px',
379
379
  height: uni_shared_1.TABBAR_HEIGHT + 'px',
380
+ list: [],
380
381
  };
381
382
  function normalizeTabBar(tabBar, platform) {
382
- const { list, midButton } = tabBar;
383
- if (!list || !list.length) {
384
- return;
385
- }
383
+ const { midButton } = tabBar;
386
384
  tabBar = (0, shared_1.extend)({}, DEFAULT_TAB_BAR, tabBar);
387
- list.forEach((item) => {
385
+ tabBar.list.forEach((item) => {
388
386
  if (item.iconPath) {
389
387
  item.iconPath = normalizeFilepath(item.iconPath);
390
388
  }
@@ -8,6 +8,7 @@ const fs_1 = __importDefault(require("fs"));
8
8
  const path_1 = __importDefault(require("path"));
9
9
  const json_1 = require("./json");
10
10
  const uni_shared_1 = require("@dcloudio/uni-shared");
11
+ const manifest_1 = require("./manifest");
11
12
  function hasThemeJson(themeLocation) {
12
13
  if (!fs_1.default.existsSync(themeLocation)) {
13
14
  return false;
@@ -47,7 +48,7 @@ const parseThemeJsonIconPath = (themeConfig, curPathThemeJsonKey) => {
47
48
  function normalizeUniConfigThemeJsonIconPath(themeConfig, pagesJson) {
48
49
  // 处理 tabbar 下 list -> item -> iconPath、selectedIconPath; midButton -> backgroundImage 路径 / 不开头的情况
49
50
  const tabBar = pagesJson.tabBar;
50
- if (tabBar) {
51
+ if (tabBar && tabBar.list && tabBar.list.length) {
51
52
  tabBar.list.forEach((item) => {
52
53
  if (item.iconPath && item.iconPath.indexOf('@') === 0) {
53
54
  parseThemeJsonIconPath(themeConfig, item.iconPath.replace(/^@/, ''));
@@ -84,7 +85,7 @@ exports.normalizeThemeConfigOnce = (0, uni_shared_1.once)((manifestJsonPlatform
84
85
  });
85
86
  function initTheme(manifestJson, pagesJson) {
86
87
  const platform = process.env.UNI_PLATFORM === 'app' ? 'app-plus' : process.env.UNI_PLATFORM;
87
- const manifestPlatform = manifestJson['plus'] || manifestJson[platform] || {};
88
+ const manifestPlatform = (0, manifest_1.getPlatformManifestJson)(manifestJson, platform) || {};
88
89
  const themeConfig = (0, exports.normalizeThemeConfigOnce)(manifestPlatform);
89
90
  return (0, uni_shared_1.normalizeStyles)(pagesJson, themeConfig);
90
91
  }
@@ -1,7 +1,8 @@
1
1
  import type { EmittedAsset } from 'rollup';
2
2
  import type { ElementNode } from '@vue/compiler-core';
3
+ import type { MiniProgramComponentsType } from '../json/mp/types';
3
4
  type LazyElementFn = (node: ElementNode, context: {
4
- isMiniProgramComponent(name: string): 'plugin' | 'component' | 'dynamicLib' | 'ext' | undefined;
5
+ isMiniProgramComponent(name: string): MiniProgramComponentsType | undefined;
5
6
  }) => {
6
7
  [name: string]: {
7
8
  name: 'on' | 'bind';
package/dist/platform.js CHANGED
@@ -4,6 +4,9 @@ exports.isMiniProgramPlatform = exports.getPlatformDir = exports.getPlatforms =
4
4
  const BUILT_IN_PLATFORMS = [
5
5
  'app',
6
6
  'app-plus',
7
+ 'app-harmony',
8
+ 'app-ios',
9
+ 'app-android',
7
10
  'h5',
8
11
  'web',
9
12
  'mp-360',
package/dist/resolve.js CHANGED
@@ -30,9 +30,11 @@ function relativeFile(from, to) {
30
30
  }
31
31
  exports.relativeFile = relativeFile;
32
32
  exports.resolveMainPathOnce = (0, uni_shared_1.once)((inputDir) => {
33
- const mainUTSPath = path_1.default.resolve(inputDir, 'main.uts');
34
- if (fs_1.default.existsSync(mainUTSPath)) {
35
- return (0, utils_1.normalizePath)(mainUTSPath);
33
+ if (process.env.UNI_APP_X === 'true') {
34
+ const mainUTSPath = path_1.default.resolve(inputDir, 'main.uts');
35
+ if (fs_1.default.existsSync(mainUTSPath)) {
36
+ return (0, utils_1.normalizePath)(mainUTSPath);
37
+ }
36
38
  }
37
39
  const mainTsPath = path_1.default.resolve(inputDir, 'main.ts');
38
40
  if (fs_1.default.existsSync(mainTsPath)) {
@@ -111,7 +113,12 @@ function resolveComponentsLibPath() {
111
113
  componentsLibPath = path_1.default.join(resolveWithSymlinks('@dcloudio/uni-components/package.json', process.env.UNI_INPUT_DIR), dir);
112
114
  }
113
115
  catch (e) {
114
- componentsLibPath = path_1.default.join(resolveWithSymlinks('@dcloudio/uni-components/package.json', process.cwd()), dir);
116
+ try {
117
+ componentsLibPath = path_1.default.join(resolveWithSymlinks('@dcloudio/uni-components/package.json', process.cwd()), dir);
118
+ }
119
+ catch (e) {
120
+ console.log(e);
121
+ }
115
122
  }
116
123
  }
117
124
  }
@@ -92,6 +92,7 @@ interface EncryptPackageJson {
92
92
  id: string;
93
93
  version: string;
94
94
  uni_modules: {
95
+ dependencies: string[];
95
96
  artifacts: {
96
97
  env: {
97
98
  compilerVersion: string;
@@ -27,7 +27,7 @@ function formatExtApiProviderName(service, name) {
27
27
  if (service === 'oauth') {
28
28
  service = 'OAuth';
29
29
  }
30
- return `Uni${(0, exports.capitalize)((0, exports.camelize)(service))}${(0, exports.capitalize)((0, exports.camelize)(name))}Provider`;
30
+ return `Uni${(0, exports.capitalize)((0, exports.camelize)(service))}${(0, exports.capitalize)((0, exports.camelize)(name))}ProviderImpl`;
31
31
  }
32
32
  exports.formatExtApiProviderName = formatExtApiProviderName;
33
33
  function getUniExtApiProviderRegisters() {
@@ -287,11 +287,13 @@ function genEncryptEasyComModuleIndex(platform, components) {
287
287
  Object.keys(components).forEach((component) => {
288
288
  const id = (0, exports.capitalize)((0, exports.camelize)(component));
289
289
  ids.push(id);
290
+ let instance = '';
290
291
  if (platform === 'app-android') {
292
+ instance = (0, easycom_1.genUTSComponentPublicInstanceIdent)(component);
291
293
  // 类型
292
- ids.push((0, easycom_1.genUTSComponentPublicInstanceIdent)(component));
294
+ ids.push(instance);
293
295
  }
294
- imports.push(`import ${id} from './components/${component}/${component}${components[component]}'`);
296
+ imports.push(`import ${id}${instance ? `, { ${instance} }` : ''} from './components/${component}/${component}${components[component]}'`);
295
297
  });
296
298
  return `
297
299
  ${imports.join('\n')}
@@ -496,7 +498,7 @@ function findLastIndex(array, predicate) {
496
498
  }
497
499
  let encryptUniModules = {};
498
500
  function resolveEncryptUniModule(id, platform, isX = true) {
499
- const parts = id.split('/');
501
+ const parts = id.split('?', 2)[0].split('/');
500
502
  const index = findLastIndex(parts, (part) => part === 'uni_modules');
501
503
  if (index !== -1) {
502
504
  const uniModuleId = parts[index + 1];
package/dist/utils.js CHANGED
@@ -147,9 +147,11 @@ function isAppVue(filename) {
147
147
  }
148
148
  exports.isAppVue = isAppVue;
149
149
  function resolveAppVue(inputDir) {
150
- const appUVue = path_1.default.resolve(inputDir, 'App.uvue');
151
- if (fs_1.default.existsSync(appUVue)) {
152
- return normalizePath(appUVue);
150
+ if (process.env.UNI_APP_X === 'true') {
151
+ const appUVue = path_1.default.resolve(inputDir, 'App.uvue');
152
+ if (fs_1.default.existsSync(appUVue)) {
153
+ return normalizePath(appUVue);
154
+ }
153
155
  }
154
156
  return normalizePath(path_1.default.resolve(inputDir, 'App.vue'));
155
157
  }
@@ -177,11 +179,18 @@ function requireUniHelpers() {
177
179
  }
178
180
  exports.requireUniHelpers = requireUniHelpers;
179
181
  function normalizeEmitAssetFileName(fileName) {
182
+ const extname = path_1.default.extname(fileName);
180
183
  if (process.env.UNI_APP_X_TSC === 'true') {
181
- if (path_1.default.extname(fileName) !== '.ts') {
184
+ if (extname !== '.ts') {
182
185
  return fileName + '.ts';
183
186
  }
184
187
  }
188
+ else {
189
+ // logo.png、pages.json 等
190
+ if (!['.ts', '.uts', '.uvue', '.vue'].includes(extname)) {
191
+ fileName = fileName + '.uts';
192
+ }
193
+ }
185
194
  return fileName;
186
195
  }
187
196
  exports.normalizeEmitAssetFileName = normalizeEmitAssetFileName;
package/dist/uts.d.ts CHANGED
@@ -12,6 +12,7 @@ export declare function resolveUTSAppModule(platform: typeof process.env.UNI_UTS
12
12
  export declare function resolveUTSModule(id: string, importer: string, includeUTSSDK?: boolean): string | undefined;
13
13
  export declare function resolveUTSCompiler(): typeof UTSCompiler;
14
14
  export declare function isUTSComponent(name: string): boolean;
15
+ export declare function getUTSComponentAutoImports(): Record<string, [[string]]>;
15
16
  export declare function parseUTSComponent(name: string, type: 'kotlin' | 'swift'): {
16
17
  className: string;
17
18
  namespace: string;
package/dist/uts.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.resolveUniTypeScript = exports.parseUniExtApiNamespacesJsOnce = exports.parseUniExtApiNamespacesOnce = exports.parseSwiftPackageWithPluginId = exports.parseKotlinPackageWithPluginId = exports.initUTSComponents = exports.parseUTSComponent = exports.isUTSComponent = exports.resolveUTSCompiler = exports.resolveUTSModule = exports.resolveUTSAppModule = void 0;
6
+ exports.resolveUniTypeScript = exports.parseUniExtApiNamespacesJsOnce = exports.parseUniExtApiNamespacesOnce = exports.parseSwiftPackageWithPluginId = exports.parseKotlinPackageWithPluginId = exports.initUTSComponents = exports.parseUTSComponent = exports.getUTSComponentAutoImports = exports.isUTSComponent = exports.resolveUTSCompiler = exports.resolveUTSModule = exports.resolveUTSAppModule = void 0;
7
7
  // 重要,该文件编译后的 js 需要同步到 vue2 编译器 uni-cli-shared/lib/uts
8
8
  const fs_1 = __importDefault(require("fs"));
9
9
  const path_1 = __importDefault(require("path"));
@@ -47,10 +47,11 @@ function resolveUTSAppModule(platform, id, importer, includeUTSSDK = true) {
47
47
  if (fs_1.default.existsSync(path_1.default.resolve(id, basedir, 'index.uts'))) {
48
48
  return id;
49
49
  }
50
+ const fileName = id.split('?')[0];
50
51
  const resolvePlatformDir = (p) => {
51
- return path_1.default.resolve(id, basedir, p);
52
+ return path_1.default.resolve(fileName, basedir, p);
52
53
  };
53
- const extname = ['.uts'];
54
+ const extname = ['.uts', '.vue', '.uvue'];
54
55
  if (platform === 'app-harmony') {
55
56
  if (resolveUTSFile(resolvePlatformDir(platform), extname)) {
56
57
  return id;
@@ -145,6 +146,22 @@ function isUTSComponent(name) {
145
146
  return utsComponents.has(name);
146
147
  }
147
148
  exports.isUTSComponent = isUTSComponent;
149
+ function getUTSComponentAutoImports() {
150
+ const utsComponentAutoImports = {};
151
+ utsComponents.forEach(({ kotlinPackage }, name) => {
152
+ const className = (0, utils_1.capitalize)((0, utils_1.camelize)(name)) + 'Element';
153
+ if (!utsComponentAutoImports[kotlinPackage]) {
154
+ utsComponentAutoImports[kotlinPackage] = [[className]];
155
+ }
156
+ else {
157
+ if (!utsComponentAutoImports[kotlinPackage].find((item) => item[0] === className)) {
158
+ utsComponentAutoImports[kotlinPackage].push([className]);
159
+ }
160
+ }
161
+ });
162
+ return utsComponentAutoImports;
163
+ }
164
+ exports.getUTSComponentAutoImports = getUTSComponentAutoImports;
148
165
  function parseUTSComponent(name, type) {
149
166
  const meta = utsComponents.get(name);
150
167
  if (meta) {
@@ -184,9 +201,12 @@ function initUTSComponents(inputDir, platform) {
184
201
  }
185
202
  }
186
203
  if (name) {
187
- const importDir = (0, utils_1.normalizePath)(is_uni_modules_utssdk ? path_1.default.dirname(dir) : dir);
204
+ const source = '@/' +
205
+ (0, utils_1.normalizePath)(isApp
206
+ ? path_1.default.relative(inputDir, is_uni_modules_utssdk ? path_1.default.dirname(dir) : dir)
207
+ : path_1.default.relative(inputDir, file));
188
208
  easycomsObj[`^${name}$`] = {
189
- source: isApp ? `${importDir}?uts-proxy` : (0, utils_1.normalizePath)(file),
209
+ source: isApp ? `${source}?uts-proxy` : source,
190
210
  kotlinPackage: parseKotlinPackageWithPluginId(pluginId, is_uni_modules_utssdk),
191
211
  swiftModule: parseSwiftPackageWithPluginId(pluginId, is_uni_modules_utssdk),
192
212
  };
@@ -143,15 +143,38 @@ function uniEncryptUniModulesPlugin() {
143
143
  const compiler = (0, uts_1.resolveUTSCompiler)();
144
144
  for (const uniModule of tempUniModules) {
145
145
  const pluginDir = path_1.default.resolve(tempUniModulesDir, uniModule);
146
+ // TODO 待优化autoImports,目前 uni-app x 的编译,autoImport 是在js层处理过,rust层基本不再使用
147
+ // 但uts插件目前还是使用的rust层的autoImports
148
+ const autoImports = {};
149
+ const allAutoImports = (0, easycom_1.getUTSEasyComAutoImports)();
150
+ Object.keys(allAutoImports).forEach((source) => {
151
+ if (!source.startsWith(`@/uni_modules/${uniModule}/components/`)) {
152
+ autoImports[source] = allAutoImports[source];
153
+ }
154
+ });
155
+ const uni_modules = [];
156
+ const pkgJson = path_1.default.resolve(process.env.UNI_INPUT_DIR, 'uni_modules', uniModule, 'package.json');
157
+ if (fs_extra_1.default.existsSync(pkgJson)) {
158
+ try {
159
+ const pkg = require(pkgJson);
160
+ if (pkg.uni_modules?.dependencies) {
161
+ uni_modules.push(...pkg.uni_modules.dependencies);
162
+ }
163
+ }
164
+ catch (e) {
165
+ console.error(e);
166
+ }
167
+ }
146
168
  const result = await compiler.compile(pluginDir, {
147
169
  isX: process.env.UNI_APP_X === 'true',
148
170
  isSingleThread: true,
149
171
  isPlugin: false,
150
172
  sourceMap: false,
151
- uni_modules: [],
173
+ uni_modules,
152
174
  transform: {
153
175
  uvueClassNamePrefix: 'Gen',
154
- autoImports: (0, easycom_1.getUTSEasyComAutoImports)(),
176
+ autoImports,
177
+ uvueGenDefaultAs: '__sfc__',
155
178
  },
156
179
  });
157
180
  if (result) {
@@ -277,6 +300,7 @@ function genUniModulesPackageJson(uniModuleId, inputDir, artifacts) {
277
300
  id: pkg.id,
278
301
  version: pkg.version,
279
302
  uni_modules: {
303
+ dependencies: pkg.uni_modules?.dependencies || [],
280
304
  artifacts,
281
305
  },
282
306
  }, null, 2);
@@ -135,9 +135,10 @@ function initManifestFeature({ manifestJson, command, platform, }) {
135
135
  // features.wxs = false
136
136
  // features.longpress = false
137
137
  }
138
- if (manifestJson.h5 &&
139
- manifestJson.h5.router &&
140
- manifestJson.h5.router.mode === 'history') {
138
+ const webManifest = manifestJson.web || manifestJson.h5;
139
+ if (webManifest &&
140
+ webManifest.router &&
141
+ webManifest.router.mode === 'history') {
141
142
  features.routerMode = '"history"';
142
143
  }
143
144
  // TODO other features
@@ -6,6 +6,5 @@ export type UniViteCopyPluginTarget = Omit<FileWatcherOptions, 'verbose'> & {
6
6
  };
7
7
  export interface UniViteCopyPluginOptions {
8
8
  targets: UniViteCopyPluginTarget[];
9
- verbose: boolean;
10
9
  }
11
- export declare function uniViteCopyPlugin({ targets, verbose, }: UniViteCopyPluginOptions): Plugin;
10
+ export declare function uniViteCopyPlugin({ targets, }: UniViteCopyPluginOptions): Plugin;
@@ -5,7 +5,7 @@ const watcher_1 = require("../../watcher");
5
5
  const messages_1 = require("../../messages");
6
6
  const logs_1 = require("../../logs");
7
7
  const uni_shared_1 = require("@dcloudio/uni-shared");
8
- function uniViteCopyPlugin({ targets, verbose, }) {
8
+ function uniViteCopyPlugin({ targets, }) {
9
9
  let resolvedConfig;
10
10
  let initialized = false;
11
11
  return {
@@ -22,31 +22,25 @@ function uniViteCopyPlugin({ targets, verbose, }) {
22
22
  return;
23
23
  }
24
24
  initialized = true;
25
+ const is_prod = process.env.NODE_ENV !== 'development' ||
26
+ process.env.UNI_AUTOMATOR_CONFIG;
27
+ const onChange = is_prod
28
+ ? undefined
29
+ : (0, uni_shared_1.debounce)(() => {
30
+ (0, logs_1.resetOutput)('log');
31
+ (0, logs_1.output)('log', messages_1.M['dev.watching.end']);
32
+ }, 100, { setTimeout, clearTimeout });
25
33
  return new Promise((resolve) => {
26
34
  Promise.all(targets.map(({ watchOptions, ...target }) => {
27
35
  return new Promise((resolve) => {
28
- // 防抖,可能短时间触发很多次add,unlink
29
- const onChange = (0, uni_shared_1.debounce)(() => {
30
- (0, logs_1.resetOutput)('log');
31
- (0, logs_1.output)('log', messages_1.M['dev.watching.end']);
32
- }, 100, { setTimeout, clearTimeout });
33
36
  new watcher_1.FileWatcher({
34
- verbose,
35
37
  ...target,
36
38
  }).watch({
37
39
  cwd: process.env.UNI_INPUT_DIR,
40
+ persistent: is_prod ? false : true,
38
41
  ...watchOptions,
39
- }, (watcher) => {
40
- if (process.env.NODE_ENV !== 'development' ||
41
- process.env.UNI_AUTOMATOR_CONFIG) {
42
- // 生产或自动化测试模式下,延迟 close,否则会影响 chokidar 初始化的 add 等事件
43
- setTimeout(() => {
44
- watcher.close().then(() => resolve(void 0));
45
- }, 2000);
46
- }
47
- else {
48
- resolve(void 0);
49
- }
42
+ }, () => {
43
+ resolve(void 0);
50
44
  }, onChange);
51
45
  });
52
46
  })).then(() => resolve());
@@ -9,6 +9,7 @@ export * from './uts/uni_modules';
9
9
  export * from './uts/uvue';
10
10
  export * from './uts/ext-api';
11
11
  export * from './easycom';
12
+ export * from './json';
12
13
  export { uniViteSfcSrcImportPlugin } from './sfc';
13
14
  export { assetPlugin, parseAssets, getAssetHash } from './vitejs/plugins/asset';
14
15
  export { isCSSRequest, cssPlugin, cssPostPlugin, minifyCSS, cssLangRE, commonjsProxyRE, rewriteScssReadFileSync, } from './vitejs/plugins/css';
@@ -26,6 +26,7 @@ __exportStar(require("./uts/uni_modules"), exports);
26
26
  __exportStar(require("./uts/uvue"), exports);
27
27
  __exportStar(require("./uts/ext-api"), exports);
28
28
  __exportStar(require("./easycom"), exports);
29
+ __exportStar(require("./json"), exports);
29
30
  var sfc_1 = require("./sfc");
30
31
  Object.defineProperty(exports, "uniViteSfcSrcImportPlugin", { enumerable: true, get: function () { return sfc_1.uniViteSfcSrcImportPlugin; } });
31
32
  var asset_1 = require("./vitejs/plugins/asset");
@@ -0,0 +1,2 @@
1
+ import type { Plugin } from 'vite';
2
+ export declare function uniJsonPlugin(): Plugin;
@@ -0,0 +1,30 @@
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.uniJsonPlugin = void 0;
7
+ const path_1 = __importDefault(require("path"));
8
+ const json_1 = require("../../json");
9
+ const preprocess_1 = require("../../preprocess");
10
+ const utils_1 = require("../utils");
11
+ function uniJsonPlugin() {
12
+ return {
13
+ name: 'uni:json',
14
+ enforce: 'pre',
15
+ transform(code, id) {
16
+ // 如果已经被其他插件处理过了,就不再处理,比如 commonjs 插件,ICAPRegistrar.json?commonjs-external
17
+ if (id.startsWith('\0')) {
18
+ return;
19
+ }
20
+ if (path_1.default.extname((0, utils_1.parseVueRequest)(id).filename) !== '.json') {
21
+ return;
22
+ }
23
+ return {
24
+ code: JSON.stringify((0, json_1.parseJson)((0, preprocess_1.preJson)(code)), null, 2),
25
+ map: null,
26
+ };
27
+ },
28
+ };
29
+ }
30
+ exports.uniJsonPlugin = uniJsonPlugin;
@@ -55,6 +55,11 @@ function uniUTSAppUniModulesPlugin(options = {}) {
55
55
  return compiler.compileArkTS(pluginDir, {
56
56
  isX: !!options.x,
57
57
  isExtApi,
58
+ transform: {
59
+ uniExtApiProviderName: extApiProvider?.name,
60
+ uniExtApiProviderService: extApiProvider?.service,
61
+ uniExtApiProviderServicePlugin,
62
+ },
58
63
  });
59
64
  }
60
65
  return compiler.compile(pluginDir, {
@@ -76,7 +81,14 @@ function uniUTSAppUniModulesPlugin(options = {}) {
76
81
  // 获取 provider 扩展(编译所有uni)
77
82
  const plugins = (0, uni_modules_1.getUniExtApiPlugins)().filter((provider) => !utsPlugins.has(provider.plugin));
78
83
  for (const plugin of plugins) {
79
- const result = await compilePlugin(path_1.default.resolve(inputDir, 'uni_modules', plugin.plugin));
84
+ const pluginDir = path_1.default.resolve(inputDir, 'uni_modules', plugin.plugin);
85
+ // 如果是 app-js 环境
86
+ if (process.env.UNI_APP_X_UVUE_SCRIPT_ENGINE === 'js') {
87
+ if (fs_1.default.existsSync(path_1.default.resolve(pluginDir, 'utssdk', 'app-js', 'index.uts'))) {
88
+ continue;
89
+ }
90
+ }
91
+ const result = await compilePlugin(pluginDir);
80
92
  if (result) {
81
93
  // 时机不对,不能addWatch
82
94
  // result.deps.forEach((dep) => {
@@ -1,7 +1,7 @@
1
1
  export interface VueQuery {
2
2
  vue?: boolean;
3
3
  src?: boolean;
4
- type?: 'script' | 'template' | 'style' | 'custom';
4
+ type?: 'script' | 'template' | 'style' | 'custom' | 'page';
5
5
  index?: number;
6
6
  lang?: string;
7
7
  raw?: boolean;
package/dist/watcher.d.ts CHANGED
@@ -5,24 +5,23 @@ export interface FileWatcherOptions {
5
5
  src: string | string[];
6
6
  dest: string;
7
7
  transform?: FileTransform;
8
- verbose?: boolean;
9
8
  }
10
9
  export declare class FileWatcher {
11
10
  private src;
12
11
  private dest;
13
12
  private transform?;
14
- private verbose?;
15
13
  private watcher;
16
14
  private onChange?;
17
- constructor({ src, dest, transform, verbose }: FileWatcherOptions);
15
+ constructor({ src, dest, transform }: FileWatcherOptions);
18
16
  watch(watchOptions: WatchOptions & {
19
17
  cwd: string;
18
+ readyTimeout?: number;
20
19
  }, onReady?: (watcher: FSWatcher) => void, onChange?: () => void): FSWatcher;
21
20
  add(paths: string | ReadonlyArray<string>): FSWatcher;
22
21
  unwatch(paths: string | ReadonlyArray<string>): FSWatcher;
23
22
  close(): Promise<void>;
24
- copy(from: string): Promise<void | undefined>;
25
- remove(from: string): Promise<void | undefined>;
23
+ copy(from: string): void;
24
+ remove(from: string): void;
26
25
  info(type: 'close' | 'copy' | 'remove' | 'add' | 'unwatch', msg?: string | unknown): void;
27
26
  from(from: string): string;
28
27
  to(from: string): string;
package/dist/watcher.js CHANGED
@@ -6,15 +6,16 @@ Object.defineProperty(exports, "__esModule", { value: true });
6
6
  exports.FileWatcher = void 0;
7
7
  const fs_extra_1 = __importDefault(require("fs-extra"));
8
8
  const path_1 = __importDefault(require("path"));
9
+ const debug_1 = __importDefault(require("debug"));
9
10
  const chokidar_1 = require("chokidar");
10
11
  const shared_1 = require("@vue/shared");
11
12
  const utils_1 = require("./utils");
13
+ const debugWatcher = (0, debug_1.default)('uni:watcher');
12
14
  class FileWatcher {
13
- constructor({ src, dest, transform, verbose }) {
15
+ constructor({ src, dest, transform }) {
14
16
  this.src = !(0, shared_1.isArray)(src) ? [src] : src;
15
17
  this.dest = dest;
16
18
  this.transform = transform;
17
- this.verbose = verbose;
18
19
  }
19
20
  watch(watchOptions, onReady, onChange) {
20
21
  if (!this.watcher) {
@@ -22,17 +23,26 @@ class FileWatcher {
22
23
  const remove = this.remove.bind(this);
23
24
  // escape chokidar cwd
24
25
  const src = this.src.map((src) => (0, utils_1.pathToGlob)(path_1.default.resolve(watchOptions.cwd), src));
26
+ let closeTimer;
27
+ const checkReady = () => {
28
+ if (closeTimer) {
29
+ clearTimeout(closeTimer);
30
+ }
31
+ closeTimer = setTimeout(() => {
32
+ onReady && onReady(this.watcher);
33
+ // 等首次change完,触发完ready,在切换到真实的onChange
34
+ this.onChange = onChange;
35
+ }, watchOptions.readyTimeout || 300);
36
+ };
37
+ this.onChange = checkReady;
25
38
  this.watcher = (0, chokidar_1.watch)(src, watchOptions)
26
39
  .on('add', copy)
27
- .on('addDir', copy)
40
+ // .on('addDir', copy)
28
41
  .on('change', copy)
29
42
  .on('unlink', remove)
30
- .on('unlinkDir', remove)
43
+ // .on('unlinkDir', remove)
31
44
  .on('ready', () => {
32
- onReady && onReady(this.watcher);
33
- setTimeout(() => {
34
- this.onChange = onChange;
35
- }, 1000);
45
+ checkReady();
36
46
  })
37
47
  .on('error', (e) => console.error('watch', e));
38
48
  }
@@ -59,32 +69,21 @@ class FileWatcher {
59
69
  content = this.transform(fs_extra_1.default.readFileSync(filename), filename);
60
70
  }
61
71
  if (content) {
62
- return fs_extra_1.default
63
- .outputFile(to, content)
64
- .catch(() => {
65
- // this.info('copy', e)
66
- })
67
- .then(() => this.onChange && this.onChange());
72
+ fs_extra_1.default.outputFileSync(to, content);
73
+ this.onChange && this.onChange();
74
+ return;
68
75
  }
69
- return fs_extra_1.default
70
- .copy(this.from(from), to, { overwrite: true })
71
- .catch(() => {
72
- // this.info('copy', e)
73
- })
74
- .then(() => this.onChange && this.onChange());
76
+ fs_extra_1.default.copySync(this.from(from), to, { overwrite: true });
77
+ this.onChange && this.onChange();
75
78
  }
76
79
  remove(from) {
77
80
  const to = this.to(from);
78
81
  this.info('remove', from + '=>' + to);
79
- return fs_extra_1.default
80
- .remove(to)
81
- .catch(() => {
82
- // this.info('remove', e)
83
- })
84
- .then(() => this.onChange && this.onChange());
82
+ fs_extra_1.default.removeSync(to);
83
+ this.onChange && this.onChange();
85
84
  }
86
85
  info(type, msg) {
87
- this.verbose && console.log(type, msg);
86
+ debugWatcher.enabled && debugWatcher(type, msg);
88
87
  }
89
88
  from(from) {
90
89
  return path_1.default.join(this.watcher.options.cwd, from);
package/license.md ADDED
@@ -0,0 +1 @@
1
+ [https://uniapp.dcloud.net.cn/license.html ](https://uniapp.dcloud.net.cn/license.html )
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@dcloudio/uni-cli-shared",
3
- "version": "3.0.0-4020420240722003",
3
+ "version": "3.0.0-4020920240930001",
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-4020420240722003",
30
- "@dcloudio/uni-shared": "3.0.0-4020420240722003",
29
+ "@dcloudio/uni-i18n": "3.0.0-4020920240930001",
30
+ "@dcloudio/uni-shared": "3.0.0-4020920240930001",
31
31
  "@intlify/core-base": "9.1.9",
32
32
  "@intlify/shared": "9.1.9",
33
33
  "@intlify/vue-devtools": "9.1.9",
@@ -71,7 +71,7 @@
71
71
  },
72
72
  "gitHead": "33e807d66e1fe47e2ee08ad9c59247e37b8884da",
73
73
  "devDependencies": {
74
- "@dcloudio/uni-uts-v1": "3.0.0-4020420240722003",
74
+ "@dcloudio/uni-uts-v1": "3.0.0-4020920240930001",
75
75
  "@types/adm-zip": "^0.5.5",
76
76
  "@types/babel__code-frame": "^7.0.6",
77
77
  "@types/babel__core": "^7.1.19",
@@ -87,7 +87,7 @@
87
87
  "@types/stylus": "^0.48.36",
88
88
  "code-frame": "link:@types/@babel/code-frame",
89
89
  "postcss": "^8.4.21",
90
- "unplugin-auto-import": "^0.16.7",
90
+ "unimport": "^3.9.0",
91
91
  "vue": "3.4.21"
92
92
  }
93
93
  }