Skip to content

Commit bdc19b6

Browse files
committed
feat(webpack): always use new native dep checker
1 parent 7042793 commit bdc19b6

File tree

1 file changed

+27
-56
lines changed

1 file changed

+27
-56
lines changed

lib/webpackConfig.js

Lines changed: 27 additions & 56 deletions
Original file line numberDiff line numberDiff line change
@@ -110,68 +110,39 @@ function getExternals (api, pluginOptions) {
110110
)
111111
const externalsList = allDependencies.reduce((depList, dep) => {
112112
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
123130
// Use user-provided name if it exists to support subpaths
124131
depList.push(name || dep)
125132
return depList
126133
}
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-
}
171134
}
172135
} 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+
)
175146
}
176147
return depList
177148
}, [])

0 commit comments

Comments
 (0)