bunchee 4.2.2 → 4.2.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
@@ -2,6 +2,7 @@
2
2
  var path = require('path');
3
3
  var arg = require('arg');
4
4
  var fs = require('fs/promises');
5
+ var require$$0 = require('tty');
5
6
  var bunchee = require('bunchee');
6
7
 
7
8
  function _interopDefault (e) { return e && e.__esModule ? e : { default: e }; }
@@ -9,6 +10,59 @@ function _interopDefault (e) { return e && e.__esModule ? e : { default: e }; }
9
10
  var path__default = /*#__PURE__*/_interopDefault(path);
10
11
  var arg__default = /*#__PURE__*/_interopDefault(arg);
11
12
  var fs__default = /*#__PURE__*/_interopDefault(fs);
13
+ var require$$0__default = /*#__PURE__*/_interopDefault(require$$0);
14
+
15
+ function getDefaultExportFromCjs (x) {
16
+ return x && x.__esModule && Object.prototype.hasOwnProperty.call(x, 'default') ? x['default'] : x;
17
+ }
18
+
19
+ var picocolors = {exports: {}};
20
+
21
+ let tty = require$$0__default.default;
22
+ let isColorSupported = !("NO_COLOR" in process.env || process.argv.includes("--no-color")) && ("FORCE_COLOR" in process.env || process.argv.includes("--color") || process.platform === "win32" || tty.isatty(1) && process.env.TERM !== "dumb" || "CI" in process.env);
23
+ let formatter = (open, close, replace = open)=>(input)=>{
24
+ let string = "" + input;
25
+ let index = string.indexOf(close, open.length);
26
+ return ~index ? open + replaceClose(string, close, replace, index) + close : open + string + close;
27
+ };
28
+ let replaceClose = (string, close, replace, index)=>{
29
+ let start = string.substring(0, index) + replace;
30
+ let end = string.substring(index + close.length);
31
+ let nextIndex = end.indexOf(close);
32
+ return ~nextIndex ? start + replaceClose(end, close, replace, nextIndex) : start + end;
33
+ };
34
+ let createColors = (enabled = isColorSupported)=>({
35
+ isColorSupported: enabled,
36
+ reset: enabled ? (s)=>`\x1b[0m${s}\x1b[0m` : String,
37
+ bold: enabled ? formatter("\x1b[1m", "\x1b[22m", "\x1b[22m\x1b[1m") : String,
38
+ dim: enabled ? formatter("\x1b[2m", "\x1b[22m", "\x1b[22m\x1b[2m") : String,
39
+ italic: enabled ? formatter("\x1b[3m", "\x1b[23m") : String,
40
+ underline: enabled ? formatter("\x1b[4m", "\x1b[24m") : String,
41
+ inverse: enabled ? formatter("\x1b[7m", "\x1b[27m") : String,
42
+ hidden: enabled ? formatter("\x1b[8m", "\x1b[28m") : String,
43
+ strikethrough: enabled ? formatter("\x1b[9m", "\x1b[29m") : String,
44
+ black: enabled ? formatter("\x1b[30m", "\x1b[39m") : String,
45
+ red: enabled ? formatter("\x1b[31m", "\x1b[39m") : String,
46
+ green: enabled ? formatter("\x1b[32m", "\x1b[39m") : String,
47
+ yellow: enabled ? formatter("\x1b[33m", "\x1b[39m") : String,
48
+ blue: enabled ? formatter("\x1b[34m", "\x1b[39m") : String,
49
+ magenta: enabled ? formatter("\x1b[35m", "\x1b[39m") : String,
50
+ cyan: enabled ? formatter("\x1b[36m", "\x1b[39m") : String,
51
+ white: enabled ? formatter("\x1b[37m", "\x1b[39m") : String,
52
+ gray: enabled ? formatter("\x1b[90m", "\x1b[39m") : String,
53
+ bgBlack: enabled ? formatter("\x1b[40m", "\x1b[49m") : String,
54
+ bgRed: enabled ? formatter("\x1b[41m", "\x1b[49m") : String,
55
+ bgGreen: enabled ? formatter("\x1b[42m", "\x1b[49m") : String,
56
+ bgYellow: enabled ? formatter("\x1b[43m", "\x1b[49m") : String,
57
+ bgBlue: enabled ? formatter("\x1b[44m", "\x1b[49m") : String,
58
+ bgMagenta: enabled ? formatter("\x1b[45m", "\x1b[49m") : String,
59
+ bgCyan: enabled ? formatter("\x1b[46m", "\x1b[49m") : String,
60
+ bgWhite: enabled ? formatter("\x1b[47m", "\x1b[49m") : String
61
+ });
62
+ picocolors.exports = createColors();
63
+ picocolors.exports.createColors = createColors;
64
+ var picocolorsExports = picocolors.exports;
65
+ var pc = /*@__PURE__*/ getDefaultExportFromCjs(picocolorsExports);
12
66
 
