Skip to content

Commit 44c954b

Browse files
authored
Try and ensure the d.ts types are definitely the ones loaded in quick-edit-extension (#7040)
* Try and ensure the d.ts types are definitely the ones loaded
1 parent c794935 commit 44c954b

File tree

3 files changed

+17
-6
lines changed

3 files changed

+17
-6
lines changed

.changeset/pink-geckos-peel.md

+5
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
"@cloudflare/quick-edit": patch
3+
---
4+
5+
Try and ensure the `d.ts` types are definitely the ones loaded in `quick-edit-extension`

packages/quick-edit-extension/scripts/bundle.ts

+11-5
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,6 @@
1+
import assert from "assert";
12
import { readFile } from "fs/promises";
3+
import path from "path";
24
import * as esbuild from "esbuild";
35

46
type BuildFlags = {
@@ -18,12 +20,11 @@ async function buildMain(flags: BuildFlags = {}) {
1820
name: "workers-types",
1921
setup(build) {
2022
build.onResolve({ filter: /^raw:.*/ }, async (args) => {
21-
const result = await build.resolve(args.path.slice(4), {
22-
kind: "import-statement",
23-
resolveDir: args.resolveDir,
24-
});
23+
const result = path.resolve(
24+
"node_modules/@cloudflare/workers-types/experimental/index.d.ts"
25+
);
2526
return {
26-
path: result.path,
27+
path: result,
2728
namespace: "raw-file",
2829
};
2930
});
@@ -32,6 +33,11 @@ async function buildMain(flags: BuildFlags = {}) {
3233
{ filter: /.*/, namespace: "raw-file" },
3334
async (args) => {
3435
const contents = await readFile(args.path);
36+
// Make sure we're loading the .d.ts and not the .ts version of the types.
37+
// Occasionally the wrong version has been loaded in CI, causing spurious typing errors
38+
// for users in the playground & quick edit.
39+
// The .d.ts file should not include `export declare` anywhere, while the .ts does
40+
assert(!/export declare/.test(contents.toString()));
3541
return { contents, loader: "text" };
3642
}
3743
);

packages/quick-edit-extension/src/cfs.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
* Copyright (c) Microsoft Corporation. All rights reserved.
55
* Licensed under the MIT License. See License.txt in the project root for license information.
66
*--------------------------------------------------------------------------------------------*/
7-
import workersTypes from "raw:@cloudflare/workers-types/experimental/index.d.ts";
7+
import workersTypes from "raw:workers-types";
88
import {
99
Disposable,
1010
EventEmitter,

0 commit comments

Comments
 (0)