makepack 1.7.21 → 1.7.22

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,63 +1,63 @@
1
- {
2
- "name": "makepack",
3
- "version": "1.7.21",
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
- }
1
+ {
2
+ "name": "makepack",
3
+ "version": "1.7.22",
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
+ }
63
63
  }
@@ -1,230 +1,230 @@
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 { loadRollupConfig, loadViteConfig } from "../../helpers.js";
10
- import dts from "rollup-plugin-dts";
11
- const MAX_FILE_COPY_CONCURRENCY = 32;
12
-
13
- // --------------------- Helpers ---------------------
14
- function isCodeFile(filename) {
15
- return /\.(ts|tsx|js|jsx|cjs|mjs)$/i.test(filename);
16
- }
17
-
18
- function isSkippedDir(name) {
19
- return ["node_modules", ".git", ".next"].includes(name);
20
- }
21
-
22
- // --------------------- Parallel asset copy ---------------------
23
- async function copyAssetsBatched(rootdir, outdir) {
24
- const queue = [];
25
-
26
- async function walk(dir) {
27
- const items = await fs.readdir(dir, { withFileTypes: true });
28
- for (const item of items) {
29
- const full = path.join(dir, item.name);
30
- const rel = path.relative(rootdir, full);
31
- if (rel.split(path.sep).some(isSkippedDir)) continue;
32
-
33
- if (item.isDirectory()) await walk(full);
34
- else if (!isCodeFile(item.name)) queue.push({ src: full, rel });
35
- }
36
- }
37
-
38
- await walk(rootdir);
39
-
40
- async function worker() {
41
- while (queue.length) {
42
- const { src, rel } = queue.shift();
43
- const dest = path.join(outdir, rel);
44
- await fs.mkdir(path.dirname(dest), { recursive: true });
45
- await fs.copyFile(src, dest);
46
- }
47
- }
48
-
49
- const workers = Array.from({ length: MAX_FILE_COPY_CONCURRENCY }, () => worker());
50
- await Promise.all(workers);
51
- }
52
-
53
- /**
54
- * Normalize rollup input (string | array | object)
55
- * → returns [{ entry, outdir }]
56
- */
57
- function mapEntriesToOutdirs(entries, rootdir, baseOutdir) {
58
- const absRoot = path.resolve(process.cwd(), rootdir);
59
- const absOut = path.resolve(process.cwd(), baseOutdir);
60
-
61
- /** normalize to array of absolute entry paths */
62
- let entryList = [];
63
-
64
- // string
65
- if (typeof entries === "string") {
66
- entryList = [entries];
67
- }
68
-
69
- // array
70
- else if (Array.isArray(entries)) {
71
- entryList = entries;
72
- }
73
-
74
- // object { name: path }
75
- else if (entries && typeof entries === "object") {
76
- entryList = Object.values(entries);
77
- }
78
-
79
- return entryList.map(entry => {
80
- const absEntry = path.isAbsolute(entry)
81
- ? entry
82
- : path.resolve(process.cwd(), entry);
83
-
84
- // relative path from rootdir (e.g. anydir/entry.ts)
85
- const rel = path.relative(absRoot, absEntry);
86
-
87
- // directory only (e.g. anydir)
88
- const subdir = path.dirname(rel);
89
-
90
- return {
91
- entry: absEntry,
92
- outdir: subdir === "." ? absOut : path.join(absOut, subdir),
93
- };
94
- });
95
- }
96
-
97
- // --------------------- Main Bundler ---------------------
98
- async function bundler(args, spinner, child = false) {
99
- const rootdir = args.rootdir;
100
- const outdir = args.outdir;
101
-
102
- const viteConfig = await loadViteConfig();
103
- const rollupConfig = await loadRollupConfig();
104
- const viteRollupConfig = viteConfig?.build?.rollupOptions || {};
105
- Object.assign(rollupConfig || {}, viteRollupConfig);
106
-
107
- const config = {
108
- ...rollupConfig,
109
- input: args.entry,
110
- external: id => {
111
- if (rollupConfig && typeof rollupConfig.external === "function") {
112
- if (rollupConfig.external(id)) return true;
113
- }
114
- if (Array.isArray(rollupConfig && rollupConfig.external)) {
115
- if (rollupConfig.external.includes(id)) return true;
116
- }
117
- return !id.startsWith(".") && !id.startsWith("/") && !/^[A-Za-z]:\\/.test(id);
118
- },
119
- plugins: [
120
- json(),
121
- resolve({ extensions: [".js", ".ts", ".jsx", ".tsx", ".json", ".mjs", ".cjs"] }),
122
- commonjs(),
123
- typescript({
124
- tsconfig: false,
125
- target: "ES2017",
126
- module: "ESNext",
127
- jsx: "react-jsx",
128
- moduleResolution: "node",
129
- esModuleInterop: true,
130
- strict: true,
131
- importHelpers: true,
132
- skipLibCheck: true,
133
- forceConsistentCasingInFileNames: true,
134
- declaration: false,
135
- emitDeclarationOnly: false,
136
- rootDir: path.resolve(process.cwd(), rootdir)
137
- }),
138
- args.minify ? terser() : null,
139
- ...(rollupConfig?.plugins || [])
140
- ]
141
- };
142
-
143
- const bundle = await rollup(config);
144
-
145
-
146
-
147
- // --------------------- Output formats ---------------------
148
- const outputs = [];
149
- if (!args.format || args.format === "both") {
150
- outputs.push({
151
- dir: outdir,
152
- format: "esm",
153
- sourcemap: args.sourcemap,
154
- preserveModules: true,
155
- preserveModulesRoot: rootdir,
156
- entryFileNames: "[name].mjs",
157
- });
158
- outputs.push({
159
- dir: outdir,
160
- format: "cjs",
161
- sourcemap: args.sourcemap,
162
- preserveModules: true,
163
- preserveModulesRoot: rootdir,
164
- entryFileNames: "[name].cjs",
165
- });
166
- } else if (args.format === "esm" || args.format === "cjs") {
167
- outputs.push({
168
- dir: outdir,
169
- format: args.format,
170
- sourcemap: args.sourcemap,
171
- preserveModules: true,
172
- preserveModulesRoot: rootdir,
173
- entryFileNames: args.format === "esm" ? "[name].mjs" : "[name].cjs",
174
- });
175
- } else if (args.format === "iife" || args.format === "umd") {
176
- outputs.push({
177
- dir: outdir,
178
- format: args.format,
179
- name: args.name || "Bundle",
180
- sourcemap: args.sourcemap,
181
- entryFileNames: "[name].js",
182
- });
183
- }
184
-
185
- for (const output of outputs) {
186
- await bundle.write(output);
187
- }
188
-
189
- await bundle.close();
190
-
191
-
192
- if (!child && rollupConfig && rollupConfig.input) {
193
- const mapentries = mapEntriesToOutdirs(rollupConfig.input, rootdir, outdir)
194
- if (mapentries.length > 1) {
195
- spinner.text = `📦 Bundling ${mapentries.length} entries...`;
196
- }
197
-
198
- for (const { entry } of mapentries) {
199
- await bundler({
200
- ...args,
201
- entry,
202
- outdir,
203
- }, spinner, true);
204
- }
205
-
206
- }
207
-
208
- // --------------------- Copy assets ---------------------
209
- if (!child) {
210
- spinner.text = "📁 Copying non-code assets...";
211
- await copyAssetsBatched(rootdir, outdir);
212
- }
213
-
214
- if (args.declaration) {
215
- spinner.text = "Generating TypeScript declarations..."
216
- const bundlets = await rollup({
217
- ...config,
218
- plugins: [dts()],
219
- });
220
- await bundlets.write({
221
- format: "esm",
222
- preserveModules: true,
223
- preserveModulesRoot: args.rootdir,
224
- dir: path.join(args.outdir),
225
- });
226
- await bundlets.close();
227
- }
228
- }
229
-
230
- 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 { loadRollupConfig, loadViteConfig } from "../../helpers.js";
10
+ import dts from "rollup-plugin-dts";
11
+ const MAX_FILE_COPY_CONCURRENCY = 32;
12
+
13
+ // --------------------- Helpers ---------------------
14
+ function isCodeFile(filename) {
15
+ return /\.(ts|tsx|js|jsx|cjs|mjs)$/i.test(filename);
16
+ }
17
+
18
+ function isSkippedDir(name) {
19
+ return ["node_modules", ".git", ".next"].includes(name);
20
+ }
21
+
22
+ // --------------------- Parallel asset copy ---------------------
23
+ async function copyAssetsBatched(rootdir, outdir) {
24
+ const queue = [];
25
+
26
+ async function walk(dir) {
27
+ const items = await fs.readdir(dir, { withFileTypes: true });
28
+ for (const item of items) {
29
+ const full = path.join(dir, item.name);
30
+ const rel = path.relative(rootdir, full);
31
+ if (rel.split(path.sep).some(isSkippedDir)) continue;
32
+
33
+ if (item.isDirectory()) await walk(full);
34
+ else if (!isCodeFile(item.name)) queue.push({ src: full, rel });
35
+ }
36
+ }
37
+
38
+ await walk(rootdir);
39
+
40
+ async function worker() {
41
+ while (queue.length) {
42
+ const { src, rel } = queue.shift();
43
+ const dest = path.join(outdir, rel);
44
+ await fs.mkdir(path.dirname(dest), { recursive: true });
45
+ await fs.copyFile(src, dest);
46
+ }
47
+ }
48
+
49
+ const workers = Array.from({ length: MAX_FILE_COPY_CONCURRENCY }, () => worker());
50
+ await Promise.all(workers);
51
+ }
52
+
53
+ /**
54
+ * Normalize rollup input (string | array | object)
55
+ * → returns [{ entry, outdir }]
56
+ */
57
+ function mapEntriesToOutdirs(entries, rootdir, baseOutdir) {
58
+ const absRoot = path.resolve(process.cwd(), rootdir);
59
+ const absOut = path.resolve(process.cwd(), baseOutdir);
60
+
61
+ /** normalize to array of absolute entry paths */
62
+ let entryList = [];
63
+
64
+ // string
65
+ if (typeof entries === "string") {
66
+ entryList = [entries];
67
+ }
68
+
69
+ // array
70
+ else if (Array.isArray(entries)) {
71
+ entryList = entries;
72
+ }
73
+
74
+ // object { name: path }
75
+ else if (entries && typeof entries === "object") {
76
+ entryList = Object.values(entries);
77
+ }
78
+
79
+ return entryList.map(entry => {
80
+ const absEntry = path.isAbsolute(entry)
81
+ ? entry
82
+ : path.resolve(process.cwd(), entry);
83
+
84
+ // relative path from rootdir (e.g. anydir/entry.ts)
85
+ const rel = path.relative(absRoot, absEntry);
86
+
87
+ // directory only (e.g. anydir)
88
+ const subdir = path.dirname(rel);
89
+
90
+ return {
91
+ entry: absEntry,
92
+ outdir: subdir === "." ? absOut : path.join(absOut, subdir),
93
+ };
94
+ });
95
+ }
96
+
97
+ // --------------------- Main Bundler ---------------------
98
+ async function bundler(args, spinner, child = false) {
99
+ const rootdir = args.rootdir;
100
+ const outdir = args.outdir;
101
+
102
+ const viteConfig = await loadViteConfig();
103
+ const rollupConfig = await loadRollupConfig();
104
+ const viteRollupConfig = viteConfig?.build?.rollupOptions || {};
105
+ Object.assign(rollupConfig || {}, viteRollupConfig);
106
+
107
+ const config = {
108
+ ...rollupConfig,
109
+ input: args.entry,
110
+ external: id => {
111
+ if (rollupConfig && typeof rollupConfig.external === "function") {
112
+ if (rollupConfig.external(id)) return true;
113
+ }
114
+ if (Array.isArray(rollupConfig && rollupConfig.external)) {
115
+ if (rollupConfig.external.includes(id)) return true;
116
+ }
117
+ return !id.startsWith(".") && !id.startsWith("/") && !/^[A-Za-z]:\\/.test(id);
118
+ },
119
+ plugins: [
120
+ json(),
121
+ resolve({ extensions: [".js", ".ts", ".jsx", ".tsx", ".json", ".mjs", ".cjs"] }),
122
+ commonjs(),
123
+ typescript({
124
+ tsconfig: false,
125
+ target: "ES2017",
126
+ module: "ESNext",
127
+ jsx: "react-jsx",
128
+ moduleResolution: "node",
129
+ esModuleInterop: true,
130
+ strict: true,
131
+ importHelpers: true,
132
+ skipLibCheck: true,
133
+ forceConsistentCasingInFileNames: true,
134
+ declaration: false,
135
+ emitDeclarationOnly: false,
136
+ rootDir: path.resolve(process.cwd(), rootdir)
137
+ }),
138
+ args.minify ? terser() : null,
139
+ ...(rollupConfig?.plugins || [])
140
+ ]
141
+ };
142
+
143
+ const bundle = await rollup(config);
144
+
145
+
146
+
147
+ // --------------------- Output formats ---------------------
148
+ const outputs = [];
149
+ if (!args.format || args.format === "both") {
150
+ outputs.push({
151
+ dir: outdir,
152
+ format: "esm",
153
+ sourcemap: args.sourcemap,
154
+ preserveModules: true,
155
+ preserveModulesRoot: rootdir,
156
+ entryFileNames: "[name].mjs",
157
+ });
158
+ outputs.push({
159
+ dir: outdir,
160
+ format: "cjs",
161
+ sourcemap: args.sourcemap,
162
+ preserveModules: true,
163
+ preserveModulesRoot: rootdir,
164
+ entryFileNames: "[name].js",
165
+ });
166
+ } else if (args.format === "esm" || args.format === "cjs") {
167
+ outputs.push({
168
+ dir: outdir,
169
+ format: args.format,
170
+ sourcemap: args.sourcemap,
171
+ preserveModules: true,
172
+ preserveModulesRoot: rootdir,
173
+ entryFileNames: args.format === "esm" ? "[name].mjs" : "[name].js",
174
+ });
175
+ } else if (args.format === "iife" || args.format === "umd") {
176
+ outputs.push({
177
+ dir: outdir,
178
+ format: args.format,
179
+ name: args.name || "Bundle",
180
+ sourcemap: args.sourcemap,
181
+ entryFileNames: "[name].js",
182
+ });
183
+ }
184
+
185
+ for (const output of outputs) {
186
+ await bundle.write(output);
187
+ }
188
+
189
+ await bundle.close();
190
+
191
+
192
+ if (!child && rollupConfig && rollupConfig.input) {
193
+ const mapentries = mapEntriesToOutdirs(rollupConfig.input, rootdir, outdir)
194
+ if (mapentries.length > 1) {
195
+ spinner.text = `📦 Bundling ${mapentries.length} entries...`;
196
+ }
197
+
198
+ for (const { entry } of mapentries) {
199
+ await bundler({
200
+ ...args,
201
+ entry,
202
+ outdir,
203
+ }, spinner, true);
204
+ }
205
+
206
+ }
207
+
208
+ // --------------------- Copy assets ---------------------
209
+ if (!child) {
210
+ spinner.text = "📁 Copying non-code assets...";
211
+ await copyAssetsBatched(rootdir, outdir);
212
+ }
213
+
214
+ if (args.declaration) {
215
+ spinner.text = "Generating TypeScript declarations..."
216
+ const bundlets = await rollup({
217
+ ...config,
218
+ plugins: [dts()],
219
+ });
220
+ await bundlets.write({
221
+ format: "esm",
222
+ preserveModules: true,
223
+ preserveModulesRoot: args.rootdir,
224
+ dir: path.join(args.outdir),
225
+ });
226
+ await bundlets.close();
227
+ }
228
+ }
229
+
230
+ export default bundler;