Skip to content

Commit c5e67ae

Browse files
authored
Merge branch 'main' into code-update-1.68
2 parents 4355006 + eb314ff commit c5e67ae

File tree

9 files changed

+172
-28
lines changed

9 files changed

+172
-28
lines changed

.github/ISSUE_TEMPLATE/bug-report.yml

+4-2
Original file line numberDiff line numberDiff line change
@@ -66,11 +66,13 @@ body:
6666
required: false
6767
- type: checkboxes
6868
attributes:
69-
label: Does this issue happen in VS Code?
70-
description: Please try reproducing this issue in VS Code
69+
label: Does this issue happen in VS Code or GitHub Codespaces?
70+
description: Please try reproducing this issue in VS Code or GitHub Codespaces
7171
options:
7272
- label: I cannot reproduce this in VS Code.
7373
required: true
74+
- label: I cannot reproduce this in GitHub Codespaces.
75+
required: true
7476
- type: checkboxes
7577
attributes:
7678
label: Are you accessing code-server over HTTPS?

.github/workflows/ci.yaml

+1-1
Original file line numberDiff line numberDiff line change
@@ -509,7 +509,7 @@ jobs:
509509
fetch-depth: 0
510510

511511
- name: Run Trivy vulnerability scanner in repo mode
512-
uses: aquasecurity/trivy-action@df3fb7d00b594d641478ba45b867f5cbb32108be
512+
uses: aquasecurity/trivy-action@e27605859b9550f81ddd818eb816c8cb83cf9650
513513
with:
514514
scan-type: "fs"
515515
scan-ref: "."

.github/workflows/docker.yaml

+2-2
Original file line numberDiff line numberDiff line change
@@ -47,11 +47,11 @@ jobs:
4747
run: echo "::set-output name=version::$(jq -r .version package.json)"
4848

4949
- name: Download release artifacts
50-
uses: robinraju/release-downloader@v1.3
50+
uses: robinraju/release-downloader@v1.4
5151
with:
5252
repository: "coder/code-server"
5353
tag: v${{ steps.version.outputs.version }}
54-
fileName: "*"
54+
fileName: "*.deb"
5555
out-file-path: "release-packages"
5656

5757
- name: Publish to Docker

.github/workflows/trivy-docker.yaml

+1-1
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,7 @@ jobs:
5151
uses: actions/checkout@v3
5252

5353
- name: Run Trivy vulnerability scanner in image mode
54-
uses: aquasecurity/trivy-action@df3fb7d00b594d641478ba45b867f5cbb32108be
54+
uses: aquasecurity/trivy-action@e27605859b9550f81ddd818eb816c8cb83cf9650
5555
with:
5656
image-ref: "docker.io/codercom/code-server:latest"
5757
ignore-unfixed: true

docs/README.md

+3-2
Original file line numberDiff line numberDiff line change
@@ -14,8 +14,9 @@ access it in the browser.
1414
- Preserve battery life when you're on the go; all intensive tasks run on your
1515
server
1616

