Skip to content

Commit

Permalink
Merge pull request #283 from afonsonf/add-build-using-esbuild
Browse files Browse the repository at this point in the history
Introduce bundling with esbuild
  • Loading branch information
afonsonf committed Apr 24, 2023
2 parents e3c7abd + 87baf31 commit 6eebff8
Show file tree
Hide file tree
Showing 13 changed files with 620 additions and 528 deletions.
5 changes: 5 additions & 0 deletions .devcontainer/devcontainer.json
Original file line number Diff line number Diff line change
@@ -1,5 +1,10 @@
{
"name": "TLA+ VSCode",
"customizations": {
"vscode": {
"extensions": ["connor4312.esbuild-problem-matchers"]
}
},
"build": { "dockerfile": "Dockerfile" },
"mounts": [
// add folder with test tla+ files, e.g. {"source": "path/to/folder", "target": "/workspaces/folder", "type": "bind"}
Expand Down
2 changes: 1 addition & 1 deletion .vscode/launch.json
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@
"--extensionTestsPath=${workspaceFolder}/out/tests/suite/index"
],
"outFiles": ["${workspaceFolder}/out/tests/**/*.js"],
"preLaunchTask": "npm: watch"
"preLaunchTask": "npm: pretest"
},
{
"name": "Run TLA Plus Grammar Tests",
Expand Down
2 changes: 1 addition & 1 deletion .vscode/tasks.json
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
{
"type": "npm",
"script": "watch",
"problemMatcher": "$tsc-watch",
"problemMatcher": "$esbuild-watch",
"isBackground": true,
"presentation": {
"reveal": "never"
Expand Down
34 changes: 23 additions & 11 deletions .vscodeignore
Original file line number Diff line number Diff line change
@@ -1,15 +1,27 @@
src/**/*
.devcontainer/
.github/
.vscode/
.vscode-test/
# include languages/
node_modules/
out/src/
out/tests/
tests/
scripts/
**/*.map
**/tsconfig.json
**/tslint.json
**/*.code-workspace
out/main.js.map
# include out/main.js
resources/images/screencast.gif
version
# include resources/
src/
tests/
# include tools/
.eslintignore
.eslintrc.json
.gitignore
.sonarcloud.properties
.travis.yml
.github/**/*
.vscode/**/*
# include CHANGELOG.md
CONTRIBUTING.md
esbuild.js
# include LICENSE.md
# include package-lock.json package.json
# include README.md
tsconfig.json
version
5 changes: 4 additions & 1 deletion CONTRIBUTING.md
Original file line number Diff line number Diff line change
Expand Up @@ -91,8 +91,11 @@ xvfb-run --auto-servernum npm test --silent
To package the extension and create the .vsix file:

```
npm install -g vsce
npm install -g @vscode/vsce
vsce package
# View files packaged in the vsix
unzip -l *.vsix
```

# Overview
Expand Down
68 changes: 68 additions & 0 deletions esbuild.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,68 @@
/* eslint-disable @typescript-eslint/no-var-requires */
/* eslint-disable no-undef */
const { build } = require('esbuild');

//@ts-check
/** @typedef {import('esbuild').BuildOptions} BuildOptions **/

const args = process.argv.slice(2);

/** @type BuildOptions */
const baseConfig = {
bundle: true,
minify: args.includes('--production'),
sourcemap: !args.includes('--production'),
};

// Config for extension source code (to be run in a Node-based context)
/** @type BuildOptions */
const extensionConfig = {
...baseConfig,
platform: 'node',
format: 'cjs',
entryPoints: ['./src/main.ts'],
outfile: './out/main.js',
external: ['vscode'],
};

// This watch config adheres to the conventions of the esbuild-problem-matchers
// extension (https://github.com/connor4312/esbuild-problem-matchers#esbuild-via-js)
/** @type BuildOptions */
const watchConfig = {
watch: {
onRebuild(error) {
console.log('[watch] build started');
if (error) {
error.errors.forEach((error) =>
console.error(
`> ${error.location.file}:${error.location.line}:${error.location.column}: error: ${error.text}`
)
);
} else {
console.log('[watch] build finished');
}
},
},
};

// Build script
(async () => {
try {
if (args.includes('--watch')) {
// Build and watch extension
console.log('[watch] build started');
await build({
...extensionConfig,
...watchConfig,
});
console.log('[watch] build finished');
} else {
// Build extension
await build(extensionConfig);
console.log('build complete');
}
} catch (err) {
process.stderr.write(err.stderr);
process.exit(1);
}
})();
Loading

0 comments on commit 6eebff8

Please sign in to comment.