Skip to content

Commit

Permalink
Build system updates (#80)
Browse files Browse the repository at this point in the history
  • Loading branch information
wch authored Nov 25, 2024
1 parent 779f862 commit 7d008b2
Show file tree
Hide file tree
Showing 24 changed files with 4,106 additions and 1,676 deletions.
24 changes: 0 additions & 24 deletions .eslintrc.json

This file was deleted.

10 changes: 5 additions & 5 deletions .github/workflows/publish.yml
Original file line number Diff line number Diff line change
Expand Up @@ -18,13 +18,13 @@ jobs:
with:
node-version: "18.x"

- run: yarn install --immutable --immutable-cache --check-cache
- run: npm ci

- name: Lint Extension
run: yarn lint
run: npm run lint

- name: Build Extension
run: yarn vsix
run: npm run vsix

- name: Upload extension to Actions Artifact
uses: actions/upload-artifact@v4
Expand All @@ -46,7 +46,7 @@ jobs:
with:
node-version: "18.x"

- run: yarn install --immutable --immutable-cache --check-cache
- run: npm ci

- name: Publish to Open VSX Registry
uses: HaaLeo/publish-vscode-extension@v1
Expand All @@ -68,7 +68,7 @@ jobs:
with:
node-version: "18.x"

- run: yarn install --immutable --immutable-cache --check-cache
- run: npm ci

- name: Publish to Visual Studio Marketplace
uses: HaaLeo/publish-vscode-extension@v1
Expand Down
4 changes: 3 additions & 1 deletion .prettierrc
Original file line number Diff line number Diff line change
Expand Up @@ -2,5 +2,7 @@
"jsxSingleQuote": true,
"semi": true,
"singleQuote": false,
"trailingComma": "es5"
"trailingComma": "es5",
"plugins": ["prettier-plugin-organize-imports"],
"organizeImportsSkipDestructiveCodeActions": true
}
8 changes: 3 additions & 5 deletions .vscode/extensions.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,5 @@
{
// See http://go.microsoft.com/fwlink/?LinkId=827846
// for the documentation about the extensions.json format
"recommendations": [
"dbaeumer.vscode-eslint"
]
// See http://go.microsoft.com/fwlink/?LinkId=827846
// for the documentation about the extensions.json format
"recommendations": ["dbaeumer.vscode-eslint", "esbenp.prettier-vscode"]
}
50 changes: 40 additions & 10 deletions .vscode/settings.json
Original file line number Diff line number Diff line change
@@ -1,12 +1,42 @@
// Place your settings in this file to overwrite default and user settings.
{
"files.exclude": {
"out": false // set this to true to hide the "out" folder with the compiled JS files
},
"search.exclude": {
"out": true // set this to false to include "out" folder in search results
},
// Turn off tsc task auto detection since we have the necessary tasks as npm scripts
"typescript.tsc.autoDetect": "off",
"editor.formatOnSave": true
}
"files.exclude": {
"out": false // set this to true to hide the "out" folder with the compiled JS files
},
"search.exclude": {
"out": true // set this to false to include "out" folder in search results
},
// Turn off tsc task auto detection since we have the necessary tasks as npm scripts
"typescript.tsc.autoDetect": "off",
"editor.formatOnSave": true,
"editor.tabSize": 2,
"files.encoding": "utf8",
"files.eol": "\n",
"files.trimTrailingWhitespace": true,
"files.insertFinalNewline": true,
"[javascript]": {
"editor.formatOnSave": true,
"editor.defaultFormatter": "esbenp.prettier-vscode"
},
"[typescript]": {
"editor.formatOnSave": true,
"editor.defaultFormatter": "esbenp.prettier-vscode"
},
"[typescriptreact]": {
"editor.formatOnSave": true,
"editor.defaultFormatter": "esbenp.prettier-vscode"
},
"[json]": {
"editor.formatOnSave": true,
"editor.defaultFormatter": "esbenp.prettier-vscode"
},
"[html]": {
"editor.formatOnSave": true,
"editor.defaultFormatter": "esbenp.prettier-vscode"
},
"[css]": {
"editor.formatOnSave": true,
"editor.defaultFormatter": "esbenp.prettier-vscode"
},
"prettier.prettierPath": "./node_modules/prettier"
}
1 change: 0 additions & 1 deletion .yarnrc

