Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Bindings extension #6600

Closed
wants to merge 23 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion .github/prereleases/1-versions.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,8 @@ import { getPackagesForPrerelease, setPackage } from "./0-packages.mjs";

function getPrereleaseVersion() {
const sha = execSync("git rev-parse --short HEAD", { encoding: "utf8" });
return `0.0.0-${sha.trim()}`;
// Prefix with a `v` to ensure the version is always alphanumeric rather than just numeric (which can cause issues with some tools e.g vsce)
return `0.0.0-v${sha.trim()}`;
}

/**
Expand Down
20 changes: 14 additions & 6 deletions .github/prereleases/2-build-pack-upload.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -42,12 +42,12 @@ function packPackage(pkg) {

/**
* @param {~Package} pkg
* @param {string} tarballPath
* @param {string} artifactPath
*/
async function uploadPackageTarball(pkg, tarballPath) {
async function uploadPackageArtifact(pkg, artifactPath) {
const name = getPrereleaseArtifactName(pkg.json.name);
console.log(`Uploading ${tarballPath} as ${name}...`);
await artifact.uploadArtifact(name, [tarballPath], pkg.path);
console.log(`Uploading ${artifactPath} as ${name}...`);
await artifact.uploadArtifact(name, [artifactPath], pkg.path);
}

{
Expand All @@ -60,7 +60,15 @@ async function uploadPackageTarball(pkg, tarballPath) {
pkgs.forEach(setPackage);

for (const pkg of pkgs) {
const tarballPath = packPackage(pkg);
await uploadPackageTarball(pkg, tarballPath);
if (pkg.json["workers-sdk"].type === "extension") {
const filePath = path.join(
pkg.path,
`${pkg.json.name}-${pkg.json.version}.vsix`
);
await uploadPackageArtifact(pkg, filePath);
} else {
const tarballPath = packPackage(pkg);
await uploadPackageArtifact(pkg, tarballPath);
}
}
}
7 changes: 5 additions & 2 deletions .github/prereleases/3-comment.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -45,9 +45,12 @@ npx ${url} dev path/to/script.js
*/
function buildAdditionalArtifactReport(pkg) {
const name = pkg.json.name;
const type = pkg.json["workers-sdk"].type;
const url = getPrereleaseArtifactUrl(name);
if (name === "create-cloudflare") {
if (type === "cli") {
return `\`\`\`sh\nnpx ${url} --no-auto-update\n\`\`\``;
} else if (type === "extension") {
return `\`\`\`sh\nwget ${url} -O ./${name}.${pkg.json.version}.vsix && code --install-extension ./${name}.${pkg.json.version}.vsix\n\`\`\``;
} else {
return `\`\`\`sh\nnpm install ${url}\n\`\`\``;
}
Expand All @@ -68,7 +71,7 @@ function buildReport(pkgs) {
const additionalReports = pkgs.map(buildAdditionalArtifactReport);

return `${wranglerReport}

<details><summary>Additional artifacts:</summary>

${additionalReports.join("\n\n")}
Expand Down
5 changes: 5 additions & 0 deletions .github/workflows/create-pullrequest-prerelease.yml
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,11 @@ jobs:

- name: Install Dependencies
uses: ./.github/actions/install-dependencies
with:
turbo-api: ${{ secrets.TURBO_API }}
turbo-team: ${{ secrets.TURBO_TEAM }}
turbo-token: ${{ secrets.TURBO_TOKEN }}
turbo-signature: ${{ secrets.TURBO_REMOTE_CACHE_SIGNATURE_KEY }}

- name: Build Miniflare
# `extract-runtime-versions.mjs` needs to be able to resolve `miniflare`, but we want to have the correct
Expand Down
4 changes: 2 additions & 2 deletions fixtures/nodejs-hybrid-app/worker-configuration.d.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
// Generated by Wrangler on Tue Mar 05 2024 16:04:07 GMT+0000 (Greenwich Mean Time)
// by running `wrangler types`
// Generated by Wrangler on Thu Aug 29 2024 19:37:30 GMT+0100 (British Summer Time)
// by running `wrangler types --x-include-runtime`

interface Env {
DB_HOSTNAME: "hh-pgsql-public.ebi.ac.uk";
Expand Down
5 changes: 5 additions & 0 deletions fixtures/pages-nodejs-v2-compat/worker-configuration.d.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
// Generated by Wrangler on Thu Aug 29 2024 19:37:32 GMT+0100 (British Summer Time)
// by running `wrangler types --x-include-runtime`

interface Env {
}
18 changes: 14 additions & 4 deletions fixtures/worker-ts/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
*/
export interface Env {
// Example binding to KV. Learn more at https://developers.cloudflare.com/workers/runtime-apis/kv/
// MY_KV_NAMESPACE: KVNamespace;
MY_KV_NAMESPACE: KVNamespace;
//
// Example binding to Durable Object. Learn more at https://developers.cloudflare.com/workers/runtime-apis/durable-objects/
// MY_DURABLE_OBJECT: DurableObjectNamespace;
Expand All @@ -27,8 +27,18 @@ export default {
env: Env,
ctx: ExecutionContext
): Promise<Response> {
const url = new URL(request.url);
if (url.pathname === "/error") throw new Error("Hello Error");
return new Response("Hello World!");
try {
await env.MY_KV_NAMESPACE.put("KEY", "VALUE");
const value = await env.MY_KV_NAMESPACE.get("KEY");
if (value === null) {
return new Response("Value not found", { status: 404 });
}
return new Response(value);
} catch (err) {
// In a production application, you could instead choose to retry your KV
// read or fall back to a default code path.
console.error(`KV returned error: ${err}`);
return new Response(err, { status: 500 });
}
},
};
7 changes: 7 additions & 0 deletions fixtures/worker-ts/worker-configuration.d.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
// Generated by Wrangler on Fri Aug 30 2024 21:11:19 GMT+0100 (British Summer Time)
// by running `wrangler types --x-include-runtime`

interface Env {
SOME: KVNamespace;
HELLO: "WORLD";
}
14 changes: 14 additions & 0 deletions fixtures/worker-ts/wrangler.toml
Original file line number Diff line number Diff line change
@@ -1,3 +1,17 @@
#:schema node_modules/wrangler/config-schema.json

name = "worker-ts"
main = "src/index.ts"
compatibility_date = "2023-05-04"

[vars]
HELLO="WORLD"

[[d1_databases]]
binding = "MY_DB"

[[kv_namespaces]]
binding = "MY_KV_NAMESPACE"

[[r2_buckets]]
binding = "MY_BUCKET"
30 changes: 30 additions & 0 deletions packages/cloudflare-workers-bindings-extension/.eslintrc.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
{
"root": true,
"parser": "@typescript-eslint/parser",
"parserOptions": {
"ecmaVersion": 6,
"sourceType": "module"
},
"plugins": [
"@typescript-eslint"
],
"rules": {
"@typescript-eslint/naming-convention": [
"warn",
{
"selector": "import",
"format": [ "camelCase", "PascalCase" ]
}
],
"@typescript-eslint/semi": "warn",
"curly": "warn",
"eqeqeq": "warn",
"no-throw-literal": "warn",
"semi": "off"
},
"ignorePatterns": [
"out",
"dist",
"**/*.d.ts"
]
}
1 change: 1 addition & 0 deletions packages/cloudflare-workers-bindings-extension/.npmrc
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
enable-pre-post-scripts = true
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
import { defineConfig } from '@vscode/test-cli';

export default defineConfig({
files: 'out/test/**/*.test.js',
});
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
{
// See http://go.microsoft.com/fwlink/?LinkId=827846
// for the documentation about the extensions.json format
"recommendations": ["dbaeumer.vscode-eslint", "connor4312.esbuild-problem-matchers", "ms-vscode.extension-test-runner"]
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
// 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",
"args": [
"--extensionDevelopmentPath=${workspaceFolder}"
],
"outFiles": [
"${workspaceFolder}/dist/**/*.js"
],
"preLaunchTask": "${defaultBuildTask}"
}
]
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
// 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
"dist": false // set this to true to hide the "dist" folder with the compiled JS files
},
"search.exclude": {
"out": true, // set this to false to include "out" folder in search results
"dist": true // set this to false to include "dist" folder in search results
},
// Turn off tsc task auto detection since we have the necessary tasks as npm scripts
"typescript.tsc.autoDetect": "off"
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,64 @@
// See https://go.microsoft.com/fwlink/?LinkId=733558
// for the documentation about the tasks.json format
{
"version": "2.0.0",
"tasks": [
{
"label": "watch",
"dependsOn": [
"npm: watch:tsc",
"npm: watch:esbuild"
],
"presentation": {
"reveal": "never"
},
"group": {
"kind": "build",
"isDefault": true
}
},
{
"type": "npm",
"script": "watch:esbuild",
"group": "build",
"problemMatcher": "$esbuild-watch",
"isBackground": true,
"label": "npm: watch:esbuild",
"presentation": {
"group": "watch",
"reveal": "never"
}
},
{
"type": "npm",
"script": "watch:tsc",
"group": "build",
"problemMatcher": "$tsc-watch",
"isBackground": true,
"label": "npm: watch:tsc",
"presentation": {
"group": "watch",
"reveal": "never"
}
},
{
"type": "npm",
"script": "watch-tests",
"problemMatcher": "$tsc-watch",
"isBackground": true,
"presentation": {
"reveal": "never",
"group": "watchers"
},
"group": "build"
},
{
"label": "tasks: watch-tests",
"dependsOn": [
"npm: watch",
"npm: watch-tests"
],
"problemMatcher": []
}
]
}
14 changes: 14 additions & 0 deletions packages/cloudflare-workers-bindings-extension/.vscodeignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
.vscode/**
.vscode-test/**
out/**
node_modules/**
src/**
.gitignore
.yarnrc
esbuild.js
vsc-extension-quickstart.md
**/tsconfig.json
**/.eslintrc.json
**/*.map
**/*.ts
**/.vscode-test.*
9 changes: 9 additions & 0 deletions packages/cloudflare-workers-bindings-extension/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
# Change Log

All notable changes to the "cloudflare-workers-bindings-extension" extension will be documented in this file.

Check [Keep a Changelog](http://keepachangelog.com/) for recommendations on how to structure this file.

## [Unreleased]

- Initial release
1 change: 1 addition & 0 deletions packages/cloudflare-workers-bindings-extension/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
# cloudflare-workers-bindings-extension README
56 changes: 56 additions & 0 deletions packages/cloudflare-workers-bindings-extension/esbuild.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
const esbuild = require("esbuild");

const production = process.argv.includes('--production');
const watch = process.argv.includes('--watch');

/**
* @type {import('esbuild').Plugin}
*/
const esbuildProblemMatcherPlugin = {
name: 'esbuild-problem-matcher',

setup(build) {
build.onStart(() => {
console.log('[watch] build started');
});
build.onEnd((result) => {
result.errors.forEach(({ text, location }) => {
console.error(`✘ [ERROR] ${text}`);
console.error(` ${location.file}:${location.line}:${location.column}:`);
});
console.log('[watch] build finished');
});
},
};

async function main() {
const ctx = await esbuild.context({
entryPoints: [
'src/extension.ts'
],
bundle: true,
format: 'cjs',
minify: production,
sourcemap: !production,
sourcesContent: false,
platform: 'node',
outfile: 'dist/extension.js',
external: ['vscode'],
logLevel: 'silent',
plugins: [
/* add to the end of plugins array */
esbuildProblemMatcherPlugin,
],
});
if (watch) {
await ctx.watch();
} else {
await ctx.rebuild();
await ctx.dispose();
}
}

main().catch(e => {
console.error(e);
process.exit(1);
});
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Loading