@dcloudio/uni-cli-shared 3.0.0-alpha-3080520230615001 → 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>;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@dcloudio/uni-cli-shared",
3
- "version": "3.0.0-alpha-3080520230615001",
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-3080520230615001",
29
- "@dcloudio/uni-shared": "3.0.0-alpha-3080520230615001",
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-3080520230615001",
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",