|
1 | 1 | import { gray, red } from "ansi-colors"; |
2 | | -import { dest, watch } from "gulp"; |
3 | | -import { init, write } from "gulp-sourcemaps"; |
4 | | -import * as ts from "gulp-typescript"; |
5 | | -import * as del from "del"; |
| 2 | +import { dest, src, watch } from "gulp"; |
| 3 | +import esbuild from "gulp-esbuild"; |
| 4 | +import ts from "gulp-typescript"; |
| 5 | +import del from "del"; |
6 | 6 |
|
7 | 7 | function goodReporter(): ts.reporter.Reporter { |
8 | 8 | return { |
@@ -35,20 +35,46 @@ export function cleanOutput() { |
35 | 35 | : Promise.resolve(); |
36 | 36 | } |
37 | 37 |
|
38 | | -export function compileTypeScript() { |
39 | | - return tsProject |
40 | | - .src() |
41 | | - .pipe(init()) |
42 | | - .pipe(tsProject(goodReporter())) |
| 38 | +export function compileEsbuild() { |
| 39 | + return src("./src/extension.ts") |
43 | 40 | .pipe( |
44 | | - write(".", { |
45 | | - includeContent: false, |
46 | | - sourceRoot: ".", |
| 41 | + esbuild({ |
| 42 | + outfile: "extension.js", |
| 43 | + bundle: true, |
| 44 | + external: ["vscode", "fsevents"], |
| 45 | + format: "cjs", |
| 46 | + platform: "node", |
| 47 | + target: "es2020", |
| 48 | + sourcemap: "linked", |
| 49 | + sourceRoot: "..", |
| 50 | + loader: { |
| 51 | + ".node": "copy", |
| 52 | + }, |
47 | 53 | }), |
48 | 54 | ) |
49 | 55 | .pipe(dest("out")); |
50 | 56 | } |
51 | 57 |
|
52 | | -export function watchTypeScript() { |
53 | | - watch("src/**/*.ts", compileTypeScript); |
| 58 | +export function watchEsbuild() { |
| 59 | + watch("src/**/*.ts", compileEsbuild); |
| 60 | +} |
| 61 | + |
| 62 | +export function checkTypeScript() { |
| 63 | + // This doesn't actually output the TypeScript files, it just |
| 64 | + // runs the TypeScript compiler and reports any errors. |
| 65 | + return tsProject.src().pipe(tsProject(goodReporter())); |
| 66 | +} |
| 67 | + |
| 68 | +export function watchCheckTypeScript() { |
| 69 | + watch("src/**/*.ts", checkTypeScript); |
| 70 | +} |
| 71 | + |
| 72 | +export function copyWasmFiles() { |
| 73 | + // We need to copy this file for the source-map package to work. Without this fie, the source-map |
| 74 | + // package is not able to load the WASM file because we are not including the full node_modules |
| 75 | + // directory. In version 0.7.4, it is not possible to call SourceMapConsumer.initialize in Node environments |
| 76 | + // to configure the path to the WASM file. So, source-map will always load the file from `__dirname/mappings.wasm`. |
| 77 | + // In version 0.8.0, it may be possible to do this properly by calling SourceMapConsumer.initialize by |
| 78 | + // using the "browser" field in source-map's package.json to load the WASM file from a given file path. |
| 79 | + return src("node_modules/source-map/lib/mappings.wasm").pipe(dest("out")); |
54 | 80 | } |
0 commit comments