From 59eef4fe5b3fc0a730fe6c8db318e94db72425ed Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Somhairle=20MacLe=C3=B2id?= Date: Tue, 17 Dec 2024 17:13:34 +0000 Subject: [PATCH] Load Wrangler in extension (#7560) * Initial Wrangler loading * Remove duplicate path * lockfile * workspace * lockfile * Create thirty-windows-prove.md --- .changeset/thirty-windows-prove.md | 5 +++++ .../package.json | 3 ++- .../src/extension.ts | 15 +++++++++++++++ .../src/wrangler.ts | 15 +++++++++++++++ .../tsconfig.json | 3 ++- pnpm-lock.yaml | 3 +++ 6 files changed, 42 insertions(+), 2 deletions(-) create mode 100644 .changeset/thirty-windows-prove.md create mode 100644 packages/cloudflare-workers-bindings-extension/src/wrangler.ts diff --git a/.changeset/thirty-windows-prove.md b/.changeset/thirty-windows-prove.md new file mode 100644 index 000000000000..7f8212348424 --- /dev/null +++ b/.changeset/thirty-windows-prove.md @@ -0,0 +1,5 @@ +--- +"cloudflare-workers-bindings-extension": patch +--- + +Load Wrangler in extension diff --git a/packages/cloudflare-workers-bindings-extension/package.json b/packages/cloudflare-workers-bindings-extension/package.json index 554fd232ff12..89a95931cbbc 100644 --- a/packages/cloudflare-workers-bindings-extension/package.json +++ b/packages/cloudflare-workers-bindings-extension/package.json @@ -69,7 +69,8 @@ "eslint": "^8.57.0", "npm-run-all": "^4.1.5", "typescript": "^5.4.5", - "vsce": "^2.15.0" + "vsce": "^2.15.0", + "wrangler": "workspace:*" }, "engines": { "vscode": "^1.92.0" diff --git a/packages/cloudflare-workers-bindings-extension/src/extension.ts b/packages/cloudflare-workers-bindings-extension/src/extension.ts index 4ec4f4d3e94c..3c930f3d6cd3 100644 --- a/packages/cloudflare-workers-bindings-extension/src/extension.ts +++ b/packages/cloudflare-workers-bindings-extension/src/extension.ts @@ -1,4 +1,5 @@ import * as vscode from "vscode"; +import { importWrangler } from "./wrangler"; export async function activate(context: vscode.ExtensionContext) { vscode.commands.registerCommand( @@ -6,4 +7,18 @@ export async function activate(context: vscode.ExtensionContext) { () => vscode.window.showInformationMessage(`Successfully called test command.`) ); + + const rootPath = + vscode.workspace.workspaceFolders && + vscode.workspace.workspaceFolders.length > 0 + ? vscode.workspace.workspaceFolders[0].uri.fsPath + : undefined; + + if (!rootPath) { + return; + } + + const wrangler = importWrangler(rootPath); + + // Do stuff with Wrangler } diff --git a/packages/cloudflare-workers-bindings-extension/src/wrangler.ts b/packages/cloudflare-workers-bindings-extension/src/wrangler.ts new file mode 100644 index 000000000000..2e35d08288e2 --- /dev/null +++ b/packages/cloudflare-workers-bindings-extension/src/wrangler.ts @@ -0,0 +1,15 @@ +import * as path from "path"; + +export function importWrangler( + workspaceRoot: string +): typeof import("wrangler") { + const wrangler = path.join( + workspaceRoot, + "node_modules", + "wrangler", + "wrangler-dist", + "cli.js" + ); + + return require(wrangler); +} diff --git a/packages/cloudflare-workers-bindings-extension/tsconfig.json b/packages/cloudflare-workers-bindings-extension/tsconfig.json index db5edf33b355..652e8b8ef6e5 100644 --- a/packages/cloudflare-workers-bindings-extension/tsconfig.json +++ b/packages/cloudflare-workers-bindings-extension/tsconfig.json @@ -6,7 +6,8 @@ "sourceMap": true, "rootDir": "src", "strict": true, - "noEmit": true /* enable all strict type-checking options */ + "noEmit": true /* enable all strict type-checking options */, + "skipLibCheck": true /* 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. */ diff --git a/pnpm-lock.yaml b/pnpm-lock.yaml index 9cc949518434..abb9fdfa83b8 100644 --- a/pnpm-lock.yaml +++ b/pnpm-lock.yaml @@ -851,6 +851,9 @@ importers: vsce: specifier: ^2.15.0 version: 2.15.0 + wrangler: + specifier: workspace:* + version: link:../wrangler packages/create-cloudflare: devDependencies: