Skip to content

Commit 63e8c96

Browse files
committed
refactor: replace parcel with tsc & browserify
1 parent 5623c28 commit 63e8c96

File tree

13 files changed

+1040
-3275
lines changed

13 files changed

+1040
-3275
lines changed

.gitignore

-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
.tsbuildinfo
22
.cache
3-
dist*
43
/out*/
54
release/
65
release-npm-package/

ci/build/build-code-server.sh

+3-11
Original file line numberDiff line numberDiff line change
@@ -3,9 +3,6 @@ set -euo pipefail
33

44
# Builds code-server into out and the frontend into dist.
55

6-
# MINIFY controls whether parcel minifies dist.
7-
MINIFY=${MINIFY-true}
8-
96
main() {
107
cd "$(dirname "${0}")/../.."
118

@@ -32,14 +29,9 @@ main() {
3229
set -e
3330
fi
3431

35-
parcel build \
36-
--public-url "." \
37-
--dist-dir dist \
38-
$([[ $MINIFY ]] || echo --no-optimize) \
39-
src/browser/register.ts \
40-
src/browser/serviceWorker.ts \
41-
src/browser/pages/login.ts \
42-
src/browser/pages/vscode.ts
32+
yarn browserify -p tinyify src/browser/register.ts -o out/browser/register.browserified.js
33+
yarn browserify -p tinyify src/browser/pages/login.ts -o out/browser/pages/login.browserified.js
34+
yarn browserify src/browser/pages/vscode.ts -o out/browser/pages/vscode.browserified.js
4335
}
4436

4537
main "$@"

ci/build/build-release.sh

+1-1
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ main() {
2828
}
2929

3030
bundle_code_server() {
31-
rsync out dist "$RELEASE_PATH"
31+
rsync out "$RELEASE_PATH"
3232

3333
# For source maps and images.
3434
mkdir -p "$RELEASE_PATH/src/browser"

ci/dev/watch.ts

+30-41
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,7 @@
11
import * as cp from "child_process"
2-
import Parcel from "@parcel/core"
32
import * as path from "path"
4-
5-
type FixMeLater = any
3+
import * as fs from "fs"
4+
import browserify from "browserify"
65

76
async function main(): Promise<void> {
87
try {
@@ -42,7 +41,6 @@ class Watcher {
4241
const plugin = process.env.PLUGIN_DIR
4342
? cp.spawn("yarn", ["build", "--watch"], { cwd: process.env.PLUGIN_DIR })
4443
: undefined
45-
const bundler = this.createBundler()
4644

4745
const cleanup = (code?: number | null): void => {
4846
Watcher.log("killing vs code watcher")
@@ -65,7 +63,7 @@ class Watcher {
6563
server.kill()
6664
}
6765

68-
Watcher.log("killing bundler")
66+
Watcher.log("killing watch")
6967
process.exit(code || 0)
7068
}
7169

@@ -86,28 +84,21 @@ class Watcher {
8684
cleanup(code)
8785
})
8886
}
89-
const bundle = bundler.watch((err: FixMeLater, buildEvent: FixMeLater) => {
90-
if (err) {
91-
console.error(err)
92-
Watcher.log("parcel watcher terminated unexpectedly")
93-
cleanup(1)
94-
}
95-
96-
if (buildEvent.type === "buildEnd") {
97-
console.log("[parcel] bundled")
98-
}
99-
100-
if (buildEvent.type === "buildError") {
101-
console.error("[parcel]", err)
102-
}
103-
})
10487

10588
vscode.stderr.on("data", (d) => process.stderr.write(d))
10689
tsc.stderr.on("data", (d) => process.stderr.write(d))
10790
if (plugin) {
10891
plugin.stderr.on("data", (d) => process.stderr.write(d))
10992
}
11093

94+
const browserFiles = [
95+
path.join(this.rootPath, "out/browser/register.js"),
96+
path.join(this.rootPath, "out/browser/pages/login.js"),
97+
path.join(this.rootPath, "out/browser/pages/vscode.js"),
98+
]
99+
100+
bundleBrowserCode(browserFiles)
101+
111102
// From https://github.com/chalk/ansi-regex
112103
const pattern = [
113104
"[\\u001B\\u009B][[\\]()#;?]*(?:(?:(?:[a-zA-Z\\d]*(?:;[-a-zA-Z\\d\\/#&.:=?%@~_]*)*)?\\u0007)",
@@ -150,7 +141,7 @@ class Watcher {
150141
startingVscode = true
151142
} else if (startingVscode && line.includes("Finished compilation")) {
152143
if (startedVscode) {
153-
bundle.then(restartServer)
144+
restartServer()
154145
}
155146
startedVscode = true
156147
}
@@ -162,7 +153,8 @@ class Watcher {
162153
console.log("[tsc]", original)
163154
}
164155
if (line.includes("Watching for file changes")) {
165-
bundle.then(restartServer)
156+
bundleBrowserCode(browserFiles)
157+
restartServer()
166158
}
167159
})
168160

@@ -173,30 +165,27 @@ class Watcher {
173165
console.log("[plugin]", original)
174166
}
175167
if (line.includes("Watching for file changes")) {
176-
bundle.then(restartServer)
168+
bundleBrowserCode(browserFiles)
169+
restartServer()
177170
}
178171
})
179172
}
180173
}
174+
}
181175

