makepack 1.7.19 → 1.7.20

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,6 +1,6 @@
1
1
  {
2
2
  "name": "makepack",
3
- "version": "1.7.19",
3
+ "version": "1.7.20",
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": [
@@ -0,0 +1,6 @@
1
+ export default {
2
+ input: {
3
+ hello: './src/test/hello.ts',
4
+ mod: './src/mod/info/test.ts',
5
+ },
6
+ };
@@ -6,10 +6,8 @@ import json from "@rollup/plugin-json";
6
6
  import terser from "@rollup/plugin-terser";
7
7
  import path from "path";
8
8
  import fs from "fs/promises";
9
- import ts from "typescript";
10
9
  import { loadRollupConfig, loadViteConfig } from "../../helpers.js";
11
-
12
- const MAX_DIR_CONCURRENCY = 16;
10
+ import dts from "rollup-plugin-dts";
13
11
  const MAX_FILE_COPY_CONCURRENCY = 32;
14
12
 
15
13
  // --------------------- Helpers ---------------------
@@ -21,48 +19,6 @@ function isSkippedDir(name) {
21
19
  return ["node_modules", ".git", ".next"].includes(name);
22
20
  }
23
21
 
24
- // --------------------- Multi-entry collector with type-only detection ---------------------
25
- async function getEntriesBatch(root) {
26
- const entries = {};
27
- const dirs = [root];
28
-
29
- async function worker() {
30
- while (dirs.length) {
31
- const dir = dirs.shift();
32
- const items = await fs.readdir(dir, { withFileTypes: true });
33
-
34
- for (const item of items) {
35
- const full = path.join(dir, item.name);
36
-
37
- if (item.isDirectory()) {
38
- dirs.push(full);
39
- continue;
40
- }
41
-
42
- if (!isCodeFile(item.name) || item.name.endsWith(".d.ts")) continue;
43
-
44
- // read file content to detect type-only
45
- const content = await fs.readFile(full, "utf-8");
46
- const lines = content.split(/\r?\n/);
47
- const typeOnly = lines.every(
48
- line =>
49
- /^\s*(export\s+)?(type|interface|enum|declare)/.test(line) ||
50
- line.trim() === ""
51
- );
52
-
53
- if (!typeOnly) {
54
- const name = path.relative(root, full).replace(/\.(ts|tsx|js|jsx)$/, "");
55
- entries[name] = full;
56
- }
57
- }
58
- }
59
- }
60
-
61
- const workers = Array.from({ length: MAX_DIR_CONCURRENCY }, () => worker());
62
- await Promise.all(workers);
63
- return entries;
64
- }
65
-
66
22
  // --------------------- Parallel asset copy ---------------------
67
23
  async function copyAssetsBatched(rootdir, outdir) {
68
24
  const queue = [];
@@ -94,47 +50,55 @@ async function copyAssetsBatched(rootdir, outdir) {
94
50
  await Promise.all(workers);
95
51
  }
96
52
 
97
- // --------------------- Generate .d.ts using TS Compiler API ---------------------
98
- async function generateDeclarations(rootDir, outDir) {
99
- const tsFiles = [];
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);
100
60
 
101
- async function walk(dir) {
102
- const items = await fs.readdir(dir, { withFileTypes: true });
103
- for (const item of items) {
104
- const full = path.join(dir, item.name);
105
- if (item.isDirectory()) await walk(full);
106
- else if (/\.(ts|tsx)$/.test(item.name)) tsFiles.push(full);
107
- }
61
+ /** normalize to array of absolute entry paths */
62
+ let entryList = [];
63
+
64
+ // string
65
+ if (typeof entries === "string") {
66
+ entryList = [entries];
108
67
  }
109
68
 
110
- await walk(rootDir);
69
+ // array
70
+ else if (Array.isArray(entries)) {
71
+ entryList = entries;
72
+ }
111
73
 
112
- if (!tsFiles.length) return;
74
+ // object { name: path }
75
+ else if (entries && typeof entries === "object") {
76
+ entryList = Object.values(entries);
77
+ }
113
78
 
114
- const options = {
115
- declaration: true,
116
- emitDeclarationOnly: true,
117
- outDir: outDir,
118
- rootDir: rootDir,
119
- moduleResolution: ts.ModuleResolutionKind.NodeJs,
120
- target: ts.ScriptTarget.ES2017,
121
- module: ts.ModuleKind.ESNext,
122
- esModuleInterop: true,
123
- skipLibCheck: true,
124
- };
79
+ return entryList.map(entry => {
80
+ const absEntry = path.isAbsolute(entry)
81
+ ? entry
82
+ : path.resolve(process.cwd(), entry);
125
83
 
126
- const program = ts.createProgram(tsFiles, options);
127
- program.emit();
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
+ });
128
95
  }
129
96
 
130
97
  // --------------------- Main Bundler ---------------------
131
- async function bundler(args, spinner) {
98
+ async function bundler(args, spinner, child = false) {
132
99
  const rootdir = args.rootdir;
133
100
  const outdir = args.outdir;
134
101
 
135
- const entries = await getEntriesBatch(rootdir);
136
- const isTs = Object.values(entries).some(f => f.endsWith(".ts") || f.endsWith(".tsx"));
137
-
138
102
  const viteConfig = await loadViteConfig();
139
103
  const rollupConfig = await loadRollupConfig();
140
104
  const viteRollupConfig = viteConfig?.build?.rollupOptions || {};
@@ -142,7 +106,7 @@ async function bundler(args, spinner) {
142
106
 
143
107
  const config = {
144
108
  ...rollupConfig,
145
- input: { ...entries },
109
+ input: args.entry,
146
110
  external: id => {
147
111
  if (rollupConfig && typeof rollupConfig.external === "function") {
148
112
  if (rollupConfig.external(id)) return true;
@@ -176,14 +140,9 @@ async function bundler(args, spinner) {
176
140
  ]
177
141
  };
178
142
 
179
- const bundle = await rollup({
180
- ...config,
181
- onwarn(warning, warn) {
182
- // Ignore empty chunk warnings
183
- if (warning.code === "EMPTY_BUNDLE") return;
184
- warn(warning);
185
- }
186
- });
143
+ const bundle = await rollup(config);
144
+
145
+
187
146
 
188
147
  // --------------------- Output formats ---------------------
189
148
  const outputs = [];
@@ -229,13 +188,42 @@ async function bundler(args, spinner) {
229
188
 
230
189
  await bundle.close();
231
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
+
232
208
  // --------------------- Copy assets ---------------------
233
- await copyAssetsBatched(rootdir, outdir);
209
+ if (!child) {
210
+ spinner.text = "📁 Copying non-code assets...";
211
+ await copyAssetsBatched(rootdir, outdir);
212
+ }
234
213
 
235
- // --------------------- Generate TypeScript declarations ---------------------
236
- if (isTs && args.declaration) {
237
- spinner.text = "📄 Generating TypeScript declarations programmatically...";
238
- await generateDeclarations(rootdir, outdir);
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();
239
227
  }
240
228
  }
241
229
 
@@ -20,6 +20,23 @@ const build = async (args) => {
20
20
 
21
21
  const outdir = path.join(process.cwd(), '.mpack');
22
22
  const rootdir = path.join(process.cwd(), 'src');
23
+ let entry = '';
24
+ let entryts = path.join(rootdir, 'index.ts');
25
+ let entryjs = path.join(rootdir, 'index.js');
26
+ let entrytsx = path.join(rootdir, 'index.tsx');
27
+ let entryjsx = path.join(rootdir, 'index.jsx');
28
+
29
+ if (fs.existsSync(entryts)) {
30
+ entry = "index.ts";
31
+ } else if (fs.existsSync(entryjs)) {
32
+ entry = "index.js";
33
+ } else if (fs.existsSync(entrytsx)) {
34
+ entry = "index.tsx";
35
+ } else if (fs.existsSync(entryjsx)) {
36
+ entry = "index.jsx";
37
+ } else {
38
+ throw new Error("No entry file found in src directory. Please provide an index.ts or index.js file.");
39
+ }
23
40
 
24
41
  args = {
25
42
  format: args.format || 'both',
@@ -29,6 +46,7 @@ const build = async (args) => {
29
46
  declaration: beBool('declaration'),
30
47
  outdir,
31
48
  rootdir,
49
+ entry: path.join(rootdir, entry),
32
50
  };
33
51
 
34
52
  const spinner = ora('✨ Building your package...\n').start();
@@ -49,6 +67,12 @@ const build = async (args) => {
49
67
  const pkgjson = await fs.readJson(pkgPath);
50
68
  delete pkgjson.scripts;
51
69
  delete pkgjson.type;
70
+ delete pkgjson.devDependencies;
71
+ delete pkgjson.jest;
72
+ delete pkgjson.prettier;
73
+ delete pkgjson.eslintConfig;
74
+ delete pkgjson.vite;
75
+ delete pkgjson.rollup;
52
76
  await fs.writeJson(path.join(outdir, 'package.json'), pkgjson, { spaces: 2 });
53
77
  } else {
54
78
  spinner.fail(concolor.red('package.json not found!'));
package/src/helpers.js CHANGED
@@ -1,4 +1,8 @@
1
1
  import child_process from 'child_process'
2
+ import fs from 'fs/promises';
3
+ import path from 'path';
4
+ import { pathToFileURL } from 'url';
5
+
2
6
 
3
7
  export const execSync = (command, option = {}) => {
4
8
  try {
@@ -53,9 +57,6 @@ export const logger = {
53
57
  }
54
58
  };
55
59
 
56
- import fs from 'fs/promises';
57
- import path from 'path';
58
- import { pathToFileURL } from 'url';
59
60
 
60
61
  /**
61
62
  * Load full Vite config object from root