Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

chore: refactor build and test env #72

Merged
merged 5 commits into from
Nov 12, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions .cssrem
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,8 @@
"fixedDigits": 3,
"vw": true,
"ignores": [
"**/*.less",
"*.tsx"
// "**/*.less",
// "*.tsx"
],
"ignoresViaCommand": []
}
58 changes: 58 additions & 0 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
name: CI

on:
pull_request:
push:
branches: [main, master]

jobs:
package:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- uses: actions/setup-node@v4
with:
node-version-file: ".nvmrc"
cache: "yarn"
- uses: actions/cache@v3
with:
path: ./node_modules
key: ${{ runner.os }}-${{ hashFiles('**/yarn.lock', '**/*.patch') }}
- name: Install node modules
run: yarn install --frozen-lockfile
- run: npm run package

test:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- uses: actions/setup-node@v4
with:
node-version-file: ".nvmrc"
cache: "yarn"
- uses: actions/cache@v3
with:
path: ./node_modules
key: ${{ runner.os }}-${{ hashFiles('**/yarn.lock', '**/*.patch') }}
- name: Install node modules
run: yarn install --frozen-lockfile
- run: xvfb-run -a npm test
if: runner.os == 'Linux'
- run: npm test
if: runner.os != 'Linux'

lint:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- uses: actions/setup-node@v4
with:
node-version-file: ".nvmrc"
cache: "yarn"
- uses: actions/cache@v3
with:
path: ./node_modules
key: ${{ runner.os }}-${{ hashFiles('**/yarn.lock', '**/*.patch') }}
- name: Install node modules
run: yarn install --frozen-lockfile
- run: npm run lint
5 changes: 4 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
node_modules

*.vsix
yarn.lock
# yarn.lock

# Yarn
# yarn.lock
Expand All @@ -14,3 +14,6 @@ yarn-error.log
!.yarn/sdks
!.yarn/versions
.pnp.*

