Skip to content

Commit fea63fe

Browse files
authored
Merge ecb29c4 into 1b80244
2 parents 1b80244 + ecb29c4 commit fea63fe

File tree

18 files changed

+206
-60
lines changed

18 files changed

+206
-60
lines changed

.eslintrc.yaml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -36,8 +36,8 @@ rules:
3636
import/order:
3737
[error, { alphabetize: { order: "asc" }, groups: [["builtin", "external", "internal"], "parent", "sibling"] }]
3838
no-async-promise-executor: off
39-
# This isn't a real module, just types, which apparently doesn't resolve.
40-
import/no-unresolved: [error, { ignore: ["express-serve-static-core"] }]
39+
# These aren't real modules, just types, which apparently don't resolve.
40+
import/no-unresolved: [error, { ignore: ["express-serve-static-core", "vscode"] }]
4141

4242
settings:
4343
# Does not work with CommonJS unfortunately.

CHANGELOG.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@ VS Code v0.00.0
3939

4040
### New Features
4141

42-
- item
42+
- Add `VSCODE_PROXY_URI` env var for use in the terminal and extensions (#1510)
4343

4444
### Bug Fixes
4545

ci/dev/postinstall.sh

Lines changed: 12 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -3,15 +3,20 @@ set -euo pipefail
33

44
main() {
55
cd "$(dirname "$0")/../.."
6+
source ./ci/lib.sh
67

7-
echo "Installing code-server test dependencies..."
8+
pushd test
9+
echo "Installing dependencies for $PWD"
10+
yarn install
11+
popd
812

9-
cd test
13+
pushd test/e2e/extensions/test-extension
14+
echo "Installing dependencies for $PWD"
1015
yarn install
11-
cd ..
16+
popd
1217

13-
cd vendor
14-
echo "Installing vendor dependencies..."
18+
pushd vendor
19+
echo "Installing dependencies for $PWD"
1520

1621
# * We install in 'modules' instead of 'node_modules' because VS Code's extensions
1722
# use a webpack config which cannot differentiate between its own node_modules
@@ -32,6 +37,8 @@ main() {
3237

3338
# Finally, run the vendor `postinstall`
3439
yarn run postinstall
40+
41+
popd
3542
}
3643

3744
main "$@"

ci/dev/test-e2e.sh

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,11 @@ main() {
66

77
source ./ci/lib.sh
88

9+
pushd test/e2e/extensions/test-extension
10+
echo "Building test extension"
11+
yarn build
12+
popd
13+
914
local dir="$PWD"
1015
if [[ ! ${CODE_SERVER_TEST_ENTRY-} ]]; then
1116
echo "Set CODE_SERVER_TEST_ENTRY to test another build of code-server"

ci/dev/test-unit.sh

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,12 +3,16 @@ set -euo pipefail
33

44
main() {
55
cd "$(dirname "$0")/../.."
6-
cd test/unit/node/test-plugin
6+
source ./ci/lib.sh
7+
8+
echo "Building test plugin"
9+
pushd test/unit/node/test-plugin
710
make -s out/index.js
11+
popd
12+
813
# We must keep jest in a sub-directory. See ../../test/package.json for more
914
# information. We must also run it from the root otherwise coverage will not
1015
# include our source files.
11-
cd "$OLDPWD"
1216
CS_DISABLE_PLUGINS=true ./test/node_modules/.bin/jest "$@"
1317
}
1418

src/common/util.ts

Lines changed: 28 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -66,33 +66,42 @@ export const resolveBase = (base?: string): string => {
6666
return normalize(url.pathname)
6767
}
6868

69+
let options: Options
70+
6971
/**
7072
* Get options embedded in the HTML or query params.
7173
*/
7274
export const getOptions = <T extends Options>(): T => {
73-
let options: T
74-
try {
75-
options = JSON.parse(document.getElementById("coder-options")!.getAttribute("data-settings")!)
76-
} catch (error) {
77-
options = {} as T
78-
}
75+
if (!options) {
76+
try {
77+
options = JSON.parse(document.getElementById("coder-options")!.getAttribute("data-settings")!)
78+
} catch (error) {
79+
console.error(error)
80+
options = {} as T
81+
}
7982

80-
// You can also pass options in stringified form to the options query
81-
// variable. Options provided here will override the ones in the options
82-
// element.
83-
const params = new URLSearchParams(location.search)
84-
const queryOpts = params.get("options")
85-
if (queryOpts) {
86-
options = {
87-
...options,
88-
...JSON.parse(queryOpts),
83+
// You can also pass options in stringified form to the options query
84+
// variable. Options provided here will override the ones in the options
85+
// element.
86+
const params = new URLSearchParams(location.search)
87+
const queryOpts = params.get("options")
88+
if (queryOpts) {
89+
try {
90+
options = {
91+
...options,
92+
...JSON.parse(queryOpts),
93+
}
94+
} catch (error) {
95+
// Don't fail if the query parameters are malformed.
96+
console.error(error)
97+
}
8998
}
90-
}
9199

92-
options.base = resolveBase(options.base)
93-
options.csStaticBase = resolveBase(options.csStaticBase)
100+
options.base = resolveBase(options.base)
101+
options.csStaticBase = resolveBase(options.csStaticBase)
102+
}
94103

95-
return options
104+
return options as T
96105
}
97106

98107
/**

test/e2e/extensions.test.ts

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
import { describe, test } from "./baseFixture"
2+
3+
describe("Extensions", true, () => {
4+
// This will only work if the test extension is loaded into code-server.
5+
test("should have access to VSCODE_PROXY_URI", async ({ codeServerPage }) => {
6+
const address = await codeServerPage.address()
7+
8+
await codeServerPage.executeCommandViaMenus("code-server: Get proxy URI")
9+
10+
await codeServerPage.page.waitForSelector(`text=${address}/proxy/{port}`)
11+
})
12+
})
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
/extension.js
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
import * as vscode from "vscode"
2+
3+
export function activate(context: vscode.ExtensionContext) {
4+
context.subscriptions.push(
5+
vscode.commands.registerCommand("codeServerTest.proxyUri", () => {
6+
if (process.env.VSCODE_PROXY_URI) {
7+
vscode.window.showInformationMessage(process.env.VSCODE_PROXY_URI)
8+
} else {
9+
vscode.window.showErrorMessage("No proxy URI was set")
10+
}
11+
}),
12+
)
13+
}
Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
{
2+
"name": "code-server-extension",
3+
"description": "code-server test extension",
4+
"version": "0.0.1",
5+
"publisher": "cdr",
6+
"activationEvents": [
7+
"onCommand:codeServerTest.proxyUri"
8+
],
9+
"engines": {
10+
"vscode": "^1.56.0"
11+
},
12+
"main": "./extension.js",
13+
"contributes": {
14+
"commands": [
15+
{
16+
"command": "codeServerTest.proxyUri",
17+
"title": "Get proxy URI",
18+
"category": "code-server"
19+
}
20+
]
21+
},
22+
"devDependencies": {
23+
"@types/vscode": "^1.56.0",
24+
"typescript": "^4.0.5"
25+
},
26+
"scripts": {
27+
"build": "tsc extension.ts"
28+
}
29+
}

0 commit comments

Comments
 (0)