3
3
const webpack = require ( 'webpack' ) ;
4
4
const createDomain = require ( './createDomain' ) ;
5
5
6
+ /**
7
+ * A Entry, it can be of type string or string[] or Object<string | string[],string>
8
+ * @typedef {(string[] | string | Object<string | string[],string>) } Entry
9
+ */
10
+
11
+ /**
12
+ * Add entries Method
13
+ * @param {?Object } config - Webpack config
14
+ * @param {?Object } options - Dev-Server options
15
+ * @param {?Object } server
16
+ * @returns {void }
17
+ */
6
18
function addEntries ( config , options , server ) {
7
19
if ( options . inline !== false ) {
8
20
// we're stubbing the app in this method as it's static and doesn't require
@@ -15,21 +27,33 @@ function addEntries(config, options, server) {
15
27
} ,
16
28
} ;
17
29
30
+ /** @type {string } */
18
31
const domain = createDomain ( options , app ) ;
32
+ /** @type {string } */
19
33
const sockHost = options . sockHost ? `&sockHost=${ options . sockHost } ` : '' ;
34
+ /** @type {string } */
20
35
const sockPath = options . sockPath ? `&sockPath=${ options . sockPath } ` : '' ;
36
+ /** @type {string } */
21
37
const sockPort = options . sockPort ? `&sockPort=${ options . sockPort } ` : '' ;
38
+ /** @type {string } */
22
39
const clientEntry = `${ require . resolve (
23
40
'../../client/'
24
41
) } ?${ domain } ${ sockHost } ${ sockPath } ${ sockPort } `;
42
+
43
+ /** @type {(string[] | string) } */
25
44
let hotEntry ;
26
45
27
46
if ( options . hotOnly ) {
28
47
hotEntry = require . resolve ( 'webpack/hot/only-dev-server' ) ;
29
48
} else if ( options . hot ) {
30
49
hotEntry = require . resolve ( 'webpack/hot/dev-server' ) ;
31
50
}
32
-
51
+ /**
52
+ * prependEntry Method
53
+ * @param {Entry } originalEntry
54
+ * @param {Entry } additionalEntries
55
+ * @returns {Entry }
56
+ */
33
57
const prependEntry = ( originalEntry , additionalEntries ) => {
34
58
if ( typeof originalEntry === 'function' ) {
35
59
return ( ) =>
@@ -39,6 +63,7 @@ function addEntries(config, options, server) {
39
63
}
40
64
41
65
if ( typeof originalEntry === 'object' && ! Array . isArray ( originalEntry ) ) {
66
+ /** @type {Object<string,string> } */
42
67
const clone = { } ;
43
68
44
69
Object . keys ( originalEntry ) . forEach ( ( key ) => {
@@ -51,6 +76,7 @@ function addEntries(config, options, server) {
51
76
52
77
// in this case, entry is a string or an array.
53
78
// make sure that we do not add duplicates.
79
+ /** @type {Entry } */
54
80
const entriesClone = additionalEntries . slice ( 0 ) ;
55
81
[ ] . concat ( originalEntry ) . forEach ( ( newEntry ) => {
56
82
if ( ! entriesClone . includes ( newEntry ) ) {
@@ -60,21 +86,38 @@ function addEntries(config, options, server) {
60
86
return entriesClone ;
61
87
} ;
62
88
89
+ /**
90
+ *
91
+ * Description of the option for checkInject method
92
+ * @typedef {Function } checkInjectOptionsParam
93
+ * @param {Object } _config - compilerConfig
94
+ * @return {Boolean }
95
+ */
96
+
97
+ /**
98
+ *
99
+ * @param {Boolean | checkInjectOptionsParam } option - inject(Hot|Client) it is Boolean | fn => Boolean
100
+ * @param {Object } _config
101
+ * @param {Boolean } defaultValue
102
+ * @return {Boolean }
103
+ */
63
104
// eslint-disable-next-line no-shadow
64
- const checkInject = ( option , config , defaultValue ) => {
105
+ const checkInject = ( option , _config , defaultValue ) => {
65
106
if ( typeof option === 'boolean' ) return option ;
66
- if ( typeof option === 'function' ) return option ( config ) ;
107
+ if ( typeof option === 'function' ) return option ( _config ) ;
67
108
return defaultValue ;
68
109
} ;
69
110
70
111
// eslint-disable-next-line no-shadow
71
112
[ ] . concat ( config ) . forEach ( ( config ) => {
113
+ /** @type {Boolean } */
72
114
const webTarget =
73
115
config . target === 'web' ||
74
116
config . target === 'webworker' ||
75
117
config . target === 'electron-renderer' ||
76
118
config . target === 'node-webkit' ||
77
119
config . target == null ;
120
+ /** @type {Entry } */
78
121
const additionalEntries = checkInject (
79
122
options . injectClient ,
80
123
config ,
0 commit comments