Skip to content

Commit

Permalink
perf(build): minify bundle (#101)
Browse files Browse the repository at this point in the history
esbuild minify bundle and set side effects false
  • Loading branch information
Everduin94 committed May 2, 2024
1 parent 2cb28ae commit a32fe6b
Show file tree
Hide file tree
Showing 7 changed files with 35 additions and 32 deletions.
4 changes: 2 additions & 2 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
"description": "A CLI for creating better commits following the conventional commits specification",
"author": "Erik Verduin (https://github.com/everduin94)",
"type": "module",
"sideEffects": false,
"keywords": [
"typescript",
"cli",
Expand Down
6 changes: 5 additions & 1 deletion src/branch.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,11 @@ import Configstore from "configstore";
import color from "picocolors";
import { chdir } from "process";
import { Output, parse } from "valibot";
import { V_BRANCH_ACTIONS, V_BRANCH_CONFIG_FIELDS, V_BRANCH_FIELDS } from "./valibot-consts";
import {
V_BRANCH_ACTIONS,
V_BRANCH_CONFIG_FIELDS,
V_BRANCH_FIELDS,
} from "./valibot-consts";
import { BranchState, CommitState, Config } from "./valibot-state";
import {
BRANCH_ACTION_OPTIONS,
Expand Down
2 changes: 1 addition & 1 deletion src/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import fs from "fs";
import { homedir } from "os";
import color from "picocolors";
import { Output, ValiError, parse } from "valibot";
import { Config } from "./valibot-state";
import { Config } from "./valibot-state";
import { V_BRANCH_ACTIONS } from "./valibot-consts";

export const CONFIG_FILE_NAME = ".better-commits.json";
Expand Down
4 changes: 1 addition & 3 deletions src/valibot-consts.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import * as v from 'valibot';
import * as v from "valibot";

export const CUSTOM_SCOPE_KEY: "custom" = "custom";
export const FOOTER_OPTION_VALUES: v.Output<typeof V_FOOTER_OPTIONS>[] = [
Expand Down Expand Up @@ -112,5 +112,3 @@ export const DEFAULT_TYPE_OPTIONS = [
},
{ value: "", label: "none" },
];


31 changes: 21 additions & 10 deletions src/valibot-state.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,14 @@
import * as v from 'valibot';
import { BRANCH_ORDER_DEFAULTS, CUSTOM_SCOPE_KEY, DEFAULT_SCOPE_OPTIONS, DEFAULT_TYPE_OPTIONS, FOOTER_OPTION_VALUES, V_BRANCH_ACTIONS, V_BRANCH_FIELDS, V_FOOTER_OPTIONS } from './valibot-consts';
import * as v from "valibot";
import {
BRANCH_ORDER_DEFAULTS,
CUSTOM_SCOPE_KEY,
DEFAULT_SCOPE_OPTIONS,
DEFAULT_TYPE_OPTIONS,
FOOTER_OPTION_VALUES,
V_BRANCH_ACTIONS,
V_BRANCH_FIELDS,
V_FOOTER_OPTIONS,
} from "./valibot-consts";

export const Config = v.object({
check_status: v.optional(v.boolean(), true),
Expand Down Expand Up @@ -27,7 +36,8 @@ export const Config = v.object({
},
[
v.custom(
(val) => val.options.map((v) => v.value).includes(val.initial_value),
(val) =>
val.options.map((v) => v.value).includes(val.initial_value),
(val) => {
const input = val.input as { initial_value: string };
return `Type: initial_value "${input.initial_value}" must exist in options`;
Expand All @@ -38,13 +48,14 @@ export const Config = v.object({
{},
),
(val) => {
const options = val.options.map((v) => ({
...v,
label:
v.emoji && val.append_emoji_to_label
? `${v.emoji} ${v.label}`
: v.label,
})) ?? [];
const options =
val.options.map((v) => ({
...v,
label:
v.emoji && val.append_emoji_to_label
? `${v.emoji} ${v.label}`
: v.label,
})) ?? [];
return { ...val, options };
},
),
Expand Down
19 changes: 4 additions & 15 deletions tsup.config.ts
Original file line number Diff line number Diff line change
@@ -1,23 +1,12 @@
import { defineConfig } from 'tsup';
import { defineConfig } from "tsup";

export default defineConfig([
{
entry: ['./src/index.ts','./src/branch.ts','./src/init.ts'],
entry: ["./src/index.ts", "./src/branch.ts", "./src/init.ts"],
clean: true,
format: ['esm'],
minify: false,
dts: false,
outDir: './dist',
},
{
entry: ['./src/index.ts','./src/branch.ts','./src/init.ts'],
clean: true,
format: ['esm'],
format: ["esm"],
minify: true,
dts: false,
outDir: './dist',
outExtension: ({ format }) => ({
js: format === 'cjs' ? '.min.cjs' : '.min.js',
}),
outDir: "./dist",
},
]);

0 comments on commit a32fe6b

Please sign in to comment.