From 2a9e967fd1c766a718808d5a7fa779d74d44e62c Mon Sep 17 00:00:00 2001 From: Ashcon Partovi Date: Sat, 26 Aug 2023 02:34:25 -0700 Subject: More improvements to debugger support (#4345) * More fixes for dap * More changes * More changes 2 * More fixes * Fix debugger.ts * Bun Terminal --- packages/bun-vscode/.gitignore | 1 + packages/bun-vscode/.vscode/launch.json | 10 +- packages/bun-vscode/.vscode/tasks.json | 7 - packages/bun-vscode/LICENSE | 0 packages/bun-vscode/assets/icon-small.png | Bin 0 -> 4965 bytes packages/bun-vscode/assets/icon.png | Bin 0 -> 21284 bytes packages/bun-vscode/assets/package.json | 848 +++++++++++++++++++++++ packages/bun-vscode/bun.lockb | Bin 14484 -> 53674 bytes packages/bun-vscode/example/.vscode/launch.json | 18 - packages/bun-vscode/example/bun.lockb | Bin 25178 -> 25565 bytes packages/bun-vscode/example/example-sourcemap.js | 30 - packages/bun-vscode/example/example.js | 63 -- packages/bun-vscode/example/example.test.ts | 11 + packages/bun-vscode/example/example.ts | 2 +- packages/bun-vscode/example/package.json | 12 +- packages/bun-vscode/example/tsconfig.json | 22 + packages/bun-vscode/package.json | 76 +- packages/bun-vscode/scripts/build.mjs | 29 + packages/bun-vscode/scripts/test.mjs | 21 + packages/bun-vscode/src/assets/icon-small.png | Bin 4965 -> 0 bytes packages/bun-vscode/src/assets/icon.png | Bin 21284 -> 0 bytes packages/bun-vscode/src/features/debug.ts | 209 ++++-- packages/bun-vscode/src/resources/package.json | 848 ----------------------- 23 files changed, 1106 insertions(+), 1101 deletions(-) create mode 100644 packages/bun-vscode/LICENSE create mode 100644 packages/bun-vscode/assets/icon-small.png create mode 100644 packages/bun-vscode/assets/icon.png create mode 100644 packages/bun-vscode/assets/package.json delete mode 100644 packages/bun-vscode/example/.vscode/launch.json delete mode 100644 packages/bun-vscode/example/example-sourcemap.js delete mode 100644 packages/bun-vscode/example/example.js create mode 100644 packages/bun-vscode/example/example.test.ts create mode 100644 packages/bun-vscode/example/tsconfig.json create mode 100644 packages/bun-vscode/scripts/build.mjs create mode 100644 packages/bun-vscode/scripts/test.mjs delete mode 100644 packages/bun-vscode/src/assets/icon-small.png delete mode 100644 packages/bun-vscode/src/assets/icon.png delete mode 100644 packages/bun-vscode/src/resources/package.json (limited to 'packages/bun-vscode') diff --git a/packages/bun-vscode/.gitignore b/packages/bun-vscode/.gitignore index 9db2648e4..cafc85cea 100644 --- a/packages/bun-vscode/.gitignore +++ b/packages/bun-vscode/.gitignore @@ -1,2 +1,3 @@ node_modules extension +example/.vscode diff --git a/packages/bun-vscode/.vscode/launch.json b/packages/bun-vscode/.vscode/launch.json index 3ec1574d3..5922fb1b6 100644 --- a/packages/bun-vscode/.vscode/launch.json +++ b/packages/bun-vscode/.vscode/launch.json @@ -5,22 +5,28 @@ "name": "Extension", "type": "extensionHost", "request": "launch", + "env": { + "NODE_ENV": "development" + }, "args": ["--extensionDevelopmentPath=${workspaceFolder}", "${workspaceFolder}/example"], "outFiles": ["${workspaceFolder}/dist/**/*.js"], - "preLaunchTask": "Build (watch)" + "preLaunchTask": "Build" }, { "name": "Extension (web)", "type": "extensionHost", "debugWebWorkerHost": true, "request": "launch", + "env": { + "NODE_ENV": "development" + }, "args": [ "--extensionDevelopmentPath=${workspaceFolder}", "--extensionDevelopmentKind=web", "${workspaceFolder}/example" ], "outFiles": ["${workspaceFolder}/dist/**/*.js"], - "preLaunchTask": "Build (watch)" + "preLaunchTask": "Build" } ] } diff --git a/packages/bun-vscode/.vscode/tasks.json b/packages/bun-vscode/.vscode/tasks.json index a471df3ec..8675db611 100644 --- a/packages/bun-vscode/.vscode/tasks.json +++ b/packages/bun-vscode/.vscode/tasks.json @@ -6,13 +6,6 @@ "type": "shell", "command": "bun run build", "problemMatcher": "$esbuild" - }, - { - "label": "Build (watch)", - "type": "shell", - "command": "bun run build:watch", - "isBackground": true, - "problemMatcher": "$esbuild-watch" } ] } diff --git a/packages/bun-vscode/LICENSE b/packages/bun-vscode/LICENSE new file mode 100644 index 000000000..e69de29bb diff --git a/packages/bun-vscode/assets/icon-small.png b/packages/bun-vscode/assets/icon-small.png new file mode 100644 index 000000000..69bc385e8 Binary files /dev/null and b/packages/bun-vscode/assets/icon-small.png differ diff --git a/packages/bun-vscode/assets/icon.png b/packages/bun-vscode/assets/icon.png new file mode 100644 index 000000000..29cda9124 Binary files /dev/null and b/packages/bun-vscode/assets/icon.png differ diff --git a/packages/bun-vscode/assets/package.json b/packages/bun-vscode/assets/package.json new file mode 100644 index 000000000..021c8125e --- /dev/null +++ b/packages/bun-vscode/assets/package.json @@ -0,0 +1,848 @@ +{ + "$schema": "http://json-schema.org/draft-04/schema#", + "title": "JSON schema for Bun package.json files.", + "definitions": { + "person": { + "description": "A person who has been involved in creating or maintaining this package.", + "type": [ + "object", + "string" + ], + "required": [ + "name" + ], + "properties": { + "name": { + "type": "string" + }, + "url": { + "type": "string", + "format": "uri" + }, + "email": { + "type": "string", + "format": "email" + } + } + }, + "dependency": { + "description": "Dependencies are specified with a simple hash of package name to version range. The version range is a string which has one or more space-separated descriptors. Dependencies can also be identified with a tarball or git URL.", + "type": "object", + "additionalProperties": { + "type": "string" + } + }, + "license": { + "anyOf": [ + { + "type": "string" + }, + { + "enum": [ + "Apache-2.0", + "MIT", + "ISC", + "BSD-3-Clause", + "BSD-2-Clause", + "CC0-1.0", + "CDDL-1.1", + "LGPL-2.1-only", + "LGPL-2.1-or-later", + "LGPL-3.0-only", + "LGPL-3.0-or-later", + "EPL-1.0", + "EPL-2.0", + "MS-PL", + "UNLICENSED" + ] + } + ] + }, + "scriptsInstallAfter": { + "description": "Run AFTER the package is installed.", + "type": "string", + "x-intellij-language-injection": "Shell Script" + }, + "scriptsPublishAfter": { + "description": "Run AFTER the package is published.", + "type": "string", + "x-intellij-language-injection": "Shell Script" + }, + "scriptsRestart": { + "description": "Run by the 'npm restart' command. Note: 'npm restart' will run the stop and start scripts if no restart script is provided.", + "type": "string", + "x-intellij-language-injection": "Shell Script" + }, + "scriptsStart": { + "description": "Run by the 'npm start' command.", + "type": "string", + "x-intellij-language-injection": "Shell Script" + }, + "scriptsStop": { + "description": "Run by the 'npm stop' command.", + "type": "string", + "x-intellij-language-injection": "Shell Script" + }, + "scriptsTest": { + "description": "Run by the 'npm test' command.", + "type": "string", + "x-intellij-language-injection": "Shell Script" + }, + "scriptsUninstallBefore": { + "description": "Run BEFORE the package is uninstalled.", + "type": "string", + "x-intellij-language-injection": "Shell Script" + }, + "scriptsVersionBefore": { + "description": "Run BEFORE bump the package version.", + "type": "string", + "x-intellij-language-injection": "Shell Script" + }, + "packageExportsEntryPath": { + "type": [ + "string", + "null" + ], + "description": "The module path that is resolved when this specifier is imported. Set to `null` to disallow importing this module.", + "pattern": "^\\./" + }, + "packageExportsEntryObject": { + "type": "object", + "description": "Used to specify conditional exports, note that Conditional exports are unsupported in older environments, so it's recommended to use the fallback array option if support for those environments is a concern.", + "properties": { + "require": { + "$ref": "#/definitions/packageExportsEntryOrFallback", + "description": "The module path that is resolved when this specifier is imported as a CommonJS module using the `require(...)` function." + }, + "import": { + "$ref": "#/definitions/packageExportsEntryOrFallback", + "description": "The module path that is resolved when this specifier is imported as an ECMAScript module using an `import` declaration or the dynamic `import(...)` function." + }, + "node": { + "$ref": "#/definitions/packageExportsEntryOrFallback", + "description": "The module path that is resolved when this environment is Node.js." + }, + "default": { + "$ref": "#/definitions/packageExportsEntryOrFallback", + "description": "The module path that is resolved when no other export type matches." + }, + "types": { + "$ref": "#/definitions/packageExportsEntryOrFallback", + "description": "The module path that is resolved for TypeScript types when this specifier is imported. Should be listed before other conditions." + } + }, + "patternProperties": { + "^(?![\\.0-9]).": { + "$ref": "#/definitions/packageExportsEntryOrFallback", + "description": "The module path that is resolved when this environment matches the property name." + } + }, + "additionalProperties": false + }, + "packageExportsEntry": { + "oneOf": [ + { + "$ref": "#/definitions/packageExportsEntryPath" + }, + { + "$ref": "#/definitions/packageExportsEntryObject" + } + ] + }, + "packageExportsFallback": { + "type": "array", + "description": "Used to allow fallbacks in case this environment doesn't support the preceding entries.", + "items": { + "$ref": "#/definitions/packageExportsEntry" + } + }, + "packageExportsEntryOrFallback": { + "oneOf": [ + { + "$ref": "#/definitions/packageExportsEntry" + }, + { + "$ref": "#/definitions/packageExportsFallback" + } + ] + }, + "fundingUrl": { + "type": "string", + "format": "uri", + "description": "URL to a website with details about how to fund the package." + }, + "fundingWay": { + "type": "object", + "description": "Used to inform about ways to help fund development of the package.", + "properties": { + "url": { + "$ref": "#/definitions/fundingUrl" + }, + "type": { + "type": "string", + "description": "The type of funding or the platform through which funding can be provided, e.g. patreon, opencollective, tidelift or github." + } + }, + "additionalProperties": false, + "required": [ + "url" + ] + } + }, + "type": "object", + "patternProperties": { + "^_": { + "description": "Any property starting with _ is valid.", + "tsType": "any" + } + }, + "properties": { + "name": { + "description": "The name of the package.", + "type": "string", + "maxLength": 214, + "minLength": 1, + "pattern": "^(?:@(?:[a-z0-9-*~][a-z0-9-*._~]*)?/)?[a-z0-9-~][a-z0-9-._~]*$" + }, + "version": { + "description": "Version must be parseable by node-semver, which is bundled with npm as a dependency.", + "type": "string" + }, + "description": { + "description": "This helps people discover your package, as it's listed in 'npm search'.", + "type": "string" + }, + "keywords": { + "description": "This helps people discover your package as it's listed in 'npm search'.", + "type": "array", + "items": { + "type": "string" + } + }, + "homepage": { + "description": "The url to the project homepage.", + "type": "string" + }, + "bugs": { + "description": "The url to your project's issue tracker and / or the email address to which issues should be reported. These are helpful for people who encounter issues with your package.", + "type": [ + "object", + "string" + ], + "properties": { + "url": { + "type": "string", + "description": "The url to your project's issue tracker.", + "format": "uri" + }, + "email": { + "type": "string", + "description": "The email address to which issues should be reported.", + "format": "email" + } + } + }, + "license": { + "$ref": "#/definitions/license", + "description": "You should specify a license for your package so that people know how they are permitted to use it, and any restrictions you're placing on it." + }, + "licenses": { + "description": "DEPRECATED: Instead, use SPDX expressions, like this: { \"license\": \"ISC\" } or { \"license\": \"(MIT OR Apache-2.0)\" } see: 'https://docs.npmjs.com/files/package.json#license'.", + "type": "array", + "items": { + "type": "object", + "properties": { + "type": { + "$ref": "#/definitions/license" + }, + "url": { + "type": "string", + "format": "uri" + } + } + } + }, + "author": { + "$ref": "#/definitions/person" + }, + "contributors": { + "description": "A list of people who contributed to this package.", + "type": "array", + "items": { + "$ref": "#/definitions/person" + } + }, + "maintainers": { + "description": "A list of people who maintains this package.", + "type": "array", + "items": { + "$ref": "#/definitions/person" + } + }, + "files": { + "description": "The 'files' field is an array of files to include in your project. If you name a folder in the array, then it will also include the files inside that folder.", + "type": "array", + "items": { + "type": "string" + } + }, + "main": { + "description": "The main field is a module ID that is the primary entry point to your program.", + "type": "string" + }, + "exports": { + "description": "The \"exports\" field is used to restrict external access to non-exported module files, also enables a module to import itself using \"name\".", + "oneOf": [ + { + "$ref": "#/definitions/packageExportsEntryPath", + "description": "The module path that is resolved when the module specifier matches \"name\", shadows the \"main\" field." + }, + { + "type": "object", + "properties": { + ".": { + "$ref": "#/definitions/packageExportsEntryOrFallback", + "description": "The module path that is resolved when the module specifier matches \"name\", shadows the \"main\" field." + } + }, + "patternProperties": { + "^\\./.+": { + "$ref": "#/definitions/packageExportsEntryOrFallback", + "description": "The module path prefix that is resolved when the module specifier starts with \"name/\", set to \"./*\" to allow external modules to import any subpath." + } + }, + "additionalProperties": false + }, + { + "$ref": "#/definitions/packageExportsEntryObject", + "description": "The module path that is resolved when the module specifier matches \"name\", shadows the \"main\" field." + }, + { + "$ref": "#/definitions/packageExportsFallback", + "description": "The module path that is resolved when the module specifier matches \"name\", shadows the \"main\" field." + } + ] + }, + "bin": { + "type": [ + "string", + "object" + ], + "additionalProperties": { + "type": "string" + } + }, + "type": { + "description": "When set to \"module\", the type field allows a package to specify all .js files within are ES modules. If the \"type\" field is omitted or set to \"commonjs\", all .js files are treated as CommonJS.", + "type": "string", + "enum": [ + "commonjs", + "module" + ], + "default": "commonjs" + }, + "types": { + "description": "Set the types property to point to your bundled declaration file.", + "type": "string" + }, + "typings": { + "description": "Note that the \"typings\" field is synonymous with \"types\", and could be used as well.", + "type": "string" + }, + "typesVersions": { + "description": "The \"typesVersions\" field is used since TypeScript 3.1 to support features that were only made available in newer TypeScript versions.", + "type": "object", + "additionalProperties": { + "description": "Contains overrides for the TypeScript version that matches the version range matching the property key.", + "type": "object", + "properties": { + "*": { + "description": "Maps all file paths to the file paths specified in the array.", + "type": "array", + "items": { + "type": "string", + "pattern": "^[^*]*(?:\\*[^*]*)?$" + } + } + }, + "patternProperties": { + "^[^*]+$": { + "description": "Maps the file path matching the property key to the file paths specified in the array.", + "type": "array", + "items": { + "type": "string" + } + }, + "^[^*]*\\*[^*]*$": { + "description": "Maps file paths matching the pattern specified in property key to file paths specified in the array.", + "type": "array", + "items": { + "type": "string", + "pattern": "^[^*]*(?:\\*[^*]*)?$" + } + } + }, + "additionalProperties": false + } + }, + "man": { + "type": [ + "array", + "string" + ], + "description": "Specify either a single file or an array of filenames to put in place for the man program to find.", + "items": { + "type": "string" + } + }, + "directories": { + "type": "object", + "properties": { + "bin": { + "description": "If you specify a 'bin' directory, then all the files in that folder will be used as the 'bin' hash.", + "type": "string" + }, + "doc": { + "description": "Put markdown files in here. Eventually, these will be displayed nicely, maybe, someday.", + "type": "string" + }, + "example": { + "description": "Put example scripts in here. Someday, it might be exposed in some clever way.", + "type": "string" + }, + "lib": { + "description": "Tell people where the bulk of your library is. Nothing special is done with the lib folder in any way, but it's useful meta info.", + "type": "string" + }, + "man": { + "description": "A folder that is full of man pages. Sugar to generate a 'man' array by walking the folder.", + "type": "string" + }, + "test": { + "type": "string" + } + } + }, + "repository": { + "description": "Specify the place where your code lives. This is helpful for people who want to contribute.", + "type": [ + "object", + "string" + ], + "properties": { + "type": { + "type": "string" + }, + "url": { + "type": "string" + }, + "directory": { + "type": "string" + } + } + }, + "funding": { + "oneOf": [ + { + "$ref": "#/definitions/fundingUrl" + }, + { + "$ref": "#/definitions/fundingWay" + }, + { + "type": "array", + "items": { + "oneOf": [ + { + "$ref": "#/definitions/fundingUrl" + }, + { + "$ref": "#/definitions/fundingWay" + } + ] + }, + "minItems": 1, + "uniqueItems": true + } + ] + }, + "scripts": { + "description": "The 'scripts' member is an object hash of script commands that are run at various times in the lifecycle of your package. The key is the lifecycle event, and the value is the command to run at that point.", + "type": "object", + "properties": { + "lint": { + "type": "string", + "description": "Run code quality tools, e.g. ESLint, TSLint, etc." + }, + "prepublish": { + "type": "string", + "description": "Run BEFORE the package is published (Also run on local npm install without any arguments)." + }, + "prepare": { + "type": "string", + "description": "Run both BEFORE the package is packed and published, and on local npm install without any arguments. This is run AFTER prepublish, but BEFORE prepublishOnly." + }, + "prepublishOnly": { + "type": "string", + "description": "Run BEFORE the package is prepared and packed, ONLY on npm publish." + }, + "prepack": { + "type": "string", + "description": "run BEFORE a tarball is packed (on npm pack, npm publish, and when installing git dependencies)." + }, + "postpack": { + "type": "string", + "description": "Run AFTER the tarball has been generated and moved to its final destination." + }, + "publish": { + "type": "string", + "description": "Publishes a package to the registry so that it can be installed by name. See https://docs.npmjs.com/cli/v8/commands/npm-publish" + }, + "postpublish": { + "$ref": "#/definitions/scriptsPublishAfter" + }, + "preinstall": { + "type": "string", + "description": "Run BEFORE the package is installed." + }, + "install": { + "$ref": "#/definitions/scriptsInstallAfter" + }, + "postinstall": { + "$ref": "#/definitions/scriptsInstallAfter" + }, + "preuninstall": { + "$ref": "#/definitions/scriptsUninstallBefore" + }, + "uninstall": { + "$ref": "#/definitions/scriptsUninstallBefore" + }, + "postuninstall": { + "type": "string", + "description": "Run AFTER the package is uninstalled." + }, + "preversion": { + "$ref": "#/definitions/scriptsVersionBefore" + }, + "version": { + "$ref": "#/definitions/scriptsVersionBefore" + }, + "postversion": { + "type": "string", + "description": "Run AFTER bump the package version." + }, + "pretest": { + "$ref": "#/definitions/scriptsTest" + }, + "test": { + "$ref": "#/definitions/scriptsTest" + }, + "posttest": { + "$ref": "#/definitions/scriptsTest" + }, + "prestop": { + "$ref": "#/definitions/scriptsStop" + }, + "stop": { + "$ref": "#/definitions/scriptsStop" + }, + "poststop": { + "$ref": "#/definitions/scriptsStop" + }, + "prestart": { + "$ref": "#/definitions/scriptsStart" + }, + "start": { + "$ref": "#/definitions/scriptsStart" + }, + "poststart": { + "$ref": "#/definitions/scriptsStart" + }, + "prerestart": { + "$ref": "#/definitions/scriptsRestart" + }, + "restart": { + "$ref": "#/definitions/scriptsRestart" + }, + "postrestart": { + "$ref": "#/definitions/scriptsRestart" + }, + "serve": { + "type": "string", + "description": "Start dev server to serve application files" + } + }, + "additionalProperties": { + "type": "string", + "tsType": "string | undefined", + "x-intellij-language-injection": "Shell Script" + } + }, + "config": { + "description": "A 'config' hash can be used to set configuration parameters used in package scripts that persist across upgrades.", + "type": "object", + "additionalProperties": true + }, + "dependencies": { + "$ref": "#/definitions/dependency" + }, + "devDependencies": { + "$ref": "#/definitions/dependency" + }, + "optionalDependencies": { + "$ref": "#/definitions/dependency" + }, + "peerDependencies": { + "$ref": "#/definitions/dependency" + }, + "peerDependenciesMeta": { + "description": "When a user installs your package, warnings are emitted if packages specified in \"peerDependencies\" are not already installed. The \"peerDependenciesMeta\" field serves to provide more information on how your peer dependencies are utilized. Most commonly, it allows peer dependencies to be marked as optional. Metadata for this field is specified with a simple hash of the package name to a metadata object.", + "type": "object", + "additionalProperties": { + "type": "object", + "additionalProperties": true, + "properties": { + "optional": { + "description": "Specifies that this peer dependency is optional and should not be installed automatically.", + "type": "boolean" + } + } + } + }, + "bundledDependencies": { + "description": "Array of package names that will be bundled when publishing the package.", + "oneOf": [ + { + "type": "array", + "items": { + "type": "string" + } + }, + { + "type": "boolean" + } + ] + }, + "bundleDependencies": { + "description": "DEPRECATED: This field is honored, but \"bundledDependencies\" is the correct field name.", + "oneOf": [ + { + "type": "array", + "items": { + "type": "string" + } + }, + { + "type": "boolean" + } + ] + }, + "trustedDependencies": { + "description": "Array of package names that are trusted to run lifecycle scripts, such as 'postinstall'.", + "type": "array", + "items": { + "type": "string" + } + }, + "resolutions": { + "description": "Resolutions is used to support selective version resolutions using yarn, which lets you define custom package versions or ranges inside your dependencies. For npm, use overrides instead. See: https://classic.yarnpkg.com/en/docs/selective-version-resolutions", + "type": "object" + }, + "overrides": { + "description": "Overrides is used to support selective version overrides using npm, which lets you define custom package versions or ranges inside your dependencies. For yarn, use resolutions instead. See: https://docs.npmjs.com/cli/v9/configuring-npm/package-json#overrides", + "type": "object" + }, + "packageManager": { + "description": "Defines which package manager is expected to be used when working on the current project. This field is currently experimental and needs to be opted-in; see https://nodejs.org/api/corepack.html", + "type": "string", + "pattern": "(bun|npm|pnpm|yarn)@\\d+\\.\\d+\\.\\d+(-.+)?" + }, + "engines": { + "type": "object", + "properties": { + "node": { + "type": "string" + } + }, + "additionalProperties": { + "type": "string" + } + }, + "engineStrict": { + "type": "boolean" + }, + "os": { + "description": "Specify which operating systems your module will run on.", + "type": "array", + "items": { + "type": "string" + } + }, + "cpu": { + "description": "Specify that your code only runs on certain cpu architectures.", + "type": "array", + "items": { + "type": "string" + } + }, + "preferGlobal": { + "type": "boolean", + "description": "DEPRECATED: This option used to trigger an npm warning, but it will no longer warn. It is purely there for informational purposes. It is now recommended that you install any binaries as local devDependencies wherever possible." + }, + "private": { + "description": "If set to true, then npm will refuse to publish it.", + "oneOf": [ + { + "type": "boolean" + }, + { + "enum": [ + "false", + "true" + ] + } + ] + }, + "publishConfig": { + "type": "object", + "properties": { + "access": { + "type": "string", + "enum": [ + "public", + "restricted" + ] + }, + "tag": { + "type": "string" + }, + "registry": { + "type": "string", + "format": "uri" + } + }, + "additionalProperties": true + }, + "dist": { + "type": "object", + "properties": { + "shasum": { + "type": "string" + }, + "tarball": { + "type": "string" + } + } + }, + "readme": { + "type": "string" + }, + "module": { + "description": "An ECMAScript module ID that is the primary entry point to your program.", + "type": "string" + }, + "esnext": { + "description": "A module ID with untranspiled code that is the primary entry point to your program.", + "type": [ + "string", + "object" + ], + "properties": { + "main": { + "type": "string" + }, + "browser": { + "type": "string" + } + }, + "additionalProperties": { + "type": "string" + } + }, + "workspaces": { + "description": "Allows packages within a directory to depend on one another using direct linking of local files. Additionally, dependencies within a workspace are hoisted to the workspace root when possible to reduce duplication. Note: It's also a good idea to set \"private\" to true when using this feature.", + "anyOf": [ + { + "type": "array", + "description": "Workspace package paths. Glob patterns are supported.", + "items": { + "type": "string" + } + }, + { + "type": "object", + "properties": { + "packages": { + "type": "array", + "description": "Workspace package paths. Glob patterns are supported.", + "items": { + "type": "string" + } + }, + "nohoist": { + "type": "array", + "description": "Packages to block from hoisting to the workspace root. Currently only supported in Yarn only.", + "items": { + "type": "string" + } + } + } + } + ] + }, + "jspm": { + "$ref": "#" + }, + "eslintConfig": { + "$ref": "https://json.schemastore.org/eslintrc.json" + }, + "prettier": { + "$ref": "https://json.schemastore.org/prettierrc.json" + }, + "stylelint": { + "$ref": "https://json.schemastore.org/stylelintrc.json" + }, + "ava": { + "$ref": "https://json.schemastore.org/ava.json" + }, + "release": { + "$ref": "https://json.schemastore.org/semantic-release.json" + }, + "jscpd": { + "$ref": "https://json.schemastore.org/jscpd.json" + } + }, + "anyOf": [ + { + "type": "object", + "not": { + "required": [ + "bundledDependencies", + "bundleDependencies" + ] + } + }, + { + "type": "object", + "not": { + "required": [ + "bundleDependencies" + ] + }, + "required": [ + "bundledDependencies" + ] + }, + { + "type": "object", + "not": { + "required": [ + "bundledDependencies" + ] + }, + "required": [ + "bundleDependencies" + ] + } + ] +} diff --git a/packages/bun-vscode/bun.lockb b/packages/bun-vscode/bun.lockb index c0949dd2d..599310c25 100755 Binary files a/packages/bun-vscode/bun.lockb and b/packages/bun-vscode/bun.lockb differ diff --git a/packages/bun-vscode/example/.vscode/launch.json b/packages/bun-vscode/example/.vscode/launch.json deleted file mode 100644 index 7ab446fad..000000000 --- a/packages/bun-vscode/example/.vscode/launch.json +++ /dev/null @@ -1,18 +0,0 @@ -{ - "version": "0.2.0", - "configurations": [ - { - "type": "bun", - "request": "launch", - "name": "Debug Bun", - "program": "${file}", - "watch": "hot" - }, - { - "type": "bun", - "request": "attach", - "name": "Attach to Bun", - "url": "ws://localhost:6499/", - } - ] -} diff --git a/packages/bun-vscode/example/bun.lockb b/packages/bun-vscode/example/bun.lockb index b6516d9ed..7153db03e 100755 Binary files a/packages/bun-vscode/example/bun.lockb and b/packages/bun-vscode/example/bun.lockb differ diff --git a/packages/bun-vscode/example/example-sourcemap.js b/packages/bun-vscode/example/example-sourcemap.js deleted file mode 100644 index 82035bedb..000000000 --- a/packages/bun-vscode/example/example-sourcemap.js +++ /dev/null @@ -1,30 +0,0 @@ -// @bun -// example.ts -var a = function (request) { - b(request); -}; -var b = function (request) { - c(request); -}; -var c = function (request) { - console.log(request); -}; -var example_default = { - async fetch(request, server) { - a(request); - const coolThing = new SuperCoolThing(); - coolThing.doCoolThing(); - debugger; - return new Response(request.url); - }, -}; - -class SuperCoolThing { - doCoolThing() { - console.log("super cool thing!"); - } -} -export { example_default as default }; - -//# debugId=9BB0B773A8E4771564756e2164756e21 -//# sourceMappingURL=data:application/json;base64,ewogICJ2ZXJzaW9uIjogMywKICAic291cmNlcyI6IFsiZXhhbXBsZS50cyJdLAogICJzb3VyY2VzQ29udGVudCI6IFsKICAgICJpbXBvcnQgdHlwZSB7IFNlcnZlciB9IGZyb20gXCJidW5cIjtcblxuZXhwb3J0IGRlZmF1bHQge1xuICBhc3luYyBmZXRjaChyZXF1ZXN0OiBSZXF1ZXN0LCBzZXJ2ZXI6IFNlcnZlcik6IFByb21pc2U8UmVzcG9uc2U+IHtcbiAgICBhKHJlcXVlc3QpO1xuICAgIGNvbnN0IGNvb2xUaGluZzogQ29vbFRoaW5nID0gbmV3IFN1cGVyQ29vbFRoaW5nKCk7XG4gICAgY29vbFRoaW5nLmRvQ29vbFRoaW5nKCk7XG4gICAgZGVidWdnZXI7XG4gICAgcmV0dXJuIG5ldyBSZXNwb25zZShyZXF1ZXN0LnVybCk7XG4gIH1cbn07XG5cbi8vIGFcbmZ1bmN0aW9uIGEocmVxdWVzdDogUmVxdWVzdCk6IHZvaWQge1xuICBiKHJlcXVlc3QpO1xufVxuXG4vLyBiXG5mdW5jdGlvbiBiKHJlcXVlc3Q6IFJlcXVlc3QpOiB2b2lkIHtcbiAgYyhyZXF1ZXN0KTtcbn1cblxuLy8gY1xuZnVuY3Rpb24gYyhyZXF1ZXN0OiBSZXF1ZXN0KSB7XG4gIGNvbnNvbGUubG9nKHJlcXVlc3QpO1xufVxuXG5pbnRlcmZhY2UgQ29vbFRoaW5nIHtcbiAgZG9Db29sVGhpbmcoKTogdm9pZDtcbn1cblxuY2xhc3MgU3VwZXJDb29sVGhpbmcgaW1wbGVtZW50cyBDb29sVGhpbmcge1xuICBkb0Nvb2xUaGluZygpOiB2b2lkIHtcbiAgICBjb25zb2xlLmxvZyhcInN1cGVyIGNvb2wgdGhpbmchXCIpO1xuICB9XG59XG4iCiAgXSwKICAibWFwcGluZ3MiOiAiOztBQS8vLy8vZkFhQSxJQUFTLFlBQUMsQ0FBQyxTQUF3QjtBQUNqQyxJQUFFLE9BQU87QUFBQTtBQUlYLElBQVMsWUFBQyxDQUFDLFNBQXdCO0FBQ2pDLElBQUUsT0FBTztBQUFBO0FBSVgsSUFBUyxZQUFDLENBQUMsU0FBa0I7QUFDM0IsVUFBUSxJQUFJLE9BQU87QUFBQTtBQXRCckIsSUFBZTtBQUFBLE9BQ1AsTUFBSyxDQUFDLFNBQWtCLFFBQW1DO0FBQy9ELE1BQUUsT0FBTztBQUNULFVBQU0sWUFBdUIsSUFBSTtBQUNqQyxjQUFVLFlBQVk7QUFDdEI7QUFDQSxXQUFPLElBQUksU0FBUyxRQUFRLEdBQUc7QUFBQTtBQUVuQztBQXFCQTtBQUFBLE1BQU0sZUFBb0M7QUFBQSxFQUN4QyxXQUFXLEdBQVM7QUFDbEIsWUFBUSxJQUFJLG1CQUFtQjtBQUFBO0FBRW5DOyIsCiAgImRlYnVnSWQiOiAiOUJCMEI3NzNBOEU0NzcxNTY0NzU2ZTIxNjQ3NTZlMjEiLAogICJuYW1lcyI6IFtdCn0= diff --git a/packages/bun-vscode/example/example.js b/packages/bun-vscode/example/example.js deleted file mode 100644 index 31831824b..000000000 --- a/packages/bun-vscode/example/example.js +++ /dev/null @@ -1,63 +0,0 @@ -// @bun -const express = import.meta.require("express"); -const app = express(); -import { readFile } from "node:fs/promises"; - -app - .get("/", (req, res) => { - console.log("I am logging a request!??"); - readFile(import.meta.path, "utf-8").then(data => { - console.log(data.length); - debugger; - res.send("hello world"); - }); - }) - .listen(3000); - -const va = 1; -let vb = 2; -var vc = 3; - -function fa() { - fb(); -} - -function fb() { - fc(); -} - -function fc() { - fd(); -} - -function fd() { - let map = new Map([ - [1, 2], - [2, 3], - [3, 4], - ]); - let set = new Set([1, 2, 3, 4, 5]); - let arr = [1, 2, 3, 4, 5]; - let obj = { - a: 1, - b: 2, - c: 3, - }; - function fd1() { - let date = new Date(); - console.log(new Error().stack); - debugger; - console.log(date); - } - fd1(); -} - -Bun.serve({ - port: 9229, - inspector: true, - development: true, - fetch(request, server) { - // console.log(request); - return new Response(request.url); - }, -}); diff --git a/packages/bun-vscode/example/example.test.ts b/packages/bun-vscode/example/example.test.ts new file mode 100644 index 000000000..a9da929eb --- /dev/null +++ b/packages/bun-vscode/example/example.test.ts @@ -0,0 +1,11 @@ +import { describe, test, expect } from "bun:test"; + +describe("example", () => { + test("it works", () => { + expect(1).toBe(1); + expect(1).not.toBe(2); + expect(() => { + throw new Error("error"); + }).toThrow(); + }); +}); diff --git a/packages/bun-vscode/example/example.ts b/packages/bun-vscode/example/example.ts index 386b97f7c..536852902 100644 --- a/packages/bun-vscode/example/example.ts +++ b/packages/bun-vscode/example/example.ts @@ -4,7 +4,7 @@ export default { const coolThing: CoolThing = new SuperCoolThing(); coolThing.doCoolThing(); debugger; - return new Response("HELLO WORLD"); + return new Response("BAI BAI"); }, }; diff --git a/packages/bun-vscode/example/package.json b/packages/bun-vscode/example/package.json index 0d7d79529..602fba159 100644 --- a/packages/bun-vscode/example/package.json +++ b/packages/bun-vscode/example/package.json @@ -1,4 +1,6 @@ { + "private": true, + "name": "example", "dependencies": { "elysia": "^0.6.3", "express": "^4.18.2", @@ -7,5 +9,11 @@ }, "trustedDependencies": [ "mime" - ] -} + ], + "devDependencies": { + "bun-types": "latest" + }, + "peerDependencies": { + "typescript": "^5.0.0" + } +} \ No newline at end of file diff --git a/packages/bun-vscode/example/tsconfig.json b/packages/bun-vscode/example/tsconfig.json new file mode 100644 index 000000000..1449bc3d9 --- /dev/null +++ b/packages/bun-vscode/example/tsconfig.json @@ -0,0 +1,22 @@ +{ + "compilerOptions": { + "lib": ["ESNext"], + "module": "esnext", + "target": "esnext", + "moduleResolution": "bundler", + "moduleDetection": "force", + "allowImportingTsExtensions": true, + "noEmit": true, + "composite": true, + "strict": true, + "downlevelIteration": true, + "skipLibCheck": true, + "jsx": "preserve", + "allowSyntheticDefaultImports": true, + "forceConsistentCasingInFileNames": true, + "allowJs": true, + "types": [ + "bun-types" // add Bun global + ] + } +} diff --git a/packages/bun-vscode/package.json b/packages/bun-vscode/package.json index c959cd8ab..985730196 100644 --- a/packages/bun-vscode/package.json +++ b/packages/bun-vscode/package.json @@ -7,18 +7,14 @@ "url": "https://github.com/oven-sh/bun" }, "main": "dist/extension.js", - "dependencies": { - "semver": "^7.5.4", - "source-map-js": "^1.0.2", - "ws": "^8.13.0" - }, "devDependencies": { "@types/vscode": "^1.81.0", "@vscode/debugadapter": "^1.56.0", "@vscode/debugadapter-testsupport": "^1.56.0", + "@vscode/vsce": "^2.20.1", "bun-types": "^0.7.3", - "typescript": "^5.0.0", - "esbuild": "^0.19.2" + "esbuild": "^0.19.2", + "typescript": "^5.0.0" }, "activationEvents": [ "onLanguage:javascript", @@ -59,14 +55,16 @@ "commands": [ { "command": "extension.bun.runFile", - "title": "Run File", + "title": "Run Bun", + "shortTitle": "Run", "category": "Bun", "enablement": "!inDebugMode", "icon": "$(play)" }, { "command": "extension.bun.debugFile", - "title": "Debug File", + "title": "Debug Bun", + "shortTitle": "Debug", "category": "Bun", "enablement": "!inDebugMode", "icon": "$(debug-alt)" @@ -169,6 +167,11 @@ false, "hot" ], + "default": false + }, + "debug": { + "type": "boolean", + "description": "If the process should be started in debug mode.", "default": true } } @@ -177,48 +180,11 @@ "properties": { "url": { "type": "string", - "description": "The URL of the Bun process to attach to.", - "default": "ws://localhost:6499/" + "description": "The URL of the Bun process to attach to." } } } - }, - "initialConfigurations": [ - { - "type": "bun", - "request": "launch", - "name": "Bun: Debug", - "program": "${file}" - }, - { - "type": "bun", - "request": "attach", - "name": "Bun: Attach", - "url": "ws://localhost:6499/" - } - ], - "configurationSnippets": [ - { - "label": "Bun: Debug", - "description": "A new configuration for 'debugging' a Bun process.", - "body": { - "type": "bun", - "request": "launch", - "name": "Ask for file name", - "program": "^\"\\${file}\"" - } - }, - { - "label": "Bun: Attach", - "description": "A new configuration for 'attaching' to a running Bun process.", - "body": { - "type": "bun", - "request": "attach", - "name": "Attach to Bun", - "url": "ws://localhost:6499/" - } - } - ] + } } ], "languages": [ @@ -231,15 +197,15 @@ ".lockb" ], "icon": { - "dark": "src/assets/icon-small.png", - "light": "src/assets/icon-small.png" + "dark": "assets/icon-small.png", + "light": "assets/icon-small.png" } } ], "jsonValidation": [ { "fileMatch": "package.json", - "url": "src/resources/package.json" + "url": "assets/package.json" } ], "customEditors": [ @@ -268,7 +234,7 @@ "theme": "dark" }, "homepage": "https://bun.sh/", - "icon": "src/assets/icon.png", + "icon": "assets/icon.png", "keywords": [ "bun", "node.js", @@ -279,10 +245,8 @@ "license": "MIT", "publisher": "oven", "scripts": { - "bundle": "./node_modules/.bin/esbuild src/extension.ts src/web-extension.ts --bundle --external:vscode --outdir=dist --platform=node --format=cjs", - "prebuild": "bun run bundle && rm -rf extension && mkdir -p extension/src && cp -r dist extension/dist && cp -r src/assets extension/src/assets && cp package.json extension && cp README.md extension", - "build": "cd extension && vsce package", - "build:watch": "./node_modules/.bin/esbuild --watch src/extension.ts src/web-extension.ts --bundle --external:vscode --outdir=dist --platform=node --format=cjs" + "build": "node scripts/build.mjs", + "test": "node scripts/test.mjs" }, "workspaceTrust": { "request": "never" diff --git a/packages/bun-vscode/scripts/build.mjs b/packages/bun-vscode/scripts/build.mjs new file mode 100644 index 000000000..261965840 --- /dev/null +++ b/packages/bun-vscode/scripts/build.mjs @@ -0,0 +1,29 @@ +import { buildSync } from "esbuild"; +import { rmSync, mkdirSync, cpSync } from "node:fs"; +import { spawnSync } from "node:child_process"; + +const { pathname } = new URL("..", import.meta.url); +process.chdir(pathname); + +buildSync({ + entryPoints: ["src/extension.ts", "src/web-extension.ts"], + outdir: "dist", + bundle: true, + external: ["vscode"], + platform: "node", + format: "cjs", +}); + +rmSync("extension", { recursive: true, force: true }); +mkdirSync("extension", { recursive: true }); +cpSync("dist", "extension/dist", { recursive: true }); +cpSync("assets", "extension/assets", { recursive: true }); +cpSync("README.md", "extension/README.md"); +cpSync("LICENSE", "extension/LICENSE"); +cpSync("package.json", "extension/package.json"); + +const cmd = process.isBun ? "bunx" : "npx"; +spawnSync(cmd, ["vsce", "package"], { + cwd: "extension", + stdio: "inherit", +}); diff --git a/packages/bun-vscode/scripts/test.mjs b/packages/bun-vscode/scripts/test.mjs new file mode 100644 index 000000000..6e890c420 --- /dev/null +++ b/packages/bun-vscode/scripts/test.mjs @@ -0,0 +1,21 @@ +import { readdirSync } from "node:fs"; +import { spawn } from "node:child_process"; + +const { pathname } = new URL("..", import.meta.url); +process.chdir(pathname); + +let path; +for (const filename of readdirSync("extension")) { + if (filename.endsWith(".vsix")) { + path = `extension/${filename}`; + break; + } +} + +if (!path) { + throw new Error("No .vsix file found"); +} + +spawn("code", ["--new-window", `--install-extension=${path}`, `--extensionDevelopmentPath=${pathname}`, "example"], { + stdio: "inherit", +}); diff --git a/packages/bun-vscode/src/assets/icon-small.png b/packages/bun-vscode/src/assets/icon-small.png deleted file mode 100644 index 69bc385e8..000000000 Binary files a/packages/bun-vscode/src/assets/icon-small.png and /dev/null differ diff --git a/packages/bun-vscode/src/assets/icon.png b/packages/bun-vscode/src/assets/icon.png deleted file mode 100644 index 29cda9124..000000000 Binary files a/packages/bun-vscode/src/assets/icon.png and /dev/null differ diff --git a/packages/bun-vscode/src/features/debug.ts b/packages/bun-vscode/src/features/debug.ts index 3b841ea66..eae2b1c33 100644 --- a/packages/bun-vscode/src/features/debug.ts +++ b/packages/bun-vscode/src/features/debug.ts @@ -3,13 +3,15 @@ import type { CancellationToken, DebugConfiguration, ProviderResult, WorkspaceFo import type { DAP } from "../../../bun-debug-adapter-protocol"; import { DebugAdapter } from "../../../bun-debug-adapter-protocol"; import { DebugSession } from "@vscode/debugadapter"; +import { inspect } from "node:util"; +import { tmpdir } from "node:os"; const debugConfiguration: vscode.DebugConfiguration = { type: "bun", request: "launch", name: "Debug Bun", program: "${file}", - watch: true, + watch: false, }; const runConfiguration: vscode.DebugConfiguration = { @@ -17,117 +19,131 @@ const runConfiguration: vscode.DebugConfiguration = { request: "launch", name: "Run Bun", program: "${file}", - watch: true, + debug: false, + watch: false, }; const attachConfiguration: vscode.DebugConfiguration = { type: "bun", request: "attach", - name: "Attach to Bun", + name: "Attach Bun", url: "ws://localhost:6499/", }; -const debugConfigurations: vscode.DebugConfiguration[] = [debugConfiguration, attachConfiguration]; +let channels: Record = {}; +let terminal: TerminalDebugSession | undefined; export default function (context: vscode.ExtensionContext, factory?: vscode.DebugAdapterDescriptorFactory) { context.subscriptions.push( - vscode.commands.registerCommand("extension.bun.runFile", (resource: vscode.Uri) => { - let targetResource = resource; - if (!targetResource && vscode.window.activeTextEditor) { - targetResource = vscode.window.activeTextEditor.document.uri; - } - if (targetResource) { - vscode.debug.startDebugging(undefined, runConfiguration, { - noDebug: true, - }); - } - }), - vscode.commands.registerCommand("extension.bun.debugFile", (resource: vscode.Uri) => { - let targetResource = resource; - if (!targetResource && vscode.window.activeTextEditor) { - targetResource = vscode.window.activeTextEditor.document.uri; - } - if (targetResource) { - vscode.debug.startDebugging(undefined, { - ...debugConfiguration, - program: targetResource.fsPath, - }); - } - }), - ); - - const provider = new BunConfigurationProvider(); - context.subscriptions.push(vscode.debug.registerDebugConfigurationProvider("bun", provider)); - - context.subscriptions.push( + vscode.commands.registerCommand("extension.bun.runFile", RunFileCommand), + vscode.commands.registerCommand("extension.bun.debugFile", DebugFileCommand), vscode.debug.registerDebugConfigurationProvider( "bun", - { - provideDebugConfigurations(folder: WorkspaceFolder | undefined): ProviderResult { - return debugConfigurations; - }, - }, + new DebugConfigurationProvider(), + vscode.DebugConfigurationProviderTriggerKind.Initial, + ), + vscode.debug.registerDebugConfigurationProvider( + "bun", + new DebugConfigurationProvider(), vscode.DebugConfigurationProviderTriggerKind.Dynamic, ), + vscode.debug.registerDebugAdapterDescriptorFactory("bun", factory ?? new InlineDebugAdapterFactory()), + (channels["dap"] = vscode.window.createOutputChannel("Debug Adapter Protocol (Bun)")), + (channels["jsc"] = vscode.window.createOutputChannel("JavaScript Inspector (Bun)")), + (channels["console"] = vscode.window.createOutputChannel("Console (Bun)")), + (terminal = new TerminalDebugSession()), ); +} - if (!factory) { - factory = new InlineDebugAdapterFactory(); +function RunFileCommand(resource?: vscode.Uri): void { + const path = getCurrentPath(resource); + if (path) { + vscode.debug.startDebugging(undefined, { + ...runConfiguration, + noDebug: true, + program: path, + }); } - context.subscriptions.push(vscode.debug.registerDebugAdapterDescriptorFactory("bun", factory)); - if ("dispose" in factory && typeof factory.dispose === "function") { - // @ts-ignore - context.subscriptions.push(factory); +} + +function DebugFileCommand(resource?: vscode.Uri): void { + const path = getCurrentPath(resource); + if (path) { + vscode.debug.startDebugging(undefined, { + ...debugConfiguration, + program: path, + }); } } -class BunConfigurationProvider implements vscode.DebugConfigurationProvider { +class DebugConfigurationProvider implements vscode.DebugConfigurationProvider { + provideDebugConfigurations(folder: WorkspaceFolder | undefined): ProviderResult { + return [debugConfiguration, runConfiguration, attachConfiguration]; + } + resolveDebugConfiguration( folder: WorkspaceFolder | undefined, config: DebugConfiguration, token?: CancellationToken, ): ProviderResult { - if (!config.type && !config.request && !config.name) { - const editor = vscode.window.activeTextEditor; - if (editor && isJavaScript(editor.document.languageId)) { - Object.assign(config, debugConfiguration); + let target: DebugConfiguration; + + const { request } = config; + if (request === "attach") { + target = attachConfiguration; + } else { + target = debugConfiguration; + } + + for (const [key, value] of Object.entries(target)) { + if (config[key] === undefined) { + config[key] = value; } } + return config; } } class InlineDebugAdapterFactory implements vscode.DebugAdapterDescriptorFactory { - createDebugAdapterDescriptor(_session: vscode.DebugSession): ProviderResult { - const adapter = new VSCodeAdapter(_session); + createDebugAdapterDescriptor(session: vscode.DebugSession): ProviderResult { + const { configuration } = session; + const { request, url } = configuration; + + if (request === "attach" && url === terminal?.url) { + return new vscode.DebugAdapterInlineImplementation(terminal); + } + + const adapter = new FileDebugSession(session.id); return new vscode.DebugAdapterInlineImplementation(adapter); } } -function isJavaScript(languageId: string): boolean { - return ( - languageId === "javascript" || - languageId === "javascriptreact" || - languageId === "typescript" || - languageId === "typescriptreact" - ); -} +class FileDebugSession extends DebugSession { + readonly url: string; + readonly adapter: DebugAdapter; -export class VSCodeAdapter extends DebugSession { - #adapter: DebugAdapter; - #dap: vscode.OutputChannel; - - constructor(session: vscode.DebugSession) { + constructor(sessionId?: string) { super(); - this.#dap = vscode.window.createOutputChannel("Debug Adapter Protocol"); - this.#adapter = new DebugAdapter({ - sendToAdapter: this.sendMessage.bind(this), + const uniqueId = sessionId ?? Math.random().toString(36).slice(2); + this.url = `ws+unix://${tmpdir()}/bun-vscode-${uniqueId}.sock`; + this.adapter = new DebugAdapter({ + url: this.url, + send: this.sendMessage.bind(this), + logger(...messages) { + log("jsc", ...messages); + }, + stdout(message) { + log("console", message); + }, + stderr(message) { + log("console", message); + }, }); } sendMessage(message: DAP.Request | DAP.Response | DAP.Event): void { - console.log("[dap] -->", message); - this.#dap.appendLine("--> " + JSON.stringify(message)); + log("dap", "-->", message); const { type } = message; if (type === "response") { @@ -140,14 +156,59 @@ export class VSCodeAdapter extends DebugSession { } handleMessage(message: DAP.Event | DAP.Request | DAP.Response): void { - console.log("[dap] <--", message); - this.#dap.appendLine("<-- " + JSON.stringify(message)); + log("dap", "<--", message); - this.#adapter.accept(message); + this.adapter.accept(message); } dispose() { - this.#adapter.close(); - this.#dap.dispose(); + this.adapter.close(); + } +} + +class TerminalDebugSession extends FileDebugSession { + readonly terminal: vscode.Terminal; + + constructor() { + super(); + this.terminal = vscode.window.createTerminal({ + name: "Bun Terminal", + env: { + "BUN_INSPECT": `1${this.url}`, + "BUN_INSPECT_NOTIFY": `unix://${this.adapter.inspector.unix}`, + }, + isTransient: true, + iconPath: new vscode.ThemeIcon("debug-console"), + }); + this.terminal.show(); + this.adapter.inspector.startDebugging = () => { + vscode.debug.startDebugging(undefined, { + ...attachConfiguration, + url: this.url, + }); + }; + } +} + +function log(channel: string, ...message: unknown[]): void { + if (process.env.NODE_ENV === "development") { + console.log(`[${channel}]`, ...message); + channels[channel]?.appendLine(message.map(v => inspect(v)).join(" ")); + } +} + +function isJavaScript(languageId: string): boolean { + return ( + languageId === "javascript" || + languageId === "javascriptreact" || + languageId === "typescript" || + languageId === "typescriptreact" + ); +} + +function getCurrentPath(target?: vscode.Uri): string | undefined { + if (!target && vscode.window.activeTextEditor) { + target = vscode.window.activeTextEditor.document.uri; } + return target?.fsPath; } diff --git a/packages/bun-vscode/src/resources/package.json b/packages/bun-vscode/src/resources/package.json deleted file mode 100644 index 021c8125e..000000000 --- a/packages/bun-vscode/src/resources/package.json +++ /dev/null @@ -1,848 +0,0 @@ -{ - "$schema": "http://json-schema.org/draft-04/schema#", - "title": "JSON schema for Bun package.json files.", - "definitions": { - "person": { - "description": "A person who has been involved in creating or maintaining this package.", - "type": [ - "object", - "string" - ], - "required": [ - "name" - ], - "properties": { - "name": { - "type": "string" - }, - "url": { - "type": "string", - "format": "uri" - }, - "email": { - "type": "string", - "format": "email" - } - } - }, - "dependency": { - "description": "Dependencies are specified with a simple hash of package name to version range. The version range is a string which has one or more space-separated descriptors. Dependencies can also be identified with a tarball or git URL.", - "type": "object", - "additionalProperties": { - "type": "string" - } - }, - "license": { - "anyOf": [ - { - "type": "string" - }, - { - "enum": [ - "Apache-2.0", - "MIT", - "ISC", - "BSD-3-Clause", - "BSD-2-Clause", - "CC0-1.0", - "CDDL-1.1", - "LGPL-2.1-only", - "LGPL-2.1-or-later", - "LGPL-3.0-only", - "LGPL-3.0-or-later", - "EPL-1.0", - "EPL-2.0", - "MS-PL", - "UNLICENSED" - ] - } - ] - }, - "scriptsInstallAfter": { - "description": "Run AFTER the package is installed.", - "type": "string", - "x-intellij-language-injection": "Shell Script" - }, - "scriptsPublishAfter": { - "description": "Run AFTER the package is published.", - "type": "string", - "x-intellij-language-injection": "Shell Script" - }, - "scriptsRestart": { - "description": "Run by the 'npm restart' command. Note: 'npm restart' will run the stop and start scripts if no restart script is provided.", - "type": "string", - "x-intellij-language-injection": "Shell Script" - }, - "scriptsStart": { - "description": "Run by the 'npm start' command.", - "type": "string", - "x-intellij-language-injection": "Shell Script" - }, - "scriptsStop": { - "description": "Run by the 'npm stop' command.", - "type": "string", - "x-intellij-language-injection": "Shell Script" - }, - "scriptsTest": { - "description": "Run by the 'npm test' command.", - "type": "string", - "x-intellij-language-injection": "Shell Script" - }, - "scriptsUninstallBefore": { - "description": "Run BEFORE the package is uninstalled.", - "type": "string", - "x-intellij-language-injection": "Shell Script" - }, - "scriptsVersionBefore": { - "description": "Run BEFORE bump the package version.", - "type": "string", - "x-intellij-language-injection": "Shell Script" - }, - "packageExportsEntryPath": { - "type": [ - "string", - "null" - ], - "description": "The module path that is resolved when this specifier is imported. Set to `null` to disallow importing this module.", - "pattern": "^\\./" - }, - "packageExportsEntryObject": { - "type": "object", - "description": "Used to specify conditional exports, note that Conditional exports are unsupported in older environments, so it's recommended to use the fallback array option if support for those environments is a concern.", - "properties": { - "require": { - "$ref": "#/definitions/packageExportsEntryOrFallback", - "description": "The module path that is resolved when this specifier is imported as a CommonJS module using the `require(...)` function." - }, - "import": { - "$ref": "#/definitions/packageExportsEntryOrFallback", - "description": "The module path that is resolved when this specifier is imported as an ECMAScript module using an `import` declaration or the dynamic `import(...)` function." - }, - "node": { - "$ref": "#/definitions/packageExportsEntryOrFallback", - "description": "The module path that is resolved when this environment is Node.js." - }, - "default": { - "$ref": "#/definitions/packageExportsEntryOrFallback", - "description": "The module path that is resolved when no other export type matches." - }, - "types": { - "$ref": "#/definitions/packageExportsEntryOrFallback", - "description": "The module path that is resolved for TypeScript types when this specifier is imported. Should be listed before other conditions." - } - }, - "patternProperties": { - "^(?![\\.0-9]).": { - "$ref": "#/definitions/packageExportsEntryOrFallback", - "description": "The module path that is resolved when this environment matches the property name." - } - }, - "additionalProperties": false - }, - "packageExportsEntry": { - "oneOf": [ - { - "$ref": "#/definitions/packageExportsEntryPath" - }, - { - "$ref": "#/definitions/packageExportsEntryObject" - } - ] - }, - "packageExportsFallback": { - "type": "array", - "description": "Used to allow fallbacks in case this environment doesn't support the preceding entries.", - "items": { - "$ref": "#/definitions/packageExportsEntry" - } - }, - "packageExportsEntryOrFallback": { - "oneOf": [ - { - "$ref": "#/definitions/packageExportsEntry" - }, - { - "$ref": "#/definitions/packageExportsFallback" - } - ] - }, - "fundingUrl": { - "type": "string", - "format": "uri", - "description": "URL to a website with details about how to fund the package." - }, - "fundingWay": { - "type": "object", - "description": "Used to inform about ways to help fund development of the package.", - "properties": { - "url": { - "$ref": "#/definitions/fundingUrl" - }, - "type": { - "type": "string", - "description": "The type of funding or the platform through which funding can be provided, e.g. patreon, opencollective, tidelift or github." - } - }, - "additionalProperties": false, - "required": [ - "url" - ] - } - }, - "type": "object", - "patternProperties": { - "^_": { - "description": "Any property starting with _ is valid.", - "tsType": "any" - } - }, - "properties": { - "name": { - "description": "The name of the package.", - "type": "string", - "maxLength": 214, - "minLength": 1, - "pattern": "^(?:@(?:[a-z0-9-*~][a-z0-9-*._~]*)?/)?[a-z0-9-~][a-z0-9-._~]*$" - }, - "version": { - "description": "Version must be parseable by node-semver, which is bundled with npm as a dependency.", - "type": "string" - }, - "description": { - "description": "This helps people discover your package, as it's listed in 'npm search'.", - "type": "string" - }, - "keywords": { - "description": "This helps people discover your package as it's listed in 'npm search'.", - "type": "array", - "items": { - "type": "string" - } - }, - "homepage": { - "description": "The url to the project homepage.", - "type": "string" - }, - "bugs": { - "description": "The url to your project's issue tracker and / or the email address to which issues should be reported. These are helpful for people who encounter issues with your package.", - "type": [ - "object", - "string" - ], - "properties": { - "url": { - "type": "string", - "description": "The url to your project's issue tracker.", - "format": "uri" - }, - "email": { - "type": "string", - "description": "The email address to which issues should be reported.", - "format": "email" - } - } - }, - "license": { - "$ref": "#/definitions/license", - "description": "You should specify a license for your package so that people know how they are permitted to use it, and any restrictions you're placing on it." - }, - "licenses": { - "description": "DEPRECATED: Instead, use SPDX expressions, like this: { \"license\": \"ISC\" } or { \"license\": \"(MIT OR Apache-2.0)\" } see: 'https://docs.npmjs.com/files/package.json#license'.", - "type": "array", - "items": { - "type": "object", - "properties": { - "type": { - "$ref": "#/definitions/license" - }, - "url": { - "type": "string", - "format": "uri" - } - } - } - }, - "author": { - "$ref": "#/definitions/person" - }, - "contributors": { - "description": "A list of people who contributed to this package.", - "type": "array", - "items": { - "$ref": "#/definitions/person" - } - }, - "maintainers": { - "description": "A list of people who maintains this package.", - "type": "array", - "items": { - "$ref": "#/definitions/person" - } - }, - "files": { - "description": "The 'files' field is an array of files to include in your project. If you name a folder in the array, then it will also include the files inside that folder.", - "type": "array", - "items": { - "type": "string" - } - }, - "main": { - "description": "The main field is a module ID that is the primary entry point to your program.", - "type": "string" - }, - "exports": { - "description": "The \"exports\" field is used to restrict external access to non-exported module files, also enables a module to import itself using \"name\".", - "oneOf": [ - { - "$ref": "#/definitions/packageExportsEntryPath", - "description": "The module path that is resolved when the module specifier matches \"name\", shadows the \"main\" field." - }, - { - "type": "object", - "properties": { - ".": { - "$ref": "#/definitions/packageExportsEntryOrFallback", - "description": "The module path that is resolved when the module specifier matches \"name\", shadows the \"main\" field." - } - }, - "patternProperties": { - "^\\./.+": { - "$ref": "#/definitions/packageExportsEntryOrFallback", - "description": "The module path prefix that is resolved when the module specifier starts with \"name/\", set to \"./*\" to allow external modules to import any subpath." - } - }, - "additionalProperties": false - }, - { - "$ref": "#/definitions/packageExportsEntryObject", - "description": "The module path that is resolved when the module specifier matches \"name\", shadows the \"main\" field." - }, - { - "$ref": "#/definitions/packageExportsFallback", - "description": "The module path that is resolved when the module specifier matches \"name\", shadows the \"main\" field." - } - ] - }, - "bin": { - "type": [ - "string", - "object" - ], - "additionalProperties": { - "type": "string" - } - }, - "type": { - "description": "When set to \"module\", the type field allows a package to specify all .js files within are ES modules. If the \"type\" field is omitted or set to \"commonjs\", all .js files are treated as CommonJS.", - "type": "string", - "enum": [ - "commonjs", - "module" - ], - "default": "commonjs" - }, - "types": { - "description": "Set the types property to point to your bundled declaration file.", - "type": "string" - }, - "typings": { - "description": "Note that the \"typings\" field is synonymous with \"types\", and could be used as well.", - "type": "string" - }, - "typesVersions": { - "description": "The \"typesVersions\" field is used since TypeScript 3.1 to support features that were only made available in newer TypeScript versions.", - "type": "object", - "additionalProperties": { - "description": "Contains overrides for the TypeScript version that matches the version range matching the property key.", - "type": "object", - "properties": { - "*": { - "description": "Maps all file paths to the file paths specified in the array.", - "type": "array", - "items": { - "type": "string", - "pattern": "^[^*]*(?:\\*[^*]*)?$" - } - } - }, - "patternProperties": { - "^[^*]+$": { - "description": "Maps the file path matching the property key to the file paths specified in the array.", - "type": "array", - "items": { - "type": "string" - } - }, - "^[^*]*\\*[^*]*$": { - "description": "Maps file paths matching the pattern specified in property key to file paths specified in the array.", - "type": "array", - "items": { - "type": "string", - "pattern": "^[^*]*(?:\\*[^*]*)?$" - } - } - }, - "additionalProperties": false - } - }, - "man": { - "type": [ - "array", - "string" - ], - "description": "Specify either a single file or an array of filenames to put in place for the man program to find.", - "items": { - "type": "string" - } - }, - "directories": { - "type": "object", - "properties": { - "bin": { - "description": "If you specify a 'bin' directory, then all the files in that folder will be used as the 'bin' hash.", - "type": "string" - }, - "doc": { - "description": "Put markdown files in here. Eventually, these will be displayed nicely, maybe, someday.", - "type": "string" - }, - "example": { - "description": "Put example scripts in here. Someday, it might be exposed in some clever way.", - "type": "string" - }, - "lib": { - "description": "Tell people where the bulk of your library is. Nothing special is done with the lib folder in any way, but it's useful meta info.", - "type": "string" - }, - "man": { - "description": "A folder that is full of man pages. Sugar to generate a 'man' array by walking the folder.", - "type": "string" - }, - "test": { - "type": "string" - } - } - }, - "repository": { - "description": "Specify the place where your code lives. This is helpful for people who want to contribute.", - "type": [ - "object", - "string" - ], - "properties": { - "type": { - "type": "string" - }, - "url": { - "type": "string" - }, - "directory": { - "type": "string" - } - } - }, - "funding": { - "oneOf": [ - { - "$ref": "#/definitions/fundingUrl" - }, - { - "$ref": "#/definitions/fundingWay" - }, - { - "type": "array", - "items": { - "oneOf": [ - { - "$ref": "#/definitions/fundingUrl" - }, - { - "$ref": "#/definitions/fundingWay" - } - ] - }, - "minItems": 1, - "uniqueItems": true - } - ] - }, - "scripts": { - "description": "The 'scripts' member is an object hash of script commands that are run at various times in the lifecycle of your package. The key is the lifecycle event, and the value is the command to run at that point.", - "type": "object", - "properties": { - "lint": { - "type": "string", - "description": "Run code quality tools, e.g. ESLint, TSLint, etc." - }, - "prepublish": { - "type": "string", - "description": "Run BEFORE the package is published (Also run on local npm install without any arguments)." - }, - "prepare": { - "type": "string", - "description": "Run both BEFORE the package is packed and published, and on local npm install without any arguments. This is run AFTER prepublish, but BEFORE prepublishOnly." - }, - "prepublishOnly": { - "type": "string", - "description": "Run BEFORE the package is prepared and packed, ONLY on npm publish." - }, - "prepack": { - "type": "string", - "description": "run BEFORE a tarball is packed (on npm pack, npm publish, and when installing git dependencies)." - }, - "postpack": { - "type": "string", - "description": "Run AFTER the tarball has been generated and moved to its final destination." - }, - "publish": { - "type": "string", - "description": "Publishes a package to the registry so that it can be installed by name. See https://docs.npmjs.com/cli/v8/commands/npm-publish" - }, - "postpublish": { - "$ref": "#/definitions/scriptsPublishAfter" - }, - "preinstall": { - "type": "string", - "description": "Run BEFORE the package is installed." - }, - "install": { - "$ref": "#/definitions/scriptsInstallAfter" - }, - "postinstall": { - "$ref": "#/definitions/scriptsInstallAfter" - }, - "preuninstall": { - "$ref": "#/definitions/scriptsUninstallBefore" - }, - "uninstall": { - "$ref": "#/definitions/scriptsUninstallBefore" - }, - "postuninstall": { - "type": "string", - "description": "Run AFTER the package is uninstalled." - }, - "preversion": { - "$ref": "#/definitions/scriptsVersionBefore" - }, - "version": { - "$ref": "#/definitions/scriptsVersionBefore" - }, - "postversion": { - "type": "string", - "description": "Run AFTER bump the package version." - }, - "pretest": { - "$ref": "#/definitions/scriptsTest" - }, - "test": { - "$ref": "#/definitions/scriptsTest" - }, - "posttest": { - "$ref": "#/definitions/scriptsTest" - }, - "prestop": { - "$ref": "#/definitions/scriptsStop" - }, - "stop": { - "$ref": "#/definitions/scriptsStop" - }, - "poststop": { - "$ref": "#/definitions/scriptsStop" - }, - "prestart": { - "$ref": "#/definitions/scriptsStart" - }, - "start": { - "$ref": "#/definitions/scriptsStart" - }, - "poststart": { - "$ref": "#/definitions/scriptsStart" - }, - "prerestart": { - "$ref": "#/definitions/scriptsRestart" - }, - "restart": { - "$ref": "#/definitions/scriptsRestart" - }, - "postrestart": { - "$ref": "#/definitions/scriptsRestart" - }, - "serve": { - "type": "string", - "description": "Start dev server to serve application files" - } - }, - "additionalProperties": { - "type": "string", - "tsType": "string | undefined", - "x-intellij-language-injection": "Shell Script" - } - }, - "config": { - "description": "A 'config' hash can be used to set configuration parameters used in package scripts that persist across upgrades.", - "type": "object", - "additionalProperties": true - }, - "dependencies": { - "$ref": "#/definitions/dependency" - }, - "devDependencies": { - "$ref": "#/definitions/dependency" - }, - "optionalDependencies": { - "$ref": "#/definitions/dependency" - }, - "peerDependencies": { - "$ref": "#/definitions/dependency" - }, - "peerDependenciesMeta": { - "description": "When a user installs your package, warnings are emitted if packages specified in \"peerDependencies\" are not already installed. The \"peerDependenciesMeta\" field serves to provide more information on how your peer dependencies are utilized. Most commonly, it allows peer dependencies to be marked as optional. Metadata for this field is specified with a simple hash of the package name to a metadata object.", - "type": "object", - "additionalProperties": { - "type": "object", - "additionalProperties": true, - "properties": { - "optional": { - "description": "Specifies that this peer dependency is optional and should not be installed automatically.", - "type": "boolean" - } - } - } - }, - "bundledDependencies": { - "description": "Array of package names that will be bundled when publishing the package.", - "oneOf": [ - { - "type": "array", - "items": { - "type": "string" - } - }, - { - "type": "boolean" - } - ] - }, - "bundleDependencies": { - "description": "DEPRECATED: This field is honored, but \"bundledDependencies\" is the correct field name.", - "oneOf": [ - { - "type": "array", - "items": { - "type": "string" - } - }, - { - "type": "boolean" - } - ] - }, - "trustedDependencies": { - "description": "Array of package names that are trusted to run lifecycle scripts, such as 'postinstall'.", - "type": "array", - "items": { - "type": "string" - } - }, - "resolutions": { - "description": "Resolutions is used to support selective version resolutions using yarn, which lets you define custom package versions or ranges inside your dependencies. For npm, use overrides instead. See: https://classic.yarnpkg.com/en/docs/selective-version-resolutions", - "type": "object" - }, - "overrides": { - "description": "Overrides is used to support selective version overrides using npm, which lets you define custom package versions or ranges inside your dependencies. For yarn, use resolutions instead. See: https://docs.npmjs.com/cli/v9/configuring-npm/package-json#overrides", - "type": "object" - }, - "packageManager": { - "description": "Defines which package manager is expected to be used when working on the current project. This field is currently experimental and needs to be opted-in; see https://nodejs.org/api/corepack.html", - "type": "string", - "pattern": "(bun|npm|pnpm|yarn)@\\d+\\.\\d+\\.\\d+(-.+)?" - }, - "engines": { - "type": "object", - "properties": { - "node": { - "type": "string" - } - }, - "additionalProperties": { - "type": "string" - } - }, - "engineStrict": { - "type": "boolean" - }, - "os": { - "description": "Specify which operating systems your module will run on.", - "type": "array", - "items": { - "type": "string" - } - }, - "cpu": { - "description": "Specify that your code only runs on certain cpu architectures.", - "type": "array", - "items": { - "type": "string" - } - }, - "preferGlobal": { - "type": "boolean", - "description": "DEPRECATED: This option used to trigger an npm warning, but it will no longer warn. It is purely there for informational purposes. It is now recommended that you install any binaries as local devDependencies wherever possible." - }, - "private": { - "description": "If set to true, then npm will refuse to publish it.", - "oneOf": [ - { - "type": "boolean" - }, - { - "enum": [ - "false", - "true" - ] - } - ] - }, - "publishConfig": { - "type": "object", - "properties": { - "access": { - "type": "string", - "enum": [ - "public", - "restricted" - ] - }, - "tag": { - "type": "string" - }, - "registry": { - "type": "string", - "format": "uri" - } - }, - "additionalProperties": true - }, - "dist": { - "type": "object", - "properties": { - "shasum": { - "type": "string" - }, - "tarball": { - "type": "string" - } - } - }, - "readme": { - "type": "string" - }, - "module": { - "description": "An ECMAScript module ID that is the primary entry point to your program.", - "type": "string" - }, - "esnext": { - "description": "A module ID with untranspiled code that is the primary entry point to your program.", - "type": [ - "string", - "object" - ], - "properties": { - "main": { - "type": "string" - }, - "browser": { - "type": "string" - } - }, - "additionalProperties": { - "type": "string" - } - }, - "workspaces": { - "description": "Allows packages within a directory to depend on one another using direct linking of local files. Additionally, dependencies within a workspace are hoisted to the workspace root when possible to reduce duplication. Note: It's also a good idea to set \"private\" to true when using this feature.", - "anyOf": [ - { - "type": "array", - "description": "Workspace package paths. Glob patterns are supported.", - "items": { - "type": "string" - } - }, - { - "type": "object", - "properties": { - "packages": { - "type": "array", - "description": "Workspace package paths. Glob patterns are supported.", - "items": { - "type": "string" - } - }, - "nohoist": { - "type": "array", - "description": "Packages to block from hoisting to the workspace root. Currently only supported in Yarn only.", - "items": { - "type": "string" - } - } - } - } - ] - }, - "jspm": { - "$ref": "#" - }, - "eslintConfig": { - "$ref": "https://json.schemastore.org/eslintrc.json" - }, - "prettier": { - "$ref": "https://json.schemastore.org/prettierrc.json" - }, - "stylelint": { - "$ref": "https://json.schemastore.org/stylelintrc.json" - }, - "ava": { - "$ref": "https://json.schemastore.org/ava.json" - }, - "release": { - "$ref": "https://json.schemastore.org/semantic-release.json" - }, - "jscpd": { - "$ref": "https://json.schemastore.org/jscpd.json" - } - }, - "anyOf": [ - { - "type": "object", - "not": { - "required": [ - "bundledDependencies", - "bundleDependencies" - ] - } - }, - { - "type": "object", - "not": { - "required": [ - "bundleDependencies" - ] - }, - "required": [ - "bundledDependencies" - ] - }, - { - "type": "object", - "not": { - "required": [ - "bundledDependencies" - ] - }, - "required": [ - "bundleDependencies" - ] - } - ] -} -- cgit v1.2.3