@iflyrpa/playwright 1.1.2 → 1.2.0

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/dist/index.cjs CHANGED
@@ -1,253 +1,238 @@
1
- 'use strict';
2
-
3
- const actions = require('@iflyrpa/actions');
4
- const fs = require('node:fs');
5
- const path = require('node:path');
6
- const childProcess = require('node:child_process');
7
- const os = require('node:os');
8
- const get = require('@electron/get');
9
- const extract = require('extract-zip');
10
- const share = require('@iflyrpa/share');
11
- const log = require('loglevel');
12
- const node = require('@sentry/node');
13
- const pacote = require('pacote');
14
-
15
- function _interopDefaultCompat (e) { return e && typeof e === 'object' && 'default' in e ? e.default : e; }
16
-
17
- const fs__default = /*#__PURE__*/_interopDefaultCompat(fs);
18
- const path__default = /*#__PURE__*/_interopDefaultCompat(path);
19
- const childProcess__default = /*#__PURE__*/_interopDefaultCompat(childProcess);
20
- const os__default = /*#__PURE__*/_interopDefaultCompat(os);
21
- const extract__default = /*#__PURE__*/_interopDefaultCompat(extract);
22
- const log__default = /*#__PURE__*/_interopDefaultCompat(log);
23
- const pacote__default = /*#__PURE__*/_interopDefaultCompat(pacote);
24
-
25
- const name = "@iflyrpa/playwright";
26
- const type = "module";
27
- const version$1 = "1.1.2";
28
- const main = "./dist/index.cjs";
29
- const module$1 = "./dist/index.mjs";
30
- const types = "./dist/index.d.ts";
31
- const scripts = {
32
- build: "unbuild",
33
- dev: "unbuild --stub",
34
- start: "esno src/index.ts"
35
- };
36
- const author = "bijinfeng";
37
- const license = "ISC";
38
- const files = [
39
- "dist"
40
- ];
41
- const peerDependencies = {
42
- playwright: "^1.46.1"
43
- };
44
- const devDependencies = {
45
- "@iflyrpa/share": "workspace:*",
46
- "@types/pacote": "^11.1.8",
47
- esno: "^4.7.0",
48
- playwright: "^1.46.1",
49
- typescript: "^5.5.2",
50
- unbuild: "^2.0.0"
51
- };
52
- const dependencies = {
53
- "@iflyrpa/actions": "workspace:*",
54
- "@iflyrpa/share": "workspace:*",
55
- "@electron/get": "^2.0.0",
56
- "@sentry/node": "^5.5.0",
57
- "extract-zip": "^2.0.1",
58
- loglevel: "^1.9.2",
59
- pacote: "^20.0.0"
60
- };
61
- const packageJson = {
62
- name: name,
63
- type: type,
64
- version: version$1,
65
- main: main,
66
- module: module$1,
67
- types: types,
68
- scripts: scripts,
69
- author: author,
70
- license: license,
71
- files: files,
72
- peerDependencies: peerDependencies,
73
- devDependencies: devDependencies,
74
- dependencies: dependencies
75
- };
76
-
77
- var __defProp$4 = Object.defineProperty;
78
- var __defNormalProp$4 = (obj, key, value) => key in obj ? __defProp$4(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
79
- var __publicField$4 = (obj, key, value) => {
80
- __defNormalProp$4(obj, typeof key !== "symbol" ? key + "" : key, value);
81
- return value;
1
+ "use strict";
2
+ var __webpack_require__ = {};
3
+ (()=>{
4
+ __webpack_require__.n = function(module) {
5
+ var getter = module && module.__esModule ? function() {
6
+ return module['default'];
7
+ } : function() {
8
+ return module;
9
+ };
10
+ __webpack_require__.d(getter, {
11
+ a: getter
12
+ });
13
+ return getter;
14
+ };
15
+ })();
16
+ (()=>{
17
+ __webpack_require__.d = function(exports1, definition) {
18
+ for(var key in definition)if (__webpack_require__.o(definition, key) && !__webpack_require__.o(exports1, key)) Object.defineProperty(exports1, key, {
19
+ enumerable: true,
20
+ get: definition[key]
21
+ });
22
+ };
23
+ })();
24
+ (()=>{
25
+ __webpack_require__.o = function(obj, prop) {
26
+ return Object.prototype.hasOwnProperty.call(obj, prop);
27
+ };
28
+ })();
29
+ (()=>{
30
+ __webpack_require__.r = function(exports1) {
31
+ if ('undefined' != typeof Symbol && Symbol.toStringTag) Object.defineProperty(exports1, Symbol.toStringTag, {
32
+ value: 'Module'
33
+ });
34
+ Object.defineProperty(exports1, '__esModule', {
35
+ value: true
36
+ });
37
+ };
38
+ })();
39
+ var __webpack_exports__ = {};
40
+ __webpack_require__.r(__webpack_exports__);
41
+ __webpack_require__.d(__webpack_exports__, {
42
+ version: ()=>src_version,
43
+ RpaTask: ()=>RpaTask
44
+ });
45
+ const actions_namespaceObject = require("@iflyrpa/actions");
46
+ var package_namespaceObject = {
47
+ i8: "1.2.0"
82
48
  };
49
+ const external_node_fs_namespaceObject = require("node:fs");
50
+ var external_node_fs_default = /*#__PURE__*/ __webpack_require__.n(external_node_fs_namespaceObject);
51
+ const external_node_path_namespaceObject = require("node:path");
52
+ var external_node_path_default = /*#__PURE__*/ __webpack_require__.n(external_node_path_namespaceObject);
53
+ const external_node_child_process_namespaceObject = require("node:child_process");
54
+ var external_node_child_process_default = /*#__PURE__*/ __webpack_require__.n(external_node_child_process_namespaceObject);
55
+ const external_node_os_namespaceObject = require("node:os");
56
+ var external_node_os_default = /*#__PURE__*/ __webpack_require__.n(external_node_os_namespaceObject);
57
+ const get_namespaceObject = require("@electron/get");
58
+ const external_extract_zip_namespaceObject = require("extract-zip");
59
+ var external_extract_zip_default = /*#__PURE__*/ __webpack_require__.n(external_extract_zip_namespaceObject);
60
+ function _define_property(obj, key, value) {
61
+ if (key in obj) Object.defineProperty(obj, key, {
62
+ value: value,
63
+ enumerable: true,
64
+ configurable: true,
65
+ writable: true
66
+ });
67
+ else obj[key] = value;
68
+ return obj;
69
+ }
83
70
  const ELECTRON_MIRROR = "http://npmmirror.com/mirrors/electron/";
84
71
  const ELECTRON_VERSION = "22.3.27";
85
72
  class ElectronInstall {
86
- constructor(task) {
87
- this.task = task;
88
- __publicField$4(this, "rootDir");
89
- __publicField$4(this, "electronPath");
90
- __publicField$4(this, "platformPath");
91
- __publicField$4(this, "version", ELECTRON_VERSION);
92
- this.platformPath = this.getPlatformPath();
93
- this.rootDir = path__default.join(task.packagesDir, `electron@${this.version}`);
94
- this.electronPath = path__default.join(this.rootDir, this.platformPath);
95
- }
96
- isInstalled() {
97
- try {
98
- if (fs__default.readFileSync(path__default.join(this.rootDir, "version"), "utf-8").replace(/^v/, "") !== this.version) {
99
- return false;
100
- }
101
- } catch (ignored) {
102
- return false;
73
+ isInstalled() {
74
+ try {
75
+ if (external_node_fs_default().readFileSync(external_node_path_default().join(this.rootDir, "version"), "utf-8").replace(/^v/, "") !== this.version) return false;
76
+ } catch (ignored) {
77
+ return false;
78
+ }
79
+ const electronPath = process.env.ELECTRON_OVERRIDE_DIST_PATH || external_node_path_default().join(this.rootDir, this.platformPath);
80
+ return external_node_fs_default().existsSync(electronPath);
103
81
  }
104
- const electronPath = process.env.ELECTRON_OVERRIDE_DIST_PATH || path__default.join(this.rootDir, this.platformPath);
105
- return fs__default.existsSync(electronPath);
106
- }
107
- getPlatformPath() {
108
- const platform = process.env.npm_config_platform || os__default.platform();
109
- switch (platform) {
110
- case "mas":
111
- case "darwin":
112
- return "Electron.app/Contents/MacOS/Electron";
113
- case "freebsd":
114
- case "openbsd":
115
- case "linux":
116
- return "electron";
117
- case "win32":
118
- return "electron.exe";
119
- default:
120
- throw new Error(
121
- `Electron builds are not available on platform: ${platform}`
122
- );
82
+ getPlatformPath() {
83
+ const platform = process.env.npm_config_platform || external_node_os_default().platform();
84
+ switch(platform){
85
+ case "mas":
86
+ case "darwin":
87
+ return "Electron.app/Contents/MacOS/Electron";
88
+ case "freebsd":
89
+ case "openbsd":
90
+ case "linux":
91
+ return "electron";
92
+ case "win32":
93
+ return "electron.exe";
94
+ default:
95
+ throw new Error(`Electron builds are not available on platform: ${platform}`);
96
+ }
123
97
  }
124
- }
125
- async install() {
126
- const installed = this.isInstalled();
127
- this.task.logger.info(`electron@${this.version} \u662F\u5426\u5DF2\u5B89\u88C5\uFF1A${installed}`);
128
- if (installed)
129
- return this.electronPath;
130
- const platform = process.env.npm_config_platform || process.platform;
131
- let arch = process.env.npm_config_arch || process.arch;
132
- if (platform === "darwin" && process.platform === "darwin" && arch === "x64" && process.env.npm_config_arch === void 0) {
133
- try {
134
- const output = childProcess__default.execSync(
135
- "sysctl -in sysctl.proc_translated"
136
- );
137
- if (output.toString().trim() === "1") {
138
- arch = "arm64";
98
+ async install() {
99
+ const installed = this.isInstalled();
100
+ this.task.logger.info(`electron@${this.version} 是否已安装:${installed}`);
101
+ if (installed) return this.electronPath;
102
+ const platform = process.env.npm_config_platform || process.platform;
103
+ let arch = process.env.npm_config_arch || process.arch;
104
+ if ("darwin" === platform && "darwin" === process.platform && "x64" === arch && void 0 === process.env.npm_config_arch) try {
105
+ const output = external_node_child_process_default().execSync("sysctl -in sysctl.proc_translated");
106
+ if ("1" === output.toString().trim()) arch = "arm64";
107
+ } catch {}
108
+ try {
109
+ this.task.logger.info(`electron@${this.version} 开始下载资源`);
110
+ const zipPath = await (0, get_namespaceObject.downloadArtifact)({
111
+ version: this.version,
112
+ artifactName: "electron",
113
+ force: "true" === process.env.force_no_cache,
114
+ cacheRoot: process.env.electron_config_cache,
115
+ checksums: void 0,
116
+ mirrorOptions: {
117
+ mirror: ELECTRON_MIRROR
118
+ },
119
+ platform,
120
+ arch
121
+ });
122
+ this.task.logger.info(`electron@${this.version} 开始解压资源`);
123
+ process.noAsar = true;
124
+ await external_extract_zip_default()(zipPath, {
125
+ dir: this.rootDir
126
+ });
127
+ this.task.logger.info(`electron@${this.version} 下载成功`);
128
+ return this.electronPath;
129
+ } catch (error) {
130
+ this.task.logger.error(`electron@${this.version} 下载失败`, error);
131
+ throw error;
139
132
  }
140
- } catch {
141
- }
142
133
  }
143
- try {
144
- this.task.logger.info(`electron@${this.version} \u5F00\u59CB\u4E0B\u8F7D\u8D44\u6E90`);
145
- const zipPath = await get.downloadArtifact({
146
- version: this.version,
147
- artifactName: "electron",
148
- force: process.env.force_no_cache === "true",
149
- cacheRoot: process.env.electron_config_cache,
150
- checksums: void 0,
151
- mirrorOptions: { mirror: ELECTRON_MIRROR },
152
- // 使用国内镜像下载
153
- platform,
154
- arch
155
- });
156
- this.task.logger.info(`electron@${this.version} \u5F00\u59CB\u89E3\u538B\u8D44\u6E90`);
157
- process.noAsar = true;
158
- await extract__default(zipPath, { dir: this.rootDir });
159
- this.task.logger.info(`electron@${this.version} \u4E0B\u8F7D\u6210\u529F`);
160
- return this.electronPath;
161
- } catch (error) {
162
- this.task.logger.error(`electron@${this.version} \u4E0B\u8F7D\u5931\u8D25`, error);
163
- throw error;
134
+ constructor(task){
135
+ _define_property(this, "task", void 0);
136
+ _define_property(this, "rootDir", void 0);
137
+ _define_property(this, "electronPath", void 0);
138
+ _define_property(this, "platformPath", void 0);
139
+ _define_property(this, "version", void 0);
140
+ this.task = task;
141
+ this.version = ELECTRON_VERSION;
142
+ this.platformPath = this.getPlatformPath();
143
+ this.rootDir = external_node_path_default().join(task.packagesDir, `electron@${this.version}`);
144
+ this.electronPath = external_node_path_default().join(this.rootDir, this.platformPath);
164
145
  }
165
- }
166
146
  }
167
-
168
- var __defProp$3 = Object.defineProperty;
169
- var __defNormalProp$3 = (obj, key, value) => key in obj ? __defProp$3(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
170
- var __publicField$3 = (obj, key, value) => {
171
- __defNormalProp$3(obj, typeof key !== "symbol" ? key + "" : key, value);
172
- return value;
173
- };
174
- class SentryInstance {
175
- constructor(dsn) {
176
- __publicField$3(this, "sentry");
177
- if (!dsn)
178
- return;
179
- this.sentry = new node.NodeClient({
180
- dsn,
181
- defaultIntegrations: false
147
+ const share_namespaceObject = require("@iflyrpa/share");
148
+ const external_loglevel_namespaceObject = require("loglevel");
149
+ var external_loglevel_default = /*#__PURE__*/ __webpack_require__.n(external_loglevel_namespaceObject);
150
+ const node_namespaceObject = require("@sentry/node");
151
+ function sentry_define_property(obj, key, value) {
152
+ if (key in obj) Object.defineProperty(obj, key, {
153
+ value: value,
154
+ enumerable: true,
155
+ configurable: true,
156
+ writable: true
182
157
  });
183
- }
184
- captureException(error) {
185
- this.sentry?.captureException(error);
186
- }
158
+ else obj[key] = value;
159
+ return obj;
160
+ }
161
+ class SentryInstance {
162
+ captureException(error) {
163
+ var _this_sentry;
164
+ null === (_this_sentry = this.sentry) || void 0 === _this_sentry || _this_sentry.captureException(error);
165
+ }
166
+ constructor(dsn){
167
+ sentry_define_property(this, "sentry", void 0);
168
+ if (!dsn) return;
169
+ this.sentry = new node_namespaceObject.NodeClient({
170
+ dsn,
171
+ defaultIntegrations: false
172
+ });
173
+ }
187
174
  }
188
175
  const sentry = new SentryInstance(process.env.RPA_SENTRY_DSN);
189
-
190
- var __defProp$2 = Object.defineProperty;
191
- var __defNormalProp$2 = (obj, key, value) => key in obj ? __defProp$2(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
192
- var __publicField$2 = (obj, key, value) => {
193
- __defNormalProp$2(obj, typeof key !== "symbol" ? key + "" : key, value);
194
- return value;
195
- };
196
- const _Logger = class _Logger {
197
- constructor(cachePath) {
198
- __publicField$2(this, "stream");
199
- if (_Logger.instance) {
200
- return _Logger.instance;
176
+ function logger_define_property(obj, key, value) {
177
+ if (key in obj) Object.defineProperty(obj, key, {
178
+ value: value,
179
+ enumerable: true,
180
+ configurable: true,
181
+ writable: true
182
+ });
183
+ else obj[key] = value;
184
+ return obj;
185
+ }
186
+ class Logger {
187
+ static getInstance(cachePath) {
188
+ if (!Logger.instance) Logger.instance = new Logger(cachePath);
189
+ return Logger.instance;
201
190
  }
202
- const logFile = path__default.join(cachePath, "rpa.log");
203
- share.ensureFileSync(logFile);
204
- this.stream = fs__default.createWriteStream(logFile, { flags: "a" });
205
- log__default.setLevel("debug");
206
- log__default.methodFactory = (methodName) => {
207
- return (message) => {
208
- this.stream.write(
209
- `[${( new Date()).toLocaleString()}] ${methodName.toUpperCase()}: ${message}
210
- `
211
- );
212
- };
213
- };
214
- log__default.setLevel(log__default.getLevel());
215
- _Logger.instance = this;
216
- }
217
- static getInstance(cachePath) {
218
- if (!_Logger.instance) {
219
- _Logger.instance = new _Logger(cachePath);
191
+ debug(...msg) {
192
+ external_loglevel_default().debug(...msg);
220
193
  }
221
- return _Logger.instance;
222
- }
223
- // biome-ignore lint/suspicious/noExplicitAny: <explanation>
224
- debug(...msg) {
225
- log__default.debug(...msg);
226
- }
227
- // biome-ignore lint/suspicious/noExplicitAny: <explanation>
228
- info(...msg) {
229
- log__default.info(...msg);
230
- }
231
- // biome-ignore lint/suspicious/noExplicitAny: <explanation>
232
- warn(...msg) {
233
- log__default.warn(...msg);
234
- }
235
- // error 级别的日志上报 sentry
236
- error(prefix, err) {
237
- const error = err || prefix;
238
- if (err instanceof Error) {
239
- err.message = `${prefix}\uFF1A${err.message}`;
194
+ info(...msg) {
195
+ external_loglevel_default().info(...msg);
240
196
  }
241
- log__default.error(error);
242
- sentry.captureException(error);
243
- }
244
- close() {
245
- this.stream.end();
246
- }
247
- };
248
- __publicField$2(_Logger, "instance", null);
249
- let Logger = _Logger;
250
-
197
+ warn(...msg) {
198
+ external_loglevel_default().warn(...msg);
199
+ }
200
+ error(prefix, err) {
201
+ let error = err || prefix;
202
+ if (err instanceof Error) err.message = `${prefix}:${err.message}`;
203
+ if ("object" == typeof err) error = `${prefix}:${JSON.stringify(err)}`;
204
+ external_loglevel_default().error(error);
205
+ sentry.captureException(error);
206
+ }
207
+ close() {
208
+ this.stream.end();
209
+ }
210
+ constructor(cachePath){
211
+ logger_define_property(this, "stream", void 0);
212
+ if (Logger.instance) return Logger.instance;
213
+ const logFile = external_node_path_default().join(cachePath, "rpa.log");
214
+ (0, share_namespaceObject.ensureFileSync)(logFile);
215
+ this.stream = external_node_fs_default().createWriteStream(logFile, {
216
+ flags: "a"
217
+ });
218
+ external_loglevel_default().setLevel("debug");
219
+ const logToFile = (level, message)=>{
220
+ const timestamp = new Date().toLocaleString();
221
+ this.stream.write(`[${timestamp}] ${level.toUpperCase()} ${message}\n`);
222
+ };
223
+ external_loglevel_default().methodFactory = (methodName, _level, _logger)=>(...messages)=>{
224
+ const formattedMessage = messages.map((message)=>{
225
+ if (message instanceof Error) return `${message.name}: ${message.message}\n${message.stack}`;
226
+ if ("object" == typeof message) return JSON.stringify(message);
227
+ return message;
228
+ }).join(" ");
229
+ logToFile(methodName, formattedMessage);
230
+ };
231
+ external_loglevel_default().setLevel(external_loglevel_default().getLevel());
232
+ Logger.instance = this;
233
+ }
234
+ }
235
+ logger_define_property(Logger, "instance", null);
251
236
  const template = `
252
237
  const { app } = require("electron");
253
238
 
@@ -255,245 +240,223 @@ app.whenReady().then(() => {});
255
240
 
256
241
  app.on("window-all-closed", (e) => e.preventDefault());
257
242
  `;
258
- const generateFile = async (dir) => {
259
- const filePath = path__default.join(dir, "main.js");
260
- const isPathExists = await share.pathExists(filePath);
261
- if (!isPathExists) {
262
- await share.ensureFile(filePath);
263
- await share.writeFile(filePath, template);
264
- }
265
- return filePath;
243
+ const generateFile = async (dir)=>{
244
+ const filePath = external_node_path_default().join(dir, "main.js");
245
+ const isPathExists = await (0, share_namespaceObject.pathExists)(filePath);
246
+ if (!isPathExists) {
247
+ await (0, share_namespaceObject.ensureFile)(filePath);
248
+ await (0, share_namespaceObject.writeFile)(filePath, template);
249
+ }
250
+ return filePath;
266
251
  };
267
- const launchElectronApp = async (cachePath, playwright, electronPath) => {
268
- const logger = Logger.getInstance(cachePath);
269
- try {
270
- const mainPath = await generateFile(cachePath);
271
- const electronApp = await playwright._electron.launch({
272
- executablePath: electronPath,
273
- // 获取 Electron 可执行文件的路径
274
- args: [mainPath],
275
- cwd: cachePath
276
- });
277
- logger.info(`electron \u542F\u52A8\u6210\u529F\uFF1A${electronPath} ${mainPath}`);
278
- return electronApp;
279
- } catch (error) {
280
- logger.error("electron \u542F\u52A8\u5931\u8D25\uFF1A", error);
281
- throw error;
282
- }
252
+ const launchElectronApp = async (cachePath, playwright, electronPath)=>{
253
+ const logger = Logger.getInstance(cachePath);
254
+ try {
255
+ const mainPath = await generateFile(cachePath);
256
+ const electronApp = await playwright._electron.launch({
257
+ executablePath: electronPath,
258
+ args: [
259
+ mainPath
260
+ ],
261
+ cwd: cachePath
262
+ });
263
+ logger.info(`electron 启动成功:${electronPath} ${mainPath}`);
264
+ return electronApp;
265
+ } catch (error) {
266
+ logger.error("electron 启动失败:", error);
267
+ throw error;
268
+ }
283
269
  };
284
-
270
+ const pacote_namespaceObject = require("@iflyrpa/pacote");
271
+ var pacote_default = /*#__PURE__*/ __webpack_require__.n(pacote_namespaceObject);
272
+ function packageManager_define_property(obj, key, value) {
273
+ if (key in obj) Object.defineProperty(obj, key, {
274
+ value: value,
275
+ enumerable: true,
276
+ configurable: true,
277
+ writable: true
278
+ });
279
+ else obj[key] = value;
280
+ return obj;
281
+ }
285
282
  const NPM_REGISTRY = "https://registry.npmmirror.com/";
286
283
  class PackageManager {
287
- constructor(task) {
288
- this.task = task;
289
- }
290
- // 获取依赖信息
291
- async getManifest(module) {
292
- try {
293
- return pacote__default.manifest(module, { registry: NPM_REGISTRY });
294
- } catch (error) {
295
- this.task.logger.error("\u83B7\u53D6\u4F9D\u8D56\u4FE1\u606F\u5931\u8D25", error);
296
- throw error;
284
+ async getManifest(module) {
285
+ try {
286
+ return pacote_default().manifest(module, {
287
+ registry: NPM_REGISTRY
288
+ });
289
+ } catch (error) {
290
+ this.task.logger.error("获取依赖信息失败", error);
291
+ throw error;
292
+ }
297
293
  }
298
- }
299
- // 安装依赖
300
- async extract(name, version = "latest") {
301
- const packageName = `${name}@${version}`;
302
- try {
303
- this.task.logger.info(`${packageName} \u5F00\u59CB\u5B89\u88C5`);
304
- await pacote__default.extract(
305
- packageName,
306
- path__default.join(this.task.packagesDir, packageName),
307
- { registry: NPM_REGISTRY }
308
- );
309
- this.task.logger.info(`${packageName} \u5B89\u88C5\u6210\u529F`);
310
- } catch (error) {
311
- this.task.logger.error(`${packageName} \u5B89\u88C5\u5931\u8D25`, error);
294
+ async extract(name, version = "latest") {
295
+ const packageName = `${name}@${version}`;
296
+ try {
297
+ this.task.logger.info(`${packageName} 开始安装`);
298
+ await pacote_default().extract(packageName, external_node_path_default().join(this.task.packagesDir, packageName), {
299
+ registry: NPM_REGISTRY
300
+ });
301
+ this.task.logger.info(`${packageName} 安装成功`);
302
+ } catch (error) {
303
+ this.task.logger.error(`${packageName} 安装失败`, error);
304
+ }
312
305
  }
313
- }
314
- // 查询本地安装的依赖
315
- require(module) {
316
- try {
317
- return require(path__default.join(this.task.packagesDir, module));
318
- } catch (error) {
319
- return null;
306
+ require(module) {
307
+ try {
308
+ return require(external_node_path_default().join(this.task.packagesDir, module));
309
+ } catch (error) {
310
+ return null;
311
+ }
320
312
  }
321
- }
322
- // 安装依赖
323
- async install(name, version) {
324
- const packageName = `${name}@${version}`;
325
- const plugin = this.require(packageName);
326
- this.task.logger.info(`${packageName} \u662F\u5426\u5DF2\u5B89\u88C5\uFF1A${!!plugin}`);
327
- if (!plugin) {
328
- await this.extract(name, version);
313
+ async install(name, version) {
314
+ const packageName = `${name}@${version}`;
315
+ const plugin = this.require(packageName);
316
+ this.task.logger.info(`${packageName} 是否已安装:${!!plugin}`);
317
+ if (!plugin) await this.extract(name, version);
329
318
  }
330
- }
331
- // 更新依赖
332
- async update(name) {
333
- const manifest = await this.getManifest(`${name}@latest`);
334
- const version = manifest.version;
335
- const plugin = this.require(`${name}@${version}`);
336
- if (!plugin) {
337
- await this.extract(name, version);
319
+ async update(name) {
320
+ const manifest = await this.getManifest(`${name}@latest`);
321
+ const version = manifest.version;
322
+ const plugin = this.require(`${name}@${version}`);
323
+ if (plugin) this.task.logger.info(`${name}@${version} 已是最新版本`);
324
+ else {
325
+ await this.extract(name, version);
326
+ this.task.logger.info(`${name}@${version} 安装成功`);
327
+ }
328
+ return version;
329
+ }
330
+ constructor(task){
331
+ packageManager_define_property(this, "task", void 0);
332
+ this.task = task;
338
333
  }
339
- return version;
340
- }
341
334
  }
342
-
343
- var __defProp$1 = Object.defineProperty;
344
- var __defNormalProp$1 = (obj, key, value) => key in obj ? __defProp$1(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
345
- var __publicField$1 = (obj, key, value) => {
346
- __defNormalProp$1(obj, typeof key !== "symbol" ? key + "" : key, value);
347
- return value;
348
- };
335
+ function task_define_property(obj, key, value) {
336
+ if (key in obj) Object.defineProperty(obj, key, {
337
+ value: value,
338
+ enumerable: true,
339
+ configurable: true,
340
+ writable: true
341
+ });
342
+ else obj[key] = value;
343
+ return obj;
344
+ }
349
345
  const PLAYWRIGHT_VERSION = "1.46.1";
350
346
  const PLAYWRIGHT_NAME = "playwright-core";
351
347
  class Task {
352
- constructor({ cachePath, debug }) {
353
- __publicField$1(this, "logger");
354
- __publicField$1(this, "cachePath");
355
- __publicField$1(this, "debug");
356
- __publicField$1(this, "packagesDir");
357
- // 依赖安装目录
358
- __publicField$1(this, "packageManager");
359
- __publicField$1(this, "playwrightPackage");
360
- __publicField$1(this, "electronPackage");
361
- __publicField$1(this, "_electronApp", null);
362
- /**
363
- * 应用是否已关闭
364
- */
365
- __publicField$1(this, "isClosed", false);
366
- this.cachePath = cachePath;
367
- this.packagesDir = path__default.join(cachePath, "packages");
368
- this.debug = debug || false;
369
- this.logger = Logger.getInstance(cachePath);
370
- this.packageManager = new PackageManager(this);
371
- this.playwrightPackage = this.installPlaywright();
372
- this.electronPackage = this.installElectron();
373
- }
374
- /**
375
- * 安装 playwright
376
- * @returns
377
- */
378
- async installPlaywright() {
379
- const packageName = `${PLAYWRIGHT_NAME}@${PLAYWRIGHT_VERSION}`;
380
- await this.packageManager.install(PLAYWRIGHT_NAME, PLAYWRIGHT_VERSION);
381
- return this.packageManager.require(packageName);
382
- }
383
- /**
384
- * 安装 electron
385
- * @returns
386
- */
387
- installElectron() {
388
- return new ElectronInstall(this).install();
389
- }
390
- /**
391
- * 启动 Electron
392
- * @returns
393
- */
394
- async launchApp() {
395
- if (!this._electronApp) {
396
- const [playwright, electronPath] = await Promise.all([
397
- this.playwrightPackage,
398
- this.electronPackage
399
- ]);
400
- this._electronApp = await launchElectronApp(
401
- this.cachePath,
402
- playwright,
403
- electronPath
404
- );
348
+ async installPlaywright() {
349
+ const packageName = `${PLAYWRIGHT_NAME}@${PLAYWRIGHT_VERSION}`;
350
+ await this.packageManager.install(PLAYWRIGHT_NAME, PLAYWRIGHT_VERSION);
351
+ return this.packageManager.require(packageName);
352
+ }
353
+ installElectron() {
354
+ return new ElectronInstall(this).install();
355
+ }
356
+ async launchApp() {
357
+ if (!this._electronApp) {
358
+ const [playwright, electronPath] = await Promise.all([
359
+ this.playwrightPackage,
360
+ this.electronPackage
361
+ ]);
362
+ this._electronApp = await launchElectronApp(this.cachePath, playwright, electronPath);
363
+ }
364
+ return this._electronApp;
365
+ }
366
+ getTmpPath() {
367
+ return external_node_path_default().join(this.cachePath, "tmp");
368
+ }
369
+ clearTmpPath() {
370
+ const tmpPath = this.getTmpPath();
371
+ return external_node_fs_default().rm(tmpPath, {
372
+ recursive: true,
373
+ force: true
374
+ }, (err)=>{
375
+ if (err) this.logger.error("删除临时文件失败,", err);
376
+ else this.logger.info("删除临时文件成功");
377
+ });
378
+ }
379
+ async close() {
380
+ var _this__electronApp;
381
+ this.logger.info("关闭应用");
382
+ this.clearTmpPath();
383
+ this.logger.close();
384
+ await (null === (_this__electronApp = this._electronApp) || void 0 === _this__electronApp ? void 0 : _this__electronApp.close());
385
+ this.isClosed = true;
386
+ this._electronApp = null;
387
+ }
388
+ async createPage(pageParams) {
389
+ const electronApp = await this.launchApp();
390
+ const [page] = await Promise.all([
391
+ electronApp.waitForEvent("window"),
392
+ electronApp.evaluate(async (electron, { pageParams })=>{
393
+ await electron.app.whenReady();
394
+ const window = new electron.BrowserWindow({
395
+ show: pageParams.show,
396
+ width: 1500,
397
+ height: 800,
398
+ webPreferences: {
399
+ nodeIntegration: true,
400
+ contextIsolation: false
401
+ }
402
+ });
403
+ if (pageParams.cookies) await Promise.all(pageParams.cookies.map((cookie)=>electron.session.defaultSession.cookies.set(cookie)));
404
+ await window.loadURL(pageParams.url);
405
+ }, {
406
+ pageParams
407
+ })
408
+ ]);
409
+ return page;
405
410
  }
406
- return this._electronApp;
407
- }
408
- /**
409
- * 临时文件目录
410
- * @returns
411
- */
412
- getTmpPath() {
413
- return path__default.join(this.cachePath, "tmp");
414
- }
415
- /**
416
- * 清空临时文件
417
- */
418
- clearTmpPath() {
419
- const tmpPath = this.getTmpPath();
420
- return fs__default.rm(tmpPath, { recursive: true, force: true }, (err) => {
421
- if (err) {
422
- this.logger.error("\u5220\u9664\u4E34\u65F6\u6587\u4EF6\u5931\u8D25\uFF0C", err);
423
- } else {
424
- this.logger.info("\u5220\u9664\u4E34\u65F6\u6587\u4EF6\u6210\u529F");
425
- }
411
+ constructor({ cachePath, debug }){
412
+ task_define_property(this, "logger", void 0);
413
+ task_define_property(this, "cachePath", void 0);
414
+ task_define_property(this, "debug", void 0);
415
+ task_define_property(this, "packagesDir", void 0);
416
+ task_define_property(this, "packageManager", void 0);
417
+ task_define_property(this, "playwrightPackage", void 0);
418
+ task_define_property(this, "electronPackage", void 0);
419
+ task_define_property(this, "_electronApp", null);
420
+ task_define_property(this, "isClosed", false);
421
+ this.cachePath = cachePath;
422
+ this.packagesDir = external_node_path_default().join(cachePath, "packages");
423
+ this.debug = debug || false;
424
+ this.logger = Logger.getInstance(cachePath);
425
+ this.packageManager = new PackageManager(this);
426
+ this.playwrightPackage = this.installPlaywright();
427
+ this.electronPackage = this.installElectron();
428
+ }
429
+ }
430
+ function src_define_property(obj, key, value) {
431
+ if (key in obj) Object.defineProperty(obj, key, {
432
+ value: value,
433
+ enumerable: true,
434
+ configurable: true,
435
+ writable: true
426
436
  });
427
- }
428
- /**
429
- * 关闭 playwright 启动的 electron 客户端
430
- * @returns
431
- */
432
- async close() {
433
- this.logger.info("\u5173\u95ED\u5E94\u7528");
434
- this.clearTmpPath();
435
- this.logger.close();
436
- await this._electronApp?.close();
437
- this.isClosed = true;
438
- this._electronApp = null;
439
- }
440
- async createPage(pageParams) {
441
- const electronApp = await this.launchApp();
442
- const [page] = await Promise.all([
443
- electronApp.waitForEvent("window"),
444
- electronApp.evaluate(
445
- async (electron, { pageParams: pageParams2 }) => {
446
- await electron.app.whenReady();
447
- const window = new electron.BrowserWindow({
448
- show: pageParams2.show,
449
- width: 1500,
450
- height: 800,
451
- webPreferences: {
452
- nodeIntegration: true,
453
- contextIsolation: false
454
- }
455
- });
456
- if (pageParams2.cookies) {
457
- await Promise.all(
458
- pageParams2.cookies.map(
459
- (cookie) => electron.session.defaultSession.cookies.set(cookie)
460
- )
461
- );
462
- }
463
- await window.loadURL(pageParams2.url);
464
- },
465
- { pageParams }
466
- )
467
- ]);
468
- return page;
469
- }
437
+ else obj[key] = value;
438
+ return obj;
470
439
  }
471
-
472
- var __defProp = Object.defineProperty;
473
- var __defNormalProp = (obj, key, value) => key in obj ? __defProp(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
474
- var __publicField = (obj, key, value) => {
475
- __defNormalProp(obj, typeof key !== "symbol" ? key + "" : key, value);
476
- return value;
477
- };
478
440
  class RpaTask extends Task {
479
- constructor(params) {
480
- super(params);
481
- __publicField(this, "actions");
482
- this.actions = new actions.Action(this);
483
- params.forceUpdate && this.update();
484
- }
485
- async update() {
486
- try {
487
- const name = "@iflyrpa/actions";
488
- const version2 = await this.packageManager.update(name);
489
- const actionPackage = this.packageManager.require(`${name}@${version2}`);
490
- actionPackage?.actions && (this.actions = actionPackage.actions);
491
- } catch (error) {
492
- this.logger.error("\u66F4\u65B0\u4F9D\u8D56\u5931\u8D25", error);
441
+ async update() {
442
+ try {
443
+ const name = "@iflyrpa/actions";
444
+ const version = await this.packageManager.update(name);
445
+ const actionPackage = this.packageManager.require(`${name}@${version}`);
446
+ (null == actionPackage ? void 0 : actionPackage.actions) && (this.actions = actionPackage.actions);
447
+ } catch (error) {
448
+ this.logger.error("更新依赖失败", error);
449
+ }
450
+ }
451
+ constructor(params){
452
+ super(params), src_define_property(this, "actions", void 0);
453
+ this.actions = new actions_namespaceObject.Action(this);
454
+ params.forceUpdate && this.update();
493
455
  }
494
- }
495
456
  }
496
- const version = packageJson.version;
497
-
498
- exports.RpaTask = RpaTask;
499
- exports.version = version;
457
+ const src_version = package_namespaceObject.i8;
458
+ var __webpack_export_target__ = exports;
459
+ for(var __webpack_i__ in __webpack_exports__)__webpack_export_target__[__webpack_i__] = __webpack_exports__[__webpack_i__];
460
+ if (__webpack_exports__.__esModule) Object.defineProperty(__webpack_export_target__, '__esModule', {
461
+ value: true
462
+ });