@miniben90/x-win 3.5.0 → 3.6.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.
Files changed (4) hide show
  1. package/README.md +2 -2
  2. package/index.d.ts +4 -1
  3. package/index.js +155 -31
  4. package/package.json +31 -26
package/README.md CHANGED
@@ -150,7 +150,7 @@ setTimeout(() => unsubscribeActiveWindow(c), 5000)
150
150
  setTimeout(() => unsubscribeAllActiveWindow(), 10000)
151
151
  ```
152
152
 
153
- ### Get icon from `WindoInfo`
153
+ ### Get icon from `WindowInfo`
154
154
 
155
155
  It is possible to get an icon from the `WindowInfo` class object using `getIcon` or `getIconAsync`, which will return an `IconInfo` struct.
156
156
  The icon will be stored in `IconInfo.data` in base64 PNG format.
@@ -226,7 +226,7 @@ It is possible to get URL of browsers window for macOS and Windows.
226
226
  | microsoft edge | ✅ |
227
227
  | opera software - opera | ✅ |
228
228
  | opera software - opera GX | ✅ |
229
- | brave | |
229
+ | brave | ✅ |
230
230
  | vivaldi | |
231
231
  | iron | |
232
232
  | epic | |
package/index.d.ts CHANGED
@@ -246,7 +246,10 @@ export interface ProcessInfo {
246
246
  * ```
247
247
  *
248
248
  */
249
- export declare function subscribeActiveWindow(callback: (error: Error | null, info: WindowInfo | undefined) => void, interval?: number): number
249
+ export declare function subscribeActiveWindow(
250
+ callback: (error: Error | null, info: WindowInfo | undefined) => void,
251
+ interval?: number,
252
+ ): number
250
253
 
251
254
  /** * Uninstall "@mininben90/x-win" Gnome extension.
252
255
  * This function will disable and remove extension files.
package/index.js CHANGED
@@ -3,7 +3,7 @@
3
3
  // @ts-nocheck
4
4
  /* auto-generated by NAPI-RS */
5
5
 
6
- const { readFileSync } = require('node:fs')
6
+ const { readFileSync } = require('fs')
7
7
  let nativeBinding = null
8
8
  const loadErrors = []
9
9
 
