bunchee 4.2.9 → 4.2.11

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
@@ -422,7 +422,7 @@ await bundle(path.resolve('./src/index.ts'), {
422
422
 
423
423
  #### Watch Mode
424
424
 
425
- Bunchee offers a convenient watch mode for rebuilding your library whenever changes are made to the source files. To enable this feature, use either -w or --watch.
425
+ Bunchee offers a convenient watch mode for rebuilding your library whenever changes are made to the source files. To enable this feature, use either `-w` or `--watch`.
426
426
 
427
427
  #### `target`
428
428
 
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.9";
118
+ var version = "4.2.11";
119
119
 
120
120
  const helpMessage = `
121
121
  Usage: bunchee [options]
package/dist/index.js CHANGED
@@ -64,7 +64,8 @@ const disabledWarnings = new Set([
64
64
  'PREFER_NAMED_EXPORTS',
65
65
  'UNRESOLVED_IMPORT',
66
66
  'THIS_IS_UNDEFINED',
67
- 'INVALID_ANNOTATION'
67
+ 'INVALID_ANNOTATION',
68
+ 'UNUSED_EXTERNAL_IMPORT'
68
69
  ]);
69
70
 
70
71
  function getDefaultExportFromCjs (x) {
@@ -222,8 +223,8 @@ function resolveTypescript(cwd) {
222
223
  m.paths = module$1.Module._nodeModulePaths(cwd);
223
224
  try {
224
225
  ts = m.require('typescript');
225
- } catch (_) {
226
- console.error(_);
226
+ } catch (e) {
227
+ console.error(e);
227
228
  if (!hasLoggedTsWarning) {
228
229
  hasLoggedTsWarning = true;
229
230
  exit('Could not load TypeScript compiler. Try to install `typescript` as dev dependency');
@@ -464,7 +465,7 @@ function findExport(exportPath, exportCondition, paths, packageType, currentPath
464
465
  } else {
465
466
  // subpath is exportType, import, require, ...
466
467
  const exportType = subpath;
467
- const defaultPath = exportCondition[subpath].default;
468
+ const defaultPath = typeof exportCondition[subpath] === 'object' ? exportCondition[subpath].default : exportCondition[subpath];
468
469
  const nestedExportCondition = {
469
470
  [exportType]: defaultPath
470
471
  };
@@ -726,22 +727,19 @@ function getBuildEnv(envs) {
726
727
  return envVars;
727
728
  }
728
729
  /**
729
- * return { '<pkg>/<export>': '<absolute source path> }
730
- */ function getEntriesAlias(entries) {
730
+ * return { '<absolute source path>': '<pkg>/<export>' }
731
+ */ function getReversedAlias(entries) {
731
732
  const alias = {};
732
733
  for (const [entryImportPath, exportCondition] of Object.entries(entries)){
733
- alias[entryImportPath] = exportCondition.source;
734
+ const exportType = entryImportPath.split('.')[1] // e.g. index.react-server, pick react-server
735
+ ;
736
+ if (!exportType) {
737
+ alias[exportCondition.source] = entryImportPath;
738
+ }
734
739
  }
735
740
  return alias;
736
741
  }
737
742
  async function buildInputConfig(entry, entries, pkg, options, cwd, { tsConfigPath, tsCompilerOptions }, pluginContext, dts) {
738
- const entriesAlias = getEntriesAlias(entries);
739
- const reversedAlias = {};
740
- for (const [key, value] of Object.entries(entriesAlias)){
741
- if (value !== entry) {
742
- reversedAlias[value] = key;
743
- }
744
- }
745
743
  const hasNoExternal = options.external === null;
746
744
  var _options_external;
747
745
  const externals = hasNoExternal ? [] : [
@@ -749,7 +747,8 @@ async function buildInputConfig(entry, entries, pkg, options, cwd, { tsConfigPat
749
747
  pkg.dependencies,
750
748
  pkg.peerDependenciesMeta
751
749
  ].filter((n)=>Boolean(n)).map((o)=>Object.keys(o)).reduce((a, b)=>a.concat(b), []).concat((_options_external = options.external) != null ? _options_external : []);
752
- for (const [exportImportPath, entryFilePath] of Object.entries(entriesAlias)){
750
+ for (const [exportImportPath, exportCondition] of Object.entries(entries)){
751
+ const entryFilePath = exportCondition.source;
753
752
  if (entryFilePath !== entry) {
754
753
  externals.push(exportImportPath);
755
754
  externals.push(entryFilePath);
@@ -786,7 +785,11 @@ async function buildInputConfig(entry, entries, pkg, options, cwd, { tsConfigPat
786
785
  const commonPlugins = [
787
786
  sizePlugin,
788
787
  aliasEntries({
789
- entries: reversedAlias
788
+ entries: {
789
+ ...pluginContext.entriesAlias,
790
+ // Do not alias current alias of package
791
+ [entry]: null
792
+ }
790
793
  })
791
794
  ];
792
795
  const typesPlugins = [
@@ -1339,9 +1342,11 @@ async function bundle(entryPath, { cwd: _cwd, ...options } = {}) {
1339
1342
  const sizeCollector = createChunkSizeCollector({
1340
1343
  entries
1341
1344
  });
1345
+ const entriesAlias = getReversedAlias(entries);
1342
1346
  const pluginContext = {
1343
1347
  sizeCollector,
1344
- moduleDirectiveLayerMap: new Map()
1348
+ moduleDirectiveLayerMap: new Map(),
1349
+ entriesAlias
1345
1350
  };
1346
1351
  const buildConfigs = await buildEntryConfig(entries, pkg, exportPaths, options, cwd, defaultTsOptions, pluginContext, false);
1347
1352
  const assetsJobs = buildConfigs.map((rollupConfig)=>bundleOrWatch(rollupConfig));
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "bunchee",
3
- "version": "4.2.9",
3
+ "version": "4.2.11",
4
4
  "description": "zero config bundler for js/ts/jsx libraries",
5
5
  "bin": "./dist/bin/cli.js",
6
6
  "main": "./dist/index.js",