Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Patch navigator usage in packages#646

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to ourterms of service andprivacy statement. We’ll occasionally send you account related emails.

Already on GitHub?Sign in to your account

Open
EhabY wants to merge3 commits intocoder:main
base:main
Choose a base branch
Loading
fromEhabY:patch-navigator-usage
Open
Show file tree
Hide file tree
Changes fromall commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletionspackage.json
View file
Open in desktop
Original file line numberDiff line numberDiff line change
Expand Up@@ -20,6 +20,7 @@
"scripts": {
"build": "webpack",
"fmt": "prettier --write .",
"postinstall": "patch-package",
"lint": "eslint . --ext ts,md,json",
"lint:fix": "yarn lint --fix",
"package": "webpack --mode production --devtool hidden-source-map",
Expand DownExpand Up@@ -387,6 +388,7 @@
"markdown-eslint-parser": "^1.2.1",
"memfs": "^4.49.0",
"nyc": "^17.1.0",
"patch-package": "^8.0.1",
"prettier": "^3.5.3",
"ts-loader": "^9.5.1",
"typescript": "^5.9.3",
Expand Down
203 changes: 203 additions & 0 deletionspatches/README.md
View file
Open in desktop
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,203 @@
# Package Patches

This directory contains patches for packages that use the `navigator` global, which triggers deprecation warnings in VS Code extensions.

All patches are automatically applied during `yarn install` via the `postinstall` script in package.json.

## How to Update Patches

When updating a patched package to a new version:

1. Update the package: `yarn upgrade package-name@x.x.x`
2. Delete the old patch file: `rm patches/package-name+old.version.patch`
3. Manually reapply the changes (documented below) to the new version's files
4. Generate new patch: `npx patch-package package-name`
5. Test: `yarn build && yarn test:ci`

---

## axios

**Why:** Removes `navigator` checks to avoid VS Code deprecation warnings. Axios uses `navigator` to detect browser environments, but this is unnecessary in Node.js-based VS Code extensions.

**What to look for:**
Search for the pattern where `_navigator` is defined. This appears in multiple distribution files.

**Pattern to find:**

<!-- prettier-ignore -->
```javascript
const _navigator = typeof navigator === 'object' && navigator || undefined;
```

**Replace with:**

```javascript
const _navigator = undefined; // PATCHED: Removed navigator check
```

**Files typically modified:**

- `node_modules/axios/dist/node/axios.cjs`
- `node_modules/axios/dist/esm/axios.js`
- `node_modules/axios/lib/platform/common/utils.js`

**Tip:** Search for `const _navigator =` in the axios directory.

---

## zod

**Why:** Removes `navigator` check used for Cloudflare Workers detection. VS Code extensions run in Node.js, not Cloudflare Workers.

**What to look for:**
Search for the `allowsEval` function that checks for Cloudflare in the user agent.

**Pattern to find:**

<!-- prettier-ignore -->
```javascript
if (typeof navigator !== "undefined" && navigator?.userAgent?.includes("Cloudflare")) {
return false;
}
```

**Replace with:**

```javascript
// PATCHED: Removed navigator check to avoid VS Code deprecation warning
// We're not running in Cloudflare Workers in a VS Code extension
```

**Files typically modified:**

- `node_modules/zod/v4/core/util.js`
- `node_modules/zod/v4/core/util.cjs`

**Tip:** Search for `allowsEval` or `Cloudflare` in the zod directory. Patch both .js and .cjs variants.

---

## openpgp

**Why:** Removes `navigator.hardwareConcurrency` check. Since VS Code extensions run in Node.js, we can use `os.cpus()` directly.

**What to look for:**
Search for the `getHardwareConcurrency` function that checks for `navigator.hardwareConcurrency`.

**Pattern to find:**

```javascript
getHardwareConcurrency: function() {
if (typeof navigator !== 'undefined') {
return navigator.hardwareConcurrency || 1;
}
const os = this.nodeRequire('os');
return os.cpus().length;
}
```

**Replace with:**

```javascript
getHardwareConcurrency: function() {
// PATCHED: Removed navigator check to avoid VS Code deprecation warning
const os = this.nodeRequire('os');
return os.cpus().length;
}
```

**Files typically modified:**

- `node_modules/openpgp/dist/openpgp.js`

**Tip:** Search for `getHardwareConcurrency` in the openpgp directory.

---

## node-forge

**Why:** Removes multiple `navigator` checks used for browser detection, hardware concurrency, and entropy collection. VS Code extensions run in Node.js, so these checks are unnecessary.

### Patch 1: Browser detection in jsbn.js

**Pattern to find:**
A conditional block that checks `typeof(navigator)` and sets `BigInteger.prototype.am` based on browser type (Internet Explorer, Netscape, etc.).

**Replace with:**

```javascript
// PATCHED: Removed navigator check to avoid VS Code deprecation warning
BigInteger.prototype.am = am3;
dbits = 28;
```

**Tip:** Search for `navigator.appName` or `BigInteger.prototype.am` in `lib/jsbn.js`.

---

### Patch 2: Entropy collection in random.js

**Pattern to find:**
A block that iterates through `navigator` properties to collect entropy bytes.

<!-- prettier-ignore -->
```javascript
if(typeof(navigator) !== 'undefined') {
var _navBytes = '';
for(var key in navigator) {
// ... entropy collection code
}
}
```

**Replace with:**

```javascript
// PATCHED: Removed navigator entropy collection to avoid VS Code deprecation warning
```

**Tip:** Search for `_navBytes` or `add some entropy from navigator` in `lib/random.js`.

---

### Patch 3: Hardware concurrency in util.js

**Pattern to find:**
In the `estimateCores` function, a check for `navigator.hardwareConcurrency`.

<!-- prettier-ignore -->
```javascript
if(typeof navigator !== 'undefined' &&
'hardwareConcurrency' in navigator &&
navigator.hardwareConcurrency > 0) {
util.cores = navigator.hardwareConcurrency;
return callback(null, util.cores);
}
```

**Replace with:**

```javascript
// PATCHED: Removed navigator check to avoid VS Code deprecation warning
```

**Tip:** Search for `estimateCores` or `hardwareConcurrency` in `lib/util.js`.

---

## Verification

After applying patches, verify the build succeeds and tests pass:

```bash
yarn build
yarn test:ci
```

## Notes

- These patches maintain functionality while removing deprecation warnings
- All patches use Node.js implementations directly, which is appropriate for VS Code extensions
- The patches do not affect the security or correctness of the packages
- When in doubt, search for `typeof navigator` in the package directory to find all occurrences
38 changes: 38 additions & 0 deletionspatches/axios+1.12.2.patch
View file
Open in desktop
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
diff --git a/node_modules/axios/dist/esm/axios.js b/node_modules/axios/dist/esm/axios.js
index 6e10897..759964e 100644
--- a/node_modules/axios/dist/esm/axios.js
+++ b/node_modules/axios/dist/esm/axios.js
@@ -1315,7 +1315,7 @@ const platform$1 = {

const hasBrowserEnv = typeof window !== 'undefined' && typeof document !== 'undefined';

-const _navigator = typeof navigator === 'object' && navigator || undefined;
+const _navigator = undefined; // PATCHED

/**
* Determine if we're running in a standard browser environment
diff --git a/node_modules/axios/dist/node/axios.cjs b/node_modules/axios/dist/node/axios.cjs
index 0e8b6ac..9df7314 100644
--- a/node_modules/axios/dist/node/axios.cjs
+++ b/node_modules/axios/dist/node/axios.cjs
@@ -1360,7 +1360,7 @@ const platform$1 = {

const hasBrowserEnv = typeof window !== 'undefined' && typeof document !== 'undefined';

-const _navigator = typeof navigator === 'object' && navigator || undefined;
+const _navigator = undefined; // PATCHED

/**
* Determine if we're running in a standard browser environment
diff --git a/node_modules/axios/lib/platform/common/utils.js b/node_modules/axios/lib/platform/common/utils.js
index 52a3186..45f1327 100644
--- a/node_modules/axios/lib/platform/common/utils.js
+++ b/node_modules/axios/lib/platform/common/utils.js
@@ -1,6 +1,6 @@
const hasBrowserEnv = typeof window !== 'undefined' && typeof document !== 'undefined';

-const _navigator = typeof navigator === 'object' && navigator || undefined;
+const _navigator = undefined; // PATCHED: Removed navigator check

/**
* Determine if we're running in a standard browser environment
82 changes: 82 additions & 0 deletionspatches/node-forge+1.3.1.patch
View file
Open in desktop
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,82 @@
diff --git a/node_modules/node-forge/lib/jsbn.js b/node_modules/node-forge/lib/jsbn.js
index 11f965c..9e5dfdc 100644
--- a/node_modules/node-forge/lib/jsbn.js
+++ b/node_modules/node-forge/lib/jsbn.js
@@ -116,21 +116,10 @@ function am3(i,x,w,j,c,n) {
return c;
}

-// node.js (no browser)
-if(typeof(navigator) === 'undefined')
-{
- BigInteger.prototype.am = am3;
- dbits = 28;
-} else if(j_lm && (navigator.appName == "Microsoft Internet Explorer")) {
- BigInteger.prototype.am = am2;
- dbits = 30;
-} else if(j_lm && (navigator.appName != "Netscape")) {
- BigInteger.prototype.am = am1;
- dbits = 26;
-} else { // Mozilla/Netscape seems to prefer am3
- BigInteger.prototype.am = am3;
- dbits = 28;
-}
+// PATCHED: Removed navigator check to avoid VS Code deprecation warning
+// VS Code extensions run in Node.js, so use Node.js implementation directly
+BigInteger.prototype.am = am3;
+dbits = 28;

BigInteger.prototype.DB = dbits;
BigInteger.prototype.DM = ((1<<dbits)-1);
diff --git a/node_modules/node-forge/lib/random.js b/node_modules/node-forge/lib/random.js
index d4e4bea..b0b6bb2 100644
--- a/node_modules/node-forge/lib/random.js
+++ b/node_modules/node-forge/lib/random.js
@@ -134,26 +134,8 @@ if(forge.options.usePureJavaScript ||
// get load time entropy
_ctx.collectInt(+new Date(), 32);

- // add some entropy from navigator object
- if(typeof(navigator) !== 'undefined') {
- var _navBytes = '';
- for(var key in navigator) {
- try {
- if(typeof(navigator[key]) == 'string') {
- _navBytes += navigator[key];
- }
- } catch(e) {
- /* Some navigator keys might not be accessible, e.g. the geolocation
- attribute throws an exception if touched in Mozilla chrome://
- context.
-
- Silently ignore this and just don't use this as a source of
- entropy. */
- }
- }
- _ctx.collect(_navBytes);
- _navBytes = null;
- }
+ // PATCHED: Removed navigator entropy collection to avoid VS Code deprecation warning
+ // VS Code extensions run in Node.js, not in a browser, so navigator is not available

