Files
wehub-resource-sync 70bf21e064
Deploy (to testing) and Test Playground Preview Worker / Deploy Playground Preview Worker (testing) (push) Has been skipped
Deploy Workers Shared Staging / Deploy Workers Shared Staging (push) Failing after 0s
Prerelease / build (push) Has been skipped
Handle Changesets / Handle Changesets (push) Has been cancelled
Semgrep OSS scan / semgrep-oss (push) Has been cancelled
chore: import upstream snapshot with attribution
2026-07-13 12:30:11 +08:00

67 lines
1.6 KiB
TypeScript

import assert from "node:assert";
import { readFile } from "node:fs/promises";
import path from "node:path";
import * as esbuild from "esbuild";
type BuildFlags = {
watch?: boolean;
};
async function buildMain(flags: BuildFlags = {}) {
const options: esbuild.BuildOptions = {
entryPoints: ["./src/extension.ts"],
bundle: true,
outfile: "./dist/extension.js",
format: "cjs",
external: ["vscode"],
logLevel: "info",
plugins: [
{
name: "workers-types",
setup(build) {
build.onResolve({ filter: /^raw:.*/ }, async () => {
const result = path.resolve(
"node_modules/@cloudflare/workers-types/experimental/index.d.ts"
);
return {
path: result,
namespace: "raw-file",
};
});
build.onLoad(
{ filter: /.*/, namespace: "raw-file" },
async (args) => {
const contents = await readFile(args.path);
// Make sure we're loading the .d.ts and not the .ts version of the types.
// Occasionally the wrong version has been loaded in CI, causing spurious typing errors
// for users in the playground & quick edit.
// The .d.ts file should not include `export declare` anywhere, while the .ts does
assert(!/export declare/.test(contents.toString()));
return { contents, loader: "text" };
}
);
},
},
],
};
if (flags.watch) {
const ctx = await esbuild.context(options);
// Start watching for changes...
await ctx.watch();
} else {
await esbuild.build(options);
}
}
async function run() {
await buildMain({ watch: process.argv.includes("--watch") });
}
run().catch((e) => {
console.error(e);
process.exit(1);
});