@iflyrpa/playwright 1.0.8 → 1.0.9

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.
Files changed (3) hide show
  1. package/dist/index.cjs +163 -42
  2. package/dist/index.mjs +159 -36
  3. package/package.json +2 -12
package/dist/index.cjs CHANGED
@@ -1,23 +1,20 @@
1
1
  'use strict';
2
2
 
3
- const semver = require('semver');
4
3
  const path = require('node:path');
5
- const axios = require('axios');
6
- const fs = require('fs-extra');
4
+ const fs = require('node:fs');
5
+ const https = require('node:https');
7
6
  const electron = require('electron');
8
- const spawn = require('cross-spawn');
7
+ const node_child_process = require('node:child_process');
9
8
 
10
9
  function _interopDefaultCompat (e) { return e && typeof e === 'object' && 'default' in e ? e.default : e; }
11
10
 
12
- const semver__default = /*#__PURE__*/_interopDefaultCompat(semver);
13
11
  const path__default = /*#__PURE__*/_interopDefaultCompat(path);
14
- const axios__default = /*#__PURE__*/_interopDefaultCompat(axios);
15
12
  const fs__default = /*#__PURE__*/_interopDefaultCompat(fs);
16
- const spawn__default = /*#__PURE__*/_interopDefaultCompat(spawn);
13
+ const https__default = /*#__PURE__*/_interopDefaultCompat(https);
17
14
 
18
15
  const name = "@iflyrpa/playwright";
19
16
  const type = "module";
20
- const version$1 = "1.0.8";
17
+ const version$1 = "1.0.9";
21
18
  const description = "";
22
19
  const main = "./dist/index.cjs";
23
20
  const module$1 = "./dist/index.mjs";
@@ -35,23 +32,13 @@ const files = [
35
32
  "dist"
36
33
  ];
37
34
  const dependencies = {
38
- axios: "^1.7.4",
39
- "cross-spawn": "^7.0.3",
40
- deepmerge: "^4.3.1",
41
- "fs-extra": "^11.2.0",
42
- playwright: "^1.46.1",
43
- semver: "^7.6.3"
35
+ playwright: "^1.46.1"
44
36
  };
45
37
  const peerDependencies = {
46
38
  electron: "*"
47
39
  };
48
40
  const devDependencies = {
49
- "@types/cross-spawn": "^6.0.6",
50
- "@types/fs-extra": "^11.0.4",
51
- "@types/semver": "^7.5.8",
52
- bumpp: "^9.5.2",
53
41
  esno: "^4.7.0",
54
- "ts-node": "^10.9.2",
55
42
  typescript: "^5.5.2",
56
43
  unbuild: "^2.0.0"
57
44
  };
@@ -73,25 +60,159 @@ const packageJson = {
73
60
  devDependencies: devDependencies
74
61
  };
75
62
 
