Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
26 changes: 11 additions & 15 deletions packages/rstack/src/rslibConfig.ts
Original file line number Diff line number Diff line change
@@ -1,28 +1,24 @@
import type {
ConfigParams,
RslibConfig,
RslibConfigDefinition,
import {
type ConfigParams,
type RslibConfig,
type RslibConfigDefinition,
mergeRslibConfig,
} from '@rslib/core';
import { withConfigMeta } from '@rstackjs/load-config';
import { loadRstackConfig, type Configs } from './config.ts';
import { resolveConfigLayers } from './configLayers.ts';

const resolveRslibConfig = async (
configs: Configs,
export const resolveRslibConfig = async (
layers: readonly Configs[],
params: ConfigParams,
): Promise<RslibConfig> => {
const libConfig = configs.lib;
if (!libConfig) {
return {};
}
if (typeof libConfig === 'function') {
return libConfig(params);
}
return libConfig;
const configs = await resolveConfigLayers(layers, 'lib', params);
return configs.length > 1 ? mergeRslibConfig(...configs) : (configs[0] ?? {});
};

const loadRslibConfig = (async (params: ConfigParams) => {
const { configs, filePath, dependencies } = await loadRstackConfig();
const config = await resolveRslibConfig(configs, params);
const config = await resolveRslibConfig([configs], params);

return withConfigMeta(config, { filePath, dependencies });
}) as RslibConfigDefinition;
Expand Down
27 changes: 27 additions & 0 deletions packages/rstack/tests/config/lib-merge.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
import { expect, test } from 'rstack/test';
import { resolveRslibConfig } from '../../src/rslibConfig.ts';

test('merges lib layers using native Rslib rules', async () => {
const config = await resolveRslibConfig(
[
{
lib: {
source: { define: { SHARED: true, ENV: 'base' } },
lib: [{ id: 'esm', format: 'esm', dts: true }],
},
},
{
lib: {
source: { define: { ENV: 'production' } },
lib: [{ id: 'esm', dts: false }, { format: 'cjs' }],
},
},
],
{ command: 'build', env: 'production' },
);

expect(config).toEqual({
source: { define: { SHARED: true, ENV: 'production' } },
lib: [{ id: 'esm', format: 'esm', dts: false }, { format: 'cjs' }],
});
});
Loading