@hypernym/bundler 0.31.2 → 0.32.0

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.
package/README.md CHANGED
@@ -297,10 +297,10 @@ export default defineConfig({
297
297
 
298
298
  Controls code minification for all `chunk` entries.
299
299
 
300
- - `true`: Enable full minification including code compression and dead code elimination.
301
- - `false`: Disable minification (default).
302
- - `'dce-only'`: Only perform dead code elimination without code compression.
303
- - `MinifyOptions`: Fine-grained control over minification settings.
300
+ - `true` - Enable full minification including code compression and dead code elimination.
301
+ - `false` - Disable minification (default).
302
+ - `'dce-only'` - Only perform dead code elimination without code compression.
303
+ - `MinifyOptions` - Fine-grained control over minification settings.
304
304
 
305
305
  ```ts
306
306
  // bundler.config.ts
@@ -325,6 +325,30 @@ export default defineConfig({
325
325
  })
326
326
  ```
327
327
 
328
+ ## comments
329
+
330
+ - Type: `boolean | CommentsOptions | undefined`
331
+ - Default: `{ legal: true, annotation: true, jsdoc: false }`
332
+
333
+ Specifies which comments are preserved in the output.
334
+
335
+ - `true` - Preserve legal, annotation, and JSDoc comments.
336
+ - `false` - Strip all comments.
337
+ - `object` - Granular control over comment categories:
338
+ - `legal` - `@license`, `@preserve`, `//!`, `/*!`.
339
+ - `annotation` - `@__PURE__`, `@__NO_SIDE_EFFECTS__`, `@vite-ignore`.
340
+ - `jsdoc` - JSDoc comments.
341
+
342
+ ```ts
343
+ // bundler.config.ts
344
+
345
+ import { defineConfig } from '@hypernym/bundler'
346
+
347
+ export default defineConfig({
348
+ comments: true,
349
+ })
350
+ ```
351
+
328
352
  ## Hooks
329
353
 
330
354
  List of lifecycle hooks that are called at various phases:
package/dist/bin/index.js CHANGED
@@ -9,7 +9,7 @@ import { build as build$1 } from "../build/index.js";
9
9
 
10
10
  //#region src/bin/meta.ts
11
11
  const name = `Hyperbundler`;
12
- const version = `0.31.2`;
12
+ const version = `0.32.0`;
13
13
 
14
14
  //#endregion
15
15
  //#region src/utils/logger.ts
@@ -73,24 +73,6 @@ function formatBytes(bytes) {
73
73
 
74
74
  //#endregion
75
75
  //#region src/config.ts
76
- /**
77
- * List of global default patterns for external module identifiers.
78
- *
79
- * @example
80
- *
81
- * ```ts
82
- * import { externals } from '@hypernym/bundler'
83
- *
84
- * export default defineConfig({
85
- * entries: [
86
- * {
87
- * input: './src/index.ts',
88
- * externals: [...externals, 'id', /regexp/]
89
- * },
90
- * ]
91
- * })
92
- * ```
93
- */
94
76
  const externals = [
95
77
  /^node:/,
96
78
  /^@types/,
@@ -103,20 +85,20 @@ const externals = [
103
85
 
104
86
  //#endregion
105
87
  //#region src/bin/loader.ts
106
- async function getTSConfigPath(cwd$1, filePath = "tsconfig.json") {
107
- const tsconfigPath = resolve(cwd$1, filePath);
88
+ async function getTSConfigPath(cwd, filePath = "tsconfig.json") {
89
+ const tsconfigPath = resolve(cwd, filePath);
108
90
  if (await exists(tsconfigPath)) return tsconfigPath;
109
91
  }
110
92
  async function loadConfig(filePath, defaults) {
111
- const cwd$1 = defaults.cwd;
93
+ const cwd = defaults.cwd;
112
94
  const result = await build({
113
- input: resolve(cwd$1, filePath),
95
+ input: resolve(cwd, filePath),
114
96
  write: false,
115
97
  external: (id) => !(isAbsolute(id) || /^(\.|@\/|~\/)/.test(id)),
116
98
  tsconfig: defaults.tsconfig,
117
99
  output: { format: "esm" }
118
100
  });
119
- const tempConfig = resolve(cwd$1, "node_modules/.hypernym/bundler/config.js");
101
+ const tempConfig = resolve(cwd, "node_modules/.hypernym/bundler/config.js");
120
102
  await write(tempConfig, result.output[0].code);
121
103
  const config = (await import(tempConfig)).default;
122
104
  return {
@@ -162,14 +144,14 @@ async function createConfigLoader(args) {
162
144
  async function createBuilder(config) {
163
145
  const { options, path: configPath } = config;
164
146
  const { hooks } = options;
165
- const cl$1 = console.log;
147
+ const cl = console.log;
166
148
  await hooks?.["bundle:start"]?.(options);
167
- cl$1();
149
+ cl();
168
150
  logger.info(dim(`v${version}`));
169
- cl$1("Config", dim(configPath));
170
- cl$1();
171
- cl$1("Processing specified entries...");
172
- cl$1();
151
+ cl("Config", dim(configPath));
152
+ cl();
153
+ cl("Processing specified entries...");
154
+ cl();
173
155
  await build$1(options).then((stats) => {
174
156
  const entriesLength = options.entries.length;
175
157
  const totalEntries = `${entriesLength} ${entriesLength > 1 ? "entries" : "entry"}`;
@@ -177,12 +159,12 @@ async function createBuilder(config) {
177
159
  const totalFiles = `${stats.files.length} file${filesLength > 1 ? "s" : ""}`;
178
160
  const buildTime = formatMs(stats.buildTime);
179
161
  const buildSize = formatBytes(stats.size);
180
- cl$1();
181
- cl$1("Stats:", dim(`${totalEntries}, ${totalFiles}, ${buildSize}, ${buildTime}`));
182
- cl$1();
183
- cl$1("All entries successfully processed.");
184
- cl$1("Bundle is optimized and ready for production.");
185
- cl$1();
162
+ cl();
163
+ cl("Stats:", dim(`${totalEntries}, ${totalFiles}, ${buildSize}, ${buildTime}`));
164
+ cl();
165
+ cl("All entries successfully processed.");
166
+ cl("Bundle is optimized and ready for production.");
167
+ cl();
186
168
  }).catch(error);
187
169
  await hooks?.["bundle:end"]?.(options);
188
170
  }
@@ -101,7 +101,7 @@ function parseOutputPath(path) {
101
101
  //#endregion
102
102
  //#region src/bin/build.ts
103
103
  function logEntryStats(stats) {
104
- const cl$1 = console.log;
104
+ const cl = console.log;
105
105
  const base = parse(stats.path).base;
106
106
  const path = stats.path.replace(base, "");
107
107
  let format = stats.format;
@@ -109,11 +109,11 @@ function logEntryStats(stats) {
109
109
  if (format === "es" || format === "module") format = "esm";
110
110
  const output = dim(path) + base;
111
111
  const outputLength = output.length + 2;
112
- cl$1(dim("+"), format.padEnd(5), output.padEnd(outputLength), dim(`[${formatBytes(stats.size)}, ${formatMs(stats.buildTime)}]`));
113
- if (stats.logs) for (const log of stats.logs) cl$1("!", log.level.padEnd(5), output.padEnd(outputLength), dim(log.log.message));
112
+ cl(dim("+"), format.padEnd(5), output.padEnd(outputLength), dim(`[${formatBytes(stats.size)}, ${formatMs(stats.buildTime)}]`));
113
+ if (stats.logs) for (const log of stats.logs) cl("!", log.level.padEnd(5), output.padEnd(outputLength), dim(log.log.message));
114
114
  }
115
115
  async function build(options) {
116
- const { cwd: cwdir = cwd(), outDir = "dist", entries, externals, tsconfig, hooks, minify } = options;
116
+ const { cwd: cwdir = cwd(), outDir = "dist", entries, externals, tsconfig, hooks, minify, comments } = options;
117
117
  let start = 0;
118
118
  const buildStats = {
119
119
  cwd: cwdir,
@@ -168,7 +168,12 @@ async function build(options) {
168
168
  name: entry.name,
169
169
  globals: entry.globals,
170
170
  extend: entry.extend,
171
- plugins: entry.paths ? [outputPaths(entry.paths)] : void 0
171
+ plugins: entry.paths ? [outputPaths(entry.paths)] : void 0,
172
+ comments: entry.comments || comments || {
173
+ legal: true,
174
+ annotation: true,
175
+ jsdoc: false
176
+ }
172
177
  };
173
178
  const entryOptions = {
174
179
  ...entryInput,