13
67
  const logger = {
14
68
  log (...arg) {
@@ -24,12 +78,18 @@ const logger = {
24
78
  console.log(' ✓', ...arg);
25
79
  }
26
80
  };
81
+ function paint(prefix, prefixColor, ...arg) {
82
+ if (pc.isColorSupported) {
83
+ console.log(' ' + pc[prefixColor](prefix), ...arg);
84
+ } else {
85
+ console.log(' ' + prefix, ...arg);
86
+ }
87
+ }
27
88
 
28
89
  function exit(err) {
29
90
  logger.error(err);
30
91
  process.exit(1);
31
92
  }
32
- const formatDuration = (duration)=>duration >= 1000 ? `${duration / 1000}s` : `${duration}ms`;
33
93
  async function hasPackageJson(cwd) {
34
94
  return await fileExists(path__default.default.resolve(cwd, 'package.json'));
35
95
  }
@@ -55,7 +115,7 @@ async function fileExists(filePath) {
55
115
  }
56
116
  }
57
117
 
58
- var version = "4.2.2";
118
+ var version = "4.2.3";
59
119
 
60
120
  const helpMessage = `
61
121
  Usage: bunchee [options]
@@ -166,11 +226,8 @@ async function run(args) {
166
226
  return help();
167
227
  }
168
228
  const entry = source ? path__default.default.resolve(cwd, source) : '';
169
- let timeStart = Date.now();
170
- let timeEnd;
171
229
  try {
172
230
  await bunchee.bundle(entry, bundleConfig);
173
- timeEnd = Date.now();
174
231
  } catch (err) {
175
232
  if (err.name === 'NOT_EXISTED') {
176
233
  help();
@@ -178,14 +235,14 @@ async function run(args) {
178
235
  }
179
236
  throw err;
180
237
  }
181
- const duration = timeEnd - timeStart;
182
238
  // watching mode
183
239
  if (watch) {
184
240
  logger.log(`Watching assets in ${cwd}...`);
185
241
  return;
186
242
  }
187
243
  // build mode
188
- logger.info(`Finished in ${formatDuration(duration)}`);
244
+ console.log();
245
+ paint('✓', 'green', `bunchee ${version} build completed`);
189
246
  await lintPackage(cwd);
190
247
  }
191
248
  async function main() {
package/dist/index.js CHANGED
@@ -12,6 +12,7 @@ var replace = require('@rollup/plugin-replace');
12
12
  var esmShim = require('@rollup/plugin-esm-shim');
13
13
  var preserveDirectives = require('rollup-preserve-directives');
14
14
  var pluginutils = require('@rollup/pluginutils');
15
+ var require$$0 = require('tty');
15
16
  var prettyBytes = require('pretty-bytes');
16
17
  var module$1 = require('module');
17
18
 
@@ -24,6 +25,7 @@ var json__default = /*#__PURE__*/_interopDefault(json);
24
25
  var replace__default = /*#__PURE__*/_interopDefault(replace);
25
26
  var esmShim__default = /*#__PURE__*/_interopDefault(esmShim);
26
27
  var preserveDirectives__default = /*#__PURE__*/_interopDefault(preserveDirectives);
28
+ var require$$0__default = /*#__PURE__*/_interopDefault(require$$0);
27
29
  var prettyBytes__default = /*#__PURE__*/_interopDefault(prettyBytes);
28
30
 
29
31
  function minifyCSS(content) {
@@ -200,6 +202,58 @@ const dtsExtensions = {
200
202
  mjs: '.d.mts'
201
203
  };
202
204
 
205
+ function getDefaultExportFromCjs (x) {
206
+ return x && x.__esModule && Object.prototype.hasOwnProperty.call(x, 'default') ? x['default'] : x;
207
+ }
208
+
209
+ var picocolors = {exports: {}};
210
+
211
+ let tty = require$$0__default.default;
212
+ let isColorSupported = !("NO_COLOR" in process.env || process.argv.includes("--no-color")) && ("FORCE_COLOR" in process.env || process.argv.includes("--color") || process.platform === "win32" || tty.isatty(1) && process.env.TERM !== "dumb" || "CI" in process.env);
213
+ let formatter = (open, close, replace = open)=>(input)=>{
214
+ let string = "" + input;
215
+ let index = string.indexOf(close, open.length);
216
+ return ~index ? open + replaceClose(string, close, replace, index) + close : open + string + close;
217
+ };
218
+ let replaceClose = (string, close, replace, index)=>{
219
+ let start = string.substring(0, index) + replace;
220
+ let end = string.substring(index + close.length);
221
+ let nextIndex = end.indexOf(close);
222
+ return ~nextIndex ? start + replaceClose(end, close, replace, nextIndex) : start + end;
223
+ };
224
+ let createColors = (enabled = isColorSupported)=>({
225
+ isColorSupported: enabled,
226
+ reset: enabled ? (s)=>`\x1b[0m${s}\x1b[0m` : String,
227
+ bold: enabled ? formatter("\x1b[1m", "\x1b[22m", "\x1b[22m\x1b[1m") : String,
228
+ dim: enabled ? formatter("\x1b[2m", "\x1b[22m", "\x1b[22m\x1b[2m") : String,
229
+ italic: enabled ? formatter("\x1b[3m", "\x1b[23m") : String,
230
+ underline: enabled ? formatter("\x1b[4m", "\x1b[24m") : String,
231
+ inverse: enabled ? formatter("\x1b[7m", "\x1b[27m") : String,
232
+ hidden: enabled ? formatter("\x1b[8m", "\x1b[28m") : String,
233
+ strikethrough: enabled ? formatter("\x1b[9m", "\x1b[29m") : String,
234
+ black: enabled ? formatter("\x1b[30m", "\x1b[39m") : String,
235
+ red: enabled ? formatter("\x1b[31m", "\x1b[39m") : String,
236
+ green: enabled ? formatter("\x1b[32m", "\x1b[39m") : String,
237
+ yellow: enabled ? formatter("\x1b[33m", "\x1b[39m") : String,
238
+ blue: enabled ? formatter("\x1b[34m", "\x1b[39m") : String,
239
+ magenta: enabled ? formatter("\x1b[35m", "\x1b[39m") : String,
240
+ cyan: enabled ? formatter("\x1b[36m", "\x1b[39m") : String,
241
+ white: enabled ? formatter("\x1b[37m", "\x1b[39m") : String,
242
+ gray: enabled ? formatter("\x1b[90m", "\x1b[39m") : String,
243
+ bgBlack: enabled ? formatter("\x1b[40m", "\x1b[49m") : String,
244
+ bgRed: enabled ? formatter("\x1b[41m", "\x1b[49m") : String,
245
+ bgGreen: enabled ? formatter("\x1b[42m", "\x1b[49m") : String,
246
+ bgYellow: enabled ? formatter("\x1b[43m", "\x1b[49m") : String,
247
+ bgBlue: enabled ? formatter("\x1b[44m", "\x1b[49m") : String,
248
+ bgMagenta: enabled ? formatter("\x1b[45m", "\x1b[49m") : String,
249
+ bgCyan: enabled ? formatter("\x1b[46m", "\x1b[49m") : String,
250
+ bgWhite: enabled ? formatter("\x1b[47m", "\x1b[49m") : String
251
+ });
252
+ picocolors.exports = createColors();
253
+ picocolors.exports.createColors = createColors;
254
+ var picocolorsExports = picocolors.exports;
255
+ var pc = /*@__PURE__*/ getDefaultExportFromCjs(picocolorsExports);
256
+
203
257
  const logger = {
204
258
  log (...arg) {
205
259
  console.log(' ', ...arg);
@@ -214,6 +268,13 @@ const logger = {
214
268
  console.log(' ✓', ...arg);
215
269
  }
216
270
  };
271
+ function paint(prefix, prefixColor, ...arg) {
272
+ if (pc.isColorSupported) {
273
+ console.log(' ' + pc[prefixColor](prefix), ...arg);
274
+ } else {
275
+ console.log(' ' + prefix, ...arg);
276
+ }
277
+ }
217
278
 
218
279
  function exit(err) {
219
280
  logger.error(err);
@@ -763,7 +824,9 @@ function getModuleLater(moduleMeta) {
763
824
  return moduleLayer;
764
825
  }
765
826
  // dependencyGraphMap: Map<subModuleId, Set<entryParentId>>
766
- function createSplitChunks(dependencyGraphMap) {
827
+ function createSplitChunks(dependencyGraphMap, entryFiles) {
828
+ // If there's existing chunk being splitted, and contains a layer { <id>: <chunkGroup> }
829
+ const splitChunksGroupMap = new Map();
767
830
  return function splitChunks(id, ctx) {
768
831
  const moduleInfo = ctx.getModuleInfo(id);
769
832
  if (!moduleInfo) {
@@ -785,7 +848,10 @@ function createSplitChunks(dependencyGraphMap) {
785
848
  if (!dependencyGraphMap.has(subId)) {
786
849
  dependencyGraphMap.set(subId, new Set());
787
850
  }
788
- dependencyGraphMap.get(subId).add(id);
851
+ dependencyGraphMap.get(subId).add([
852
+ id,
853
+ moduleLayer
854
+ ]);
789
855
  }
790
856
  }
791
857
  }
@@ -795,18 +861,34 @@ function createSplitChunks(dependencyGraphMap) {
795
861
  // when the module layer is same as entry layer, keep it as part of entry and don't split it;
796
862
  // when the module layer is different from entry layer, split the module into a separate chunk as a separate boundary.
797
863
  if (dependencyGraphMap.has(id)) {
798
- const parentModuleLayers = Array.from(dependencyGraphMap.get(id));
799
- if (parentModuleLayers.every((layer)=>layer === moduleLayer)) {
864
+ const parentModuleIds = Array.from(dependencyGraphMap.get(id));
865
+ const isImportFromOtherEntry = parentModuleIds.some(([id])=>{
866
+ // If other entry is dependency of this entry
867
+ if (entryFiles.has(id)) {
868
+ const entryModuleInfo = ctx.getModuleInfo(id);
869
+ const entryModuleLayer = getModuleLater(entryModuleInfo ? entryModuleInfo.meta : {});
870
+ return entryModuleLayer === moduleLayer;
871
+ }
872
+ return false;
873
+ });
874
+ if (isImportFromOtherEntry) return;
875
+ const isPartOfCurrentEntry = parentModuleIds.every(([, layer])=>layer === moduleLayer);
876
+ if (isPartOfCurrentEntry) {
877
+ if (splitChunksGroupMap.has(id)) {
878
+ return splitChunksGroupMap.get(id);
879
+ }
800
880
  return;
801
881
  }
802
882
  const chunkName = path__default.default.basename(id, path__default.default.extname(id));
803
- return `${chunkName}-${moduleLayer}`;
883
+ const chunkGroup = `${chunkName}-${moduleLayer}`;
884
+ splitChunksGroupMap.set(id, chunkGroup);
885
+ return chunkGroup;
804
886
  }
805
887
  }
806
888
  return;
807
889
  };
808
890
  }
809
- function buildOutputConfigs(pkg, exportPaths, options, exportCondition, cwd, { tsCompilerOptions }, pluginContext, dts) {
891
+ function buildOutputConfigs(entries, pkg, exportPaths, options, exportCondition, cwd, { tsCompilerOptions }, pluginContext, dts) {
810
892
  const { format } = options;
811
893
  // Add esm mark and interop helper if esm export is detected
812
894
  const useEsModuleMark = hasEsmExport(exportPaths, tsCompilerOptions);
@@ -820,6 +902,7 @@ function buildOutputConfigs(pkg, exportPaths, options, exportCondition, cwd, { t
820
902
  dir: dtsFile ? path.dirname(dtsFile) : dtsDir
821
903
  };
822
904
  const outputFile = dtsFile || file;
905
+ const entryFiles = new Set(Object.values(entries).map((entry)=>entry.source));
823
906
  return {
824
907
  name: pkg.name || name,
825
908
  ...dts ? dtsPathConfig : {
@@ -832,7 +915,7 @@ function buildOutputConfigs(pkg, exportPaths, options, exportCondition, cwd, { t
832
915
  freeze: false,
833
916
  strict: false,
834
917
  sourcemap: options.sourcemap,
835
- manualChunks: createSplitChunks(pluginContext.moduleDirectiveLayerMap),
918
+ manualChunks: createSplitChunks(pluginContext.moduleDirectiveLayerMap, entryFiles),
836
919
  chunkFileNames: '[name]-[hash].js',
837
920
  // By default in rollup, when creating multiple chunks, transitive imports of entry chunks
838
921
  // will be added as empty imports to the entry chunks. Disable to avoid imports hoist outside of boundaries
@@ -951,7 +1034,7 @@ async function buildConfig(entries, pkg, exportPaths, bundleConfig, exportCondit
951
1034
  // Generate dts job - single config
952
1035
  if (dts) {
953
1036
  const typeOutputExports = getExportTypeDist(exportCondition, cwd);
954
- outputConfigs = typeOutputExports.map((typeFile)=>buildOutputConfigs(pkg, exportPaths, {
1037
+ outputConfigs = typeOutputExports.map((typeFile)=>buildOutputConfigs(entries, pkg, exportPaths, {
955
1038
  ...bundleConfig,
956
1039
  format: 'es',
957
1040
  useTypescript,
@@ -960,7 +1043,7 @@ async function buildConfig(entries, pkg, exportPaths, bundleConfig, exportCondit
960
1043
  } else {
961
1044
  // multi outputs with specified format
962
1045
  outputConfigs = outputExports.map((exportDist)=>{
963
- return buildOutputConfigs(pkg, exportPaths, {
1046
+ return buildOutputConfigs(entries, pkg, exportPaths, {
964
1047
  ...bundleConfig,
965
1048
  file: exportDist.file,
966
1049
  format: exportDist.format,
@@ -972,7 +1055,7 @@ async function buildConfig(entries, pkg, exportPaths, bundleConfig, exportCondit
972
1055
  var _outputExports_;
973
1056
  const fallbackFormat = (_outputExports_ = outputExports[0]) == null ? void 0 : _outputExports_.format;
974
1057
  outputConfigs = [
975
- buildOutputConfigs(pkg, exportPaths, {
1058
+ buildOutputConfigs(entries, pkg, exportPaths, {
976
1059
  ...bundleConfig,
977
1060
  file,
978
1061
  format: bundleConfig.format || fallbackFormat,
@@ -1022,7 +1105,7 @@ function createChunkSizeCollector({ entries }) {
1022
1105
  const sourceFileName = chunk.facadeModuleId || '';
1023
1106
  const exportPath = reversedMapping.get(sourceFileName) || '.';
1024
1107
  addSize({
1025
- fileName: filePath.startsWith(cwd) ? path__default.default.relative(cwd, filePath) : filePath,
1108
+ fileName: path__default.default.isAbsolute(cwd) ? path__default.default.relative(cwd, filePath) : filePath,
1026
1109
  size,
1027
1110
  sourceFileName,
1028
1111
  exportPath
@@ -1046,9 +1129,10 @@ function logSizeStats(sizeCollector) {
1046
1129
  filesList.forEach((item)=>{
1047
1130
  const [filename, , size] = item;
1048
1131
  const padding = ' '.repeat(maxLength - filename.length);
1049
- const action = dtsExtensionRegex.test(filename) ? 'Typed' : 'Built';
1132
+ const isTypeFile = dtsExtensionRegex.test(filename);
1133
+ const action = isTypeFile ? '[types]' : '[chunk]';
1050
1134
  const prettiedSize = prettyBytes__default.default(size);
1051
- logger.info(`${action} ${filename}${padding} - ${prettiedSize}`);
1135
+ paint(' ' + action, isTypeFile ? 'blue' : 'white', `${filename}${padding} - ${prettiedSize}`);
1052
1136
  });
1053
1137
  });
1054
1138
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "bunchee",
3
- "version": "4.2.2",
3
+ "version": "4.2.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",
@@ -82,14 +82,15 @@
82
82
  "@swc/types": "^0.1.5",
83
83
  "@types/jest": "29.0.0",
84
84
  "@types/node": "^20.4.1",
85
+ "bunchee": "link:./",
85
86
  "husky": "^8.0.3",
86
87
  "jest": "29.0.1",
87
88
  "lint-staged": "^13.2.3",
89
+ "picocolors": "^1.0.0",
88
90
  "prettier": "^3.0.0",
89
91
  "react": "^18.2.0",
90
92
  "tsx": "^4.6.2",
91
- "typescript": "^5.3.2",
92
- "bunchee": "link:./"
93
+ "typescript": "^5.3.2"
93
94
  },
94
95
  "lint-staged": {
95
96
  "*.{ts,tsx,js,jsx,md,json,yml}": "prettier --write"