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/package.json CHANGED
@@ -1,64 +1,63 @@
1
- {
2
- "name": "makepack",
3
- "version": "1.7.16",
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-copy": "^3.5.0",
47
- "rollup-plugin-dts": "^6.2.1",
48
- "tslib": "^2.8.1",
49
- "vite": "^6.0.2"
50
- },
51
- "keywords": [
52
- "CLI",
53
- "npm",
54
- "library",
55
- "JavaScript",
56
- "TypeScript",
57
- "React",
58
- "npm-package"
59
- ],
60
- "devDependencies": {
61
- "@types/react": "^19.1.8",
62
- "typescript": "^5.8.3"
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 path from "path";
6
- import dts from "rollup-plugin-dts";
7
- import json from "@rollup/plugin-json";
8
- import terser from "@rollup/plugin-terser";
9
- import fs from "fs/promises";
10
- import fss from "fs";
11
- import { loadRollupConfig, loadViteConfig } from "../../helpers.js";
12
-
13
- const MAX_DIR_CONCURRENCY = 16;
14
- const MAX_FILE_COPY_CONCURRENCY = 32;
15
-
16
- // --------------------- Batched multi-entry collector ---------------------
17
- async function getEntriesBatch(root) {
18
- const entries = {};
19
- const dirs = [root];
20
-
21
- async function worker() {
22
- while (dirs.length) {
23
- const dir = dirs.shift();
24
- const items = await fs.readdir(dir, { withFileTypes: true });
25
-
26
- for (const item of items) {
27
- const full = path.join(dir, item.name);
28
- if (item.isDirectory()) {
29
- dirs.push(full);
30
- } else if (/\.(ts|tsx|js|jsx)$/.test(item.name)) {
31
- const name = path.relative(root, full).replace(/\.(ts|tsx|js|jsx)$/, "");
32
- entries[name] = full;
33
- }
34
- }
35
- }
36
- }
37
-
38
- const workers = Array.from({ length: MAX_DIR_CONCURRENCY }, () => worker());
39
- await Promise.all(workers);
40
-
41
- return entries;
42
- }
43
-
44
- // --------------------- Batched parallel asset copy ---------------------
45
- function isCodeFile(filename) {
46
- return /\.(ts|tsx|js|jsx|cjs|mjs|d\.ts)$/i.test(filename);
47
- }
48
-
49
- function isSkippedDir(name) {
50
- return name === "node_modules" || name === ".git" || name === ".next";
51
- }
52
-
53
- async function copyAssetsBatched(rootdir, outdir) {
54
- const queue = [];
55
-
56
- async function walk(dir) {
57
- const items = await fs.readdir(dir, { withFileTypes: true });
58
- for (const item of items) {
59
- const full = path.join(dir, item.name);
60
- const rel = path.relative(rootdir, full);
61
-
62
- if (rel.split(path.sep).some(p => isSkippedDir(p))) continue;
63
-
64
- if (item.isDirectory()) {
65
- await walk(full);
66
- } else if (!isCodeFile(item.name)) {
67
- queue.push({ src: full, rel });
68
- }
69
- }
70
- }
71
-
72
- await walk(rootdir);
73
-
74
- async function worker() {
75
- while (queue.length) {
76
- const { src, rel } = queue.shift();
77
- const dest = path.join(outdir, rel);
78
- await fs.mkdir(path.dirname(dest), { recursive: true });
79
- await fs.copyFile(src, dest);
80
- }
81
- }
82
-
83
- const workers = Array.from({ length: MAX_FILE_COPY_CONCURRENCY }, () => worker());
84
- await Promise.all(workers);
85
- }
86
-
87
- // --------------------- Main Bundler ---------------------
88
- async function bundler(args, spinner) {
89
- const rootdir = args.rootdir;
90
- const outdir = args.outdir;
91
-
92
- // Multi-entry
93
- const entries = await getEntriesBatch(rootdir);
94
- const isTs = Object.values(entries).some(f => f.endsWith(".ts") || f.endsWith(".tsx"));
95
-
96
- const viteConfig = await loadViteConfig();
97
- const rollupConfig = await loadRollupConfig();
98
- const viteRollupConfig = viteConfig?.build?.rollupOptions || {};
99
- Object.assign(rollupConfig || {}, viteRollupConfig);
100
-
101
- const config = {
102
- ...rollupConfig,
103
- input: { ...entries },
104
- external: id => {
105
- if (rollupConfig && typeof rollupConfig.external === "function") {
106
- if (rollupConfig.external(id)) return true;
107
- }
108
- if (Array.isArray(rollupConfig && rollupConfig.external)) {
109
- if (rollupConfig.external.includes(id)) return true;
110
- }
111
- return !id.startsWith(".") && !id.startsWith("/") && !/^[A-Za-z]:\\/.test(id);
112
- },
113
- plugins: [
114
- json(),
115
- resolve({ extensions: [".js", ".ts", ".jsx", ".tsx", ".json", ".mjs", ".cjs"] }),
116
- commonjs(),
117
- typescript({
118
- tsconfig: false,
119
- target: "ES2017",
120
- module: "ESNext",
121
- jsx: "react-jsx",
122
- moduleResolution: "node",
123
- esModuleInterop: true,
124
- strict: true,
125
- importHelpers: true,
126
- skipLibCheck: false,
127
- forceConsistentCasingInFileNames: true,
128
- declaration: false,
129
- emitDeclarationOnly: false,
130
- rootDir: path.resolve(process.cwd(), rootdir)
131
- }),
132
- args.minify ? terser() : null,
133
- ...(rollupConfig?.plugins || [])
134
- ]
135
- };
136
-
137
- const bundle = await rollup(config);
138
-
139
- // --------------------- Determine output formats ---------------------
140
- const outputs = [];
141
-
142
- // Default: build both esm and cjs
143
- if (!args.format || args.format === "both") {
144
- outputs.push({
145
- dir: outdir,
146
- format: "esm",
147
- sourcemap: args.sourcemap,
148
- preserveModules: true,
149
- preserveModulesRoot: rootdir,
150
- entryFileNames: "[name].mjs"
151
- });
152
- outputs.push({
153
- dir: outdir,
154
- format: "cjs",
155
- sourcemap: args.sourcemap,
156
- preserveModules: true,
157
- preserveModulesRoot: rootdir,
158
- entryFileNames: "[name].cjs"
159
- });
160
- } else if (args.format === "esm" || args.format === "cjs") {
161
- outputs.push({
162
- dir: outdir,
163
- format: args.format,
164
- sourcemap: args.sourcemap,
165
- preserveModules: true,
166
- preserveModulesRoot: rootdir,
167
- entryFileNames: args.format === "esm" ? "[name].mjs" : "[name].cjs"
168
- });
169
- } else if (args.format === "iife" || args.format === "umd") {
170
- outputs.push({
171
- dir: outdir,
172
- format: args.format,
173
- name: args.name || "Bundle",
174
- sourcemap: args.sourcemap,
175
- entryFileNames: "[name].js"
176
- });
177
- }
178
-
179
- for (const output of outputs) {
180
- await bundle.write(output);
181
- }
182
-
183
- await bundle.close();
184
-
185
- // --------------------- Parallel asset copy ---------------------
186
- await copyAssetsBatched(rootdir, outdir);
187
-
188
- // --------------------- DTS Generation ---------------------
189
- if (isTs && args.declaration) {
190
- spinner.text = "Generating TypeScript declarations…";
191
- const dtsBundle = await rollup({ ...config, plugins: [dts()] });
192
- await dtsBundle.write({
193
- dir: outdir,
194
- format: "esm",
195
- preserveModules: true,
196
- preserveModulesRoot: rootdir
197
- });
198
- await dtsBundle.close();
199
- }
200
- }
201
-
202
- export default bundler;
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;