Repository: folke/vscode-monorepo-workspace Branch: master Commit: bccdd34dc65a Files: 22 Total size: 34.2 KB Directory structure: gitextract_l75d_29m/ ├── .eslintrc.js ├── .gitignore ├── .husky/ │ ├── .gitignore │ └── prepare-commit-msg ├── .prettierrc ├── .vscode/ │ ├── extensions.json │ ├── launch.json │ ├── settings.json │ └── tasks.json ├── .vscodeignore ├── CHANGELOG.md ├── LICENSE ├── README.md ├── package.json ├── renovate.json ├── rollup.config.js ├── src/ │ ├── extension.ts │ └── test/ │ ├── run-test.ts │ └── suite/ │ ├── extension.test.ts │ └── index.ts ├── tsconfig.json └── vsc-extension-quickstart.md ================================================ FILE CONTENTS ================================================ ================================================ FILE: .eslintrc.js ================================================ module.exports = { parser: "@typescript-eslint/parser", // Specifies the ESLint parser extends: [ "eslint:recommended", "plugin:@typescript-eslint/eslint-recommended", "plugin:@typescript-eslint/recommended", "plugin:@typescript-eslint/recommended-requiring-type-checking", "prettier", "plugin:unicorn/recommended", "plugin:promise/recommended", "plugin:chai-expect/recommended", ], env: { node: true, browser: false, mocha: true, }, plugins: [ "@typescript-eslint", "prettier", // "import", "promise", "chai-expect", ], settings: { "import/core-modules": ["vscode"] }, parserOptions: { ecmaVersion: 2019, // Allows for the parsing of modern ECMAScript features sourceType: "module", // Allows for the use of imports project: "./tsconfig.json", impliedStrict: true, createDefaultProgram: true, }, rules: { "array-callback-return": "error", "prefer-template": "warn", "prefer-promise-reject-errors": "error", "require-unicode-regexp": "error", yoda: "error", "prefer-spread": "error", "prettier/prettier": "warn", "unicorn/prevent-abbreviations": "off", "unicorn/explicit-length-check": "off", "unicorn/consistent-function-scoping": "off", "@typescript-eslint/explicit-module-boundary-types": "off", "lines-between-class-members": [ "error", "always", { exceptAfterSingleLine: true }, ], "@typescript-eslint/explicit-function-return-type": "off", "@typescript-eslint/no-unused-vars": ["warn", { argsIgnorePattern: "^_" }], }, } ================================================ FILE: .gitignore ================================================ out node_modules .vscode-test/ *.vsix .DS_Store ================================================ FILE: .husky/.gitignore ================================================ _ ================================================ FILE: .husky/prepare-commit-msg ================================================ #!/bin/sh . "$(dirname "$0")/_/husky.sh" npx devmoji -e --lint ================================================ FILE: .prettierrc ================================================ { "semi": false, "singleQuote": false, "tabWidth": 2, "useTabs": false, "printWidth": 80, "trailingComma": "es5", "proseWrap": "preserve" } ================================================ FILE: .vscode/extensions.json ================================================ { // See http://go.microsoft.com/fwlink/?LinkId=827846 // for the documentation about the extensions.json format "recommendations": [] } ================================================ FILE: .vscode/launch.json ================================================ // 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": "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}" } ] } ================================================ FILE: .vscode/settings.json ================================================ // 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" } ================================================ FILE: .vscode/tasks.json ================================================ // See https://go.microsoft.com/fwlink/?LinkId=733558 // for the documentation about the tasks.json format { "version": "2.0.0", "tasks": [ { "type": "npm", "script": "compile", "group": { "kind": "build", "isDefault": true }, "problemMatcher": [], "label": "npm: compile", "detail": "npx rollup -c rollup.config.js" } ] } ================================================ FILE: .vscodeignore ================================================ .vscode/** .vscode-test/** out/test/** src/** .gitignore vsc-extension-quickstart.md **/tsconfig.json **/.eslintrc.json **/*.map **/*.ts node_modules ================================================ FILE: CHANGELOG.md ================================================ # Release Notes ## 1.3.0 - Use rollup for smaller (and faster) builds - Added config option to include monorepo root during sync. (Implements Make includeRoot configurable from VSCode settings #56) ## 1.2.0 - Added option to configure custom package types ## 1.1.3 - Fixed an issue with workspace folders on Windows ## 1.0.0 - Initial release :tada: ================================================ FILE: LICENSE ================================================ Apache License Version 2.0, January 2004 http://www.apache.org/licenses/ TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION 1. Definitions. "License" shall mean the terms and conditions for use, reproduction, and distribution as defined by Sections 1 through 9 of this document. "Licensor" shall mean the copyright owner or entity authorized by the copyright owner that is granting the License. "Legal Entity" shall mean the union of the acting entity and all other entities that control, are controlled by, or are under common control with that entity. For the purposes of this definition, "control" means (i) the power, direct or indirect, to cause the direction or management of such entity, whether by contract or otherwise, or (ii) ownership of fifty percent (50%) or more of the outstanding shares, or (iii) beneficial ownership of such entity. "You" (or "Your") shall mean an individual or Legal Entity exercising permissions granted by this License. "Source" form shall mean the preferred form for making modifications, including but not limited to software source code, documentation source, and configuration files. "Object" form shall mean any form resulting from mechanical transformation or translation of a Source form, including but not limited to compiled object code, generated documentation, and conversions to other media types. "Work" shall mean the work of authorship, whether in Source or Object form, made available under the License, as indicated by a copyright notice that is included in or attached to the work (an example is provided in the Appendix below). "Derivative Works" shall mean any work, whether in Source or Object form, that is based on (or derived from) the Work and for which the editorial revisions, annotations, elaborations, or other modifications represent, as a whole, an original work of authorship. For the purposes of this License, Derivative Works shall not include works that remain separable from, or merely link (or bind by name) to the interfaces of, the Work and Derivative Works thereof. "Contribution" shall mean any work of authorship, including the original version of the Work and any modifications or additions to that Work or Derivative Works thereof, that is intentionally submitted to Licensor for inclusion in the Work by the copyright owner or by an individual or Legal Entity authorized to submit on behalf of the copyright owner. For the purposes of this definition, "submitted" means any form of electronic, verbal, or written communication sent to the Licensor or its representatives, including but not limited to communication on electronic mailing lists, source code control systems, and issue tracking systems that are managed by, or on behalf of, the Licensor for the purpose of discussing and improving the Work, but excluding communication that is conspicuously marked or otherwise designated in writing by the copyright owner as "Not a Contribution." "Contributor" shall mean Licensor and any individual or Legal Entity on behalf of whom a Contribution has been received by Licensor and subsequently incorporated within the Work. 2. Grant of Copyright License. Subject to the terms and conditions of this License, each Contributor hereby grants to You a perpetual, worldwide, non-exclusive, no-charge, royalty-free, irrevocable copyright license to reproduce, prepare Derivative Works of, publicly display, publicly perform, sublicense, and distribute the Work and such Derivative Works in Source or Object form. 3. Grant of Patent License. Subject to the terms and conditions of this License, each Contributor hereby grants to You a perpetual, worldwide, non-exclusive, no-charge, royalty-free, irrevocable (except as stated in this section) patent license to make, have made, use, offer to sell, sell, import, and otherwise transfer the Work, where such license applies only to those patent claims licensable by such Contributor that are necessarily infringed by their Contribution(s) alone or by combination of their Contribution(s) with the Work to which such Contribution(s) was submitted. If You institute patent litigation against any entity (including a cross-claim or counterclaim in a lawsuit) alleging that the Work or a Contribution incorporated within the Work constitutes direct or contributory patent infringement, then any patent licenses granted to You under this License for that Work shall terminate as of the date such litigation is filed. 4. Redistribution. You may reproduce and distribute copies of the Work or Derivative Works thereof in any medium, with or without modifications, and in Source or Object form, provided that You meet the following conditions: (a) You must give any other recipients of the Work or Derivative Works a copy of this License; and (b) You must cause any modified files to carry prominent notices stating that You changed the files; and (c) You must retain, in the Source form of any Derivative Works that You distribute, all copyright, patent, trademark, and attribution notices from the Source form of the Work, excluding those notices that do not pertain to any part of the Derivative Works; and (d) If the Work includes a "NOTICE" text file as part of its distribution, then any Derivative Works that You distribute must include a readable copy of the attribution notices contained within such NOTICE file, excluding those notices that do not pertain to any part of the Derivative Works, in at least one of the following places: within a NOTICE text file distributed as part of the Derivative Works; within the Source form or documentation, if provided along with the Derivative Works; or, within a display generated by the Derivative Works, if and wherever such third-party notices normally appear. The contents of the NOTICE file are for informational purposes only and do not modify the License. You may add Your own attribution notices within Derivative Works that You distribute, alongside or as an addendum to the NOTICE text from the Work, provided that such additional attribution notices cannot be construed as modifying the License. You may add Your own copyright statement to Your modifications and may provide additional or different license terms and conditions for use, reproduction, or distribution of Your modifications, or for any such Derivative Works as a whole, provided Your use, reproduction, and distribution of the Work otherwise complies with the conditions stated in this License. 5. Submission of Contributions. Unless You explicitly state otherwise, any Contribution intentionally submitted for inclusion in the Work by You to the Licensor shall be under the terms and conditions of this License, without any additional terms or conditions. Notwithstanding the above, nothing herein shall supersede or modify the terms of any separate license agreement you may have executed with Licensor regarding such Contributions. 6. Trademarks. This License does not grant permission to use the trade names, trademarks, service marks, or product names of the Licensor, except as required for reasonable and customary use in describing the origin of the Work and reproducing the content of the NOTICE file. 7. Disclaimer of Warranty. Unless required by applicable law or agreed to in writing, Licensor provides the Work (and each Contributor provides its Contributions) on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied, including, without limitation, any warranties or conditions of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A PARTICULAR PURPOSE. You are solely responsible for determining the appropriateness of using or redistributing the Work and assume any risks associated with Your exercise of permissions under this License. 8. Limitation of Liability. In no event and under no legal theory, whether in tort (including negligence), contract, or otherwise, unless required by applicable law (such as deliberate and grossly negligent acts) or agreed to in writing, shall any Contributor be liable to You for damages, including any direct, indirect, special, incidental, or consequential damages of any character arising as a result of this License or out of the use or inability to use the Work (including but not limited to damages for loss of goodwill, work stoppage, computer failure or malfunction, or any and all other commercial damages or losses), even if such Contributor has been advised of the possibility of such damages. 9. Accepting Warranty or Additional Liability. While redistributing the Work or Derivative Works thereof, You may choose to offer, and charge a fee for, acceptance of support, warranty, indemnity, or other liability obligations and/or rights consistent with this License. However, in accepting such obligations, You may act only on Your own behalf and on Your sole responsibility, not on behalf of any other Contributor, and only if You agree to indemnify, defend, and hold each Contributor harmless for any liability incurred by, or claims asserted against, such Contributor by reason of your accepting any such warranty or additional liability. END OF TERMS AND CONDITIONS APPENDIX: How to apply the Apache License to your work. To apply the Apache License to your work, attach the following boilerplate notice, with the fields enclosed by brackets "[]" replaced with your own identifying information. (Don't include the brackets!) The text should be enclosed in the appropriate comment syntax for the file format. We also recommend that a file or class name and description of purpose be included on the same "printed page" as the copyright notice for easier identification within third-party archives. Copyright [yyyy] [name of copyright owner] Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0 Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License. ================================================ FILE: README.md ================================================ # Monorepo Workspace Manage monorepos with multi-root workspaces. Supports Lerna, Yarn, Pnpm, Rushjs and recursive package directories. ## Features All **Monorepo Workspace** functionality can be found in the command palette. Available commands: ![Commands](images/animation.gif) Selecting workspace folders: ![Select](images/select.png) Selecting one package: ![Commands](images/list.png) * `Monorepo: Select Workspace Folders`: select active folders in your workspace, including packages in your repository * `Monorepo: Open Package (Current Window)`: open a package from your repository in the current window * `Monorepo: Open Package (New Window)`: open a package from your repository in a new window * `Monorepo: Open Package (Workspace Folder)`: add a package from your repository as a workspace folder You can also create workspace folders for all your repository packages with `Monorepo: Sync Workspace Folders`: ![Commands](images/explorer.png) ## Extension Settings **Monorepo Manager** tries to detect the type of package (library, application or tool) based on configurable regexes. The workspace folder prefix containing the emoji is also configurable. You can also configure custom types with a prefix in your JSON settings: ```json { "monorepoWorkspace.folders.custom": [ {"regex":"app1", "prefix": "🔥"}, {"regex":"app2", "prefix": "📚"} ] } ``` You can find all options under "Monorepo Workspace" in your configurtion. ## Release Notes ### 1.2.0 Added option to configure custom package types ### 1.1.3 Fixed an issue with workspace folders on Windows ### 1.0.0 Initial release :tada: ================================================ FILE: package.json ================================================ { "name": "vscode-monorepo-workspace", "displayName": "Monorepo Workspace", "description": "Manage monorepos with multi-root workspaces. Supports Lerna, Yarn, Pnpm, Rushjs and recursive package directories", "version": "1.3.1", "publisher": "folke", "repository": "http://github.com/folke/vscode-monorepo-workspace", "license": "SEE LICENSE IN LICENSE", "engines": { "vscode": ">=1.53.0" }, "categories": [ "Other" ], "keywords": [ "workspace", "monorepo", "project", "yarn", "folder" ], "activationEvents": [ "workspaceContains:**/package.json" ], "main": "./out/extension.js", "icon": "images/icon.png", "contributes": { "commands": [ { "command": "extension.openPackageCurrentWindow", "title": "Monorepo: Open Package (Current Window)" }, { "command": "extension.openPackageNewWindow", "title": "Monorepo: Open Package (New Window)" }, { "command": "extension.openPackageWorkspaceFolder", "title": "Monorepo: Open Package (Workspace Folder)" }, { "command": "extension.select", "title": "Monorepo: Select Workspace Folders" }, { "command": "extension.updateAll", "title": "Monorepo: Sync Workspace Folders" } ], "configuration": { "title": "Monorepo Workspace", "properties": { "monorepoWorkspace.includeRoot": { "type": "boolean", "default": true, "description": "Inlcude the top-level monorepo root path as a workspace folder" }, "monorepoWorkspace.folders.regex.apps": { "type": "string", "default": "^app|web|api|frontend|backend", "description": "Regex to match app-like package paths" }, "monorepoWorkspace.folders.prefix.apps": { "type": "string", "default": "🚀 ", "description": "Folder prefix for apps" }, "monorepoWorkspace.folders.regex.libs": { "type": "string", "default": "^common|package|lib|private", "description": "Regex to match library-like package paths" }, "monorepoWorkspace.folders.prefix.libs": { "type": "string", "default": "📦 ", "description": "Folder prefix for libraries" }, "monorepoWorkspace.folders.regex.tools": { "type": "string", "default": "^tool|script|util", "description": "Regex to match tool-like package paths" }, "monorepoWorkspace.folders.prefix.tools": { "type": "string", "default": "⚙️ ", "description": "Folder prefix for tools" }, "monorepoWorkspace.folders.prefix.unknown": { "type": "string", "default": "", "description": "Folder prefix for unknown packages" }, "monorepoWorkspace.folders.prefix.root": { "type": "string", "default": "✨ ", "description": "Folder prefix for the root folder" }, "monorepoWorkspace.folders.custom": { "type": "array", "default": [], "description": "An array of custom 'regex/prefix' pairs like: [{regex:'foo', prefix:'bar'}, {regex:'fffoo', prefix:'bbbar'}]" } } } }, "scripts": { "vscode:prepublish": "yarn run compile", "compile": "npx rollup -c", "lint": "eslint src --ext ts", "pretest": "yarn run compile && yarn run lint", "test": "node ./out/test/run-test.js", "release": "vsce package && vsce publish" }, "devDependencies": { "@rollup/plugin-commonjs": "17.1.0", "@rollup/plugin-node-resolve": "11.2.0", "@rollup/plugin-typescript": "8.2.0", "@types/glob": "7.1.3", "@types/mocha": "8.2.1", "@types/node": "14.14.31", "@types/vscode": "1.53.0", "@typescript-eslint/eslint-plugin": "4.15.2", "@typescript-eslint/parser": "4.15.2", "devmoji": "2.2.0", "eslint": "7.21.0", "eslint-config-prettier": "8.1.0", "eslint-plugin-chai-expect": "2.2.0", "eslint-plugin-import": "2.22.1", "eslint-plugin-jest": "24.1.5", "eslint-plugin-node": "11.1.0", "eslint-plugin-prettier": "3.3.1", "eslint-plugin-promise": "4.3.1", "eslint-plugin-unicorn": "28.0.2", "glob": "7.1.6", "husky": "5.1.1", "mocha": "8.3.0", "prettier": "2.2.1", "rollup": "2.40.0", "rollup-plugin-terser": "7.0.2", "rollup-plugin-typescript2": "0.30.0", "tslib": "2.1.0", "typescript": "4.2.2", "vscode-test": "1.5.1" }, "dependencies": { "rollup-plugin-progress": "1.1.2", "ultra-runner": "3.10.5" } } ================================================ FILE: renovate.json ================================================ { "extends": [ "config:base", ":semanticCommits", "group:allApollographql", "group:definitelyTyped", "group:vueMonorepo", "group:nestMonorepo", "group:fortawesome", "group:linters", "group:test", "group:allNonMajor" ], "masterIssue": true, "prHourlyLimit": 20, "packageRules": [ { "packagePatterns": ["vscode"], "groupName": "vscode" }, { "updateTypes": ["patch", "pin", "digest"], "automerge": true } ] } ================================================ FILE: rollup.config.js ================================================ // import typescript from "@rollup/plugin-typescript" import typescript from "rollup-plugin-typescript2" import { nodeResolve } from "@rollup/plugin-node-resolve" import { terser } from "rollup-plugin-terser" import commonjs from "@rollup/plugin-commonjs" import progress from "rollup-plugin-progress" import { builtinModules } from "module" export default { input: "src/extension.ts", // our source file output: { sourcemap: false, // freeze: false, // interop: "auto", // dir: "out", file: "out/extension.js", format: "cjs", }, // external: [...Object.keys(pkg.dependencies || {}), ...builtins], external: [...builtinModules, "vscode"], plugins: [ nodeResolve({ preferBuiltins: true, }), typescript({ // tsconfig: "./tsconfig.json", // module: "esnext", // typescript: require("typescript"), }), commonjs({ dynamicRequireTargets: ["*"] }), terser({ compress: true, mangle: true }), // eslint-disable-next-line @typescript-eslint/no-unsafe-call progress(), ], } ================================================ FILE: src/extension.ts ================================================ // eslint-disable-next-line unicorn/import-style import path from "path" import { getWorkspace } from "ultra-runner" import { commands, ExtensionContext, QuickPickItem, Uri, window, workspace as vscodeWorkspace, } from "vscode" interface WorkspaceFolderItem extends QuickPickItem { root: Uri isRoot: boolean description: string } function getFolderEmoji(root: string, pkgRoot: string) { const config = vscodeWorkspace.getConfiguration("monorepoWorkspace.folders") if (root == pkgRoot) return config.get("prefix.root") || "" const dir = path.relative(root, pkgRoot) // Use custom prefixes first const custom = config.get<{ regex: string; prefix: string }[]>("custom") if (custom?.length) { for (const c of custom) { if (c.prefix && c.regex && new RegExp(c.regex, "u").test(dir)) return c.prefix } } for (const type of ["apps", "libs", "tools"]) { const regex = config.get(`regex.${type}`) const prefix = config.get(`prefix.${type}`) if (regex && prefix && new RegExp(regex, "u").test(dir)) return prefix } return config.get("prefix.unknown") || "" } async function getPackageFolders( includeRoot = true ): Promise { const cwd = vscodeWorkspace.workspaceFolders?.[0].uri.fsPath if (cwd) { const workspace = await getWorkspace({ cwd, includeRoot: true, }) if (workspace) { const ret: WorkspaceFolderItem[] = [] if (includeRoot) ret.push({ label: `${getFolderEmoji(workspace.root, workspace.root)}${ workspace.getPackageForRoot(workspace.root) || "root" }`, description: `${ workspace.type[0].toUpperCase() + workspace.type.slice(1) } Workspace Root`, root: Uri.file(workspace.root), isRoot: true, }) ret.push( ...workspace .getPackages() .filter((p) => p.root !== workspace.root) .map((p) => { return { label: `${getFolderEmoji(workspace.root, p.root)}${p.name}`, description: `at ${path.relative(workspace.root, p.root)}`, root: Uri.file(p.root), isRoot: false, } }) .sort((a, b) => a.root.fsPath.localeCompare(b.root.fsPath)) ) return ret } } } enum PackageAction { newWindow, currentWindow, workspaceFolder, } function addWorkspaceFolder(item: WorkspaceFolderItem) { const folders = vscodeWorkspace.workspaceFolders let start = 0 let deleteCount = 0 if (folders) for (const folder of folders) { if (folder.uri == item.root) { // Nothing to update if (folder.name == item.label) return deleteCount = 1 break } start++ } vscodeWorkspace.updateWorkspaceFolders(start, deleteCount, { name: item.label, uri: item.root, }) } async function updateAll(items?: WorkspaceFolderItem[], clean = false) { const config = vscodeWorkspace.getConfiguration("monorepoWorkspace") if (!items) items = await getPackageFolders(config.get("includeRoot")) if (!items) return const itemsSet = new Set(items.map((item) => item.root.fsPath)) const folders = vscodeWorkspace.workspaceFolders const adds: { name: string; uri: Uri }[] = [] if (folders && !clean) { adds.push(...folders.filter((f) => !itemsSet.has(f.uri.fsPath))) } adds.push( ...items.map((item) => ({ name: item.label, uri: item.root, })) ) vscodeWorkspace.updateWorkspaceFolders(0, folders?.length, ...adds) } async function select(items?: WorkspaceFolderItem[]) { if (!items) items = await getPackageFolders() if (!items) return const itemsSet = new Map(items.map((item) => [item.root.fsPath, item])) const folders = vscodeWorkspace.workspaceFolders if (folders) { for (const folder of folders) { if (itemsSet.has(folder.uri.fsPath)) { // eslint-disable-next-line @typescript-eslint/no-non-null-assertion itemsSet.get(folder.uri.fsPath)!.picked = true } else { items.push({ root: folder.uri, isRoot: false, label: folder.name, description: "", picked: true, }) } } } const picked = await window.showQuickPick(items, { canPickMany: true, matchOnDescription: true, }) if (picked?.length) return updateAll(picked, true) } async function openPackage(action: PackageAction) { const items = await getPackageFolders() if (items) { const item = await window.showQuickPick(items, { canPickMany: false, matchOnDescription: true, }) if (item) { switch (action) { case PackageAction.currentWindow: return commands.executeCommand("vscode.openFolder", item.root) case PackageAction.newWindow: return commands.executeCommand("vscode.openFolder", item.root, true) case PackageAction.workspaceFolder: addWorkspaceFolder(item) break } } } } // this method is called when your extension is activated // your extension is activated the very first time the command is executed export function activate(context: ExtensionContext) { context.subscriptions.push( commands.registerCommand("extension.openPackageCurrentWindow", () => openPackage(PackageAction.currentWindow) ), commands.registerCommand("extension.openPackageNewWindow", () => openPackage(PackageAction.newWindow) ), commands.registerCommand("extension.openPackageWorkspaceFolder", () => openPackage(PackageAction.workspaceFolder) ), commands.registerCommand("extension.updateAll", () => updateAll()), commands.registerCommand("extension.select", () => select()) ) } // this method is called when your extension is deactivated export function deactivate() { true } ================================================ FILE: src/test/run-test.ts ================================================ import path from "path" import { runTests } from "vscode-test" async function main() { 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") // Download VS Code, unzip it and run the integration test await runTests({ extensionDevelopmentPath, extensionTestsPath }) } catch { console.error("Failed to run tests") // eslint-disable-next-line unicorn/no-process-exit process.exit(1) } } void main() ================================================ FILE: src/test/suite/extension.test.ts ================================================ import * as assert from "assert" // You can import and use all API from the 'vscode' module // as well as import your extension to test it import * as vscode from "vscode" // import * as myExtension from '../extension'; suite("Extension Test Suite", () => { void vscode.window.showInformationMessage("Start all tests.") test("Sample test", () => { assert.equal(-1, [1, 2, 3].indexOf(5)) assert.equal(-1, [1, 2, 3].indexOf(0)) }) }) ================================================ FILE: src/test/suite/index.ts ================================================ import path from "path" import Mocha from "mocha" import glob from "glob" export function run(): Promise { // Create the mocha test const mocha = new Mocha({ ui: "tdd", color: true, }) const testsRoot = path.resolve(__dirname, "..") return new Promise((resolve, reject) => { glob("**/**.test.js", { cwd: testsRoot }, (err, files) => { if (err) { return reject(err) } // Add files to the test suite for (const f of files) mocha.addFile(path.resolve(testsRoot, f)) try { // Run the mocha test mocha.run((failures) => { if (failures > 0) { reject(new Error(`${failures} tests failed.`)) } else { resolve() } }) } catch (error) { console.error(error) reject(error) } }) }) } ================================================ FILE: tsconfig.json ================================================ { "compilerOptions": { "module": "es2015", "target": "es6", // "outDir": "out", "lib": ["es6"], "sourceMap": true, "moduleResolution": "node", "rootDir": "src", "allowSyntheticDefaultImports": true, "importHelpers": true, "esModuleInterop": true, "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"] } ================================================ FILE: vsc-extension-quickstart.md ================================================ # Welcome to your VS Code Extension ## What's in the folder * This folder contains all of the files necessary for your extension. * `package.json` - this is the manifest file in which you declare your extension and command. * The sample plugin registers a command and defines its title and command name. With this information VS Code can show the command in the command palette. It doesn’t yet need to load the plugin. * `src/extension.ts` - this is the main file where you will provide the implementation of your command. * The file exports one function, `activate`, which is called the very first time your extension is activated (in this case by executing the command). Inside the `activate` function we call `registerCommand`. * We pass the function containing the implementation of the command as the second parameter to `registerCommand`. ## Get up and running straight away * Press `F5` to open a new window with your extension loaded. * Run your command from the command palette by pressing (`Ctrl+Shift+P` or `Cmd+Shift+P` on Mac) and typing `Hello World`. * Set breakpoints in your code inside `src/extension.ts` to debug your extension. * Find output from your extension in the debug console. ## Publishing * create a new token at https://dev.azure.com/hipfu/_usersSettings/tokens * `vsce login [TOKEN]` ## Make changes * You can relaunch the extension from the debug toolbar after changing code in `src/extension.ts`. * You can also reload (`Ctrl+R` or `Cmd+R` on Mac) the VS Code window with your extension to load your changes. ## Explore the API * You can open the full set of our API when you open the file `node_modules/@types/vscode/index.d.ts`. ## Run tests * Open the debug viewlet (`Ctrl+Shift+D` or `Cmd+Shift+D` on Mac) and from the launch configuration dropdown pick `Extension Tests`. * Press `F5` to run the tests in a new window with your extension loaded. * See the output of the test result in the debug console. * Make changes to `src/test/suite/extension.test.ts` or create new test files inside the `test/suite` folder. * The provided test runner will only consider files matching the name pattern `**.test.ts`. * You can create folders inside the `test` folder to structure your tests any way you want. ## Go further * Reduce the extension size and improve the startup time by [bundling your extension](https://code.visualstudio.com/api/working-with-extensions/bundling-extension). * [Publish your extension](https://code.visualstudio.com/api/working-with-extensions/publishing-extension) on the VSCode extension marketplace. * Automate builds by setting up [Continuous Integration](https://code.visualstudio.com/api/working-with-extensions/continuous-integration).