makepack 1.7.16 → 1.7.18
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 +365 -365
- package/package.json +62 -63
- package/src/actions/build/bundler.js +223 -202
- package/src/actions/build/index.js +79 -79
- package/src/actions/create/files/gitignore.js +9 -9
- package/src/actions/create/files/main.js +36 -36
- package/src/actions/create/files/package-json.js +49 -49
- package/src/actions/create/files/project-js.js +12 -12
- package/src/actions/create/files/project-jsx.js +50 -50
- package/src/actions/create/files/project-ts.js +10 -10
- package/src/actions/create/files/project-tsx.js +50 -50
- package/src/actions/create/files/readme.md.js +62 -62
- package/src/actions/create/files/tsconfig.js +33 -33
- package/src/actions/create/index.js +95 -95
- package/src/actions/create/makeFiles.js +65 -65
- package/src/actions/release/index.js +19 -19
- package/src/actions/start/index.js +215 -215
- package/src/actions/start/vite.js +72 -72
- package/src/helpers.js +120 -120
- package/src/index.js +39 -39
package/package.json
CHANGED
|
@@ -1,64 +1,63 @@
|
|
|
1
|
-
{
|
|
2
|
-
"name": "makepack",
|
|
3
|
-
"version": "1.7.
|
|
4
|
-
"type": "module",
|
|
5
|
-
"description": "A CLI tool to create, build, and manage JavaScript, TypeScript, React, and React-TypeScript libraries for npm projects.",
|
|
6
|
-
"categories": [
|
|
7
|
-
"Other"
|
|
8
|
-
],
|
|
9
|
-
"author": {
|
|
10
|
-
"name": "Devnax",
|
|
11
|
-
"email": "devnaxrul@gmail.com"
|
|
12
|
-
},
|
|
13
|
-
"bin": "./src/index.js",
|
|
14
|
-
"repository": {
|
|
15
|
-
"type": "git",
|
|
16
|
-
"url": "https://github.com/devnax/makepack"
|
|
17
|
-
},
|
|
18
|
-
"bugs": {
|
|
19
|
-
"url": "https://github.com/devnax/makepack/issues"
|
|
20
|
-
},
|
|
21
|
-
"homepage": "https://github.com/devnax/makepack#readme",
|
|
22
|
-
"scripts": {
|
|
23
|
-
"start": "node ./src/index.js start",
|
|
24
|
-
"create": "node ./src/index.js create",
|
|
25
|
-
"build": "node ./src/index.js build"
|
|
26
|
-
},
|
|
27
|
-
"dependencies": {
|
|
28
|
-
"@rollup/plugin-commonjs": "^28.0.5",
|
|
29
|
-
"@rollup/plugin-json": "^6.1.0",
|
|
30
|
-
"@rollup/plugin-node-resolve": "^16.0.1",
|
|
31
|
-
"@rollup/plugin-terser": "^0.4.4",
|
|
32
|
-
"@rollup/plugin-typescript": "^12.1.2",
|
|
33
|
-
"@types/fs-extra": "^11.0.4",
|
|
34
|
-
"chokidar": "^4.0.3",
|
|
35
|
-
"commander": "^12.1.0",
|
|
36
|
-
"esbuild": "^0.25.5",
|
|
37
|
-
"express": "^4.21.1",
|
|
38
|
-
"fs-extra": "^11.2.0",
|
|
39
|
-
"inquirer": "^12.1.0",
|
|
40
|
-
"lodash.debounce": "^4.0.8",
|
|
41
|
-
"madge": "^8.0.0",
|
|
42
|
-
"ora": "^8.1.1",
|
|
43
|
-
"react": "^19.1.0",
|
|
44
|
-
"react-dom": "^19.0.0",
|
|
45
|
-
"rollup": "^4.43.0",
|
|
46
|
-
"rollup-plugin-
|
|
47
|
-
"
|
|
48
|
-
"
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
"
|
|
53
|
-
"
|
|
54
|
-
"
|
|
55
|
-
"
|
|
56
|
-
"
|
|
57
|
-
"
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
"
|
|
62
|
-
|
|
63
|
-
}
|
|
1
|
+
{
|
|
2
|
+
"name": "makepack",
|
|
3
|
+
"version": "1.7.18",
|
|
4
|
+
"type": "module",
|
|
5
|
+
"description": "A CLI tool to create, build, and manage JavaScript, TypeScript, React, and React-TypeScript libraries for npm projects.",
|
|
6
|
+
"categories": [
|
|
7
|
+
"Other"
|
|
8
|
+
],
|
|
9
|
+
"author": {
|
|
10
|
+
"name": "Devnax",
|
|
11
|
+
"email": "devnaxrul@gmail.com"
|
|
12
|
+
},
|
|
13
|
+
"bin": "./src/index.js",
|
|
14
|
+
"repository": {
|
|
15
|
+
"type": "git",
|
|
16
|
+
"url": "https://github.com/devnax/makepack"
|
|
17
|
+
},
|
|
18
|
+
"bugs": {
|
|
19
|
+
"url": "https://github.com/devnax/makepack/issues"
|
|
20
|
+
},
|
|
21
|
+
"homepage": "https://github.com/devnax/makepack#readme",
|
|
22
|
+
"scripts": {
|
|
23
|
+
"start": "node ./src/index.js start",
|
|
24
|
+
"create": "node ./src/index.js create",
|
|
25
|
+
"build": "node ./src/index.js build"
|
|
26
|
+
},
|
|
27
|
+
"dependencies": {
|
|
28
|
+
"@rollup/plugin-commonjs": "^28.0.5",
|
|
29
|
+
"@rollup/plugin-json": "^6.1.0",
|
|
30
|
+
"@rollup/plugin-node-resolve": "^16.0.1",
|
|
31
|
+
"@rollup/plugin-terser": "^0.4.4",
|
|
32
|
+
"@rollup/plugin-typescript": "^12.1.2",
|
|
33
|
+
"@types/fs-extra": "^11.0.4",
|
|
34
|
+
"chokidar": "^4.0.3",
|
|
35
|
+
"commander": "^12.1.0",
|
|
36
|
+
"esbuild": "^0.25.5",
|
|
37
|
+
"express": "^4.21.1",
|
|
38
|
+
"fs-extra": "^11.2.0",
|
|
39
|
+
"inquirer": "^12.1.0",
|
|
40
|
+
"lodash.debounce": "^4.0.8",
|
|
41
|
+
"madge": "^8.0.0",
|
|
42
|
+
"ora": "^8.1.1",
|
|
43
|
+
"react": "^19.1.0",
|
|
44
|
+
"react-dom": "^19.0.0",
|
|
45
|
+
"rollup": "^4.43.0",
|
|
46
|
+
"rollup-plugin-dts": "^6.2.1",
|
|
47
|
+
"tslib": "^2.8.1",
|
|
48
|
+
"vite": "^6.0.2"
|
|
49
|
+
},
|
|
50
|
+
"keywords": [
|
|
51
|
+
"CLI",
|
|
52
|
+
"npm",
|
|
53
|
+
"library",
|
|
54
|
+
"JavaScript",
|
|
55
|
+
"TypeScript",
|
|
56
|
+
"React",
|
|
57
|
+
"npm-package"
|
|
58
|
+
],
|
|
59
|
+
"devDependencies": {
|
|
60
|
+
"@types/react": "^19.1.8",
|
|
61
|
+
"typescript": "^5.8.3"
|
|
62
|
+
}
|
|
64
63
|
}
|
|
@@ -1,202 +1,223 @@
|
|
|
1
|
-
import { rollup } from "rollup";
|
|
2
|
-
import resolve from "@rollup/plugin-node-resolve";
|
|
3
|
-
import commonjs from "@rollup/plugin-commonjs";
|
|
4
|
-
import typescript from "@rollup/plugin-typescript";
|
|
5
|
-
import
|
|
6
|
-
import
|
|
7
|
-
import
|
|
8
|
-
import
|
|
9
|
-
import
|
|
10
|
-
import
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
const
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
}
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
}
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
|
|
189
|
-
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
|
|
196
|
-
|
|
197
|
-
|
|
198
|
-
|
|
199
|
-
|
|
200
|
-
|
|
201
|
-
|
|
202
|
-
|
|
1
|
+
import { rollup } from "rollup";
|
|
2
|
+
import resolve from "@rollup/plugin-node-resolve";
|
|
3
|
+
import commonjs from "@rollup/plugin-commonjs";
|
|
4
|
+
import typescript from "@rollup/plugin-typescript";
|
|
5
|
+
import json from "@rollup/plugin-json";
|
|
6
|
+
import terser from "@rollup/plugin-terser";
|
|
7
|
+
import path from "path";
|
|
8
|
+
import fs from "fs/promises";
|
|
9
|
+
import ts from "typescript";
|
|
10
|
+
import { loadRollupConfig, loadViteConfig } from "../../helpers.js";
|
|
11
|
+
|
|
12
|
+
const MAX_DIR_CONCURRENCY = 16;
|
|
13
|
+
const MAX_FILE_COPY_CONCURRENCY = 32;
|
|
14
|
+
|
|
15
|
+
function isCodeFile(filename) {
|
|
16
|
+
return /\.(ts|tsx|js|jsx|cjs|mjs)$/i.test(filename);
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
function isSkippedDir(name) {
|
|
20
|
+
return name === "node_modules" || name === ".git" || name === ".next";
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
async function getEntriesBatch(root) {
|
|
24
|
+
const entries = {};
|
|
25
|
+
const dirs = [root];
|
|
26
|
+
|
|
27
|
+
async function worker() {
|
|
28
|
+
while (dirs.length) {
|
|
29
|
+
const dir = dirs.shift();
|
|
30
|
+
const items = await fs.readdir(dir, { withFileTypes: true });
|
|
31
|
+
|
|
32
|
+
for (const item of items) {
|
|
33
|
+
const full = path.join(dir, item.name);
|
|
34
|
+
if (item.isDirectory()) dirs.push(full);
|
|
35
|
+
else if (isCodeFile(item.name) && !item.name.endsWith(".d.ts")) {
|
|
36
|
+
// Skip type-only files heuristically
|
|
37
|
+
const content = await fs.readFile(full, "utf-8");
|
|
38
|
+
const typeOnly = /^\s*(export\s+)?(type|interface|enum|declare)/m.test(content);
|
|
39
|
+
if (!typeOnly) {
|
|
40
|
+
const name = path.relative(root, full).replace(/\.(ts|tsx|js|jsx)$/, "");
|
|
41
|
+
entries[name] = full;
|
|
42
|
+
}
|
|
43
|
+
}
|
|
44
|
+
}
|
|
45
|
+
}
|
|
46
|
+
}
|
|
47
|
+
|
|
48
|
+
const workers = Array.from({ length: MAX_DIR_CONCURRENCY }, () => worker());
|
|
49
|
+
await Promise.all(workers);
|
|
50
|
+
|
|
51
|
+
return entries;
|
|
52
|
+
}
|
|
53
|
+
|
|
54
|
+
// --------------------- Parallel asset copy ---------------------
|
|
55
|
+
async function copyAssetsBatched(rootdir, outdir) {
|
|
56
|
+
const queue = [];
|
|
57
|
+
|
|
58
|
+
async function walk(dir) {
|
|
59
|
+
const items = await fs.readdir(dir, { withFileTypes: true });
|
|
60
|
+
for (const item of items) {
|
|
61
|
+
const full = path.join(dir, item.name);
|
|
62
|
+
const rel = path.relative(rootdir, full);
|
|
63
|
+
if (rel.split(path.sep).some(p => isSkippedDir(p))) continue;
|
|
64
|
+
|
|
65
|
+
if (item.isDirectory()) await walk(full);
|
|
66
|
+
else if (!isCodeFile(item.name)) queue.push({ src: full, rel });
|
|
67
|
+
}
|
|
68
|
+
}
|
|
69
|
+
|
|
70
|
+
await walk(rootdir);
|
|
71
|
+
|
|
72
|
+
async function worker() {
|
|
73
|
+
while (queue.length) {
|
|
74
|
+
const { src, rel } = queue.shift();
|
|
75
|
+
const dest = path.join(outdir, rel);
|
|
76
|
+
await fs.mkdir(path.dirname(dest), { recursive: true });
|
|
77
|
+
await fs.copyFile(src, dest);
|
|
78
|
+
}
|
|
79
|
+
}
|
|
80
|
+
|
|
81
|
+
const workers = Array.from({ length: MAX_FILE_COPY_CONCURRENCY }, () => worker());
|
|
82
|
+
await Promise.all(workers);
|
|
83
|
+
}
|
|
84
|
+
|
|
85
|
+
// --------------------- Generate .d.ts programmatically ---------------------
|
|
86
|
+
async function generateDeclarations(rootDir, outDir) {
|
|
87
|
+
const tsFiles = [];
|
|
88
|
+
|
|
89
|
+
async function walk(dir) {
|
|
90
|
+
const items = await fs.readdir(dir, { withFileTypes: true });
|
|
91
|
+
for (const item of items) {
|
|
92
|
+
const full = path.join(dir, item.name);
|
|
93
|
+
if (item.isDirectory()) await walk(full);
|
|
94
|
+
else if (/\.(ts|tsx)$/.test(item.name)) tsFiles.push(full);
|
|
95
|
+
}
|
|
96
|
+
}
|
|
97
|
+
|
|
98
|
+
await walk(rootDir);
|
|
99
|
+
|
|
100
|
+
if (!tsFiles.length) return;
|
|
101
|
+
|
|
102
|
+
const options = {
|
|
103
|
+
declaration: true,
|
|
104
|
+
emitDeclarationOnly: true,
|
|
105
|
+
outDir: outDir,
|
|
106
|
+
rootDir: rootDir,
|
|
107
|
+
moduleResolution: ts.ModuleResolutionKind.NodeJs,
|
|
108
|
+
target: ts.ScriptTarget.ES2017,
|
|
109
|
+
module: ts.ModuleKind.ESNext,
|
|
110
|
+
esModuleInterop: true,
|
|
111
|
+
skipLibCheck: true,
|
|
112
|
+
};
|
|
113
|
+
|
|
114
|
+
const program = ts.createProgram(tsFiles, options);
|
|
115
|
+
program.emit();
|
|
116
|
+
}
|
|
117
|
+
|
|
118
|
+
// --------------------- Main bundler ---------------------
|
|
119
|
+
async function bundler(args, spinner) {
|
|
120
|
+
const rootdir = args.rootdir;
|
|
121
|
+
const outdir = args.outdir;
|
|
122
|
+
|
|
123
|
+
const entries = await getEntriesBatch(rootdir);
|
|
124
|
+
const isTs = Object.values(entries).some(f => f.endsWith(".ts") || f.endsWith(".tsx"));
|
|
125
|
+
|
|
126
|
+
const viteConfig = await loadViteConfig();
|
|
127
|
+
const rollupConfig = await loadRollupConfig();
|
|
128
|
+
const viteRollupConfig = viteConfig?.build?.rollupOptions || {};
|
|
129
|
+
Object.assign(rollupConfig || {}, viteRollupConfig);
|
|
130
|
+
|
|
131
|
+
const config = {
|
|
132
|
+
...rollupConfig,
|
|
133
|
+
input: { ...entries },
|
|
134
|
+
external: id => {
|
|
135
|
+
if (rollupConfig && typeof rollupConfig.external === "function") {
|
|
136
|
+
if (rollupConfig.external(id)) return true;
|
|
137
|
+
}
|
|
138
|
+
if (Array.isArray(rollupConfig && rollupConfig.external)) {
|
|
139
|
+
if (rollupConfig.external.includes(id)) return true;
|
|
140
|
+
}
|
|
141
|
+
return !id.startsWith(".") && !id.startsWith("/") && !/^[A-Za-z]:\\/.test(id);
|
|
142
|
+
},
|
|
143
|
+
plugins: [
|
|
144
|
+
json(),
|
|
145
|
+
resolve({ extensions: [".js", ".ts", ".jsx", ".tsx", ".json", ".mjs", ".cjs"] }),
|
|
146
|
+
commonjs(),
|
|
147
|
+
typescript({
|
|
148
|
+
tsconfig: false,
|
|
149
|
+
target: "ES2017",
|
|
150
|
+
module: "ESNext",
|
|
151
|
+
jsx: "react-jsx",
|
|
152
|
+
moduleResolution: "node",
|
|
153
|
+
esModuleInterop: true,
|
|
154
|
+
strict: true,
|
|
155
|
+
importHelpers: true,
|
|
156
|
+
skipLibCheck: true,
|
|
157
|
+
forceConsistentCasingInFileNames: true,
|
|
158
|
+
declaration: false,
|
|
159
|
+
emitDeclarationOnly: false,
|
|
160
|
+
rootDir: path.resolve(process.cwd(), rootdir)
|
|
161
|
+
}),
|
|
162
|
+
args.minify ? terser() : null,
|
|
163
|
+
...(rollupConfig?.plugins || [])
|
|
164
|
+
]
|
|
165
|
+
};
|
|
166
|
+
|
|
167
|
+
const bundle = await rollup(config);
|
|
168
|
+
|
|
169
|
+
// --------------------- Output formats ---------------------
|
|
170
|
+
const outputs = [];
|
|
171
|
+
if (!args.format || args.format === "both") {
|
|
172
|
+
outputs.push({
|
|
173
|
+
dir: outdir,
|
|
174
|
+
format: "esm",
|
|
175
|
+
sourcemap: args.sourcemap,
|
|
176
|
+
preserveModules: true,
|
|
177
|
+
preserveModulesRoot: rootdir,
|
|
178
|
+
entryFileNames: "[name].mjs"
|
|
179
|
+
});
|
|
180
|
+
outputs.push({
|
|
181
|
+
dir: outdir,
|
|
182
|
+
format: "cjs",
|
|
183
|
+
sourcemap: args.sourcemap,
|
|
184
|
+
preserveModules: true,
|
|
185
|
+
preserveModulesRoot: rootdir,
|
|
186
|
+
entryFileNames: "[name].cjs"
|
|
187
|
+
});
|
|
188
|
+
} else if (args.format === "esm" || args.format === "cjs") {
|
|
189
|
+
outputs.push({
|
|
190
|
+
dir: outdir,
|
|
191
|
+
format: args.format,
|
|
192
|
+
sourcemap: args.sourcemap,
|
|
193
|
+
preserveModules: true,
|
|
194
|
+
preserveModulesRoot: rootdir,
|
|
195
|
+
entryFileNames: args.format === "esm" ? "[name].mjs" : "[name].cjs"
|
|
196
|
+
});
|
|
197
|
+
} else if (args.format === "iife" || args.format === "umd") {
|
|
198
|
+
outputs.push({
|
|
199
|
+
dir: outdir,
|
|
200
|
+
format: args.format,
|
|
201
|
+
name: args.name || "Bundle",
|
|
202
|
+
sourcemap: args.sourcemap,
|
|
203
|
+
entryFileNames: "[name].js"
|
|
204
|
+
});
|
|
205
|
+
}
|
|
206
|
+
|
|
207
|
+
for (const output of outputs) {
|
|
208
|
+
await bundle.write(output);
|
|
209
|
+
}
|
|
210
|
+
|
|
211
|
+
await bundle.close();
|
|
212
|
+
|
|
213
|
+
// --------------------- Copy assets ---------------------
|
|
214
|
+
await copyAssetsBatched(rootdir, outdir);
|
|
215
|
+
|
|
216
|
+
// --------------------- Generate TypeScript declarations ---------------------
|
|
217
|
+
if (isTs && args.declaration) {
|
|
218
|
+
spinner.text = "📄 Generating TypeScript declarations programmatically...";
|
|
219
|
+
await generateDeclarations(rootdir, outdir);
|
|
220
|
+
}
|
|
221
|
+
}
|
|
222
|
+
|
|
223
|
+
export default bundler;
|