Socket
Socket
Sign inDemoInstall

bunchee

Package Overview
Dependencies
Maintainers
1
Versions
145
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 1.9.0 to 2.0.0-alpha.1

29

dist/cli.js
#!/usr/bin/env node
var tslib = require('tslib');
var fs = require('fs');
var path = require('path');
require('fs');
var arg = require('arg');

@@ -9,3 +9,2 @@

var fs__default = /*#__PURE__*/_interopDefaultLegacy(fs);
var path__default = /*#__PURE__*/_interopDefaultLegacy(path);

@@ -80,3 +79,3 @@ var arg__default = /*#__PURE__*/_interopDefaultLegacy(arg);

var version = "1.9.0";
var version = "2.0.0-alpha.1";

@@ -93,3 +92,3 @@ var helpMessage = "\nUsage: bunchee [options]\n\nOptions:\n -v, --version output the version number\n -w, --watch watch src files changes\n -m, --minify compress output. false by default\n -o, --output <file> specify output filename\n -f, --format <format> specify bundle type: \"esm\", \"cjs\", \"umd\". \"esm\" by default\n -e, --external <mod> specify an external dependency\n --target <target> build environment, use \"node\" for nodejs runtime\n --no-sourcemap disable sourcemap generation, sourcemap generation is enabled by default\n --cwd <cwd> specify current working directory\n -h, --help output usage information\n";

