@hypernym/bundler 0.9.0 → 0.9.2
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/dist/bin/index.mjs +31 -61
- package/package.json +11 -11
package/dist/bin/index.mjs
CHANGED
|
@@ -28,7 +28,7 @@ const externals = [
|
|
|
28
28
|
];
|
|
29
29
|
|
|
30
30
|
const name = "bundler";
|
|
31
|
-
const version = `0.9.
|
|
31
|
+
const version = `0.9.2`;
|
|
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
|
-
|
|
64
|
-
if (msAbs >=
|
|
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
|
-
|
|
90
|
-
if (output.endsWith(".
|
|
91
|
-
|
|
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
|
-
|
|
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
|
-
|
|
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
|
-
|
|
445
|
-
if (format === "
|
|
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.9.
|
|
3
|
+
"version": "0.9.2",
|
|
4
4
|
"author": "Hypernym Studio",
|
|
5
5
|
"description": "ESM & TS module bundler.",
|
|
6
6
|
"license": "MIT",
|
|
@@ -68,18 +68,18 @@
|
|
|
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.
|
|
72
|
-
"rollup": "^4.
|
|
73
|
-
"rollup-plugin-dts": "^6.1.
|
|
71
|
+
"esbuild": "^0.21.4",
|
|
72
|
+
"rollup": "^4.18.0",
|
|
73
|
+
"rollup-plugin-dts": "^6.1.1"
|
|
74
74
|
},
|
|
75
75
|
"devDependencies": {
|
|
76
|
-
"@hypernym/eslint-config": "^3.0.
|
|
77
|
-
"@hypernym/prettier-config": "^3.0.
|
|
76
|
+
"@hypernym/eslint-config": "^3.0.2",
|
|
77
|
+
"@hypernym/prettier-config": "^3.0.1",
|
|
78
78
|
"@hypernym/tsconfig": "^2.0.0",
|
|
79
|
-
"@types/node": "^20.
|
|
80
|
-
"eslint": "^9.
|
|
81
|
-
"prettier": "^3.
|
|
82
|
-
"tsx": "^4.
|
|
83
|
-
"typescript": "^5.4.
|
|
79
|
+
"@types/node": "^20.14.1",
|
|
80
|
+
"eslint": "^9.4.0",
|
|
81
|
+
"prettier": "^3.3.0",
|
|
82
|
+
"tsx": "^4.11.2",
|
|
83
|
+
"typescript": "^5.4.5"
|
|
84
84
|
}
|
|
85
85
|
}
|