diff --git a/e2e/cases/dts/__snapshots__/index.test.ts.snap b/e2e/cases/dts/__snapshots__/index.test.ts.snap index d289eeff6..b8d780689 100644 --- a/e2e/cases/dts/__snapshots__/index.test.ts.snap +++ b/e2e/cases/dts/__snapshots__/index.test.ts.snap @@ -1,6 +1,6 @@ // Vitest Snapshot v1, https://vitest.dev/guide/snapshot.html -exports[`dts when bundle: false 1`] = ` +exports[`dts when bundle: false > basic - bundleless dts 1`] = ` { "./dist/esm/index.d.ts": "export * from './utils/numbers'; export * from './utils/strings'; @@ -20,7 +20,7 @@ export declare const str3 = "str3"; } `; -exports[`dts when bundle: true 1`] = ` +exports[`dts when bundle: true > basic - bundle dts 1`] = ` { "esm": "export declare const num1 = 1; diff --git a/e2e/cases/dts/bundle-false/rslib.distpath.config.ts b/e2e/cases/dts/bundle-false/rslib.distpath.config.ts new file mode 100644 index 000000000..fcb9d056c --- /dev/null +++ b/e2e/cases/dts/bundle-false/rslib.distpath.config.ts @@ -0,0 +1,22 @@ +import { generateBundleCjsConfig, generateBundleEsmConfig } from '@e2e/helper'; +import { defineConfig } from '@rslib/core'; + +export default defineConfig({ + lib: [ + generateBundleEsmConfig(__dirname, { + bundle: false, + dts: { + bundle: false, + distPath: './dist/custom', + }, + }), + generateBundleCjsConfig(__dirname, { + bundle: false, + }), + ], + source: { + entry: { + main: ['./src/**'], + }, + }, +}); diff --git a/e2e/cases/dts/bundle-false/rslib.false.config.ts b/e2e/cases/dts/bundle-false/rslib.false.config.ts new file mode 100644 index 000000000..dc0adc946 --- /dev/null +++ b/e2e/cases/dts/bundle-false/rslib.false.config.ts @@ -0,0 +1,19 @@ +import { generateBundleCjsConfig, generateBundleEsmConfig } from '@e2e/helper'; +import { defineConfig } from '@rslib/core'; + +export default defineConfig({ + lib: [ + generateBundleEsmConfig(__dirname, { + bundle: false, + dts: false, + }), + generateBundleCjsConfig(__dirname, { + bundle: false, + }), + ], + source: { + entry: { + main: ['./src/**'], + }, + }, +}); diff --git a/e2e/cases/dts/bundle/rslib.distpath.config.ts b/e2e/cases/dts/bundle/rslib.distpath.config.ts new file mode 100644 index 000000000..2adf35fb8 --- /dev/null +++ b/e2e/cases/dts/bundle/rslib.distpath.config.ts @@ -0,0 +1,19 @@ +import { generateBundleCjsConfig, generateBundleEsmConfig } from '@e2e/helper'; +import { defineConfig } from '@rslib/core'; + +export default defineConfig({ + lib: [ + generateBundleEsmConfig(__dirname, { + dts: { + bundle: true, + distPath: './dist/custom', + }, + }), + generateBundleCjsConfig(__dirname), + ], + source: { + entry: { + main: './src/index.ts', + }, + }, +}); diff --git a/e2e/cases/dts/bundle/rslib.false.config.ts b/e2e/cases/dts/bundle/rslib.false.config.ts new file mode 100644 index 000000000..631fd8e0b --- /dev/null +++ b/e2e/cases/dts/bundle/rslib.false.config.ts @@ -0,0 +1,16 @@ +import { generateBundleCjsConfig, generateBundleEsmConfig } from '@e2e/helper'; +import { defineConfig } from '@rslib/core'; + +export default defineConfig({ + lib: [ + generateBundleEsmConfig(__dirname, { + dts: false, + }), + generateBundleCjsConfig(__dirname), + ], + source: { + entry: { + main: './src/index.ts', + }, + }, +}); diff --git a/e2e/cases/dts/index.test.ts b/e2e/cases/dts/index.test.ts index 22e5f307b..4699cd9da 100644 --- a/e2e/cases/dts/index.test.ts +++ b/e2e/cases/dts/index.test.ts @@ -1,20 +1,76 @@ import { join } from 'node:path'; import { buildAndGetResults } from '@e2e/helper'; -import { expect, test } from 'vitest'; +import { describe, expect, test } from 'vitest'; -test('dts when bundle: false', async () => { - const fixturePath = join(__dirname, 'bundle-false'); - const { files, contents } = await buildAndGetResults(fixturePath, 'dts'); +describe('dts when bundle: false', () => { + test('basic - bundleless dts', async () => { + const fixturePath = join(__dirname, 'bundle-false'); + const { files, contents } = await buildAndGetResults( + fixturePath, + 'rslib.config.ts', + 'dts', + ); - expect(files.esm?.length).toBe(4); - expect(files.esm?.[0]!.endsWith('.d.ts')).toEqual(true); - expect(contents.esm).toMatchSnapshot(); + expect(files.esm?.length).toBe(4); + expect(files.esm?.[0]!.endsWith('.d.ts')).toEqual(true); + expect(contents.esm).toMatchSnapshot(); + }); + + test('dts false - bundleless dts', async () => { + const fixturePath = join(__dirname, 'bundle-false'); + const { files } = await buildAndGetResults( + fixturePath, + 'rslib.false.config.ts', + 'dts', + ); + + expect(files.esm).toBe(undefined); + }); + + test('distPath - bundleless dts', async () => { + const fixturePath = join(__dirname, 'bundle-false'); + const { files } = await buildAndGetResults( + fixturePath, + 'rslib.distpath.config.ts', + 'dts', + ); + expect(files.esm?.length).toBe(4); + expect(files.esm?.[0]!.startsWith('./dist/custom')).toEqual(true); + }); }); -test('dts when bundle: true', async () => { - const fixturePath = join(__dirname, 'bundle'); - const { entryFiles, entries } = await buildAndGetResults(fixturePath, 'dts'); +describe('dts when bundle: true', () => { + test('basic - bundle dts', async () => { + const fixturePath = join(__dirname, 'bundle'); + const { entryFiles, entries } = await buildAndGetResults( + fixturePath, + 'rslib.config.ts', + 'dts', + ); + + expect(entryFiles.esm!.endsWith('index.d.ts')).toEqual(true); + expect(entries).toMatchSnapshot(); + }); + + test('dts false - bundle dts', async () => { + const fixturePath = join(__dirname, 'bundle'); + const { entryFiles } = await buildAndGetResults( + fixturePath, + 'rslib.false.config.ts', + 'dts', + ); + + expect(entryFiles.esm).toEqual(undefined); + }); + + test('distPath - bundle dts', async () => { + const fixturePath = join(__dirname, 'bundle'); + const { entryFiles } = await buildAndGetResults( + fixturePath, + 'rslib.distpath.config.ts', + 'dts', + ); - expect(entryFiles.esm!.endsWith('index.d.ts')).toEqual(true); - expect(entries).toMatchSnapshot(); + expect(entryFiles.esm!.startsWith('./dist/custom')).toEqual(true); + }); }); diff --git a/e2e/scripts/shared.ts b/e2e/scripts/shared.ts index 248976be9..2353afd47 100644 --- a/e2e/scripts/shared.ts +++ b/e2e/scripts/shared.ts @@ -104,6 +104,7 @@ export async function getResults( export const buildAndGetResults = async ( fixturePath: string, + configFile = 'rslib.config.ts', type: 'js' | 'dts' = 'js', ): Promise<{ contents: Record>; @@ -113,7 +114,7 @@ export const buildAndGetResults = async ( rspackConfig: InspectConfigResult['origin']['bundlerConfigs']; rsbuildConfig: InspectConfigResult['origin']['rsbuildConfig']; }> => { - const rslibConfig = await loadConfig(join(fixturePath, 'rslib.config.ts')); + const rslibConfig = await loadConfig(join(fixturePath, configFile)); process.chdir(fixturePath); const rsbuildInstance = await build(rslibConfig); const { diff --git a/scripts/dictionary.txt b/scripts/dictionary.txt index 8c0d22567..422cbc5c2 100644 --- a/scripts/dictionary.txt +++ b/scripts/dictionary.txt @@ -22,6 +22,7 @@ craco crossorigin datauri deepmerge +distpath docgen dogfooding envinfo