makepack 1.7.13 → 1.7.15

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 CHANGED
@@ -1,122 +1,365 @@
1
- <p align="center">
2
- <a href="https://github.com/devnax/makepack" rel="noopener" target="_blank"><img src="https://raw.githubusercontent.com/devnax/makepack/main/logo.png" alt="Makepack logo"></a>
1
+ <div align="center">
2
+
3
+ <img src="./logo.png" alt="makepack" width="90"/>
4
+
5
+ # makepack
6
+
7
+ <strong>A zero‑config (yet configurable) CLI to scaffold, develop, build, and publish modern JavaScript / TypeScript / React libraries.</strong>
8
+
9
+ <p>
10
+ Create a production‑ready npm package in seconds: pick a template, start a hot‑reloading dev server, bundle to ESM + CJS (and optionally a single bundle), generate type declarations, and publish – all with one tool.
3
11
  </p>
4
12
 
5
- <h1 align="center">Makepack</h1>
13
+ <p>
14
+ <!-- Badges (add/adjust once published on npm) -->
15
+ <a href="https://www.npmjs.com/package/makepack"><img src="https://img.shields.io/npm/v/makepack?color=3B82F6" alt="npm version"/></a>
16
+ <a href="https://github.com/devnax/makepack/actions"><img src="https://img.shields.io/badge/build-passing-brightgreen" alt="build"/></a>
17
+ <a href="https://github.com/devnax/makepack/issues"><img src="https://img.shields.io/github/issues/devnax/makepack" alt="issues"/></a>
18
+ <a href="#license"><img src="https://img.shields.io/badge/license-TBD-lightgrey" alt="license"/></a>
19
+ </p>
20
+
21
+ </div>
6
22
 
7
- **MakePack** is a command-line interface (CLI) tool that helps you to quickly set up, build, and manage JavaScript, TypeScript, React, and React-TypeScript libraries for use in npm projects. With just a few simple commands, you can generate your own libraries, start a development server, or build and publish your project to the npm repository.
23
+ ---
8
24
 
25
+ ## ✨ Features
9
26
 
10
- ## 📥 Installation
27
+ - Rapid project creation with four templates:
28
+ - TypeScript library
29
+ - JavaScript library
30
+ - React + TypeScript component library
31
+ - React + JavaScript component library
32
+ - Development server with hot reload + optional Express middleware (`express.ts` / `express.js`)
33
+ - Automatic dependency graph tracking (via `madge`) for efficient reloads
34
+ - Incremental TypeScript compilation and declaration output
35
+ - Dual module build (`esm`, `cjs`, or both) with optional single bundled file
36
+ - Tree‑shaken and optionally minified output
37
+ - Sourcemaps & type declarations by default
38
+ - Clean build output in an isolated `.mpack` directory (publish‑ready)
39
+ - Simple release workflow (`makepack release` or `npm run release` guidance)
11
40
 
12
- Install `makepack` globally to get started:
41
+ ---
13
42
 
14
- ```sh
15
- npm install -g makepack
43
+ ## 🚀 Quick Start
44
+
45
+ Install globally (recommended) or use `npx`.
46
+
47
+ ```bash
48
+ npm install -g makepack # global
49
+ # or
50
+ npx makepack create # without global install
16
51
  ```
17
52
 
18
- ---
53
+ Create a new project:
54
+
55
+ ```bash
56
+ makepack create
57
+ # Answer the interactive prompts:
58
+ # - Project name
59
+ # - Template
60
+ ```
61
+
62
+ Enter the project (if created in a new folder) and start the dev server:
63
+
64
+ ```bash
65
+ cd your-project
66
+ npm start
67
+ ```
68
+
69
+ Build the library:
70
+
71
+ ```bash
72
+ makepack build
73
+ ```
74
+
75
+ Release (after building):
76
+
77
+ ```bash
78
+ makepack release # publishes the contents of ./.mpack to npm
79
+ ```
80
+
81
+ > Tip: You can also run via package scripts (auto‑generated or added manually): `npm run build` / `npm run start`.
19
82
 
20
- ## 🎯 Why Choose makepack?
21
- - **Zero-Config Setup** – Instantly scaffold a structured project.
22
- - **TypeScript Support** – Seamlessly work with modern JavaScript.
23
- - **Integrated Dev Server** – Run your package with Vite and Express.
24
- - **Efficient Build System** – Generate optimized ESM and CJS outputs.
25
- - **One-Command Publish** – Deploy your package to npm effortlessly.
26
83
  ---
27
84
 
28
- ## 📜 CLI Commands
85
+ ## 📦 Generated Project Structure
29
86
 
30
- ### `makepack create` Scaffold a New Project
31
- Quickly initialize a structured package with the following setup:
87
+ Depending on template, you’ll get something like:
32
88
 
33
89
  ```
