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
13 changes: 11 additions & 2 deletions packages/rstack/src/config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,10 @@ import type { StagedConfig } from './staged.ts';
export type RslintConfigDefinition = RslintConfig | (() => Promise<RslintConfig>);
export type RspressConfigDefinition = UserConfig | UserConfigAsyncFn;

type RslintConfigFactory = (
lint: typeof import('@rslint/core'),
) => RslintConfig | Promise<RslintConfig>;

export type Configs = {
app?: RsbuildConfigDefinition;
lib?: RslibConfigDefinition;
Expand Down Expand Up @@ -125,10 +129,11 @@ type Define = {
* Defines the Rslint config for linting.
*
* This config is used by the `rs lint` command.
* A config factory receives the exports from `rstack/lint`.
*
* @see {@link https://rstack.rs/config | Rstack configuration guide}
*/
lint: (config: RslintConfig | (() => Promise<RslintConfig>)) => void;
lint: (config: RslintConfig | RslintConfigFactory) => void;
/**
* Defines the Prettier config for formatting.
*
Expand Down Expand Up @@ -165,7 +170,11 @@ export const define: Define = {
lib: (config) => setConfig('lib', config),
doc: (config) => setConfig('doc', config),
test: (config) => setConfig('test', config),
lint: (config) => setConfig('lint', config),
lint: (config) =>
setConfig(
'lint',
typeof config === 'function' ? async () => config(await import('@rslint/core')) : config,
),
fmt: (config) => setConfig('fmt', config),
staged: (config) => setConfig('staged', config),
};
Expand Down
8 changes: 4 additions & 4 deletions packages/rstack/src/rslintConfig.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,15 +2,15 @@ import { loadRstackConfig } from './config.ts';
import type { RslintConfig } from '@rslint/core';

const { configs } = await loadRstackConfig();
const lintExports = configs.lint ?? [];
const lintDefinition = configs.lint ?? [];

let lintConfig: RslintConfig;

// TODO: support function in Rslint core
if (typeof lintExports === 'function') {
lintConfig = await lintExports();
if (typeof lintDefinition === 'function') {
lintConfig = await lintDefinition();
} else {
lintConfig = lintExports;
lintConfig = lintDefinition;
}

export default lintConfig;
6 changes: 4 additions & 2 deletions packages/rstack/tests/types/resolution-bundler/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,11 +11,12 @@ import {
type LoadRstackConfigOptions,
} from 'rstack/config';
import { defineConfig as defineLibConfig } from 'rstack/lib';
import { js, ts } from 'rstack/lint';
import { defineConfig as defineLintConfig } from 'rstack/lint';
import { expect as importedExpect, test as importedTest } from 'rstack/test';

const appConfig = defineAppConfig({});
const libConfig = defineLibConfig({});
const lintConfig = defineLintConfig([]);
const loadOptions: LoadRstackConfigOptions = { configFilePath: 'rstack.config.ts' };
const loadedConfig: Promise<LoadedRstackConfig> = loadRstackConfig(loadOptions);
const configs: Configs = {};
Expand All @@ -26,9 +27,10 @@ void configs;
void createRsbuild({ config: appConfig });
define.app(appConfig);
define.lib(libConfig);
define.lint(lintConfig);
define.lint(({ js, ts }) => [js.configs.recommended, ts.configs.recommendedTypeChecked]);
define.doc({});
define.test({});
define.lint([js.configs.recommended, ts.configs.recommended]);
define.staged({});

importedTest('exposes the Rstest APIs', () => {
Expand Down
8 changes: 5 additions & 3 deletions packages/rstack/tests/types/resolution-nodenext/index.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// This folder checks Rstack's exports and APIs with NodeNext resolution.
// This folder checks Rstack's exports and APIs with bundler resolution.
import 'rstack/test/globals';
import 'rstack/test/importMeta';
import 'rstack/types';
Expand All @@ -11,11 +11,12 @@ import {
type LoadRstackConfigOptions,
} from 'rstack/config';
import { defineConfig as defineLibConfig } from 'rstack/lib';
import { js, ts } from 'rstack/lint';
import { defineConfig as defineLintConfig } from 'rstack/lint';
import { expect as importedExpect, test as importedTest } from 'rstack/test';

const appConfig = defineAppConfig({});
const libConfig = defineLibConfig({});
const lintConfig = defineLintConfig([]);
const loadOptions: LoadRstackConfigOptions = { configFilePath: 'rstack.config.ts' };
const loadedConfig: Promise<LoadedRstackConfig> = loadRstackConfig(loadOptions);
const configs: Configs = {};
Expand All @@ -26,9 +27,10 @@ void configs;
void createRsbuild({ config: appConfig });
define.app(appConfig);
define.lib(libConfig);
define.lint(lintConfig);
define.lint(({ js, ts }) => [js.configs.recommended, ts.configs.recommendedTypeChecked]);
define.doc({});
define.test({});
define.lint([js.configs.recommended, ts.configs.recommended]);
define.staged({});

importedTest('exposes the Rstest APIs', () => {
Expand Down