Skip to content

Commit 9790a22

Browse files
author
Teffen
authored
Merge branch 'main' into watcher-improvements
2 parents e969ebb + dd29a82 commit 9790a22

File tree

8 files changed

+52
-22
lines changed

8 files changed

+52
-22
lines changed

ci/helm-chart/templates/NOTES.txt

+1-2
Original file line numberDiff line numberDiff line change
@@ -15,9 +15,8 @@
1515
export SERVICE_IP=$(kubectl get svc --namespace {{ .Release.Namespace }} {{ include "code-server.fullname" . }} -o jsonpath='{.status.loadBalancer.ingress[0].ip}')
1616
echo http://$SERVICE_IP:{{ .Values.service.port }}
1717
{{- else if contains "ClusterIP" .Values.service.type }}
18-
export POD_NAME=$(kubectl get pods --namespace {{ .Release.Namespace }} -l "app.kubernetes.io/name={{ include "code-server.name" . }},app.kubernetes.io/instance={{ .Release.Name }}" -o jsonpath="{.items[0].metadata.name}")
1918
echo "Visit http://127.0.0.1:8080 to use your application"
20-
kubectl port-forward $POD_NAME 8080:80
19+
kubectl port-forward --namespace {{ .Release.Namespace }} service/{{ include "code-server.fullname" . }} 8080:http
2120
{{- end }}
2221

2322
Administrator credentials:

docs/CONTRIBUTING.md

