diff --git a/packages/core/src/config.ts b/packages/core/src/config.ts index 69062d73a..4c5a150f3 100644 --- a/packages/core/src/config.ts +++ b/packages/core/src/config.ts @@ -25,6 +25,7 @@ import { getDefaultExtension } from './utils/extension'; import { calcLongestCommonPath, color, + isObject, nodeBuiltInModules, readPackageJson, } from './utils/helper'; @@ -111,10 +112,7 @@ export const composeAutoExternalConfig = (options: { // eg: autoExternal: ['react'], user: output: { externals: { react: 'react-1' } } // Only handle the case where the externals type is object, string / string[] does not need to be processed, other types are too complex. const userExternalKeys = - userExternals && - Object.prototype.toString.call(userExternals) === '[object Object]' - ? Object.keys(userExternals) - : []; + userExternals && isObject(userExternals) ? Object.keys(userExternals) : []; const externals = ( ['dependencies', 'peerDependencies', 'devDependencies'] as const diff --git a/packages/core/src/utils/helper.ts b/packages/core/src/utils/helper.ts index be18d67fc..ca36e081b 100644 --- a/packages/core/src/utils/helper.ts +++ b/packages/core/src/utils/helper.ts @@ -118,4 +118,7 @@ export const readPackageJson = (rootPath: string): undefined | PkgJson => { } }; +export const isObject = (obj: unknown): obj is Record => + Object.prototype.toString.call(obj) === '[object Object]'; + export { color, calcLongestCommonPath };