bunchee 4.2.5 → 4.2.7

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
@@ -115,7 +115,7 @@ async function fileExists(filePath) {
115
115
  }
116
116
  }
117
117
 
118
- var version = "4.2.5";
118
+ var version = "4.2.7";
119
119
 
120
120
  const helpMessage = `
121
121
  Usage: bunchee [options]
package/dist/index.js CHANGED
@@ -43,7 +43,7 @@ const helpers = {
43
43
  function __insertCSS(code) {
44
44
  if (!code || typeof document == 'undefined') return
45
45
  let head = document.head || document.getElementsByTagName('head')[0]
46
- style = document.createElement('style')
46
+ let style = document.createElement('style')
47
47
  style.type = 'text/css'
48
48
  head.appendChild(style)
49
49
  ;style.styleSheet ? (style.styleSheet.cssText = code) : style.appendChild(document.createTextNode(code))
@@ -164,10 +164,7 @@ function prependDirectives() {
164
164
  return directiveCode + '\n' + code;
165
165
  }
166
166
  }
167
- return {
168
- code,
169
- map: null
170
- };
167
+ return null;
171
168
  }
172
169
  }
173
170
  };
@@ -209,8 +206,7 @@ const disabledWarnings = new Set([
209
206
  'PREFER_NAMED_EXPORTS',
210
207
  'UNRESOLVED_IMPORT',
211
208
  'THIS_IS_UNDEFINED',
212
- 'INVALID_ANNOTATION',
213
- 'SOURCEMAP_BROKEN'
209
+ 'INVALID_ANNOTATION'
214
210
  ]);
215
211
 
216
212
  function getDefaultExportFromCjs (x) {
@@ -374,11 +370,11 @@ function isExportLike(field) {
374
370
  ([key, value])=>typeof value === 'string' && !key.startsWith('.'));
375
371
  }
376
372
  function constructFullExportCondition(exportCondition, packageType) {
377
- const isEsmPkg = isESModulePackage(packageType);
378
373
  let fullExportCond;
379
374
  if (typeof exportCondition === 'string') {
375
+ const exportType = getExportTypeFromFile(exportCondition, packageType);
380
376
  fullExportCond = {
381
- [isEsmPkg ? 'import' : 'require']: exportCondition
377
+ [exportType]: exportCondition
382
378
  };
383
379
  } else {
384
380
  const exportTypes = Object.keys(exportCondition);
@@ -402,6 +398,8 @@ function joinRelativePath(...segments) {
402
398
  return result;
403
399
  }
404
400
  function findExport(exportPath, exportCondition, paths, packageType) {
401
+ // Skip `types` field, it cannot be the entry point
402
+ if (exportPath === 'types') return;
405
403
  if (isExportLike(exportCondition)) {
406
404
  const fullExportCondition = constructFullExportCondition(exportCondition, packageType);
407
405
  paths[exportPath] = {
@@ -640,6 +638,13 @@ function getTypeFilePath(entryFilePath, exportCondition, cwd) {
640
638
  const exportName = (exportCondition == null ? void 0 : exportCondition.name) || 'index';
641
639
  return entryFilePath ? name + '.d.ts' : path.resolve(firstDistPath ? path.dirname(firstDistPath) : path.join(cwd, 'dist'), (exportName === '.' ? 'index' : exportName) + '.d.ts');
642
640
  }
641
+ function getExportTypeFromFile(filename, pkgType) {
642
+ const isESModule = isESModulePackage(pkgType);
643
+ const isCjsExt = filename.endsWith('.cjs');
644
+ const isEsmExt = filename.endsWith('.mjs');
645
+ const exportType = isEsmExt ? 'import' : isCjsExt ? 'require' : isESModule ? 'import' : 'require';
646
+ return exportType;
647
+ }
643
648
 
644
649
  const swcMinifyOptions = {
645
650
  compress: true,
@@ -727,23 +732,6 @@ async function buildInputConfig(entry, entries, pkg, options, cwd, { tsConfigPat
727
732
  entries: reversedAlias
728
733
  })
729
734
  ];
730
- const baseResolvedTsOptions = {
731
- declaration: true,
732
- noEmit: false,
733
- noEmitOnError: true,
734
- emitDeclarationOnly: true,
735
- checkJs: false,
736
- declarationMap: false,
737
- skipLibCheck: true,
738
- preserveSymlinks: false,
739
- // disable incremental build
740
- incremental: false,
741
- // use default tsBuildInfoFile value
742
- tsBuildInfoFile: '.tsbuildinfo',
743
- target: 'esnext',
744
- module: 'esnext',
745
- jsx: tsCompilerOptions.jsx || 'react-jsx'
746
- };
747
735
  const typesPlugins = [
748
736
  ...commonPlugins,
749
737
  inlineCss({
@@ -751,16 +739,27 @@ async function buildInputConfig(entry, entries, pkg, options, cwd, { tsConfigPat
751
739
  })
752
740
  ];
753
741
  if (useTypescript) {
742
+ const overrideResolvedTsOptions = {
743
+ declaration: true,
744
+ noEmit: false,
745
+ noEmitOnError: true,
746
+ emitDeclarationOnly: true,
747
+ checkJs: false,
748
+ declarationMap: false,
749
+ skipLibCheck: true,
750
+ preserveSymlinks: false,
751
+ target: 'esnext',
752
+ module: 'esnext',
753
+ jsx: tsCompilerOptions.jsx || 'react-jsx'
754
+ };
754
755
  const mergedOptions = {
755
- ...baseResolvedTsOptions,
756
- ...tsCompilerOptions
756
+ ...tsCompilerOptions,
757
+ ...overrideResolvedTsOptions
757
758
  };
758
759
  // error TS5074: Option '--incremental' can only be specified using tsconfig, emitting to single
759
760
  // file or when option '--tsBuildInfoFile' is specified.
760
- if (!mergedOptions.incremental) {
761
- delete mergedOptions.incremental;
762
- delete mergedOptions.tsBuildInfoFile;
763
- }
761
+ delete mergedOptions.incremental;
762
+ delete mergedOptions.tsBuildInfoFile;
764
763
  const dtsPlugin = require('rollup-plugin-dts').default({
765
764
  tsconfig: undefined,
766
765
  compilerOptions: mergedOptions
@@ -999,12 +998,8 @@ async function buildEntryConfig(entries, pkg, exportPaths, bundleConfig, cwd, ts
999
998
  path.join('bin', key),
1000
999
  binaryExports[key]
1001
1000
  ]);
1002
- const isESModule = isESModulePackage(pkg.type);
1003
1001
  const binExportPaths = binPairs.reduce((acc, [binName, binDistPath])=>{
1004
- const ext = path.extname(binDistPath).slice(1);
1005
- const isCjsExt = ext === 'cjs';
1006
- const isEsmExt = ext === 'mjs';
1007
- const exportType = isEsmExt ? 'import' : isCjsExt ? 'require' : isESModule ? 'import' : 'require';
1002
+ const exportType = getExportTypeFromFile(binDistPath, pkg.type);
1008
1003
  acc[binName] = {
1009
1004
  [exportType]: binDistPath
1010
1005
  };
@@ -1179,7 +1174,6 @@ async function resolveTsConfig(cwd) {
1179
1174
  const tsconfigJSON = ts.readConfigFile(tsConfigPath, ts.sys.readFile).config;
1180
1175
  tsCompilerOptions = ts.parseJsonConfigFileContent(tsconfigJSON, ts.sys, basePath).options;
1181
1176
  } else {
1182
- tsConfigPath = undefined;
1183
1177
  return null;
1184
1178
  }
1185
1179
  return {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "bunchee",
3
- "version": "4.2.5",
3
+ "version": "4.2.7",
4
4
  "description": "zero config bundler for js/ts/jsx libraries",
5
5
  "bin": "./dist/bin/cli.js",
6
6
  "main": "./dist/index.js",
@@ -62,7 +62,7 @@
62
62
  "rollup": "^4.9.1",
63
63
  "rollup-plugin-dts": "^6.1.0",
64
64
  "rollup-plugin-swc3": "^0.11.0",
65
- "rollup-preserve-directives": "^1.1.0",
65
+ "rollup-preserve-directives": "^1.1.1",
66
66
  "tslib": "^2.6.2"
67
67
  },
68
68
  "peerDependencies": {