76
- async function downloadImage(url, path2) {
77
- const response = await axios__default({
78
- url,
79
- method: "GET",
80
- responseType: "stream"
81
- // 重要:设置响应类型为 'stream'
82
- });
83
- await fs__default.ensureFile(path2);
84
- const writer = fs__default.createWriteStream(path2);
85
- response.data.pipe(writer);
63
+ async function downloadImage(url, savePath) {
64
+ await ensureFile(savePath);
86
65
  return new Promise((resolve, reject) => {
87
- writer.on("finish", () => resolve(path2));
88
- writer.on("error", reject);
66
+ https__default.get(url, (response) => {
67
+ if (response.statusCode === 200) {
68
+ const fileStream = fs__default.createWriteStream(savePath);
69
+ response.pipe(fileStream);
70
+ fileStream.on("finish", () => {
71
+ fileStream.close();
72
+ console.log("\u4E0B\u8F7D\u5B8C\u6210\uFF0C\u6587\u4EF6\u5DF2\u4FDD\u5B58\u81F3:", savePath);
73
+ resolve(savePath);
74
+ });
75
+ } else {
76
+ console.log("\u56FE\u7247\u4E0B\u8F7D\u5931\u8D25:", response.statusCode);
77
+ response.resume();
78
+ reject();
79
+ }
80
+ }).on("error", (error) => {
81
+ console.error("\u8BF7\u6C42\u56FE\u7247\u65F6\u53D1\u751F\u9519\u8BEF:", error.message);
82
+ reject();
83
+ });
89
84
  });
90
85
  }
91
86
  function getFilenameFromUrl(imageUrl) {
92
87
  const parsedUrl = new URL(imageUrl);
93
88
  return path__default.basename(parsedUrl.pathname);
94
89
  }
90
+ function pathExists(path2) {
91
+ return new Promise((resolve) => {
92
+ fs__default.stat(path2, (err) => {
93
+ resolve(!err);
94
+ });
95
+ });
96
+ }
97
+ function ensureFile(filePath) {
98
+ return new Promise((resolve, reject) => {
99
+ const dirPath = path__default.dirname(filePath);
100
+ fs__default.stat(dirPath, (err, stats) => {
101
+ if (err) {
102
+ if (err.code === "ENOENT") {
103
+ fs__default.mkdir(dirPath, { recursive: true }, (err2) => {
104
+ if (err2) {
105
+ return reject(err2);
106
+ }
107
+ createFile();
108
+ });
109
+ } else {
110
+ return reject(err);
111
+ }
112
+ } else if (stats.isDirectory()) {
113
+ checkFile();
114
+ } else {
115
+ reject(new Error(`${dirPath} is not a directory`));
116
+ }
117
+ });
118
+ function checkFile() {
119
+ fs__default.stat(filePath, (err, stats) => {
120
+ if (err) {
121
+ if (err.code === "ENOENT") {
122
+ createFile();
123
+ } else {
124
+ reject(err);
125
+ }
126
+ } else if (stats.isFile()) {
127
+ resolve();
128
+ } else {
129
+ reject(new Error(`${filePath} is not a file`));
130
+ }
131
+ });
132
+ }
133
+ function createFile() {
134
+ fs__default.writeFile(filePath, "", (err) => {
135
+ if (err) {
136
+ reject(err);
137
+ } else {
138
+ resolve();
139
+ }
140
+ });
141
+ }
142
+ });
143
+ }
144
+ function ensureFileSync(filePath) {
145
+ const dirPath = path__default.dirname(filePath);
146
+ try {
147
+ if (!fs__default.existsSync(dirPath)) {
148
+ fs__default.mkdirSync(dirPath, { recursive: true });
149
+ }
150
+ } catch (err) {
151
+ if (err instanceof Error) {
152
+ throw new Error(`Error creating directory: ${err.message}`);
153
+ }
154
+ }
155
+ try {
156
+ if (!fs__default.existsSync(filePath)) {
157
+ fs__default.writeFileSync(filePath, "");
158
+ }
159
+ } catch (err) {
160
+ if (err instanceof Error) {
161
+ throw new Error(`Error creating file: ${err.message}`);
162
+ }
163
+ }
164
+ }
165
+ function writeFile(filePath, data) {
166
+ return new Promise((resolve, reject) => {
167
+ fs__default.writeFile(filePath, data, (err) => {
168
+ if (err) {
169
+ console.error("Error writing file:", err);
170
+ reject();
171
+ } else {
172
+ console.log("File written successfully");
173
+ resolve();
174
+ }
175
+ });
176
+ });
177
+ }
178
+ function compareVersions(v1, v2) {
179
+ const parts1 = v1.split(".").map(Number);
180
+ const parts2 = v2.split(".").map(Number);
181
+ for (let i = 0; i < Math.max(parts1.length, parts2.length); i++) {
182
+ const num1 = i < parts1.length ? parts1[i] : 0;
183
+ const num2 = i < parts2.length ? parts2[i] : 0;
184
+ if (num1 > num2)
185
+ return 1;
186
+ if (num1 < num2)
187
+ return -1;
188
+ }
189
+ return 0;
190
+ }
191
+ const semver = {
192
+ gt: (v1, v2) => compareVersions(v1, v2) === 1
193
+ };
194
+ function fetchJSON(url) {
195
+ return new Promise((resolve, reject) => {
196
+ https__default.get(url, (res) => {
197
+ let data = "";
198
+ res.on("data", (chunk) => {
199
+ data += chunk;
200
+ });
201
+ res.on("end", () => {
202
+ try {
203
+ const parsedData = JSON.parse(data);
204
+ resolve(parsedData);
205
+ } catch (e) {
206
+ if (e instanceof Error) {
207
+ reject(new Error(`Error parsing JSON: ${e.message}`));
208
+ }
209
+ }
210
+ });
211
+ }).on("error", (err) => {
212
+ reject(new Error(`Request failed: ${err.message}`));
213
+ });
214
+ });
215
+ }
95
216
 
96
217
  const visibleRangeTexts = {
97
218
  public: "\u516C\u5F00",
@@ -224,10 +345,10 @@ app.on("window-all-closed", (e) => e.preventDefault());
224
345
  `;
225
346
  const generateFile = async (dir) => {
226
347
  const filePath = path__default.join(dir, "src", "main.js");
227
- const pathExists = await fs__default.pathExists(filePath);
228
- if (!pathExists) {
229
- await fs__default.ensureFile(filePath);
230
- await fs__default.writeFile(filePath, template);
348
+ const isPathExists = await pathExists(filePath);
349
+ if (!isPathExists) {
350
+ await ensureFile(filePath);
351
+ await writeFile(filePath, template);
231
352
  }
232
353
  return filePath;
233
354
  };
@@ -264,7 +385,7 @@ class PackageManager {
264
385
  return new Promise((resolve) => {
265
386
  const args = [cmd].concat(modules).concat("--color=always").concat("--save");
266
387
  try {
267
- const npm = spawn__default("npm", args, { cwd: where });
388
+ const npm = node_child_process.spawn("npm", args, { cwd: where });
268
389
  let output = "";
269
390
  npm.stdout?.on("data", (data) => {
270
391
  output += data;
@@ -297,16 +418,16 @@ class PackageManager {
297
418
  description: "rpa-plugins",
298
419
  license: "MIT"
299
420
  };
300
- fs__default.ensureFileSync(packagePath);
421
+ ensureFileSync(packagePath);
301
422
  fs__default.writeFileSync(packagePath, JSON.stringify(pkg), "utf8");
302
423
  }
303
424
  }
304
425
  // 获取依赖信息
305
426
  async getPluginInfo(module) {
306
- const res = await axios__default.get(
427
+ const res = await fetchJSON(
307
428
  `https://registry.npmjs.com/-/v1/search?text=${module}`
308
429
  );
309
- const packages = res.data.objects;
430
+ const packages = res.objects;
310
431
  return packages.find((it) => it.package.name === module)?.package;
311
432
  }
