- Notifications
You must be signed in to change notification settings - Fork35
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:mainChoose a base branch fromEhabY:patch-navigator-usage
base:main
Could not load branches
Branch not found:{{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline, and old review comments may become outdated.
+484 −2
Open
Changes fromall commits
Commits
Show all changes
3 commits Select commitHold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Uh oh!
There was an error while loading.Please reload this page.
Jump to
Jump to file
Failed to load files.
Loading
Uh oh!
There was an error while loading.Please reload this page.
Diff view
Diff view
There are no files selected for viewing
2 changes: 2 additions & 0 deletionspackage.json
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.Learn more about bidirectional Unicode characters
203 changes: 203 additions & 0 deletionspatches/README.md
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff 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
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff 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
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff 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
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff 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
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff 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(""); |
Oops, something went wrong.
Uh oh!
There was an error while loading.Please reload this page.
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.