bunchee 5.6.0 → 5.6.2

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
@@ -525,7 +525,7 @@ function lint$1(pkg) {
525
525
  }
526
526
  }
527
527
 
528
- var version = "5.6.0";
528
+ var version = "5.6.2";
529
529
 
530
530
  function relativify(path) {
531
531
  return path.startsWith('.') ? path : `./${path}`;
package/dist/index.js CHANGED
@@ -142,6 +142,67 @@ const runtimeExportConventions = new Set([
142
142
  // Browser only
143
143
  'browser'
144
144
  ]);
145
+ const runtimeExportConventionsFallback = new Map([
146
+ // ESM only runtime
147
+ [
148
+ 'workerd',
149
+ [
150
+ 'import',
151
+ 'default'
152
+ ]
153
+ ],
154
+ [
155
+ 'edge-light',
156
+ [
157
+ 'import',
158
+ 'default'
159
+ ]
160
+ ],
161
+ [
162
+ 'browser',
163
+ [
164
+ 'import',
165
+ 'default'
166
+ ]
167
+ ],
168
+ // it could be CJS or ESM
169
+ [
170
+ 'electron',
171
+ [
172
+ 'default'
173
+ ]
174
+ ],
175
+ [
176
+ 'react-server',
177
+ [
178
+ 'default'
179
+ ]
180
+ ],
181
+ [
182
+ 'react-native',
183
+ [
184
+ 'default'
185
+ ]
186
+ ],
187
+ [
188
+ 'node',
189
+ [
190
+ 'default'
191
+ ]
192
+ ],
193
+ [
194
+ 'deno',
195
+ [
196
+ 'default'
197
+ ]
198
+ ],
199
+ [
200
+ 'bun',
201
+ [
202
+ 'default'
203
+ ]
204
+ ]
205
+ ]);
145
206
  const optimizeConventions = new Set([
146
207
  'development',
147
208
  'production'
@@ -821,9 +882,9 @@ function createOutputState({ entries }) {
821
882
  return {
822
883
  name: 'collect-sizes',
823
884
  writeBundle (options, bundle) {
824
- const dir = options.dir || path.posix.dirname(options.file);
885
+ const dir = options.dir || path__default.default.dirname(options.file);
825
886
  Object.entries(bundle).forEach(([fileName, chunk])=>{
826
- const filePath = path.posix.join(dir, fileName);
887
+ const filePath = path__default.default.join(dir, fileName);
827
888
  if (chunk.type !== 'chunk') {
828
889
  return;
829
890
  }
@@ -834,7 +895,7 @@ function createOutputState({ entries }) {
834
895
  const sourceFileName = chunk.facadeModuleId || '';
835
896
  const exportPath = removeScope(reversedMapping.get(sourceFileName) || '.');
836
897
  addSize({
837
- fileName: path__default.default.isAbsolute(cwd) ? path.posix.relative(cwd, filePath) : filePath,
898
+ fileName: path__default.default.relative(cwd, filePath).replace(path__default.default.sep, '/'),
838
899
  size,
839
900
  sourceFileName,
840
901
  exportPath
@@ -960,7 +1021,7 @@ async function writeDefaultTsconfig(tsConfigPath) {
960
1021
  const FILENAME_REGEX = /__filename/;
961
1022
  const DIRNAME_REGEX = /__dirname/;
962
1023
  // not char, or space before require(.resolve)?(
963
- const GLOBAL_REQUIRE_REGEX = /[\W\s]require(\.resolve)?\(/;
1024
+ const GLOBAL_REQUIRE_REGEX = /(?:^|[^.\w'"`])\brequire(\.resolve)?\(\s*[\r\n]*(['"`])/;
964
1025
  const PolyfillComment = '/** rollup-private-do-not-use-esm-shim-polyfill */';
965
1026
  const createESMShim = ({ filename, dirname, globalRequire })=>{
966
1027
  const useNodeUrl = filename || dirname;
@@ -1153,7 +1214,17 @@ function findJsBundlePathCallback({ format, bundlePath, conditionNames }, specia
1153
1214
  const hasFormatCond = conditionNames.has('import') || conditionNames.has('require');
1154
1215
  const isMatchedFormat = hasFormatCond ? conditionNames.has(formatCond) : true;
1155
1216
  const isMatchedConditionWithFormat = conditionNames.has(specialCondition) || !conditionNames.has('default') && hasNoSpecialCondition(conditionNames);
1156
- return isMatchedConditionWithFormat && !isTypesCondName && hasBundle && isMatchedFormat;
1217
+ const match = isMatchedConditionWithFormat && !isTypesCondName && hasBundle && isMatchedFormat;
1218
+ if (!match) {
1219
+ const fallback = runtimeExportConventionsFallback.get(specialCondition);
1220
+ if (!fallback) {
1221
+ return false;
1222
+ } else {
1223
+ return fallback.some((name)=>conditionNames.has(name));
1224
+ }
1225
+ } else {
1226
+ return match;
1227
+ }
1157
1228
  }
1158
1229
  function findTypesFileCallback({ format, bundlePath, conditionNames }) {
1159
1230
  const hasCondition = bundlePath != null;
@@ -1235,10 +1306,11 @@ function prependDirectives() {
1235
1306
  handler (code, id) {
1236
1307
  var _moduleInfo_meta;
1237
1308
  const moduleInfo = this.getModuleInfo(id);
1238
- if (moduleInfo == null ? void 0 : (_moduleInfo_meta = moduleInfo.meta) == null ? void 0 : _moduleInfo_meta.preserveDirectives) {
1239
- const firstDirective = moduleInfo.meta.preserveDirectives.directives[0];
1309
+ const preserveDirectives = moduleInfo == null ? void 0 : (_moduleInfo_meta = moduleInfo.meta) == null ? void 0 : _moduleInfo_meta.preserveDirectives;
1310
+ if (preserveDirectives) {
1311
+ const firstDirective = preserveDirectives.directives[0];
1240
1312
  if (firstDirective) {
1241
- const directive = firstDirective.value;
1313
+ const directive = firstDirective;
1242
1314
  const directiveCode = `'${directive}';`;
1243
1315
  return directiveCode + '\n' + code;
1244
1316
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "bunchee",
3
- "version": "5.6.0",
3
+ "version": "5.6.2",
4
4
  "description": "zero config bundler for js/ts/jsx libraries",
5
5
  "bin": "./dist/bin/cli.js",
6
6
  "main": "./dist/index.js",
@@ -51,7 +51,7 @@
51
51
  "rollup": "^4.24.0",
52
52
  "rollup-plugin-dts": "^6.1.1",
53
53
  "rollup-plugin-swc3": "^0.11.1",
54
- "rollup-preserve-directives": "^1.1.2",
54
+ "rollup-preserve-directives": "^1.1.3",
55
55
  "tslib": "^2.7.0",
56
56
  "yargs": "^17.7.2"
57
57
  },