bunchee 4.4.2 → 4.4.3

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
@@ -161,7 +161,7 @@ const hasCjsExtension = (filename)=>path__default.default.extname(filename) ===
161
161
  const baseNameWithoutExtension = (filename)=>path__default.default.basename(filename, path__default.default.extname(filename));
162
162
  const isTestFile = (filename)=>/\.(test|spec)$/.test(baseNameWithoutExtension(filename));
163
163
 
164
- function getTypings(pkg) {
164
+ function getPackageTypings(pkg) {
165
165
  return pkg.types || pkg.typings;
166
166
  }
167
167
  // Reached the end of the export path
@@ -382,7 +382,7 @@ function findExport(exportPath, exportCondition, paths, packageType, currentPath
382
382
  const defaultMainExport = constructFullExportCondition({
383
383
  ...mainExportCondition,
384
384
  module: pkg.module,
385
- types: getTypings(pkg)
385
+ types: getPackageTypings(pkg)
386
386
  }, packageType);
387
387
  if (!isEsmPackage && ((_pathsMap_ = pathsMap['.']) == null ? void 0 : _pathsMap_['require'])) {
388
388
  // pathsMap's exports.require are prioritized.
@@ -553,7 +553,7 @@ function lint$1(pkg) {
553
553
  }
554
554
  }
555
555
 
556
- var version = "4.4.2";
556
+ var version = "4.4.3";
557
557
 
558
558
  function relativify(path) {
559
559
  return path.startsWith('.') ? path : `./${path}`;
@@ -888,7 +888,7 @@ async function run(args) {
888
888
  }
889
889
  // watching mode
890
890
  if (watch) {
891
- logger.log(`Watching assets in ${cwd}...`);
891
+ logger.log(`Watching project ${cwd}...`);
892
892
  return;
893
893
  }
894
894
  // build mode
package/dist/index.js CHANGED
@@ -4,6 +4,7 @@ var rollup = require('rollup');
4
4
  var fsp = require('fs/promises');
5
5
  var fs = require('fs');
6
6
  var path = require('path');
7
+ var perf_hooks = require('perf_hooks');
7
8
  var require$$0 = require('tty');
8
9
  var module$1 = require('module');
9
10
  var rimraf = require('rimraf');
@@ -461,7 +462,7 @@ function prependDirectives() {
461
462
  };
462
463
  }
463
464
 
464
- function getTypings(pkg) {
465
+ function getPackageTypings(pkg) {
465
466
  return pkg.types || pkg.typings;
466
467
  }
467
468
  // Reached the end of the export path
@@ -682,7 +683,7 @@ function findExport(exportPath, exportCondition, paths, packageType, currentPath
682
683
  const defaultMainExport = constructFullExportCondition({
683
684
  ...mainExportCondition,
684
685
  module: pkg.module,
685
- types: getTypings(pkg)
686
+ types: getPackageTypings(pkg)
686
687
  }, packageType);
687
688
  if (!isEsmPackage && ((_pathsMap_ = pathsMap['.']) == null ? void 0 : _pathsMap_['require'])) {
688
689
  // pathsMap's exports.require are prioritized.
@@ -712,7 +713,7 @@ function constructDefaultExportCondition(value, packageType) {
712
713
  const isEsmPackage = isESModulePackage(packageType);
713
714
  let exportCondition;
714
715
  if (typeof value === 'string') {
715
- const types = getTypings(value);
716
+ const types = getPackageTypings(value);
716
717
  exportCondition = {
717
718
  [isEsmPackage ? 'import' : 'require']: value,
718
719
  ...types && {
@@ -788,7 +789,7 @@ const swcMinifyOptions = {
788
789
  }
789
790
  };
790
791
  // return { 'process.env.<key>': '<value>' }
791
- function getBuildEnv(envs, parsedExportCondition) {
792
+ function getDefinedInlineVariables(envs, parsedExportCondition) {
792
793
  if (!envs.includes('NODE_ENV')) {
793
794
  envs.push('NODE_ENV');
794
795
  }
@@ -808,6 +809,9 @@ function getBuildEnv(envs, parsedExportCondition) {
808
809
  } else if (exportConditionNames.has('production')) {
809
810
  envVars['process.env.NODE_ENV'] = JSON.stringify('production');
810
811
  }
812
+ if (exportConditionNames.has('edge-light')) {
813
+ envVars['EdgeRuntime'] = JSON.stringify('edge-runtime');
814
+ }
811
815
  return envVars;
812
816
  }
813
817
  /**
@@ -842,7 +846,7 @@ async function buildInputConfig(entry, bundleConfig, exportCondition, buildConte
842
846
  externals.push(entryFilePath);
843
847
  }
844
848
  }
845
- const envValues = getBuildEnv(bundleConfig.env || [], exportCondition);
849
+ const inlineDefinedValues = getDefinedInlineVariables(bundleConfig.env || [], exportCondition);
846
850
  const { useTypeScript } = buildContext;
847
851
  const { runtime, target: jscTarget, minify: shouldMinify } = bundleConfig;
848
852
  const hasSpecifiedTsTarget = Boolean(tsCompilerOptions.target && tsConfigPath);
@@ -894,7 +898,7 @@ async function buildInputConfig(entry, bundleConfig, exportCondition, buildConte
894
898
  const incrementalOptions = enableIncrementalWithoutBuildInfo ? {
895
899
  incremental: false
896
900
  } : undefined;
897
- const compositeOptions = tsCompilerOptions.composite && enableIncrementalWithoutBuildInfo ? {
901
+ const compositeOptions = tsCompilerOptions.composite ? {
898
902
  composite: false
899
903
  } : undefined;
900
904
  const { options: overrideResolvedTsOptions } = await convertCompilerOptions(cwd, {
@@ -933,7 +937,7 @@ async function buildInputConfig(entry, bundleConfig, exportCondition, buildConte
933
937
  preserveDirectives__default.default(),
934
938
  prependDirectives(),
935
939
  replace__default.default({
936
- values: envValues,
940
+ values: inlineDefinedValues,
937
941
  preventAssignment: true
938
942
  }),
939
943
  pluginNodeResolve.nodeResolve({
@@ -1503,11 +1507,11 @@ async function bundle(cliEntryPath, { cwd: _cwd, ...options } = {}) {
1503
1507
  const bundleOrWatch = async (rollupConfig)=>{
1504
1508
  if (options.clean) {
1505
1509
  if (!isFromCli) {
1506
- await removeOutputDir(rollupConfig.output);
1510
+ await removeOutputDir(rollupConfig.output, cwd);
1507
1511
  }
1508
1512
  }
1509
1513
  if (options.watch) {
1510
- return Promise.resolve(runWatch(rollupConfig));
1514
+ return runWatch(rollupConfig);
1511
1515
  }
1512
1516
  return runBundle(rollupConfig);
1513
1517
  };
@@ -1556,12 +1560,15 @@ async function bundle(cliEntryPath, { cwd: _cwd, ...options } = {}) {
1556
1560
  const buildConfigs = await buildEntryConfig(options, buildContext, false);
1557
1561
  const assetsJobs = buildConfigs.map((rollupConfig)=>bundleOrWatch(rollupConfig));
1558
1562
  const typesJobs = hasTsConfig ? (await buildEntryConfig(options, buildContext, true)).map((rollupConfig)=>bundleOrWatch(rollupConfig)) : [];
1559
- const result = await Promise.all(assetsJobs.concat(typesJobs));
1563
+ const totalJobs = assetsJobs.concat(typesJobs);
1564
+ const result = await Promise.all(totalJobs);
1560
1565
  if (result.length === 0) {
1561
1566
  logger.warn('The "src" directory does not contain any entry files. ' + 'For proper usage, please refer to the following link: ' + 'https://github.com/huozhi/bunchee#usage');
1562
1567
  }
1563
1568
  if (!options.watch) {
1564
1569
  logOutputState(sizeCollector);
1570
+ } else {
1571
+ logWatcherBuildTime(result);
1565
1572
  }
1566
1573
  return result;
1567
1574
  }
@@ -1578,29 +1585,45 @@ function runWatch({ input, output }) {
1578
1585
  }
1579
1586
  ];
1580
1587
  const watcher = rollup.watch(watchOptions);
1581
- watcher.on('event', (event)=>{
1582
- switch(event.code){
1583
- case 'ERROR':
1584
- {
1585
- logError(event.error);
1586
- break;
1587
- }
1588
- case 'START':
1589
- {
1590
- break;
1591
- }
1592
- case 'END':
1593
- {
1594
- break;
1595
- }
1596
- default:
1597
- return;
1588
+ return watcher;
1589
+ }
1590
+ function logWatcherBuildTime(result) {
1591
+ let watcherCounter = 0;
1592
+ let startTime = 0;
1593
+ result.map((watcher)=>{
1594
+ function start() {
1595
+ if (startTime === 0) startTime = perf_hooks.performance.now();
1596
+ }
1597
+ function end() {
1598
+ watcherCounter++;
1599
+ if (watcherCounter === result.length) {
1600
+ logger.info(`Build in ${(perf_hooks.performance.now() - startTime).toFixed(2)}ms`);
1601
+ }
1598
1602
  }
1603
+ watcher.on('event', (event)=>{
1604
+ switch(event.code){
1605
+ case 'ERROR':
1606
+ {
1607
+ logError(event.error);
1608
+ break;
1609
+ }
1610
+ case 'START':
1611
+ {
1612
+ start();
1613
+ break;
1614
+ }
1615
+ case 'END':
1616
+ {
1617
+ end();
1618
+ break;
1619
+ }
1620
+ }
1621
+ });
1599
1622
  });
1600
- return watcher;
1601
1623
  }
1602
- async function removeOutputDir(output) {
1603
- if (output.dir) await removeDir(output.dir);
1624
+ async function removeOutputDir(output, cwd) {
1625
+ const dir = output.dir;
1626
+ if (dir && dir !== cwd) await removeDir(dir);
1604
1627
  }
1605
1628
  function runBundle({ input, output }) {
1606
1629
  return rollup.rollup(input).then((bundle)=>{
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "bunchee",
3
- "version": "4.4.2",
3
+ "version": "4.4.3",
4
4
  "description": "zero config bundler for js/ts/jsx libraries",
5
5
  "bin": "./dist/bin/cli.js",
6
6
  "main": "./dist/index.js",
@@ -54,7 +54,7 @@
54
54
  "@rollup/plugin-replace": "^5.0.5",
55
55
  "@rollup/plugin-wasm": "^6.2.2",
56
56
  "@rollup/pluginutils": "^5.1.0",
57
- "@swc/core": "^1.3.102",
57
+ "@swc/core": "^1.3.106",
58
58
  "@swc/helpers": "^0.5.3",
59
59
  "arg": "^5.0.2",
60
60
  "clean-css": "^5.3.3",
@@ -79,7 +79,7 @@
79
79
  },
80
80
  "devDependencies": {
81
81
  "@huozhi/testing-package": "1.0.0",
82
- "@swc/jest": "^0.2.29",
82
+ "@swc/jest": "^0.2.31",
83
83
  "@swc/types": "^0.1.5",
84
84
  "@types/clean-css": "^4.2.11",
85
85
  "@types/jest": "29.0.0",