34
- src/index.ts or tsx or js or jsx
35
- .gitignore
36
- package.json
37
- README.md
90
+ your-lib/
91
+ package.json
92
+ readme.md
93
+ tsconfig.json (TypeScript templates)
94
+ src/
95
+ index.(ts|js|tsx|jsx)
96
+ (React templates include an example component + export)
38
97
  ```
39
98
 
40
- Run:
41
- ```sh
42
- makepack create
99
+ During development/build:
100
+
101
+ ```
102
+ .mpack/ # Build output (cleaned & regenerated each build)
103
+ package.json # Stripped (scripts & "type" removed for publishing clarity)
104
+ readme.md
105
+ dist files # ESM/CJS outputs + declarations + sourcemaps
43
106
  ```
44
- Follow the interactive prompts to configure your project.
45
107
 
46
- ### 🚀 `makepack start` Launch the Development Server
47
- Run a Vite + Express server to develop and test your package in real-time.
108
+ > Do not edit files inside `.mpack` directly. Treat it as a disposable publish directory.
48
109
 
49
- ```sh
50
- makepack start
110
+ ---
111
+
112
+ ## 🧪 Development Server
113
+
114
+ Run: `makepack start --port 3000`
115
+
116
+ Features:
117
+ - Hot reload on dependency change
118
+ - Optional custom Express bootstrap via a root `express.ts` or `express.js` exporting a default function `(app) => { ... }`
119
+ - Safe handler wrapping to catch async errors
120
+
121
+ Example `express.ts`:
122
+
123
+ ```ts
124
+ import { Express } from 'express';
125
+
126
+ export default function routes(app: Express) {
127
+ app.get('/health', (_req, res) => {
128
+ res.json({ ok: true, ts: Date.now() });
129
+ });
130
+ }
131
+ ```
132
+
133
+ If present, it’s reloaded automatically when edited.
134
+
135
+ ---
136
+
137
+ ## 🏗 Build System
138
+
139
+ Command:
140
+
141
+ ```bash
142
+ makepack build [options]
51
143
  ```
52
144
 
53
- ### 🏗️ `makepack build` Compile Your Package
54
- Builds and optimizes your package into the `build` directory.
145
+ | Option | Default | Values | Description |
146
+ | ---------------------- | ------- | -------------------- | --------------------------------------------------- |
147
+ | `--format` / `-f` | `both` | `cjs`, `esm`, `both` | Module formats to output |
148
+ | `--bundle` / `-b` | `false` | `true/false` | Bundle into a single file (rollup/esbuild assisted) |
149
+ | `--minify` / `-m` | `false` | `true/false` | Minify output (Terser) |
150
+ | `--sourcemap` / `-s` | `true` | `true/false` | Emit source maps |
151
+ | `--declaration` / `-d` | `true` | `true/false` | Emit TypeScript `.d.ts` files |
152
+
153
+ Behavior notes:
154
+ - The tool auto‑detects `src/index.(ts|js|tsx|jsx)` as the entry.
155
+ - Boolean flags accept either actual booleans or string equivalents: `--minify=true`.
156
+ - Output is always placed in `.mpack/` (cleaned each run).
157
+ - `package.json` in output has `scripts` and `type` removed for neutral publishing.
55
158
 
56
- ```sh
159
+ ### Example Builds
160
+
161
+ Dual build with declarations (default):
162
+
163
+ ```bash
57
164
  makepack build
58
165
  ```
