Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

docs: add jsdocs #363

Merged
merged 4 commits into from
Jun 4, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
145 changes: 143 additions & 2 deletions src/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -50,52 +50,176 @@ export type BuildEntry =
| CopyBuildEntry;

export interface RollupBuildOptions {
/**
* If enabled, unbuild generates a CommonJS build in addition to the ESM build.
*/
emitCJS?: boolean;

/**
* If enabled, unbuild generates CommonJS polyfills for ESM builds.
*/
cjsBridge?: boolean;

/**
* Preserve dynamic imports as-is
*/
preserveDynamicImports?: boolean;

/**
* Inline dependencies nor explicitly set in "dependencies" or "peerDependencies" or as marked externals to the bundle.
*/
inlineDependencies?: boolean;

/**
* Rollup [Output Options](https://rollupjs.org/configuration-options)
*/
output?: OutputOptions;
// Plugins

/**
* Replace plugin options
* Set to `false` to disable the plugin.
* Read more: [@rollup/plugin-replace](https://www.npmjs.com/package/@rollup/plugin-replace)
*/
replace: RollupReplaceOptions | false;

/**
* Alias plugin options
* Set to `false` to disable the plugin.
* Read more: [@rollup/plugin-alias](https://www.npmjs.com/package/@rollup/plugin-alias)
*/
alias: RollupAliasOptions | false;

/**
* Resolve plugin options
* Set to `false` to disable the plugin.
* Read more: [@rollup/plugin-node-resolve](https://www.npmjs.com/package/@rollup/plugin-node-resolve)
*/
resolve: RollupNodeResolveOptions | false;

/**
* JSON plugin options
* Set to `false` to disable the plugin.
* Read more: [@rollup/plugin-json](https://www.npmjs.com/package/@rollup/plugin-json)
*/
json: RollupJsonOptions | false;

/**
* ESBuild plugin options
* Set to `false` to disable the plugin.
* Read more: [esbuild](https://www.npmjs.com/package/esbuild)
*/
esbuild: EsbuildOptions | false;

/**
* CommonJS plugin options
* Set to `false` to disable the plugin.
* Read more: [@rollup/plugin-commonjs](https://www.npmjs.com/package/@rollup/plugin-commonjs)
*/
commonjs: RollupCommonJSOptions | false;

/**
* DTS plugin options
* Set to `false` to disable the plugin.
* Read more: [rollup-plugin-dts](https://www.npmjs.com/package/rollup-plugin-dts)
*/
dts: RollupDtsOptions;
}

export interface BuildOptions {
/**
* The name of the project.
*/
name: string;

/**
* The root directory of the project.
*/
rootDir: string;

/**
* Build entries.
*/
entries: BuildEntry[];

/**
* Clean the output directory before building.
*/
clean: boolean;
/** @experimental */

/**
* @experimental
* Generate source mapping file.
*/
sourcemap: boolean;

/**
* Whether to generate declaration files.
* * `compatible` means "src/index.ts" will generate "dist/index.d.mts", "dist/index.d.cts" and "dist/index.d.ts".
* * `node16` means "src/index.ts" will generate "dist/index.d.mts" and "dist/index.d.cts".
* * `true` is equivalent to `compatible`.
* * `false` will disable declaration generation.
* * `undefined` will auto detect based on "package.json". If "package.json" has "types" field, it will be `"compatible"`, otherwise `false`.
*/
declaration?: "compatible" | "node16" | boolean;

/**
* Output directory.
*/
outDir: string;

/**
* Whether to generate declaration files.
* [stubbing](https://antfu.me/posts/publish-esm-and-cjs#stubbing)
*/
stub: boolean;

/**
* Stub options, where [jiti](https://github.com/unjs/jiti)
* is an object of type `Omit<JITIOptions, "transform" | "onError">`.
*/
stubOptions: { jiti: Omit<JITIOptions, "transform" | "onError"> };

/**
* Used to specify which modules or libraries should be considered external dependencies
* and not included in the final build product.
*/
externals: (string | RegExp)[];

dependencies: string[];

peerDependencies: string[];

devDependencies: string[];

/**
* Create aliases for module imports to reference modules in code using more concise paths.
* Allow you to specify an alias for the module path.
*/
alias: { [find: string]: string };

/**
* Replace the text in the source code with rules.
*/
replace: { [find: string]: string };

/**
* Terminate the build process when a warning appears
*/
failOnWarn?: boolean;

/**
* [Rollup](https://rollupjs.org/configuration-options) Build Options
*/
rollup: RollupBuildOptions;
}

export interface BuildContext {
options: BuildOptions;
/**
* Read more: [pkg-types](https://github.com/unjs/pkg-types#readme).
*/
pkg: PackageJson;

buildEntries: {
path: string;
bytes?: number;
Expand All @@ -104,6 +228,7 @@ export interface BuildContext {
chunk?: boolean;
modules?: { id: string; bytes: number }[];
}[];

usedImports: Set<string>;
warnings: Set<string>;
hooks: Hookable<BuildHooks>;
Expand All @@ -113,10 +238,26 @@ export type BuildPreset = BuildConfig | (() => BuildConfig);

type DeepPartial<T> = { [P in keyof T]?: DeepPartial<T[P]> };

/**
* In addition to basic `entries`, `presets`, and `hooks`,
* there are also all the properties of `BuildOptions` except for BuildOptions's `entries`.
*/
export interface BuildConfig
extends DeepPartial<Omit<BuildOptions, "entries">> {
/**
* Specify the entry file or entry module during the construction process.
*/
entries?: (BuildEntry | string)[];

/**
* Used to specify the preset build configuration.
*/
preset?: string | BuildPreset;

/**
* Used to define hook functions during the construction process to perform custom operations during specific construction stages.
* This configuration allows you to insert custom logic during the build process to meet specific requirements or perform additional operations.
*/
hooks?: Partial<BuildHooks>;
}

Expand Down