Skip to content

Commit 43c21fb

Browse files
committed
refactor: upgrade to parcel v2
1 parent 5623c28 commit 43c21fb

12 files changed

+1002
-3067
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

+5-8
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,8 @@ set -euo pipefail
77
MINIFY=${MINIFY-true}
88

99
main() {
10+
local opts=()
11+
[[ $MINIFY ]] && opts+=("-p" "tinyfy")
1012
cd "$(dirname "${0}")/../.."
1113

1214
tsc
@@ -32,14 +34,9 @@ main() {
3234
set -e
3335
fi
3436

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
37+
yarn browserify "${opts[@]}" src/browser/register.ts -o out/browser/register.browserified.js
38+
yarn browserify "${opts[@]}" src/browser/pages/login.ts -o out/browser/pages/login.browserified.js
39+
yarn browserify "${opts[@]}" src/browser/pages/vscode.ts -o out/browser/pages/vscode.browserified.js
4340
}
4441

4542
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

+27-39
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
import * as cp from "child_process"
2-
import Parcel from "@parcel/core"
32
import * as path from "path"
3+
import * as fs from "fs"
4+
import browserify from "browserify"
45

56
type FixMeLater = any
67

@@ -42,7 +43,6 @@ class Watcher {
4243
const plugin = process.env.PLUGIN_DIR
4344
? cp.spawn("yarn", ["build", "--watch"], { cwd: process.env.PLUGIN_DIR })
4445
: undefined
45-
const bundler = this.createBundler()
4646

4747
const cleanup = (code?: number | null): void => {
4848
Watcher.log("killing vs code watcher")
@@ -65,7 +65,7 @@ class Watcher {
6565
server.kill()
6666
}
6767

68-
Watcher.log("killing bundler")
68+
Watcher.log("killing watch")
6969
process.exit(code || 0)
7070
}
7171

@@ -86,28 +86,19 @@ class Watcher {
8686
cleanup(code)
8787
})
8888
}
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-
})
10489

10590
vscode.stderr.on("data", (d) => process.stderr.write(d))
10691
tsc.stderr.on("data", (d) => process.stderr.write(d))
10792
if (plugin) {
10893
plugin.stderr.on("data", (d) => process.stderr.write(d))
10994
}
11095

96+
const browserFiles = [
97+
path.join(this.rootPath, "out/browser/register.js"),
98+
path.join(this.rootPath, "out/browser/pages/login.js"),
99+
path.join(this.rootPath, "out/browser/pages/vscode.js"),
100+
]
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,26 @@ class Watcher {
173165
console.log("[plugin]", original)
174166
}
175167
if (line.includes("Watching for file changes")) {
176-
bundle.then(restartServer)
168+
restartServer()
177169
}
178170
})
179171
}
180172
}
173+
}
181174

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-
}
175+
function bundleBrowserCode(inputFiles: string[]) {
176+
console.log(`[browser] bundling...`)
177+
inputFiles.forEach(async (path: string) => {
178+
const outputPath = path.replace(".js", ".browserified.js")
179+
browserify()
180+
.add(path)
181+
.bundle()
182+
.on("error", function (error: Error) {
183+
console.error(error.toString())
184+
})
185+
.pipe(fs.createWriteStream(outputPath))
186+
})
187+
console.log(`[browser] done bundling`)
200188
}
201189

202190
main()

package.json

+4-2
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@
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
},
@@ -42,6 +42,7 @@
4242
"@parcel/types": "^2.0.0-alpha.3",
4343
"@schemastore/package": "^0.0.6",
4444
"@types/body-parser": "^1.19.0",
45+
"@types/browserify": "^12.0.36",
4546
"@types/compression": "^1.7.0",
4647
"@types/cookie-parser": "^1.4.2",
4748
"@types/express": "^4.17.8",
@@ -60,6 +61,7 @@
6061
"@typescript-eslint/eslint-plugin": "^4.7.0",
6162
"@typescript-eslint/parser": "^4.7.0",
6263
"audit-ci": "^4.0.0",
64+
"browserify": "^17.0.0",
6365
"codecov": "^3.8.1",
6466
"doctoc": "^2.0.0",
6567
"eslint": "^7.7.0",
@@ -68,12 +70,12 @@
6870
"eslint-plugin-import": "^2.18.2",
6971
"eslint-plugin-prettier": "^3.1.0",
7072
"leaked-handles": "^5.2.0",
71-
"parcel": "^2.0.0-beta.3.1",
7273
"prettier": "^2.2.1",
7374
"prettier-plugin-sh": "^0.6.0",
7475
"shellcheck": "^1.0.0",
7576
"stylelint": "^13.0.0",
7677
"stylelint-config-recommended": "^5.0.0",
78+
"tinyify": "^3.0.0",
7779
"ts-node": "^10.0.0",
7880
"typescript": "^4.1.3",
7981
"wtfnode": "^0.8.4"

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/pages/login.browserified.js"></script>
53+
``
5454
</html>

src/browser/pages/login.ts

+1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
import { getOptions } from "../../common/util"
2+
import "../register"
23

34
const options = getOptions()
45
const el = document.getElementById("base") as HTMLInputElement

src/browser/pages/vscode.html

+1-2
Original file line numberDiff line numberDiff line change
@@ -39,8 +39,7 @@
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/pages/vscode.browserified.js"></script>
4443
<script data-cfasync="false" src="{{CS_STATIC_BASE}}/lib/vscode/out/vs/loader.js"></script>
4544
<script>
4645
performance.mark("code/willLoadWorkbenchMain")

src/browser/pages/vscode.ts

+3-2
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
import { getOptions } from "../../common/util"
2+
import "../register"
23

34
const options = getOptions()
45

@@ -30,8 +31,8 @@ try {
3031
/* Probably fine. */
3132
}
3233

33-
;(self.require as any) = {
34-
// Without the full URL VS Code will try to load file://.
34+
;(self as any).require = {
35+
// Without the full URL VS Code will try to load file://.w
3536
baseUrl: `${window.location.origin}${options.csStaticBase}/lib/vscode/out`,
3637
recordStats: true,
3738
paths: {

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,

0 commit comments

Comments
 (0)