59
166
 
60
- ### 📦 `makepack publish` – Deploy to NPM
61
- Publish your package to the npm registry in one command.
167
+ ESM only, minified, bundled:
168
+
169
+ ```bash
170
+ makepack build --format=esm --bundle=true --minify=true
171
+ ```
172
+
173
+ Disable sourcemaps & declarations (faster):
174
+
175
+ ```bash
176
+ makepack build -s=false -d=false
177
+ ```
178
+
179
+ ---
180
+
181
+ ## 🚢 Releasing
182
+
183
+ 1. Ensure you are logged in to npm: `npm login`
184
+ 2. Build your package: `makepack build`
185
+ 3. Publish from the generated directory:
186
+ - Quick command: `makepack release`
187
+ - Manual: `cd .mpack && npm publish`
188
+
189
+ > The release command simply runs `npm publish` inside `.mpack` after verifying a build exists.
190
+
191
+ ---
192
+
193
+ ## 🔌 Express Integration (Optional)
194
+
195
+ Add `express.ts` or `express.js` in the project root. Export a default function receiving the Express `app`. Example with middleware:
196
+
197
+ ```ts
198
+ import compression from 'compression';
199
+
200
+ export default function(app) {
201
+ app.use(compression());
202
+ app.get('/', (_req, res) => res.send('Hello from makepack dev server'));
203
+ }
204
+ ```
205
+
206
+ The file and all its dependency graph (resolved via `madge`) are watched; edits trigger a reload.
207
+
208
+ ---
209
+
210
+ ## 🧬 Technology Stack
211
+
212
+ | Area | Tooling |
213
+ | ---------- | ---------------------------------------------------------------------- |
214
+ | CLI | `commander` |
215
+ | Dev Server | `express`, `vite`, `chokidar`, `madge` |
216
+ | Builds | `rollup`, `@rollup/plugin-*`, `esbuild`, `rollup-plugin-dts`, `terser` |
217
+ | UX | `inquirer`, `ora` |
218
+ | FS/Utils | `fs-extra`, `lodash.debounce` |
219
+
220
+ ---
221
+
222
+ ## 🛠 Templates Overview
223
+
224
+ | Template | Use Case | Entry | Extras |
225
+ | ----------------------- | ----------------------------- | --------------- | ------------------- |
226
+ | `typescript` | Library in TypeScript | `src/index.ts` | `tsconfig.json` |
227
+ | `javascript` | Plain JS library | `src/index.js` | – |
228
+ | `react with typescript` | React component library (TSX) | `src/index.tsx` | React + types setup |
229
+ | `react with javascript` | React component library (JSX) | `src/index.jsx` | React setup |
230
+
231
+ Generated React templates export a sample component you can replace.
62
232
 
