1+ import assert from "assert" ;
12import { readFile } from "fs/promises" ;
3+ import path from "path" ;
24import * as esbuild from "esbuild" ;
35
46type BuildFlags = {
@@ -18,12 +20,11 @@ async function buildMain(flags: BuildFlags = {}) {
1820 name : "workers-types" ,
1921 setup ( build ) {
2022 build . onResolve ( { filter : / ^ r a w : .* / } , 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 ( ! / e x p o r t d e c l a r e / . test ( contents . toString ( ) ) ) ;
3541 return { contents, loader : "text" } ;
3642 }
3743 ) ;
0 commit comments