@hypernym/bundler 0.8.1 → 0.9.1

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
@@ -1,4 +1,4 @@
1
- # Bundler
1
+ # @hypernym/bundler
2
2
 
3
3
  ESM & TS module bundler.
4
4
 
@@ -28,7 +28,7 @@ const externals = [
28
28
  ];
29
29
 
30
30
  const name = "bundler";
31
- const version = `0.8.1`;
31
+ const version = `0.9.1`;
32
32
 
33
33
  const cl = console.log;
34
34
  const logger = {
@@ -59,20 +59,16 @@ function formatMs(ms) {
59
59
  const m = s * 60;
60
60
  const h = m * 60;
61
61
  const msAbs = Math.abs(ms);
62
- if (msAbs >= h)
63
- return `${(ms / h).toFixed(2)}h`;
64
- if (msAbs >= m)
65
- return `${(ms / m).toFixed(2)}m`;
66
- if (msAbs >= s)
67
- return `${(ms / s).toFixed(2)}s`;
62
+ if (msAbs >= h) return `${(ms / h).toFixed(2)}h`;
63
+ if (msAbs >= m) return `${(ms / m).toFixed(2)}m`;
64
+ if (msAbs >= s) return `${(ms / s).toFixed(2)}s`;
68
65
  return `${ms}ms`;
69
66
  }
70
67
 
71
68
  function formatBytes(bytes) {
72
69
  const decimals = 2;
73
70
  const units = ["B", "KB", "MB", "GB", "TB"];
74
- if (bytes === 0)
75
- return `0 B`;
71
+ if (bytes === 0) return `0 B`;
76
72
  const k = 1024;
77
73
  const dm = decimals;
78
74
  const i = Math.floor(Math.log(bytes) / Math.log(k));
@@ -85,14 +81,10 @@ function getOutputPath(outDir, input, types = false) {
85
81
  const ts = types ? "d.ts" : "mjs";
86
82
  const mts = types ? "d.mts" : "mjs";
87
83
  const cts = types ? "d.cts" : "cjs";
88
- if (output.endsWith(".ts"))
89
- output = `${output.slice(0, -2)}${ts}`;
90
- if (output.endsWith(".mts"))
91
- output = `${output.slice(0, -3)}${mts}`;
92
- if (output.endsWith(".cts"))
93
- output = `${output.slice(0, -3)}${cts}`;
94
- if (outDir.startsWith("./") || outDir.startsWith("../"))
95
- return output;
84
+ if (output.endsWith(".ts")) output = `${output.slice(0, -2)}${ts}`;
85
+ if (output.endsWith(".mts")) output = `${output.slice(0, -3)}${mts}`;
86
+ if (output.endsWith(".cts")) output = `${output.slice(0, -3)}${cts}`;
87
+ if (outDir.startsWith("./") || outDir.startsWith("../")) return output;
96
88
  return `./${output}`;
97
89
  }
98
90
 
@@ -129,18 +121,15 @@ async function createConfigLoader(cwd, args) {
129
121
  if (args.config) {
130
122
  const path = resolve(cwd, args.config);
131
123
  const isConfig = await exists(path);
132
- if (isConfig)
133
- return await loadConfig(cwd, path, defaults);
134
- else
135
- return logger.exit(warnMessage);
124
+ if (isConfig) return await loadConfig(cwd, path, defaults);
125
+ else return logger.exit(warnMessage);
136
126
  }
137
127
  const configName = "bundler.config";
138
128
  const configExts = [".ts", ".js", ".mts", ".mjs"];
139
129
  for (const ext of configExts) {
140
130
  const path = resolve(cwd, `${configName}${ext}`);
141
131
  const isConfig = await exists(path);
142
- if (isConfig)
143
- return await loadConfig(cwd, path, defaults);
132
+ if (isConfig) return await loadConfig(cwd, path, defaults);
144
133
  }
145
134
  return logger.exit(warnMessage);
146
135
  }
@@ -150,8 +139,7 @@ function resolvePath(path, index = false) {
150
139
  const fileWithoutExt = path.replace(/\.[jt]sx?$/, "");
151
140
  for (const ext of extensions) {
152
141
  const file = index ? join(path, `index${ext}`) : `${fileWithoutExt}${ext}`;
153
- if (existsSync(file))
154
- return file;
142
+ if (existsSync(file)) return file;
155
143
  }
156
144
  return null;
157
145
  }
@@ -163,19 +151,16 @@ function esbuild(options) {
163
151
  if (importer) {
164
152
  const resolved = resolve(importer ? dirname(importer) : cwd(), id);
165
153
  let file = resolvePath(resolved);
166
- if (file)
167
- return file;
154
+ if (file) return file;
168
155
  if (!file && existsSync(resolved) && statSync(resolved).isDirectory()) {
169
156
  file = resolvePath(resolved, true);
170
- if (file)
171
- return file;
157
+ if (file) return file;
172
158
  }
173
159
  }
174
160
  return null;
175
161
  },
176
162
  async transform(code, id) {
177
- if (!filter(id))
178
- return null;
163
+ if (!filter(id)) return null;
179
164
  const result = await transform(code, {
180
165
  loader: "default",
181
166
  ...options,
@@ -187,10 +172,8 @@ function esbuild(options) {
187
172
  };
188
173
  },
189
174
  async renderChunk(code, { fileName }) {
190
- if (!options?.minify)
191
- return null;
192
- if (/\.d\.(c|m)?tsx?$/.test(fileName))
193
- return null;
175
+ if (!options?.minify) return null;
176
+ if (/\.d\.(c|m)?tsx?$/.test(fileName)) return null;
194
177
  const result = await transform(code, {
195
178
  ...options,
196
179
  sourcefile: fileName,
@@ -213,8 +196,7 @@ async function build(cwd, options) {
213
196
  buildTime: 0,
214
197
  files: []
215
198
  };
216
- if (hooks?.["build:start"])
217
- await hooks["build:start"](options, buildStats);
199
+ if (hooks?.["build:start"]) await hooks["build:start"](options, buildStats);
218
200
  if (options.entries) {
219
201
  start = Date.now();
220
202
  const aliasDir = `${resolve(cwd, "./src")}/`;
@@ -230,8 +212,7 @@ async function build(cwd, options) {
230
212
  if ("input" in entry) {
231
213
  const _output = getOutputPath(outDir, entry.input);
232
214
  let _format = "esm";
233
- if (_output.endsWith(".cjs"))
234
- _format = "cjs";
215
+ if (_output.endsWith(".cjs")) _format = "cjs";
235
216
  const buildLogs = [];
236
217
  const _entry = {
237
218
  input: entry.input,
@@ -276,8 +257,7 @@ async function build(cwd, options) {
276
257
  external: _entry.externals,
277
258
  plugins: _entry.plugins,
278
259
  onLog: (level, log) => {
279
- if (logFilter(log))
280
- buildLogs.push({ level, log });
260
+ if (logFilter(log)) buildLogs.push({ level, log });
281
261
  }
282
262
  });
283
263
  await _build.write({
@@ -308,8 +288,7 @@ async function build(cwd, options) {
308
288
  if ("types" in entry) {
309
289
  const _output = getOutputPath(outDir, entry.types, true);
310
290
  let _format = "esm";
311
- if (_output.endsWith(".d.cts"))
312
- _format = "cjs";
291
+ if (_output.endsWith(".d.cts")) _format = "cjs";
313
292
  const buildLogs = [];
314
293
  const _entry = {
315
294
  types: entry.types,
@@ -335,8 +314,7 @@ async function build(cwd, options) {
335
314
  external: _entry.externals,
336
315
  plugins: _entry.plugins,
337
316
  onLog: (level, log) => {
338
- if (logFilter(log))
339
- buildLogs.push({ level, log });
317
+ if (logFilter(log)) buildLogs.push({ level, log });
340
318
  }
341
319
  });
342
320
  await _build.write({
@@ -366,8 +344,7 @@ async function build(cwd, options) {
366
344
  const _distDir = parse(fileURLToPath(import.meta.url)).dir;
367
345
  const _output = entry.output;
368
346
  let _format = "esm";
369
- if (_output.endsWith(".cjs"))
370
- _format = "cjs";
347
+ if (_output.endsWith(".cjs")) _format = "cjs";
371
348
  const buildLogs = [];
372
349
  const _entry = {
373
350
  template: resolve(_distDir, "_empty.ts"),
@@ -381,8 +358,7 @@ async function build(cwd, options) {
381
358
  input: _entry.template,
382
359
  plugins: _entry.plugins,
383
360
  onLog: (level, log) => {
384
- if (logFilter(log))
385
- buildLogs.push({ level, log });
361
+ if (logFilter(log)) buildLogs.push({ level, log });
386
362
  }
387
363
  });
388
364
  await _build.write({
@@ -402,15 +378,13 @@ async function build(cwd, options) {
402
378
  }
403
379
  buildStats.buildTime = Date.now() - start;
404
380
  }
405
- if (hooks?.["build:end"])
406
- await hooks["build:end"](options, buildStats);
381
+ if (hooks?.["build:end"]) await hooks["build:end"](options, buildStats);
407
382
  return buildStats;
408
383
  }
409
384
 
410
385
  async function createBuilder(cwd, args, options) {
411
386
  const { hooks } = options;
412
- if (hooks?.["bundle:start"])
413
- await hooks["bundle:start"](options);
387
+ if (hooks?.["bundle:start"]) await hooks["bundle:start"](options);
414
388
  logger.info(version);
415
389
  logger.info(`Bundling started...`);
416
390
  const spinner = createSpinner();
@@ -440,12 +414,9 @@ async function createBuilder(cwd, args, options) {
440
414
  let format = file.format;
441
415
  const base = parse(file.path).base;
442
416
  const path = file.path.replace(base, "");
443
- if (format.includes("system"))
444
- format = "sys";
445
- if (format === "commonjs")
446
- format = "cjs";
447
- if (format === "module")
448
- format = "esm";
417
+ if (format.includes("system")) format = "sys";
418
+ if (format === "commonjs") format = "cjs";
419
+ if (format === "module") format = "esm";
449
420
  if (file.logs) {
450
421
  for (const log of file.logs) {
451
422
  cl(
@@ -481,8 +452,7 @@ async function createBuilder(cwd, args, options) {
481
452
  console.error(err);
482
453
  return process.exit(1);
483
454
  });
484
- if (hooks?.["bundle:end"])
485
- await hooks["bundle:end"](options);
455
+ if (hooks?.["bundle:end"]) await hooks["bundle:end"](options);
486
456
  }
487
457
 
488
458
  async function main() {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@hypernym/bundler",
3
- "version": "0.8.1",
3
+ "version": "0.9.1",
4
4
  "author": "Hypernym Studio",
5
5
  "description": "ESM & TS module bundler.",
6
6
  "license": "MIT",
@@ -38,14 +38,14 @@
38
38
  },
39
39
  "scripts": {
40
40
  "build": "tsx src/bin/index.ts",
41
- "lint": "ESLINT_USE_FLAT_CONFIG=true eslint -c .config/eslint.config.js .",
42
- "lint:fix": "ESLINT_USE_FLAT_CONFIG=true eslint -c .config/eslint.config.js --fix .",
41
+ "lint": "eslint -c .config/eslint.config.js .",
42
+ "lint:fix": "eslint -c .config/eslint.config.js --fix .",
43
43
  "format": "prettier --config .config/prettier.config.js --write .",
44
44
  "prepublishOnly": "npm run build"
45
45
  },
46
46
  "sideEffects": false,
47
47
  "engines": {
48
- "node": ">=v18.0.0"
48
+ "node": ">=20.0.0"
49
49
  },
50
50
  "peerDependencies": {
51
51
  "@types/node": ">=20.0.0",
@@ -63,23 +63,23 @@
63
63
  "@hypernym/args": "^0.2.1",
64
64
  "@hypernym/colors": "^1.0.1",
65
65
  "@hypernym/spinner": "^0.2.0",
66
- "@hypernym/utils": "^2.3.0",
66
+ "@hypernym/utils": "^3.0.0",
67
67
  "@rollup/plugin-alias": "^5.1.0",
68
68
  "@rollup/plugin-json": "^6.1.0",
69
69
  "@rollup/plugin-node-resolve": "^15.2.3",
70
70
  "@rollup/plugin-replace": "^5.0.5",
71
- "esbuild": "^0.20.1",
72
- "rollup": "^4.13.0",
73
- "rollup-plugin-dts": "^6.1.0"
71
+ "esbuild": "^0.21.3",
72
+ "rollup": "^4.18.0",
73
+ "rollup-plugin-dts": "^6.1.1"
74
74
  },
75
75
  "devDependencies": {
76
- "@hypernym/eslint-config": "^2.0.5",
77
- "@hypernym/prettier-config": "^2.0.4",
78
- "@hypernym/tsconfig": "^1.2.0",
79
- "@types/node": "^20.11.26",
80
- "eslint": "^8.57.0",
76
+ "@hypernym/eslint-config": "^3.0.1",
77
+ "@hypernym/prettier-config": "^3.0.1",
78
+ "@hypernym/tsconfig": "^2.0.0",
79
+ "@types/node": "^20.12.12",
80
+ "eslint": "^9.3.0",
81
81
  "prettier": "^3.2.5",
82
- "tsx": "^4.7.1",
83
- "typescript": "^5.4.2"
82
+ "tsx": "^4.11.0",
83
+ "typescript": "^5.4.5"
84
84
  }
85
85
  }