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.3.1 to 3.3.2

2

dist/cli.js

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

var version = "3.3.1";
var version = "3.3.2";

@@ -103,0 +103,0 @@ function asyncGeneratorStep(gen, resolve, reject, _next, _throw, key, arg) {

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

function asyncGeneratorStep$3(gen, resolve, reject, _next, _throw, key, arg) {
try {
var info = gen[key](arg);
var value = info.value;
} catch (error) {
reject(error);
return;
}
if (info.done) {
resolve(value);
} else {
Promise.resolve(value).then(_next, _throw);
}
}
function _async_to_generator$3(fn) {
return function() {
var self = this, args = arguments;
return new Promise(function(resolve, reject) {
var gen = fn.apply(self, args);
function _next(value) {
asyncGeneratorStep$3(gen, resolve, reject, _next, _throw, "next", value);
}
function _throw(err) {
asyncGeneratorStep$3(gen, resolve, reject, _next, _throw, "throw", err);
}
_next(undefined);
});
};
}
function exit(err) {
logger.error(err);
process.exit(1);
}
function getPackageMeta(cwd) {
return _getPackageMeta.apply(this, arguments);
}
function _getPackageMeta() {
_getPackageMeta = _async_to_generator$3(function*(cwd) {
const pkgFilePath = path__default.default.resolve(cwd, 'package.json');
let targetPackageJson = {};
try {
targetPackageJson = JSON.parse((yield fs__default.default.readFile(pkgFilePath, {
encoding: 'utf-8'
})));
} catch (_) {}
return targetPackageJson;
});
return _getPackageMeta.apply(this, arguments);
}
const logger = {
log (arg) {
console.log(arg);
},
warn (arg) {
console.log('\x1b[33m' + arg + '\x1b[0m');
},
error (arg) {
console.error('\x1b[31m' + arg + '\x1b[0m');
}
};
function fileExists(filePath) {
return _fileExists.apply(this, arguments);
}
function _fileExists() {
_fileExists = _async_to_generator$3(function*(filePath) {
try {
yield fs__default.default.access(filePath);
return true;
} catch (err) {
if (err.code === 'ENOENT') {
return false;
}
throw err;
}
});
return _fileExists.apply(this, arguments);
}
// . -> pkg name
// ./lite -> <pkg name>/lite
function getExportPath(pkg, cwd, exportName) {
const name = pkg.name || path__default.default.basename(cwd);
if (exportName === '.' || !exportName) return name;
return path__default.default.join(name, exportName);
}
const isNotNull = (n)=>Boolean(n);
const SRC = 'src' // resolve from src/ directory
;
function resolveSourceFile(cwd, filename) {
return path__default.default.resolve(cwd, SRC, filename);
}
// Map '.' -> './index.[ext]'
// Map './lite' -> './lite.[ext]'
// Return undefined if no match or if it's package.json exports
function getSourcePathFromExportPath(cwd, exportPath) {
return _getSourcePathFromExportPath.apply(this, arguments);
}
function _getSourcePathFromExportPath() {
_getSourcePathFromExportPath = _async_to_generator$3(function*(cwd, exportPath) {
const exts = [
'js',
'cjs',
'mjs',
'jsx',
'ts',
'tsx'
];
for (const ext of exts){
// ignore package.json
if (exportPath.endsWith('package.json')) return;
if (exportPath === '.') exportPath = './index';
const filename = resolveSourceFile(cwd, `${exportPath}.${ext}`);
if (yield fileExists(filename)) {
return filename;
}
}
return;
});
return _getSourcePathFromExportPath.apply(this, arguments);
}
// Unlike path.basename, forcedly removing extension
function filenameWithoutExtension(file) {
return file ? file.replace(new RegExp(`${path__default.default.extname(file)}$`), '') : undefined;
}
function getTypings(pkg) {

@@ -280,122 +404,8 @@ return pkg.types || pkg.typings;

}
function asyncGeneratorStep$3(gen, resolve, reject, _next, _throw, key, arg) {
try {
var info = gen[key](arg);
var value = info.value;
} catch (error) {
reject(error);
return;
}
if (info.done) {
resolve(value);
} else {
Promise.resolve(value).then(_next, _throw);
}
function getTypeFilePath(entryFilePath, exportCondition, cwd) {
const name = filenameWithoutExtension(entryFilePath);
const firstDistPath = exportCondition ? Object.values(exportCondition.export)[0] : undefined;
const exportName = (exportCondition == null ? void 0 : exportCondition.name) || 'index';
return entryFilePath ? name + '.d.ts' : path.resolve(firstDistPath ? path.dirname(firstDistPath) : path.join(cwd, 'dist'), (exportName === '.' ? 'index' : exportName) + '.d.ts');
}
function _async_to_generator$3(fn) {
return function() {
var self = this, args = arguments;
return new Promise(function(resolve, reject) {
var gen = fn.apply(self, args);
function _next(value) {
asyncGeneratorStep$3(gen, resolve, reject, _next, _throw, "next", value);
}
function _throw(err) {
asyncGeneratorStep$3(gen, resolve, reject, _next, _throw, "throw", err);
}
_next(undefined);
});
};
}
function exit(err) {
logger.error(err);
process.exit(1);
}
function getPackageMeta(cwd) {
return _getPackageMeta.apply(this, arguments);
}
function _getPackageMeta() {
_getPackageMeta = _async_to_generator$3(function*(cwd) {
const pkgFilePath = path__default.default.resolve(cwd, 'package.json');
let targetPackageJson = {};
try {
targetPackageJson = JSON.parse((yield fs__default.default.readFile(pkgFilePath, {
encoding: 'utf-8'
})));
} catch (_) {}
return targetPackageJson;
});
return _getPackageMeta.apply(this, arguments);
}
const logger = {
log (arg) {
console.log(arg);
},
warn (arg) {
console.log('\x1b[33m' + arg + '\x1b[0m');
},
error (arg) {
console.error('\x1b[31m' + arg + '\x1b[0m');
}
};
function fileExists(filePath) {
return _fileExists.apply(this, arguments);
}
function _fileExists() {
_fileExists = _async_to_generator$3(function*(filePath) {
try {
yield fs__default.default.access(filePath);
return true;
} catch (err) {
if (err.code === 'ENOENT') {
return false;
}
throw err;
}
});
return _fileExists.apply(this, arguments);
}
// . -> pkg name
// ./lite -> <pkg name>/lite
function getExportPath(pkg, cwd, exportName) {
const name = pkg.name || path__default.default.basename(cwd);
if (exportName === '.' || !exportName) return name;
return path__default.default.join(name, exportName);
}
const isNotNull = (n)=>Boolean(n);
const SRC = 'src' // resolve from src/ directory
;
function resolveSourceFile(cwd, filename) {
return path__default.default.resolve(cwd, SRC, filename);
}
// Map '.' -> './index.[ext]'
// Map './lite' -> './lite.[ext]'
// Return undefined if no match or if it's package.json exports
function getSourcePathFromExportPath(cwd, exportPath) {
return _getSourcePathFromExportPath.apply(this, arguments);
}
function _getSourcePathFromExportPath() {
_getSourcePathFromExportPath = _async_to_generator$3(function*(cwd, exportPath) {
const exts = [
'js',
'cjs',
'mjs',
'jsx',
'ts',
'tsx'
];
for (const ext of exts){
// ignore package.json
if (exportPath.endsWith('package.json')) return;
if (exportPath === '.') exportPath = './index';
const filename = resolveSourceFile(cwd, `${exportPath}.${ext}`);
if (yield fileExists(filename)) {
return filename;
}
}
return;
});
return _getSourcePathFromExportPath.apply(this, arguments);
}

@@ -471,3 +481,3 @@ function asyncGeneratorStep$2(gen, resolve, reject, _next, _throw, key, arg) {

}
function buildInputConfig(entry, pkg, options, cwd, { tsConfigPath , tsCompilerOptions }, dtsOnly) {
function buildInputConfig(entry, pkg, options, cwd, { tsConfigPath , tsCompilerOptions }, dts) {
var _options_external;

@@ -488,3 +498,3 @@ const externals = options.noExternal ? [] : [

];
const plugins = (dtsOnly ? [
const plugins = (dts ? [
...commonPlugins,

@@ -566,3 +576,3 @@ useTypescript && require('rollup-plugin-dts').default({

// Some may not have types, like CLI binary
if (dtsOnly && code === 'EMPTY_BUNDLE') return;
if (dts && code === 'EMPTY_BUNDLE') return;
if ([

@@ -594,3 +604,3 @@ 'MIXED_EXPORTS',

}
function buildOutputConfigs(pkg, exportPaths, options, exportCondition, cwd, { tsCompilerOptions }, dtsOnly) {
function buildOutputConfigs(pkg, exportPaths, options, exportCondition, cwd, { tsCompilerOptions }, dts) {
const { format } = options;

@@ -602,6 +612,5 @@ // Add esm mark and interop helper if esm export is detected

const dtsDir = typings ? path.dirname(path.resolve(cwd, typings)) : path.resolve(cwd, 'dist');
// file base name without extension
const name = file ? file.replace(new RegExp(`${path.extname(file)}$`), '') : undefined;
const name = filenameWithoutExtension(file);
// TODO: simplify dts file name detection
const dtsFile = exportCondition.export['types'] ? path.resolve(cwd, exportCondition.export['types']) : file ? name + '.d.ts' : (exportCondition == null ? void 0 : exportCondition.name) ? path.resolve(dtsDir, (exportCondition.name === '.' ? 'index' : exportCondition.name) + '.d.ts') : typings && path.resolve(cwd, typings);
const dtsFile = exportCondition.export['types'] ? path.resolve(cwd, exportCondition.export['types']) : file ? name + '.d.ts' : path.resolve(dtsDir, (exportCondition.name === '.' ? 'index' : exportCondition.name) + '.d.ts');
// If there's dts file, use `output.file`

@@ -615,3 +624,3 @@ const dtsPathConfig = dtsFile ? {

name: pkg.name || name
}, dtsOnly ? dtsPathConfig : {
}, dts ? dtsPathConfig : {
file: file

@@ -629,7 +638,7 @@ }, {

// build configs for each entry from package exports
function buildEntryConfig(pkg, entryPath, exportPaths, bundleConfig, cwd, tsOptions, dtsOnly) {
function buildEntryConfig(pkg, entryPath, exportPaths, bundleConfig, cwd, tsOptions, dts) {
return _buildEntryConfig.apply(this, arguments);
}
function _buildEntryConfig() {
_buildEntryConfig = _async_to_generator$2(function*(pkg, entryPath, exportPaths, bundleConfig, cwd, tsOptions, dtsOnly) {
_buildEntryConfig = _async_to_generator$2(function*(pkg, entryPath, exportPaths, bundleConfig, cwd, tsOptions, dts) {
const configs = Object.keys(exportPaths).map(/*#__PURE__*/ _async_to_generator$2(function*(entryExport) {

@@ -639,2 +648,4 @@ // TODO: improve the source detection

if (!source) return undefined;
// For dts, only build types filed
if (dts && !exportPaths[entryExport]['types']) return undefined;
const exportCondition = {

@@ -646,3 +657,3 @@ source,

const entry = resolveSourceFile(cwd, source);
const rollupConfig = buildConfig(entry, pkg, exportPaths, bundleConfig, exportCondition, cwd, tsOptions, dtsOnly);
const rollupConfig = buildConfig(entry, pkg, exportPaths, bundleConfig, exportCondition, cwd, tsOptions, dts);
return rollupConfig;

@@ -654,3 +665,3 @@ }));

}
function buildConfig(entry, pkg, exportPaths, bundleConfig, exportCondition, cwd, tsOptions, dtsOnly) {
function buildConfig(entry, pkg, exportPaths, bundleConfig, exportCondition, cwd, tsOptions, dts) {
const { file } = bundleConfig;

@@ -661,7 +672,7 @@ const useTypescript = Boolean(tsOptions.tsConfigPath);

});
const inputOptions = buildInputConfig(entry, pkg, options, cwd, tsOptions, dtsOnly);
const inputOptions = buildInputConfig(entry, pkg, options, cwd, tsOptions, dts);
const outputExports = getExportConditionDist(pkg, exportCondition, cwd);
let outputConfigs = [];
// Generate dts job - single config
if (dtsOnly) {
if (dts) {
outputConfigs = [

@@ -671,3 +682,3 @@ buildOutputConfigs(pkg, exportPaths, _extends$1({}, bundleConfig, {

useTypescript
}), exportCondition, cwd, tsOptions, dtsOnly)
}), exportCondition, cwd, tsOptions, dts)
];

@@ -681,3 +692,3 @@ } else {

useTypescript
}), exportCondition, cwd, tsOptions, dtsOnly);
}), exportCondition, cwd, tsOptions, dts);
});

@@ -693,3 +704,3 @@ // CLI output option is always prioritized

useTypescript
}), exportCondition, cwd, tsOptions, dtsOnly)
}), exportCondition, cwd, tsOptions, dts)
];

@@ -868,2 +879,4 @@ }

;
// has `types` field in package.json or has `types` exports in any export condition for multi-entries
const hasTypings = Object.values(exportPaths).some((condition)=>condition.hasOwnProperty('types'));
const tsConfig = yield resolveTsConfig(cwd);

@@ -882,8 +895,19 @@ const hasTsConfig = Boolean(tsConfig == null ? void 0 : tsConfig.tsConfigPath);

if (entryPath) {
let mainEntryPath;
let typesEntryPath;
// with -o option
if (options.file) {
exportPaths['.'] = constructDefaultExportCondition(options.file, packageType);
mainEntryPath = options.file;
} else if (exportKeys.length === 0) {
exportPaths['.'] = constructDefaultExportCondition('dist/index.js', packageType);
mainEntryPath = path.resolve(cwd, 'dist/index.js');
}
if (mainEntryPath) {
if (options.dts) {
typesEntryPath = getTypeFilePath(mainEntryPath, undefined, cwd);
}
exportPaths['.'] = constructDefaultExportCondition({
main: mainEntryPath,
types: typesEntryPath
}, packageType);
}
}

@@ -909,4 +933,2 @@ const bundleOrWatch = (rollupConfig)=>{

}
// has `types` field in package.json or has `types` exports in any export condition for multi-entries
const hasTypings = Object.values(exportPaths).some((condition)=>condition.hasOwnProperty('types'));
// Enable types generation if it's types field specified in package.json

@@ -913,0 +935,0 @@ if (hasTypings) {

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

@@ -5,0 +5,0 @@ "bin": {

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