Skip to content

Commit 40ec1d9

Browse files
committed
chore: format with prettier v3
1 parent c338907 commit 40ec1d9

File tree

14 files changed

+99
-94
lines changed

14 files changed

+99
-94
lines changed

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -61,7 +61,7 @@
6161
"changelogen": "^0.5.4",
6262
"eslint": "^8.45.0",
6363
"eslint-config-unjs": "^0.2.1",
64-
"prettier": "^2.8.8",
64+
"prettier": "^3.0.0",
6565
"vitest": "^0.33.0"
6666
},
6767
"packageManager": "pnpm@8.2.0"

pnpm-lock.yaml

Lines changed: 5 additions & 5 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

src/auto.ts

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -40,17 +40,17 @@ export const autoPreset = definePreset(() => {
4040
chalk.bold(
4141
e.input
4242
.replace(ctx.options.rootDir + "/", "")
43-
.replace(/\/$/, "/*")
44-
)
43+
.replace(/\/$/, "/*"),
44+
),
4545
)
46-
.join(", ")
46+
.join(", "),
4747
),
4848
chalk.gray(
4949
["esm", res.cjs && "cjs", res.dts && "dts"]
5050
.filter(Boolean)
5151
.map((tag) => `[${tag}]`)
52-
.join(" ")
53-
)
52+
.join(" "),
53+
),
5454
);
5555
},
5656
},
@@ -65,7 +65,7 @@ export const autoPreset = definePreset(() => {
6565
*/
6666
export function inferEntries(
6767
pkg: PackageJson,
68-
sourceFiles: string[]
68+
sourceFiles: string[],
6969
): InferEntriesResult {
7070
const warnings = [];
7171

@@ -113,7 +113,7 @@ export function inferEntries(
113113
// But we support any file extension here in case user has extended rollup options
114114
const outputSlug = output.file.replace(
115115
/(\*[^/\\]*|\.d\.(m|c)?ts|\.\w+)$/,
116-
""
116+
"",
117117
);
118118
const isDir = outputSlug.endsWith("/");
119119

src/build.ts

Lines changed: 14 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ import { mkdistBuild } from "./builder/mkdist";
2424
export async function build(
2525
rootDir: string,
2626
stub: boolean,
27-
inputConfig: BuildConfig = {}
27+
inputConfig: BuildConfig = {},
2828
) {
2929
// Determine rootDir
3030
rootDir = resolve(process.cwd(), rootDir || ".");
@@ -49,7 +49,7 @@ async function _build(
4949
stub: boolean,
5050
inputConfig: BuildConfig = {},
5151
buildConfig: BuildConfig,
52-
pkg: PackageJson & Record<"unbuild" | "build", BuildConfig>
52+
pkg: PackageJson & Record<"unbuild" | "build", BuildConfig>,
5353
) {
5454
// Resolve preset
5555
const preset = resolvePreset(
@@ -58,7 +58,7 @@ async function _build(
5858
pkg.build?.preset ||
5959
inputConfig.preset ||
6060
"auto",
61-
rootDir
61+
rootDir,
6262
);
6363

6464
// Merge options
@@ -110,7 +110,7 @@ async function _build(
110110
respectExternal: true,
111111
},
112112
},
113-
}
113+
},
114114
) as BuildOptions;
115115

116116
// Resolve dirs relative to rootDir
@@ -142,7 +142,7 @@ async function _build(
142142

143143
// Normalize entries
144144
options.entries = options.entries.map((entry) =>
145-
typeof entry === "string" ? { input: entry } : entry
145+
typeof entry === "string" ? { input: entry } : entry,
146146
);
147147

148148
for (const entry of options.entries) {
@@ -185,7 +185,7 @@ async function _build(
185185

186186
// Start info
187187
consola.info(
188-
chalk.cyan(`${options.stub ? "Stubbing" : "Building"} ${options.name}`)
188+
chalk.cyan(`${options.stub ? "Stubbing" : "Building"} ${options.name}`),
189189
);
190190
if (process.env.DEBUG) {
191191
consola.info(`${chalk.bold("Root dir:")} ${options.rootDir}
@@ -271,7 +271,9 @@ async function _build(
271271
return chalk.gray(
272272
" └─ " +
273273
rPath(p) +
274-
chalk.bold(chunk.bytes ? ` (${prettyBytes(chunk?.bytes)})` : "")
274+
chalk.bold(
275+
chunk.bytes ? ` (${prettyBytes(chunk?.bytes)})` : "",
276+
),
275277
);
276278
})
277279
.join("\n");
@@ -286,7 +288,7 @@ async function _build(
286288
return chalk.gray(
287289
" 📦 " +
288290
rPath(m.id) +
289-
chalk.bold(m.bytes ? ` (${prettyBytes(m.bytes)})` : "")
291+
chalk.bold(m.bytes ? ` (${prettyBytes(m.bytes)})` : ""),
290292
);
291293
})
292294
.join("\n");
@@ -296,8 +298,8 @@ async function _build(
296298
console.log(
297299
"Σ Total dist size (byte size):",
298300
chalk.cyan(
299-
prettyBytes(ctx.buildEntries.reduce((a, e) => a + (e.bytes || 0), 0))
300-
)
301+
prettyBytes(ctx.buildEntries.reduce((a, e) => a + (e.bytes || 0), 0)),
302+
),
301303
);
302304

303305
// Validate
@@ -312,11 +314,11 @@ async function _build(
312314
if (ctx.warnings.size > 0) {
313315
consola.warn(
314316
"Build is done with some warnings:\n\n" +
315-
[...ctx.warnings].map((msg) => "- " + msg).join("\n")
317+
[...ctx.warnings].map((msg) => "- " + msg).join("\n"),
316318
);
317319
if (ctx.options.failOnWarn) {
318320
consola.error(
319-
"Exiting with code (1). You can change this behavior by setting `failOnWarn: false` ."
321+
"Exiting with code (1). You can change this behavior by setting `failOnWarn: false` .",
320322
);
321323
// eslint-disable-next-line unicorn/no-process-exit
322324
process.exit(1);

src/builder/mkdist.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ import type { MkdistBuildEntry, BuildContext } from "../types";
55

66
export async function mkdistBuild(ctx: BuildContext) {
77
const entries = ctx.options.entries.filter(
8-
(e) => e.builder === "mkdist"
8+
(e) => e.builder === "mkdist",
99
) as MkdistBuildEntry[];
1010
await ctx.hooks.callHook("mkdist:entries", ctx, entries);
1111
for (const entry of entries) {
@@ -29,7 +29,7 @@ export async function mkdistBuild(ctx: BuildContext) {
2929
"mkdist:entry:options",
3030
ctx,
3131
entry,
32-
mkdistOptions
32+
mkdistOptions,
3333
);
3434
const output = await mkdist(mkdistOptions);
3535
ctx.buildEntries.push({

src/builder/plugins/esbuild.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -114,7 +114,7 @@ export function esbuild(options: EsbuildOptions): Plugin {
114114
function printWarnings(
115115
id: string,
116116
result: TransformResult,
117-
plugin: PluginContext
117+
plugin: PluginContext,
118118
) {
119119
if (result.warnings) {
120120
for (const warning of result.warnings) {

src/builder/rollup.ts

Lines changed: 21 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -38,20 +38,20 @@ export async function rollupBuild(ctx: BuildContext) {
3838
const jitiPath = await resolvePath("jiti", { url: import.meta.url });
3939

4040
for (const entry of ctx.options.entries.filter(
41-
(entry) => entry.builder === "rollup"
41+
(entry) => entry.builder === "rollup",
4242
)) {
4343
const output = resolve(
4444
ctx.options.rootDir,
4545
ctx.options.outDir,
46-
entry.name!
46+
entry.name!,
4747
);
4848

4949
const resolvedEntry = normalize(
50-
tryResolve(entry.input, ctx.options.rootDir) || entry.input
50+
tryResolve(entry.input, ctx.options.rootDir) || entry.input,
5151
);
5252
const resolvedEntryWithoutExt = resolvedEntry.slice(
5353
0,
54-
Math.max(0, resolvedEntry.length - extname(resolvedEntry).length)
54+
Math.max(0, resolvedEntry.length - extname(resolvedEntry).length),
5555
);
5656
const code = await fsp.readFile(resolvedEntry, "utf8");
5757
const shebang = getShebang(code);
@@ -63,10 +63,10 @@ export async function rollupBuild(ctx: BuildContext) {
6363
await writeFile(
6464
output + ".cjs",
6565
`${shebang}module.exports = require(${JSON.stringify(
66-
jitiPath
66+
jitiPath,
6767
)})(null, { interopDefault: true, esmResolve: true })(${JSON.stringify(
68-
resolvedEntry
69-
)})`
68+
resolvedEntry,
69+
)})`,
7070
);
7171
}
7272

@@ -76,7 +76,7 @@ export async function rollupBuild(ctx: BuildContext) {
7676
resolvedEntry,
7777
{
7878
extensions: DEFAULT_EXTENSIONS,
79-
}
79+
},
8080
).catch((error) => {
8181
warn(ctx, `Cannot analyze ${resolvedEntry} for exports:` + error);
8282
return [];
@@ -92,13 +92,13 @@ export async function rollupBuild(ctx: BuildContext) {
9292
"",
9393
`/** @type {import(${JSON.stringify(resolvedEntryWithoutExt)})} */`,
9494
`const _module = jiti(null, { interopDefault: true, esmResolve: true })(${JSON.stringify(
95-
resolvedEntry
95+
resolvedEntry,
9696
)});`,
9797
hasDefaultExport ? "\nexport default _module;" : "",
9898
...namedExports
9999
.filter((name) => name !== "default")
100100
.map((name) => `export const ${name} = _module.${name};`),
101-
].join("\n")
101+
].join("\n"),
102102
);
103103

104104
// DTS Stub
@@ -108,10 +108,10 @@ export async function rollupBuild(ctx: BuildContext) {
108108
`export * from ${JSON.stringify(resolvedEntryWithoutExt)};`,
109109
hasDefaultExport
110110
? `export { default } from ${JSON.stringify(
111-
resolvedEntryWithoutExt
111+
resolvedEntryWithoutExt,
112112
)};`
113113
: "",
114-
].join("\n")
114+
].join("\n"),
115115
);
116116

117117
if (shebang) {
@@ -138,7 +138,7 @@ export async function rollupBuild(ctx: BuildContext) {
138138
const { output } = await buildResult.write(outputOptions);
139139
const chunkFileNames = new Set<string>();
140140
const outputChunks = output.filter(
141-
(e) => e.type === "chunk"
141+
(e) => e.type === "chunk",
142142
) as OutputChunk[];
143143
for (const entry of outputChunks) {
144144
chunkFileNames.add(entry.fileName);
@@ -148,7 +148,7 @@ export async function rollupBuild(ctx: BuildContext) {
148148
if (entry.isEntry) {
149149
ctx.buildEntries.push({
150150
chunks: entry.imports.filter((i) =>
151-
outputChunks.find((c) => c.fileName === i)
151+
outputChunks.find((c) => c.fileName === i),
152152
),
153153
modules: Object.entries(entry.modules).map(([id, mod]) => ({
154154
id,
@@ -170,7 +170,7 @@ export async function rollupBuild(ctx: BuildContext) {
170170
rollupOptions.plugins = rollupOptions.plugins || [];
171171
// TODO: Use fresh rollup options
172172
const shebangPlugin: any = rollupOptions.plugins.find(
173-
(p) => p && p.name === "unbuild-shebang"
173+
(p) => p && p.name === "unbuild-shebang",
174174
);
175175
shebangPlugin._options.preserve = false;
176176

@@ -215,7 +215,7 @@ export async function rollupBuild(ctx: BuildContext) {
215215
const getChunkFilename = (
216216
ctx: BuildContext,
217217
chunk: PreRenderedChunk,
218-
ext: string
218+
ext: string,
219219
) => {
220220
if (chunk.isDynamicEntry) {
221221
return `chunks/[name].${ext}`;
@@ -229,7 +229,10 @@ export function getRollupOptions(ctx: BuildContext): RollupOptions {
229229
input: Object.fromEntries(
230230
ctx.options.entries
231231
.filter((entry) => entry.builder === "rollup")
232-
.map((entry) => [entry.name, resolve(ctx.options.rootDir, entry.input)])
232+
.map((entry) => [
233+
entry.name,
234+
resolve(ctx.options.rootDir, entry.input),
235+
]),
233236
),
234237

235238
output: [
@@ -307,7 +310,7 @@ export function getRollupOptions(ctx: BuildContext): RollupOptions {
307310
? Object.fromEntries(
308311
ctx.options.rollup.alias.entries.map((entry) => {
309312
return [entry.find, entry.replacement];
310-
})
313+
}),
311314
)
312315
: ctx.options.rollup.alias.entries),
313316
},

src/builder/untyped.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ import type { BuildContext, UntypedBuildEntry, UntypedOutputs } from "../types";
99

1010
export async function typesBuild(ctx: BuildContext) {
1111
const entries = ctx.options.entries.filter(
12-
(entry) => entry.builder === "untyped"
12+
(entry) => entry.builder === "untyped",
1313
) as UntypedBuildEntry[];
1414
await ctx.hooks.callHook("untyped:entries", ctx, entries);
1515

@@ -64,7 +64,7 @@ export async function typesBuild(ctx: BuildContext) {
6464
await writeFile(
6565
resolve(distDir, output.fileName),
6666
output.contents,
67-
"utf8"
67+
"utf8",
6868
);
6969
}
7070
}

0 commit comments

Comments
 (0)