bunchee 5.4.0 → 5.5.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.
Files changed (3) hide show
  1. package/dist/bin/cli.js +103 -52
  2. package/dist/index.js +130 -112
  3. package/package.json +7 -7
package/dist/bin/cli.js CHANGED
@@ -28,10 +28,19 @@ const availableExtensions = new Set([
28
28
  'cts',
29
29
  'mts'
30
30
  ]);
31
+ // You can find the list of runtime keys here:
32
+ // https://runtime-keys.proposal.wintercg.org/
31
33
  const runtimeExportConventions = new Set([
34
+ 'electron',
32
35
  'react-server',
33
36
  'react-native',
34
- 'edge-light'
37
+ 'edge-light',
38
+ 'node',
39
+ 'deno',
40
+ 'bun',
41
+ 'workerd',
42
+ // Browser only
43
+ 'browser'
35
44
  ]);
36
45
  const optimizeConventions = new Set([
37
46
  'development',
@@ -68,51 +77,58 @@ function getDefaultExportFromCjs (x) {
68
77
 
69
78
  var picocolors = {exports: {}};
70
79
 
71
- let tty = require$$0__default.default;
72
- 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);
73
- let formatter = (open, close, replace = open)=>(input)=>{
74
- let string = "" + input;
75
- let index = string.indexOf(close, open.length);
76
- return ~index ? open + replaceClose(string, close, replace, index) + close : open + string + close;
77
- };
78
- let replaceClose = (string, close, replace, index)=>{
79
- let start = string.substring(0, index) + replace;
80
- let end = string.substring(index + close.length);
81
- let nextIndex = end.indexOf(close);
82
- return ~nextIndex ? start + replaceClose(end, close, replace, nextIndex) : start + end;
83
- };
84
- let createColors = (enabled = isColorSupported)=>({
85
- isColorSupported: enabled,
86
- reset: enabled ? (s)=>`\x1b[0m${s}\x1b[0m` : String,
87
- bold: enabled ? formatter("\x1b[1m", "\x1b[22m", "\x1b[22m\x1b[1m") : String,
88
- dim: enabled ? formatter("\x1b[2m", "\x1b[22m", "\x1b[22m\x1b[2m") : String,
89
- italic: enabled ? formatter("\x1b[3m", "\x1b[23m") : String,
90
- underline: enabled ? formatter("\x1b[4m", "\x1b[24m") : String,
91
- inverse: enabled ? formatter("\x1b[7m", "\x1b[27m") : String,
92
- hidden: enabled ? formatter("\x1b[8m", "\x1b[28m") : String,
93
- strikethrough: enabled ? formatter("\x1b[9m", "\x1b[29m") : String,
94
- black: enabled ? formatter("\x1b[30m", "\x1b[39m") : String,
95
- red: enabled ? formatter("\x1b[31m", "\x1b[39m") : String,
96
- green: enabled ? formatter("\x1b[32m", "\x1b[39m") : String,
97
- yellow: enabled ? formatter("\x1b[33m", "\x1b[39m") : String,
98
- blue: enabled ? formatter("\x1b[34m", "\x1b[39m") : String,
99
- magenta: enabled ? formatter("\x1b[35m", "\x1b[39m") : String,
100
- cyan: enabled ? formatter("\x1b[36m", "\x1b[39m") : String,
101
- white: enabled ? formatter("\x1b[37m", "\x1b[39m") : String,
102
- gray: enabled ? formatter("\x1b[90m", "\x1b[39m") : String,
103
- bgBlack: enabled ? formatter("\x1b[40m", "\x1b[49m") : String,
104
- bgRed: enabled ? formatter("\x1b[41m", "\x1b[49m") : String,
105
- bgGreen: enabled ? formatter("\x1b[42m", "\x1b[49m") : String,
106
- bgYellow: enabled ? formatter("\x1b[43m", "\x1b[49m") : String,
107
- bgBlue: enabled ? formatter("\x1b[44m", "\x1b[49m") : String,
108
- bgMagenta: enabled ? formatter("\x1b[45m", "\x1b[49m") : String,
109
- bgCyan: enabled ? formatter("\x1b[46m", "\x1b[49m") : String,
110
- bgWhite: enabled ? formatter("\x1b[47m", "\x1b[49m") : String
111
- });
112
- picocolors.exports = createColors();
113
- picocolors.exports.createColors = createColors;
80
+ var hasRequiredPicocolors;
81
+
82
+ function requirePicocolors () {
83
+ if (hasRequiredPicocolors) return picocolors.exports;
84
+ hasRequiredPicocolors = 1;
85
+ let tty = require$$0__default.default;
86
+ 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);
87
+ let formatter = (open, close, replace = open)=>(input)=>{
88
+ let string = "" + input;
89
+ let index = string.indexOf(close, open.length);
90
+ return ~index ? open + replaceClose(string, close, replace, index) + close : open + string + close;
91
+ };
92
+ let replaceClose = (string, close, replace, index)=>{
93
+ let start = string.substring(0, index) + replace;
94
+ let end = string.substring(index + close.length);
95
+ let nextIndex = end.indexOf(close);
96
+ return ~nextIndex ? start + replaceClose(end, close, replace, nextIndex) : start + end;
97
+ };
98
+ let createColors = (enabled = isColorSupported)=>({
99
+ isColorSupported: enabled,
100
+ reset: enabled ? (s)=>`\x1b[0m${s}\x1b[0m` : String,
101
+ bold: enabled ? formatter("\x1b[1m", "\x1b[22m", "\x1b[22m\x1b[1m") : String,
102
+ dim: enabled ? formatter("\x1b[2m", "\x1b[22m", "\x1b[22m\x1b[2m") : String,
103
+ italic: enabled ? formatter("\x1b[3m", "\x1b[23m") : String,
104
+ underline: enabled ? formatter("\x1b[4m", "\x1b[24m") : String,
105
+ inverse: enabled ? formatter("\x1b[7m", "\x1b[27m") : String,
106
+ hidden: enabled ? formatter("\x1b[8m", "\x1b[28m") : String,
107
+ strikethrough: enabled ? formatter("\x1b[9m", "\x1b[29m") : String,
108
+ black: enabled ? formatter("\x1b[30m", "\x1b[39m") : String,
109
+ red: enabled ? formatter("\x1b[31m", "\x1b[39m") : String,
110
+ green: enabled ? formatter("\x1b[32m", "\x1b[39m") : String,
111
+ yellow: enabled ? formatter("\x1b[33m", "\x1b[39m") : String,
112
+ blue: enabled ? formatter("\x1b[34m", "\x1b[39m") : String,
113
+ magenta: enabled ? formatter("\x1b[35m", "\x1b[39m") : String,
114
+ cyan: enabled ? formatter("\x1b[36m", "\x1b[39m") : String,
115
+ white: enabled ? formatter("\x1b[37m", "\x1b[39m") : String,
116
+ gray: enabled ? formatter("\x1b[90m", "\x1b[39m") : String,
117
+ bgBlack: enabled ? formatter("\x1b[40m", "\x1b[49m") : String,
118
+ bgRed: enabled ? formatter("\x1b[41m", "\x1b[49m") : String,
119
+ bgGreen: enabled ? formatter("\x1b[42m", "\x1b[49m") : String,
120
+ bgYellow: enabled ? formatter("\x1b[43m", "\x1b[49m") : String,
121
+ bgBlue: enabled ? formatter("\x1b[44m", "\x1b[49m") : String,
122
+ bgMagenta: enabled ? formatter("\x1b[45m", "\x1b[49m") : String,
123
+ bgCyan: enabled ? formatter("\x1b[46m", "\x1b[49m") : String,
124
+ bgWhite: enabled ? formatter("\x1b[47m", "\x1b[49m") : String
125
+ });
126
+ picocolors.exports = createColors();
127
+ picocolors.exports.createColors = createColors;
128
+ return picocolors.exports;
129
+ }
114
130
 
115
- var picocolorsExports = picocolors.exports;
131
+ var picocolorsExports = /*@__PURE__*/ requirePicocolors();
116
132
  var pc = /*@__PURE__*/getDefaultExportFromCjs(picocolorsExports);
117
133
 
118
134
  const defaultColorFn = (text)=>text;
@@ -183,6 +199,9 @@ function isESModulePackage(packageType) {
183
199
  function isBinExportPath(exportPath) {
184
200
  return exportPath === BINARY_TAG || exportPath.startsWith(BINARY_TAG + '/');
185
201
  }
202
+ function isTypeFile(filename) {
203
+ return filename.endsWith('.d.ts') || filename.endsWith('.d.mts') || filename.endsWith('.d.cts');
204
+ }
186
205
 
187
206
  function collectExportPath(exportValue, exportKey, currentPath, exportTypes, exportToDist) {
188
207
  // End of searching, export value is file path.
@@ -329,6 +348,14 @@ function getExportTypeFromFile(filename, pkgType) {
329
348
  return exportType;
330
349
  }
331
350
 
351
+ function validateTypesFieldCondition(pair) {
352
+ const [outputPath, composedExportType] = pair;
353
+ const exportTypes = new Set(composedExportType.split('.'));
354
+ if (!exportTypes.has('types') && isTypeFile(outputPath)) {
355
+ return true;
356
+ }
357
+ return false;
358
+ }
332
359
  function lint$1(pkg) {
333
360
  const { name, main, exports } = pkg;
334
361
  const isESM = isESModulePackage(pkg.type);
@@ -355,7 +382,8 @@ function lint$1(pkg) {
355
382
  badEsmImportExport: {
356
383
  value: false,
357
384
  paths: []
358
- }
385
+ },
386
+ badTypesExport: []
359
387
  };
360
388
  // Validate ESM package
361
389
  if (isESM) {
@@ -368,7 +396,17 @@ function lint$1(pkg) {
368
396
  state.invalidExportsFieldType = true;
369
397
  } else {
370
398
  parsedExports.forEach((outputPairs)=>{
371
- for (const [outputPath, composedExportType] of outputPairs){
399
+ for (const outputPair of outputPairs){
400
+ const [outputPath, composedExportType] = outputPair;
401
+ if (validateTypesFieldCondition([
402
+ outputPath,
403
+ composedExportType
404
+ ])) {
405
+ state.badTypesExport.push([
406
+ outputPath,
407
+ composedExportType
408
+ ]);
409
+ }
372
410
  const exportTypes = new Set(composedExportType.split('.'));
373
411
  let requirePath = '';
374
412
  let importPath = '';
@@ -406,7 +444,17 @@ function lint$1(pkg) {
406
444
  state.invalidExportsFieldType = true;
407
445
  } else {
408
446
  parsedExports.forEach((outputPairs)=>{
409
- for (const [outputPath, composedExportType] of outputPairs){
447
+ for (const outputPair of outputPairs){
448
+ const [outputPath, composedExportType] = outputPair;
449
+ if (validateTypesFieldCondition([
450
+ outputPath,
451
+ composedExportType
452
+ ])) {
453
+ state.badTypesExport.push([
454
+ outputPath,
455
+ composedExportType
456
+ ]);
457
+ }
410
458
  const exportTypes = new Set(composedExportType.split('.'));
411
459
  let requirePath = '';
412
460
  let importPath = '';
@@ -468,9 +516,15 @@ function lint$1(pkg) {
468
516
  logger.warn(` ${p}`);
469
517
  });
470
518
  }
519
+ if (state.badTypesExport.length) {
520
+ state.badTypesExport.forEach(([outputPath, composedExportType])=>{
521
+ logger.error(`Bad export types field with ${composedExportType} in ${outputPath}, use "types" export condition for it`);
522
+ });
523
+ process.exit(1);
524
+ }
471
525
  }
472
526
 
473
- var version = "5.4.0";
527
+ var version = "5.5.1";
474
528
 
475
529
  function relativify(path) {
476
530
  return path.startsWith('.') ? path : `./${path}`;
@@ -842,9 +896,6 @@ async function prepare(cwd) {
842
896
  logger.info('Configured `exports` in package.json');
843
897
  }
844
898
 
845
- function isTypeFile(filename) {
846
- return filename.endsWith('.d.ts') || filename.endsWith('.d.mts') || filename.endsWith('.d.cts');
847
- }
848
899
  function normalizeExportName(exportName) {
849
900
  const isBinary = isBinExportPath(exportName);
850
901
  let result = exportName;
package/dist/index.js CHANGED
@@ -37,51 +37,58 @@ function getDefaultExportFromCjs (x) {
37
37
 
38
38
  var picocolors = {exports: {}};
39
39
 
40
- let tty = require$$0__default.default;
41
- 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);
42
- let formatter = (open, close, replace = open)=>(input)=>{
43
- let string = "" + input;
44
- let index = string.indexOf(close, open.length);
45
- return ~index ? open + replaceClose(string, close, replace, index) + close : open + string + close;
46
- };
47
- let replaceClose = (string, close, replace, index)=>{
48
- let start = string.substring(0, index) + replace;
49
- let end = string.substring(index + close.length);
50
- let nextIndex = end.indexOf(close);
51
- return ~nextIndex ? start + replaceClose(end, close, replace, nextIndex) : start + end;
52
- };
53
- let createColors = (enabled = isColorSupported)=>({
54
- isColorSupported: enabled,
55
- reset: enabled ? (s)=>`\x1b[0m${s}\x1b[0m` : String,
56
- bold: enabled ? formatter("\x1b[1m", "\x1b[22m", "\x1b[22m\x1b[1m") : String,
57
- dim: enabled ? formatter("\x1b[2m", "\x1b[22m", "\x1b[22m\x1b[2m") : String,
58
- italic: enabled ? formatter("\x1b[3m", "\x1b[23m") : String,
59
- underline: enabled ? formatter("\x1b[4m", "\x1b[24m") : String,
60
- inverse: enabled ? formatter("\x1b[7m", "\x1b[27m") : String,
61
- hidden: enabled ? formatter("\x1b[8m", "\x1b[28m") : String,
62
- strikethrough: enabled ? formatter("\x1b[9m", "\x1b[29m") : String,
63
- black: enabled ? formatter("\x1b[30m", "\x1b[39m") : String,
64
- red: enabled ? formatter("\x1b[31m", "\x1b[39m") : String,
65
- green: enabled ? formatter("\x1b[32m", "\x1b[39m") : String,
66
- yellow: enabled ? formatter("\x1b[33m", "\x1b[39m") : String,
67
- blue: enabled ? formatter("\x1b[34m", "\x1b[39m") : String,
68
- magenta: enabled ? formatter("\x1b[35m", "\x1b[39m") : String,
69
- cyan: enabled ? formatter("\x1b[36m", "\x1b[39m") : String,
70
- white: enabled ? formatter("\x1b[37m", "\x1b[39m") : String,
71
- gray: enabled ? formatter("\x1b[90m", "\x1b[39m") : String,
72
- bgBlack: enabled ? formatter("\x1b[40m", "\x1b[49m") : String,
73
- bgRed: enabled ? formatter("\x1b[41m", "\x1b[49m") : String,
74
- bgGreen: enabled ? formatter("\x1b[42m", "\x1b[49m") : String,
75
- bgYellow: enabled ? formatter("\x1b[43m", "\x1b[49m") : String,
76
- bgBlue: enabled ? formatter("\x1b[44m", "\x1b[49m") : String,
77
- bgMagenta: enabled ? formatter("\x1b[45m", "\x1b[49m") : String,
78
- bgCyan: enabled ? formatter("\x1b[46m", "\x1b[49m") : String,
79
- bgWhite: enabled ? formatter("\x1b[47m", "\x1b[49m") : String
80
- });
81
- picocolors.exports = createColors();
82
- picocolors.exports.createColors = createColors;
40
+ var hasRequiredPicocolors;
41
+
42
+ function requirePicocolors () {
43
+ if (hasRequiredPicocolors) return picocolors.exports;
44
+ hasRequiredPicocolors = 1;
45
+ let tty = require$$0__default.default;
46
+ 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);
47
+ let formatter = (open, close, replace = open)=>(input)=>{
48
+ let string = "" + input;
49
+ let index = string.indexOf(close, open.length);
50
+ return ~index ? open + replaceClose(string, close, replace, index) + close : open + string + close;
51
+ };
52
+ let replaceClose = (string, close, replace, index)=>{
53
+ let start = string.substring(0, index) + replace;
54
+ let end = string.substring(index + close.length);
55
+ let nextIndex = end.indexOf(close);
56
+ return ~nextIndex ? start + replaceClose(end, close, replace, nextIndex) : start + end;
57
+ };
58
+ let createColors = (enabled = isColorSupported)=>({
59
+ isColorSupported: enabled,
60
+ reset: enabled ? (s)=>`\x1b[0m${s}\x1b[0m` : String,
61
+ bold: enabled ? formatter("\x1b[1m", "\x1b[22m", "\x1b[22m\x1b[1m") : String,
62
+ dim: enabled ? formatter("\x1b[2m", "\x1b[22m", "\x1b[22m\x1b[2m") : String,
63
+ italic: enabled ? formatter("\x1b[3m", "\x1b[23m") : String,
64
+ underline: enabled ? formatter("\x1b[4m", "\x1b[24m") : String,
65
+ inverse: enabled ? formatter("\x1b[7m", "\x1b[27m") : String,
66
+ hidden: enabled ? formatter("\x1b[8m", "\x1b[28m") : String,
67
+ strikethrough: enabled ? formatter("\x1b[9m", "\x1b[29m") : String,
68
+ black: enabled ? formatter("\x1b[30m", "\x1b[39m") : String,
69
+ red: enabled ? formatter("\x1b[31m", "\x1b[39m") : String,
70
+ green: enabled ? formatter("\x1b[32m", "\x1b[39m") : String,
71
+ yellow: enabled ? formatter("\x1b[33m", "\x1b[39m") : String,
72
+ blue: enabled ? formatter("\x1b[34m", "\x1b[39m") : String,
73
+ magenta: enabled ? formatter("\x1b[35m", "\x1b[39m") : String,
74
+ cyan: enabled ? formatter("\x1b[36m", "\x1b[39m") : String,
75
+ white: enabled ? formatter("\x1b[37m", "\x1b[39m") : String,
76
+ gray: enabled ? formatter("\x1b[90m", "\x1b[39m") : String,
77
+ bgBlack: enabled ? formatter("\x1b[40m", "\x1b[49m") : String,
78
+ bgRed: enabled ? formatter("\x1b[41m", "\x1b[49m") : String,
79
+ bgGreen: enabled ? formatter("\x1b[42m", "\x1b[49m") : String,
80
+ bgYellow: enabled ? formatter("\x1b[43m", "\x1b[49m") : String,
81
+ bgBlue: enabled ? formatter("\x1b[44m", "\x1b[49m") : String,
82
+ bgMagenta: enabled ? formatter("\x1b[45m", "\x1b[49m") : String,
83
+ bgCyan: enabled ? formatter("\x1b[46m", "\x1b[49m") : String,
84
+ bgWhite: enabled ? formatter("\x1b[47m", "\x1b[49m") : String
85
+ });
86
+ picocolors.exports = createColors();
87
+ picocolors.exports.createColors = createColors;
88
+ return picocolors.exports;
89
+ }
83
90
 
84
- var picocolorsExports = picocolors.exports;
91
+ var picocolorsExports = /*@__PURE__*/ requirePicocolors();
85
92
  var pc = /*@__PURE__*/getDefaultExportFromCjs(picocolorsExports);
86
93
 
87
94
  const defaultColorFn = (text)=>text;
@@ -121,10 +128,19 @@ const nodeResolveExtensions = [
121
128
  '.node',
122
129
  '.jsx'
123
130
  ];
131
+ // You can find the list of runtime keys here:
132
+ // https://runtime-keys.proposal.wintercg.org/
124
133
  const runtimeExportConventions = new Set([
134
+ 'electron',
125
135
  'react-server',
126
136
  'react-native',
127
- 'edge-light'
137
+ 'edge-light',
138
+ 'node',
139
+ 'deno',
140
+ 'bun',
141
+ 'workerd',
142
+ // Browser only
143
+ 'browser'
128
144
  ]);
129
145
  const optimizeConventions = new Set([
130
146
  'development',
@@ -908,6 +924,39 @@ async function writeDefaultTsconfig(tsConfigPath) {
908
924
  logger.log(`Detected using TypeScript but tsconfig.json is missing, created a ${pc.blue('tsconfig.json')} for you.`);
909
925
  }
910
926
 
927
+ /**
928
+ * @return {Record<string, string>} env { 'process.env.<key>': '<value>' }
929
+ */ function getDefinedInlineVariables(envs, parsedExportCondition) {
930
+ if (!envs.includes('NODE_ENV')) {
931
+ envs.push('NODE_ENV');
932
+ }
933
+ const envVars = envs.reduce((acc, key)=>{
934
+ const value = process.env[key];
935
+ if (typeof value !== 'undefined') {
936
+ acc['process.env.' + key] = JSON.stringify(value);
937
+ }
938
+ return acc;
939
+ }, {});
940
+ const exportConditionNames = Object.keys(parsedExportCondition.export).reduce((acc, key)=>{
941
+ // key could be 'require' or 'import.development' etc.
942
+ const exportTypes = key.split('.');
943
+ for (const exportType of exportTypes){
944
+ acc.add(exportType);
945
+ }
946
+ return acc;
947
+ }, new Set());
948
+ // For development and production convention, we override the NODE_ENV value
949
+ if (exportConditionNames.has('development')) {
950
+ envVars['process.env.NODE_ENV'] = JSON.stringify('development');
951
+ } else if (exportConditionNames.has('production')) {
952
+ envVars['process.env.NODE_ENV'] = JSON.stringify('production');
953
+ }
954
+ if (exportConditionNames.has('edge-light')) {
955
+ envVars['EdgeRuntime'] = JSON.stringify('edge-runtime');
956
+ }
957
+ return envVars;
958
+ }
959
+
911
960
  const FILENAME_REGEX = /__filename/;
912
961
  const DIRNAME_REGEX = /__dirname/;
913
962
  // not char, or space before require(.resolve)?(
@@ -1217,60 +1266,6 @@ const prependShebang = (entry)=>({
1217
1266
  }
1218
1267
  });
1219
1268
 
1220
- /**
1221
- * @return {Record<string, string>} env { 'process.env.<key>': '<value>' }
1222
- */ function getDefinedInlineVariables(envs, parsedExportCondition) {
1223
- if (!envs.includes('NODE_ENV')) {
1224
- envs.push('NODE_ENV');
1225
- }
1226
- const envVars = envs.reduce((acc, key)=>{
1227
- const value = process.env[key];
1228
- if (typeof value !== 'undefined') {
1229
- acc['process.env.' + key] = JSON.stringify(value);
1230
- }
1231
- return acc;
1232
- }, {});
1233
- const exportConditionNames = Object.keys(parsedExportCondition.export).reduce((acc, key)=>{
1234
- // key could be 'require' or 'import.development' etc.
1235
- const exportTypes = key.split('.');
1236
- for (const exportType of exportTypes){
1237
- acc.add(exportType);
1238
- }
1239
- return acc;
1240
- }, new Set());
1241
- // For development and production convention, we override the NODE_ENV value
1242
- if (exportConditionNames.has('development')) {
1243
- envVars['process.env.NODE_ENV'] = JSON.stringify('development');
1244
- } else if (exportConditionNames.has('production')) {
1245
- envVars['process.env.NODE_ENV'] = JSON.stringify('production');
1246
- }
1247
- if (exportConditionNames.has('edge-light')) {
1248
- envVars['EdgeRuntime'] = JSON.stringify('edge-runtime');
1249
- }
1250
- return envVars;
1251
- }
1252
-
1253
- function getModuleLayer(moduleMeta) {
1254
- const directives = (moduleMeta.preserveDirectives || {
1255
- directives: []
1256
- }).directives.map((d)=>d.replace(/^use /, '')).filter((d)=>d !== 'strict');
1257
- const moduleLayer = directives[0];
1258
- return moduleLayer;
1259
- }
1260
- function getCustomModuleLayer(moduleId) {
1261
- const segments = path__default.default.basename(moduleId).split('.');
1262
- if (segments.length >= 2) {
1263
- const [layerSegment, ext] = segments.slice(-2);
1264
- const baseName = segments[0];
1265
- const match = layerSegment.match(/^(\w+)-runtime$/);
1266
- const layer = match && match[1];
1267
- if (availableExtensions.has(ext) && layer && layer.length > 0) {
1268
- return baseName + '-' + layer;
1269
- }
1270
- }
1271
- return undefined;
1272
- }
1273
-
1274
1269
  const swcMinifyOptions = {
1275
1270
  compress: {
1276
1271
  directives: false
@@ -1318,8 +1313,6 @@ async function createDtsPlugin(tsCompilerOptions, tsConfigPath, respectExternal,
1318
1313
  });
1319
1314
  return dtsPlugin;
1320
1315
  }
1321
- // Avoid create multiple dts plugins instance and parsing the same tsconfig multi times,
1322
- // This will avoid memory leak and performance issue.
1323
1316
  const memoizeDtsPluginByKey = memoizeByKey(createDtsPlugin);
1324
1317
  async function buildInputConfig(entry, bundleConfig, exportCondition, buildContext, dts) {
1325
1318
  var _bundleConfig_file, _bundleConfig_file1;
@@ -1461,6 +1454,27 @@ async function buildInputConfig(entry, bundleConfig, exportCondition, buildConte
1461
1454
  }
1462
1455
  };
1463
1456
  }
1457
+
1458
+ function getModuleLayer(moduleMeta) {
1459
+ const directives = (moduleMeta.preserveDirectives || {
1460
+ directives: []
1461
+ }).directives.map((d)=>d.replace(/^use /, '')).filter((d)=>d !== 'strict');
1462
+ const moduleLayer = directives[0];
1463
+ return moduleLayer;
1464
+ }
1465
+ function getCustomModuleLayer(moduleId) {
1466
+ const segments = path__default.default.basename(moduleId).split('.');
1467
+ if (segments.length >= 2) {
1468
+ const [layerSegment, ext] = segments.slice(-2);
1469
+ const baseName = segments[0];
1470
+ const match = layerSegment.match(/^(\w+)-runtime$/);
1471
+ const layer = match && match[1];
1472
+ if (availableExtensions.has(ext) && layer && layer.length > 0) {
1473
+ return baseName + '-' + layer;
1474
+ }
1475
+ }
1476
+ return undefined;
1477
+ }
1464
1478
  // dependencyGraphMap: Map<subModuleId, Set<entryParentId>>
1465
1479
  function createSplitChunks(dependencyGraphMap, entryFiles) {
1466
1480
  // If there's existing chunk being splitted, and contains a layer { <id>: <chunkGroup> }
@@ -1535,13 +1549,12 @@ function createSplitChunks(dependencyGraphMap, entryFiles) {
1535
1549
  return;
1536
1550
  };
1537
1551
  }
1538
- async function buildOutputConfigs(entry, bundleConfig, exportCondition, buildContext, dts) {
1552
+
1553
+ async function buildOutputConfigs(bundleConfig, exportCondition, buildContext, dts) {
1539
1554
  const { format } = bundleConfig;
1540
- const { entries, pkg, // exportPaths,
1541
- cwd, tsOptions: { tsCompilerOptions }, pluginContext } = buildContext;
1555
+ const { entries, pkg, cwd, tsOptions: { tsCompilerOptions }, pluginContext } = buildContext;
1542
1556
  // Add esm mark and interop helper if esm export is detected
1543
- const useEsModuleMark = tsCompilerOptions == null ? void 0 : tsCompilerOptions.esModuleInterop // hasEsmExport(exportPaths, tsCompilerOptions)
1544
- ;
1557
+ const useEsModuleMark = tsCompilerOptions == null ? void 0 : tsCompilerOptions.esModuleInterop;
1545
1558
  const absoluteOutputFile = path.resolve(cwd, bundleConfig.file);
1546
1559
  const isEsmPkg = isESModulePackage(pkg.type);
1547
1560
  const name = filePathWithoutExtension(absoluteOutputFile);
@@ -1551,7 +1564,6 @@ async function buildOutputConfigs(entry, bundleConfig, exportCondition, buildCon
1551
1564
  const jsDir = path.dirname(absoluteOutputFile);
1552
1565
  const outputFile = dts ? dtsFile : absoluteOutputFile;
1553
1566
  const entryFiles = new Set(Object.values(entries).map((entry)=>entry.source));
1554
- const inputOptions = await buildInputConfig(entry, bundleConfig, exportCondition, buildContext, dts);
1555
1567
  const outputOptions = {
1556
1568
  name: pkg.name || name,
1557
1569
  dir: dts ? typesDir : jsDir,
@@ -1573,11 +1585,9 @@ async function buildOutputConfigs(entry, bundleConfig, exportCondition, buildCon
1573
1585
  hoistTransitiveImports: false,
1574
1586
  entryFileNames: path.basename(outputFile)
1575
1587
  };
1576
- return {
1577
- input: inputOptions,
1578
- output: outputOptions
1579
- };
1588
+ return outputOptions;
1580
1589
  }
1590
+
1581
1591
  async function buildEntryConfig(bundleConfig, pluginContext, bundleEntryOptions) {
1582
1592
  const configs = [];
1583
1593
  const { entries } = pluginContext;
@@ -1587,6 +1597,14 @@ async function buildEntryConfig(bundleConfig, pluginContext, bundleEntryOptions)
1587
1597
  }
1588
1598
  return configs;
1589
1599
  }
1600
+ async function buildRollupConfigs(entry, bundleConfig, exportCondition, buildContext, dts) {
1601
+ const inputOptions = await buildInputConfig(entry, bundleConfig, exportCondition, buildContext, dts);
1602
+ const outputOptions = await buildOutputConfigs(bundleConfig, exportCondition, buildContext, dts);
1603
+ return {
1604
+ input: inputOptions,
1605
+ output: outputOptions
1606
+ };
1607
+ }
1590
1608
  async function buildConfig(bundleConfig, exportCondition, pluginContext, bundleEntryOptions) {
1591
1609
  const { file } = bundleConfig;
1592
1610
  const { pkg, cwd } = pluginContext;
@@ -1660,7 +1678,7 @@ async function buildConfig(bundleConfig, exportCondition, pluginContext, bundleE
1660
1678
  [bundleOption.exportCondition]: bundleOption.exportCondition === 'types' ? bundleOption.file : exportCondition.export[bundleOption.exportCondition]
1661
1679
  }
1662
1680
  };
1663
- return await buildOutputConfigs(entry, {
1681
+ return await buildRollupConfigs(entry, {
1664
1682
  ...bundleConfig,
1665
1683
  file: bundleOption.file,
1666
1684
  format: bundleOption.format
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "bunchee",
3
- "version": "5.4.0",
3
+ "version": "5.5.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",
@@ -36,10 +36,10 @@
36
36
  },
37
37
  "license": "MIT",
38
38
  "dependencies": {
39
- "@rollup/plugin-commonjs": "^26.0.1",
39
+ "@rollup/plugin-commonjs": "^28.0.0",
40
40
  "@rollup/plugin-json": "^6.1.0",
41
41
  "@rollup/plugin-node-resolve": "^15.2.3",
42
- "@rollup/plugin-replace": "^5.0.7",
42
+ "@rollup/plugin-replace": "^6.0.1",
43
43
  "@rollup/plugin-wasm": "^6.2.2",
44
44
  "@rollup/pluginutils": "^5.1.0",
45
45
  "@swc/core": "^1.7.14",
@@ -49,11 +49,11 @@
49
49
  "magic-string": "^0.30.11",
50
50
  "ora": "^8.0.1",
51
51
  "pretty-bytes": "^5.6.0",
52
- "rollup": "^4.19.2",
52
+ "rollup": "^4.24.0",
53
53
  "rollup-plugin-dts": "^6.1.1",
54
54
  "rollup-plugin-swc3": "^0.11.1",
55
- "rollup-preserve-directives": "^1.1.1",
56
- "tslib": "^2.6.2"
55
+ "rollup-preserve-directives": "^1.1.2",
56
+ "tslib": "^2.7.0"
57
57
  },
58
58
  "peerDependencies": {
59
59
  "typescript": "^4.1 || ^5.0"
@@ -82,7 +82,7 @@
82
82
  "picocolors": "^1.0.0",
83
83
  "prettier": "^3.0.0",
84
84
  "react": "^18.2.0",
85
- "typescript": "^5.5.2"
85
+ "typescript": "^5.6.2"
86
86
  },
87
87
  "lint-staged": {
88
88
  "*.{js,jsx,ts,tsx,md,json,yml,yaml}": "prettier --write"