@iflyrpa/playwright 4.0.8 → 4.0.9-beta.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.d.ts CHANGED
@@ -10,6 +10,34 @@ import { User } from '@sentry/node';
10
10
 
11
11
  export { ActionMethodParams }
12
12
 
13
+ /**
14
+ * 脚本包(@iflyrpa/actions)的版本状态
15
+ */
16
+ export declare interface ActionVersionInfo {
17
+ /** 当前内存中实际生效的版本 */
18
+ current: string;
19
+ /** 随 @iflyrpa/playwright 一起打包的内置版本 */
20
+ bundled: string;
21
+ /** 远端 registry 上对应渠道的最新版本,未查询成功时为 null */
22
+ latest: string | null;
23
+ /** 远端存在更新且尚未生效(current !== latest) */
24
+ hasUpdate: boolean;
25
+ /** 更新已下载并热替换成功,无需重启 */
26
+ applied: boolean;
27
+ /** 本次查询使用的渠道:beta 由 GrowthBook 灰度开关决定 */
28
+ channel: "latest" | "beta";
29
+ /** 更新流程失败时的原因 */
30
+ error?: string;
31
+ }
32
+
33
+ /**
34
+ * 比较两个 semver 版本,a 比 b 新返回正数
35
+ *
36
+ * 只覆盖本仓库用到的 `x.y.z` 和 `x.y.z-beta.n` 两种形态,
37
+ * 按 semver 规则 prerelease 小于同版本号的正式版。
38
+ */
39
+ export declare function compareVersion(a: string, b: string): number;
40
+
13
41
  declare class Logger extends SentryInstance implements LoggerImplement {
14
42
  private stream;
15
43
  constructor(taskParams: TaskParams);
@@ -27,14 +55,64 @@ declare class PackageManager {
27
55
  private extract;
28
56
  require(module: string): any;
29
57
  install(name: string, version: string): Promise<void>;
30
- update(name: string): Promise<string>;
58
+ /**
59
+ * 查询远端指定 dist-tag 的版本号(只读,不下载)
60
+ *
61
+ * distTag 缺失时(比如从未发过 beta)回退到 latest,不阻断更新。
62
+ */
63
+ getVersionByTag(name: string, distTag?: string): Promise<string>;
64
+ /**
65
+ * 查询远端应当使用的版本号(只读,不下载)
66
+ *
67
+ * beta 渠道取 beta 与 latest 的较大值:beta tag 可能落后于正式版
68
+ * (正式版发布后 beta tag 不会自动前移),此时不应让灰度用户降级。
69
+ */
70
+ getLatestVersion(name: string, useBeta?: boolean): Promise<string>;
71
+ update(name: string, useBeta?: boolean): Promise<string>;
31
72
  }
32
73
 
33
74
  export declare class RpaTask extends Task {
34
75
  actions: RpaAction.Action;
35
76
  private actionName;
77
+ /** 内置版本,热更新失败时的回退基线 */
78
+ private readonly bundledActionVersion;
79
+ /** 内存中实际生效的版本 */
80
+ private currentActionVersion;
81
+ private latestActionVersion;
82
+ private appliedUpdate;
83
+ private updateChannel;
84
+ private updateError?;
85
+ /** 构造函数触发的更新任务,供 waitForUpdate 复用,避免重复请求 */
86
+ private updateTask;
36
87
  constructor(params: TaskParams);
37
88
  private registerActions;
89
+ /**
90
+ * 脚本包版本状态快照(同步,不发起网络请求)
91
+ *
92
+ * 第三方可用它与自己记录的版本比对,决定是否提示重启。
93
+ * 注意:applied 为 true 时更新已在内存中生效,无需重启。
94
+ */
95
+ getActionVersionInfo(): ActionVersionInfo;
96
+ /**
97
+ * 当前用户是否走灰度渠道
98
+ *
99
+ * 取决于 GrowthBook 的 HuiwenCanary 开关,未初始化时返回 false(走正式渠道)。
100
+ * 注意 GrowthBook 依赖 setUser 才会初始化,未调用 setUser 的场景恒为正式渠道。
101
+ */
102
+ private useBetaChannel;
103
+ /**
104
+ * 只查询远端最新版本号,不下载、不替换
105
+ *
106
+ * 适合"启动时静默检查有没有新版本"的场景。
107
+ */
108
+ checkActionUpdate(): Promise<ActionVersionInfo>;
109
+ /**
110
+ * 等待构造函数触发的更新流程结束,返回最终版本状态
111
+ *
112
+ * forceUpdate 为 false 时会主动执行一次更新。
113
+ * 多次调用复用同一个任务,不会重复下载。
114
+ */
115
+ waitForActionUpdate(): Promise<ActionVersionInfo>;
38
116
  private update;
39
117
  }
40
118
 
package/dist/index.js CHANGED
@@ -1,5 +1,5 @@
1
1
 
2
- !function(){try{var e="undefined"!=typeof window?window:"undefined"!=typeof global?global:"undefined"!=typeof globalThis?globalThis:"undefined"!=typeof self?self:{},n=(new e.Error).stack;n&&(e._sentryDebugIds=e._sentryDebugIds||{},e._sentryDebugIds[n]="7135424a-8b43-5186-b3bf-add32278e972")}catch(e){}}();
2
+ !function(){try{var e="undefined"!=typeof window?window:"undefined"!=typeof global?global:"undefined"!=typeof globalThis?globalThis:"undefined"!=typeof self?self:{},n=(new e.Error).stack;n&&(e._sentryDebugIds=e._sentryDebugIds||{},e._sentryDebugIds[n]="5aee042a-271f-593f-94b2-737064f7b3b3")}catch(e){}}();
3
3
  import * as __WEBPACK_EXTERNAL_MODULE_punycode__ from "punycode";
4
4
  import * as __WEBPACK_EXTERNAL_MODULE_stream__ from "stream";
5
5
  import * as __WEBPACK_EXTERNAL_MODULE_http__ from "http";
@@ -2552,9 +2552,7 @@ function __webpack_require__(moduleId) {
2552
2552
  });
