@hypernym/bundler 0.5.0 → 0.6.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.
@@ -0,0 +1 @@
1
+ // Generated by @hypernym/bundler
@@ -7,6 +7,7 @@ import { exists, writeFile } from '@hypernym/utils/fs';
7
7
  import { cyan, dim, red, magenta, green } from '@hypernym/colors';
8
8
  import { build as build$1, transform } from 'esbuild';
9
9
  import { createSpinner } from '@hypernym/spinner';
10
+ import { fileURLToPath } from 'node:url';
10
11
  import { isObject } from '@hypernym/utils';
11
12
  import { rollup } from 'rollup';
12
13
  import { getLogFilter } from 'rollup/getLogFilter';
@@ -25,7 +26,7 @@ const externals = [
25
26
  ];
26
27
 
27
28
  const name = "bundler";
28
- const version = `0.5.0`;
29
+ const version = `0.6.0`;
29
30
 
30
31
  const cl = console.log;
31
32
  const logger = {
@@ -202,7 +203,7 @@ async function build(cwd, options) {
202
203
  start = Date.now();
203
204
  for (const entry of options.entries) {
204
205
  const entryStart = Date.now();
205
- const logFilter = getLogFilter(entry.logFilter || []);
206
+ let logFilter = getLogFilter(entry.logFilter || []);
206
207
  if ("input" in entry) {
207
208
  const _output = getOutputPath(outDir, entry.input);
208
209
  let _format = "esm";
@@ -331,6 +332,44 @@ async function build(cwd, options) {
331
332
  await hooks["build:entry:end"](_entry, buildStats);
332
333
  }
333
334
  }
335
+ if ("template" in entry) {
336
+ logFilter = getLogFilter(entry.logFilter || ["!code:EMPTY_BUNDLE"]);
337
+ const _distDir = parse(fileURLToPath(import.meta.url)).dir;
338
+ const _output = entry.output;
339
+ let _format = "esm";
340
+ if (_output.endsWith(".cjs"))
341
+ _format = "cjs";
342
+ const buildLogs = [];
343
+ const _entry = {
344
+ template: resolve(_distDir, "_empty.ts"),
345
+ output: _output,
346
+ content: entry.content,
347
+ plugins: [esbuild(entry.plugins?.esbuild)],
348
+ pluginsOptions: entry.plugins,
349
+ format: entry.format || _format
350
+ };
351
+ const _build = await rollup({
352
+ input: _entry.template,
353
+ plugins: _entry.plugins,
354
+ onLog: (level, log) => {
355
+ if (logFilter(log))
356
+ buildLogs.push({ level, log });
357
+ }
358
+ });
359
+ await _build.write({
360
+ file: resolve(cwd, _entry.output),
361
+ intro: _entry.content
362
+ });
363
+ const stats = await stat(resolve(cwd, _entry.output));
364
+ buildStats.files.push({
365
+ path: _entry.output,
366
+ size: stats.size,
367
+ buildTime: Date.now() - entryStart,
368
+ format: _entry.format,
369
+ logs: buildLogs
370
+ });
371
+ buildStats.size = buildStats.size + stats.size;
372
+ }
334
373
  }
335
374
  buildStats.buildTime = Date.now() - start;
336
375
  }
@@ -122,7 +122,64 @@ interface EntryTypes extends EntryBase {
122
122
  */
123
123
  plugins?: PluginsTypes;
124
124
  }
125
- type EntryOptions = EntryInput | EntryTypes;
125
+ interface EntryTemplate extends Pick<EntryBase, 'logFilter'> {
126
+ /**
127
+ * Specifies the build entry as a module template.
128
+ *
129
+ * Provides the ability to dynamically inject template content during the build phase.
130
+ *
131
+ * @example
132
+ *
133
+ * ```ts
134
+ * export default defineConfig({
135
+ * entries: [
136
+ * {
137
+ * template: true,
138
+ * output: './dist/template.ts',
139
+ * content: '// TypeScript code...',
140
+ * },
141
+ * ]
142
+ * })
143
+ * ```
144
+ */
145
+ template: true;
146
+ /**
147
+ * Specifies the path of the transformed module template.
148
+ */
149
+ output: string;
150
+ /**
151
+ * Specifies the content of the module template.
152
+ */
153
+ content: OutputOptions['intro'];
154
+ /**
155
+ * Specifies the format of the generated module template.
156
+ *
157
+ * @example
158
+ *
159
+ * ```ts
160
+ * export default defineConfig({
161
+ * entries: [
162
+ * {
163
+ * template: true,
164
+ * output: './dist/template.json',
165
+ * content: '{}',
166
+ * format: 'json',
167
+ * },
168
+ * ]
169
+ * })
170
+ * ```
171
+ *
172
+ * @default 'esm'
173
+ */
174
+ format?: string;
175
+ /**
176
+ * Specifies plugin options.
177
+ *
178
+ * @default undefined
179
+ */
180
+ plugins?: Pick<PluginsInput, 'esbuild'>;
181
+ }
182
+ type EntryOptions = EntryInput | EntryTypes | EntryTemplate;
126
183
 
127
184
  interface Options {
128
185
  /**
@@ -386,4 +443,4 @@ interface HooksOptions {
386
443
  declare const externals: RegExp[];
387
444
  declare function defineConfig(options: Options): Options;
388
445
 
389
- export { type BuildLogs, type BuildStats, type EntryBase, type EntryInput, type EntryOptions, type EntryTypes, type HooksOptions, type Options, type PluginsInput, type PluginsTypes, defineConfig, externals };
446
+ export { type BuildLogs, type BuildStats, type EntryBase, type EntryInput, type EntryOptions, type EntryTemplate, type EntryTypes, type HooksOptions, type Options, type PluginsInput, type PluginsTypes, defineConfig, externals };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@hypernym/bundler",
3
- "version": "0.5.0",
3
+ "version": "0.6.0",
4
4
  "author": "Hypernym Studio",
5
5
  "description": "ESM & TS module bundler.",
6
6
  "license": "MIT",
@@ -71,8 +71,8 @@
71
71
  "@hypernym/eslint-config": "^2.0.2",
72
72
  "@hypernym/prettier-config": "^2.0.2",
73
73
  "@hypernym/tsconfig": "^1.1.0",
74
- "@types/node": "^20.8.7",
75
- "eslint": "^8.51.0",
74
+ "@types/node": "^20.8.9",
75
+ "eslint": "^8.52.0",
76
76
  "prettier": "^3.0.3",
77
77
  "tsx": "^3.14.0",
78
78
  "typescript": "^5.2.2"