From f0e8ccddf7282a8c6714c5782740f0d16448caa2 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E6=88=B4=E9=99=88=E5=A8=81?= Date: Tue, 13 May 2025 16:50:31 +0800 Subject: [PATCH] chore: throw error when using bundleless mode with mf format --- packages/core/src/config.ts | 6 ++++++ pnpm-lock.yaml | 2 ++ tests/integration/format/index.test.ts | 11 +++++++++++ .../format/mf-bundle-false/package.json | 6 ++++++ .../format/mf-bundle-false/rslib.config.ts | 15 +++++++++++++++ .../format/mf-bundle-false/src/index.js | 1 + 6 files changed, 41 insertions(+) create mode 100644 tests/integration/format/mf-bundle-false/package.json create mode 100644 tests/integration/format/mf-bundle-false/rslib.config.ts create mode 100644 tests/integration/format/mf-bundle-false/src/index.js diff --git a/packages/core/src/config.ts b/packages/core/src/config.ts index 4116c524e..8d79f21b4 100644 --- a/packages/core/src/config.ts +++ b/packages/core/src/config.ts @@ -680,6 +680,12 @@ const composeFormatConfig = ({ return config; } case 'mf': + if (bundle === false) { + throw new Error( + 'When using "mf" format, "bundle" must be set to "true". Since the default value for "bundle" is "true", so you can either explicitly set it to "true" or remove the field entirely.', + ); + } + return { dev: { writeToDisk: true, diff --git a/pnpm-lock.yaml b/pnpm-lock.yaml index 2e016bf39..db70fb248 100644 --- a/pnpm-lock.yaml +++ b/pnpm-lock.yaml @@ -787,6 +787,8 @@ importers: tests/integration/format/import-meta-url: {} + tests/integration/format/mf-bundle-false: {} + tests/integration/json: {} tests/integration/minify/config/disabled: {} diff --git a/tests/integration/format/index.test.ts b/tests/integration/format/index.test.ts index 9f6c0f873..0e3fda57e 100644 --- a/tests/integration/format/index.test.ts +++ b/tests/integration/format/index.test.ts @@ -100,3 +100,14 @@ test('CJS exports should be statically analyzable (cjs-module-lexer for Node.js) } `); }); + +test('throw error when using mf with `bundle: false`', async () => { + const fixturePath = path.resolve(__dirname, 'mf-bundle-false'); + const build = buildAndGetResults({ + fixturePath, + }); + + await expect(build).rejects.toThrowErrorMatchingInlineSnapshot( + `[Error: When using "mf" format, "bundle" must be set to "true". Since the default value for "bundle" is "true", so you can either explicitly set it to "true" or remove the field entirely.]`, + ); +}); diff --git a/tests/integration/format/mf-bundle-false/package.json b/tests/integration/format/mf-bundle-false/package.json new file mode 100644 index 000000000..5cdf56682 --- /dev/null +++ b/tests/integration/format/mf-bundle-false/package.json @@ -0,0 +1,6 @@ +{ + "name": "format-mf-bundle-false-test", + "version": "1.0.0", + "private": true, + "type": "module" +} diff --git a/tests/integration/format/mf-bundle-false/rslib.config.ts b/tests/integration/format/mf-bundle-false/rslib.config.ts new file mode 100644 index 000000000..c7bb522e0 --- /dev/null +++ b/tests/integration/format/mf-bundle-false/rslib.config.ts @@ -0,0 +1,15 @@ +import { defineConfig } from '@rslib/core'; +import { generateBundleMFConfig } from 'test-helper'; + +export default defineConfig({ + lib: [ + generateBundleMFConfig( + { + name: 'test', + }, + { + bundle: false, + }, + ), + ], +}); diff --git a/tests/integration/format/mf-bundle-false/src/index.js b/tests/integration/format/mf-bundle-false/src/index.js new file mode 100644 index 000000000..3329a7d97 --- /dev/null +++ b/tests/integration/format/mf-bundle-false/src/index.js @@ -0,0 +1 @@ +export const foo = 'foo';