Skip to content

Commit

Permalink
fix: replace node-fetch-with-proxy because of webpack issues
Browse files Browse the repository at this point in the history
node-fetch-with-proxy uses vm2 package which has webpack issues, so using simple-proxy-agent instead

SAP#285
  • Loading branch information
uxkjaer committed Jan 11, 2022
1 parent 9cd735a commit 66bf54d
Show file tree
Hide file tree
Showing 7 changed files with 84 additions and 46 deletions.
6 changes: 2 additions & 4 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,8 @@
"source-map-support": "0.5.19",
"typescript": "3.9.7",
"webpack": "5.36.2",
"webpack-cli": "4.4.0"
"webpack-cli": "4.4.0",
"proxy-agent": "latest"
},
"husky": {
"hooks": {
Expand All @@ -96,8 +97,5 @@
"extends": [
"@commitlint/config-conventional"
]
},
"dependencies": {
"node-fetch-with-proxy": "^0.1.6"
}
}
2 changes: 1 addition & 1 deletion packages/language-server/api.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -30,4 +30,4 @@ export type FetchResponse = {
json: () => Promise<unknown>;
};

export type Fetcher = (url: string) => Promise<FetchResponse>;
export type Fetcher = (url: string, options: object) => Promise<FetchResponse>;
2 changes: 2 additions & 0 deletions packages/language-server/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -39,8 +39,10 @@
"@xml-tools/parser": "1.0.7",
"assert-never": "1.2.1",
"fs-extra": "9.0.1",
"get-proxy": "^2.1.0",
"lodash": "4.17.21",
"node-fetch": "2.6.1",
"simple-proxy-agent": "^1.1.0",
"vscode-languageserver": "6.1.1",
"vscode-languageserver-textdocument": "1.0.1",
"vscode-uri": "2.1.2"
Expand Down
25 changes: 25 additions & 0 deletions packages/language-server/package_dist.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
{
"dependencies": {
"vm2": "latest",
"@sap/swa-for-sapbas-vsx": "1.1.9",
"@ui5-language-assistant/semantic-model": "^3.0.1",
"@ui5-language-assistant/settings": "^3.0.1",
"@ui5-language-assistant/user-facing-text": "^3.0.1",
"@ui5-language-assistant/xml-views-completion": "^3.0.1",
"@ui5-language-assistant/xml-views-quick-fix": "^3.0.1",
"@ui5-language-assistant/xml-views-tooltip": "^3.0.1",
"@ui5-language-assistant/xml-views-validation": "^3.0.1",
"@vscode-logging/logger": "1.2.2",
"@vscode-logging/types": "0.1.3",
"@xml-tools/ast": "5.0.0",
"@xml-tools/ast-position": "2.0.2",
"@xml-tools/parser": "1.0.7",
"assert-never": "1.2.1",
"fs-extra": "9.0.1",
"lodash": "4.17.21",
"node-fetch": "2.6.1",
"vscode-languageserver": "6.1.1",
"vscode-languageserver-textdocument": "1.0.1",
"vscode-uri": "2.1.2"
}
}
17 changes: 14 additions & 3 deletions packages/language-server/src/ui5-model.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
import { map } from "lodash";
import fetch from "node-fetch-with-proxy";
import fetch from "node-fetch";
import { resolve } from "path";
import { pathExists, lstat, readJson, writeJson, mkdirs } from "fs-extra";

