|
| 1 | +# Package Patches |
| 2 | + |
| 3 | +This directory contains patches for packages that use the `navigator` global, which triggers deprecation warnings in VS Code extensions. |
| 4 | + |
| 5 | +All patches are automatically applied during `yarn install` via the `postinstall` script in package.json. |
| 6 | + |
| 7 | +## How to Update Patches |
| 8 | + |
| 9 | +When updating a patched package to a new version: |
| 10 | + |
| 11 | +1. Update the package: `yarn upgrade package-name@x.x.x` |
| 12 | +2. Delete the old patch file: `rm patches/package-name+old.version.patch` |
| 13 | +3. Manually reapply the changes (documented below) to the new version's files |
| 14 | +4. Generate new patch: `npx patch-package package-name` |
| 15 | +5. Test: `yarn build && yarn test:ci` |
| 16 | + |
| 17 | +--- |
| 18 | + |
| 19 | +## axios |
| 20 | + |
| 21 | +**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. |
| 22 | + |
| 23 | +**What to look for:** |
| 24 | +Search for the pattern where `_navigator` is defined. This appears in multiple distribution files. |
| 25 | + |
| 26 | +**Pattern to find:** |
| 27 | +```javascript |
| 28 | +const _navigator = typeof navigator === 'object' && navigator || undefined; |
| 29 | +``` |
| 30 | + |
| 31 | +**Replace with:** |
| 32 | +```javascript |
| 33 | +const _navigator = undefined; // PATCHED: Removed navigator check |
| 34 | +``` |
| 35 | + |
| 36 | +**Files typically modified:** |
| 37 | +- `node_modules/axios/dist/node/axios.cjs` |
| 38 | +- `node_modules/axios/dist/esm/axios.js` |
| 39 | +- `node_modules/axios/lib/platform/common/utils.js` |
| 40 | + |
| 41 | +**Tip:** Search for `const _navigator =` in the axios directory. |
| 42 | + |
| 43 | +--- |
| 44 | + |
| 45 | +## zod |
| 46 | + |
| 47 | +**Why:** Removes `navigator` check used for Cloudflare Workers detection. VS Code extensions run in Node.js, not Cloudflare Workers. |
| 48 | + |
| 49 | +**What to look for:** |
| 50 | +Search for the `allowsEval` function that checks for Cloudflare in the user agent. |
| 51 | + |
| 52 | +**Pattern to find:** |
| 53 | +```javascript |
| 54 | +if (typeof navigator !== "undefined" && navigator?.userAgent?.includes("Cloudflare")) { |
| 55 | + return false; |
| 56 | +} |
| 57 | +``` |
| 58 | +
|
| 59 | +**Replace with:** |
| 60 | +```javascript |
| 61 | +// PATCHED: Removed navigator check to avoid VS Code deprecation warning |
| 62 | +// We're not running in Cloudflare Workers in a VS Code extension |
| 63 | +``` |
| 64 | +
|
| 65 | +**Files typically modified:** |
| 66 | +- `node_modules/zod/v4/core/util.js` |
| 67 | +- `node_modules/zod/v4/core/util.cjs` |
| 68 | +
|
| 69 | +**Tip:** Search for `allowsEval` or `Cloudflare` in the zod directory. Patch both .js and .cjs variants. |
| 70 | +
|
| 71 | +--- |
| 72 | +
|
| 73 | +## openpgp |
| 74 | +
|
| 75 | +**Why:** Removes `navigator.hardwareConcurrency` check. Since VS Code extensions run in Node.js, we can use `os.cpus()` directly. |
| 76 | +
|
| 77 | +**What to look for:** |
| 78 | +Search for the `getHardwareConcurrency` function that checks for `navigator.hardwareConcurrency`. |
| 79 | +
|
| 80 | +**Pattern to find:** |
| 81 | +```javascript |
| 82 | +getHardwareConcurrency: function() { |
| 83 | + if (typeof navigator !== 'undefined') { |
| 84 | + return navigator.hardwareConcurrency || 1; |
| 85 | + } |
| 86 | + const os = this.nodeRequire('os'); |
| 87 | + return os.cpus().length; |
| 88 | +} |
| 89 | +``` |
| 90 | +
|
| 91 | +**Replace with:** |
| 92 | +```javascript |
| 93 | +getHardwareConcurrency: function() { |
| 94 | + // PATCHED: Removed navigator check to avoid VS Code deprecation warning |
| 95 | + const os = this.nodeRequire('os'); |
| 96 | + return os.cpus().length; |
| 97 | +} |
| 98 | +``` |
| 99 | +
|
| 100 | +**Files typically modified:** |
| 101 | +- `node_modules/openpgp/dist/openpgp.js` |
| 102 | +
|
| 103 | +**Tip:** Search for `getHardwareConcurrency` in the openpgp directory. |
| 104 | +
|
| 105 | +--- |
| 106 | +
|
| 107 | +## node-forge |
| 108 | +
|
| 109 | +**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. |
| 110 | +
|
| 111 | +### Patch 1: Browser detection in jsbn.js |
| 112 | +
|
| 113 | +**Pattern to find:** |
| 114 | +A conditional block that checks `typeof(navigator)` and sets `BigInteger.prototype.am` based on browser type (Internet Explorer, Netscape, etc.). |
| 115 | +
|
| 116 | +**Replace with:** |
| 117 | +```javascript |
| 118 | +// PATCHED: Removed navigator check to avoid VS Code deprecation warning |
| 119 | +BigInteger.prototype.am = am3; |
| 120 | +dbits = 28; |
| 121 | +``` |
| 122 | +
|
| 123 | +**Tip:** Search for `navigator.appName` or `BigInteger.prototype.am` in `lib/jsbn.js`. |
| 124 | +
|
| 125 | +--- |
| 126 | +
|
| 127 | +### Patch 2: Entropy collection in random.js |
| 128 | +
|
| 129 | +**Pattern to find:** |
| 130 | +A block that iterates through `navigator` properties to collect entropy bytes. |
| 131 | +
|
| 132 | +```javascript |
| 133 | +if(typeof(navigator) !== 'undefined') { |
| 134 | + var _navBytes = ''; |
| 135 | + for(var key in navigator) { |
| 136 | + // ... entropy collection code |
| 137 | + } |
| 138 | +} |
| 139 | +``` |
| 140 | +
|
| 141 | +**Replace with:** |
| 142 | +```javascript |
| 143 | +// PATCHED: Removed navigator entropy collection to avoid VS Code deprecation warning |
| 144 | +``` |
| 145 | +
|
| 146 | +**Tip:** Search for `_navBytes` or `add some entropy from navigator` in `lib/random.js`. |
| 147 | +
|
| 148 | +--- |
| 149 | +
|
| 150 | +### Patch 3: Hardware concurrency in util.js |
| 151 | +
|
| 152 | +**Pattern to find:** |
| 153 | +In the `estimateCores` function, a check for `navigator.hardwareConcurrency`. |
| 154 | +
|
| 155 | +```javascript |
| 156 | +if(typeof navigator !== 'undefined' && |
| 157 | + 'hardwareConcurrency' in navigator && |
| 158 | + navigator.hardwareConcurrency > 0) { |
| 159 | + util.cores = navigator.hardwareConcurrency; |
| 160 | + return callback(null, util.cores); |
| 161 | +} |
| 162 | +``` |
| 163 | +
|
| 164 | +**Replace with:** |
| 165 | +```javascript |
| 166 | +// PATCHED: Removed navigator check to avoid VS Code deprecation warning |
| 167 | +``` |
| 168 | +
|
| 169 | +**Tip:** Search for `estimateCores` or `hardwareConcurrency` in `lib/util.js`. |
| 170 | +
|
| 171 | +--- |
| 172 | +
|
| 173 | +## Verification |
| 174 | +
|
| 175 | +After applying patches, verify the build succeeds and tests pass: |
| 176 | +
|
| 177 | +```bash |
| 178 | +yarn build |
| 179 | +yarn test:ci |
| 180 | +``` |
| 181 | +
|
| 182 | +## Notes |
| 183 | +
|
| 184 | +- These patches maintain functionality while removing deprecation warnings |
| 185 | +- All patches use Node.js implementations directly, which is appropriate for VS Code extensions |
| 186 | +- The patches do not affect the security or correctness of the packages |
| 187 | +- When in doubt, search for `typeof navigator` in the package directory to find all occurrences |
0 commit comments