Socket
Socket
Sign inDemoInstall

bunchee

Package Overview
Dependencies
Maintainers
1
Versions
143
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

bunchee - npm Package Compare versions

Comparing version 3.6.1 to 3.7.0

2

dist/cli.js

@@ -53,3 +53,3 @@ #!/usr/bin/env node

var version = "3.6.1";
var version = "3.7.0";

@@ -56,0 +56,0 @@ const helpMessage = `

@@ -21,2 +21,2 @@ import { JscTarget } from '@swc/core';

export { BundleConfig, bundle };
export { type BundleConfig, bundle };

@@ -81,2 +81,3 @@ Object.defineProperty(exports, '__esModule', { value: true });

const dtsExtensionRegex = /\.d\.(m|c)?ts$/;
const SRC = 'src';

@@ -127,4 +128,2 @@ function exit(err) {

const isNotNull = (n)=>Boolean(n);
const SRC = 'src' // resolve from src/ directory
;
function resolveSourceFile(cwd, filename) {

@@ -167,2 +166,3 @@ return path__default.default.resolve(cwd, SRC, filename);

const nonNullable = (n)=>Boolean(n);
const hasAvailableExtension = (filename)=>availableExtensions.includes(path__default.default.extname(filename).slice(1));

@@ -182,17 +182,18 @@ function getTypings(pkg) {

}
function constructFullExportCondition(value, packageType) {
function constructFullExportCondition(exportCondition, packageType) {
const isCommonjs = packageType === 'commonjs';
let result;
if (typeof value === 'string') {
if (typeof exportCondition === 'string') {
result = {
[isCommonjs ? 'require' : 'import']: value
[isCommonjs ? 'require' : 'import']: exportCondition
};
} else {
// TODO: valid export condition, warn if it's not valid
const keys = Object.keys(value);
const keys = Object.keys(exportCondition);
result = {};
keys.forEach((key)=>{
const condition = exportCondition[key];
// Filter out nullable value
if (key in value && value[key]) {
result[key] = value[key];
if (key in exportCondition && condition) {
result[key] = condition;
}

@@ -211,12 +212,12 @@ });

}
function findExport(name, value, paths, packageType) {
function findExport(name, exportCondition, paths, packageType) {
// TODO: handle export condition based on package.type
if (isExportLike(value)) {
paths[name] = constructFullExportCondition(value, packageType);
if (isExportLike(exportCondition)) {
paths[name] = constructFullExportCondition(exportCondition, packageType);
return;
}
Object.keys(value).forEach((subpath)=>{
Object.keys(exportCondition).forEach((subpath)=>{
const nextName = joinRelativePath(name, subpath);
const nestedValue = value[subpath];
findExport(nextName, nestedValue, paths, packageType);
const nestedExportCondition = exportCondition[subpath];
findExport(nextName, nestedExportCondition, paths, packageType);
});

@@ -258,4 +259,4 @@ }

Object.keys(exportsCondition).forEach((key)=>{
const value = exportsCondition[key];
findExport(key, value, paths, packageType);
const exportCondition = exportsCondition[key];
findExport(key, exportCondition, paths, packageType);
});

@@ -305,8 +306,8 @@ }

* pkg.main and pkg.module will be added to ['.'] if exists
*/ function getExportPaths(pkg) {
*/ function getExportPaths(pkg, pkgType, resolvedWildcardExports) {
var _pathsMap_;
const pathsMap = {};
const packageType = getPackageType(pkg);
const packageType = pkgType != null ? pkgType : getPackageType(pkg);
const isCjsPackage = packageType === 'commonjs';
const { exports: exportsConditions } = pkg;
const exportsConditions = resolvedWildcardExports != null ? resolvedWildcardExports : pkg.exports;
if (exportsConditions) {

@@ -368,7 +369,15 @@ const paths = parseExport(exportsConditions, packageType);

function constructDefaultExportCondition(value, packageType) {
const objValue = typeof value === 'string' ? {
[packageType === 'commonjs' ? 'require' : 'import']: value,
types: getTypings(value)
} : value;
return constructFullExportCondition(objValue, packageType);
let exportCondition;
if (typeof value === 'string') {
const types = getTypings(value);
exportCondition = {
[packageType === 'commonjs' ? 'require' : 'import']: value,
...types && {
types
}
};
} else {
exportCondition = value;
}
return constructFullExportCondition(exportCondition, packageType);
}

@@ -769,2 +778,57 @@ function isEsmExportName(name, ext) {

// TODO: support nested wildcard exportsCondition (e.g. './foo/*')
const getWildcardExports = (exportsCondition)=>{
return {
'./*': exportsCondition['./*']
};
};
const isExportable = async (dirent, pathname)=>{
if (dirent.isDirectory()) {
const innerDirents = await fs__default.default.readdir(path__default.default.join(pathname, dirent.name), {
withFileTypes: true
});
return innerDirents.some(({ name })=>name.startsWith('index') && hasAvailableExtension(name));
}
return dirent.isFile() && !dirent.name.startsWith('index') && hasAvailableExtension(dirent.name);
};
async function getExportables(cwd, excludeKeys) {
const pathname = path__default.default.resolve(cwd, SRC);
const dirents = await fs__default.default.readdir(pathname, {
withFileTypes: true
});
const exportables = await Promise.all(dirents.map(async (dirent)=>await isExportable(dirent, pathname) && !excludeKeys.includes(dirent.name) ? dirent.name : undefined));
return exportables.filter(nonNullable);
}
function mapWildcard(wildcardExports, exportables) {
return exportables.map((exportable)=>{
const isFile = exportable.includes('.');
const filename = isFile ? filenameWithoutExtension(exportable) : exportable;
return {
[`./${filename}`]: Object.fromEntries(Object.entries(wildcardExports['./*']).map(([key, value])=>[
key,
value.replace(/\*/g, isFile ? filename : `${filename}/index`)
]))
};
});
}
async function resolveWildcardExports(exportsCondition, cwd) {
if (!exportsCondition || typeof exportsCondition === 'string') return undefined;
const hasWildcard = !!exportsCondition['./*'];
if (hasWildcard) {
console.warn(`The wildcard export "./*" is experimental and may change or be removed at any time.\n` + 'To open an issue, please visit https://github.com/huozhi/bunchee/issues' + '.\n');
// './foo' -> ['foo']; './foo/bar' -> ['bar']
// will contain '*' also but it's not a problem
const excludeKeys = Object.keys(exportsCondition).map((key)=>key.split('/').pop());
const exportables = await getExportables(cwd, excludeKeys);
if (exportables.length > 0) {
const wildcardExports = getWildcardExports(exportsCondition);
const resolvedWildcardExports = mapWildcard(wildcardExports, exportables);
const resolvedExports = Object.assign({}, exportsCondition, ...resolvedWildcardExports);
delete resolvedExports['./*'];
return resolvedExports;
}
}
return undefined;
}
function assignDefault(options, name, defaultValue) {

@@ -786,4 +850,5 @@ if (!(name in options) || options[name] == null) {

const pkg = await getPackageMeta(cwd);
const resolvedWildcardExports = await resolveWildcardExports(pkg.exports, cwd);
const packageType = getPackageType(pkg);
const exportPaths = getExportPaths(pkg);
const exportPaths = getExportPaths(pkg, packageType, resolvedWildcardExports);
const exportKeys = Object.keys(exportPaths).filter((key)=>key !== './package.json');

@@ -790,0 +855,0 @@ // const exportPathsLength = Object.keys(exportPaths).length

{
"name": "bunchee",
"version": "3.6.1",
"version": "3.7.0",
"description": "zero config bundler for js/ts/jsx libraries",

@@ -50,17 +50,17 @@ "bin": {

"dependencies": {
"@rollup/plugin-commonjs": "~24.0.1",
"@rollup/plugin-json": "~6.0.0",
"@rollup/plugin-node-resolve": "~15.0.2",
"@rollup/plugin-replace": "~5.0.2",
"@rollup/plugin-wasm": "~6.1.3",
"@swc/core": "^1.3.68",
"@rollup/plugin-commonjs": "^25.0.4",
"@rollup/plugin-json": "^6.0.0",
"@rollup/plugin-node-resolve": "^15.2.1",
"@rollup/plugin-replace": "^5.0.2",
"@rollup/plugin-wasm": "^6.1.3",
"@swc/core": "^1.3.82",
"@swc/helpers": "^0.5.0",
"arg": "~5.0.2",
"pretty-bytes": "~5.6.0",
"publint": "~0.1.11",
"rollup": "~3.20.2",
"rollup-plugin-dts": "~5.3.0",
"rollup-plugin-swc3": "~0.8.1",
"rollup-swc-preserve-directives": "~0.3.2",
"tslib": "~2.5.0"
"arg": "^5.0.2",
"pretty-bytes": "^5.6.0",
"publint": "^0.1.11",
"rollup": "^3.28.1",
"rollup-plugin-dts": "^6.0.1",
"rollup-plugin-swc3": "^0.10.1",
"rollup-swc-preserve-directives": "^0.4.0",
"tslib": "^2.5.0"
},

@@ -67,0 +67,0 @@ "peerDependencies": {

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc