Skip to content

Commit 2bfdeec

Browse files
committed
Use esbuild over webpack
1 parent 8533bdd commit 2bfdeec

File tree

15 files changed

+967
-716
lines changed

15 files changed

+967
-716
lines changed

.eslintrc.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -58,8 +58,8 @@ module.exports = {
5858
"out/",
5959
"dist/",
6060
"wallaby.js",
61-
"webpack.config.js",
6261
".eslintrc.js",
62+
"esbuild.js",
6363
"**/*.d.ts"
6464
],
6565
};

.vscode/launch.json

+7-7
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99
"args": ["--extensionDevelopmentPath=${workspaceRoot}"],
1010
"sourceMaps": true,
1111
"outFiles": ["${workspaceRoot}/dist/*.js"],
12-
"preLaunchTask": "buildDev"
12+
"preLaunchTask": "packageDev"
1313
},
1414
{
1515
"name": "[Roslyn] Run Current File Integration Tests",
@@ -35,7 +35,7 @@
3535
"sourceMaps": true,
3636
"outFiles": ["${workspaceRoot}/dist/*.js", "${workspaceRoot}/out/test/**/*.js"],
3737
"resolveSourceMapLocations": ["${workspaceFolder}/**", "!**/node_modules/**"],
38-
"preLaunchTask": "buildDev",
38+
"preLaunchTask": "packageDev",
3939
"internalConsoleOptions": "openOnSessionStart"
4040
},
4141
{
@@ -62,7 +62,7 @@
6262
"sourceMaps": true,
6363
"outFiles": ["${workspaceRoot}/dist/*.js", "${workspaceRoot}/out/test/**/*.js"],
6464
"resolveSourceMapLocations": ["${workspaceFolder}/**", "!**/node_modules/**"],
65-
"preLaunchTask": "buildDev",
65+
"preLaunchTask": "packageDev",
6666
"internalConsoleOptions": "openOnSessionStart"
6767
},
6868
{
@@ -89,7 +89,7 @@
8989
"sourceMaps": true,
9090
"outFiles": ["${workspaceRoot}/dist/*.js", "${workspaceRoot}/out/test/**/*.js"],
9191
"resolveSourceMapLocations": ["${workspaceFolder}/**", "!**/node_modules/**"],
92-
"preLaunchTask": "buildTest",
92+
"preLaunchTask": "packageDev",
9393
"internalConsoleOptions": "openOnSessionStart"
9494
},
9595
{
@@ -115,7 +115,7 @@
115115
"sourceMaps": true,
116116
"outFiles": ["${workspaceRoot}/dist/*.js", "${workspaceRoot}/out/test/**/*.js"],
117117
"resolveSourceMapLocations": ["${workspaceFolder}/**", "!**/node_modules/**"],
118-
"preLaunchTask": "buildTest"
118+
"preLaunchTask": "packageDev"
119119
},
120120
{
121121
"name": "[O# LSP] Run Current File Integration Tests",
@@ -140,7 +140,7 @@
140140
"sourceMaps": true,
141141
"outFiles": ["${workspaceRoot}/dist/*.js", "${workspaceRoot}/out/test/**/*.js"],
142142
"resolveSourceMapLocations": ["${workspaceFolder}/**", "!**/node_modules/**"],
143-
"preLaunchTask": "buildTest"
143+
"preLaunchTask": "packageDev"
144144
},
145145
{
146146
"type": "node",
@@ -195,7 +195,7 @@
195195
"name": "Razor integration tests",
196196
"preLaunchTask": "build",
197197
"program": "${workspaceFolder}/node_modules/gulp/bin/gulp.js",
198-
"args": ["test:razorintegration"],
198+
"args": ["test:integration:razor"],
199199
"cwd": "${workspaceFolder}"
200200
}
201201
],

.vscode/tasks.json

