makepack 1.7.24 → 1.7.25

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.24",
3
+ "version": "1.7.25",
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": [
@@ -141,48 +141,36 @@ async function bundler(args, spinner, child = false) {
141
141
 
142
142
  const bundle = await rollup(config);
143
143
 
144
-
145
-
146
144
  // --------------------- Output formats ---------------------
147
- const outputs = [];
148
- if (!args.format || args.format === "both") {
149
- outputs.push({
150
- dir: outdir,
151
- format: "esm",
152
- sourcemap: args.sourcemap,
153
- preserveModules: true,
154
- preserveModulesRoot: rootdir,
155
- entryFileNames: "[name].mjs",
156
- });
157
- outputs.push({
158
- dir: outdir,
159
- format: "cjs",
160
- sourcemap: args.sourcemap,
161
- preserveModules: true,
162
- preserveModulesRoot: rootdir,
163
- entryFileNames: "[name].js",
164
- });
165
- } else if (args.format === "esm" || args.format === "cjs") {
166
- outputs.push({
167
- dir: outdir,
168
- format: args.format,
169
- sourcemap: args.sourcemap,
170
- preserveModules: true,
171
- preserveModulesRoot: rootdir,
172
- entryFileNames: args.format === "esm" ? "[name].mjs" : "[name].js",
173
- });
174
- } else if (args.format === "iife" || args.format === "umd") {
175
- outputs.push({
176
- dir: outdir,
177
- format: args.format,
178
- name: args.name || "Bundle",
179
- sourcemap: args.sourcemap,
180
- entryFileNames: "[name].js",
181
- });
145
+ const outputs = []
146
+ const isModern = args.format === "modern";
147
+ const formats = isModern ? ["esm", "cjs"] : [args.format];
148
+
149
+ for (let f of formats) {
150
+ const isFirst = formats[0] === f;
151
+ const dir = isFirst ? outdir : path.join(outdir, f);
152
+
153
+ if (f === "esm" || f === "cjs") {
154
+ let ext = isModern ? f === "esm" ? "js" : "cjs" : "js"
155
+ outputs.push({
156
+ dir,
157
+ format: f,
158
+ sourcemap: args.sourcemap,
159
+ preserveModules: true,
160
+ preserveModulesRoot: rootdir,
161
+ entryFileNames: `[name].${ext}`,
162
+ });
163
+ } else if (f === "iife" || f === "umd") {
164
+ outputs.push({
165
+ dir,
166
+ format: f,
167
+ name: args.name || "Bundle",
168
+ sourcemap: args.sourcemap,
169
+ entryFileNames: "[name].js",
170
+ });
171
+ }
182
172
  }
183
173
 
184
-
185
-
186
174
  for (const output of outputs) {
187
175
  await bundle.write(output);
188
176
  }
@@ -7,7 +7,7 @@ import bundler from './bundler.js';
7
7
  const build = async (args) => {
8
8
  /*
9
9
  args options:
10
- --format=both
10
+ --format=both or esm,cjs,iife,umd
11
11
  --bundle=true
12
12
  --minify=false
13
13
  --sourcemap=true
@@ -39,7 +39,7 @@ const build = async (args) => {
39
39
  }
40
40
 
41
41
  args = {
42
- format: args.format || 'both',
42
+ format: args.format ??= "modern",
43
43
  bundle: beBool('bundle'),
44
44
  minify: beBool('minify'),
45
45
  sourcemap: beBool('sourcemap'),
package/src/index.js CHANGED
@@ -1,4 +1,4 @@
1
- #!/usr/bin/env node
1
+ #!/usr/bin/env node
2
2
 
3
3
  import { Command } from "commander";
4
4
  import start from "./actions/start/index.js";
@@ -24,7 +24,7 @@ program
24
24
  program
25
25
  .command("build")
26
26
  .description("Build the project")
27
- .option("-f, --format <format>", "Output format (cjs, esm, both)", "both")
27
+ .option("-f, --format <format>", "Output format (modern, cjs, esm, umd, iife)", "modern")
28
28
  .option("-b, --bundle <bundle>", "Bundle the project", false)
29
29
  .option("-m, --minify <minify>", "Minify the output", false)
30
30
  .option("-s, --sourcemap <sourcemap>", "Generate sourcemaps", true)