diff --git a/docs/README.md b/docs/README.md index 71b0ff83..175e1746 100644 --- a/docs/README.md +++ b/docs/README.md @@ -84,6 +84,8 @@ You can use any of these files: > INFO: In all the custom files you can export the options either as `tsup`, `default` or `module.exports =` +You can also specify a custom filename using the `--config` flag, or passing `--no-config` to disable config files. + [Check out all available options](https://paka.dev/npm/tsup#module-index-export-Options). #### TypeScript / JavaScript diff --git a/src/cli-main.ts b/src/cli-main.ts index 374ebbbb..1c40dac1 100644 --- a/src/cli-main.ts +++ b/src/cli-main.ts @@ -78,6 +78,7 @@ export async function main(options: Options = {}) { default: 'node', }) .option('--loader ', 'Specify the loader for a file extension') + .option('--config ', 'Use a custom config file') .option('--no-config', 'Disable config file') .option('--shims', 'Enable cjs and esm shims') .option('--inject-style', 'Inject style tag to document head') diff --git a/src/index.ts b/src/index.ts index feeb590f..8ac5f349 100644 --- a/src/index.ts +++ b/src/index.ts @@ -115,7 +115,12 @@ const normalizeOptions = async ( export async function build(_options: Options) { const config = - _options.config === false ? {} : await loadTsupConfig(process.cwd()) + _options.config === false + ? {} + : await loadTsupConfig( + process.cwd(), + _options.config === true ? undefined : _options.config + ) const configData = typeof config.data === 'function' diff --git a/src/load.ts b/src/load.ts index 14cf013c..4a8fe024 100644 --- a/src/load.ts +++ b/src/load.ts @@ -33,18 +33,21 @@ const jsonLoader = { joycon.addLoader(jsonLoader) export async function loadTsupConfig( - cwd: string + cwd: string, + configFile?: string ): Promise<{ path?: string; data?: ReturnType }> { const configJoycon = new JoyCon() const configPath = await configJoycon.resolve({ - files: [ - 'tsup.config.ts', - 'tsup.config.js', - 'tsup.config.cjs', - 'tsup.config.mjs', - 'tsup.config.json', - 'package.json', - ], + files: configFile + ? [configFile] + : [ + 'tsup.config.ts', + 'tsup.config.js', + 'tsup.config.cjs', + 'tsup.config.mjs', + 'tsup.config.json', + 'package.json', + ], cwd, stopDir: path.parse(cwd).root, packageKey: 'tsup', diff --git a/src/options.ts b/src/options.ts index 502fe761..f37320c5 100644 --- a/src/options.ts +++ b/src/options.ts @@ -142,8 +142,9 @@ export type Options = { loader?: Record /** * Disable config file with `false` + * Or pass a custom config filename */ - config?: boolean + config?: boolean | string /** * Use a custom tsconfig */ diff --git a/test/index.test.ts b/test/index.test.ts index fae18544..77acc078 100644 --- a/test/index.test.ts +++ b/test/index.test.ts @@ -886,3 +886,24 @@ test('custom output extension', async () => { ] `) }) + +test('custom config file', async () => { + const { outFiles } = await run( + getTestName(), + { + 'input.ts': `export const foo = [1,2,3]`, + 'custom.config.ts': `export default { + format: ['esm'] + }`, + }, + { + entry: ['input.ts'], + flags: ['--config', 'custom.config.ts'], + } + ) + expect(outFiles).toMatchInlineSnapshot(` + [ + "input.mjs", + ] + `) +}) diff --git a/tsconfig.json b/tsconfig.json index a99461b1..df1a32d9 100644 --- a/tsconfig.json +++ b/tsconfig.json @@ -8,7 +8,8 @@ // "allowJs": true, /* Allow javascript files to be compiled. */ // "checkJs": true, /* Report errors in .js files. */ // "jsx": "preserve", /* Specify JSX code generation: 'preserve', 'react-native', or 'react'. */ - // "declaration": true, /* Generates corresponding '.d.ts' file. */ + "declaration": true /* Generates corresponding '.d.ts' file. */, + "declarationDir": "dist", // "declarationMap": true, /* Generates a sourcemap for each corresponding '.d.ts' file. */ // "sourceMap": true, /* Generates corresponding '.map' file. */ // "outFile": "./", /* Concatenate and emit output to single file. */