|
1 | 1 | import * as cp from "child_process"
|
2 |
| -import Bundler from "parcel-bundler" |
| 2 | +import Parcel from "@parcel/core" |
3 | 3 | import * as path from "path"
|
4 | 4 |
|
| 5 | +type FixMeLater = any |
| 6 | + |
5 | 7 | async function main(): Promise<void> {
|
6 | 8 | try {
|
7 | 9 | const watcher = new Watcher()
|
@@ -84,15 +86,20 @@ class Watcher {
|
84 | 86 | cleanup(code)
|
85 | 87 | })
|
86 | 88 | }
|
87 |
| - const bundle = bundler.bundle().catch(() => { |
88 |
| - Watcher.log("parcel watcher terminated unexpectedly") |
89 |
| - cleanup(1) |
90 |
| - }) |
91 |
| - bundler.on("buildEnd", () => { |
92 |
| - console.log("[parcel] bundled") |
93 |
| - }) |
94 |
| - bundler.on("buildError", (error) => { |
95 |
| - console.error("[parcel]", error) |
| 89 | + const bundle = bundler.watch((err: any, buildEvent: string) => { |
| 90 | + if (err) { |
| 91 | + console.error(err) |
| 92 | + Watcher.log("parcel watcher terminated unexpectedly") |
| 93 | + cleanup(1) |
| 94 | + } |
| 95 | + |
| 96 | + if (buildEvent === "buildEnd") { |
| 97 | + console.log("[parcel] bundled") |
| 98 | + } |
| 99 | + |
| 100 | + if (buildEvent === "buildError") { |
| 101 | + console.error("[parcel]", err) |
| 102 | + } |
96 | 103 | })
|
97 | 104 |
|
98 | 105 | vscode.stderr.on("data", (d) => process.stderr.write(d))
|
@@ -172,22 +179,23 @@ class Watcher {
|
172 | 179 | }
|
173 | 180 | }
|
174 | 181 |
|
175 |
| - private createBundler(out = "dist"): Bundler { |
176 |
| - return new Bundler( |
177 |
| - [ |
| 182 | + private createBundler(out = "dist"): FixMeLater { |
| 183 | + return new (Parcel as any)({ |
| 184 | + entries: [ |
178 | 185 | path.join(this.rootPath, "src/browser/register.ts"),
|
179 | 186 | path.join(this.rootPath, "src/browser/serviceWorker.ts"),
|
180 | 187 | path.join(this.rootPath, "src/browser/pages/login.ts"),
|
181 | 188 | path.join(this.rootPath, "src/browser/pages/vscode.ts"),
|
182 | 189 | ],
|
183 |
| - { |
184 |
| - outDir: path.join(this.rootPath, out), |
185 |
| - cacheDir: path.join(this.rootPath, ".cache"), |
186 |
| - minify: !!process.env.MINIFY, |
187 |
| - logLevel: 1, |
| 190 | + cacheDir: path.join(this.rootPath, ".cache"), |
| 191 | + logLevel: 1, |
| 192 | + defaultConfig: require.resolve("@parcel/config-default"), |
| 193 | + defaultTargetOptions: { |
188 | 194 | publicUrl: ".",
|
| 195 | + shouldOptimize: !!process.env.MINIFY, |
| 196 | + distDir: path.join(this.rootPath, out), |
189 | 197 | },
|
190 |
| - ) |
| 198 | + }) |
191 | 199 | }
|
192 | 200 | }
|
193 | 201 |
|
|
0 commit comments