Skip to content

Commit

Permalink
Try and ensure the d.ts types are definitely the ones loaded in `qu…
Browse files Browse the repository at this point in the history
…ick-edit-extension` (#7040)

* Try and ensure the d.ts types are definitely the ones loaded
  • Loading branch information
penalosa authored Oct 21, 2024
1 parent c794935 commit 44c954b
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 6 deletions.
5 changes: 5 additions & 0 deletions .changeset/pink-geckos-peel.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"@cloudflare/quick-edit": patch
---

Try and ensure the `d.ts` types are definitely the ones loaded in `quick-edit-extension`
16 changes: 11 additions & 5 deletions packages/quick-edit-extension/scripts/bundle.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
import assert from "assert";
import { readFile } from "fs/promises";
import path from "path";
import * as esbuild from "esbuild";

type BuildFlags = {
Expand All @@ -18,12 +20,11 @@ async function buildMain(flags: BuildFlags = {}) {
name: "workers-types",
setup(build) {
build.onResolve({ filter: /^raw:.*/ }, async (args) => {
const result = await build.resolve(args.path.slice(4), {
kind: "import-statement",
resolveDir: args.resolveDir,
});
const result = path.resolve(
"node_modules/@cloudflare/workers-types/experimental/index.d.ts"
);
return {
path: result.path,
path: result,
namespace: "raw-file",
};
});
Expand All @@ -32,6 +33,11 @@ async function buildMain(flags: BuildFlags = {}) {
{ 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" };
}
);
Expand Down
2 changes: 1 addition & 1 deletion packages/quick-edit-extension/src/cfs.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
* Copyright (c) Microsoft Corporation. All rights reserved.
* Licensed under the MIT License. See License.txt in the project root for license information.
*--------------------------------------------------------------------------------------------*/
import workersTypes from "raw:@cloudflare/workers-types/experimental/index.d.ts";
import workersTypes from "raw:workers-types";
import {
Disposable,
EventEmitter,
Expand Down

0 comments on commit 44c954b

Please sign in to comment.