Skip to content

Commit

Permalink
Migrate to TypeScript (#12)
Browse files Browse the repository at this point in the history
  • Loading branch information
furudean authored Jul 6, 2024
1 parent caa1a24 commit f0dccaa
Show file tree
Hide file tree
Showing 19 changed files with 2,858 additions and 613 deletions.
8 changes: 6 additions & 2 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
node_modules
.vscode-test/
out/**
dist/
node_modules/**
.gitignore
*.vsix
.vscode-test/
.DS_Store
6 changes: 3 additions & 3 deletions .vscode-test.mjs
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { defineConfig } from '@vscode/test-cli';
import { defineConfig } from '@vscode/test-cli'

export default defineConfig({
files: 'test/**/*.test.js',
});
files: 'out/test/**/*.test.js',
})
5 changes: 3 additions & 2 deletions .vscode/extensions.json
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
{
// See https://go.microsoft.com/fwlink/?LinkId=733558
// See http://go.microsoft.com/fwlink/?LinkId=827846
// for the documentation about the extensions.json format
"recommendations": [
"dbaeumer.vscode-eslint",
"ms-vscode.extension-test-runner"
"connor4312.esbuild-problem-matchers",
"ms-vscode.extension-test-runner"
]
}
6 changes: 4 additions & 2 deletions .vscode/launch.json
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// A launch configuration that launches the extension inside a new window
// 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
Expand All @@ -9,7 +9,9 @@
"name": "Run Extension",
"type": "extensionHost",
"request": "launch",
"args": ["--extensionDevelopmentPath=${workspaceFolder}"]
"args": ["--extensionDevelopmentPath=${workspaceFolder}"],
"outFiles": ["${workspaceFolder}/dist/**/*.js"],
"preLaunchTask": "${defaultBuildTask}"
}
]
}
14 changes: 10 additions & 4 deletions .vscode/settings.json
Original file line number Diff line number Diff line change
@@ -1,10 +1,16 @@
{
"editor.formatOnSave": true,
"editor.defaultFormatter": "esbenp.prettier-vscode",
// Turn off tsc task auto detection since we have the necessary tasks as npm scripts
"typescript.tsc.autoDetect": "off",
"files.exclude": {
"**/*.rpyc": true,
"**/*.rpa": true,
"**/*.rpymc": true,
"**/cache/": true
"out": true,
"dist": false,
".vscode-test": true
},
"search.exclude": {
"out": true,
"dist": true,
".vscode-test": true
}
}
58 changes: 58 additions & 0 deletions .vscode/tasks.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
// See https://go.microsoft.com/fwlink/?LinkId=733558
// for the documentation about the tasks.json format
{
"version": "2.0.0",
"tasks": [
{
"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,
"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": []
}
]
}
7 changes: 6 additions & 1 deletion .vscodeignore
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,13 @@
test/**
.gitignore
.yarnrc
vsc-extension-quickstart.md
**/jsconfig.json
**/*.map
**/.eslintrc.json
**/.vscode-test.*
**/*.ts
out/**
src/**
.github/**
tsconfig.json
esbuild.js
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ All notable changes to this project will be documented in this file.
## Unreleased

- Don't link to specific settings (it doesn't work very well)
- Migrate source code to TypeScript

## 1.2.0 - 2024-07-06

Expand Down
63 changes: 63 additions & 0 deletions esbuild.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,63 @@
const { context } = require('esbuild')
const { copy } = require('esbuild-plugin-copy')

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 context({
entryPoints: ['src/extension.ts'],
bundle: true,
format: 'cjs',
minify: production,
sourcemap: !production,
sourcesContent: false,
platform: 'node',
outfile: 'dist/extension.js',
external: ['vscode', 'node-window-manager', 'extract-file-icon'],
logLevel: 'silent',
plugins: [
/* add to the end of plugins array */
esbuildProblemMatcherPlugin,
copy({
resolveFrom: 'cwd',
assets: {
from: ['./src/**/*.py'],
to: ['./dist/'],
},
watch: true,
}),
],
})
if (watch) {
await ctx.watch()
} else {
await ctx.rebuild()
await ctx.dispose()
}
}

main().catch((e) => {
console.error(e)
process.exit(1)
})
59 changes: 32 additions & 27 deletions eslint.config.mjs
Original file line number Diff line number Diff line change
@@ -1,31 +1,36 @@
import globals from "globals";
import globals from 'globals'

export default [{
languageOptions: {
globals: {
...Object.fromEntries(Object.entries(globals.browser).map(([key]) => [key, "off"])),
...globals.commonjs,
...globals.node,
...globals.mocha,
},
export default [
{
languageOptions: {
globals: {
...Object.fromEntries(
Object.entries(globals.browser).map(([key]) => [key, 'off'])
),
...globals.commonjs,
...globals.node,
...globals.mocha,
},

ecmaVersion: 2018,
sourceType: "module",
ecmaVersion: 2018,
sourceType: 'module',

parserOptions: {
ecmaFeatures: {
jsx: true,
},
},
},
parserOptions: {
ecmaFeatures: {
jsx: true,
},
},
},

rules: {
"no-const-assign": "warn",
"no-this-before-super": "warn",
"no-undef": "warn",
"no-unreachable": "warn",
"no-unused-vars": "warn",
"constructor-super": "warn",
"valid-typeof": "warn",
},
}];
rules: {
'no-const-assign': 'warn',
'no-this-before-super': 'warn',
'no-undef': 'warn',
'no-unreachable': 'warn',
'no-unused-vars': 'warn',
'constructor-super': 'warn',
'valid-typeof': 'warn',
},
ignores: ['out', 'dist', '**/*.d.ts', '.vscode-test/'],
},
]
9 changes: 0 additions & 9 deletions jsconfig.json

This file was deleted.

Loading

0 comments on commit f0dccaa

Please sign in to comment.