Skip to content

Commit

Permalink
chore: add isObject util
Browse files Browse the repository at this point in the history
  • Loading branch information
9aoy committed Aug 9, 2024
1 parent 6fce2ed commit 3f24d59
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 4 deletions.
6 changes: 2 additions & 4 deletions packages/core/src/config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ import { getDefaultExtension } from './utils/extension';
import {
calcLongestCommonPath,
color,
isObject,
nodeBuiltInModules,
readPackageJson,
} from './utils/helper';
Expand Down Expand Up @@ -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
Expand Down
3 changes: 3 additions & 0 deletions packages/core/src/utils/helper.ts
Original file line number Diff line number Diff line change
Expand Up @@ -118,4 +118,7 @@ export const readPackageJson = (rootPath: string): undefined | PkgJson => {
}
};

export const isObject = (obj: unknown): obj is Record<string, any> =>
Object.prototype.toString.call(obj) === '[object Object]';

export { color, calcLongestCommonPath };

0 comments on commit 3f24d59

Please sign in to comment.