return tslib.__awaiter(this, void 0, void 0, function () {
var source, format, watch, minify, sourcemap, target, cwd, file, outputConfig, entry, err, bundle;
var source, format, watch, minify, sourcemap, target, cwd, file, outputConfig, entry, bundle, err_1;
return tslib.__generator(this, function (_a) {

@@ -114,14 +113,20 @@ switch (_a.label) {

}
if (args.help || !source) {
if (args.help) {
return [2, help()];
}
entry = path__default["default"].resolve(cwd, source);
if (!fs__default["default"].existsSync(entry) || !fs__default["default"].statSync(entry).isFile()) {
err = new Error("Entry file is not existed");
entry = source ? path__default["default"].resolve(cwd, source) : '';
bundle = require(".").bundle;
_a.label = 1;
case 1:
_a.trys.push([1, 3, , 4]);
return [4, bundle(entry, outputConfig)];
case 2: return [2, _a.sent()];
case 3:
err_1 = _a.sent();
if (err_1.name === 'NOT_EXISTED') {
help();
return [2, exit(err)];
return [2, exit(err_1)];
}
bundle = require(".").bundle;
return [4, bundle(entry, outputConfig)];
case 1: return [2, _a.sent()];
throw err_1;
case 4: return [2];
}

@@ -128,0 +133,0 @@ });

Object.defineProperty(exports, '__esModule', { value: true });
var tslib = require('tslib');
var fs = require('fs');
var path = require('path');
var rollup = require('rollup');
var fs = require('fs');
var rollupPluginSwc3 = require('rollup-plugin-swc3');
var commonjs = require('@rollup/plugin-commonjs');
var shebang = require('rollup-plugin-preserve-shebang');
var json = require('@rollup/plugin-json');
var babel = require('@rollup/plugin-babel');
var nodeResolve = require('@rollup/plugin-node-resolve');

@@ -17,8 +17,7 @@ var rollupPluginTerser = require('rollup-plugin-terser');

var fs__default = /*#__PURE__*/_interopDefaultLegacy(fs);
var path__default = /*#__PURE__*/_interopDefaultLegacy(path);
var fs__default = /*#__PURE__*/_interopDefaultLegacy(fs);
var commonjs__default = /*#__PURE__*/_interopDefaultLegacy(commonjs);
var shebang__default = /*#__PURE__*/_interopDefaultLegacy(shebang);
var json__default = /*#__PURE__*/_interopDefaultLegacy(json);
var babel__default = /*#__PURE__*/_interopDefaultLegacy(babel);
var nodeResolve__default = /*#__PURE__*/_interopDefaultLegacy(nodeResolve);

@@ -65,2 +64,11 @@

var Module = require("module").Module;
var minifyOptions = {
compress: true,
format: {
comments: 'some',
wrapFuncArgs: false,
preserveAnnotations: true,
},
mangle: true
};
var hasLoggedTsWarning = false;

@@ -87,2 +95,3 @@ function resolveTypescript() {

var _a;
var _b;
var externals = [pkg.peerDependencies, pkg.dependencies]

@@ -92,4 +101,4 @@ .filter(function (n) { return Boolean(n); })

.reduce(function (a, b) { return a.concat(b); }, [])
.concat((_a = options.external) !== null && _a !== void 0 ? _a : []);
var useTypescript = options.useTypescript, target = options.target, _b = options.minify, minify = _b === void 0 ? false : _b;
.concat((_b = options.external) !== null && _b !== void 0 ? _b : []);
var useTypescript = options.useTypescript, target = options.target, _c = options.minify, minify = _c === void 0 ? false : _c;
var typings = pkg.types || pkg.typings;

@@ -109,15 +118,6 @@ var cwd = config.rootDir;

var tsconfig = path.resolve(cwd, "tsconfig.json");
return fs.existsSync(tsconfig) ? tsconfig : undefined;
return fs__default["default"].existsSync(tsconfig) ? tsconfig : undefined;
})(), typescript: resolveTypescript(), jsx: "react", module: "ES6", target: "ES5", noEmitOnError: !options.watch, sourceMap: options.sourcemap, declaration: !!typings }, (!!typings && {
declarationDir: path.dirname(path.resolve(cwd, typings)),
}))),
!useTypescript && babel__default["default"]({
babelHelpers: "bundled",
babelrc: false,
configFile: false,
exclude: "node_modules/**",
presets: [
["babel-preset-o", { targets: {} }]
],
}),
minify && rollupPluginTerser.terser({

@@ -133,2 +133,27 @@ compress: {

}),
useTypescript && minify && rollupPluginTerser.terser({
compress: {
"keep_infinity": true,
},
format: {
"comments": /^\s*([@#]__[A-Z]__\s*$|@[a-zA-Z]\s*$)/,
"wrap_func_args": false,
"preserve_annotations": true,
}
}),
!useTypescript && rollupPluginSwc3.swc({
include: /\.(m|c)?[jt]sx?$/,
exclude: 'node_modules',
tsconfig: 'tsconfig.json',
jsc: tslib.__assign({ target: 'es5', loose: true, externalHelpers: false, parser: (_a = {
syntax: useTypescript ? 'typescript' : 'ecmascript'
},
_a[useTypescript ? 'tsx' : 'jsx'] = true,
_a.privateMethod = true,
_a.classPrivateProperty = true,
_a.exportDefaultFrom = true,
_a) }, (minify && { minify: minifyOptions })),
sourceMaps: options.sourcemap,
inlineSourcesContent: false,
}),
].filter(function (n) { return Boolean(n); });

@@ -182,3 +207,3 @@ return {

if (!field)
return null;
return;
if (typeof field === "string")

@@ -189,28 +214,46 @@ return field;

}
function parseExport(exportsCondition) {
var paths = {};
if (typeof exportsCondition === "string") {
paths.export = exportsCondition;
}
else {
paths.main = paths.main || exportsCondition["require"] || exportsCondition["node"] || exportsCondition["default"];
paths.module = paths.module || exportsCondition["module"];
paths.export = findExport(exportsCondition);
}
return paths;
}
function getExportPaths(pkg) {
var paths = {
main: null,
module: null,
export: null,
};
var pathsMap = {};
var mainExport = {};
if (pkg.main) {
paths.main = pkg.main;
mainExport.main = pkg.main;
}
if (pkg.module) {
paths.module = pkg.module;
mainExport.module = pkg.module;
}
if (pkg.exports) {
if (typeof pkg.exports === "string") {
paths.export = pkg.exports;
pathsMap['.'] = mainExport;
var exportsConditions = pkg.exports;
if (exportsConditions) {
if (typeof exportsConditions === 'string') {
mainExport.export = exportsConditions;
}
else {
paths.main = paths.main || pkg.exports["require"] || pkg.exports["node"] || pkg.exports["default"];
paths.module = paths.module || pkg.exports["module"];
paths.export = findExport(pkg.exports);
var exportKeys = Object.keys(exportsConditions);
if (exportKeys.some(function (key) { return key.startsWith('.'); })) {
exportKeys.forEach(function (subExport) {
pathsMap[subExport] = parseExport(exportsConditions[subExport]);
});
}
else {
Object.assign(mainExport, parseExport(exportsConditions));
}
}
}
return paths;
pathsMap['.'] = mainExport;
return pathsMap;
}
function getExportDist(pkg) {
var paths = getExportPaths(pkg);
var paths = getExportPaths(pkg)['.'];
var dist = [];

@@ -231,3 +274,27 @@ if (paths.main) {

}
function createRollupConfig(entry, pkg, cliArgs) {
function getSubExportDist(pkg, subExport) {
var pkgExports = pkg.exports || {};
var dist = [];
if (typeof pkgExports === 'string') {
dist.push({ format: pkg.type === "module" ? "esm" : "cjs", file: getDistPath(pkgExports) });
}
else {
var exports_1 = pkgExports[subExport];
if (subExport.endsWith(".json"))
return dist;
if (typeof exports_1 === 'string') {
dist.push({ format: "esm", file: getDistPath(exports_1) });
}
else {
if (exports_1.require) {
dist.push({ format: "cjs", file: getDistPath(exports_1.require) });
}
if (exports_1.import) {
dist.push({ format: "esm", file: getDistPath(exports_1.import) });
}
}
}
return dist;
}
function createRollupConfig(entry, pkg, cliArgs, entryExport) {
var file = cliArgs.file, format = cliArgs.format;

@@ -238,3 +305,6 @@ var ext = path.extname(entry);

var inputOptions = createInputConfig(entry, pkg, options);
var outputConfigs = getExportDist(pkg)
var outputExports = entryExport
? getSubExportDist(pkg, entryExport)
: getExportDist(pkg);
var outputConfigs = outputExports
.map(function (exportDist) {

@@ -259,3 +329,3 @@ return createOutputOptions(tslib.__assign(tslib.__assign({}, cliArgs), { file: exportDist.file, format: exportDist.format, useTypescript: useTypescript }), pkg);

}
function bundle(entry, _a) {
function bundle(entryPath, _a) {
if (_a === void 0) { _a = {}; }

@@ -270,3 +340,31 @@ var cwd = _a.cwd, options = tslib.__rest(_a, ["cwd"]);

var npmPackage = getPackageMeta();
var rollupConfig = createRollupConfig(entry, npmPackage, options);
var _b = npmPackage.bunchee || {}, entries = _b.entry, customConfig = tslib.__rest(_b, ["entry"]);
var isSingleEntry = typeof entries === 'string';
var hasMultiEntries = entries
&& !isSingleEntry
&& Object.keys(entries).length > 0;
if (isSingleEntry) {
entryPath = path.resolve(config.rootDir, entries);
}
if (!fs__default["default"].existsSync(entryPath)) {
var hasEntryFile = entryPath === '' ? '' : fs__default["default"].statSync(entryPath).isFile();
if (!hasEntryFile && !hasMultiEntries) {
var err = new Error("Entry file is not existed");
err.name = "NOT_EXISTED";
return Promise.reject(err);
}
if (hasMultiEntries) {
Object.assign(options, customConfig);
var rollupConfigs = Object.keys(entries).map(function (entryExport) {
var source = entries[entryExport];
var rollupConfig = createRollupConfig(path.resolve(cwd, source), npmPackage, options, entryExport);
return rollupConfig;
});
return Promise.all(rollupConfigs.map(function (rollupConfig) {
return runBundle(rollupConfig);
}));
}
}
Object.assign(options, customConfig);
var rollupConfig = createRollupConfig(entryPath, npmPackage, options);
if (options.watch) {

@@ -273,0 +371,0 @@ return Promise.resolve(runWatch(rollupConfig));

import type { CliArgs } from "./types";
declare function bundle(entry: string, { cwd, ...options }?: CliArgs): Promise<any>;
declare function bundle(entryPath: string, { cwd, ...options }?: CliArgs): Promise<any>;
export default bundle;
import type { PackageMetadata, BuncheeRollupConfig, CliArgs } from "./types";
declare function createRollupConfig(entry: string, pkg: PackageMetadata, cliArgs: CliArgs): BuncheeRollupConfig;
declare function createRollupConfig(entry: string, pkg: PackageMetadata, cliArgs: CliArgs, entryExport?: string): BuncheeRollupConfig;
export default createRollupConfig;
import type { InputOptions, OutputOptions, RollupOptions } from "rollup";
declare type ExportType = "require" | "export" | "default" | string;
declare type CommonConfig = {
format?: OutputOptions["format"];
minify?: boolean;
sourcemap?: boolean;
external?: string[];
target?: string;
};
declare type BuildConfig = CommonConfig & {
entry: string | Record<string, string>;
};
declare type PackageMetadata = {

@@ -6,8 +17,11 @@ name?: string;

module?: string;
type?: "commonjs" | "module";
dependencies?: Record<string, string>;
peerDependencies?: Record<string, string>;
exports?: string | Record<string, string>;
exports?: string | Record<string, ExportCondition>;
types?: string;
typings?: string;
bunchee?: BuildConfig;
};
declare type ExportCondition = string | Record<ExportType, string>;
declare type BuncheeRollupConfig = Partial<Omit<RollupOptions, 'input' | 'output'>> & {

@@ -17,11 +31,6 @@ input: InputOptions;

};
declare type CliArgs = {
declare type CliArgs = CommonConfig & {
file?: string;
format?: OutputOptions["format"];
minify?: boolean;
watch?: boolean;
target?: string;
cwd?: string;
sourcemap?: boolean;
external?: string[];
};

@@ -31,2 +40,2 @@ declare type BundleOptions = CliArgs & {

};
export type { CliArgs, BundleOptions, PackageMetadata, BuncheeRollupConfig, };
export type { CliArgs, ExportType, BundleOptions, ExportCondition, PackageMetadata, BuncheeRollupConfig, };
{
"name": "bunchee",
"version": "1.9.0",
"version": "2.0.0-alpha.1",
"description": "zero config bundler for js/ts/jsx libraries",

@@ -11,3 +11,4 @@ "bin": {

"scripts": {
"test": "jest",
"test": "jest --env node",
"test:update": "TEST_UPDATE_SNAPSHOT=1 yarn test",
"clean": "rm -rf ./dist",

@@ -37,11 +38,12 @@ "typecheck": "tsc --noEmit",

"dependencies": {
"@rollup/plugin-babel": "5.2.1",
"@rollup/plugin-commonjs": "21.1.0",
"@rollup/plugin-json": "4.0.2",
"@rollup/plugin-json": "4.1.0",
"@rollup/plugin-node-resolve": "13.3.0",
"@rollup/plugin-typescript": "8.2.3",
"@rollup/plugin-typescript": "8.3.4",
"@swc/core": "~1.2.229",
"regenerator-runtime": "0.13.9",
"arg": "5.0.0",
"babel-preset-o": "0.4.3",
"rollup": "2.74.1",
"rollup-plugin-preserve-shebang": "1.0.1",
"rollup-plugin-swc3": "0.3.0",
"rollup-plugin-terser": "7.0.2",

@@ -48,0 +50,0 @@ "tslib": "2.3.0"

@@ -16,6 +16,7 @@ # bunchee

Bunchee can help you to bundle your library into one file with zero configuration. It's built on top of rollup and babel.
Let you focus on writing code and can generate multiple types of module (commonjs, esmodule) at the same time.
Bunchee can help you to bundle your library into one file with zero configuration. It's built on top of rollup.
Let you focus on writing code and can generate multiple types of module (CommonJS, ESModules) at the same time.
## Installation

@@ -22,0 +23,0 @@

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

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