63
- ```sh
64
- makepack publish
233
+ ---
234
+
235
+ ## 🔄 Lifecycle Summary
236
+
237
+ 1. `create` → scaffold + install deps
238
+ 2. `start` → hot dev (optionally with express middleware)
239
+ 3. `build` → produce distributable code in `.mpack`
240
+ 4. `release` → publish the build to npm
241
+
242
+ ---
243
+
244
+ ## 📘 Command Reference
245
+
246
+ ```bash
247
+ makepack create # Interactive project scaffolding
248
+ makepack start --port 4000 # Start dev server on custom port
249
+ makepack build [flags] # Build library
250
+ makepack release # Publish from .mpack
65
251
  ```
66
252
 
253
+ See build flags in the [Build System](#-build-system) section.
254
+
67
255
  ---
68
256
 
69
- ## ⚙️ Configuration
257
+ ## 🧩 Using From `package.json`
258
+
259
+ You can wire scripts (some templates already do this):
260
+
261
+ ```jsonc
262
+ {
263
+ "scripts": {
264
+ "start": "makepack start --port 3000",
265
+ "build": "makepack build",
266
+ "release": "makepack release"
267
+ }
268
+ }
269
+ ```
270
+
271
+ Run with `npm run build` etc.
272
+
273
+ ---
70
274
 
71
- Customize your project by creating a `makepack.js` file in the root directory. This file allows full control over the build and dev environment.
275
+ ## 🧷 Best Practices
72
276
 
73
- ### 🔧 Default Configuration
277
+ - Keep a clean root: limit extra build artifacts outside `src/`.
278
+ - Export your public API from a single `src/index.*`.
279
+ - Use semantic versioning (e.g. `npm version patch`).
280
+ - For React libraries, avoid bundling peer deps – list `react` & `react-dom` as `peerDependencies` in your own `package.json` before publishing.
281
+ - Add a LICENSE file (see below) – required for many consumers.
74
282
 
75
- ```js
76
- module.exports = (prevConfig) => ({
77
- build: {
78
- outdir: "build",
79
- types: true,
80
- formatPackageJson: (p) => p,
81
- configs: [
82
- {
83
- entryPoints: "src/**/*.{tsx,ts,js,jsx}",
84
- outdir: "esm",
85
- format: "esm",
86
- sourcemap: true,
87
- jsx: 'automatic',
88
- loader: {
89
- '.ts': 'ts',
90
- '.tsx': 'tsx'
91
- },
92
- },
93
- {
94
- entryPoints: "src/**/*.{tsx,ts,js,jsx}",
95
- outdir: "",
96
- format: "cjs",
97
- sourcemap: true,
98
- jsx: 'automatic',
99
- loader: {
100
- '.ts': 'ts',
101
- '.tsx': 'tsx'
102
- },
103
- }
104
- ]
105
- },
106
- start: {
107
- port: 5000,
108
- entry: "App.tsx",
109
- }
110
- });
283
+ ---
284
+
285
+ ## 🐞 Troubleshooting
286
+
287
+ | Issue | Cause | Fix |
288
+ | --------------------- | ------------------------------------ | ----------------------------------------------------------------------- |
289
+ | "No entry file found" | Missing `src/index.*` | Create `src/index.ts` or equivalent |
290
+ | Express not reloading | File outside dependency graph | Import files directly from `express.(ts | js)` |
291
+ | Declarations missing | `--declaration=false` or JS template | Use TS template or enable flag |
292
+ | Publish fails | Not built | Run `makepack build` first |
293
+ | ESM import errors | Missing `"type": "module"` in root | Add `type` back in your source project (it’s stripped only in `.mpack`) |
294
+
295
+ ---
296
+
297
+ ## 🤝 Contributing
298
+
299
+ Contributions welcome! Suggested flow:
300
+
301
+ 1. Fork & clone
302
+ 2. Create a feature branch: `git checkout -b feat/your-idea`
303
+ 3. Implement + add/update docs
304
+ 4. Commit with conventional style: `feat(build): add xyz`
305
+ 5. Open a PR
306
+
307
+ Please include clear reproduction steps for any bug fix.
308
+
309
+ ### Future Ideas (Open for PRs)
310
+ - Plugin system for custom build steps
311
+ - Peer dependency auto‑detection
312
+ - Template customization presets
313
+ - E2E test harness
314
+
315
+ ---
316
+
317
+ ## 🔐 Security
318
+
319
+ No network calls are performed beyond npm install/publish and user code execution. Always audit generated dependencies before publishing.
320
+
321
+ Report vulnerabilities via GitHub Issues (consider labeling as `security`). Avoid posting exploit details publicly – request a private channel if needed.
322
+
323
+ ---
324
+
325
+ ## 📄 License
326
+
327
+ License: **TBD** (e.g. MIT). Add a `LICENSE` file such as:
328
+
329
+ ```text
330
+ MIT License
331
+ Copyright (c) 2025 Devnax
332
+ Permission is hereby granted, free of charge, to any person obtaining a copy...
111
333
  ```
