Skip to content

Commit

Permalink
feat: add declaration (#624)
Browse files Browse the repository at this point in the history
* feat: add declaration

* chore: lint

* chore: change pos

* chore: changeset

---------

Co-authored-by: luhc228 <[email protected]>
  • Loading branch information
HomyeeKing and luhc228 authored Feb 2, 2024
1 parent af38e3c commit e099923
Show file tree
Hide file tree
Showing 4 changed files with 36 additions and 18 deletions.
5 changes: 5 additions & 0 deletions .changeset/fluffy-penguins-buy.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
'@ice/pkg': patch
---

feat: add declaration user config
5 changes: 5 additions & 0 deletions packages/pkg/src/config/userConfig.ts
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,11 @@ function getUserConfig() {
validation: 'boolean',
default: false,
},
{
name: 'declaration',
validation: 'boolean',
default: true,
},
// TODO: validate values recursively
{
name: 'transform',
Expand Down
20 changes: 11 additions & 9 deletions packages/pkg/src/helpers/getRollupOptions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -72,15 +72,17 @@ export function getRollupOptions(
);

if (taskConfig.type === 'transform') {
rollupOptions.plugins.unshift(
dtsPlugin({
rootDir,
entry: taskConfig.entry as Record<string, string>,
generateTypesForJs: userConfig.generateTypesForJs,
alias: taskConfig.alias,
outputDir: taskConfig.outputDir,
}),
);
if (userConfig.declaration) {
rollupOptions.plugins.unshift(
dtsPlugin({
rootDir,
entry: taskConfig.entry as Record<string, string>,
generateTypesForJs: userConfig.generateTypesForJs,
alias: taskConfig.alias,
outputDir: taskConfig.outputDir,
}),
);
}
rollupOptions.plugins.push(transformAliasPlugin(rootDir, taskConfig.alias));
} else if (taskConfig.type === 'bundle') {
const [external, globals] = getExternalsAndGlobals(taskConfig, pkg as PkgJson);
Expand Down
24 changes: 15 additions & 9 deletions packages/pkg/src/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -100,9 +100,9 @@ export interface BundleUserConfig {

export interface UserConfig {
/**
* Entry for a task
* @default `./src/index`
*/
* Entry for a task
* @default `./src/index`
*/
entry?: RollupOptions['input'];
/**
* Alias to file system paths
Expand All @@ -114,17 +114,23 @@ export interface UserConfig {
*/
define?: PlainObject;
/**
* - true to generate a sourcemap for the code and include it in the result object.
* - "inline" to generate a sourcemap and append it as a data URL to the end of the code,
* but not include it in the result object.
* - true to generate a sourcemap for the code and include it in the result object.
* - "inline" to generate a sourcemap and append it as a data URL to the end of the code,
* but not include it in the result object.
*/
sourceMaps?: boolean | 'inline';
/**
* Whether or not to generate declaration files for Ecmascript
* @default false
*/
* Whether or not to generate declaration files for Ecmascript
* @default false
*/
generateTypesForJs?: boolean;

/**
* Generate .d.ts files from TypeScript files in your project.
* @default true
*/
declaration?: boolean;

/**
* Configure JSX transform type.
* @default 'automatic'
Expand Down

0 comments on commit e099923

Please sign in to comment.