@dcloudio/uni-cli-shared 3.0.0-alpha-3080520230612002 → 3.0.0-alpha-3080520230616001

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.
@@ -1,30 +1,3 @@
1
- interface CheckUpdateOptions {
2
- inputDir: string;
3
- compilerVersion: string;
4
- versionType: 'a' | 'r';
5
- }
6
- interface CheckUpdatePlatform {
7
- appid?: string;
8
- dev: number;
9
- build: number;
10
- }
11
- interface CheckUpdateCache {
12
- vid: string;
13
- lastCheck: number;
14
- newVersion?: string;
15
- note?: string;
16
- [name: string]: CheckUpdatePlatform | undefined | string | number;
17
- }
18
- export declare function checkUpdate(options: CheckUpdateOptions): Promise<void>;
19
- /**
20
- * 检查本地缓存,返回 false 表示需要执行云端检查,返回 true 表示,无需云端检查,返回 string 表示,无需云端检测,且有更新
21
- * @param inputDir
22
- * @param compilerVersion
23
- * @param interval
24
- * @returns
25
- */
26
- export declare function checkLocalCache(updateCache: CheckUpdateCache, compilerVersion: string, interval?: number): string | boolean;
27
- export declare function md5(str: string): string;
28
- export declare function getMac(): string;
29
- export declare function createPostData({ versionType, compilerVersion }: CheckUpdateOptions, manifestJson: Record<string, any>, updateCache: CheckUpdateCache): string;
1
+ declare function checkUpdate1(options: any): Promise<undefined>;
2
+ export declare const checkUpdate: typeof checkUpdate1;
30
3
  export {};
@@ -1,254 +1,61 @@
1
+ /* eslint-disable */
2
+ // @ts-ignore
1
3
  "use strict";
2
- var __importDefault = (this && this.__importDefault) || function (mod) {
3
- return (mod && mod.__esModule) ? mod : { "default": mod };
4
- };
5
4
  Object.defineProperty(exports, "__esModule", { value: true });