2553
2553
  };
2554
2554
  })();
2555
- var package_namespaceObject = {
2556
- i8: "4.0.8"
2557
- };
2555
+ var package_namespaceObject = JSON.parse('{"i8":"4.0.9-beta.0"}');
2558
2556
  function _define_property(obj, key, value) {
2559
2557
  if (key in obj) Object.defineProperty(obj, key, {
2560
2558
  value: value,
@@ -5363,10 +5361,45 @@ function packageManager_define_property(obj, key, value) {
5363
5361
  return obj;
5364
5362
  }
5365
5363
  const NPM_REGISTRY = "https://registry.npmmirror.com/";
5364
+ const LATEST_TAG = "latest";
5365
+ const BETA_TAG = "beta";
5366
+ function compareVersion(a, b) {
5367
+ const parse = (v)=>{
5368
+ const [core, pre] = v.split("-");
5369
+ const nums = core.split(".").map(Number);
5370
+ return {
5371
+ nums,
5372
+ pre
5373
+ };
5374
+ };
5375
+ const va = parse(a);
5376
+ const vb = parse(b);
5377
+ for(let i = 0; i < 3; i++){
5378
+ const diff = (va.nums[i] ?? 0) - (vb.nums[i] ?? 0);
5379
+ if (0 !== diff) return diff;
5380
+ }
5381
+ if (!va.pre && !vb.pre) return 0;
5382
+ if (!va.pre) return 1;
5383
+ if (!vb.pre) return -1;
5384
+ const pa = va.pre.split(".");
5385
+ const pb = vb.pre.split(".");
5386
+ for(let i = 0; i < Math.max(pa.length, pb.length); i++){
5387
+ const sa = pa[i];
5388
+ const sb = pb[i];
5389
+ if (void 0 === sa) return -1;
5390
+ if (void 0 === sb) return 1;
5391
+ const na = Number(sa);
5392
+ const nb = Number(sb);
5393
+ const bothNumeric = !Number.isNaN(na) && !Number.isNaN(nb);
5394
+ const diff = bothNumeric ? na - nb : sa.localeCompare(sb);
5395
+ if (0 !== diff) return diff;
5396
+ }
5397
+ return 0;
5398
+ }
5366
5399
  class PackageManager {
5367
5400
  async getManifest(module) {
5368
5401
  try {
5369
- return __WEBPACK_EXTERNAL_MODULE__iflyrpa_pacote_56da1cff__["default"].manifest(module, {
5402
+ return await __WEBPACK_EXTERNAL_MODULE__iflyrpa_pacote_56da1cff__["default"].manifest(module, {
5370
5403
  registry: NPM_REGISTRY
5371
5404
  });
5372
5405
  } catch (error) {
@@ -5397,9 +5430,25 @@ class PackageManager {
5397
5430
  const plugin = this.require(packageName);
5398
5431
  if (!plugin) await this.extract(name, version);
5399
5432
  }
5400
- async update(name) {
5401
- const manifest = await this.getManifest(`${name}@latest`);
5402
- const version = manifest.version;
5433
+ async getVersionByTag(name, distTag = LATEST_TAG) {
5434
+ try {
5435
+ const manifest = await this.getManifest(`${name}@${distTag}`);
5436
+ return manifest.version;
5437
+ } catch (error) {
5438
+ if (distTag === LATEST_TAG) throw error;
5439
+ this.task.logger.warn(`${name}@${distTag} 不存在,回退到 ${LATEST_TAG}`);
5440
+ const manifest = await this.getManifest(`${name}@${LATEST_TAG}`);
5441
+ return manifest.version;
5442
+ }
5443
+ }
5444
+ async getLatestVersion(name, useBeta = false) {
5445
+ const latest = await this.getVersionByTag(name, LATEST_TAG);
5446
+ if (!useBeta) return latest;
5447
+ const beta = await this.getVersionByTag(name, BETA_TAG);
5448
+ return compareVersion(beta, latest) > 0 ? beta : latest;
5449
+ }
5450
+ async update(name, useBeta = false) {
5451
+ const version = await this.getLatestVersion(name, useBeta);
5403
5452
  const plugin = this.require(`${name}@${version}/package.json`);
5404
5453
  if (!plugin) await this.extract(name, version);
5405
5454
  return version;
@@ -5628,25 +5677,73 @@ function src_define_property(obj, key, value) {
5628
5677
  class RpaTask extends Task {
5629
5678
  registerActions(rpaAction) {
5630
5679
  this.actions = new rpaAction.Action(this);
5680
+ this.currentActionVersion = rpaAction.version;
5631
5681
  this.setActionVersion(rpaAction.version);
5632
5682
  }
5683
+ getActionVersionInfo() {
5684
+ return {
5685
+ current: this.currentActionVersion,
5686
+ bundled: this.bundledActionVersion,
5687
+ latest: this.latestActionVersion,
5688
+ hasUpdate: !!this.latestActionVersion && this.latestActionVersion !== this.currentActionVersion,
5689
+ applied: this.appliedUpdate,
5690
+ channel: this.updateChannel,
5691
+ error: this.updateError
5692
+ };
5693
+ }
5694
+ useBetaChannel() {
5695
+ const useBeta = this.isFeatOn(__WEBPACK_EXTERNAL_MODULE__iflyrpa_actions_bd801d6f__.BetaFlag);
5696
+ this.updateChannel = useBeta ? "beta" : "latest";
5697
+ return useBeta;
5698
+ }
5699
+ async checkActionUpdate() {
5700
+ try {
5701
+ this.latestActionVersion = await this.packageManager.getLatestVersion(this.actionName, this.useBetaChannel());
5702
+ this.updateError = void 0;
5703
+ } catch (error) {
5704
+ this.updateError = error instanceof Error ? error.message : String(error);
5705
+ this.logger.error("检查脚本版本失败", error);
5706
+ }
5707
+ return this.getActionVersionInfo();
5708
+ }
5709
+ waitForActionUpdate() {
5710
+ if (!this.updateTask) this.updateTask = this.update();
5711
+ return this.updateTask;
5712
+ }
5633
5713
  async update() {
5634
5714
  try {
5635
- const version = await this.packageManager.update(this.actionName);
5715
+ const version = await this.packageManager.update(this.actionName, this.useBetaChannel());
5716
+ this.latestActionVersion = version;
5717
+ if (version === this.currentActionVersion) {
5718
+ this.appliedUpdate = false;
5719
+ return this.getActionVersionInfo();
5720
+ }
5636
5721
  const rpaPackage = this.packageManager.require(`${this.actionName}@${version}/dist/bundle.js`);
5637
- (null == rpaPackage ? void 0 : rpaPackage.Action) && this.registerActions(rpaPackage);
5722
+ if (null == rpaPackage ? void 0 : rpaPackage.Action) {
5723
+ this.registerActions(rpaPackage);
5724
+ this.appliedUpdate = true;
5725
+ this.updateError = void 0;
5726
+ this.logger.info(`脚本已热更新至 ${version}`);
5727
+ } else {
5728
+ this.appliedUpdate = false;
5729
+ this.updateError = `加载 ${this.actionName}@${version} 失败`;
5730
+ this.logger.warn(this.updateError);
5731
+ }
5638
5732
  } catch (error) {
5733
+ this.appliedUpdate = false;
5734
+ this.updateError = error instanceof Error ? error.message : String(error);
5639
5735
  this.logger.error("更新依赖失败", error);
5640
5736
  }
5737
+ return this.getActionVersionInfo();
5641
5738
  }
5642
5739
  constructor(params){
5643
- super(params), src_define_property(this, "actions", void 0), src_define_property(this, "actionName", "@iflyrpa/actions");
5740
+ super(params), src_define_property(this, "actions", void 0), src_define_property(this, "actionName", "@iflyrpa/actions"), src_define_property(this, "bundledActionVersion", __WEBPACK_EXTERNAL_MODULE__iflyrpa_actions_bd801d6f__.version), src_define_property(this, "currentActionVersion", __WEBPACK_EXTERNAL_MODULE__iflyrpa_actions_bd801d6f__.version), src_define_property(this, "latestActionVersion", null), src_define_property(this, "appliedUpdate", false), src_define_property(this, "updateChannel", "latest"), src_define_property(this, "updateError", void 0), src_define_property(this, "updateTask", null);
5644
5741
  this.registerActions(__WEBPACK_EXTERNAL_MODULE__iflyrpa_actions_bd801d6f__);
5645
- params.forceUpdate && this.update();
5742
+ if (params.forceUpdate) this.updateTask = this.update();
5646
5743
  }
5647
5744
  }
5648
5745
  const src_version = package_namespaceObject.i8;
5649
- export { RpaTask, src_version as version };
5746
+ export { RpaTask, compareVersion, src_version as version };
5650
5747
 
5651
5748
  //# sourceMappingURL=index.js.map
5652
- //# debugId=7135424a-8b43-5186-b3bf-add32278e972
5749
+ //# debugId=5aee042a-271f-593f-94b2-737064f7b3b3