17-
| 🔔 code-server is a free browser-based IDE while [Coder](https://coder.com/) is our enterprise developer workspace platform. For more information, visit [Coder.com](https://coder.com/docs/comparison)
18-
| ---
17+
> **Note**
18+
> To manage multiple IDEs, workspaces, and teams, see
19+
> our new project: [coder/coder](http://cdr.co/coder-github)
1920
2021
## Requirements
2122

package.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -100,7 +100,7 @@
100100
"limiter": "^1.1.5",
101101
"pem": "^1.14.2",
102102
"proxy-agent": "^5.0.0",
103-
"qs": "6.10.3",
103+
"qs": "6.10.5",
104104
"rotating-file-stream": "^3.0.0",
105105
"safe-buffer": "^5.1.1",
106106
"safe-compare": "^1.1.4",

src/node/util.ts

+60-15
Original file line numberDiff line numberDiff line change
@@ -377,11 +377,62 @@ export const getMediaMime = (filePath?: string): string => {
377377
return (filePath && mimeTypes[path.extname(filePath)]) || "text/plain"
378378
}
379379

380-
export const isWsl = async (): Promise<boolean> => {
381-
return (
382-
(process.platform === "linux" && os.release().toLowerCase().indexOf("microsoft") !== -1) ||
383-
(await fs.readFile("/proc/version", "utf8")).toLowerCase().indexOf("microsoft") !== -1
384-
)
380+
/**
381+
* A helper function that checks if the platform is Windows Subsystem for Linux
382+
* (WSL)
383+
*
384+
* @see https://github.com/sindresorhus/is-wsl/blob/main/index.js
385+
* @returns {Boolean} boolean if it is WSL
386+
*/
387+
export const isWsl = async (
388+
platform: NodeJS.Platform,
389+
osRelease: string,
390+
procVersionFilePath: string,
391+
): Promise<boolean> => {
392+
if (platform !== "linux") {
393+
return false
394+
}
395+
396+
if (osRelease.toLowerCase().includes("microsoft")) {
397+
return true
398+
}
399+
400+
try {
401+
return (await fs.readFile(procVersionFilePath, "utf8")).toLowerCase().includes("microsoft")
402+
} catch (_) {
403+
return false
404+
}
405+
}
406+
407+
interface OpenOptions {
408+
args: string[]
409+
command: string
410+
urlSearch: string
411+
}
412+
413+
/**
414+
* A helper function to construct options for `open` function.
415+
*
416+
* Extract to make it easier to test.
417+
*
418+
* @param platform - platform on machine
419+
* @param urlSearch - url.search
420+
* @returns an object with args, command, options and urlSearch
421+
*/
422+
export function constructOpenOptions(platform: NodeJS.Platform | "wsl", urlSearch: string): OpenOptions {
423+
const args: string[] = []
424+
let command = platform === "darwin" ? "open" : "xdg-open"
425+
if (platform === "win32" || platform === "wsl") {
426+
command = platform === "wsl" ? "cmd.exe" : "cmd"
427+
args.push("/c", "start", '""', "/b")
428+
urlSearch = urlSearch.replace(/&/g, "^&")
429+
}
430+
431+
return {
432+
args,
433+
command,
434+
urlSearch,
435+
}
385436
}
386437

387438
/**
@@ -396,16 +447,10 @@ export const open = async (address: URL | string): Promise<void> => {
396447
if (url.hostname === "0.0.0.0") {
397448
url.hostname = "localhost"
398449
}
399-
const args = [] as string[]
400-
const options = {} as cp.SpawnOptions
401-
const platform = (await isWsl()) ? "wsl" : process.platform
402-
let command = platform === "darwin" ? "open" : "xdg-open"
403-
if (platform === "win32" || platform === "wsl") {
404-
command = platform === "wsl" ? "cmd.exe" : "cmd"
405-
args.push("/c", "start", '""', "/b")
406-
url.search = url.search.replace(/&/g, "^&")
407-
}
408-
const proc = cp.spawn(command, [...args, url.toString()], options)
450+
const platform = (await isWsl(process.platform, os.release(), "/proc/version")) ? "wsl" : process.platform
451+
const { command, args, urlSearch } = constructOpenOptions(platform, url.search)
452+
url.search = urlSearch
453+
const proc = cp.spawn(command, [...args, url.toString()], {})
409454
await new Promise<void>((resolve, reject) => {
410455
proc.on("error", reject)
411456
proc.on("close", (code) => {

test/unit/node/util.test.ts

+96
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ import * as path from "path"
44
import { generateUuid } from "../../../src/common/util"
55
import { tmpdir } from "../../../src/node/constants"
66
import * as util from "../../../src/node/util"
7+
import { clean, tmpdir as tempDirHelper } from "../../utils/helpers"
78

89
describe("getEnvPaths", () => {
910
describe("on darwin", () => {
@@ -482,3 +483,98 @@ describe("humanPath", () => {
482483
expect(actual).toBe(expected)
483484
})
484485
})
486+
487+
describe("isWsl", () => {
488+
const testName = "wsl"
489+
490+
beforeAll(async () => {
491+
await clean(testName)
492+
})
493+
494+
describe("on Linux (microsoft)", () => {
495+
it("should return true", async () => {
496+
const fileName = "proc-version"
497+
const osRelease = "5.4.0-1066-gke"
498+
const pathToFile = path.join(await tempDirHelper(testName), fileName)
499+
await fs.writeFile(
500+
pathToFile,
501+
"Linux version 3.4.0-Microsoft ([email protected]) (gcc version 4.7 (GCC) ) #1 SMP PREEMPT Wed Dec 31 14:42:53 PST 2014",
502+
)
503+
expect(await util.isWsl("linux", osRelease, pathToFile)).toBe(true)
504+
})
505+
})
506+
describe("on Linux (non-microsoft)", () => {
507+
it("should return false", async () => {
508+
const fileName = "proc-version2"
509+
const osRelease = "Linux"
510+
const pathToFile = path.join(await tempDirHelper(testName), fileName)
511+
await fs.writeFile(
512+
pathToFile,
513+
"Linux version 5.4.0-1066-gke (buildd@lcy02-amd64-039) (gcc version 9.4.0 (Ubuntu 9.4.0-1ubuntu1~20.04)) #69-Ubuntu SMP Fri Mar 11 13:52:45 UTC 202",
514+
)
515+
expect(await util.isWsl("linux", osRelease, pathToFile)).toBe(false)
516+
})
517+
})
518+
describe("on Win32 with microsoft in /proc/version", () => {
519+
it("should return false", async () => {
520+
const fileName = "proc-version3"
521+
const osRelease = "3.4.0-Microsoft"
522+
const pathToFile = path.join(await tempDirHelper(testName), fileName)
523+
await fs.writeFile(
524+
pathToFile,
525+
"Linux version 3.4.0-Microsoft ([email protected]) (gcc version 4.7 (GCC) ) #1 SMP PREEMPT Wed Dec 31 14:42:53 PST 2014",
526+
)
527+
expect(await util.isWsl("win32", osRelease, pathToFile)).toBe(false)
528+
})
529+
})
530+
describe("on Darwin", () => {
531+
it("should return false", async () => {
532+
const fileName = "proc-version4"
533+
const osRelease =
534+
"Darwin Roadrunner.local 10.3.0 Darwin Kernel Version 10.3.0: Fri Feb 26 11:58:09 PST 2010; root:xnu-1504.3.12~1/RELEASE_I386 i386"
535+
const pathToFile = path.join(await tempDirHelper(testName), fileName)
536+
expect(await util.isWsl("darwin", osRelease, pathToFile)).toBe(false)
537+
})
538+
})
539+
})
540+
541+
describe("open", () => {
542+
it("should throw an error if address is a string", async () => {
543+
const address = "localhost:3000"
544+
await expect(util.open(address)).rejects.toThrow("Cannot open socket paths")
545+
})
546+
})
547+
describe("constructOpenOptions", () => {
548+
it("should return options for darwin", () => {
549+
const platform: NodeJS.Platform | "wsl" = "darwin"
550+
const url = new URL("localhost:8080")
551+
const { args, command, urlSearch } = util.constructOpenOptions(platform, url.search)
552+
expect(args).toStrictEqual([])
553+
expect(command).toBe("open")
554+
expect(urlSearch).toBe("")
555+
})
556+
it("should return options for linux", () => {
557+
const platform: NodeJS.Platform | "wsl" = "linux"
558+
const url = new URL("localhost:8080")
559+
const { args, command, urlSearch } = util.constructOpenOptions(platform, url.search)
560+
expect(args).toStrictEqual([])
561+
expect(command).toBe("xdg-open")
562+
expect(urlSearch).toBe("")
563+
})
564+
it("should return options for win32", () => {
565+
const platform: NodeJS.Platform | "wsl" = "win32"
566+
const url = new URL("localhost:8080?q=&test")
567+
const { args, command, urlSearch } = util.constructOpenOptions(platform, url.search)
568+
expect(args).toStrictEqual(["/c", "start", '""', "/b"])
569+
expect(command).toBe("cmd")
570+
expect(urlSearch).toBe("?q=^&test")
571+
})
572+
it("should return options for wsl", () => {
573+
const platform: NodeJS.Platform | "wsl" = "wsl"
574+
const url = new URL("localhost:8080?q=&test")
575+
const { args, command, urlSearch } = util.constructOpenOptions(platform, url.search)
576+
expect(args).toStrictEqual(["/c", "start", '""', "/b"])
577+
expect(command).toBe("cmd.exe")
578+
expect(urlSearch).toBe("?q=^&test")
579+
})
580+
})

yarn.lock

+4-4
Original file line numberDiff line numberDiff line change
@@ -3513,10 +3513,10 @@ punycode@^2.1.0:
35133513
resolved "https://registry.yarnpkg.com/punycode/-/punycode-2.1.1.tgz#b58b010ac40c22c5657616c8d2c2c02c7bf479ec"
35143514
integrity sha512-XRsRjdf+j5ml+y/6GKHPZbrF/8p2Yga0JPtdqTIY2Xe5ohJPD9saDJJLPvp9+NSBprVvevdXZybnj2cv8OEd0A==
35153515

3516-
3517-
version "6.10.3"
3518-
resolved "https://registry.yarnpkg.com/qs/-/qs-6.10.3.tgz#d6cde1b2ffca87b5aa57889816c5f81535e22e8e"
3519-
integrity sha512-wr7M2E0OFRfIfJZjKGieI8lBKb7fRCH4Fv5KNPEs7gJ8jadvotdsS08PzOKR7opXhZ/Xkjtt3WF9g38drmyRqQ==
3516+
3517+
version "6.10.5"
3518+
resolved "https://registry.yarnpkg.com/qs/-/qs-6.10.5.tgz#974715920a80ff6a262264acd2c7e6c2a53282b4"
3519+
integrity sha512-O5RlPh0VFtR78y79rgcgKK4wbAI0C5zGVLztOIdpWX6ep368q5Hv6XRxDvXuZ9q3C6v+e3n8UfZZJw7IIG27eQ==
35203520
dependencies:
35213521
side-channel "^1.0.4"
35223522

0 commit comments

Comments
 (0)