Skip to content

Commit

Permalink
build: better options for createTsupConfig
Browse files Browse the repository at this point in the history
  • Loading branch information
favna committed Dec 4, 2023
1 parent 75f215c commit 9630bf1
Show file tree
Hide file tree
Showing 23 changed files with 130 additions and 52 deletions.
6 changes: 5 additions & 1 deletion packages/async-queue/tsup.config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,4 +3,8 @@ import { createTsupConfig } from '../../scripts/tsup.config';

const options: Options = { target: 'es2020' };

export default createTsupConfig(options, options, { ...options, globalName: 'SapphireAsyncQueue' });
export default createTsupConfig({
cjsOptions: options,
esmOptions: options,
iifeOptions: { ...options, globalName: 'SapphireAsyncQueue' }
});
4 changes: 3 additions & 1 deletion packages/bitfield/tsup.config.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
import { createTsupConfig } from '../../scripts/tsup.config';

export default createTsupConfig(undefined, undefined, { globalName: 'SapphireBitField' });
export default createTsupConfig({
iifeOptions: { globalName: 'SapphireBitField' }
});
6 changes: 5 additions & 1 deletion packages/cron/tsup.config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,4 +3,8 @@ import { createTsupConfig } from '../../scripts/tsup.config';

const options: Options = { target: 'es2020' };

export default createTsupConfig(options, options, { ...options, globalName: 'SapphireCron' });
export default createTsupConfig({
cjsOptions: options,
esmOptions: options,
iifeOptions: { ...options, globalName: 'SapphireCron' }
});
4 changes: 3 additions & 1 deletion packages/decorators/tsup.config.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
import { createTsupConfig } from '../../scripts/tsup.config';

export default createTsupConfig(undefined, undefined, { disabled: true });
export default createTsupConfig({
iifeOptions: { disabled: true }
});
4 changes: 3 additions & 1 deletion packages/discord-utilities/tsup.config.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
import { createTsupConfig } from '../../scripts/tsup.config';

export default createTsupConfig(undefined, undefined, { globalName: 'SapphireDiscordUtilities' });
export default createTsupConfig({
iifeOptions: { globalName: 'SapphireDiscordUtilities' }
});
4 changes: 3 additions & 1 deletion packages/discord.js-utilities/tsup.config.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
import { createTsupConfig } from '../../scripts/tsup.config';

export default createTsupConfig(undefined, undefined, { disabled: true });
export default createTsupConfig({
iifeOptions: { disabled: true }
});
6 changes: 5 additions & 1 deletion packages/duration/tsup.config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,4 +3,8 @@ import { createTsupConfig } from '../../scripts/tsup.config';

const options: Options = { target: 'es2020' };

export default createTsupConfig(options, options, { ...options, globalName: 'SapphireDuration' });
export default createTsupConfig({
cjsOptions: options,
esmOptions: options,
iifeOptions: { ...options, globalName: 'SapphireDuration' }
});
6 changes: 5 additions & 1 deletion packages/eslint-config/tsup.config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,4 +6,8 @@ const options: Options = {
dts: false
};

export default createTsupConfig(options, options, { disabled: true });
export default createTsupConfig({
cjsOptions: options,
esmOptions: options,
iifeOptions: { disabled: true }
});
6 changes: 5 additions & 1 deletion packages/eslint-plugin-result/tsup.config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,4 +6,8 @@ const options: Options = {
dts: false
};

export default createTsupConfig(options, options, { disabled: true });
export default createTsupConfig({
cjsOptions: options,
esmOptions: options,
iifeOptions: { disabled: true }
});
4 changes: 3 additions & 1 deletion packages/event-iterator/tsup.config.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
import { createTsupConfig } from '../../scripts/tsup.config';

export default createTsupConfig(undefined, undefined, { disabled: true });
export default createTsupConfig({
iifeOptions: { disabled: true }
});
6 changes: 5 additions & 1 deletion packages/fetch/tsup.config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -32,4 +32,8 @@ const options: Options = {
}
};

export default createTsupConfig(options, options, { ...options, globalName: 'SapphireFetch' });
export default createTsupConfig({
cjsOptions: options,
esmOptions: options,
iifeOptions: { ...options, globalName: 'SapphireFetch' }
});
4 changes: 3 additions & 1 deletion packages/lexure/tsup.config.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
import { createTsupConfig } from '../../scripts/tsup.config';

export default createTsupConfig(undefined, undefined, { globalName: 'SapphireLexure' });
export default createTsupConfig({
iifeOptions: { globalName: 'SapphireLexure' }
});
4 changes: 3 additions & 1 deletion packages/node-utilities/tsup.config.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
import { createTsupConfig } from '../../scripts/tsup.config';

export default createTsupConfig(undefined, undefined, { disabled: true });
export default createTsupConfig({
iifeOptions: { disabled: true }
});
4 changes: 3 additions & 1 deletion packages/phisherman/tsup.config.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
import { createTsupConfig } from '../../scripts/tsup.config';

export default createTsupConfig(undefined, undefined, { disabled: true });
export default createTsupConfig({
iifeOptions: { disabled: true }
});
6 changes: 5 additions & 1 deletion packages/ratelimits/tsup.config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,4 +3,8 @@ import { createTsupConfig } from '../../scripts/tsup.config';

