makepack 1.7.16 → 1.7.17
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 -2
- package/src/actions/build/bundler.js +45 -27
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "makepack",
|
|
3
|
-
"version": "1.7.
|
|
3
|
+
"version": "1.7.17",
|
|
4
4
|
"type": "module",
|
|
5
5
|
"description": "A CLI tool to create, build, and manage JavaScript, TypeScript, React, and React-TypeScript libraries for npm projects.",
|
|
6
6
|
"categories": [
|
|
@@ -43,7 +43,6 @@
|
|
|
43
43
|
"react": "^19.1.0",
|
|
44
44
|
"react-dom": "^19.0.0",
|
|
45
45
|
"rollup": "^4.43.0",
|
|
46
|
-
"rollup-plugin-copy": "^3.5.0",
|
|
47
46
|
"rollup-plugin-dts": "^6.2.1",
|
|
48
47
|
"tslib": "^2.8.1",
|
|
49
48
|
"vite": "^6.0.2"
|
|
@@ -2,12 +2,11 @@ import { rollup } from "rollup";
|
|
|
2
2
|
import resolve from "@rollup/plugin-node-resolve";
|
|
3
3
|
import commonjs from "@rollup/plugin-commonjs";
|
|
4
4
|
import typescript from "@rollup/plugin-typescript";
|
|
5
|
-
import path from "path";
|
|
6
|
-
import dts from "rollup-plugin-dts";
|
|
7
5
|
import json from "@rollup/plugin-json";
|
|
8
6
|
import terser from "@rollup/plugin-terser";
|
|
7
|
+
import path from "path";
|
|
9
8
|
import fs from "fs/promises";
|
|
10
|
-
import
|
|
9
|
+
import ts from "typescript";
|
|
11
10
|
import { loadRollupConfig, loadViteConfig } from "../../helpers.js";
|
|
12
11
|
|
|
13
12
|
const MAX_DIR_CONCURRENCY = 16;
|
|
@@ -25,9 +24,8 @@ async function getEntriesBatch(root) {
|
|
|
25
24
|
|
|
26
25
|
for (const item of items) {
|
|
27
26
|
const full = path.join(dir, item.name);
|
|
28
|
-
if (item.isDirectory())
|
|
29
|
-
|
|
30
|
-
} else if (/\.(ts|tsx|js|jsx)$/.test(item.name)) {
|
|
27
|
+
if (item.isDirectory()) dirs.push(full);
|
|
28
|
+
else if (/\.(ts|tsx|js|jsx)$/.test(item.name)) {
|
|
31
29
|
const name = path.relative(root, full).replace(/\.(ts|tsx|js|jsx)$/, "");
|
|
32
30
|
entries[name] = full;
|
|
33
31
|
}
|
|
@@ -43,7 +41,7 @@ async function getEntriesBatch(root) {
|
|
|
43
41
|
|
|
44
42
|
// --------------------- Batched parallel asset copy ---------------------
|
|
45
43
|
function isCodeFile(filename) {
|
|
46
|
-
return /\.(ts|tsx|js|jsx|cjs|mjs
|
|
44
|
+
return /\.(ts|tsx|js|jsx|cjs|mjs)$/i.test(filename);
|
|
47
45
|
}
|
|
48
46
|
|
|
49
47
|
function isSkippedDir(name) {
|
|
@@ -58,14 +56,10 @@ async function copyAssetsBatched(rootdir, outdir) {
|
|
|
58
56
|
for (const item of items) {
|
|
59
57
|
const full = path.join(dir, item.name);
|
|
60
58
|
const rel = path.relative(rootdir, full);
|
|
61
|
-
|
|
62
59
|
if (rel.split(path.sep).some(p => isSkippedDir(p))) continue;
|
|
63
60
|
|
|
64
|
-
if (item.isDirectory())
|
|
65
|
-
|
|
66
|
-
} else if (!isCodeFile(item.name)) {
|
|
67
|
-
queue.push({ src: full, rel });
|
|
68
|
-
}
|
|
61
|
+
if (item.isDirectory()) await walk(full);
|
|
62
|
+
else if (!isCodeFile(item.name)) queue.push({ src: full, rel });
|
|
69
63
|
}
|
|
70
64
|
}
|
|
71
65
|
|
|
@@ -84,12 +78,44 @@ async function copyAssetsBatched(rootdir, outdir) {
|
|
|
84
78
|
await Promise.all(workers);
|
|
85
79
|
}
|
|
86
80
|
|
|
81
|
+
// --------------------- Generate .d.ts using TS Compiler API ---------------------
|
|
82
|
+
async function generateDeclarations(rootDir, outDir) {
|
|
83
|
+
const tsFiles = [];
|
|
84
|
+
|
|
85
|
+
async function walk(dir) {
|
|
86
|
+
const items = await fs.readdir(dir, { withFileTypes: true });
|
|
87
|
+
for (const item of items) {
|
|
88
|
+
const full = path.join(dir, item.name);
|
|
89
|
+
if (item.isDirectory()) await walk(full);
|
|
90
|
+
else if (/\.(ts|tsx)$/.test(item.name)) tsFiles.push(full);
|
|
91
|
+
}
|
|
92
|
+
}
|
|
93
|
+
|
|
94
|
+
await walk(rootDir);
|
|
95
|
+
|
|
96
|
+
if (!tsFiles.length) return;
|
|
97
|
+
|
|
98
|
+
const options = {
|
|
99
|
+
declaration: true,
|
|
100
|
+
emitDeclarationOnly: true,
|
|
101
|
+
outDir: outDir,
|
|
102
|
+
rootDir: rootDir,
|
|
103
|
+
moduleResolution: ts.ModuleResolutionKind.NodeJs,
|
|
104
|
+
target: ts.ScriptTarget.ES2017,
|
|
105
|
+
module: ts.ModuleKind.ESNext,
|
|
106
|
+
esModuleInterop: true,
|
|
107
|
+
skipLibCheck: true,
|
|
108
|
+
};
|
|
109
|
+
|
|
110
|
+
const program = ts.createProgram(tsFiles, options);
|
|
111
|
+
program.emit();
|
|
112
|
+
}
|
|
113
|
+
|
|
87
114
|
// --------------------- Main Bundler ---------------------
|
|
88
115
|
async function bundler(args, spinner) {
|
|
89
116
|
const rootdir = args.rootdir;
|
|
90
117
|
const outdir = args.outdir;
|
|
91
118
|
|
|
92
|
-
// Multi-entry
|
|
93
119
|
const entries = await getEntriesBatch(rootdir);
|
|
94
120
|
const isTs = Object.values(entries).some(f => f.endsWith(".ts") || f.endsWith(".tsx"));
|
|
95
121
|
|
|
@@ -123,7 +149,7 @@ async function bundler(args, spinner) {
|
|
|
123
149
|
esModuleInterop: true,
|
|
124
150
|
strict: true,
|
|
125
151
|
importHelpers: true,
|
|
126
|
-
skipLibCheck:
|
|
152
|
+
skipLibCheck: true,
|
|
127
153
|
forceConsistentCasingInFileNames: true,
|
|
128
154
|
declaration: false,
|
|
129
155
|
emitDeclarationOnly: false,
|
|
@@ -139,7 +165,6 @@ async function bundler(args, spinner) {
|
|
|
139
165
|
// --------------------- Determine output formats ---------------------
|
|
140
166
|
const outputs = [];
|
|
141
167
|
|
|
142
|
-
// Default: build both esm and cjs
|
|
143
168
|
if (!args.format || args.format === "both") {
|
|
144
169
|
outputs.push({
|
|
145
170
|
dir: outdir,
|
|
@@ -182,20 +207,13 @@ async function bundler(args, spinner) {
|
|
|
182
207
|
|
|
183
208
|
await bundle.close();
|
|
184
209
|
|
|
185
|
-
// ---------------------
|
|
210
|
+
// --------------------- Copy assets ---------------------
|
|
186
211
|
await copyAssetsBatched(rootdir, outdir);
|
|
187
212
|
|
|
188
|
-
// ---------------------
|
|
213
|
+
// --------------------- Generate TypeScript declarations ---------------------
|
|
189
214
|
if (isTs && args.declaration) {
|
|
190
|
-
spinner.text = "Generating TypeScript declarations
|
|
191
|
-
|
|
192
|
-
await dtsBundle.write({
|
|
193
|
-
dir: outdir,
|
|
194
|
-
format: "esm",
|
|
195
|
-
preserveModules: true,
|
|
196
|
-
preserveModulesRoot: rootdir
|
|
197
|
-
});
|
|
198
|
-
await dtsBundle.close();
|
|
215
|
+
spinner.text = "📄 Generating TypeScript declarations programmatically...";
|
|
216
|
+
await generateDeclarations(rootdir, outdir);
|
|
199
217
|
}
|
|
200
218
|
}
|
|
201
219
|
|