.vscode/**
.vscode-test/**
1 change: 1 addition & 0 deletions .nvmrc
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
18.19.1
23 changes: 0 additions & 23 deletions .prettierrc

This file was deleted.

5 changes: 5 additions & 0 deletions .vscode-test.mjs
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
import { defineConfig } from '@vscode/test-cli';

export default defineConfig({
files: 'out/test/**/*.test.js',
});
21 changes: 13 additions & 8 deletions .vscode/launch.json
Original file line number Diff line number Diff line change
@@ -1,16 +1,21 @@
// A launch configuration that compiles the extension and then opens it inside a new window
// Use IntelliSense to learn about possible attributes.
// Hover to view descriptions of existing attributes.
// For more information, visit: https://go.microsoft.com/fwlink/?linkid=830387
{
"version": "0.2.0",
"configurations": [
{
"name": "Launch Extension",
"name": "Run Extension",
"type": "extensionHost",
"request": "launch",
"runtimeExecutable": "${execPath}",
"args": ["--extensionDevelopmentPath=${workspaceRoot}"],
"stopOnEntry": false,
"sourceMaps": true,
"preLaunchTask": "npm",
"outFiles": ["${workspaceRoot}/out/**/*.js"]
"args": [
"--extensionDevelopmentPath=${workspaceFolder}"
],
"outFiles": [
"${workspaceFolder}/dist/**/*.js"
],
"preLaunchTask": "${defaultBuildTask}"
}
]
}
}
12 changes: 11 additions & 1 deletion .vscode/settings.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,18 @@
"files.associations": {
".cssrem": "jsonc"
},
"files.exclude": {
"out": false, // set this to true to hide the "out" folder with the compiled JS files
"dist": false // set this to true to hide the "dist" folder with the compiled JS files
},
"search.exclude": {
"out": true, // set this to false to include "out" folder in search results
"dist": true // set this to false to include "dist" folder in search results
},
"editor.formatOnSave": true,
"[markdown]": {
"editor.formatOnSave": false
}
},
// Turn off tsc task auto detection since we have the necessary tasks as npm scripts
"typescript.tsc.autoDetect": "off"
}
72 changes: 58 additions & 14 deletions .vscode/tasks.json
Original file line number Diff line number Diff line change
@@ -1,20 +1,64 @@
// A task runner that calls a custom npm script that compiles the extension.
// See https://go.microsoft.com/fwlink/?LinkId=733558
// for the documentation about the tasks.json format
{
"version": "2.0.0",
"tasks": [
{
"taskName": "npm",
// we want to run npm
"command": "npm",
// the command is a shell script
"isShellCommand": true,
// show the output window only if unrecognized errors occur.
"showOutput": "silent",
// we run the custom script "compile" as defined in package.json
"args": ["run", "prod", "--loglevel", "silent"],
// The tsc compiler is started in watching mode
"label": "watch",
"dependsOn": [
"npm: watch:tsc",
"npm: watch:esbuild"
],
"presentation": {
"reveal": "never"
},
"group": {
"kind": "build",
"isDefault": true
}
},
{
"type": "npm",
"script": "watch:esbuild",
"group": "build",
"problemMatcher": "$esbuild-watch",
"isBackground": true,
"label": "npm: watch:esbuild",
"presentation": {
"group": "watch",
"reveal": "never"
}
},
{
"type": "npm",
"script": "watch:tsc",
"group": "build",
"problemMatcher": "$tsc-watch",
"isBackground": true,
// use the standard tsc in watch mode problem matcher to find compile problems in the output.
"problemMatcher": "$tsc-watch"
"label": "npm: watch:tsc",
"presentation": {
"group": "watch",
"reveal": "never"
}
},
{
"type": "npm",
"script": "watch-tests",
"problemMatcher": "$tsc-watch",
"isBackground": true,
"presentation": {
"reveal": "never",
"group": "watchers"
},
"group": "build"
},
{
"label": "tasks: watch-tests",
"dependsOn": [
"npm: watch",
"npm: watch-tests"
],
"problemMatcher": []
}
]
}
}
17 changes: 13 additions & 4 deletions .vscodeignore
Original file line number Diff line number Diff line change
@@ -1,9 +1,18 @@
.vscode/**
.vscode-test/**
out/test/**
test/**
src/**
**/*.map
.gitignore
tsconfig.json
.yarnrc
esbuild.js
vsc-extension-quickstart.md
**/tsconfig.json
**/eslint.config.mjs
**/*.map
**/*.ts
**/.vscode-test.*
.github/**
.yarn/**
examples/**
demo.gif
.cssrem
.yarnrc.yml
55 changes: 55 additions & 0 deletions esbuild.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
const esbuild = require('esbuild');

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

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

setup(build) {
build.onStart(() => {
console.log('[watch] build started');
});
build.onEnd(result => {
result.errors.forEach(({ text, location }) => {
console.error(`✘ [ERROR] ${text}`);
console.error(` ${location.file}:${location.line}:${location.column}:`);
});
console.log('[watch] build finished');
});
},
};

async function main() {
const ctx = await esbuild.context({
entryPoints: ['src/extension.ts'],
bundle: true,
format: 'cjs',
minify: production,
sourcemap: !production,
sourcesContent: false,
platform: 'node',
outfile: 'out/extension.js',
mainFields: ['module', 'main'],
external: ['vscode'],
logLevel: 'silent',
plugins: [
/* add to the end of plugins array */
esbuildProblemMatcherPlugin,
],
});
if (watch) {
await ctx.watch();
} else {
await ctx.rebuild();
await ctx.dispose();
}
}

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

export default [
{
files: ['**/*.ts'],
},
{
plugins: {
'@typescript-eslint': typescriptEslint,
},

languageOptions: {
parser: tsParser,
ecmaVersion: 2022,
sourceType: 'module',
},

rules: {
'@typescript-eslint/naming-convention': [
'warn',
{
selector: 'import',
format: ['camelCase', 'PascalCase'],
},
],

// curly: "warn",
// eqeqeq: "warn",
'no-throw-literal': 'warn',
semi: 'warn',
},
},
];
Loading
Loading