bunchee 4.3.2 → 4.3.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
@@ -14,7 +14,7 @@ var fs__default = /*#__PURE__*/_interopDefault(fs);
14
14
  var fsp__default = /*#__PURE__*/_interopDefault(fsp);
15
15
  var require$$0__default = /*#__PURE__*/_interopDefault(require$$0);
16
16
 
17
- const availableExtensions = [
17
+ const availableExtensions = new Set([
18
18
  'js',
19
19
  'cjs',
20
20
  'mjs',
@@ -23,19 +23,19 @@ const availableExtensions = [
23
23
  'tsx',
24
24
  'cts',
25
25
  'mts'
26
- ];
26
+ ]);
27
27
  const SRC = 'src';
28
28
  const dtsExtensionsMap = {
29
29
  js: 'd.ts',
30
30
  cjs: 'd.cts',
31
31
  mjs: 'd.mts'
32
32
  };
33
- const tsExtensions = [
33
+ const tsExtensions = new Set([
34
34
  'ts',
35
35
  'tsx',
36
36
  'cts',
37
37
  'mts'
38
- ];
38
+ ]);
39
39
 
40
40
  function getDefaultExportFromCjs (x) {
41
41
  return x && x.__esModule && Object.prototype.hasOwnProperty.call(x, 'default') ? x['default'] : x;
@@ -134,21 +134,27 @@ async function getPackageMeta(cwd) {
134
134
  }
135
135
  function isTypescriptFile(filename) {
136
136
  const ext = path__default.default.extname(filename).slice(1);
137
- return tsExtensions.includes(ext);
137
+ return tsExtensions.has(ext);
138
138
  }
139
139
  function fileExists(filePath) {
140
140
  return fs__default.default.existsSync(filePath);
141
141
  }
142
- const hasAvailableExtension = (filename)=>availableExtensions.includes(path__default.default.extname(filename).slice(1));
142
+ const hasAvailableExtension = (filename)=>availableExtensions.has(path__default.default.extname(filename).slice(1));
143
143
  const baseNameWithoutExtension = (filename)=>path__default.default.basename(filename, path__default.default.extname(filename));
144
144
 
145
- var version = "4.3.2";
145
+ var version = "4.3.3";
146
146
 
147
147
  function relativify(path) {
148
148
  return path.startsWith('.') ? path : `./${path}`;
149
149
  }
150
150
 
151
151
  const DIST = 'dist';
152
+ const DEFAULT_TS_CONFIG = {
153
+ compilerOptions: {
154
+ module: 'ESNext',
155
+ moduleResolution: 'bundler'
156
+ }
157
+ };
152
158
  // Output with posix style in package.json
153
159
  function getDistPath(...subPaths) {
154
160
  return `./${DIST}/${subPaths.join('/')}`;
@@ -193,18 +199,17 @@ async function collectSourceEntries(sourceFolderPath) {
193
199
  });
194
200
  for (const binDirent of binDirentList){
195
201
  if (binDirent.isFile()) {
196
- const binFile = path__default.default.join(sourceFolderPath, dirent.name, binDirent.name);
202
+ const binFileAbsolutePath = path__default.default.join(sourceFolderPath, dirent.name, binDirent.name);
197
203
  const binName = baseNameWithoutExtension(binDirent.name);
198
- if (fs__default.default.existsSync(binFile)) {
204
+ if (fs__default.default.existsSync(binFileAbsolutePath)) {
199
205
  bins.set(binName, binDirent.name);
200
206
  }
201
207
  }
202
208
  }
203
209
  } else {
204
210
  // Search folder/<index>.<ext> convention entries
205
- const extensions = availableExtensions;
206
- for (const extension of extensions){
207
- const indexFile = path__default.default.join(sourceFolderPath, dirent.name, `index.${extension}`);
211
+ for (const extension of availableExtensions){
212
+ const indexFile = path__default.default.join(dirent.name, `index.${extension}`);
208
213
  if (fs__default.default.existsSync(indexFile)) {
209
214
  exportsEntries.set(dirent.name, indexFile);
210
215
  break;
@@ -212,7 +217,7 @@ async function collectSourceEntries(sourceFolderPath) {
212
217
  }
213
218
  }
214
219
  } else if (dirent.isFile()) {
215
- const isAvailableExtension = availableExtensions.includes(path__default.default.extname(dirent.name).slice(1));
220
+ const isAvailableExtension = availableExtensions.has(path__default.default.extname(dirent.name).slice(1));
216
221
  if (isAvailableExtension) {
217
222
  const baseName = baseNameWithoutExtension(dirent.name);
218
223
  const isBinFile = baseName === 'bin';
@@ -277,18 +282,18 @@ async function prepare(cwd) {
277
282
  // Collect bins and exports entries
278
283
  const { bins, exportsEntries } = await collectSourceEntries(sourceFolder);
279
284
  const tsconfigPath = path__default.default.join(cwd, 'tsconfig.json');
280
- if (!fs__default.default.existsSync(tsconfigPath)) {
281
- const sourceFiles = [
282
- ...exportsEntries.values()
283
- ].concat([
284
- ...bins.values()
285
- ]);
286
- const hasTypeScriptFiles = sourceFiles.some((filename)=>isTypescriptFile(filename));
287
- if (hasTypeScriptFiles) {
288
- isUsingTs = true;
289
- await fsp__default.default.writeFile(tsconfigPath, '{}', 'utf-8');
290
- logger.log(`Detected using TypeScript but tsconfig.json is missing, created a ${pc.blue('tsconfig.json')} for you.`);
285
+ const sourceFiles = [
286
+ ...exportsEntries.values()
287
+ ].concat([
288
+ ...bins.values()
289
+ ]);
290
+ const hasTypeScriptFiles = sourceFiles.some((filename)=>isTypescriptFile(filename));
291
+ if (hasTypeScriptFiles) {
292
+ isUsingTs = true;
293
+ if (!fs__default.default.existsSync(tsconfigPath)) {
294
+ await fsp__default.default.writeFile(tsconfigPath, JSON.stringify(DEFAULT_TS_CONFIG, null, 2), 'utf-8');
291
295
  }
296
+ logger.log(`Detected using TypeScript but tsconfig.json is missing, created a ${pc.blue('tsconfig.json')} for you.`);
292
297
  }
293
298
  // Configure as ESM package by default if there's no package.json
294
299
  if (!hasPackageJson) {
@@ -330,10 +335,14 @@ async function prepare(cwd) {
330
335
  const isESM = pkgJson.type === 'module';
331
336
  const mainExport = pkgExports['.'];
332
337
  const mainCondition = isESM ? 'import' : 'require';
333
- pkgJson.main = isUsingTs ? mainExport[mainCondition].default : mainExport[mainCondition];
334
- pkgJson.module = isUsingTs ? mainExport.import.default : mainExport.import;
338
+ if (!pkgJson.main) {
339
+ pkgJson.main = isUsingTs ? mainExport[mainCondition].default : mainExport[mainCondition];
340
+ }
341
+ if (!pkgJson.module) {
342
+ pkgJson.module = isUsingTs ? mainExport.import.default : mainExport.import;
343
+ }
335
344
  if (isUsingTs) {
336
- pkgJson.types = isESM ? mainExport.import.types : mainExport.require.types;
345
+ pkgJson.types = mainExport[mainCondition].types;
337
346
  }
338
347
  }
339
348
  // Assign the properties by order: files, main, module, types, exports
package/dist/index.js CHANGED
@@ -30,7 +30,7 @@ var esmShim__default = /*#__PURE__*/_interopDefault(esmShim);
30
30
  var preserveDirectives__default = /*#__PURE__*/_interopDefault(preserveDirectives);
31
31
  var prettyBytes__default = /*#__PURE__*/_interopDefault(prettyBytes);
32
32
 
33
- const availableExtensions = [
33
+ const availableExtensions = new Set([
34
34
  'js',
35
35
  'cjs',
36
36
  'mjs',
@@ -39,7 +39,7 @@ const availableExtensions = [
39
39
  'tsx',
40
40
  'cts',
41
41
  'mts'
42
- ];
42
+ ]);
43
43
  const nodeResolveExtensions = [
44
44
  '.mjs',
45
45
  '.cjs',
@@ -48,11 +48,11 @@ const nodeResolveExtensions = [
48
48
  '.node',
49
49
  '.jsx'
50
50
  ];
51
- const availableExportConventions = [
51
+ const availableExportConventions = new Set([
52
52
  'react-server',
53
53
  'react-native',
54
54
  'edge-light'
55
- ];
55
+ ]);
56
56
  const availableESExtensionsRegex = /\.(m|c)?[jt]sx?$/;
57
57
  const SRC = 'src';
58
58
  const dtsExtensionsMap = {
@@ -191,7 +191,7 @@ async function getSourcePathFromExportPath(cwd, exportPath, exportType) {
191
191
  if (exportPath === '.') exportPath = './index';
192
192
  // Find convention-based source file for specific export types
193
193
  // $binary represents `pkg.bin`
194
- if (availableExportConventions.includes(exportType) && exportType !== '$binary') {
194
+ if (availableExportConventions.has(exportType) && exportType !== '$binary') {
195
195
  const filename = await findSourceEntryFile(cwd, exportPath, exportType, ext);
196
196
  if (filename) return filename;
197
197
  }
@@ -205,7 +205,7 @@ function filePathWithoutExtension(file) {
205
205
  return file ? file.replace(new RegExp(`${path__default.default.extname(file)}$`), '') : undefined;
206
206
  }
207
207
  const nonNullable = (n)=>Boolean(n);
208
- const hasAvailableExtension = (filename)=>availableExtensions.includes(path__default.default.extname(filename).slice(1));
208
+ const hasAvailableExtension = (filename)=>availableExtensions.has(path__default.default.extname(filename).slice(1));
209
209
  const hasCjsExtension = (filename)=>path__default.default.extname(filename) === '.cjs';
210
210
 
211
211
  let hasLoggedTsWarning = false;
@@ -1013,7 +1013,7 @@ async function buildEntryConfig(bundleConfig, pluginContext, dts) {
1013
1013
  ...exportCondRef
1014
1014
  };
1015
1015
  // Special cases of export type, only pass down the exportPaths for the type
1016
- if (availableExportConventions.includes(exportType)) {
1016
+ if (availableExportConventions.has(exportType)) {
1017
1017
  exportCondForType = {
1018
1018
  [entryExport]: exportCondRef[exportType]
1019
1019
  };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "bunchee",
3
- "version": "4.3.2",
3
+ "version": "4.3.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,12 +54,12 @@
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.99",
57
+ "@swc/core": "^1.3.102",
58
58
  "@swc/helpers": "^0.5.3",
59
59
  "arg": "^5.0.2",
60
60
  "pretty-bytes": "^5.6.0",
61
61
  "publint": "~0.2.7",
62
- "rollup": "^4.9.1",
62
+ "rollup": "^4.9.4",
63
63
  "rollup-plugin-dts": "^6.1.0",
64
64
  "rollup-plugin-swc3": "^0.11.0",
65
65
  "rollup-preserve-directives": "^1.1.1",