prepare-package 2.0.5 → 2.0.7

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
@@ -109,6 +109,7 @@ Uses esbuild to produce optimized builds in multiple module formats.
109
109
  | `build.platform` | `"neutral"` | esbuild platform |
110
110
  | `build.external` | `[]` | Packages to exclude from bundle |
111
111
  | `build.sourcemap` | `false` | Generate source maps |
112
+ | `build.cjs.footer` | `"module.exports=module.exports.default\|\|module.exports;"` | CJS footer — unwraps `export default` so `require()` returns the value directly |
112
113
  | `build.iife.globalName` | — | **Required** when `"iife"` is in formats. The global variable name (e.g., `window.MyLib`) |
113
114
  | `build.iife.fileName` | `"{name}.min.js"` | Output filename for IIFE build |
114
115
  | `build.iife.target` | `"es2015"` | esbuild target for IIFE build |
@@ -123,6 +124,19 @@ Uses esbuild to produce optimized builds in multiple module formats.
123
124
  #### Version replacement
124
125
  In bundle mode, all occurrences of `{version}` in `.js` source files are replaced with the version from `package.json` at build time via an esbuild plugin.
125
126
 
127
+ #### CJS default export
128
+ The CJS build automatically appends a footer that unwraps `export default` so `require('your-package')` returns the function/class directly — not `{ default: fn }`. This means both of these just work:
129
+
130
+ ```js
131
+ // ESM
132
+ import MyLib from 'your-package';
133
+
134
+ // CJS
135
+ const MyLib = require('your-package');
136
+ ```
137
+
138
+ To override the footer, set `build.cjs.footer` in your config.
139
+
126
140
  #### IIFE global export
127
141
  The IIFE build automatically unwraps the default export so `window[globalName]` is the class/function directly, not a `{ default }` wrapper.
128
142
 
package/dist/build.js CHANGED
@@ -66,6 +66,7 @@ async function build(options) {
66
66
 
67
67
  // CJS
68
68
  if (formats.includes('cjs')) {
69
+ const cjsConfig = buildConfig.cjs || {};
69
70
  builds.push({
70
71
  ...shared,
71
72
  outfile: path.join(outputPath, 'index.js'),
@@ -73,6 +74,8 @@ async function build(options) {
73
74
  platform,
74
75
  minify: false,
75
76
  target,
77
+ // Unwrap default export so require() returns the function/class directly
78
+ footer: { js: cjsConfig.footer || 'module.exports=module.exports.default||module.exports;' },
76
79
  });
77
80
  }
78
81
 
@@ -185,6 +188,7 @@ async function createWatchContexts(options) {
185
188
  }
186
189
 
187
190
  if (formats.includes('cjs')) {
191
+ const cjsConfig = buildConfig.cjs || {};
188
192
  builds.push({
189
193
  ...shared,
190
194
  outfile: path.join(outputPath, 'index.js'),
@@ -192,6 +196,8 @@ async function createWatchContexts(options) {
192
196
  platform,
193
197
  minify: false,
194
198
  target,
199
+ // Unwrap default export so require() returns the function/class directly
200
+ footer: { js: cjsConfig.footer || 'module.exports=module.exports.default||module.exports;' },
195
201
  });
196
202
  }
197
203
 
package/dist/index.js CHANGED
@@ -1,5 +1,5 @@
1
1
  const jetpack = require('fs-jetpack');
2
- const fetch = require('wonderful-fetch').default;
2
+ const fetch = require('wonderful-fetch');
3
3
  const path = require('path');
4
4
  const { default: chalk } = require('chalk');
5
5
  const logger = require('./logger');
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "prepare-package",
3
- "version": "2.0.5",
3
+ "version": "2.0.7",
4
4
  "description": "Prepare a Node.js package before being published",
5
5
  "main": "dist/index.js",
6
6
  "bin": {
@@ -50,7 +50,7 @@
50
50
  "chokidar": "^5.0.0",
51
51
  "esbuild": "^0.27.4",
52
52
  "fs-jetpack": "^5.1.0",
53
- "wonderful-fetch": "^2.0.1"
53
+ "wonderful-fetch": "^2.0.4"
54
54
  },
55
55
  "devDependencies": {
56
56
  "mocha": "^11.7.5"