@@ -33,7 +33,7 @@ const isMuslFromFilesystem = () => {
33
33
 
34
34
  const isMuslFromReport = () => {
35
35
  let report = null
36
- if (typeof process.report?.getReport === 'function') {
36
+ if (process.report && typeof process.report.getReport === 'function') {
37
37
  process.report.excludeNetwork = true
38
38
  report = process.report.getReport()
39
39
  }
@@ -105,7 +105,7 @@ function requireNative() {
105
105
  }
106
106
  } else if (process.platform === 'win32') {
107
107
  if (process.arch === 'x64') {
108
- if (process.config?.variables?.shlib_suffix === 'dll.a' || process.config?.variables?.node_target_type === 'shared_library') {
108
+ if ((process.config && process.config.variables && process.config.variables.shlib_suffix === 'dll.a') || (process.config && process.config.variables && process.config.variables.node_target_type === 'shared_library')) {
109
109
  try {
110
110
  return require('./x-win.win32-x64-gnu.node')
111
111
  } catch (e) {
@@ -523,54 +523,178 @@ function requireNative() {
523
523
  }
524
524
  }
525
525
 
526
- nativeBinding = requireNative()
526
+ function createLoadErrorChain(errors) {
527
+ return errors.reduce((previous, current) => {
528
+ let message
529
+ try {
530
+ message =
531
+ current && typeof current.message === 'string'
532
+ ? current.message
533
+ : String(current)
534
+ } catch {
535
+ message = 'Unknown error'
536
+ }
537
+ const error = new Error(message)
538
+ error.cause = previous
539
+ return error
540
+ }, null)
541
+ }
542
+
543
+ // NAPI_RS_FORCE_WASI is a tri-state flag:
544
+ // unset / any other value → native binding preferred, WASI is only a fallback
545
+ // 'true' → prefer WASI, but retain native as a lazy fallback
546
+ // 'error' → require WASI without initializing a native fallback
547
+ // Treating any non-empty string as truthy (the historical behavior) meant
548
+ // NAPI_RS_FORCE_WASI=false, NAPI_RS_FORCE_WASI=0, etc. inadvertently triggered
549
+ // the WASI path, causing ENOENT for packages shipped without a .wasi.cjs file.
550
+ //
551
+ // NAPI_RS_WASI_FLAVOR selects one exact generated flavor and implies strict
552
+ // WASI loading. It never crosses into another flavor or falls back to native.
553
+ const __napiWasiFlavors = ["wasm32-wasi"]
554
+ const __napiWasiFlavor = process.env.NAPI_RS_WASI_FLAVOR
555
+ const __napiWasiFlavorRequested =
556
+ typeof __napiWasiFlavor === 'string' && __napiWasiFlavor.length > 0
557
+ if (
558
+ __napiWasiFlavorRequested &&
559
+ __napiWasiFlavors.indexOf(__napiWasiFlavor) === -1
560
+ ) {
561
+ throw new Error(
562
+ 'Unsupported WASI flavor "' +
563
+ __napiWasiFlavor +
564
+ '". Available flavors: ' +
565
+ __napiWasiFlavors.join(', '),
566
+ )
567
+ }
568
+ const forceWasiError = process.env.NAPI_RS_FORCE_WASI === 'error'
569
+ const forceWasi =
570
+ process.env.NAPI_RS_FORCE_WASI === 'true' ||
571
+ forceWasiError ||
572
+ __napiWasiFlavorRequested
573
+
574
+ if (!forceWasi) {
575
+ nativeBinding = requireNative()
576
+ }
527
577
 
528
- if (!nativeBinding || process.env.NAPI_RS_FORCE_WASI) {
578
+ if (!nativeBinding || forceWasi) {
529
579
  let wasiBinding = null
530
- let wasiBindingError = null
531
- try {
532
- wasiBinding = require('./x-win.wasi.cjs')
533
- nativeBinding = wasiBinding
534
- } catch (err) {
535
- if (process.env.NAPI_RS_FORCE_WASI) {
536
- wasiBindingError = err
580
+ let wasiBindingLoaded = false
581
+ const wasiBindingErrors = []
582
+ const __napiWasiResolveCandidate = (specifier, isPackage, localArtifacts) => {
583
+ try {
584
+ require.resolve(specifier)
585
+ } catch (resolveError) {
586
+ if (!resolveError || resolveError.code !== 'MODULE_NOT_FOUND') {
587
+ throw resolveError
588
+ }
589
+ if (isPackage) {
590
+ try {
591
+ require.resolve(specifier + '/package.json')
592
+ } catch (packageError) {
593
+ if (packageError && packageError.code === 'MODULE_NOT_FOUND') {
594
+ return resolveError
595
+ }
596
+ // An exports restriction proves the package exists even when its
597
+ // package.json is not public. Preserve the root resolution failure.
598
+ throw resolveError
599
+ }
600
+ // The package exists but its main/export target is broken.
601
+ throw resolveError
602
+ }
603
+ return resolveError
537
604
  }
605
+ if (localArtifacts) {
606
+ let artifactError = null
607
+ for (let i = 0; i < localArtifacts.length; i++) {
608
+ try {
609
+ require.resolve(localArtifacts[i])
610
+ return null
611
+ } catch (resolveError) {
612
+ if (!resolveError || resolveError.code !== 'MODULE_NOT_FOUND') {
613
+ throw resolveError
614
+ }
615
+ artifactError = resolveError
616
+ }
617
+ }
618
+ return artifactError
619
+ }
620
+ return null
538
621
  }
539
- if (!nativeBinding || process.env.NAPI_RS_FORCE_WASI) {
622
+ if (!wasiBindingLoaded && (!__napiWasiFlavorRequested || __napiWasiFlavor === "wasm32-wasi")) {
623
+ let candidateError = null
624
+ let candidateFailed = false
540
625
  try {
541
- wasiBinding = require('@miniben90/x-win-wasm32-wasi')
542
- nativeBinding = wasiBinding
626
+ candidateError = __napiWasiResolveCandidate('./x-win.wasi.cjs', false, ["./x-win.wasm32-wasi.debug.wasm","./x-win.wasm32-wasi.wasm"])
627
+ candidateFailed = candidateError !== null
628
+ if (!candidateFailed) {
629
+ wasiBinding = require('./x-win.wasi.cjs')
630
+ nativeBinding = wasiBinding
631
+ wasiBindingLoaded = true
632
+ }
543
633
  } catch (err) {
544
- if (process.env.NAPI_RS_FORCE_WASI) {
545
- if (!wasiBindingError) {
546
- wasiBindingError = err
547
- } else {
548
- wasiBindingError.cause = err
634
+ candidateError = err
635
+ candidateFailed = true
636
+ }
637
+ if (candidateFailed) {
638
+ wasiBindingErrors.push(candidateError)
639
+ loadErrors.push(candidateError)
640
+ }
641
+ }
642
+ if (!wasiBindingLoaded && (!__napiWasiFlavorRequested || __napiWasiFlavor === "wasm32-wasi")) {
643
+ let candidateError = null
644
+ let candidateFailed = false
645
+ try {
646
+ candidateError = __napiWasiResolveCandidate('@miniben90/x-win-wasm32-wasi', true, undefined)
647
+ candidateFailed = candidateError !== null
648
+ if (!candidateFailed) {
649
+ if (process.env.NAPI_RS_ENFORCE_VERSION_CHECK && process.env.NAPI_RS_ENFORCE_VERSION_CHECK !== '0') {
650
+ const bindingPackageVersion = require('@miniben90/x-win-wasm32-wasi/package.json').version
651
+ if (bindingPackageVersion !== '1.6.0') {
652
+ throw new Error(`WASI binding package version mismatch, expected 1.6.0 but got ${bindingPackageVersion}. You can reinstall dependencies to fix this issue.`)
653
+ }
549
654
  }
550
- loadErrors.push(err)
655
+ wasiBinding = require('@miniben90/x-win-wasm32-wasi')
656
+ nativeBinding = wasiBinding
657
+ wasiBindingLoaded = true
551
658
  }
659
+ } catch (err) {
660
+ candidateError = err
661
+ candidateFailed = true
662
+ }
663
+ if (candidateFailed) {
664
+ wasiBindingErrors.push(candidateError)
665
+ loadErrors.push(candidateError)
552
666
  }
553
667
  }
554
- if (process.env.NAPI_RS_FORCE_WASI === 'error' && !wasiBinding) {
555
- const error = new Error('WASI binding not found and NAPI_RS_FORCE_WASI is set to error')
556
- error.cause = wasiBindingError
668
+ if (
669
+ !wasiBindingLoaded &&
670
+ forceWasi &&
671
+ !forceWasiError &&
672
+ !__napiWasiFlavorRequested
673
+ ) {
674
+ nativeBinding = requireNative()
675
+ }
676
+ if ((forceWasiError || __napiWasiFlavorRequested) && !wasiBindingLoaded) {
677
+ const error = new Error(
678
+ __napiWasiFlavorRequested
679
+ ? 'WASI binding for flavor "' + __napiWasiFlavor + '" not found'
680
+ : 'WASI binding not found and NAPI_RS_FORCE_WASI is set to error',
681
+ )
682
+ error.cause = createLoadErrorChain(wasiBindingErrors)
557
683
  throw error
558
684
  }
559
685
  }
560
686
 
561
687
  if (!nativeBinding) {
562
688
  if (loadErrors.length > 0) {
563
- throw new Error(
689
+ const error = new Error(
564
690
  `Cannot find native binding. ` +
565
691
  `npm has a bug related to optional dependencies (https://github.com/npm/cli/issues/4828). ` +
566
692
  'Please try `npm i` again after removing both package-lock.json and node_modules directory.',
567
- {
568
- cause: loadErrors.reduce((err, cur) => {
569
- cur.cause = err
570
- return cur
571
- }),
572
- },
573
693
  )
694
+ // assign instead of the `new Error(message, { cause })` options form,
695
+ // which Node < 16.9 silently ignores
696
+ error.cause = createLoadErrorChain(loadErrors)
697
+ throw error
574
698
  }
575
699
  throw new Error(`Failed to load native binding`)
576
700
  }
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@miniben90/x-win",
3
3
  "description": "This package allows you to retrieve precise information about active and open windows on Windows, MacOS, and Linux. You can obtain the position, size, title, and other memory of windows.",
4
- "version": "3.5.0",
4
+ "version": "3.6.0",
5
5
  "main": "index.js",
6
6
  "types": "index.d.ts",
7
7
  "files": [
@@ -23,6 +23,10 @@
23
23
  "universal-apple-darwin"
24
24
  ]
25
25
  },
26
+ "publishConfig": {
27
+ "registry": "https://registry.npmjs.org/",
28
+ "access": "public"
29
+ },
26
30
  "author": {
27
31
  "name": "BENKHADRA Hocine",
28
32
  "email": "contact@benkhadra.com",
@@ -46,22 +50,22 @@
46
50
  "open"
47
51
  ],
48
52
  "devDependencies": {
49
- "@emnapi/core": "^1.9.1",
50
- "@emnapi/runtime": "^1.9.1",
51
- "@napi-rs/cli": "^3.6.0",
53
+ "@emnapi/core": "^1.11.1",
54
+ "@emnapi/runtime": "^1.11.1",
55
+ "@napi-rs/cli": "^3.7.2",
52
56
  "@oxc-node/core": "^0.1.0",
53
57
  "@taplo/cli": "^0.7.0",
54
- "@tybys/wasm-util": "^0.10.1",
55
- "@types/node": "^25.5.0",
56
- "ava": "^7.0.0",
58
+ "@tybys/wasm-util": "^0.10.3",
59
+ "@types/node": "^26.1.2",
60
+ "ava": "^8.0.1",
57
61
  "chalk": "^5.6.2",
58
62
  "husky": "^9.1.7",
59
- "lint-staged": "^16.4.0",
60
- "npm-run-all2": "^8.0.4",
61
- "oxlint": "^1.58.0",
62
- "prettier": "^3.8.1",
63
- "tinybench": "^6.0.0",
64
- "typescript": "^6.0.2"
63
+ "lint-staged": "^17.0.8",
64
+ "npm-run-all2": "^9.0.2",
65
+ "oxlint": "^1.71.0",
66
+ "prettier": "^3.8.4",
67
+ "tinybench": "^6.0.2",
68
+ "typescript": "^7.0.2"
65
69
  },
66
70
  "lint-staged": {
67
71
  "*.@(js|ts|tsx)": [
@@ -75,9 +79,9 @@
75
79
  ]
76
80
  },
77
81
  "ava": {
78
- "extensions": {
79
- "ts": "module"
80
- },
82
+ "extensions": [
83
+ "ts"
84
+ ],
81
85
  "workerThreads": false,
82
86
  "timeout": "3m",
83
87
  "failFast": true,
@@ -109,8 +113,9 @@
109
113
  "format:toml": "taplo format",
110
114
  "format:rs": "cargo fmt",
111
115
  "lint": "oxlint .",
112
- "prepublishOnly": "napi prepublish -t npm",
116
+ "prepublishOnly": "napi prepublish -t npm --no-gh-release",
113
117
  "test": "ava",
118
+ "preversion": "napi build --platform && git add .",
114
119
  "version": "napi version",
115
120
  "prepare": "husky",
116
121
  "clippy:rs": "cd ./x-win-rs && cargo clippy --all-features -- -D warnings",
@@ -122,15 +127,15 @@
122
127
  "checkall": "yarn format && yarn lint && yarn clippy && yarn fmt",
123
128
  "universalize": "napi universalize"
124
129
  },
125
- "packageManager": "yarn@4.13.0",
130
+ "packageManager": "yarn@4.17.1",
126
131
  "optionalDependencies": {
127
- "@miniben90/x-win-darwin-x64": "3.5.0",
128
- "@miniben90/x-win-darwin-arm64": "3.5.0",
129
- "@miniben90/x-win-linux-x64-gnu": "3.5.0",
130
- "@miniben90/x-win-linux-x64-musl": "3.5.0",
131
- "@miniben90/x-win-win32-ia32-msvc": "3.5.0",
132
- "@miniben90/x-win-win32-x64-msvc": "3.5.0",
133
- "@miniben90/x-win-win32-arm64-msvc": "3.5.0",
134
- "@miniben90/x-win-darwin-universal": "3.5.0"
132
+ "@miniben90/x-win-darwin-x64": "3.6.0",
133
+ "@miniben90/x-win-darwin-arm64": "3.6.0",
134
+ "@miniben90/x-win-linux-x64-gnu": "3.6.0",
135
+ "@miniben90/x-win-linux-x64-musl": "3.6.0",
136
+ "@miniben90/x-win-win32-ia32-msvc": "3.6.0",
137
+ "@miniben90/x-win-win32-x64-msvc": "3.6.0",
138
+ "@miniben90/x-win-win32-arm64-msvc": "3.6.0",
139
+ "@miniben90/x-win-darwin-universal": "3.6.0"
135
140
  }
136
141
  }