makepack 1.7.15 → 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 CHANGED
@@ -1,63 +1,63 @@
1
- {
2
- "name": "makepack",
3
- "version": "1.7.15",
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.17",
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,132 +1,220 @@
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 { loadRollupConfig, loadViteConfig } from "../../helpers.js";
10
-
11
- async function bundler(args, spinner) {
12
-
13
- const isTs = args.entry.endsWith('.ts') || args.entry.endsWith('.tsx')
14
- const viteConfig = await loadViteConfig()
15
- const rollupConfig = await loadRollupConfig()
16
- const viteRollupConfig = viteConfig?.build?.rollupOptions || {}
17
- Object.assign(rollupConfig || {}, viteRollupConfig);
18
-
19
- const config = {
20
- ...rollupConfig,
21
- input: [args.entry],
22
- external: (id) => {
23
- if (rollupConfig && typeof rollupConfig.external === 'function') {
24
- if (rollupConfig.external(id)) {
25
- return true;
26
- }
27
- } else if (Array.isArray(rollupConfig && rollupConfig.external)) {
28
- if (rollupConfig.external.includes(id)) {
29
- return true;
30
- }
31
- }
32
- return !id.startsWith('.') && !id.startsWith('/') && !/^[A-Za-z]:\\/.test(id);
33
- },
34
- plugins: [
35
- json(),
36
- resolve({
37
- extensions: ['.js', '.ts', '.jsx', '.tsx', '.json', '.mjs', '.cjs'],
38
- browser: false
39
- }),
40
- commonjs(),
41
- typescript({
42
- tsconfig: false,
43
- target: "ES2017",
44
- module: "ESNext",
45
- jsx: "react-jsx",
46
- moduleResolution: "node", // ✅ Correct and lowercase
47
- esModuleInterop: true,
48
- skipLibCheck: false,
49
- strict: true,
50
- importHelpers: true,
51
- forceConsistentCasingInFileNames: true,
52
- declaration: false,
53
- emitDeclarationOnly: false,
54
- rootDir: path.resolve(process.cwd(), args.rootdir),
55
- }),
56
- args.minify ? terser() : null,
57
- ...rollupConfig?.plugins || [],
58
- ]
59
- };
60
-
61
- const bundle = await rollup(config);
62
- const esm = {
63
- dir: args.outdir,
64
- format: "esm",
65
- sourcemap: args.sourcemap,
66
- compact: true,
67
- strict: true,
68
- exports: "named"
69
- };
70
- if (!args.bundle) {
71
- esm.preserveModules = true
72
- esm.preserveModulesRoot = args.rootdir
73
- }
74
-
75
- let cjs = {
76
- ...esm,
77
- dir: args.outdir,
78
- format: "cjs",
79
- dynamicImportInCjs: true,
80
- esModule: true,
81
- }
82
-
83
- let outputOptions = []
84
-
85
- if (args.format === "both") {
86
- outputOptions = [
87
- { ...esm, entryFileNames: '[name].mjs' },
88
- cjs,
89
- ]
90
- } else if (args.format === "esm") {
91
- outputOptions = [esm];
92
- } else if (args.format === "cjs") {
93
- outputOptions = [cjs];
94
- } else if (args.format === "iife") {
95
- outputOptions = [{
96
- ...esm,
97
- format: "iife",
98
- name: args.name || path.basename(args.entry, path.extname(args.entry)),
99
- entryFileNames: '[name].js',
100
- }];
101
- } else if (args.format === "umd") {
102
- outputOptions = [{
103
- ...esm,
104
- format: "umd",
105
- name: args.name || path.basename(args.entry, path.extname(args.entry)),
106
- entryFileNames: '[name].js',
107
- }];
108
- }
109
-
110
- for (const output of outputOptions) {
111
- await bundle.write(output);
112
- }
113
- await bundle.close();
114
-
115
- // If TypeScript declaration files are requested, generate them
116
- if (isTs && args.declaration) {
117
- spinner.text = "Generating TypeScript declarations..."
118
- const bundlets = await rollup({
119
- ...config,
120
- plugins: [dts()],
121
- });
122
- await bundlets.write({
123
- format: "esm",
124
- preserveModules: true,
125
- preserveModulesRoot: args.rootdir,
126
- dir: path.join(args.outdir),
127
- });
128
- await bundlets.close();
129
- }
130
- }
131
-
132
- 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
+ // --------------------- Batched multi-entry collector ---------------------
16
+ async function getEntriesBatch(root) {
17
+ const entries = {};
18
+ const dirs = [root];
19
+
20
+ async function worker() {
21
+ while (dirs.length) {
22
+ const dir = dirs.shift();
23
+ const items = await fs.readdir(dir, { withFileTypes: true });
24
+
25
+ for (const item of items) {
26
+ const full = path.join(dir, item.name);
27
+ if (item.isDirectory()) dirs.push(full);
28
+ else if (/\.(ts|tsx|js|jsx)$/.test(item.name)) {
29
+ const name = path.relative(root, full).replace(/\.(ts|tsx|js|jsx)$/, "");
30
+ entries[name] = full;
31
+ }
32
+ }
33
+ }
34
+ }
35
+
36
+ const workers = Array.from({ length: MAX_DIR_CONCURRENCY }, () => worker());
37
+ await Promise.all(workers);
38
+
39
+ return entries;
40
+ }
41
+
42
+ // --------------------- Batched parallel asset copy ---------------------
43
+ function isCodeFile(filename) {
44
+ return /\.(ts|tsx|js|jsx|cjs|mjs)$/i.test(filename);
45
+ }
46
+
47
+ function isSkippedDir(name) {
48
+ return name === "node_modules" || name === ".git" || name === ".next";
49
+ }
50
+
51
+ async function copyAssetsBatched(rootdir, outdir) {
52
+ const queue = [];
53
+
54
+ async function walk(dir) {
55
+ const items = await fs.readdir(dir, { withFileTypes: true });
56
+ for (const item of items) {
57
+ const full = path.join(dir, item.name);
58
+ const rel = path.relative(rootdir, full);
59
+ if (rel.split(path.sep).some(p => isSkippedDir(p))) continue;
60
+
61
+ if (item.isDirectory()) await walk(full);
62
+ else if (!isCodeFile(item.name)) queue.push({ src: full, rel });
63
+ }
64
+ }
65
+
66
+ await walk(rootdir);
67
+
68
+ async function worker() {
69
+ while (queue.length) {
70
+ const { src, rel } = queue.shift();
71
+ const dest = path.join(outdir, rel);
72
+ await fs.mkdir(path.dirname(dest), { recursive: true });
73
+ await fs.copyFile(src, dest);
74
+ }
75
+ }
76
+
77
+ const workers = Array.from({ length: MAX_FILE_COPY_CONCURRENCY }, () => worker());
78
+ await Promise.all(workers);
79
+ }
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
+
114
+ // --------------------- Main Bundler ---------------------
115
+ async function bundler(args, spinner) {
116
+ const rootdir = args.rootdir;
117
+ const outdir = args.outdir;
118
+
119
+ const entries = await getEntriesBatch(rootdir);
120
+ const isTs = Object.values(entries).some(f => f.endsWith(".ts") || f.endsWith(".tsx"));
121
+
122
+ const viteConfig = await loadViteConfig();
123
+ const rollupConfig = await loadRollupConfig();
124
+ const viteRollupConfig = viteConfig?.build?.rollupOptions || {};
125
+ Object.assign(rollupConfig || {}, viteRollupConfig);
126
+
127
+ const config = {
128
+ ...rollupConfig,
129
+ input: { ...entries },
130
+ external: id => {
131
+ if (rollupConfig && typeof rollupConfig.external === "function") {
132
+ if (rollupConfig.external(id)) return true;
133
+ }
134
+ if (Array.isArray(rollupConfig && rollupConfig.external)) {
135
+ if (rollupConfig.external.includes(id)) return true;
136
+ }
137
+ return !id.startsWith(".") && !id.startsWith("/") && !/^[A-Za-z]:\\/.test(id);
138
+ },
139
+ plugins: [
140
+ json(),
141
+ resolve({ extensions: [".js", ".ts", ".jsx", ".tsx", ".json", ".mjs", ".cjs"] }),
142
+ commonjs(),
143
+ typescript({
144
+ tsconfig: false,
145
+ target: "ES2017",
146
+ module: "ESNext",
147
+ jsx: "react-jsx",
148
+ moduleResolution: "node",
149
+ esModuleInterop: true,
150
+ strict: true,
151
+ importHelpers: true,
152
+ skipLibCheck: true,
153
+ forceConsistentCasingInFileNames: true,
154
+ declaration: false,
155
+ emitDeclarationOnly: false,
156
+ rootDir: path.resolve(process.cwd(), rootdir)
157
+ }),
158
+ args.minify ? terser() : null,
159
+ ...(rollupConfig?.plugins || [])
160
+ ]
161
+ };
162
+
163
+ const bundle = await rollup(config);
164
+
165
+ // --------------------- Determine output formats ---------------------
166
+ const outputs = [];
167
+
168
+ if (!args.format || args.format === "both") {
169
+ outputs.push({
170
+ dir: outdir,
171
+ format: "esm",
172
+ sourcemap: args.sourcemap,
173
+ preserveModules: true,
174
+ preserveModulesRoot: rootdir,
175
+ entryFileNames: "[name].mjs"
176
+ });
177
+ outputs.push({
178
+ dir: outdir,
179
+ format: "cjs",
180
+ sourcemap: args.sourcemap,
181
+ preserveModules: true,
182
+ preserveModulesRoot: rootdir,
183
+ entryFileNames: "[name].cjs"
184
+ });
185
+ } else if (args.format === "esm" || args.format === "cjs") {
186
+ outputs.push({
187
+ dir: outdir,
188
+ format: args.format,
189
+ sourcemap: args.sourcemap,
190
+ preserveModules: true,
191
+ preserveModulesRoot: rootdir,
192
+ entryFileNames: args.format === "esm" ? "[name].mjs" : "[name].cjs"
193
+ });
194
+ } else if (args.format === "iife" || args.format === "umd") {
195
+ outputs.push({
196
+ dir: outdir,
197
+ format: args.format,
198
+ name: args.name || "Bundle",
199
+ sourcemap: args.sourcemap,
200
+ entryFileNames: "[name].js"
201
+ });
202
+ }
203
+
204
+ for (const output of outputs) {
205
+ await bundle.write(output);
206
+ }
207
+
208
+ await bundle.close();
209
+
210
+ // --------------------- Copy assets ---------------------
211
+ await copyAssetsBatched(rootdir, outdir);
212
+
213
+ // --------------------- Generate TypeScript declarations ---------------------
214
+ if (isTs && args.declaration) {
215
+ spinner.text = "📄 Generating TypeScript declarations programmatically...";
216
+ await generateDeclarations(rootdir, outdir);
217
+ }
218
+ }
219
+
220
+ export default bundler;
@@ -1,75 +1,79 @@
1
- import fs from 'fs-extra'
2
- import path from 'path'
3
- import ora from 'ora'
4
- import { concolor, logger } from '../../helpers.js'
5
- import bundler from './bundler.js'
6
-
7
- const build = async (args) => {
8
- /* args
9
- --format=both
10
- --bundle=true,
11
- --minify=false,
12
- --sourcemap=true,
13
- --declaration=true,
14
- */
15
-
16
- let printBool = (f) => typeof args[f] === 'string' ? (args[f] === 'true') : args[f];
17
-
18
- const outdir = path.join(process.cwd(), '.mpack');
19
- const rootdir = path.join(process.cwd(), 'src');
20
-
21
- let entry = '';
22
- let entryts = path.join(rootdir, 'index.ts');
23
- let entryjs = path.join(rootdir, 'index.js');
24
- let entrytsx = path.join(rootdir, 'index.tsx');
25
- let entryjsx = path.join(rootdir, 'index.jsx');
26
-
27
- if (fs.existsSync(entryts)) {
28
- entry = "index.ts";
29
- } else if (fs.existsSync(entryjs)) {
30
- entry = "index.js";
31
- } else if (fs.existsSync(entrytsx)) {
32
- entry = "index.tsx";
33
- } else if (fs.existsSync(entryjsx)) {
34
- entry = "index.jsx";
35
- } else {
36
- throw new Error("No entry file found in src directory. Please provide an index.ts or index.js file.");
37
- }
38
-
39
- args = {
40
- format: args.format || "both",
41
- bundle: printBool('bundle'),
42
- minify: printBool('minify'),
43
- sourcemap: printBool('sourcemap'),
44
- declaration: printBool('declaration'),
45
- outdir,
46
- rootdir,
47
- entry: path.join(rootdir, entry),
48
- }
49
-
50
- if (fs.existsSync(outdir)) {
51
- fs.rmSync(outdir, { recursive: true, force: true });
52
- }
53
- fs.mkdirSync(outdir)
54
- const spinner = ora("✨ Bundling your package..\n").start();
55
- await bundler(args, spinner);
56
- spinner.text = "Copying package.json and readme.md files..."
57
- const pkgPath = path.join(process.cwd(), 'package.json');
58
- if (fs.existsSync(pkgPath)) {
59
- const pkgjson = JSON.parse(fs.readFileSync(pkgPath, 'utf-8'));
60
- delete pkgjson.scripts
61
- delete pkgjson.type
62
- fs.writeFileSync(path.join(outdir, 'package.json'), JSON.stringify(pkgjson, null, 2));
63
- } else {
64
- logger.error("package.json not found!");
65
- return;
66
- }
67
-
68
- fs.copyFileSync(path.join(process.cwd(), '/readme.md'), path.join(outdir, `/readme.md`))
69
- spinner.succeed(concolor.bold(concolor.green(`Build successfully completed\n`)));
70
- console.log(concolor.bold(`To publish your package to npm run:`));
71
- console.log(`${concolor.yellow(`\`npm run release\``)} Or navigate to \`.mpack\` and run: ${concolor.yellow(`\`npm publish\`\n`)}`);
72
- spinner.stop();
73
- }
74
-
75
- export default build
1
+ import fs from 'fs-extra';
2
+ import path from 'path';
3
+ import ora from 'ora';
4
+ import { concolor, logger } from '../../helpers.js';
5
+ import bundler from './bundler.js';
6
+
7
+ const build = async (args) => {
8
+ /*
9
+ args options:
10
+ --format=both
11
+ --bundle=true
12
+ --minify=false
13
+ --sourcemap=true
14
+ --declaration=true
15
+ */
16
+
17
+ // Convert string "true"/"false" to boolean
18
+ const beBool = (f) =>
19
+ typeof args[f] === 'string' ? args[f].toLowerCase() === 'true' : !!args[f];
20
+
21
+ const outdir = path.join(process.cwd(), '.mpack');
22
+ const rootdir = path.join(process.cwd(), 'src');
23
+
24
+ args = {
25
+ format: args.format || 'both',
26
+ bundle: beBool('bundle'),
27
+ minify: beBool('minify'),
28
+ sourcemap: beBool('sourcemap'),
29
+ declaration: beBool('declaration'),
30
+ outdir,
31
+ rootdir,
32
+ };
33
+
34
+ const spinner = ora('✨ Building your package...\n').start();
35
+
36
+ try {
37
+ // Remove old build folder
38
+ await fs.remove(outdir);
39
+ await fs.mkdirp(outdir);
40
+
41
+ // Run bundler
42
+ await bundler(args, spinner);
43
+
44
+ spinner.text = '📦 Copying package.json and readme.md files...';
45
+
46
+ // Copy package.json
47
+ const pkgPath = path.join(process.cwd(), 'package.json');
48
+ if (await fs.pathExists(pkgPath)) {
49
+ const pkgjson = await fs.readJson(pkgPath);
50
+ delete pkgjson.scripts;
51
+ delete pkgjson.type;
52
+ await fs.writeJson(path.join(outdir, 'package.json'), pkgjson, { spaces: 2 });
53
+ } else {
54
+ spinner.fail(concolor.red('package.json not found!'));
55
+ return;
56
+ }
57
+
58
+ // Copy readme.md if exists
59
+ const readmePath = path.join(process.cwd(), 'readme.md');
60
+ if (await fs.pathExists(readmePath)) {
61
+ await fs.copy(readmePath, path.join(outdir, 'readme.md'));
62
+ }
63
+
64
+ spinner.succeed(concolor.bold(concolor.green('Build successfully completed!\n')));
65
+ console.log(concolor.bold('To publish your package, run:'));
66
+ console.log(
67
+ `${concolor.yellow('`npm run release`')} or navigate to \`.mpack\` and run: ${concolor.yellow(
68
+ '`npm publish`\n'
69
+ )}`
70
+ );
71
+ } catch (err) {
72
+ spinner.fail(concolor.red('Build failed!'));
73
+ logger.error(err);
74
+ } finally {
75
+ spinner.stop();
76
+ }
77
+ };
78
+
79
+ export default build;
@@ -1,10 +1,10 @@
1
-
2
- export default async () => {
3
- return {
4
- content: `
5
- node_modules
6
- .mpack
7
- `,
8
- filename: ".gitignore"
9
- }
1
+
2
+ export default async () => {
3
+ return {
4
+ content: `
5
+ node_modules
6
+ .mpack
7
+ `,
8
+ filename: ".gitignore"
9
+ }
10
10
  }