112
334
 
113
335
  ---
114
336
 
115
- ## 📜 License
337
+ ## 🙋 FAQ
338
+
339
+ **Why strip `scripts` and `type` from the published package.json?**
340
+ To minimize accidental exposure of internal scripts and to keep the distributed package neutral; consumers rarely need them.
341
+
342
+ **Can I output only one format?**
343
+ Yes: `--format=esm` or `--format=cjs`.
344
+
345
+ **How do I include assets (e.g. CSS)?**
346
+ Import them from your entry; configure rollup/esbuild plugins in future versions (PRs welcome) – currently you’d manually copy in a post-step.
347
+
348
+ **Does it support monorepos?**
349
+ Not natively; you can still run it per package folder.
350
+
351
+ **Why another tool?**
352
+ To reduce the ceremony of picking + wiring rollup, tsconfig, scripts, vite dev preview, express hooks, and publish layout – all unified.
353
+
354
+ ---
355
+
356
+ ## 📬 Support
116
357
 
117
- `makepack` is released under the **MIT License**, allowing free usage in both open-source and commercial projects.
358
+ Open an issue for bugs, ideas, or questions: https://github.com/devnax/makepack/issues
118
359
 
119
360
  ---
120
361
 
121
- 🚀 **Start building your next NPM package with `makepack` today!**
362
+ <div align="center">
363
+ <sub>Built with ❤️ to streamline modern package creation.</sub>
364
+ </div>
122
365
 
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "makepack",
3
- "version": "1.7.13",
3
+ "version": "1.7.15",
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": [
@@ -20,7 +20,7 @@
20
20
  },
21
21
  "homepage": "https://github.com/devnax/makepack#readme",
22
22
  "scripts": {
23
- "start": "node ./src/index.js start --port 3000",
23
+ "start": "node ./src/index.js start",
24
24
  "create": "node ./src/index.js create",
25
25
  "build": "node ./src/index.js build"
26
26
  },
@@ -6,13 +6,29 @@ import path from "path";
6
6
  import dts from "rollup-plugin-dts";
7
7
  import json from '@rollup/plugin-json';
8
8
  import terser from "@rollup/plugin-terser";
9
+ import { loadRollupConfig, loadViteConfig } from "../../helpers.js";
9
10
 
10
11
  async function bundler(args, spinner) {
12
+
11
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);
12
18
 
13
19
  const config = {
20
+ ...rollupConfig,
14
21
  input: [args.entry],
15
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
+ }
16
32
  return !id.startsWith('.') && !id.startsWith('/') && !/^[A-Za-z]:\\/.test(id);
17
33
  },
18
34
  plugins: [
@@ -38,6 +54,7 @@ async function bundler(args, spinner) {
38
54
  rootDir: path.resolve(process.cwd(), args.rootdir),
39
55
  }),
40
56
  args.minify ? terser() : null,
57
+ ...rollupConfig?.plugins || [],
41
58
  ]
42
59
  };
43
60
 
@@ -9,7 +9,7 @@ import viteSetup from './vite.js';
9
9
  import * as esbuild from 'esbuild';
10
10
  import { randomUUID } from 'crypto';
11
11
  import debounce from 'lodash.debounce';
12
- import { logger, concolor } from '../../helpers.js';
12
+ import { logger, concolor, loadViteConfig } from '../../helpers.js';
13
13
 
14
14
  const projectRoot = process.cwd();
15
15
  const requireFn = createRequire(import.meta.url);
@@ -106,9 +106,9 @@ async function bootServer(args) {
106
106
  };
107
107
  middleware(app);
108
108
  }
109
-
109
+ const config = await loadViteConfig() || {}
110
110
  viteServer = await viteSetup(app);