6
- exports.createPostData = exports.getMac = exports.md5 = exports.checkLocalCache = exports.checkUpdate = void 0;
7
- const fs_extra_1 = __importDefault(require("fs-extra"));
8
- const os_1 = __importDefault(require("os"));
9
- const path_1 = __importDefault(require("path"));
10
- const debug_1 = __importDefault(require("debug"));
11
- const crypto_1 = __importDefault(require("crypto"));
12
- const https_1 = require("https");
13
- const compare_versions_1 = __importDefault(require("compare-versions"));
14
- const shared_1 = require("@vue/shared");
15
- const json_1 = require("./json");
16
- const hbx_1 = require("./hbx");
17
- const debugCheckUpdate = (0, debug_1.default)('uni:check-update');
18
- const INTERVAL = 1000 * 60 * 60 * 24;
19
- async function checkUpdate(options) {
20
- if (process.env.CI) {
21
- debugCheckUpdate('isInCI');
22
- return;
23
- }
24
- if ((0, hbx_1.isInHBuilderX)()) {
25
- debugCheckUpdate('isInHBuilderX');
26
- return;
27
- }
28
- const { inputDir, compilerVersion } = options;
29
- const updateCache = readCheckUpdateCache(inputDir);
30
- debugCheckUpdate('read.cache', updateCache);
31
- const res = checkLocalCache(updateCache, compilerVersion);
32
- if (res) {
33
- if ((0, shared_1.isString)(res)) {
34
- console.log();
35
- console.log(res);
36
- }
37
- }
38
- else {
39
- await checkVersion(options, normalizeUpdateCache(updateCache, (0, json_1.parseManifestJsonOnce)(inputDir)));
40
- }
41
- writeCheckUpdateCache(inputDir, statUpdateCache(normalizeUpdateCache(updateCache)));
42
- }
43
- exports.checkUpdate = checkUpdate;
44
- function normalizeUpdateCache(updateCache, manifestJson) {
45
- const platform = process.env.UNI_PLATFORM;
46
- if (!updateCache[platform]) {
47
- updateCache[platform] = {
48
- appid: '',
49
- dev: 0,
50
- build: 0,
51
- };
52
- }
53
- if (manifestJson) {
54
- const platformOptions = manifestJson[platform === 'app' ? 'app-plus' : platform];
55
- updateCache[platform].appid = platformOptions
56
- ? platformOptions.appid || platformOptions.package || ''
57
- : '';
58
- }
59
- return updateCache;
60
- }
61
- function statUpdateCache(updateCache) {
62
- debugCheckUpdate('stat.before', updateCache);
63
- const platform = process.env.UNI_PLATFORM;
64
- const type = process.env.NODE_ENV === 'production' ? 'build' : 'dev';
65
- const platformOptions = updateCache[platform];
66
- platformOptions[type] = (platformOptions[type] || 0) + 1;
67
- debugCheckUpdate('stat.after', updateCache);
68
- return updateCache;
69
- }
70
- function getFilepath(inputDir, filename) {
71
- return path_1.default.resolve(os_1.default.tmpdir(), 'uni-app-cli', md5(inputDir), filename);
72
- }
73
- function getCheckUpdateFilepath(inputDir) {
74
- return getFilepath(inputDir, 'check-update.json');
75
- }
76
- function generateVid() {
77
- let result = '';
78
- for (let i = 0; i < 4; i++) {
79
- result += ((65536 * (1 + Math.random())) | 0).toString(16).substring(1);
80
- }
81
- return 'UNI_' + result.toUpperCase();
82
- }
83
- function createCheckUpdateCache(vid = generateVid()) {
84
- return {
85
- vid: generateVid(),
86
- lastCheck: 0,
87
- };
88
- }
89
- function readCheckUpdateCache(inputDir) {
90
- const updateFilepath = getCheckUpdateFilepath(inputDir);
91
- debugCheckUpdate('read:', updateFilepath);
92
- if (fs_extra_1.default.existsSync(updateFilepath)) {
93
- try {
94
- return require(updateFilepath);
95
- }
96
- catch (e) {
97
- debugCheckUpdate('read.error', e);
98
- }
99
- }
100
- return createCheckUpdateCache();
101
- }
102
- /**
103
- * 检查本地缓存,返回 false 表示需要执行云端检查,返回 true 表示,无需云端检查,返回 string 表示,无需云端检测,且有更新
104
- * @param inputDir
105
- * @param compilerVersion
106
- * @param interval
107
- * @returns
108
- */
109
- function checkLocalCache(updateCache, compilerVersion, interval = INTERVAL) {
110
- if (!updateCache.lastCheck) {
111
- debugCheckUpdate('cache: lastCheck not found');
112
- return false;
113
- }
114
- if (Date.now() - updateCache.lastCheck > interval) {
115
- debugCheckUpdate('cache: lastCheck > interval');
116
- return false;
117
- }
118
- if (updateCache.newVersion &&
119
- (0, compare_versions_1.default)(updateCache.newVersion, compilerVersion) > 0) {
120
- debugCheckUpdate('cache: find new version');
121
- return updateCache.note;
122
- }
123
- return true;
124
- }
125
- exports.checkLocalCache = checkLocalCache;
126
- function writeCheckUpdateCache(inputDir, updateCache) {
127
- const filepath = getCheckUpdateFilepath(inputDir);
128
- debugCheckUpdate('write:', filepath, updateCache);
5
+ exports.checkUpdate = void 0;
6
+ var __importDefault = this && this.__importDefault || function (mod) { return mod && mod.__esModule ? mod : { default: mod }; };
7
+ Object.defineProperty(exports, "__esModule", { value: !0 }), exports.createPostData = exports.getMac = exports.md5 = exports.checkLocalCache = exports.checkUpdate1 = void 0;
8
+ const fs_extra_1 = __importDefault(require("fs-extra")), os_1 = __importDefault(require("os")), path_1 = __importDefault(require("path")), debug_1 = __importDefault(require("debug")), crypto_1 = __importDefault(require("crypto")), https_1 = require("https"), compare_versions_1 = __importDefault(require("compare-versions")), shared_1 = require("@vue/shared"), json_1 = require("./json"), hbx_1 = require("./hbx"), debugCheckUpdate = (0, debug_1.default)("uni:check-update"), INTERVAL = 864e5;
9
+ async function checkUpdate1(options) { if (process.env.CI)
10
+ return void debugCheckUpdate("isInCI"); if ((0, hbx_1.isInHBuilderX)())
11
+ return void debugCheckUpdate("isInHBuilderX"); const { inputDir: inputDir, compilerVersion: compilerVersion } = options, updateCache = readCheckUpdateCache(inputDir); debugCheckUpdate("read.cache", updateCache); const res = checkLocalCache(updateCache, compilerVersion); res ? (0, shared_1.isString)(res) && (console.log(), console.log(res)) : await checkVersion(options, normalizeUpdateCache(updateCache, (0, json_1.parseManifestJsonOnce)(inputDir))), writeCheckUpdateCache(inputDir, statUpdateCache(normalizeUpdateCache(updateCache))); }
12
+ function normalizeUpdateCache(updateCache, manifestJson) { const platform = process.env.UNI_PLATFORM; if (updateCache[platform] || (updateCache[platform] = { appid: "", dev: 0, build: 0 }), manifestJson) {
13
+ const platformOptions = manifestJson["app" === platform ? "app-plus" : platform];
14
+ updateCache[platform].appid = platformOptions && (platformOptions.appid || platformOptions.package) || "";
15
+ } return updateCache; }
16
+ function statUpdateCache(updateCache) { debugCheckUpdate("stat.before", updateCache); const platform = process.env.UNI_PLATFORM, type = "production" === process.env.NODE_ENV ? "build" : "dev", platformOptions = updateCache[platform]; return platformOptions[type] = (platformOptions[type] || 0) + 1, debugCheckUpdate("stat.after", updateCache), updateCache; }
17
+ function getFilepath(inputDir, filename) { return path_1.default.resolve(os_1.default.tmpdir(), "uni-app-cli", md5(inputDir), filename); }
18
+ function getCheckUpdateFilepath(inputDir) { return getFilepath(inputDir, "check-update.json"); }
19
+ function generateVid() { let result = ""; for (let i = 0; i < 4; i++)
20
+ result += (65536 * (1 + Math.random()) | 0).toString(16).substring(1); return "UNI_" + result.toUpperCase(); }
21
+ function createCheckUpdateCache(vid = generateVid()) { return { vid: generateVid(), lastCheck: 0 }; }
22
+ function readCheckUpdateCache(inputDir) { const updateFilepath = getCheckUpdateFilepath(inputDir); if (debugCheckUpdate("read:", updateFilepath), fs_extra_1.default.existsSync(updateFilepath))
129
23
  try {
130
- fs_extra_1.default.outputFileSync(filepath, JSON.stringify(updateCache));
24
+ return require(updateFilepath);
131
25
  }
132
26
  catch (e) {
133
- debugCheckUpdate('write.error', e);
134
- }
135
- }
136
- function md5(str) {
137
- return crypto_1.default.createHash('md5').update(str).digest('hex');
138
- }
139
- exports.md5 = md5;
140
- function getMac() {
141
- let mac = '';
142
- const network = os_1.default.networkInterfaces();
143
- for (const key in network) {
144
- const array = network[key];
145
- for (let i = 0; i < array.length; i++) {
146
- const item = array[i];
147
- if (!item.family || (item.mac && item.mac === '00:00:00:00:00:00')) {
148
- continue;
149
- }
150
- if (
151
- // Node < v18
152
- (0, shared_1.isString)(item.family) &&
153
- (item.family === 'IPv4' || item.family === 'IPv6')) {
27
+ debugCheckUpdate("read.error", e);
28
+ } return createCheckUpdateCache(); }
29
+ function checkLocalCache(updateCache, compilerVersion, interval = INTERVAL) { return updateCache.lastCheck ? Date.now() - updateCache.lastCheck > interval ? (debugCheckUpdate("cache: lastCheck > interval"), !1) : !(updateCache.newVersion && (0, compare_versions_1.default)(updateCache.newVersion, compilerVersion) > 0) || (debugCheckUpdate("cache: find new version"), updateCache.note) : (debugCheckUpdate("cache: lastCheck not found"), !1); }
30
+ function writeCheckUpdateCache(inputDir, updateCache) { const filepath = getCheckUpdateFilepath(inputDir); debugCheckUpdate("write:", filepath, updateCache); try {
31
+ fs_extra_1.default.outputFileSync(filepath, JSON.stringify(updateCache));
32
+ }
33
+ catch (e) {
34
+ debugCheckUpdate("write.error", e);
35
+ } }
36
+ function md5(str) { return crypto_1.default.createHash("md5").update(str).digest("hex"); }
37
+ function getMac() { let mac = ""; const network = os_1.default.networkInterfaces(); for (const key in network) {
38
+ const array = network[key];
39
+ for (let i = 0; i < array.length; i++) {
40
+ const item = array[i];
41
+ if (item.family && (!item.mac || "00:00:00:00:00:00" !== item.mac)) {
42
+ if ((0, shared_1.isString)(item.family) && ("IPv4" === item.family || "IPv6" === item.family)) {
154
43
  mac = item.mac;
155
44
  break;
156
45
  }
157
- else if (
158
- // Node >= v18
159
- typeof item.family === 'number' &&
160
- // @ts-ignore
161
- (item.family === 4 || item.family === 6)) {
46
+ if ("number" == typeof item.family && (4 === item.family || 6 === item.family)) {
162
47
  mac = item.mac;
163
48
  break;
164
49
  }
165
50
  }
166
51
  }
167
- return mac;
168
- }
169
- exports.getMac = getMac;
170
- function createPostData({ versionType, compilerVersion }, manifestJson, updateCache) {
171
- const data = {
172
- vv: 3,
173
- device: md5(getMac()),
174
- vtype: versionType,
175
- vcode: compilerVersion,
176
- };
177
- if (manifestJson.appid) {
178
- data.appid = manifestJson.appid;
179
- }
180
- else {
181
- data.vid = updateCache.vid;
182
- }
183
- Object.keys(updateCache).forEach((name) => {
184
- const value = updateCache[name];
185
- if ((0, shared_1.isPlainObject)(value) &&
186
- ((0, shared_1.hasOwn)(value, 'dev') || (0, shared_1.hasOwn)(value, 'build'))) {
187
- data[name] = value;
188
- }
189
- });
190
- return JSON.stringify(data);
191
- }
192
- exports.createPostData = createPostData;
193
- function handleCheckVersion({ code, isUpdate, newVersion, note }, updateCache) {
194
- if (code !== 0) {
195
- return;
196
- }
197
- // clear
198
- Object.keys(updateCache).forEach((key) => {
199
- if (key !== 'vid')
200
- delete updateCache[key];
201
- });
202
- updateCache.lastCheck = Date.now();
203
- if (isUpdate) {
204
- updateCache.note = note;
205
- updateCache.newVersion = newVersion;
206
- }
207
- else {
208
- delete updateCache.note;
209
- delete updateCache.newVersion;
210
- }
211
- }
212
- const HOSTNAME = 'uniapp.dcloud.net.cn';
213
- const PATH = '/update/cli';
214
- function checkVersion(options, updateCache) {
215
- return new Promise((resolve) => {
216
- const postData = JSON.stringify({
217
- id: createPostData(options, (0, json_1.parseManifestJsonOnce)(options.inputDir), updateCache),
218
- });
219
- let responseData = '';
220
- const req = (0, https_1.request)({
221
- hostname: HOSTNAME,
222
- path: PATH,
223
- port: 443,
224
- method: 'POST',
225
- headers: {
226
- 'Content-Type': 'application/json',
227
- 'Content-Length': postData.length,
228
- },
229
- }, (res) => {
230
- res.setEncoding('utf8');
231
- res.on('data', (chunk) => {
232
- responseData += chunk;
233
- });
234
- res.on('end', () => {
235
- debugCheckUpdate('response: ', responseData);
236
- try {
237
- handleCheckVersion(JSON.parse(responseData), updateCache);
238
- }
239
- catch (e) { }
240
- resolve(true);
241
- });
242
- res.on('error', (e) => {
243
- debugCheckUpdate('response.error:', e);
244
- resolve(false);
245
- });
246
- }).on('error', (e) => {
247
- debugCheckUpdate('request.error:', e);
248
- resolve(false);
249
- });
250
- debugCheckUpdate('request: ', postData);
251
- req.write(postData);
252
- req.end();
253
- });
52
+ } return mac; }
53
+ function createPostData({ versionType: versionType, compilerVersion: compilerVersion }, manifestJson, updateCache) { const data = { vv: 3, device: md5(getMac()), vtype: versionType, vcode: compilerVersion }; return manifestJson.appid ? data.appid = manifestJson.appid : data.vid = updateCache.vid, Object.keys(updateCache).forEach((name => { const value = updateCache[name]; (0, shared_1.isPlainObject)(value) && ((0, shared_1.hasOwn)(value, "dev") || (0, shared_1.hasOwn)(value, "build")) && (data[name] = value); })), JSON.stringify(data); }
54
+ function handleCheckVersion({ code: code, isUpdate: isUpdate, newVersion: newVersion, note: note }, updateCache) { 0 === code && (Object.keys(updateCache).forEach((key => { "vid" !== key && delete updateCache[key]; })), updateCache.lastCheck = Date.now(), isUpdate ? (updateCache.note = note, updateCache.newVersion = newVersion) : (delete updateCache.note, delete updateCache.newVersion)); }
55
+ exports.checkUpdate1 = checkUpdate1, exports.checkLocalCache = checkLocalCache, exports.md5 = md5, exports.getMac = getMac, exports.createPostData = createPostData;
56
+ const HOSTNAME = "uniapp.dcloud.net.cn", PATH = "/update/cli";
57
+ function checkVersion(options, updateCache) { return new Promise((resolve => { const postData = JSON.stringify({ id: createPostData(options, (0, json_1.parseManifestJsonOnce)(options.inputDir), updateCache) }); let responseData = ""; const req = (0, https_1.request)({ hostname: HOSTNAME, path: PATH, port: 443, method: "POST", headers: { "Content-Type": "application/json", "Content-Length": postData.length } }, (res => { res.setEncoding("utf8"), res.on("data", (chunk => { responseData += chunk; })), res.on("end", (() => { debugCheckUpdate("response: ", responseData); try {
58
+ handleCheckVersion(JSON.parse(responseData), updateCache);
254
59
  }
60
+ catch (e) { } resolve(!0); })), res.on("error", (e => { debugCheckUpdate("response.error:", e), resolve(!1); })); })).on("error", (e => { debugCheckUpdate("request.error:", e), resolve(!1); })); debugCheckUpdate("request: ", postData), req.write(postData), req.end(); })); }
61
+ exports.checkUpdate = checkUpdate1;
package/dist/index.js CHANGED
@@ -44,5 +44,6 @@ Object.defineProperty(exports, "parseInjects", { enumerable: true, get: function
44
44
  var messages_1 = require("./messages");
45
45
  Object.defineProperty(exports, "M", { enumerable: true, get: function () { return messages_1.M; } });
46
46
  __exportStar(require("./exports"), exports);
47
+ // @ts-ignore
47
48
  var checkUpdate_1 = require("./checkUpdate");
48
49
  Object.defineProperty(exports, "checkUpdate", { enumerable: true, get: function () { return checkUpdate_1.checkUpdate; } });
@@ -3,7 +3,7 @@ export declare function isMiniProgramPageFile(file: string, inputDir?: string):
3
3
  export declare function isMiniProgramPageSfcFile(file: string, inputDir?: string): boolean;
4
4
  export declare function hasJsonFile(filename: string): boolean;
5
5
  export declare function getComponentJsonFilenames(): string[];
6
- export declare function findJsonFile(filename: string): ComponentJson | PageWindowOptions | Record<string, any> | undefined;
6
+ export declare function findJsonFile(filename: string): Record<string, any> | ComponentJson | PageWindowOptions | undefined;
7
7
  export declare function findUsingComponents(filename: string): UsingComponents | undefined;
8
8
  export declare function normalizeJsonFilename(filename: string): string;
9
9
  export declare function findChangedJsonFiles(supportGlobalUsingComponents?: boolean): Map<string, string>;
@@ -31,7 +31,7 @@ declare const _default: {
31
31
  readonly 'prompt.run.devtools.mp--kuaishou': "Kuaishou Mini Program Devtools";
32
32
  readonly 'prompt.run.devtools.mp-lark': "Lark Mini Program Devtools";
33
33
  readonly 'prompt.run.devtools.mp-qq': "QQ Mini Program Devtools";
34
- readonly 'prompt.run.devtools.mp-toutiao': "ByteDance Mini Program Devtools";
34
+ readonly 'prompt.run.devtools.mp-toutiao': "Douyin Mini Program Devtools";
35
35
  readonly 'prompt.run.devtools.mp-weixin': "Weixin Mini Program Devtools";
36
36
  readonly 'prompt.run.devtools.mp-jd': "Jingdong Mini Program Devtools";
37
37
  readonly 'prompt.run.devtools.mp-xhs': "Xiaohongshu Mini Program Devtools";
@@ -33,7 +33,7 @@ exports.default = {
33
33
  'prompt.run.devtools.mp--kuaishou': 'Kuaishou Mini Program Devtools',
34
34
  'prompt.run.devtools.mp-lark': 'Lark Mini Program Devtools',
35
35
  'prompt.run.devtools.mp-qq': 'QQ Mini Program Devtools',
36
- 'prompt.run.devtools.mp-toutiao': 'ByteDance Mini Program Devtools',
36
+ 'prompt.run.devtools.mp-toutiao': 'Douyin Mini Program Devtools',
37
37
  'prompt.run.devtools.mp-weixin': 'Weixin Mini Program Devtools',
38
38
  'prompt.run.devtools.mp-jd': 'Jingdong Mini Program Devtools',
39
39
  'prompt.run.devtools.mp-xhs': 'Xiaohongshu Mini Program Devtools',
@@ -31,7 +31,7 @@ export declare const M: {
31
31
  readonly 'prompt.run.devtools.mp--kuaishou': "快手开发者工具";
32
32
  readonly 'prompt.run.devtools.mp-lark': "飞书开发者工具";
33
33
  readonly 'prompt.run.devtools.mp-qq': "QQ小程序开发者工具";
34
- readonly 'prompt.run.devtools.mp-toutiao': "字节跳动开发者工具";
34
+ readonly 'prompt.run.devtools.mp-toutiao': "抖音开发者工具";
35
35
  readonly 'prompt.run.devtools.mp-weixin': "微信开发者工具";
36
36
  readonly 'prompt.run.devtools.mp-jd': "京东开发者工具";
37
37
  readonly 'prompt.run.devtools.mp-xhs': "小红书开发者工具";
@@ -72,7 +72,7 @@ export declare const M: {
72
72
  readonly 'prompt.run.devtools.mp--kuaishou': "Kuaishou Mini Program Devtools";
73
73
  readonly 'prompt.run.devtools.mp-lark': "Lark Mini Program Devtools";
74
74
  readonly 'prompt.run.devtools.mp-qq': "QQ Mini Program Devtools";
75
- readonly 'prompt.run.devtools.mp-toutiao': "ByteDance Mini Program Devtools";
75
+ readonly 'prompt.run.devtools.mp-toutiao': "Douyin Mini Program Devtools";
76
76
  readonly 'prompt.run.devtools.mp-weixin': "Weixin Mini Program Devtools";
77
77
  readonly 'prompt.run.devtools.mp-jd': "Jingdong Mini Program Devtools";
78
78
  readonly 'prompt.run.devtools.mp-xhs': "Xiaohongshu Mini Program Devtools";
@@ -31,7 +31,7 @@ declare const _default: {
31
31
  readonly 'prompt.run.devtools.mp--kuaishou': "快手开发者工具";
32
32
  readonly 'prompt.run.devtools.mp-lark': "飞书开发者工具";
33
33
  readonly 'prompt.run.devtools.mp-qq': "QQ小程序开发者工具";
34
- readonly 'prompt.run.devtools.mp-toutiao': "字节跳动开发者工具";
34
+ readonly 'prompt.run.devtools.mp-toutiao': "抖音开发者工具";
35
35
  readonly 'prompt.run.devtools.mp-weixin': "微信开发者工具";
36
36
  readonly 'prompt.run.devtools.mp-jd': "京东开发者工具";
37
37
  readonly 'prompt.run.devtools.mp-xhs': "小红书开发者工具";
@@ -33,7 +33,7 @@ exports.default = {
33
33
  'prompt.run.devtools.mp--kuaishou': '快手开发者工具',
34
34
  'prompt.run.devtools.mp-lark': '飞书开发者工具',
35
35
  'prompt.run.devtools.mp-qq': 'QQ小程序开发者工具',
36
- 'prompt.run.devtools.mp-toutiao': '字节跳动开发者工具',
36
+ 'prompt.run.devtools.mp-toutiao': '抖音开发者工具',
37
37
  'prompt.run.devtools.mp-weixin': '微信开发者工具',
38
38
  'prompt.run.devtools.mp-jd': '京东开发者工具',
39
39
  'prompt.run.devtools.mp-xhs': '小红书开发者工具',
@@ -101,7 +101,9 @@ function parseInject(vite = true, platform, language, source, globalObject, defi
101
101
  const keys = Object.keys(define);
102
102
  keys.forEach((d) => {
103
103
  if (typeof define[d] === 'string') {
104
- injects[globalObject + '.' + d] = [source, define[d]];
104
+ if (hasPlatformFile) {
105
+ injects[globalObject + '.' + d] = [source, define[d]];
106
+ }
105
107
  }
106
108
  else {
107
109
  const defineOptions = define[d];
@@ -34,11 +34,12 @@ export declare function cssPlugin(config: ResolvedConfig): Plugin;
34
34
  /**
35
35
  * Plugin applied after user plugins
36
36
  */
37
- export declare function cssPostPlugin(config: ResolvedConfig, { platform, isJsCode, chunkCssFilename, chunkCssCode, }: {
37
+ export declare function cssPostPlugin(config: ResolvedConfig, { platform, isJsCode, chunkCssFilename, chunkCssCode, includeComponentCss, }: {
38
38
  platform: UniApp.PLATFORM;
39
39
  isJsCode?: boolean;
40
40
  chunkCssFilename: (id: string) => string | void;
41
41
  chunkCssCode: (filename: string, cssCode: string) => Promise<string> | string;
42
+ includeComponentCss?: boolean;
42
43
  }): Plugin;
43
44
  export declare function formatPostcssSourceMap(rawMap: ExistingRawSourceMap, file: string): ExistingRawSourceMap;
44
45
  export declare const cssUrlRE: RegExp;
@@ -110,7 +110,7 @@ function cssPlugin(config) {
110
110
  };
111
111
  }
112
112
  exports.cssPlugin = cssPlugin;
113
- function findCssModuleIds(moduleId, cssModuleIds, seen) {
113
+ function findCssModuleIds(moduleId, includeComponentCss = true, cssModuleIds, seen) {
114
114
  if (!cssModuleIds) {
115
115
  cssModuleIds = new Set();
116
116
  }
@@ -132,7 +132,12 @@ function findCssModuleIds(moduleId, cssModuleIds, seen) {
132
132
  cssModuleIds.add(id);
133
133
  }
134
134
  else {
135
- findCssModuleIds.call(this, id, cssModuleIds, seen);
135
+ if (!includeComponentCss &&
136
+ (id.includes('.vue') || id.includes('.uvue') || id.includes('.nvue'))) {
137
+ // 不包含组件样式,不需要继续查找,uni x中不需要包含
138
+ return;
139
+ }
140
+ findCssModuleIds.call(this, id, includeComponentCss, cssModuleIds, seen);
136
141
  }
137
142
  });
138
143
  }
@@ -141,7 +146,7 @@ function findCssModuleIds(moduleId, cssModuleIds, seen) {
141
146
  /**
142
147
  * Plugin applied after user plugins
143
148
  */
144
- function cssPostPlugin(config, { platform, isJsCode, chunkCssFilename, chunkCssCode, }) {
149
+ function cssPostPlugin(config, { platform, isJsCode, chunkCssFilename, chunkCssCode, includeComponentCss, }) {
145
150
  // styles initialization in buildStart causes a styling loss in watch
146
151
  const styles = new Map();
147
152
  let cssChunks;
@@ -172,7 +177,7 @@ function cssPostPlugin(config, { platform, isJsCode, chunkCssFilename, chunkCssC
172
177
  const filename = chunkCssFilename(id);
173
178
  if (filename) {
174
179
  if (platform === 'app' &&
175
- (filename === 'app.css' || filename === 'App.vue.style.uts')) {
180
+ (filename === 'app.css' || filename.startsWith('App.vue.style'))) {
176
181
  // 获取 unocss 的样式文件信息
177
182
  const ids = Object.keys(chunk.modules).filter((id) => styles.has(id) &&
178
183
  (id.includes('__uno.css') || id.includes('-unocss-')));
@@ -183,7 +188,7 @@ function cssPostPlugin(config, { platform, isJsCode, chunkCssFilename, chunkCssC
183
188
  // 当页面作为组件使用时,上一步找不到依赖的css,需要再次查找
184
189
  // renderChunk会执行两次,一次是页面chunk,一次是组件chunk,两者生成的css文件名和内容都是一样的
185
190
  if (!ids.length) {
186
- ids = [...findCssModuleIds.call(this, id)];
191
+ ids = [...findCssModuleIds.call(this, id, includeComponentCss)];
187
192
  }
188
193
  cssChunks.set(filename, ids);
189
194
  }
@@ -198,7 +203,7 @@ function cssPostPlugin(config, { platform, isJsCode, chunkCssFilename, chunkCssC
198
203
  moduleIds.forEach((id) => {
199
204
  const filename = chunkCssFilename(id);
200
205
  if (filename) {
201
- const ids = findCssModuleIds.call(this, id);
206
+ const ids = findCssModuleIds.call(this, id, includeComponentCss);
202
207
  if (cssChunks.has(filename)) {
203
208
  cssChunks.get(filename).forEach((id) => {
204
209
  ids.add(id);
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@dcloudio/uni-cli-shared",
3
- "version": "3.0.0-alpha-3080520230612002",
3
+ "version": "3.0.0-alpha-3080520230616001",
4
4
  "description": "@dcloudio/uni-cli-shared",
5
5
  "main": "dist/index.js",
6
6
  "types": "dist/index.d.ts",
@@ -25,8 +25,8 @@
25
25
  "@babel/core": "^7.21.3",
26
26
  "@babel/parser": "^7.16.4",
27
27
  "@babel/types": "^7.20.7",
28
- "@dcloudio/uni-i18n": "3.0.0-alpha-3080520230612002",
29
- "@dcloudio/uni-shared": "3.0.0-alpha-3080520230612002",
28
+ "@dcloudio/uni-i18n": "3.0.0-alpha-3080520230616001",
29
+ "@dcloudio/uni-shared": "3.0.0-alpha-3080520230616001",
30
30
  "@intlify/core-base": "9.1.9",
31
31
  "@intlify/shared": "9.1.9",
32
32
  "@intlify/vue-devtools": "9.1.9",
@@ -64,7 +64,7 @@
64
64
  },
65
65
  "gitHead": "33e807d66e1fe47e2ee08ad9c59247e37b8884da",
66
66
  "devDependencies": {
67
- "@dcloudio/uni-uts-v1": "3.0.0-alpha-3080520230612002",
67
+ "@dcloudio/uni-uts-v1": "3.0.0-alpha-3080520230616001",
68
68
  "@types/babel__core": "^7.1.19",
69
69
  "@types/debug": "^4.1.7",
70
70
  "@types/estree": "^0.0.51",