@@ -110,68 +110,39 @@ function getExternals (api, pluginOptions) {
110
110
)
111
111
const externalsList = allDependencies . reduce ( ( depList , dep ) => {
112
112
try {
113
- if ( process . env . VCPEB_EXPERIMENTAL_NATIVE_DEP_CHECK ) {
114
- // If dep is in whitelist, don't add it no matter what
115
- if ( userExternalsWhitelist . includes ( dep ) ) {
116
- return depList
117
- }
118
- const name = userExternals . find ( ( name ) =>
119
- new RegExp ( `^${ dep } (/|$)` ) . test ( name )
120
- )
121
- // If dep is listed in user external array, it is an external
122
- if ( name ) {
113
+ // If dep is in whitelist, don't add it no matter what
114
+ if ( userExternalsWhitelist . includes ( dep ) ) {
115
+ return depList
116
+ }
117
+ const name = userExternals . find ( ( name ) =>
118
+ new RegExp ( `^${ dep } (/|$)` ) . test ( name )
119
+ )
120
+ // If dep is listed in user external array, it is an external
121
+ if ( name ) {
122
+ // Use user-provided name if it exists to support subpaths
123
+ depList . push ( name || dep )
124
+ return depList
125
+ }
126
+ for ( const path of nodeModulesPaths ) {
127
+ // Check if binding.gyp exists
128
+ if ( fs . existsSync ( api . resolve ( `${ path } /${ dep } /binding.gyp` ) ) ) {
129
+ // If it does, dep is native
123
130
// Use user-provided name if it exists to support subpaths
124
131
depList . push ( name || dep )
125
132
return depList
126
133
}
127
- for ( const path of nodeModulesPaths ) {
128
- // Check if binding.gyp exists
129
- if ( fs . existsSync ( api . resolve ( `${ path } /${ dep } /binding.gyp` ) ) ) {
130
- // If it does, dep is native
131
- // Use user-provided name if it exists to support subpaths
132
- depList . push ( name || dep )
133
- return depList
134
- }
135
- }
136
- } else {
137
- let pgkString
138
- for ( const path of nodeModulesPaths ) {
139
- // Check if package.json exists
140
- if ( fs . existsSync ( api . resolve ( `${ path } /${ dep } /package.json` ) ) ) {
141
- // If it does, read it and break
142
- pgkString = fs
143
- . readFileSync ( api . resolve ( `${ path } /${ dep } /package.json` ) )
144
- . toString ( )
145
- break
146
- }
147
- }
148
- if ( ! pgkString ) {
149
- throw new Error ( `Could not find a package.json for module ${ dep } ` )
150
- }
151
- const pkg = JSON . parse ( pgkString )
152
- const name = userExternals . find ( ( name ) =>
153
- new RegExp ( `^${ pkg . name } (/|$)` ) . test ( name )
154
- )
155
- const fields = [ 'main' , 'module' , 'jsnext:main' , 'browser' ]
156
- if (
157
- // Not whitelisted
158
- userExternalsWhitelist . indexOf ( dep ) === - 1 &&
159
- // Doesn't have main property
160
- ( ! fields . some ( ( field ) => field in pkg ) ||
161
- // Has binary property
162
- ! ! pkg . binary ||
163
- // Has gypfile property
164
- ! ! pkg . gypfile ||
165
- // Listed in user-defined externals list
166
- ! ! name )
167
- ) {
168
- // Use user-provided name if it exists, for subpaths
169
- depList . push ( name || dep )
170
- }
171
134
}
172
135
} catch ( e ) {
173
- console . log ( e )
174
- depList . push ( dep )
136
+ error (
137
+ `An error occurred while trying to determine if dependecy "${ dep } " is native:` ,
138
+ e
139
+ )
140
+ error (
141
+ 'Please manually specify the dependency in the "externals" option, prefixing with a "!" if it should not be externalized.'
142
+ )
143
+ error (
144
+ 'See https://nklayman.github.io/vue-cli-plugin-electron-builder/guide/guide.html#native-modules for more details.'
145
+ )
175
146
}
176
147
return depList
177
148
} , [ ] )
0 commit comments