bunup 0.8.41 → 0.8.42

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -1,367 +0,0 @@
1
- var __create = Object.create;
2
- var __getProtoOf = Object.getPrototypeOf;
3
- var __defProp = Object.defineProperty;
4
- var __getOwnPropNames = Object.getOwnPropertyNames;
5
- var __hasOwnProp = Object.prototype.hasOwnProperty;
6
- var __toESM = (mod, isNodeMode, target) => {
7
- target = mod != null ? __create(__getProtoOf(mod)) : {};
8
- const to = isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target;
9
- for (let key of __getOwnPropNames(mod))
10
- if (!__hasOwnProp.call(to, key))
11
- __defProp(to, key, {
12
- get: () => mod[key],
13
- enumerable: true
14
- });
15
- return to;
16
- };
17
- var __require = import.meta.require;
18
-
19
- // src/logger.ts
20
- import pc from "picocolors";
21
- var silent = false;
22
- function setSilent(value) {
23
- silent = value ?? false;
24
- }
25
-
26
- class Logger {
27
- static instance;
28
- loggedOnceMessages = new Set;
29
- constructor() {}
30
- static getInstance() {
31
- if (!Logger.instance) {
32
- Logger.instance = new Logger;
33
- }
34
- return Logger.instance;
35
- }
36
- dispose() {
37
- this.loggedOnceMessages.clear();
38
- }
39
- shouldLog(options) {
40
- if (!options?.once) {
41
- return true;
42
- }
43
- if (this.loggedOnceMessages.has(options.once)) {
44
- return false;
45
- }
46
- this.loggedOnceMessages.add(options.once);
47
- return true;
48
- }
49
- getIcon(type, tick) {
50
- if (tick) {
51
- return pc.green("\u2713");
52
- }
53
- const iconMap = {
54
- info: pc.blue("i"),
55
- warn: pc.yellow("!"),
56
- error: pc.red("\u2715")
57
- };
58
- return iconMap[type];
59
- }
60
- formatIdentifier(identifier) {
61
- return identifier ? ` ${pc.bgBlue(pc.black(` ${identifier} `))}` : "";
62
- }
63
- formatMessage(options) {
64
- const {
65
- message,
66
- identifier,
67
- muted = false,
68
- tick = false,
69
- type = "info"
70
- } = options;
71
- const icon = this.getIcon(type, tick);
72
- const styledMessage = muted ? pc.dim(message) : type === "error" ? pc.red(message) : type === "warn" ? pc.yellow(message) : message;
73
- const identifierPart = this.formatIdentifier(identifier);
74
- return `${icon} ${styledMessage}${identifierPart}`;
75
- }
76
- output(message, options = {}, logFn = console.log) {
77
- if (silent || !this.shouldLog(options)) {
78
- return;
79
- }
80
- if (options.verticalSpace) {
81
- logFn("");
82
- }
83
- logFn(message);
84
- if (options.verticalSpace) {
85
- logFn("");
86
- }
87
- }
88
- info(message, options = {}) {
89
- const formattedMessage = this.formatMessage({
90
- ...options,
91
- message,
92
- type: "info"
93
- });
94
- this.output(formattedMessage, options);
95
- }
96
- warn(message, options = {}) {
97
- const formattedMessage = this.formatMessage({
98
- ...options,
99
- message,
100
- type: "warn"
101
- });
102
- this.output(formattedMessage, options);
103
- }
104
- error(message, options = {}) {
105
- const formattedMessage = this.formatMessage({
106
- ...options,
107
- message,
108
- type: "error"
109
- });
110
- this.output(formattedMessage, options);
111
- }
112
- success(message, options = {}) {
113
- const formattedMessage = this.formatMessage({
114
- ...options,
115
- message,
116
- tick: true
117
- });
118
- this.output(formattedMessage, options);
119
- }
120
- space() {
121
- if (!silent) {
122
- console.log("");
123
- }
124
- }
125
- }
126
- function logTable(columns, data, footer) {
127
- if (silent)
128
- return;
129
- const widths = {};
130
- for (const col of columns) {
131
- const headerLength = col.header.length;
132
- const dataLengths = data.map((row) => row[col.header]?.length || 0);
133
- const footerLength = footer ? footer[col.header]?.length || 0 : 0;
134
- widths[col.header] = Math.max(headerLength, ...dataLengths, footerLength);
135
- }
136
- const pad = (str, width, align) => {
137
- return align === "left" ? str.padEnd(width) : str.padStart(width);
138
- };
139
- const headerRow = columns.map((col) => pad(col.header, widths[col.header], col.align)).join(pc.gray(" | "));
140
- console.log(pc.gray(headerRow));
141
- const separator = columns.map((col) => "-".repeat(widths[col.header])).join(" | ");
142
- console.log(pc.gray(separator));
143
- for (const row of data) {
144
- const rowStr = columns.map((col) => {
145
- const value = row[col.header] || "";
146
- const padded = pad(value, widths[col.header], col.align);
147
- return col.color ? col.color(padded) : padded;
148
- }).join(pc.gray(" | "));
149
- console.log(rowStr);
150
- }
151
- console.log(pc.gray(separator));
152
- if (footer) {
153
- const footerRow = columns.map((col) => {
154
- const value = footer[col.header] || "";
155
- const padded = pad(value, widths[col.header], col.align);
156
- return padded;
157
- }).join(pc.gray(" | "));
158
- console.log(footerRow);
159
- }
160
- }
161
- var logger = Logger.getInstance();
162
-
163
- // src/errors.ts
164
- import pc2 from "picocolors";
165
- class BunupError extends Error {
166
- constructor(message) {
167
- super(message);
168
- this.name = "BunupError";
169
- }
170
- }
171
-
172
- class BunupBuildError extends BunupError {
173
- constructor(message) {
174
- super(message);
175
- this.name = "BunupBuildError";
176
- }
177
- }
178
-
179
- class BunupDTSBuildError extends BunupError {
180
- constructor(message) {
181
- super(message);
182
- this.name = "BunupDTSBuildError";
183
- }
184
- }
185
-
186
- class BunupCLIError extends BunupError {
187
- constructor(message) {
188
- super(message);
189
- this.name = "BunupCLIError";
190
- }
191
- }
192
-
193
- class BunupWatchError extends BunupError {
194
- constructor(message) {
195
- super(message);
196
- this.name = "BunupWatchError";
197
- }
198
- }
199
-
200
- class BunupPluginError extends BunupError {
201
- constructor(message) {
202
- super(message);
203
- this.name = "BunupPluginError";
204
- }
205
- }
206
- var parseErrorMessage = (error) => {
207
- if (error instanceof Error) {
208
- return error.message;
209
- }
210
- return String(error);
211
- };
212
- var KNOWN_ERRORS = [
213
- {
214
- pattern: /Could not resolve: "bun"/i,
215
- errorType: "BUILD ERROR",
216
- logSolution: () => {
217
- logger.info(pc2.white("You're trying to build a project that uses Bun. ") + pc2.white("Please set the target option to ") + pc2.cyan("`bun`") + pc2.white(`.
218
- `) + pc2.white("Example: ") + pc2.green("`bunup --target bun`") + pc2.white(" or in config: ") + pc2.green("{ target: 'bun' }"));
219
- }
220
- }
221
- ];
222
- var handleError = (error, context) => {
223
- const errorMessage = parseErrorMessage(error);
224
- const contextPrefix = context ? `[${context}] ` : "";
225
- let errorType = "UNKNOWN ERROR";
226
- if (error instanceof BunupBuildError) {
227
- errorType = "BUILD ERROR";
228
- } else if (error instanceof BunupDTSBuildError) {
229
- errorType = "DTS ERROR";
230
- } else if (error instanceof BunupCLIError) {
231
- errorType = "CLI ERROR";
232
- } else if (error instanceof BunupWatchError) {
233
- errorType = "WATCH ERROR";
234
- } else if (error instanceof BunupPluginError) {
235
- errorType = "PLUGIN ERROR";
236
- } else if (error instanceof BunupError) {
237
- errorType = "BUNUP ERROR";
238
- }
239
- const knownError = KNOWN_ERRORS.find((error2) => error2.pattern.test(errorMessage) && (error2.errorType === errorType || !error2.errorType));
240
- if (!knownError && errorType) {
241
- console.error(`${pc2.red(errorType)} ${contextPrefix}${errorMessage}`);
242
- }
243
- if (knownError) {
244
- console.log(`
245
- `);
246
- knownError.logSolution(errorMessage);
247
- console.log(`
248
- `);
249
- } else {
250
- console.error(pc2.dim(pc2.white("If you think this is a bug, please open an issue at: ") + pc2.cyan("https://github.com/arshad-yaseen/bunup/issues/new")));
251
- }
252
- };
253
- var handleErrorAndExit = (error, context) => {
254
- handleError(error, context);
255
- process.exit(1);
256
- };
257
-
258
- // src/utils.ts
259
- import fsSync from "fs";
260
- import fs from "fs/promises";
261
- import path, { normalize } from "path";
262
- function ensureArray(value) {
263
- return Array.isArray(value) ? value : [value];
264
- }
265
- function getDefaultOutputExtension(format, packageType) {
266
- switch (format) {
267
- case "esm":
268
- return isModulePackage(packageType) ? ".js" : ".mjs";
269
- case "cjs":
270
- return isModulePackage(packageType) ? ".cjs" : ".js";
271
- case "iife":
272
- return ".global.js";
273
- }
274
- }
275
- function getDefaultDtsExtention(format, packageType) {
276
- switch (format) {
277
- case "esm":
278
- return isModulePackage(packageType) ? ".d.ts" : ".d.mts";
279
- case "cjs":
280
- return isModulePackage(packageType) ? ".d.cts" : ".d.ts";
281
- case "iife":
282
- return ".global.d.ts";
283
- }
284
- }
285
- function isModulePackage(packageType) {
286
- return packageType === "module";
287
- }
288
- function formatTime(ms) {
289
- return ms >= 1000 ? `${(ms / 1000).toFixed(2)}s` : `${Math.round(ms)}ms`;
290
- }
291
- function getPackageDeps(packageJson) {
292
- if (!packageJson)
293
- return [];
294
- return Array.from(new Set([
295
- ...Object.keys(packageJson.dependencies || {}),
296
- ...Object.keys(packageJson.peerDependencies || {})
297
- ]));
298
- }
299
- function formatFileSize(bytes) {
300
- if (bytes === 0)
301
- return "0 B";
302
- const units = ["B", "KB", "MB", "GB"];
303
- const i = Math.floor(Math.log(bytes) / Math.log(1024));
304
- if (i === 0)
305
- return `${bytes} ${units[i]}`;
306
- return `${(bytes / 1024 ** i).toFixed(2)} ${units[i]}`;
307
- }
308
- function getShortFilePath(filePath, maxLength = 3) {
309
- const fileParts = filePath.split("/");
310
- const shortPath = fileParts.slice(-maxLength).join("/");
311
- return shortPath;
312
- }
313
- async function cleanOutDir(rootDir, outDir) {
314
- const outDirPath = path.join(rootDir, outDir);
315
- try {
316
- await fs.rm(outDirPath, { recursive: true, force: true });
317
- } catch (error) {
318
- throw new BunupBuildError(`Failed to clean output directory: ${error}`);
319
- }
320
- await fs.mkdir(outDirPath, { recursive: true });
321
- }
322
- function cleanPath(path2) {
323
- let cleaned = normalize(path2).replace(/\\/g, "/");
324
- cleaned = cleaned.replace(/^[a-zA-Z]:\//, "");
325
- cleaned = cleaned.replace(/^\/+/, "");
326
- cleaned = cleaned.replace(/\/+/g, "/");
327
- return cleaned;
328
- }
329
- function isDirectoryPath(filePath) {
330
- return path.extname(filePath) === "";
331
- }
332
- function pathExistsSync(filePath) {
333
- try {
334
- fsSync.accessSync(filePath);
335
- return true;
336
- } catch (error) {
337
- return false;
338
- }
339
- }
340
- function formatListWithAnd(arr) {
341
- return new Intl.ListFormat("en", {
342
- style: "long",
343
- type: "conjunction"
344
- }).format(arr);
345
- }
346
- async function getFilesFromGlobs(patterns, cwd) {
347
- const includePatterns = patterns.filter((p) => !p.startsWith("!"));
348
- const excludePatterns = patterns.filter((p) => p.startsWith("!")).map((p) => p.slice(1));
349
- const includedFiles = new Set;
350
- for (const pattern of includePatterns) {
351
- const glob = new Bun.Glob(pattern);
352
- for await (const file of glob.scan(cwd)) {
353
- includedFiles.add(file);
354
- }
355
- }
356
- if (excludePatterns.length > 0) {
357
- for (const pattern of excludePatterns) {
358
- const glob = new Bun.Glob(pattern);
359
- for await (const file of glob.scan(cwd)) {
360
- includedFiles.delete(file);
361
- }
362
- }
363
- }
364
- return Array.from(includedFiles);
365
- }
366
-
367
- export { __toESM, __require, setSilent, logTable, logger, BunupBuildError, BunupCLIError, BunupWatchError, BunupPluginError, parseErrorMessage, handleError, handleErrorAndExit, ensureArray, getDefaultOutputExtension, getDefaultDtsExtention, formatTime, getPackageDeps, formatFileSize, getShortFilePath, cleanOutDir, cleanPath, isDirectoryPath, pathExistsSync, formatListWithAnd, getFilesFromGlobs };
@@ -1,30 +0,0 @@
1
- // src/loaders.ts
2
- import path from "path";
3
- import { loadConfig } from "coffi";
4
- async function processLoadedConfigs(config, cwd, filter) {
5
- return Array.isArray(config) && "root" in config[0] ? config.filter((c) => filter ? filter.includes(c.name) : true).map((c) => ({
6
- rootDir: path.resolve(cwd, c.root),
7
- options: addField(c.config, "name", c.name)
8
- })) : [
9
- {
10
- rootDir: cwd,
11
- options: config
12
- }
13
- ];
14
- }
15
- function addField(objectOrArray, field, value) {
16
- return Array.isArray(objectOrArray) ? objectOrArray.map((o) => ({ ...o, [field]: value })) : { ...objectOrArray, [field]: value };
17
- }
18
- async function loadPackageJson(cwd = process.cwd()) {
19
- const { config, filepath } = await loadConfig({
20
- name: "package",
21
- cwd,
22
- extensions: [".json"]
23
- });
24
- return {
25
- data: config,
26
- path: filepath
27
- };
28
- }
29
-
30
- export { processLoadedConfigs, loadPackageJson };
@@ -1,155 +0,0 @@
1
- // @bun
2
- import {
3
- displayBunupGradientArt
4
- } from "./chunk-a7j07gk7.js";
5
- import {
6
- pathExistsSync
7
- } from "./chunk-c1eyecm3.js";
8
-
9
- // src/cli/new.ts
10
- import { renameSync } from "fs";
11
- import path from "path";
12
- import {
13
- cancel,
14
- confirm,
15
- intro,
16
- outro,
17
- select,
18
- tasks,
19
- text
20
- } from "@clack/prompts";
21
- import { downloadTemplate } from "giget";
22
- import pc from "picocolors";
23
- import { replaceInFile } from "replace-in-file";
24
- var TEMPLATE_OWNER = "arshad-yaseen";
25
- var TEMPLATE_REPO = "bunup-new";
26
- var GITHUB_USERNAME_PLACEHOLDER = "username";
27
- var GITHUB_REPO_PLACEHOLDER = "repo-name";
28
- var MONOREPO_FIRST_PACKAGE_NAME_PLACEHOLDER = "package-1";
29
- var MONOREPO_PACKAGES_DIR = "packages";
30
- var TEMPLATES = [
31
- {
32
- type: "typescript",
33
- defaultName: "my-ts-lib",
34
- name: "Typescript Library",
35
- dir: "ts-lib",
36
- monorepoDir: "ts-lib-monorepo"
37
- },
38
- {
39
- type: "react",
40
- defaultName: "my-react-lib",
41
- name: "React Library",
42
- dir: "react-lib"
43
- }
44
- ];
45
- async function newProject() {
46
- displayBunupGradientArt();
47
- intro(pc.bgCyan(pc.black(" Scaffold a new project with Bunup ")));
48
- const selectedTemplateDir = await select({
49
- message: "Select a template",
50
- options: TEMPLATES.map((template2) => ({
51
- value: template2.dir,
52
- label: pc.blue(template2.name)
53
- }))
54
- });
55
- const template = TEMPLATES.find((t) => t.dir === selectedTemplateDir);
56
- if (!template) {
57
- cancel("Invalid template");
58
- process.exit(1);
59
- }
60
- const hasMonorepo = template.monorepoDir !== undefined;
61
- const projectName = await text({
62
- message: "Enter the project name",
63
- placeholder: template.defaultName,
64
- defaultValue: template.defaultName,
65
- validate: (value) => {
66
- if (!value) {
67
- return "Project name is required";
68
- }
69
- if (value.includes(" ")) {
70
- return "Project name cannot contain spaces";
71
- }
72
- if (pathExistsSync(getProjectPath(value))) {
73
- return "Project already exists";
74
- }
75
- }
76
- });
77
- const projectPath = getProjectPath(projectName);
78
- let useMonorepo = false;
79
- let monorepoFirstPackageName;
80
- if (hasMonorepo) {
81
- useMonorepo = await confirm({
82
- message: "Do you want to create a monorepo?",
83
- initialValue: false
84
- });
85
- if (useMonorepo) {
86
- monorepoFirstPackageName = await text({
87
- message: "Enter the name of the first package",
88
- placeholder: MONOREPO_FIRST_PACKAGE_NAME_PLACEHOLDER,
89
- defaultValue: MONOREPO_FIRST_PACKAGE_NAME_PLACEHOLDER
90
- });
91
- }
92
- }
93
- const githubRepoInfo = await text({
94
- message: "GitHub username and repo name (username/repo):",
95
- placeholder: `${GITHUB_USERNAME_PLACEHOLDER}/${GITHUB_REPO_PLACEHOLDER}`,
96
- defaultValue: `${GITHUB_USERNAME_PLACEHOLDER}/${GITHUB_REPO_PLACEHOLDER}`
97
- });
98
- const [githubUsername, githubRepoName] = githubRepoInfo.split("/");
99
- await tasks([
100
- {
101
- title: "Downloading template",
102
- task: async () => {
103
- const templatePath = useMonorepo ? template.monorepoDir : template.dir;
104
- await downloadTemplate(`github:${TEMPLATE_OWNER}/${TEMPLATE_REPO}/${templatePath}`, {
105
- dir: projectPath
106
- });
107
- return "Template downloaded";
108
- }
109
- },
110
- {
111
- title: "Making the project yours",
112
- task: async () => {
113
- await replaceInFile({
114
- files: path.join(projectPath, "**/*"),
115
- from: [
116
- new RegExp(GITHUB_REPO_PLACEHOLDER, "g"),
117
- new RegExp(GITHUB_USERNAME_PLACEHOLDER, "g"),
118
- new RegExp(template.defaultName, "g")
119
- ],
120
- to: [githubRepoName, githubUsername, projectName],
121
- ignore: ["node_modules", "dist", "bun.lock"]
122
- });
123
- if (useMonorepo && monorepoFirstPackageName) {
124
- await replaceInFile({
125
- files: path.join(projectPath, "**/*"),
126
- from: [new RegExp(MONOREPO_FIRST_PACKAGE_NAME_PLACEHOLDER, "g")],
127
- to: [monorepoFirstPackageName],
128
- ignore: ["node_modules", "dist", "bun.lock"]
129
- });
130
- renameSync(path.join(projectPath, MONOREPO_PACKAGES_DIR, MONOREPO_FIRST_PACKAGE_NAME_PLACEHOLDER), path.join(projectPath, MONOREPO_PACKAGES_DIR, monorepoFirstPackageName));
131
- }
132
- }
133
- }
134
- ]);
135
- outro(`
136
- ${pc.green("\u2728 Project scaffolded successfully! \u2728")}
137
-
138
- ${pc.bold("Ready to launch your awesome new project?")}
139
-
140
- ${pc.cyan("cd")} ${projectName}
141
- ${pc.cyan("bun install")}
142
- ${pc.cyan("bun run dev")}${pc.dim(" (watch mode for development)")}${template.type === "react" ? `
143
- ${pc.cyan("bun run dev:test")} ${pc.dim("(preview components in a test Next.js app)")} ` : ""}
144
-
145
- ${pc.dim("Learn more:")} ${pc.underline("https://bunup.dev/docs")}
146
-
147
- ${pc.yellow("Happy coding!")} \uD83D\uDE80
148
- `);
149
- }
150
- function getProjectPath(projectName) {
151
- return path.join(process.cwd(), projectName);
152
- }
153
- export {
154
- newProject
155
- };