111
- const port = args.port || 4000;
111
+ const port = args.port || config?.server?.port || 4000;
112
112
  server = app.listen(port, () => {
113
113
  if (!wasServer) {
114
114
  logger.success(`Server running on: ${concolor.green(concolor.bold(`http://localhost:${port}`))}`, '')
@@ -1,10 +1,11 @@
1
1
  // import react from '@vitejs/plugin-react'
2
2
  import { createServer as createViteServer } from 'vite';
3
- import { logger } from '../../helpers.js'
3
+ import { loadViteConfig, logger } from '../../helpers.js'
4
4
  import path from 'path';
5
5
  import fs from 'fs';
6
6
 
7
7
  const viteSetup = async (app) => {
8
+ const config = await loadViteConfig() || {}
8
9
 
9
10
  // delete .vite directory if exists
10
11
  const viteDir = path.join(process.cwd(), 'node_modules/.vite');
@@ -13,10 +14,13 @@ const viteSetup = async (app) => {
13
14
  }
14
15
 
15
16
  const viteConfig = {
17
+ ...config,
18
+ configFile: false,
16
19
  root: process.cwd(),
17
20
  base: "/",
18
21
  // plugins: [react()],
19
22
  server: {
23
+ ...config?.server,
20
24
  middlewareMode: true,
21
25
  },
22
26
  customLogger: {
package/src/helpers.js CHANGED
@@ -1,4 +1,5 @@
1
1
  import child_process from 'child_process'
2
+
2
3
  export const execSync = (command, option = {}) => {
3
4
  try {
4
5
  const result = child_process.execSync(command, {
@@ -50,4 +51,70 @@ export const logger = {
50
51
  error: (message, prefix = 'ERROR:', icon = true) => {
51
52
  logger.log(message, prefix, icon ? 'error' : '', 'red');
52
53
  }
53
- };
54
+ };
55
+
56
+ import fs from 'fs/promises';
57
+ import path from 'path';
58
+ import { pathToFileURL } from 'url';
59
+
60
+ /**
61
+ * Load full Vite config object from root
62
+ */
63
+ export async function loadViteConfig() {
64
+ // List of common Vite config files
65
+ const possibleFiles = [
66
+ 'vite.config.js',
67
+ 'vite.config.ts',
68
+ 'vite.config.mjs',
69
+ 'vite.config.cjs',
70
+ ];
71
+
72
+ for (const file of possibleFiles) {
73
+ const configPath = path.resolve(process.cwd(), file);
74
+
75
+ try {
76
+ await fs.access(configPath); // check if file exists
77
+ } catch {
78
+ continue; // file doesn't exist, try next
79
+ }
80
+
81
+ try {
82
+ const imported = await import(pathToFileURL(configPath).href);
83
+ return imported.default || imported; // return full config object
84
+ } catch (err) {
85
+ console.error(`Failed to load ${file}:`, err);
86
+ return null;
87
+ }
88
+ }
89
+
90
+ return null; // no config found
91
+ }
92
+
93
+
94
+ export async function loadRollupConfig() {
95
+ const possibleFiles = [
96
+ 'rollup.config.js',
97
+ 'rollup.config.mjs',
98
+ 'rollup.config.cjs',
99
+ ];
100
+
101
+ for (const file of possibleFiles) {
102
+ const configPath = path.resolve(process.cwd(), file);
103
+
104
+ try {
105
+ await fs.access(configPath); // check if file exists
106
+ } catch {
107
+ continue; // file doesn't exist, try next
108
+ }
109
+
110
+ try {
111
+ const imported = await import(pathToFileURL(configPath).href);
112
+ return imported.default || imported; // return full config object
113
+ } catch (err) {
114
+ console.error(`Failed to load ${file}:`, err);
115
+ return null;
116
+ }
117
+ }
118
+
119
+ return null;
120
+ }
package/src/index.js CHANGED
@@ -17,7 +17,7 @@ program
17
17
 
18
18
  program
19
19
  .command("start")
20
- .option("-p, --port <port>", "Port to run the server", 3000)
20
+ .option("-p, --port <port>", "Port to run the server")
21
21
  .description("Start the server")
22
22
  .action(start);
23
23