const options: Options = { target: 'es2020' };

export default createTsupConfig(options, options, { ...options, globalName: 'SapphireSnowflake' });
export default createTsupConfig({
cjsOptions: options,
esmOptions: options,
iifeOptions: { ...options, globalName: 'SapphireSnowflake' }
});
4 changes: 3 additions & 1 deletion packages/result/tsup.config.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
import { createTsupConfig } from '../../scripts/tsup.config';

export default createTsupConfig(undefined, undefined, { globalName: 'SapphireResult' });
export default createTsupConfig({
iifeOptions: { globalName: 'SapphireResult' }
});
6 changes: 5 additions & 1 deletion packages/snowflake/tsup.config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,4 +3,8 @@ import { createTsupConfig } from '../../scripts/tsup.config';

const options: Options = { target: 'es2020' };

export default createTsupConfig(options, options, { ...options, globalName: 'SapphireSnowflake' });
export default createTsupConfig({
cjsOptions: options,
esmOptions: options,
iifeOptions: { ...options, globalName: 'SapphireSnowflake' }
});
4 changes: 3 additions & 1 deletion packages/stopwatch/tsup.config.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
import { createTsupConfig } from '../../scripts/tsup.config';

export default createTsupConfig(undefined, undefined, { globalName: 'SapphireStopwatch' });
export default createTsupConfig({
iifeOptions: { globalName: 'SapphireStopwatch' }
});
6 changes: 5 additions & 1 deletion packages/time-utilities/tsup.config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,4 +3,8 @@ import { createTsupConfig } from '../../scripts/tsup.config';

const options: Options = { target: 'es2020' };

export default createTsupConfig(options, options, { ...options, globalName: 'SapphireTimeUtilities' });
export default createTsupConfig({
cjsOptions: options,
esmOptions: options,
iifeOptions: { ...options, globalName: 'SapphireTimeUtilities' }
});
6 changes: 5 additions & 1 deletion packages/timer-manager/tsup.config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,4 +3,8 @@ import { createTsupConfig } from '../../scripts/tsup.config';

const options: Options = { target: 'es2020' };

export default createTsupConfig(options, options, { ...options, globalName: 'SapphireTimerManager' });
export default createTsupConfig({
cjsOptions: options,
esmOptions: options,
iifeOptions: { ...options, globalName: 'SapphireTimerManager' }
});
6 changes: 5 additions & 1 deletion packages/timestamp/tsup.config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,4 +3,8 @@ import { createTsupConfig } from '../../scripts/tsup.config';

const options: Options = { target: 'es2020' };

export default createTsupConfig(options, options, { ...options, globalName: 'SapphireTimestamp' });
export default createTsupConfig({
cjsOptions: options,
esmOptions: options,
iifeOptions: { ...options, globalName: 'SapphireTimestamp' }
});
12 changes: 10 additions & 2 deletions packages/utilities/tsup.config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,18 @@ import { Options } from 'tsup';
import { createTsupConfig } from '../../scripts/tsup.config';

const options: Options = {
target: 'es2019',
target: 'es2019'
};

const cjsAndEsmOptions: Options = {
...options,
bundle: true,
entry: ['src/**/*.ts', '!src/**/*.d.ts'],
esbuildPlugins: [esbuildPluginFilePathExtensions()]
};

export default createTsupConfig(options, options, { ...options, globalName: 'SapphireUtilities' });
export default createTsupConfig({
cjsOptions: cjsAndEsmOptions,
esmOptions: cjsAndEsmOptions,
iifeOptions: { ...options, globalName: 'SapphireUtilities' }
});
64 changes: 35 additions & 29 deletions scripts/tsup.config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,34 +14,40 @@ const baseOptions: Options = {
treeshake: true
};

export const createTsupConfig = (cjsOptions: Options = {}, esmOptions: Options = cjsOptions, iifeOptions: IifeOptions = cjsOptions) => [
defineConfig({
...baseOptions,
outDir: 'dist/cjs',
format: 'cjs',
outExtension: () => ({ js: '.cjs' }),
...cjsOptions
}),
defineConfig({
...baseOptions,
outDir: 'dist/esm',
format: 'esm',
...esmOptions
}),
...(iifeOptions.disabled
? []
: [
defineConfig({
...baseOptions,
dts: false,
entry: ['src/index.ts'],
outDir: 'dist/iife',
format: 'iife',
...iifeOptions
})
])
];
export function createTsupConfig(options: EnhancedTsupOptions) {
return [
defineConfig({
...baseOptions,
outDir: 'dist/cjs',
format: 'cjs',
outExtension: () => ({ js: '.cjs' }),
...options.cjsOptions
}),
defineConfig({
...baseOptions,
outDir: 'dist/esm',
format: 'esm',
...options.esmOptions
}),
...(options.iifeOptions?.disabled
? []
: [
defineConfig({
...baseOptions,
dts: false,
entry: ['src/index.ts'],
outDir: 'dist/iife',
format: 'iife',
...options.iifeOptions
})
])
];
}

export interface IifeOptions extends Options {
disabled?: boolean;
interface EnhancedTsupOptions {
cjsOptions?: Options;
esmOptions?: Options;
iifeOptions?: Options & {
disabled?: boolean;
};
}

0 comments on commit 9630bf1

Please sign in to comment.