+12-2
Original file line numberDiff line numberDiff line change
@@ -28,10 +28,20 @@
2828
}
2929
},
3030
{
31-
"label": "buildTest",
31+
"label": "package",
3232
"command": "npm",
3333
"type": "shell",
34-
"args": ["run", "compileTest"],
34+
"args": ["run", "package"],
35+
"group": {
36+
"kind": "build",
37+
"isDefault": true
38+
}
39+
},
40+
{
41+
"label": "packageDev",
42+
"command": "npm",
43+
"type": "shell",
44+
"args": ["run", "packageDev"],
3545
"group": {
3646
"kind": "build",
3747
"isDefault": true

.vscodeignore

+1-2
Original file line numberDiff line numberDiff line change
@@ -52,8 +52,7 @@ package.json
5252
tsconfig.json
5353
version.json
5454
wallaby.js
55-
webpack.config.js
56-
55+
esbuild.js
5756
!src/razor/language-configuration.json
5857
!src/razor/syntaxes/*
5958

CONTRIBUTING.md

+3-1
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,7 @@ Follow these steps to build, run, and test the repository:
3636
#### Building
3737

3838
1. Run `npm install -g vsts-npm-auth`, then run `vsts-npm-auth -config .npmrc` - This command will configure your credentials for the next command.
39+
a. If you have already authenticated before, but the token expired, you may need to run `vsts-npm-auth -config .npmrc -f` instead.
3940
2. Run `npm i` - This command installs the project dependencies.
4041
3. Run `npm i -g gulp` - This command installs Gulp globally.
4142
4. Run `gulp installDependencies` - This command downloads the various dependencies as specified by the version in the [package.json](package.json) file.
@@ -51,7 +52,8 @@ After completing the build steps:
5152

5253
#### Testing
5354

54-
To run all tests, execute `npm run test`.
55+
To run all unit tests, execute `npm run test:unit`.
56+
To run all integration tests execute `npm run test:integration`
5557

5658
To debug unit tests locally, press <kbd>F5</kbd> in VS Code with the "Launch Tests" debug configuration selected.
5759

azure-pipelines/prereqs.yml

-3
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,3 @@ steps:
4040
npm ci
4141
npm i -g gulp
4242
displayName: 'Install dependencies'
43-
44-
- script: npm run compile
45-
displayName: 'Compile'

azure-pipelines/test-matrix.yml

+6-2
Original file line numberDiff line numberDiff line change
@@ -16,10 +16,14 @@ jobs:
1616
- job:
1717
strategy:
1818
matrix:
19-
CSharpTests:
20-
npmCommand: test:withoutDevKit
19+
UnitTests:
20+
npmCommand: test:unit
21+
CSharpIntegrationTests:
22+
npmCommand: test:integration:csharp
2123
DevKitTests:
2224
npmCommand: test:integration:devkit
25+
RazorTests:
26+
npmCommand: test:integration:razor
2327
pool: ${{ parameters.pool }}
2428
${{ if parameters.containerName }}:
2529
container: ${{ parameters.containerName }}

azure-pipelines/test-prereqs.yml

-3
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,5 @@
11
steps:
22

3-
- script: npm run vscode:prepublish
4-
displayName: 'Prepublish VSIXs'
5-
63
# We need to download the roslyn language server for the current platform to run integration tests against it.
74
- script: gulp installDependencies
85
displayName: 'Install Roslyn Language Server'

esbuild.js

+76
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,76 @@
1+
const esbuild = require("esbuild");
2+
const fs = require('fs/promises');
3+
4+
const production = process.argv.includes('--production');
5+
const watch = process.argv.includes('--watch');
6+
7+
/**
8+
* @type {import('esbuild').Plugin}
9+
*/
10+
const esbuildProblemMatcherPlugin = {
11+
name: 'esbuild-problem-matcher',
12+
13+
setup(build) {
14+
build.onStart(() => {
15+
console.log('[watch] build started');
16+
});
17+
build.onEnd((result) => {
18+
result.errors.forEach(({ text, location }) => {
19+
console.error(`✘ [ERROR] ${text}`);
20+
console.error(` ${location.file}:${location.line}:${location.column}:`);
21+
});
22+
console.log('[watch] build finished');
23+
});
24+
},
25+
};
26+
27+
/**
28+
* Some VSCode libraries include UMD versions that are not esbuild compatible, and also have broken ESM packages.
29+
* This plugin replaces the UMD imports with the ESM imports.
30+
* See https://github.com/microsoft/vscode/issues/192144
31+
*/
32+
const umdEsmLoaderPlugin = {
33+
name: 'umdEsmLoaderPlugin',
34+
35+
setup(build) {
36+
build.onLoad({ filter: /(vscode-html-languageservice|jsonc-parser).*lib[\/\\]umd/ }, async (moduleArgs) => {
37+
// replace the umd path with the esm path from the package.
38+
const newPath = moduleArgs.path.replace(/(.*)lib([\/\\])umd(.*)/, '$1lib$2esm$3');
39+
const contents = await fs.readFile(newPath, 'utf8');
40+
return { contents: contents };
41+
});
42+
},
43+
};
44+
45+
async function main() {
46+
const ctx = await esbuild.context({
47+
entryPoints: [
48+
'src/main.ts'
49+
],
50+
bundle: true,
51+
format: 'cjs',
52+
minify: production,
53+
sourcemap: !production,
54+
sourcesContent: false,
55+
platform: 'node',
56+
outfile: 'dist/extension.js',
57+
external: ['vscode', 'applicationinsights-native-metrics', '@opentelemetry/tracing'],
58+
logLevel: 'info',
59+
plugins: [
60+
umdEsmLoaderPlugin,
61+
/* add to the end of plugins array */
62+
esbuildProblemMatcherPlugin,
63+
],
64+
});
65+
if (watch) {
66+
await ctx.watch();
67+
} else {
68+
await ctx.rebuild();
69+
await ctx.dispose();
70+
}
71+
}
72+
73+
main().catch(e => {
74+
console.error(e);
75+
process.exit(1);
76+
});

0 commit comments

Comments
 (0)