@@ -11,6 +11,33 @@ const root = path.join(__dirname, "..", "..");
11
11
const packages = path . join ( root , "packages" ) ;
12
12
const walk = require ( "../utils/walk" ) ;
13
13
14
+ const node_libraries = [
15
+ "buffer" ,
16
+ "child_process" ,
17
+ "crypto" ,
18
+ "dns" ,
19
+ "dns/promises" ,
20
+ "events" ,
21
+ "fs" ,
22
+ "fs/promises" ,
23
+ "http" ,
24
+ "http2" ,
25
+ "https" ,
26
+ "os" ,
27
+ "path" ,
28
+ "path/posix" ,
29
+ "path/win32" ,
30
+ "process" ,
31
+ "stream" ,
32
+ "stream/consumers" ,
33
+ "stream/promises" ,
34
+ "stream/web" ,
35
+ "tls" ,
36
+ "url" ,
37
+ "util" ,
38
+ "zlib" ,
39
+ ] ;
40
+
14
41
( async ( ) => {
15
42
const errors = [ ] ;
16
43
@@ -44,17 +71,21 @@ const walk = require("../utils/walk");
44
71
const importedDependencies = [ ] ;
45
72
importedDependencies . push (
46
73
...new Set (
47
- [ ...( contents . toString ( ) . match ( / ( f r o m | i m p o r t \( ) " ( @ ( a w s - s d k | s m i t h y ) \/ .* ?) " ; / g) || [ ] ) ] . map ( ( _ ) =>
48
- _ . replace ( / f r o m " / g, "" ) . replace ( / " ; $ / , "" )
49
- )
74
+ [ ...( contents . toString ( ) . match ( / ( f r o m | i m p o r t \( ) " ( .* ?) " ; / g) || [ ] ) ]
75
+ . map ( ( _ ) => _ . replace ( / f r o m " / g, "" ) . replace ( / " ; $ / , "" ) )
76
+ . filter ( ( _ ) => ! _ . startsWith ( "." ) && ! node_libraries . includes ( _ ) )
50
77
)
51
78
) ;
52
79
53
80
for ( const dependency of importedDependencies ) {
81
+ const dependencyPackageName = dependency . startsWith ( "@" )
82
+ ? dependency . split ( "/" ) . slice ( 0 , 2 ) . join ( "/" )
83
+ : dependency . split ( "/" ) [ 0 ] ;
84
+
54
85
if (
55
- ! ( dependency in ( pkgJson . dependencies ?? { } ) ) &&
56
- ! ( dependency in ( pkgJson . peerDependencies ?? { } ) ) &&
57
- dependency !== pkgJson . name
86
+ ! ( dependencyPackageName in ( pkgJson . dependencies ?? { } ) ) &&
87
+ ! ( dependencyPackageName in ( pkgJson . peerDependencies ?? { } ) ) &&
88
+ dependencyPackageName !== pkgJson . name
58
89
) {
59
90
errors . push ( `${ dependency } undeclared but imported in ${ pkgJson . name } ${ file } }` ) ;
60
91
}
0 commit comments