bunchee 4.3.0 → 4.3.1

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
@@ -135,6 +135,9 @@ The output format will based on the exports condition and also the file extensio
135
135
  - It's CommonJS for `require` and ESM for `import` based on the exports condition.
136
136
  - It's CommonJS for `.js` and ESM for `.mjs` based on the extension regardless the exports condition. Then for export condition like "node" you could choose the format with your extension.
137
137
 
138
+ > [!NOTE]
139
+ > All the `dependencies` and `peerDependencies` will be marked as external automatically and not included in the bundle. If you want to include them in the bundle, you can use the `--no-external` option.
140
+
138
141
  ## Usage
139
142
 
140
143
  ### File Conventions
@@ -277,13 +280,14 @@ bunchee ./src/index.js --runtime node --target es2019
277
280
 
278
281
  #### Specifying extra external dependencies
279
282
 
280
- If you want to mark specific dependencies as external and not include them in the bundle, use the `--external` option followed by a comma-separated list of dependency names:
283
+ By default, `bunchee` will mark all the `dependencies` and `peerDependencies` as externals so you don't need to pass them as CLI args.
284
+ But if there's any dependency that used but not in the dependency list and you want to mark as external, you can use the `--external` option to specify them.
281
285
 
282
286
  ```sh
283
- bunchee --external=dependency1,dependency2,dependency3
287
+ bunchee --external=dep1,dep2,dep3
284
288
  ```
285
289
 
286
- Replace `dependency1`, `dependency2`, and `dependency3` with the names of the dependencies you want to exclude from the bundle.
290
+ Replace `dep1`, `dep2`, and `dep3` with the names of the dependencies you want to exclude from the bundle.
287
291
 
288
292
  #### Bundling everything without external dependencies
289
293
 
package/dist/bin/cli.js CHANGED
@@ -150,7 +150,7 @@ async function fileExists(filePath) {
150
150
  const hasAvailableExtension = (filename)=>availableExtensions.includes(path__default.default.extname(filename).slice(1));
151
151
  const baseNameWithoutExtension = (filename)=>path__default.default.basename(filename, path__default.default.extname(filename));
152
152
 
153
- var version = "4.3.0";
153
+ var version = "4.3.1";
154
154
 
155
155
  function relativify(path) {
156
156
  return path.startsWith('.') ? path : `./${path}`;
@@ -267,9 +267,11 @@ async function prepare(cwd) {
267
267
  logger.error(`Source folder ${sourceFolder} does not exist. Cannot proceed to configure \`exports\` field.`);
268
268
  process.exit(1);
269
269
  }
270
+ let hasPackageJson = false;
270
271
  const pkgJsonPath = path__default.default.join(cwd, 'package.json');
271
272
  let pkgJson = {};
272
273
  if (fs__default.default.existsSync(pkgJsonPath)) {
274
+ hasPackageJson = true;
273
275
  const pkgJsonString = await fsp__default.default.readFile(pkgJsonPath, 'utf-8');
274
276
  pkgJson = JSON.parse(pkgJsonString);
275
277
  }
@@ -296,8 +298,8 @@ async function prepare(cwd) {
296
298
  logger.log(`Detected using TypeScript but tsconfig.json is missing, created a ${pc.blue('tsconfig.json')} for you.`);
297
299
  }
298
300
  }
299
- // Configure as ESM package by default if there's no `type` field
300
- if (!pkgJson.type) {
301
+ // Configure as ESM package by default if there's no package.json
302
+ if (!hasPackageJson) {
301
303
  pkgJson.type = 'module';
302
304
  }
303
305
  if (bins.size > 0) {
package/dist/index.js CHANGED
@@ -180,9 +180,11 @@ async function findSourceEntryFile(cwd, exportPath, exportTypeSuffix, ext) {
180
180
  return filename;
181
181
  }
182
182
  const subFolderIndexFilename = resolveSourceFile(cwd, `${exportPath}/index${exportTypeSuffix ? `.${exportTypeSuffix}` : ''}.${ext}`);
183
- if (await fileExists(subFolderIndexFilename)) {
184
- return subFolderIndexFilename;
185
- }
183
+ try {
184
+ if (await fileExists(subFolderIndexFilename)) {
185
+ return subFolderIndexFilename;
186
+ }
187
+ } catch {}
186
188
  return undefined;
187
189
  }
188
190
  // Map '.' -> './index.[ext]'
@@ -191,7 +193,7 @@ async function findSourceEntryFile(cwd, exportPath, exportTypeSuffix, ext) {
191
193
  async function getSourcePathFromExportPath(cwd, exportPath, exportType) {
192
194
  for (const ext of availableExtensions){
193
195
  // ignore package.json
194
- if (exportPath.endsWith('package.json')) return;
196
+ if (exportPath === '/package.json') return;
195
197
  if (exportPath === '.') exportPath = './index';
196
198
  // Find convention-based source file for specific export types
197
199
  // $binary represents `pkg.bin`
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "bunchee",
3
- "version": "4.3.0",
3
+ "version": "4.3.1",
4
4
  "description": "zero config bundler for js/ts/jsx libraries",
5
5
  "bin": "./dist/bin/cli.js",
6
6
  "main": "./dist/index.js",