// add mouse and keyboard collectors if jquery is available
if(jQuery) {
diff --git a/node_modules/node-forge/lib/util.js b/node_modules/node-forge/lib/util.js
index aaede5a..a11ad50 100644
--- a/node_modules/node-forge/lib/util.js
+++ b/node_modules/node-forge/lib/util.js
@@ -2555,12 +2555,8 @@ util.estimateCores = function(options, callback) {
if('cores' in util && !options.update) {
return callback(null, util.cores);
}
- if(typeof navigator !== 'undefined' &&
- 'hardwareConcurrency' in navigator &&
- navigator.hardwareConcurrency > 0) {
- util.cores = navigator.hardwareConcurrency;
- return callback(null, util.cores);
- }
+ // PATCHED: Removed navigator check to avoid VS Code deprecation warning
+ // VS Code extensions run in Node.js, not in a browser
if(typeof Worker === 'undefined') {
// workers not available
util.cores = 1;
19 changes: 19 additions & 0 deletionspatches/openpgp+6.2.2.patch
View file
Open in desktop
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
diff --git a/node_modules/openpgp/dist/openpgp.js b/node_modules/openpgp/dist/openpgp.js
index b990fa2..1106a18 100644
--- a/node_modules/openpgp/dist/openpgp.js
+++ b/node_modules/openpgp/dist/openpgp.js
@@ -2206,11 +2206,9 @@ var openpgp = (function (exports) {
},

getHardwareConcurrency: function() {
- if (typeof navigator !== 'undefined') {
- return navigator.hardwareConcurrency || 1;
- }
-
- const os = this.nodeRequire('os'); // Assume we're on Node.js.
+ // PATCHED: Removed navigator check to avoid VS Code deprecation warning
+ // VS Code extensions run in Node.js, so use os.cpus() directly
+ const os = this.nodeRequire('os');
return os.cpus().length;
},

34 changes: 34 additions & 0 deletionspatches/zod+4.1.12.patch
View file
Open in desktop
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
diff --git a/node_modules/zod/v4/core/util.cjs b/node_modules/zod/v4/core/util.cjs
index 9e412dc..c0e64af 100644
--- a/node_modules/zod/v4/core/util.cjs
+++ b/node_modules/zod/v4/core/util.cjs
@@ -195,10 +195,8 @@ function isObject(data) {
return typeof data === "object" && data !== null && !Array.isArray(data);
}
exports.allowsEval = cached(() => {
- // @ts-ignore
- if (typeof navigator !== "undefined" && navigator?.userAgent?.includes("Cloudflare")) {
- return false;
- }
+ // PATCHED: Removed navigator check to avoid VS Code deprecation warning
+ // We're not running in Cloudflare Workers in a VS Code extension
try {
const F = Function;
new F("");
diff --git a/node_modules/zod/v4/core/util.js b/node_modules/zod/v4/core/util.js
index 3cf33fd..c4519fc 100644
--- a/node_modules/zod/v4/core/util.js
+++ b/node_modules/zod/v4/core/util.js
@@ -140,10 +140,8 @@ export function isObject(data) {
return typeof data === "object" && data !== null && !Array.isArray(data);
}
export const allowsEval = cached(() => {
- // @ts-ignore
- if (typeof navigator !== "undefined" && navigator?.userAgent?.includes("Cloudflare")) {
- return false;
- }
+ // PATCHED: Removed navigator check to avoid VS Code deprecation warning
+ // We're not running in Cloudflare Workers in a VS Code extension
try {
const F = Function;
new F("");
Loading

[8]ページ先頭

©2009-2025 Movatter.jp