bunchee 4.2.3 → 4.2.4

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/dist/bin/cli.js CHANGED
@@ -115,7 +115,7 @@ async function fileExists(filePath) {
115
115
  }
116
116
  }
117
117
 
118
- var version = "4.2.3";
118
+ var version = "4.2.4";
119
119
 
120
120
  const helpMessage = `
121
121
  Usage: bunchee [options]
package/dist/index.js CHANGED
@@ -370,13 +370,13 @@ function constructFullExportCondition(exportCondition, packageType) {
370
370
  [isEsmPkg ? 'import' : 'require']: exportCondition
371
371
  };
372
372
  } else {
373
- const keys = Object.keys(exportCondition);
373
+ const exportTypes = Object.keys(exportCondition);
374
374
  fullExportCond = {};
375
- keys.forEach((key)=>{
376
- const condition = exportCondition[key];
375
+ exportTypes.forEach((exportType)=>{
376
+ const condition = exportCondition[exportType];
377
377
  // Filter out nullable value
378
- if (key in exportCondition && condition) {
379
- fullExportCond[key] = condition;
378
+ if (condition) {
379
+ fullExportCond[exportType] = condition;
380
380
  }
381
381
  });
382
382
  }
@@ -384,22 +384,36 @@ function constructFullExportCondition(exportCondition, packageType) {
384
384
  }
385
385
  function joinRelativePath(...segments) {
386
386
  let result = path.join(...segments);
387
- // If the first segment starts with './', ensure the result does too.
388
- if (segments[0] === '.' && !result.startsWith('./')) {
387
+ // If the first segment starts with '.', ensure the result does too.
388
+ if (segments[0] === '.' && !result.startsWith('.')) {
389
389
  result = './' + result;
390
390
  }
391
391
  return result;
392
392
  }
393
- function findExport(name, exportCondition, paths, packageType) {
394
- // TODO: handle export condition based on package.type
393
+ function findExport(exportPath, exportCondition, paths, packageType) {
395
394
  if (isExportLike(exportCondition)) {
396
- paths[name] = constructFullExportCondition(exportCondition, packageType);
395
+ const fullExportCondition = constructFullExportCondition(exportCondition, packageType);
396
+ paths[exportPath] = {
397
+ ...paths[exportPath],
398
+ ...fullExportCondition
399
+ };
397
400
  return;
398
401
  }
399
402
  Object.keys(exportCondition).forEach((subpath)=>{
400
- const nextName = joinRelativePath(name, subpath);
401
- const nestedExportCondition = exportCondition[subpath];
402
- findExport(nextName, nestedExportCondition, paths, packageType);
403
+ if (subpath.startsWith('.')) {
404
+ // subpath is actual export path, ./a, ./b, ...
405
+ const nestedExportPath = joinRelativePath(exportPath, subpath);
406
+ const nestedExportCondition = exportCondition[subpath];
407
+ findExport(nestedExportPath, nestedExportCondition, paths, packageType);
408
+ } else {
409
+ // subpath is exportType, import, require, ...
410
+ const exportType = subpath;
411
+ const defaultPath = exportCondition[subpath].default;
412
+ const nestedExportCondition = {
413
+ [exportType]: defaultPath
414
+ };
415
+ findExport(exportPath, nestedExportCondition, paths, packageType);
416
+ }
403
417
  });
404
418
  }
405
419
  /**
@@ -409,11 +423,10 @@ function findExport(name, exportCondition, paths, packageType) {
409
423
  *
410
424
  * Input:
411
425
  * {
412
- * ".": {
413
- * "sub": {
414
- * "import": "./sub.js",
415
- * "require": "./sub.cjs",
416
- * "types": "./sub.d.ts
426
+ * "./sub": {
427
+ * "import": {
428
+ * "types": "./sub.js",
429
+ * "default": "./sub.cjs",
417
430
  * }
418
431
  * }
419
432
  * }
@@ -423,7 +436,7 @@ function findExport(name, exportCondition, paths, packageType) {
423
436
  * "./sub": {
424
437
  * "import": "./sub.js",
425
438
  * "require": "./sub.cjs",
426
- * "types": "./sub.d.ts,
439
+ * "types": "./sub.d.ts",
427
440
  * }
428
441
  * }
429
442
  *
@@ -571,8 +584,7 @@ function isCjsExportName(pkg, name, ext) {
571
584
  return !isESModule && [
572
585
  'require',
573
586
  'main',
574
- 'node',
575
- 'default'
587
+ 'node'
576
588
  ].includes(name) && ext !== 'mjs' || ext === 'cjs';
577
589
  }
578
590
  function getExportConditionDist(pkg, parsedExportCondition, cwd) {
@@ -603,7 +615,6 @@ function getExportConditionDist(pkg, parsedExportCondition, cwd) {
603
615
  });
604
616
  }
605
617
  if (dist.length === 0 && !pkg.bin) {
606
- console.error(`Doesn't fin any exports in ${pkg.name}, using default dist path dist/index.js`);
607
618
  const defaultFormat = isESModulePackage(pkg.type) ? 'esm' : 'cjs';
608
619
  dist.push({
609
620
  format: defaultFormat,
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "bunchee",
3
- "version": "4.2.3",
3
+ "version": "4.2.4",
4
4
  "description": "zero config bundler for js/ts/jsx libraries",
5
5
  "bin": "./dist/bin/cli.js",
6
6
  "main": "./dist/index.js",