This file was deleted.

2 changes: 1 addition & 1 deletion LICENSE
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
The MIT License (MIT)

Copyright (c) RStudio
Copyright (c) Posit Software, PBC

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
Expand Down
108 changes: 108 additions & 0 deletions esbuild.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,108 @@
const esbuild = require("esbuild");
const fs = require("fs");

const production = process.argv.includes("--production");
const watch = process.argv.includes("--watch");
const metafile = process.argv.includes("--metafile");

/**
* @type {import('esbuild').Plugin}
*/
const esbuildProblemMatcherPlugin = {
name: "esbuild-problem-matcher",

setup(build) {
build.onStart(() => {
console.log(build);
console.log(
`[${watch ? "watch " : ""}${new Date().toISOString()}] build ${
build.initialOptions.entryPoints
}`
);
});
build.onEnd((result) => {
result.errors.forEach(({ text, location }) => {
console.error(`✘ [ERROR] ${text}`);
console.error(
` ${location.file}:${location.line}:${location.column}:`
);
});

// Log output files
if (result.metafile) {
Object.keys(result.metafile.outputs).forEach((output) => {
console.log(`built: ${output}`);
});
}
});
},
};

const metafilePlugin = {
name: "metafile",
setup(build) {
// const outfile = build.initialOptions.outfile;
// const entryPoints = build.initialOptions.entryPoints;

build.onEnd((result) => {
if (result.metafile) {
// For each output in the metafile
Object.entries(result.metafile.outputs).forEach(
([outputPath, output]) => {
// Get the entry point for this output
const entryPoint = output.entryPoint;
if (entryPoint) {
// Extract filename without extension
const bundleName = entryPoint
.replace(/^.*[\\/]/, "")
.replace(/\.[^/.]+$/, "");
console.log(`meta.${bundleName}.json`);

fs.writeFileSync(
`${bundleName}.esbuild-meta.json`,
JSON.stringify(result.metafile)
);
}
}
);
}
});
},
};

async function main() {
const buildmap = {
extension: esbuild.context({
entryPoints: ["src/extension.ts", "src/test/runTest.ts"],
bundle: true,
outdir: "out/",
format: "cjs",
minify: production,
sourcemap: !production,
sourcesContent: false,
platform: "node",
external: ["vscode"],
logLevel: "silent",
metafile: metafile,
plugins: [metafilePlugin, esbuildProblemMatcherPlugin],
}),
};

Object.values(buildmap).forEach((build) =>
build
.then(async (context) => {
if (watch) {
await context.watch();
} else {
await context.rebuild();
await context.dispose();
}
})
.catch(() => process.exit(1))
);
}

main().catch((e) => {
console.error(e);
process.exit(1);
});
56 changes: 56 additions & 0 deletions eslint.config.mjs
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
import eslint from "@eslint/js";
import tsParser from "@typescript-eslint/parser";
import globals from "globals";
import tseslint from "typescript-eslint";

const commonRules = {
"@typescript-eslint/naming-convention": "warn",
curly: ["warn", "multi-line"],
eqeqeq: "warn",
"no-throw-literal": "warn",
semi: "warn",
"@typescript-eslint/no-unused-vars": "off",
"@typescript-eslint/consistent-type-imports": "warn",
"@typescript-eslint/no-floating-promises": "error",
};

const commonTsConfig = {
parser: tsParser,
ecmaVersion: 2022,
sourceType: "module",
parserOptions: {
ecmaVersion: 2022,
sourceType: "module",
project: "./tsconfig.json",
ecmaFeatures: {
jsx: true,
},
},
};

export default tseslint.config(
eslint.configs.recommended,
...tseslint.configs.recommended,
{
ignores: ["out", "**/*.d.ts"],
},
{
// Build scripts config - these are run by nodejs, and use commonjs syntax.
files: ["esbuild.js", "**/tailwind.config.js"],
languageOptions: {
globals: globals.node,
},
rules: {
"@typescript-eslint/no-require-imports": "off",
},
},
{
// Node.js TypeScript files (src/)
files: ["src/**/*.ts"],
languageOptions: {
...commonTsConfig,
globals: globals.node,
},
rules: commonRules,
}
);
Loading

0 comments on commit 7d008b2

Please sign in to comment.