makepack 1.7.18 → 1.7.19
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/package.json +1 -1
- package/src/actions/build/bundler.js +38 -19
- package/src/index.js +1 -1
package/package.json
CHANGED
|
@@ -12,14 +12,16 @@ import { loadRollupConfig, loadViteConfig } from "../../helpers.js";
|
|
|
12
12
|
const MAX_DIR_CONCURRENCY = 16;
|
|
13
13
|
const MAX_FILE_COPY_CONCURRENCY = 32;
|
|
14
14
|
|
|
15
|
+
// --------------------- Helpers ---------------------
|
|
15
16
|
function isCodeFile(filename) {
|
|
16
17
|
return /\.(ts|tsx|js|jsx|cjs|mjs)$/i.test(filename);
|
|
17
18
|
}
|
|
18
19
|
|
|
19
20
|
function isSkippedDir(name) {
|
|
20
|
-
return
|
|
21
|
+
return ["node_modules", ".git", ".next"].includes(name);
|
|
21
22
|
}
|
|
22
23
|
|
|
24
|
+
// --------------------- Multi-entry collector with type-only detection ---------------------
|
|
23
25
|
async function getEntriesBatch(root) {
|
|
24
26
|
const entries = {};
|
|
25
27
|
const dirs = [root];
|
|
@@ -31,15 +33,26 @@ async function getEntriesBatch(root) {
|
|
|
31
33
|
|
|
32
34
|
for (const item of items) {
|
|
33
35
|
const full = path.join(dir, item.name);
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
36
|
+
|
|
37
|
+
if (item.isDirectory()) {
|
|
38
|
+
dirs.push(full);
|
|
39
|
+
continue;
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
if (!isCodeFile(item.name) || item.name.endsWith(".d.ts")) continue;
|
|
43
|
+
|
|
44
|
+
// read file content to detect type-only
|
|
45
|
+
const content = await fs.readFile(full, "utf-8");
|
|
46
|
+
const lines = content.split(/\r?\n/);
|
|
47
|
+
const typeOnly = lines.every(
|
|
48
|
+
line =>
|
|
49
|
+
/^\s*(export\s+)?(type|interface|enum|declare)/.test(line) ||
|
|
50
|
+
line.trim() === ""
|
|
51
|
+
);
|
|
52
|
+
|
|
53
|
+
if (!typeOnly) {
|
|
54
|
+
const name = path.relative(root, full).replace(/\.(ts|tsx|js|jsx)$/, "");
|
|
55
|
+
entries[name] = full;
|
|
43
56
|
}
|
|
44
57
|
}
|
|
45
58
|
}
|
|
@@ -47,7 +60,6 @@ async function getEntriesBatch(root) {
|
|
|
47
60
|
|
|
48
61
|
const workers = Array.from({ length: MAX_DIR_CONCURRENCY }, () => worker());
|
|
49
62
|
await Promise.all(workers);
|
|
50
|
-
|
|
51
63
|
return entries;
|
|
52
64
|
}
|
|
53
65
|
|
|
@@ -60,7 +72,7 @@ async function copyAssetsBatched(rootdir, outdir) {
|
|
|
60
72
|
for (const item of items) {
|
|
61
73
|
const full = path.join(dir, item.name);
|
|
62
74
|
const rel = path.relative(rootdir, full);
|
|
63
|
-
if (rel.split(path.sep).some(
|
|
75
|
+
if (rel.split(path.sep).some(isSkippedDir)) continue;
|
|
64
76
|
|
|
65
77
|
if (item.isDirectory()) await walk(full);
|
|
66
78
|
else if (!isCodeFile(item.name)) queue.push({ src: full, rel });
|
|
@@ -82,7 +94,7 @@ async function copyAssetsBatched(rootdir, outdir) {
|
|
|
82
94
|
await Promise.all(workers);
|
|
83
95
|
}
|
|
84
96
|
|
|
85
|
-
// --------------------- Generate .d.ts
|
|
97
|
+
// --------------------- Generate .d.ts using TS Compiler API ---------------------
|
|
86
98
|
async function generateDeclarations(rootDir, outDir) {
|
|
87
99
|
const tsFiles = [];
|
|
88
100
|
|
|
@@ -115,7 +127,7 @@ async function generateDeclarations(rootDir, outDir) {
|
|
|
115
127
|
program.emit();
|
|
116
128
|
}
|
|
117
129
|
|
|
118
|
-
// --------------------- Main
|
|
130
|
+
// --------------------- Main Bundler ---------------------
|
|
119
131
|
async function bundler(args, spinner) {
|
|
120
132
|
const rootdir = args.rootdir;
|
|
121
133
|
const outdir = args.outdir;
|
|
@@ -164,7 +176,14 @@ async function bundler(args, spinner) {
|
|
|
164
176
|
]
|
|
165
177
|
};
|
|
166
178
|
|
|
167
|
-
const bundle = await rollup(
|
|
179
|
+
const bundle = await rollup({
|
|
180
|
+
...config,
|
|
181
|
+
onwarn(warning, warn) {
|
|
182
|
+
// Ignore empty chunk warnings
|
|
183
|
+
if (warning.code === "EMPTY_BUNDLE") return;
|
|
184
|
+
warn(warning);
|
|
185
|
+
}
|
|
186
|
+
});
|
|
168
187
|
|
|
169
188
|
// --------------------- Output formats ---------------------
|
|
170
189
|
const outputs = [];
|
|
@@ -175,7 +194,7 @@ async function bundler(args, spinner) {
|
|
|
175
194
|
sourcemap: args.sourcemap,
|
|
176
195
|
preserveModules: true,
|
|
177
196
|
preserveModulesRoot: rootdir,
|
|
178
|
-
entryFileNames: "[name].mjs"
|
|
197
|
+
entryFileNames: "[name].mjs",
|
|
179
198
|
});
|
|
180
199
|
outputs.push({
|
|
181
200
|
dir: outdir,
|
|
@@ -183,7 +202,7 @@ async function bundler(args, spinner) {
|
|
|
183
202
|
sourcemap: args.sourcemap,
|
|
184
203
|
preserveModules: true,
|
|
185
204
|
preserveModulesRoot: rootdir,
|
|
186
|
-
entryFileNames: "[name].cjs"
|
|
205
|
+
entryFileNames: "[name].cjs",
|
|
187
206
|
});
|
|
188
207
|
} else if (args.format === "esm" || args.format === "cjs") {
|
|
189
208
|
outputs.push({
|
|
@@ -192,7 +211,7 @@ async function bundler(args, spinner) {
|
|
|
192
211
|
sourcemap: args.sourcemap,
|
|
193
212
|
preserveModules: true,
|
|
194
213
|
preserveModulesRoot: rootdir,
|
|
195
|
-
entryFileNames: args.format === "esm" ? "[name].mjs" : "[name].cjs"
|
|
214
|
+
entryFileNames: args.format === "esm" ? "[name].mjs" : "[name].cjs",
|
|
196
215
|
});
|
|
197
216
|
} else if (args.format === "iife" || args.format === "umd") {
|
|
198
217
|
outputs.push({
|
|
@@ -200,7 +219,7 @@ async function bundler(args, spinner) {
|
|
|
200
219
|
format: args.format,
|
|
201
220
|
name: args.name || "Bundle",
|
|
202
221
|
sourcemap: args.sourcemap,
|
|
203
|
-
entryFileNames: "[name].js"
|
|
222
|
+
entryFileNames: "[name].js",
|
|
204
223
|
});
|
|
205
224
|
}
|
|
206
225
|
|
package/src/index.js
CHANGED