182-
private createBundler(out = "dist"): FixMeLater {
183-
return new (Parcel as FixMeLater)({
184-
entries: [
185-
path.join(this.rootPath, "src/browser/register.ts"),
186-
path.join(this.rootPath, "src/browser/serviceWorker.ts"),
187-
path.join(this.rootPath, "src/browser/pages/login.ts"),
188-
path.join(this.rootPath, "src/browser/pages/vscode.ts"),
189-
],
190-
cacheDir: path.join(this.rootPath, ".cache"),
191-
logLevel: 1,
192-
defaultConfig: require.resolve("@parcel/config-default"),
193-
defaultTargetOptions: {
194-
publicUrl: ".",
195-
shouldOptimize: !!process.env.MINIFY,
196-
distDir: path.join(this.rootPath, out),
197-
},
198-
})
199-
}
176+
function bundleBrowserCode(inputFiles: string[]) {
177+
console.log(`[browser] bundling...`)
178+
inputFiles.forEach(async (path: string) => {
179+
const outputPath = path.replace(".js", ".browserified.js")
180+
browserify()
181+
.add(path)
182+
.bundle()
183+
.on("error", function (error: Error) {
184+
console.error(error.toString())
185+
})
186+
.pipe(fs.createWriteStream(outputPath))
187+
})
188+
console.log(`[browser] done bundling`)
200189
}
201190

202191
main()

package.json

