bunchee 6.0.1 → 6.0.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
@@ -154,9 +154,8 @@ const logger = {
154
154
  }
155
155
  };
156
156
 
157
- const { sep } = require('path');
158
- function relativify(path) {
159
- return path.startsWith('.') ? path : `.${sep}${path}`;
157
+ function posixRelativify(path) {
158
+ return path.startsWith('.') ? path : `./${path}`;
160
159
  }
161
160
 
162
161
  function exit(err) {
@@ -217,7 +216,7 @@ function isTypeFile(filename) {
217
216
  function sourceFilenameToExportFullPath(filename) {
218
217
  const ext = path__default.default.extname(filename);
219
218
  const exportPath = filename.slice(0, -ext.length);
220
- return relativify(exportPath);
219
+ return posixRelativify(exportPath);
221
220
  }
222
221
  // If the file is matching the private module convention file export path.
223
222
  // './lib/_foo' -> true
@@ -227,6 +226,9 @@ function sourceFilenameToExportFullPath(filename) {
227
226
  function isPrivateExportPath(exportPath) {
228
227
  return /\/_/.test(exportPath);
229
228
  }
229
+ function normalizePath(filePath) {
230
+ return filePath.replace(/\\/g, '/');
231
+ }
230
232
 
231
233
  function collectExportPath(exportValue, exportKey, currentPath, exportTypes, exportToDist) {
232
234
  // End of searching, export value is file path.
@@ -376,10 +378,10 @@ function getExportTypeFromFile(filename, pkgType) {
376
378
  const matchFile = (matchingPattern, filePath)=>{
377
379
  return matchingPattern.some((pattern)=>{
378
380
  // pattern is always posix
379
- const normalizedPattern = path__default.default.posix.normalize(pattern);
381
+ const normalizedPattern = path.posix.normalize(pattern);
380
382
  const expandedPattern = normalizedPattern.endsWith('/') ? `${normalizedPattern}**` : `${normalizedPattern}/**`;
381
383
  const matcher = picomatch__default.default(expandedPattern);
382
- const normalizedFilePath = path__default.default.normalize(filePath.replace(/\\/g, '/'));
384
+ const normalizedFilePath = path.posix.normalize(filePath);
383
385
  return matcher(normalizedFilePath);
384
386
  });
385
387
  };
@@ -394,12 +396,12 @@ function validateTypesFieldCondition(pair) {
394
396
  }
395
397
  function validateFilesField(packageJson) {
396
398
  const state = {
397
- definedField: true,
398
399
  missingFiles: []
399
400
  };
400
- const filesField = packageJson.files || [];
401
+ const filesField = packageJson.files || [
402
+ '*'
403
+ ];
401
404
  const exportsField = packageJson.exports || {};
402
- state.definedField = !!packageJson.files;
403
405
  const resolveExportsPaths = (exports)=>{
404
406
  const paths = [];
405
407
  if (typeof exports === 'string') {
@@ -411,7 +413,7 @@ function validateFilesField(packageJson) {
411
413
  }
412
414
  return paths;
413
415
  };
414
- const exportedPaths = resolveExportsPaths(exportsField).map((p)=>path__default.default.normalize(p));
416
+ const exportedPaths = resolveExportsPaths(exportsField).map((p)=>normalizePath(path__default.default.normalize(p)));
415
417
  const commonFields = [
416
418
  'main',
417
419
  'module',
@@ -425,7 +427,7 @@ function validateFilesField(packageJson) {
425
427
  }
426
428
  state.missingFiles = exportedPaths.filter((exportPath)=>{
427
429
  // Special case for package.json
428
- if (exportPath === './package.json') {
430
+ if (exportPath === 'package.json') {
429
431
  return false;
430
432
  }
431
433
  return !matchFile(filesField, exportPath);
@@ -559,12 +561,8 @@ function lint$1(pkg) {
559
561
  const warningsCount = exportsState.badTypesExport.length + fieldState.missingFiles.length;
560
562
  if (warningsCount) {
561
563
  logger.warn(`Lint: ${warningsCount} issues found.`);
562
- } else {
563
- logger.info(`Lint: package.json is healthy.`);
564
564
  }
565
- if (!fieldState.definedField) {
566
- logger.warn('Missing files field in package.json');
567
- } else if (fieldState.missingFiles.length) {
565
+ if (fieldState.missingFiles.length) {
568
566
  logger.warn('Missing files in package.json');
569
567
  fieldState.missingFiles.forEach((p)=>{
570
568
  logger.warn(` ${p}`);
@@ -614,7 +612,7 @@ function lint$1(pkg) {
614
612
  }
615
613
  }
616
614
 
617
- var version = "6.0.1";
615
+ var version = "6.0.3";
618
616
 
619
617
  async function writeDefaultTsconfig(tsConfigPath) {
620
618
  await fs.promises.writeFile(tsConfigPath, JSON.stringify(DEFAULT_TS_CONFIG, null, 2), 'utf-8');
@@ -673,12 +671,12 @@ function normalizeExportPath(exportPath) {
673
671
  async function collectSourceEntriesByExportPath(sourceFolderPath, originalSubpath, bins, exportsEntries) {
674
672
  const isBinaryPath = isBinExportPath(originalSubpath);
675
673
  const subpath = originalSubpath.replace(BINARY_TAG, 'bin');
676
- const absoluteDirPath = path.join(sourceFolderPath, subpath);
677
- const dirName = path.dirname(subpath) // Get directory name regardless of file/directory
674
+ const absoluteDirPath = path__default.default.join(sourceFolderPath, subpath);
675
+ const dirName = path__default.default.dirname(subpath) // Get directory name regardless of file/directory
678
676
  ;
679
- const baseName = path.basename(subpath) // Get base name regardless of file/directory
677
+ const baseName = path__default.default.basename(subpath) // Get base name regardless of file/directory
680
678
  ;
681
- const dirPath = path.join(sourceFolderPath, dirName);
679
+ const dirPath = path__default.default.join(sourceFolderPath, dirName);
682
680
  // Match <name>{,/index}.{<ext>,<runtime>.<ext>}
683
681
  const globalPatterns = [
684
682
  `${baseName}.{${[
@@ -704,14 +702,14 @@ async function collectSourceEntriesByExportPath(sourceFolderPath, originalSubpat
704
702
  ignore: '**/_*'
705
703
  });
706
704
  for (const file of files){
707
- const ext = path.extname(file).slice(1);
705
+ const ext = path__default.default.extname(file).slice(1);
708
706
  if (!availableExtensions.has(ext) || isTestFile(file)) continue;
709
- const sourceFileAbsolutePath = path.join(dirPath, file);
710
- const exportPath = relativify(fs.existsSync(absoluteDirPath) && (await fsp__default.default.stat(absoluteDirPath)).isDirectory() ? subpath : originalSubpath);
707
+ const sourceFileAbsolutePath = path__default.default.join(dirPath, file);
708
+ const exportPath = posixRelativify(fs.existsSync(absoluteDirPath) && (await fsp__default.default.stat(absoluteDirPath)).isDirectory() ? subpath : originalSubpath);
711
709
  if (isBinaryPath) {
712
710
  bins.set(normalizeExportPath(originalSubpath), sourceFileAbsolutePath);
713
711
  } else {
714
- const parts = path.basename(file).split('.');
712
+ const parts = path__default.default.basename(file).split('.');
715
713
  const exportType = parts.length > 2 ? parts[1] : getExportTypeFromExportPath(exportPath);
716
714
  const specialExportPath = exportType !== 'index' && parts.length > 2 ? exportPath + '.' + exportType : exportPath // Adjust for direct file matches
717
715
  ;
@@ -757,12 +755,12 @@ async function collectSourceEntries(sourceFolderPath) {
757
755
  });
758
756
  for (const file of binMatches){
759
757
  // convert relative path to export path
760
- const exportPath = sourceFilenameToExportFullPath(file);
758
+ const exportPath = sourceFilenameToExportFullPath(normalizePath(file));
761
759
  const binExportPath = exportPath.replace(/^\.[\//]bin/, BINARY_TAG);
762
760
  await collectSourceEntriesByExportPath(sourceFolderPath, binExportPath, bins, exportsEntries);
763
761
  }
764
762
  for (const file of srcMatches){
765
- const binExportPath = file.replace(/^bin/, BINARY_TAG)// Remove index.<ext> to [^index].<ext> to build the export path
763
+ const binExportPath = normalizePath(file).replace(/^bin/, BINARY_TAG)// Remove index.<ext> to [^index].<ext> to build the export path
766
764
  .replace(/(\/index)?\.[^/]+$/, '');
767
765
  await collectSourceEntriesByExportPath(sourceFolderPath, binExportPath, bins, exportsEntries);
768
766
  }
@@ -774,7 +772,7 @@ async function collectSourceEntries(sourceFolderPath) {
774
772
 
775
773
  // Output with posix style in package.json
776
774
  function getDistPath(...subPaths) {
777
- return relativify(path.posix.join(DIST, ...subPaths));
775
+ return posixRelativify(path.posix.join(DIST, ...subPaths));
778
776
  }
779
777
  function stripeBinaryTag(exportName) {
780
778
  // Add \ to decode leading $
@@ -782,7 +780,7 @@ function stripeBinaryTag(exportName) {
782
780
  }
783
781
  const normalizeBaseNameToExportName = (name)=>{
784
782
  const baseName = stripeBinaryTag(name);
785
- return /^\.\/index(\.|$)/.test(baseName) ? '.' : relativify(baseName);
783
+ return /^\.\/index(\.|$)/.test(baseName) ? '.' : posixRelativify(baseName);
786
784
  };
787
785
  function createExportCondition(exportName, sourceFile, moduleType) {
788
786
  const isTsSourceFile = isTypescriptFile(sourceFile);
package/dist/index.js CHANGED
@@ -242,9 +242,8 @@ const DEFAULT_TS_CONFIG = {
242
242
  };
243
243
  const BINARY_TAG = '$binary';
244
244
 
245
- const { sep } = require('path');
246
- function relativify(path) {
247
- return path.startsWith('.') ? path : `.${sep}${path}`;
245
+ function posixRelativify(path) {
246
+ return path.startsWith('.') ? path : `./${path}`;
248
247
  }
249
248
 
250
249
  function exit(err) {
@@ -376,7 +375,10 @@ function isBinExportPath(exportPath) {
376
375
  function sourceFilenameToExportFullPath(filename) {
377
376
  const ext = path__default.default.extname(filename);
378
377
  const exportPath = filename.slice(0, -ext.length);
379
- return relativify(exportPath);
378
+ return posixRelativify(exportPath);
379
+ }
380
+ function normalizePath(filePath) {
381
+ return filePath.replace(/\\/g, '/');
380
382
  }
381
383
 
382
384
  function collectExportPath(exportValue, exportKey, currentPath, exportTypes, exportToDist) {
@@ -571,7 +573,7 @@ function getExportFileTypePath(absoluteJsBundlePath) {
571
573
  const baseName = baseNameWithoutExtension(absoluteJsBundlePath);
572
574
  const ext = path.extname(absoluteJsBundlePath).slice(1);
573
575
  const typeExtension = dtsExtensionsMap[ext];
574
- return path.join(dirName, baseName + '.' + typeExtension);
576
+ return normalizePath(path.join(dirName, baseName + '.' + typeExtension));
575
577
  }
576
578
  function getExportTypeFromFile(filename, pkgType) {
577
579
  const isESModule = isESModulePackage(pkgType);
@@ -594,7 +596,7 @@ async function collectEntriesFromParsedExports(cwd, parsedExportsInfo, pkg, sour
594
596
  };
595
597
  }
596
598
  // Find source files
597
- const { bins, exportsEntries } = await collectSourceEntriesFromExportPaths(path.join(cwd, SRC), parsedExportsInfo, pkg);
599
+ const { bins, exportsEntries } = await collectSourceEntriesFromExportPaths(path__default.default.join(cwd, SRC), parsedExportsInfo, pkg);
598
600
  // A mapping between each export path and its related special export conditions,
599
601
  // excluding the 'default' export condition.
600
602
  // { './index' => Set('development', 'edge-light') }
@@ -743,12 +745,12 @@ function stripSpecialCondition(exportPath) {
743
745
  async function collectSourceEntriesByExportPath(sourceFolderPath, originalSubpath, bins, exportsEntries) {
744
746
  const isBinaryPath = isBinExportPath(originalSubpath);
745
747
  const subpath = originalSubpath.replace(BINARY_TAG, 'bin');
746
- const absoluteDirPath = path.join(sourceFolderPath, subpath);
747
- const dirName = path.dirname(subpath) // Get directory name regardless of file/directory
748
+ const absoluteDirPath = path__default.default.join(sourceFolderPath, subpath);
749
+ const dirName = path__default.default.dirname(subpath) // Get directory name regardless of file/directory
748
750
  ;
749
- const baseName = path.basename(subpath) // Get base name regardless of file/directory
751
+ const baseName = path__default.default.basename(subpath) // Get base name regardless of file/directory
750
752
  ;
751
- const dirPath = path.join(sourceFolderPath, dirName);
753
+ const dirPath = path__default.default.join(sourceFolderPath, dirName);
752
754
  // Match <name>{,/index}.{<ext>,<runtime>.<ext>}
753
755
  const globalPatterns = [
754
756
  `${baseName}.{${[
@@ -774,14 +776,14 @@ async function collectSourceEntriesByExportPath(sourceFolderPath, originalSubpat
774
776
  ignore: '**/_*'
775
777
  });
776
778
  for (const file of files){
777
- const ext = path.extname(file).slice(1);
779
+ const ext = path__default.default.extname(file).slice(1);
778
780
  if (!availableExtensions.has(ext) || isTestFile(file)) continue;
779
- const sourceFileAbsolutePath = path.join(dirPath, file);
780
- const exportPath = relativify(fs.existsSync(absoluteDirPath) && (await fsp__default.default.stat(absoluteDirPath)).isDirectory() ? subpath : originalSubpath);
781
+ const sourceFileAbsolutePath = path__default.default.join(dirPath, file);
782
+ const exportPath = posixRelativify(fs.existsSync(absoluteDirPath) && (await fsp__default.default.stat(absoluteDirPath)).isDirectory() ? subpath : originalSubpath);
781
783
  if (isBinaryPath) {
782
784
  bins.set(normalizeExportPath(originalSubpath), sourceFileAbsolutePath);
783
785
  } else {
784
- const parts = path.basename(file).split('.');
786
+ const parts = path__default.default.basename(file).split('.');
785
787
  const exportType = parts.length > 2 ? parts[1] : getExportTypeFromExportPath(exportPath);
786
788
  const specialExportPath = exportType !== 'index' && parts.length > 2 ? exportPath + '.' + exportType : exportPath // Adjust for direct file matches
787
789
  ;
@@ -841,7 +843,7 @@ async function collectSourceEntriesByExportPath(sourceFolderPath, originalSubpat
841
843
  nodir: true
842
844
  });
843
845
  for (const file of privateFiles){
844
- const sourceFileAbsolutePath = path.join(sourceFolderPath, file);
846
+ const sourceFileAbsolutePath = path__default.default.join(sourceFolderPath, file);
845
847
  const exportPath = sourceFilenameToExportFullPath(file);
846
848
  const isEsmPkg = isESModulePackage(pkg.type);
847
849
  // const specialItems: [string, string][] = []
@@ -855,11 +857,11 @@ async function collectSourceEntriesByExportPath(sourceFolderPath, originalSubpat
855
857
  // e.g. ./_utils.ts -> ./dist/_utils.js
856
858
  const privateExportInfo = [
857
859
  [
858
- relativify(path.join('./dist', exportPath + (isEsmPkg ? '.js' : '.mjs'))),
860
+ posixRelativify(path.posix.join('./dist', exportPath + (isEsmPkg ? '.js' : '.mjs'))),
859
861
  condPart + 'import'
860
862
  ],
861
863
  [
862
- relativify(path.join('./dist', exportPath + (isEsmPkg ? '.cjs' : '.js'))),
864
+ posixRelativify(path.posix.join('./dist', exportPath + (isEsmPkg ? '.cjs' : '.js'))),
863
865
  condPart + 'require'
864
866
  ]
865
867
  ];
@@ -930,9 +932,9 @@ function createOutputState({ entries }) {
930
932
  const sourceFileName = chunk.facadeModuleId || '';
931
933
  const exportPath = removeScope(reversedMapping.get(sourceFileName) || '.');
932
934
  addSize({
933
- fileName: path__default.default.relative(cwd, filePath).replace(path__default.default.sep, '/'),
935
+ fileName: normalizePath(path__default.default.relative(cwd, filePath)),
934
936
  size,
935
- sourceFileName,
937
+ sourceFileName: normalizePath(sourceFileName),
936
938
  exportPath
937
939
  });
938
940
  });
@@ -1320,7 +1322,7 @@ function aliasEntries({ entry: sourceFilePath, conditionNames, entries, format,
1320
1322
  const absoluteBundlePath = path.posix.resolve(cwd, srcBundle);
1321
1323
  const absoluteImportBundlePath = path.posix.resolve(cwd, resolvedModuleBundle);
1322
1324
  const filePathBase = path.posix.relative(path.posix.dirname(absoluteBundlePath), absoluteImportBundlePath);
1323
- const relativePath = relativify(filePathBase);
1325
+ const relativePath = posixRelativify(normalizePath(filePathBase));
1324
1326
  return {
1325
1327
  id: relativePath,
1326
1328
  external: true
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "bunchee",
3
- "version": "6.0.1",
3
+ "version": "6.0.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",
@@ -111,11 +111,13 @@
111
111
  },
112
112
  "scripts": {
113
113
  "test": "jest --env node",
114
+ "test:ci": "pnpm test -- --ci",
114
115
  "test:update": "TEST_UPDATE_SNAPSHOT=1 pnpm test",
115
116
  "test:post": "cross-env POST_BUILD=1 pnpm jest test/compile.test.ts test/integration.test.ts",
116
- "test:ci": "[ -z $CI ] || pnpm test",
117
117
  "clean": "rm -rf ./dist",
118
118
  "typecheck": "tsc --noEmit && tsc -p test/tsconfig.json --noEmit",
119
+ "prepare-release": "pnpm clean && pnpm build",
120
+ "publish-local": "pnpm prepare-release && pnpm test && pnpm publish",
119
121
  "run-ts": "cross-env SWC_NODE_IGNORE_DYNAMIC=1 node -r @swc-node/register",
120
122
  "ts-bunchee": "pnpm run-ts ./src/bin/index.ts",
121
123
  "build-dir": "pnpm ts-bunchee --cwd",