@@ -45,46 +45,55 @@ const getChunkNamesToLoad = (path: string): string[] =>
45
45
)
46
46
. flatMap ( ( [ , routeChunks ] ) => Object . values ( flat ( routeChunks ) ) ) ;
47
47
48
- const docusaurus = {
49
- prefetch ( routePath : string ) : false | Promise < void [ ] > {
50
- if ( ! canPrefetch ( routePath ) ) {
51
- return false ;
52
- }
53
- fetched . add ( routePath ) ;
54
-
55
- // Find all webpack chunk names needed.
56
- const matches = matchRoutes ( routes , routePath ) ;
57
-
58
- const chunkNamesNeeded = matches . flatMap ( ( match ) =>
59
- getChunkNamesToLoad ( match . route . path ) ,
60
- ) ;
61
-
62
- // Prefetch all webpack chunk assets file needed.
63
- return Promise . all (
64
- chunkNamesNeeded . map ( ( chunkName ) => {
65
- // "__webpack_require__.gca" is injected by ChunkAssetPlugin. Pass it
66
- // the name of the chunk you want to load and it will return its URL.
67
- // eslint-disable-next-line camelcase
68
- const chunkAsset = __webpack_require__ . gca ( chunkName ) ;
69
-
70
- // In some cases, webpack might decide to optimize further, leading to
71
- // the chunk assets being merged to another chunk. In this case, we can
72
- // safely filter it out and don't need to load it.
73
- if ( chunkAsset && ! chunkAsset . includes ( 'undefined' ) ) {
74
- return prefetchHelper ( chunkAsset ) ;
75
- }
76
- return Promise . resolve ( ) ;
77
- } ) ,
78
- ) ;
79
- } ,
80
-
81
- preload ( routePath : string ) : false | Promise < void [ ] > {
82
- if ( ! canPreload ( routePath ) ) {
83
- return false ;
84
- }
85
- loaded . add ( routePath ) ;
86
- return preloadHelper ( routePath ) ;
87
- } ,
48
+ type Docusaurus = Window [ 'docusaurus' ] ;
49
+
50
+ const prefetch : Docusaurus [ 'prefetch' ] = (
51
+ routePath : string ,
52
+ ) : false | Promise < void [ ] > => {
53
+ if ( ! canPrefetch ( routePath ) ) {
54
+ return false ;
55
+ }
56
+ fetched . add ( routePath ) ;
57
+
58
+ // Find all webpack chunk names needed.
59
+ const matches = matchRoutes ( routes , routePath ) ;
60
+
61
+ const chunkNamesNeeded = matches . flatMap ( ( match ) =>
62
+ getChunkNamesToLoad ( match . route . path ) ,
63
+ ) ;
64
+
65
+ // Prefetch all webpack chunk assets file needed.
66
+ return Promise . all (
67
+ chunkNamesNeeded . map ( ( chunkName ) => {
68
+ // "__webpack_require__.gca" is injected by ChunkAssetPlugin. Pass it
69
+ // the name of the chunk you want to load and it will return its URL.
70
+ // eslint-disable-next-line camelcase
71
+ const chunkAsset = __webpack_require__ . gca ( chunkName ) ;
72
+
73
+ // In some cases, webpack might decide to optimize further, leading to
74
+ // the chunk assets being merged to another chunk. In this case, we can
75
+ // safely filter it out and don't need to load it.
76
+ if ( chunkAsset && ! chunkAsset . includes ( 'undefined' ) ) {
77
+ return prefetchHelper ( chunkAsset ) ;
78
+ }
79
+ return Promise . resolve ( ) ;
80
+ } ) ,
81
+ ) ;
82
+ } ;
83
+
84
+ const preload : Docusaurus [ 'preload' ] = (
85
+ routePath : string ,
86
+ ) : false | Promise < void [ ] > => {
87
+ if ( ! canPreload ( routePath ) ) {
88
+ return false ;
89
+ }
90
+ loaded . add ( routePath ) ;
91
+ return preloadHelper ( routePath ) ;
92
+ } ;
93
+
94
+ const docusaurus : Window [ 'docusaurus' ] = {
95
+ prefetch,
96
+ preload,
88
97
} ;
89
98
90
99
// This object is directly mounted onto window, better freeze it
0 commit comments