1
+ import assert from "assert" ;
1
2
import { readFile } from "fs/promises" ;
3
+ import path from "path" ;
2
4
import * as esbuild from "esbuild" ;
3
5
4
6
type BuildFlags = {
@@ -18,12 +20,11 @@ async function buildMain(flags: BuildFlags = {}) {
18
20
name : "workers-types" ,
19
21
setup ( build ) {
20
22
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
+ ) ;
25
26
return {
26
- path : result . path ,
27
+ path : result ,
27
28
namespace : "raw-file" ,
28
29
} ;
29
30
} ) ;
@@ -32,6 +33,11 @@ async function buildMain(flags: BuildFlags = {}) {
32
33
{ filter : / .* / , namespace : "raw-file" } ,
33
34
async ( args ) => {
34
35
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 ( ) ) ) ;
35
41
return { contents, loader : "text" } ;
36
42
}
37
43
) ;
0 commit comments