312
433
  // 查询本地安装的依赖
@@ -339,8 +460,8 @@ class PackageManager {
339
460
  } else if (this.forceUpdate) {
340
461
  const pkInfo = await this.getPluginInfo(name);
341
462
  if (!pkInfo)
342
- throw new Error("\u4F9D\u8D56\u4FE1\u606F\u83B7\u53D6\u5931\u8D25");
343
- const hasNewVersion = semver__default.gt(pkInfo.version, plugin.version);
463
+ return;
464
+ const hasNewVersion = semver.gt(pkInfo.version, plugin.version);
344
465
  if (hasNewVersion) {
345
466
  await this.install(name, pkInfo.version);
346
467
  }
@@ -449,7 +570,7 @@ const RpaTask = (params) => {
449
570
  cacheDir: params.cachePath
450
571
  });
451
572
  const localPackge = packageManager.getPlugin(packageJson.name);
452
- if (localPackge?.LocalAutomateTask && localPackge?.version && semver__default.gt(localPackge.version, packageJson.version)) {
573
+ if (localPackge?.LocalAutomateTask && localPackge?.version && semver.gt(localPackge.version, packageJson.version)) {
453
574
  return new localPackge.LocalAutomateTask(params);
454
575
  }
455
576
  return new LocalAutomateTask(params);
package/dist/index.mjs CHANGED
@@ -1,13 +1,12 @@
1
- import semver from 'semver';
2
1
  import path from 'node:path';
3
- import axios from 'axios';
4
- import fs from 'fs-extra';
2
+ import fs from 'node:fs';
3
+ import https from 'node:https';
5
4
  import { app } from 'electron';
6
- import spawn from 'cross-spawn';
5
+ import { spawn } from 'node:child_process';
7
6
 
8
7
  const name = "@iflyrpa/playwright";
9
8
  const type = "module";
10
- const version$1 = "1.0.8";
9
+ const version$1 = "1.0.9";
11
10
  const description = "";
12
11
  const main = "./dist/index.cjs";
13
12
  const module = "./dist/index.mjs";
@@ -25,23 +24,13 @@ const files = [
25
24
  "dist"
26
25
  ];
27
26
  const dependencies = {
28
- axios: "^1.7.4",
29
- "cross-spawn": "^7.0.3",
30
- deepmerge: "^4.3.1",
31
- "fs-extra": "^11.2.0",
32
- playwright: "^1.46.1",
33
- semver: "^7.6.3"
27
+ playwright: "^1.46.1"
34
28
  };
35
29
  const peerDependencies = {
36
30
  electron: "*"
37
31
  };
38
32
  const devDependencies = {
39
- "@types/cross-spawn": "^6.0.6",
40
- "@types/fs-extra": "^11.0.4",
41
- "@types/semver": "^7.5.8",
42
- bumpp: "^9.5.2",
43
33
  esno: "^4.7.0",
44
- "ts-node": "^10.9.2",
45
34
  typescript: "^5.5.2",
46
35
  unbuild: "^2.0.0"
47
36
  };
@@ -63,25 +52,159 @@ const packageJson = {
63
52
  devDependencies: devDependencies
64
53
  };
65
54
 
66
- async function downloadImage(url, path2) {
67
- const response = await axios({
68
- url,
69
- method: "GET",
70
- responseType: "stream"
71
- // 重要:设置响应类型为 'stream'
72
- });
73
- await fs.ensureFile(path2);
74
- const writer = fs.createWriteStream(path2);
75
- response.data.pipe(writer);
55
+ async function downloadImage(url, savePath) {
56
+ await ensureFile(savePath);
76
57
  return new Promise((resolve, reject) => {
77
- writer.on("finish", () => resolve(path2));
78
- writer.on("error", reject);
58
+ https.get(url, (response) => {
59
+ if (response.statusCode === 200) {
60
+ const fileStream = fs.createWriteStream(savePath);
61
+ response.pipe(fileStream);
62
+ fileStream.on("finish", () => {
63
+ fileStream.close();
64
+ console.log("\u4E0B\u8F7D\u5B8C\u6210\uFF0C\u6587\u4EF6\u5DF2\u4FDD\u5B58\u81F3:", savePath);
65
+ resolve(savePath);
66
+ });
67
+ } else {
68
+ console.log("\u56FE\u7247\u4E0B\u8F7D\u5931\u8D25:", response.statusCode);
69
+ response.resume();
70
+ reject();
71
+ }
72
+ }).on("error", (error) => {
73
+ console.error("\u8BF7\u6C42\u56FE\u7247\u65F6\u53D1\u751F\u9519\u8BEF:", error.message);
74
+ reject();
75
+ });
79
76
  });
80
77
  }
81
78
  function getFilenameFromUrl(imageUrl) {
82
79
  const parsedUrl = new URL(imageUrl);
83
80
  return path.basename(parsedUrl.pathname);
84
81
  }
82
+ function pathExists(path2) {
83
+ return new Promise((resolve) => {
84
+ fs.stat(path2, (err) => {
85
+ resolve(!err);
86
+ });
87
+ });
88
+ }
89
+ function ensureFile(filePath) {
90
+ return new Promise((resolve, reject) => {
91
+ const dirPath = path.dirname(filePath);
92
+ fs.stat(dirPath, (err, stats) => {
93
+ if (err) {
94
+ if (err.code === "ENOENT") {
95
+ fs.mkdir(dirPath, { recursive: true }, (err2) => {
96
+ if (err2) {
97
+ return reject(err2);
98
+ }
99
+ createFile();
100
+ });
101
+ } else {
102
+ return reject(err);
103
+ }
104
+ } else if (stats.isDirectory()) {
105
+ checkFile();
106
+ } else {
107
+ reject(new Error(`${dirPath} is not a directory`));
108
+ }
109
+ });
110
+ function checkFile() {
111
+ fs.stat(filePath, (err, stats) => {
112
+ if (err) {
113
+ if (err.code === "ENOENT") {
114
+ createFile();
115
+ } else {
116
+ reject(err);
117
+ }
118
+ } else if (stats.isFile()) {
119
+ resolve();
120
+ } else {
121
+ reject(new Error(`${filePath} is not a file`));
122
+ }
123
+ });
124
+ }
125
+ function createFile() {
126
+ fs.writeFile(filePath, "", (err) => {
127
+ if (err) {
128
+ reject(err);
129
+ } else {
130
+ resolve();
131
+ }
132
+ });
133
+ }
134
+ });
135
+ }
136
+ function ensureFileSync(filePath) {
137
+ const dirPath = path.dirname(filePath);
138
+ try {
139
+ if (!fs.existsSync(dirPath)) {
140
+ fs.mkdirSync(dirPath, { recursive: true });
141
+ }
142
+ } catch (err) {
143
+ if (err instanceof Error) {
144
+ throw new Error(`Error creating directory: ${err.message}`);
145
+ }
146
+ }
147
+ try {
148
+ if (!fs.existsSync(filePath)) {
149
+ fs.writeFileSync(filePath, "");
150
+ }
151
+ } catch (err) {
152
+ if (err instanceof Error) {
153
+ throw new Error(`Error creating file: ${err.message}`);
154
+ }
155
+ }
156
+ }
157
+ function writeFile(filePath, data) {
158
+ return new Promise((resolve, reject) => {
159
+ fs.writeFile(filePath, data, (err) => {
160
+ if (err) {
161
+ console.error("Error writing file:", err);
162
+ reject();
163
+ } else {
164
+ console.log("File written successfully");
165
+ resolve();
166
+ }
167
+ });
168
+ });
169
+ }
170
+ function compareVersions(v1, v2) {
171
+ const parts1 = v1.split(".").map(Number);
172
+ const parts2 = v2.split(".").map(Number);
173
+ for (let i = 0; i < Math.max(parts1.length, parts2.length); i++) {
174
+ const num1 = i < parts1.length ? parts1[i] : 0;
175
+ const num2 = i < parts2.length ? parts2[i] : 0;
176
+ if (num1 > num2)
177
+ return 1;
178
+ if (num1 < num2)
179
+ return -1;
180
+ }
181
+ return 0;
182
+ }
183
+ const semver = {
184
+ gt: (v1, v2) => compareVersions(v1, v2) === 1
185
+ };
186
+ function fetchJSON(url) {
187
+ return new Promise((resolve, reject) => {
188
+ https.get(url, (res) => {
189
+ let data = "";
190
+ res.on("data", (chunk) => {
191
+ data += chunk;
192
+ });
193
+ res.on("end", () => {
194
+ try {
195
+ const parsedData = JSON.parse(data);
196
+ resolve(parsedData);
197
+ } catch (e) {
198
+ if (e instanceof Error) {
199
+ reject(new Error(`Error parsing JSON: ${e.message}`));
200
+ }
201
+ }
202
+ });
203
+ }).on("error", (err) => {
204
+ reject(new Error(`Request failed: ${err.message}`));
205
+ });
206
+ });
207
+ }
85
208
 
86
209
  const visibleRangeTexts = {
87
210
  public: "\u516C\u5F00",
@@ -214,10 +337,10 @@ app.on("window-all-closed", (e) => e.preventDefault());
214
337
  `;
215
338
  const generateFile = async (dir) => {
216
339
  const filePath = path.join(dir, "src", "main.js");
217
- const pathExists = await fs.pathExists(filePath);
218
- if (!pathExists) {
219
- await fs.ensureFile(filePath);
220
- await fs.writeFile(filePath, template);
340
+ const isPathExists = await pathExists(filePath);
341
+ if (!isPathExists) {
342
+ await ensureFile(filePath);
343
+ await writeFile(filePath, template);
221
344
  }
222
345
  return filePath;
223
346
  };
@@ -287,16 +410,16 @@ class PackageManager {
287
410
  description: "rpa-plugins",
288
411
  license: "MIT"
289
412
  };
290
- fs.ensureFileSync(packagePath);
413
+ ensureFileSync(packagePath);
291
414
  fs.writeFileSync(packagePath, JSON.stringify(pkg), "utf8");
292
415
  }
293
416
  }
294
417
  // 获取依赖信息
295
418
  async getPluginInfo(module) {
296
- const res = await axios.get(
419
+ const res = await fetchJSON(
297
420
  `https://registry.npmjs.com/-/v1/search?text=${module}`
298
421
  );
299
- const packages = res.data.objects;
422
+ const packages = res.objects;
300
423
  return packages.find((it) => it.package.name === module)?.package;
301
424
  }
302
425
  // 查询本地安装的依赖
@@ -329,7 +452,7 @@ class PackageManager {
329
452
  } else if (this.forceUpdate) {
330
453
  const pkInfo = await this.getPluginInfo(name);
331
454
  if (!pkInfo)
332
- throw new Error("\u4F9D\u8D56\u4FE1\u606F\u83B7\u53D6\u5931\u8D25");
455
+ return;
333
456
  const hasNewVersion = semver.gt(pkInfo.version, plugin.version);
334
457
  if (hasNewVersion) {
335
458
  await this.install(name, pkInfo.version);
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@iflyrpa/playwright",
3
3
  "type": "module",
4
- "version": "1.0.8",
4
+ "version": "1.0.9",
5
5
  "description": "",
6
6
  "main": "./dist/index.cjs",
7
7
  "module": "./dist/index.mjs",
@@ -16,23 +16,13 @@
16
16
  "license": "ISC",
17
17
  "files": ["dist"],
18
18
  "dependencies": {
19
- "axios": "^1.7.4",
20
- "cross-spawn": "^7.0.3",
21
- "deepmerge": "^4.3.1",
22
- "fs-extra": "^11.2.0",
23
- "playwright": "^1.46.1",
24
- "semver": "^7.6.3"
19
+ "playwright": "^1.46.1"
25
20
  },
26
21
  "peerDependencies": {
27
22
  "electron": "*"
28
23
  },
29
24
  "devDependencies": {
30
- "@types/cross-spawn": "^6.0.6",
31
- "@types/fs-extra": "^11.0.4",
32
- "@types/semver": "^7.5.8",
33
- "bumpp": "^9.5.2",
34
25
  "esno": "^4.7.0",
35
- "ts-node": "^10.9.2",
36
26
  "typescript": "^5.5.2",
37
27
  "unbuild": "^2.0.0"
38
28
  }