import getProxy from "get-proxy";
import ProxyAgent from "simple-proxy-agent";
import { UI5SemanticModel } from "@ui5-language-assistant/semantic-model-types";
import {
generate,
Expand Down Expand Up @@ -58,7 +59,17 @@ export async function getSemanticModelWithFetcher(
if (apiJson === undefined) {
getLogger().info("No cache found for UI5 lib", { libName });
const url = baseUrl + libName.replace(/\./g, "/") + suffix;
const response = await fetcher(url);
const proxy = getProxy();
let fetchOptions = {};
if (proxy) {
fetchOptions["agent"] = new ProxyAgent(proxy, {
// Options, with all defaults
tunnel: true, // If true, will tunnel all HTTPS using CONNECT method
timeout: 5000, // Time in milli-seconds, to maximum wait for proxy connection to establish
});
}

const response = await fetcher(url, fetchOptions);
if (response.ok) {
apiJson = await response.json();
await writeToCache(cacheFilePath, apiJson);
Expand Down
17 changes: 15 additions & 2 deletions test-packages/test-utils/src/utils/download-ui5-resources.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
import { zipObject, keys, map, noop } from "lodash";
import { resolve } from "path";
import { writeFile, mkdirs, pathExists } from "fs-extra";
import fetch from "node-fetch-with-proxy";
import fetch from "node-fetch";
import getProxy from "get-proxy";
import ProxyAgent from "simple-proxy-agent";
import { TestModelVersion } from "../../api";

// Disable this flag if you want/need spam/info in the tests logs.
Expand Down Expand Up @@ -66,7 +68,18 @@ async function writeUrlToFile(url: string, file: string): Promise<void> {
}

log(`fetching from ${url}`);
const response = await fetch(url);
const proxy = getProxy();

let fetchOptions = {};
if (proxy) {
fetchOptions["agent"] = new ProxyAgent(proxy, {
// Options, with all defaults
tunnel: true, // If true, will tunnel all HTTPS using CONNECT method
timeout: 5000, // Time in milli-seconds, to maximum wait for proxy connection to establish
});
}

const response = await fetch(url, fetchOptions);
if (!response.ok) {
error(`error fetching from ${url}`);
return;
Expand Down
61 changes: 25 additions & 36 deletions yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -4445,6 +4445,13 @@ get-port@^4.2.0:
resolved "https://registry.yarnpkg.com/get-port/-/get-port-4.2.0.tgz#e37368b1e863b7629c43c5a323625f95cf24b119"
integrity sha512-/b3jarXkH8KJoOMQc3uVGHASwGLPq3gSFJ7tgJm2diza+bydJPTGOibin2steecKeOylE8oY2JERlVWkAJO6yw==

get-proxy@^2.1.0:
version "2.1.0"
resolved "https://registry.yarnpkg.com/get-proxy/-/get-proxy-2.1.0.tgz#349f2b4d91d44c4d4d4e9cba2ad90143fac5ef93"
integrity sha512-zmZIaQTWnNQb4R4fJUEp/FC51eZsc6EkErspy3xtIYStaq8EB/hDIWipxsal+E8rz0qD7f2sL/NA9Xee4RInJw==
dependencies:
npm-conf "^1.1.0"

get-stdin@8.0.0:
version "8.0.0"
resolved "https://registry.yarnpkg.com/get-stdin/-/get-stdin-8.0.0.tgz#cbad6a73feb75f6eeb22ba9e01f89aa28aa97a53"
Expand Down Expand Up @@ -6503,14 +6510,6 @@ node-fetch-npm@^2.0.2:
json-parse-better-errors "^1.0.0"
safe-buffer "^5.1.1"

node-fetch-with-proxy@^0.1.6:
version "0.1.6"
resolved "https://registry.yarnpkg.com/node-fetch-with-proxy/-/node-fetch-with-proxy-0.1.6.tgz#20325185c80917e6d1e23c332838b76d05f6ad20"
integrity sha512-gw/TN6EZpL9Fp7YwGRJa6pz3akgFTHF2tTFNKXX3qG8bJGBzF+Hd6pTsFW4p0zBiRF6OBALR02G1FoTpQEyU+g==
dependencies:
node-fetch "^2.6.2"
proxy-agent "^5.0.0"

node-fetch@*:
version "3.1.0"
resolved "https://registry.yarnpkg.com/node-fetch/-/node-fetch-3.1.0.tgz#714f4922dc270239487654eaeeab86b8206cb52e"
Expand All @@ -6525,13 +6524,6 @@ node-fetch@2.6.1, node-fetch@^2.3.0, node-fetch@^2.5.0:
resolved "https://registry.yarnpkg.com/node-fetch/-/node-fetch-2.6.1.tgz#045bd323631f76ed2e2b55573394416b639a0052"
integrity sha512-V4aYg89jEoVRxRb2fJdAg8FHvI7cEyYdVAh94HH0UIK8oJxUfkjlDQN9RbMx+bEjP7+ggMiFRprSti032Oipxw==

node-fetch@^2.6.2:
version "2.6.6"
resolved "https://registry.yarnpkg.com/node-fetch/-/node-fetch-2.6.6.tgz#1751a7c01834e8e1697758732e9efb6eeadfaf89"
integrity sha512-Z8/6vRlTUChSdIgMa51jxQ4lrw/Jy5SOW10ObaA47/RElsAN2c5Pn8bTgFGWn/ibwzXTE8qwr1Yzx28vsecXEA==
dependencies:
whatwg-url "^5.0.0"

node-gyp@^5.0.2:
version "5.1.1"
resolved "https://registry.yarnpkg.com/node-gyp/-/node-gyp-5.1.1.tgz#eb915f7b631c937d282e33aed44cb7a025f62a3e"
Expand Down Expand Up @@ -6606,6 +6598,14 @@ npm-bundled@^1.0.1:
dependencies:
npm-normalize-package-bin "^1.0.1"

npm-conf@^1.1.0:
version "1.1.3"
resolved "https://registry.yarnpkg.com/npm-conf/-/npm-conf-1.1.3.tgz#256cc47bd0e218c259c4e9550bf413bc2192aff9"
integrity sha512-Yic4bZHJOt9RCFbRP3GgpqhScOY4HH3V2P8yBj6CeYq118Qr+BLXqT2JvpJ00mryLESpgOxf5XlFv4ZjXxLScw==
dependencies:
config-chain "^1.1.11"
pify "^3.0.0"

npm-lifecycle@^3.1.2:
version "3.1.5"
resolved "https://registry.yarnpkg.com/npm-lifecycle/-/npm-lifecycle-3.1.5.tgz#9882d3642b8c82c815782a12e6a1bfeed0026309"
Expand Down Expand Up @@ -7358,7 +7358,7 @@ protoduck@^5.0.1:
dependencies:
genfun "^5.0.0"

proxy-agent@^5.0.0:
proxy-agent@latest:
version "5.0.0"
resolved "https://registry.yarnpkg.com/proxy-agent/-/proxy-agent-5.0.0.tgz#d31405c10d6e8431fde96cba7a0c027ce01d633b"
integrity sha512-gkH7BkvLVkSfX9Dk27W6TyNOWWZWRilRfk1XxGNWOYJ2TuedAv1yFpCaU9QSBmBe716XOTNpYNOzhysyw8xn7g==
Expand Down Expand Up @@ -8021,6 +8021,13 @@ simple-git@2.38.0:
"@kwsites/promise-deferred" "^1.1.1"
debug "^4.3.1"

simple-proxy-agent@^1.1.0:
version "1.1.0"
resolved "https://registry.yarnpkg.com/simple-proxy-agent/-/simple-proxy-agent-1.1.0.tgz#974cd1130dd32554775e2d4caeb70d701f7ca8b3"
integrity sha512-amJaLagzNELaNNB2UXdXiORVbbU/RC4yRwtGvF4cttJheTm4JvL2fZ1SfuLU952XC7TLamYdgzzJtWUbGM6Jcw==
dependencies:
socks "^2.3.2"

simple-swizzle@^0.2.2:
version "0.2.2"
resolved "https://registry.yarnpkg.com/simple-swizzle/-/simple-swizzle-0.2.2.tgz#a4da6b635ffcccca33f70d17cb92592de95e557a"
Expand Down Expand Up @@ -8130,7 +8137,7 @@ socks-proxy-agent@^4.0.0:
agent-base "~4.2.1"
socks "~2.3.2"

socks@^2.3.3:
socks@^2.3.2, socks@^2.3.3:
version "2.6.1"
resolved "https://registry.yarnpkg.com/socks/-/socks-2.6.1.tgz#989e6534a07cf337deb1b1c94aaa44296520d30e"
integrity sha512-kLQ9N5ucj8uIcxrDwjm0Jsqk06xdpBjGNQtpXy4Q8/QY2k+fY7nZH8CARy+hkbG+SGAovmzzuauCpBlb8FrnBA==
Expand Down Expand Up @@ -8831,11 +8838,6 @@ tr46@^1.0.1:
dependencies:
punycode "^2.1.0"

tr46@~0.0.3:
version "0.0.3"
resolved "https://registry.yarnpkg.com/tr46/-/tr46-0.0.3.tgz#8184fd347dac9cdc185992f3a6622e14b9d9ab6a"
integrity sha1-gYT9NH2snNwYWZLzpmIuFLnZq2o=

trim-newlines@^1.0.0:
version "1.0.0"
resolved "https://registry.yarnpkg.com/trim-newlines/-/trim-newlines-1.0.0.tgz#5887966bb582a4503a41eb524f7d35011815a613"
Expand Down Expand Up @@ -9143,7 +9145,7 @@ verror@1.10.0:
core-util-is "1.0.2"
extsprintf "^1.2.0"

vm2@^3.9.3:
vm2@^3.9.3, vm2@latest:
version "3.9.5"
resolved "https://registry.yarnpkg.com/vm2/-/vm2-3.9.5.tgz#5288044860b4bbace443101fcd3bddb2a0aa2496"
integrity sha512-LuCAHZN75H9tdrAiLFf030oW7nJV5xwNMuk1ymOZwopmuK3d2H4L1Kv4+GFHgarKiLfXXLFU+7LDABHnwOkWng==
Expand Down Expand Up @@ -9251,11 +9253,6 @@ web-streams-polyfill@^3.0.3:
resolved "https://registry.yarnpkg.com/web-streams-polyfill/-/web-streams-polyfill-3.2.0.tgz#a6b74026b38e4885869fb5c589e90b95ccfc7965"
integrity sha512-EqPmREeOzttaLRm5HS7io98goBgZ7IVz79aDvqjD0kYXLtFZTc0T/U6wHTPKyIjb+MdN7DFIIX6hgdBEpWmfPA==

webidl-conversions@^3.0.0:
version "3.0.1"
resolved "https://registry.yarnpkg.com/webidl-conversions/-/webidl-conversions-3.0.1.tgz#24534275e2a7bc6be7bc86611cc16ae0a5654871"
integrity sha1-JFNCdeKnvGvnvIZhHMFq4KVlSHE=

webidl-conversions@^4.0.2:
version "4.0.2"
resolved "https://registry.yarnpkg.com/webidl-conversions/-/webidl-conversions-4.0.2.tgz#a855980b1f0b6b359ba1d5d9fb39ae941faa63ad"
Expand Down Expand Up @@ -9326,14 +9323,6 @@ webpack@5.36.2:
watchpack "^2.0.0"
webpack-sources "^2.1.1"

whatwg-url@^5.0.0:
version "5.0.0"
resolved "https://registry.yarnpkg.com/whatwg-url/-/whatwg-url-5.0.0.tgz#966454e8765462e37644d3626f6742ce8b70965d"
integrity sha1-lmRU6HZUYuN2RNNib2dCzotwll0=
dependencies:
tr46 "~0.0.3"
webidl-conversions "^3.0.0"

whatwg-url@^7.0.0:
version "7.1.0"
resolved "https://registry.yarnpkg.com/whatwg-url/-/whatwg-url-7.1.0.tgz#c2c492f1eca612988efd3d2266be1b9fc6170d06"
Expand Down

0 comments on commit 66bf54d

Please sign in to comment.