+19-7
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99
- [Development workflow](#development-workflow)
1010
- [Updates to VS Code](#updates-to-vs-code)
1111
- [Build](#build)
12+
- [Help](#help)
1213
- [Test](#test)
1314
- [Unit tests](#unit-tests)
1415
- [Script tests](#script-tests)
@@ -77,16 +78,23 @@ we'll guide you.
7778

7879
## Development workflow
7980

80-
```shell
81-
yarn
82-
yarn watch
83-
# Visit http://localhost:8080 once the build is completed.
84-
```
81+
The current development workflow is a bit tricky because we have this repo and we use our `cdr/vscode` fork inside it with [`yarn link`](https://classic.yarnpkg.com/lang/en/docs/cli/link/).
82+
83+
Here are these steps you should follow to get your dev environment setup:
8584

86-
`yarn watch` will live reload changes to the source.
85+
1. `git clone https://github.com/cdr/code-server.git` - Clone `code-server`
86+
2. `git clone https://github.com/cdr/vscode.git` - Clone `vscode`
87+
3. `cd vscode && git checkout code-server-v2` - checkout the branch we use (not the default)
88+
4. `cd vscode && yarn install` - install the dependencies in the `vscode` repo
89+
5. `cd code-server && yarn install` - install the dependencies in the `code-server` repo
90+
6. `cd vscode && yarn link` - use `yarn` to create a symlink to the `vscode` repo (`code-oss-dev` package)
91+
7. `cd code-server && yarn link code-oss-dev --modules-folder vendor/modules` - links your local `vscode` repo (`code-oss-dev` package) inside your local version of code-server
92+
8. `cd code-server && yarn watch` - this will spin up code-server on localhost:8080 which you can start developing. It will live reload changes to the source.
8793

8894
### Updates to VS Code
8995

96+
If changes are made and merged into `code-server-v2` in the `cdr/vscode` repo, then you'll need to update the version in the `code-server` repo by following these steps:
97+
9098
1. Update the package tag listed in `vendor/package.json`:
9199

92100
```json
@@ -97,7 +105,7 @@ yarn watch
97105
}
98106
```
99107

100-
2. From the code-server **project root**, run `yarn install`.
108+
1. From the code-server **project root**, run `yarn install`.
101109
Then, test code-server locally to make sure everything works.
102110
1. Check the Node.js version that's used by Electron (which is shipped with VS
103111
Code. If necessary, update your version of Node.js to match.
@@ -139,6 +147,10 @@ yarn package
139147
> If you need your builds to support older distros, run the build commands
140148
> inside a Docker container with all the build requirements installed.
141149
150+
### Help
151+
152+
If you get stuck or need help, you can always start a new GitHub Discussion [here](https://github.com/cdr/code-server/discussions). One of the maintainers will respond and help you out.
153+
142154
## Test
143155

144156
There are four kinds of tests in code-server:

src/node/cli.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -606,7 +606,7 @@ export async function readConfigFile(configPath?: string): Promise<ConfigArgs> {
606606
await fs.writeFile(configPath, defaultConfigFile(generatedPassword), {
607607
flag: "wx", // wx means to fail if the path exists.
608608
})
609-
logger.info(`Wrote default config file to ${humanPath(configPath)}`)
609+
logger.info(`Wrote default config file to ${humanPath(os.homedir(), configPath)}`)
610610
} catch (error: any) {
611611
// EEXIST is fine; we don't want to overwrite existing configurations.
612612
if (error.code !== "EEXIST") {

src/node/main.ts

+6-5
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
import { field, logger } from "@coder/logger"
2+
import * as os from "os"
23
import http from "http"
34
import path from "path"
45
import { Disposable } from "../common/emitter"
@@ -95,8 +96,8 @@ export const runCodeServer = async (
9596
): Promise<{ dispose: Disposable["dispose"]; server: http.Server }> => {
9697
logger.info(`code-server ${version} ${commit}`)
9798

98-
logger.info(`Using user-data-dir ${humanPath(args["user-data-dir"])}`)
99-
logger.trace(`Using extensions-dir ${humanPath(args["extensions-dir"])}`)
99+
logger.info(`Using user-data-dir ${humanPath(os.homedir(), args["user-data-dir"])}`)
100+
logger.trace(`Using extensions-dir ${humanPath(os.homedir(), args["extensions-dir"])}`)
100101

101102
if (args.auth === AuthType.Password && !args.password && !args["hashed-password"]) {
102103
throw new Error(
@@ -109,7 +110,7 @@ export const runCodeServer = async (
109110
const serverAddress = ensureAddress(app.server, protocol)
110111
const disposeRoutes = await register(app, args)
111112

112-
logger.info(`Using config file ${humanPath(args.config)}`)
113+
logger.info(`Using config file ${humanPath(os.homedir(), args.config)}`)
113114
logger.info(
114115
`${protocol.toUpperCase()} server listening on ${serverAddress.toString()} ${
115116
args.link ? "(randomized by --link)" : ""
@@ -123,14 +124,14 @@ export const runCodeServer = async (
123124
} else if (args.usingEnvHashedPassword) {
124125
logger.info(" - Using password from $HASHED_PASSWORD")
125126
} else {
126-
logger.info(` - Using password from ${humanPath(args.config)}`)
127+
logger.info(` - Using password from ${humanPath(os.homedir(), args.config)}`)
127128
}
128129
} else {
129130
logger.info(` - Authentication is disabled ${args.link ? "(disabled by --link)" : ""}`)
130131
}
131132

132133
if (args.cert) {
133-
logger.info(` - Using certificate for HTTPS: ${humanPath(args.cert.value)}`)
134+
logger.info(` - Using certificate for HTTPS: ${humanPath(os.homedir(), args.cert.value)}`)
134135
} else {
135136
logger.info(` - Not serving HTTPS ${args.link ? "(disabled by --link)" : ""}`)
136137
}

src/node/routes/index.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -141,7 +141,7 @@ export const register = async (app: App, args: DefaultedArgs): Promise<Disposabl
141141
const vsServerRouteHandler = new CodeServerRouteWrapper()
142142

143143
// Note that the root route is replaced in Coder Enterprise by the plugin API.
144-
for (const routePrefix of ["/", "/vscode"]) {
144+
for (const routePrefix of ["/vscode", "/"]) {
145145
app.router.use(routePrefix, vsServerRouteHandler.router)
146146
app.wsRouter.use(routePrefix, vsServerRouteHandler.wsRouter)
147147
}

src/node/routes/login.ts

+2-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
import { Router, Request } from "express"
22
import { promises as fs } from "fs"
33
import { RateLimiter as Limiter } from "limiter"
4+
import * as os from "os"
45
import * as path from "path"
56
import { rootPath } from "../constants"
67
import { authenticated, getCookieDomain, redirect, replaceTemplates } from "../http"
@@ -30,7 +31,7 @@ export class RateLimiter {
3031

3132
const getRoot = async (req: Request, error?: Error): Promise<string> => {
3233
const content = await fs.readFile(path.join(rootPath, "src/browser/pages/login.html"), "utf8")
33-
let passwordMsg = `Check the config file at ${humanPath(req.args.config)} for the password.`
34+
let passwordMsg = `Check the config file at ${humanPath(os.homedir(), req.args.config)} for the password.`
3435
if (req.args.usingEnvPassword) {
3536
passwordMsg = "Password was set from $PASSWORD."
3637
} else if (req.args.usingEnvHashedPassword) {

src/node/util.ts

+6-5
Original file line numberDiff line numberDiff line change
@@ -90,16 +90,17 @@ export function getEnvPaths(): Paths {
9090
}
9191

9292
/**
93-
* humanPath replaces the home directory in p with ~.
93+
* humanPath replaces the home directory in path with ~.
9494
* Makes it more readable.
9595
*
96-
* @param p
96+
* @param homedir - the home directory(i.e. `os.homedir()`)
97+
* @param path - a file path
9798
*/
98-
export function humanPath(p?: string): string {
99-
if (!p) {
99+
export function humanPath(homedir: string, path?: string): string {
100+
if (!path) {
100101
return ""
101102
}
102-
return p.replace(os.homedir(), "~")
103+
return path.replace(homedir, "~")
103104
}
104105

105106
export const generateCertificate = async (hostname: string): Promise<{ cert: string; certKey: string }> => {

test/unit/node/util.test.ts

+16
Original file line numberDiff line numberDiff line change
@@ -476,3 +476,19 @@ describe("isFile", () => {
476476
expect(await util.isFile(pathToFile)).toBe(true)
477477
})
478478
})
479+
480+
describe("humanPath", () => {
481+
it("should return an empty string if no path provided", () => {
482+
const mockHomedir = "/home/coder"
483+
const actual = util.humanPath(mockHomedir)
484+
const expected = ""
485+
expect(actual).toBe(expected)
486+
})
487+
it("should replace the homedir with ~", () => {
488+
const mockHomedir = "/home/coder"
489+
const path = `${mockHomedir}/code-server`
490+
const actual = util.humanPath(mockHomedir, path)
491+
const expected = "~/code-server"
492+
expect(actual).toBe(expected)
493+
})
494+
})

0 commit comments

Comments
 (0)