From f85fc5c17400f4f43dee9b04e71510a0aed4e8f4 Mon Sep 17 00:00:00 2001 From: Amr Bashir Date: Mon, 19 Sep 2022 15:08:43 +0200 Subject: [PATCH] feat: provide schema for config based on tauri-build version (#162) * feat: provide schema for config based on cli version * fallback to latest release * enable commented code * get schema based on tauri-build version * change url * handle schema get request error * Update versioned-schema.md * Update extension.ts --- .changes/config.json | 4 +- .changes/readme.md | 11 +- .changes/versioned-schema.md | 5 + .eslintrc.json | 32 +- ...on.yml => covector-version-or-publish.yml} | 19 +- .github/workflows/publish.yml | 6 +- .github/workflows/test.yml | 18 +- .prettierrc | 6 + .vscode/extensions.json | 8 +- .vscode/launch.json | 57 ++-- .vscode/settings.json | 20 +- .vscode/tasks.json | 32 +- package.json | 9 +- renovate.json | 4 +- snippets/markdown.json | 5 +- snippets/rust.json | 12 +- src/extension.ts | 312 +++++++++++++----- src/test/runTest.ts | 26 +- src/test/suite/extension.test.ts | 12 +- src/test/suite/index.ts | 56 ++-- tsconfig.json | 33 +- yarn.lock | 61 ++++ 22 files changed, 475 insertions(+), 273 deletions(-) create mode 100644 .changes/versioned-schema.md rename .github/workflows/{covector-version.yml => covector-version-or-publish.yml} (59%) create mode 100644 .prettierrc diff --git a/.changes/config.json b/.changes/config.json index da1c830..0aca2f1 100644 --- a/.changes/config.json +++ b/.changes/config.json @@ -3,7 +3,7 @@ "pkgManagers": { "javascript": { "version": true, - "publish": false + "publish": [] } }, "packages": { @@ -12,4 +12,4 @@ "manager": "javascript" } } -} \ No newline at end of file +} diff --git a/.changes/readme.md b/.changes/readme.md index 5c6ba52..a3502a9 100644 --- a/.changes/readme.md +++ b/.changes/readme.md @@ -1,16 +1,17 @@ # Changes + ##### via https://github.com/jbolda/covector -As you create PRs and make changes that require a version bump, please add a new markdown file in this folder. You do not note the version *number*, but rather the type of bump that you expect: major, minor, or patch. The filename is not important, as long as it is a `.md`, but we recommend it represents the overall change for our sanity. +As you create PRs and make changes that require a version bump, please add a new markdown file in this folder. You do not note the version _number_, but rather the type of bump that you expect: major, minor, or patch. The filename is not important, as long as it is a `.md`, but we recommend it represents the overall change for our sanity. -When you select the version bump required, you do *not* need to consider depedencies. Only note the package with the actual change, and any packages that depend on that package will be bumped automatically in the process. +When you select the version bump required, you do _not_ need to consider depedencies. Only note the package with the actual change, and any packages that depend on that package will be bumped automatically in the process. Use the following format: + ```md --- -"tauri-log-plugin": minor +'tauri-log-plugin': minor --- Change summary goes here - -``` \ No newline at end of file +``` diff --git a/.changes/versioned-schema.md b/.changes/versioned-schema.md new file mode 100644 index 0000000..637b2ea --- /dev/null +++ b/.changes/versioned-schema.md @@ -0,0 +1,5 @@ +--- +"tauri-vscode": "minor" +--- + +Provide schema for `tauri.conf.json` based on `tauri-build` version. diff --git a/.eslintrc.json b/.eslintrc.json index 89e3f9c..0bb58ec 100644 --- a/.eslintrc.json +++ b/.eslintrc.json @@ -1,18 +1,16 @@ { - "root": true, - "parser": "@typescript-eslint/parser", - "parserOptions": { - "ecmaVersion": 6, - "sourceType": "module" - }, - "plugins": [ - "@typescript-eslint" - ], - "rules": { - "@typescript-eslint/semi": "warn", - "curly": "warn", - "eqeqeq": "warn", - "no-throw-literal": "warn", - "semi": "off" - } -} \ No newline at end of file + "root": true, + "parser": "@typescript-eslint/parser", + "parserOptions": { + "ecmaVersion": 6, + "sourceType": "module" + }, + "plugins": ["@typescript-eslint"], + "rules": { + "@typescript-eslint/semi": "warn", + "curly": "warn", + "eqeqeq": "warn", + "no-throw-literal": "warn", + "semi": "off" + } +} diff --git a/.github/workflows/covector-version.yml b/.github/workflows/covector-version-or-publish.yml similarity index 59% rename from .github/workflows/covector-version.yml rename to .github/workflows/covector-version-or-publish.yml index f3a2a5d..fa8477d 100644 --- a/.github/workflows/covector-version.yml +++ b/.github/workflows/covector-version-or-publish.yml @@ -22,13 +22,26 @@ jobs: id: covector with: token: ${{ secrets.GITHUB_TOKEN }} - command: 'version' + command: 'version-or-publish' + createRelease: false + - name: Create Pull Request With Versions Bumped + if: steps.covector.outputs.commandRan == 'version' uses: tauri-apps/create-pull-request@v3.4.1 with: token: ${{ secrets.GITHUB_TOKEN }} branch: covector/version-updates title: Apply Version Updates From Current Changes - commit-message: "apply version updates" - labels: "version updates" + commit-message: 'apply version updates' + labels: 'version updates' body: ${{ steps.covector.outputs.change }} + + - name: Trigger publish.yml workflow + if: | + steps.covector.outputs.successfulPublish == 'true' && + contains(steps.covector.outputs.packagesPublished, 'tauri-vscode') + uses: peter-evans/repository-dispatch@v2 + with: + token: ${{ secrets.TAURI_BOT_PAT }} + repo: tauri-apps/tauri-vscode + event-type: publish diff --git a/.github/workflows/publish.yml b/.github/workflows/publish.yml index f4e0e5f..7bf0f5f 100644 --- a/.github/workflows/publish.yml +++ b/.github/workflows/publish.yml @@ -1,7 +1,7 @@ on: - push: - branches: - - release + workflow_dispatch: + repository_dispatch: + types: [publish] name: Publish Extension diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml index c52f4f2..d6605bd 100644 --- a/.github/workflows/test.yml +++ b/.github/workflows/test.yml @@ -10,12 +10,12 @@ jobs: runs-on: ${{ matrix.platform }} steps: - - uses: actions/checkout@v2 - - name: setup node - uses: actions/setup-node@v1 - with: - node-version: 14 - - name: install dependencies - run: yarn - - name: compile extension - run: yarn compile + - uses: actions/checkout@v2 + - name: setup node + uses: actions/setup-node@v1 + with: + node-version: 14 + - name: install dependencies + run: yarn + - name: compile extension + run: yarn compile diff --git a/.prettierrc b/.prettierrc new file mode 100644 index 0000000..0a72520 --- /dev/null +++ b/.prettierrc @@ -0,0 +1,6 @@ +{ + "trailingComma": "es5", + "tabWidth": 2, + "semi": true, + "singleQuote": true +} diff --git a/.vscode/extensions.json b/.vscode/extensions.json index 3ac9aeb..c0a2258 100644 --- a/.vscode/extensions.json +++ b/.vscode/extensions.json @@ -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"] } diff --git a/.vscode/launch.json b/.vscode/launch.json index b1fbaf5..48c9817 100644 --- a/.vscode/launch.json +++ b/.vscode/launch.json @@ -3,34 +3,31 @@ // Hover to view descriptions of existing attributes. // For more information, visit: https://go.microsoft.com/fwlink/?linkid=830387 { - "version": "0.2.0", - "configurations": [ - { - "name": "Run Extension", - "type": "extensionHost", - "request": "launch", - "runtimeExecutable": "${execPath}", - "args": [ - "--extensionDevelopmentPath=${workspaceFolder}" - ], - "outFiles": [ - "${workspaceFolder}/out/**/*.js" - ], - "preLaunchTask": "${defaultBuildTask}" - }, - { - "name": "Extension Tests", - "type": "extensionHost", - "request": "launch", - "runtimeExecutable": "${execPath}", - "args": [ - "--extensionDevelopmentPath=${workspaceFolder}", - "--extensionTestsPath=${workspaceFolder}/out/test/suite/index" - ], - "outFiles": [ - "${workspaceFolder}/out/test/**/*.js" - ], - "preLaunchTask": "${defaultBuildTask}" - } - ] + "version": "0.2.0", + "configurations": [ + { + "name": "Run Extension", + "type": "extensionHost", + "request": "launch", + "runtimeExecutable": "${execPath}", + "args": [ + "--extensionDevelopmentPath=${workspaceFolder}", + "--disable-extensions" + ], + "outFiles": ["${workspaceFolder}/out/**/*.js"], + "preLaunchTask": "${defaultBuildTask}" + }, + { + "name": "Extension Tests", + "type": "extensionHost", + "request": "launch", + "runtimeExecutable": "${execPath}", + "args": [ + "--extensionDevelopmentPath=${workspaceFolder}", + "--extensionTestsPath=${workspaceFolder}/out/test/suite/index" + ], + "outFiles": ["${workspaceFolder}/out/test/**/*.js"], + "preLaunchTask": "${defaultBuildTask}" + } + ] } diff --git a/.vscode/settings.json b/.vscode/settings.json index a8f83b8..7b580c6 100644 --- a/.vscode/settings.json +++ b/.vscode/settings.json @@ -1,12 +1,12 @@ // 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", - "npm.runInTerminal": false -} \ No newline at end of file + "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", + "npm.runInTerminal": false +} diff --git a/.vscode/tasks.json b/.vscode/tasks.json index 3b17e53..078ff7e 100644 --- a/.vscode/tasks.json +++ b/.vscode/tasks.json @@ -1,20 +1,20 @@ // See https://go.microsoft.com/fwlink/?LinkId=733558 // for the documentation about the tasks.json format { - "version": "2.0.0", - "tasks": [ - { - "type": "npm", - "script": "watch", - "problemMatcher": "$tsc-watch", - "isBackground": true, - "presentation": { - "reveal": "never" - }, - "group": { - "kind": "build", - "isDefault": true - } - } - ] + "version": "2.0.0", + "tasks": [ + { + "type": "npm", + "script": "watch", + "problemMatcher": "$tsc-watch", + "isBackground": true, + "presentation": { + "reveal": "never" + }, + "group": { + "kind": "build", + "isDefault": true + } + } + ] } diff --git a/package.json b/package.json index 1a618a8..0fc06e2 100644 --- a/package.json +++ b/package.json @@ -33,7 +33,8 @@ "onCommand:tauri.deps-update", "onCommand:tauri.dev", "onCommand:tauri.build", - "onCommand:tauri.build-debug" + "onCommand:tauri.build-debug", + "onFileSystem:tauri" ], "main": "./out/extension.js", "contributes": { @@ -45,7 +46,7 @@ "tauri.*.conf.json", "tauri.*.conf.json5" ], - "url": "https://raw.githubusercontent.com/tauri-apps/tauri/dev/tooling/cli/schema.json" + "url": "tauri://schemas/config.json" } ], "commands": [ @@ -95,6 +96,7 @@ "vscode:prepublish": "yarn run compile", "compile": "tsc -p ./", "lint": "eslint src --ext ts", + "format": "prettier ./**/*.{json,ts,js} -w --ignore-path .gitignore", "watch": "tsc -watch -p ./", "pretest": "yarn run compile && yarn run lint", "test": "node ./out/test/runTest.js" @@ -109,9 +111,12 @@ "@vscode/test-electron": "2.1.5", "eslint": "8.23.1", "mocha": "10.0.0", + "prettier": "^2.7.1", "typescript": "4.8.3" }, "dependencies": { + "@types/semver": "^7.3.12", + "axios": "^0.27.2", "glob": "8.0.3", "run-in-terminal": "^0.0.3" }, diff --git a/renovate.json b/renovate.json index f45d8f1..4f39080 100644 --- a/renovate.json +++ b/renovate.json @@ -1,5 +1,3 @@ { - "extends": [ - "config:base" - ] + "extends": ["config:base"] } diff --git a/snippets/markdown.json b/snippets/markdown.json index d047add..c17c670 100644 --- a/snippets/markdown.json +++ b/snippets/markdown.json @@ -1,9 +1,6 @@ { "Create a covector change file": { - "prefix": [ - "covector", - "---" - ], + "prefix": ["covector", "---"], "body": [ "---", "\"${3:$WORKSPACE_NAME}\": \"${1|patch,minor,major|}\"", diff --git a/snippets/rust.json b/snippets/rust.json index 7b12a39..f95b62e 100644 --- a/snippets/rust.json +++ b/snippets/rust.json @@ -1,10 +1,6 @@ { "Create a tauri command": { - "prefix": [ - "command", - "#[tauri::command]", - "#[command]" - ], + "prefix": ["command", "#[tauri::command]", "#[command]"], "body": [ "#[tauri::command]", "async fn ${1:command_name}(app: tauri::AppHandle, window: tauri::Window) -> Result<(), String> {", @@ -14,11 +10,7 @@ "description": "Communicate between the UI and the Rust code" }, "Create a stateful tauri command": { - "prefix": [ - "command", - "#[tauri::command]", - "#[command]" - ], + "prefix": ["command", "#[tauri::command]", "#[command]"], "body": [ "#[derive(Default)]", "struct MyState {", diff --git a/src/extension.ts b/src/extension.ts index c5c5f58..e401793 100644 --- a/src/extension.ts +++ b/src/extension.ts @@ -3,6 +3,7 @@ import { exec, ChildProcess } from 'child_process'; import { runInTerminal } from 'run-in-terminal'; import { join } from 'path'; import { existsSync, readFileSync } from 'fs'; +import axios from 'axios'; const glob = require('glob'); const path = require('path'); const fs = require('fs'); @@ -20,11 +21,12 @@ const runningProcesses: Map = new Map(); // your extension is activated the very first time the command is executed export function activate(context: vscode.ExtensionContext) { registerCommands(context); + registerSchemasHandler(context); outputChannel = vscode.window.createOutputChannel('tauri'); context.subscriptions.push(outputChannel); - vscode.window.onDidCloseTerminal(closedTerminal => { + vscode.window.onDidCloseTerminal((closedTerminal) => { if (terminal === closedTerminal) { terminal = null; } @@ -41,77 +43,174 @@ export function deactivate() { function registerCommands(context: vscode.ExtensionContext) { context.subscriptions.push( vscode.commands.registerCommand('tauri.init', runTauriInit), - vscode.commands.registerCommand('tauri.deps-install', runTauriDepsInstall), - vscode.commands.registerCommand('tauri.deps-update', runTauriDepsUpdate), vscode.commands.registerCommand('tauri.dev', runTauriDev), vscode.commands.registerCommand('tauri.build', runTauriBuild), vscode.commands.registerCommand('tauri.build-debug', runTauriBuildDebug) ); } +function registerSchemasHandler(context: vscode.ExtensionContext) { + vscode.workspace.registerTextDocumentContentProvider( + 'tauri', + new (class implements vscode.TextDocumentContentProvider { + onDidChangeEmitter = new vscode.EventEmitter(); + onDidChange = this.onDidChangeEmitter.event; + + async provideTextDocumentContent(uri: vscode.Uri): Promise { + if (uri.authority === 'schemas' && uri.path === '/config.json') { + // get schema form local file in node_modules + const schemaFile = ( + await vscode.workspace.findFiles( + '**/node_modules/@tauri-apps/cli/schema.json' + ) + )[0]; + if (schemaFile) return readFileSync(schemaFile.fsPath, 'utf-8'); + + async function getSchemaFromRelease(version: string) { + const res = await axios.get( + `https://github.com/tauri-apps/tauri/releases/download/tauri-build-v${version}/schema.json` + ); + return res.status == 200 ? JSON.stringify(res.data) : null; + } + + // get schema form github release based on tauri-build version in Cargo.lock + const cargoLockPath = ( + await vscode.workspace.findFiles('**/Cargo.lock') + )[0]; + if (cargoLockPath) { + const cargoLock = readFileSync(cargoLockPath.fsPath, 'utf-8'); + const matches = + /\[\[package\]\]\nname = "tauri-build"\nversion = "(.*)"/g.exec( + cargoLock + ); + if (matches && matches[1]) { + const schema = await getSchemaFromRelease(matches[1]); + if (schema) return schema; + } + } + + // get schema form github release based on tauri-build version in Cargo.toml + const cargoTomlPath = ( + await vscode.workspace.findFiles('**/Cargo.toml') + )[0]; + if (cargoTomlPath) { + const cargoToml = readFileSync(cargoTomlPath.fsPath, 'utf-8'); + + for (const regex of [ + // specifying a dependency in Cargo.toml can be done in 4 ways + // 1st, tauri-build = "1.0.2" + /tauri-build *= *"(.*)"/g, + // 2nd, tauri-build = { version = "1.0.2" } + /tauri-build *= *{.*version = "(.*)".*}\n/g, + // 3rd, + // tauri-build = { features = [ + // "f1", + // "f2" + // ], version = "1.0.2" } + /tauri-build *= *{[\s\S.]*version = "(.*)"[\s\S.]*}\n/g, + // 4th, + // [dependencies.tauri-build] + // \n version = "1.0.2" + /\[.*tauri-build\][\s\S.]*version = "(.*)"\n/g, + ]) { + const matches = regex.exec(cargoToml); + if (matches && matches[1]) { + const schema = await getSchemaFromRelease(matches[1]); + if (schema) return schema; + } + } + } + + // fallback to latest release + let res = await axios.get( + `https://api.github.com/repos/tauri-apps/tauri/releases` + ); + let tag_name = (res.data as Array<{ tag_name: string }>).find((e) => + e.tag_name.startsWith('tauri-build-v') + )?.tag_name; + if (tag_name) { + const matches = + /((\d|x|\*)+\.(\d|x|\*)+\.(\d|x|\*)+(-[a-zA-Z-0-9]*(.[0-9]+))*)/g.exec( + tag_name + ); + if (matches && matches[1]) { + const schema = await getSchemaFromRelease(matches[1]); + if (schema) return schema; + } + } + } + + return ''; + } + })() + ); +} + function runTauriInit(): void { - __pickProjectAndRunTauriScript(projectPath => { - let installCommand: string; - let onInstall = () => { }; - if (__isVueCliApp(projectPath)) { - installCommand = 'vue add tauri'; - } else { - installCommand = __usePnpm(projectPath) - ? 'pnpm add -D @tauri-apps/cli' - : __useYarn(projectPath) - ? 'yarn add @tauri-apps/cli --dev' - : `${__getNpmBin()} install @tauri-apps/cli --save-dev`; - onInstall = () => { - const packageJson = JSON.parse(fs.readFileSync(`${projectPath}/package.json`)); - if (!packageJson.scripts) { - packageJson.scripts = {}; - } - if (!packageJson.scripts['tauri']) { - packageJson.scripts['tauri'] = 'tauri'; - fs.writeFileSync(`${projectPath}/package.json`, JSON.stringify(packageJson, null, 4)); - } - __runTauriScript(['init'], { cwd: projectPath, noOutputWindow: true }); - }; + __pickProjectAndRunTauriScript( + (projectPath) => { + let installCommand: string; + let onInstall = () => {}; + if (__isVueCliApp(projectPath)) { + installCommand = 'vue add tauri'; + } else { + installCommand = __usePnpm(projectPath) + ? 'pnpm add -D @tauri-apps/cli' + : __useYarn(projectPath) + ? 'yarn add @tauri-apps/cli --dev' + : `${__getNpmBin()} install @tauri-apps/cli --save-dev`; + onInstall = () => { + const packageJson = JSON.parse( + fs.readFileSync(`${projectPath}/package.json`) + ); + if (!packageJson.scripts) { + packageJson.scripts = {}; + } + if (!packageJson.scripts['tauri']) { + packageJson.scripts['tauri'] = 'tauri'; + fs.writeFileSync( + `${projectPath}/package.json`, + JSON.stringify(packageJson, null, 4) + ); + } + __runTauriScript(['init'], { + cwd: projectPath, + noOutputWindow: true, + }); + }; + } + + const [command, ...args] = installCommand.split(' '); + __runScript(command, args, { + cwd: projectPath, + noOutputWindow: command === 'vue', + }).then(onInstall); + }, + () => { + const paths = __getNpmProjectsPaths(); + return paths.filter((p) => { + return !fs.existsSync(path.join(p, 'src-tauri')); + }); } - - const [command, ...args] = (installCommand).split(' '); - __runScript(command, args, { cwd: projectPath, noOutputWindow: command === 'vue' }).then(onInstall); - }, () => { - const paths = __getNpmProjectsPaths(); - return paths.filter(p => { - return !fs.existsSync(path.join(p, 'src-tauri')); - }); - }); -} - -function runTauriDepsInstall(): void { - const projectPaths = __getTauriProjectsPaths(); - if (projectPaths.length === 0) { - vscode.window.showErrorMessage('Tauri project not found'); - return; - } - __runTauriScript(['deps', 'install'], { cwd: projectPaths[0] }); -} - -function runTauriDepsUpdate(): void { - const projectPaths = __getTauriProjectsPaths(); - if (projectPaths.length === 0) { - vscode.window.showErrorMessage('Tauri project not found'); - return; - } - __runTauriScript(['deps', 'update'], { cwd: projectPaths[0] }); + ); } function runTauriDev(): void { - __pickProjectAndRunTauriScript(projectPath => __runTauriScript(['dev'], { cwd: projectPath })); + __pickProjectAndRunTauriScript((projectPath) => + __runTauriScript(['dev'], { cwd: projectPath }) + ); } function runTauriBuild(): void { - __pickProjectAndRunTauriScript(projectPath => __runTauriScript(['build'], { cwd: projectPath })); + __pickProjectAndRunTauriScript((projectPath) => + __runTauriScript(['build'], { cwd: projectPath }) + ); } function runTauriBuildDebug(): void { - __pickProjectAndRunTauriScript(projectPath => __runTauriScript(['build', '--debug'], { cwd: projectPath })); + __pickProjectAndRunTauriScript((projectPath) => + __runTauriScript(['build', '--debug'], { cwd: projectPath }) + ); } function __isVueCliApp(cwd: string): boolean { @@ -120,13 +219,16 @@ function __isVueCliApp(cwd: string): boolean { } interface PackageJson { + dependencies: { + [name: string]: any; + }; devDependencies: { - [name: string]: any - } + [name: string]: any; + }; } -function __getPackageJson(cwd: string): PackageJson | null { - const packagePath = join(cwd, 'package.json'); +function __getPackageJson(path: string): PackageJson | null { + const packagePath = join(path, 'package.json'); if (existsSync(packagePath)) { const packageStr = readFileSync(packagePath).toString(); return JSON.parse(packageStr) as PackageJson; @@ -143,13 +245,14 @@ function __getNpmProjectsPaths(): string[] { const paths = []; for (const folder of folders) { - const npmProjectRoots: string[] = glob.sync(folder.uri.fsPath.split('\\').join('/') + '/**/package.json') + const npmProjectRoots: string[] = glob + .sync(folder.uri.fsPath.split('\\').join('/') + '/**/package.json') .map((p: string) => path.dirname(p)); - paths.push(...npmProjectRoots.filter(p => !p.includes('node_modules'))); + paths.push(...npmProjectRoots.filter((p) => !p.includes('node_modules'))); } if (paths.length === 0) { - return folders.map(f => f.uri.fsPath); + return folders.map((f) => f.uri.fsPath); } return paths; @@ -163,9 +266,10 @@ function __getTauriProjectsPaths(): string[] { const paths = []; for (const folder of folders) { - const tauriProjectRoots: string[] = glob.sync(folder.uri.fsPath.split('\\').join('/') + '/**/src-tauri') + const tauriProjectRoots: string[] = glob + .sync(folder.uri.fsPath.split('\\').join('/') + '/**/src-tauri') .map((p: string) => path.dirname(p)); - paths.push(...tauriProjectRoots.filter(p => !p.includes('node_modules'))); + paths.push(...tauriProjectRoots.filter((p) => !p.includes('node_modules'))); } return paths; } @@ -177,21 +281,31 @@ function __isMultiRoot(): boolean { return false; } -function __runCommandInTerminal(command: string, args: string[], cwd: string | undefined): Promise { - return runInTerminal(command, args, { cwd, env: process.env }).then(process => { - return new Promise((resolve, reject) => { - process.on('exit', code => { - if (code) { - reject(); - } else { - resolve(); - } +function __runCommandInTerminal( + command: string, + args: string[], + cwd: string | undefined +): Promise { + return runInTerminal(command, args, { cwd, env: process.env }).then( + (process) => { + return new Promise((resolve, reject) => { + process.on('exit', (code) => { + if (code) { + reject(); + } else { + resolve(); + } + }); }); - }); - }); + } + ); } -function __runCommandInIntegratedTerminal(command: string, args: string[], cwd: string | undefined): Promise { +function __runCommandInIntegratedTerminal( + command: string, + args: string[], + cwd: string | undefined +): Promise { if (!terminal) { terminal = vscode.window.createTerminal('tauri'); } @@ -206,7 +320,11 @@ function __runCommandInIntegratedTerminal(command: string, args: string[], cwd: return Promise.resolve(); } -function __runCommandInOutputWindow(command: string, args: string[], cwd: string | undefined): Promise { +function __runCommandInOutputWindow( + command: string, + args: string[], + cwd: string | undefined +): Promise { return new Promise((resolve, reject) => { const cmd = command + ' ' + args.join(' '); const p = exec(cmd, { cwd, env: process.env }); @@ -243,8 +361,8 @@ function __runCommandInOutputWindow(command: string, args: string[], cwd: string } interface TauriProject { - label: string - projectPath: string + label: string; + projectPath: string; } function __useTerminal() { @@ -264,17 +382,22 @@ function __getNpmBin() { } function __getPackageManagerBin(projectPath: string) { - return __usePnpm(projectPath) ? 'pnpm' : __useYarn(projectPath) ? 'yarn' : __getNpmBin(); + return __usePnpm(projectPath) + ? 'pnpm' + : __useYarn(projectPath) + ? 'yarn' + : __getNpmBin(); } - interface RunOptions { - noOutputWindow?: boolean - cwd: string + noOutputWindow?: boolean; + cwd: string; } function __runScript(command: string, args: string[], options: RunOptions) { - vscode.window.showInformationMessage(`Running \`${command} ${args.join(' ')}\` in ${options.cwd}`); + vscode.window.showInformationMessage( + `Running \`${command} ${args.join(' ')}\` in ${options.cwd}` + ); return vscode.workspace.saveAll().then(() => { if (__useTerminal() || options.noOutputWindow) { @@ -293,13 +416,24 @@ function __runScript(command: string, args: string[], options: RunOptions) { function __runTauriScript(args: string[], options: RunOptions): void { if (__isVueCliApp(options.cwd)) { const [cmd, ...cmgArgs] = args; - __runScript(__getPackageManagerBin(options.cwd), ['run', `tauri:${cmd === 'dev' ? 'serve' : cmd}`, ...cmgArgs], options); + __runScript( + __getPackageManagerBin(options.cwd), + ['run', `tauri:${cmd === 'dev' ? 'serve' : cmd}`, ...cmgArgs], + options + ); } else { - __runScript(__getPackageManagerBin(options.cwd), ['run', 'tauri', ...args], options); + __runScript( + __getPackageManagerBin(options.cwd), + ['run', 'tauri', ...args], + options + ); } } -function __pickProjectAndRunTauriScript(runner: (projectPath: string) => void, getProjectPathsFn = __getTauriProjectsPaths): void { +function __pickProjectAndRunTauriScript( + runner: (projectPath: string) => void, + getProjectPathsFn = __getTauriProjectsPaths +): void { const tauriProjectsPaths = getProjectPathsFn(); const projectList: TauriProject[] = []; @@ -314,7 +448,7 @@ function __pickProjectAndRunTauriScript(runner: (projectPath: string) => void, g projectList.push({ label, - projectPath: p + projectPath: p, }); } @@ -326,7 +460,7 @@ function __pickProjectAndRunTauriScript(runner: (projectPath: string) => void, g if (projectList.length === 1) { runner(projectList[0].projectPath); } else { - vscode.window.showQuickPick(projectList).then(project => { + vscode.window.showQuickPick(projectList).then((project) => { if (project) { runner(project.projectPath); } diff --git a/src/test/runTest.ts b/src/test/runTest.ts index 9de5f84..014c3a2 100644 --- a/src/test/runTest.ts +++ b/src/test/runTest.ts @@ -3,21 +3,21 @@ import * as path from 'path'; import { runTests } from '@vscode/test-electron'; async function main() { - try { - // The folder containing the Extension Manifest package.json - // Passed to `--extensionDevelopmentPath` - const extensionDevelopmentPath = path.resolve(__dirname, '../../'); + try { + // The folder containing the Extension Manifest package.json + // Passed to `--extensionDevelopmentPath` + const extensionDevelopmentPath = path.resolve(__dirname, '../../'); - // The path to test runner - // Passed to --extensionTestsPath - const extensionTestsPath = path.resolve(__dirname, './suite/index'); + // The path to test runner + // Passed to --extensionTestsPath + const extensionTestsPath = path.resolve(__dirname, './suite/index'); - // Download VS Code, unzip it and run the integration test - await runTests({ extensionDevelopmentPath, extensionTestsPath }); - } catch (err) { - console.error('Failed to run tests'); - process.exit(1); - } + // Download VS Code, unzip it and run the integration test + await runTests({ extensionDevelopmentPath, extensionTestsPath }); + } catch (err) { + console.error('Failed to run tests'); + process.exit(1); + } } main(); diff --git a/src/test/suite/extension.test.ts b/src/test/suite/extension.test.ts index b2895f8..b5fea9d 100644 --- a/src/test/suite/extension.test.ts +++ b/src/test/suite/extension.test.ts @@ -6,10 +6,12 @@ import * as vscode from 'vscode'; // import * as myExtension from '../../extension'; suite('Extension Test Suite', () => { - vscode.window.showInformationMessage('Start all tests.'); + vscode.window.showInformationMessage('Start all tests.'); - test('Sample test', () => { - vscode.window.showInformationMessage(JSON.stringify(vscode.workspace.workspaceFolders)); - setTimeout(() => { }, 2000); - }); + test('Sample test', () => { + vscode.window.showInformationMessage( + JSON.stringify(vscode.workspace.workspaceFolders) + ); + setTimeout(() => {}, 2000); + }); }); diff --git a/src/test/suite/index.ts b/src/test/suite/index.ts index 7029e38..8ced9b1 100644 --- a/src/test/suite/index.ts +++ b/src/test/suite/index.ts @@ -3,36 +3,36 @@ import * as Mocha from 'mocha'; import * as glob from 'glob'; export function run(): Promise { - // Create the mocha test - const mocha = new Mocha({ - ui: 'tdd', - color: true - }); + // Create the mocha test + const mocha = new Mocha({ + ui: 'tdd', + color: true, + }); - const testsRoot = path.resolve(__dirname, '..'); + const testsRoot = path.resolve(__dirname, '..'); - return new Promise((c, e) => { - glob('**/**.test.js', { cwd: testsRoot }, (err, files) => { - if (err) { - return e(err); - } + return new Promise((c, e) => { + glob('**/**.test.js', { cwd: testsRoot }, (err, files) => { + if (err) { + return e(err); + } - // Add files to the test suite - files.forEach(f => mocha.addFile(path.resolve(testsRoot, f))); + // Add files to the test suite + files.forEach((f) => mocha.addFile(path.resolve(testsRoot, f))); - try { - // Run the mocha test - mocha.run(failures => { - if (failures > 0) { - e(new Error(`${failures} tests failed.`)); - } else { - c(); - } - }); - } catch (err) { - console.error(err); - e(err); - } - }); - }); + try { + // Run the mocha test + mocha.run((failures) => { + if (failures > 0) { + e(new Error(`${failures} tests failed.`)); + } else { + c(); + } + }); + } catch (err) { + console.error(err); + e(err); + } + }); + }); } diff --git a/tsconfig.json b/tsconfig.json index b65c745..b9534e2 100644 --- a/tsconfig.json +++ b/tsconfig.json @@ -1,21 +1,16 @@ { - "compilerOptions": { - "module": "commonjs", - "target": "es6", - "outDir": "out", - "lib": [ - "es6" - ], - "sourceMap": true, - "rootDir": "src", - "strict": true /* enable all strict type-checking options */ - /* Additional Checks */ - // "noImplicitReturns": true, /* Report error when not all code paths in function return a value. */ - // "noFallthroughCasesInSwitch": true, /* Report errors for fallthrough cases in switch statement. */ - // "noUnusedParameters": true, /* Report errors on unused parameters. */ - }, - "exclude": [ - "node_modules", - ".vscode-test" - ] + "compilerOptions": { + "module": "commonjs", + "target": "es6", + "outDir": "out", + "lib": ["es6"], + "sourceMap": true, + "rootDir": "src", + "strict": true /* enable all strict type-checking options */ + /* Additional Checks */ + // "noImplicitReturns": true, /* Report error when not all code paths in function return a value. */ + // "noFallthroughCasesInSwitch": true, /* Report errors for fallthrough cases in switch statement. */ + // "noUnusedParameters": true, /* Report errors on unused parameters. */ + }, + "exclude": ["node_modules", ".vscode-test"] } diff --git a/yarn.lock b/yarn.lock index 9a7a7f4..5a433ff 100644 --- a/yarn.lock +++ b/yarn.lock @@ -100,6 +100,11 @@ resolved "https://registry.yarnpkg.com/@types/node/-/node-16.11.59.tgz#823f238b9063ccc3b3b7f13186f143a57926c4f6" integrity sha512-6u+36Dj3aDzhfBVUf/mfmc92OEdzQ2kx2jcXGdigfl70E/neV21ZHE6UCz4MDzTRcVqGAM27fk+DLXvyDsn3Jw== +"@types/semver@^7.3.12": + version "7.3.12" + resolved "https://registry.yarnpkg.com/@types/semver/-/semver-7.3.12.tgz#920447fdd78d76b19de0438b7f60df3c4a80bf1c" + integrity sha512-WwA1MW0++RfXmCr12xeYOOC5baSC9mSb0ZqCquFzKhcoF4TvHu5MKOuXsncgZcpVFhB1pXd5hZmM0ryAoCp12A== + "@types/vscode@1.66.0": version "1.66.0" resolved "https://registry.yarnpkg.com/@types/vscode/-/vscode-1.66.0.tgz#e90e1308ad103f2bd31b72c17b8031b4cec0713d" @@ -263,6 +268,19 @@ array-union@^2.1.0: resolved "https://registry.yarnpkg.com/array-union/-/array-union-2.1.0.tgz#b798420adbeb1de828d84acd8a2e23d3efe85e8d" integrity sha512-HGyxoOTYUyCM6stUe6EJgnd4EoewAI7zMdfqO+kGjnlZmBDz/cR5pf8r/cR4Wq60sL/p0IkcjUEEPwS3GFrIyw== +asynckit@^0.4.0: + version "0.4.0" + resolved "https://registry.yarnpkg.com/asynckit/-/asynckit-0.4.0.tgz#c79ed97f7f34cb8f2ba1bc9790bcc366474b4b79" + integrity sha512-Oei9OH4tRh0YqU3GxhX79dM/mwVgvbZJaSNaRk+bshkj0S5cfHcgYakreBjrHwatXKbz+IoIdYLxrKim2MjW0Q== + +axios@^0.27.2: + version "0.27.2" + resolved "https://registry.yarnpkg.com/axios/-/axios-0.27.2.tgz#207658cc8621606e586c85db4b41a750e756d972" + integrity sha512-t+yRIyySRTp/wua5xEr+z1q60QmLq8ABsS5O9Me1AsE5dfKqgnCFzwiCZZ/cGNd1lq4/7akDWMxdhVlucjmnOQ== + dependencies: + follow-redirects "^1.14.9" + form-data "^4.0.0" + balanced-match@^1.0.0: version "1.0.2" resolved "https://registry.yarnpkg.com/balanced-match/-/balanced-match-1.0.2.tgz#e83e3a7e3f300b34cb9d87f615fa0cbf357690ee" @@ -381,6 +399,13 @@ color-name@~1.1.4: resolved "https://registry.yarnpkg.com/color-name/-/color-name-1.1.4.tgz#c2a09a87acbde69543de6f63fa3995c826c536a2" integrity sha512-dOy+3AuW3a2wNbZHIuMZpTcgjGuLU/uBL/ubcZF9OXbDo8ff4O8yVp5Bf0efS8uEoYo5q4Fx7dY9OgQGXgAsQA== +combined-stream@^1.0.8: + version "1.0.8" + resolved "https://registry.yarnpkg.com/combined-stream/-/combined-stream-1.0.8.tgz#c3d45a8b34fd730631a110a8a2520682b31d5a7f" + integrity sha512-FQN4MRfuJeHf7cBbBMJFXhKSDq+2kAArBlmRBvcvFE5BB1HZKXtSFASDhdlz9zOYwxh8lDdnvmMOe/+5cdoEdg== + dependencies: + delayed-stream "~1.0.0" + core-util-is@~1.0.0: version "1.0.3" resolved "https://registry.yarnpkg.com/core-util-is/-/core-util-is-1.0.3.tgz#a6042d3634c2b27e9328f837b965fac83808db85" @@ -412,6 +437,11 @@ deep-is@^0.1.3: resolved "https://registry.yarnpkg.com/deep-is/-/deep-is-0.1.4.tgz#a6f2dce612fadd2ef1f519b73551f17e85199831" integrity sha512-oIPzksmTg4/MriiaYGO+okXDT7ztn/w3Eptv/+gSIdMdKsJo0u4CfYNFJPy+4SKMuCqGw2wxnA+URMg3t8a/bQ== +delayed-stream@~1.0.0: + version "1.0.0" + resolved "https://registry.yarnpkg.com/delayed-stream/-/delayed-stream-1.0.0.tgz#df3ae199acadfb7d440aaae0b29e2272b24ec619" + integrity sha512-ZySD7Nf91aLB0RxL4KGrKHBXl7Eds1DAmEdcoVawXnLD7SDhpNgtuII2aAkg7a7QS41jxPSZ17p4VdGnMHk3MQ== + diff@5.0.0: version "5.0.0" resolved "https://registry.yarnpkg.com/diff/-/diff-5.0.0.tgz#7ed6ad76d859d030787ec35855f5b1daf31d852b" @@ -642,6 +672,20 @@ flatted@^3.1.0: resolved "https://registry.yarnpkg.com/flatted/-/flatted-3.2.7.tgz#609f39207cb614b89d0765b477cb2d437fbf9787" integrity sha512-5nqDSxl8nn5BSNxyR3n4I6eDmbolI6WT+QqR547RwxQapgjQBmtktdP+HTBb/a/zLsbzERTONyUB5pefh5TtjQ== +follow-redirects@^1.14.9: + version "1.15.1" + resolved "https://registry.yarnpkg.com/follow-redirects/-/follow-redirects-1.15.1.tgz#0ca6a452306c9b276e4d3127483e29575e207ad5" + integrity sha512-yLAMQs+k0b2m7cVxpS1VKJVvoz7SS9Td1zss3XRwXj+ZDH00RJgnuLx7E44wx02kQLrdM3aOOy+FpzS7+8OizA== + +form-data@^4.0.0: + version "4.0.0" + resolved "https://registry.yarnpkg.com/form-data/-/form-data-4.0.0.tgz#93919daeaf361ee529584b9b31664dc12c9fa452" + integrity sha512-ETEklSGi5t0QMZuiXoA/Q6vcnxcLQP5vdugSpuAyi6SVGi2clPPp+xgEhuMaHC+zGgn31Kd235W35f7Hykkaww== + dependencies: + asynckit "^0.4.0" + combined-stream "^1.0.8" + mime-types "^2.1.12" + fs.realpath@^1.0.0: version "1.0.0" resolved "https://registry.yarnpkg.com/fs.realpath/-/fs.realpath-1.0.0.tgz#1504ad2523158caa40db4a2787cb01411994ea4f" @@ -932,6 +976,18 @@ micromatch@^4.0.4: braces "^3.0.2" picomatch "^2.3.1" +mime-db@1.52.0: + version "1.52.0" + resolved "https://registry.yarnpkg.com/mime-db/-/mime-db-1.52.0.tgz#bbabcdc02859f4987301c856e3387ce5ec43bf70" + integrity sha512-sPU4uV7dYlvtWJxwwxHD0PuihVNiE7TyAbQ5SWxDCB9mUYvOgroQOwYQQOKPJ8CIbE+1ETVlOoK1UC2nU3gYvg== + +mime-types@^2.1.12: + version "2.1.35" + resolved "https://registry.yarnpkg.com/mime-types/-/mime-types-2.1.35.tgz#381a871b62a734450660ae3deee44813f70d959a" + integrity sha512-ZDY+bPm5zTTF+YpCrAU9nK0UgICYPT0QtT1NZWFv4s++TNkcgVaT0g6+4R2uI4MjQjzysHB1zxuWL50hzaeXiw== + dependencies: + mime-db "1.52.0" + minimatch@5.0.1: version "5.0.1" resolved "https://registry.yarnpkg.com/minimatch/-/minimatch-5.0.1.tgz#fb9022f7528125187c92bd9e9b6366be1cf3415b" @@ -1088,6 +1144,11 @@ prelude-ls@^1.2.1: resolved "https://registry.yarnpkg.com/prelude-ls/-/prelude-ls-1.2.1.tgz#debc6489d7a6e6b0e7611888cec880337d316396" integrity sha512-vkcDPrRZo1QZLbn5RLGPpg/WmIQ65qoWWhcGKf/b5eplkkarX0m9z8ppCat4mlOqUsWpyNuYgO3VRyrYHSzX5g== +prettier@^2.7.1: + version "2.7.1" + resolved "https://registry.yarnpkg.com/prettier/-/prettier-2.7.1.tgz#e235806850d057f97bb08368a4f7d899f7760c64" + integrity sha512-ujppO+MkdPqoVINuDFDRLClm7D78qbDt0/NR+wp5FqEZOoTNAjPHWj17QRhu7geIHJfcNhRk1XVQmF8Bp3ye+g== + process-nextick-args@~2.0.0: version "2.0.1" resolved "https://registry.yarnpkg.com/process-nextick-args/-/process-nextick-args-2.0.1.tgz#7820d9b16120cc55ca9ae7792680ae7dba6d7fe2"