robuild 0.0.6 → 0.0.8

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.
@@ -0,0 +1,492 @@
1
+ import { ResolveOptions } from "exsolve";
2
+ import { InputOptions, MinifyOptions, OutputOptions, RolldownBuild, RolldownPluginOption } from "rolldown";
3
+ import { Options } from "rolldown-plugin-dts";
4
+ import { MinifyOptions as MinifyOptions$1 } from "oxc-minify";
5
+ import { TransformOptions } from "oxc-transform";
6
+
7
+ //#region src/types.d.ts
8
+ type OutputFormat = "esm" | "cjs" | "iife" | "umd";
9
+ type Platform = "browser" | "node" | "neutral";
10
+ type Target = "es5" | "es2015" | "es2016" | "es2017" | "es2018" | "es2019" | "es2020" | "es2021" | "es2022" | "esnext";
11
+ interface CopyEntry {
12
+ from: string;
13
+ to: string;
14
+ }
15
+ type CopyOptions = Array<string | CopyEntry>;
16
+ type ChunkAddon = string | Record<string, string>;
17
+ type OutExtensionFactory = (format: OutputFormat) => {
18
+ js?: string;
19
+ dts?: string;
20
+ };
21
+ type LoaderType = "js" | "jsx" | "ts" | "tsx" | "json" | "css" | "text" | "binary" | "file" | "dataurl" | "empty";
22
+ interface LoaderConfig {
23
+ loader: LoaderType;
24
+ options?: Record<string, any>;
25
+ }
26
+ interface ShimsConfig {
27
+ /**
28
+ * Enable __dirname and __filename shims for ESM.
29
+ *
30
+ * @default true
31
+ */
32
+ dirname?: boolean;
33
+ /**
34
+ * Enable require() shim for ESM.
35
+ *
36
+ * @default true
37
+ */
38
+ require?: boolean;
39
+ /**
40
+ * Enable module.exports shim for ESM.
41
+ *
42
+ * @default true
43
+ */
44
+ exports?: boolean;
45
+ /**
46
+ * Enable process.env shim for browser.
47
+ *
48
+ * @default false
49
+ */
50
+ env?: boolean;
51
+ }
52
+ interface BuildContext {
53
+ pkgDir: string;
54
+ pkg: {
55
+ name: string;
56
+ } & Record<string, unknown>;
57
+ }
58
+ interface _BuildEntry {
59
+ /**
60
+ * Output directory relative to project root.
61
+ *
62
+ * Defaults to `dist/` if not provided.
63
+ */
64
+ outDir?: string;
65
+ /**
66
+ * Avoid actual build but instead link to the source files.
67
+ */
68
+ stub?: boolean;
69
+ /**
70
+ * Output format(s) for the build.
71
+ *
72
+ * Defaults to `['esm']` if not provided.
73
+ */
74
+ format?: OutputFormat | OutputFormat[];
75
+ /**
76
+ * Target platform for the build.
77
+ *
78
+ * Defaults to `'node'` if not provided.
79
+ */
80
+ platform?: Platform;
81
+ /**
82
+ * Target ES version for the build.
83
+ *
84
+ * Defaults to `'es2022'` if not provided.
85
+ */
86
+ target?: Target;
87
+ /**
88
+ * Global variable name for IIFE/UMD formats.
89
+ */
90
+ globalName?: string;
91
+ /**
92
+ * Module path aliases.
93
+ *
94
+ * Allows defining path mappings for imports.
95
+ */
96
+ alias?: Record<string, string>;
97
+ /**
98
+ * Copy files to output directory.
99
+ *
100
+ * @example
101
+ * ```ts
102
+ * copy: ['src/assets', { from: 'src/assets', to: 'dist/assets' }]
103
+ * ```
104
+ */
105
+ copy?: CopyOptions;
106
+ /**
107
+ * Add banner/footer to output files.
108
+ *
109
+ * @example
110
+ * ```ts
111
+ * banner: '// Copyright 2024'
112
+ * footer: '// End of file'
113
+ * ```
114
+ */
115
+ banner?: string | ChunkAddon;
116
+ footer?: string | ChunkAddon;
117
+ /**
118
+ * Add content hash to output filenames.
119
+ *
120
+ * @default false
121
+ */
122
+ hash?: boolean;
123
+ /**
124
+ * Use fixed extensions (.cjs/.mjs) for output files.
125
+ *
126
+ * @default false
127
+ */
128
+ fixedExtension?: boolean;
129
+ /**
130
+ * Custom output file extensions.
131
+ */
132
+ outExtensions?: OutExtensionFactory;
133
+ /**
134
+ * Handle Node.js protocol imports.
135
+ *
136
+ * - `true`: Add `node:` prefix to built-in modules
137
+ * - `'strip'`: Remove `node:` prefix from imports
138
+ * - `false`: Keep imports unchanged
139
+ *
140
+ * @default false
141
+ */
142
+ nodeProtocol?: "strip" | boolean;
143
+ /**
144
+ * Clean output directory before build.
145
+ *
146
+ * Defaults to `true` if not provided.
147
+ */
148
+ clean?: boolean | string[];
149
+ /**
150
+ * Environment variables to inject at compile time.
151
+ */
152
+ env?: Record<string, any>;
153
+ /**
154
+ * Define constants to replace at compile time.
155
+ */
156
+ define?: Record<string, string>;
157
+ /**
158
+ * External dependencies that should not be bundled.
159
+ */
160
+ external?: (string | RegExp)[] | ((id: string, importer?: string) => boolean);
161
+ /**
162
+ * Dependencies that should be bundled even if they're in node_modules.
163
+ */
164
+ noExternal?: (string | RegExp)[] | ((id: string, importer?: string) => boolean);
165
+ /**
166
+ * File type loaders configuration.
167
+ */
168
+ loaders?: Record<string, LoaderConfig>;
169
+ /**
170
+ * CommonJS default export handling.
171
+ *
172
+ * - `true`: Preserve CommonJS default exports
173
+ * - `false`: Transform to ES module default exports
174
+ * - `'auto'`: Auto-detect based on file content
175
+ *
176
+ * @default 'auto'
177
+ */
178
+ cjsDefault?: boolean | "auto";
179
+ /**
180
+ * Enable CJS/ESM compatibility shims.
181
+ *
182
+ * @default false
183
+ */
184
+ shims?: boolean | ShimsConfig;
185
+ /**
186
+ * Skip bundling node_modules dependencies.
187
+ *
188
+ * @default false
189
+ */
190
+ skipNodeModules?: boolean;
191
+ /**
192
+ * Unbundle mode - preserve file structure without bundling.
193
+ *
194
+ * @default false
195
+ */
196
+ unbundle?: boolean;
197
+ }
198
+ type BundleEntry = _BuildEntry & {
199
+ type: "bundle";
200
+ /**
201
+ * Entry point(s) to bundle relative to the project root.
202
+ */
203
+ input: string | string[];
204
+ /**
205
+ * Minify the output using rolldown.
206
+ *
207
+ * Defaults to `false` if not provided.
208
+ */
209
+ minify?: boolean | "dce-only" | MinifyOptions;
210
+ /**
211
+ * Options passed to rolldown.
212
+ *
213
+ * See [rolldown config options](https://rolldown.rs/reference/config-options) for more details.
214
+ */
215
+ rolldown?: InputOptions & {
216
+ plugins?: RolldownPluginOption[];
217
+ };
218
+ /**
219
+ * Declaration generation options.
220
+ *
221
+ * See [rolldown-plugin-dts](https://github.com/sxzz/rolldown-plugin-dts) for more details.
222
+ *
223
+ * Options are inferred from the `tsconfig.json` file if available.
224
+ *
225
+ * Set to `false` to disable.
226
+ */
227
+ dts?: boolean | Options;
228
+ };
229
+ type TransformEntry = _BuildEntry & {
230
+ type: "transform";
231
+ /**
232
+ * Directory to transform relative to the project root.
233
+ */
234
+ input: string;
235
+ /**
236
+ * Minify the output using oxc-minify.
237
+ *
238
+ * Defaults to `false` if not provided.
239
+ */
240
+ minify?: boolean | MinifyOptions$1;
241
+ /**
242
+ * Options passed to oxc-transform.
243
+ *
244
+ * See [oxc-transform](https://www.npmjs.com/package/oxc-transform) for more details.
245
+ */
246
+ oxc?: TransformOptions;
247
+ /**
248
+ * Options passed to exsolve for module resolution.
249
+ *
250
+ * See [exsolve](https://github.com/unjs/exsolve) for more details.
251
+ */
252
+ resolve?: Omit<ResolveOptions, "from">;
253
+ };
254
+ type BuildEntry = BundleEntry | TransformEntry;
255
+ interface RobuildPlugin {
256
+ name: string;
257
+ setup?: (build: PluginBuild) => void | Promise<void>;
258
+ buildStart?: (opts: any) => void | Promise<void>;
259
+ buildEnd?: (error?: Error) => void | Promise<void>;
260
+ resolveId?: (id: string, importer?: string) => string | null | Promise<string | null>;
261
+ load?: (id: string) => string | null | Promise<string | null>;
262
+ transform?: (code: string, id: string) => string | {
263
+ code: string;
264
+ map?: any;
265
+ } | null | Promise<string | {
266
+ code: string;
267
+ map?: any;
268
+ } | null>;
269
+ generateBundle?: (options: any, bundle: any) => void | Promise<void>;
270
+ writeBundle?: (options: any, bundle: any) => void | Promise<void>;
271
+ config?: (config: any, env: any) => any | Promise<any>;
272
+ configResolved?: (config: any) => void | Promise<void>;
273
+ configureServer?: (server: any) => void | Promise<void>;
274
+ unplugin?: boolean;
275
+ meta?: {
276
+ framework?: string;
277
+ rollup?: boolean;
278
+ vite?: boolean;
279
+ webpack?: boolean;
280
+ esbuild?: boolean;
281
+ };
282
+ }
283
+ interface PluginBuild {
284
+ onResolve: (options: {
285
+ filter: RegExp;
286
+ namespace?: string;
287
+ }, callback: (args: any) => any) => void;
288
+ onLoad: (options: {
289
+ filter: RegExp;
290
+ namespace?: string;
291
+ }, callback: (args: any) => any) => void;
292
+ onTransform: (options: {
293
+ filter: RegExp;
294
+ }, callback: (args: any) => any) => void;
295
+ resolve: (path: string, options?: any) => Promise<any>;
296
+ getConfig: () => BuildConfig;
297
+ }
298
+ interface GlobImportOptions {
299
+ /**
300
+ * Enable glob imports support
301
+ * @default false
302
+ */
303
+ enabled?: boolean;
304
+ /**
305
+ * Glob patterns to match
306
+ * @default ['**\/*']
307
+ */
308
+ patterns?: string[];
309
+ /**
310
+ * Whether to import as URLs
311
+ * @default false
312
+ */
313
+ asUrls?: boolean;
314
+ /**
315
+ * Whether to import eagerly
316
+ * @default false
317
+ */
318
+ eager?: boolean;
319
+ }
320
+ interface BuildHooks {
321
+ start?: (ctx: BuildContext) => void | Promise<void>;
322
+ end?: (ctx: BuildContext) => void | Promise<void>;
323
+ entries?: (entries: BuildEntry[], ctx: BuildContext) => void | Promise<void>;
324
+ rolldownConfig?: (cfg: InputOptions, ctx: BuildContext) => void | Promise<void>;
325
+ rolldownOutput?: (cfg: OutputOptions, res: RolldownBuild, ctx: BuildContext) => void | Promise<void>;
326
+ buildStart?: (ctx: BuildContext) => void | Promise<void>;
327
+ buildEnd?: (ctx: BuildContext, result?: any) => void | Promise<void>;
328
+ resolveId?: (id: string, importer?: string, ctx?: BuildContext) => string | null | Promise<string | null>;
329
+ load?: (id: string, ctx?: BuildContext) => string | null | Promise<string | null>;
330
+ transform?: (code: string, id: string, ctx?: BuildContext) => string | {
331
+ code: string;
332
+ map?: any;
333
+ } | null | Promise<string | {
334
+ code: string;
335
+ map?: any;
336
+ } | null>;
337
+ generateBundle?: (options: any, bundle: any, ctx?: BuildContext) => void | Promise<void>;
338
+ writeBundle?: (options: any, bundle: any, ctx?: BuildContext) => void | Promise<void>;
339
+ }
340
+ interface WatchOptions {
341
+ /**
342
+ * Enable watch mode.
343
+ *
344
+ * Defaults to `false` if not provided.
345
+ */
346
+ enabled?: boolean;
347
+ /**
348
+ * Glob patterns for files to watch.
349
+ *
350
+ * Defaults to watching all source files if not provided.
351
+ */
352
+ include?: string[];
353
+ /**
354
+ * Glob patterns for files to ignore.
355
+ *
356
+ * Defaults to common ignore patterns if not provided.
357
+ */
358
+ exclude?: string[];
359
+ /**
360
+ * Delay in milliseconds before rebuilding after a file change.
361
+ *
362
+ * Defaults to `100` if not provided.
363
+ */
364
+ delay?: number;
365
+ /**
366
+ * Whether to ignore the initial build when starting watch mode.
367
+ *
368
+ * Defaults to `false` if not provided.
369
+ */
370
+ ignoreInitial?: boolean;
371
+ /**
372
+ * Whether to watch for new files being added.
373
+ *
374
+ * Defaults to `true` if not provided.
375
+ */
376
+ watchNewFiles?: boolean;
377
+ }
378
+ type LogLevel = "silent" | "error" | "warn" | "info" | "verbose";
379
+ type OnSuccessCallback = string | ((result: BuildResult) => void | Promise<void>);
380
+ interface BuildResult {
381
+ entries: Array<{
382
+ format: OutputFormat;
383
+ name: string;
384
+ exports: string[];
385
+ deps: string[];
386
+ size: number;
387
+ gzipSize: number;
388
+ sideEffectSize: number;
389
+ }>;
390
+ duration: number;
391
+ }
392
+ interface BuildConfig {
393
+ cwd?: string | URL;
394
+ entries?: (BuildEntry | string)[];
395
+ hooks?: BuildHooks;
396
+ watch?: WatchOptions;
397
+ /**
398
+ * Plugins to use during build
399
+ */
400
+ plugins?: RobuildPlugin[];
401
+ /**
402
+ * Glob import configuration
403
+ */
404
+ globImport?: GlobImportOptions;
405
+ /**
406
+ * Log level for build output.
407
+ *
408
+ * @default 'info'
409
+ */
410
+ logLevel?: LogLevel;
411
+ /**
412
+ * Callback to execute after successful build.
413
+ */
414
+ onSuccess?: OnSuccessCallback;
415
+ /**
416
+ * Fail build on warnings.
417
+ *
418
+ * @default false
419
+ */
420
+ failOnWarn?: boolean;
421
+ /**
422
+ * Additional paths to ignore in watch mode.
423
+ */
424
+ ignoreWatch?: string[];
425
+ /**
426
+ * Load configuration from Vite config file.
427
+ *
428
+ * @default false
429
+ */
430
+ fromVite?: boolean;
431
+ /**
432
+ * Workspace configuration for monorepo support.
433
+ */
434
+ workspace?: WorkspaceConfig;
435
+ /**
436
+ * Package exports generation configuration.
437
+ */
438
+ exports?: ExportsConfig;
439
+ /**
440
+ * Package filter for workspace builds.
441
+ */
442
+ filter?: string | string[];
443
+ }
444
+ interface WorkspaceConfig {
445
+ /**
446
+ * Workspace package patterns.
447
+ */
448
+ packages?: string[];
449
+ /**
450
+ * Package filter patterns.
451
+ */
452
+ filter?: string | string[];
453
+ /**
454
+ * Package exclude patterns.
455
+ */
456
+ exclude?: string | string[];
457
+ /**
458
+ * Build packages in dependency order.
459
+ */
460
+ dependencyOrder?: boolean;
461
+ }
462
+ interface ExportsConfig {
463
+ /**
464
+ * Whether to generate package.json exports field.
465
+ */
466
+ enabled?: boolean;
467
+ /**
468
+ * Custom exports mapping.
469
+ */
470
+ custom?: Record<string, string | {
471
+ import?: string;
472
+ require?: string;
473
+ types?: string;
474
+ }>;
475
+ /**
476
+ * Whether to include types in exports.
477
+ */
478
+ includeTypes?: boolean;
479
+ /**
480
+ * Base directory for exports (relative to package root).
481
+ */
482
+ baseDir?: string;
483
+ /**
484
+ * Whether to update package.json automatically.
485
+ */
486
+ autoUpdate?: boolean;
487
+ }
488
+ //#endregion
489
+ //#region src/config.d.ts
490
+ declare function defineConfig(config: BuildConfig): BuildConfig;
491
+ //#endregion
492
+ export { BuildConfig, BuildEntry, BundleEntry, TransformEntry, defineConfig };
@@ -0,0 +1,84 @@
1
+ //#region package.json
2
+ var name = "robuild";
3
+ var type = "module";
4
+ var version = "0.0.8";
5
+ var packageManager = "pnpm@10.11.1";
6
+ var description = "Zero-config ESM/TS package builder. Powered by Rolldown and Oxc";
7
+ var license = "MIT";
8
+ var repository = "Sunny-117/robuild";
9
+ var sideEffects = false;
10
+ var exports = {
11
+ ".": "./dist/index.mjs",
12
+ "./config": "./dist/config.mjs"
13
+ };
14
+ var types = "./dist/index.d.mts";
15
+ var bin = "./dist/cli.mjs";
16
+ var files = ["dist"];
17
+ var scripts = {
18
+ "build": "pnpm robuild",
19
+ "dev": "pnpm vitest",
20
+ "lint": "eslint .",
21
+ "lint:fix": "automd && eslint . --fix",
22
+ "robuild": "esno src/cli.ts",
23
+ "prepack": "pnpm build",
24
+ "release": "pnpm test && changelogen --release && npm publish && git push --follow-tags",
25
+ "test": "vitest run",
26
+ "test:watch": "vitest",
27
+ "test:types": "tsc --noEmit --skipLibCheck",
28
+ "docs:dev": "vitepress dev docs",
29
+ "docs:build": "vitepress build docs",
30
+ "docs:preview": "vitepress preview docs"
31
+ };
32
+ var dependencies = {
33
+ "c12": "^3.0.4",
34
+ "cac": "^6.7.14",
35
+ "chokidar": "^4.0.3",
36
+ "consola": "^3.4.2",
37
+ "defu": "^6.1.4",
38
+ "exsolve": "^1.0.5",
39
+ "glob": "^11.0.3",
40
+ "js-yaml": "^4.1.0",
41
+ "magic-string": "^0.30.17",
42
+ "minimatch": "^10.0.3",
43
+ "oxc-minify": "^0.89.0",
44
+ "oxc-parser": "^0.89.0",
45
+ "oxc-transform": "^0.89.0",
46
+ "pretty-bytes": "^7.0.1",
47
+ "rolldown": "1.0.0-beta.30",
48
+ "rolldown-plugin-dts": "^0.16.5",
49
+ "tinyglobby": "^0.2.14",
50
+ "typescript": "^5.8.3"
51
+ };
52
+ var devDependencies = {
53
+ "@antfu/eslint-config": "^5.3.0",
54
+ "@types/js-yaml": "^4.0.9",
55
+ "@types/node": "^24.4.0",
56
+ "@vitest/coverage-v8": "^3.2.2",
57
+ "automd": "^0.4.0",
58
+ "changelogen": "^0.6.1",
59
+ "eslint": "^9.28.0",
60
+ "esno": "^4.8.0",
61
+ "prettier": "^3.5.3",
62
+ "vitepress": "^1.6.3",
63
+ "vitest": "^3.2.2"
64
+ };
65
+ var package_default = {
66
+ name,
67
+ type,
68
+ version,
69
+ packageManager,
70
+ description,
71
+ license,
72
+ repository,
73
+ sideEffects,
74
+ exports,
75
+ types,
76
+ bin,
77
+ files,
78
+ scripts,
79
+ dependencies,
80
+ devDependencies
81
+ };
82
+
83
+ //#endregion
84
+ export { package_default as default };