Skip to content

Commit

Permalink
feat: allow to configure prettier for single dep (#8)
Browse files Browse the repository at this point in the history
  • Loading branch information
chenjiahan authored Jul 11, 2024
1 parent c2e2131 commit 0d0ef4e
Show file tree
Hide file tree
Showing 4 changed files with 12 additions and 5 deletions.
7 changes: 6 additions & 1 deletion src/helper.ts
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,10 @@ export const resolveConfig = async () => {
return config.default as Config;
};

export function parseTasks(dependencies: Array<string | DependencyConfig>) {
export function parseTasks(
dependencies: Array<string | DependencyConfig>,
globalPrettier?: boolean,
) {
const result: ParsedTask[] = [];

for (const dep of dependencies) {
Expand Down Expand Up @@ -61,6 +64,7 @@ export function parseTasks(dependencies: Array<string | DependencyConfig>) {
dtsExternals: [],
emitFiles: [],
packageJsonField: [],
prettier: globalPrettier,
...info,
});
} else {
Expand All @@ -71,6 +75,7 @@ export function parseTasks(dependencies: Array<string | DependencyConfig>) {
externals: dep.externals ?? {},
dtsExternals: dep.dtsExternals ?? [],
emitFiles: dep.emitFiles ?? [],
prettier: dep.prettier ?? globalPrettier,
afterBundle: dep.afterBundle,
beforeBundle: dep.beforeBundle,
packageJsonField: dep.packageJsonField ?? [],
Expand Down
4 changes: 2 additions & 2 deletions src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,10 @@ import { prebundle } from './prebundle.js';

export async function run() {
const config = await resolveConfig();
const parsedTasks = parseTasks(config.dependencies);
const parsedTasks = parseTasks(config.dependencies, config.prettier);

for (const task of parsedTasks) {
await prebundle(task, config.externals, config.prettier);
await prebundle(task, config.externals);
}
}

Expand Down
3 changes: 1 addition & 2 deletions src/prebundle.ts
Original file line number Diff line number Diff line change
Expand Up @@ -203,7 +203,6 @@ const pkgName = process.argv[2];
export async function prebundle(
task: ParsedTask,
commonExternals: Record<string, string> = {},
prettier?: boolean,
) {
if (pkgName && task.depName !== pkgName) {
return;
Expand All @@ -230,7 +229,7 @@ export async function prebundle(
assetBuilds: false,
});

await emitIndex(code, task.distPath, prettier);
await emitIndex(code, task.distPath, task.prettier);
emitAssets(assets, task.distPath);
await emitDts(task, mergedExternals);
emitLicense(task);
Expand Down
3 changes: 3 additions & 0 deletions src/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,8 @@ export type DependencyConfig = {
externals?: Record<string, string>;
/** Externals types */
dtsExternals?: Array<string | RegExp>;
/** Whether to prettier the code and strip comments */
prettier?: boolean;
/** Emit extra entry files to map imports. */
emitFiles?: ImportMap[];
/** Copy extra fields from original package.json to target package.json. */
Expand Down Expand Up @@ -43,6 +45,7 @@ export type ParsedTask = {
distPath: string;
importPath: string;
ignoreDts?: boolean;
prettier?: boolean;
target: NonNullable<DependencyConfig['target']>;
minify: NonNullable<DependencyConfig['minify']>;
depName: NonNullable<DependencyConfig['name']>;
Expand Down

0 comments on commit 0d0ef4e

Please sign in to comment.