+5-13
Original file line numberDiff line numberDiff line change
@@ -29,19 +29,15 @@
2929
"lint": "./ci/dev/lint.sh",
3030
"test": "echo 'Run yarn test:unit or yarn test:e2e' && exit 1",
3131
"ci": "./ci/dev/ci.sh",
32-
"watch": "VSCODE_IPC_HOOK_CLI= NODE_OPTIONS=--max_old_space_size=32384 ts-node ./ci/dev/watch.ts",
32+
"watch": "VSCODE_IPC_HOOK_CLI= NODE_OPTIONS='--max_old_space_size=32384 --trace-warnings' ts-node ./ci/dev/watch.ts",
3333
"icons": "./ci/dev/gen_icons.sh",
3434
"coverage": "codecov"
3535
},
3636
"main": "out/node/entry.js",
37-
"targets": {
38-
"main": false
39-
},
4037
"devDependencies": {
41-
"@parcel/core": "^2.0.0-beta.3.1",
42-
"@parcel/types": "^2.0.0-alpha.3",
4338
"@schemastore/package": "^0.0.6",
4439
"@types/body-parser": "^1.19.0",
40+
"@types/browserify": "^12.0.36",
4541
"@types/compression": "^1.7.0",
4642
"@types/cookie-parser": "^1.4.2",
4743
"@types/express": "^4.17.8",
@@ -60,6 +56,7 @@
6056
"@typescript-eslint/eslint-plugin": "^4.7.0",
6157
"@typescript-eslint/parser": "^4.7.0",
6258
"audit-ci": "^4.0.0",
59+
"browserify": "^17.0.0",
6360
"codecov": "^3.8.1",
6461
"doctoc": "^2.0.0",
6562
"eslint": "^7.7.0",
@@ -68,12 +65,12 @@
6865
"eslint-plugin-import": "^2.18.2",
6966
"eslint-plugin-prettier": "^3.1.0",
7067
"leaked-handles": "^5.2.0",
71-
"parcel": "^2.0.0-beta.3.1",
7268
"prettier": "^2.2.1",
7369
"prettier-plugin-sh": "^0.6.0",
7470
"shellcheck": "^1.0.0",
7571
"stylelint": "^13.0.0",
7672
"stylelint-config-recommended": "^5.0.0",
73+
"tinyify": "^3.0.0",
7774
"ts-node": "^10.0.0",
7875
"typescript": "^4.1.3",
7976
"wtfnode": "^0.8.4"
@@ -85,12 +82,7 @@
8582
"postcss": "^8.2.1",
8683
"browserslist": "^4.16.5",
8784
"safe-buffer": "^5.1.1",
88-
"vfile-message": "^2.0.2",
89-
"parcel/@parcel/config-default/@parcel/optimizer-cssnano/cssnano/cssnano-preset-default/postcss-svgo/svgo/css-select/css-what": "5.0.1",
90-
"parcel/@parcel/config-default/@parcel/optimizer-htmlnano/htmlnano/cssnano/cssnano-preset-default/postcss-svgo/svgo/css-select/css-what": "5.0.1",
91-
"parcel/@parcel/config-default/@parcel/optimizer-htmlnano/htmlnano/svgo/css-select/css-what": "5.0.1",
92-
"parcel/@parcel/config-default/@parcel/optimizer-cssnano/cssnano/cssnano-preset-default/postcss-normalize-url/normalize-url": "4.5.1",
93-
"parcel/@parcel/config-default/@parcel/optimizer-htmlnano/htmlnano/cssnano/cssnano-preset-default/postcss-normalize-url/normalize-url": "4.5.1"
85+
"vfile-message": "^2.0.2"
9486
},
9587
"dependencies": {
9688
"@coder/logger": "1.1.16",

src/browser/pages/error.html

+1-1
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,6 @@ <h2 class="header">{{ERROR_HEADER}}</h2>
3030
</div>
3131
</div>
3232
</div>
33-
<script data-cfasync="false" src="{{CS_STATIC_BASE}}/dist/register.js"></script>
33+
<script data-cfasync="false" src="{{CS_STATIC_BASE}}/out/browser/register.browserified.js"></script>
3434
</body>
3535
</html>

src/browser/pages/login.html

+2-2
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,6 @@ <h1 class="main">Welcome to code-server</h1>
4949
</div>
5050
</div>
5151
</body>
52-
<script data-cfasync="false" src="{{CS_STATIC_BASE}}/dist/register.js"></script>
53-
<script data-cfasync="false" src="{{CS_STATIC_BASE}}/dist/pages/login.js"></script>
52+
<script data-cfasync="false" src="{{CS_STATIC_BASE}}/out/browser/register.browserified.js"></script>
53+
<script data-cfasync="false" src="{{CS_STATIC_BASE}}/out/browser/login.browserified.js"></script>
5454
</html>

src/browser/pages/vscode.html

+2-2
Original file line numberDiff line numberDiff line change
@@ -39,8 +39,8 @@
3939
<body aria-label=""></body>
4040

4141
<!-- Startup (do not modify order of script tags!) -->
42-
<script data-cfasync="false" src="{{CS_STATIC_BASE}}/dist/pages/vscode.js"></script>
43-
<script data-cfasync="false" src="{{CS_STATIC_BASE}}/dist/register.js"></script>
42+
<script data-cfasync="false" src="{{CS_STATIC_BASE}}/out/browser/register.browserified.js"></script>
43+
<script data-cfasync="false" src="{{CS_STATIC_BASE}}/out/browser/pages/vscode.browserified.js"></script>
4444
<script data-cfasync="false" src="{{CS_STATIC_BASE}}/lib/vscode/out/vs/loader.js"></script>
4545
<script>
4646
performance.mark("code/willLoadWorkbenchMain")

src/browser/pages/vscode.ts

+3-3
Original file line numberDiff line numberDiff line change
@@ -30,8 +30,8 @@ try {
3030
/* Probably fine. */
3131
}
3232

33-
;(self.require as any) = {
34-
// Without the full URL VS Code will try to load file://.
33+
;(self as any).require = {
34+
// Without the full URL VS Code will try to load file://.w
3535
baseUrl: `${window.location.origin}${options.csStaticBase}/lib/vscode/out`,
3636
recordStats: true,
3737
paths: {
@@ -52,4 +52,4 @@ try {
5252
document.body.style.background = JSON.parse(localStorage.getItem("colorThemeData")!).colorMap["editor.background"]
5353
} catch (error) {
5454
// Oh well.
55-
}
55+
}

tsconfig.json

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,14 @@
11
{
22
"compilerOptions": {
3-
"target": "es5",
3+
"target": "es2020",
44
"module": "commonjs",
55
"moduleResolution": "node",
66
"strict": true,
77
"noImplicitReturns": true,
88
"noUnusedLocals": true,
99
"forceConsistentCasingInFileNames": true,
1010
"outDir": "./out",
11-
"declaration": true,
11+
"declaration": false,
1212
"experimentalDecorators": true,
1313
"esModuleInterop": true,
1414
"allowSyntheticDefaultImports": true,

typings/parcel/index.d.ts

-1
This file was deleted.

typings/parcel__core/index.d.ts

-6
This file was deleted.

0 commit comments

Comments
 (0)