Skip to content

Commit 75c6188

Browse files
committed
fix: count in optionalDependencies in autoExternal.
1 parent c8c1726 commit 75c6188

File tree

3 files changed

+17
-8
lines changed

3 files changed

+17
-8
lines changed

packages/core/src/config.ts

Lines changed: 13 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -227,21 +227,27 @@ export const composeAutoExternalConfig = (options: {
227227
return {};
228228
}
229229

230+
// User externals configuration has higher priority than autoExternal
231+
// eg: autoExternal: ['react'], user: output: { externals: { react: 'react-1' } }
232+
// Only handle the case where the externals type is object, string / string[] does not need to be processed, other types are too complex.
233+
const userExternalKeys =
234+
userExternals && isObject(userExternals) ? Object.keys(userExternals) : [];
235+
230236
const externalOptions = {
231237
dependencies: true,
238+
optionalDependencies: true,
232239
peerDependencies: true,
233240
devDependencies: false,
234241
...(autoExternal === true ? {} : autoExternal),
235242
};
236243

237-
// User externals configuration has higher priority than autoExternal
238-
// eg: autoExternal: ['react'], user: output: { externals: { react: 'react-1' } }
239-
// Only handle the case where the externals type is object, string / string[] does not need to be processed, other types are too complex.
240-
const userExternalKeys =
241-
userExternals && isObject(userExternals) ? Object.keys(userExternals) : [];
242-
243244
const externals = (
244-
['dependencies', 'peerDependencies', 'devDependencies'] as const
245+
[
246+
'dependencies',
247+
'peerDependencies',
248+
'devDependencies',
249+
'optionalDependencies',
250+
] as const
245251
)
246252
.reduce<string[]>((prev, type) => {
247253
if (externalOptions[type]) {

packages/core/src/types/utils.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
export type PkgJson = {
2+
type?: 'module' | 'commonjs';
23
dependencies?: Record<string, string>;
34
peerDependencies?: Record<string, string>;
45
devDependencies?: Record<string, string>;
5-
[key: string]: unknown;
6+
optionalDependencies?: Record<string, string>;
67
};

packages/plugin-dts/src/dts.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@ export const calcBundledPackages = (options: {
2626
dependencies?: Record<string, string>;
2727
peerDependencies?: Record<string, string>;
2828
devDependencies?: Record<string, string>;
29+
optionalDependencies?: Record<string, string>;
2930
};
3031

3132
try {
@@ -42,6 +43,7 @@ export const calcBundledPackages = (options: {
4243
? {
4344
dependencies: true,
4445
peerDependencies: true,
46+
optionalDependencies: true,
4547
devDependencies: false,
4648
...(autoExternal === true ? {} : autoExternal),
4749
}

0 commit comments

Comments
 (0)